WoW:Creating GUI configuration options (source)
Revision as of 04:47, 15 August 2023
, 15 August 2023Move page script moved page Creating GUI configuration options to WoW:Creating GUI configuration options without leaving a redirect
No edit summary |
m (Move page script moved page Creating GUI configuration options to WoW:Creating GUI configuration options without leaving a redirect) |
||
| (5 intermediate revisions by 5 users not shown) | |||
| Line 1: | Line 1: | ||
{{Cleanup|Inaccurate information, dead links, relies on an add-on that is no longer available}} | |||
Making a GUI Config/Options dialog for your addon is always a bit tricky, however this HOWTO will hopefully help you in such an endeavor. Since a config dialog is usually added to an existing addon, this HOWTO will use an existing addon as an example, but we encourage you to use your own addon while following this HOWTO. | Making a GUI Config/Options dialog for your addon is always a bit tricky, however this HOWTO will hopefully help you in such an endeavor. Since a config dialog is usually added to an existing addon, this HOWTO will use an existing addon as an example, but we encourage you to use your own addon while following this HOWTO. | ||
| Line 5: | Line 7: | ||
This HOWTO is not meant to reproduce myClock in any shape or form, and you'll notice that the code has been changed in a number of places. Nevertheless this HOWTO is based on it, and if you filled in the gaps would give you a nice basic myClock like addon. | This HOWTO is not meant to reproduce myClock in any shape or form, and you'll notice that the code has been changed in a number of places. Nevertheless this HOWTO is based on it, and if you filled in the gaps would give you a nice basic myClock like addon. | ||
= The TOC file = | == The TOC file == | ||
;Reference Material (optional reading) : [[The TOC Format]] | ;Reference Material (optional reading) : [[The TOC Format]] | ||
In the TOC file we need to add your config dialog's .xml file. Also to have a config dialog that remembers it's settings between game sessions, you will need to use the SavedVariables directive. | In the TOC file we need to add your config dialog's .xml file. Also to have a config dialog that remembers it's settings between game sessions, you will need to use the SavedVariables directive. | ||
| Line 34: | Line 36: | ||
;SavedVariables : Allow us to use a variable that is saved between game sessions, on a per-account basis. | ;SavedVariables : Allow us to use a variable that is saved between game sessions, on a per-account basis. | ||
;myClockIndicatorFrame.xml : Main addon frame | ;myClockIndicatorFrame.xml : Main addon frame | ||
;myClockConfigFrame.xml : | ;myClockConfigFrame.xml : Config addon frame | ||
= Load config from SavedVariables = | == Load config from SavedVariables == | ||
: '''Reference Material''' (optional reading) : [[Saving variables between game sessions]] | |||
Using the SavedVariable 'myClockConfig' we declared in the .toc file, we can now load and save our addon's configuration between game sessions. Remember that SavedVariable is per-account, not per-realm and not per-character, so we will need to use tables to store individual settings. | Using the SavedVariable 'myClockConfig' we declared in the .toc file, we can now load and save our addon's configuration between game sessions. Remember that SavedVariable is per-account, not per-realm and not per-character, so we will need to use tables to store individual settings. | ||
== Main frame: .xml == | === Main frame: .xml === | ||
We will be modifying the main addon frame, in this case 'myClockIndicatorFrame.xml' which is used to display the current time. | We will be modifying the main addon frame, in this case 'myClockIndicatorFrame.xml' which is used to display the current time. | ||
| Line 61: | Line 63: | ||
</Ui> | </Ui> | ||
== Main frame: .lua == | === Main frame: .lua === | ||
=== Globals === | ==== Globals ==== | ||
We need to: | We need to: | ||
| Line 96: | Line 97: | ||
; myClockConfig_default : Each of these variables is a default setting for a configuration option the user will be able to change in our config dialog. They are also used the first time a character uses our addon, as they have no saved settings yet. | ; myClockConfig_default : Each of these variables is a default setting for a configuration option the user will be able to change in our config dialog. They are also used the first time a character uses our addon, as they have no saved settings yet. | ||
=== Registering Events === | ==== Registering Events ==== | ||
Since we will use the VARIABLES_LOADED event to know when it is safe to use our SavedVariable, | Since we will use the VARIABLES_LOADED event to know when it is safe to use our SavedVariable, | ||
| Line 125: | Line 126: | ||
... | ... | ||
=== Custom Update Functions === | ==== Custom Update Functions ==== | ||
We now have a function that will be called when our variables are loaded. | We now have a function that will be called when our variables are loaded. | ||
| Line 217: | Line 218: | ||
... | ... | ||
= Making your config frame = | == Making your config frame == | ||
Now that your mod is using your SavedVariable, and is both loading it's settings from it (or using the defaults), you need a configuration frame to allow users to modify their settings! There are many popular ways of doing this, you can create slash commands (learn more at [[HOWTO: Create a Slash Command]]), a right click menu, but for now we will stay simple, and just have a frame popup when you use myAddons to display the options. | Now that your mod is using your SavedVariable, and is both loading it's settings from it (or using the defaults), you need a configuration frame to allow users to modify their settings! There are many popular ways of doing this, you can create slash commands (learn more at [[HOWTO: Create a Slash Command]]), a right click menu, but for now we will stay simple, and just have a frame popup when you use myAddons to display the options. | ||
From inside the game, you can hit the 'ESCAPE' key and chose the 'Addons' item to have myAddons open. From there you can click on the name for your addon, and then click the 'Options' button on the bottom right. But it won't open your options right now, because you haven't made the frame yet! | From inside the game, you can hit the 'ESCAPE' key and chose the 'Addons' item to have myAddons open. From there you can click on the name for your addon, and then click the 'Options' button on the bottom right. But it won't open your options right now, because you haven't made the frame yet! | ||
== config frame .xml == | === config frame .xml === | ||
=== Basic Frame with Backdrop === | ==== Basic Frame with Backdrop ==== | ||
Let's flesh out a basic config frame: | Let's flesh out a basic config frame: | ||
| Line 280: | Line 281: | ||
... | ... | ||
=== Adding Close and Default Buttons === | ==== Adding Close and Default Buttons ==== | ||
That should make a small title box appear, and you'll notice the FontString's text attribute is set to "Clock Config" -- you can change this to anything you want. If you're doing [[localization (ui)]], maybe even a constant! You might notice that once you display your config frame, there's no way to get rid of it! Let's fix that right away by adding a `Close' button: | That should make a small title box appear, and you'll notice the FontString's text attribute is set to "Clock Config" -- you can change this to anything you want. If you're doing [[localization (ui)]], maybe even a constant! You might notice that once you display your config frame, there's no way to get rid of it! Let's fix that right away by adding a `Close' button: | ||
| Line 334: | Line 335: | ||
You'll notice all we really had to do here was call our ConfigToDefault function we made in 'myClockIndicatorFrame.lua' -- it will take care of updating our addon for us! Now we should be able to undo any damage should we mess around with our mod's config settings. | You'll notice all we really had to do here was call our ConfigToDefault function we made in 'myClockIndicatorFrame.lua' -- it will take care of updating our addon for us! Now we should be able to undo any damage should we mess around with our mod's config settings. | ||
=== Checkboxes and Sliders === | ==== Checkboxes and Sliders ==== | ||
With most of the graphical frame stuff out of the way, it's time to add our checkboxes, and a slider for the offset (Dropdown menus are a lot more complicated, so this HOWTO won't be covering that). | With most of the graphical frame stuff out of the way, it's time to add our checkboxes, and a slider for the offset (Dropdown menus are a lot more complicated, so this HOWTO won't be covering that). | ||
| Line 407: | Line 408: | ||
You'll again notice that we're using the Anchor relativeTo on the last checkbox, which will be $parentCheckButtonTime24. We're again dynamically getting the FontStrings that WoW will create for us, like the 'Text' one set to "Offset". As well, because this is a slider, we have "High" and "Low" FontStrings, have to set the minimum and maximum values the slider has, and how many values are added or subtracted when you move the slider. What will most surprise you is that.. yes... we can still use that option function for our slider too! One function for all the basic config options! | You'll again notice that we're using the Anchor relativeTo on the last checkbox, which will be $parentCheckButtonTime24. We're again dynamically getting the FontStrings that WoW will create for us, like the 'Text' one set to "Offset". As well, because this is a slider, we have "High" and "Low" FontStrings, have to set the minimum and maximum values the slider has, and how many values are added or subtracted when you move the slider. What will most surprise you is that.. yes... we can still use that option function for our slider too! One function for all the basic config options! | ||
=== Frame Scripts === | ==== Frame Scripts ==== | ||
It's also important that all our current settings are loaded into our config frame, and since they might change when we use a slash command or something, the best way would be to use a OnShow event. | It's also important that all our current settings are loaded into our config frame, and since they might change when we use a slash command or something, the best way would be to use a OnShow event. | ||
| Line 423: | Line 424: | ||
== config frame .lua == | === config frame .lua === | ||
Our lua file for the config frame then breaks down into just 2 functions, one for when the frame is shown, the other for when an option in the config frame (like a checkbox, or a slider is moved) changes. | Our lua file for the config frame then breaks down into just 2 functions, one for when the frame is shown, the other for when an option in the config frame (like a checkbox, or a slider is moved) changes. | ||
| Line 470: | Line 471: | ||
Alternatively you could leave out the 'myClock_ConfigChange();' of this function, and add it to the Done button OnClick event to make a Save/Cancel dialog. Generally speaking for a config people want to see the changes happen live so they can tweak them. | Alternatively you could leave out the 'myClock_ConfigChange();' of this function, and add it to the Done button OnClick event to make a Save/Cancel dialog. Generally speaking for a config people want to see the changes happen live so they can tweak them. | ||
You're done! Hopefully this provided some concrete examples on how to make a config dialog, and much thanks to Scheid for being the ginipig! You could easily go from here to make a more complex configuration pane, using tabs, multiple pages, or even using Cosmos' Khaos (another howto someday). | You're done! Hopefully this provided some concrete examples on how to make a config dialog, and much thanks to Scheid for being the ginipig! You could easily go from here to make a more complex configuration pane, using tabs, multiple pages, or even using Cosmos' Khaos (another howto someday). | ||
[[Category:HOWTOs|Create GUI Config Options]] | [[Category:HOWTOs|Create GUI Config Options]] | ||