summaryrefslogtreecommitdiff
path: root/src/main/java/net/tylermurphy/Minecraft/Input/CommandInput.java
blob: 85540ab74d8f7e6e473075d2504b79ccb493c26f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package net.tylermurphy.Minecraft.Input;

import org.lwjgl.glfw.GLFW;

import net.tylermurphy.Minecraft.Command.CommandHandler;
import net.tylermurphy.Minecraft.Scene.World;

import static net.tylermurphy.Minecraft.UI.UIMaster.*;

public class CommandInput extends IInput {
	
	public void keyPressed(int keyCode) {
		switch(keyCode) {
			case GLFW.GLFW_KEY_ESCAPE: 
				Input.setEnabled("CommandInput", false);
				Input.setEnabled("GameInput", true);
				bindUI(3);
				setEnabled(false);
				getText("commandBar").setText("");
				World.player.isPaused = false;
				break;
			case GLFW.GLFW_KEY_BACKSPACE: 
				bindUI(3);
				String currentText = getText("commandBar").getTextString();
				if(currentText.length() > 0)
					getText("commandBar").setText(currentText.substring(0,currentText.length()-1));
				break;
			case GLFW.GLFW_KEY_ENTER:
				bindUI(3);
				setEnabled(false);
				
				String command = getText("commandBar").getTextString();
				CommandHandler.handleCommand(command);
				
				Input.setEnabled("CommandInput", false);
				Input.setEnabled("GameInput", true);
				getText("commandBar").setText("");
				World.player.isPaused = false;
				break;
		}
	}

	public void keyRelesed(int keyCode) {}

	public void mousePressed(int mouseButton) {}

	public void mouseRelesed(int mouseButton) {}

	public void charAction(char c) {
		bindUI(3);
		String currentText = getText("commandBar").getTextString();
		
		currentText += c;
		getText("commandBar").setText(currentText);
	}

}