From 12686460c17f4dde21e90d01e3302358b7d56368 Mon Sep 17 00:00:00 2001 From: iczero Date: Sat, 17 Mar 2018 12:12:41 -0700 Subject: [PATCH 1/2] Add chat history --- .../mindustry/ui/fragments/ChatFragment.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/core/src/io/anuke/mindustry/ui/fragments/ChatFragment.java b/core/src/io/anuke/mindustry/ui/fragments/ChatFragment.java index 6ef83b3c89..8286d5c4ef 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/ChatFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/ChatFragment.java @@ -20,6 +20,7 @@ import io.anuke.ucore.scene.ui.TextField; import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.ucore.scene.ui.layout.Unit; import io.anuke.ucore.util.Log; +import java.util.Arrays; import static io.anuke.mindustry.Vars.state; import static io.anuke.ucore.core.Core.scene; @@ -39,6 +40,8 @@ public class ChatFragment extends Table implements Fragment{ private float textWidth = Unit.dp.scl(600); private Color shadowColor = new Color(0, 0, 0, 0.4f); private float textspacing = Unit.dp.scl(10); + private Array history = new Array(); + private int historyPos = 0; public ChatFragment(){ super(); @@ -57,8 +60,23 @@ public class ChatFragment extends Table implements Fragment{ if(Net.active() && Inputs.keyTap("chat")){ toggle(); } + + if (chatOpen) { + // up arrow key + if (Inputs.keyTap(19) && historyPos < history.size - 1) { + if (historyPos == 0) history.set(0, chatfield.getText()); + historyPos++; + updateChat(); + } + // down arrow key + if (Inputs.keyTap(20) && historyPos > 0) { + historyPos--; + updateChat(); + } + } }); + history.insert(0, ""); setup(); } @@ -69,6 +87,8 @@ public class ChatFragment extends Table implements Fragment{ public void clearMessages(){ messages.clear(); + history.clear(); + history.insert(0, ""); } private void setup(){ @@ -144,7 +164,8 @@ public class ChatFragment extends Table implements Fragment{ private void sendMessage(){ String message = chatfield.getText(); - chatfield.clearText(); + clearChatInput(); + history.insert(1, message); if(message.replaceAll(" ", "").isEmpty()) return; @@ -170,6 +191,17 @@ public class ChatFragment extends Table implements Fragment{ public void hide(){ scene.setKeyboardFocus(null); chatOpen = false; + clearChatInput(); + } + + public void updateChat() { + chatfield.setText(history.get(historyPos)); + chatfield.setCursorPosition(chatfield.getText().length()); + } + + public void clearChatInput() { + historyPos = 0; + history.set(0, ""); chatfield.setText(""); } From 2eae47342955cf439a5af7432ab8f2f6bf52af0e Mon Sep 17 00:00:00 2001 From: iczero Date: Sat, 17 Mar 2018 17:08:02 -0700 Subject: [PATCH 2/2] Add chat_scroll_up and chat_scroll_down to keybinds --- core/src/io/anuke/mindustry/input/DefaultKeybinds.java | 4 ++++ core/src/io/anuke/mindustry/ui/fragments/ChatFragment.java | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/io/anuke/mindustry/input/DefaultKeybinds.java b/core/src/io/anuke/mindustry/input/DefaultKeybinds.java index 7140b8269b..72608d7d20 100644 --- a/core/src/io/anuke/mindustry/input/DefaultKeybinds.java +++ b/core/src/io/anuke/mindustry/input/DefaultKeybinds.java @@ -26,6 +26,8 @@ public class DefaultKeybinds { "block_info", Input.CONTROL_LEFT, "player_list", Input.TAB, "chat", Input.ENTER, + "chat_scroll_up", Input.UP, + "chat_scroll_down", Input.DOWN, "console", Input.GRAVE, "weapon_1", Input.NUM_1, "weapon_2", Input.NUM_2, @@ -53,6 +55,8 @@ public class DefaultKeybinds { "rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B), "player_list", Input.CONTROLLER_START, "chat", Input.ENTER, + "chat_scroll_up", Input.UP, + "chat_scroll_down", Input.DOWN, "console", Input.GRAVE, "weapon_1", Input.NUM_1, "weapon_2", Input.NUM_2, diff --git a/core/src/io/anuke/mindustry/ui/fragments/ChatFragment.java b/core/src/io/anuke/mindustry/ui/fragments/ChatFragment.java index 8286d5c4ef..2f7f5d71c4 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/ChatFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/ChatFragment.java @@ -62,14 +62,12 @@ public class ChatFragment extends Table implements Fragment{ } if (chatOpen) { - // up arrow key - if (Inputs.keyTap(19) && historyPos < history.size - 1) { + if (Inputs.keyTap("chat_scroll_up") && historyPos < history.size - 1) { if (historyPos == 0) history.set(0, chatfield.getText()); historyPos++; updateChat(); } - // down arrow key - if (Inputs.keyTap(20) && historyPos > 0) { + if (Inputs.keyTap("chat_scroll_down") && historyPos > 0) { historyPos--; updateChat(); }