Nenue@6: --- Turok - Import.lua Nenue@6: -- @file-author@ Nenue@6: -- @project-revision@ @project-hash@ Nenue@6: -- @file-revision@ @file-hash@ Nenue@6: -- Created: 1/4/2016 11:07 AM Nenue@6: -- Dialog interfaces and framework debugging tools; see the Google Doc Nenue@6: Nenue@6: local tconcat, unpack, pairs, ipairs, tostring, string = table.concat, unpack, pairs, ipairs, tostring, string Nenue@6: local BOOKTYPE_SPELL, GetSpellBookItemName, GetSpellBookItemInfo = BOOKTYPE_SPELL, GetSpellBookItemName, GetSpellBookItemInfo Nenue@6: local GetSpellTabInfo, GetNumSpellTabs, GetSpellInfo, GetFlyoutInfo, GetSpellDescription = GetSpellTabInfo, GetNumSpellTabs, GetSpellInfo, GetFlyoutInfo, GetSpellDescription Nenue@6: local GetFlyoutSlotInfo, GetSpellBaseCooldown, FindSpellBookSlotBySpellID, IsTalentSpell = GetFlyoutSlotInfo, GetSpellBaseCooldown, FindSpellBookSlotBySpellID, IsTalentSpell Nenue@6: local GetNumClasses, GetClassInfo, GetNumSpecializationsForClassID, GetSpecializationInfoForClassID Nenue@6: = GetNumClasses, GetClassInfo, GetNumSpecializationsForClassID, GetSpecializationInfoForClassID Nenue@6: local _G, setmetatable, type, T = _G, setmetatable, type, Turok Nenue@6: local mod = Turok.modules.TimerControl Nenue@6: mod.EditDialog = TkTimerConfig Nenue@6: mod.SelectDialog = {} Nenue@6: Nenue@6: local print = function(...) Nenue@6: if Devian and DevianDB.workspace ~= 1 then Nenue@6: print('Dialog', ...) Nenue@6: end Nenue@6: end Nenue@6: local strpad = function(str, num) Nenue@6: return tostring(str) .. string.rep(' ', num - #tostring(str)) Nenue@6: end Nenue@6: Nenue@6: --- Handles mouse click on spellbook row frame Nenue@6: mod.SpellBook_Click = function(self, btn) Nenue@6: print('mouse', btn, self.spellID) Nenue@6: mod.Dialog_Select(mod.EditDialog, self.spellID) Nenue@6: end Nenue@6: Nenue@6: --- Creates the spell book import frame Nenue@6: -- Nenue@6: local cmd Nenue@6: function mod.Import_Open() Nenue@6: local self = mod Nenue@6: print('Spirit', 'SpecSpells') Nenue@6: local book_list = {} Nenue@6: local tab = {} Nenue@6: local list_info = {} Nenue@6: local book_max = 0 Nenue@6: for k = 1, GetNumSpellTabs() do Nenue@6: local name, texture, offset, numSpells = GetSpellTabInfo(k) Nenue@6: tab[offset] = {k, name, texture, numSpells} Nenue@6: print('Spirit', name, offset, numSpells) Nenue@6: book_max = offset + numSpells Nenue@6: end Nenue@6: local tabID, tabName, tabTexture Nenue@6: local flyout, spellflyout = {}, {} Nenue@6: for i = 1, book_max do Nenue@6: if tab[i] then Nenue@6: tabID, tabName, tabTexture = unpack(tab[i]) Nenue@6: end Nenue@6: Nenue@6: if book_list[i] == nil then Nenue@6: local skillType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_SPELL) Nenue@6: local spellNameUpper, spellSubText = GetSpellBookItemName(i, BOOKTYPE_SPELL) Nenue@6: local spellName, spellRank, spellTexture, castTime, minRange, maxRange = GetSpellInfo(spellID) Nenue@6: _G.print('Spirit', i, spellID, spellName) Nenue@6: _G.print('Spirit', ' ', skillType, spellSubText) Nenue@6: Nenue@6: local spellDesc Nenue@6: if skillType == 'FLYOUT' then Nenue@6: local numSlots Nenue@6: spellName, spellDesc, numSlots = GetFlyoutInfo(spellID) Nenue@6: print('flyout #'..spellID..':', spellName) Nenue@6: flyout[spellID] = {} Nenue@6: for i=1, numSlots do Nenue@6: local fspellID, _, isKnown, fSpellName, fSpellValue = GetFlyoutSlotInfo(spellID, i) Nenue@6: print(' spell #', fspellID, fSpellName, isKnown) Nenue@6: if isKnown then Nenue@6: flyout[spellID][i] = fspellID Nenue@6: spellflyout[fspellID] = spellID Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: else Nenue@6: spellDesc = GetSpellDescription(spellID) Nenue@6: end Nenue@6: Nenue@6: book_list[i] = { Nenue@6: skillType = skillType, Nenue@6: spellIndex = i, Nenue@6: spellID = spellID, Nenue@6: spellName = spellName, Nenue@6: spellDesc = spellDesc, Nenue@6: spellNameUpper = spellNameUpper, Nenue@6: spellSubText = spellSubText, Nenue@6: spellTexture = spellTexture, Nenue@6: spellCooldown = GetSpellBaseCooldown(spellID), Nenue@6: castTime = castTime, Nenue@6: minRange = minRange, Nenue@6: maxRange = maxRange, Nenue@6: tabID = tabID, Nenue@6: tabName = tabName, Nenue@6: tabTexture = tabTexture Nenue@6: } Nenue@6: Nenue@6: Nenue@6: Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: local selector = CreateFrame('Frame', 'TkSpellSelector', UIParent, 'TurokListFrame') Nenue@6: self.frames.selector = selector Nenue@6: selector.name:SetText("Spells") Nenue@6: selector:SetPoint('TOP') Nenue@6: selector.page = 1 Nenue@6: Nenue@6: selector.GetRow = function(row, info, id, item_num) Nenue@6: print(' ', row:GetName(), info, id, item_num) Nenue@6: if not row.opts then Nenue@6: row.opts = { Nenue@6: CreateFrame('CheckButton', 'TkCheck_'..item_num, row, 'TurokCheckButtonInline'), Nenue@6: row:CreateFontString('TextItem_'..item_num, 'OVERLAY', 'TurokFontDetail'), Nenue@6: row:CreateTexture(nil, 'OVERLAY'), Nenue@6: row:CreateTexture(nil, 'OVERLAY'), Nenue@6: row:CreateFontString('TextItem_'..item_num..'ID', 'OVERLAY', 'TurokFontDetail'), Nenue@6: } Nenue@6: end Nenue@6: local page = book_list[id] Nenue@6: if page.skillType == 'FLYOUT' then Nenue@6: row.background:SetTexture(1,.2,.3,.4) Nenue@6: Nenue@6: elseif rawget(mod.frames.spellID, page.spellID) then Nenue@6: print('has timer frame under spell #', page.spellID, mod.frames.spellID[page.spellID]) Nenue@6: row.background:SetTexture(1,1,0,1) Nenue@6: local timer = mod.frames.spellID[page.spellID] Nenue@6: row:SetScript('OnMouseDown', function(self) self.clicked = true end) Nenue@6: row:SetScript('OnMouseUp', function(self) if self.clicked then self.clicked = nil mod.Dialog_Select(mod.Editor, timer.timerName) end end) Nenue@6: elseif page.spellCooldown and page.spellCooldown > 0 then Nenue@6: row.background:SetTexture(.3,.6,1,1) Nenue@6: else Nenue@6: row.background:SetTexture(0,0,0,0.3) Nenue@6: end Nenue@6: Nenue@6: row:SetScript('OnMouseDown', mod.SpellBook_Click) Nenue@6: Nenue@6: row.desc = page.spellDesc Nenue@6: row.spellID = page.spellID Nenue@6: row.opts[1].desc = page.skillType Nenue@6: row.opts[1]:SetSize(20,20) Nenue@6: row.opts[1].description:SetText(nil) Nenue@6: row.opts[1]:SetChecked(page.checked) Nenue@6: row.opts[2]:SetText(page.spellName) Nenue@6: row.opts[2]:SetWidth(200) Nenue@6: row.opts[2]:SetJustifyH('LEFT') Nenue@6: row.opts[3]:SetSize(20,20) Nenue@6: row.opts[3]:SetTexture(page.spellTexture) Nenue@6: row.opts[3]:SetPoint('CENTER') Nenue@6: row.opts[4]:SetSize(20,20) Nenue@6: row.opts[4]:SetTexture(page.tabTexture) Nenue@6: row.opts[4]:SetPoint('CENTER') Nenue@6: row.opts[5]:SetWidth(60) Nenue@6: row.opts[5]:SetJustifyH('LEFT') Nenue@6: row.opts[5]:SetText(page.spellID) Nenue@6: end Nenue@6: Nenue@6: selector.Click = function(button, list) Nenue@6: local b = button:GetName():match("_(%a+)$") Nenue@6: if b == 'Prev' then Nenue@6: --print(b, list.offset, list.num_rows) Nenue@6: if list.page > 1 then Nenue@6: list.page = list.page - 1 Nenue@6: TkList_SetView(list, list.num_rows * (list.page-1) + 1) Nenue@6: end Nenue@6: list.pagenum:SetText(list.page) Nenue@6: elseif b == 'Next' then Nenue@6: --print(' ',list.page, list.num_rows, list.max_row) Nenue@6: if (list.page) * list.num_rows < list.max_row then Nenue@6: list.page = list.page + 1 Nenue@6: TkList_SetView(list, list.offset + list.num_rows) Nenue@6: end Nenue@6: list.pagenum:SetText(list.page) Nenue@6: Nenue@6: elseif b == 'Add' then Nenue@6: mod.CommitBook(book_list, tab, list_info) Nenue@6: end Nenue@6: --print(list.page, list.offset, list.num_rows) Nenue@6: end Nenue@6: Nenue@6: selector.Wheel = function(self, delta) Nenue@6: local offset = self.offset - delta Nenue@6: if offset > 0 and offset <= (self.max_row - self.num_rows) then Nenue@6: TkList_SetView(self, offset) Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: selector.Check = function(checkbutton, row, list) Nenue@6: local index = checkbutton:GetParent().actual_row Nenue@6: book_list[index].checked = (not book_list[index].checked) and true or false Nenue@6: checkbutton:SetChecked(book_list[index].checked) Nenue@6: Nenue@6: if book_list[index].skillType == 'FLYOUT' then Nenue@6: for slot, spellID in pairs(flyout[book_list[index].spellID]) do Nenue@6: Nenue@6: local spIndex = FindSpellBookSlotBySpellID(spellID) Nenue@6: print(' also toggling', slot, spellID, ' book slot', spIndex, book_list[spIndex].spellName) Nenue@6: book_list[spIndex].checked = book_list[index].checked Nenue@6: end Nenue@6: TkList_SetView(list, list.offset) Nenue@6: end Nenue@6: end Nenue@6: TkList_Init(selector, book_list, 1, 12) Nenue@6: selector:Show() Nenue@6: mod.SelectDialog = selector Nenue@6: end Nenue@6: --@end-debug@ Nenue@6: Nenue@6: Nenue@6: function mod.CommitBook(bookInfo, tabInfo, uiInfo) Nenue@6: print('committing') Nenue@6: print(' book data: ', #bookInfo, 'entries') Nenue@6: print(' tab data: ', #tabInfo, 'entries') Nenue@6: Nenue@6: for index, e in ipairs(bookInfo) do Nenue@6: if e.checked then Nenue@6: local spellPretext = '' Nenue@6: if IsTalentSpell(index) then Nenue@6: spellPretext = 'Talent' Nenue@6: end Nenue@6: print(' ', strpad(spellPretext .. e.spellName, 20)) Nenue@6: print(' ', strpad(e.spellSubText, 10), strpad(e.spellCooldown,5), strpad(e.skillType,6)) Nenue@6: Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: Nenue@6: Nenue@6: Nenue@6: --- /tki command Nenue@6: -- Constructs an index that associates global spec ID's with a list of the timers that would display under it. Nenue@6: -- List entries are stored as [name] = true to prevent duplication of values in SavedVariables. Nenue@6: Nenue@6: function mod:CreateIndex() Nenue@6: Nenue@6: --@debug@ Revert config to defaults Nenue@6: _G.TurokData = T.defaults Nenue@6: --@end-debug@ Nenue@6: Nenue@6: mod.db.timerindex = {} Nenue@6: setmetatable(mod.db.timerindex, {__mode = "v"}) -- ensure that dead leafs fall off Nenue@6: local index = mod.index Nenue@6: local timers = mod.timersByName Nenue@6: Nenue@6: -- build class info hash and create subtables Nenue@6: local classID = {} Nenue@6: local className = {} Nenue@6: local specIDPage = {} Nenue@6: local specPageID = {} Nenue@6: local classSpecs = {} Nenue@6: print('|cFF0088FFCreateIndex|r') Nenue@6: Nenue@6: --- use the internal class/specialization list Nenue@6: for i = 1, GetNumClasses() do Nenue@6: local _, tag, id = GetClassInfo(i) Nenue@6: classID[tag] = id Nenue@6: className[id] = tag Nenue@6: index[id] = {} Nenue@6: specPageID[tag] = {} Nenue@6: index[tag] = index[id] Nenue@6: Nenue@6: classSpecs[tag] = GetNumSpecializationsForClassID(id) Nenue@6: for j = 1, classSpecs[tag] do Nenue@6: local specID, specName = GetSpecializationInfoForClassID(id, j) Nenue@6: print('|cFFFF0088map:|r', tag, j, specID, specName) Nenue@6: specIDPage[specID] = j Nenue@6: specPageID[tag][j] = specID Nenue@6: index[specID] = {} Nenue@6: index[id][j] = {} Nenue@6: end Nenue@6: end Nenue@6: index.global = {} Nenue@6: Nenue@6: for name,timer in pairs(timers) do Nenue@6: -- class is set Nenue@6: if type(timer) == 'table' then Nenue@6: print(name) Nenue@6: if timer.playerClass then Nenue@6: Nenue@6: index[timer.playerClass][name] = true Nenue@6: Nenue@6: -- spec restricted Nenue@6: if timer.specPage then Nenue@6: if type(timer.specPage) ~= 'table' then Nenue@6: -- fix it up Nenue@6: timer.specPage = {timer.specPage } Nenue@6: end Nenue@6: Nenue@6: print(' |cFFFFFF00class:|r', timer.playerClass .. ', |cFF99FF00spec:|r '.. tconcat(timer.specPage,', ')) Nenue@6: for _, specPage in ipairs(timer.specPage) do Nenue@6: index[timer.playerClass][specPage][name] = true Nenue@6: index[specPageID[timer.playerClass][specPage]][name] = true Nenue@6: end Nenue@6: Nenue@6: -- no spec restriction, copy it out Nenue@6: elseif not timer.specID then Nenue@6: print(' |cFFFFFF00class:|r', timer.playerClass .. ', |cFF99FF00spec:|r ALL') Nenue@6: for i = 1, classSpecs[timer.playerClass] do Nenue@6: local specID = specPageID[timer.playerClass][i] Nenue@6: Nenue@6: index[timer.playerClass][i][name] = true -- store for local ID Nenue@6: index[specID][name] = true -- store for global ID Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: if timer.specID then Nenue@6: index[timer.specID][name] = true Nenue@6: end Nenue@6: Nenue@6: if not (timer.playerClass or timer.specID or timer.specPage) then Nenue@6: for tag, id in pairs(classID) do Nenue@6: index[tag][name] = true Nenue@6: for specPage, specID in pairs(specPageID[tag]) do Nenue@6: index[tag][specPage][name] = true Nenue@6: index[specID][name] = true Nenue@6: end Nenue@6: end Nenue@6: print(' |cFFFFFF00class:|r ALL, |cFF99FF00spec:|r ALL') Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: _G.TurokData.timerindex = index Nenue@6: T:Print('Hive data updated. /rl to commit.') Nenue@6: end