📄 earthmenu.lua
字号:
info.isTitle = [nil, 1] -- If it's a title the button is disabled and the font color is set to yellowinfo.disabled = [nil, 1] -- Disable the button and show an invisible button that still traps the mouseover event so menu doesn't time outinfo.hasArrow = [nil, 1] -- Show the expand arrow for multilevel menusinfo.hasColorSwatch = [nil, 1] -- Show color swatch or not, for color selectioninfo.r = [1 - 255] -- Red color value of the color swatchinfo.g = [1 - 255] -- Green color value of the color swatchinfo.b = [1 - 255] -- Blue color value of the color swatchinfo.textR = [1 - 255] -- Red color value of the button textinfo.textG = [1 - 255] -- Green color value of the button textinfo.textB = [1 - 255] -- Blue color value of the button textinfo.swatchFunc = [function()] -- Function called by the color picker on color changeinfo.hasOpacity = [nil, 1] -- Show the opacity slider on the colorpicker frameinfo.opacity = [0.0 - 1.0] -- Percentatge of the opacity, 1.0 is fully shown, 0 is transparentinfo.opacityFunc = [function()] -- Function called by the opacity slider when you change its valueinfo.cancelFunc = [function(previousValues)] -- Function called by the colorpicker when you click the cancel button (it takes the previous values as its argument)info.notClickable = [nil, 1] -- Disable the button and color the font whiteinfo.notCheckable = [nil, 1] -- Shrink the size of the buttons and don't display a check boxinfo.owner = [Frame] -- Dropdown frame that "owns" the current dropdownlistinfo.keepShownOnClick = [nil, 1] -- Don't hide the dropdownlist after a button is clickedinfo.tooltipTitle = [nil, STRING] -- Title of the tooltip shown on mouseoverinfo.tooltipText = [nil, STRING] -- Text of the tooltip shown on mouseoverinfo.justifyH = [nil, "CENTER"] -- Justify button text]]--function EarthMenu_AddButton(info, level) --[[ Might to uncomment this if there are performance issues if ( not EARTH_UIDROPDOWNMENU_OPEN_MENU ) then return; end ]] if ( not level ) then level = 1; end local listFrame = getglobal("EarthDropDownList"..level); local listFrameName = listFrame:GetName(); local index = listFrame.numButtons + 1; local width; -- If too many buttons error out if ( index > EARTH_UIDROPDOWNMENU_MAXBUTTONS ) then Sea.io.error("Too many buttons in EarthMenu: "..EARTH_UIDROPDOWNMENU_OPEN_MENU); return; end -- If too many levels error out if ( level > EARTH_UIDROPDOWNMENU_MAXLEVELS ) then Sea.io.error("Too many levels in EarthMenu: "..EARTH_UIDROPDOWNMENU_OPEN_MENU); return; end -- Set the number of buttons in the listframe listFrame.numButtons = index; local button = getglobal(listFrameName.."Button"..index); local normalText = getglobal(button:GetName().."NormalText"); local highlightText = getglobal(button:GetName().."HighlightText"); local disabledText = getglobal(button:GetName().."DisabledText"); -- This button is used to capture the mouse OnEnter/OnLeave events if the dropdown button is disabled, since a disabled button doesn't receive any events -- This is used specifically for drop down menu time outs local invisibleButton = getglobal(button:GetName().."InvisibleButton"); -- Default settings disabledText:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b); invisibleButton:Hide(); button:Enable(); -- Configure button if ( info.text ) then button:SetText(info.text); -- Determine the maximum width of a button width = normalText:GetWidth() + 60; -- Add padding if has and expand arrow or color swatch if ( info.hasArrow or info.hasColorSwatch ) then width = width + 50 - 30; end if ( info.notCheckable ) then width = width - 30; end if ( width > listFrame.maxWidth ) then listFrame.maxWidth = width; end -- If a textR is set then set the vertex color of the button text if ( info.textR ) then normalText:SetTextColor(info.textR, info.textG, info.textB); highlightText:SetTextColor(info.textR, info.textG, info.textB); else normalText:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b); highlightText:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b); end else button:SetText(""); end -- Pass through attributes button.func = info.func; button.owner = info.owner; button.hasOpacity = info.hasOpacity; button.opacity = info.opacity; button.opacityFunc = info.opacityFunc; button.cancelFunc = info.cancelFunc; button.swatchFunc = info.swatchFunc; button.keepShownOnClick = info.keepShownOnClick; button.tooltipTitle = info.tooltipTitle; button.tooltipText = info.tooltipText; button.index = info.index; if ( info.value ) then button.value = info.value; elseif ( info.text ) then button.value = info.text; else button.value = nil; end -- Show the expand arrow if it has one if ( info.hasArrow ) then getglobal(listFrameName.."Button"..index.."ExpandArrow"):Show(); else getglobal(listFrameName.."Button"..index.."ExpandArrow"):Hide(); end button.hasArrow = info.hasArrow; -- If not checkable move everything over to the left to fill in the gap where the check would be local xPos = 5; local yPos = -((button:GetID() - 1) * EARTH_UIDROPDOWNMENU_BUTTON_HEIGHT) - EARTH_UIDROPDOWNMENU_BORDER_HEIGHT; normalText:ClearAllPoints(); highlightText:ClearAllPoints(); disabledText:ClearAllPoints(); if ( info.notCheckable ) then if ( info.justifyH and info.justifyH == "CENTER" ) then normalText:SetPoint("CENTER", button:GetName(), "CENTER", -7, 0); highlightText:SetPoint("CENTER", button:GetName(), "CENTER", -7, 0); disabledText:SetPoint("CENTER", button:GetName(), "CENTER", -7, 0); else normalText:SetPoint("LEFT", button:GetName(), "LEFT", 0, 0); highlightText:SetPoint("LEFT", button:GetName(), "LEFT", 0, 0); disabledText:SetPoint("LEFT", button:GetName(), "LEFT", 0, 0); end xPos = xPos + 10; else xPos = xPos + 12; normalText:SetPoint("LEFT", button:GetName(), "LEFT", 27, 0); highlightText:SetPoint("LEFT", button:GetName(), "LEFT", 27, 0); disabledText:SetPoint("LEFT", button:GetName(), "LEFT", 27, 0); end -- Adjust offset if displayMode is menu local frame = getglobal(EARTH_UIDROPDOWNMENU_OPEN_MENU); if ( frame and frame.displayMode == "MENU" ) then if ( not info.notCheckable ) then xPos = xPos - 6; end end -- If no open frame then set the frame to the currently initialized frame if ( not frame ) then frame = getglobal(EARTH_UIDROPDOWNMENU_INIT_MENU); end button:SetPoint("TOPLEFT", button:GetParent():GetName(), "TOPLEFT", xPos, yPos); -- See if button is selected by id or name if ( frame ) then if ( EarthMenu_GetSelectedName(frame) ) then if ( button:GetText() == EarthMenu_GetSelectedName(frame) ) then info.checked = 1; end elseif ( EarthMenu_GetSelectedID(frame) ) then if ( button:GetID() == EarthMenu_GetSelectedID(frame) ) then info.checked = 1; end elseif ( EarthMenu_GetSelectedValue(frame) ) then if ( button.value == EarthMenu_GetSelectedValue(frame) ) then info.checked = 1; end end end -- Show the check if checked if ( info.checked ) then button:LockHighlight(); getglobal(listFrameName.."Button"..index.."Check"):Show(); else button:UnlockHighlight(); getglobal(listFrameName.."Button"..index.."Check"):Hide(); end button.checked = info.checked; -- If has a colorswatch, show it and vertex color it local colorSwatch = getglobal(listFrameName.."Button"..index.."ColorSwatch"); if ( info.hasColorSwatch ) then getglobal("EarthDropDownList"..level.."Button"..index.."ColorSwatch".."NormalTexture"):SetVertexColor(info.r, info.g, info.b); button.r = info.r; button.g = info.g; button.b = info.b; colorSwatch:Show(); else colorSwatch:Hide(); end -- If not clickable then disable the button and set it white if ( info.notClickable ) then info.disabled = 1; disabledText:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b); end -- Set the text color and disable it if its a title if ( info.isTitle ) then info.disabled = 1; disabledText:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b); end -- Disable the button if disabled if ( info.disabled ) then button:Disable(); invisibleButton:Show(); end -- Set the height of the listframe listFrame:SetHeight((index * EARTH_UIDROPDOWNMENU_BUTTON_HEIGHT) + (EARTH_UIDROPDOWNMENU_BORDER_HEIGHT * 2)); button:Show();endfunction EarthMenu_Refresh(frame, isCleared, useValue) local button, checked, checkImage; if ( not frame ) then frame = this; end -- Just redraws the existing menu for i=1, EARTH_UIDROPDOWNMENU_MAXBUTTONS do button = getglobal("EarthDropDownList"..EARTH_UIDROPDOWNMENU_MENU_LEVEL.."Button"..i); checked = nil; -- See if checked or not if ( EarthMenu_GetSelectedName(frame) ) then if ( button:GetText() == EarthMenu_GetSelectedName(frame) ) then checked = 1; end elseif ( EarthMenu_GetSelectedID(frame) ) then if ( button:GetID() == EarthMenu_GetSelectedID(frame) ) then checked = 1; end elseif ( EarthMenu_GetSelectedValue(frame) ) then if ( button.value == EarthMenu_GetSelectedValue(frame) ) then checked = 1; end end -- If checked show check image checkImage = getglobal("EarthDropDownList"..EARTH_UIDROPDOWNMENU_MENU_LEVEL.."Button"..i.."Check"); if ( checked and not isCleared ) then if ( useValue ) then EarthMenu_SetText(button.value, frame); else EarthMenu_SetText(button:GetText(), frame); end button:LockHighlight(); checkImage:Show(); else button:UnlockHighlight(); checkImage:Hide(); end endendfunction EarthMenu_SetSelectedName(frame, name, useValue) frame.selectedName = name; frame.selectedID = nil; frame.selectedValue = nil; EarthMenu_Refresh(frame, nil, useValue);endfunction EarthMenu_SetSelectedValue(frame, value, useValue) -- useValue will set the value as the text, not the name frame.selectedName = nil; frame.selectedID = nil; frame.selectedValue = value; EarthMenu_Refresh(frame, nil, useValue);endfunction EarthMenu_SetSelectedID(frame, id, useValue) frame.selectedID = id; frame.selectedName = nil; frame.selectedValue = nil; EarthMenu_Refresh(frame, nil, useValue);endfunction EarthMenu_GetSelectedName(frame) return frame.selectedName;endfunction EarthMenu_GetSelectedID(frame) if ( frame.selectedID ) then return frame.selectedID; else -- If no explicit selectedID then try to send the id of a selected value or name local button; for i=1, EARTH_UIDROPDOWNMENU_MAXBUTTONS do button = getglobal("EarthDropDownList"..EARTH_UIDROPDOWNMENU_MENU_LEVEL.."Button"..i); -- See if checked or not if ( EarthMenu_GetSelectedName(frame) ) then if ( button:GetText() == EarthMenu_GetSelectedName(frame) ) then return i; end elseif ( EarthMenu_GetSelectedValue(frame) ) then if ( button.value == EarthMenu_GetSelectedValue(frame) ) then return i; end end end endendfunction EarthMenu_GetSelectedValue(frame) return frame.selectedValue;endfunction EarthMenuButton_OnClick() local func = this.func; if ( func ) then func(not this.checked, this.value); else return; end if ( this.keepShownOnClick ) then if ( this.checked ) then getglobal(this:GetName().."Check"):Hide(); this.checked = nil; else getglobal(this:GetName().."Check"):Show(); this.checked = 1; end else this:GetParent():Hide(); end PlaySound("UChatScrollButton");endfunction EarthMenu_ToggleDropDownMenu(level, value, dropDownFrame, anchorName, xOffset, yOffset, customPoint) if ( not level ) then level = 1; end EARTH_UIDROPDOWNMENU_MENU_LEVEL = level; EARTH_UIDROPDOWNMENU_MENU_VALUE = value; local listFrame = getglobal("EarthDropDownList"..level); local listFrameName = "EarthDropDownList"..level; local tempFrame; if ( not dropDownFrame ) then tempFrame = this:GetParent(); else tempFrame = dropDownFrame; end if ( not customPoint ) then customPoint = "TOPLEFT"; end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -