Mercurial > wow > devian
view Console.lua @ 111:5c591d9b4029 tip
Added tag v8.0.1-20181807-1 for changeset 930922e1ec5b
author | Nenue |
---|---|
date | Wed, 18 Jul 2018 15:02:50 -0400 |
parents | 7a36f5a92f0a |
children |
line wrap: on
line source
-- Mixin for console local _, D = ... DevianConsoleMixin = {} local print = function(...) print('Dvn', ...) end function D.IterateChannels(callback, sender) for index, channel in ipairs(D.console) do if channel ~= sender then callback(channel) end end end function DevianConsoleMixin:OnLoad() self:SetMaxResize(GetScreenWidth(), GetScreenHeight()) self:SetMinResize(100, 24) self:EnableMouse(true) self:RegisterForDrag('LeftButton') self:SetMovable(true) self:SetResizable(true) self:SetClampedToScreen(true) self.out:SetFont("Interface\\Addons\\Devian\\font\\SourceCodePro-Regular.ttf", 13, 'NORMAL') self.out:SetJustifyH('LEFT') self.out:SetFading(false) self.out:SetMaxLines(2048) self:RegisterEvent('PLAYER_STARTED_MOVING') self:RegisterEvent('PLAYER_STOPPED_MOVING') self:RegisterEvent('PLAYER_ENTERING_WORLD') UIDropDownMenu_Initialize(self.DropdownFrame, function() local info = UIDropDownMenu_CreateInfo() info.text = 'Pin' info.func = function() self:Pin() end info.isNotRadio = true info.checked = (self.pinned) UIDropDownMenu_AddButton(info) info.notCheckable = 1 if self.minimized then info.text = 'Maximize' info.func = function() self:Maximize() end else info.text = 'Minimize' info.func = function() self:Minimize() end end UIDropDownMenu_AddButton(info) info.text = 'Close' info.func = function() self:Toggle() end UIDropDownMenu_AddButton(info) end, 'MENU') self.DropdownButton:SetScript('OnClick', function(button) ToggleDropDownMenu(1, nil, self.DropdownFrame, button, 0, 0) end) self.width = self:GetWidth() self.height = self:GetWidth() self.isHover = false end function DevianConsoleMixin:Setup(info) for k,v in pairs(info) do self[k] = v --oldprint(k,v) end self.Dock = DevianDock:GetDockButton(self) self:Update() end local blockedType = {['table'] = true, ['function'] = true } local blockedKey = {[0] = true } -- Synchronize vars function DevianConsoleMixin:Finalize() local id = self:GetID() for k,v in pairs(D.channels[id]) do if not self[k] then D.channels[id][k] = nil end end for k,v in pairs(self) do if not (blockedType[type(v)] or blockedKey[k]) then if D.channels[id][k] ~= v then D.channels[id][k] = v end end end D.channels[id].isPressed = nil D.channels[id].isHover = nil end function DevianConsoleMixin:Pin(pinned) self.pinned = pinned or (not self.pinned) self:Update(true) end function DevianConsoleMixin:Update(setFinal) self:SetPoint('TOPLEFT', UIParent, 'TOPLEFT', self.x, self.y) if self.minimized then self:SetHeight(20) self:SetMaxResize(GetScreenWidth(),20) self.GripBottom:Hide() self.GripSide:Hide() else self:SetSize(self.width, self.height) self.GripBottom:Show() self.GripSide:Show() end -- oldprint(self:GetName(), self.x, self.y) local isFront = (D.currentProfile.current_channel == self.index) local r,g,b,a = unpack(D.db.backborder) if isFront then r,g,b,a = unpack(D.db.frontborder) self.backdrop:SetColorTexture(0,0,0,1) elseif self.pinned then self.backdrop:SetColorTexture(0,0,0,1) r,g,b,a = unpack(D.db.backborder) self.DropdownButton.Background:SetGradient('VERTICAL', .65,.35,.25, .15, .11, .05) else self.DropdownButton.Background:SetGradient('VERTICAL', .25,.35,.65, .05, .11, .15) self.backdrop:SetColorTexture(0,0,0,1) if self.raised then self.raised = nil self:Lower() end end if self.isPressed then r,g,b,a = 1,1,1,1 elseif self.isHover then r,g,b,a = 1,.5,0,1 end for name, region in pairs(self.border) do region:SetColorTexture(r,g,b,a) end self.title:SetText(self.index..' '.. (self.signature or '?') .. (' '..self:GetFrameLevel())) --oldprint(self:GetID(), self.enabled, self.minimized, self.x, self.y) self.isFront = isFront self:SetShown(self.enabled) self.backdrop:SetShown(self.enabled) self.out:SetShown((not self.minimized)) if setFinal then self:Finalize() end end function DevianConsoleMixin:OnShow() self:Update() end function DevianConsoleMixin:OnHide() end function DevianConsoleMixin:OnMouseWheel(delta) local up = delta > 0 if IsControlKeyDown() then if up then self.out:ScrollToTop() else self.out:ScrollToBottom() end elseif IsShiftKeyDown() then if up then self.out:PageUp() else self.out:PageDown() end else if up then self.out:ScrollUp() else self.out:ScrollDown() end end if self.out:AtBottom() then self.newMessage = nil self.Dock:Update() end end function DevianConsoleMixin:MinMax(minimized) minimized = minimized or self.minimized if minimized then self:Maximize() else self:Minimize() end end function DevianConsoleMixin:Minimize() self.minimized = true self:Update(true) end function DevianConsoleMixin:Maximize() self.minimized = nilnil self:Update(true) end function DevianConsoleMixin:OnMouseDown(button) self.isPressed = true self:Update() end function DevianConsoleMixin:OnMouseUp(button) self.isPressed = nil if button == 'LeftButton' then --print('go to front') self:ToFront() else self:MinMax() end end function DevianConsoleMixin:OnLeave() self.isHover = nil self:Update() end function DevianConsoleMixin:OnEnter() self.isHover = true self:Update() end function DevianConsoleMixin:OnDragStart() self:ToFront() self:StartMoving() D.IterateChannels(function(frame) frame.out:SetShown(false) frame.backdrop:Hide() end, self) end function DevianConsoleMixin:OnDragStop() local channelEntry = D.channels[self:GetID()] self.x = self:GetLeft() self.y = self:GetTop() - GetScreenHeight() if not self.minimized then self.width = self:GetWidth() self.height = self:GetHeight() end --print(channelEntry.x, channelEntry.y, channelEntry.width, channelEntry.height) self:StopMovingOrSizing() self:SetClampRectInsets(0,0,0,0) self:Update(true) D.IterateChannels(function(frame) frame:Update(true) end, self) end function DevianConsoleMixin:ToFront() D.currentProfile.current_channel = self.index self:Raise() for index, channel in ipairs(D.console) do channel:Update(true) end end function DevianConsoleMixin:Toggle(value) if value == nil then value = (not self.enabled) end self.enabled = value D:Print('Console #'..self:GetID(), self.enabled and 'open' or 'closed') self:Update(true) end function DevianConsoleMixin:OnEvent(event, arg) --oldprint(event, arg) local db = D.db if self.enabled then if event == 'PLAYER_STARTED_MOVING' then local F1 = self.moveFade.alphaOut self:SetAlpha(db.movement_fade_to) self:EnableMouse(false) elseif event == 'PLAYER_STOPPED_MOVING' then self:SetAlpha(db.movement_fade_from) self:EnableMouse(true) end end end DevianConsoleSizeButtonMixin = {} function DevianConsoleSizeButtonMixin:OnLoad() self:RegisterForDrag('LeftButton') end function DevianConsoleSizeButtonMixin:OnDragStart() local anchor = self:GetPoint(2) local frame = self:GetParent() if anchor == 'BOTTOMLEFT' then frame:SetClampRectInsets(frame:GetLeft(), GetScreenWidth()- frame:GetRight(), GetScreenHeight() - frame:GetTop(), 0) frame:SetMinResize(frame.width, 24) frame:SetMaxResize(frame.width, GetScreenHeight()) elseif anchor == 'BOTTOM' then frame:SetClampRectInsets(frame:GetLeft(), 0, GetScreenHeight() - frame:GetTop(), GetScreenHeight() - frame:GetBottom()) frame:SetMinResize(200, frame.height) frame:SetMaxResize(GetScreenWidth(), frame.height) end frame:StartSizing() end function DevianConsoleSizeButtonMixin:OnDragStop() local frame = self:GetParent() frame:OnDragStop() end