Quantcast

First pass on the code to make it work in Legion

Eyal Solnik [05-14-16 - 08:20]
First pass on the code to make it work in Legion
Filename
.gitignore
CastingBar.lua
DefaultCastingBar.toc
Features/DragFrame.lua
Features/DragFrame.xml
Features/Icon.lua
Features/Timer.lua
Modules/DragFrame.lua
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 <Lynxium>
-
-	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 @@
-<Ui xmlns="http://www.blizzard.com/wow/ui/">
-	<Frame name="DefaultCastingBar_DragFrame" parent="UIParent">
-		<Anchors>
-			<Anchor point="CENTER" relativeTo="UIParent">
-				<Offset>
-					<AbsDimension x="0" y="0"/>
-				</Offset>
-			</Anchor>
-		</Anchors>
-		<Layers>
-			<Layer>
-				<FontString name="$parentPos" font="GameFontHighlight" setAllPoints="true" text="Tooltip" maxLines="1" justifyH="CENTER" />
-			</Layer>
-		</Layers>
-		<Backdrop bgFile="Interface\Tooltips\UI-Tooltip-Background" tile="true">
-			<EdgeSize>
-				<AbsValue val="16"/>
-			</EdgeSize>
-			<TileSize>
-				<AbsValue val="16"/>
-			</TileSize>
-		</Backdrop>
-		<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"/>
-</Ui>
\ No newline at end of file
diff --git a/Features/Icon.lua b/Features/Icon.lua
deleted file mode 100644
index ba458b4..0000000
--- a/Features/Icon.lua
+++ /dev/null
@@ -1,39 +0,0 @@
-local _, addon = ...
-local icon = addon:NewModule("Icon")
-
-local frame
-
-function icon:Create(castingBar)
-	local name = castingBar:GetName()
-
-	frame = _G[name .. "Icon"]
-	frame:SetSize(22, 22)
-	frame:SetTexCoord(0.07, 0.93, 0.07, 0.93)
-
-	return icon
-end
-
-function icon:Hide()
-	frame:Hide()
-end
-
-function icon:Show()
-	frame:Show()
-end
-
-function icon:IsHidden()
-	return addon.db.profile.hideIcon
-end
-
-function icon:SetPosition(parent)
-	-- NYI
-end
-
-function icon:SetVisibility(parent)
-	if not self:IsHidden() then
-		self:SetPosition(parent)
-		self:Show()
-	else
-		self:Hide()
-	end
-end
\ No newline at end of file
diff --git a/Features/Timer.lua b/Features/Timer.lua
deleted file mode 100644
index 6ae1994..0000000
--- a/Features/Timer.lua
+++ /dev/null
@@ -1,68 +0,0 @@
-local _, addon = ...
-local timer = addon:NewModule("Timer")
-
-local frame
-
-function timer:Create(castingBar)
-	frame = castingBar:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
-	return timer
-end
-
-function timer:SetValue(castingBar)
-	if castingBar.casting then
-		local value = self.maxValue - self.value
-		if timer:IsHidden() then
-			frame:SetText(nil)
-		elseif timer:HasTotalTimeOnly() then
-			frame:SetFormattedText("%.1f", self.maxValue)
-		elseif timer:HasCastTimeOnly() then
-			frame:SetFormattedText("%.1f", value)
-		else
-			frame:SetFormattedText("%.1f/%.1f", value, self.maxValue)
-		end
-	elseif castingBar.channeling then
-		frame:SetFormattedText("%.1f", self.value)
-	end
-end
-
-function timer:Hide()
-	frame:Hide()
-end
-
-function timer:Show()
-	frame:Show()
-end
-
-function timer:IsHidden()
-	return addon.db.profile.timerDisplay == "Hide"
-end
-
-function timer:HasTotalTimeOnly()
-	return not timer:IsHidden() and addon.db.profile.timerDisplay == "Hide Total Time"
-end
-
-function timer:HasCastTimeOnly()
-	return not timer:IsHidden() and addon.db.profile.timerDisplay == "Hide Cast Time"
-end
-
-function timer:SetPosition(parent)
-	local parent = self:GetParent()
-	-- NYI
-end
-
-function timer:SetDisplay(timerDisplay)
-	addon.db.profile.timerDisplay = timerDisplay
-end
-
-function timer:GetDisplay()
-	return addon.db.profile.timerDisplay
-end
-
-function timer:SetVisibility(parent)
-	if not self:IsHidden() then
-		self:SetPosition(parent)
-		self:Show()
-	else
-		self:Hide()
-	end
-end
\ No newline at end of file
diff --git a/Modules/DragFrame.lua b/Modules/DragFrame.lua
new file mode 100644
index 0000000..f6a022e
--- /dev/null
+++ b/Modules/DragFrame.lua
@@ -0,0 +1,97 @@
+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/Modules/DragFrame.xml b/Modules/DragFrame.xml
new file mode 100644
index 0000000..fb5bfae
--- /dev/null
+++ b/Modules/DragFrame.xml
@@ -0,0 +1,36 @@
+<Ui xmlns="http://www.blizzard.com/wow/ui/">
+	<Frame name="DefaultCastingBar_DragFrame" parent="UIParent">
+		<Anchors>
+			<Anchor point="CENTER" relativeTo="UIParent">
+				<Offset>
+					<AbsDimension x="0" y="0"/>
+				</Offset>
+			</Anchor>
+		</Anchors>
+		<Layers>
+			<Layer>
+				<FontString name="$parentPos" font="GameFontHighlight" setAllPoints="true" text="Tooltip" maxLines="1" justifyH="CENTER" />
+			</Layer>
+		</Layers>
+		<Backdrop bgFile="Interface\Tooltips\UI-Tooltip-Background" tile="true">
+			<EdgeSize>
+				<AbsValue val="16"/>
+			</EdgeSize>
+			<TileSize>
+				<AbsValue val="16"/>
+			</TileSize>
+		</Backdrop>
+		<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"/>
+</Ui>
\ No newline at end of file