Thread Tools Display Modes
10-12-11, 08:00 AM   #1
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Few XML/LUA questions

Hello,

I have few questions I gathered, which I couldn't find answers to. I hope someone here will be able to assist me

1. I want to use local functions properly, in order to save memory.
If I'm declaring a local frame and having all my functions declared as myFrame:myFunc(), will they be local as well? Is it a good practice for saving memory?

2. I want to make a dropdown checkbutton list, which will have only one valid option at a time. Meaning, when I choose an option, the previous option will be unchecked. So I though of doing so using the initialize function, setting the "checked" flag. However, it seems to be updated only when I close and open the dropdown list. Until then, I get more than one option selected. How can I make a dropdown with one selected option which is not closed when selecting an option? I managed do both separately, but not together...

3. The dropdown list has a text that I can set using "UIDropDownMenu_SetText". How can I set the font and font size of this text? I coudn't find any function to do so.

Thanks in advance!
  Reply With Quote
10-12-11, 08:41 AM   #2
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
Originally Posted by Animor View Post
Hello,

I have few questions I gathered, which I couldn't find answers to. I hope someone here will be able to assist me

1. I want to use local functions properly, in order to save memory.
If I'm declaring a local frame and having all my functions declared as myFrame:myFunc(), will they be local as well? Is it a good practice for saving memory?

2. I want to make a dropdown checkbutton list, which will have only one valid option at a time. Meaning, when I choose an option, the previous option will be unchecked. So I though of doing so using the initialize function, setting the "checked" flag. However, it seems to be updated only when I close and open the dropdown list. Until then, I get more than one option selected. How can I make a dropdown with one selected option which is not closed when selecting an option? I managed do both separately, but not together...
1. It has nothing to do with "saving memory", since your function will use memory, regardless of being local or not. It is a matter of "good programming style" and scope. You don't want to use a global (not local) loop-variable i, cause many programmers do it and you will taint each other, if it is not local (or might taint, at least).
And yes, creating functions as the child of a local frame will make them local aswell, technically.

2. Just write a custom functions to uncheck all other options.
__________________
  Reply With Quote
10-12-11, 12:28 PM   #3
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Thank you for you answer.

1. I've encountered an issue trying to call myFrame:Myfunc() from within XML onLoad script of a parent xmlframe (a different frame). It did work ok for a check-button onClick script, though. Something I'm missing here?

2. I couldn't find a way to access the buttons and uncheck them from a function that is not the initialize function. How can I access them and modify the checked field?
  Reply With Quote
10-12-11, 03:45 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Originally Posted by Mischback View Post
... You don't want to use a global (not local) loop-variable i, cause many programmers do it and you will taint each other, if it is not local (or might taint, at least). ...
This depends on which loop statement you use. Each one has their tricks and specific uses.


Code:
while condition do
-- Loop code here
end
condition is checked at the beginning of each loop and is outside the scope of the loop. Locals inside the loop won't be used.

Code:
repeat
-- Loop code here
until condition
condition is checked after each loop and is contained inside the scope of the loop. Locals inside the loop are used.

Code:
for i=1,10 do
-- Loop code here
end
i is created as a local inside the scope of the loop. Conditions are checked at the beginning of the loop.





Originally Posted by Animor View Post
1. I've encountered an issue trying to call myFrame:Myfunc() from within XML onLoad script of a parent xmlframe (a different frame). It did work ok for a check-button onClick script, though. Something I'm missing here?

2. I couldn't find a way to access the buttons and uncheck them from a function that is not the initialize function. How can I access them and modify the checked field?
Frames defined in XML need to either have a name that places them in a global variable sharing the same name or have the parentKey attribute set so it can be accessed through its parent.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-12-11, 11:49 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Animor View Post
3. The dropdown list has a text that I can set using "UIDropDownMenu_SetText". How can I set the font and font size of this text? I coudn't find any function to do so.
There is no API for changing the font of dropdown menu buttons. You would need to study Blizzard's template code to learn the structure of the buttons and how to programatically identify which buttons are being displayed on an open menu. Then, each time your dropdown was shown, you would need to change the font of all of the buttons being displayed on it, and each time your dropdown was hidden, you would need to reset the fonts for all of those buttons (otherwise your font changes will show up randomly in other dropdowns, since addons that do not change the fonts will not expect to have to change it back).

You may be better off writing your own dropdown menu widget; that's what I did for my addons where I wanted to have scrollable dropdown menus, or custom fonts/textures in the dropdown menu. See my addon oUF_Phanx for examples if you're interested.
  Reply With Quote
10-14-11, 03:14 PM   #6
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Thanks

Perhaps there is a common lib for dropdown list with more control? I don't want to write that myself, will take me too long I'm afraid.

Does someone know the answer to my other question, about choosing from dropdown list while keeping it open?
  Reply With Quote
10-14-11, 03:30 PM   #7
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Originally Posted by Animor View Post
Thanks

Perhaps there is a common lib for dropdown list with more control? I don't want to write that myself, will take me too long I'm afraid.

Does someone know the answer to my other question, about choosing from dropdown list while keeping it open?
The keepShownOnClick arg will allow that.

http://www.wowwiki.com/UI_Object_UID...The_info_table
  Reply With Quote
10-14-11, 04:38 PM   #8
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Xinhuan has written a good guide for using UIDropDownMenus.
__________________
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
10-14-11, 08:39 PM   #9
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Originally Posted by Nibelheim View Post
The keepShownOnClick arg will allow that.

http://www.wowwiki.com/UI_Object_UID...The_info_table
I've read that, and I've also read the link that Torhal gave. keepShownOnClick is the way to keep the list open. but as I wrote at my original post, the problem is not keeping it open. The problem is unchecking all but one option while the list remains open.
  Reply With Quote
10-14-11, 09:25 PM   #10
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Originally Posted by Animor View Post
I've read that, and I've also read the link that Torhal gave. keepShownOnClick is the way to keep the list open. but as I wrote at my original post, the problem is not keeping it open. The problem is unchecking all but one option while the list remains open.
Ahh. Not sure if it can be done. Might have to make your own DropDownMenu.
  Reply With Quote
10-15-11, 02:42 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I'm pretty sure that standard dropdown menus only let you have one thing selected at a time by default. They definitely work that way in any addon I've used them in. Without seeing your code, though, there's not much else I can tell you.
  Reply With Quote
10-16-11, 01:42 AM   #12
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Originally Posted by Phanx View Post
I'm pretty sure that standard dropdown menus only let you have one thing selected at a time by default. They definitely work that way in any addon I've used them in. Without seeing your code, though, there's not much else I can tell you.
The reason it works like that at any addon is that the list is always closed when you select an option. Any anyway, this is not done by default, you have to uncheck it in the initialize function. By default, you can check more than one item, which is the behavior of some of the dropdown lists.

What I'm trying to do is uncheck other not selected items while the list remains open. I don't know how to access the other options and do that other than through the initialize function.
  Reply With Quote
10-16-11, 02:17 AM   #13
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Originally Posted by Animor View Post
The reason it works like that at any addon is that the list is always closed when you select an option. Any anyway, this is not done by default, you have to uncheck it in the initialize function. By default, you can check more than one item, which is the behavior of some of the dropdown lists.

What I'm trying to do is uncheck other not selected items while the list remains open. I don't know how to access the other options and do that other than through the initialize function.
So, basically something like the Minimap tracking menu? Might be some hints in that code.

Lua Code:
  1. function MiniMapTracking_Update()
  2.     UIDropDownMenu_Refresh(MiniMapTrackingDropDown);
  3. end
  4.  
  5. function MiniMapTrackingDropDown_OnLoad(self)
  6.     UIDropDownMenu_Initialize(self, MiniMapTrackingDropDown_Initialize, "MENU");
  7.     self.noResize = true;
  8. end
  9.  
  10. function MiniMapTracking_SetTracking (self, id, unused, on)
  11.     SetTracking(id, on);
  12.     UIDropDownMenu_Refresh(MiniMapTrackingDropDown);
  13. end
  14.  
  15. function MiniMapTrackingDropDownButton_IsActive(button)
  16.     local name, texture, active, category = GetTrackingInfo(button.arg1);
  17.     return active;
  18. end
  19.  
  20. function MiniMapTrackingDropDown_IsNoTrackingActive()
  21.     local name, texture, active, category;
  22.     local count = GetNumTrackingTypes();
  23.     for id=1, count do
  24.         name, texture, active, category  = GetTrackingInfo(id);
  25.         if (active) then
  26.             return false;
  27.         end
  28.     end
  29.     return true;
  30. end
  31.  
  32. function MiniMapTrackingDropDown_Initialize()
  33.     local name, texture, active, category;
  34.     local count = GetNumTrackingTypes();
  35.     local info;
  36.    
  37.     info = UIDropDownMenu_CreateInfo();
  38.     info.text=MINIMAP_TRACKING_NONE;
  39.     info.checked = MiniMapTrackingDropDown_IsNoTrackingActive;
  40.     info.func = ClearAllTracking;
  41.     info.icon = nil;
  42.     info.arg1 = nil;
  43.     info.isNotRadio = true;
  44.     info.keepShownOnClick = true;
  45.     UIDropDownMenu_AddButton(info);
  46.    
  47.     for id=1, count do
  48.         name, texture, active, category  = GetTrackingInfo(id);
  49.  
  50.         info = UIDropDownMenu_CreateInfo();
  51.         info.text = name;
  52.         info.checked = MiniMapTrackingDropDownButton_IsActive;
  53.         info.func = MiniMapTracking_SetTracking;
  54.         info.icon = texture;
  55.         info.arg1 = id;
  56.         info.isNotRadio = true;
  57.         info.keepShownOnClick = true;
  58.         if ( category == "spell" ) then
  59.             info.tCoordLeft = 0.0625;
  60.             info.tCoordRight = 0.9;
  61.             info.tCoordTop = 0.0625;
  62.             info.tCoordBottom = 0.9;
  63.         else
  64.             info.tCoordLeft = 0;
  65.             info.tCoordRight = 1;
  66.             info.tCoordTop = 0;
  67.             info.tCoordBottom = 1;
  68.         end
  69.         UIDropDownMenu_AddButton(info);
  70.     end
  71. end
  Reply With Quote
10-16-11, 04:47 AM   #14
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Yes, but in the Minimap tracking menu, you can select more than one option.
Meaning, when you select an option the other selected options remain selected.

I want to unselect/uncheck them while keeping the list open. So only one option will be selected at any time.
  Reply With Quote
10-16-11, 05:19 AM   #15
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Ok, I went over the minimap code and I've found something similar to what I want to accomplish: the first option is "None" and when you click it, all other selections are unchecked while the list remains open!
The function is info.func = ClearAllTracking

But I couldn't find "ClearAllTracking" anywhere.
Do you know where can I find it?
  Reply With Quote
10-16-11, 07:54 AM   #16
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by Animor View Post
The function is info.func = ClearAllTracking

But I couldn't find "ClearAllTracking" anywhere.
Do you know where can I find it?
I just did a search-in-files for it, and that was the only instance of ClearAllTracking that showed up

So afaik that function is defined in Blizzard's C back-end code, sorry

Last edited by Ketho : 10-16-11 at 03:50 PM.
  Reply With Quote
10-16-11, 11:04 AM   #17
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Hmm, might be able to just define your own table. Example:

Lua Code:
  1. local MyVals = {}
  2.  
  3. function MiniMapTracking_SetTracking (self, id, on)
  4.     wipe(MyVals)
  5.     MyVals[id] = on
  6.     UIDropDownMenu_Refresh(MyDropDown);
  7. end
  8.  
  9. function MiniMapTrackingDropDownButton_IsActive(button)
  10.     return MyVals[button.arg1];
  11. end
  Reply With Quote
10-17-11, 07:15 AM   #18
SaraFdS
A Fallenroot Satyr
 
SaraFdS's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 24
Originally Posted by Animor View Post
2. I want to make a dropdown checkbutton list, which will have only one valid option at a time. Meaning, when I choose an option, the previous option will be unchecked. So I though of doing so using the initialize function, setting the "checked" flag. However, it seems to be updated only when I close and open the dropdown list. Until then, I get more than one option selected. How can I make a dropdown with one selected option which is not closed when selecting an option? I managed do both separately, but not together...
Isn't it as simple as combining
Code:
isNotRadio = false
and
Code:
keepShownOnClick = true
?
__________________
Sará the Insane
  Reply With Quote
10-17-11, 09:14 AM   #19
Animor
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Mar 2011
Posts: 136
Unfortunately, no...
and btw, isNotRadio = false is the default.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Few XML/LUA questions

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