annotate UI.lua @ 45:5341e4d84622

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