ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Adding elements to existing UI elements (https://www.esoui.com/forums/showthread.php?t=518)

Wukar 04/03/14 06:19 AM

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 ;-)

Seerah 04/03/14 04:28 PM

From the description:
Quote:

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. ;)

Wukar 04/03/14 07:12 PM

*self-facepalm* configuration gui - got it ;)

But the UI elment question remains.

Seerah 04/03/14 08:35 PM

Look to see how LAM creates the editbox. (Hint: I used a template from the default UI ;) )

Cr4x 04/04/14 07:42 AM

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* :D

Cheers

Wukar 04/04/14 01:18 PM

Thanks for the hints. I hate direct solutions and prefer learning by doing ;)

Wukar 04/05/14 11:42 AM

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())


Wukar 04/05/14 12:28 PM

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 ;-)

Seerah 04/05/14 01:55 PM

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

Wukar 04/05/14 02:15 PM

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 :cool:

Wukar 04/05/14 03:33 PM

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)

Lyrael 04/05/14 09:52 PM

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.

Seerah 04/05/14 10:35 PM

Yeah, I came across stuff referencing that last night but didn't look too much into it. Nice find.

Cr4x 04/06/14 04:07 AM

Quote:

Originally Posted by Wukar (Post 2839)
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.

Quote:

Originally Posted by Lyrael (Post 2880)
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 :D. I already figured that out too and was wondering why ZO isnt showing it :D. However if you want to add a filter, you may check the ZO_InventoryManager even the data sets of the different filters

Wukar 04/06/14 06:56 AM

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.

Cr4x 04/06/14 07:33 AM

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)

Wukar 04/06/14 09:09 AM

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.


All times are GMT -6. The time now is 11:57 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI