Display current character for control
parent
78b6c197e8
commit
070e5eeb2a
|
@ -7,8 +7,8 @@ public class Middleware {
|
||||||
|
|
||||||
public static ArrayList<Integer> allOldCode = new ArrayList<Integer>();
|
public static ArrayList<Integer> allOldCode = new ArrayList<Integer>();
|
||||||
public static ArrayList<Integer> allNewCode = new ArrayList<Integer>();
|
public static ArrayList<Integer> allNewCode = new ArrayList<Integer>();
|
||||||
private final int oldCode;
|
public final int oldCode;
|
||||||
private final int newCode;
|
public final int newCode;
|
||||||
public boolean isDestroyed = false;
|
public boolean isDestroyed = false;
|
||||||
|
|
||||||
Middleware(int oldCode, int newCode) {
|
Middleware(int oldCode, int newCode) {
|
||||||
|
@ -48,7 +48,7 @@ public class Middleware {
|
||||||
// duck typing equals check
|
// duck typing equals check
|
||||||
// if it has the same oldCode, assume it is the same; this is because oldCodes should be unique
|
// if it has the same oldCode, assume it is the same; this is because oldCodes should be unique
|
||||||
// also makes some corner cases easier
|
// also makes some corner cases easier
|
||||||
return this.oldCode == m.oldCode;
|
return this.oldCode == m.oldCode || this.newCode == m.newCode;
|
||||||
} catch (ClassCastException e) {
|
} catch (ClassCastException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,13 +105,22 @@ public class SettingPanel extends JPanel implements Runnable, KeyListener{
|
||||||
|
|
||||||
//call the draw methods in each class to update positions as things move
|
//call the draw methods in each class to update positions as things move
|
||||||
public void draw(Graphics g, int playerFrame, int enemyFrame){
|
public void draw(Graphics g, int playerFrame, int enemyFrame){
|
||||||
|
String oldText;
|
||||||
|
int middlewareIndex;
|
||||||
background.draw(g);
|
background.draw(g);
|
||||||
title.draw(g,null, Color.black);
|
title.draw(g,null, Color.black);
|
||||||
for (TextBox t: textBoxArray) {
|
for (TextBox t: textBoxArray) {
|
||||||
|
oldText = t.text;
|
||||||
|
middlewareIndex = GamePanel.middlewareArray.indexOf(new Middleware(Integer.parseInt(t.id), -1));
|
||||||
|
t.text += "(" + (middlewareIndex > -1 ? (char)GamePanel.middlewareArray.get(middlewareIndex).newCode:(char)Integer.parseInt(t.id)) + ")";
|
||||||
t.draw(g, null, Color.cyan);
|
t.draw(g, null, Color.cyan);
|
||||||
|
t.text = oldText;
|
||||||
}
|
}
|
||||||
|
oldText = textBoxArray.get(currentBox).text;
|
||||||
|
middlewareIndex = GamePanel.middlewareArray.indexOf(new Middleware(Integer.parseInt(textBoxArray.get(currentBox).id), -1));
|
||||||
|
textBoxArray.get(currentBox).text += "(" + (middlewareIndex > -1 ? (char)GamePanel.middlewareArray.get(middlewareIndex).newCode:(char)Integer.parseInt(textBoxArray.get(currentBox).id)) + ")";
|
||||||
textBoxArray.get(currentBox).draw(g, Color.gray, Color.blue);
|
textBoxArray.get(currentBox).draw(g, Color.gray, Color.blue);
|
||||||
|
textBoxArray.get(currentBox).text = oldText;
|
||||||
if (waitForKey) {
|
if (waitForKey) {
|
||||||
g.setColor(new Color(255, 255, 255, 100));
|
g.setColor(new Color(255, 255, 255, 100));
|
||||||
g.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
|
g.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
|
||||||
|
@ -161,11 +170,15 @@ public class SettingPanel extends JPanel implements Runnable, KeyListener{
|
||||||
|
|
||||||
public void changeKeyBind() {
|
public void changeKeyBind() {
|
||||||
if (lastKeyCode != -1) {
|
if (lastKeyCode != -1) {
|
||||||
System.out.println(lastKeyCode);
|
boolean canRemove = true;
|
||||||
|
while (canRemove) {
|
||||||
// newCode is -1 as it does not matter
|
// newCode is -1 as it does not matter
|
||||||
GamePanel.middlewareArray.remove(new Middleware(Integer.parseInt(textBoxArray.get(currentBox).id), -1));
|
canRemove = GamePanel.middlewareArray.remove(new Middleware(Integer.parseInt(textBoxArray.get(currentBox).id), lastKeyCode));
|
||||||
|
}
|
||||||
|
// add actual middleware
|
||||||
GamePanel.middlewareArray.add(new Middleware(Integer.parseInt(textBoxArray.get(currentBox).id), lastKeyCode));
|
GamePanel.middlewareArray.add(new Middleware(Integer.parseInt(textBoxArray.get(currentBox).id), lastKeyCode));
|
||||||
System.out.println(GamePanel.middlewareArray.get(0));
|
// add middleware to redirect default key
|
||||||
|
GamePanel.middlewareArray.add(new Middleware(-1, Integer.parseInt(textBoxArray.get(currentBox).id)));
|
||||||
// lastKeyCode is set to -1 to prevent endless execution
|
// lastKeyCode is set to -1 to prevent endless execution
|
||||||
lastKeyCode = -1;
|
lastKeyCode = -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ public class TextBox extends Rectangle {
|
||||||
int xWidth, yHeight;
|
int xWidth, yHeight;
|
||||||
int newX, newY;
|
int newX, newY;
|
||||||
Font font;
|
Font font;
|
||||||
String text;
|
public String text;
|
||||||
public final String id;
|
public final String id;
|
||||||
|
|
||||||
public TextBox(int y, int xWidth, int yHeight, int totalWidth, Font font, String text, String id) {
|
public TextBox(int y, int xWidth, int yHeight, int totalWidth, Font font, String text, String id) {
|
||||||
|
|
Loading…
Reference in New Issue