Thread Tools Display Modes
04/03/14, 06:19 AM   #1
Wukar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 27
Adding elements to existing UI elements

Hi there,

after walking through the very basic addon tutorial, i come up with more questions than answers. I am familiar with Lua in a way from my studies. But i definetly lack the knowledge to interact with the ESO UI.

I want to extend inventory and bank windows with a crafting-profession filter as well as a editbox for a full-text search. Well, the events aren't the problem. Adding the elements to the proper control is. On top of it: is there a predefined editBox (doesn't look like that) ?

I tried to skip that problem with the usage of the library LibAddonMenu-1.0:
Code:
LAM:AddEditBox(ZO_PlayerInventoryBackpack, "bbs_search", "filter inventory", "custom tooltip", false, getFunc(), setFunc())
But the LibAddon itself complains about the optionsWindow variable which is set at the beginning to:
Code:
local optionsWindow = ZO_OptionsWindowSettingsScrollChild
Thanks for your time ;-)
  Reply With Quote
04/03/14, 04:28 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
From the description:
LibAddonMenu-1.0 is a library to aid addon authors in creating a configuration GUI for their addons which is located in the game's Settings menu.
LAM doesn't do what you think it does.
  Reply With Quote
04/03/14, 07:12 PM   #3
Wukar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 27
*self-facepalm* configuration gui - got it

But the UI elment question remains.
  Reply With Quote
04/03/14, 08:35 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Look to see how LAM creates the editbox. (Hint: I used a template from the default UI )
  Reply With Quote
04/04/14, 07:42 AM   #5
Cr4x
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 11
Easiest way to achive your goal is to install zgoo and try to figure out which is the head control of the tabs.

type /zgoo mouse while you are on any filter button and have a look at his parent
Should be something like ZO_PlayerInventoryFilterTab or so

now have a look at the wiki example to dynamicly adding some controls to another.

That should be enough to make it. if you need a complete soloutin and dont want to learn from it (i totally advice! you to do it by yourself), reply on my post and wait until i got time for it *lol*

Cheers
  Reply With Quote
04/04/14, 01:18 PM   #6
Wukar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 27
Thanks for the hints. I hate direct solutions and prefer learning by doing
  Reply With Quote
04/05/14, 11:42 AM   #7
Wukar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 27
Ok, raised an UI error previously - messed up syntax. But now i see neither an error, nor an added editbox...

Code:
function BBS_Initialize()
	local backpack = ZO_PlayerInventoryBackpack
	local wm = WINDOW_MANAGER
	local inv = ZO_PlayerInventory

	local editbox = wm:CreateControl("BBS_ToplevelTest", inv, CT_EDITBOX)
	editbox:SetParent(inv)
	editbox:SetAnchor(TOPLEFT, inv, TOPLEFT, 0, 10)
	editbox:SetResizeToFitDescendents(true)
	editbox:SetWidth(510)
	editbox:SetMouseEnabled(true)
end


-- Hook initialization onto the EVENT_ADD_ON_LOADED listener
EVENT_MANAGER:RegisterForEvent(EVENT_ADD_ON_LOADED, BBS_Initialize())

Last edited by Wukar : 04/05/14 at 11:52 AM. Reason: Fixed event registration
  Reply With Quote
04/05/14, 12:28 PM   #8
Wukar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 27
So, the CreateControl doesn't seem to create a visual UI element, or should it?

When is either or used? Couldn't find a list of valid virtual names.
Code:
     CreateControl(string arg1, object parent, integer type)
        Returns: object apRet 

    CreateControlFromVirtual(string controlName, object parent, string virtualName)
        Returns: object apRet
Sigh, just the API is not too helpful ;-)
  Reply With Quote
04/05/14, 01:55 PM   #9
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
1. Unless you need to access this function from another file, make it local.
Lua Code:
  1. local function BBS_Initialize()

2. Only put your function name in the event handler. You want a reference for what to call when the event fires. Not what the function actually returns (which is, in this case, nil).

3. You need to tell the EVENT_MANAGER what is registering for this event. So the first argument is going to be a unique string for your addon. (The alternative is to register the event directly on a frame/control in your addon and skipping the event manager completely.)

4. EVENT_ADD_ON_LOADED fires for every addon that loads. You want to run your code if it's only your addon. Not 10 times for each addon that loads. Use either of the below.
Lua Code:
  1. EVENT_MANAGER:RegisterForEvent(EVENT_ADD_ON_LOADED, function(event, addon
  2.      if addon == "MyAddonName" then
  3.           BBS_Initialize()
  4.      end
  5. end)
[highlight="Lua"]local function BBS_Initialize(event, addon)
if addon == "MyAddonName" then[
--do all the things
end
end/highlight]

4. You created an edit box, but you did not give it a height or say how it should look or anything else. As I mentioned above, I used a template so I didn't have to create it from scratch.


/edit: re-read these two parts of the Addon Quick Questions section of the wiki:
http://wiki.esoui.com/AddOn_Quick_Qu...events_work.3F
http://wiki.esoui.com/AddOn_Quick_Qu...s_or_labels.3F
  Reply With Quote
04/05/14, 02:15 PM   #10
Wukar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 27
Thanks for your effort in helping me

Nice hint with the ADD_ON_LOADED_EVENT. Thought it was possible but not sure of it.

Yeah, suddenly noticed copying the following was not a good idea
lua Code:
  1. editbox:SetResizeToFitDescendents(true)

I played around with zgoo a bit and tried to analyse the guild filter search box. The controls are structured CT_BACKDROP > CT_EDITBOX > CT_LABEL. I now wonder why the CT_LABEL is used as a child of CT_EDITBOX. Is it just because of a default text if the editbox value is (empty) - would make sense
  Reply With Quote
04/05/14, 03:33 PM   #11
Wukar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 27
Now i am stuck with setting appropriate handlers. Is there a list of valid and fireing events for controls? OnKeyup as well as Onclicked or OnFocus is not working.

lua Code:
  1. local function BBS_OnFocusLost(editbox, label)
  2.     label:SetHidden(editbox:GetText() ~= "")
  3. end
  4.  
  5. local function BBS_OnKeyUp(editbox, label)
  6.     label:SetHidden(editbox:GetText():len() > 0)
  7. end
  8.  
  9. editbox:SetHandler("OnKeyUp", function(self) BBS_OnKeyUp(self, label) end)
  10. editbox:SetHandler("OnFocusLost", function(self) BBS_OnFocusLost(self, label) end)
  Reply With Quote
04/05/14, 09:52 PM   #12
Lyrael
Join Date: Apr 2014
Posts: 2
Not sure how to add a filter as I found this trying to figure that out myself.

There is however an existing search box in the game, there's just no non-script way of showing it (AFAIK).

/script ZO_PlayerInventorySearchBox:ToggleHidden() will toggle its visibility.
  Reply With Quote
04/05/14, 10:35 PM   #13
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 648
Yeah, I came across stuff referencing that last night but didn't look too much into it. Nice find.
  Reply With Quote
04/06/14, 04:07 AM   #14
Cr4x
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 11
Originally Posted by Wukar View Post
Now i am stuck with setting appropriate handlers. Is there a list of valid and fireing events for controls? OnKeyup as well as Onclicked or OnFocus is not working.

lua Code:
  1. local function BBS_OnFocusLost(editbox, label)
  2.     label:SetHidden(editbox:GetText() ~= "")
  3. end
  4.  
  5. local function BBS_OnKeyUp(editbox, label)
  6.     label:SetHidden(editbox:GetText():len() > 0)
  7. end
  8.  
  9. editbox:SetHandler("OnKeyUp", function(self) BBS_OnKeyUp(self, label) end)
  10. editbox:SetHandler("OnFocusLost", function(self) BBS_OnFocusLost(self, label) end)
wiki.esoui.com/UI_XML

Use zgoo to inspect which type of control you want to handle, head to the specific section and looks what it has of attributes additional childs and ofc which events (OnEvent). The most Controls inherits from Control which also have OnEvents so this is the overview you requested.

Originally Posted by Lyrael View Post
Not sure how to add a filter as I found this trying to figure that out myself.

There is however an existing search box in the game, there's just no non-script way of showing it (AFAIK).

/script ZO_PlayerInventorySearchBox:ToggleHidden() will toggle its visibility.
The search bar is working but, as you said, not there . I already figured that out too and was wondering why ZO isnt showing it . However if you want to add a filter, you may check the ZO_InventoryManager even the data sets of the different filters
  Reply With Quote
04/06/14, 06:56 AM   #15
Wukar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 27
Thanks for the event list, really helped out. Only thing i miss now, is how to capture events for closing/opening bank/inventory/guildbank.

I came across that InventorySearchBox, too, but was thinking it is for internal use only.

After showing it with :SetHidden(false), i first tried to reposition it with :SetParent(ZO_SharedRightPanelBackgroundLeft). But, strangely, changing its size with :SetDimensions(x, y) has no effect. :SetResizeToFitDescendents(false) has no effect, too.

God, why do easy considerations last that long to implement? Horrible, like looking for a needle in a haystack.
  Reply With Quote
04/06/14, 07:33 AM   #16
Cr4x
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 11
You can capture such events with :SetHandler("OnShow", MyAddOnFunctionOnShow)

However you need to set the handler to a toplevel window cause thats usually the only one wich is shown or hided.

So ZO_PlayerInventory:SetHandler("OnShow", MyFunction)
  Reply With Quote
04/06/14, 09:09 AM   #17
Wukar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 27
Nice hint, thought of event delegation but was wrong. But using TopLevel controlls makes perfect sense.

Still struggling with :SetAnchor and :SetDimensions after i changed an element's parent.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Adding elements to existing UI elements


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