vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --===========================================================================-- |
2 | ---------------------------- LootTracker by PNB ---------------------------- |
||
3 | --===========================================================================-- |
||
4 | -- LootTrackerKillDetailsUI.lua |
||
5 | -- |
||
6 | -- Code behind the kill details UI |
||
7 | --===========================================================================-- |
||
8 | |||
9 | |||
10 | ------------------------------------------------------------------------------ |
||
11 | -- SetKill |
||
12 | ------------------------------------------------------------------------------ |
||
13 | |||
14 | function LT_SetKill(kill) |
||
15 | |||
16 | LT_DebugMessage(2, string.format("Viewing kill %s", kill.Name)); |
||
17 | |||
18 | LT_KillDetails:Show(); |
||
19 | LT_ItemDetails:Hide(); |
||
20 | LT_PlayerDetails:Hide(); |
||
21 | LT_SettingsFrame:Hide(); |
||
22 | |||
23 | local description = kill.Name; |
||
24 | description = description .. string.format("\nLevel %d", kill.Level); |
||
25 | --description = description .. string.format("\n%s %s %s", kill.Gender, kill.Race, kill.Class); |
||
26 | |||
27 | if (kill.TimesKilled ~= nil) then |
||
28 | local deaths = getn(kill.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_Kill_DescriptionText:SetText(description); |
||
37 | |||
38 | LT_Kill_RemoveDeathButton:Disable(); |
||
39 | |||
40 | local totalValue = 0; |
||
41 | if (kill.Drops ~= nil) then |
||
42 | local items = LT_GetItems(); |
||
43 | foreach(kill.Drops, function(k,v) |
||
44 | |||
45 | local item = items[k]; |
||
46 | if (item.Value) then |
||
47 | totalValue = totalValue + (item.Value * v); |
||
48 | end |
||
49 | |||
50 | end); |
||
51 | end |
||
52 | |||
53 | local averageValue = totalValue / getn(kill.TimesKilled); |
||
54 | |||
55 | local averageValueString = LT_GetValueString(averageValue, true); |
||
56 | LT_Kill_ValueText:SetText(averageValueString); |
||
57 | |||
58 | LT_Kill_DeathsList.Data = kill; |
||
59 | LT_Kill_DropsList.Data = kill; |
||
60 | LT_KillDetails.Data = kill; |
||
61 | |||
62 | LT_UpdateGenericScroller(LT_Kill_DeathsList); |
||
63 | LT_UpdateGenericScroller(LT_Kill_DropsList); |
||
64 | |||
65 | end |
||
66 | |||
67 | |||
68 | ------------------------------------------------------------------------------ |
||
69 | -- Kill_RemoveDeath |
||
70 | ------------------------------------------------------------------------------ |
||
71 | |||
72 | function LT_Kill_RemoveDeath() |
||
73 | |||
74 | LT_DebugMessage(1, "TODO: Remove the currently selected death entry"); |
||
75 | |||
76 | end |
||
77 | |||
78 | |||
79 | |||
80 | ------------------------------------------------------------------------------ |
||
81 | -- Kill_Drops_GetTotal |
||
82 | ------------------------------------------------------------------------------ |
||
83 | |||
84 | function LT_Kill_Drops_GetTotal(scroller) |
||
85 | |||
86 | if (scroller.Data == nil) then |
||
87 | LT_DebugMessage(1, "No kill: Unable to get Drops total"); |
||
88 | return 0; |
||
89 | end |
||
90 | |||
91 | if (scroller.Data.Drops == nil) then |
||
92 | LT_DebugMessage(1, "No drop list: Unable to get Drops total"); |
||
93 | return 0; |
||
94 | end |
||
95 | |||
96 | local uniqueCount = 0; |
||
97 | foreach(scroller.Data.Drops, function(k,v) |
||
98 | |||
99 | uniqueCount = uniqueCount + 1; |
||
100 | |||
101 | end); |
||
102 | |||
103 | local totalCount = getn(scroller.Data.TimesKilled); |
||
104 | |||
105 | scroller.TotalCount = totalCount; |
||
106 | |||
107 | return uniqueCount; |
||
108 | |||
109 | end |
||
110 | |||
111 | ------------------------------------------------------------------------------ |
||
112 | -- Kill_Drops_GetItemLabel |
||
113 | ------------------------------------------------------------------------------ |
||
114 | |||
115 | function LT_Kill_Drops_GetItemLabel(scroller, index) |
||
116 | |||
117 | if (scroller.Data == nil) then |
||
118 | return "Unknown"; |
||
119 | end |
||
120 | |||
121 | local label, data = LT_GetItemLabel(scroller, scroller.Data.Drops, index, LT_Kill_Drops_GetItemLabelWorker); |
||
122 | return label, data; |
||
123 | |||
124 | end |
||
125 | |||
126 | |||
127 | ------------------------------------------------------------------------------ |
||
128 | -- Kill_Drops_GetItemLabelWorker |
||
129 | ------------------------------------------------------------------------------ |
||
130 | |||
131 | function LT_Kill_Drops_GetItemLabelWorker(scroller, k, v) |
||
132 | |||
133 | local items = LT_GetItems(); |
||
134 | local item = items[k]; |
||
135 | |||
136 | local count = v; |
||
137 | local percentage = (count / scroller.TotalCount) * 100; |
||
138 | |||
139 | local qualityColor = LT_QualityColors[tostring(item.Quality)]; |
||
140 | local description = LT_ColorText(item.Name, qualityColor); |
||
141 | |||
142 | local label = string.format("%s: %d (%.2f%%)", description, count, percentage); |
||
143 | local data = item.Name; |
||
144 | |||
145 | return label, data; |
||
146 | |||
147 | end |
||
148 | |||
149 | |||
150 | ------------------------------------------------------------------------------ |
||
151 | -- Kill_Deaths_GetTotal |
||
152 | ------------------------------------------------------------------------------ |
||
153 | |||
154 | function LT_Kill_Deaths_GetTotal(scroller) |
||
155 | |||
156 | if (scroller.Data == nil) then |
||
157 | LT_DebugMessage(1, "No kill: Unable to get Deaths total"); |
||
158 | return 0; |
||
159 | end |
||
160 | |||
161 | if (scroller.Data.TimesKilled == nil) then |
||
162 | LT_DebugMessage(1, "No death list: Unable to get Deaths total"); |
||
163 | return 0; |
||
164 | end |
||
165 | |||
166 | local uniqueCount = 0; |
||
167 | local totalCount = 0; |
||
168 | foreach(scroller.Data.TimesKilled, function(k,v) |
||
169 | |||
170 | uniqueCount = uniqueCount + 1; |
||
171 | |||
172 | end); |
||
173 | |||
174 | scroller.TotalCount = uniqueCount; |
||
175 | |||
176 | return uniqueCount; |
||
177 | |||
178 | end |
||
179 | |||
180 | ------------------------------------------------------------------------------ |
||
181 | -- Kill_Deaths_GetItemLabel |
||
182 | ------------------------------------------------------------------------------ |
||
183 | |||
184 | function LT_Kill_Deaths_GetItemLabel(scroller, index) |
||
185 | |||
186 | if (scroller.Data == nil) then |
||
187 | return "Unknown"; |
||
188 | end |
||
189 | |||
190 | local label, data = LT_GetItemLabel(scroller, scroller.Data.TimesKilled, index, LT_Scroller_GetLabel); |
||
191 | return label, data; |
||
192 | |||
193 | end |
||
194 | |||
195 | |||
196 | ------------------------------------------------------------------------------ |
||
197 | -- OnKillButtonClicked |
||
198 | ------------------------------------------------------------------------------ |
||
199 | |||
200 | function LT_OnKillButtonClicked(button) |
||
201 | |||
202 | local name = button.Data; |
||
203 | |||
204 | local kills = LT_GetKills(); |
||
205 | local kill = kills[name]; |
||
206 | |||
207 | if (kill ~= nil) then |
||
208 | LT_SetKill(kill); |
||
209 | else |
||
210 | LT_DebugMessage(2, string.format("No kill found for name %s", name)); |
||
211 | end |
||
212 | |||
213 | end |
||
214 |