[QoL] Chat modes (#3869)
Credits: Remint32 (idea); sk7725 (korean i18n); Volas171 (spanish i18n).
This commit is contained in:
committed by
GitHub
parent
1e8621d9d4
commit
43757a247e
@@ -917,6 +917,7 @@ keybind.toggle_menus.name = Toggle Menus
|
|||||||
keybind.chat_history_prev.name = Chat History Prev
|
keybind.chat_history_prev.name = Chat History Prev
|
||||||
keybind.chat_history_next.name = Chat History Next
|
keybind.chat_history_next.name = Chat History Next
|
||||||
keybind.chat_scroll.name = Chat Scroll
|
keybind.chat_scroll.name = Chat Scroll
|
||||||
|
keybind.chat_mode.name = Change Chat Mode
|
||||||
keybind.drop_unit.name = Drop Unit
|
keybind.drop_unit.name = Drop Unit
|
||||||
keybind.zoom_minimap.name = Zoom Minimap
|
keybind.zoom_minimap.name = Zoom Minimap
|
||||||
mode.help.title = Description of modes
|
mode.help.title = Description of modes
|
||||||
|
|||||||
@@ -915,6 +915,7 @@ keybind.toggle_menus.name = Ocultar menús
|
|||||||
keybind.chat_history_prev.name = Historial de chat - Anterior
|
keybind.chat_history_prev.name = Historial de chat - Anterior
|
||||||
keybind.chat_history_next.name = Historial de chat - Siguiente
|
keybind.chat_history_next.name = Historial de chat - Siguiente
|
||||||
keybind.chat_scroll.name = Desplazar el chat
|
keybind.chat_scroll.name = Desplazar el chat
|
||||||
|
keybind.chat_mode.name = Cambiar modo de chat
|
||||||
keybind.drop_unit.name = Soltar unidad
|
keybind.drop_unit.name = Soltar unidad
|
||||||
keybind.zoom_minimap.name = Zoom del minimapa
|
keybind.zoom_minimap.name = Zoom del minimapa
|
||||||
mode.help.title = Descripción de modos
|
mode.help.title = Descripción de modos
|
||||||
|
|||||||
@@ -915,6 +915,7 @@ keybind.toggle_menus.name = 메뉴 보이기/숨기기
|
|||||||
keybind.chat_history_prev.name = 이전 채팅 기록
|
keybind.chat_history_prev.name = 이전 채팅 기록
|
||||||
keybind.chat_history_next.name = 다음 채팅 기록
|
keybind.chat_history_next.name = 다음 채팅 기록
|
||||||
keybind.chat_scroll.name = 채팅 스크롤
|
keybind.chat_scroll.name = 채팅 스크롤
|
||||||
|
keybind.chat_mode = 대화 대상 변경
|
||||||
keybind.drop_unit.name = 유닛 떨구기
|
keybind.drop_unit.name = 유닛 떨구기
|
||||||
keybind.zoom_minimap.name = 미니맵 확대
|
keybind.zoom_minimap.name = 미니맵 확대
|
||||||
mode.help.title = 모드 설명
|
mode.help.title = 모드 설명
|
||||||
|
|||||||
@@ -918,6 +918,7 @@ keybind.toggle_menus.name = Переключение меню
|
|||||||
keybind.chat_history_prev.name = Пред. история чата
|
keybind.chat_history_prev.name = Пред. история чата
|
||||||
keybind.chat_history_next.name = След. история чата
|
keybind.chat_history_next.name = След. история чата
|
||||||
keybind.chat_scroll.name = Прокрутка чата
|
keybind.chat_scroll.name = Прокрутка чата
|
||||||
|
keybind.chat_mode.name = Изменить режим чата
|
||||||
keybind.drop_unit.name = Сбросить боев. ед.
|
keybind.drop_unit.name = Сбросить боев. ед.
|
||||||
keybind.zoom_minimap.name = Масштабировать мини-карту
|
keybind.zoom_minimap.name = Масштабировать мини-карту
|
||||||
mode.help.title = Описание режимов
|
mode.help.title = Описание режимов
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ public enum Binding implements KeyBind{
|
|||||||
chat_history_prev(KeyCode.up),
|
chat_history_prev(KeyCode.up),
|
||||||
chat_history_next(KeyCode.down),
|
chat_history_next(KeyCode.down),
|
||||||
chat_scroll(new Axis(KeyCode.scroll)),
|
chat_scroll(new Axis(KeyCode.scroll)),
|
||||||
|
chat_mode(KeyCode.tab),
|
||||||
console(KeyCode.f8),
|
console(KeyCode.f8),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package mindustry.ui.fragments;
|
|||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
import arc.Input.*;
|
import arc.Input.*;
|
||||||
|
import arc.func.*;
|
||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
@@ -14,6 +15,7 @@ import arc.util.*;
|
|||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.input.*;
|
import mindustry.input.*;
|
||||||
|
import mindustry.type.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
|
|
||||||
import static arc.Core.*;
|
import static arc.Core.*;
|
||||||
@@ -27,6 +29,7 @@ public class ChatFragment extends Table{
|
|||||||
private boolean shown = false;
|
private boolean shown = false;
|
||||||
private TextField chatfield;
|
private TextField chatfield;
|
||||||
private Label fieldlabel = new Label(">");
|
private Label fieldlabel = new Label(">");
|
||||||
|
private ChatMode mode = ChatMode.normal;
|
||||||
private Font font;
|
private Font font;
|
||||||
private GlyphLayout layout = new GlyphLayout();
|
private GlyphLayout layout = new GlyphLayout();
|
||||||
private float offsetx = Scl.scl(4), offsety = Scl.scl(4), fontoffsetx = Scl.scl(2), chatspace = Scl.scl(50);
|
private float offsetx = Scl.scl(4), offsety = Scl.scl(4), fontoffsetx = Scl.scl(2), chatspace = Scl.scl(50);
|
||||||
@@ -76,6 +79,9 @@ public class ChatFragment extends Table{
|
|||||||
historyPos--;
|
historyPos--;
|
||||||
updateChat();
|
updateChat();
|
||||||
}
|
}
|
||||||
|
if(input.keyTap(Binding.chat_mode)){
|
||||||
|
nextMode();
|
||||||
|
}
|
||||||
scrollPos = (int)Mathf.clamp(scrollPos + input.axis(Binding.chat_scroll), 0, Math.max(0, messages.size - messagesShown));
|
scrollPos = (int)Mathf.clamp(scrollPos + input.axis(Binding.chat_scroll), 0, Math.max(0, messages.size - messagesShown));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -216,14 +222,35 @@ public class ChatFragment extends Table{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateChat(){
|
public void updateChat(){
|
||||||
chatfield.setText(history.get(historyPos));
|
chatfield.setText(mode.normalizedPrefix() + history.get(historyPos));
|
||||||
chatfield.setCursorPosition(chatfield.getText().length());
|
updateCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void nextMode(){
|
||||||
|
ChatMode prev = mode;
|
||||||
|
|
||||||
|
do{
|
||||||
|
mode = mode.next();
|
||||||
|
}while(!mode.isValid());
|
||||||
|
|
||||||
|
if(chatfield.getText().startsWith(prev.normalizedPrefix())){
|
||||||
|
chatfield.setText(mode.normalizedPrefix() + chatfield.getText().substring(prev.normalizedPrefix().length()));
|
||||||
|
}else{
|
||||||
|
chatfield.setText(mode.normalizedPrefix());
|
||||||
|
}
|
||||||
|
|
||||||
|
updateCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearChatInput(){
|
public void clearChatInput(){
|
||||||
historyPos = 0;
|
historyPos = 0;
|
||||||
history.set(0, "");
|
history.set(0, "");
|
||||||
chatfield.setText("");
|
chatfield.setText(mode.normalizedPrefix());
|
||||||
|
updateCursor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateCursor(){
|
||||||
|
chatfield.setCursorPosition(chatfield.getText().length());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shown(){
|
public boolean shown(){
|
||||||
@@ -256,4 +283,36 @@ public class ChatFragment extends Table{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum ChatMode{
|
||||||
|
normal(""),
|
||||||
|
team("/t"),
|
||||||
|
admin("/a", player::admin)
|
||||||
|
;
|
||||||
|
|
||||||
|
public String prefix;
|
||||||
|
public Boolp valid;
|
||||||
|
public static final ChatMode[] all = values();
|
||||||
|
|
||||||
|
ChatMode(String prefix){
|
||||||
|
this.prefix = prefix;
|
||||||
|
this.valid = () -> true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatMode(String prefix, Boolp valid){
|
||||||
|
this.prefix = prefix;
|
||||||
|
this.valid = valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatMode next(){
|
||||||
|
return all[(ordinal() + 1) % all.length];
|
||||||
|
}
|
||||||
|
|
||||||
|
public String normalizedPrefix(){
|
||||||
|
return prefix.isEmpty() ? "" : prefix + " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValid(){
|
||||||
|
return valid.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user