From 8d94b30db659e09c58711f969877234840b4979e Mon Sep 17 00:00:00 2001 From: Zid <12006932+SaschaJankowiak@users.noreply.github.com> Date: Mon, 25 Jul 2022 13:59:27 +0200 Subject: [PATCH] Buff Presets (PR #10) --- PallyPower.lua | 111 +++++++++++++++++++++++++++++++++++++---- PallyPowerValues.lua | 2 + PallyPower_TBC.xml | 35 ++++++++++++- PallyPower_Vanilla.xml | 35 ++++++++++++- PallyPower_Wrath.xml | 35 ++++++++++++- 5 files changed, 205 insertions(+), 13 deletions(-) diff --git a/PallyPower.lua b/PallyPower.lua index 62a51ff..ea0ec3a 100644 --- a/PallyPower.lua +++ b/PallyPower.lua @@ -92,6 +92,12 @@ function PallyPower:OnInitialize() self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileChanged") self.db.RegisterCallback(self, "OnProfileReset", "OnProfileChanged") + if not PallyPower_SavedPresets or PallyPower_SavedPresets == nil then + PallyPower_SavedPresets = {} + PallyPower_SavedPresets["PallyPower_Assignments"] = {[0] = {}} + PallyPower_SavedPresets["PallyPower_NormalAssignments"] = {[0] = {}} + end + self.opt = self.db.profile self.options.args.profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) @@ -274,6 +280,19 @@ function PallyPower:OpenConfigWindow() end end +local function tablecopy(tbl) + if type(tbl) ~= "table" then return tbl end + local t = {} + for i,v in pairs(tbl) do + t[i] = tablecopy(v) + end + return t + end + +local function safeget(t,k) -- always return nil or t[k] if at least t is a table / Treeston + return t and t[k] +end + function PallyPowerBlessings_Clear() if InCombatLockdown() then return end @@ -377,12 +396,7 @@ function SetNormalBlessings(pname, class, tname, value) 2.0, function() if PallyPower_NormalAssignments and PallyPower_NormalAssignments[pname] and PallyPower_NormalAssignments[pname][class] and PallyPower_NormalAssignments[pname][class][tname] then - if PallyPower_NormalAssignments[pname][class][tname] == nil then - value = 0 - else - value = PallyPower_NormalAssignments[pname][class][tname] - end - PallyPower:SendMessage("NASSIGN " .. pname .. " " .. class .. " " .. tname .. " " .. value) + PallyPower:SendNormalBlessings(pname, class, tname) PallyPower:UpdateLayout() msgQueue:Cancel() end @@ -390,6 +404,13 @@ function SetNormalBlessings(pname, class, tname, value) ) end +-- sends blessing to tname as previously set in PallyPower_NormalAssignments[pname]... +function PallyPower:SendNormalBlessings(pname, class, tname) + local value = safeget(safeget(safeget(PallyPower_NormalAssignments, pname), class), tname) + if value == nil then value = 0 end + self:SendMessage("NASSIGN " .. pname .. " " .. class .. " " .. tname .. " " .. value) +end + function PallyPowerGrid_NormalBlessingMenu(btn, mouseBtn, pname, class) if InCombatLockdown() then return end @@ -458,7 +479,7 @@ function PallyPowerGrid_NormalBlessingMenu(btn, mouseBtn, pname, class) if PallyPower_NormalAssignments[pally] and PallyPower_NormalAssignments[pally][class] and PallyPower_NormalAssignments[pally][class][pname] then PallyPower_NormalAssignments[pally][class][pname] = nil end - PallyPower:SendMessage("NASSIGN " .. pally .. " " .. class .. " " .. pname .. " 0") + PallyPower:SendNormalBlessings(pname, class, tname) PallyPower:UpdateLayout() end end @@ -1845,9 +1866,9 @@ function PallyPower:ParseMessage(sender, msg) if strfind(msg, "^CLEAR") then if leader then - self:ClearAssignments(sender) + self:ClearAssignments(sender, strfind(msg, "SKIP")) elseif self.opt.freeassign then - self:ClearAssignments(self.player) + self:ClearAssignments(self.player, strfind(msg, "SKIP")) end end @@ -1928,7 +1949,7 @@ function PallyPower:CheckMainAssists(nick) return raidmainassists[nick] end -function PallyPower:ClearAssignments(sender) +function PallyPower:ClearAssignments(sender, skipAuras) local leader = self:CheckLeader(sender) for name in pairs(PallyPower_Assignments) do if leader or name == self.player then @@ -1946,6 +1967,7 @@ function PallyPower:ClearAssignments(sender) end end end + if skipAuras then return end for name in pairs(PallyPower_AuraAssignments) do if leader or name == self.player then PallyPower_AuraAssignments[name] = 0 @@ -2498,6 +2520,19 @@ function PallyPower:UpdateLayout() pButton:Hide() end end + + -- Preset Button handling: show/hide if leader + local presetButton = _G["PallyPowerBlessingsFramePreset"] + local reportButton = _G["PallyPowerBlessingsFrameReport"] + local autoassignButton = _G["PallyPowerBlessingsAutoAssign"] + if self:CheckLeader(self.player) then + presetButton:Show() + reportButton:SetPoint("BOTTOMRIGHT", presetButton, "BOTTOMLEFT", -7, 0) + else + presetButton:Hide() + reportButton:SetPoint("BOTTOMRIGHT", autoassignButton, "BOTTOMLEFT", -7, 0) + end + self:ButtonsUpdate() self:UpdateAnchor(displayedButtons) end @@ -3778,6 +3813,62 @@ function PallyPower:AutoAssign() end end +function PallyPower:StorePreset() + --save current Assignments to preset + PallyPower_SavedPresets["PallyPower_Assignments"][0] = tablecopy(PallyPower_Assignments) + PallyPower_SavedPresets["PallyPower_NormalAssignments"][0] = tablecopy(PallyPower_NormalAssignments) +end + +function PallyPower:LoadPreset() + -- if leader, load preset and publish to other pallys if possible + if not PallyPower:CheckLeader(PallyPower.player) then return end + + PallyPower:ClearAssignments(PallyPower.player, true) + PallyPower:SendMessage("CLEAR SKIP") + PallyPower_Assignments = tablecopy(PallyPower_SavedPresets["PallyPower_Assignments"][0]) + PallyPower_NormalAssignments = tablecopy(PallyPower_SavedPresets["PallyPower_NormalAssignments"][0]) + C_Timer.After( + 0.25, + function() -- send Class-Assignments + for name in pairs(AllPallys) do + local s = "" + local BuffInfo = PallyPower_Assignments[name] + for i = 1, PALLYPOWER_MAXCLASSES do + if not BuffInfo[i] or BuffInfo[i] == 0 then + s = s .. "n" + else + s = s .. BuffInfo[i] + end + end + PallyPower:SendMessage("PASSIGN " .. name .. "@" .. s) + end + C_Timer.After( + 0.25, + function() -- send Single-Assignments + for pname, passignments in pairs(PallyPower_NormalAssignments) do + if (AllPallys[pname] and PallyPower:GetUnitIdByName(pname) and passignments) then + for class, cassignments in pairs(passignments) do + if cassignments then + for tname, value in pairs(cassignments) do + PallyPower:SendNormalBlessings(pname, class, tname) + end + end + end + end + end + C_Timer.After( + 0.25, + function() + PallyPower:UpdateLayout() + PallyPower:UpdateRoster() + end + ) + end + ) + end + ) +end + function PallyPower:CalcSkillRanks(name) local wisdom, might, kings, salv, light, sanct if AllPallys[name][1] then diff --git a/PallyPowerValues.lua b/PallyPowerValues.lua index 2ab59ca..3dde49d 100644 --- a/PallyPowerValues.lua +++ b/PallyPowerValues.lua @@ -301,6 +301,8 @@ PALLYPOWER_REFRESH = L["Refresh"] PALLYPOWER_REFRESH_DESC = L["PP_REFRESH_TOOLTIP"] PALLYPOWER_AUTOASSIGN = L["Auto-Assign"] PALLYPOWER_AUTOASSIGN_DESC = L["AUTO_ASSIGN_TOOLIP"] +PALLYPOWER_PRESET = L["Preset"] +PALLYPOWER_PRESET_DESC = L["PRESET_TOOLIP"] PALLYPOWER_REPORT = L["Blessings Report"] PALLYPOWER_REPORT_DESC = L["BLESSING_REPORT_TOOLTIP"] PALLYPOWER_FREEASSIGN = L["Free Assignment"] diff --git a/PallyPower_TBC.xml b/PallyPower_TBC.xml index 783edbb..70ac186 100644 --- a/PallyPower_TBC.xml +++ b/PallyPower_TBC.xml @@ -1853,12 +1853,45 @@ + + +