Skip to content

Commit

Permalink
added first button click events to menu panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Kelm committed Aug 8, 2013
1 parent 60b147e commit c3daddb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
20 changes: 19 additions & 1 deletion lib/MCT/Display/UI/Panel/Menu.js
Expand Up @@ -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 } }
}
)
Expand All @@ -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;
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;
}
}
}
9 changes: 9 additions & 0 deletions lib/MCT/Util.js
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/mct/hotkeys.js
Expand Up @@ -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);
}
Expand Down

0 comments on commit c3daddb

Please sign in to comment.