nodePong/client/lib/core/page_handler.js

125 lines
2.7 KiB
JavaScript

/**
* @file page_handler.js
* @author frtk@tetalab
*/
NPGClient.PageHandler = {
currPage: '',
pages: [],
//
setup: function() {
var self = this;
self.currPage = NPGClient.LOGIN.NAME;
// create login page
self.createLoginPage();
// create start menu page
self.createStartMenuPage();
},
//
setCurrPage: function(n) {
var self = this;
self.currPage = n;
},
//
moveToPage: function(n) {
var self = this;
switch (n) {
case NPGClient.LOGIN.NAME:
NPGClient.Utils.resetName();
NPGClient.PageHandler.getCurrPageUIElemByName('login_cursor').reset();
self.setCurrPage(NPGClient.LOGIN.NAME);
break;
default:
break;
}
},
//
getCurrPageUIElems: function() {
var self = this;
return self.getPageByName(self.currPage).getUIElems();
},
//
getCurrPageUIElemByName: function(name) {
var self = this;
if (self.pages.length > 0) {
for (var i = 0; i < self.pages.length; i++) {
if (self.pages[i].name == self.currPage) {
return self.pages[i].getUIElemByName(name);
}
}
}
return undefined;
},
// @need rework
getUIElemFromPage: function(elem, page) {
var self = this;
if (self.pages.length > 0) {
for (var i = 0; i < self.pages.length; i++) {
if (page == self.pages[i].name) {
// return self.pages[i];
}
}
}
return undefined;
},
//
getPageByName: function(name) {
var self = this;
if (self.pages.length > 0) {
for (var i = 0; i < self.pages.length; i++) {
if (name == self.pages[i].name) return self.pages[i];
}
}
return undefined;
},
// create login page
createLoginPage: function() {
//
console.log('[NPGClient] Creating Login Page');
var self = this;
var p = new NPGClient.AppPage(NPGClient.LOGIN.NAME);
// Title label
p.addUIObject(new NPGClient.UILabel('login_title', NPGClient.LOGIN.TITLE));
// name input
p.addUIObject(new NPGClient.UIInputText('login_input', NPGClient.LOGIN.INPUT));
// Server status
p.addUIObject(new NPGClient.UIStatusText('login_servstat', NPGClient.LOGIN.SERVSTATUS));
// test cursor
p.addUIObject(new NPGClient.UICursor('login_cursor', NPGClient.LOGIN.CURSOR));
//
self.pages.push(p);
},
// create login page
createStartMenuPage: function() {
//
console.log('[NPGClient] Creating Start Menu Page');
var self = this;
var p = new NPGClient.AppPage(NPGClient.STARTMENU.NAME);
// Title label
p.addUIObject(new NPGClient.UILabel('login_title', NPGClient.STARTMENU.TITLE));
// Start Menu
// Server Players and Games status
//
self.pages.push(p);
},
};