94 lines
3.1 KiB
JavaScript
94 lines
3.1 KiB
JavaScript
const { Color, Point } = require("telidon");
|
||
const Page = require("./page.js");
|
||
|
||
module.exports = class Menu extends Page {
|
||
globalMenu = {
|
||
"#": "./views/mainmenu.js",
|
||
"#8378": "./views/test.js",
|
||
"*": ()=>this.gotoPrev(),
|
||
"*69": null,
|
||
"*911": ()=>{throw new Error("Écran de la mort qui tue causé par l'utilisateur")},
|
||
}
|
||
|
||
selection = "";
|
||
menu = {};
|
||
bgColor = new Color(0,0,0);
|
||
fgColor = new Color(1,1,1);
|
||
position = new Point(0.836,0);
|
||
maxLength = 5;
|
||
|
||
constructor(naplps) {
|
||
super(naplps);
|
||
}
|
||
|
||
start() {
|
||
//this.naplps.pointSetAbs(this.position);
|
||
//this.naplps.textMode();
|
||
}
|
||
|
||
data(byte) {
|
||
if(byte == 13) {
|
||
if(Object.keys(this.globalMenu).includes(this.selection))
|
||
{
|
||
if(typeof this.globalMenu[this.selection] == "function")
|
||
this.globalMenu[this.selection]();
|
||
else
|
||
this.goto(this.globalMenu[this.selection]);
|
||
}
|
||
else if(Object.keys(this.menu).includes(this.selection))
|
||
{
|
||
if(typeof this.menu[this.selection] == "function")
|
||
this.menu[this.selection]();
|
||
else
|
||
this.goto(this.menu[this.selection]);
|
||
}
|
||
else {
|
||
this.naplps.bell();
|
||
if(this.selection.length > 0){
|
||
this.naplps.pdiMode();
|
||
this.naplps.pointSetAbs(this.position);
|
||
this.naplps.setColor(this.bgColor);
|
||
this.naplps.textMode();
|
||
this.naplps.write(this.selection);
|
||
/*this.naplps.pdiMode();
|
||
this.naplps.pointSetAbs(this.position);
|
||
this.naplps.setColor(this.fgColor);
|
||
this.naplps.textMode();*/
|
||
this.selection = "";
|
||
}
|
||
}
|
||
}
|
||
if((byte >= 48 && byte <= 57 && this.selection.length < this.maxLength) ||
|
||
((byte == 35 || byte == 42) && this.selection.length == 0))
|
||
{
|
||
this.naplps.pdiMode();
|
||
this.naplps.pointSetAbs(new Point(this.position.x + this.naplps.options.characterSize.x * this.selection.length, this.position.y));
|
||
this.selection += String.fromCharCode(byte);
|
||
this.naplps.textMode();
|
||
this.naplps.writeBytes(byte);
|
||
this.naplps.pdiMode();
|
||
}
|
||
if(byte == 8)
|
||
{
|
||
if(this.selection.length > 0)
|
||
{
|
||
this.naplps.pdiMode();
|
||
this.naplps.pointSetAbs(this.position);
|
||
this.naplps.setColor(this.bgColor);
|
||
this.naplps.text(this.selection);
|
||
this.naplps.pointSetAbs(this.position);
|
||
this.naplps.setColor(this.fgColor);
|
||
this.selection = this.selection.slice(0,-1);
|
||
this.naplps.text(this.selection);
|
||
}
|
||
else
|
||
{
|
||
this.naplps.bell();
|
||
}
|
||
}
|
||
// TODO: if arrow keys, esc
|
||
}
|
||
|
||
leave() {
|
||
}
|
||
} |