ApplyTemplateToControl question
Hey guys,
I have a TopLevelWindow that contains a header, a close button to the right and two buttons ("Sounds subcategory" and "Animations subcategory"): Code:
<TopLevelControl name="AuraMasteryAuraActionsWindow" clampedToScreen="true" mouseEnabled="true" movable="true" tier="2" layer="2" hidden="true"> I wanted to use ApplyTemplateToControl() to "attach" two different menues to "$(parent)_DisplayContainer", but the function probably works differently from what I expected. When hiting the "AnimationsButton" for the first time everything works perfectly, the DisplayContainer is filled with the "animations template". When hiting the "SoundsButton" the DisplayContainer is filled with the "sounds template", but the "animations template" is not removed. Is ApplyTemplateToControl() not working like a templating system in php or anything comparable? /edit: I have a suspicion: The function is used only to change data in two templates of the same structure and not to entirely replace template a) with template b), is that correct? If yes, is there another function or lib that does what I need? Thanks in advance! |
you need to use "overide = true" if you want to change the parameters of an existing object. I tried to do it with InventoryRowControl, but I could not get a fully working version. If you need to change the object that you created, then I would use XML only for creating the structure of objects, and all the remaining parameters would be assigned to the LUA.
|
Ah no it's not about changing an existing objects parameters, it's about entirely replacing a template by another. Example:
Container C: << apply template A to this container (menu for animations) when a button is klicked. Once another button is klicked, apply template B to this container, with B having entirely different controls. Template A should be removed from C. I want to "load" menues into a container, like using templates in php. Until now I have always anchored the controls from A to a control pool element and set them to hidden. But swaping menues by reanchoring A to a hidden element + anchoring B to C does not feel elegant. |
That's not possible. Controls are here to stay once they are created. There is no way to delete them. Not even with templates.
|
Quote:
@Letho but as Siri said, a pool for saving objects for quick access. If you decide to completely replace the object in the pool, it will not be elegant, it will be terribly expensive in terms of resources. |
Quote:
Quote:
https://cdn-eso.mmoui.com/preview/pvw6325.png A (De)Buff trigger has totally different configuration parameters than a combat event based trigger (the latter does not require a "Source Unit", but target and source parameters, actionResults that the aura should react to, etc.). So the "Trigger Settings" submenu totally changes if the user changes the trigger type form "(De)Buff" to "Combat Event" by using the appropriate combobox. I cannot think of a more elegant way to achieve this than just taking all relevant controls and reanchoring them to hidden pools. |
Quote:
|
So as I understand it, you want to have the Source Unit line disappear if the player has a combat event trigger? An OnInitialized field in the virtual might work: You could change anchors + hide the source control in it.
But doing it yourself via anchors and SetHidden would probably be the easiest and simplest method. I think you could also use ApplyTemplateToControl for styling. I'm pretty sure controls created from Lua can handle OnUpdate. I haven't tried OnUpdate specifically but I have done OnClicked and some others, so I don't see why OnUpdate would be an exception. (control:SetHandler("OnUpdate", functionStuff) should work) |
Quote:
@Siri, what do you say? |
Quote:
|
Thanks for all the answers, guys, much appreciated! I will dig myself into SetCustomAcquireBehavior() and see how I can implement it! :)
|
Quote:
|
They do call <OnUpdate>. Virtual controls DO NOT call <OnInitialized> though, each child control of a virtual has to call the <OnInitialized> functions seperately. That is very strange...
|
A short excerpt from the control pool source:
Quote:
So I will probably have to write a lib for it. Very time intense and I am not very experienced in writing performant code :D |
Quote:
However, control created via CreateControl() -- I've tested with CT_LABEL -- DOES NOT call handler set via control:SetHandler("OnUpdate", ...). Quote:
For example here: https://github.com/merlight/eso-merT...es.xml#L67-L69 Had the <OnInitialized> part not been called, I'd be getting "attempt to index a nil value" whenever I try to access control.label member. |
Quote:
<OnInitialized> is called once when an object is created, any global function or Lua code can be placed here. Xml Code:
|
Okay, this is the XML that contains the container ("$(parent)_DisplayContainer") where the templates should be applied to:
Code:
<TopLevelControl name="AuraMasteryAuraActionsWindow" clampedToScreen="true" mouseEnabled="true" movable="true" tier="1" layer="2" hidden="true"> This is Template A: Code:
<Control name="AM_TEMP_ANIMATIONS" virtual="true"> Code:
<!-- TEMPORARY!! --> When I hit the first button, template A gets applied to "_DisplayContainer". Whenever I hit the second button and template B gets applied to "_DisplayContainer" aswell, A and B are mixed together, override="true" does not change anything. Here is a screenshot of what happens after pressing both buttons: I want Template A to be entirely replaced by Template B and vice versa. I tested it with template A and template B having only one label control of the same structure just with different texts. It worked flawlessly. Override="true" was only neccessary if the header B had some other attributes, etc. As I see it, you cannot overwrite one control with a different control type. |
As for the comment "STRANGE: <OnInitialized> is not called for this control, ..."
ApplyTemplateToControl does not create the target control -- it must've been created previously (and its OnInitialized handler called, if it had any) -- I think that's why it doesn't call the template's top-level <OnInitialized> handler (it would be called if you used the template to CreateControlFromVirtual). The template's children that didn't exist on the target control actually do get created by ApplyTemplateToControl, so their <OnInitialized> get called. Anyway, I think you're trying to use ApplyTemplateToControl for something it's not been intended for. There's no way to remove a control from the UI once it's been created. It can be repurposed or hidden, but it's there until /reloadui. I suggest you create a distinct control container for each mode and switch between them by showing one and hiding the other. |
Quote:
|
All times are GMT -6. The time now is 05:20 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI