vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 BagnonDBUI
3 Functions for the dropdown menu for showing cached data
4 No alterations if this code should be needed to make it work with other databases
5  
6 Essentially the dropdown is used to switch between the inventory of other characters
7 Why not use a normal dropdown? It takes a lot of memory
8 --]]
9  
10 local minWidth = 120;
11  
12 --switch to view a different character's data
13 function BagnonDBUI_ChangePlayer(frame, player)
14 frame.player = player;
15  
16 --update the frame's title
17 getglobal(frame:GetName() .. "Title"):SetText(string.format(frame.title, player));
18  
19 --update the frame's contents
20 BagnonFrame_Generate(frame);
21  
22 --update the frame's bags, if they exist and are shown
23 local bagFrame = getglobal(frame:GetName() .. "Bags");
24 if bagFrame and bagFrame:IsShown() then
25 for i = 1, 10 do
26 BagnonBag_UpdateTexture(frame, i);
27 end
28 end
29  
30 --update banknon's purchase button
31 if frame == Banknon then
32 Banknon_UpdatePurchaseButtonVis();
33 end
34 end
35  
36 --[[ Character List ]]--
37  
38 --create a player button, which is used to switch between characters
39 local function CreatePlayerButton(id, parent)
40 local button = CreateFrame("CheckButton", parent:GetName() .. id, parent, "BagnonDBUINameBox");
41 if id == 1 then
42 button:SetPoint("TOPLEFT", parent, "TOPLEFT", 6, -4);
43 else
44 button:SetPoint("TOP", getglobal(parent:GetName() .. (id - 1) ), "BOTTOM", 0, 6);
45 end
46 return button;
47 end
48  
49 function BagnonDBUI_ShowCharacterList(parentFrame)
50 BagnonDBUICharacterList.frame = parentFrame;
51  
52 local width = 0;
53  
54 --update button info
55 local index = 0;
56 for player in BagnonDB.GetPlayers() do
57 index = index + 1;
58  
59 local button = getglobal("BagnonDBUICharacterList" .. index) or CreatePlayerButton(index, BagnonDBUICharacterList);
60 button:SetText(player);
61 if button:GetTextWidth() + 40 > width then
62 width = button:GetTextWidth() + 40;
63 end
64  
65 if parentFrame.player == player then
66 button:SetChecked(true);
67 button:Show();
68 else
69 button:SetChecked(false);
70 end
71 end
72  
73 local i = index + 1;
74 while getglobal("BagnonDBUICharacterList" .. i) do
75 getglobal("BagnonDBUICharacterList" .. i):Hide();
76 i = i + 1;
77 end
78  
79 --resize and position the frame
80 BagnonDBUICharacterList:SetHeight(12 + index * 19);
81 BagnonDBUICharacterList:SetWidth(width);
82 BagnonDBUICharacterList:ClearAllPoints();
83 BagnonDBUICharacterList:SetPoint("TOPLEFT", parentFrame:GetName() .. "DropDown", "BOTTOMLEFT", 0, 4);
84 BagnonDBUICharacterList:Show();
85 end
86  
87 --[[ Function Hooks and Overrides ]]--
88  
89 --hide any menus attached to the frame, if they're visible and we're hiding the frame
90 local oBagnonFrame_OnHide = BagnonFrame_OnHide;
91 BagnonFrame_OnHide = function()
92 oBagnonFrame_OnHide()
93  
94 if BagnonDBUICharacterList.frame == this then
95 BagnonDBUICharacterList:Hide()
96 end
97 end