Merge remote-tracking branch 'origin/master'

This commit is contained in:
Anuken
2018-03-28 00:22:25 -04:00
2 changed files with 17 additions and 16 deletions

View File

@@ -26,8 +26,9 @@ 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_history_prev", Input.UP,
"chat_scroll_down", Input.DOWN, "chat_history_next", Input.DOWN,
"chat_scroll", new Axis(Input.SCROLL),
"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,
@@ -55,8 +56,9 @@ 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_history_prev", Input.UP,
"chat_scroll_down", Input.DOWN, "chat_history_next", Input.DOWN,
"chat_scroll", new Axis(Input.SCROLL),
"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,

View File

@@ -19,8 +19,7 @@ import io.anuke.ucore.scene.ui.Label.LabelStyle;
import io.anuke.ucore.scene.ui.TextField; 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.Mathf;
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;
@@ -30,7 +29,7 @@ public class ChatFragment extends Table implements Fragment{
private final static int messagesShown = 10; private final static int messagesShown = 10;
private final static int maxLength = 150; private final static int maxLength = 150;
private Array<ChatMessage> messages = new Array<>(); private Array<ChatMessage> messages = new Array<>();
private float fadetime, lastfade; private float fadetime;
private boolean chatOpen = false; private boolean chatOpen = false;
private TextField chatfield; private TextField chatfield;
private Label fieldlabel = new Label(">"); private Label fieldlabel = new Label(">");
@@ -42,6 +41,7 @@ public class ChatFragment extends Table implements Fragment{
private float textspacing = Unit.dp.scl(10); private float textspacing = Unit.dp.scl(10);
private Array<String> history = new Array<String>(); private Array<String> history = new Array<String>();
private int historyPos = 0; private int historyPos = 0;
private int scrollPos = 0;
public ChatFragment(){ public ChatFragment(){
super(); super();
@@ -62,15 +62,16 @@ public class ChatFragment extends Table implements Fragment{
} }
if (chatOpen) { if (chatOpen) {
if (Inputs.keyTap("chat_scroll_up") && historyPos < history.size - 1) { if (Inputs.keyTap("chat_history_prev") && historyPos < history.size - 1) {
if (historyPos == 0) history.set(0, chatfield.getText()); if (historyPos == 0) history.set(0, chatfield.getText());
historyPos++; historyPos++;
updateChat(); updateChat();
} }
if (Inputs.keyTap("chat_scroll_down") && historyPos > 0) { if (Inputs.keyTap("chat_history_next") && historyPos > 0) {
historyPos--; historyPos--;
updateChat(); updateChat();
} }
scrollPos = (int)Mathf.clamp(scrollPos + Inputs.getAxis("chat_scroll"), 0, Math.max(0, messages.size - messagesShown));
} }
}); });
@@ -134,16 +135,16 @@ public class ChatFragment extends Table implements Fragment{
batch.setColor(shadowColor); batch.setColor(shadowColor);
float theight = offsety + spacing + getMarginBottom(); float theight = offsety + spacing + getMarginBottom();
for(int i = 0; i < messagesShown && i < messages.size && i < fadetime; i ++){ for(int i = scrollPos; i < messages.size && i < messagesShown + scrollPos && (i < fadetime || chatOpen); i++){
layout.setText(font, messages.get(i).formattedMessage, Color.WHITE, textWidth, Align.bottomLeft, true); layout.setText(font, messages.get(i).formattedMessage, Color.WHITE, textWidth, Align.bottomLeft, true);
theight += layout.height+textspacing; theight += layout.height+textspacing;
if(i == 0) theight -= textspacing+1; if(i - scrollPos == 0) theight -= textspacing+1;
font.getCache().clear(); font.getCache().clear();
font.getCache().addText(messages.get(i).formattedMessage, fontoffsetx + offsetx, offsety + theight, textWidth, Align.bottomLeft, true); font.getCache().addText(messages.get(i).formattedMessage, fontoffsetx + offsetx, offsety + theight, textWidth, Align.bottomLeft, true);
if(fadetime-i < 1f && fadetime-i >= 0f){ if(!chatOpen && fadetime-i < 1f && fadetime-i >= 0f){
font.getCache().setAlphas(fadetime-i); font.getCache().setAlphas(fadetime-i);
batch.setColor(0, 0, 0, shadowColor.a*(fadetime-i)); batch.setColor(0, 0, 0, shadowColor.a*(fadetime-i));
} }
@@ -163,10 +164,10 @@ public class ChatFragment extends Table implements Fragment{
private void sendMessage(){ private void sendMessage(){
String message = chatfield.getText(); String message = chatfield.getText();
clearChatInput(); clearChatInput();
history.insert(1, message);
if(message.replaceAll(" ", "").isEmpty()) return; if(message.replaceAll(" ", "").isEmpty()) return;
history.insert(1, message);
NetEvents.handleSendMessage(message); NetEvents.handleSendMessage(message);
} }
@@ -176,12 +177,10 @@ public class ChatFragment extends Table implements Fragment{
scene.setKeyboardFocus(chatfield); scene.setKeyboardFocus(chatfield);
chatfield.fireClick(); chatfield.fireClick();
chatOpen = !chatOpen; chatOpen = !chatOpen;
lastfade = fadetime;
fadetime = messagesShown + 1;
}else{ }else{
scene.setKeyboardFocus(null); scene.setKeyboardFocus(null);
chatOpen = !chatOpen; chatOpen = !chatOpen;
fadetime = lastfade; scrollPos = 0;
sendMessage(); sendMessage();
} }
} }