Mercurial > wow > devian
comparison UI.lua @ 66:516ceb31703d
New profile system that stores channel and tag settings for each saved AddOn list.
A boatload of structural revisions, making better use of the built-in table, and hopefully making console command issues easier to pick up.
| author | Nenue |
|---|---|
| date | Sat, 05 Mar 2016 13:35:51 -0500 |
| parents | 8729d39f6a3d |
| children | 1687ae1c6162 |
comparison
equal
deleted
inserted
replaced
| 65:4148c90986e7 | 66:516ceb31703d |
|---|---|
| 4 -- @file-revision@ @file-hash@ | 4 -- @file-revision@ @file-hash@ |
| 5 -- Created: 12/27/2015 3:01 AM | 5 -- Created: 12/27/2015 3:01 AM |
| 6 if not LibStub then | 6 if not LibStub then |
| 7 print('Something has happened...') | 7 print('Something has happened...') |
| 8 end | 8 end |
| 9 local D = LibStub("AceAddon-3.0"):GetAddon("Devian") | 9 local _, D = ... |
| 10 local DEVIAN_FRAME = 'DevianConsole' | 10 local DEVIAN_FRAME = 'DevianConsole' |
| 11 local insert, tonumber, pairs, concat = tinsert, tonumber, pairs, table.concat | |
| 12 local L = D.L | |
| 13 local print = D.print | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 local Console_OnMovementChanged = function(self, event) | |
| 19 local db = D.db | |
| 20 if self.enabled then | |
| 21 if event == 'PLAYER_STARTED_MOVING' then | |
| 22 self.moveFade:Stop() | |
| 23 local F1 = self.moveFade.alphaOut | |
| 24 F1:SetFromAlpha(db.movement_fade_from) | |
| 25 F1:SetToAlpha(db.movement_fade_to) | |
| 26 F1:SetDuration(db.movement_fade_time) | |
| 27 self.moveFade:Play() | |
| 28 self:EnableMouse(false) | |
| 29 else | |
| 30 self.moveFade:Stop() | |
| 31 local F1 = self.moveFade.alphaOut | |
| 32 F1:SetToAlpha(db.movement_fade_from) | |
| 33 F1:SetFromAlpha(db.movement_fade_to) | |
| 34 F1:SetDuration(db.movement_fade_time) | |
| 35 self.moveFade:Play() | |
| 36 self:EnableMouse(true) | |
| 37 end | |
| 38 end | |
| 39 end | |
| 40 | |
| 11 | 41 |
| 12 | 42 |
| 13 local function Console_MinMax(self) | 43 local function Console_MinMax(self) |
| 14 if self.minimized then | 44 if self.minimized then |
| 15 self:Maximize() | 45 self:Maximize() |
| 175 f.MinMax = Console_MinMax | 205 f.MinMax = Console_MinMax |
| 176 f.ToFront = Console_ToFront | 206 f.ToFront = Console_ToFront |
| 177 f.Toggle = D.Console_Toggle | 207 f.Toggle = D.Console_Toggle |
| 178 f:SetScript('OnMouseDown', Console_MouseDown) | 208 f:SetScript('OnMouseDown', Console_MouseDown) |
| 179 f:SetScript('OnMouseUp', Console_MouseUp) | 209 f:SetScript('OnMouseUp', Console_MouseUp) |
| 210 f.profileID = db.current_profile | |
| 180 | 211 |
| 181 | 212 |
| 182 UIDropDownMenu_Initialize(f.menuFrame, function() | 213 UIDropDownMenu_Initialize(f.menuFrame, function() |
| 183 local info = { { | 214 local info = { { |
| 184 text= "Close", | 215 text= "Close", |
| 196 for _, v in ipairs(info) do | 227 for _, v in ipairs(info) do |
| 197 UIDropDownMenu_AddButton(v) | 228 UIDropDownMenu_AddButton(v) |
| 198 end | 229 end |
| 199 end, 'MENU') | 230 end, 'MENU') |
| 200 | 231 |
| 232 if db.movement_fade then | |
| 233 f:RegisterEvent('PLAYER_STARTED_MOVING') | |
| 234 f:RegisterEvent('PLAYER_STOPPED_MOVING') | |
| 235 f:SetScript('OnEvent', Console_OnMovementChanged) | |
| 236 end | |
| 237 | |
| 201 D.dock.buttons[i] = CreateFrame('Button', 'Channel'..i..'Beacon', UIParent, 'DevianBeacon') | 238 D.dock.buttons[i] = CreateFrame('Button', 'Channel'..i..'Beacon', UIParent, 'DevianBeacon') |
| 202 D.dock.buttons[i].icon:SetVertexColor(math.random(),math.random(),math.random()) | 239 D.dock.buttons[i].icon:SetVertexColor(math.random(),math.random(),math.random()) |
| 203 D.dock.buttons[i].console = f | 240 D.dock.buttons[i].console = f |
| 204 D.dock.buttons[i].index = i | 241 D.dock.buttons[i].index = i |
| 205 D.dock.buttons[i].caption.name:SetText(vars.signature) | 242 D.dock.buttons[i].caption.name:SetText(vars.signature) |
| 225 -- @param cinfo string signature of a new channel, or a table of config variables to be imposed on the channel | 262 -- @param cinfo string signature of a new channel, or a table of config variables to be imposed on the channel |
| 226 -- @param key string signature or index number of channel to operate on | 263 -- @param key string signature or index number of channel to operate on |
| 227 -- @usage channel = D:SetChannel('new', nil) -- creates a new channel | 264 -- @usage channel = D:SetChannel('new', nil) -- creates a new channel |
| 228 -- @usage channel = D:SetChannel({x = 200, y = 100}, 4) -- updates channel #4 | 265 -- @usage channel = D:SetChannel({x = 200, y = 100}, 4) -- updates channel #4 |
| 229 function D:SetChannel(cinfo, key) | 266 function D:SetChannel(cinfo, key) |
| 230 local db = self.db | 267 local profile = D.currentProfile |
| 231 local t_info = {} | 268 local t_info = {} |
| 232 local channel, isNew, id, sig, t_id | 269 local channel, isNew, id, sig, t_id |
| 233 --@debug@ | 270 --@debug@ |
| 234 --print('setchan(0) cinfo, key', cinfo, key)--@end-debug@ | 271 print('setchan(0) cinfo, key', cinfo, key)--@end-debug@ |
| 235 -- obtain source data | 272 -- obtain source data |
| 236 if tonumber(key) ~= nil and db.channels[key] then | 273 if tonumber(key) ~= nil and D.channels[key] then |
| 237 id = tonumber(key) | 274 id = tonumber(key) |
| 238 elseif D.sigID[tostring(key)] then | 275 elseif D.sigID[tostring(key)] then |
| 239 id = D.sigID[tostring(key)] | 276 id = D.sigID[tostring(key)] |
| 240 else | 277 else |
| 241 id = db.primary_channel | 278 id = profile.default_channel |
| 242 isNew = true | 279 isNew = true |
| 243 end | 280 end |
| 244 local dbvars = db.channels[id] | 281 local dbvars = D.channels[id] |
| 245 t_id = id -- overridden later if new | 282 t_id = id -- overridden later if new |
| 246 t_info.index = t_id -- | 283 t_info.index = t_id -- |
| 247 --@debug@ | 284 --@debug@ |
| 248 --print('setchan(1) cinfo, key, id=', cinfo, key, id)--@end-debug@ | 285 print('setchan(1) cinfo, key, id=', cinfo, key, id)--@end-debug@ |
| 249 | 286 |
| 250 | 287 |
| 251 -- obtain config info | 288 -- obtain config info |
| 252 if type(cinfo) == 'string' then | 289 if type(cinfo) == 'string' then |
| 253 sig = cinfo | 290 sig = cinfo |
| 254 cinfo = {signature = sig} | 291 cinfo = {signature = sig} |
| 255 elseif type(cinfo) ~= 'table' then -- stop here if a table wans't passed | 292 elseif type(cinfo) ~= 'table' then -- stop here if a table wans't passed |
| 256 error('Expecting table of string as arg1') | 293 error('Expecting table of string as arg1') |
| 257 elseif cinfo.signature then -- new sig | 294 elseif cinfo.signature then -- new sig |
| 258 sig = cinfo.signature | 295 sig = cinfo.signature |
| 259 elseif isNew then -- new channel sig | 296 elseif isNew then -- new channel sig |
| 260 sig = 'Ch' | 297 sig = 'Ch' |
| 261 else -- old sig | 298 else -- old sig |
| 262 sig = db.channels[id].signature | 299 sig = D.channels[id].signature |
| 263 end | 300 end |
| 264 t_info.signature = sig | 301 t_info.signature = sig |
| 265 --@debug@ | 302 --@debug@ |
| 266 --print('setchan(2) sig,id,isNew=', sig, id, isNew)--@end-debug@ | 303 print('setchan(2) sig,id,isNew=', sig, id, isNew)--@end-debug@ |
| 267 | 304 |
| 268 for k,v in pairs(cinfo) do -- allow all cinfo to pass | 305 for k,v in pairs(cinfo) do -- allow all cinfo to pass |
| 269 t_info[k] = v | 306 t_info[k] = v |
| 270 end | 307 end |
| 271 | 308 |
| 289 t_info.signature = result | 326 t_info.signature = result |
| 290 end | 327 end |
| 291 t_id = self.max_channel + 1 | 328 t_id = self.max_channel + 1 |
| 292 t_info.index = t_id | 329 t_info.index = t_id |
| 293 --@debug@ | 330 --@debug@ |
| 294 --print('setchan(3a) t_id, isNew, sig, t_info.signature=', t_id, isNew, sig, t_info.signature)--@end-debug@ | 331 print('setchan(3a) t_id, isNew, sig, t_info.signature=', t_id, isNew, sig, t_info.signature)--@end-debug@ |
| 295 else | 332 else |
| 296 --@debug@ | 333 --@debug@ |
| 297 --print('setchan(3b) t_id, isNew, sig, t_info.signature=', t_id, isNew, sig, t_info.signature)--@end-debug@ | 334 print('setchan(3b) t_id, isNew, sig, t_info.signature=', t_id, isNew, sig, t_info.signature)--@end-debug@ |
| 298 end | 335 end |
| 299 | 336 |
| 300 local channel | 337 local channel |
| 301 if not self.console[t_id] then -- create a frame | 338 if not self.console[t_id] then -- create a frame |
| 302 if isNew then -- position the channel frame | 339 if isNew then -- position the channel frame |
| 303 self.max_channel = t_id | 340 profile.max_channel = t_id |
| 304 db.max_channel = t_id | 341 t_info.x = t_info.x + 20 |
| 305 t_info.x = t_info.x + 20 | 342 t_info.y = t_info.y - 20 |
| 306 t_info.y = t_info.y - 20 | 343 profile.channels[t_id] = t_info |
| 307 db.channels[t_id] = t_info | 344 --@debug@ |
| 308 --@debug@ | 345 print('setchan(4a)', 't_id, x, y=', t_id, t_info.x, t_info.y)--@end-debug@ |
| 309 --print('setchan(4a)', 't_id, x, y=', t_id, t_info.x, t_info.y)--@end-debug@ | 346 end |
| 310 end | 347 channel = CreateConsole(t_id, t_info) |
| 311 channel = CreateConsole(t_id, t_info) | 348 self.console[t_id] = channel |
| 312 self.console[t_id] = channel | 349 self.sig[t_info.signature] = channel |
| 313 self.sig[t_info.signature] = channel | 350 self.sigID[t_info.signature] = t_id |
| 314 self.sigID[t_info.signature] = t_id | 351 self.IDsig[t_id] = t_info.signature |
| 315 self.IDsig[t_id] = t_info.signature | |
| 316 | |
| 317 end | 352 end |
| 318 channel = self.console[t_id] | 353 channel = self.console[t_id] |
| 319 if channel.minimized then | 354 if channel.minimized then |
| 320 channel:Minimize() | 355 channel:Minimize() |
| 321 else | 356 else |
| 322 channel:Maximize() | 357 channel:Maximize() |
| 323 end | 358 end |
| 324 | 359 |
| 325 if channel.enabled then -- hide or show last since Min/Max mess with visibility | 360 if channel.enabled then -- hide or show last since Min/Max mess with visibility |
| 326 --print('setchan(5a) enable') | 361 print('setchan(5a) enable') |
| 327 channel:Show() | 362 channel:Show() |
| 328 --channel:ToFront() | 363 --channel:ToFront() |
| 329 else | 364 else |
| 330 --print('setchan(5a) disable') | 365 print('setchan(5a) disable') |
| 331 channel:Hide() | 366 channel:Hide() |
| 332 end | 367 end |
| 333 --@debug@ | 368 --@debug@ |
| 334 --print('setchan(end); c:IsVisible(), c.enabled, db.enabled=', channel:IsVisible(), channel.enabled, db.enabled)--@end-debug@ | 369 print('setchan(end); c:IsVisible(), c.enabled, db.enabled=', channel:IsVisible(), channel.enabled, profile.enabled)--@end-debug@ |
| 335 return channel | 370 return channel |
| 336 end | 371 end |
| 372 | |
| 373 --- Console frame toggler | |
| 374 -- @paramsig [...] | |
| 375 -- @param ... one or more space-seperated channel keys | |
| 376 function D:Console_Toggle(input, force) | |
| 377 local profile = D.currentProfile | |
| 378 --oldprint(input) | |
| 379 local setAll | |
| 380 local search = {} | |
| 381 local key | |
| 382 local n = 0 | |
| 383 while self:GetArgs(input,1,n) and n < 255 do --should end itself when it gets nil, but | |
| 384 key, n = self:GetArgs(input,1,n) | |
| 385 | |
| 386 if self.sig[key] then | |
| 387 --print(key, self.sigID[key]) | |
| 388 insert(search, self.sigID[key]) | |
| 389 elseif self.console[tonumber(key)] then | |
| 390 --print(key, tonumber(key)) | |
| 391 insert(search, tonumber(key)) | |
| 392 end | |
| 393 | |
| 394 --oldprint(#search, key, n) | |
| 395 end | |
| 396 if #search < 1 then | |
| 397 search = self.sigID | |
| 398 setAll = true | |
| 399 end | |
| 400 if setAll then | |
| 401 --oldprint('setall', setAll) | |
| 402 profile.enabled = (not profile.enabled) and true or nil | |
| 403 if force == 0 then | |
| 404 profile.enabled = nil | |
| 405 end | |
| 406 end | |
| 407 | |
| 408 for i, id in pairs(search) do | |
| 409 --oldprint(i, id) | |
| 410 local c = self.console[id] | |
| 411 if setAll then | |
| 412 c.enabled = profile.enabled and profile.enabled or nil | |
| 413 else | |
| 414 | |
| 415 profile.enabled = true | |
| 416 c.enabled = (not c.enabled) and true or nil | |
| 417 if force == 0 then | |
| 418 c.enabled = nil | |
| 419 end | |
| 420 --oldprint(id, ' ', force, c.enabled, db.enabled) | |
| 421 end | |
| 422 | |
| 423 if c.enabled or (setAll and profile.enabled) then | |
| 424 c:Show() | |
| 425 elseif not (c.enabled and profile.enabled) then | |
| 426 c:Hide() | |
| 427 end | |
| 428 c:Save() | |
| 429 end | |
| 430 | |
| 431 if setAll then | |
| 432 if profile.enabled then | |
| 433 self:Print('toggled all consoles ON') | |
| 434 if D.console[profile.current_channel] then | |
| 435 D.console[profile.current_channel]:ToFront() | |
| 436 end | |
| 437 else | |
| 438 self:Print('toggled all consoles OFF') | |
| 439 end | |
| 440 else | |
| 441 local result = {} | |
| 442 for i, id in pairs(search) do | |
| 443 result[i] = tostring(id) .. ' = ' .. (self.console[id].enabled and 'ON' or 'OFF') | |
| 444 end | |
| 445 self:Print('toggled: '..concat(result, ', ')) | |
| 446 end | |
| 447 end |
