Skip to content

Commit

Permalink
Add "Send Global / Team Quick Chat" keybindings
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Oct 9, 2023
1 parent bcbd587 commit 8f95eba
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/hci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -3041,7 +3041,7 @@ void chatDialog(int mode)
WzChatMode initialChatMode = (mode == CHAT_GLOB) ? WzChatMode::Glob : WzChatMode::Team;
createChatScreen([]() {
ChatDialogUp = false;
}, initialChatMode);
}, initialChatMode, startWithQuickChatFocused);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/hci.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ void intDemolishCancel();

void makeObsoleteButton(const std::shared_ptr<WIDGET> &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);
Expand Down
2 changes: 2 additions & 0 deletions src/input/keyconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ static void initializeKeyFunctions(std::vector<KeyFunctionInfo>& 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 } }}));
Expand Down
39 changes: 25 additions & 14 deletions src/keybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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);
}

// --------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/keybind.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 15 additions & 8 deletions src/screens/chatscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct WzInGameChatScreen: public W_SCREEN

public:
typedef std::function<void ()> OnCloseFunc;
static std::shared_ptr<WzInGameChatScreen> make(const OnCloseFunc& onCloseFunction, WzChatMode initialChatMode);
static std::shared_ptr<WzInGameChatScreen> make(const OnCloseFunc& onCloseFunction, WzChatMode initialChatMode, bool startWithQuickChatFocused);

public:
void closeScreen();
Expand Down Expand Up @@ -495,7 +495,7 @@ void WzInGameChatScreen_CLICKFORM::run(W_CONTEXT *psContext)

// MARK: - WzGameStartOverlayScreen

std::shared_ptr<WzInGameChatScreen> WzInGameChatScreen::make(const OnCloseFunc& _onCloseFunc, WzChatMode initialChatMode)
std::shared_ptr<WzInGameChatScreen> WzInGameChatScreen::make(const OnCloseFunc& _onCloseFunc, WzChatMode initialChatMode, bool startWithQuickChatFocused)
{
class make_shared_enabler: public WzInGameChatScreen {};
auto newRootFrm = WzInGameChatScreen_CLICKFORM::make(initialChatMode);
Expand All @@ -513,14 +513,21 @@ std::shared_ptr<WzInGameChatScreen> 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;
Expand All @@ -535,9 +542,9 @@ void WzInGameChatScreen::closeScreen()
}
}

std::shared_ptr<W_SCREEN> createChatScreen(std::function<void ()> onCloseFunc, WzChatMode initialChatMode)
std::shared_ptr<W_SCREEN> createChatScreen(std::function<void ()> 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;
Expand Down
2 changes: 1 addition & 1 deletion src/screens/chatscreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ enum class WzChatMode
Glob
};

std::shared_ptr<W_SCREEN> createChatScreen(std::function<void ()> onCloseFunc, WzChatMode initialChatMode);
std::shared_ptr<W_SCREEN> createChatScreen(std::function<void ()> onCloseFunc, WzChatMode initialChatMode, bool startWithQuickChatFocused);
void shutdownChatScreen();

0 comments on commit 8f95eba

Please sign in to comment.