Nenue@6: --- Modules Nenue@6: -- @file-author@ Nenue@6: -- @project-revision@ @project-hash@ Nenue@6: -- @file-revision@ @file-hash@ Nenue@6: -- Created: 1/18/2016 3:33 PM Nenue@6: local _G = _G Nenue@6: local T, type, pairs = _G.Turok, type, pairs Nenue@6: local mod = T.modules.TimerControl Nenue@6: local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool 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: print('Peep!', ...) Nenue@6: Nenue@6: Nenue@6: local TimerConfig = { Nenue@6: conf = { Nenue@6: padding = 4, Nenue@6: spacing = 1, Nenue@6: width = 450, Nenue@6: }, Nenue@6: info = { Nenue@6: { key = 'timerName', Nenue@6: desc = 'Unique Name:', Nenue@6: type='EditBox', name = 'timerName', fill=true, Nenue@6: line = true, Nenue@6: }, Nenue@6: { key = 'spellEnable', Nenue@6: inherits = 'TurokCheckButtonOverlay', Nenue@6: type='CheckButton', name = 'spellEnable', fixed=25, point='LEFT', Nenue@6: get = Dialog_Boolean, getarg = 'spellID', Nenue@6: collapse = true, Nenue@6: desc = 'Spell Name', Nenue@6: }, Nenue@6: { key = 'spellID', Nenue@6: type='EditBox', name = 'spellName', Nenue@6: line = true, float = true Nenue@6: }, Nenue@6: { key = 'fill_inverse', Nenue@6: desc = 'Reverse Fill', Nenue@6: type='CheckButton', name='fillInverse', fixed=25, point='LEFT', Nenue@6: get = Dialog_Boolean, getarg = 'fill_inverse', text='Inverted Fill', Nenue@6: line = true, Nenue@6: }, Nenue@6: { key = 'display', Nenue@6: desc = 'Display Type', Nenue@6: type='EditBox', name='displayType', Nenue@6: line = true, Nenue@6: }, Nenue@6: }, Nenue@6: } Nenue@6: Nenue@6: local Dialog_SetField = {} Nenue@6: local dget = function(name, key) Nenue@6: if mod.db.timers[name] then Nenue@6: return mod.db.timers[name][key] Nenue@6: end Nenue@6: return nil Nenue@6: end Nenue@6: local inherits = { Nenue@6: EditBox = 'TkEditBox', Nenue@6: CheckButton = 'TurokCheckButtonInline', Nenue@6: Slider = 'TkSlider', Nenue@6: } Nenue@6: Nenue@6: Dialog_SetField['CheckButton'] = function(self, checked) self:SetChecked(checked) end Nenue@6: Dialog_SetField['EditBox'] = function(self, text) Nenue@6: print(' ', cKey(self:GetName()), text) Nenue@6: self:SetText(text or '') end Nenue@6: Dialog_SetField['Button'] = function(self, text) self:SetText(text) end Nenue@6: Nenue@6: Nenue@6: local function Dialog_Boolean(name, key) Nenue@6: print(' Dialog_Boolean', name, key) Nenue@6: return (mod.db.timers[name][key] and true or false) Nenue@6: end Nenue@6: Nenue@6: function mod.Dialog_Select(self, key) Nenue@6: local timer Nenue@6: if self.parent_values[key] then Nenue@6: print('matched timer name', key) Nenue@6: timer = self.parent_values[key] Nenue@6: elseif rawget(mod.frames.spellID, key) then Nenue@6: print('matched spellID', key) Nenue@6: timer = mod.frames.spellID[key][1] Nenue@6: for k,v in pairs(timer) do Nenue@6: print(' -', k, '=', v) Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: if timer then Nenue@6: self.values = timer Nenue@6: self.timerName = timer.timerName Nenue@6: else Nenue@6: self.values = { Nenue@6: timerName = 'New Timer' Nenue@6: } Nenue@6: self.timerName = 'New Timer' Nenue@6: end Nenue@6: mod.Dialog_Init(self, TimerConfig.conf, TimerConfig.info) Nenue@6: end Nenue@6: Nenue@6: function mod.Dialog_Init(self, dconf, dinfo) Nenue@6: print('init,', self.values.timerName) Nenue@6: Nenue@6: if not self.fields then Nenue@6: self.fields = {} Nenue@6: self.rows = {} Nenue@6: self.Click = mod.Dialog_Click Nenue@6: self.Check = mod.Dialog_Check Nenue@6: self.EditBox = mod.Dialog_EditBox Nenue@6: end Nenue@6: print(self.name, self.timerName) Nenue@6: self.name:SetText(self.timerName) Nenue@6: Nenue@6: local inset = dconf.padding + dconf.spacing Nenue@6: -- frame X max Nenue@6: local fX = 0 Nenue@6: -- row number, row Y offset Nenue@6: local rn, ry = 1, -34 Nenue@6: -- row x offset left-align, row x offset right-aligned, largest collapsed element Nenue@6: local rxL, rxR, rC, rh = dconf.spacing, dconf.spacing, 0, 0 Nenue@6: for i, opt in ipairs(dinfo) do Nenue@6: if not self.rows[rn] then Nenue@6: self.rows[rn] = CreateFrame('Frame', self:GetName()..'Row'..rn, self, 'TurokDialogRow') Nenue@6: end Nenue@6: Nenue@6: local k = opt.key Nenue@6: if self.fields[i] == nil then Nenue@6: self.fields[i] = CreateFrame(opt.type, self:GetName()..opt.name, self.rows[rn], opt.inherits or inherits[opt.type]) Nenue@6: self.fields[i].index = i Nenue@6: self.fields[i].key = k Nenue@6: -- row point (from), row point (to), row x offset Nenue@6: local rp, rpt, rx Nenue@6: -- row delta Nenue@6: local rd Nenue@6: if opt.fill then Nenue@6: rpt = opt.float and 'BOTTOMLEFT' or 'BOTTOMRIGHT' Nenue@6: -- row point X offset Nenue@6: local rpx = opt.float and dconf.spacing or -dconf.spacing Nenue@6: self.fields[i]:SetPoint(rpt, self.rows[rn], rpt, rpx, 0) Nenue@6: print(' fill:', rpt, '-', rpt,' :: ', rpx, 0) Nenue@6: rd = 0 Nenue@6: else Nenue@6: rd = self.fields[i]:GetWidth() + dconf.spacing Nenue@6: end Nenue@6: if opt.float then Nenue@6: rp = 'BOTTOMRIGHT' Nenue@6: rx = -rxR Nenue@6: rxR = rxR + rd Nenue@6: elseif opt.collapse then Nenue@6: rp = 'BOTTOMLEFT' Nenue@6: rx = dconf.spacing Nenue@6: rC = math.max(rC, rd + dconf.spacing) -- spacing L + rd{width + spacing R} Nenue@6: else Nenue@6: rp = 'BOTTOMLEFT' Nenue@6: rx = rxL Nenue@6: rxL = rxL + rd Nenue@6: end Nenue@6: Nenue@6: rh = math.max(rh, self.fields[i]:GetHeight()) Nenue@6: self.fields[i]:SetPoint(rp, self.rows[rn], rp, rx, dconf.spacing) Nenue@6: print(' align:', rp, '-', rp, ' :: ', rx, 0) Nenue@6: print(' dR:', cNum(rd), 'nR:',cWord(rn), 'rX:', cNum(rx), 'i:', cText(i)) Nenue@6: Nenue@6: if opt.line or (not dinfo[i+1]) then Nenue@6: print(cText'nR:', cNum(rn), 'rY:', cNum(ry)) Nenue@6: self.rows[rn]:ClearAllPoints() Nenue@6: self.rows[rn]:SetPoint('TOPLEFT', self, 'TOPLEFT', dconf.padding, ry) Nenue@6: self.rows[rn]:SetPoint('TOPRIGHT', self, 'TOPRIGHT', -dconf.padding, ry) Nenue@6: self.rows[rn]:SetHeight(rh + dconf.spacing*2) Nenue@6: self.rows[rn]:Show() Nenue@6: rn = rn + 1 Nenue@6: ry = ry - (rh + dconf.spacing*3) -->| {spacing T + rh + spacing B} + spacing dR |<-- Nenue@6: Nenue@6: print('fX:',cNum(fX), 'rX:', cNum(rxL+rxR+dconf.spacing), 'rC:', cNum(rC)) Nenue@6: fX = math.max(fX, rxL+rxR+dconf.spacing) Nenue@6: fX = math.max(fX, rC) Nenue@6: rxL, rxR = dconf.spacing, dconf.spacing Nenue@6: rh = 0 Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: self.fields[i]:Show() Nenue@6: if opt.desc and self.fields[i].description then Nenue@6: self.fields[i].description:SetText(opt.desc) Nenue@6: end Nenue@6: Dialog_SetField[opt.type](self.fields[i], opt.get and opt.get(self.values.timerName, opt.getarg) or self.values[k]) Nenue@6: Nenue@6: end Nenue@6: if not self.initialized then Nenue@6: self.initialized = true Nenue@6: self:SetSize(fX + dconf.padding + dconf.spacing*2, dconf.padding + math.abs(ry)) Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: function mod.Dialog_Click(self,...) Nenue@6: local command = self:GetName():match("_(a%+)$") Nenue@6: Nenue@6: print(command) Nenue@6: end Nenue@6: Nenue@6: function mod.Dialog_Check(self, ...) Nenue@6: print('field #', self.index, self.key, 'checked') Nenue@6: --self:SetChecked(self:GetChecked() and false or true) Nenue@6: end Nenue@6: Nenue@6: function mod.Dialog_EditBox(self, ...) Nenue@6: print('field #', self.index, self.key, 'changed', self:GetText()) Nenue@6: Nenue@6: if self.key == 'timerName' then Nenue@6: self.values.timerName = self:GetText() Nenue@6: self.name:SetText(self.values.timerName) Nenue@6: self.timerName = self.values.timerName Nenue@6: elseif self.key == 'spellID' then Nenue@6: print('handling spellID') Nenue@6: end Nenue@6: Nenue@6: end Nenue@6: Nenue@6: function mod.Dialog_Command(str, editbox) Nenue@6: --local spellID = T:GetArgs(str, 1,0) Nenue@6: local f = mod.EditDialog Nenue@6: f.values = {} Nenue@6: local db = mod.db Nenue@6: Nenue@6: Nenue@6: local func, t, z = pairs(db.timers) -- iterator, table Nenue@6: local name, values, y = func(t) -- index, values Nenue@6: f.parent_values = {[name] = values} Nenue@6: f.timerName = name Nenue@6: f.values = values Nenue@6: f.values.timerName = name Nenue@6: for k,v in pairs(f.values) do Nenue@6: print(cText(k), cType(v)) Nenue@6: end Nenue@6: print('pairs1', func, t) Nenue@6: print('pairs2', z, y) Nenue@6: name, values = func(t, name) Nenue@6: while name do Nenue@6: print(' entry:', name, values) Nenue@6: f.parent_values[name] = values Nenue@6: name, values = func(t, name) Nenue@6: end Nenue@6: Nenue@6: Nenue@6: Nenue@6: if f:IsVisible() then Nenue@6: f:Hide() Nenue@6: else Nenue@6: mod.Dialog_Init(f, TimerConfig.conf, TimerConfig.info) Nenue@6: Nenue@6: f:Show() Nenue@6: end Nenue@6: end