From 8f95eba9060e078356d8d86d88020bc59dcf047c Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Mon, 9 Oct 2023 12:45:19 -0400 Subject: [PATCH] Add "Send Global / Team Quick Chat" keybindings --- src/hci.cpp | 4 ++-- src/hci.h | 2 +- src/input/keyconfig.cpp | 2 ++ src/keybind.cpp | 39 ++++++++++++++++++++++++-------------- src/keybind.h | 2 ++ src/screens/chatscreen.cpp | 23 ++++++++++++++-------- src/screens/chatscreen.h | 2 +- 7 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/hci.cpp b/src/hci.cpp index 90e9ba02466..4d3d3fe09b9 100644 --- a/src/hci.cpp +++ b/src/hci.cpp @@ -3032,7 +3032,7 @@ bool CoordInBuild(int x, int y) // Our chat dialog for global & team communication // \mode sets if global or team communication is wanted -void chatDialog(int mode) +void chatDialog(int mode, bool startWithQuickChatFocused) { if (!ChatDialogUp) { @@ -3041,7 +3041,7 @@ void chatDialog(int mode) WzChatMode initialChatMode = (mode == CHAT_GLOB) ? WzChatMode::Glob : WzChatMode::Team; createChatScreen([]() { ChatDialogUp = false; - }, initialChatMode); + }, initialChatMode, startWithQuickChatFocused); } else { diff --git a/src/hci.h b/src/hci.h index 7e4f32fc17b..dbca3ec0768 100644 --- a/src/hci.h +++ b/src/hci.h @@ -399,7 +399,7 @@ void intDemolishCancel(); void makeObsoleteButton(const std::shared_ptr &parent); ///< Makes a button to toggle showing obsolete items. -void chatDialog(int mode); +void chatDialog(int mode, bool startWithQuickChatFocused); bool isChatUp(); bool isSecondaryWindowUp(); void setSecondaryWindowUp(bool value); diff --git a/src/input/keyconfig.cpp b/src/input/keyconfig.cpp index fe35d239420..19bd99c2588 100644 --- a/src/input/keyconfig.cpp +++ b/src/input/keyconfig.cpp @@ -154,6 +154,8 @@ static void initializeKeyFunctions(std::vector& entries) entries.emplace_back(KeyFunctionInfo(InputContext::GAMEPLAY, KeyMappingType::ASSIGNABLE, kf_SetDroid(DSO_ATTACK_RANGE, DSS_ARANGE_LONG), "SetDroidRangeLong", N_("Long Range"), {{ KeyMappingSlot::PRIMARY, { KEY_CODE::KEY_U } }})); entries.emplace_back(KeyFunctionInfo(InputContext::GAMEPLAY, KeyMappingType::ASSIGNABLE, kf_SendGlobalMessage, "SendGlobalMessage", N_("Send Global Text Message"), {{ KeyMappingSlot::PRIMARY, { KEY_CODE::KEY_RETURN } }})); entries.emplace_back(KeyFunctionInfo(InputContext::GAMEPLAY, KeyMappingType::ASSIGNABLE, kf_SendTeamMessage, "SendTeamMessage", N_("Send Team Text Message"), {{ KeyMappingSlot::PRIMARY, { KEY_CODE::KEY_LCTRL, KEY_CODE::KEY_RETURN } }})); + entries.emplace_back(KeyFunctionInfo(InputContext::GAMEPLAY, KeyMappingType::ASSIGNABLE, kf_SendGlobalQuickChat, "SendGlobalQuickChat", N_("Send Global Quick Chat"), {})); + entries.emplace_back(KeyFunctionInfo(InputContext::GAMEPLAY, KeyMappingType::ASSIGNABLE, kf_SendTeamQuickChat, "SendTeamQuickChat", N_("Send Team Quick Chat"), {{ KeyMappingSlot::PRIMARY, { KEY_CODE::KEY_LSHIFT, KEY_CODE::KEY_RETURN } }})); entries.emplace_back(KeyFunctionInfo(InputContext::GAMEPLAY, KeyMappingType::ASSIGNABLE, kf_AddHelpBlip, "AddHelpBlip", N_("Drop a beacon"), {{ KeyMappingSlot::PRIMARY, { KEY_CODE::KEY_LALT, KEY_CODE::KEY_H } }})); entries.emplace_back(KeyFunctionInfo(InputContext::GAMEPLAY, KeyMappingType::ASSIGNABLE, kf_ToggleShadows, "ToggleShadows", N_("Toggles shadows"), {{ KeyMappingSlot::PRIMARY, { KEY_CODE::KEY_LALT, KEY_CODE::KEY_S } }})); entries.emplace_back(KeyFunctionInfo(InputContext::GAMEPLAY, KeyMappingType::ASSIGNABLE, kf_toggleTrapCursor, "toggleTrapCursor", N_("Trap cursor"), {{ KeyMappingSlot::PRIMARY, { KEY_CODE::KEY_LALT, KEY_CODE::KEY_T } }})); diff --git a/src/keybind.cpp b/src/keybind.cpp index 7a36305210a..17ceaf300d7 100644 --- a/src/keybind.cpp +++ b/src/keybind.cpp @@ -1994,10 +1994,13 @@ void kf_KillSelected() // -------------------------------------------------------------------------- // Chat message. NOTE THIS FUNCTION CAN DISABLE ALL OTHER KEYPRESSES -void kf_SendTeamMessage() +static void OpenChatUI(int mode, bool startWithQuickChatFocused) { - /* not supported if a spectator */ - SPECTATOR_NO_OP(); + if (mode == CHAT_TEAM) + { + /* not supported if a spectator */ + SPECTATOR_NO_OP(); + } if (!getWidgetsStatus()) { @@ -2008,24 +2011,32 @@ void kf_SendTeamMessage() { sstrcpy(sCurrentConsoleText, ""); //for beacons inputClearBuffer(); - chatDialog(CHAT_TEAM); // throw up the dialog + chatDialog(mode, startWithQuickChatFocused); // throw up the dialog } } +// Chat message. NOTE THIS FUNCTION CAN DISABLE ALL OTHER KEYPRESSES +void kf_SendTeamMessage() +{ + OpenChatUI(CHAT_TEAM, false); +} + // Chat message. NOTE THIS FUNCTION CAN DISABLE ALL OTHER KEYPRESSES void kf_SendGlobalMessage() { - if (!getWidgetsStatus()) - { - return; - } + OpenChatUI(CHAT_GLOB, false); +} - if (bAllowOtherKeyPresses && !gamePaused()) // just starting. - { - sstrcpy(sCurrentConsoleText, ""); //for beacons - inputClearBuffer(); - chatDialog(CHAT_GLOB); // throw up the dialog - } +// Chat message. NOTE THIS FUNCTION CAN DISABLE ALL OTHER KEYPRESSES +void kf_SendTeamQuickChat() +{ + OpenChatUI(CHAT_TEAM, true); +} + +// Chat message. NOTE THIS FUNCTION CAN DISABLE ALL OTHER KEYPRESSES +void kf_SendGlobalQuickChat() +{ + OpenChatUI(CHAT_GLOB, true); } // -------------------------------------------------------------------------- diff --git a/src/keybind.h b/src/keybind.h index 2efe24c2f66..ae4a8cc3ba4 100644 --- a/src/keybind.h +++ b/src/keybind.h @@ -103,7 +103,9 @@ void kf_ChooseCancel(); void kf_ToggleWeather(); void kf_KillSelected(); void kf_SendGlobalMessage(); +void kf_SendGlobalQuickChat(); void kf_SendTeamMessage(); +void kf_SendTeamQuickChat(); void kf_ToggleConsole(); void kf_ToggleTeamChat(); MappableFunction kf_SelectUnits(const SELECTIONTYPE selectionType, const SELECTION_CLASS selectionClass = SELECTION_CLASS::DS_BY_TYPE, const bool bOnScreen = false); diff --git a/src/screens/chatscreen.cpp b/src/screens/chatscreen.cpp index 0fa4bf9851d..4c3cb4a0f3b 100644 --- a/src/screens/chatscreen.cpp +++ b/src/screens/chatscreen.cpp @@ -56,7 +56,7 @@ struct WzInGameChatScreen: public W_SCREEN public: typedef std::function OnCloseFunc; - static std::shared_ptr make(const OnCloseFunc& onCloseFunction, WzChatMode initialChatMode); + static std::shared_ptr make(const OnCloseFunc& onCloseFunction, WzChatMode initialChatMode, bool startWithQuickChatFocused); public: void closeScreen(); @@ -495,7 +495,7 @@ void WzInGameChatScreen_CLICKFORM::run(W_CONTEXT *psContext) // MARK: - WzGameStartOverlayScreen -std::shared_ptr WzInGameChatScreen::make(const OnCloseFunc& _onCloseFunc, WzChatMode initialChatMode) +std::shared_ptr WzInGameChatScreen::make(const OnCloseFunc& _onCloseFunc, WzChatMode initialChatMode, bool startWithQuickChatFocused) { class make_shared_enabler: public WzInGameChatScreen {}; auto newRootFrm = WzInGameChatScreen_CLICKFORM::make(initialChatMode); @@ -513,14 +513,21 @@ std::shared_ptr WzInGameChatScreen::make(const OnCloseFunc& newRootFrm->onCancelPressed = newRootFrm->onClickedFunc; // must select default element focus *after* adding the root form to the screen - bool chatBoxEnabled = true; - if (chatBoxEnabled) + if (startWithQuickChatFocused) { - newRootFrm->giveChatBoxFocus(); + newRootFrm->giveQuickChatFocus(); } else { - newRootFrm->giveQuickChatFocus(); + bool chatBoxEnabled = true; + if (chatBoxEnabled) + { + newRootFrm->giveChatBoxFocus(); + } + else + { + newRootFrm->giveQuickChatFocus(); + } } return screen; @@ -535,9 +542,9 @@ void WzInGameChatScreen::closeScreen() } } -std::shared_ptr createChatScreen(std::function onCloseFunc, WzChatMode initialChatMode) +std::shared_ptr createChatScreen(std::function onCloseFunc, WzChatMode initialChatMode, bool startWithQuickChatFocused) { - auto screen = WzInGameChatScreen::make(onCloseFunc, initialChatMode); + auto screen = WzInGameChatScreen::make(onCloseFunc, initialChatMode, startWithQuickChatFocused); widgRegisterOverlayScreenOnTopOfScreen(screen, psWScreen); psCurrentChatScreen = screen; return screen; diff --git a/src/screens/chatscreen.h b/src/screens/chatscreen.h index af9c08de4e9..32b1ef1a239 100644 --- a/src/screens/chatscreen.h +++ b/src/screens/chatscreen.h @@ -30,5 +30,5 @@ enum class WzChatMode Glob }; -std::shared_ptr createChatScreen(std::function onCloseFunc, WzChatMode initialChatMode); +std::shared_ptr createChatScreen(std::function onCloseFunc, WzChatMode initialChatMode, bool startWithQuickChatFocused); void shutdownChatScreen();