diff --git a/lib/MCT/Display/UI/Panel/Menu.js b/lib/MCT/Display/UI/Panel/Menu.js index 41c66e2..9ff58a3 100644 --- a/lib/MCT/Display/UI/Panel/Menu.js +++ b/lib/MCT/Display/UI/Panel/Menu.js @@ -74,6 +74,7 @@ MCT.DisplayUIPanelMenu = function() { this.layout.displayObjects.add( "menuButtonStart", 'button', { image: "mct_menu_button", + interaction : { type: "click", element: this, data: { action: "start" } }, text: { value: "lt.menuButtonStart", style: "menubutton1", borderSize : { vertical: 1 } } } ) @@ -91,11 +92,28 @@ MCT.DisplayUIPanelMenu = function() { this.layout.displayObjects.add( "menuButtonQuit", 'button', { image: "mct_menu_button", + interaction : { type: "click", element: this, data: { action: "quit" } }, text: { value: "lt.menuButtonQuit", style: "menubutton1", borderSize : { vertical: 1 } } } ) ); + + this.addEventListener('click', this.onButtonClick.curry()); } MCT.DisplayUIPanelMenu.prototype = Object.create(MCT.DisplayUIPanel.prototype); -MCT.DisplayUIPanelMenu.prototype.constructor = MCT.DisplayUIPanelMenu; \ No newline at end of file +MCT.DisplayUIPanelMenu.prototype.constructor = MCT.DisplayUIPanelMenu; + +MCT.DisplayUIPanelMenu.prototype.onButtonClick = function(event) { + if (typeof event.content.action != "undefined") { + switch (event.content.action) { + case "start": + alert("Start game? Not yet!"); + break; + case "quit": + alert("Bye!"); + mct.util.quit(); + break; + } + } +} \ No newline at end of file diff --git a/lib/MCT/Util.js b/lib/MCT/Util.js index bd2c49a..978bdd2 100644 --- a/lib/MCT/Util.js +++ b/lib/MCT/Util.js @@ -26,6 +26,15 @@ MCT.Util = function() { MCT.Util.prototype.constructor = MCT.Util; +MCT.Util.prototype.quit = function(delay) { + if (typeof delay == "undefined") { + delay = 0; + } + global.setTimeout(function() { + require('nw.gui').App.closeAllWindows(); + }, delay); +} + MCT.Util.prototype.loadJSON = function(json) { if (typeof this.jsons[json] == "undefined") { // load json files one time only, espacially externals which will be used in multiple data files diff --git a/lib/mct/hotkeys.js b/lib/mct/hotkeys.js index e4c0083..7f2928e 100644 --- a/lib/mct/hotkeys.js +++ b/lib/mct/hotkeys.js @@ -22,8 +22,7 @@ $("html").keyup(function(e){ if (e.which == 27){ - var gui = require('nw.gui'); - gui.App.closeAllWindows(); + mct.util.quit(); } else if (e.which == 112){ mct.pixi.setFpsCounter(true, mct.pixi); }