From acb22e6ae8065fa823f5a88db8bd0848aee3e0fc Mon Sep 17 00:00:00 2001 From: James Whitehead II Date: Fri, 15 Oct 2010 18:51:29 +0100 Subject: [PATCH] Add unit raid icon support, thanks to Panoramix --- Localization.enUS.lua | 7 ++- PerfectRaid.lua | 3 ++ PerfectRaid.toc | 1 + PerfectRaid_Config.lua | 32 +++++++++++++- PerfectRaid_RaidIcons.lua | 108 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 PerfectRaid_RaidIcons.lua diff --git a/Localization.enUS.lua b/Localization.enUS.lua index 20fee5e..76551e9 100644 --- a/Localization.enUS.lua +++ b/Localization.enUS.lua @@ -67,6 +67,9 @@ PerfectRaidLocals = { ["Group 8"] = "Group 8", ["Group Buff Name:"] = "Group Buff Name:", ["Group frames by:"] = "Group frames by:", + ["Healthbar - left"] = "Healthbar - left", + ["Healthbar - middle"] = "Healthbar - middle", + ["Healthbar - right"] = "Healthbar - right", ["Hide Blizzard Party Frames"] = "Hide Blizzard Party Frames", ["Highlight"] = "Highlight", ["Highlight on mouseover"] = "Highlight on mouseover", @@ -79,6 +82,7 @@ PerfectRaidLocals = { ["In-Range Alpha"] = "In-Range Alpha", ["Innervate"] = "Innervate", ["Index"] = "Index", + ["Left of the name"] = "Left of the name", ["Lifebloom"] = "Lifebloom", ["Lock frames"] = "Lock frames", ["Mage"] = "Mage", @@ -154,13 +158,14 @@ PerfectRaidLocals = { ["Save"] = "Save", ["Shadow Protection"] = "Shadow Protection", ["Shaman"] = "Shaman", - ["Show HP deficit"] = "Show HP deficit", + ["Show HP deficit"] = "Show HP deficit", ["Show frame in raid"] = "Show frame in raid", ["Show frame when solo"] = "Show frame when solo", ["Show frame while in party"] = "Show frame while in party", ["Show group number"] = "Show group number", ["Show options GUI"] = "Show options GUI", ["Show player in frame"] = "Show player in frame", + ["Show raid icons"] = "Show raid icons", ["Show unit tooltip on mouseover"] = "Show unit tooltip on mouseover", ["Sort Frames By:"] = "Sort Frames By:", ["Soulstone Resurrection"] = "Soulstone Resurrection", diff --git a/PerfectRaid.lua b/PerfectRaid.lua index d160721..924d7b3 100644 --- a/PerfectRaid.lua +++ b/PerfectRaid.lua @@ -62,6 +62,8 @@ function PerfectRaid:Initialize() showmanaonly = true, clickcast = true, locked = false, + showraidicons = true, + raidiconposition = "LNAME", highlight = { mouseover = true, tooltip = false, @@ -527,6 +529,7 @@ function OnAttributeChanged(frame, name, value) self:UNIT_HEALTH(nil, unit) self:UNIT_MANA(nil, unit) + self:TriggerMessage("PERFECTRAID_FRAME_LAYOUT_CHANGED"); end -- Hide any empty parents diff --git a/PerfectRaid.toc b/PerfectRaid.toc index 5dd2daa..60e2958 100644 --- a/PerfectRaid.toc +++ b/PerfectRaid.toc @@ -27,3 +27,4 @@ PerfectRaid_Frames.lua PerfectRaid_Range.lua PerfectRaid_Highlight.lua PerfectRaid_Config.lua +PerfectRaid_RaidIcons.lua diff --git a/PerfectRaid_Config.lua b/PerfectRaid_Config.lua index 7979b5c..798d6f6 100644 --- a/PerfectRaid_Config.lua +++ b/PerfectRaid_Config.lua @@ -67,6 +67,26 @@ function Config:CreateOptions(opt) check.Label:SetText(L["Lock frames"]) table.insert(options.widgets, check) + local check = CreateFrame("CheckButton", "PRConfig_RaidIcons", options, "PRCheckTemplate") + check.Label:SetText(L["Show raid icons"]) + table.insert(options.widgets, check) + + local iconPositionDropDown = CreateFrame("Frame", "PRConfig_IconPositionDropDown", options, "UIDropDownMenuTemplate") + local clickFunc = function(self) UIDropDownMenu_SetSelectedValue(iconPositionDropDown, self.value) end + iconPositionDropDown.Initialize = function() + UIDropDownMenu_AddButton{text = L["Left of the name"], value = "LNAME", func = clickFunc} + UIDropDownMenu_AddButton{text = L["Healthbar - left"], value = "LHBAR", func = clickFunc} + UIDropDownMenu_AddButton{text = L["Healthbar - middle"], value = "MHBAR", func = clickFunc} + UIDropDownMenu_AddButton{text = L["Healthbar - right"], value = "RHBAR", func = clickFunc} + end + iconPositionDropDown:SetScript("OnShow", function(f) + UIDropDownMenu_Initialize(iconPositionDropDown, iconPositionDropDown.Initialize) + UIDropDownMenu_SetSelectedValue(iconPositionDropDown,"LNAME") + end) + iconPositionDropDown:SetWidth(200); + iconPositionDropDown:SetPoint("LEFT", check, "RIGHT", 100, 0) + options.iconposition = iconPositionDropDown; + local cancel = CreateFrame("Button", "PRConfig_Cancel", options, "PRButtonTemplate") cancel:SetText(L["Cancel"]) cancel:SetPoint("BOTTOMRIGHT", 0, 5) @@ -84,12 +104,17 @@ function Config:CreateOptions(opt) local showMana = PRConfig_ShowManaOnly:GetChecked() and true or false local clickCast = PRConfig_ClickCast:GetChecked() and true or false local locked = PRConfig_Lock:GetChecked() and true or false - + local showRaidIcons = PRConfig_RaidIcons:GetChecked() and true or false + local raidIconPosition = UIDropDownMenu_GetSelectedValue(PRConfig_IconPositionDropDown) + PerfectRaid.db.profile.hideparty = hideParty PerfectRaid.db.profile.showmanaonly = showMana PerfectRaid.db.profile.clickcast = clickCast PerfectRaid.db.profile.locked = locked - + PerfectRaid.db.profile.showraidicons = showRaidIcons + PerfectRaid.db.profile.raidiconposition = raidIconPosition + + PerfectRaid:TriggerMessage("PERFECTRAID_CONFIG_CHANGED") Config:PartyVisibility() end @@ -98,6 +123,8 @@ function Config:CreateOptions(opt) PRConfig_ShowManaOnly:SetChecked(PerfectRaid.db.profile.showmanaonly) PRConfig_ClickCast:SetChecked(PerfectRaid.db.profile.clickcast) PRConfig_Lock:SetChecked(PerfectRaid.db.profile.locked) + PRConfig_RaidIcons:SetChecked(PerfectRaid.db.profile.showraidicons) + UIDropDownMenu_SetSelectedValue(PRConfig_IconPositionDropDown,PerfectRaid.db.profile.raidiconposition) end options:SetScript("OnShow", function() options:CancelOptions() end) @@ -111,6 +138,7 @@ function Config:CreateOptions(opt) widget:SetPoint("TOPLEFT", options.widgets[idx - 1], "BOTTOMLEFT", 0, -15) end end + options.iconposition:Show(); end local old_ShowPartyFrame = ShowPartyFrame diff --git a/PerfectRaid_RaidIcons.lua b/PerfectRaid_RaidIcons.lua new file mode 100644 index 0000000..e6d33d1 --- /dev/null +++ b/PerfectRaid_RaidIcons.lua @@ -0,0 +1,108 @@ +--[[------------------------------------------------------------------------- + * + * RaidIcons module for PerfectRaid addon. + * + * Written by: Panoramix + * Version: 1.0 + * +---------------------------------------------------------------------------]] + +local RaidIcons = PerfectRaid:NewModule("PerfectRaid-RaidIcons") +local L = PerfectRaidLocals +local utils, frames + +function RaidIcons:Initialize() + + frames = PerfectRaid.frames + utils = PerfectRaid.utils + + self:RegisterMessage("DONGLE_PROFILE_CHANGED") + self:RegisterMessage("PERFECTRAID_CONFIG_CHANGED") +end + +-- Update Raid Icons when profiles changes +function RaidIcons:DONGLE_PROFILE_CHANGED(event, addon, svname, name) + if svname == "PerfectRaidDB" then + RaidIcons:ShowRaidIcons(PerfectRaid.db.profile.showraidicons) + end +end + +-- Update Raid Icons when config is changed +function RaidIcons:PERFECTRAID_CONFIG_CHANGED(event, addon, svname, name) + self:ShowRaidIcons(PerfectRaid.db.profile.showraidicons) +end + +-- Update Raid Icons when addon is enabled +function RaidIcons:Enable() + self:ShowRaidIcons(PerfectRaid.db.profile.showraidicons) +end + +-- Show/Hide raid icons depending on value +function RaidIcons:ShowRaidIcons(value) + if value then + self:RegisterEvent("RAID_TARGET_UPDATE", "UpdateAllUnits") + self:RegisterMessage("PERFECTRAID_FRAME_LAYOUT_CHANGED", "UpdateAllUnits") + else + self:UnregisterEvent("RAID_TARGET_UPDATE") + self:UnregisterMessage("PERFECTRAID_FRAME_LAYOUT_CHANGED") + end + self:UpdateAllUnits() +end + +-- Request full update for all units +function RaidIcons:FullUpdate() + self:UpdateAllUnits() +end + +function RaidIcons:UpdateAllUnits() + local showraidicons = PerfectRaid.db.profile.showraidicons + local iconposition = PerfectRaid.db.profile.raidiconposition + + for unit, tbl in pairs(frames) do + local raidicon = GetRaidTargetIndex(unit) + if (showraidicons and raidicon and frames and frames[unit]) then + for frame in pairs(frames[unit]) do + -- create indicator and texture + if (not frame.raidicon) then + --frame.indicator = CreateFrame("Frame", nil, frame.leftbox) + frame.indicator = CreateFrame("Frame", nil, frame.healthbar) + frame.indicator:SetHeight(frame:GetHeight()) + frame.indicator:SetWidth(frame:GetHeight( )) + frame.indicator:SetFrameLevel(frame.leftbox:GetFrameLevel()+1) + + frame.raidicon = frame.indicator:CreateTexture(nil, "OVERLAY") + frame.raidicon:SetAllPoints() + frame.raidicon:SetTexture("Interface\\TargetingFrame\\UI-RaidTargetingIcons") + end + + -- resize the texture and show it + frame.indicator:ClearAllPoints() + + if iconposition == "LNAME" then + frame.indicator:SetParent(frame.leftbox) + frame.indicator:SetPoint("RIGHT", -3-frame.name:GetWidth(), 0) + elseif iconposition == "LHBAR" then + frame.indicator:SetParent(frame.healthbar) + frame.indicator:SetPoint("LEFT", 0, 0) + elseif iconposition == "MHBAR" then + frame.indicator:SetParent(frame.healthbar) + frame.indicator:SetPoint("CENTER", 0, 0) + elseif iconposition == "RHBAR" then + frame.indicator:SetParent(frame.healthbar) + frame.indicator:SetPoint("RIGHT", 0, 0) + end + SetRaidTargetIconTexture(frame.raidicon, raidicon) + frame.raidicon:Show() + end + end + + -- unit doesn't have raidtarget icon, hide it + if ((not showraidicons or not raidicon) and frames and frames[unit]) then + for frame in pairs(frames[unit]) do + if (frame.raidicon) then + frame.raidicon:Hide() + end + end + end + end +end -- 1.7.9.5