Thread Tools Display Modes
08-10-23, 11:48 PM   #1
Sharpedge
A Wyrmkin Dreamwalker
 
Sharpedge's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2022
Posts: 54
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)
My addon at curse: Incoming-BG

I also works nights. So I will answer any questions once I get back to work tonight.
Attached Thumbnails
Click image for larger version

Name:	pic5.png
Views:	67
Size:	167.2 KB
ID:	9834  

Last edited by Sharpedge : 08-11-23 at 04:08 AM.
  Reply With Quote
08-11-23, 12:06 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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:
  1. local r, g, b, a
  2. if IncDB.buttonColor then
  3.      r, g, b, a = IncDB.buttonColor.r, IncDB.buttonColor.g, IncDB.buttonColor.b, IncDB.buttonColor.a
  4. else -- Not sure why this is because AceDb should be configred for defaults before you get here but I didn't read that far.
  5.      r, g, b, a = 1, 0, 0, 1
  6. end
  7. button:SetBackdropColor(r, g, b, a)

unpack unpacks tables in numeric order

Lua Code:
  1. local tbl={ [1]="aaa", [2]="bbb", [3]="ccc", }
  2. local a, b, c = unpack(tbl)
That and the order that tables with string keys are "packed" cannot be determined.
__________________
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.
  Reply With Quote
08-11-23, 04:19 PM   #3
Sharpedge
A Wyrmkin Dreamwalker
 
Sharpedge's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2022
Posts: 54
Originally Posted by Fizzlemizz View Post
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:
  1. local r, g, b, a
  2. if IncDB.buttonColor then
  3.      r, g, b, a = IncDB.buttonColor.r, IncDB.buttonColor.g, IncDB.buttonColor.b, IncDB.buttonColor.a
  4. else -- Not sure why this is because AceDb should be configred for defaults before you get here but I didn't read that far.
  5.      r, g, b, a = 1, 0, 0, 1
  6. end
  7. button:SetBackdropColor(r, g, b, a)

unpack unpacks tables in numeric order

Lua Code:
  1. local tbl={ [1]="aaa", [2]="bbb", [3]="ccc", }
  2. local a, b, c = unpack(tbl)
That and the order that tables with string keys are "packed" cannot be determined.
Thank you for pointing that out. I'll redo that part and see how it goes.
  Reply With Quote
08-12-23, 07:08 PM   #4
Sharpedge
A Wyrmkin Dreamwalker
 
Sharpedge's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2022
Posts: 54
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,
But the issue that I am having is it seems the button color not saving after a /reload or logout/login. Sometimes it will save the color I had picked, other times it will not. Now the button font color will change instantly and will stay the color I picked through a /reload or a logout/login. The button color will not change instantly when you pick another color. I'm pretty much lost at this point. Here is my full code if someone has the time to see where I messed up.

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)]
  Reply With Quote
08-13-23, 09:23 AM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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
and in the code above you use:
Code:
IncDB = AceDB:New(addonName.."DB", defaults, true)
I'm not sure if it's the case with what you are testing now, but if so, it indicates a mis-understanding of how Saved Variables work.

There should only be one ## SavedVariables: line in the .toc
Code:
## SavedVariables: IncCalloutDB
(if you want multiple Saved Vars, you seperate the names with commas but in your case, you only need the one.).



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.
  Reply With Quote
08-13-23, 06:28 PM   #6
Sharpedge
A Wyrmkin Dreamwalker
 
Sharpedge's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2022
Posts: 54
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.
  Reply With Quote
08-13-23, 10:30 PM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,879
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
the actual characters profile from the ["profiles"] key in saved variables file

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)
and each character will get their own seperate profile by default so you don't need to add anything extra but you lose the ability to "share" a saved profile with multiple characters if that might be what you are ultimately intending.

.toc file
Lua Code:
  1. ## Interface: 100105
  2. ## Title: IncCallout
  3. ## Author: Sharpedge_Gaming
  4. ## Version: v.2.0
  5. ## Notes: GUI for calling out Inc's
  6. ## X-Category: Battlegrounds/PvP, Chat/Communication
  7. ## IconTexture: 975742
  8. ## SavedVariables: IncCalloutDB
  9.  
  10.  
  11. embeds.xml
  12. IncCallout.lua

.lua file
Lua Code:
  1. -- IncCallout (Rebuild of Incoming-BG)
  2. -- Made by Sharpedge_Gaming
  3. -- v2.0 - 10.1.5
  4.  
  5. -- Load embedded libraries
  6. local LibStub = LibStub or _G.LibStub
  7. --local AceDB = LibStub("AceDB-3.0")
  8. local AceDB = LibStub:GetLibrary("AceDB-3.0")
  9. --local AceAddon = LibStub("AceAddon-3.0")
  10. local AceAddon = LibStub:GetLibrary("AceAddon-3.0")
  11. --local AceConfig = LibStub("AceConfig-3.0")
  12. local AceConfig = LibStub:GetLibrary("AceConfig-3.0")
  13. --local AceConfigDialog = LibStub("AceConfigDialog-3.0")
  14. local AceConfigDialog = LibStub:GetLibrary("AceConfigDialog-3.0")
  15. --local icon = LibStub("LibDBIcon-1.0")
  16. local icon = LibStub:GetLibrary("LibDBIcon-1.0")
  17. --local LDB = LibStub("LibDataBroker-1.1")
  18. local LDB = LibStub:GetLibrary("LibDataBroker-1.1")
  19.  
  20. local addonName, addonNamespace = ...
  21.  
  22. local IncDB, db -- Fizzlemizz added db
  23. -- Initialize your addon using AceAddon-3.0
  24. local addon = AceAddon:NewAddon(addonName)
  25.  
  26. local defaults = {
  27.     profile = {
  28.         buttonColor = {r = 1, g = 0, b = 0, a = 1}, -- Default to red
  29.         fontColor = {r=1, g=1, b=1, a=1},  -- Default to white -- Fizzlemizz added r=, g=, b=, a= to avoid the error (not using unpack() anymore)
  30.         opacity = 1,  -- Default to fully opaque
  31.     },
  32. }
  33.  
  34.  
  35. local buttonTexts = {}
  36. local buttons = {}
  37.  
  38. local playerFaction
  39.  
  40. local buttonMessageIndices = {
  41.     sendMore = 1,
  42.     inc = 1,
  43.     allClear = 1
  44. }
  45.  
  46. -- Define the battleground locations
  47. local battlegroundLocations = {
  48.     "Stables", "Blacksmith", "Lumber Mill", "Gold Mine", "Mine", "Trollbane Hall", "Defiler's Den", "Farm",
  49.     "Mage Tower", "Draenei Ruins", "Blood Elf Tower", "Fel Reaver Ruins",
  50.     "The Broken Temple", "Cauldron of Flames", "Central Bridge", "The Chilled Quagemire",
  51.     "Eastern Bridge", "Flamewatch Tower", "The Forest of Shadows", "Glacial Falls", "The Steppe of Life",
  52.     "The Sunken Ring", "Western Bridge", "Winter's Edge Tower", "Wintergrasp Fortress", "Eastpark Workshop", "Westpark Workshop ",
  53.     "Lighthouse", "Waterworks", "Mines", "Docks", "Workshop", "Horde Keep", "Alliance Keep", "Market",
  54.     "Hangar", "Refinery", "Quarry", "Wildhammer Stronghold", "Dragonmaw Stronghold",
  55.     "Silverwing Hold", "Warsong Flag Room", "Baradin Base Camp", "Rustberg Village",
  56.     "The Restless Front", "Wellson Shipyard", "Largo's Overlook", "Farson Hold",
  57.     "Forgotten Hill", "Hellscream's Grasp","Stormpike Graveyard", "Irondeep Mine", "Dun Baldar",
  58.     "Hall of the Stormpike", "Icewing Pass", "Stonehearth Outpost", "Iceblood Graveyard",
  59.     "Iceblood Garrison", "Tower Point", "Coldtooth Mine", "Dun Baldar Pass", "Icewing Bunker",
  60.     "Field of Strife", "Stonehearth Graveyard", "Stonehearth Bunker", "Frost Dagger Pass",
  61.     "Snowfall Graveyard", "Winterax Hold", "Frostwolf Graveyard", "Frostwolf Village",
  62.     "Deepwind Gorge", "Frostwolf Keep", "Hall of the Frostwolf","Temple of Kotmogu",  "Silvershard Mines", "Southshore vs. Tauren Mill", "Alterac Valley",
  63.     "Ashran", "StormShield",   
  64. }
  65.  
  66. local buttonMessages = {
  67.     sendMore = {
  68.         "We need more peeps",
  69.         "Need help",
  70.         "We are outnumbered",
  71.         "Need a few more",
  72.         "Need more",
  73.         "Backup required",
  74.         "We could use some help",
  75.         "Calling for backup",
  76.         "Could use some backup",
  77.         "Reinforcements needed",
  78.         "In need of additional support",
  79.         "Calling all hands on deck",
  80.         "Require extra manpower",
  81.         "Assistance urgently needed",
  82.         "Requesting more participants",
  83.         -- Add more custom messages if needed...
  84.     },
  85.     inc = {
  86.         "Incoming",
  87.         "INC INC INC",
  88.         "INC",
  89.         "Gotta INC",
  90.         "BIG INC",
  91.         "Incoming enemy forces",
  92.         "Incoming threat",
  93.         "Enemy push incoming",
  94.         "Enemy blitz incoming",
  95.         "Enemy strike team inbound",
  96.         "Incoming attack alert",
  97.         "Enemy wave inbound",
  98.         "Enemy squad closing in",
  99.         "Anticipate enemy push",
  100.         "Enemy forces are closing in",
  101.         -- Add more custom messages if needed...
  102.     },
  103.     allClear = {
  104.         "We are all clear",
  105.         "All clear",
  106.         "Looks like a ghost town",
  107.         "All good",
  108.         "Looking good",
  109.         "Area secure",
  110.         "All quiet on the front",
  111.         "Situation is under control",
  112.         "All quiet here",
  113.         "We are looking good",
  114.         "Perimeter is secured",
  115.         "Situation is calm",
  116.         "No threats detected",
  117.         "All quiet on this end",
  118.         "Area is threat-free",
  119.         -- Add more custom messages if needed...
  120.     },
  121. }
  122.  
  123. -- Create the main frame
  124. local IncCallout = CreateFrame("Frame", "IncCalloutMainFrame", UIParent, "BackdropTemplate")
  125. IncCallout:SetSize(160, 155)
  126. IncCallout:SetPoint("CENTER")
  127.  
  128. -- Create a background texture for the main frame
  129. local bgTexture = IncCallout:CreateTexture(nil, "BACKGROUND")
  130. bgTexture:SetColorTexture(0, 0, 0)
  131. bgTexture:SetAllPoints(IncCallout)
  132.  
  133. -- Create a border frame
  134. local BorderFrame = CreateFrame("Frame", nil, IncCallout, "BackdropTemplate")
  135. BorderFrame:SetFrameLevel(IncCallout:GetFrameLevel() - 1) -- Ensure it's behind the main frame
  136. BorderFrame:SetSize(IncCallout:GetWidth() + 4, IncCallout:GetHeight() + 4) -- Adjust these values for border thickness
  137. BorderFrame:SetPoint("CENTER", IncCallout, "CENTER")
  138.  
  139. -- Create a border texture for the border frame
  140. local borderTexture = BorderFrame:CreateTexture(nil, "OVERLAY")
  141. borderTexture:SetColorTexture(1, 1, 1)
  142. borderTexture:SetAllPoints(BorderFrame)
  143.  
  144. IncCallout:SetMovable(true)
  145. IncCallout:EnableMouse(true)
  146. IncCallout:RegisterForDrag("LeftButton")
  147. IncCallout:SetScript("OnDragStart", IncCallout.StartMoving)
  148. IncCallout:SetScript("OnDragStop", IncCallout.StopMovingOrSizing)
  149.  
  150. local fontSize = 15
  151.  
  152. -- Function to create a button
  153. local function createButton(name, width, height, text, anchor, xOffset, yOffset, onClick)
  154.     local button = CreateFrame("Button", nil, IncCallout, "UIPanelButtonTemplate, BackdropTemplate")
  155.     button:SetSize(width, height)
  156.     button:SetText(text)
  157.     if type(anchor) == "table" then
  158.         button:SetPoint(anchor[1], anchor[2], anchor[3], xOffset, yOffset)
  159.     else
  160.         button:SetPoint(anchor, xOffset, yOffset)
  161.     end
  162.     button:SetScript("OnClick", onClick)
  163.     button:GetFontString():SetTextColor(1, 1, 1, 1)
  164. --    button:SetBackdrop({
  165. --        bgFile = "Interface/Tooltips/UI-Tooltip-Background",
  166. --        edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
  167. --        tile = true,
  168. --        tileSize = 16,
  169. --        edgeSize = 16,
  170. --        insets = { left = 4, right = 4, top = 4, bottom = 4 }
  171. --    })
  172.     table.insert(buttonTexts, button:GetFontString())
  173.     table.insert(buttons, button)
  174.     return button
  175. end
  176.  
  177. local function applyButtonColor()
  178.     local r, g, b, a
  179.     if IncDB.buttonColor then
  180.         r, g, b, a = IncDB.buttonColor.r, IncDB.buttonColor.g, IncDB.buttonColor.b, IncDB.buttonColor.a
  181.     else
  182.         r, g, b, a = 1, 0, 0, 1 -- Default to red
  183.     end
  184.     for _, button in ipairs(buttons) do
  185.         button:SetBackdropColor(r, g, b, a)
  186.     button.Left:SetVertexColor(r, g, b, a)  -- Fizzlemizz added
  187.     button.Right:SetVertexColor(r, g, b, a)  -- Fizzlemizz added
  188.     button.Middle:SetVertexColor(r, g, b, a)  -- Fizzlemizz added
  189.     end
  190. end
  191.  
  192. local options = {
  193.     name = "IncCallout",
  194.     type = "group",
  195.     args = {
  196.         sendMore = {
  197.             type = "select",
  198.             name = "Send More message",
  199.             desc = "Select the message for the 'Send More' button",
  200.             values = buttonMessages.sendMore,
  201.             get = function() return buttonMessageIndices.sendMore end,
  202.             set = function(_, newValue) buttonMessageIndices.sendMore = newValue end,
  203.             order = 1,
  204.         },
  205.         inc = {
  206.             type = "select",
  207.             name = "INC message",
  208.             desc = "Select the message for the 'INC' button",
  209.             values = buttonMessages.inc,
  210.             get = function() return buttonMessageIndices.inc end,
  211.             set = function(_, newValue) buttonMessageIndices.inc = newValue end,
  212.             order = 2,
  213.         },
  214.         allClear = {
  215.             type = "select",
  216.             name = "All Clear message",
  217.             desc = "Select the message for the 'All Clear' button",
  218.             values = buttonMessages.allClear,
  219.             get = function() return buttonMessageIndices.allClear end,
  220.             set = function(_, newValue) buttonMessageIndices.allClear = newValue end,
  221.             order = 3,
  222.         },
  223.         opacity = {
  224.             type = "range",
  225.             name = "Opacity",
  226.             desc = "Adjust the transparency of the IncCallout frame.",
  227.             min = 0, max = 1, step = 0.05,
  228.             get = function() return IncDB.opacity or 1 end,
  229.             set = function(_, newValue)
  230.                 bgTexture:SetAlpha(newValue)
  231.                 borderTexture:SetAlpha(newValue)
  232.                 IncDB.opacity = newValue
  233.             end,
  234.             order = 4,
  235.         },
  236.         fontColor = {
  237.         type = "color",
  238.         name = "Button Font Color",
  239.         desc = "Set the color of the button text.",
  240.         hasAlpha = true,
  241.         get = function()
  242.             local color = IncDB.fontColor or {r = 1, g = 1, b = 1, a = 1} -- Default to white
  243.             return color.r, color.g, color.b, color.a
  244.         end,
  245.         set = function(_, r, g, b, a)
  246.             IncDB.fontColor.r = r
  247.             IncDB.fontColor.g = g
  248.             IncDB.fontColor.b = b
  249.             IncDB.fontColor.a = a
  250.             for _, text in ipairs(buttonTexts) do
  251.                 text:SetTextColor(r, g, b, a)
  252.             end
  253.         end,
  254.         order = 5,
  255.         },
  256.         buttonColor = {
  257.             type = "color",
  258.             name = "Button Color",
  259.             desc = "Set the color of the buttons.",
  260.             hasAlpha = true,
  261.             get = function()
  262.                 local color = IncDB.buttonColor or {r = 1, g = 0, b = 0, a = 1} -- Default to red
  263.                 return color.r, color.g, color.b, color.a
  264.             end,
  265.             set = function(_, r, g, b, a)
  266.                 IncDB.buttonColor.r = r  -- Fizzlemizz
  267.                 IncDB.buttonColor.g = g -- Fizzlemizz
  268.                 IncDB.buttonColor.b = b -- Fizzlemizz
  269.                 IncDB.buttonColor.a = a -- Fizzlemizz
  270.             applyButtonColor() -- Fizzlemizz use this instead of for loop below because it does the same thing
  271. --                for _, button in ipairs(buttons) do
  272. --                    button:SetBackdropColor(r, g, b, a)
  273. --                end
  274.             end,
  275.             order = 6,
  276.         },
  277.     },
  278. }
  279.  
  280. -- Create a table to map each location to itself
  281. local locationTable = {}
  282. for _, location in ipairs(battlegroundLocations) do
  283.     locationTable[location] = location
  284. end
  285.  
  286. local function isInBattleground()
  287.     local inInstance, instanceType = IsInInstance()
  288.     return inInstance and (instanceType == "pvp" or instanceType == "arena")
  289. end
  290.  
  291. local function ButtonOnClick(self)
  292.     if not isInBattleground() then
  293.         print("You are not in a battleground.")
  294.         return
  295.     end
  296.  
  297.     local currentLocation = GetSubZoneText()
  298.     local playerFaction = UnitFactionGroup("player") or ""
  299.     local enemyFaction = playerFaction == "Alliance" and "Horde" or "Alliance"
  300.     local message = self:GetText() .. " " .. enemyFaction .. " incoming at " .. currentLocation
  301.     SendChatMessage(message, "INSTANCE_CHAT")
  302. end
  303.  
  304. -- Register an event listener for when the player enters a new zone or subzone
  305. local f = CreateFrame("Frame")
  306. f:RegisterEvent("ZONE_CHANGED_NEW_AREA")
  307.  
  308. f:SetScript("OnEvent", function(self, event, ...)
  309.     if event == "ZONE_CHANGED_NEW_AREA" then
  310.         local currentLocation = GetRealZoneText() .. " - " .. GetSubZoneText()
  311.         local location = locationTable[currentLocation]
  312.  
  313.         -- Check if location is in the defined battleground locations
  314.         if location then
  315.             IncCallout:Show()  -- Show the GUI
  316.         else
  317.            
  318.         end
  319.     end
  320. end)
  321.  
  322. -- Now that IncCallout is defined, you can create IncCalloutLDB
  323. local IncCalloutLDB = LibStub("LibDataBroker-1.1"):NewDataObject("IncCallout", {
  324.     type = "data source",
  325.     text = "IncCallout",
  326.     icon = "Interface\\AddOns\\IncCallout\\Icon\\INC.png",
  327.     OnClick = function(_, button)
  328.         if button == "LeftButton" then
  329.             if IncCallout:IsShown() then
  330.                 IncCallout:Hide()
  331.             else
  332.                 IncCallout:Show()
  333.             end
  334.         else
  335.             InterfaceOptionsFrame_OpenToCategory("IncCallout")
  336.             InterfaceOptionsFrame_OpenToCategory("IncCallout") -- Call it twice to ensure the correct category is selected
  337.         end
  338.     end,
  339.     OnMouseDown = function(self, button)
  340.         if button == "LeftButton" then
  341.             IncCallout:StartMoving()
  342.         end
  343.     end,
  344.     OnMouseUp = function(self, button)
  345.         if button == "LeftButton" then
  346.             IncCallout:StopMovingOrSizing()
  347.             local point, _, _, x, y = IncCallout:GetPoint()
  348.             local centerX, centerY = Minimap:GetCenter()
  349.             local scale = Minimap:GetEffectiveScale()
  350.             x, y = (x - centerX) / scale, (y - centerY) / scale
  351.             IncDB.minimap.minimapPos = math.deg(math.atan2(y, x)) % 360
  352.         end
  353.     end,
  354.     OnTooltipShow = function(tooltip)
  355.         tooltip:AddLine("|cffff0000IncCallout|r")
  356.         tooltip:AddLine("Left Click: GUI")
  357.         tooltip:AddLine("Right Click: Options")
  358.         tooltip:Show()
  359.     end,
  360. })
  361.  
  362. -- Function to handle the All Clear button click event
  363. local function AllClearButtonOnClick()
  364.     local location = GetSubZoneText()
  365.  
  366.     -- Check if location is in the defined battleground locations
  367.     if not location then
  368.     print("You are not in a BattleGround.")
  369.     return
  370. end
  371.  
  372. local message = buttonMessages.allClear[buttonMessageIndices.allClear] .. " at " .. location
  373. SendChatMessage(message, "INSTANCE_CHAT")
  374. end
  375.  
  376.  
  377. -- Function to handle the Send More button click event
  378. local function SendMoreButtonOnClick()
  379.     local location = GetSubZoneText()
  380.  
  381.     -- Check if location is in the defined battleground locations
  382.     if not location then
  383.     print("You are not in a BattleGround.")
  384.     return
  385. end
  386.  
  387. local message = buttonMessages.sendMore[buttonMessageIndices.sendMore] .. " at " .. location
  388. SendChatMessage(message, "INSTANCE_CHAT")
  389. end
  390.  
  391. -- Function to handle the INC button click event
  392. local function IncButtonOnClick()
  393.     local location = GetSubZoneText()
  394.  
  395.     -- Check if location is in the defined battleground locations
  396.     if not location then
  397.     print("You are not in a BattleGround.")
  398.     return
  399. end
  400.  
  401. local message = buttonMessages.inc[buttonMessageIndices.inc] .. " at " .. location
  402. SendChatMessage(message, "INSTANCE_CHAT")
  403. end
  404.  
  405. -- Register the slash command
  406. SLASH_INC1 = "/inc"
  407. SlashCmdList["INC"] = function()
  408.     if IncCallout:IsShown() then
  409.         IncCallout:Hide()
  410.     end
  411. end
  412.  
  413. local function OnEvent(self, event, ...)
  414.     if event == "PLAYER_ENTERING_WORLD" then
  415.         local inInstance, instanceType = IsInInstance()
  416.         if inInstance and (instanceType == "pvp" or instanceType == "arena") then
  417.    
  418.         else
  419.             print("|cFFFF0000You need to queue up for PvP|r")
  420.         end
  421.        
  422.         if inInstance and instanceType == "pvp" then
  423.             IncCalloutMainFrame:Show()
  424.         end
  425.  
  426.     elseif event == "PLAYER_LOGIN" then
  427. --[[ Fizzlemizz moved ]]--
  428. db = LibStub("AceDB-3.0"):New(addonName.."DB", defaults, true)
  429. IncDB = db.profile
  430. playerFaction = UnitFactionGroup("player")
  431.  
  432. local button1 = createButton("button1", 20, 22, "1", {"TOPLEFT", IncCallout, "TOPLEFT"}, 15, -20, ButtonOnClick)
  433. local button2 = createButton("button2", 20, 22, "2", {"LEFT", button1, "RIGHT"}, 3, 0, ButtonOnClick)
  434. local button3 = createButton("button3", 20, 22, "3", {"LEFT", button2, "RIGHT"}, 3, 0, ButtonOnClick)
  435. local button4 = createButton("button4", 20, 22, "4", {"LEFT", button3, "RIGHT"}, 3, 0, ButtonOnClick)
  436. local buttonZerg = createButton("buttonZerg", 40, 22, "Zerg", {"LEFT", button4, "RIGHT"}, 3, 0, ButtonOnClick)
  437. local incButton = createButton("incButton", 60, 22, "Inc", {"TOP", IncCallout, "TOP"}, 0, -45, ButtonOnClick)
  438. local sendMoreButton = createButton("sendMoreButton", 80, 22, "Send More", {"TOP", incButton, "BOTTOM"}, 0, -5, SendMoreButtonOnClick)
  439. local allClearButton = createButton("allClearButton", 60, 22, "All Clear", {"TOP", sendMoreButton, "BOTTOM"}, 0, -5, AllClearButtonOnClick)
  440. local exitButton = createButton("exitButton", 60, 22, "Exit", {"TOP", allClearButton, "BOTTOM"}, 0, -5, function() IncCallout:Hide() end)
  441.  
  442. allClearButton:SetScript("OnClick", AllClearButtonOnClick)
  443. sendMoreButton:SetScript("OnClick", SendMoreButtonOnClick)
  444. incButton:SetScript("OnClick", IncButtonOnClick)
  445. -- Apply the color to all the buttons
  446. applyButtonColor()
  447.  
  448. -- Initialize IncDB.minimap if it's not already initialized
  449. if not IncDB.minimap then
  450.     IncDB.minimap = {
  451.         hide = false,
  452.         minimapPos = 45, -- Default position angle (in degrees)
  453.     }
  454. end
  455.  
  456. -- Register the options table
  457. AceConfig:RegisterOptionsTable(addonName, options)
  458.  
  459. -- Create a config panel
  460. local configPanel = AceConfigDialog:AddToBlizOptions(addonName, "IncCallout")
  461. configPanel.default = function()
  462.     -- Reset the options to default values
  463.     buttonMessageIndices.sendMore = 1
  464.     buttonMessageIndices.inc = 1
  465.     buttonMessageIndices.allClear = 1
  466. end
  467. --[[ Fizzlemizz end moved ]]--
  468.  
  469.  
  470.     -- Load saved button messages indices
  471.     buttonMessageIndices.sendMore = IncDB.sendMoreIndex or 1
  472.     buttonMessageIndices.inc = IncDB.incIndex or 1
  473.     buttonMessageIndices.allClear = IncDB.allClearIndex or 1
  474.  
  475.     -- Load the opacity setting
  476.     bgTexture:SetAlpha(IncDB.opacity or 1)
  477.     borderTexture:SetAlpha(IncDB.opacity or 1)
  478.  
  479.     -- Load the button color
  480.     local color = IncDB.buttonColor or {r = 1, g = 0, b = 0, a = 1} -- Default to red
  481.     local r, g, b, a = color.r, color.g, color.b, color.a
  482.     applyButtonColor() -- Fizzlemizz use this instead of for loop below because it does the same thing
  483. --    for _, button in ipairs(buttons) do
  484. --        button:SetBackdropColor(r, g, b, a)
  485. --    end
  486.  
  487.     -- Load the font color
  488.     local savedColor = IncDB.fontColor or {r = 1, g = 1, b = 1, a = 1}  -- Default to white
  489.     local r, g, b, a = savedColor.r, savedColor.g, savedColor.b, savedColor.a
  490.     for _, text in ipairs(buttonTexts) do
  491.         text:SetTextColor(r, g, b, a)
  492.     end
  493.  
  494.     -- Load the font
  495.     local defaultSize = 15  -- Default font size
  496.     local font = IncDB.font or "Fonts\\ARIALN.ttf"  -- Default to Arial
  497.     for _, text in ipairs(buttonTexts) do
  498.         local _, size = text:GetFont()
  499.         size = size or defaultSize
  500.         text:SetFont(font, size)  -- Preserve the font size
  501.     end
  502.  
  503.     -- Load the minimap icon settings
  504.     icon:Register("IncCallout", IncCalloutLDB, IncDB.minimap)
  505.  
  506.     elseif event == "PLAYER_LOGOUT" then
  507. --[[ Fizzlemizz commented out ]]--
  508.     -- Save button messages indices
  509. --    IncDB.sendMoreIndex = buttonMessageIndices.sendMore
  510. --    IncDB.incIndex = buttonMessageIndices.inc
  511. --    IncDB.allClearIndex = buttonMessageIndices.allClear
  512.  
  513.     -- Save the opacity setting
  514. --    IncDB.opacity = bgTexture:GetAlpha()
  515.  
  516.     -- Save the font color
  517. --    local savedColor = IncDB.fontColor or {r = 1, g = 1, b = 1, a = 1}  -- Default to white
  518. --    local r, g, b, a = savedColor.r, savedColor.g, savedColor.b, savedColor.a
  519. --    for _, text in ipairs(buttonTexts) do
  520. --        text:SetTextColor(r, g, b, a)
  521. --    end
  522.  
  523.     -- Save the font
  524. --    IncDB.font = buttonTexts[1]:GetFont()
  525.  
  526.     -- Save the button color
  527. --    local r, g, b, a = buttons[1]:GetBackdropColor()
  528. --    IncDB.buttonColor = {r = r, g = g, b = b, a = a}
  529. --[[ Fizzlemizz end commented out ]]--
  530. end
  531.  
  532.  
  533. end
  534.  
  535. IncCallout:SetScript("OnEvent", OnEvent)
  536.  
  537. -- Register the events
  538. IncCallout:RegisterEvent("PLAYER_ENTERING_WORLD")
  539. IncCallout:RegisterEvent("PLAYER_LOGIN")
  540. IncCallout:RegisterEvent("PLAYER_LOGOUT")
  541. IncCallout:SetScript("OnEvent", OnEvent)
__________________
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.
  Reply With Quote
08-14-23, 05:34 AM   #8
Sharpedge
A Wyrmkin Dreamwalker
 
Sharpedge's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2022
Posts: 54
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)
Also had to move this up seeing that it wasn't showing in Options:

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
Then there was an issue if you closed out the GUI with the MiniMap button the colors would revert to the default red. So I had to adjust that a little:

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)
And lastly, whenever you would click a button it would stay the default red until you did a /reload. So i fixed that as well:

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
But everything else it awesome. Thank you very much for taking the time to look at my code. My head was spinning trying to figure out what was causing all the issues. Once I update my addon I will post a link to my Github.....

Thank you again, Fizzlemizz
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Having issues with AceDB, I think...


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off