annotate Turok/Modules/Timer/Editor.lua @ 11:0b1a2f3dbfc4 tip

aura duration override triggering activation twice when aura data still exists briefly after duration end
author Nenue
date Mon, 22 Feb 2016 03:11:54 -0500
parents 9400a0ff8540
children
rev   line source
Nenue@6 1 --- Modules
Nenue@6 2 -- @file-author@
Nenue@6 3 -- @project-revision@ @project-hash@
Nenue@6 4 -- @file-revision@ @file-hash@
Nenue@6 5 -- Created: 1/18/2016 3:33 PM
Nenue@6 6 local _G = _G
Nenue@6 7 local T, type, pairs = _G.Turok, type, pairs
Nenue@6 8 local mod = T.modules.TimerControl
Nenue@6 9 local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool
Nenue@6 10 local print = function(...)
Nenue@6 11 if Devian and DevianDB.workspace ~= 1 then
Nenue@6 12 print('Dialog', ...)
Nenue@6 13 end
Nenue@6 14 end
Nenue@6 15
Nenue@6 16
Nenue@6 17 local TimerConfig = {
Nenue@6 18 conf = {
Nenue@6 19 padding = 4,
Nenue@6 20 spacing = 1,
Nenue@6 21 width = 450,
Nenue@6 22 },
Nenue@6 23 info = {
Nenue@6 24 { key = 'timerName',
Nenue@6 25 desc = 'Unique Name:',
Nenue@6 26 type='EditBox', name = 'timerName', fill=true,
Nenue@6 27 line = true,
Nenue@6 28 },
Nenue@6 29 { key = 'spellEnable',
Nenue@6 30 inherits = 'TurokCheckButtonOverlay',
Nenue@6 31 type='CheckButton', name = 'spellEnable', fixed=25, point='LEFT',
Nenue@6 32 get = Dialog_Boolean, getarg = 'spellID',
Nenue@6 33 collapse = true,
Nenue@6 34 desc = 'Spell Name',
Nenue@6 35 },
Nenue@6 36 { key = 'spellID',
Nenue@6 37 type='EditBox', name = 'spellName',
Nenue@6 38 line = true, float = true
Nenue@6 39 },
Nenue@6 40 { key = 'fill_inverse',
Nenue@6 41 desc = 'Reverse Fill',
Nenue@6 42 type='CheckButton', name='fillInverse', fixed=25, point='LEFT',
Nenue@6 43 get = Dialog_Boolean, getarg = 'fill_inverse', text='Inverted Fill',
Nenue@6 44 line = true,
Nenue@6 45 },
Nenue@6 46 { key = 'display',
Nenue@6 47 desc = 'Display Type',
Nenue@6 48 type='EditBox', name='displayType',
Nenue@6 49 line = true,
Nenue@6 50 },
Nenue@6 51 },
Nenue@6 52 }
Nenue@6 53
Nenue@6 54 local Dialog_SetField = {}
Nenue@6 55 local dget = function(name, key)
Nenue@6 56 if mod.db.timers[name] then
Nenue@6 57 return mod.db.timers[name][key]
Nenue@6 58 end
Nenue@6 59 return nil
Nenue@6 60 end
Nenue@6 61 local inherits = {
Nenue@6 62 EditBox = 'TkEditBox',
Nenue@6 63 CheckButton = 'TurokCheckButtonInline',
Nenue@6 64 Slider = 'TkSlider',
Nenue@6 65 }
Nenue@6 66
Nenue@6 67 Dialog_SetField['CheckButton'] = function(self, checked) self:SetChecked(checked) end
Nenue@6 68 Dialog_SetField['EditBox'] = function(self, text)
Nenue@6 69 print(' ', cKey(self:GetName()), text)
Nenue@6 70 self:SetText(text or '') end
Nenue@6 71 Dialog_SetField['Button'] = function(self, text) self:SetText(text) end
Nenue@6 72
Nenue@6 73
Nenue@6 74 local function Dialog_Boolean(name, key)
Nenue@6 75 print(' Dialog_Boolean', name, key)
Nenue@6 76 return (mod.db.timers[name][key] and true or false)
Nenue@6 77 end
Nenue@6 78
Nenue@6 79 function mod.Dialog_Select(self, key)
Nenue@6 80 local timer
Nenue@6 81 if self.parent_values[key] then
Nenue@6 82 print('matched timer name', key)
Nenue@6 83 timer = self.parent_values[key]
Nenue@6 84 elseif rawget(mod.frames.spellID, key) then
Nenue@6 85 print('matched spellID', key)
Nenue@6 86 timer = mod.frames.spellID[key][1]
Nenue@6 87 for k,v in pairs(timer) do
Nenue@6 88 print(' -', k, '=', v)
Nenue@6 89 end
Nenue@6 90 end
Nenue@6 91
Nenue@6 92 if timer then
Nenue@6 93 self.values = timer
Nenue@6 94 self.timerName = timer.timerName
Nenue@6 95 else
Nenue@6 96 self.values = {
Nenue@6 97 timerName = 'New Timer'
Nenue@6 98 }
Nenue@6 99 self.timerName = 'New Timer'
Nenue@6 100 end
Nenue@6 101 mod.Dialog_Init(self, TimerConfig.conf, TimerConfig.info)
Nenue@6 102 end
Nenue@6 103
Nenue@6 104 function mod.Dialog_Init(self, dconf, dinfo)
Nenue@6 105 print('init,', self.values.timerName)
Nenue@6 106
Nenue@6 107 if not self.fields then
Nenue@6 108 self.fields = {}
Nenue@6 109 self.rows = {}
Nenue@6 110 self.Click = mod.Dialog_Click
Nenue@6 111 self.Check = mod.Dialog_Check
Nenue@6 112 self.EditBox = mod.Dialog_EditBox
Nenue@6 113 end
Nenue@6 114 print(self.name, self.timerName)
Nenue@6 115 self.name:SetText(self.timerName)
Nenue@6 116
Nenue@6 117 local inset = dconf.padding + dconf.spacing
Nenue@6 118 -- frame X max
Nenue@6 119 local fX = 0
Nenue@6 120 -- row number, row Y offset
Nenue@6 121 local rn, ry = 1, -34
Nenue@6 122 -- row x offset left-align, row x offset right-aligned, largest collapsed element
Nenue@6 123 local rxL, rxR, rC, rh = dconf.spacing, dconf.spacing, 0, 0
Nenue@6 124 for i, opt in ipairs(dinfo) do
Nenue@6 125 if not self.rows[rn] then
Nenue@6 126 self.rows[rn] = CreateFrame('Frame', self:GetName()..'Row'..rn, self, 'TurokDialogRow')
Nenue@6 127 end
Nenue@6 128
Nenue@6 129 local k = opt.key
Nenue@6 130 if self.fields[i] == nil then
Nenue@6 131 self.fields[i] = CreateFrame(opt.type, self:GetName()..opt.name, self.rows[rn], opt.inherits or inherits[opt.type])
Nenue@6 132 self.fields[i].index = i
Nenue@6 133 self.fields[i].key = k
Nenue@6 134 -- row point (from), row point (to), row x offset
Nenue@6 135 local rp, rpt, rx
Nenue@6 136 -- row delta
Nenue@6 137 local rd
Nenue@6 138 if opt.fill then
Nenue@6 139 rpt = opt.float and 'BOTTOMLEFT' or 'BOTTOMRIGHT'
Nenue@6 140 -- row point X offset
Nenue@6 141 local rpx = opt.float and dconf.spacing or -dconf.spacing
Nenue@6 142 self.fields[i]:SetPoint(rpt, self.rows[rn], rpt, rpx, 0)
Nenue@6 143 print(' fill:', rpt, '-', rpt,' :: ', rpx, 0)
Nenue@6 144 rd = 0
Nenue@6 145 else
Nenue@6 146 rd = self.fields[i]:GetWidth() + dconf.spacing
Nenue@6 147 end
Nenue@6 148 if opt.float then
Nenue@6 149 rp = 'BOTTOMRIGHT'
Nenue@6 150 rx = -rxR
Nenue@6 151 rxR = rxR + rd
Nenue@6 152 elseif opt.collapse then
Nenue@6 153 rp = 'BOTTOMLEFT'
Nenue@6 154 rx = dconf.spacing
Nenue@6 155 rC = math.max(rC, rd + dconf.spacing) -- spacing L + rd{width + spacing R}
Nenue@6 156 else
Nenue@6 157 rp = 'BOTTOMLEFT'
Nenue@6 158 rx = rxL
Nenue@6 159 rxL = rxL + rd
Nenue@6 160 end
Nenue@6 161
Nenue@6 162 rh = math.max(rh, self.fields[i]:GetHeight())
Nenue@6 163 self.fields[i]:SetPoint(rp, self.rows[rn], rp, rx, dconf.spacing)
Nenue@6 164 print(' align:', rp, '-', rp, ' :: ', rx, 0)
Nenue@6 165 print(' dR:', cNum(rd), 'nR:',cWord(rn), 'rX:', cNum(rx), 'i:', cText(i))
Nenue@6 166
Nenue@6 167 if opt.line or (not dinfo[i+1]) then
Nenue@6 168 print(cText'nR:', cNum(rn), 'rY:', cNum(ry))
Nenue@6 169 self.rows[rn]:ClearAllPoints()
Nenue@6 170 self.rows[rn]:SetPoint('TOPLEFT', self, 'TOPLEFT', dconf.padding, ry)
Nenue@6 171 self.rows[rn]:SetPoint('TOPRIGHT', self, 'TOPRIGHT', -dconf.padding, ry)
Nenue@6 172 self.rows[rn]:SetHeight(rh + dconf.spacing*2)
Nenue@6 173 self.rows[rn]:Show()
Nenue@6 174 rn = rn + 1
Nenue@6 175 ry = ry - (rh + dconf.spacing*3) -->| {spacing T + rh + spacing B} + spacing dR |<--
Nenue@6 176
Nenue@6 177 print('fX:',cNum(fX), 'rX:', cNum(rxL+rxR+dconf.spacing), 'rC:', cNum(rC))
Nenue@6 178 fX = math.max(fX, rxL+rxR+dconf.spacing)
Nenue@6 179 fX = math.max(fX, rC)
Nenue@6 180 rxL, rxR = dconf.spacing, dconf.spacing
Nenue@6 181 rh = 0
Nenue@6 182 end
Nenue@6 183 end
Nenue@6 184
Nenue@6 185 self.fields[i]:Show()
Nenue@6 186 if opt.desc and self.fields[i].description then
Nenue@6 187 self.fields[i].description:SetText(opt.desc)
Nenue@6 188 end
Nenue@6 189 Dialog_SetField[opt.type](self.fields[i], opt.get and opt.get(self.values.timerName, opt.getarg) or self.values[k])
Nenue@6 190
Nenue@6 191 end
Nenue@6 192 if not self.initialized then
Nenue@6 193 self.initialized = true
Nenue@6 194 self:SetSize(fX + dconf.padding + dconf.spacing*2, dconf.padding + math.abs(ry))
Nenue@6 195 end
Nenue@6 196 end
Nenue@6 197
Nenue@6 198 function mod.Dialog_Click(self,...)
Nenue@6 199 local command = self:GetName():match("_(a%+)$")
Nenue@6 200
Nenue@6 201 print(command)
Nenue@6 202 end
Nenue@6 203
Nenue@6 204 function mod.Dialog_Check(self, ...)
Nenue@6 205 print('field #', self.index, self.key, 'checked')
Nenue@6 206 --self:SetChecked(self:GetChecked() and false or true)
Nenue@6 207 end
Nenue@6 208
Nenue@6 209 function mod.Dialog_EditBox(self, ...)
Nenue@6 210 print('field #', self.index, self.key, 'changed', self:GetText())
Nenue@6 211
Nenue@6 212 if self.key == 'timerName' then
Nenue@6 213 self.values.timerName = self:GetText()
Nenue@6 214 self.name:SetText(self.values.timerName)
Nenue@6 215 self.timerName = self.values.timerName
Nenue@6 216 elseif self.key == 'spellID' then
Nenue@6 217 print('handling spellID')
Nenue@6 218 end
Nenue@6 219
Nenue@6 220 end
Nenue@6 221
Nenue@6 222 function mod.Dialog_Command(str, editbox)
Nenue@6 223 --local spellID = T:GetArgs(str, 1,0)
Nenue@6 224 local f = mod.EditDialog
Nenue@6 225 f.values = {}
Nenue@6 226 local db = mod.db
Nenue@6 227
Nenue@6 228
Nenue@6 229 local func, t, z = pairs(db.timers) -- iterator, table
Nenue@6 230 local name, values, y = func(t) -- index, values
Nenue@6 231 f.parent_values = {[name] = values}
Nenue@6 232 f.timerName = name
Nenue@6 233 f.values = values
Nenue@6 234 f.values.timerName = name
Nenue@6 235 for k,v in pairs(f.values) do
Nenue@6 236 print(cText(k), cType(v))
Nenue@6 237 end
Nenue@6 238 print('pairs1', func, t)
Nenue@6 239 print('pairs2', z, y)
Nenue@6 240 name, values = func(t, name)
Nenue@6 241 while name do
Nenue@6 242 print(' entry:', name, values)
Nenue@6 243 f.parent_values[name] = values
Nenue@6 244 name, values = func(t, name)
Nenue@6 245 end
Nenue@6 246
Nenue@6 247
Nenue@6 248
Nenue@6 249 if f:IsVisible() then
Nenue@6 250 f:Hide()
Nenue@6 251 else
Nenue@6 252 mod.Dialog_Init(f, TimerConfig.conf, TimerConfig.info)
Nenue@6 253
Nenue@6 254 f:Show()
Nenue@6 255 end
Nenue@6 256 end