Quantcast Config.lua to ingame GUI? - WoWInterface
Thread Tools Display Modes
08-25-11, 08:17 PM   #1
dreamcatcher
A Black Drake
 
dreamcatcher's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 82
Config.lua to ingame GUI?

Ok so I have been trying for weeks to make a in game GUI with no luck. I was hopping to do this just with lua code and no libs.
I tried looking into doing it with Ace3 but I can't understand all that has to be done and were to place the code. I added my SavedVariables field to my TOC, put all my settings into a single table. That's as far as I can get with out then getting completely lost.

Her is all of my code.

http://www.wowace.com/paste/3767/

O also when using Ace3 were do I put the files and which ones do I use, or do I just place the whole Ace3 file in the addons?

Last edited by dreamcatcher : 08-25-11 at 08:21 PM.
  Reply With Quote
08-27-11, 02:47 AM   #2
dreamcatcher
A Black Drake
 
dreamcatcher's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 82
So i finely got the GUI to show up but im getting lots of errors.

Code:
Message: Interface\AddOns\Tweaks\Core.lua:536: attempt to index upvalue 'db' (a nil value)
Time: 08/27/11 01:47:06
Count: 1
Stack: Interface\AddOns\Tweaks\Core.lua:536: in function <Interface\AddOns\Tweaks\Core.lua:534>
[C]: in function `UIParent_ManageFramePositions'
Interface\FrameXML\InterfaceOptionsPanels.lua:1284: in function `InterfaceOptions_UpdateMultiActionBars'
[string "*:OnLoad"]:4: in function `setFunc'
Interface\FrameXML\InterfaceOptionsPanels.lua:1253: in function <Interface\FrameXML\InterfaceOptionsPanels.lua:1246>

Locals: (*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index upvalue 'db' (a nil value)"
db = nil
Here is link to whole code.
http://www.wowace.com/paste/3784/
  Reply With Quote
08-27-11, 03:00 AM   #3
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
First, I don't see you declaring your addon at the very top in Ace fashion. Ie:

Core.lua
Code:
local MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon")
Config.lua
Code:
local MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon")

For getting DB, you'll want to put this line in:
Code:
self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, "Default")
I generally put my defaults table in Core.lua, along with the above line in the MyAddon:OnInitialize() function. MyAddonDB is the SavedVariable table name declared in .toc, and Default is the name of your initial profile.

To get the DB into a variable, something like this in a MyAddon:Anything() function.
Code:
db = self.db.profile

O also when using Ace3 were do I put the files and which ones do I use, or do I just place the whole Ace3 file in the addons?
For now, you can just install Ace3 like a regular addon, this will ensure you have all the components necessary. When you finalize your addon later on, you can set up dependencies and an Embeds.xml, as well as store required Ace folders inside your addon.

Last edited by Nibelheim : 08-27-11 at 03:21 AM.
  Reply With Quote
08-27-11, 03:18 AM   #4
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
Here's some quick examples of a basic Ace addon. You can install Ace3 components under MyAddon\libs\

MyAddon.toc
Embeds.xml
Core.lua
Config.lua

Last edited by Nibelheim : 08-27-11 at 03:26 AM.
  Reply With Quote
08-28-11, 03:48 AM   #5
dreamcatcher
A Black Drake
 
dreamcatcher's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 82
First thank you for your help, I got the options to show up now and there are no errors.
Now I'm trying to set up all the functions and I'm having some problems.
  1. One
I don't know how to set it so I can have the option to re position the bars. My code for that is this.

Core.lua
Code:
local defaults = {
	profile = {
		MAB = {
			Enable = true,
			HideMacronames = true,
			HideGryphons = false,
			Scale = .8,
			["Position"] = {"BOTTOMLEFT",Minimap,-510,0},
		},

local function ActionBars()

-- MainActionBar
	for i = 1, 12 do
		local MAB = _G["ActionButton"..i]
		if (i == 1) then
        MAB:ClearAllPoints()
        MAB:SetPoint(unpack(db.MAB.Position))
		MAB:SetScale(db.MAB.Scale)
	else
        MAB:ClearAllPoints()
        MAB:SetPoint("LEFT", _G["ActionButton"..i-1],"RIGHT",6,0)
		MAB:SetScale(db.MAB.Scale)
		end
	end
Config.lua
Code:
MAB = {
	name = "MainActionBar",
	type = "group",
	order = 30,
	args = {
		Position= {
			type = "input",
			name = "Position",
			order = 1,
			set = function(info, val)
			db.MAB.Position = val
			MyAddon:UpdateStuff()
			end,
			get = function(info) return db.MAB.Position end,
		},
         },
  1. Second
I can get the end caps to show and hide but I can't get the micro names to do the same.

Core.lua
Code:
function Style(self)  
	local name = self:GetName()
	local action = self.action
	local Button = self
	local Count = _G[name.."Count"]
	local HotKey = _G[name.."HotKey"]
	local Border  = _G[name.."Border"]
	local Btname = _G[name.."Name"]
	local Normal  = _G[name.."NormalTexture"]
Btname:Show()
	Button:SetNormalTexture[[Interface\AddOns\MyAddon\Media\button]]
	Border:Hide()
	if db.MAB.HideMacronames then
	Btname:Hide()
	end
end
Config.lua
Code:
HideMacronames = {
	type = "toggle",
	name = "HideMacronames",
	order = 2,
	set = function(info, val)
	db.MAB.HideMacronames = val
	MyAddon:UpdateStuff()
	end,
	get = function(info) return db.MAB.HideMacronames end,
},
  Reply With Quote
08-28-11, 01:16 PM   #6
cokedrivers
A Frostmaul Preserver
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 298
Originally Posted by dreamcatcher View Post
First thank you for your help, I got the options to show up now and there are no errors.
Now I'm trying to set up all the functions and I'm having some problems.
  1. One
I don't know how to set it so I can have the option to re position the bars. My code for that is this.

Core.lua
Code:
local defaults = {
	profile = {
		MAB = {
			Enable = true,
			HideMacronames = true,
			HideGryphons = false,
			Scale = .8,
			["Position"] = {"BOTTOMLEFT",Minimap,-510,0},
		},

local function ActionBars()

-- MainActionBar
	for i = 1, 12 do
		local MAB = _G["ActionButton"..i]
		if (i == 1) then
        MAB:ClearAllPoints()
        MAB:SetPoint(unpack(db.MAB.Position))
		MAB:SetScale(db.MAB.Scale)
	else
        MAB:ClearAllPoints()
        MAB:SetPoint("LEFT", _G["ActionButton"..i-1],"RIGHT",6,0)
		MAB:SetScale(db.MAB.Scale)
		end
	end
Config.lua
Code:
MAB = {
	name = "MainActionBar",
	type = "group",
	order = 30,
	args = {
		Position= {
			type = "input",
			name = "Position",
			order = 1,
			set = function(info, val)
			db.MAB.Position = val
			MyAddon:UpdateStuff()
			end,
			get = function(info) return db.MAB.Position end,
		},
         },
  1. Second
I can get the end caps to show and hide but I can't get the micro names to do the same.

Core.lua
Code:
function Style(self)  
	local name = self:GetName()
	local action = self.action
	local Button = self
	local Count = _G[name.."Count"]
	local HotKey = _G[name.."HotKey"]
	local Border  = _G[name.."Border"]
	local Btname = _G[name.."Name"]
	local Normal  = _G[name.."NormalTexture"]
Btname:Show()
	Button:SetNormalTexture[[Interface\AddOns\MyAddon\Media\button]]
	Border:Hide()
	if db.MAB.HideMacronames then
	Btname:Hide()
	end
end
Config.lua
Code:
HideMacronames = {
	type = "toggle",
	name = "HideMacronames",
	order = 2,
	set = function(info, val)
	db.MAB.HideMacronames = val
	MyAddon:UpdateStuff()
	end,
	get = function(info) return db.MAB.HideMacronames end,
},
dreamcatcher im getting close maybe something in my code will help you solve your issue.

Post from wowace.com
WOOT!!



ok so i have my options in game now and its almost working right LOL.

Issues are:

1) does not load default setting to start yet in the options everything is checked. (see screenshot)

2) does not save option changes.

Here are my core.lua and config.lua for you to look at (fair warning the core is huge) did i do forget something did i add something i shouldn't have.

Any Help would be great.

And thank you to everyone who as helped me with the long process.

Coke
Hopefully we both can be up and running soon... havent played WoW in a week been to obsessed with getting this to work LOL

Hope this helps ya.

Coke
  Reply With Quote
08-28-11, 01:48 PM   #7
dreamcatcher
A Black Drake
 
dreamcatcher's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 82
I to have not played wow in two weeks been like you say obsessed with my coding

I have been looking at your stuff on the WowAce Forums. But yours is so so so much bigger then mine that i get lost in your code. Also you don't have any gui command for positions.
  Reply With Quote
08-28-11, 03:20 PM   #8
dreamcatcher
A Black Drake
 
dreamcatcher's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 82
Woot figured out how to change position of bar.

Config.lua
Code:
        offsetX = {
		name = "X Offset",
		type = "input",
		width = "half",
		order = 13,
		desc = "Offsets from the tooltip's anchor left/right",
		set = function(info, value)
		db.MAB.offsetX = value
		MyAddon:UpdateStuff()
		end,
		get = function(info) return tostring(db.MAB.offsetX) end,
	},
	offsetY = {
		name = "Y Offset",
	        type = "input",
		width = "half",
		order = 14,
		desc = "Offsets from the anchor up/down",
		set = function(info, value)
		db.MAB.offsetY = value
		MyAddon:UpdateStuff()
		end,
		get = function(info) return tostring(db.MAB.offsetY) end,
	},
	anchor = {
		name = "Anchor To...",
		type = "select",
		order = 11,
		desc = "What side of the screen you would like the located at.",
		values = positions,
		set = function(info, value)
		db.MAB.anchor = positions[value]
		MyAddon:UpdateStuff()
		end,
		get = function()
        	     for k, v in pairs(positions) do
        	         if v == db.MAB.anchor then
		        	return k
			end
        	     end
		end,
	},
Core.lua
Code:
local defaults = {
	profile = {
		MAB = {
			Enable = true,
			HideMacronames = true,
			HideGryphons = false,
			Scale = .8,
			anchor = "BOTTOMLEFT",
			offsetX = "-510",
			offsetY = "0",
		},

-- MainActionBar
	for i = 1, 12 do
		local MAB = _G["ActionButton"..i]
		if (i == 1) then
        MAB:ClearAllPoints()
        MAB:SetPoint(db.MAB.anchor, Minimap, db.MAB.anchor, db.MAB.offsetX, db.MAB.offsetY)
		MAB:SetScale(db.MAB.Scale)
	else
        MAB:ClearAllPoints()
        MAB:SetPoint("LEFT", _G["ActionButton"..i-1],"RIGHT",6,0)
		MAB:SetScale(db.MAB.Scale)
		end
	end
Now still need to figure out how to get the micro names to show and hide.
  Reply With Quote
08-28-11, 03:50 PM   #9
dreamcatcher
A Black Drake
 
dreamcatcher's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 82
Another problem I just noticed is when I do a reload it is resenting all options to default.

Config.lua
Code:
function MyAddon:ConfigRefresh()
	db = self.db.profile;
end

function MyAddon:SetUpOptions()
	db = self.db.profile;

	LibStub("AceConfig-3.0"):RegisterOptionsTable("MyAddon", GetOptions);
	LibStub("AceConfig-3.0"):RegisterOptionsTable("MyAddon-Profiles", LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db));
	
	self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MyAddon", "MyAddon");
	self.profilesFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MyAddon-Profiles", "Profiles", "MyAddon");
	
	self:RegisterChatCommand("MyAddon", "ChatCommand");
end
Core.lua
Code:
function MyAddon:UpdateStuff()
	Hideblz();
	Quest();
	Buffs_N_Debuffs();
	Chat();
	Map();
 	ActionBars();
	MicroMenu();
	OneBag();
	ExpBar();
	CreateFrames();

	hooksecurefunc("VehicleMenuBar_MoveMicroButtons",MicroMenu)
	hooksecurefunc("ActionButton_Update", Style)
	hooksecurefunc("PetActionBar_Update", StylePet)
	hooksecurefunc("ShapeshiftBar_Update", StyleShapeshift)
	hooksecurefunc("UIParent_ManageFramePositions",ActionBars)

end

---- EVENTS
function MyAddon:PLAYER_ENTERING_WORLD()
	self:UpdateStuff();
end

---- INIT
function MyAddon:ProfChange()
	db = self.db.profile;
	self:ConfigRefresh();
	self:Refresh();
end

function MyAddon:Refresh()
	self:UpdateStuff();
	-- self:UpdatePosition();	
	-- self:UpdateColors();
end

function MyAddon:PLAYER_LOGIN()
	self:UpdateStuff();
	self:Refresh();
end

function MyAddon:OnInitialize()
	self.db = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, "Default");
		
	self.db.RegisterCallback(self, "OnProfileChanged", "ProfChange");
	self.db.RegisterCallback(self, "OnProfileCopied", "ProfChange");
	self.db.RegisterCallback(self, "OnProfileReset", "ProfChange");
	
	self:SetUpOptions();
	
	db = self.db.profile;
	
	self:RegisterEvent("PLAYER_LOGIN");
	self:RegisterEvent("PLAYER_ENTERING_WORLD");
end
  Reply With Quote
08-28-11, 04:54 PM   #10
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,670
I would have given you permission to use my code had you asked...
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
08-28-11, 04:59 PM   #11
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
Originally Posted by dreamcatcher View Post
Another problem I just noticed is when I do a reload it is resenting all options to default.
Do the settings stick before a reload? I.e, you can change an option and it will stay that way? If so, it may be a WTF folder permissions/read-only issue.
  Reply With Quote
08-28-11, 11:46 PM   #12
dreamcatcher
A Black Drake
 
dreamcatcher's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 82
Originally Posted by Seerah View Post
I would have given you permission to use my code had you asked...
Code for a GUI with ace or with out?
  Reply With Quote
08-28-11, 11:52 PM   #13
dreamcatcher
A Black Drake
 
dreamcatcher's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 82
Originally Posted by Nibelheim View Post
Do the settings stick before a reload? I.e, you can change an option and it will stay that way? If so, it may be a WTF folder permissions/read-only issue.
Yes the settings stay when i set them but on a reload they go back to the default setting.
  Reply With Quote
08-29-11, 12:10 AM   #14
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,346
If your game installation is in the program files folder then try running with administrator rights.

I apologise if this has already been suggested and tried without success.
__________________
  Reply With Quote
08-29-11, 01:18 AM   #15
dreamcatcher
A Black Drake
 
dreamcatcher's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 82
Originally Posted by Xrystal View Post
If your game installation is in the program files folder then try running with administrator rights.

I apologise if this has already been suggested and tried without success.
Don't know what the problem was but after I changed the name from MyAddon to DreamTweaks it now saves the profile changes. I was just using MyAddon name for it as a test name so I would not have it mess up my working addon. Since I had both installed. lol o well I will just have to transfer them in and out of the addons file or make a new name for the one I'm working on. I'm rambling on a bought stuff that don't matter.

So any way, question. I still cant get the option for hide/show micro names to work.

Config.lua
Code:
	HideMacronames = {
		name = "HideMacronames",
		type = "toggle",
		order = 2,
		set = function(info, val)
		db.MAB.HideMacronames = val
		DreamTweaks:UpdateStuff()
		end,
		get = function(info) return db.MAB.HideMacronames end,
	},
Core.lua
Code:
function Style(self)  
	local name = self:GetName()
	local action = self.action
	local Button = self
	local Count = _G[name.."Count"]
	local HotKey = _G[name.."HotKey"]
	local Border  = _G[name.."Border"]
	local Btname = _G[name.."Name"]
	local Normal  = _G[name.."NormalTexture"]
	
	Button:SetNormalTexture[[Interface\AddOns\DreamTweaks\Media\button]]
	Border:Hide()
	
	if db.MAB.HideMacronames then
	Btname:Hide()
	else
	Btname:Show()
	end
end
  Reply With Quote
08-29-11, 02:46 AM   #16
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,346
Ah yes, each addon needs a unique name. If you want to use a TestAddon temporary folder for one you are working on then you would have to make sure that the old wtf file for that last addon you used it with has been deleted so as to not confuse things. I usually just create a new folder with a new name and rename it later if I needed to.

As to it not seeming to work do a test printout of the values. If the values are stored as "1" and "0" for one reason or another the test of if x then .. will not work if I remember rightly. try doing the following before the if statements.

print(db.MAB.HideMacronames,type(db.MAB.HideMacronames))
if db.MAB.HideMacronames then
print("Hiding")
Btname:Hide()
else
print("Showing")
Btname:Show()
end
Hopefully that little test will highlight the problem for you.
__________________
  Reply With Quote
08-29-11, 04:57 PM   #17
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,670
Originally Posted by dreamcatcher View Post
Code for a GUI with ace or with out?
Well, considering your above AceConfig options table code mostly originated in TipTop, with.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
08-29-11, 05:44 PM   #18
dreamcatcher
A Black Drake
 
dreamcatcher's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 82
Originally Posted by Seerah View Post
Well, considering your above AceConfig options table code mostly originated in TipTop, with.
o hehe well I got most working good now but the micro names hide/show option.

The thing is it works fine if i do it manually in the default config but it dos nothing in the gui.

Config.lua
Code:
	HideMacronames = {
		name = "HideMacronames",
		type = "toggle",
		order = 2,
		set = function(info, val)
		db.HideMacronames = val
		DreamTweaks:UpdateStuff()
		end,
		get = function(info) return db.HideMacronames end,
	},
Core.lua
Code:
local defaults = {
	profile = {
		HideMacronames = true,


hooksecurefunc('ActionButton_Update', function(self)
        for _, icon in pairs({
            self:GetName(),
            'MultiCastRecallSpellButton',
            'MultiCastSummonSpellButton',
        }) do
        local macroname = _G[self:GetName()..'Name']
        if (db.HideMacronames) then
            macroname:SetAlpha(0)
        end
    end
end)


function DreamTweaks:UpdateStuff()
	hooksecurefunc("ActionButton_Update", Style)
  Reply With Quote
08-29-11, 06:03 PM   #19
dreamcatcher
A Black Drake
 
dreamcatcher's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2010
Posts: 82
Ok well I'm confused. The option to show or hide micro names from the gui is working but only if i do a reload after selecting it in the gui.
  Reply With Quote
08-29-11, 06:22 PM   #20
Nibelheim
local roygbi-
 
Nibelheim's Avatar
Featured
Join Date: Jan 2010
Posts: 1,600
Originally Posted by dreamcatcher View Post
Ok well I'm confused. The option to show or hide micro names from the gui is working but only if i do a reload after selecting it in the gui.
Why are you hooking 'ActionButton_Update' twice? I'd hook it once, call Style() function from the hook, and call Style() function in UpdateStuff()

Code:
function UpdateActionButtonStyle()
    for _, icon in pairs({
        self:GetName(),
        'MultiCastRecallSpellButton',
        'MultiCastSummonSpellButton',
    }) do
        local macroname = _G[self:GetName()..'Name']
        if (db.HideMacronames) then
            macroname:SetAlpha(0)
        end
    end
end

function DreamTweaks:UpdateStuff()
	UpdateActionButtonStyle()
	-- etc
end

function StickThisIntoAFunctionSomewhere()
	hooksecurefunc("ActionButton_Update", UpdateActionButtonStyle)
end
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Config.lua to ingame GUI?

Thread Tools
Display Modes

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