mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-08-04 08:59:33 +07:00
Merge pull request #103 from valoran-labs/chat-history
Add chat history
This commit is contained in:
@ -26,6 +26,8 @@ public class DefaultKeybinds {
|
|||||||
"block_info", Input.CONTROL_LEFT,
|
"block_info", Input.CONTROL_LEFT,
|
||||||
"player_list", Input.TAB,
|
"player_list", Input.TAB,
|
||||||
"chat", Input.ENTER,
|
"chat", Input.ENTER,
|
||||||
|
"chat_scroll_up", Input.UP,
|
||||||
|
"chat_scroll_down", Input.DOWN,
|
||||||
"console", Input.GRAVE,
|
"console", Input.GRAVE,
|
||||||
"weapon_1", Input.NUM_1,
|
"weapon_1", Input.NUM_1,
|
||||||
"weapon_2", Input.NUM_2,
|
"weapon_2", Input.NUM_2,
|
||||||
@ -53,6 +55,8 @@ public class DefaultKeybinds {
|
|||||||
"rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B),
|
"rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B),
|
||||||
"player_list", Input.CONTROLLER_START,
|
"player_list", Input.CONTROLLER_START,
|
||||||
"chat", Input.ENTER,
|
"chat", Input.ENTER,
|
||||||
|
"chat_scroll_up", Input.UP,
|
||||||
|
"chat_scroll_down", Input.DOWN,
|
||||||
"console", Input.GRAVE,
|
"console", Input.GRAVE,
|
||||||
"weapon_1", Input.NUM_1,
|
"weapon_1", Input.NUM_1,
|
||||||
"weapon_2", Input.NUM_2,
|
"weapon_2", Input.NUM_2,
|
||||||
|
@ -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.Table;
|
||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||||
import io.anuke.ucore.util.Log;
|
import io.anuke.ucore.util.Log;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.state;
|
import static io.anuke.mindustry.Vars.state;
|
||||||
import static io.anuke.ucore.core.Core.scene;
|
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 float textWidth = Unit.dp.scl(600);
|
||||||
private Color shadowColor = new Color(0, 0, 0, 0.4f);
|
private Color shadowColor = new Color(0, 0, 0, 0.4f);
|
||||||
private float textspacing = Unit.dp.scl(10);
|
private float textspacing = Unit.dp.scl(10);
|
||||||
|
private Array<String> history = new Array<String>();
|
||||||
|
private int historyPos = 0;
|
||||||
|
|
||||||
public ChatFragment(){
|
public ChatFragment(){
|
||||||
super();
|
super();
|
||||||
@ -57,8 +60,21 @@ public class ChatFragment extends Table implements Fragment{
|
|||||||
if(Net.active() && Inputs.keyTap("chat")){
|
if(Net.active() && Inputs.keyTap("chat")){
|
||||||
toggle();
|
toggle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (chatOpen) {
|
||||||
|
if (Inputs.keyTap("chat_scroll_up") && historyPos < history.size - 1) {
|
||||||
|
if (historyPos == 0) history.set(0, chatfield.getText());
|
||||||
|
historyPos++;
|
||||||
|
updateChat();
|
||||||
|
}
|
||||||
|
if (Inputs.keyTap("chat_scroll_down") && historyPos > 0) {
|
||||||
|
historyPos--;
|
||||||
|
updateChat();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
history.insert(0, "");
|
||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +85,8 @@ public class ChatFragment extends Table implements Fragment{
|
|||||||
|
|
||||||
public void clearMessages(){
|
public void clearMessages(){
|
||||||
messages.clear();
|
messages.clear();
|
||||||
|
history.clear();
|
||||||
|
history.insert(0, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setup(){
|
private void setup(){
|
||||||
@ -144,7 +162,8 @@ public class ChatFragment extends Table implements Fragment{
|
|||||||
|
|
||||||
private void sendMessage(){
|
private void sendMessage(){
|
||||||
String message = chatfield.getText();
|
String message = chatfield.getText();
|
||||||
chatfield.clearText();
|
clearChatInput();
|
||||||
|
history.insert(1, message);
|
||||||
|
|
||||||
if(message.replaceAll(" ", "").isEmpty()) return;
|
if(message.replaceAll(" ", "").isEmpty()) return;
|
||||||
|
|
||||||
@ -170,6 +189,17 @@ public class ChatFragment extends Table implements Fragment{
|
|||||||
public void hide(){
|
public void hide(){
|
||||||
scene.setKeyboardFocus(null);
|
scene.setKeyboardFocus(null);
|
||||||
chatOpen = false;
|
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("");
|
chatfield.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user