Skip to content

Commit 27521c6

Browse files
committed
Making things easier on the user
1 parent cb2d43e commit 27521c6

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Console Java Engine - Version 0.1.15-Talos
1+
# Console Java Engine - Version 0.1.15-Jyggalag
22
[![](https://jitpack.io/v/CaptainSly/ConsoleJavaEngine.svg)](https://jitpack.io/#CaptainSly/ConsoleJavaEngine)
33

44
The Console Java Engine is based off of JavidX9's PixelGameEngine.

src/main/java/com/spireprod/cje/core/input/Input.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,5 @@ private KeyStroke normalize(KeyStroke stroke) {
6767
}
6868
return new KeyStroke(stroke.getKeyType());
6969
}
70+
7071
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.spireprod.cje.core.ui;
2+
3+
import com.googlecode.lanterna.input.KeyType;
4+
import com.spireprod.cje.core.ConsoleRenderer;
5+
import com.spireprod.cje.core.input.Input;
6+
7+
public class TextUI {
8+
public int selectedIndex = 0;
9+
public int totalItems = 0;
10+
11+
public void reset() {
12+
totalItems = 0;
13+
}
14+
15+
public boolean selectable(String label, ConsoleRenderer renderer, Input input, int x, int y) {
16+
boolean selected = (selectedIndex == totalItems);
17+
String display = selected ? "> " + label : " " + label;
18+
19+
renderer.writeString(display, x, y);
20+
21+
totalItems++;
22+
return selected && input.isKeyPressed(KeyType.Enter);
23+
}
24+
25+
public void handleInput(Input input) {
26+
if (input.isKeyPressed(KeyType.ArrowUp))
27+
selectedIndex--;
28+
if (input.isKeyPressed(KeyType.ArrowDown))
29+
selectedIndex++;
30+
31+
selectedIndex = Math.floorMod(selectedIndex, totalItems);
32+
}
33+
}

0 commit comments

Comments
 (0)