diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index b93e405939..f7a571615b 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -917,6 +917,7 @@ keybind.toggle_menus.name = Toggle Menus keybind.chat_history_prev.name = Chat History Prev keybind.chat_history_next.name = Chat History Next keybind.chat_scroll.name = Chat Scroll +keybind.chat_mode.name = Change Chat Mode keybind.drop_unit.name = Drop Unit keybind.zoom_minimap.name = Zoom Minimap mode.help.title = Description of modes diff --git a/core/assets/bundles/bundle_es.properties b/core/assets/bundles/bundle_es.properties index 63fd6d8055..60e9538f1a 100644 --- a/core/assets/bundles/bundle_es.properties +++ b/core/assets/bundles/bundle_es.properties @@ -915,6 +915,7 @@ keybind.toggle_menus.name = Ocultar menús keybind.chat_history_prev.name = Historial de chat - Anterior keybind.chat_history_next.name = Historial de chat - Siguiente keybind.chat_scroll.name = Desplazar el chat +keybind.chat_mode.name = Cambiar modo de chat keybind.drop_unit.name = Soltar unidad keybind.zoom_minimap.name = Zoom del minimapa mode.help.title = Descripción de modos diff --git a/core/assets/bundles/bundle_ko.properties b/core/assets/bundles/bundle_ko.properties index 762e8a3cd8..3b24659e2a 100644 --- a/core/assets/bundles/bundle_ko.properties +++ b/core/assets/bundles/bundle_ko.properties @@ -915,6 +915,7 @@ keybind.toggle_menus.name = 메뉴 보이기/숨기기 keybind.chat_history_prev.name = 이전 채팅 기록 keybind.chat_history_next.name = 다음 채팅 기록 keybind.chat_scroll.name = 채팅 스크롤 +keybind.chat_mode = 대화 대상 변경 keybind.drop_unit.name = 유닛 떨구기 keybind.zoom_minimap.name = 미니맵 확대 mode.help.title = 모드 설명 diff --git a/core/assets/bundles/bundle_ru.properties b/core/assets/bundles/bundle_ru.properties index 74c15811a7..3a4afc4188 100644 --- a/core/assets/bundles/bundle_ru.properties +++ b/core/assets/bundles/bundle_ru.properties @@ -918,6 +918,7 @@ keybind.toggle_menus.name = Переключение меню keybind.chat_history_prev.name = Пред. история чата keybind.chat_history_next.name = След. история чата keybind.chat_scroll.name = Прокрутка чата +keybind.chat_mode.name = Изменить режим чата keybind.drop_unit.name = Сбросить боев. ед. keybind.zoom_minimap.name = Масштабировать мини-карту mode.help.title = Описание режимов diff --git a/core/src/mindustry/input/Binding.java b/core/src/mindustry/input/Binding.java index 0f1ecd4339..6291012259 100644 --- a/core/src/mindustry/input/Binding.java +++ b/core/src/mindustry/input/Binding.java @@ -69,6 +69,7 @@ public enum Binding implements KeyBind{ chat_history_prev(KeyCode.up), chat_history_next(KeyCode.down), chat_scroll(new Axis(KeyCode.scroll)), + chat_mode(KeyCode.tab), console(KeyCode.f8), ; diff --git a/core/src/mindustry/ui/fragments/ChatFragment.java b/core/src/mindustry/ui/fragments/ChatFragment.java index 2cef92009b..58b7735c23 100644 --- a/core/src/mindustry/ui/fragments/ChatFragment.java +++ b/core/src/mindustry/ui/fragments/ChatFragment.java @@ -2,6 +2,7 @@ package mindustry.ui.fragments; import arc.*; import arc.Input.*; +import arc.func.*; import arc.graphics.*; import arc.graphics.g2d.*; import arc.math.*; @@ -14,6 +15,7 @@ import arc.util.*; import mindustry.*; import mindustry.gen.*; import mindustry.input.*; +import mindustry.type.*; import mindustry.ui.*; import static arc.Core.*; @@ -27,6 +29,7 @@ public class ChatFragment extends Table{ private boolean shown = false; private TextField chatfield; private Label fieldlabel = new Label(">"); + private ChatMode mode = ChatMode.normal; private Font font; private GlyphLayout layout = new GlyphLayout(); 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--; 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)); } }); @@ -216,14 +222,35 @@ public class ChatFragment extends Table{ } public void updateChat(){ - chatfield.setText(history.get(historyPos)); - chatfield.setCursorPosition(chatfield.getText().length()); + chatfield.setText(mode.normalizedPrefix() + history.get(historyPos)); + 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(){ historyPos = 0; history.set(0, ""); - chatfield.setText(""); + chatfield.setText(mode.normalizedPrefix()); + updateCursor(); + } + + public void updateCursor(){ + chatfield.setCursorPosition(chatfield.getText().length()); } 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(); + } + } }