Thread Tools Display Modes
04/08/14, 07:53 PM   #1
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Hmm... I am able to get the font to change with only
Lua Code:
  1. dropdown:SetFont("ZoFontBookPaper")
Attached Thumbnails
Click image for larger version

Name:	Capture.PNG
Views:	685
Size:	378.4 KB
ID:	112  
  Reply With Quote
04/08/14, 08:40 PM   #2
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Hmm, guess ZoFontGameLarge isn't that much larger than ZoFontGame rofl. I probably didn't notice the difference.

I added another combo box with a selection of built in fonts listed in Zgoo, not figured out whether there is a way to set the font per option but probably not a good idea seeing as it seems to be using the same font for the whole control.

I adjusted my combo box function to add an option callback function and in the OnSelect function I return the font selected to the callback function so that it can use it and I told it to change the font for the dropdowns of the combo boxes. It changes the selected font to the same font as well.

Some don't look much different but some of them you can definitely see the change.

SetResizeToFitDescendents don't seem to work unless I am expecting it to do something different at the wrong time.

Anyway,

Function header line was changed to
Lua Code:
  1. local function CreateDropDown(name,parent,data,selected,callback)
And the OnSelect function was changed to
Lua Code:
  1. combo.dropdown.OnSelect = function(self,value)
  2.     self:SetSelectedItem(value)
  3.     if callback then callback(value) end
  4. end
The call to this function changed to ..
Lua Code:
  1. Fonts = CreateDropDown("Fonts",testTLW,choices3,"ZoFontGame",function(value) UseFont(value) end)
And that callback function
Lua Code:
  1. local function UseFont(fontName)
  2.     Fonts.dropdown:SetFont(fontName)
  3.     GreekAlphabet.dropdown:SetFont(fontName)
  4.     Weekdays.dropdown:SetFont(fontName)
  5. end

Picture showing what it looks like now. Just did a quick test to see if you can turn off the names but nada .. so even though the variables are local the frames/windows still have global names .. which is a pity.
Attached Thumbnails
Click image for larger version

Name:	Screenshot_20140409_033706.jpg
Views:	704
Size:	406.5 KB
ID:	113  
  Reply With Quote
04/09/14, 03:07 AM   #3
Shinni
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 167
I tried using lua instead of xml but i must have done something wrong:

Lua Code:
  1. local control = WINDOW_MANAGER:CreateTopLevelWindow("TestTopLevel")
  2. control:SetHandler("OnUpdate", function() d(123) end )

the OnUpdate function doesn't seem to be called...

edit:
function(self, time)
doesnt work as well

edit2:
Lua Code:
  1. local b = WINDOW_MANAGER:CreateControlFromVirtual("asd", GuiRoot, "ZO_StatsDropdownRow")
  2. local a = WINDOW_MANAGER:CreateControl("asd2", GuiRoot, CT_CONTROL )
  3. b:SetHandler("OnUpdate", function(...) d(123) end )
  4. a:SetHandler("OnUpdate", function(...) d(456) end )
hmm the control from CreateControlFromVirtual works, but the other one doesn't...

Last edited by Shinni : 04/09/14 at 04:11 AM.
  Reply With Quote
04/09/14, 05:06 AM   #4
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Ah, so that's why sometimes OnUpdate has been working for some people from Lua and other times not. Good find Shinni.
  Reply With Quote
04/09/14, 12:40 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
I think I (or someone else?) have mentioned this "bug" before - it was noticed during Beta. When creating a control from scratch, the OnUpdate handler is missing. You need to set it in XML or use a template that already has it set.
  Reply With Quote
04/09/14, 12:42 PM   #6
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Originally Posted by Seerah View Post
I think I (or someone else?) have mentioned this "bug" before - it was noticed during Beta. When creating a control from scratch, the OnUpdate handler is missing. You need to set it in XML or use a template that already has it set.
Ah, I know it was suggested to use the XML to get the OnUpdate routine working but I never knew the reason for it not working.

Thanks Seerah.
  Reply With Quote
04/10/14, 09:51 AM   #7
Stormknight
 
Stormknight's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 128
Posting this here as it may help someone else.

I was getting odd "attempt to index a nil value" message on loading from my add-on, from a line in the OnUpdate() function.

The reason it was happening is because I have the <OnUpdate> declared within the XML and it was firing before my add-on had completed it's initialisation, which included loading saved variables.

So, the OnUpdate() function was trying to access a saved variable that hadn't been loaded yet.

I resolved this by simply creating an initialised variable in my add-on.

Code:
MyAddon = ()
MyAddon.initialised = false
MyAddon.name = "MyAddon"

function MyAddon.OnUpdate()
    -- Bail if we haven't completed the initialisation routine yet.
    if (not MyAddon.initialised) then return end
    -- code I wanted to execute here
end

function MyAddon.Initialise(eventCode, addOnName)
    -- Only initialize our own addon
    if (MyAddon.name ~= addOnName) then return end
    -- Do my initialisation tasks here, including loading saved variables etc
    MyAddon.initialised = true
end

EVENT_MANAGER:RegisterForEvent("MyAddon", EVENT_ADD_ON_LOADED, MyAddon.Initialise)
with the XML being something like
Code:
<GuiXml>
    <Controls>
        <TopLevelControl name="MyAddon" mouseEnabled="true" movable="true" clampedToScreen="true">
            <Dimensions x="200" y="200" />
            <OnUpdate>
                MyAddon.OnUpdate()
            </OnUpdate>
        </TopLevelControl>
    </Controls>
</GuiXml>
  Reply With Quote
05/11/14, 02:17 PM   #8
Klingo
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 16
Originally Posted by Shinni View Post
Lua Code:
  1. local b = WINDOW_MANAGER:CreateControlFromVirtual("asd", GuiRoot, "ZO_StatsDropdownRow")
  2. local a = WINDOW_MANAGER:CreateControl("asd2", GuiRoot, CT_CONTROL )
  3. b:SetHandler("OnUpdate", function(...) d(123) end )
  4. a:SetHandler("OnUpdate", function(...) d(456) end )
hmm the control from CreateControlFromVirtual works, but the other one doesn't...
Is there a difference between CreateControl and CreateControlFromVirtual?
  Reply With Quote
05/11/14, 03:13 PM   #9
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Outside of the fact you use the virtual one when inheriting from a template control, nothing. Of course the template control may have had it's own update function set up in it's initialisation. Most likely from within XML which is where we usually have to do it.

Although I seemed to have missed Shinni's post. But not sure if that would have resolved my problem as it is usually the top level control that has the update routine set up in it.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » XML vs Lua for GUI Best Practices


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