annotate Turok/Modules/Timer/Editor.lua @ 6:a9b8b0866ece

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