Thread Tools Display Modes
07-29-08, 10:50 AM   #1
Jashoo
A Deviate Faerie Dragon
 
Jashoo's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 12
Setting current value on initial DropDown button

Hi All,

I'm working on a dropdown option that selects from a series of themes based on a SavedVariable.

When the GUI pops up the dropdown menu display no value. And it's only when you've selected your option that it will display. I can screen shot it when I get home if it will help.

What I'd like to do is when the GUI loads, display the current theme in the dropdown menu before clicking the dropdown button.

here is the code below.

XML file
Code:
<Button name="dropdown" inherits="UIDropDownMenuTemplate">
                <Size>
                    <AbsDimension x="48" y="24"/>
                </Size>
                <Anchors>
                    <Anchor point="TOPLEFT">
                        <Offset><AbsDimension x="30" y="-150"/></Offset>
                    </Anchor>
                </Anchors>
                <Scripts>
                    <OnShow>
                        UIDropDownMenu_Initialize( this, DropDownInitialize );
                    </OnShow>
                </Scripts>
            </Button>
LUA file
Code:
function DropDownInitialize()
        local entry = { func = DropDownOnClick; }
        for i=1,table.getn(CAA_AUDIO_PACK) do  -- CAA_AUDIO_PACK is an array of themes
                entry.text = CAA_AUDIO_PACK[i];
                entry.value = i;
                if (UIDropDownMenu_GetSelectedValue(dropdown) == entry.value) then
                        entry.checked = true
                else
                        entry.checked = nil
                end
                UIDropDownMenu_AddButton(entry)
        end
end

function DropDownOnClick()
        UIDropDownMenu_SetSelectedID( dropdown, this:GetID() );
        caa_set_pack = CAA_AUDIO_PACK[this:GetID()];
        setpack = CAA_AUDIO_PACK[this:GetID()];
        audiopath = "Interface\\AddOns\\CAA\\audio\\"..CAA_AUDIO_PACK[this:GetID()].."\\";
        AddMsg("Setting Theme:"..audiopath);
end
Any help would be greatly appreciated!

J.
  Reply With Quote
07-29-08, 01:53 PM   #2
Jashoo
A Deviate Faerie Dragon
 
Jashoo's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 12
Code:
if (UIDropDownMenu_GetSelectedValue(dropdown) == entry.value) then
    entry.checked = true
else
    entry.checked = nil
end
So I think it's in this statement. I'm still at work right now so I can't test this till I get home. But I think if I change UIDropDownMenu_GetSelectedValue(dropdown) to caa_set_pack that it will initialize the dropdown box checked to the caa_set_pack variable, which is the current setting variable.

Code:
if (caa_set_pack == entry.value) then
    entry.checked = true
else
    entry.checked = nil
end

isn't this fun?
__________________
Won't you look at me
I'm crazy
But I get the job done
Yeah I'm crazy
But I get the job done
  Reply With Quote
07-29-08, 02:42 PM   #3
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
i didn't actually look through all the code in your first post 'cause i'm lazy, but i think what you want is:

UIDropDownMenu_SetSelectedValue(dropdown, caa_set_pack)

also btw, it's not generally a good idea to call a global something as generic as "dropdown." you might want to rename that.

edit: you want that code to run after the ADDON_LOADED event fires for your addon (or VARIABLES_LOADED fires); otherwise caa_set_pack won't exist yet. OnShow works for this as well as an event handler does, but only if the dropdown starts out hidden.

Last edited by Akryn : 07-29-08 at 02:46 PM.
  Reply With Quote
07-29-08, 05:26 PM   #4
Jashoo
A Deviate Faerie Dragon
 
Jashoo's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 12
Thank you for your help Akryn. Unfortunately it didn't work. I will look at that more closely though than just copy/pasting

The variables and settings are all loaded properly. It's just how to make the GUI dropdown to display the current variable on the initial "onshow"

Here are some screenshots.

1. GUI opens up. Notice no value in dropdown. This is where the problem is.
I want the current variable to display there.


2. DropDown displays the options with the current value checked off


3. Highlight and switch value to Default


4. Now the value is displayed on the dropdown



I can't find the library functions for the UIDropDownMenuTemplate. I think Akryn is correct about SetValue but I can't seem to get it to work properly.

Again thank you Akryn. I will continue to pick at this
__________________
Won't you look at me
I'm crazy
But I get the job done
Yeah I'm crazy
But I get the job done
  Reply With Quote
07-29-08, 05:40 PM   #5
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
this should work, assuming the value of caa_set_pack is one of the values in the menu:

Code:
<OnShow>
     UIDropDownMenu_Initialize(self, DropDownInitialize)
     UIDropDownMenu_SetSelectedValue(self, caa_set_pack)
</OnShow>
("this" is being removed in 3.0, so it's good to start using "self" now )

you can also just set the fontstring itself's text, which is useful if you want it to display something other than the menu text:

Code:
<OnShow>
     UIDropDownMenu_Initialize(self, DropDownInitialize)
     UIDropDownMenu_SetSelectedValue(self, caa_set_pack)
     _G[self:GetName().."Text"]:SetText("Something")
</OnShow>
  Reply With Quote
07-29-08, 05:59 PM   #6
Jashoo
A Deviate Faerie Dragon
 
Jashoo's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 12
Akryn you rock!

I just SetText to caa_set_pack

Code:
<OnShow>
     UIDropDownMenu_Initialize(self, DropDownInitialize)
     _G[self:GetName().."Text"]:SetText(caa_set_pack)
</OnShow>
So it loads the caa_set_pack value onshow.

Thank you so much!

I will convert all the this to self as well
__________________
Won't you look at me
I'm crazy
But I get the job done
Yeah I'm crazy
But I get the job done
  Reply With Quote
08-02-08, 06:26 PM   #7
Demonhak88
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 3
Thank you for all the information in this thread it helped me learn something i needed for my mod =)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Setting current value on initial DropDown button


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