2
* This file is part of the dis-Emi-A HaXe Library. Copyright (c) edA-qa mort-ora-y
3
* For full copyright and license information please refer to doc/license.txt.
14
import DrawBasicTypes;
16
typedef ActorArgs = Void -> Dynamic;
18
class TestActor extends ui.StageLayout, implements ui.Animation
21
var actorClass : Class<Dynamic>;
23
var box : PositionBox;
24
var notice : ui.StaticText;
26
var edit1 : ui.EditText;
28
var actorButtons : ui.LinearLayout;
29
var testButtons : ui.LinearLayout;
30
var buttons : ui.LinearLayout;
31
var status : ui.LinearLayout;
32
var primary : ui.LinearLayout;
34
var tfActor : ui.StaticText;
35
var tfRatio : ui.StaticText;
36
var tfZoom : ui.StaticText;
37
var tfFPS : ui.StaticText;
38
var tfLoad : ui.StaticText;
45
ui.AnimationManager.s_addListener( this, 1.0 );
47
primary = ui.LinearLayout.horizontal();
48
layout.add( primary, ui.SizeType.Fill( 1 ) );
50
status = ui.LinearLayout.horizontal();
51
status.setBackground( ui.Box.plain( Brush.solid( Color.rgb(0.2,0.5,0.5) ) ) );
52
//TODO: the need to repeat 1.5 in each line here is distressing, if you
53
//don't then the StaticText won't know it's preferred size... :(
54
layout.add( status, ui.SizeType.Lines( 1.5 ) );
55
tfActor = ui.StaticText.singleLine( "", ui.StaticTextAlign.Left, 1.5 );
56
tfRatio = ui.StaticText.singleLine( "", 1.5 );
57
tfZoom = ui.StaticText.singleLine( "", 1.5 );
58
tfFPS = ui.StaticText.singleLine( "xx.x fps", 1.5 );
59
tfLoad = ui.StaticText.singleLine( "xxx.xx ms", 1.5 );
61
status.add( tfActor );
62
status.add( ui.Box.empty(), ui.SizeType.Fill( 0 ) );
63
status.add( tfRatio );
70
testButtons = ui.LinearLayout.vertical();
71
testButtons.add( ui.Button.plain( ui.Action.bind( control ), "Control" ) );
74
box = new PositionBox( );
75
primary.add( box, ui.SizeType.Fill( 1 ) );
77
//combine it all together
78
buttons = ui.LinearLayout.vertical();
79
primary.add( buttons );
80
buttons.add( testButtons );
82
//ensure we fill the stage
83
layout.setBackground( ui.Box.plain( draw.TileDesc.brushFromXML( backTile ) ) );
85
var cl = Type.resolveClass( TestActorOptions.actorClassName );
89
setupActor( cl, null );
93
TestActorOptions.actorClassName = null;
98
public function animate( elapsed : Float ) : Bool
100
tfFPS.text = Math.floor( ui.AnimationManager.getInstance().lastFPS * 10 ) /10.0 + "fps";
101
tfLoad.text = Math.floor( ui.AnimationManager.getInstance().lastLoad * 100000 ) / 100 + "ms";
105
function updateStatus()
107
tfActor.text = TestActorOptions.actorClassName;
108
tfZoom.text = Math.floor( TestActorOptions.zoom * 100 ) + "% "; //extra space until full auto-text sizing works
110
if( TestActorOptions.ratio == null )
111
tfRatio.text = "none";
114
//rough check for simple ratios (TODO: lookup a good way to do this)
119
if( mathx.MathUtil.equals( x/y, TestActorOptions.ratio ) )
121
tfRatio.text = x + ":" + y;
130
tfRatio.text = "" + TestActorOptions.ratio;
139
var menu = Menu.popup();
140
menu.addSubMenu( "Select Actor", getSelectActorMenu() );
141
menu.addSubMenu( "Size Ratio", getSelectRatio() );
143
menu.addItem( "Params", ui.Action.bind( setParams ) );
144
menu.addItem( "Reset", ui.Action.bind( doActorReset ) );
145
menu.addItem( "Zoom Out", ui.Action.bind1( doZoom, 0.5 ) );
146
menu.addItem( "Zoom In", ui.Action.bind1( doZoom, 2 ) );
148
menu.modalAtMouse(null,false/*gray*/);
151
function getSelectRatio()
153
var menu = Menu.popup();
166
menu.addItem( r[0], ui.Action.bind1( setRatio, r[1] ) );
171
function setRatio( ratio : Null<Float> )
173
TestActorOptions.ratio = ratio;
174
box.setRatio( TestActorOptions.ratio );
178
function getSelectActorMenu()
180
var menu = Menu.popup();
181
//create the built-in samples
182
var sub = Menu.popup();
184
[ "Stacked Panels", ui.anim.lib.StackedPanels, argsStackedPanels ],
185
[ "Puzzle Piece", ui.anim.lib.PuzzlePiece, argsPuzzlePiece ],
186
[ "Gift Box", ui.anim.lib.GiftBox, argsGiftBox ],
187
[ "Bone Circle", ui.anim.lib.BoneCircle, argsBoneCircle ],
188
[ "Bone Jitter", ui.anim.lib.BoneJitter, argsBoneJitter ],
189
[ "Bone Slider", ui.anim.lib.BoneSlider, argsBoneSlider ],
190
[ "Bone Shatter", ui.anim.lib.BoneShatter, argsBoneSlider ],
191
[ "Bone Wheel", ui.anim.lib.BoneWheel, argsBoneWheel ],
195
sub.addItem( s[0], ui.Action.bind2( selectActor, s[1], s[2] ) );
196
menu.addSubMenu( "TestActor Samples", sub );
198
//add a default for each of the actors
200
for( s in ActorList.actorList )
201
sub.addItem( s[0], ui.Action.bind2( setupActor, s[1], {} ) );
202
menu.addSubMenu( "Library Animations", sub );
207
function selectActor( actorClass : Class<Dynamic>, actorArgFunc : ActorArgs )
209
setupActor( actorClass, actorArgFunc() );
212
function setupActor( actorClass : Class<Dynamic>, actorArgs : Dynamic )
214
TestActorOptions.actorClassName = Type.getClassName( actorClass );
216
this.actorClass = actorClass;
217
this.actor = Type.createInstance( actorClass, [ actorArgs ] );
218
var replace = new Array<ui.Widget>();
219
replace.push( ui.Box.plain( Pen.solid( 0, Color.rgb(0,0,0) ) ) );
220
replace.push( actor );
221
box.replace( replace );
222
box.setZoom( TestActorOptions.zoom );
223
box.setRatio( TestActorOptions.ratio );
225
if( actorButtons != null )
226
buttons.remove( actorButtons );
228
//setup buttons to control the actor
229
actorButtons = ui.LinearLayout.vertical();
230
actorButtons.add( ui.StaticText.singleLine( "Sequences" ) );
231
for( seq in actor.getSequences() )
235
actor.actorSetSequence,
237
ui.Action.bind1( seqDone, seq ),
243
notice = ui.StaticText.singleLine( "" );
244
actorButtons.add( notice );
246
actorButtons.add( ui.StaticText.singleLine( "Traits" ) );
247
for( group in actor.getTraitGroups() )
249
var menu = Menu.popup();
251
actorButtons.add( ui.Button.plain( ui.Action.bind( function() { menu.modalAtMouse(null,false); } ), group ) );
252
for( trait in actor.getTraits(group) )
254
var numArgs = actor.getTraitNumArgs( group, trait );
255
menu.addItem( trait, ui.Action.bind3( setTrait, group, trait, numArgs ) );
259
actorButtons.add( ui.StaticText.singleLine( "Params" ) );
260
actorButtons.add( edit1 = ui.EditText.singleLine() );
262
buttons.add( actorButtons );
263
primary.update(); //width of buttons may have changed
268
function doActorReset()
270
//can't be bound directly since the actor object changes
274
function setTrait( group : String, trait : String, numArgs : Int )
277
actor.actorSetTrait( actor.getTraitRef(group, trait) );
278
else if( numArgs == 1 )
279
actor.actorSetTrait1( actor.getTraitRef(group, trait), edit1.text ); //use auto-conversions...
281
Assert.unreachable();
284
function seqDone( seq : String )
286
notice.text = "Done: " + seq;
289
function doZoom( mul : Float )
291
TestActorOptions.zoom *= mul;
292
box.setZoom( TestActorOptions.zoom );
298
var dlg = new ActorParamsDialog( actor );
299
dlg.usePrefSize(stage);
300
ui.Modal.asStageModal( dlg, ui.Action.bind1( dialogDone, dlg ) );
303
function dialogDone( dlg : ActorParamsDialog )
305
var newParams = dlg.getParams();
306
if( newParams == null )
307
return; //user pressed cancel
309
//recreate the actor entirely since Actors do not expect their params to
310
//change during their execution
311
setupActor( actorClass, newParams );
314
//////////////////////////////////////////////////////////////////////
315
// Sample actor arguments
316
function argsStackedPanels()
321
function argsPuzzlePiece()
324
var image = new ui.PositionBox( ui.Box.plain( new squix.IClipBackground() ) );
325
image.setOrigin( Point2.at( 0.5, 0.5 ) );
326
image.setTranslate( Point2.at( -0.25, 0 ) );
337
function argsBoneJitter()
341
item: new ui.anim.lib.Polygon( { sides: 5, fill: Brush.solid( Color.rgb(0.8,0.1,0.5) ) } )
345
function argsBoneSlider()
349
item: new ui.anim.lib.Polygon( { sides: 4, fill: Brush.solid( Color.rgb(0.8,0.1,0.5) ), angleOffset: 0.7854 } )
353
function argsGiftBox()
358
prize: new ui.anim.lib.Polygon( { sides: 5, fill: Brush.solid( Color.rgb(0.8,0.1,0.5) ) } )
362
function argsBoneCircle()
365
{ actors: getListActors(),
370
function argsBoneWheel()
374
actors: getListActors().concat( getListActors() )
379
function getListActors()
381
var text = "Press Me!";
382
var inner = new ui.PositionBox( ui.StaticText.singleLine( text ) );
383
inner.setRatio( 4 ); //TODO: still to be done automatically by StaticText!!!
384
var subActor = new ui.anim.lib.Polygon(
389
sides: 5, fill: Brush.solid( Color.rgb(0.8,0.1,0.5) )
391
var testButton = ui.Button.actor( ui.Action.bind( function() { trace( "Clicked" ); } ), subActor );
394
new ui.anim.lib.Polygon( { sides: 3, fill: Brush.solid( Color.rgb(0.5,0.8,0.1) ) } ),
395
new ui.anim.lib.Polygon( { sides: 4, fill: Brush.solid( Color.rgb(0.1,0.5,0.8) ) } ),
396
new ui.anim.lib.Polygon( { sides: 5, fill: Brush.solid( Color.rgb(0.8,0.1,0.5) ) } )
400
//////////////////////////////////////////////////////////////////////
402
static public function main()
404
ui.StageLayout.setup( TestActor );
407
//////////////////////////////////////////////////////////////////////
409
define(`IsVerticalLayout',`')
410
include(`ui/MixinLayout.ihx')
412
static var backTile = HERE _FILE(actor_back.tile.xml);