From 20b06a17488f7b82d76c6af1609b91825de7dab6 Mon Sep 17 00:00:00 2001 From: Eyal Solnik Date: Sat, 14 May 2016 11:20:34 +0300 Subject: [PATCH] First pass on the code to make it work in Legion --- .gitignore | 2 - CastingBar.lua | 100 ++++++++++++++++++------------------------------ DefaultCastingBar.toc | 6 +-- Features/DragFrame.lua | 97 ---------------------------------------------- Features/DragFrame.xml | 36 ----------------- Features/Icon.lua | 39 ------------------- Features/Timer.lua | 68 -------------------------------- Modules/DragFrame.lua | 97 ++++++++++++++++++++++++++++++++++++++++++++++ Modules/DragFrame.xml | 36 +++++++++++++++++ 9 files changed, 172 insertions(+), 309 deletions(-) delete mode 100644 .gitignore delete mode 100644 Features/DragFrame.lua delete mode 100644 Features/DragFrame.xml delete mode 100644 Features/Icon.lua delete mode 100644 Features/Timer.lua create mode 100644 Modules/DragFrame.lua create mode 100644 Modules/DragFrame.xml diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 47a521d..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.buildpath -.project \ No newline at end of file diff --git a/CastingBar.lua b/CastingBar.lua index 8364f42..b0a22e0 100644 --- a/CastingBar.lua +++ b/CastingBar.lua @@ -1,26 +1,3 @@ ---[[ - Copyright (c) 2014 Eyal Shilony - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -]] - local addonName, addon = ... local castingBar = addon:NewModule("CastingBar") @@ -31,7 +8,8 @@ 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") +castingBar.frame = CreateFrame("StatusBar", "CastingBarTest", UIParent, "CastingBarFrameTemplate") +CastingBarFrame_OnLoad(castingBar.frame, "player", true, false) local function createTexture(fileName, left, right, width) local texture = castingBar.frame:CreateTexture() @@ -47,11 +25,11 @@ local function buildTexture(fileName, width) local left = createTexture(fileName, 0, FRAGMENT_WIDTH, CUT_WIDTH) left:SetPoint("RIGHT", middle, "LEFT") - middle.left = left + middle.Left = left local right = createTexture(fileName, RIGHT_EDGE_START, 1, CUT_WIDTH) right:SetPoint("LEFT", middle, "RIGHT") - middle.right = right + middle.Right = right return middle end @@ -93,7 +71,7 @@ local function setIconAndTimePositions(frame, position) frame:ClearAllPoints() local parent, x, y = castingBar.frame, -10, 3 - local isTime = frame == parent.time + local isTime = frame == parent.Time if isTime then if not position:find("Outer") then @@ -116,20 +94,20 @@ end local function setIcon(castingBar, texture) if texture and not addon.db.profile.hideIcon then - castingBar.icon:SetTexture(texture) - setIconAndTimePositions(castingBar.icon, addon.db.profile.iconPosition) - castingBar.icon:Show() + castingBar.Icon:SetTexture(texture) + setIconAndTimePositions(castingBar.Icon, addon.db.profile.iconPosition) + castingBar.Icon:Show() else - castingBar.icon:Hide() + castingBar.Icon:Hide() end end local function setTime(castingBar) if not addon.db.profile.hideTime then - setIconAndTimePositions(castingBar.time, addon.db.profile.timePosition) - castingBar.time:Show() + setIconAndTimePositions(castingBar.Time, addon.db.profile.timePosition) + castingBar.Time:Show() else - castingBar.time:Hide() + castingBar.Time:Hide() end end @@ -139,21 +117,20 @@ end local function setWidth(castingBar) local width, textWidth = getWidth() - - castingBar.border:SetWidth(textWidth) - castingBar.barFlash:SetWidth(textWidth) + castingBar.Border:SetWidth(textWidth) + castingBar.Flash:SetWidth(textWidth) castingBar:SetWidth(width) end local function onEvent(self, event, ...) setWidth(self) - self.borderShield:Hide() + 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) + updateVisibility(self.Border, self.Border.Left, self.Border.Right) + updateVisibility(self.Flash, self.Flash.Left, self.Flash.Right) if self.casting or self.channeling then setStatusBarColor() @@ -176,18 +153,18 @@ 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) + updateVisibility(self.Border, self.Border.Left, self.Border.Right) + updateVisibility(self.Flash, self.Flash.Left, self.Flash.Right) if self.casting then local value = self.maxValue - self.value if not addon.db.profile.hideTotalTime then - self.time:SetFormattedText("%.1f/%.1f", value, self.maxValue) + self.Time:SetFormattedText("%.1f/%.1f", value, self.maxValue) else - self.time:SetFormattedText("%.1f", value) + self.Time:SetFormattedText("%.1f", value) end elseif self.channeling then - self.time:SetFormattedText("%.1f", self.value) + self.Time:SetFormattedText("%.1f", self.value) end end @@ -196,36 +173,33 @@ function castingBar:OnInitialize() local width, textWidth = getWidth() - self.frame.border:Hide() - self.frame.border:ClearAllPoints() + self.frame.Border:Hide() + self.frame.Border:ClearAllPoints() - self.frame.borderShield:Hide() - self.frame.borderShield:ClearAllPoints() + self.frame.BorderShield:Hide() + self.frame.BorderShield:ClearAllPoints() - self.frame.barFlash:Hide() - self.frame.barFlash:ClearAllPoints() + self.frame.Flash:Hide() + self.frame.Flash:ClearAllPoints() local border = buildTexture([[Interface\CastingBar\UI-CastingBar-Border]], textWidth) - self.frame.border = border - _G[name.."Border"] = border + self.frame.Border = border - local barFlash = buildTexture([[Interface\CastingBar\UI-CastingBar-Flash]], textWidth) - barFlash:SetBlendMode("ADD") - self.frame.barFlash = barFlash - _G[name.."Flash"] = barFlash + local flash = buildTexture([[Interface\CastingBar\UI-CastingBar-Flash]], textWidth) + flash:SetBlendMode("ADD") + self.frame.Flash = flash - self.frame.time = self.frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight") + self.frame.Time = self.frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight") - self.frame.icon = _G[name .. "Icon"] - self.frame.icon:SetSize(22, 22) - self.frame.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93) + self.frame.Icon:SetSize(22, 22) + self.frame.Icon:SetTexCoord(0.07, 0.93, 0.07, 0.93) self.frame:SetPoint("CENTER", DefaultCastingBar_DragFrame) self.frame:SetSize(width, addon.barMaxHeight) self.frame:Hide() - self.frame:SetScript('OnUpdate', onUpdate) - self.frame:SetScript('OnEvent', onEvent) + self.frame:SetScript("OnUpdate", onUpdate) + self.frame:SetScript("OnEvent", onEvent) end CastingBarFrame:UnregisterAllEvents() diff --git a/DefaultCastingBar.toc b/DefaultCastingBar.toc index 297c42a..1f4a3c7 100644 --- a/DefaultCastingBar.toc +++ b/DefaultCastingBar.toc @@ -4,7 +4,7 @@ ## Title: Default: |cffEAE669CastingBar|r ## Notes: A lightweight casting bar that you can move and resize. -## Version: @project-version@ +## Version: 0.1.0-beta+@project-version@ ## X-Category: Combat ## X-Localizations: enUS @@ -21,8 +21,6 @@ Libs\Libra\Libra.xml Locale\enUS.lua Core.lua -Features\Timer.lua -Features\Icon.lua -Features\DragFrame.xml +Modules\DragFrame.xml CastingBar.lua Options.lua \ No newline at end of file diff --git a/Features/DragFrame.lua b/Features/DragFrame.lua deleted file mode 100644 index f6a022e..0000000 --- a/Features/DragFrame.lua +++ /dev/null @@ -1,97 +0,0 @@ -local _, addon = ... -local dragFrame = addon:NewModule("DragFrame") - -local MIN_RESIZE_WIDTH = 128 -local MAX_RESIZE_WIDTH = 512 - -dragFrame.frame = DefaultCastingBar_DragFrame - -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", initPositionAndDimensions) - addon.db.RegisterCallback(addon, "OnProfileCopied", initPositionAndDimensions) - addon.db.RegisterCallback(addon, "OnProfileReset", initPositionAndDimensions) - - 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") -dragFrame.frame:SetScript("OnDragStart", function(self, button) - if button == "LeftButton" then - self:StartMoving() - end -end) - -dragFrame.frame:SetScript("OnDragStop", function(self) - 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/Features/DragFrame.xml b/Features/DragFrame.xml deleted file mode 100644 index fb5bfae..0000000 --- a/Features/DragFrame.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - -