vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --===========================================================================--
2 ---------------------------- LootTracker by PNB ----------------------------
3 --===========================================================================--
4 -- LootTrackerPlayerDetailsUI.lua
5 --
6 -- Code behind the player details UI
7 --===========================================================================--
8  
9  
10 ------------------------------------------------------------------------------
11 -- SetPlayer
12 ------------------------------------------------------------------------------
13  
14 function LT_SetPlayer(player)
15  
16 LT_DebugMessage(2, string.format("Viewing player %s", player.Name));
17  
18 LT_PlayerDetails:Show();
19 LT_ItemDetails:Hide();
20 LT_KillDetails:Hide();
21 LT_SettingsFrame:Hide();
22  
23 local description = player.Name;
24 description = description .. string.format("\nLevel %d", player.Level);
25 description = description .. string.format("\n%s %s %s", player.Gender, player.Race, player.Class);
26  
27 if (player.TimesKilled ~= nil) then
28 local deaths = getn(player.TimesKilled);
29 if (deaths == 1) then
30 description = description .. string.format("\n%d death", deaths);
31 else
32 description = description .. string.format("\n%d deaths", deaths);
33 end
34 end
35  
36 LT_Player_DescriptionText:SetText(description);
37  
38  
39 local totalValue = 0;
40 local items = LT_GetItems();
41 foreach(player.Loot, function(k,v)
42  
43 local item = items[k];
44 if (item.Value) then
45 totalValue = totalValue + (item.Value * v);
46 end
47  
48 end);
49  
50 local totalValueString = LT_GetValueString(totalValue, true);
51 LT_Player_ValueText:SetText(totalValueString);
52  
53  
54 LT_Player_GearList.Data = player;
55 LT_Player_LootList.Data = player;
56 LT_PlayerDetails.Data = player;
57  
58 LT_UpdateGenericScroller(LT_Player_GearList);
59 LT_UpdateGenericScroller(LT_Player_LootList);
60  
61 end
62  
63  
64 ------------------------------------------------------------------------------
65 -- Player_Update
66 ------------------------------------------------------------------------------
67  
68 function LT_Player_Update()
69  
70 local player = LT_PlayerDetails.Data;
71 LT_UpdatePlayer(player);
72  
73 LT_UpdateGenericScroller(LT_Player_GearList);
74  
75 end
76  
77  
78 ------------------------------------------------------------------------------
79 -- Player_Loot_GetTotal
80 ------------------------------------------------------------------------------
81  
82 function LT_Player_Loot_GetTotal(scroller)
83  
84 if (scroller.Data == nil) then
85 LT_DebugMessage(1, "No player: Unable to get Loot total");
86 return 0;
87 end
88  
89 if (scroller.Data.Loot == nil) then
90 LT_DebugMessage(1, "No loot list: Unable to get Loot total");
91 return 0;
92 end
93  
94 local uniqueCount = 0;
95 local totalCount = 0;
96 foreach(scroller.Data.Loot, function(k,v)
97  
98 uniqueCount = uniqueCount + 1;
99 totalCount = totalCount + v;
100  
101 end);
102  
103 scroller.TotalCount = totalCount;
104  
105 return uniqueCount;
106  
107 end
108  
109 ------------------------------------------------------------------------------
110 -- Player_Loot_GetItemLabel
111 ------------------------------------------------------------------------------
112  
113 function LT_Player_Loot_GetItemLabel(scroller, index)
114  
115 if (scroller.Data == nil) then
116 return "Unknown";
117 end
118  
119 local label, data = LT_GetItemLabel(scroller, scroller.Data.Loot, index, LT_Player_Loot_GetItemLabelWorker);
120 return label, data;
121  
122 end
123  
124  
125 ------------------------------------------------------------------------------
126 -- Player_Loot_GetItemLabelWorker
127 ------------------------------------------------------------------------------
128  
129 function LT_Player_Loot_GetItemLabelWorker(scroller, k, v)
130  
131 local items = LT_GetItems();
132 local item = items[k];
133  
134 if (item == nil) then
135 return "Unknown", k;
136 end
137  
138 local count = v;
139  
140 local qualityColor = LT_QualityColors[tostring(item.Quality)];
141 local description = LT_ColorText(item.Name, qualityColor);
142  
143 local valueString = "";
144 if (item.Value) then
145 valueString = "(" .. LT_GetValueString(item.Value, true) .. ")";
146 end
147  
148 local label = string.format("%s: %d %s", description, count, valueString);
149 local data = k;
150  
151 return label, data;
152  
153 end
154  
155  
156 ------------------------------------------------------------------------------
157 -- Player_Gear_GetTotal
158 ------------------------------------------------------------------------------
159  
160 function LT_Player_Gear_GetTotal(scroller)
161  
162 if (scroller.Data == nil) then
163 LT_DebugMessage(1, "No player: Unable to get Gear total");
164 return 0;
165 end
166  
167 if (scroller.Data.Gear == nil) then
168 LT_DebugMessage(1, "No gear list: Unable to get Gear total");
169 return 0;
170 end
171  
172 local uniqueCount = 0;
173 local totalCount = 0;
174 foreach(scroller.Data.Gear, function(k,v)
175  
176 uniqueCount = uniqueCount + 1;
177  
178 end);
179  
180 scroller.TotalCount = uniqueCount;
181  
182 return uniqueCount;
183  
184 end
185  
186 ------------------------------------------------------------------------------
187 -- Player_Gear_GetItemLabel
188 ------------------------------------------------------------------------------
189  
190 function LT_Player_Gear_GetItemLabel(scroller, index)
191  
192 if (scroller.Data == nil) then
193 return "Unknown";
194 end
195  
196 local label, data = LT_GetItemLabel(scroller, scroller.Data.Gear, index, LT_Player_Gear_GetItemLabelWorker);
197 return label, data;
198  
199 end
200  
201  
202 ------------------------------------------------------------------------------
203 -- Player_Gear_GetItemLabelWorker
204 ------------------------------------------------------------------------------
205  
206 function LT_Player_Gear_GetItemLabelWorker(scroller, k, v)
207  
208 local item = v;
209  
210 local qualityColor = LT_QualityColors[tostring(item.Quality)];
211 local description = LT_ColorText(item.Name, qualityColor);
212  
213 return description, item.Name;
214  
215 end
216  
217  
218 ------------------------------------------------------------------------------
219 -- OnPlayerButtonClicked
220 ------------------------------------------------------------------------------
221  
222 function LT_OnPlayerButtonClicked(button)
223  
224 local name = button.Data;
225  
226 LT_DebugMessage(2, string.format("Clicked %s", name));
227  
228 local players = LT_GetPlayers();
229 local player = players[name];
230  
231 LT_SetPlayer(player);
232  
233 end