Quantcast
WoWInterface - View Single Post - adding a GUI for addon options
View Single Post
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,511
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