Ticket #3870: keyfixv4.patch

File keyfixv4.patch, 6.5 KB (added by njm, 8 years ago)

Improvement to Imarok's patch: Typing t in chat does not close the chat anymore. More information below.

  • binaries/data/mods/public/gui/session/hotkeys/misc.xml

     
    44        <action on="Press">closeOpenDialogs();</action>
    55    </object>
    66
    7     <!-- Chat: Depending on the current state, it either opens message window or closes message window / posts message -->
     7    <!-- Chat: Depending on the current state, it opens the message window. -->
    88    <object hotkey="chat">
    9         <action on="Press">toggleChatWindow();</action>
     9        <action on="Press">openChatWindow();</action>
    1010    </object>
    1111
    1212    <!-- Team Chat: Does the same as the above, but sets the window up to only send messages to teammates. -->
    1313    <object hotkey="teamchat">
    14         <action on="Press">toggleChatWindow(true);</action>
     14        <action on="Press">openChatWindow(true);</action>
    1515    </object>
    1616
    1717    <!-- Menu -->
  • binaries/data/mods/public/gui/session/menu.js

     
    8686
    8787function chatMenuButton()
    8888{
    89     closeOpenDialogs();
    90     openChat();
     89    closeMenu();
     90    openChatWindow();
    9191}
    9292
    9393function diplomacyMenuButton()
     
    196196    Engine.PushGuiPage("page_options.xml", { "callback": "resumeGame" });
    197197}
    198198
    199 function openChat()
    200 {
    201     if (g_Disconnected)
    202         return;
    203 
    204     closeOpenDialogs();
    205 
    206     setTeamChat(false);
    207 
    208     Engine.GetGUIObjectByName("chatInput").focus(); // Grant focus to the input area
    209     Engine.GetGUIObjectByName("chatDialogPanel").hidden = false;
    210 }
    211 
    212199function closeChat()
    213200{
    214     Engine.GetGUIObjectByName("chatInput").caption = ""; // Clear chat input
    215     Engine.GetGUIObjectByName("chatInput").blur(); // Remove focus
    216     Engine.GetGUIObjectByName("chatDialogPanel").hidden = true;
     201    let chatWindow = Engine.GetGUIObjectByName("chatDialogPanel");
     202    if(!chatWindow.hidden)
     203    {
     204        Engine.GetGUIObjectByName("chatInput").caption = ""; // Clear chat input
     205        Engine.GetGUIObjectByName("chatInput").blur(); // Remove focus
     206        chatWindow.hidden = true;
     207    }
    217208}
    218209
    219210/**
     
    228219}
    229220
    230221/**
    231  * Opens chat-window or closes it and sends the userinput.
     222 * Opens or focuses chat-window.
    232223 */
    233 function toggleChatWindow(teamChat)
     224function openChatWindow(teamChat)
    234225{
    235226    if (g_Disconnected)
    236227        return;
     
    237228
    238229    let chatWindow = Engine.GetGUIObjectByName("chatDialogPanel");
    239230    let chatInput = Engine.GetGUIObjectByName("chatInput");
    240     let hidden = chatWindow.hidden;
    241 
    242     closeOpenDialogs();
    243 
    244     if (hidden)
     231    if(!chatWindow.hidden)
    245232    {
    246         setTeamChat(teamChat);
    247233        chatInput.focus();
     234        return;
    248235    }
    249     else
    250     {
    251         if (chatInput.caption.length)
    252         {
    253             submitChatInput();
    254             return;
    255         }
    256         chatInput.caption = "";
    257     }
    258236
    259     chatWindow.hidden = !hidden;
     237    closeOpenDialogs();
     238    setTeamChat(teamChat);
     239    chatInput.focus();
     240
     241    chatWindow.hidden = false;
    260242}
    261243
    262244function openDiplomacy()
  • binaries/data/mods/public/gui/session/messages.js

     
    574574    let input = Engine.GetGUIObjectByName("chatInput");
    575575    let text = input.caption;
    576576
    577     input.blur(); // Remove focus
    578     input.caption = ""; // Clear chat input
    579     toggleChatWindow();
     577    closeChat();
    580578
    581579    if (!text.length)
    582580        return;
  • source/gui/CGUI.cpp

     
    6565{
    6666    InReaction ret = IN_PASS;
    6767
    68     if (ev->ev.type == SDL_HOTKEYDOWN)
     68    // Handle keys for input boxes
     69    if ( GetFocusedObject() &&
     70        ((ev->ev.type == SDL_KEYDOWN &&
     71            ev->ev.key.keysym.sym != SDLK_ESCAPE &&
     72            !g_keys[SDLK_LCTRL] && !g_keys[SDLK_RCTRL] &&
     73            !g_keys[SDLK_LALT] && !g_keys[SDLK_RALT]) ||
     74            ev->ev.type == SDL_HOTKEYDOWN ||
     75            (ev->ev.type == SDL_KEYUP && (ev->ev.key.keysym.sym == SDLK_KP_ENTER || ev->ev.key.keysym.sym == SDLK_RETURN)) ||
     76            ev->ev.type == SDL_TEXTINPUT ||
     77            ev->ev.type == SDL_TEXTEDITING) )
    6978    {
     79        ret = GetFocusedObject()->ManuallyHandleEvent(ev);
     80    }
     81
     82    else if (ev->ev.type == SDL_HOTKEYUP)
     83    {
    7084        const char* hotkey = static_cast<const char*>(ev->ev.user.data1);
    7185        std::map<CStr, std::vector<IGUIObject*> >::iterator it = m_HotkeyObjects.find(hotkey);
    7286        if (it != m_HotkeyObjects.end())
     
    243257        m_MousePos = oldMousePos;
    244258    }
    245259
    246     // Handle keys for input boxes
    247     if (GetFocusedObject())
    248     {
    249         if (
    250             (ev->ev.type == SDL_KEYDOWN &&
    251                 ev->ev.key.keysym.sym != SDLK_ESCAPE &&
    252                 !g_keys[SDLK_LCTRL] && !g_keys[SDLK_RCTRL] &&
    253                 !g_keys[SDLK_LALT] && !g_keys[SDLK_RALT])
    254             || ev->ev.type == SDL_HOTKEYDOWN
    255             || ev->ev.type == SDL_TEXTINPUT || ev->ev.type == SDL_TEXTEDITING
    256             )
    257         {
    258             ret = GetFocusedObject()->ManuallyHandleEvent(ev);
    259         }
    260         // else will return IN_PASS because we never used the button.
    261     }
    262 
     260    // else will return IN_PASS because we never used the button.
    263261    return ret;
    264262}
    265263
  • source/gui/CInput.cpp

     
    9595{
    9696    ENSURE(m_iBufferPos != -1);
    9797
    98     if (ev->ev.type == SDL_HOTKEYDOWN)
     98    if (ev->ev.type == SDL_HOTKEYUP)
    9999    {
    100100        if (m_ComposingText)
    101101            return IN_HANDLED;
     
    181181
    182182        return IN_HANDLED;
    183183    }
     184    else if (ev->ev.type == SDL_KEYUP)
     185    {
     186        if (ev->ev.key.keysym.sym == SDLK_KP_ENTER || ev->ev.key.keysym.sym == SDLK_RETURN)
     187            // 'Return' should do a Press event for single liners (e.g. submitting forms)
     188            //  otherwise a '\n' character will be added.
     189        {
     190            bool multiline;
     191            GUI<bool>::GetSetting(this, "multiline", multiline);
     192            if (!multiline)
     193            {
     194                SendEvent(GUIM_PRESSED, "press");
     195                UpdateBufferPositionSetting();
     196                return IN_HANDLED;
     197            }
     198           
     199        }
     200    }
    184201    else if (ev->ev.type == SDL_KEYDOWN)
    185202    {
    186203        if (m_ComposingText)
     
    474491        {
    475492            bool multiline;
    476493            GUI<bool>::GetSetting(this, "multiline", multiline);
    477             if (!multiline)
     494            if (multiline)
    478495            {
    479                 SendEvent(GUIM_PRESSED, "press");
    480                 break;
     496                cooked = '\n'; // Change to '\n' and do default:
    481497            }
    482 
    483             cooked = '\n'; // Change to '\n' and do default:
    484498            // NOTE: Fall-through
    485499        }
    486500        default: // Insert a character