Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 2 save normal blessings / allow Buff Presets #10

Merged
merged 11 commits into from
Jul 25, 2022
Merged
111 changes: 101 additions & 10 deletions PallyPower.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -377,19 +396,21 @@ 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
end
)
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)
SaschaJankowiak marked this conversation as resolved.
Show resolved Hide resolved
end

function PallyPowerGrid_NormalBlessingMenu(btn, mouseBtn, pname, class)
if InCombatLockdown() then return end

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1844,9 +1865,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

Expand Down Expand Up @@ -1927,7 +1948,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
Expand All @@ -1945,6 +1966,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
Expand Down Expand Up @@ -2497,6 +2519,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()
SaschaJankowiak marked this conversation as resolved.
Show resolved Hide resolved
reportButton:SetPoint("BOTTOMRIGHT", autoassignButton, "BOTTOMLEFT", -7, 0)
end

self:ButtonsUpdate()
self:UpdateAnchor(displayedButtons)
end
Expand Down Expand Up @@ -3777,6 +3812,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
Expand Down
2 changes: 2 additions & 0 deletions PallyPowerValues.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
SaschaJankowiak marked this conversation as resolved.
Show resolved Hide resolved
PALLYPOWER_REPORT = L["Blessings Report"]
PALLYPOWER_REPORT_DESC = L["BLESSING_REPORT_TOOLTIP"]
PALLYPOWER_FREEASSIGN = L["Free Assignment"]
Expand Down
35 changes: 34 additions & 1 deletion PallyPower_TBC.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1853,12 +1853,45 @@
</OnLeave>
</Scripts>
</Button>
<Button name = "$parentPreset" inherits = "GameMenuButtonTemplate" text = "PALLYPOWER_PRESET" hidden = "false">
<Size>
<AbsDimension x = "100" y = "20"/>
</Size>
<Anchors>
<Anchor point = "BOTTOMRIGHT" relativeTo = "$parentAutoAssign" relativePoint = "BOTTOMLEFT">
<Offset>
<AbsDimension x = "-7" y = "0"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnClick>
if InCombatLockdown() then return end
if IsShiftKeyDown() then
PallyPower:StorePreset()
else
PallyPower:LoadPreset()
end
</OnClick>
<OnEnter>
if PallyPower.opt.ShowTooltips then
GameTooltip:SetOwner(self, "ANCHOR_BOTTOM");
GameTooltip:SetText(PALLYPOWER_PRESET_DESC);
GameTooltip:Show(self, motion);
CursorUpdate(self, motion);
end
</OnEnter>
<OnLeave>
GameTooltip:Hide(self, motion);
</OnLeave>
</Scripts>
</Button>
<Button name = "$parentReport" inherits = "GameMenuButtonTemplate" text = "PALLYPOWER_REPORT" hidden = "false">
<Size>
<AbsDimension x = "120" y = "20"/>
</Size>
<Anchors>
<Anchor point = "BOTTOMRIGHT" relativeTo = "$parentAutoAssign" relativePoint = "BOTTOMLEFT">
<Anchor point = "BOTTOMRIGHT" relativeTo = "$parentPreset" relativePoint = "BOTTOMLEFT">
<Offset>
<AbsDimension x = "-7" y = "0"/>
</Offset>
Expand Down
35 changes: 34 additions & 1 deletion PallyPower_Vanilla.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1840,12 +1840,45 @@
</OnLeave>
</Scripts>
</Button>
<Button name = "$parentPreset" inherits = "GameMenuButtonTemplate" text = "PALLYPOWER_PRESET" hidden = "false">
<Size>
<AbsDimension x = "100" y = "20"/>
</Size>
<Anchors>
<Anchor point = "BOTTOMRIGHT" relativeTo = "$parentAutoAssign" relativePoint = "BOTTOMLEFT">
<Offset>
<AbsDimension x = "-7" y = "0"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnClick>
if InCombatLockdown() then return end
if IsShiftKeyDown() then
PallyPower:StorePreset()
else
PallyPower:LoadPreset()
end
</OnClick>
<OnEnter>
if PallyPower.opt.ShowTooltips then
GameTooltip:SetOwner(self, "ANCHOR_BOTTOM");
GameTooltip:SetText(PALLYPOWER_PRESET_DESC);
GameTooltip:Show(self, motion);
CursorUpdate(self, motion);
end
</OnEnter>
<OnLeave>
GameTooltip:Hide(self, motion);
</OnLeave>
</Scripts>
</Button>
<Button name = "$parentReport" inherits = "GameMenuButtonTemplate" text = "PALLYPOWER_REPORT" hidden = "false">
<Size>
<AbsDimension x = "120" y = "20"/>
</Size>
<Anchors>
<Anchor point = "BOTTOMRIGHT" relativeTo = "$parentAutoAssign" relativePoint = "BOTTOMLEFT">
<Anchor point = "BOTTOMRIGHT" relativeTo = "$parentPreset" relativePoint = "BOTTOMLEFT">
<Offset>
<AbsDimension x = "-7" y = "0"/>
</Offset>
Expand Down
35 changes: 34 additions & 1 deletion PallyPower_Wrath.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1883,12 +1883,45 @@
</OnLeave>
</Scripts>
</Button>
<Button name = "$parentPreset" inherits = "GameMenuButtonTemplate" text = "PALLYPOWER_PRESET" hidden = "false">
<Size>
<AbsDimension x = "100" y = "20"/>
</Size>
<Anchors>
<Anchor point = "BOTTOMRIGHT" relativeTo = "$parentAutoAssign" relativePoint = "BOTTOMLEFT">
<Offset>
<AbsDimension x = "-7" y = "0"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnClick>
if InCombatLockdown() then return end
if IsShiftKeyDown() then
PallyPower:StorePreset()
else
PallyPower:LoadPreset()
end
</OnClick>
<OnEnter>
if PallyPower.opt.ShowTooltips then
GameTooltip:SetOwner(self, "ANCHOR_BOTTOM");
GameTooltip:SetText(PALLYPOWER_PRESET_DESC);
GameTooltip:Show(self, motion);
CursorUpdate(self, motion);
end
</OnEnter>
<OnLeave>
GameTooltip:Hide(self, motion);
</OnLeave>
</Scripts>
</Button>
<Button name = "$parentReport" inherits = "GameMenuButtonTemplate" text = "PALLYPOWER_REPORT" hidden = "false">
<Size>
<AbsDimension x = "120" y = "20"/>
</Size>
<Anchors>
<Anchor point = "BOTTOMRIGHT" relativeTo = "$parentAutoAssign" relativePoint = "BOTTOMLEFT">
<Anchor point = "BOTTOMRIGHT" relativeTo = "$parentPreset" relativePoint = "BOTTOMLEFT">
<Offset>
<AbsDimension x = "-7" y = "0"/>
</Offset>
Expand Down