PDA

View Full Version : Button states in template



Varsuuk
June 9th, 2023, 05:09
I press the button and the action happens opening the thing but I noticed unlike another cog I use (different icons) pressing it doesn't result in a graphic change.
So then I tried the state/pressed combo - same thing nothing changed. Of course this is just a minor visual thing, was curious however.


<template name="button_charabiltiesdetail">
<buttoncontrol>
<anchored width="20"/>
<!-- <state icon="details_white" pressed="details_down" /> -->
<state>
<icon>details_white</icon>
</state>
<pressed>
<icon>details_down</icon>
</pressed>
<script>
function onButtonPress()
Interface.openWindow("charsheet_abilities_details", window.getDatabaseNode());
end
</script>
</buttoncontrol>
</template>

Trenloe
June 9th, 2023, 10:10
Have you 100% confirmed that "details_down" is a valid icon resource?

If so, try the <icon> property: <icon normal="details_white" pressed="details_down" />

Moon Wizard
June 9th, 2023, 15:50
"button_details" and "button_details_down" are the names of the default icons for the "button_details" template button in CorRPG.

Regards,
JPG

Varsuuk
June 10th, 2023, 04:03
Have you 100% confirmed that "details_down" is a valid icon resource?

If so, try the <icon> property: <icon normal="details_white" pressed="details_down" />

Thanks Trenloe, that worked precisely. Below is my slight modification of 2E's template based on your instructions (I was trying various combos from looking up controls on Wiki before trying to replicate in RW):
The commented out line is the original code - like mine, it "worked", you could press it and it opened a panel but it didn't animate until your correction.


<template name="button_charabiltiesdetail">
<buttoncontrol>
<anchored width="20"/>
<!-- <state icon="details_white" pressed="details_down" /> -->
<icon normal="details_white" pressed="details_down" />
<script>
function onButtonPress()
Interface.openWindow("charsheet_abilities_details", window.getDatabaseNode());
end
</script>
</buttoncontrol>
</template>


EDIT, forgot the / in code.

PS - Changing those 2 lines should fix all or most of the Charsheet buttons in 2E Ruleset that don't "press" unless it was intended for them to stay white-cog when pressed.

Moon Wizard
June 10th, 2023, 04:07
Why not just use the button_toggledetails template, that uses button_details and button_details_down?

If the color is wrong, why not just replace button_details icon?

JPG

Varsuuk
June 11th, 2023, 01:04
Why not just use the button_toggledetails template, that uses button_details and button_details_down?

If the color is wrong, why not just replace button_details icon?

JPG

Mainly cos right now, been adding the minimal gui elements I need for the sheet and using a lot of 2E for guide for the first draft since it's 1E-based. So, what I do there is create a normal coreRPG.xml file for things that appear to be overrides of coreRPG stuff and a coreRPG_add.xml file (coreRPG represents whatever that file is called in coreRPG, like tempate_char.xml and template_char_add.xml) since the source 2E often mixes these, I search for exact name matches in Core in order to delineate it. I also carry over now (after spending WAAAAY to long making my first 4 graphic elements on my own) the 2E graphics and append "_2E" to them so I know which to replace and rearrange when done later that aren't mine or from coreRPG.

So I didn't see this existing template. I guess he made his own before it existed or he missed it.
That said, I am ALL FOR reuse so I went to do just that (but intending to test to see if could simply override the <icon...> part because the detail button is only going to be "white" in certain situations (contrast with element it is on) and then I saw that both this detail template above and the original one you mention rely on scripts. I haven't yet re-gone over the wiki (cos... I need to dive in or will never get to it) so I do not know if there is a mechanism for a CONTROL (vs file) script to call a parent control script. I'll just try it without calling anything to see if it work magicalifically.

EDIT: I see now the CoreRPG one is a multi-state control, which is not what Cel's is, that one is a toggle switch.
That said, I found I could merge="replace" the first one but if put both it onl;y keeps the last (prob rules on that when there are multiple of same xml tag, but not gonna look for it to read since what I got works for me atm fine enough. But appreciate knowing about that template for when it will apply.

EDIT2: Since I tend to obsessively try to trace things, I initially avoided thinking about how window.toggleDetail worked. Unfortunately upon editing back my code, I felt I needed to know and yup, this is how I get distracted ;) Anyhow, it seems this button is very tightly coupled with record_power_item and that is the only place in CoreRPG it is used and it expects the enclosing window to have a toggleDetails method (which we could override to do what the above control does but at this point, it seems safer to just roll your own like Cel did since it is a matter of trying to shoehorn one purpose control for another. It isn't written to be overridden easily (I think) )

EDIT3: Grrr (see above...obsessive) - so I trped the words "overriden easily" and thought, yeah between the name and other stuff the one I am using would only work once on a page and yet, it COULD be reusable if I knew what to do. So two tries later, I found target[1] was the right syntax and modified Cel's version to:


<template name="button_toggledetails">
<buttoncontrol>
<anchored width="20"/>
<icon normal="details_white" pressed="details_down" />
<target>charsheet_abilities_details</target>
<script>
function onButtonPress()
Interface.openWindow(target[1], window.getDatabaseNode());
end
</script>
</buttoncontrol>
</template>


The next step would be to making a REAL toggle were onButtonPress checks a state and either opens or closes the window. But I don't need that yet and don't want to continue down rabbit holes ;) I just want the minimal UI up so I can start coding the functionality. But the above I am thinking is a good start for a control that can open different windows if you redefine "<target>" in a consitant way. And you can update the button icons in the normal xml manner as well.