Quantcast
adding a GUI for addon options - WoWInterface
Thread Tools Display Modes
06-01-10, 10:50 AM   #1
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
adding a GUI for addon options

So I want to know how to add a GUI to an addon. I thought to myself, "Minimap is easy to modify, should be a good place to start off with a GUI." pMinimap is alilttle more complicated than I'd how to learn from :P

can people give me tips or lead me in the right direction pls

so far i'm looking @ pMinimap & sThreatMeter2

--to be more specifc. I would like the config to in the AddOns tab in the default Blizzard options panels.
  Reply With Quote
06-01-10, 10:56 AM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,759
Sometimes, you can't just *add* a GUI to another addon. If that addon's functions and variables are locals, they are only accessible through that addon - not from something outside of it. Another thing with a beginner trying to add a GUI to a different addon is that you have to learn the API of that addon and that author's style/practices.

It's best just to write something simple for yourself with a simple GUI (like one or two checkboxes).
__________________
"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
06-01-10, 10:58 AM   #3
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
srry left out they were my addons :P

one or two checkboxes sounds great lol i just have nfi where to start. and the widgets page in wowprogramming is MASSIVE
  Reply With Quote
06-01-10, 11:01 AM   #4
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Look at the code for AddOns which you know have a config options GUI, and study those. That should, at least, narrow down what you need to reference on WowProgramming.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
06-01-10, 11:04 AM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,759
Make sure that they are addons which don't use LibAceConfig-3.0
__________________
"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
06-01-10, 11:07 AM   #6
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
stuck...

i know the problem... (i think) but im not experienced nuff to fix it

i have two seperate tables.
e.g.
the original
alTestOne = true

and the saved variable
alTestOne = true

now when I click the button i've made on the GUI. the savedvariable boolean changes, but nothing changes on my UI.. Is my UI taking its value from the original alTestOne? if yes how do i fix it?
hope i xplained it well nuff :P

Last edited by alimjocox : 06-01-10 at 12:24 PM.
  Reply With Quote
06-01-10, 12:13 PM   #7
Marthisdil
An Onyxian Warder
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 363
Originally Posted by Seerah View Post
Make sure that they are addons which don't use LibAceConfig-3.0
Or just use LibAceConfig!
__________________

Marth



  Reply With Quote
06-01-10, 12:38 PM   #8
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,512
Originally Posted by alimjocox View Post
stuck...

i know the problem... (i think) but im not experienced nuff to fix it

i have two seperate tables.
e.g.
the original
alTestOne = true

and the saved variable
alTestOne = true

now when I click the button i've made on the GUI. the savedvariable boolean changes, but nothing changes on my UI.. Is my UI taking its value from the original alTestOne? if yes how do i fix it?
hope i xplained it well nuff :P
Are you telling it to use the new value when it gets changed by the UI ? If not that would be your problem. Just setting the variable won't make it update.
__________________
  Reply With Quote
06-01-10, 12:46 PM   #9
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
Originally Posted by Xrystal View Post
Are you telling it to use the new value when it gets changed by the UI ? If not that would be your problem. Just setting the variable won't make it update.
Okay i've written this up to replicate whats going on... just imagine @ at a much larger scale :P

Code:
alUI_DB = {}

alUI_DB.example = true
if ( alUI_DB.example ) then
	print("Yay");
else
        print("Off")
end


local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(_, _, name)
	if name ~= "alUI" then return end
	if not (alUI_DB) then
		alUI_DB = { }
	f:UnregisterEvent("ADDON_LOADED")
	f:SetScript("OnEvent", nil)
	end
end)
So you said, make it tak on the SavedVariable.. how do i do that? lol
The box stays unticked. so for some reason the box is taking the savedvariable boolean. but...

Last edited by alimjocox : 06-01-10 at 12:48 PM.
  Reply With Quote
06-01-10, 01:11 PM   #10
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,512
Where is the UI code for the check box ?

This is roughly what I do to get checkboxes to work:

Code:
--Create the Button
local f = CreateFrame("CheckButton", name, parent,"OptionsCheckButtonTemplate")
local f.Text = _G[f:GetName().."Text"]
f.Text:SetText("MyText")

-- initialise a dirty flag for a global update run
parent.dirty = false

-- Get Current Value for this CheckBox from the saved variables table
f:SetChecked(MySavedVariablesTable[name]["isChecked"])

-- Now we can tell it to react to any further changes
f:SetScript("OnClick",function(self,button,down)  
   local checked = ( self:GetChecked() == 1 )
   -- It needs to be stored in a stored variable somewhere
   MySavedVariablesTable[name] = MySavedVariablesTable[name] or {}
   MySavedVariablesTable[name]["isChecked"] = checked

   -- Update addon to reflect this change only
   if ( checked ) then 
      -- Do something because this is checked
   else
      -- Do something else because it isn't checked
   end

   -- Or flag that a change has been made for a global update later
   parent.dirty = true
end)
If you use the dirty option set up a button to *Confirm* the changes and then call an UpdateRoutine if there have been changes ( settings are dirty ).

Edit: Note though that the Saved Variables Table doesn't have to be set up this way to work. As long as the value that is stored in the saved variables is set and used and the OnClick script set and acted on then it should work as descirbed.
__________________

Last edited by Xrystal : 06-01-10 at 01:14 PM.
  Reply With Quote
06-01-10, 01:14 PM   #11
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
Code:
local frame = CreateFrame("CheckButton", "alUIConfigButton1", al)
frame:SetWidth(26)
frame:SetHeight(26)
frame:SetPoint("TOPLEFT", 16, -52)
frame:SetScript("OnShow", function(frame)
	if alUI_DB.example then
		frame:SetChecked(true)
	else
		frame:SetChecked(false)
	end
end)
frame:SetScript("OnClick", function(frame)
	local tick = frame:GetChecked()
	if tick then
		PlaySound("igMainMenuOptionCheckBoxOn")
		alUI_DB.example = true
	else
		PlaySound("igMainMenuOptionCheckBoxOff")
		alUI_DB.example = false
	end
end)
taken straight out of BadBoy, but looking @ his code. his booleans are pre-defined so it kinda means i need to change things. which dont know how
  Reply With Quote
06-01-10, 01:29 PM   #12
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,512
Well, your two pieces of code are fine as they are but apart from setting your variable in one and printing it in another you are not showing how they work together.

For example, you have that print statement to see if your variable is set. When is that set to run ? In the main chunk of the code, in a function called when an event is triggered, in a function called from another function etc.

Also, when is BadBoy CheckBox code set up ? Is it after you have initialised and loaded the saved variables ?

Using the code you supplied it should work in the following order if in the same lua file :

Code:
alUI_DB = {}
alUI_DB.example = true


local frame = CreateFrame("CheckButton", "alUIConfigButton1", al)
frame:SetWidth(26)
frame:SetHeight(26)
frame:SetPoint("TOPLEFT", 16, -52)
frame:SetScript("OnShow", function(frame)
	if alUI_DB.example then
		frame:SetChecked(true)
	else
		frame:SetChecked(false)
	end
end)
frame:SetScript("OnClick", function(frame)
	local tick = frame:GetChecked()
	if tick then
		PlaySound("igMainMenuOptionCheckBoxOn")
		alUI_DB.example = true
	else
		PlaySound("igMainMenuOptionCheckBoxOff")
		alUI_DB.example = false
	end

             -- Now react to the changes
             if ( alUI_DB.example ) then
                print("Yay");
             else
                print("Off")
             end
end)


-- Slight change here
local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function(_, _, name)
	if name ~= "alUI" then return end

             -- use existing/loaded table or create a new one
             alUI_DB = alUI_DB or {}

             -- use existing/loaded variable or set default
             alUI_DB.example = alUI_DB.example or true

             f:UnregisterEvent("ADDON_LOADED")
	f:SetScript("OnEvent", nil)

             -- React to the loaded value
             if ( alUI_DB.example ) then
                print("Yay");
             else
                print("Off")
             end
end)
__________________
  Reply With Quote
06-01-10, 01:42 PM   #13
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
Originally Posted by Xrystal View Post
For example, you have that print statement to see if your variable is set. When is that set to run ? In the main chunk of the code, in a function called when an event is triggered, in a function called from another function etc.

Also, when is BadBoy CheckBox code set up ? Is it after you have initialised and loaded the saved variables ?
firstly thx for ur help. its kudos.

Well. My .toc / .xml
e.g.
Code:
defaults.lua
guioptions.lua
(ui lua)....
so I imagine that print is triggered right off the bat.

WoW FrameXML code is loaded and executed.
Addon code is loaded and executed.
Saved variables for one addon a time are loaded and executed, then ADDON_LOADED event is fired for that addon.
VARIABLES_LOADED event is fired to let addons know that all saved variables were loaded.
- from Wowwiki
but yeah i have no idea when Checkbox code is run tbh. after still reading wowwiki.

I'm going to put it all in one lua file. But question -ideally when or how should default settings be initialised? I see addon setting them on event, but my defaults handle the UI where or not something should be enabled so i kinda need them to load first.
  Reply With Quote
06-01-10, 02:14 PM   #14
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,759
Originally Posted by Marthisdil View Post
Or just use LibAceConfig!
Now, how is he supposed to learn from that?
__________________
"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
06-01-10, 02:24 PM   #15
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,512
Assuming the SavedVariables is set up in your TOC it will automatically load up when the ADDON_LOADED event is called.


For a simplish addon these 3 events should be all you need to use. The PLAYER_LOGOUT event is only really needed if you don't use the saved variables directly but copy them into local variables for ease of access. Just make sure to store them back to the saved variables during this LOGOUT event.
Code:
if event == ADDON_LOADED then
   -- The AddOn's Saved Variables are loaded
   -- Use this event to make sure that the values are valid or set to the default
  -- EG. SavedVariable = SavedVariable or SomeDefaultValue
  -- This basically uses the loaded value or sets the default value if there is no loaded value
elseif event == VARIABLES_LOADED then
   -- Blizzards Saved Variables and CVars etc are loaded
   -- Use this to override what they have done such as positioning of blizz frames and sizing
elseif event == PLAYER_LOGOUT then
   -- This is where you want to make sure that your saved variables are set 
   -- as this is the last port of call before it stores the values in the WTF file
   -- You can also use this similarly to the ADDON_LOADED event where you set the default if a value doesn't exist as a double check that the values didn't get nulled during process.
   -- EG. SavedVariable = SavedVariable or SomeDefaultValue
end
__________________
  Reply With Quote
06-01-10, 09:38 PM   #16
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
why do so many peple use Ace? whats the benefits?
  Reply With Quote
06-01-10, 10:03 PM   #17
Nobgul
A Molten Giant
 
Nobgul's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 693
I Figured I would piggyback this thread and ask a few questions myself.
I have looked around for libaceconfig I was not able to find any refrence to it. I however did find LibGUIFacroty. I have made quite a few addons and most of what i know has come from tearing apart other users addons and looking. I would really like to add a gui for my addons for configuration. Is there a idot's guide on how to make a gui ?

Last edited by Nobgul : 06-01-10 at 10:22 PM.
  Reply With Quote
06-01-10, 10:19 PM   #18
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
http://www.wowace.com/addons/ace3/
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » adding a GUI for addon options

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