appletree.lua
字号:
else getglobal(frame:GetName().."HighlightFrame"):SetAllPoints(frame:GetName().."Title"..i); end -- If there's a highlight color if ( frame.highlightColor ) then getglobal(frame:GetName().."HighlightFrameHighlight"):SetVertexColor(frame.highlightColor.r,frame.highlightColor.g,frame.highlightColor.b); else getglobal(frame:GetName().."HighlightFrameHighlight"):SetVertexColor(EARTHTREE_DEFAULT_HIGHLIGHT_COLOR.r,EARTHTREE_DEFAULT_HIGHLIGHT_COLOR.g,EARTHTREE_DEFAULT_HIGHLIGHT_COLOR.b); end -- Render the highlight getglobal(frame:GetName().."HighlightFrame"):Show(); end end -- all children items if ( item.children and (table.getn(item.children) > 0 or item.childrenOverride) ) then -- Indent the + symbol getglobal(frame:GetName().."Title"..i.."Expand"):SetPoint("TOPLEFT",frame:GetName().."Title"..i,"TOPLEFT",EARTHTREE_EXPAND_INDENT*(ldepth) -2, 2 ); getglobal(frame:GetName().."Title"..i.."Expand"):Enable(); getglobal(frame:GetName().."Title"..i.."Expand"):Show(); -- Ignore collapsed items if ( item.collapsed ) then getglobal(frame:GetName().."Title"..i.."Expand"):SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up"); else getglobal(frame:GetName().."Title"..i.."Expand"):SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up"); getglobal(frame:GetName().."Title"..i.."Expand".."Highlight"):SetTexture("Interface\\Buttons\\UI-PlusButton-Hilight"); end else getglobal(frame:GetName().."Title"..i.."Expand"):Hide(); getglobal(frame:GetName().."Title"..i.."Expand"):Disable(); getglobal(frame:GetName().."Title"..i.."Expand"):SetNormalTexture(""); getglobal(frame:GetName().."Title"..i.."Expand".."Highlight"):SetTexture(""); end -- Indent the text further if its marked as indented if ( not item.noTextIndent ) then ldepth = ldepth + 1; end -- Indent the text getglobal(frame:GetName().."Title"..i.."Button"):SetPoint("TOPLEFT",frame:GetName().."Title"..i,"TOPLEFT",EARTHTREE_EXPAND_INDENT*(ldepth), 0 ); getglobal(frame:GetName().."Title"..i.."Button"):SetWidth( getglobal(frame:GetName().."Title"..i):GetWidth() - ldepth * EARTHTREE_EXPAND_INDENT ); -- Set the text width if ( item.right ) then local newWidth = getglobal(frame:GetName().."Title"..i):GetWidth() - getglobal(frame:GetName().."Title"..i.."Tag"):GetStringWidth() - ldepth * EARTHTREE_EXPAND_INDENT - 2; -- Ideally this should be changed so frame scrolls left/right, needs looking at. if (newWidth < 1) then newWidth = 1; end getglobal(frame:GetName().."Title"..i.."ButtonNormalText"):SetWidth( newWidth ); else local newWidth = getglobal(frame:GetName().."Title"..i):GetWidth() - ldepth * EARTHTREE_EXPAND_INDENT - 2; -- Ideally this should be changed so frame scrolls left/right, needs looking at. if (newWidth < 1) then newWidth = 1; end getglobal(frame:GetName().."Title"..i.."ButtonNormalText"):SetWidth( newWidth ); end end end return i;end--[[ Clear's a Tree's Item ]]--function EarthTree_ClearItem(frame, i ) if ( i > 0 and i <= EARTHTREE_MAXTITLE_COUNT ) then getglobal(frame:GetName().."Title"..i):Hide(); getglobal(frame:GetName().."Title"..i.."Tag"):Hide(); getglobal(frame:GetName().."Title"..i.."Check"):Hide(); getglobal(frame:GetName().."Title"..i.."Expand"):Disable(); getglobal(frame:GetName().."Title"..i.."Expand"):SetNormalTexture(""); getglobal(frame:GetName().."Title"..i.."Expand".."Highlight"):SetTexture(""); endend--[[ Makes a flat tree from the activeTable, skipping collapsed trees according to setting ]]--function EarthTree_MakeFlatTable(theTable, depth, ignoreCollapsed) if ( not depth ) then depth = 0; end if ( ignoreCollapsed == nil ) then ignoreCollapsed = true; end local flatTable = {}; local myTable = theTable; local i = 0; -- If the table doesnt exist, then the flat table is empty if ( myTable == nil ) then return {}; end for k,v in myTable do v.depth = depth; table.insert(flatTable, v); if ( v.children and (not v.collapsed or ignoreCollapsed == false ) ) then local flatChildren = EarthTree_MakeFlatTable(v.children, depth + 1, ignoreCollapsed); for k2,v2 in flatChildren do table.insert(flatTable,v2); end end end return flatTable;end--[[ Collapses a Tree ]]--function EarthTree_SetItemCollapsed( frame, id, state ) local count = 0; local nth = id+FauxScrollFrame_GetOffset(getglobal(frame:GetName().."ListScrollFrame")); local myTable = EarthTree_MakeFlatTable(frame.activeTable); if ( myTable[nth] ) then myTable[nth].collapsed = state; end EarthTree_UpdateFrame(frame);end--[[ Set the selected ID ]]--function EarthTree_SetSelectedByID(frame,id) local nth = id+FauxScrollFrame_GetOffset(getglobal(frame:GetName().."ListScrollFrame")); local flat = EarthTree_MakeFlatTable(frame.activeTable, nil, true); if ( flat[nth] ) then frame.selected = flat[nth]; else frame.selected = nil; endend--[[ Get the selected object or nil ]]--function EarthTree_GetSelected(frame) if ( frame.selected ) then return frame.selected; end return nil;end--[[-- Returns the number of nodes in a table counting .children tables--]]function EarthTree_GetNodeCount( tableD, ignoreCollapsed ) local count = 0; if ( tableD.children ) then if ( ignoreCollapsed and tableD.collapsed ) then else count = count + table.getn(tableD.children); for k,v in tableD.children do if ( v.children ) then count = count + EarthTree_GetNodeCount(v, ignoreCollapsed); end end end end return count;end--[[-- Returns the number of nodes in a table counting .children tables--]]function EarthTree_GetFullCount( tableD, ignoreCollapsed ) local count = table.getn( tableD ); for k,v in tableD do if ( v.children ) then if ( v.collapsed and ignoreCollapsed ) then else count = count + table.getn(v.children); for k2,v2 in v.children do if ( v2.children ) then count = count + EarthTree_GetNodeCount(v2, ignoreCollapsed); end end end end end return count;end--[[ Validates a Frame ]]--function EarthTree_CheckFrame(frame) if ( frame ) then return true; else MFC.IO.print("Invalid frame passed to EarthTree_CheckFrame"); return nil; endend--[[ Validates a Table ]]--function EarthTree_CheckTable(data) if ( not data ) then MFC.IO.print("Data sent to EarthTree is nil! Name:", this:GetName() ); return false; end if ( type(data) ~= "table" ) then MFC.IO.print("Data sent to EarthTree is not a table! Name:", this:GetName() ); return false; end for k,v in data do --Something if ( type(k) ~= "number" ) then MFC.IO.print("Invalid index in data: ",this:GetName() ); return false; end if ( EarthTree_CheckItem(v) == false ) then MFC.IO.print("Invalid item: ",k); return false; end end return true;end--[[ Validates a Table Item ]]--function EarthTree_CheckItem(item) if ( not item.title and not item.right ) then MFC.IO.print("No title or subtext provided: ",this:GetName() ); return false; end -- Now subfunctioned, this may never be used. if ( not item.titleColor ) then item.titleColor = EARTHTREE_COLOR_STRING; end if ( not item.rightColor ) then item.rightColor = EARTHTREE_COLOR_STRING; end if ( item.children ) then return EarthTree_CheckTable(item.children); endend --[[ Creates an Entry out of a Standard Table ]]--function EarthTree_CreateEntry(k,v,funcTable,parents) local entry = {}; -- Create the parent chain if ( not parents ) then parents = {}; end -- Set the title portion if ( type(k) == "table" ) then entry.title = EARTHTREE_KEYWORD_TABLE; entry.titleColor = EARTHTREE_COLOR_STRING; elseif ( type(k) == "function" ) then entry.title = EARTHTREE_KEYWORD_FUNCTION; entry.titleColor = EARTHTREE_COLOR_STRING; elseif ( type(k) == "nil" ) then entry.title = EARTHTREE_KEYWORD_NIL; entry.titleColor = EARTHTREE_COLOR_NUMBER; elseif ( type(k) == "number" ) then entry.title = "["..k.."]"; entry.titleColor = EARTHTREE_COLOR_NUMBER; elseif ( type(k) == "boolean" ) then if ( k ) then entry.title = "|".."true".."|"; else entry.title = "|".."false".."|"; end entry.titleColor = EARTHTREE_COLOR_BOOLEAN; elseif ( type(k) == "string" ) then entry.title = k; entry.titleColor = EARTHTREE_COLOR_STRING; else entry.title = EARTHTREE_KEYWORD_UNKNOWN; entry.titleColor = EARTHTREE_COLOR_UNKNOWN; end -- Set the secondary value if ( type(v) == "table" ) then entry.right = EARTHTREE_KEYWORD_TABLE; entry.rightColor = EARTHTREE_COLOR_TABLE; entry.children = {}; -- Ooh, its a table! Parse its children. for k2,v2 in v do -- Create the parent hierarchy! local newParent = {}; for k3,v3 in parents do table.insert(newParent, v3); end -- Add the current parent table.insert(newParent, k); -- Add kids local kid = EarthTree_CreateEntry(k2,v2,funcTable,newParent); table.insert(entry.children, kid); end entry.expandTooltip = EARTHTREE_EXPAND_INFO..EarthTree_GetNodeCount( entry ); elseif ( type(v) == "function" ) then entry.right = EARTHTREE_KEYWORD_FUNCTION; entry.rightColor = EARTHTREE_COLOR_FUNCTION; elseif ( type(v) == "nil" ) then entry.right = EARTHTREE_KEYWORD_NIL; entry.rightColor = EARTHTREE_COLOR_NIL; elseif ( type(v) == "number" ) then entry.right = v; entry.rightColor = EARTHTREE_COLOR_NUMBER; elseif ( type(v) == "string" ) then entry.right = '"'..v..'"'; entry.rightColor = EARTHTREE_COLOR_STRING; elseif ( type(v) == "boolean" ) then if ( v ) then entry.right = "true"; else entry.right = "false"; end entry.rightColor = EARTHTREE_COLOR_BOOLEAN; else entry.right = EARTHTREE_KEYWORD_UNKNOWN; entry.rightColor = EARTHTREE_COLOR_UNKNOWN; end -- Set the functions if ( funcTable.onClick ) then entry.onClick = funcTable.onClick; end if ( funcTable.onCollapseClick ) then entry.onCollapseClick = funcTable.onCollapseClick; end if ( funcTable.onDoubleClick ) then entry.onDoubleClick = funcTable.onDoubleClick; end if ( funcTable.onCheck ) then entry.onCheck = funcTable.onCheck; end -- Set the value passed back to the function entry.value = {key=k,value=v,parent=parents}; return entry;end--[[-- HandleAction---- Delegates particular actions to events----]]function EarthTree_HandleAction (frame, id, action, a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20) --MFC.IO.print(ET_DEBUG, frame:GetName(),": ",id," [",action,"]"); local update = true; if ( action == "CLICK_EXPAND" or action == "CLICK_COLLAPSE") then if ( id > 0 ) then local item = EarthTree_GetItemByID(frame,id); local collapse = false; if ( not item.collapsed ) then collapse = true; end if ( item ) then if ( item.onCollapseClick ) then local newCollapse = nil; newCollapse = item.onCollapseClick(collapse, item.value); if ( newCollapse ~= nil ) then collapse = newCollapse; end end end EarthTree_SetItemCollapsed(frame,id, collapse); else EarthTree_CollapseAllToggle(frame); end elseif ( action == "CLICK_TEXT" ) then if ( id > 0 ) then local item = EarthTree_GetItemByID(frame,id); if ( item ) then if ( item.onClick ) then item.onClick(item.value); end end -- Set the selection EarthTree_SetSelectedByID(frame,id); end elseif ( action == "DOUBLECLICK_TEXT" ) then if ( id > 0 ) then local item = EarthTree_GetItemByID(frame,id); if ( item ) then if ( item.onDoubleClick ) then item.onDoubleClick(item.value); end end -- Set the selection EarthTree_SetSelectedByID(frame,id); end elseif ( action == "CLICK_CHECK" ) then if ( id > 0 ) then local item = EarthTree_GetItemByID(frame,id); if ( item ) then local checked = nil; if ( item.onCheck ) then checked = item.onCheck(a1, item.value); end if ( checked == nil ) then -- Set the checkbox state. item.checked = a1; else item.checked = checked; end end end elseif ( action == "CLICK_RADIO" ) then if ( id > 0 ) then local item = EarthTree_GetItemByID(frame,id); if ( item ) then if ( item.onRadio ) then item.onRadio(a1, item.value); end -- Set the checkbox state. item.radioSelected = a1; end end elseif ( action == "ENTER_TEXT" ) then local tooltipText = EarthTree_GetTooltipText(frame,id); EarthTree_SetTooltip(frame, tooltipText); update = false; elseif ( action == "ENTER_CHECK" ) then local tooltipText = EarthTree_GetTooltipText(frame,id, "CHECK"); EarthTree_SetTooltip(frame, tooltipText); update = false; elseif ( action == "ENTER_RADIO" ) then local tooltipText = EarthTree_GetTooltipText(frame,id, "RADIO"); EarthTree_SetTooltip(frame, tooltipText); update = false; elseif ( action == "ENTER_EXPAND" ) then local tooltipText = EarthTree_GetTooltipText(frame,id, "EXPAND"); EarthTree_SetTooltip(frame, tooltipText); update = false; elseif ( action == "LEAVE_TEXT" or action == "LEAVE_CHECK" or action == "LEAVE_EXPAND" ) then EarthTree_HideTooltip(frame); update = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -