Browse Source

WIP platform UI update

Josh Engebretson 10 years ago
parent
commit
b3d2324102

+ 73 - 113
PhysicsPlatformer/Resources/Components/UI.js

@@ -1,125 +1,85 @@
 
 var game = Atomic.game;
-var ui = game.ui;
-var root = ui.getRoot();
+var view = game.uiView;
+var UI = Atomic.UI;
+var UIButton = Atomic.UIButton;
+var UITextField = Atomic.UITextField;
+var UILayout = Atomic.UILayout;
+
+// create the start ui programmatically, we could also
+// use a ui template
+var window = new Atomic.UIWindow();
+// disable close button
+window.settings = UI.WINDOW_SETTINGS_DEFAULT & ~UI.WINDOW_SETTINGS_CLOSE_BUTTON;
+window.text = "Physics Platformer";
+
+// root content layout
+var layout = new UILayout();
+layout.axis = UI.AXIS_Y;
+// give ourselves a little more spacing
+layout.spacing = 18;
+layout.layoutSize = UI.LAYOUT_SIZE_AVAILABLE;
+window.contentRoot.addChild(layout);
+
+var text = new UITextField();
+text.text = "Please select the time of day:";
+layout.addChild(text);
+
+// Buttons layout
+var buttonLayout = new UILayout();
+buttonLayout.layoutDistribution = UI.LAYOUT_DISTRIBUTION_GRAVITY;
+layout.addChild(buttonLayout);
+
+var button = new UIButton();
+button.text = "Daytime";
+button.onClick = function () {
+  runPlatformer(true);
+  // must return handled, as we're being GC'd here (window is being removed)
+  return true;
+}
+buttonLayout.addChild(button);
+
+button = new UIButton();
+button.text = "Nighttime";
+button.onClick = function () {
+  runPlatformer(false);
+  // must return handled, as we're being GC'd here (window is being removed)
+  return true;
+}
+buttonLayout.addChild(button);
+
+window.resizeToFitContent();
+
+// add to the root view and center
+view.addChild(window);
+window.center();
+
+function runPlatformer(daytime) {
+
+  view.removeChild(window)
+
+  var musicFile = game.cache.getResource("Sound", "Sounds/JumpingBat.ogg");
+  musicFile.looped = true;
+  var musicNode = game.scene.createChild("MusicNode");
+  var musicSource = musicNode.createComponent("SoundSource");
+  musicSource.gain = 1.0;
+  musicSource.soundType = Atomic.SOUND_MUSIC;
+  musicSource.play(musicFile);
+
+
+  var platformerNode = game.scene.createChild("Platformer");
+  var platformer = platformerNode.createJSComponent("Platformer");
+
+  platformer.init(daytime);
 
-var uiStyle = game.cache.getResource("XMLFile", "UI/DefaultStyle.xml");
-root.defaultStyle = uiStyle;
-
-var window = new Atomic.Window();
-root.addChild(window);
-
-window.setMinSize(384, 192);
-
-window.setAlignment(Atomic.HA_CENTER, Atomic.VA_CENTER);
-
-window.setLayout(Atomic.LM_VERTICAL, 6, [6, 6, 6, 6]);
-window.setName("Window");
-
-var titleBar = new Atomic.UIElement();
-titleBar.setMinSize(0, 24);
-titleBar.setVerticalAlignment(Atomic.VA_TOP);
-titleBar.setLayoutMode(Atomic.LM_HORIZONTAL);
-
-// Create the Window title Text
-var windowTitle = new Atomic.Text();
-windowTitle.setName("WindowTitle");
-windowTitle.setText("Please select Daytime of Nighttime");
-titleBar.addChild(windowTitle);
-
-window.addChild(titleBar);
-
-// Daytime button
-var button = new Atomic.Button();
-button.setName ("Daytime");
-button.setMinHeight(48);
-
-var buttonText = new Atomic.Text();
-
-buttonText.text = "Daytime";
-var font = game.cache.getResource("Font", "Fonts/Anonymous Pro.ttf");
-
-buttonText.setFont(font, 12);
-buttonText.color = [1, 1, 0, 1];
-
-buttonText.horizontalAlignment = Atomic.HA_CENTER;
-buttonText.verticalAlignment = Atomic.VA_CENTER;
-button.addChild(buttonText);
-
-window.addChild(button);
-button.setStyleAuto();
-
-// Nighttime button
-button = new Atomic.Button();
-button.setName ("Nighttime");
-button.setMinHeight(48);
-
-buttonText = new Atomic.Text();
-
-buttonText.text = "Nighttime";
-
-buttonText.setFont(font, 12);
-buttonText.color = [0, 1, 1, 1];
-
-buttonText.horizontalAlignment = Atomic.HA_CENTER;
-buttonText.verticalAlignment = Atomic.VA_CENTER;
-button.addChild(buttonText);
-
-window.addChild(button);
-button.setStyleAuto();
-
-window.movable = true;
-window.resizeable = true;
-
-window.setStyleAuto();
-titleBar.setStyleAuto();
-windowTitle.setStyleAuto();
-
-
-self.onMouseClick = function(element) {
-
-    var go = 0;
-    
-    if (element.name == "Daytime") {
-        go = 1;
-    }
-    
-    if (element.name == "Nighttime") {
-        go = 2;    
-    }
-   
-    if (go) {
-    
-        root.removeChild(window);
-        
-        var musicFile = game.cache.getResource("Sound", "Sounds/JumpingBat.ogg");
-        musicFile.looped = true;
-        var musicNode = game.scene.createChild("MusicNode");
-        var musicSource = musicNode.createComponent("SoundSource");
-        musicSource.gain = 1.0;
-        musicSource.soundType = Atomic.SOUND_MUSIC;
-        musicSource.play(musicFile);
-        
-    
-        var platformerNode = game.scene.createChild("Platformer");
-        var platformer = platformerNode.createJSComponent("Platformer");
-        
-        platformer.init(go == 1);
-    
-    }
-    
 }
 
 function start() {
-    
-
-    self.listenToEvent(null, "UIMouseClick", self.onMouseClick );
 
 }
 
 function update(timeStep) {
 
-    
-    
-}
 
+
+}

+ 16 - 9
PhysicsPlatformer/Resources/Scripts/main.js

@@ -6,25 +6,36 @@ require("AtomicGame");
 
 Atomic.script("LevelParser");
 
+var uiConfig = {
+
+	//tbui->Initialize("UI/language/lng_en.tb.txt");
+	//tbui->LoadSkin("UI/default_skin/skin.tb.txt", "Skin/skin.tb.txt");
+	//tbui->AddFont("UI/fonts/vera.ttf", "Vera");
+	//tbui->SetDefaultFont("Vera", 12);
+
+}
+
+
+
 Atomic.game.init(start, update);
 
 // called at the start of play
 function start() {
 
 	var game = Atomic.game;
-	
+
 	game.input.setMouseVisible(true);
 
 	// create a 2D scene
 	game.createScene2D();
-	
+
 	var uiNode = game.scene.createChild("UI");
-	
+
 	if (Atomic.platform == "iOS" || Atomic.platform == "Android")
 	    uiNode.createJSComponent("TouchInput");
-	
+
 	uiNode.createJSComponent("UI");
-		
+
 }
 
 // called per frame
@@ -32,7 +43,3 @@ function update(timeStep) {
 
 
 }
-
-
-
-

+ 0 - 1
UITests/Resources/Scripts/main.js

@@ -4,7 +4,6 @@ require("AtomicGame");
 
 Atomic.script("utils.js");
 
-
 Atomic.game.init(start, update);
 
 // called at the start of play