Go to Page... |
|
Thread Tools | Display Modes |
|
08-10-23, 11:48 PM | #1 |
Having issues with AceDB, I think...
I have a addon called IncCallout. It is a complete rewrite of Incoming-BG. At curse the addon name is Incoming-BG, i took it over last year.
Here is the issues I have been facing. Just recently I have added the options to change the opacity, the button font color and the button color. Its all good except for the button color. I can change the button color, (sometimes it will not change) but on a reload it reverts back to default red. If I reload a few times it will actually change to the color i had picked. But, after another reload it will go back to red. Before I added all the my addon worked just fine. MiniMap Icon position was saved as well as the GUI position was saved, as well as any messages players picked in options. I'm at my wits end on this and need some new eyes on it to see where I messed up. The code below is not in my Github yet as I want it correct before I update my addon. You guys are alot better than I with LUA. Can someone take a look and tell me what I did wrong, and how to correct it? Code:
-- IncCallout (Rebuild of Incoming-BG) -- Made by Sharpedge_Gaming -- v2.0 - 10.1.5 -- Load embedded libraries local LibStub = LibStub or _G.LibStub local AceDB = LibStub("AceDB-3.0") local AceAddon = LibStub("AceAddon-3.0") local AceConfig = LibStub("AceConfig-3.0") local AceConfigDialog = LibStub("AceConfigDialog-3.0") local icon = LibStub("LibDBIcon-1.0") local LDB = LibStub("LibDataBroker-1.1") local addonName, addonNamespace = ... -- Initialize your addon using AceAddon-3.0 local addon = AceAddon:NewAddon(addonName) local defaults = { profile = { buttonColor = {1, 0, 0, 1}, -- Default to red fontColor = {1, 1, 1, 1}, -- Default to white opacity = 1, -- Default to fully opaque }, } local db = AceDB:New("IncDB", defaults, "Default") local AceDB = LibStub("AceDB-3.0") IncDB = AceDB:New(addonName.."DB", defaults, true) local buttonTexts = {} local buttons = {} local playerFaction playerFaction = UnitFactionGroup("player") local buttonMessageIndices = { sendMore = 1, inc = 1, allClear = 1 } -- Define the battleground locations local battlegroundLocations = { "Stables", "Blacksmith", "Lumber Mill", "Gold Mine", "Mine", "Trollbane Hall", "Defiler's Den", "Farm", "Mage Tower", "Draenei Ruins", "Blood Elf Tower", "Fel Reaver Ruins", "The Broken Temple", "Cauldron of Flames", "Central Bridge", "The Chilled Quagemire", "Eastern Bridge", "Flamewatch Tower", "The Forest of Shadows", "Glacial Falls", "The Steppe of Life", "The Sunken Ring", "Western Bridge", "Winter's Edge Tower", "Wintergrasp Fortress", "Eastpark Workshop", "Westpark Workshop ", "Lighthouse", "Waterworks", "Mines", "Docks", "Workshop", "Horde Keep", "Alliance Keep", "Market", "Hangar", "Refinery", "Quarry", "Wildhammer Stronghold", "Dragonmaw Stronghold", "Silverwing Hold", "Warsong Flag Room", "Baradin Base Camp", "Rustberg Village", "The Restless Front", "Wellson Shipyard", "Largo's Overlook", "Farson Hold", "Forgotten Hill", "Hellscream's Grasp","Stormpike Graveyard", "Irondeep Mine", "Dun Baldar", "Hall of the Stormpike", "Icewing Pass", "Stonehearth Outpost", "Iceblood Graveyard", "Iceblood Garrison", "Tower Point", "Coldtooth Mine", "Dun Baldar Pass", "Icewing Bunker", "Field of Strife", "Stonehearth Graveyard", "Stonehearth Bunker", "Frost Dagger Pass", "Snowfall Graveyard", "Winterax Hold", "Frostwolf Graveyard", "Frostwolf Village", "Deepwind Gorge", "Frostwolf Keep", "Hall of the Frostwolf","Temple of Kotmogu", "Silvershard Mines", "Southshore vs. Tauren Mill", "Alterac Valley", "Ashran", "StormShield", } local buttonMessages = { sendMore = { "We need more peeps", "Need help", "We are outnumbered", "Need a few more", "Need more", "Backup required", "We could use some help", "Calling for backup", "Could use some backup", "Reinforcements needed", "In need of additional support", "Calling all hands on deck", "Require extra manpower", "Assistance urgently needed", "Requesting more participants", -- Add more custom messages if needed... }, inc = { "Incoming", "INC INC INC", "INC", "Gotta INC", "BIG INC", "Incoming enemy forces", "Incoming threat", "Enemy push incoming", "Enemy blitz incoming", "Enemy strike team inbound", "Incoming attack alert", "Enemy wave inbound", "Enemy squad closing in", "Anticipate enemy push", "Enemy forces are closing in", -- Add more custom messages if needed... }, allClear = { "We are all clear", "All clear", "Looks like a ghost town", "All good", "Looking good", "Area secure", "All quiet on the front", "Situation is under control", "All quiet here", "We are looking good", "Perimeter is secured", "Situation is calm", "No threats detected", "All quiet on this end", "Area is threat-free", -- Add more custom messages if needed... }, } -- Create the main frame local IncCallout = CreateFrame("Frame", "IncCalloutMainFrame", UIParent, "BackdropTemplate") IncCallout:SetSize(160, 155) IncCallout:SetPoint("CENTER") -- Create a background texture for the main frame local bgTexture = IncCallout:CreateTexture(nil, "BACKGROUND") bgTexture:SetColorTexture(0, 0, 0) bgTexture:SetAllPoints(IncCallout) -- Create a border frame local BorderFrame = CreateFrame("Frame", nil, IncCallout, "BackdropTemplate") BorderFrame:SetFrameLevel(IncCallout:GetFrameLevel() - 1) -- Ensure it's behind the main frame BorderFrame:SetSize(IncCallout:GetWidth() + 4, IncCallout:GetHeight() + 4) -- Adjust these values for border thickness BorderFrame:SetPoint("CENTER", IncCallout, "CENTER") -- Create a border texture for the border frame local borderTexture = BorderFrame:CreateTexture(nil, "OVERLAY") borderTexture:SetColorTexture(1, 1, 1) borderTexture:SetAllPoints(BorderFrame) IncCallout:SetMovable(true) IncCallout:EnableMouse(true) IncCallout:RegisterForDrag("LeftButton") IncCallout:SetScript("OnDragStart", IncCallout.StartMoving) IncCallout:SetScript("OnDragStop", IncCallout.StopMovingOrSizing) local options = { name = "IncCallout", type = "group", args = { sendMore = { type = "select", name = "Send More message", desc = "Select the message for the 'Send More' button", values = buttonMessages.sendMore, get = function() return buttonMessageIndices.sendMore end, set = function(_, newValue) buttonMessageIndices.sendMore = newValue end, order = 1, }, inc = { type = "select", name = "INC message", desc = "Select the message for the 'INC' button", values = buttonMessages.inc, get = function() return buttonMessageIndices.inc end, set = function(_, newValue) buttonMessageIndices.inc = newValue end, order = 2, }, allClear = { type = "select", name = "All Clear message", desc = "Select the message for the 'All Clear' button", values = buttonMessages.allClear, get = function() return buttonMessageIndices.allClear end, set = function(_, newValue) buttonMessageIndices.allClear = newValue end, order = 3, }, opacity = { type = "range", name = "Opacity", desc = "Adjust the transparency of the IncCallout frame.", min = 0, max = 1, step = 0.05, get = function() return IncDB.opacity or 1 end, set = function(_, newValue) bgTexture:SetAlpha(newValue) borderTexture:SetAlpha(newValue) IncDB.opacity = newValue end, order = 4, }, fontColor = { type = "color", name = "Button Font Color", desc = "Set the color of the button text.", hasAlpha = true, get = function() return unpack(IncDB.fontColor or {1, 1, 1, 1}) -- Default to white end, set = function(_, r, g, b, a) for _, text in ipairs(buttonTexts) do text:SetTextColor(r, g, b, a) end IncDB.fontColor = {r, g, b, a} end, order = 5, }, buttonColor = { type = "color", name = "Button Color", desc = "Set the color of the buttons.", hasAlpha = true, get = function() local color = IncDB.buttonColor or {1, 0, 0, 1} -- Default to red return unpack(color) end, set = function(_, r, g, b, a) for _, button in ipairs(buttons) do button:SetBackdropColor(r, g, b, a) end IncDB.buttonColor = {r, g, b, a} end, order = 6, }, }, } -- Register the options table AceConfig:RegisterOptionsTable(addonName, options) -- Create a config panel local configPanel = AceConfigDialog:AddToBlizOptions(addonName, "IncCallout") configPanel.default = function() -- Reset the options to default values buttonMessageIndices.sendMore = 1 buttonMessageIndices.inc = 1 buttonMessageIndices.allClear = 1 end -- Create a table to map each location to itself local locationTable = {} for _, location in ipairs(battlegroundLocations) do locationTable[location] = location end local function isInBattleground() local inInstance, instanceType = IsInInstance() return inInstance and (instanceType == "pvp" or instanceType == "arena") end local function ButtonOnClick(self) if not isInBattleground() then print("You are not in a battleground.") return end local currentLocation = GetSubZoneText() local playerFaction = UnitFactionGroup("player") or "" local enemyFaction = playerFaction == "Alliance" and "Horde" or "Alliance" local message = self:GetText() .. " " .. enemyFaction .. " incoming at " .. currentLocation SendChatMessage(message, "INSTANCE_CHAT") end -- Register an event listener for when the player enters a new zone or subzone local f = CreateFrame("Frame") f:RegisterEvent("ZONE_CHANGED_NEW_AREA") f:SetScript("OnEvent", function(self, event, ...) if event == "ZONE_CHANGED_NEW_AREA" then local currentLocation = GetRealZoneText() .. " - " .. GetSubZoneText() local location = locationTable[currentLocation] -- Check if location is in the defined battleground locations if location then IncCallout:Show() -- Show the GUI else end end end) local fontSize = 15 -- Function to create a button local function createButton(name, width, height, text, anchor, xOffset, yOffset, onClick) local button = CreateFrame("Button", nil, IncCallout, "UIPanelButtonTemplate, BackdropTemplate") button:SetSize(width, height) button:SetText(text) if type(anchor) == "table" then button:SetPoint(anchor[1], anchor[2], anchor[3], xOffset, yOffset) else button:SetPoint(anchor, xOffset, yOffset) end button:SetScript("OnClick", onClick) button:GetFontString():SetTextColor(1, 1, 1, 1) -- Create a backdrop for the button button:SetBackdrop({ bgFile = "Interface/Tooltips/UI-Tooltip-Background", edgeFile = "Interface/Tooltips/UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 16, insets = { left = 4, right = 4, top = 4, bottom = 4 } }) -- Set the backdrop color button:SetBackdropColor(unpack(IncDB.buttonColor or {1, 0, 0, 1})) -- Set the button color table.insert(buttonTexts, button:GetFontString()) table.insert(buttons, button) -- Add button to the list return button end -- Define a function to apply the button color local function applyButtonColor() local color = IncDB.buttonColor or {1, 0, 0, 1} -- Default to red for _, button in ipairs(buttons) do button:SetBackdropColor(unpack(color)) end end applyButtonColor() -- Create buttons local button1 = createButton("button1", 20, 22, "1", {"TOPLEFT", IncCallout, "TOPLEFT"}, 15, -20, ButtonOnClick) local button2 = createButton("button2", 20, 22, "2", {"LEFT", button1, "RIGHT"}, 3, 0, ButtonOnClick) local button3 = createButton("button3", 20, 22, "3", {"LEFT", button2, "RIGHT"}, 3, 0, ButtonOnClick) local button4 = createButton("button4", 20, 22, "4", {"LEFT", button3, "RIGHT"}, 3, 0, ButtonOnClick) local buttonZerg = createButton("buttonZerg", 40, 22, "Zerg", {"LEFT", button4, "RIGHT"}, 3, 0, ButtonOnClick) local incButton = createButton("incButton", 60, 22, "Inc", {"TOP", IncCallout, "TOP"}, 0, -45, ButtonOnClick) local sendMoreButton = createButton("sendMoreButton", 80, 22, "Send More", {"TOP", incButton, "BOTTOM"}, 0, -5, SendMoreButtonOnClick) local allClearButton = createButton("allClearButton", 60, 22, "All Clear", {"TOP", sendMoreButton, "BOTTOM"}, 0, -5, AllClearButtonOnClick) local exitButton = createButton("exitButton", 60, 22, "Exit", {"TOP", allClearButton, "BOTTOM"}, 0, -5, function() IncCallout:Hide() end) -- Initialize IncDB.minimap if it's not already initialized if not IncDB.minimap then IncDB.minimap = { hide = false, minimapPos = 45, -- Default position angle (in degrees) } end -- Now that IncCallout is defined, you can create IncCalloutLDB local IncCalloutLDB = LibStub("LibDataBroker-1.1"):NewDataObject("IncCallout", { type = "data source", text = "IncCallout", icon = "Interface\\AddOns\\IncCallout\\Icon\\INC.png", OnClick = function(_, button) if button == "LeftButton" then if IncCallout:IsShown() then IncCallout:Hide() else IncCallout:Show() end else InterfaceOptionsFrame_OpenToCategory("IncCallout") InterfaceOptionsFrame_OpenToCategory("IncCallout") -- Call it twice to ensure the correct category is selected end end, OnMouseDown = function(self, button) if button == "LeftButton" then IncCallout:StartMoving() end end, OnMouseUp = function(self, button) if button == "LeftButton" then IncCallout:StopMovingOrSizing() local point, _, _, x, y = IncCallout:GetPoint() local centerX, centerY = Minimap:GetCenter() local scale = Minimap:GetEffectiveScale() x, y = (x - centerX) / scale, (y - centerY) / scale IncDB.minimap.minimapPos = math.deg(math.atan2(y, x)) % 360 end end, OnTooltipShow = function(tooltip) tooltip:AddLine("|cffff0000IncCallout|r") tooltip:AddLine("Left Click: GUI") tooltip:AddLine("Right Click: Options") tooltip:Show() end, }) -- Function to handle the All Clear button click event local function AllClearButtonOnClick() local location = GetSubZoneText() -- Check if location is in the defined battleground locations if not location then print("You are not in a BattleGround.") return end local message = buttonMessages.allClear[buttonMessageIndices.allClear] .. " at " .. location SendChatMessage(message, "INSTANCE_CHAT") end allClearButton:SetScript("OnClick", AllClearButtonOnClick) -- Function to handle the Send More button click event local function SendMoreButtonOnClick() local location = GetSubZoneText() -- Check if location is in the defined battleground locations if not location then print("You are not in a BattleGround.") return end local message = buttonMessages.sendMore[buttonMessageIndices.sendMore] .. " at " .. location SendChatMessage(message, "INSTANCE_CHAT") end sendMoreButton:SetScript("OnClick", SendMoreButtonOnClick) -- Function to handle the INC button click event local function IncButtonOnClick() local location = GetSubZoneText() -- Check if location is in the defined battleground locations if not location then print("You are not in a BattleGround.") return end local message = buttonMessages.inc[buttonMessageIndices.inc] .. " at " .. location SendChatMessage(message, "INSTANCE_CHAT") end incButton:SetScript("OnClick", IncButtonOnClick) -- Register the slash command SLASH_INC1 = "/inc" SlashCmdList["INC"] = function() if IncCallout:IsShown() then IncCallout:Hide() end end -- Function to handle player login, logout, and entering the world local function OnEvent(self, event, ...) if event == "PLAYER_ENTERING_WORLD" then local inInstance, instanceType = IsInInstance() if inInstance and (instanceType == "pvp" or instanceType == "arena") then print("Don't forget to call INC's") else print("|cFFFF0000You need to queue up for PvP|r") end if inInstance and instanceType == "pvp" then IncCalloutMainFrame:Show() end elseif event == "PLAYER_LOGIN" then -- Load saved button messages indices buttonMessageIndices.sendMore = IncDB.sendMoreIndex or 1 buttonMessageIndices.inc = IncDB.incIndex or 1 buttonMessageIndices.allClear = IncDB.allClearIndex or 1 -- Load the opacity setting bgTexture:SetAlpha(IncDB.opacity or 1) borderTexture:SetAlpha(IncDB.opacity or 1) -- Load the font color local savedColor = IncDB.fontColor or {1, 1, 1, 1} -- Default to white for _, text in ipairs(buttonTexts) do text:SetTextColor(unpack(savedColor)) local color = IncDB.buttonColor or {1, 0, 0, 1} -- Default to red end -- Load the font local defaultSize = 15 -- Default font size local font = IncDB.font or "Fonts\\ARIALN.ttf" -- Default to Arial for _, text in ipairs(buttonTexts) do local _, size = text:GetFont() size = size or defaultSize text:SetFont(font, size) -- Preserve the font size end -- Load the minimap icon settings icon:Register("IncCallout", IncCalloutLDB, IncDB.minimap) -- Apply the button color applyButtonColor() -- Call the function here elseif event == "PLAYER_LOGOUT" then -- Save button messages indices IncDB.sendMoreIndex = buttonMessageIndices.sendMore IncDB.incIndex = buttonMessageIndices.inc IncDB.allClearIndex = buttonMessageIndices.allClear -- Save the opacity setting IncDB.opacity = bgTexture:GetAlpha() -- Ensure all texts have the same color local firstTextColor = {buttonTexts[1]:GetTextColor()} for _, text in ipairs(buttonTexts) do text:SetTextColor(unpack(firstTextColor)) end -- Save the font IncDB.font = buttonTexts[1]:GetFont() -- Save the button color IncDB.buttonColor = {buttons[1]:GetBackdropColor()} end end IncCallout:SetScript("OnEvent", OnEvent) -- Register the events IncCallout:RegisterEvent("PLAYER_ENTERING_WORLD") IncCallout:RegisterEvent("PLAYER_LOGIN") IncCallout:RegisterEvent("PLAYER_LOGOUT") IncCallout:SetScript("OnEvent", OnEvent) I also works nights. So I will answer any questions once I get back to work tonight. Last edited by Sharpedge : 08-11-23 at 04:08 AM. |
|
08-11-23, 12:06 PM | #2 |
Your Ace Setter uses r, g, b (and SetBackdropColor(r, g, b, a)) but your button creation uses unpack(). Your create setup should be something like.
Lua Code:
unpack unpacks tables in numeric order Lua Code:
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 08-11-23 at 12:31 PM. |
|
08-11-23, 04:19 PM | #3 | |
|
||
08-12-23, 07:08 PM | #4 |
I applied the colors as you suggested:
Code:
buttonColor = { type = "color", name = "Button Color", desc = "Set the color of the buttons.", hasAlpha = true, get = function() local color = IncDB.buttonColor or {r = 1, g = 0, b = 0, a = 1} -- Default to red return color.r, color.g, color.b, color.a end, set = function(_, r, g, b, a) IncDB.buttonColor = {r = r, g = g, b = b, a = a} for _, button in ipairs(buttons) do button:SetBackdropColor(r, g, b, a) end end, order = 6, Code:
-- IncCallout (Rebuild of Incoming-BG) -- Made by Sharpedge_Gaming -- v2.0 - 10.1.5 -- Load embedded libraries local LibStub = LibStub or _G.LibStub local AceDB = LibStub("AceDB-3.0") local AceAddon = LibStub("AceAddon-3.0") local AceConfig = LibStub("AceConfig-3.0") local AceConfigDialog = LibStub("AceConfigDialog-3.0") local icon = LibStub("LibDBIcon-1.0") local LDB = LibStub("LibDataBroker-1.1") local addonName, addonNamespace = ... -- Initialize your addon using AceAddon-3.0 local addon = AceAddon:NewAddon(addonName) local defaults = { profile = { buttonColor = {r = 1, g = 0, b = 0, a = 1}, -- Default to red fontColor = {1, 1, 1, 1}, -- Default to white opacity = 1, -- Default to fully opaque }, } IncDB = AceDB:New(addonName.."DB", defaults, true) local buttonTexts = {} local buttons = {} local playerFaction playerFaction = UnitFactionGroup("player") local buttonMessageIndices = { sendMore = 1, inc = 1, allClear = 1 } -- Define the battleground locations local battlegroundLocations = { "Stables", "Blacksmith", "Lumber Mill", "Gold Mine", "Mine", "Trollbane Hall", "Defiler's Den", "Farm", "Mage Tower", "Draenei Ruins", "Blood Elf Tower", "Fel Reaver Ruins", "The Broken Temple", "Cauldron of Flames", "Central Bridge", "The Chilled Quagemire", "Eastern Bridge", "Flamewatch Tower", "The Forest of Shadows", "Glacial Falls", "The Steppe of Life", "The Sunken Ring", "Western Bridge", "Winter's Edge Tower", "Wintergrasp Fortress", "Eastpark Workshop", "Westpark Workshop ", "Lighthouse", "Waterworks", "Mines", "Docks", "Workshop", "Horde Keep", "Alliance Keep", "Market", "Hangar", "Refinery", "Quarry", "Wildhammer Stronghold", "Dragonmaw Stronghold", "Silverwing Hold", "Warsong Flag Room", "Baradin Base Camp", "Rustberg Village", "The Restless Front", "Wellson Shipyard", "Largo's Overlook", "Farson Hold", "Forgotten Hill", "Hellscream's Grasp","Stormpike Graveyard", "Irondeep Mine", "Dun Baldar", "Hall of the Stormpike", "Icewing Pass", "Stonehearth Outpost", "Iceblood Graveyard", "Iceblood Garrison", "Tower Point", "Coldtooth Mine", "Dun Baldar Pass", "Icewing Bunker", "Field of Strife", "Stonehearth Graveyard", "Stonehearth Bunker", "Frost Dagger Pass", "Snowfall Graveyard", "Winterax Hold", "Frostwolf Graveyard", "Frostwolf Village", "Deepwind Gorge", "Frostwolf Keep", "Hall of the Frostwolf","Temple of Kotmogu", "Silvershard Mines", "Southshore vs. Tauren Mill", "Alterac Valley", "Ashran", "StormShield", } local buttonMessages = { sendMore = { "We need more peeps", "Need help", "We are outnumbered", "Need a few more", "Need more", "Backup required", "We could use some help", "Calling for backup", "Could use some backup", "Reinforcements needed", "In need of additional support", "Calling all hands on deck", "Require extra manpower", "Assistance urgently needed", "Requesting more participants", -- Add more custom messages if needed... }, inc = { "Incoming", "INC INC INC", "INC", "Gotta INC", "BIG INC", "Incoming enemy forces", "Incoming threat", "Enemy push incoming", "Enemy blitz incoming", "Enemy strike team inbound", "Incoming attack alert", "Enemy wave inbound", "Enemy squad closing in", "Anticipate enemy push", "Enemy forces are closing in", -- Add more custom messages if needed... }, allClear = { "We are all clear", "All clear", "Looks like a ghost town", "All good", "Looking good", "Area secure", "All quiet on the front", "Situation is under control", "All quiet here", "We are looking good", "Perimeter is secured", "Situation is calm", "No threats detected", "All quiet on this end", "Area is threat-free", -- Add more custom messages if needed... }, } -- Create the main frame local IncCallout = CreateFrame("Frame", "IncCalloutMainFrame", UIParent, "BackdropTemplate") IncCallout:SetSize(160, 155) IncCallout:SetPoint("CENTER") -- Create a background texture for the main frame local bgTexture = IncCallout:CreateTexture(nil, "BACKGROUND") bgTexture:SetColorTexture(0, 0, 0) bgTexture:SetAllPoints(IncCallout) -- Create a border frame local BorderFrame = CreateFrame("Frame", nil, IncCallout, "BackdropTemplate") BorderFrame:SetFrameLevel(IncCallout:GetFrameLevel() - 1) -- Ensure it's behind the main frame BorderFrame:SetSize(IncCallout:GetWidth() + 4, IncCallout:GetHeight() + 4) -- Adjust these values for border thickness BorderFrame:SetPoint("CENTER", IncCallout, "CENTER") -- Create a border texture for the border frame local borderTexture = BorderFrame:CreateTexture(nil, "OVERLAY") borderTexture:SetColorTexture(1, 1, 1) borderTexture:SetAllPoints(BorderFrame) IncCallout:SetMovable(true) IncCallout:EnableMouse(true) IncCallout:RegisterForDrag("LeftButton") IncCallout:SetScript("OnDragStart", IncCallout.StartMoving) IncCallout:SetScript("OnDragStop", IncCallout.StopMovingOrSizing) local fontSize = 15 -- Function to create a button local function createButton(name, width, height, text, anchor, xOffset, yOffset, onClick) local button = CreateFrame("Button", nil, IncCallout, "UIPanelButtonTemplate, BackdropTemplate") button:SetSize(width, height) button:SetText(text) if type(anchor) == "table" then button:SetPoint(anchor[1], anchor[2], anchor[3], xOffset, yOffset) else button:SetPoint(anchor, xOffset, yOffset) end button:SetScript("OnClick", onClick) button:GetFontString():SetTextColor(1, 1, 1, 1) button:SetBackdrop({ bgFile = "Interface/Tooltips/UI-Tooltip-Background", edgeFile = "Interface/Tooltips/UI-Tooltip-Border", tile = true, tileSize = 16, edgeSize = 16, insets = { left = 4, right = 4, top = 4, bottom = 4 } }) table.insert(buttonTexts, button:GetFontString()) table.insert(buttons, button) return button end local function applyButtonColor() local r, g, b, a if IncDB.buttonColor then r, g, b, a = IncDB.buttonColor.r, IncDB.buttonColor.g, IncDB.buttonColor.b, IncDB.buttonColor.a else r, g, b, a = 1, 0, 0, 1 -- Default to red end for _, button in ipairs(buttons) do button:SetBackdropColor(r, g, b, a) end end local button1 = createButton("button1", 20, 22, "1", {"TOPLEFT", IncCallout, "TOPLEFT"}, 15, -20, ButtonOnClick) local button2 = createButton("button2", 20, 22, "2", {"LEFT", button1, "RIGHT"}, 3, 0, ButtonOnClick) local button3 = createButton("button3", 20, 22, "3", {"LEFT", button2, "RIGHT"}, 3, 0, ButtonOnClick) local button4 = createButton("button4", 20, 22, "4", {"LEFT", button3, "RIGHT"}, 3, 0, ButtonOnClick) local buttonZerg = createButton("buttonZerg", 40, 22, "Zerg", {"LEFT", button4, "RIGHT"}, 3, 0, ButtonOnClick) local incButton = createButton("incButton", 60, 22, "Inc", {"TOP", IncCallout, "TOP"}, 0, -45, ButtonOnClick) local sendMoreButton = createButton("sendMoreButton", 80, 22, "Send More", {"TOP", incButton, "BOTTOM"}, 0, -5, SendMoreButtonOnClick) local allClearButton = createButton("allClearButton", 60, 22, "All Clear", {"TOP", sendMoreButton, "BOTTOM"}, 0, -5, AllClearButtonOnClick) local exitButton = createButton("exitButton", 60, 22, "Exit", {"TOP", allClearButton, "BOTTOM"}, 0, -5, function() IncCallout:Hide() end) -- Apply the color to all the buttons applyButtonColor() -- Initialize IncDB.minimap if it's not already initialized if not IncDB.minimap then IncDB.minimap = { hide = false, minimapPos = 45, -- Default position angle (in degrees) } end local options = { name = "IncCallout", type = "group", args = { sendMore = { type = "select", name = "Send More message", desc = "Select the message for the 'Send More' button", values = buttonMessages.sendMore, get = function() return buttonMessageIndices.sendMore end, set = function(_, newValue) buttonMessageIndices.sendMore = newValue end, order = 1, }, inc = { type = "select", name = "INC message", desc = "Select the message for the 'INC' button", values = buttonMessages.inc, get = function() return buttonMessageIndices.inc end, set = function(_, newValue) buttonMessageIndices.inc = newValue end, order = 2, }, allClear = { type = "select", name = "All Clear message", desc = "Select the message for the 'All Clear' button", values = buttonMessages.allClear, get = function() return buttonMessageIndices.allClear end, set = function(_, newValue) buttonMessageIndices.allClear = newValue end, order = 3, }, opacity = { type = "range", name = "Opacity", desc = "Adjust the transparency of the IncCallout frame.", min = 0, max = 1, step = 0.05, get = function() return IncDB.opacity or 1 end, set = function(_, newValue) bgTexture:SetAlpha(newValue) borderTexture:SetAlpha(newValue) IncDB.opacity = newValue end, order = 4, }, fontColor = { type = "color", name = "Button Font Color", desc = "Set the color of the button text.", hasAlpha = true, get = function() local color = IncDB.fontColor or {r = 1, g = 1, b = 1, a = 1} -- Default to white return color.r, color.g, color.b, color.a end, set = function(_, r, g, b, a) IncDB.fontColor = {r = r, g = g, b = b, a = a} for _, text in ipairs(buttonTexts) do text:SetTextColor(r, g, b, a) end end, order = 5, }, buttonColor = { type = "color", name = "Button Color", desc = "Set the color of the buttons.", hasAlpha = true, get = function() local color = IncDB.buttonColor or {r = 1, g = 0, b = 0, a = 1} -- Default to red return color.r, color.g, color.b, color.a end, set = function(_, r, g, b, a) IncDB.buttonColor = {r = r, g = g, b = b, a = a} for _, button in ipairs(buttons) do button:SetBackdropColor(r, g, b, a) end end, order = 6, }, }, } -- Register the options table AceConfig:RegisterOptionsTable(addonName, options) -- Create a config panel local configPanel = AceConfigDialog:AddToBlizOptions(addonName, "IncCallout") configPanel.default = function() -- Reset the options to default values buttonMessageIndices.sendMore = 1 buttonMessageIndices.inc = 1 buttonMessageIndices.allClear = 1 end -- Create a table to map each location to itself local locationTable = {} for _, location in ipairs(battlegroundLocations) do locationTable[location] = location end local function isInBattleground() local inInstance, instanceType = IsInInstance() return inInstance and (instanceType == "pvp" or instanceType == "arena") end local function ButtonOnClick(self) if not isInBattleground() then print("You are not in a battleground.") return end local currentLocation = GetSubZoneText() local playerFaction = UnitFactionGroup("player") or "" local enemyFaction = playerFaction == "Alliance" and "Horde" or "Alliance" local message = self:GetText() .. " " .. enemyFaction .. " incoming at " .. currentLocation SendChatMessage(message, "INSTANCE_CHAT") end -- Register an event listener for when the player enters a new zone or subzone local f = CreateFrame("Frame") f:RegisterEvent("ZONE_CHANGED_NEW_AREA") f:SetScript("OnEvent", function(self, event, ...) if event == "ZONE_CHANGED_NEW_AREA" then local currentLocation = GetRealZoneText() .. " - " .. GetSubZoneText() local location = locationTable[currentLocation] -- Check if location is in the defined battleground locations if location then IncCallout:Show() -- Show the GUI else end end end) -- Now that IncCallout is defined, you can create IncCalloutLDB local IncCalloutLDB = LibStub("LibDataBroker-1.1"):NewDataObject("IncCallout", { type = "data source", text = "IncCallout", icon = "Interface\\AddOns\\IncCallout\\Icon\\INC.png", OnClick = function(_, button) if button == "LeftButton" then if IncCallout:IsShown() then IncCallout:Hide() else IncCallout:Show() end else InterfaceOptionsFrame_OpenToCategory("IncCallout") InterfaceOptionsFrame_OpenToCategory("IncCallout") -- Call it twice to ensure the correct category is selected end end, OnMouseDown = function(self, button) if button == "LeftButton" then IncCallout:StartMoving() end end, OnMouseUp = function(self, button) if button == "LeftButton" then IncCallout:StopMovingOrSizing() local point, _, _, x, y = IncCallout:GetPoint() local centerX, centerY = Minimap:GetCenter() local scale = Minimap:GetEffectiveScale() x, y = (x - centerX) / scale, (y - centerY) / scale IncDB.minimap.minimapPos = math.deg(math.atan2(y, x)) % 360 end end, OnTooltipShow = function(tooltip) tooltip:AddLine("|cffff0000IncCallout|r") tooltip:AddLine("Left Click: GUI") tooltip:AddLine("Right Click: Options") tooltip:Show() end, }) -- Function to handle the All Clear button click event local function AllClearButtonOnClick() local location = GetSubZoneText() -- Check if location is in the defined battleground locations if not location then print("You are not in a BattleGround.") return end local message = buttonMessages.allClear[buttonMessageIndices.allClear] .. " at " .. location SendChatMessage(message, "INSTANCE_CHAT") end allClearButton:SetScript("OnClick", AllClearButtonOnClick) -- Function to handle the Send More button click event local function SendMoreButtonOnClick() local location = GetSubZoneText() -- Check if location is in the defined battleground locations if not location then print("You are not in a BattleGround.") return end local message = buttonMessages.sendMore[buttonMessageIndices.sendMore] .. " at " .. location SendChatMessage(message, "INSTANCE_CHAT") end sendMoreButton:SetScript("OnClick", SendMoreButtonOnClick) -- Function to handle the INC button click event local function IncButtonOnClick() local location = GetSubZoneText() -- Check if location is in the defined battleground locations if not location then print("You are not in a BattleGround.") return end local message = buttonMessages.inc[buttonMessageIndices.inc] .. " at " .. location SendChatMessage(message, "INSTANCE_CHAT") end incButton:SetScript("OnClick", IncButtonOnClick) -- Register the slash command SLASH_INC1 = "/inc" SlashCmdList["INC"] = function() if IncCallout:IsShown() then IncCallout:Hide() end end local function OnEvent(self, event, ...) if event == "PLAYER_ENTERING_WORLD" then local inInstance, instanceType = IsInInstance() if inInstance and (instanceType == "pvp" or instanceType == "arena") then else print("|cFFFF0000You need to queue up for PvP|r") end if inInstance and instanceType == "pvp" then IncCalloutMainFrame:Show() end elseif event == "PLAYER_LOGIN" then -- Load saved button messages indices buttonMessageIndices.sendMore = IncDB.sendMoreIndex or 1 buttonMessageIndices.inc = IncDB.incIndex or 1 buttonMessageIndices.allClear = IncDB.allClearIndex or 1 -- Load the opacity setting bgTexture:SetAlpha(IncDB.opacity or 1) borderTexture:SetAlpha(IncDB.opacity or 1) -- Load the button color local color = IncDB.buttonColor or {r = 1, g = 0, b = 0, a = 1} -- Default to red local r, g, b, a = color.r, color.g, color.b, color.a for _, button in ipairs(buttons) do button:SetBackdropColor(r, g, b, a) end -- Load the font color local savedColor = IncDB.fontColor or {r = 1, g = 1, b = 1, a = 1} -- Default to white local r, g, b, a = savedColor.r, savedColor.g, savedColor.b, savedColor.a for _, text in ipairs(buttonTexts) do text:SetTextColor(r, g, b, a) end -- Load the font local defaultSize = 15 -- Default font size local font = IncDB.font or "Fonts\\ARIALN.ttf" -- Default to Arial for _, text in ipairs(buttonTexts) do local _, size = text:GetFont() size = size or defaultSize text:SetFont(font, size) -- Preserve the font size end -- Load the minimap icon settings icon:Register("IncCallout", IncCalloutLDB, IncDB.minimap) elseif event == "PLAYER_LOGOUT" then -- Save button messages indices IncDB.sendMoreIndex = buttonMessageIndices.sendMore IncDB.incIndex = buttonMessageIndices.inc IncDB.allClearIndex = buttonMessageIndices.allClear -- Save the opacity setting IncDB.opacity = bgTexture:GetAlpha() -- Save the font color local savedColor = IncDB.fontColor or {r = 1, g = 1, b = 1, a = 1} -- Default to white local r, g, b, a = savedColor.r, savedColor.g, savedColor.b, savedColor.a for _, text in ipairs(buttonTexts) do text:SetTextColor(r, g, b, a) end -- Save the font IncDB.font = buttonTexts[1]:GetFont() -- Save the button color local r, g, b, a = buttons[1]:GetBackdropColor() IncDB.buttonColor = {r = r, g = g, b = b, a = a} end end IncCallout:SetScript("OnEvent", OnEvent) -- Register the events IncCallout:RegisterEvent("PLAYER_ENTERING_WORLD") IncCallout:RegisterEvent("PLAYER_LOGIN") IncCallout:RegisterEvent("PLAYER_LOGOUT") IncCallout:SetScript("OnEvent", OnEvent)] |
|
08-13-23, 09:23 AM | #5 |
I don't use Ace but I did take a quick look at the addon from Curse and the first thing I noticed is that the .toc file had two entries starting with ## SavedVariables:
Code:
## SavedVariables: IncCalloutDB ## SavedVariables: IncDB Code:
IncDB = AceDB:New(addonName.."DB", defaults, true) There should only be one ## SavedVariables: line in the .toc Code:
## SavedVariables: IncCalloutDB IncDB can be a local variable (or an entry in your namespace table if the addon has multiple .lua files) as it's an instance of the AceDB code so it can't be saved. Anything in your SavedVariable table (IncCalloutDB (addonNamespace.."DB")) will be automatically saved by the game (not Ace) when you character logs out (/reload etc.). So you don't need to do anything at the PLAYER_LOGOUT event unless you have data you want to save that's not already in the table (not sure why you would but...). You also seem to be doing a bunch of things that require IncDB (the IncCalloutDB table) when your .lua file is loaded (before any events have fired) which means the game hasn't loaded your SavedVariables file (meaning the IncCalloutDB table) yet therefore, each time you login, you are probably working with a brand new (empty) SV table. Anything requiring information from the IncCalloutDB table should not be created/assigned/setup until after that table has been loaded (PLAYER_LOGIN is an event only fired once where you know the table has already been loaded so is a safe place to do this kind of thing) You should also check AceDB is being correctly used by checking you addonname.lua file in the SavedVariable folder. It should have a ["propfileKeys"] entry that contains character name to used profile entry and a ["profiles"] entry that contains the actual profiles and data (initally just the "Default" profile). If you are going to make changes to how AceDB works while testing (eg. changing/adding/removing default data) you need to either do that after the table has loaded or, (after exiting the game) delete the SV file so a new one with the new defaults etc. can be created otherwise the old version is loaded each time. If you users already use SavedVariables, your code should "work around" having to delete the file.) Again, I don't Ace so finding a small simple addon that does as an example would probably help you figure out the how, when and where of getting it all working would probably be useful.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 08-13-23 at 10:32 AM. |
|
08-13-23, 06:28 PM | #6 |
Thank you for the detailed response. I will follow your suggestions and see what happens. I am still in the learning stage of all of this.
That you again for such a detailed response. |
|
08-13-23, 10:30 PM | #7 |
I had a bit of a play with the code and moved some things around. This is what I came up with (very rough and probably not error free. I was doing button colours and ignored everything else)
I marked (I think all) my changes with a Fizzlemizz comment so you can see what I moved to PLAYER_LOGIN. (I said before I don't Ace so it's not an experts guide) but primarily I added the db variable to hold what was IncDB in your posted version (the AceDB instance) and I change IncDB to hold Code:
db.profile You will probably need to delete your SavedVariales .lua/.bak file before logging in. The button colours will be wierd because they are based on the UIPanelButtonTemplate and the textures used for the buttons are hard coloured red (mixing a new colour into red doesn't make it the new colour) but the button borders (white bits) should change) Your code doesn't have any mechanism for creating/changing profiles so as-is, any changes made by a character will change the "Default" profile which is the only one available and used by all characters. You could remove the true from Code:
db = LibStub("AceDB-3.0"):New(addonName.."DB", defaults, true) .toc file Lua Code:
.lua file Lua Code:
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 08-13-23 at 11:09 PM. |
|
08-14-23, 05:34 AM | #8 |
Awesome man....I had to make a few minor changes though. I wasn't liking the SetVertexColor. It made the buttons look funny. So I went with:
Code:
button:SetBackdropColor(r, g, b, a) button.Left:SetColorTexture(r, g, b, a) button.Right:SetColorTexture(r, g, b, a) button.Middle:SetColorTexture(r, g, b, a) Code:
-- Register the options table AceConfig:RegisterOptionsTable(addonName, options) -- Create a config panel local configPanel = AceConfigDialog:AddToBlizOptions(addonName, "IncCallout") configPanel.default = function() -- Reset the options to default values buttonMessageIndices.sendMore = 1 buttonMessageIndices.inc = 1 buttonMessageIndices.allClear = 1 end Code:
-- This function will be triggered every time IncCallout is shown IncCallout:SetScript("OnShow", function() applyButtonColor() -- You can also apply other settings here, if needed. end) Code:
-- Create the buttons local button1 = createButton("button1", 20, 22, "1", {"TOPLEFT", IncCallout, "TOPLEFT"}, 15, -20, ButtonOnClick) local button2 = createButton("button2", 20, 22, "2", {"LEFT", button1, "RIGHT"}, 3, 0, ButtonOnClick) local button3 = createButton("button3", 20, 22, "3", {"LEFT", button2, "RIGHT"}, 3, 0, ButtonOnClick) local button4 = createButton("button4", 20, 22, "4", {"LEFT", button3, "RIGHT"}, 3, 0, ButtonOnClick) local buttonZerg = createButton("buttonZerg", 40, 22, "Zerg", {"LEFT", button4, "RIGHT"}, 3, 0, ButtonOnClick) local incButton = createButton("incButton", 60, 22, "Inc", {"TOP", IncCallout, "TOP"}, 0, -45, ButtonOnClick) local sendMoreButton = createButton("sendMoreButton", 80, 22, "Send More", {"TOP", incButton, "BOTTOM"}, 0, -5, SendMoreButtonOnClick) local allClearButton = createButton("allClearButton", 60, 22, "All Clear", {"TOP", sendMoreButton, "BOTTOM"}, 0, -5, AllClearButtonOnClick) local exitButton = createButton("exitButton", 60, 22, "Exit", {"TOP", allClearButton, "BOTTOM"}, 0, -5, function() IncCallout:Hide() end) -- Apply the PostClick script to each button for _, button in ipairs(buttons) do button:SetScript("PostClick", function() applyButtonColor() end) end Thank you again, Fizzlemizz |
|
WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Having issues with AceDB, I think... |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Hybrid Mode |
Switch to Threaded Mode |
|
|