annotate UI.lua @ 35:3304455a3f45

code organizing; UI stuff is in the UI script, Devian prime just deals with config and print corner menu elements placed and hooked, still needs follow-up code
author Nenue
date Sun, 27 Dec 2015 03:51:17 -0500
parents
children bec37163b7fe
rev   line source
Nenue@35 1 --- ${PACKAGE_NAME}
Nenue@35 2 -- @file-author@
Nenue@35 3 -- @project-revision@ @project-hash@
Nenue@35 4 -- @file-revision@ @file-hash@
Nenue@35 5 -- Created: 12/27/2015 3:01 AM
Nenue@35 6
Nenue@35 7
Nenue@35 8 if not LibStub then
Nenue@35 9 print('Something has happened...')
Nenue@35 10 end
Nenue@35 11 local D = LibStub("AceAddon-3.0"):GetAddon("Devian")
Nenue@35 12
Nenue@35 13
Nenue@35 14
Nenue@35 15 local DEVIAN_FRAME = 'DevianConsole'
Nenue@35 16 local DEVIAN_DOCK_FRAME = 'DevianDockFrame'
Nenue@35 17 local MSG_NEED_DEV_MODE = 'Must be in development mode to use this function.'
Nenue@35 18
Nenue@35 19
Nenue@35 20 local function Console_MinMax(self)
Nenue@35 21 if self.minimized then
Nenue@35 22 self:Maximize()
Nenue@35 23 else
Nenue@35 24 self:Minimize()
Nenue@35 25 end
Nenue@35 26 end
Nenue@35 27
Nenue@35 28 local function Console_Minimize(self)
Nenue@35 29 self:SetHeight(20)
Nenue@35 30 self:SetMaxResize(GetScreenWidth(),20)
Nenue@35 31 self.minimized = true
Nenue@35 32 self.out:Hide()
Nenue@35 33 self:Save()
Nenue@35 34 end
Nenue@35 35
Nenue@35 36 local function Console_Maximize(self)
Nenue@35 37 local db = D.channels[self.index]
Nenue@35 38 self:SetHeight(db.height)
Nenue@35 39 self:SetMaxResize(GetScreenWidth(),GetScreenHeight())
Nenue@35 40 self.minimized = nil
Nenue@35 41 self.out:Show()
Nenue@35 42 self:Save()
Nenue@35 43 end
Nenue@35 44
Nenue@35 45
Nenue@35 46 local function Console_Save(self)
Nenue@35 47 local db = D.channels[self.index]
Nenue@35 48 if self.x then
Nenue@35 49 db.x = self.x
Nenue@35 50 else
Nenue@35 51 db.x = self:GetLeft()
Nenue@35 52 end
Nenue@35 53
Nenue@35 54 if self.y then
Nenue@35 55 db.y = self.y
Nenue@35 56 else
Nenue@35 57 db.y = (self:GetTop() - GetScreenHeight())
Nenue@35 58 end
Nenue@35 59
Nenue@35 60 if self.width then
Nenue@35 61 db.width = self.width
Nenue@35 62 else
Nenue@35 63 db.width = self:GetWidth()
Nenue@35 64 end
Nenue@35 65
Nenue@35 66 if not self.minimized then
Nenue@35 67 if self.height then
Nenue@35 68 db.height = self.height
Nenue@35 69 else
Nenue@35 70 db.height = self:GetHeight()
Nenue@35 71 end
Nenue@35 72 self:SetHeight(db.height)
Nenue@35 73 end
Nenue@35 74
Nenue@35 75 db.dockedTo = self.dockedTo
Nenue@35 76 db.docked = self.docked
Nenue@35 77
Nenue@35 78 db.minimized = self.minimized and true or nil
Nenue@35 79 db.enabled = self:IsVisible() and true or nil
Nenue@35 80 db.active = self.active and true or nil
Nenue@35 81 --print('save:', db.signature, 'min=', db.minimized, ' enabled=', db.enabled, ' active = ', db.active, 'x=', db.x, 'y=', db.y, 'h=', db.height, 'w=', db.width)
Nenue@35 82 self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', db.x, db.y)
Nenue@35 83 self:SetWidth(db.width)
Nenue@35 84 end
Nenue@35 85
Nenue@35 86 -- Console frame toggler
Nenue@35 87 -- @paramsig [...]
Nenue@35 88 -- @param ... one or more space-seperated channel keys
Nenue@35 89 local function Console_Toggle(input)
Nenue@35 90 local db = D.db
Nenue@35 91 if db.workspace == 1 then
Nenue@35 92 return D:Print(MSG_NEED_DEV_MODE)
Nenue@35 93 end
Nenue@35 94 local search = {}
Nenue@35 95 local n = 0
Nenue@35 96 if D:GetArgs(input,1) then
Nenue@35 97 repeat
Nenue@35 98 key, n = D:GetArgs(input,1,n)
Nenue@35 99 if D.sig[key] then
Nenue@35 100 table.insert(search, D.sig[key])
Nenue@35 101 elseif D.console[key] then
Nenue@35 102 table.insert(search, D.console[key])
Nenue@35 103 end
Nenue@35 104 until n == 1e9
Nenue@35 105 else
Nenue@35 106 search = D.console
Nenue@35 107 end
Nenue@35 108
Nenue@35 109 db.enabled = (not db.enabled) and true or nil
Nenue@35 110 for i, c in ipairs(search) do
Nenue@35 111 --print(i,c.index)
Nenue@35 112 if db.enabled then
Nenue@35 113 c.enabled = true
Nenue@35 114 c:Show()
Nenue@35 115 if db.current_channel == c.index then
Nenue@35 116 c:ToFront()
Nenue@35 117 end
Nenue@35 118 c:Save()
Nenue@35 119 else
Nenue@35 120 c:Hide()
Nenue@35 121 end
Nenue@35 122 end
Nenue@35 123
Nenue@35 124 if db.enabled then
Nenue@35 125 D:Print('toggled on?')
Nenue@35 126 else
Nenue@35 127 D:Print('toggled off?')
Nenue@35 128 end
Nenue@35 129 end
Nenue@35 130
Nenue@35 131 --- Brings the console to the front.
Nenue@35 132 -- Frame method used to bring a console frame to the front of the display stack.
Nenue@35 133 local function Console_ToFront(c)
Nenue@35 134 local db = D.db
Nenue@35 135 --print(D.raise_ct, 'Raising', c.signature)
Nenue@35 136 --print(unpack(db.frontdrop))
Nenue@35 137 --print(unpack(db.frontgrad))
Nenue@35 138 --print(db.frontblend)
Nenue@35 139 -- D.raise_ct = D.raise_ct + 1
Nenue@35 140 c:Raise()
Nenue@35 141 c:SetAlpha(db.frontalpha)
Nenue@35 142 c.out.backdrop:SetTexture(unpack(db.frontdrop))
Nenue@35 143 c.out.backdrop:SetGradientAlpha(unpack(db.frontgrad))
Nenue@35 144 c.out.backdrop:SetBlendMode(db.frontblend)
Nenue@35 145 db.current_channel = c.index
Nenue@35 146
Nenue@35 147 for _, part in pairs(c.border) do
Nenue@35 148 part:SetTexture(unpack(db.frontborder))
Nenue@35 149 end
Nenue@35 150
Nenue@35 151 for id, bc in pairs(D.console) do
Nenue@35 152 if id ~= c.index then
Nenue@35 153 --print(D.raise_ct, 'Lowering', bc.signature)
Nenue@35 154 --print(unpack(db.backdrop))
Nenue@35 155 --print(unpack(db.backgrad))
Nenue@35 156 --print(db.backblend)
Nenue@35 157 bc:SetAlpha(db.backalpha)
Nenue@35 158 bc.out.backdrop:SetTexture(unpack(db.backdrop))
Nenue@35 159 bc.out.backdrop:SetGradientAlpha(unpack(db.backgrad))
Nenue@35 160 bc.out.backdrop:SetBlendMode(db.backblend)
Nenue@35 161
Nenue@35 162 for _, part in pairs(bc.border) do
Nenue@35 163 part:SetTexture(unpack(db.backborder))
Nenue@35 164 end
Nenue@35 165 end
Nenue@35 166 end
Nenue@35 167 end
Nenue@35 168
Nenue@35 169 local function Console_MouseDown(self, button, up)
Nenue@35 170 if button == 'LeftButton' then
Nenue@35 171 if up then
Nenue@35 172 self:StopMovingOrSizing()
Nenue@35 173 self:ToFront()
Nenue@35 174 self.x = nil
Nenue@35 175 self.y = nil
Nenue@35 176 self.width = nil
Nenue@35 177 self.height = nil
Nenue@35 178 self:Save()
Nenue@35 179 elseif self.out.grip:IsMouseOver() then
Nenue@35 180 self:StartSizing()
Nenue@35 181 else
Nenue@35 182 self:StartMoving()
Nenue@35 183 end
Nenue@35 184 else
Nenue@35 185 if up then
Nenue@35 186 self:MinMax()
Nenue@35 187 end
Nenue@35 188 end
Nenue@35 189 end
Nenue@35 190 local function Console_MouseUp(self, button)
Nenue@35 191 return Console_MouseDown(self, button, true)
Nenue@35 192 end
Nenue@35 193 print('load check')
Nenue@35 194
Nenue@35 195
Nenue@35 196 --- Constructs the frame object for a console channel
Nenue@35 197 -- Initializes the console channel at a specified index.
Nenue@35 198 -- Configuration data can be overridden by passing a desired settings table.
Nenue@35 199 -- @param i Numeric index of the channel as it manifests in db.channels
Nenue@35 200 -- @param vars Optional settings table to be used.
Nenue@35 201 local function CreateConsole(i, vars)
Nenue@35 202 local db = D.db
Nenue@35 203 if tonumber(i) == nil or math.floor(i) ~= i then
Nenue@35 204 error('Non-integer index value.')
Nenue@35 205 end
Nenue@35 206 if not vars then
Nenue@35 207 vars = D.channels[i] and D.channels[i] or D.channels[db.primary_channel]
Nenue@35 208 end
Nenue@35 209 local f
Nenue@35 210 if vars.docked then
Nenue@35 211 f = CreateFrame('Frame','DevianDockFrame' .. i, DEVIAN_DOCK_FRAME)
Nenue@35 212 else
Nenue@35 213 f= CreateFrame('Frame', 'DevianChannelFrame' .. i, UIParent, DEVIAN_FRAME)
Nenue@35 214 end
Nenue@35 215 --@debug@
Nenue@35 216 --print(f:GetName())
Nenue@35 217
Nenue@35 218 --print('create(2)')
Nenue@35 219 for k,v in pairs(vars) do
Nenue@35 220 f[k] = v
Nenue@35 221 --@debug@
Nenue@35 222 print(' f['..type(k)..' '..tostring(k)..'] = '..type(v)..' '..tostring(v))
Nenue@35 223 end
Nenue@35 224
Nenue@35 225 f:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', vars.x, vars.y)
Nenue@35 226 f:SetSize(vars.width, vars.height)
Nenue@35 227 f:Lower()
Nenue@35 228 f.out:SetFont(db.font, db.fontsize, db.fontoutline)
Nenue@35 229 if (db.current_channel == i) then
Nenue@35 230 f.out.backdrop:SetTexture(unpack(db.frontdrop))
Nenue@35 231 else
Nenue@35 232 f.out.backdrop:SetTexture(unpack(db.backdrop))
Nenue@35 233 end
Nenue@35 234
Nenue@35 235
Nenue@35 236
Nenue@35 237 f.Save = Console_Save
Nenue@35 238 f.Minimize = Console_Minimize
Nenue@35 239 f.Maximize = Console_Maximize
Nenue@35 240 f.MinMax = Console_MinMax
Nenue@35 241 f.ToFront = Console_ToFront
Nenue@35 242 f.Toggle = D.Console_Toggle
Nenue@35 243 f:SetScript('OnMouseDown', Console_MouseDown)
Nenue@35 244 f:SetScript('OnMouseUp', Console_MouseUp)
Nenue@35 245
Nenue@35 246 if vars.minimized then
Nenue@35 247 f:Minimize()
Nenue@35 248 else
Nenue@35 249 f:Maximize()
Nenue@35 250 end
Nenue@35 251 if db.enabled and f.enabled then
Nenue@35 252 f:Show()
Nenue@35 253 end
Nenue@35 254
Nenue@35 255 return f
Nenue@35 256 end
Nenue@35 257
Nenue@35 258
Nenue@35 259 --- Updates console information and returns the handle of the channel object that was worked on.
Nenue@35 260 -- When key is nil or not a valid handle, a new channel is created using whatever signature can be found in cinfo.
Nenue@35 261 -- The signature can be passed as a string, or as a table entry under the key 'signature'
Nenue@35 262 -- If the signature of a new channel is also a tag, the channel will be added to that tag
Nenue@35 263 -- @param cinfo string signature of a new channel, or a table of config variables to be imposed on the channel
Nenue@35 264 -- @param key string signature or index number of channel to operate on
Nenue@35 265 -- @usage channel = D:SetChannel('new', nil) -- creates a new channel
Nenue@35 266 -- @usage channel = D:SetChannel({x = 200, y = 100}, 4) -- updates channel #4
Nenue@35 267 function D:SetChannel(cinfo, key)
Nenue@35 268 local db = self.db
Nenue@35 269 local t_info = {}
Nenue@35 270 local channel, isNew, id, sig, t_id
Nenue@35 271 -- obtain source data
Nenue@35 272 if tonumber(key) ~= nil and db.channels[key] then
Nenue@35 273 id = tonumber(key)
Nenue@35 274 elseif D.sigID[tostring(key)] then
Nenue@35 275 id = D.sigID[tostring(key)]
Nenue@35 276 else
Nenue@35 277 id = db.primary_channel
Nenue@35 278 isNew = true
Nenue@35 279 end
Nenue@35 280 local dbvars = db.channels[id]
Nenue@35 281 t_id = id -- overridden later if new
Nenue@35 282 t_info.index = t_id --
Nenue@35 283 --@debug@
Nenue@35 284 --print('setchan(1) cinfo, key, id=', cinfo, key, id)--@end-debug@
Nenue@35 285
Nenue@35 286
Nenue@35 287 -- obtain config info
Nenue@35 288 if type(cinfo) == 'string' then
Nenue@35 289 sig = cinfo
Nenue@35 290 cinfo = {signature = sig}
Nenue@35 291 elseif type(cinfo) ~= 'table' then -- stop here if a table wans't passed
Nenue@35 292 error('Expecting table of string as arg1')
Nenue@35 293 elseif cinfo.signature then -- new sig
Nenue@35 294 sig = cinfo.signature
Nenue@35 295 elseif isNew then -- new channel sig
Nenue@35 296 sig = 'Ch'
Nenue@35 297 else -- old sig
Nenue@35 298 sig = db.channels[id].signature
Nenue@35 299 end
Nenue@35 300 t_info.signature = sig
Nenue@35 301 --@debug@
Nenue@35 302 --print('setchan(2) sig,id,isNew=', sig, id, isNew)--@end-debug@
Nenue@35 303
Nenue@35 304 for k,v in pairs(cinfo) do -- allow all cinfo to pass
Nenue@35 305 t_info[k] = v
Nenue@35 306 end
Nenue@35 307
Nenue@35 308 local blocked = { -- ignore these vars:
Nenue@35 309 ['docked'] = true, -- table
Nenue@35 310 ['dockedTo'] = true, -- table-related
Nenue@35 311 ['signature'] = true} -- already determined
Nenue@35 312 for k,v in pairs(dbvars) do
Nenue@35 313 if not t_info[k] and not blocked[k] then -- already set or blocked?
Nenue@35 314 t_info[k] = v
Nenue@35 315 end
Nenue@35 316 end
Nenue@35 317 -- new channel overrides
Nenue@35 318 if isNew then
Nenue@35 319 if D.sigID[sig]then -- find a non-clashing signature
Nenue@35 320 local result, i = sig, 1
Nenue@35 321 while D.sigID[result] do
Nenue@35 322 result = sig .. i
Nenue@35 323 i = i + 1
Nenue@35 324 end
Nenue@35 325 t_info.signature = result
Nenue@35 326 end
Nenue@35 327 t_id = db.max_channel + 1
Nenue@35 328 t_info.index = t_id
Nenue@35 329 --@debug@
Nenue@35 330 --print('setchan(3a) isNew, sig, t_info.signature=', isNew, sig, t_info.signature)--@end-debug@
Nenue@35 331 else
Nenue@35 332 --@debug@
Nenue@35 333 --print('setchan(3b) isNew, sig, t_info.signature=', isNew, sig, t_info.signature)--@end-debug@
Nenue@35 334 end
Nenue@35 335
Nenue@35 336 local channel
Nenue@35 337 if not self.console[t_id] then -- create a frame
Nenue@35 338 if isNew then -- position the channel frame
Nenue@35 339 t_info.x = t_info.x + 20
Nenue@35 340 t_info.y = t_info.y - 20
Nenue@35 341 db.channels[t_id] = t_info
Nenue@35 342 --@debug@
Nenue@35 343 print('setchan(4a)', 't_id, x, y=', t_id, t_info.x, t_info.y)--@end-debug@
Nenue@35 344 end
Nenue@35 345 channel = CreateConsole(t_id, t_info)
Nenue@35 346 self.console[t_id] = channel
Nenue@35 347 self.sig[t_info.signature] = channel
Nenue@35 348 self.sigID[t_info.signature] = t_id
Nenue@35 349 self.IDsig[t_id] = t_info.signature
Nenue@35 350
Nenue@35 351 end
Nenue@35 352 channel = self.console[t_id]
Nenue@35 353 if channel.minimized then
Nenue@35 354 channel:Minimize()
Nenue@35 355 else
Nenue@35 356 channel:Maximize()
Nenue@35 357 end
Nenue@35 358
Nenue@35 359 if channel.enabled and db.enabled then -- hide or show last since Min/Max mess with visibility
Nenue@35 360 print('setchan(5a) enable')
Nenue@35 361 channel:Show()
Nenue@35 362 else
Nenue@35 363 print('setchan(5a) disable')
Nenue@35 364 channel:Hide()
Nenue@35 365 end
Nenue@35 366 --@debug@
Nenue@35 367 --print('setchan(end); c:IsVisible(), c.enabled, db.enabled=', channel:IsVisible(), channel.enabled, db.enabled)--@end-debug@
Nenue@35 368 return channel
Nenue@35 369 end