mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
fix(chat): suppress alnum hotkeys while typing
This commit is contained in:
parent
14e58eaa01
commit
a5b877de67
2 changed files with 28 additions and 15 deletions
|
|
@ -2274,7 +2274,21 @@ void GameScreen::renderChatWindow(game::GameHandler& gameHandler) {
|
||||||
void GameScreen::processTargetInput(game::GameHandler& gameHandler) {
|
void GameScreen::processTargetInput(game::GameHandler& gameHandler) {
|
||||||
auto& io = ImGui::GetIO();
|
auto& io = ImGui::GetIO();
|
||||||
auto& input = core::Input::getInstance();
|
auto& input = core::Input::getInstance();
|
||||||
const bool textFocus = chatInputActive || io.WantTextInput;
|
|
||||||
|
// If the user is typing (or about to focus chat this frame), do not allow
|
||||||
|
// A-Z or 1-0 shortcuts to fire.
|
||||||
|
if (!io.WantTextInput && !chatInputActive && input.isKeyJustPressed(SDL_SCANCODE_SLASH)) {
|
||||||
|
refocusChatInput = true;
|
||||||
|
chatInputBuffer[0] = '/';
|
||||||
|
chatInputBuffer[1] = '\0';
|
||||||
|
chatInputMoveCursorToEnd = true;
|
||||||
|
}
|
||||||
|
if (!io.WantTextInput && !chatInputActive &&
|
||||||
|
KeybindingManager::getInstance().isActionPressed(KeybindingManager::Action::TOGGLE_CHAT, true)) {
|
||||||
|
refocusChatInput = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool textFocus = chatInputActive || refocusChatInput || io.WantTextInput;
|
||||||
|
|
||||||
// Tab targeting (when keyboard not captured by UI)
|
// Tab targeting (when keyboard not captured by UI)
|
||||||
if (!io.WantCaptureKeyboard) {
|
if (!io.WantCaptureKeyboard) {
|
||||||
|
|
@ -2372,19 +2386,6 @@ void GameScreen::processTargetInput(game::GameHandler& gameHandler) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slash key: focus chat input — always works unless already typing in chat
|
|
||||||
if (!chatInputActive && input.isKeyJustPressed(SDL_SCANCODE_SLASH)) {
|
|
||||||
refocusChatInput = true;
|
|
||||||
chatInputBuffer[0] = '/';
|
|
||||||
chatInputBuffer[1] = '\0';
|
|
||||||
chatInputMoveCursorToEnd = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enter key: focus chat input (empty) — always works unless already typing
|
|
||||||
if (!chatInputActive && KeybindingManager::getInstance().isActionPressed(KeybindingManager::Action::TOGGLE_CHAT, true)) {
|
|
||||||
refocusChatInput = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cursor affordance: show hand cursor over interactable game objects.
|
// Cursor affordance: show hand cursor over interactable game objects.
|
||||||
if (!io.WantCaptureMouse) {
|
if (!io.WantCaptureMouse) {
|
||||||
auto* renderer = core::Application::getInstance().getRenderer();
|
auto* renderer = core::Application::getInstance().getRenderer();
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,19 @@ void KeybindingManager::initializeDefaults() {
|
||||||
bool KeybindingManager::isActionPressed(Action action, bool repeat) {
|
bool KeybindingManager::isActionPressed(Action action, bool repeat) {
|
||||||
auto it = bindings_.find(static_cast<int>(action));
|
auto it = bindings_.find(static_cast<int>(action));
|
||||||
if (it == bindings_.end()) return false;
|
if (it == bindings_.end()) return false;
|
||||||
return ImGui::IsKeyPressed(it->second, repeat);
|
ImGuiKey key = it->second;
|
||||||
|
if (key == ImGuiKey_None) return false;
|
||||||
|
|
||||||
|
// When typing in a text field (e.g. chat input), never treat A-Z or 0-9 as shortcuts.
|
||||||
|
const ImGuiIO& io = ImGui::GetIO();
|
||||||
|
if (io.WantTextInput) {
|
||||||
|
if ((key >= ImGuiKey_A && key <= ImGuiKey_Z) ||
|
||||||
|
(key >= ImGuiKey_0 && key <= ImGuiKey_9)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ImGui::IsKeyPressed(key, repeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGuiKey KeybindingManager::getKeyForAction(Action action) const {
|
ImGuiKey KeybindingManager::getKeyForAction(Action action) const {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue