Skip to content

Commit

Permalink
add a confirmation popup when setting a goal if one exists to prevent…
Browse files Browse the repository at this point in the history
… accidental override
  • Loading branch information
mynian committed Feb 25, 2022
1 parent e40633f commit ec8b6d5
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions HonorTrack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Addon.HonorGoalAmount:SetPoint("RIGHT", -2, -12);
Addon.HonorPerHourAmount = Addon:CreateFontString("HonorTrack_HonorPerHourAmount", "OVERLAY", "GameFontNormal");
Addon.HonorPerHourAmount:SetPoint("RIGHT", -2, -32);

--Create a dummy frame for update function?
--Create a dummy frame for update function
local hthiddenframe = CreateFrame("Frame")

--Pull the ldb library into here
Expand Down Expand Up @@ -106,10 +106,41 @@ local function SetState(self)
end
end

-- Create a confirmation box if trying to set a goal when one is already set
StaticPopupDialogs["HONORTRACK"] = {
text = "You currently have a goal set. Do you want to start a new goal?",
button1 = ACCEPT,
button2 = CANCEL,
OnAccept = function(self)
hthonorgoal = hthonorgoalnew
Addon.HonorGoalAmount:SetText(hthonorgoal)
--Let the user know it worked and what we set the goal to.
print("Honor Track: Honor Goal set to " .. hthonorgoal)
htgoalset = true
end,
timeout = 0,
whileDead = true,
hideOnEscape = false,
}

-- Function to set the goal amount based on input from the slash command
local function UpdateNewGoal(self)
--check if goal set
if hthonorgoal ~= 0 then
--Call confirmation box if one is already set
StaticPopup_Show("HONORTRACK")
else
--Set goal if one is not already set
hthonorgoal = hthonorgoalnew
Addon.HonorGoalAmount:SetText(hthonorgoal)
print("Honor Track: Honor Goal set to " .. hthonorgoal)
htgoalset = true
end
end

--Function to set the text on login and when resetting goal
local function UpdateGoal(self)
Addon.HonorGoalAmount:SetText(hthonorgoal)
Addon.HonorGoalAmount:SetText(hthonorgoal)
end

--Create Slash Commands
Expand Down Expand Up @@ -138,12 +169,9 @@ function SlashCmdList.HONORTRACK(msg, editBox)
--Set the goal command check. This makes sure the user input only numbers and errors if they didn't
elseif string.lower(command) == 'goal' and string.match(rest, "%d*") ~= nil and string.match(rest, "%a") == nil then
--Grab the goal amount entered
hthonorgoal = string.match(rest, "%d*")
hthonorgoalnew = string.match(rest, "%d*")
--Send the goal to the update function
UpdateGoal(self)
htgoalset = true
--Let the user know it worked and what we set the goal to.
print("Honor Track: Honor Goal set to " .. string.match(rest, "%d*"))
UpdateNewGoal(self)
--Reset the goal
elseif string.lower(command) == 'goal' and string.lower(rest) == "reset" then
--Set the goal to 0
Expand Down

0 comments on commit ec8b6d5

Please sign in to comment.