Nenue@0: -- User: Krakyn Nenue@0: -- Created: 11/30/2015 7:46 AM Nenue@0: if not LibStub then Nenue@0: print('Something has happened...') Nenue@0: end Nenue@0: Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0") Nenue@0: local D = _G.Devian Nenue@0: local STATE_LOW, STATE_HIGH = 1, 2 Nenue@0: local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() Nenue@4: local DEVIAN_FRAME = DevianConsole Nenue@4: local cherry = false Nenue@7: local print = function(...) Nenue@7: _G.print('DVN', ...) Nenue@7: end Nenue@9: local db Nenue@9: Nenue@4: Nenue@4: function D:SavePos(x,y) Nenue@7: db.y = (DEVIAN_FRAME:GetTop() - GetScreenHeight()) Nenue@4: db.x = DEVIAN_FRAME:GetLeft() Nenue@4: db.width = DEVIAN_FRAME:GetWidth() Nenue@7: if not DEVIAN_FRAME.minimized then Nenue@7: db.height = DEVIAN_FRAME:GetHeight() Nenue@7: end Nenue@7: Nenue@7: print(db.y) Nenue@7: DEVIAN_FRAME:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', db.x, db.y) Nenue@4: end Nenue@0: Nenue@0: local ScanAddOnList = function(args) Nenue@0: local list_state Nenue@0: Nenue@0: local mode = tonumber(args:match('^%d$')) Nenue@0: Nenue@0: print('ScanAddOnList(', mode, ')') Nenue@0: if mode == nil then Nenue@0: list_state = db.enabled and STATE_LOW or STATE_HIGH Nenue@0: db.enabled = (db.enabled == false) and true or false Nenue@0: print(list_state, db.enabled) Nenue@0: Nenue@0: if list_state == STATE_LOW then Nenue@0: BNSetDND(true) Nenue@0: end Nenue@0: Nenue@0: else Nenue@0: if mode > 2 then Nenue@0: print('ScanAddOnList(',mode,'): Something has happened.') Nenue@0: return Nenue@0: end Nenue@0: list_state = mode == STATE_LOW and STATE_LOW or STATE_HIGH Nenue@0: Nenue@0: if not db.chat_size then Nenue@0: db.chat_size = {} Nenue@0: end Nenue@0: if mode == STATE_LOW or mode == STATE_HIGH then Nenue@0: db.chat_size[list_state] = ChatFrame1:GetHeight() Nenue@0: end Nenue@0: Nenue@0: end Nenue@0: local char_list, global_list = db[PLAYER_REALM][list_state], db.global[list_state] Nenue@0: Nenue@0: local playername = UnitName("player") Nenue@0: Nenue@0: for i = 1, GetNumAddOns() do Nenue@0: local name = GetAddOnInfo(i) Nenue@0: local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i) Nenue@0: Nenue@0: if mode == STATE_LOW or mode == STATE_HIGH then Nenue@0: char_list[name] = enableState Nenue@0: global_list[name] = globalState Nenue@0: else Nenue@0: Nenue@0: if char_list[name] ~= 0 and global_list[name] ~= 0 then Nenue@0: local value = false Nenue@0: if char_list[name] == 2 and global_list[name] == 1 then Nenue@0: value = UnitName("player") Nenue@0: elseif global_list[name] == 2 then Nenue@0: value = true Nenue@0: end Nenue@0: print('EnableAddOn(', i, ',', value,')') Nenue@0: EnableAddOn(i, value) Nenue@0: else Nenue@0: local value = true Nenue@0: if char_list[name] == 2 and global_list[name] == 1 then Nenue@0: value = UnitName("player") Nenue@0: end Nenue@0: print('DisableAddOn(', i, ',', value,')') Nenue@0: DisableAddOn(i,value) Nenue@0: end Nenue@0: Nenue@0: end Nenue@0: end Nenue@0: Nenue@0: if mode == nil then Nenue@0: ReloadUI() Nenue@0: end Nenue@0: if mode == STATE_LOW then Nenue@0: D:Print('Developement AddOn list saved.') Nenue@0: else Nenue@0: D:Print('Standard AddOn list saved.') Nenue@0: end Nenue@0: end Nenue@0: Nenue@0: -- Debug info Nenue@0: local function CreateMessenger() Nenue@11: if db.console == true and db.enabled == false then Nenue@4: DEVIAN_FRAME:Show() Nenue@0: end Nenue@0: Nenue@4: Nenue@0: local f = DEVIAN_FRAME Nenue@4: --[[ Nenue@0: f.backdrop = f:CreateTexture('backdrop', 'BACKGROUND') Nenue@0: f.backdrop:SetTexture(1,1,1,1) Nenue@0: f.backdrop:SetGradient('HORIZONTAL', 0.2, 0.2, 0.2, 1, 1, 1) Nenue@0: f.backdrop:SetBlendMode('MOD') Nenue@0: f.backdrop:SetAllPoints(f) Nenue@0: f:AddMessage('init a thing') Nenue@0: Nenue@0: f:EnableMouseWheel(true) Nenue@0: f:EnableKeyboard(true) Nenue@0: f:SetScript('OnMouseWheel', function (self, delta) Nenue@0: end) Nenue@0: Nenue@0: f:ScrollToBottom() Nenue@2: f:SetMaxLines(500) Nenue@4: --]] Nenue@4: f.console:SetInsertMode('BOTTOM') Nenue@7: f:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', db.x, db.y) Nenue@4: f:SetSize(db.width, db.height) Nenue@4: f:Lower() Nenue@0: Nenue@4: f.console:SetFading(false) Nenue@4: f.console:SetTimeVisible(2147483647) Nenue@5: f.console:SetFont(db.font, db.fontsize, db.fontoutline) Nenue@4: --f:SetJustifyH('LEFT') Nenue@0: Nenue@0: Nenue@0: D.debug_init = true Nenue@0: end Nenue@7: function D:ToggleMinMax() Nenue@7: if DEVIAN_FRAME.minimized then Nenue@7: self:Maximize() Nenue@7: else Nenue@7: self:Minimize() Nenue@7: end Nenue@7: end Nenue@7: function D:Minimize() Nenue@7: DEVIAN_FRAME:SetHeight(20) Nenue@7: DEVIAN_FRAME.minimized = true Nenue@7: DEVIAN_FRAME:SetMaxResize(GetScreenWidth(),20) Nenue@7: return DEVIAN_FRAME.console:Hide() Nenue@7: end Nenue@7: function D:Maximize() Nenue@7: DEVIAN_FRAME:SetHeight(db.height) Nenue@7: DEVIAN_FRAME.minimized = nil Nenue@7: DEVIAN_FRAME:SetMaxResize(GetScreenWidth(),GetScreenHeight()) Nenue@7: return DEVIAN_FRAME.console:Show() Nenue@7: end Nenue@0: Nenue@0: local prefix_cache = {} Nenue@0: local function Message(prefix, ...) Nenue@1: if prefix == nil then Nenue@1: oldprint('Tried to print nothing.') Nenue@1: return Nenue@1: end Nenue@9: Nenue@9: -- color me timbers Nenue@9: local pcolor Nenue@9: if db.tags[prefix] then Nenue@9: pcolor = db.tags[prefix] Nenue@9: elseif not prefix_cache[prefix] then Nenue@0: local c = {0, 0, 0 } Nenue@0: local max = string.len(prefix) Nenue@0: for i = 1, max, 3 do Nenue@0: for k, v in ipairs(c) do Nenue@0: local j = i + (k - 1) Nenue@0: c[k] = c[k] + (j <= max and string.byte(prefix,j) or 0) Nenue@0: end Nenue@0: end Nenue@0: for k,v in ipairs(c) do Nenue@0: c[k] = c[k] % 255 Nenue@0: if c[k] < 64 then Nenue@0: c[k] = 0 Nenue@0: elseif c[k] > 127 then Nenue@0: c[k] = 255 Nenue@0: end Nenue@0: end Nenue@0: prefix_cache[prefix] = string.format('%02X%02X%02X', unpack(c)) Nenue@0: end Nenue@0: Nenue@0: local buffer = {'|cFF'.. prefix_cache[prefix]..prefix ..'|r'} Nenue@0: for i = 1, select('#',...) do Nenue@0: local var = select(i, ...) Nenue@0: Nenue@0: if type(var) == 'table' then Nenue@0: var = '' Nenue@0: elseif type(var) == 'boolean' then Nenue@0: var = var and 'true' or 'false' Nenue@0: elseif type(var) == 'function' then Nenue@0: var = '' Nenue@0: elseif type(var) == 'nil' then Nenue@0: var = 'nil' Nenue@0: end Nenue@0: Nenue@0: table.insert(buffer, var) Nenue@0: end Nenue@4: DEVIAN_FRAME.console:AddMessage(table.concat(buffer, ' ')) Nenue@0: table.wipe(buffer) Nenue@0: end Nenue@0: Nenue@0: function D:OnEnable() Nenue@11: if db.enabled == true then Nenue@0: D:Print('Standard AddOn list active. Type /dvn to switch to development mode.') Nenue@0: else Nenue@0: D:Print('Development AddOn list active. Type /dvn to revert to regular operation.') Nenue@0: end Nenue@0: end Nenue@0: Nenue@5: Nenue@0: function D:OnInitialize() Nenue@9: if not _G.DevianDB then Nenue@9: _G.DevianDB = { Nenue@9: ['global'] = {[STATE_LOW] = {}, [STATE_HIGH] = {}}, Nenue@9: ['tags'] = {}, Nenue@9: console = true, Nenue@9: dnd_status = true, Nenue@9: dnd_message = "Debugging. Your messages may get eaten.", Nenue@9: x = 100, Nenue@9: y = 800, Nenue@9: height = 500, Nenue@9: width = 600, Nenue@9: font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]], Nenue@9: fontsize = 13, Nenue@9: fontoutline = 'NONE', Nenue@9: } Nenue@9: cherry = "This is probably the first time, so:\n /dvn 2 to save your regular addon list\n /dvn 1 to save your development addon list\n /dvn to switch between the two\n /dvc to toggle print() frame" Nenue@9: end Nenue@9: db = _G.DevianDB Nenue@0: Nenue@9: print(PLAYER_REALM) Nenue@0: if not db[PLAYER_REALM] then Nenue@9: db[PLAYER_REALM] = {[STATE_LOW] = {}, [STATE_HIGH] = {}} Nenue@0: if not cherry then Nenue@0: cherry = "This character didn't have an AddOn table." Nenue@0: end Nenue@0: end Nenue@0: Nenue@0: -- inform the user if we have a virgin data table Nenue@0: if cherry then Nenue@0: D:Print(cherry) Nenue@0: end Nenue@0: Nenue@0: -- replace print handler and make the original available in global if possible Nenue@0: Nenue@0: CreateMessenger() Nenue@0: D.oldprint = getprinthandler() Nenue@0: if not _G.oldprint then Nenue@0: _G.oldprint = D.oldprint Nenue@0: end Nenue@0: setprinthandler(Message) Nenue@0: self:RegisterChatCommand("dvn", ScanAddOnList) Nenue@0: self:RegisterChatCommand("dvc", function(args) Nenue@9: db.console = (not db.console) and true or nil Nenue@0: if db.console then Nenue@0: DEVIAN_FRAME:Show() Nenue@5: D:Maximize() Nenue@0: else Nenue@0: DEVIAN_FRAME:Hide() Nenue@0: end Nenue@0: end) Nenue@0: Nenue@0: print('Master! I am here.') Nenue@0: end