From 7089e3fe321cf353b0488a4af8378baf31098585 Mon Sep 17 00:00:00 2001 From: Eyal Shilony Date: Mon, 17 Nov 2014 18:01:51 +0200 Subject: [PATCH] A new option was added for class colors. More options were added for the timer's position. The icon and the timer shouldn't overlap when positioned to the same direction. --- CastingBar.lua | 90 ++++++++++++++++++++++++++++++++++++++++---------------- Core.lua | 1 + Options.lua | 22 +++++++++++++- loc/enUS.lua | 5 +++- 4 files changed, 91 insertions(+), 27 deletions(-) diff --git a/CastingBar.lua b/CastingBar.lua index bede0a5..8364f42 100644 --- a/CastingBar.lua +++ b/CastingBar.lua @@ -68,18 +68,42 @@ local function updateVisibility(source, ...) end end +local function setStatusBarColor() + local useClassColors = addon.db.profile.useClassColors + if not useClassColors:find("None") then + local _, class + if useClassColors:find("or") then + _, class = UnitClass("target") + if not class then + _, class = UnitClass("player") + end + elseif useClassColors:find("Target") then + _, class = UnitClass("target") + elseif useClassColors:find("Player") then + _, class = UnitClass("player") + end + if class then + local color = RAID_CLASS_COLORS[class] + castingBar.frame:SetStatusBarColor(color.r, color.g, color.b) + end + end +end + local function setIconAndTimePositions(frame, position) frame:ClearAllPoints() local parent, x, y = castingBar.frame, -10, 3 - - if position:find("Inner") then - x, y = addon.db.profile.hideTotalTime and 30 or 60, 20 - elseif not addon.db.profile.hideIcon then - local isTime = frame == parent.time - local isPosEqual = addon.db.profile.timePosition:find(addon.db.profile.iconPosition) - if isTime and isPosEqual then - parent, x, y = parent.icon, -5, 0 + local isTime = frame == parent.time + + if isTime then + if not position:find("Outer") then + x = addon.db.profile.hideTotalTime and 30 or 60 + y = position:find("Bottom") and -18 or position:find("Top") and 20 or y + elseif not addon.db.profile.hideIcon and not addon.db.profile.hideTime then + local isPosEqual = addon.db.profile.timePosition:find(addon.db.profile.iconPosition) + if isPosEqual then + parent, x, y = parent.icon, -5, 0 + end end end @@ -90,16 +114,39 @@ local function setIconAndTimePositions(frame, position) end 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() + else + 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() + else + castingBar.time:Hide() + end +end + local function getWidth() return addon.db.profile.width, addon.db.profile.width - CUT_WIDTH/2 end -local function onEvent(self, event, ...) +local function setWidth(castingBar) local width, textWidth = getWidth() - self.border:SetWidth(textWidth) - self.barFlash:SetWidth(textWidth) - self:SetWidth(width) + castingBar.border:SetWidth(textWidth) + castingBar.barFlash:SetWidth(textWidth) + castingBar:SetWidth(width) +end + +local function onEvent(self, event, ...) + setWidth(self) self.borderShield:Hide() @@ -108,6 +155,10 @@ local function onEvent(self, event, ...) updateVisibility(self.border, self.border.left, self.border.right) updateVisibility(self.barFlash, self.barFlash.left, self.barFlash.right) + if self.casting or self.channeling then + setStatusBarColor() + end + if self.unit then local texture if self.casting then @@ -115,19 +166,8 @@ local function onEvent(self, event, ...) elseif self.channeling then texture = select(4, UnitChannelInfo(self.unit)) end - if texture and not addon.db.profile.hideIcon then - self.icon:SetTexture(texture) - setIconAndTimePositions(self.icon, addon.db.profile.iconPosition) - self.icon:Show() - else - self.icon:Hide() - end - if not addon.db.profile.hideTime then - setIconAndTimePositions(self.time, addon.db.profile.timePosition) - self.time:Show() - else - self.time:Hide() - end + setIcon(self, texture) + setTime(self) end DefaultCastingBar_DragFrame:Hide() diff --git a/Core.lua b/Core.lua index 0d7ee5d..b63b6fc 100644 --- a/Core.lua +++ b/Core.lua @@ -30,6 +30,7 @@ local defaults = { profile = { width = 195, position = {"CENTER", "CENTER", 0, 0}, + useClassColors = "Target", iconPosition = "Left", hideIcon = false, timePosition = "Outer Right", diff --git a/Options.lua b/Options.lua index a4f30b4..d5e9fa3 100644 --- a/Options.lua +++ b/Options.lua @@ -34,6 +34,22 @@ function options:OnInitialize() options:CreateOptions({ { type = "Dropdown", + text = L["Use Class Colors"], + get = function() + return addon.db.profile.useClassColors + end, + set = function(_, value) + addon.db.profile.useClassColors = value + end, + menuList = { + "None", + "Target", + "Player", + "Target or Player" + } + }, + { + type = "Dropdown", text = L["Icon Position"], get = function() return addon.db.profile.iconPosition @@ -69,7 +85,11 @@ function options:OnInitialize() "Outer Left", "Outer Right", "Inner Left", - "Inner Right" + "Inner Right", + "Top Left", + "Top Right", + "Bottom Left", + "Bottom Right" } }, { diff --git a/loc/enUS.lua b/loc/enUS.lua index 1e63483..5ec4085 100644 --- a/loc/enUS.lua +++ b/loc/enUS.lua @@ -24,6 +24,7 @@ local addonName = ... local L = LibStub("AceLocale-3.0"):NewLocale(addonName, "enUS", true, false) +L["Use Class Colors"] = true L["Icon Position"] = true L["Hide Icon"] = true L["Time Position"] = true @@ -31,4 +32,6 @@ L["Hide Total Time"] = true L["Hide Time"] = true L["Profiles"] = true -L["You can change the active database profile, so you can have different settings for every character."] = true \ No newline at end of file +L["You can change the active database profile, so you can have different settings for every character."] = true + +-- todo: Add localization for dropdown options. \ No newline at end of file -- 1.7.9.5