Mercurial > wow > devian
comparison Devian.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 | 59e047d6c5de |
| children | 137b8c55a593 |
comparison
equal
deleted
inserted
replaced
| 65:4148c90986e7 | 66:516ceb31703d |
|---|---|
| 1 --- Devian - Devian.lua | 1 --- Devian - Devian.lua |
| 2 -- @file-author@ | 2 -- @file-author@ |
| 3 -- @project-revision@ @project-hash@ | 3 -- @project-revision@ @project-hash@ |
| 4 -- @file-revision@ @file-hash@ | 4 -- @file-revision@ @file-hash@ |
| 5 if not LibStub then | 5 |
| 6 print('Something has happened...') | 6 --GLOBALS: Devian, DevCon, DevianLoadMessage |
| 7 end | 7 local ADDON, D = ... |
| 8 | |
| 9 local currentProfile | |
| 10 local playerName = UnitName("player") | |
| 11 local playerRealm = playerName .. '-' .. GetRealmName() | |
| 12 local num_dock_tabs = 0 | |
| 13 local in_workspace = false | |
| 14 --@debug@ | |
| 15 D.debugmode = true | |
| 16 --@end-debug@ | |
| 17 D.print = function(...) | |
| 18 if currentProfile and not currentProfile.workspace then | |
| 19 return | |
| 20 end | |
| 21 | |
| 22 if D.debugmode then | |
| 23 return print('Dvn', ...) | |
| 24 else | |
| 25 return function() end | |
| 26 end | |
| 27 end | |
| 28 local print = D.print | |
| 29 | |
| 30 setmetatable(D, { | |
| 31 __call = function(t,k) | |
| 32 if not k then | |
| 33 return t.in_workspace | |
| 34 end | |
| 35 | |
| 36 return function(value) | |
| 37 if value then | |
| 38 D[k] = value | |
| 39 end | |
| 40 return D[k] | |
| 41 end | |
| 42 end | |
| 43 }) | |
| 44 D.L = setmetatable({}, { | |
| 45 __index= function(t,k) | |
| 46 return k | |
| 47 end, | |
| 48 __call = function(t,k,...) | |
| 49 return string.format((t[k] or k) , ...) | |
| 50 end | |
| 51 }) | |
| 52 | |
| 8 local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@' | 53 local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@' |
| 9 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0") | 54 local D = LibStub("AceAddon-3.0"):NewAddon(D, "Devian", "AceConsole-3.0", "AceEvent-3.0") |
| 10 local D = _G.Devian | 55 local L = D.L |
| 56 _G.Devian = D | |
| 11 D:SetDefaultModuleState(false) | 57 D:SetDefaultModuleState(false) |
| 12 D.L = {} | 58 D.oldprint = getprinthandler() |
| 13 setmetatable(D.L, {__index= function(t,k) return k end, __call = function(t,k,...) return string.format((t[k] or k) , ...) end}) | 59 if not _G.oldprint then _G.oldprint = D.oldprint end |
| 14 local L = D.L | 60 |
| 15 local pairs, tostring, tonumber, ipairs, type = pairs, tostring, tonumber, ipairs, type | 61 local pairs, tostring, tonumber, ipairs, type = pairs, tostring, tonumber, ipairs, type |
| 16 local max, rand, format = math.max, math.random, string.format | 62 local max, rand, format, print = max, math.random, string.format, print |
| 17 local insert, wipe, concat = table.insert, table.wipe, table.concat | 63 local insert, wipe, concat = table.insert, table.wipe, table.concat |
| 18 local select, unpack = select, unpack | 64 local select, unpack = select, unpack |
| 19 local GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn = GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn | 65 local GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn = GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn |
| 20 local UnitName, DisableAddOn = UnitName, DisableAddOn | 66 local UnitName, DisableAddOn = UnitName, DisableAddOn |
| 21 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2 | 67 |
| 22 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() | |
| 23 local print = _G.print | |
| 24 local db | 68 local db |
| 25 local defaults = { | 69 local defaults = { |
| 26 ['global'] = {{}, {}}, | 70 global = {{}, {}}, |
| 27 ['tags'] = {}, | 71 default_channel = { |
| 28 ['channels'] = {[1] = { | |
| 29 signature = 'Main', | 72 signature = 'Main', |
| 30 index = 1, | |
| 31 x = 100, y = 800, | 73 x = 100, y = 800, |
| 32 height = 500, width = 600, | 74 height = 500, width = 600, |
| 33 enabled = true}}, | 75 enabled = true}, |
| 34 ['profiles'] = { | 76 current_profile = 1, |
| 35 {'Main', false}, | 77 main_profile = 1, |
| 36 {'Devian', true}, | 78 last_profile = 1, |
| 37 {'Turok', true}, | 79 profilesName = {}, |
| 38 {'Bam', true} | 80 profiles = { |
| 39 }, | 81 }, |
| 40 primary_channel = 1, -- the channel to which default output is sent | |
| 41 current_channel = 1, -- the front channel | |
| 42 max_channel = 1, -- the highest created channel id | |
| 43 enabled = true, -- allow enabled consoles to appear | |
| 44 load_message = "Defaults loaded.", -- messages to be displayed after reload | |
| 45 font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]], -- font info | 82 font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]], -- font info |
| 46 fontsize = 13, | 83 fontsize = 13, |
| 47 fontoutline = 'NONE', | 84 fontoutline = 'NONE', |
| 48 | 85 |
| 49 headergrad = {'VERTICAL', 0, 0, 0, 1, | 86 headergrad = {'VERTICAL', 0, 0, 0, 1, |
| 89 movement_fade_to = 0, | 126 movement_fade_to = 0, |
| 90 movement_translation_x = 25, | 127 movement_translation_x = 25, |
| 91 movement_translation_y = 25, | 128 movement_translation_y = 25, |
| 92 } | 129 } |
| 93 | 130 |
| 94 local function ScanAddOnList(cmd, ...) | 131 D.console = {} |
| 95 local list_state | 132 D.max_channel = 0 |
| 96 | 133 |
| 134 D.Profile = function (id, name) | |
| 135 | |
| 136 if name and not id and db.profilesName[name] then | |
| 137 id = db.profilesName[name] | |
| 138 print('ID located by name, |cFF00FF00'..name..'|r is |cFFFFFF00'.. id..'|r') | |
| 139 end | |
| 140 | |
| 141 if not id or not db.profiles[id] then | |
| 142 if not id then | |
| 143 id = #db.profiles+1 | |
| 144 print('Generated profile ID: |cFFFFFF00'.. id .. '|r') | |
| 145 end | |
| 146 | |
| 147 if not name or db.profilesName[name] then | |
| 148 local newName = name or (id == 1 and 'Main' or 'Profile') | |
| 149 local prefix = newName | |
| 150 local i = 2 | |
| 151 while db.profilesName[newName] do | |
| 152 i = i + 1 | |
| 153 newName = prefix .. i | |
| 154 end | |
| 155 name = newName | |
| 156 print('Generated profile name: |cFF00FF00'..newName..'|r') | |
| 157 end | |
| 158 print('Creating profile') | |
| 159 db.profilesName[name] = id | |
| 160 db.profiles[id] = { | |
| 161 name = name, | |
| 162 workspace = (id ~= 1), | |
| 163 current_channel = 1, | |
| 164 default_channel = 1, | |
| 165 num_channels = 1, | |
| 166 max_channel = 1, -- the highest created channel id | |
| 167 enabled = true, -- allow enabled consoles to appear | |
| 168 channels = { | |
| 169 { | |
| 170 index = 1, | |
| 171 signature = 'Main', | |
| 172 x = 100, y = 800, | |
| 173 height = 500, width = 600, | |
| 174 enabled = true | |
| 175 } | |
| 176 }, | |
| 177 loadouts = {}, | |
| 178 global = {}, | |
| 179 tags = {}, | |
| 180 char = { | |
| 181 [playerRealm] = {} | |
| 182 }, | |
| 183 unlisted = {} | |
| 184 } | |
| 185 end | |
| 186 | |
| 187 D.currentProfile = db.profiles[id] | |
| 188 currentProfile = D.currentProfile | |
| 189 currentProfile.char[playerRealm] = currentProfile.char[playerRealm] or {} | |
| 190 if currentProfile.workspace then | |
| 191 setprinthandler(D.Message) | |
| 192 else | |
| 193 print = function() end | |
| 194 end | |
| 195 | |
| 196 D.unlisted = currentProfile.unlisted | |
| 197 D.channels = currentProfile.channels | |
| 198 D.tags = currentProfile.tags | |
| 199 D.channelinfo = currentProfile.channels | |
| 200 D.char = currentProfile.char[playerRealm] | |
| 201 D.global = currentProfile.global | |
| 202 D.num_channels = currentProfile.num_channels | |
| 203 D.enabled = currentProfile.enabled | |
| 204 D.sig = {} | |
| 205 D.sigID = {} | |
| 206 D.IDsig = {} | |
| 207 D.dock = DevianDock | |
| 208 D.dock.buttons = D.dock.buttons or {} | |
| 209 | |
| 210 return id, name | |
| 211 end | |
| 212 | |
| 213 local targetGlobal, targetChar | |
| 214 D.Command = function (self, cmd, ...) | |
| 215 local list_id, scan_func, reload | |
| 97 local args = {} | 216 local args = {} |
| 98 local arg, n = D:GetArgs(cmd, 1) | 217 local arg, n = D:GetArgs(cmd, 1) |
| 99 while arg do | 218 while arg do |
| 100 insert(args, arg) | 219 insert(args, arg) |
| 101 arg, n = D:GetArgs(cmd,1,n) | 220 arg, n = D:GetArgs(cmd,1,n) |
| 102 end | 221 end |
| 103 local mode, tag, dest = unpack(args) | 222 local mode, tag, dest = unpack(args) |
| 104 | 223 |
| 105 | |
| 106 -- no args, toggle ui | 224 -- no args, toggle ui |
| 107 if mode == 'stack' then | 225 if mode == 'stack' then |
| 108 if db.workspace == 1 then | |
| 109 return D:Print(L['Need devmode']) | |
| 110 end | |
| 111 return D:StackFrames() | 226 return D:StackFrames() |
| 112 elseif mode == 'grid' then | 227 elseif mode == 'grid' then |
| 113 if db.workspace == 1 then | |
| 114 return D:Print(L['Need devmode']) | |
| 115 end | |
| 116 return D:DistributeFrames() | 228 return D:DistributeFrames() |
| 117 elseif mode == 'tag' then -- tagging | 229 elseif mode == 'tag' then -- tagging |
| 118 if db.workspace == 1 then | 230 return D.Tag(self, tag, dest) |
| 119 return D:Print(L['Need devmode']) | 231 elseif tonumber(mode) ~= nil or mode == 'save' then |
| 120 end | 232 -- either a number of the save command |
| 121 | 233 if mode == 'save' then |
| 122 local sig | 234 list_id = tonumber(tag) |
| 123 if tag ~= nil and dest ~= nil then | 235 if list_id == nil then |
| 124 --@debug@ | 236 D:Print(L('Invalid ID from arg', tag)) |
| 125 --print(tag, dest) | 237 end |
| 126 --@end-debug@ | 238 D.Profile(list_id, dest) |
| 127 | 239 scan_func = D.Save |
| 128 -- convert to ID | 240 D:Print("Profile |cFFFFFF00".. list_id .."|r saved.") |
| 129 if tonumber(dest) == nil then | |
| 130 if D.sigID[dest] then | |
| 131 dest = db.channels[D.sigID[dest]].index | |
| 132 else | |
| 133 sig = dest | |
| 134 end | |
| 135 else | |
| 136 dest = tonumber(dest) | |
| 137 end | |
| 138 --@debug@ | |
| 139 --print('2 tag,dest,sig', tag, dest, sig)--@end-debug@ | |
| 140 | |
| 141 -- make a new channel? | |
| 142 local channel | |
| 143 if not D.db.channels[dest] then | |
| 144 dest = D.max_channel + 1 | |
| 145 D:Print(L('New channel created', sig and (dest..':'..sig) or dest )) | |
| 146 channel = D:SetChannel(sig or tag,dest) | |
| 147 else | |
| 148 | |
| 149 channel = D.db.channels[dest] | |
| 150 end | |
| 151 --@debug@ | |
| 152 --print('3 tag,dest,channel.sig=',tag, dest, channel.signature)--@end-debug@ | |
| 153 | |
| 154 if not db.tags[tag] then -- no tag table? | |
| 155 db.tags[tag] = {} | |
| 156 end | |
| 157 | |
| 158 if db.tags[tag][dest] then -- is tag set? | |
| 159 db.tags[tag][dest] = nil | |
| 160 D:Print(L('Tag removed from channel', tag, db.channels[dest].index, db.channels[dest].signature)) | |
| 161 else | |
| 162 db.tags[tag][dest] = dest | |
| 163 D:Print(L('Tag added to channel', tag, db.channels[dest].index, db.channels[dest].signature)) | |
| 164 end | |
| 165 D:UpdateDock() | |
| 166 else | 241 else |
| 167 D:Print(L['Command tag help']) | 242 |
| 168 end | 243 DevianLoadMessage = "Switched profiles." |
| 169 return | 244 |
| 170 elseif tonumber(mode) ~= nil or mode == 'save' then | 245 list_id = tonumber(mode) |
| 171 -- iterating for something | 246 if list_id ~= db.main_profile then |
| 172 if mode == 'save' then | 247 db.last_profile = list_id |
| 173 if tonumber(tag) == nil then | 248 end |
| 174 T:Print(L('Invalid ID from arg', tag)) | 249 db.current_profile = list_id |
| 175 end | 250 scan_func = D.Load |
| 176 list_state = tonumber(tag) | |
| 177 else | |
| 178 list_state = tonumber(mode) | |
| 179 db.workspace = list_state | |
| 180 if list_state ~= 1 then | |
| 181 db.last_workspace = list_state | |
| 182 end | |
| 183 | |
| 184 end | 251 end |
| 185 elseif mode == nil then | 252 elseif mode == nil then |
| 186 list_state = (db.workspace == 1) and db.last_workspace or 1 | 253 list_id = (db.current_profile ~= db.main_profile) and db.main_profile or db.last_profile |
| 187 db.workspace = list_state | 254 DevianLoadMessage = "Switched between main and recent profile ("..db.current_profile..' and '..list_id..')' |
| 255 db.current_profile = list_id | |
| 256 scan_func = D.Load | |
| 188 else | 257 else |
| 189 return D:PrintHelp() | 258 return D:PrintHelp() |
| 190 end | 259 end |
| 191 | 260 targetGlobal = db.profiles[list_id].global |
| 192 -- start the iterating | 261 targetChar = db.profiles[list_id].char[playerRealm] |
| 193 if not db[PLAYER_REALM][list_state] then | 262 |
| 194 db[PLAYER_REALM][list_state] = {} | 263 if scan_func then |
| 195 end | 264 for id, name, enableState, globalState in D.Addons() do |
| 196 if not db.global[list_state] then | 265 scan_func(id, name, enableState, globalState) |
| 197 db.global[list_state] = {} | 266 end |
| 198 end | 267 end |
| 199 | 268 |
| 200 local char_list, global_list = db[PLAYER_REALM][list_state], db.global[list_state] | 269 if scan_func == D.Load then |
| 270 ReloadUI() | |
| 271 end | |
| 272 D.Profile(db.current_profile) | |
| 273 end | |
| 274 | |
| 275 D.Addons = function() | |
| 201 local playername = UnitName("player") | 276 local playername = UnitName("player") |
| 202 | 277 return function(n, i) |
| 203 for i = 1, GetNumAddOns() do | 278 if i >= n then |
| 279 return nil | |
| 280 end | |
| 281 | |
| 282 i = i + 1 | |
| 204 local name = GetAddOnInfo(i) | 283 local name = GetAddOnInfo(i) |
| 205 local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i) | 284 local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i) |
| 206 | 285 return i, name, enableState, globalState |
| 207 if mode == 'save' then | 286 end, GetNumAddOns(), 0 |
| 208 char_list[name] = enableState | 287 end |
| 209 global_list[name] = globalState | 288 |
| 289 D.Load = function(id, name, charState, globalState) | |
| 290 if targetChar[name] or targetGlobal[name] then | |
| 291 if targetGlobal[name] == 2 then | |
| 292 EnableAddOn(id, true) | |
| 293 elseif targetChar[name] == 2 then | |
| 294 EnableAddOn(id, playerName) | |
| 210 else | 295 else |
| 211 if char_list[name] or global_list[name] then | 296 DisableAddOn(id, playerName) |
| 212 if char_list[name] ~= 0 and global_list[name] ~= 0 then | 297 end |
| 213 local value = false | 298 print('load', name, 'global =', targetGlobal[name], 'char =', targetChar[name]) |
| 214 if char_list[name] == 2 and global_list[name] == 1 then | |
| 215 value = UnitName("player") | |
| 216 elseif global_list[name] == 2 then | |
| 217 value = true | |
| 218 end | |
| 219 --print('EnableAddOn(', i, ',', value,')') | |
| 220 EnableAddOn(i, value) | |
| 221 else | |
| 222 local value = true | |
| 223 if char_list[name] == 2 and global_list[name] == 1 then | |
| 224 value = UnitName("player") | |
| 225 end | |
| 226 --print('DisableAddOn(', i, ',', value,')') | |
| 227 DisableAddOn(i,value) | |
| 228 end | |
| 229 elseif mode ~= 'save' then | |
| 230 if type(db.unlisted) ~= 'table' then | |
| 231 db.unlisted = {} | |
| 232 end | |
| 233 insert(db.unlisted, name) | |
| 234 end | |
| 235 | |
| 236 end | |
| 237 end | |
| 238 | |
| 239 if mode ~= 'save' then | |
| 240 db.load_message = (mode == nil) and L("Toggled to profile", list_state) or L('Switched to profile number', list_state) | |
| 241 ReloadUI() | |
| 242 else | 299 else |
| 243 | 300 tinsert(D.unlisted, name) |
| 244 if list_state == 1 then | 301 end |
| 245 D:Print(L['Profile main saved']) | 302 end |
| 303 D.Save = function(id, name, charState, globalState) | |
| 304 print('save', id, name, charState, globalState) | |
| 305 targetGlobal[name] = globalState | |
| 306 targetChar[name] = charState | |
| 307 end | |
| 308 | |
| 309 D.Tag = function(self, tag, dest) | |
| 310 local sig | |
| 311 if tag ~= nil and dest ~= nil then | |
| 312 --@debug@ | |
| 313 --print(tag, dest) | |
| 314 --@end-debug@ | |
| 315 | |
| 316 -- convert to ID | |
| 317 if tonumber(dest) == nil then | |
| 318 if D.sigID[dest] then | |
| 319 dest = currentProfile.channels[D.sigID[dest]].index | |
| 320 else | |
| 321 sig = dest | |
| 322 end | |
| 246 else | 323 else |
| 247 db.last_workspace = list_state | 324 dest = tonumber(dest) |
| 248 D:Print(L('Profile number saved', list_state, list_state)) | 325 end |
| 249 end | 326 --@debug@ |
| 327 --print('2 tag,dest,sig', tag, dest, sig)--@end-debug@ | |
| 328 | |
| 329 -- make a new channel? | |
| 330 local channel | |
| 331 if not currentProfile.channels[dest] then | |
| 332 dest = D.max_channel + 1 | |
| 333 D:Print(L('New channel created', sig and (dest..':'..sig) or dest )) | |
| 334 channel = D:SetChannel(sig or tag,dest) | |
| 335 else | |
| 336 channel = D.channels[dest] | |
| 337 end | |
| 338 --@debug@ | |
| 339 --print('3 tag,dest,channel.sig=',tag, dest, channel.signature)--@end-debug@ | |
| 340 | |
| 341 if not currentProfile.tags[tag] then -- no tag table? | |
| 342 currentProfile.tags[tag] = {} | |
| 343 end | |
| 344 | |
| 345 if currentProfile.tags[tag][dest] then -- is tag set? | |
| 346 currentProfile.tags[tag][dest] = nil | |
| 347 D:Print(L('Tag removed from channel', tag, currentProfile.channels[dest].index, currentProfile.channels[dest].signature)) | |
| 348 else | |
| 349 currentProfile.tags[tag][dest] = dest | |
| 350 D:Print(L('Tag added to channel', tag, currentProfile.channels[dest].index, currentProfile.channels[dest].signature)) | |
| 351 end | |
| 352 D:UpdateDock() | |
| 353 else | |
| 354 D:Print(L['Command tag help']) | |
| 250 end | 355 end |
| 251 end | 356 end |
| 252 | 357 |
| 253 | 358 |
| 254 | 359 |
| 255 --- Creates a Devian-style output. | 360 --- Creates a Devian-style output. |
| 256 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print() | 361 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print() |
| 257 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint(). | 362 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint(). |
| 258 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel. | 363 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel. |
| 259 -- @param ... Output contents. | 364 -- @param ... Output contents. |
| 260 local function Message(prefix, ...) | 365 function D.Message(prefix, ...) |
| 261 if db.workspace == 1 then | 366 if currentProfile.workspace then |
| 262 return D.oldprint(prefix, ...) | 367 return D.oldprint(prefix, ...) |
| 263 end | 368 end |
| 264 prefix = tostring(prefix) | 369 prefix = tostring(prefix) |
| 265 if prefix == nil then | 370 if prefix == nil then |
| 266 prefix = 'nil*' | 371 prefix = 'nil*' |
| 347 | 452 |
| 348 D:Print("|cFFFFFF00/resetdvn|r", "- Resets all but profile data SavedVariables.") | 453 D:Print("|cFFFFFF00/resetdvn|r", "- Resets all but profile data SavedVariables.") |
| 349 D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.") | 454 D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.") |
| 350 end | 455 end |
| 351 | 456 |
| 352 local dot1, dot2 = CreateFrame('Frame', nil, UIParent), CreateFrame('Frame', nil, UIParent) | 457 local blocked = {profiles = true, debugmode = true} |
| 353 dot1:SetSize(5,5) | 458 D.SetDefaults = function() |
| 354 dot1:SetFrameStrata('TOOLTIP') | 459 for k,v in pairs(DevianDB) do |
| 355 local a = dot1:CreateTexture('fill', nil) | 460 if not blocked[k] then |
| 356 a:SetAllPoints(dot1) | 461 DevianDB[k] = nil |
| 357 a:SetTexture(1,0,0,1) | 462 end |
| 358 dot2:SetSize(5,5) | 463 end |
| 359 dot2:SetFrameStrata('TOOLTIP') | 464 for k,v in pairs(defaults) do |
| 360 a = dot2:CreateTexture('fill', nil) | 465 if not blocked[k] then |
| 361 a:SetAllPoints(dot2) | 466 DevianDB[k] = v |
| 362 a:SetTexture(0,1,0,1) | 467 end |
| 363 | 468 end |
| 364 local OnStartedMoving = function() | 469 DevianLoadMessage = "Non-user SavedVars have been reset." |
| 365 for k, v in pairs(D.console) do | 470 ReloadUI() |
| 366 if v.enabled then | 471 end |
| 367 v.moveFade:Stop() | 472 D.SetDefaultsAll = function () |
| 368 local F1 = v.moveFade.alphaOut | 473 DevianDB = nil |
| 369 F1:SetFromAlpha(db.movement_fade_from) | 474 DevianLoadMessage = "All SavedVars wiped." |
| 370 F1:SetToAlpha(db.movement_fade_to) | 475 ReloadUI() |
| 371 F1:SetDuration(db.movement_fade_time) | 476 end |
| 372 v.moveFade:Play() | 477 D.ConfigCommand = function(input) |
| 373 v:EnableMouse(false) | 478 if not self.config then |
| 374 end | 479 self.config = DevCon |
| 375 end | 480 self:EnableModule("Config") |
| 376 end | 481 end |
| 377 | 482 self.modules.Config:ChatCommand(input) |
| 378 local OnStoppedMoving = function() | 483 end |
| 379 for k, v in pairs(D.console) do | |
| 380 if v.enabled then | |
| 381 v.moveFade:Stop() | |
| 382 local F1 = v.moveFade.alphaOut | |
| 383 F1:SetToAlpha(db.movement_fade_from) | |
| 384 F1:SetFromAlpha(db.movement_fade_to) | |
| 385 F1:SetDuration(db.movement_fade_time) | |
| 386 v.moveFade:Play() | |
| 387 v:EnableMouse(true) | |
| 388 end | |
| 389 end | |
| 390 end | |
| 391 | |
| 392 | 484 |
| 393 function D:OnEnable() | 485 function D:OnEnable() |
| 394 | 486 |
| 395 if db.unlisted and #db.unlisted > 0 then | |
| 396 D:Print('New AddOns have been found since the last profile update: '.. concat(db.unlisted, ', ')) | |
| 397 wipe(db.unlisted) | |
| 398 end | |
| 399 | |
| 400 if db.workspace == 1 then | |
| 401 D:Print(L('Devian loaded on standby',MAJOR, MINOR)) | |
| 402 else | |
| 403 D:Print(L('Devian loaded in workspace', MAJOR, MINOR, db.workspace)) | |
| 404 -- movement fading | |
| 405 if db.movement_fade then | |
| 406 | |
| 407 self:RegisterEvent('PLAYER_STARTED_MOVING', OnStartedMoving) | |
| 408 self:RegisterEvent('PLAYER_STOPPED_MOVING', OnStoppedMoving) | |
| 409 end | |
| 410 end | |
| 411 | |
| 412 --@debug@ | |
| 413 self:RegisterChatCommand("dvg", function(input) | |
| 414 if not self.config then | |
| 415 self.config = DevCon | |
| 416 self:EnableModule("Config") | |
| 417 end | |
| 418 self.modules.Config:ChatCommand(input) | |
| 419 end) | |
| 420 --@end-debug@ | |
| 421 | |
| 422 end | |
| 423 | |
| 424 function D:OnInitialize() | |
| 425 -- commands | 487 -- commands |
| 426 self:RegisterChatCommand("cleandvn", function(args) | |
| 427 DevianDB = nil | |
| 428 DevianDB = { | |
| 429 load_message = "All SavedVars wiped." | |
| 430 } | |
| 431 ReloadUI() | |
| 432 end) | |
| 433 local blocked = {global = true, channels = true, tags = true, [PLAYER_REALM] = true} | |
| 434 self:RegisterChatCommand("resetdvn", function(args) | |
| 435 for k,v in pairs(DevianDB) do | |
| 436 if not blocked[k] then | |
| 437 DevianDB[k] = nil | |
| 438 end | |
| 439 end | |
| 440 for k,v in pairs(defaults) do | |
| 441 if not blocked[k] then | |
| 442 DevianDB[k] = v | |
| 443 end | |
| 444 end | |
| 445 DevianDB.load_message = "Non-user SavedVars have been reset." | |
| 446 ReloadUI() | |
| 447 end) | |
| 448 local cmdlist = { | 488 local cmdlist = { |
| 449 ['dvn'] = ScanAddOnList, | 489 ['dvn'] = "Command", |
| 450 ['devian'] = ScanAddOnList, | 490 ['devian'] = "Command", |
| 451 ['dvc'] = "Console_Toggle", | 491 ['dvc'] = "Console_Toggle", |
| 492 ['cleandvn'] = "SetDefaultsAll", | |
| 493 ['resetdvn'] = "SetDefaults", | |
| 494 ['dvg'] = "ConfigCommand" | |
| 452 } | 495 } |
| 453 for cmd, func in pairs(cmdlist) do | 496 for cmd, func in pairs(cmdlist) do |
| 454 self:RegisterChatCommand(cmd, func, true) | 497 self:RegisterChatCommand(cmd, func, true) |
| 455 end | 498 end |
| 499 end | |
| 500 | |
| 501 function D:OnInitialize() | |
| 456 | 502 |
| 457 -- pull defaults | 503 -- pull defaults |
| 458 if not _G.DevianDB then | 504 if not _G.DevianDB then |
| 459 _G.DevianDB = defaults | 505 _G.DevianDB = defaults |
| 460 end | 506 end |
| 461 db = _G.DevianDB | 507 db = _G.DevianDB |
| 462 self.db = db | 508 self.db = db |
| 463 self.tags = db.tags | 509 |
| 464 self.channelinfo = db.channels | 510 --- |
| 465 | 511 if DevianLoadMessage then |
| 466 if not db[PLAYER_REALM] then | 512 D:Print(DevianLoadMessage) |
| 467 db[PLAYER_REALM] = {[WORKSPACE_ON] = {}, [WORKSPACE_OFF] = {}} | 513 DevianLoadMessage = nil |
| 468 end | 514 end |
| 469 | 515 |
| 470 if db.load_message then | 516 |
| 471 D:Print(db.load_message) | 517 --- initialize the current profile |
| 472 db.load_message = nil | 518 local id, name = D.Profile(db.current_profile or 1) |
| 473 end | 519 D:Print('Using profile |cFFFFFF00'.. id ..'|r: |cFF00FF00'..currentProfile.name..'|r') |
| 474 D.oldprint = getprinthandler() | 520 if currentProfile.workspace then |
| 475 if not _G.oldprint then | 521 D:Print('Workspace: '.. (#currentProfile.channels) .. ' channels, ' .. #currentProfile.tags .. ' tags.') |
| 476 _G.oldprint = D.oldprint | 522 D:Print('Default channel: |cFFFFFF00'..currentProfile.default_channel..'|r: |cFF00FFFF'.. D.channels[currentProfile.default_channel].signature..'|r') |
| 477 end | 523 end |
| 478 | 524 |
| 479 -- Stop here in game mode | 525 for i, cinfo in pairs(D.channels) do |
| 480 if db.workspace == 1 then | |
| 481 return | |
| 482 end | |
| 483 ----------------------------------------------------------------------- | |
| 484 self.db = db | |
| 485 self.channels = db.channels | |
| 486 self.max_channel = 0 | |
| 487 self.num_channels = 0 | |
| 488 self.console = {} | |
| 489 self.sig = {} | |
| 490 self.sigID = {} | |
| 491 self.IDsig = {} | |
| 492 self.dock = DevianDock | |
| 493 self.dock.buttons = {} | |
| 494 for i, cinfo in pairs(db.channels) do | |
| 495 i = tonumber(i) | 526 i = tonumber(i) |
| 496 if not self.primary_channel then | 527 if not D.primary_channel then |
| 497 self.primary_channel = i | 528 D.primary_channel = i |
| 498 end | 529 end |
| 499 self:SetChannel(cinfo, i) | 530 D:SetChannel(cinfo, i) |
| 500 self.max_channel = max(i, self.max_channel) | 531 D.num_channels = D.num_channels + 1 |
| 501 self.num_channels = self.num_channels + 1 | 532 end |
| 502 end | 533 |
| 503 | 534 D.max_channel = max(D.max_channel, currentProfile.max_channel) |
| 504 if self.console[db.current_channel] then | 535 if currentProfile.max_channel < D.max_channel then |
| 505 print('bringing', self.console[db.current_channel].signature, 'to the front') | 536 for i = currentProfile.max_channel, D.max_channel do |
| 506 self.console[db.current_channel]:ToFront() | 537 D.console[i]:Hide() |
| 507 -- bring the current channel to the front | 538 end |
| 508 end | 539 end |
| 509 DevianDock:Show() | 540 |
| 510 self:UpdateDock() | 541 if currentProfile.workspace then |
| 511 setprinthandler(Message) | 542 if D.console[currentProfile.current_channel] then |
| 512 print = function(...) | 543 print('bringing', D.console[currentProfile.current_channel].signature, 'to the front') |
| 513 _G.print('Dvn', ...) | 544 D.console[currentProfile.current_channel]:ToFront() |
| 514 end | 545 -- bring the current channel to the front |
| 515 end | 546 end |
| 516 | 547 DevianDock:Show() |
| 517 --- Console frame toggler | 548 D:UpdateDock() |
| 518 -- @paramsig [...] | 549 end |
| 519 -- @param ... one or more space-seperated channel keys | 550 end |
| 520 function D:Console_Toggle(input, force) | |
| 521 --oldprint(input) | |
| 522 local setAll | |
| 523 if db.workspace == 1 then | |
| 524 return self:Print(MSG_NEED_DEV_MODE) | |
| 525 end | |
| 526 local search = {} | |
| 527 local key | |
| 528 local n = 0 | |
| 529 while self:GetArgs(input,1,n) and n < 255 do --should end itself when it gets nil, but | |
| 530 key, n = self:GetArgs(input,1,n) | |
| 531 | |
| 532 if self.sig[key] then | |
| 533 --print(key, self.sigID[key]) | |
| 534 insert(search, self.sigID[key]) | |
| 535 elseif self.console[tonumber(key)] then | |
| 536 --print(key, tonumber(key)) | |
| 537 insert(search, tonumber(key)) | |
| 538 end | |
| 539 | |
| 540 --oldprint(#search, key, n) | |
| 541 end | |
| 542 if #search < 1 then | |
| 543 search = self.sigID | |
| 544 setAll = true | |
| 545 end | |
| 546 if setAll then | |
| 547 --oldprint('setall', setAll) | |
| 548 db.enabled = (not db.enabled) and true or nil | |
| 549 if force == 0 then | |
| 550 db.enabled = nil | |
| 551 end | |
| 552 end | |
| 553 | |
| 554 for i, id in pairs(search) do | |
| 555 --oldprint(i, id) | |
| 556 local c = self.console[id] | |
| 557 if setAll then | |
| 558 c.enabled = db.enabled and db.enabled or nil | |
| 559 else | |
| 560 | |
| 561 db.enabled = true | |
| 562 c.enabled = (not c.enabled) and true or nil | |
| 563 if force == 0 then | |
| 564 c.enabled = nil | |
| 565 end | |
| 566 --oldprint(id, ' ', force, c.enabled, db.enabled) | |
| 567 end | |
| 568 | |
| 569 if c.enabled or (setAll and db.enabled) then | |
| 570 c:Show() | |
| 571 elseif not (c.enabled and db.enabled) then | |
| 572 c:Hide() | |
| 573 end | |
| 574 c:Save() | |
| 575 end | |
| 576 | |
| 577 if setAll then | |
| 578 if db.enabled then | |
| 579 self:Print('toggled all consoles ON') | |
| 580 if D.console[db.current_channel] then | |
| 581 oldprint('push', D.console[db.current_channel].signature, 'to the front') | |
| 582 D.console[db.current_channel]:ToFront() | |
| 583 end | |
| 584 else | |
| 585 self:Print('toggled all consoles OFF') | |
| 586 end | |
| 587 else | |
| 588 local result = {} | |
| 589 for i, id in pairs(search) do | |
| 590 result[i] = tostring(id) .. ' = ' .. (self.console[id].enabled and 'ON' or 'OFF') | |
| 591 end | |
| 592 self:Print('toggled: '..concat(result, ', ')) | |
| 593 end | |
| 594 end |
