Mercurial > wow > devian
view Console.lua @ 99:7d94df3804a7
- Console drag buttons for resizing
- While dragging a console frame, other frames are ghosted out
- Dropdown menu includes Toggle, Pin, and MinMax
author | Nenue |
---|---|
date | Thu, 27 Oct 2016 06:11:04 -0400 |
parents | 33bc8baba858 |
children | 790dca545f1d |
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') UIDropDownMenu_Initialize(self.DropdownFrame, function() local info = UIDropDownMenu_CreateInfo() info.notCheckable = 1 info.text = 'Pin' info.func = function() self:Pin() end UIDropDownMenu_AddButton(info) 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() 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 end function DevianConsoleMixin:Pin(pinned) self.pinned = pinned or (not self.pinned) self:Update(true) end function DevianConsoleMixin:Update(setFinal) self.title:SetText(self.index..' '.. (self.signature or '?')) 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) else self.backdrop:SetColorTexture(0,0,0,0.5) end for name, region in pairs(self.border) do region:SetColorTexture(r,g,b,a) end --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 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) if button == 'LeftButton' then self:ToFront() end end function DevianConsoleMixin:OnMouseUp(button) if button == 'LeftButton' then self:ToFront() else self:MinMax() end end function DevianConsoleMixin:OnLeave() end function DevianConsoleMixin:OnEnter() 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() end, self) end function DevianConsoleMixin:ToFront() self:Raise() D.currentProfile.current_channel = self.index for index, channel in ipairs(D.console) do channel:Update() end end function DevianConsoleMixin:Toggle() self.enabled = (not self.enabled) --oldprint(self:GetID(), self.enabled) self:Update() end function DevianConsoleMixin:OnEvent(event, arg) oldprint(event, arg) local db = D.db if self.enabled then if event == 'PLAYER_STARTED_MOVING' then self.moveFade:GetProgress() self.moveFade:Stop() local F1 = self.moveFade.alphaOut F1:SetFromAlpha(db.movement_fade_from) F1:SetToAlpha(db.movement_fade_to) F1:SetDuration(db.movement_fade_time) self.moveFade:Play() self:EnableMouse(false) else self.moveFade:Stop() local F1 = self.moveFade.alphaOut F1:SetToAlpha(db.movement_fade_from) F1:SetFromAlpha(db.movement_fade_to) F1:SetDuration(db.movement_fade_time) self.moveFade:Play() 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