diff --git a/CastingBar.lua b/CastingBar.lua index b349489..7d3018f 100644 --- a/CastingBar.lua +++ b/CastingBar.lua @@ -24,9 +24,51 @@ local addonName, addon = ... local castingBar = addon:NewModule("CastingBar") +local CASTINGBAR_WIDTH = 256 +local CASTINGBAR_HEIGHT = 64 + +local CUT_WIDTH = 40 +local FRAGMENT_WIDTH = CUT_WIDTH / CASTINGBAR_WIDTH +local RIGHT_EDGE_START = (CASTINGBAR_WIDTH - CUT_WIDTH) / CASTINGBAR_WIDTH + castingBar.frame = CreateFrame("StatusBar", "DefaultCastingBar", UIParent, "CastingBarFrameTemplate") -local function handlePosition(frame, position) +local function createTexture(fileName, left, right, width) + local texture = castingBar.frame:CreateTexture() + texture:SetTexture(fileName); + texture:SetTexCoord(left, right, 0, 1) + texture:SetSize(width, CASTINGBAR_HEIGHT) + return texture +end + +local function buildTexture(fileName, width) + local middle = createTexture(fileName, FRAGMENT_WIDTH, FRAGMENT_WIDTH, width) + middle:SetPoint("TOP", 0, 28) + + local left = createTexture(fileName, 0, FRAGMENT_WIDTH, CUT_WIDTH) + left:SetPoint("RIGHT", middle, "LEFT") + middle.left = left + + local right = createTexture(fileName, RIGHT_EDGE_START, 1, CUT_WIDTH) + right:SetPoint("LEFT", middle, "RIGHT") + middle.right = right + + return middle +end + +local function updateVisibility(source, ...) + for i = 1, select('#', ...) do + local dest = select(i, ...) + if source:IsVisible() then + dest:Show() + else + dest:Hide() + end + dest:SetAlpha(source:GetAlpha()) + end +end + +local function setFeaturesPosition(frame, position) frame:ClearAllPoints() if position:find("Left") then frame:SetPoint("RIGHT", castingBar.frame, "LEFT", position:find("Inner") and 25 or -10, 3) @@ -35,8 +77,24 @@ local function handlePosition(frame, position) end end +local function getWidth() + return addon.db.profile.width, addon.db.profile.width - CUT_WIDTH/2 +end + local function onEvent(self, event, ...) + local width, textWidth = getWidth() + + self.border:SetWidth(textWidth) + self.barFlash:SetWidth(textWidth) + self:SetWidth(width) + + self.borderShield:Hide() + CastingBarFrame_OnEvent(self, event, ...) + + updateVisibility(self.border, self.border.left, self.border.right) + updateVisibility(self.barFlash, self.barFlash.left, self.barFlash.right) + if self.unit then local texture if self.casting then @@ -46,23 +104,28 @@ local function onEvent(self, event, ...) end if texture and not addon.db.profile.hideIcon then self.icon:SetTexture(texture) - handlePosition(self.icon, addon.db.profile.iconPosition) + setFeaturesPosition(self.icon, addon.db.profile.iconPosition) self.icon:Show() else self.icon:Hide() end if not addon.db.profile.hideTime then - handlePosition(self.time, addon.db.profile.timePosition) + setFeaturesPosition(self.time, addon.db.profile.timePosition) self.time:Show() else self.time:Hide() end end + DefaultCastingBar_DragFrame:Hide() end local function onUpdate(self, elapsed) CastingBarFrame_OnUpdate(self, elapsed) + + updateVisibility(self.border, self.border.left, self.border.right) + updateVisibility(self.barFlash, self.barFlash.left, self.barFlash.right) + if self.casting then self.time:SetFormattedText('%.1f', self.maxValue - self.value) elseif self.channeling then @@ -73,6 +136,26 @@ end function castingBar:OnInitialize() local name = self.frame:GetName() + local width, textWidth = getWidth() + + self.frame.border:Hide() + self.frame.border:ClearAllPoints() + + self.frame.borderShield:Hide() + self.frame.borderShield:ClearAllPoints() + + self.frame.barFlash:Hide() + self.frame.barFlash:ClearAllPoints() + + local border = buildTexture([[Interface\CastingBar\UI-CastingBar-Border]], textWidth) + self.frame.border = border + _G[name.."Border"] = border + + local barFlash = buildTexture([[Interface\CastingBar\UI-CastingBar-Flash]], textWidth) + barFlash:SetBlendMode("ADD") + self.frame.barFlash = barFlash + _G[name.."Flash"] = barFlash + self.frame.time = self.frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight") self.frame.icon = _G[name .. "Icon"] @@ -80,7 +163,7 @@ function castingBar:OnInitialize() self.frame.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93) self.frame:SetPoint("CENTER", DefaultCastingBar_DragFrame) - self.frame:SetSize(CastingBarFrame:GetWidth(), CastingBarFrame:GetHeight()) + self.frame:SetSize(width, addon.barMaxHeight) self.frame:Hide() self.frame:SetScript('OnUpdate', onUpdate) diff --git a/Core.lua b/Core.lua index 73984e7..f38fab1 100644 --- a/Core.lua +++ b/Core.lua @@ -28,6 +28,7 @@ addon.name = GetAddOnMetadata(addonName, "Title") local defaults = { profile = { + width = 195, position = {"CENTER", "CENTER", 0, 0}, hideIcon = false, iconPosition = "Left", @@ -38,4 +39,6 @@ local defaults = { function core:OnInitialize() addon.db = LibStub("AceDB-3.0"):New("DefaultCastingBarDb", defaults, true) + + addon.barMaxHeight = CastingBarFrame:GetHeight() end \ No newline at end of file diff --git a/DragFrame.lua b/DragFrame.lua index 40e2e5c..7f33b48 100644 --- a/DragFrame.lua +++ b/DragFrame.lua @@ -24,32 +24,61 @@ local _, addon = ... local dragFrame = addon:NewModule("DragFrame") +local MIN_RESIZE_WIDTH = 128 +local MAX_RESIZE_WIDTH = 500 + dragFrame.frame = DefaultCastingBar_DragFrame -local function setPosition() +local function savePositionAndDimensions(self) + if not addon.db.profile.position then + addon.db.profile.position = {} + end + local point, _, relpoint, x, y = self:GetPoint() + addon.db.profile.position = { point, relpoint, x, y } + addon.db.profile.width = self:GetWidth() +end + +local function initPositionAndDimensions() local position = addon.db.profile.position if position then local point, relpoint, x, y = unpack(position) dragFrame.frame:ClearAllPoints() dragFrame.frame:SetPoint(point, UIParent, relpoint, x, y) end + dragFrame.frame:SetSize(addon.db.profile.width, addon.barMaxHeight) + dragFrame.frame.resizeButton:SetSize(addon.barMaxHeight, addon.barMaxHeight) end function dragFrame:OnInitialize() - addon.db.RegisterCallback(addon, "OnProfileChanged", setPosition) - addon.db.RegisterCallback(addon, "OnProfileCopied", setPosition) - addon.db.RegisterCallback(addon, "OnProfileReset", setPosition) + addon.db.RegisterCallback(addon, "OnProfileChanged", initPositionAndDimensions) + addon.db.RegisterCallback(addon, "OnProfileCopied", initPositionAndDimensions) + addon.db.RegisterCallback(addon, "OnProfileReset", initPositionAndDimensions) - setPosition() + initPositionAndDimensions() SLASH_DEFAULTCASTINGBAR1 = "/dcb" SlashCmdList["DEFAULTCASTINGBAR"] = function(input) if dragFrame.frame:IsVisible() then dragFrame.frame:Hide() + dragFrame.frame.resizeButton:Hide() else dragFrame.frame:Show() + dragFrame.frame.resizeButton:Show() end end + + self.frame:SetBackdropColor(0, 1, 0, 0.5) + self.frame.text = _G[self.frame:GetName().."Pos"] + + self.frame:EnableMouse(true) + + self.frame:SetResizable(true) + self.frame:SetMinResize(MIN_RESIZE_WIDTH, addon.barMaxHeight) + self.frame:SetMaxResize(MAX_RESIZE_WIDTH, addon.barMaxHeight) + + self.frame:SetMovable(true) + self.frame:SetClampedToScreen(true) + self.frame:Hide() end dragFrame.frame:RegisterForDrag("LeftButton") @@ -60,10 +89,32 @@ dragFrame.frame:SetScript("OnDragStart", function(self, button) end) dragFrame.frame:SetScript("OnDragStop", function(self) - if not addon.db.profile.position then - addon.db.profile.position = { } - end - local point, _, relpoint, x, y = self:GetPoint() - addon.db.profile.position = { point, relpoint, x, y } + savePositionAndDimensions(self) + self:StopMovingOrSizing() +end) + +dragFrame.frame:SetScript('OnUpdate', function(self) + local x, y = self:GetLeft(), self:GetBottom() + if x and y then + self.text:SetText(("Left: %d Bottom: %d"):format(x , y)) + end +end) + +dragFrame.frame.resizeButton:SetScript('OnMouseDown', function(self) + self:SetButtonState("PUSHED", true) + + self:GetHighlightTexture():Hide() + + dragFrame.frame:StartSizing("BOTTOMRIGHT") +end) + +dragFrame.frame.resizeButton:SetScript('OnMouseUp', function(self) + self:SetButtonState("NORMAL", false) + + self:GetHighlightTexture():Show() + + savePositionAndDimensions(dragFrame.frame) + + dragFrame.frame:StopMovingOrSizing() end) \ No newline at end of file diff --git a/DragFrame.xml b/DragFrame.xml index ef1f0df..fb5bfae 100644 --- a/DragFrame.xml +++ b/DragFrame.xml @@ -1,8 +1,5 @@ <Ui xmlns="http://www.blizzard.com/wow/ui/"> - <Frame name="DefaultCastingBar_DragFrame" parent="UIParent" enableMouse="true" movable="true" clampedToScreen="true" hidden="true"> - <Size> - <AbsDimension x="120" y="40" /> - </Size> + <Frame name="DefaultCastingBar_DragFrame" parent="UIParent"> <Anchors> <Anchor point="CENTER" relativeTo="UIParent"> <Offset> @@ -23,22 +20,16 @@ <AbsValue val="16"/> </TileSize> </Backdrop> - <Scripts> - <OnLoad> - self:SetSize(CastingBarFrame:GetWidth(), CastingBarFrame:GetHeight()) - self:SetBackdropColor(0, 1, 0, 0.5) - self.text = _G[self:GetName().."Pos"] - self.UpdatePosition = function(self) - local x, y = self:GetLeft(), self:GetBottom() - if x and y then - self.text:SetText(("Left: %d Bottom: %d"):format(x , y)) - end - end - </OnLoad> - <OnUpdate> - self:UpdatePosition() - </OnUpdate> - </Scripts> + <Frames> + <Button name="$parentResizeButton" parentKey="resizeButton"> + <Anchors> + <Anchor point="BOTTOMRIGHT" relativeTo="$parent" x="0" y="0"/> + </Anchors> + <NormalTexture file="Interface\ChatFrame\UI-ChatIM-SizeGrabber-Up"/> + <HighlightTexture file="Interface\ChatFrame\UI-ChatIM-SizeGrabber-Highlight"/> + <PushedTexture file="Interface\ChatFrame\UI-ChatIM-SizeGrabber-Down"/> + </Button> + </Frames> </Frame> <Script file="DragFrame.lua"/> diff --git a/Options.lua b/Options.lua index 9b89ab3..e48ca8c 100644 --- a/Options.lua +++ b/Options.lua @@ -30,7 +30,7 @@ LibStub("Libra"):EmbedWidgets(options) function options:OnInitialize() local options = self:CreateOptionsFrame(addon.name) options:SetDescription(GetAddOnMetadata(addonName, "Notes")) - + options:CreateOptions({ { type = "Dropdown",