appletree.lua
字号:
end -- Prevent unnessecary re-draws if ( update ) then -- Update the gui EarthTree_UpdateFrame( frame ); endend---- Sets the location of the Tooltip--function EarthTree_SetTooltip(frame, tooltipText) if ( frame.tooltip ) then local tooltip = getglobal(frame.tooltip); if ( tooltipText ) then -- Set the location of the tooltip if ( frame.tooltipPlacement == "cursor" ) then tooltip:SetOwner(UIParent,"ANCHOR_CURSOR"); elseif ( frame.tooltipPlacement == "button" ) then tooltip:SetOwner(this,frame.tooltipAnchor); else tooltip:SetOwner(frame,frame.tooltipAnchor); end --Sea.wow.tooltip.protectTooltipMoney(); tooltip:SetText(tooltipText, 0.8, 0.8, 1.0); tooltip:Show(); --Sea.wow.tooltip.unprotectTooltipMoney(); end endend---- Hides the location of the Tooltip--function EarthTree_HideTooltip(frame) if ( frame.tooltip ) then getglobal(frame.tooltip):Hide(); getglobal(frame.tooltip):SetOwner(UIParent, "ANCHOR_RIGHT"); endend--[[-- All Object Event Handlers are Below----]]--[[ MouseWheel Events ]]function EarthTree_OnMouseWheel(frameName, delta) local offset = FauxScrollFrame_GetOffset(getglobal(frameName.."ListScrollFrame")); local maxOffset = EarthTree_GetFullCount( getglobal(frameName).activeTable, true) - getglobal(frameName).titleCount; local scrollbar = getglobal(frameName.."ListScrollFrameScrollBar") local min,max = scrollbar:GetMinMaxValues(); if ( type(offset) == "number" ) then local newVal = offset - delta; if ( newVal >= 0 and newVal <= maxOffset ) then scrollbar:SetValue(newVal/maxOffset*max); FauxScrollFrame_SetOffset(getglobal(frameName.."ListScrollFrame"), newVal ); EarthTree_UpdateFrame(getglobal(frameName)); elseif ( newVal > maxOffset ) then if ( maxOffset < 0 ) then offset = 0; maxOffset = 1; else offset = maxOffset; end scrollbar:SetValue(offset/maxOffset*max); FauxScrollFrame_SetOffset(getglobal(frameName.."ListScrollFrame"), offset); EarthTree_UpdateFrame(getglobal(frameName)); end endend--[[ CheckButton Events ]]--function EarthTree_CheckButton_OnLoad() --this:RegisterForClicks("LeftButtonDown", "LeftButtonUp", "RightButtonDown", "RightButtonUp"); this:RegisterForClicks("LeftButtonDown", "RightButtonDown"); this.onEnter = EarthTree_CheckButton_OnEnter; this.onLeave = EarthTree_CheckButton_OnLeave; this.onClick = EarthTree_CheckButton_OnClick; this.onMouseWheel = EarthTree_ExpandButton_OnMouseWheel; end function EarthTree_CheckButton_OnEnter() EarthTree_HandleAction(this:GetParent():GetParent(),this:GetParent():GetID(),"ENTER_CHECK", this:GetChecked());endfunction EarthTree_CheckButton_OnLeave() EarthTree_HandleAction(this:GetParent():GetParent(),this:GetParent():GetID(),"LEAVE_CHECK", this:GetChecked());endfunction EarthTree_CheckButton_OnClick() EarthTree_HandleAction(this:GetParent():GetParent(),this:GetParent():GetID(),"CLICK_CHECK", this:GetChecked());end--[[ CheckButton Events ]]--function EarthTree_RadioButton_OnLoad() --this:RegisterForClicks("LeftButtonDown", "LeftButtonUp", "RightButtonDown", "RightButtonUp"); this:RegisterForClicks("LeftButtonDown", "RightButtonDown"); this.onEnter = EarthTree_RadioButton_OnEnter; this.onLeave = EarthTree_RadioButton_OnLeave; this.onClick = EarthTree_RadioButton_OnClick; this.onMouseWheel = EarthTree_ExpandButton_OnMouseWheel; end function EarthTree_RadioButton_OnEnter() EarthTree_HandleAction(this:GetParent():GetParent(),this:GetParent():GetID(),"ENTER_RADIO", this:GetChecked());endfunction EarthTree_RadioButton_OnLeave() EarthTree_HandleAction(this:GetParent():GetParent(),this:GetParent():GetID(),"LEAVE_RADIO", this:GetChecked());endfunction EarthTree_RadioButton_OnClick() EarthTree_HandleAction(this:GetParent():GetParent(),this:GetParent():GetID(),"CLICK_RADIO", this:GetChecked());end--[[ Expand Button Event Handlers ]]--function EarthTree_ExpandButton_OnLoad() --this:RegisterForClicks("LeftButtonDown", "LeftButtonUp", "RightButtonDown", "RightButtonUp"); this:RegisterForClicks("LeftButtonDown", "RightButtonDown"); this.onEnter = EarthTree_ExpandButton_OnEnter; this.onClick = EarthTree_ExpandButton_OnClick; this.onLeave = EarthTree_ExpandButton_OnLeave; this.onMouseWheel = EarthTree_ExpandButton_OnMouseWheel;endfunction EarthTree_ExpandButton_OnEnter() EarthTree_HandleAction(this:GetParent():GetParent(),this:GetParent():GetID(),"ENTER_EXPAND");endfunction EarthTree_ExpandButton_OnClick() EarthTree_HandleAction(this:GetParent():GetParent(),this:GetParent():GetID(),"CLICK_EXPAND");endfunction EarthTree_ExpandButton_OnLeave() EarthTree_HandleAction(this:GetParent():GetParent(),this:GetParent():GetID(),"LEAVE_EXPAND");endfunction EarthTree_ExpandButton_OnMouseWheel(delta) local frameName = this:GetParent():GetParent():GetName(); EarthTree_OnMouseWheel(frameName, delta);end--[[ Clicking on Text Event Handlers ]]--function EarthTree_ButtonFrame_OnLoad() this.onEnter = EarthTree_Text_OnEnter; this.onClick = EarthTree_Text_OnClick; this.onLeave = EarthTree_Text_OnLeave; this.onDoubleClick = EarthTree_Text_OnDoubleClick; this.onMouseWheel = EarthTree_Text_OnMouseWheel;endfunction EarthTree_Text_OnLoad() --this:RegisterForClicks("LeftButtonDown", "LeftButtonUp", "RightButtonDown", "RightButtonUp"); this:RegisterForClicks("LeftButtonDown", "RightButtonDown"); this.onEnter = EarthTree_Text_OnEnter; this.onClick = EarthTree_Text_OnClick; this.onLeave = EarthTree_Text_OnLeave; this.onDoubleClick = EarthTree_Text_OnDoubleClick; this.onMouseWheel = EarthTree_Text_OnMouseWheel;endfunction EarthTree_Text_OnEnter() -- Highlights the 2ndary text on mouseover getglobal(this:GetParent():GetName().."Tag"):SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b); EarthTree_HandleAction(this:GetParent():GetParent(),this:GetParent():GetID(),"ENTER_TEXT"); endfunction EarthTree_Text_OnClick() EarthTree_HandleAction(this:GetParent():GetParent(),this:GetParent():GetID(),"CLICK_TEXT");endfunction EarthTree_Text_OnDoubleClick() EarthTree_HandleAction(this:GetParent():GetParent(),this:GetParent():GetID(),"DOUBLECLICK_TEXT");endfunction EarthTree_Text_OnMouseWheel(delta) local frameName = this:GetParent():GetParent():GetName(); EarthTree_OnMouseWheel(frameName, delta);endfunction EarthTree_Text_OnLeave() if (this:GetParent():GetID() ~= this:GetParent():GetParent().selectedId) then local button = getglobal(this:GetName()); button:SetTextColor(button.r, button.g,button.b); local check = getglobal(this:GetParent():GetName().."Check"); check:SetTextColor(check.r, check.g, check.b); local tag = getglobal(this:GetParent():GetName().."Tag"); tag:SetTextColor(tag.r, tag.g,tag.b); end -- Hides the parent tooltip EarthTree_HideTooltip(this:GetParent():GetParent());end--[[ Collapse All Button Event Handlers ]]--function EarthTree_CollapseAllButton_OnLoad() --this:RegisterForClicks("LeftButtonDown", "LeftButtonUp", "RightButtonDown", "RightButtonUp"); getglobal(this:GetName().."Button"):RegisterForClicks("LeftButtonDown", "RightButtonDown"); getglobal(this:GetName().."Button"):SetText(ALL); getglobal(this:GetName().."Button"):SetWidth(this:GetWidth()); getglobal(this:GetName().."Button"):SetPoint("TOPLEFT", this:GetName(), "TOPLEFT", EARTHTREE_EXPAND_INDENT, -2); this.onClick = EarthTree_CollapseAllButton_OnClick; this.onEnter = EarthTree_CollapseAllButton_OnEnter; this.onLeave = EarthTree_CollapseAllButton_OnLeave; getglobal(this:GetName().."Button").onClick = EarthTree_CollapseAllButton_OnClick; getglobal(this:GetName().."Expand").onClick = EarthTree_CollapseAllButton_Icon_OnClick; getglobal(this:GetName().."Button").onEnter = EarthTree_CollapseAllButton_OnEnter; getglobal(this:GetName().."Expand").onEnter = EarthTree_CollapseAllButton_Icon_OnEnter; getglobal(this:GetName().."Button").onLeave = EarthTree_CollapseAllButton_OnLeave; getglobal(this:GetName().."Expand").onLeave = EarthTree_CollapseAllButton_Icon_OnLeave;endfunction EarthTree_CollapseAllButton_Icon_OnClick() EarthTree_HandleAction(this:GetParent():GetParent():GetParent(),0,"CLICK_COLLAPSE");endfunction EarthTree_CollapseAllButton_OnClick() EarthTree_HandleAction(this:GetParent():GetParent():GetParent(),0,"CLICK_COLLAPSE");endfunction EarthTree_CollapseAllButton_OnEnter()endfunction EarthTree_CollapseAllButton_Icon_OnEnter()endfunction EarthTree_CollapseAllButton_OnLeave()endfunction EarthTree_CollapseAllButton_Icon_OnLeave()end--[[-- Toggles the collapsed state of all trees.--]]function EarthTree_CollapseAllToggle(frame) local count = 0; local myTable = EarthTree_MakeFlatTable(frame.activeTable, nil, false); -- Check if they are all collapsed for k,v in myTable do if ( v.collapsed ) then count = count + 1; end end -- If they are all collapsed if ( count == table.getn(myTable) ) then -- Expand them all for k,v in myTable do myTable[k].collapsed = false; end getglobal(frame:GetName().."Expand".."CollapseAllExpand"):SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up"); else -- Collapse them all for k,v in myTable do myTable[k].collapsed = true; end getglobal(frame:GetName().."Expand".."CollapseAllExpand"):SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up"); end EarthTree_UpdateFrame(frame);end--[[ Frame Event handlers ]]--function EarthTree_Frame_OnLoad() this.onClick = EarthTree_Frame_OnClick; this.onShow = EarthTree_Frame_OnShow; this.onEvent = EarthTree_Frame_OnEvent; this.onMouseWheel = EarthTree_Frame_OnMouseWheel; -- -- Sets the default object values -- this.titleCount = EARTHTREE_MAXTITLE_COUNT; this.highlight = true; this.highlightSize = "long"; -- Can also be "short" [Buggy] this.extraIndent = true; -- Indents child nodes once all the of the time -- Use any tooltip you'd like. I use my own this.tooltip = "EarthTooltip"; -- -- Can be "button", "frame", "cursor" -- this.tooltipPlacement = "cursor"; this.tooltipAnchor = "ANCHOR_RIGHT"; -- Can be any valid tooltip anchor this.activeTable = {}; -- -- Shows or hides the expand all button -- this.collapseAllButton = true; this.collapseAllArtwork = true; -- Hide all buttons once for i=1,this.titleCount do getglobal(this:GetName().."Title"..i):Show(); end for i=this.titleCount+1, EARTHTREE_MAXTITLE_COUNT do getglobal(this:GetName().."Title"..i):Hide(); endendfunction EarthTree_Frame_OnShow() EarthTree_UpdateFrame(this);endfunction EarthTree_Frame_OnClick()endfunction EarthTree_Frame_OnEvent()endfunction EarthTree_Frame_OnMouseWheel(delta) local frameName = this:GetName(); EarthTree_OnMouseWheel(frameName, delta);end--[[---- Earth Tree Demo Code--------function dt() local tree = { a = "a"; b = "b"; c = "c"; d = "d"; e = "e"; f = { 1,2,3,4,5,6,7,8; a={ 11,22,33,44,55; }; b={ 66,77,88,99,110; }; }; }; local eTree = { { title="a"; right="b"; tooltip="Hail!"; onClick = function(a) Sea.io.print(a); end; children = { { title="a's child"; right="(some thing)"; onClick = function(a) MFC.IO.print(a); end; children = { { title="a's first grandkid"; check=true; checked=true; onCheck = function(check) Sea.io.print(check) end; onClick = function( a ) Sea.io.print(a); end; children = { { check=true; checked=1; title="great grandkid"; onClick = function( a ) MFC.IO.print(a,"!") end; } }; }; { title="a's second grandkid"; check=true; checked=true; checkDisabled=true; onCheck = function(check) Sea.io.print(check) end; onClick = function( a ) Sea.io.print(a); end; children = { { check=true; checked=1; title="great grandkid"; onClick = function( a ) MFC.IO.print(a,"!") end; } }; }; }; }; { title="a's child 2"; right="(some other thing)"; tooltip="Simon"; onClick = function(a) MFC.IO.print(a); end; }; { title="a's child 3"; right="(some other2 thing)"; tooltip="Alvin"; onClick = function(a) MFC.IO.print(a); end; } }; }; { title="two"; right="5"; onClick = function(a) Sea.io.print(a); end; children = { { title="two's child"; tooltip="Theodore"; right="(some OTHER)"; rightColor={r=1.0,g=.24,b=0}; onClick = function(a) Sea.io.print(a); end; } }; }; { title="three"; right="99 Bottles"; onClick = function(a) Sea.io.print(a); end; children = { { title="three's child"; right="(some third thing)"; rightColor={r=1.0,g=.24,b=0}; onClick = function(a) Sea.io.print(a); end; } }; }; }; EarthTree_LoadTable( getglobal("EarthTree"), tree, { onClick = function(a) Sea.io.printTable(a); end; }, ); EarthTree_LoadEnhanced( getglobal("EarthTree"), eTree ); EarthTree_UpdateFrame( getglobal("EarthTree") ); end]]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -