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