101 lines
3.3 KiB
JavaScript
101 lines
3.3 KiB
JavaScript
"use strict";
|
|
|
|
const MainMenuView = (function(){
|
|
|
|
const MainMenuView = function(xgravity){
|
|
|
|
const self = this;
|
|
let view_element = null;
|
|
|
|
this.close = () => {
|
|
if(view_element && view_element.parentNode){
|
|
view_element.parentNode.removeChild(view_element);
|
|
view_element = null;
|
|
}
|
|
};
|
|
|
|
this.go = () => {
|
|
self.close();
|
|
|
|
const is_game_active = xgravity.views.game && typeof xgravity.views.game.is_active === "function"
|
|
? xgravity.views.game.is_active()
|
|
: false;
|
|
|
|
const menu_buttons = [];
|
|
|
|
// 1. Si hay partida en curso: botón Reanudar
|
|
if(is_game_active){
|
|
menu_buttons.push([
|
|
"button", {
|
|
class : "xg-btn xg-btn-resume",
|
|
"data-i18n" : "btn_resume",
|
|
onclick : () => {
|
|
self.close();
|
|
if(xgravity.views.game){
|
|
xgravity.views.game.resume();
|
|
}
|
|
}
|
|
}
|
|
]);
|
|
}
|
|
|
|
// 2. Jugar / Nueva Partida -> Abre DifficultySelectView
|
|
menu_buttons.push([
|
|
"button", {
|
|
class : "xg-btn",
|
|
"data-i18n" : is_game_active ? "btn_new_game" : "btn_play",
|
|
onclick : () => {
|
|
self.close();
|
|
if(xgravity.views.difficulty_select){
|
|
xgravity.views.difficulty_select.go();
|
|
}
|
|
}
|
|
}
|
|
]);
|
|
|
|
// 3. Vistas secundarias
|
|
menu_buttons.push(
|
|
["button", {
|
|
class : "xg-btn",
|
|
"data-i18n" : "btn_options",
|
|
onclick : () => {
|
|
self.close();
|
|
if(xgravity.views.options) xgravity.views.options.go();
|
|
}
|
|
}],
|
|
["button", {
|
|
class : "xg-btn",
|
|
"data-i18n" : "btn_ranking",
|
|
onclick : () => {
|
|
self.close();
|
|
if(xgravity.views.ranking) xgravity.views.ranking.go();
|
|
}
|
|
}],
|
|
["button", {
|
|
class : "xg-btn",
|
|
"data-i18n" : "btn_credits",
|
|
onclick : () => {
|
|
self.close();
|
|
if(xgravity.views.credits) xgravity.views.credits.go();
|
|
}
|
|
}]
|
|
);
|
|
|
|
const nodes = xgravity.html(xgravity.item_self, [
|
|
"div", { class : "xg-view xg-main-menu" }, [
|
|
["div", { class : "xg-menu-header" }, [
|
|
["img", { class : "xg-main-logo", src : "images/logo.svg", alt : "XGravity Logo" }],
|
|
["h1", { class : "xg-title", "data-i18n" : "xgravity" }]
|
|
]],
|
|
["div", { class : "xg-menu-list" }, menu_buttons]
|
|
]
|
|
]);
|
|
|
|
view_element = nodes[0];
|
|
xgravity.i18n.update();
|
|
};
|
|
|
|
};
|
|
|
|
return MainMenuView;
|
|
})(); |