Mercurial > wow > turok
comparison Turok/Modules/Timer/Import.lua @ 6:a9b8b0866ece
clear out log jam
author | Nenue |
---|---|
date | Sun, 21 Feb 2016 08:32:53 -0500 |
parents | |
children | 9400a0ff8540 |
comparison
equal
deleted
inserted
replaced
5:8a9a6637f082 | 6:a9b8b0866ece |
---|---|
1 --- Turok - Import.lua | |
2 -- @file-author@ | |
3 -- @project-revision@ @project-hash@ | |
4 -- @file-revision@ @file-hash@ | |
5 -- Created: 1/4/2016 11:07 AM | |
6 -- Dialog interfaces and framework debugging tools; see the Google Doc | |
7 | |
8 local tconcat, unpack, pairs, ipairs, tostring, string = table.concat, unpack, pairs, ipairs, tostring, string | |
9 local BOOKTYPE_SPELL, GetSpellBookItemName, GetSpellBookItemInfo = BOOKTYPE_SPELL, GetSpellBookItemName, GetSpellBookItemInfo | |
10 local GetSpellTabInfo, GetNumSpellTabs, GetSpellInfo, GetFlyoutInfo, GetSpellDescription = GetSpellTabInfo, GetNumSpellTabs, GetSpellInfo, GetFlyoutInfo, GetSpellDescription | |
11 local GetFlyoutSlotInfo, GetSpellBaseCooldown, FindSpellBookSlotBySpellID, IsTalentSpell = GetFlyoutSlotInfo, GetSpellBaseCooldown, FindSpellBookSlotBySpellID, IsTalentSpell | |
12 local GetNumClasses, GetClassInfo, GetNumSpecializationsForClassID, GetSpecializationInfoForClassID | |
13 = GetNumClasses, GetClassInfo, GetNumSpecializationsForClassID, GetSpecializationInfoForClassID | |
14 local _G, setmetatable, type, T = _G, setmetatable, type, Turok | |
15 local mod = Turok.modules.TimerControl | |
16 mod.EditDialog = TkTimerConfig | |
17 mod.SelectDialog = {} | |
18 | |
19 local print = function(...) | |
20 if Devian and DevianDB.workspace ~= 1 then | |
21 print('Dialog', ...) | |
22 end | |
23 end | |
24 print('Peep!', ...) | |
25 local strpad = function(str, num) | |
26 return tostring(str) .. string.rep(' ', num - #tostring(str)) | |
27 end | |
28 | |
29 --- Handles mouse click on spellbook row frame | |
30 mod.SpellBook_Click = function(self, btn) | |
31 print('mouse', btn, self.spellID) | |
32 mod.Dialog_Select(mod.EditDialog, self.spellID) | |
33 end | |
34 | |
35 --- Creates the spell book import frame | |
36 -- | |
37 local cmd | |
38 function mod.Import_Open() | |
39 local self = mod | |
40 print('Spirit', 'SpecSpells') | |
41 local book_list = {} | |
42 local tab = {} | |
43 local list_info = {} | |
44 local book_max = 0 | |
45 for k = 1, GetNumSpellTabs() do | |
46 local name, texture, offset, numSpells = GetSpellTabInfo(k) | |
47 tab[offset] = {k, name, texture, numSpells} | |
48 print('Spirit', name, offset, numSpells) | |
49 book_max = offset + numSpells | |
50 end | |
51 local tabID, tabName, tabTexture | |
52 local flyout, spellflyout = {}, {} | |
53 for i = 1, book_max do | |
54 if tab[i] then | |
55 tabID, tabName, tabTexture = unpack(tab[i]) | |
56 end | |
57 | |
58 if book_list[i] == nil then | |
59 local skillType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_SPELL) | |
60 local spellNameUpper, spellSubText = GetSpellBookItemName(i, BOOKTYPE_SPELL) | |
61 local spellName, spellRank, spellTexture, castTime, minRange, maxRange = GetSpellInfo(spellID) | |
62 _G.print('Spirit', i, spellID, spellName) | |
63 _G.print('Spirit', ' ', skillType, spellSubText) | |
64 | |
65 local spellDesc | |
66 if skillType == 'FLYOUT' then | |
67 local numSlots | |
68 spellName, spellDesc, numSlots = GetFlyoutInfo(spellID) | |
69 print('flyout #'..spellID..':', spellName) | |
70 flyout[spellID] = {} | |
71 for i=1, numSlots do | |
72 local fspellID, _, isKnown, fSpellName, fSpellValue = GetFlyoutSlotInfo(spellID, i) | |
73 print(' spell #', fspellID, fSpellName, isKnown) | |
74 if isKnown then | |
75 flyout[spellID][i] = fspellID | |
76 spellflyout[fspellID] = spellID | |
77 end | |
78 end | |
79 | |
80 else | |
81 spellDesc = GetSpellDescription(spellID) | |
82 end | |
83 | |
84 book_list[i] = { | |
85 skillType = skillType, | |
86 spellIndex = i, | |
87 spellID = spellID, | |
88 spellName = spellName, | |
89 spellDesc = spellDesc, | |
90 spellNameUpper = spellNameUpper, | |
91 spellSubText = spellSubText, | |
92 spellTexture = spellTexture, | |
93 spellCooldown = GetSpellBaseCooldown(spellID), | |
94 castTime = castTime, | |
95 minRange = minRange, | |
96 maxRange = maxRange, | |
97 tabID = tabID, | |
98 tabName = tabName, | |
99 tabTexture = tabTexture | |
100 } | |
101 | |
102 | |
103 | |
104 end | |
105 end | |
106 | |
107 local selector = CreateFrame('Frame', 'TkSpellSelector', UIParent, 'TurokListFrame') | |
108 self.frames.selector = selector | |
109 selector.name:SetText("Spells") | |
110 selector:SetPoint('TOP') | |
111 selector.page = 1 | |
112 | |
113 selector.GetRow = function(row, info, id, item_num) | |
114 print(' ', row:GetName(), info, id, item_num) | |
115 if not row.opts then | |
116 row.opts = { | |
117 CreateFrame('CheckButton', 'TkCheck_'..item_num, row, 'TurokCheckButtonInline'), | |
118 row:CreateFontString('TextItem_'..item_num, 'OVERLAY', 'TurokFontDetail'), | |
119 row:CreateTexture(nil, 'OVERLAY'), | |
120 row:CreateTexture(nil, 'OVERLAY'), | |
121 row:CreateFontString('TextItem_'..item_num..'ID', 'OVERLAY', 'TurokFontDetail'), | |
122 } | |
123 end | |
124 local page = book_list[id] | |
125 if page.skillType == 'FLYOUT' then | |
126 row.background:SetTexture(1,.2,.3,.4) | |
127 | |
128 elseif rawget(mod.frames.spellID, page.spellID) then | |
129 print('has timer frame under spell #', page.spellID, mod.frames.spellID[page.spellID]) | |
130 row.background:SetTexture(1,1,0,1) | |
131 local timer = mod.frames.spellID[page.spellID] | |
132 row:SetScript('OnMouseDown', function(self) self.clicked = true end) | |
133 row:SetScript('OnMouseUp', function(self) if self.clicked then self.clicked = nil mod.Dialog_Select(mod.Editor, timer.timerName) end end) | |
134 elseif page.spellCooldown and page.spellCooldown > 0 then | |
135 row.background:SetTexture(.3,.6,1,1) | |
136 else | |
137 row.background:SetTexture(0,0,0,0.3) | |
138 end | |
139 | |
140 row:SetScript('OnMouseDown', mod.SpellBook_Click) | |
141 | |
142 row.desc = page.spellDesc | |
143 row.spellID = page.spellID | |
144 row.opts[1].desc = page.skillType | |
145 row.opts[1]:SetSize(20,20) | |
146 row.opts[1].description:SetText(nil) | |
147 row.opts[1]:SetChecked(page.checked) | |
148 row.opts[2]:SetText(page.spellName) | |
149 row.opts[2]:SetWidth(200) | |
150 row.opts[2]:SetJustifyH('LEFT') | |
151 row.opts[3]:SetSize(20,20) | |
152 row.opts[3]:SetTexture(page.spellTexture) | |
153 row.opts[3]:SetPoint('CENTER') | |
154 row.opts[4]:SetSize(20,20) | |
155 row.opts[4]:SetTexture(page.tabTexture) | |
156 row.opts[4]:SetPoint('CENTER') | |
157 row.opts[5]:SetWidth(60) | |
158 row.opts[5]:SetJustifyH('LEFT') | |
159 row.opts[5]:SetText(page.spellID) | |
160 end | |
161 | |
162 selector.Click = function(button, list) | |
163 local b = button:GetName():match("_(%a+)$") | |
164 if b == 'Prev' then | |
165 --print(b, list.offset, list.num_rows) | |
166 if list.page > 1 then | |
167 list.page = list.page - 1 | |
168 TkList_SetView(list, list.num_rows * (list.page-1) + 1) | |
169 end | |
170 list.pagenum:SetText(list.page) | |
171 elseif b == 'Next' then | |
172 --print(' ',list.page, list.num_rows, list.max_row) | |
173 if (list.page) * list.num_rows < list.max_row then | |
174 list.page = list.page + 1 | |
175 TkList_SetView(list, list.offset + list.num_rows) | |
176 end | |
177 list.pagenum:SetText(list.page) | |
178 | |
179 elseif b == 'Add' then | |
180 mod.CommitBook(book_list, tab, list_info) | |
181 end | |
182 --print(list.page, list.offset, list.num_rows) | |
183 end | |
184 | |
185 selector.Wheel = function(self, delta) | |
186 local offset = self.offset - delta | |
187 if offset > 0 and offset <= (self.max_row - self.num_rows) then | |
188 TkList_SetView(self, offset) | |
189 end | |
190 end | |
191 | |
192 selector.Check = function(checkbutton, row, list) | |
193 local index = checkbutton:GetParent().actual_row | |
194 book_list[index].checked = (not book_list[index].checked) and true or false | |
195 checkbutton:SetChecked(book_list[index].checked) | |
196 | |
197 if book_list[index].skillType == 'FLYOUT' then | |
198 for slot, spellID in pairs(flyout[book_list[index].spellID]) do | |
199 | |
200 local spIndex = FindSpellBookSlotBySpellID(spellID) | |
201 print(' also toggling', slot, spellID, ' book slot', spIndex, book_list[spIndex].spellName) | |
202 book_list[spIndex].checked = book_list[index].checked | |
203 end | |
204 TkList_SetView(list, list.offset) | |
205 end | |
206 end | |
207 TkList_Init(selector, book_list, 1, 12) | |
208 selector:Show() | |
209 mod.SelectDialog = selector | |
210 end | |
211 --@end-debug@ | |
212 | |
213 | |
214 function mod.CommitBook(bookInfo, tabInfo, uiInfo) | |
215 print('committing') | |
216 print(' book data: ', #bookInfo, 'entries') | |
217 print(' tab data: ', #tabInfo, 'entries') | |
218 | |
219 for index, e in ipairs(bookInfo) do | |
220 if e.checked then | |
221 local spellPretext = '' | |
222 if IsTalentSpell(index) then | |
223 spellPretext = 'Talent' | |
224 end | |
225 print(' ', strpad(spellPretext .. e.spellName, 20)) | |
226 print(' ', strpad(e.spellSubText, 10), strpad(e.spellCooldown,5), strpad(e.skillType,6)) | |
227 | |
228 end | |
229 end | |
230 end | |
231 | |
232 | |
233 | |
234 | |
235 --- /tki command | |
236 -- Constructs an index that associates global spec ID's with a list of the timers that would display under it. | |
237 -- List entries are stored as [name] = true to prevent duplication of values in SavedVariables. | |
238 | |
239 function mod:CreateIndex() | |
240 | |
241 --@debug@ Revert config to defaults | |
242 _G.TurokData = T.defaults | |
243 --@end-debug@ | |
244 | |
245 mod.db.timerindex = {} | |
246 setmetatable(mod.db.timerindex, {__mode = "v"}) -- ensure that dead leafs fall off | |
247 local index = mod.index | |
248 local timers = mod.timersByName | |
249 | |
250 -- build class info hash and create subtables | |
251 local classID = {} | |
252 local className = {} | |
253 local specIDPage = {} | |
254 local specPageID = {} | |
255 local classSpecs = {} | |
256 print('|cFF0088FFCreateIndex|r') | |
257 | |
258 --- use the internal class/specialization list | |
259 for i = 1, GetNumClasses() do | |
260 local _, tag, id = GetClassInfo(i) | |
261 classID[tag] = id | |
262 className[id] = tag | |
263 index[id] = {} | |
264 specPageID[tag] = {} | |
265 index[tag] = index[id] | |
266 | |
267 classSpecs[tag] = GetNumSpecializationsForClassID(id) | |
268 for j = 1, classSpecs[tag] do | |
269 local specID, specName = GetSpecializationInfoForClassID(id, j) | |
270 print('|cFFFF0088map:|r', tag, j, specID, specName) | |
271 specIDPage[specID] = j | |
272 specPageID[tag][j] = specID | |
273 index[specID] = {} | |
274 index[id][j] = {} | |
275 end | |
276 end | |
277 index.global = {} | |
278 | |
279 for name,timer in pairs(timers) do | |
280 -- class is set | |
281 if type(timer) == 'table' then | |
282 print(name) | |
283 if timer.playerClass then | |
284 | |
285 index[timer.playerClass][name] = true | |
286 | |
287 -- spec restricted | |
288 if timer.specPage then | |
289 if type(timer.specPage) ~= 'table' then | |
290 -- fix it up | |
291 timer.specPage = {timer.specPage } | |
292 end | |
293 | |
294 print(' |cFFFFFF00class:|r', timer.playerClass .. ', |cFF99FF00spec:|r '.. tconcat(timer.specPage,', ')) | |
295 for _, specPage in ipairs(timer.specPage) do | |
296 index[timer.playerClass][specPage][name] = true | |
297 index[specPageID[timer.playerClass][specPage]][name] = true | |
298 end | |
299 | |
300 -- no spec restriction, copy it out | |
301 elseif not timer.specID then | |
302 print(' |cFFFFFF00class:|r', timer.playerClass .. ', |cFF99FF00spec:|r ALL') | |
303 for i = 1, classSpecs[timer.playerClass] do | |
304 local specID = specPageID[timer.playerClass][i] | |
305 | |
306 index[timer.playerClass][i][name] = true -- store for local ID | |
307 index[specID][name] = true -- store for global ID | |
308 end | |
309 end | |
310 end | |
311 | |
312 if timer.specID then | |
313 index[timer.specID][name] = true | |
314 end | |
315 | |
316 if not (timer.playerClass or timer.specID or timer.specPage) then | |
317 for tag, id in pairs(classID) do | |
318 index[tag][name] = true | |
319 for specPage, specID in pairs(specPageID[tag]) do | |
320 index[tag][specPage][name] = true | |
321 index[specID][name] = true | |
322 end | |
323 end | |
324 print(' |cFFFFFF00class:|r ALL, |cFF99FF00spec:|r ALL') | |
325 end | |
326 end | |
327 end | |
328 | |
329 _G.TurokData.timerindex = index | |
330 T:Print('Hive data updated. /rl to commit.') | |
331 end |