1
1
// JSCFEditor consts
2
+ const __JSCFEDITOR_ADD_WINDOW_NAME = "add-window" ;
2
3
const __JSCFEDITOR_HELP_PANEL_NAME = "help-panel" ;
3
4
const __JSCFEDITOR_LIST_PANEL_NAME = "panel-script" ;
4
5
const __JSCFEDITOR_ID = "jscf-editor" ;
5
6
const __JSCFEDITOR_SAVE_ID = "jscf-editor-save-button" ;
6
7
const __JSCFEDITOR_CANCEL_ID = "jscf-editor-cancel-button" ;
7
8
const __JSCFEDITOR_PANEL_ID = "jscf-editor-panel" ;
9
+ // debug panel consts
10
+ const __JSCFEDITOR_HELP_TEXT = "Welcome to the JSCF editor!\n\
11
+ - Mod key: left ctrl\n\
12
+ - Use Mod+left-click to drag entities\n\
13
+ - Use Mod+right-click to resize\n\
14
+ - Use ~ button to toggle" ;
8
15
// keybinds
9
- const __JSCFEDITOR_KB_DEV_TOGGLE = 192 ;
16
+ const __JSCFEDITOR_KB_DEV_TOGGLE = 192 ;
10
17
11
18
/**
12
19
* conservingBind: keeps code but applies native binding
@@ -273,6 +280,11 @@ function JSCFEditor (game)
273
280
SceneUtils . saveToFile ( game . getCurrentScene ( ) . serialize ( ) , "scene" ) ;
274
281
} ) ;
275
282
283
+ var createBtn = guim . createDefaultButton ( 0 , 0 , "Create Entity" , function ( ) {
284
+ var e = game . getCurrentScene ( ) . createNewEntity ( ) ;
285
+ tb . value ( e . name ) ;
286
+ } ) ;
287
+
276
288
// Create the panel
277
289
var panel = guim . createContainer ( __GUIMANAGER_DEBUG_PANEL_NAME ,
278
290
panelWidth / 2 , panelHeight / 2 , panelWidth ,
@@ -281,8 +293,9 @@ function JSCFEditor (game)
281
293
panel . getComponentOfType ( LayoutHandler ) . layoutType = LinedLayout ;
282
294
283
295
panel . insertChild ( fpsLabel ) ;
284
- panel . insertChild ( saveBtn ) ;
285
296
panel . insertChild ( toggleBtn ) ;
297
+ panel . insertChild ( saveBtn ) ;
298
+ panel . insertChild ( createBtn ) ;
286
299
panel . insertChild ( searchTB ) ;
287
300
panel . insertChild ( listLabel ) ;
288
301
panel . addChild ( __JSCFEDITOR_LIST_PANEL_NAME , panelScript ) ;
@@ -369,6 +382,13 @@ function JSCFEditor (game)
369
382
// seperator
370
383
panel . insertChild ( guim . createLabel ( 0 , 0 , "______________________" ) ) ;
371
384
385
+ // add button
386
+ var addBtn = guim . createDefaultButton ( 0 , 0 , "Add" ) ;
387
+ addBtn . getComponentOfType ( ButtonHandler ) . onClick = function ( ) {
388
+ game . getCurrentScene ( ) . addEntity ( self . createAddWindow ( obj , panel ) ) ;
389
+ } ;
390
+ panel . insertChild ( addBtn ) ;
391
+
372
392
// close button
373
393
var closeBtn = guim . createDefaultButton ( 0 , 0 , "Close" ) ;
374
394
closeBtn . getComponentOfType ( ButtonHandler ) . onClick = function ( ) {
@@ -384,22 +404,68 @@ function JSCFEditor (game)
384
404
} ;
385
405
386
406
/**
387
- * create help panel
407
+ * creates add property window for object
408
+ *
409
+ * @method
410
+ * @param {Entity } obj the object to add property to
411
+ * @param {Entity } panel the creating panel
412
+ * @return {Entity } the window entity
413
+ */
414
+ this . createAddWindow = function ( obj , panel )
415
+ {
416
+ var guim = game . guiManager ;
417
+
418
+ const PANEL_WIDTH = guim . theme . getSize ( "panel" , "width" ) ;
419
+ const DP_WIDTH = PANEL_WIDTH + guim . theme . getSize ( "panel" , "margin" ) ;
420
+ const COMPONENT_LIST = [ LayoutHandler , ButtonHandler , Script , Collider , Rigidbody , RectangleEditor ] ;
421
+
422
+ var addWindow = guim . createDefaultWindow ( DP_WIDTH * 2 , PANEL_WIDTH ) ;
423
+ addWindow . name = guim . generateUIName ( __JSCFEDITOR_ADD_WINDOW_NAME ) ;
424
+ addWindow . addComponent ( LayoutHandler ) ;
425
+ addWindow . getComponentOfType ( LayoutHandler ) . layoutType = FitLayout ;
426
+
427
+ var self = this ;
428
+ var closeFn = function ( ) {
429
+ game . getCurrentScene ( ) . delEntity ( panel . name ) ;
430
+ self . createInspectionPanel ( obj ) ;
431
+ game . getCurrentScene ( ) . delEntity ( addWindow . name ) ;
432
+ } ;
433
+
434
+ for ( var i = 0 ; i < COMPONENT_LIST . length ; i ++ ) {
435
+ var btn = guim . createDefaultButton ( 0 , 0 , COMPONENT_LIST [ i ] . component_name , null ) ;
436
+ btn . componentType = COMPONENT_LIST [ i ] ;
437
+ btn . getComponentOfType ( ButtonHandler ) . onClick = function ( ) {
438
+ obj . addComponent ( this . componentType ) ;
439
+ closeFn ( ) ;
440
+ } . bind ( btn ) ;
441
+ addWindow . insertChild ( btn ) ;
442
+ }
443
+
444
+ var planeBtn = guim . createDefaultButton ( 0 , 0 , "Plane" , function ( ) {
445
+ obj . insertChild ( new Plane ( game , 100 , 100 , "black" ) ) ;
446
+ closeFn ( ) ;
447
+ } ) ;
448
+ addWindow . insertChild ( planeBtn ) ;
449
+
450
+ return addWindow ;
451
+ } ;
452
+
453
+ /**
454
+ * create help window
388
455
*
389
456
* @method
390
457
* @return {Core.Entity } a help popup entity
391
458
*/
392
- this . createHelpPanel = function ( )
459
+ this . createHelpWindow = function ( )
393
460
{
394
461
var guim = game . guiManager ;
395
462
396
- const HELP_TEXT = "Welcome to the JSCF editor!\n- Use left-click to drag entities\n- Use right-click to resize\n- Use ~ button to toggle" ;
397
463
const PANEL_WIDTH = guim . theme . getSize ( "panel" , "width" ) ;
398
464
const DP_WIDTH = PANEL_WIDTH + guim . theme . getSize ( "panel" , "margin" ) ;
399
465
400
466
var helpPanel = guim . createDefaultWindow ( DP_WIDTH * 2 , PANEL_WIDTH ) ;
401
467
helpPanel . name = guim . generateUIName ( __JSCFEDITOR_HELP_PANEL_NAME ) ;
402
- helpPanel . insertChild ( guim . createLabel ( 0 , 0 , HELP_TEXT ) ) ;
468
+ helpPanel . insertChild ( guim . createLabel ( 0 , 0 , __JSCFEDITOR_HELP_TEXT ) ) ;
403
469
404
470
return helpPanel ;
405
471
} ;
@@ -437,7 +503,7 @@ function JSCFEditor (game)
437
503
// Create debug panel
438
504
var debugPanel = this . createDebugPanel ( ) ;
439
505
// Create debug help panel
440
- var helpPanel = this . createHelpPanel ( ) ;
506
+ var helpPanel = this . createHelpWindow ( ) ;
441
507
442
508
// Insert panels
443
509
game . getCurrentScene ( ) . addEntity ( debugPanel ) ;
0 commit comments