playMaker

Author Topic: How to make dynamic GUI elements with Playmaker?  (Read 4224 times)

derkork

  • Playmaker Newbie
  • *
  • Posts: 1
How to make dynamic GUI elements with Playmaker?
« on: June 19, 2012, 04:47:39 AM »
I want to make a list of buttons which lead the player to various levels of the game. The list originates from an xml file which I read with a custom playMaker action. Now I want to do something like this:

Code: [Select]
BeginVertical

Foreach item in my list
  Button

EndVertical

I could code this of course, but I wonder if there is a way of doing this just with playMaker actions. I thought of creating an action which iterates over the list just like the GetNextChild action and then create some kind of loop there. However I faced three problems:

1.When I loop back to my own state, i get a warning that I am creating an infinite loop and the state is no longer executed. How would I prevent that?
2. I really cannot link back to the top of my GUI state, because that contains something more than just the list of buttons:

Code: [Select]
BeginArea
BeginHorizontal
FlexibleSpace
...
Button actions here..
...
FlexibleSpace
EndHorizontal
EndArea

When I link back to the top of my state I get error messages that my GUI stack is imbalanced (which is clear because I do a lot more BeginArea than EndArea).

I tried creating a separate state for doing just the button list, but I'm not sure how to wire it with the state drawing the rest of the GUI. I tried the "return to last state" action after the GUI list, but this brought me another "infinite loop" warning. As far as I can see all GUI stuff has to be in one state.

3. I would require the buttons to throw different events and handle them accordingly. However since the events are not known upfront (because they are in the xml file), I don't know how to model the event handling for this. Also the event property of the button does not take a variable, so I actually need to know the event upfront.

Is there a way to do this with playMaker or do I have to use real scripting for a GUI like this?
« Last Edit: June 19, 2012, 04:49:54 AM by derkork »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How to make dynamic GUI elements with Playmaker?
« Reply #1 on: June 20, 2012, 02:13:52 AM »
Hi,

 I have started few weeks ago a GUIML system that use xml to describe your gui, just like you want to do. The benefit to the approach I took was that once you create a gui button it will live until you delete it, which is not how gui is working as is and how playmaker is working with gui as is.

Your problem would be solved elegantly because you can reference xml nodes, which means chuncks of gui, not just an element. Working with gui becomes very similar to how gameOnbjects are working, they persits and behaves more like we expect them to.

The really cool thing, on top of that, is that I can bind any property of the gui to Fsm variables and events, all within xml definition!! and I have a series of actions to control the gui elements, for example create a button, delete a button, show/hide element,  etc etc.

Code: [Select]
<layoutButton text="click me!" >
<events>
<onClick>
<fsmEvent name="ADD NEW BUTTON" >
<eventTarget broadcast="true" ignoreSelf="true" />
<eventData string="Remove me" int="5" bool="true" />
</fsmEvent>
</onClick>
</events>
</layoutButton>

that xml would display a gui button with text "click me!" and fire  a global event "ADD NEW BUTTON" with event data set to various variables

I have made it so flexible that you can actually declare your own elements, I have for example created drop down elements and breadcrumbs elements.

 It's unfortunatly still in very early stage, so pm me to get access to the current alpha version if you are interested.

So all that to say, that unfortunatly, you will likely need to use scripts to start doing anything serious with unity gui system.

Bye,

 Jean