mirror of
https://github.com/curioustorvald/tsvm.git
synced 2026-06-09 14:44:05 +09:00
tui wip
This commit is contained in:
@@ -69,7 +69,7 @@ class TextList extends UIItem {
|
|||||||
this.selection = (isNaN(selection)) ? 0 : selection|0;
|
this.selection = (isNaN(selection)) ? 0 : selection|0;
|
||||||
this.visible = true;
|
this.visible = true;
|
||||||
this.scroll = 0;
|
this.scroll = 0;
|
||||||
this.keyLatched = false;
|
this.redrawReq = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
getInternalHeight() {
|
getInternalHeight() {
|
||||||
@@ -100,29 +100,28 @@ class TextList extends UIItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
cursorUp() {
|
||||||
let keys = con.poll_keys();
|
if ((this.selection + this.scroll) > 0) {
|
||||||
let redraw = false;
|
|
||||||
|
|
||||||
// un-latch
|
|
||||||
if (this.keyLatched && keys[0] == 0) {
|
|
||||||
this.keyLatched = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// up
|
|
||||||
if (!this.keyLatched && keys[0] == 19 && (this.selection + this.scroll) > 0) {
|
|
||||||
this.selection -= 1;
|
this.selection -= 1;
|
||||||
redraw = true;
|
this.redrawReq = true;
|
||||||
}
|
|
||||||
// down
|
|
||||||
else if (!this.keyLatched && keys[0] == 20 && (this.selection + this.scroll) < this.item.length - 1) {
|
|
||||||
this.selection += 1;
|
|
||||||
redraw = true;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// finally update key latched state
|
cursorDown() {
|
||||||
this.keyLatched = keys[0] != 0;
|
if ((this.selection + this.scroll) < this.item.length - 1) {
|
||||||
return redraw;
|
this.selection += 1;
|
||||||
|
this.redrawReq = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getSelection() {
|
||||||
|
return {index: (this.scroll + this.selection), item: this.item[this.scroll + this.selection]};
|
||||||
|
}
|
||||||
|
|
||||||
|
update() {
|
||||||
|
let r = this.redrawReq;
|
||||||
|
this.redrawReq = false;
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,46 +134,38 @@ class Demo extends SimpleScreen {
|
|||||||
mainCanvas.selector = new TextList(40, 31, ["The", "Quick", "Brown", "Fox", "Jumps"]);
|
mainCanvas.selector = new TextList(40, 31, ["The", "Quick", "Brown", "Fox", "Jumps"]);
|
||||||
|
|
||||||
mainCanvas.redraw = () => {
|
mainCanvas.redraw = () => {
|
||||||
mainCanvas.selector.redraw(1,1);
|
mainCanvas.selector.redraw(1,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ballX = 1 + ((Math.random() * this.termWidth)|0);
|
this.keyLatched = false;
|
||||||
this.ballY = 1 + ((Math.random() * (this.termHeight-1))|0)
|
|
||||||
this.ballMomentumX = (Math.random() < 0.5) ? -1 : 1;
|
|
||||||
this.ballMomentumY = (Math.random() < 0.5) ? -1 : 1;
|
|
||||||
this.collision = 0;
|
|
||||||
|
|
||||||
mainCanvas.update = () => {
|
mainCanvas.update = () => {
|
||||||
// erase a track
|
let keys = con.poll_keys();
|
||||||
/*con.mvaddch(this.ballY, this.ballX, 0);
|
let redraw = false;
|
||||||
|
|
||||||
// collide
|
// un-latch
|
||||||
if (this.ballX <= 1) this.ballMomentumX = 1;
|
if (this.keyLatched && keys[0] == 0) {
|
||||||
if (this.ballX >= this.termWidth) this.ballMomentumX = -1;
|
this.keyLatched = false;
|
||||||
if (this.ballY <= 2) this.ballMomentumY = 1;
|
|
||||||
if (this.ballY >= this.termHeight) this.ballMomentumY = -1;
|
|
||||||
|
|
||||||
// collision counter
|
|
||||||
if (this.ballX <= 1 || this.ballX >= this.termWidth || this.ballY <= 2 || this.ballY >= this.termHeight) {
|
|
||||||
this.collision += 1;
|
|
||||||
this.title = "Ctrl-C to exit - "+this.collision;
|
|
||||||
this.drawTitlebar();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// move
|
// up
|
||||||
this.ballX += this.ballMomentumX;
|
if (!this.keyLatched && keys[0] == 19) {
|
||||||
this.ballY += this.ballMomentumY;
|
mainCanvas.selector.cursorUp();
|
||||||
|
}
|
||||||
// draw
|
// down
|
||||||
con.mvaddch(this.ballY, this.ballX, 2);*/
|
else if (!this.keyLatched && keys[0] == 20) {
|
||||||
//sys.spin();sys.spin();sys.spin();sys.spin();
|
mainCanvas.selector.cursorDown();
|
||||||
|
|
||||||
|
|
||||||
if (mainCanvas.selector.update()) {
|
|
||||||
mainCanvas.selector.redraw(1,1);
|
|
||||||
}
|
}
|
||||||
con.mvaddch(20,20); print("TEXT");
|
|
||||||
|
|
||||||
|
if (mainCanvas.selector.update())
|
||||||
|
mainCanvas.selector.redraw(1,2);
|
||||||
|
|
||||||
|
if (this.keyLatched && keys[0] == 66) {
|
||||||
|
con.mvaddch(20,20); print("SEL:"+mainCanvas.selector.getSelection().item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// finally update key latched state
|
||||||
|
this.keyLatched = keys[0] != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user