View Single Post
06-15-21, 06:11 PM   #3
Srzm
A Murloc Raider
Join Date: Jun 2021
Posts: 4
Alright then. I made a minimum version of the config where you can reproduce the problem. Just checked it. To open the config, you have to type "/test".
Here is the code.

The config.lua.

Code:
UITestAddOn = LibStub("AceAddon-3.0"):NewAddon("UITestAddOn", "AceEvent-3.0","AceConsole-3.0","AceTimer-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local AceConfig = LibStub("AceConfig-3.0")
local self , UITestAddOn = UITestAddOn , UITestAddOn
local UITestAddOndb



local ShortStats = {
	["Strength"] = "STR",
	["Agility"] = "AGI",
	["Stamina"] = "STA",
	["Intellect"] = "INT",
	["Spirit"] = "SPI",
	["Attack Power"] = "ATK",
	["Armor Penetration"] = "ARP",
	["Expertise"] = "EXP",
	["Spell Power"] = "SPW",
	["Mana per 5s"] = "MP5",
	["Haste Rating"] = "HST",
	["Crit Rating"] = "CRI",
	["Hit Rating"] = "HIT",
	["Defense Rating"] = "DEF",
	["Dodge Rating"] = "DDG",
	["Parry Rating"] = "PAR",
	["Resilience Rating"] = "RES",
	["Armor"] = "ARM",
}

local LongStats = {
	["STR"] = "Strength",
	["AGI"] = "Agility",
	["STA"] = "Stamina",
	["INT"] = "Intellect",
	["SPI"] = "Spirit",
	["ATK"] = "Attack Power",
	["ARP"] = "Armor Penetration",
	["EXP"] = "Expertise",
	["SPW"] = "Spell Power",
	["MP5"] = "Mana per 5s",
	["HST"] = "Haste Rating",
	["CRI"] = "Crit Rating",
	["HIT"] = "Hit Rating",
	["DEF"] = "Defense Rating",
	["DDG"] = "Dodge Rating",
	["PAR"] = "Parry Rating",
	["RES"] = "Resilience Rating",
	["ARM"] = "Armor",
}

local function splitStringToTable (inputstr, seperator)
        if seperator == nil then
                seperator = "%s"
        end
        local t={}
        for str in string.gmatch(inputstr, "([^"..seperator.."]+)") do
                table.insert(t, str)
        end
        return t
end

function UITestAddOn:OnInitialize()
	self.db = LibStub("AceDB-3.0"):New("UITestAddOndb",UITestAddOn_DBdefaults, "Default");
	self.db.RegisterCallback(self, "OnProfileChanged", "ChangeProfile")
	self.db.RegisterCallback(self, "OnProfileCopied", "ChangeProfile")
	self.db.RegisterCallback(self, "OnProfileReset", "ChangeProfile")
	UITestAddOndb = self.db.profile;
	
	self:RegisterChatCommand("test", "ShowConfig")
	
	UITestAddOn.options =
	{
		name = "UITestAddOn",
		desc = "Learning to code GUI",
		type = 'group',
		args = {},
	}
	
	local bliz_options = CopyTable(UITestAddOn.options)
	bliz_options.args.load =
	{
		name = "Load configuration",
		desc = "Load configuration options",
		type = 'execute',
		func = "ShowConfig",
		handler = UITestAddOn,
	}
	
	LibStub("AceConfig-3.0"):RegisterOptionsTable("UITestAddOn_bliz", bliz_options)
	AceConfigDialog:AddToBlizOptions("UITestAddOn_bliz", "UITestAddOn")
end

local function initOptions()
	if UITestAddOn.options.args["Analysis Options"] then
		return
	end
	
	UITestAddOn:OnOptionsCreate()
	
	for k, v in UITestAddOn:IterateModules() do
		if type(v.OnOptionsCreate) == "function" then
			v:OnOptionsCreate()
		end
	end
	AceConfig:RegisterOptionsTable("UITestAddOn", UITestAddOn.options)
end

function UITestAddOn:ShowConfig()
	initOptions()
	AceConfigDialog:Open("UITestAddOn")
end

function UITestAddOn:ChangeProfile()
	UITestAddOndb = self.db.profile
	for k,v in UITestAddOn:IterateModules() do
		if type(v.ChangeProfile) == 'function' then
			v:ChangeProfile()
		end
	end
end

function UITestAddOn:AddOption(key, table)
	self.options.args[key] = table
end

function UITestAddOn:OnOptionsCreate()
	self:AddOption("profiles", LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db))
	self.options.args.profiles.order = -1
	
	self:AddOption('Analysis Options', {
		type = 'group',
		name = "Analysis Options",
		desc = "Options for Character Analysis",
		order = 1,
		args = 
		{
			header =
			{
				type = "header",
				name = "Analysis Options",
				order = 1,
				width = "full",
			},
			optionsArea = 
			{
				type = 'group',
				inline = true,
				name = "",
				args =
				{
					failstats = 
					{
						type = "input",
						name = "Enter Failstats to add / remove.\nA new line for each fail stat.",
						set = function(info,value)
									local inputRaw = splitStringToTable(value,"\n");
									
									for k,v in pairs(inputRaw) do
										if not (ShortStats[v]) then -- Check if player entered nonsence. And remove it.
											DEFAULT_CHAT_FRAME:AddMessage(v .. "is not a stat, removing.")
											table.remove(inputRaw,k)
										else
											inputRaw[k] = ShortStats[v] -- Transform the nice stats into short upper stats.
										end
									end
									
									wipe(UITestAddOndb["failstats"]["WARRIOR"]["Arms"])
									UITestAddOndb["failstats"]["WARRIOR"]["Arms"] = CopyTable(inputRaw);
									
								end,
						get = function(info)
									local failStatsString = "";
									for k,v in pairs(UITestAddOndb["failstats"]["WARRIOR"]["Arms"]) do
										failStatsString = failStatsString .. LongStats[UITestAddOndb["failstats"]["WARRIOR"]["Arms"][k]] .. "\n"
									end
									return failStatsString;
								end,
						multiline = 15,
						order = 2,
					},
				},
			},
		}
	})
end

The profiles.lua

Code:
UITestAddOn_DBdefaults = {
	profile = {
		failstats = { -- Failstats on Equipment
			["WARRIOR"] = {
				["Arms"] = { "INT", "SPI", "SPW", "MP5", "DEF", "DDG", "PAR", "RES" }, -- Arms
			},
		},
	}
}

And the .toc-file:

Code:
## Interface: 20500
## Title: UITestAddOn
## Notes: Just some goofing to learn UI.
## Author: Srzm
## Version: 0.1
## SavedVariables: UITestAddOndb

embeds.xml
profiles.lua
config.lua
And the embeds.xml:

Code:
<Ui xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.blizzard.com/wow/ui/  ..\FrameXML\UI.xsd" xmlns="http://www.blizzard.com/wow/ui/">
	<Include file="libs\AceAddon-3.0\AceAddon-3.0.xml" />
	<Include file="libs\AceEvent-3.0\AceEvent-3.0.xml" />
	<Include file="libs\AceTimer-3.0\AceTimer-3.0.xml" />
	<Include file="libs\AceHook-3.0\AceHook-3.0.xml" />
	<Include file="libs\AceDB-3.0\AceDB-3.0.xml" />
	<Include file="libs\AceDBOptions-3.0\AceDBOptions-3.0.xml" />
	<Include file="libs\AceLocale-3.0\AceLocale-3.0.xml" />
	<Include file="libs\AceConsole-3.0\AceConsole-3.0.xml" />
	<Include file="libs\AceGUI-3.0\AceGUI-3.0.xml" />
	<Include file="libs\AceConfig-3.0\AceConfig-3.0.xml" />
	<Include file="libs\LibSharedMedia-3.0\lib.xml" />
	<Include file="libs\AceGUI-3.0-SharedMediaWidgets\widget.xml" />
	<Include file="libs\LibDeformat-3.0\lib.xml" />
	<Script file="libs\LibStub\LibStub.lua" />
	<Script file="libs\CallbackHandler-1.0\CallbackHandler-1.0.lua" />
	<Script file="libs\LibDataBroker-1.1\LibDataBroker-1.1.lua" />
</Ui>

One last note: I develop this addon for patch TBC Classic 2.5.1.
Greetz and thanks!
Srzm

Last edited by Srzm : 06-16-21 at 02:40 AM.
  Reply With Quote