From 0f77c19c3bac60c9e5d1f18987024db553991a0e Mon Sep 17 00:00:00 2001 From: Pokey Date: Fri, 26 Jan 2024 18:43:46 -0500 Subject: [PATCH 1/3] Code cleanup --- RollTracker.lua | 548 +++++++++++++----------------------------------- 1 file changed, 142 insertions(+), 406 deletions(-) diff --git a/RollTracker.lua b/RollTracker.lua index 0a93bfd..54e720a 100644 --- a/RollTracker.lua +++ b/RollTracker.lua @@ -1,12 +1,89 @@ -- RollTracker.lua --- ----Start of options---- +-- ####Start of setup#### + +local dropDowns = {["dropDownPlayer"] = "", ["dropDownLocation"] = "",["dropDownItem"] = "", ["dropDownRollType"] = ""} +local firstUse = true +-- Get the player's name +local playerName = UnitName("player") +-- Set Roll Reason +local rollReason = nil +-- Create a table to keep track of the roll texts +local rollTexts = {} + +-- Functions + +-- Function to do ipairs in reverse order +function rpairs(t) + return function(t, i) + i = i - 1 + if i ~= 0 then + return i, t[i] + end + end, t, #t + 1 +end + +-- Function to clear history +local function ClearHistory() + if next(RollTrackerDB) ~= nil then + StaticPopupDialogs["CLEAR_ROLL_HISTORY"] = { + text = "Are you sure you want to clear the roll history?", + button1 = "Accept", + button2 = "Decline", + OnAccept = function() + wipe(RollTrackerDB) + UpdateHistory() + end, + timeout = 0, + whileDead = true, + hideOnEscape = true, + preferredIndex = 3, + } + StaticPopup_Show("CLEAR_ROLL_HISTORY") + end +end + +-- Function to handle rolling for a reason +local function RollReason() + StaticPopupDialogs["Roll_With_Reason"] = { + text = "What is the reason for rolling?", + hasEditBox = 1, + maxLetters = 500, + button1 = "Roll", + button2 = "Cancel", + OnShow = function(self) + local editBox = self.editBox + editBox:SetText("Chest") + editBox:HighlightText() + if editBox:HasFocus() then + hooksecurefunc("ChatEdit_InsertLink", function(text) + editBox:SetText(text) + end) + end + end, + OnAccept = function(self) + local editBox = self.editBox + rollReason = editBox:GetText() + RandomRoll(1, 100) -- Roll + end, + timeout = 0, + whileDead = true, + hideOnEscape = true, + preferredIndex = 3, + } + StaticPopup_Show("Roll_With_Reason") +end + +-- ####End of setup#### + +-- ####Start of options#### -- Check if the DB exists and if not, initialize it if not options then options = {} end +-- Create options frame local optionsPanel = CreateFrame("Frame") optionsPanel:RegisterEvent("ADDON_LOADED") optionsPanel.name = "Roll Tracker" @@ -28,19 +105,19 @@ local optionsTitle = optionsScrollChild:CreateFontString("ARTWORK", nil, "GameFo optionsTitle:SetPoint("TOP") optionsTitle:SetText("Roll Tracker") +-- Display date check box displayDateCheckButton = CreateFrame("CheckButton", "displayDateCheckButton", optionsScrollChild, "ChatConfigCheckButtonTemplate"); displayDateCheckButton:SetPoint("TOPLEFT", 10, -15); displayDateCheckButton:SetText("Display Dates"); displayDateCheckButton.tooltip = "When checked Roll Tracker will display the date the roll was made on"; +-- Only set check box once addon is loaded otherwise DB is not avalable optionsPanel:SetScript("OnEvent", function (self, event) if event == "ADDON_LOADED" then if options["displayDate"] then displayDateCheckButton:SetChecked(true) - -- print("Display date was true") -- Debug else displayDateCheckButton:SetChecked(false) - -- print("Display date was false") -- Debug end end end) @@ -48,40 +125,32 @@ displayDateCheckButton:SetScript("OnClick", function() if displayDateCheckButton:GetChecked() then options["displayDate"] = true - -- print("Checked!") -- Debug else options["displayDate"] = false - -- print("Unchecked!") -- Debug end end ); +-- Display date text optionsScrollChild.rollTypeText = optionsScrollChild:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") optionsScrollChild.rollTypeText:SetText("Display Date?") optionsScrollChild.rollTypeText:SetTextColor(1, 1, 1) -- White color optionsScrollChild.rollTypeText:SetPoint("TOPLEFT",35,-20) +-- Footer text local optionsFooter = optionsScrollChild:CreateFontString("ARTWORK", nil, "GameFontNormal") -optionsFooter:SetPoint("TOP", 0, -5000) -optionsFooter:SetText("This is 5000 below the top, so the scrollChild automatically expanded.") +optionsFooter:SetPoint("TOP", 0, -550) +optionsFooter:SetText("Made by |cFF69CCF0Pokey|r to satisfy my curiosity") --- ----End of options---- +-- ####End of options#### + +-- ####Start Main addon#### -- Create a frame to handle events local frame = CreateFrame("FRAME") frame:RegisterEvent("CHAT_MSG_SYSTEM") frame:RegisterEvent("CHAT_MSG_LOOT") -local dropDowns = {["dropDownPlayer"] = "", ["dropDownLocation"] = "",["dropDownItem"] = "", ["dropDownRollType"] = ""} - -local firstUse = true - --- Get the player's name -local playerName = UnitName("player") - --- Set Roll Reason -local rollReason = nil - -- Event handler function local function OnEvent(self, event, ...) local message = ... @@ -136,9 +205,6 @@ end -- Register the event handler frame:SetScript("OnEvent", OnEvent) --- Create a table to keep track of the roll texts -local rollTexts = {} - -- Create a container frame local containerFrame = CreateFrame("Frame", "RollTrackerContainer", UIParent, "BasicFrameTemplate") containerFrame:ClearAllPoints() -- Reset window position @@ -150,7 +216,7 @@ containerFrame:SetMovable(true) -- Make the container frame movable containerFrame:EnableMouse(false) -- Enable mouse interaction containerFrame:Hide() - +-- Make sure to hide the history frame when the container frame X is clicked containerFrame.CloseButton:SetScript("OnClick", function() containerFrame.historyFrame:Hide() containerFrame:Hide() @@ -192,15 +258,13 @@ containerFrame.historyFrame = CreateFrame("ScrollFrame", "RollTrackerHistoryFram containerFrame.historyFrame:SetSize(450, 280) containerFrame.historyFrame:SetPoint("TOPLEFT",10,-68) containerFrame.historyFrame:SetPoint("TOPRIGHT",-30,0) ---containerFrame.historyFrame:SetPoint("BOTTOM", containerFrame, "BOTTOM", 0, 0) -- Position to the bottom of the container frame containerFrame.historyFrame:SetFrameStrata("BACKGROUND") containerFrame.historyFrame:Hide() containerFrame.contentFrame = CreateFrame("Frame", "RollTrackerContentFrame", containerFrame.historyFrame) -containerFrame.contentFrame:SetSize(240, 240) -- Adjust the size to accommodate the text +containerFrame.contentFrame:SetSize(240, 240) containerFrame.contentFrame:SetPoint("TOPLEFT",10,-48) containerFrame.contentFrame:SetPoint("TOPRIGHT",-30,0) ---containerFrame.contentFrame:SetPoint("TOPLEFT", containerFrame.historyFrame, "TOPLEFT", 5, -5) -- Adjust the position and add a small padding containerFrame.contentFrame:SetFrameStrata("BACKGROUND") containerFrame.contentFrame:SetHyperlinksEnabled(true) @@ -224,30 +288,25 @@ containerFrame.historyFrame:SetScrollChild(containerFrame.contentFrame) -- Create player drop-down menu containerFrame.playerDropDown = CreateFrame("Frame", "RollTrackerPlayerDropDown", containerFrame, "UIDropDownMenuTemplate") ---containerFrame.locationDropDown:ClearAllPoints() -- Reset window position ---containerFrame.locationDropDown:SetPoint("TOPLEFT", containerFrame, "TOPLEFT", 120, 00) containerFrame.playerDropDown:SetPoint("TOPLEFT",-15,-35) ---containerFrame.playerDropDown:SetPoint("TOPRIGHT",0,0) UIDropDownMenu_SetWidth(containerFrame.playerDropDown,80,0) UIDropDownMenu_JustifyText(containerFrame.playerDropDown,"LEFT") containerFrame.playerDropDown:Hide() -- Hide initially +-- Player dropdown label containerFrame.characterNameText = containerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") containerFrame.characterNameText:SetText("Character") containerFrame.characterNameText:SetTextColor(1, 1, 1) -- White color containerFrame.characterNameText:SetPoint("TOPLEFT",30,-25) --- containerFrame.characterNameText:SetPoint("TOPRIGHT",0,0) -- Create location drop-down menu containerFrame.locationDropDown = CreateFrame("Frame", "RollTrackerLocationDropDown", containerFrame, "UIDropDownMenuTemplate") ---containerFrame.locationDropDown:ClearAllPoints() -- Reset window position ---containerFrame.locationDropDown:SetPoint("TOPLEFT", containerFrame, "TOPLEFT", 120, 00) containerFrame.locationDropDown:SetPoint("TOPLEFT",85,-35) ---containerFrame.locationDropDown:SetPoint("TOPRIGHT",0,0) UIDropDownMenu_SetWidth(containerFrame.locationDropDown,80,0) UIDropDownMenu_JustifyText(containerFrame.locationDropDown,"LEFT") containerFrame.locationDropDown:Hide() -- Hide initially +-- Location drop down label containerFrame.locationText = containerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") containerFrame.locationText:SetText("Location") containerFrame.locationText:SetTextColor(1, 1, 1) -- White color @@ -255,14 +314,12 @@ containerFrame.locationText:SetPoint("TOPLEFT",130,-25) -- Create item drop-down menu containerFrame.itemDropDown = CreateFrame("Frame", "RollTrackerItemDropDown", containerFrame, "UIDropDownMenuTemplate") ---containerFrame.locationDropDown:ClearAllPoints() -- Reset window position ---containerFrame.locationDropDown:SetPoint("TOPLEFT", containerFrame, "TOPLEFT", 120, 00) containerFrame.itemDropDown:SetPoint("TOPLEFT",185,-35) ---containerFrame.locationDropDown:SetPoint("TOPRIGHT",0,0) UIDropDownMenu_SetWidth(containerFrame.itemDropDown,120,0) UIDropDownMenu_JustifyText(containerFrame.itemDropDown,"LEFT") containerFrame.itemDropDown:Hide() -- Hide initially +-- Item drop down label containerFrame.itemText = containerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") containerFrame.itemText:SetText("Item") containerFrame.itemText:SetTextColor(1, 1, 1) -- White color @@ -270,14 +327,12 @@ containerFrame.itemText:SetPoint("TOPLEFT",260,-25) -- Create roll type drop-down menu containerFrame.rollTypeDropDown = CreateFrame("Frame", "RollTrackerrollTypeDropDown", containerFrame, "UIDropDownMenuTemplate") ---containerFrame.locationDropDown:ClearAllPoints() -- Reset window position ---containerFrame.locationDropDown:SetPoint("TOPLEFT", containerFrame, "TOPLEFT", 120, 00) containerFrame.rollTypeDropDown:SetPoint("TOPLEFT",325,-35) ---containerFrame.locationDropDown:SetPoint("TOPRIGHT",0,0) UIDropDownMenu_SetWidth(containerFrame.rollTypeDropDown,60,0) UIDropDownMenu_JustifyText(containerFrame.rollTypeDropDown,"LEFT") containerFrame.rollTypeDropDown:Hide() -- Hide initially +-- Roll type drop down label containerFrame.rollTypeText = containerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") containerFrame.rollTypeText:SetText("Roll Type") containerFrame.rollTypeText:SetTextColor(1, 1, 1) -- White color @@ -288,101 +343,8 @@ containerFrame.NoRolls = containerFrame:CreateFontString(nil,"ARTWORK","GameFon containerFrame.NoRolls:SetPoint("TOPLEFT",8,-24) containerFrame.NoRolls:SetPoint("BOTTOMRIGHT",-10,8) ---f.Text = f:CreateFontString(nil,"ARTWORK","GameFontNormalLarge") ---f.Text:SetPoint("TOPLEFT",8,-24) ---f.Text:SetPoint("BOTTOMRIGHT",-10,8) ---f.Text:SetText("This is centered text.\n\nDrag the lower right corner of the window to resize it. Drag any other part of the window to move it.") ---f.Text:SetJustifyH("CENTER") -- probably not needed ---f.Text:SetJustifyV("CENTER") -- probably not needed either - --- Create a background frame ---local bgFrame = CreateFrame("Frame", "RollTrackerBgFrame", containerFrame) ---bgFrame:SetSize(450, 300) -- Set the size to match historyFrame ---bgFrame:SetPoint("BOTTOM", containerFrame, "BOTTOM", 0, 0) -- Position to match historyFrame ---bgFrame:SetFrameLevel(0) -- To ensure it stays behind the contentFrame ---bgFrame:SetFrameStrata("BACKGROUND") ---bgFrame:Hide() -- Hide the black frame on load - --- Create background background ---local bgFrameBackground = bgFrame:CreateTexture(nil, "BACKGROUND") ---bgFrameBackground:SetAllPoints() ---bgFrameBackground:SetColorTexture(0, 0, 0, 0.50) -- Black color with 50% opacity - --- Create frame border ---[[ -bgFrame.border = CreateFrame("Frame", nil, bgFrame, "BackdropTemplate") -bgFrame.border:SetPoint("TOPLEFT", -5, 5) -bgFrame.border:SetPoint("BOTTOMRIGHT", 5, -5) -bgFrame.border:SetBackdrop({ - bgFile = "Interface\\Stationery\\StationeryTest1", - edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", - edgeSize = 16, - insets = { left = 5, right = 5, top = 5, bottom = 5 }, -}) -bgFrame.border:SetBackdropBorderColor(0.6, 0.6, 0.6) -- Light gray color - ---]] - ---[[ --- Create history frame -local historyFrame = CreateFrame("ScrollFrame", "RollTrackerHistoryFrame", containerFrame, "UIPanelScrollFrameTemplate") -historyFrame:SetSize(450, 300) -historyFrame:SetPoint("BOTTOM", containerFrame, "BOTTOM", 0, 0) -- Position to the bottom of the container frame -historyFrame:SetFrameStrata("BACKGROUND") -historyFrame:Hide() ---]] - ---[[ --- Create scrollable content frame -local contentFrame = CreateFrame("Frame", "RollTrackerContentFrame", containerFrame.historyFrame) -contentFrame:SetSize(240, 240) -- Adjust the size to accommodate the text -contentFrame:SetPoint("TOPLEFT", containerFrame.historyFrame, "TOPLEFT", 5, -5) -- Adjust the position and add a small padding -contentFrame:SetFrameStrata("BACKGROUND") -contentFrame:SetHyperlinksEnabled(true) ---]] - ---[[ --- Create a title bar -local titleBar = CreateFrame("Frame", "RollTrackerTitleBar", containerFrame) -titleBar:SetSize(450, 70) -- Increase the height to accommodate the text -titleBar:SetPoint("BOTTOM", historyFrame, "TOP", 0, 0) -- Position at the top of the history frame -titleBar:SetFrameStrata("BACKGROUND") -titleBar:Hide() -- Hide the title bar initially - --- Create title bar background -local titleBarBackground = titleBar:CreateTexture(nil, "BACKGROUND") -titleBarBackground:SetAllPoints() -titleBarBackground:SetColorTexture(0, 0, 0, 0.50) -- Black color with 50% opacity - --- Create title text -local titleText = titleBar:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge") -titleText:SetText("ROLL HISTORY") -titleText:SetPoint("CENTER", titleBar, "TOP", 0, -10) - --- Create percentage text -local percentageText = titleBar:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall") -percentageText:SetTextColor(1, 1, 1) -- White color -percentageText:SetPoint("TOP", titleText, "BOTTOM", 0, -5) ---]] - -function rpairs(t) - return function(t, i) - i = i - 1 - if i ~= 0 then - return i, t[i] - end - end, t, #t + 1 -end - -- Function to update history based on selected location -local function UpdateHistoryByLocation(location) - -- print("UpdateHistoryByLocation called with location:", location) -- debugging - - --[[ - for k, v in pairs(dropDowns) do -- Debug - print(k,v) -- Debug - end - --]] +local function UpdateHistory() -- Check if RollTrackerDB exists if not RollTrackerDB then @@ -395,49 +357,28 @@ local function UpdateHistoryByLocation(location) end wipe(rollTexts) - -- Print the content of RollTrackerDB for debugging - -- print("RollTrackerDB content:", #RollTrackerDB) - for i, rollData in ipairs(RollTrackerDB) do - -- print(i, rollData.location, rollData.roll) - end - -- Populate content frame with roll history for the selected location local rolls25AndUnder = 0 local rolls75AndAbove = 0 for i, rollData in rpairs(RollTrackerDB) do - --if location == "All" or rollData.location == location or then -- Old - --if dropDowns["dropDownLocation"] == "All" or rollData.location == dropDowns["dropDownLocation"] and dropDowns["dropDownPlayer"] == "All" or rollData.name == dropDowns["dropDownPlayer"] then - --if dropDowns["dropDownLocation"] == "All" or rollData.location == dropDowns["dropDownLocation"] then -- Debug Works - --if dropDowns["dropDownPlayer"] == "All" or rollData.name == dropDowns["dropDownPlayer"] then -- Debug Works if dropDowns["dropDownLocation"] == "All" or rollData.location == dropDowns["dropDownLocation"] then if dropDowns["dropDownPlayer"] == "All" or rollData.name == dropDowns["dropDownPlayer"] then if dropDowns["dropDownItem"] == "All" or rollData.item == dropDowns["dropDownItem"] then if dropDowns["dropDownRollType"] == "All" or rollData.type == dropDowns["dropDownRollType"] then - - - - -- print("Drop downs - Location: " .. dropDowns["dropDownLocation"] .. " Player: " .. dropDowns["dropDownPlayer"]) -- debug - -- print("Roll data - Location: " .. rollData.location .. " Player: " .. rollData.name) -- debug if rollData.item == nil then rollData.item = "Unknown" end local dateText = date("%m/%d/%Y", rollData.timestamp or 0) local rollText = containerFrame.contentFrame:CreateFontString("RollTrackerRollText", "HIGHLIGHT", "GameFontNormalSmall") - --rollText:SetPoint("TOPLEFT",0,-0) - --rollText:SetPoint("TOPRIGHT",-0,0) - --rollText:SetJustifyH("CENTER") - --rollText:SetText(dateText .. " | " .. rollData.name .. " | " .. rollData.location .. " | " .. rollData.item .. " | " ..rollData.type .. " | " .. rollData.roll) local showDate - if options["displayDate"] then showDate = dateText .. " | " else showDate = "" end rollText:SetText(showDate .. rollData.name .. " | " .. rollData.location .. " | " .. rollData.item .. " | " ..rollData.type .. " | " .. rollData.roll) - -- print(dateText .. " | " .. rollData.location .. " | " .. rollData.item .. " | " ..rollData.type .. " | " .. rollData.roll) -- Debug rollText:SetTextColor(1, 1, 1) if rollData.roll >= 75 then @@ -450,7 +391,6 @@ local function UpdateHistoryByLocation(location) rollText:SetTextColor(1, 1, 0) end - --rollText:SetPoint("TOPLEFT", containerFrame.contentFrame, "TOPLEFT", 10, -10 - 15 * (#rollTexts + 1)) rollText:SetPoint("TOPLEFT", containerFrame.contentFrame, "TOPLEFT", 0, - 15 * (#rollTexts + 1)) rollText:SetDrawLayer("OVERLAY") rollText:Show() @@ -496,38 +436,10 @@ end -- Function to handle location drop-down menu selection local function OnLocationDropDownSelect(self, arg1, arg2, checked) - -- print("OnLocationDropDownSelect location:", arg1) -- debugging local selectedLocation = arg1 or "All" -- Use "All" if arg1 is nil UIDropDownMenu_SetText(containerFrame.locationDropDown, selectedLocation) dropDowns["dropDownLocation"] = selectedLocation - UpdateHistoryByLocation(selectedLocation) -end - --- Function to handle player drop-down menu selection -local function OnPlayerDropDownSelect(self, arg1, arg2, checked) - -- print("OnLocationDropDownSelect location:", arg1) -- debugging - local selectedPlayer = arg1 or "All" -- Use Player name if arg1 is nil - UIDropDownMenu_SetText(containerFrame.playerDropDown, selectedPlayer) - dropDowns["dropDownPlayer"] = selectedPlayer - UpdateHistoryByLocation(selectedPlayer) -end - --- Function to handle item drop-down menu selection -local function OnItemDropDownSelect(self, arg1, arg2, checked) - -- print("OnLocationDropDownSelect location:", arg1) -- debugging - local selectedItem = arg1 or "All" -- Use Player name if arg1 is nil - UIDropDownMenu_SetText(containerFrame.itemDropDown, selectedItem) - dropDowns["dropDownItem"] = selectedItem - UpdateHistoryByLocation(selectedItem) -end - --- Function to handle roll type drop-down menu selection -local function OnRollTypeDropDownSelect(self, arg1, arg2, checked) - -- print("OnLocationDropDownSelect location:", arg1) -- debugging - local selectedRollType = arg1 or "All" -- Use Player name if arg1 is nil - UIDropDownMenu_SetText(containerFrame.rollTypeDropDown, selectedRollType) - dropDowns["dropDownRollType"] = selectedRollType - UpdateHistoryByLocation(selectedRollType) + UpdateHistory() end -- Initialize location drop-down menu with default value @@ -552,6 +464,19 @@ UIDropDownMenu_Initialize(containerFrame.locationDropDown, function() end end) +-- Set the initial selected value for locationDropDown +local initialLocation = "All" +UIDropDownMenu_SetText(containerFrame.locationDropDown, initialLocation) +OnLocationDropDownSelect(nil, initialLocation) -- Manually trigger the initial selection + +-- Function to handle player drop-down menu selection +local function OnPlayerDropDownSelect(self, arg1, arg2, checked) + local selectedPlayer = arg1 or "All" -- Use "All" if arg1 is nil + UIDropDownMenu_SetText(containerFrame.playerDropDown, selectedPlayer) + dropDowns["dropDownPlayer"] = selectedPlayer + UpdateHistory() +end + -- Initialize player drop-down menu with default value UIDropDownMenu_Initialize(containerFrame.playerDropDown, function() local info = UIDropDownMenu_CreateInfo() @@ -574,6 +499,19 @@ UIDropDownMenu_Initialize(containerFrame.playerDropDown, function() end end) +-- Set the initial selected value for playerDropDown +local initialPlayer = playerName +UIDropDownMenu_SetText(containerFrame.playerDropDown, initialPlayer) +OnPlayerDropDownSelect(nil, initialPlayer) -- Manually trigger the initial selection + +-- Function to handle item drop-down menu selection +local function OnItemDropDownSelect(self, arg1, arg2, checked) + local selectedItem = arg1 or "All" -- Use "All" if arg1 is nil + UIDropDownMenu_SetText(containerFrame.itemDropDown, selectedItem) + dropDowns["dropDownItem"] = selectedItem + UpdateHistory() +end + -- Initialize item drop-down menu with default value UIDropDownMenu_Initialize(containerFrame.itemDropDown, function() local info = UIDropDownMenu_CreateInfo() @@ -596,6 +534,19 @@ UIDropDownMenu_Initialize(containerFrame.itemDropDown, function() end end) +-- Set the initial selected value for itemDropDown +local initialItem = "All" +UIDropDownMenu_SetText(containerFrame.itemDropDown, initialItem) +OnItemDropDownSelect(nil, initialItem) -- Manually trigger the initial selection + +-- Function to handle roll type drop-down menu selection +local function OnRollTypeDropDownSelect(self, arg1, arg2, checked) + local selectedRollType = arg1 or "All" -- Use "All" if arg1 is nil + UIDropDownMenu_SetText(containerFrame.rollTypeDropDown, selectedRollType) + dropDowns["dropDownRollType"] = selectedRollType + UpdateHistory() +end + -- Initialize roll type drop-down menu with default value UIDropDownMenu_Initialize(containerFrame.rollTypeDropDown, function() local info = UIDropDownMenu_CreateInfo() @@ -618,214 +569,14 @@ UIDropDownMenu_Initialize(containerFrame.rollTypeDropDown, function() end end) --- Set the initial selected value for locationDropDown -local initialLocation = "All" -UIDropDownMenu_SetText(containerFrame.locationDropDown, initialLocation) -OnLocationDropDownSelect(nil, initialLocation) -- Manually trigger the initial selection - --- Set the initial selected value for playerDropDown -local initialPlayer = playerName -UIDropDownMenu_SetText(containerFrame.playerDropDown, initialPlayer) -OnPlayerDropDownSelect(nil, initialPlayer) -- Manually trigger the initial selection - --- Set the initial selected value for itemDropDown -local initialItem = "All" -UIDropDownMenu_SetText(containerFrame.itemDropDown, initialItem) -OnItemDropDownSelect(nil, initialItem) -- Manually trigger the initial selection - -- Set the initial selected value for rollType local initialRollType = "All" UIDropDownMenu_SetText(containerFrame.rollTypeDropDown, initialRollType) OnItemDropDownSelect(nil, initialRollType) -- Manually trigger the initial selection +-- ####End Main addon#### - - ---[[ --- Create close button -local closeButton = CreateFrame("Button", nil, containerFrame.historyFrame, "GameMenuButtonTemplate") -closeButton:SetPoint("TOP", containerFrame.historyFrame, "BOTTOM", -55, -10) -- Adjust the X position to center the button -closeButton:SetSize(100, 25) -closeButton:SetText("Close") -closeButton:SetScript("OnClick", function() - containerFrame.historyFrame:Hide() - titleBar:Hide() -- Hide the title bar when clicked - --bgFrame:Hide() -- Hide the black frame when clicked - locationDropDown:Hide() - RollTrackerContainer:EnableMouse(false) -end) -closeButton:Hide() -- Hide the close button on load ---]] - ---[[ --- Create clear history button -local clearButton = CreateFrame("Button", nil, containerFrame.historyFrame, "GameMenuButtonTemplate") -clearButton:SetPoint("TOP", containerFrame.historyFrame, "TOP", 110, 0) -- Adjust the X position to center the button -clearButton:SetSize(100, 25) -clearButton:SetText("Clear History") -clearButton:Hide() -- Hide the clear button on load ---]] - --- Function to update history ---[[ -local function UpdateHistory() - -- Clear content frame - for _, rollText in ipairs(rollTexts) do - rollText:Hide() - end - wipe(rollTexts) - - -- Populate content frame with roll history - -- Check if the DB exists and if not, initialize it - if not RollTrackerDB then - RollTrackerDB = {} - end - - local rolls25AndUnder = 0 - local rolls75AndAbove = 0 - - for i, rollData in ipairs(RollTrackerDB) do - if rollData.item == nil then - rollData.item = "Unknown" - end - local dateText = date("%m/%d/%Y", rollData.timestamp or 0) -- Get the date in MM/DD/YYYY format - local rollText = contentFrame:CreateFontString(nil, "HIGHLIGHT", "GameFontNormalSmall") - rollText:SetText(dateText .. " | " .. rollData.location .. " | " .. rollData.item .. " | " ..rollData.type .. " | " .. rollData.roll) - rollText:SetTextColor(1, 1, 1) -- White color - - -- Change text color based on roll value - if rollData.roll >= 75 then - rollText:SetTextColor(0, 1, 0) -- Green for rolls 75 and above - rolls75AndAbove = rolls75AndAbove + 1 - elseif rollData.roll <= 25 then - rollText:SetTextColor(1, 0, 0) -- Red for rolls 25 and below - rolls25AndUnder = rolls25AndUnder + 1 - else - rollText:SetTextColor(1, 1, 0) -- Yellow for all other rolls - end - - rollText:SetPoint("TOPLEFT", contentFrame, "TOPLEFT", 10, -10 - 15 * (i - 1)) -- Adjust the starting point and set draw layer - rollText:SetDrawLayer("OVERLAY") -- Set the draw layer to OVERLAY - - rollText:Show() - - -- Add the roll text to the table - table.insert(rollTexts, rollText) - end - - -- Calculate percentages - local totalRolls = #RollTrackerDB - if totalRolls > 0 then - local percentage25AndUnder = (rolls25AndUnder / totalRolls) * 100 - local percentage75AndAbove = (rolls75AndAbove / totalRolls) * 100 - - -- Update percentage text - percentageText:SetText(string.format("Percentage of rolls 25 and under: %.2f%% | Percentage of rolls 75 and over: %.2f%%", percentage25AndUnder, percentage75AndAbove)) - else - percentageText:SetText("No roll history available") - end -end ---]] - --- Function to clear history -local function ClearHistory() - if next(RollTrackerDB) ~= nil then - StaticPopupDialogs["CLEAR_ROLL_HISTORY"] = { - text = "Are you sure you want to clear the roll history?", - button1 = "Accept", - button2 = "Decline", - OnAccept = function() - wipe(RollTrackerDB) - UpdateHistoryByLocation("Unknown") -- Was UpdateHistory() - end, - timeout = 0, - whileDead = true, - hideOnEscape = true, - preferredIndex = 3, - } - StaticPopup_Show("CLEAR_ROLL_HISTORY") - end -end - --- Function to handle rolling for a reason -local function RollReason() - StaticPopupDialogs["Roll_With_Reason"] = { - text = "What is the reason for rolling?", - hasEditBox = 1, - maxLetters = 500, - button1 = "Roll", - button2 = "Cancel", - OnShow = function(self) - local editBox = self.editBox - editBox:SetText("Chest") - editBox:HighlightText() - if editBox:HasFocus() then - hooksecurefunc("ChatEdit_InsertLink", function(text) - editBox:SetText(text) - --local clickedItem = text - --print(clickedItem) - end) - end - end, - OnAccept = function(self) - local editBox = self.editBox - rollReason = editBox:GetText() - RandomRoll(1, 100) -- Roll - -- print(rollReason) -- Debug - end, - timeout = 0, - whileDead = true, - hideOnEscape = true, - preferredIndex = 3, - } - StaticPopup_Show("Roll_With_Reason") -end - --- clearButton:SetScript("OnClick", ClearHistory) - ---[[ --- Make the container frame draggable -containerFrame:SetScript("OnMouseDown", function(self, button) - if button == "LeftButton" and not self.isMoving then - self:StartMoving() - self.isMoving = true - end -end) -containerFrame:SetScript("OnMouseUp", function(self, button) - if button == "LeftButton" and self.isMoving then - self:StopMovingOrSizing() - self.isMoving = false - end -end) -containerFrame:SetScript("OnHide", function(self) - if self.isMoving then - self:StopMovingOrSizing() - self.isMoving = false - end -end) ---]] - ---[[ --- Slash command to display roll history -SLASH_rolltracker1 = "/rh" -SLASH_rolltracker2 = "/rollhistory" -SlashCmdList["rolltracker"] = function() - -- Check if the DB exists and if not, print no rolls recorded - if not RollTrackerDB or #RollTrackerDB == 0 then - print("No rolls recorded.") - else - -- UpdateHistory() - containerFrame.historyFrame:Show() - UpdateHistoryByLocation("All") - titleBar:Show() -- Show the title bar when the command is used - --closeButton:Show() -- Show the close button when the command is used - clearButton:Show() -- Show the clear history button when the command is used - --bgFrame:Show() -- Show the black frame when the command is used - locationDropDown:Show() - RollTrackerContainer:EnableMouse(true) - end -end ---]] +-- ####Start Minimap Button#### -- Create a button frame local minimapButton = CreateFrame("Button", "RollTrackerMinimapButton", Minimap) @@ -852,29 +603,16 @@ minimapButton:SetScript("OnClick", function(self, button) dropDowns = {["dropDownPlayer"] = playerName, ["dropDownLocation"] = GetRealZoneText(), ["dropDownItem"] = "All", ["dropDownRollType"] = "All"} OnLocationDropDownSelect(nil, GetRealZoneText()) -- Manually trigger the initial selection end - --local initialLocation = "All" - --UIDropDownMenu_SetText(containerFrame.locationDropDown, initialLocation) - - -- UpdateHistory() - --UpdateHistoryByLocation("All") containerFrame.historyFrame:Show() - --titleBar:Show() -- Show the title bar when the command is used - --closeButton:Show() -- Show the close button when the command is used - --clearButton:Show() -- Show the clear history button when the command is used - --bgFrame:Show() -- Show the black frame when the command is used containerFrame.locationDropDown:Show() containerFrame.playerDropDown:Show() containerFrame.itemDropDown:Show() containerFrame.rollTypeDropDown:Show() containerFrame:Show() containerFrame:EnableMouse(true) - UpdateHistoryByLocation(GetRealZoneText()) -- Update history for current location + UpdateHistory() -- Update history else containerFrame.historyFrame:Hide() - --titleBar:Hide() -- Show the title bar when the command is used - --closeButton:Hide() -- Show the close button when the command is used - --clearButton:Hide() -- Show the clear history button when the command is used - --bgFrame:Hide() -- Show the black frame when the command is used containerFrame.locationDropDown:Hide() containerFrame.playerDropDown:Hide() containerFrame.itemDropDown:Hide() @@ -883,7 +621,6 @@ minimapButton:SetScript("OnClick", function(self, button) containerFrame:EnableMouse(false) end elseif IsShiftKeyDown() and IsLeftAltKeyDown() and button == "RightButton" then - --print("Shift Alt Right!") -- Debug ClearHistory() elseif IsShiftKeyDown() and button == "RightButton" then RollReason() @@ -891,16 +628,13 @@ minimapButton:SetScript("OnClick", function(self, button) containerFrame:ClearAllPoints() -- Reset window position containerFrame:SetSize(450, 360) containerFrame:SetPoint("CENTER") - --locationDropDown:ClearAllPoints() -- Reset window position - --locationDropDown:SetPoint("TOPLEFT", containerFrame, "TOPLEFT", 120, 00) elseif IsLeftAltKeyDown() and button == "RightButton" then InterfaceAddOnsList_Update() InterfaceOptionsFrame_OpenToCategory(optionsPanel) - --InterfaceOptionsFrame_Show() elseif button == "RightButton" then -- Use the built-in /roll command for right-click RandomRoll(1, 100) -- Roll - UpdateHistoryByLocation(GetRealZoneText()) + UpdateHistory() end end) @@ -938,6 +672,8 @@ minimapButton:SetScript("OnLeave", function() GameTooltip:Hide() end) +-- ####End Minimap Button#### -UpdateHistoryByLocation("All") -- Maybe not needed? -containerFrame:EnableMouse(false) \ No newline at end of file +-- Dont think these are needed any more but leaving them for now in case any bugs are reported +--UpdateHistory() -- Maybe not needed? +--containerFrame:EnableMouse(false) -- Without this mouse does not work when addon is hidden \ No newline at end of file From 6ffc34d843f409e1cd38036315a1166ab9c8fae9 Mon Sep 17 00:00:00 2001 From: Pokey Date: Fri, 26 Jan 2024 18:54:58 -0500 Subject: [PATCH 2/3] Fixed error when clearing history after code cleanup --- RollTracker.lua | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/RollTracker.lua b/RollTracker.lua index 54e720a..597abfc 100644 --- a/RollTracker.lua +++ b/RollTracker.lua @@ -23,26 +23,6 @@ function rpairs(t) end, t, #t + 1 end --- Function to clear history -local function ClearHistory() - if next(RollTrackerDB) ~= nil then - StaticPopupDialogs["CLEAR_ROLL_HISTORY"] = { - text = "Are you sure you want to clear the roll history?", - button1 = "Accept", - button2 = "Decline", - OnAccept = function() - wipe(RollTrackerDB) - UpdateHistory() - end, - timeout = 0, - whileDead = true, - hideOnEscape = true, - preferredIndex = 3, - } - StaticPopup_Show("CLEAR_ROLL_HISTORY") - end -end - -- Function to handle rolling for a reason local function RollReason() StaticPopupDialogs["Roll_With_Reason"] = { @@ -434,6 +414,26 @@ local function UpdateHistory() end end +-- Function to clear history +local function ClearHistory() + if next(RollTrackerDB) ~= nil then + StaticPopupDialogs["CLEAR_ROLL_HISTORY"] = { + text = "Are you sure you want to clear the roll history?", + button1 = "Accept", + button2 = "Decline", + OnAccept = function() + wipe(RollTrackerDB) + UpdateHistory() + end, + timeout = 0, + whileDead = true, + hideOnEscape = true, + preferredIndex = 3, + } + StaticPopup_Show("CLEAR_ROLL_HISTORY") + end +end + -- Function to handle location drop-down menu selection local function OnLocationDropDownSelect(self, arg1, arg2, checked) local selectedLocation = arg1 or "All" -- Use "All" if arg1 is nil From 25410511d749c3c420e19dff933642bef49230c8 Mon Sep 17 00:00:00 2001 From: Pokey Date: Thu, 8 Feb 2024 10:00:00 -0500 Subject: [PATCH 3/3] version bump --- RollTracker.toc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RollTracker.toc b/RollTracker.toc index 1d6b655..db5c9ce 100644 --- a/RollTracker.toc +++ b/RollTracker.toc @@ -2,7 +2,7 @@ ## Title: RollTracker ## Notes: Tracks and displays roll history. ## Author: Pokey -## Version: 1.0.5 +## Version: 1.0.6 ## SavedVariables: RollTrackerDB ## SavedVariables: options RollTracker.lua