Ticket #3194: gui_hotkey_release_event_v1.patch

File gui_hotkey_release_event_v1.patch, 3.0 KB (added by elexis, 8 years ago)

release candidate

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

     
    4848
    4949    <object hotkey="session.stop">
    5050        <action on="Press">stopUnits(g_Selection.toList());</action>
    5151    </object>
    5252
     53    <object hotkey="session.batchtrain">
     54        <action on="Press">updateSelectionDetails();</action>
     55        <action on="Release">updateSelectionDetails();</action>
     56    </object>
     57
     58    <object hotkey="session.massbarter">
     59        <action on="Press">updateSelectionDetails();</action>
     60        <action on="Release">updateSelectionDetails();</action>
     61    </object>
     62
    5363    <!-- Find idle warrior - TODO: Potentially move this to own UI button? -->
    5464    <object hotkey="selection.idlewarrior">
    5565        <action on="Press">findIdleUnit(["Hero", "Champion", "CitizenSoldier", "Siege", "Warship", "Dog"]);</action>
    5666    </object>
    5767
  • source/gui/CGUI.cpp

    const u32 MAX_OBJECT_DEPTH = 100; // Max  
    6363
    6464InReaction CGUI::HandleEvent(const SDL_Event_* ev)
    6565{
    6666    InReaction ret = IN_PASS;
    6767
    68     if (ev->ev.type == SDL_HOTKEYDOWN)
     68    if (ev->ev.type == SDL_HOTKEYDOWN || ev->ev.type == SDL_HOTKEYUP)
    6969    {
    7070        const char* hotkey = static_cast<const char*>(ev->ev.user.data1);
     71
    7172        std::map<CStr, std::vector<IGUIObject*> >::iterator it = m_HotkeyObjects.find(hotkey);
    7273        if (it != m_HotkeyObjects.end())
    7374            for (IGUIObject* const& obj : it->second)
    74                 obj->SendEvent(GUIM_PRESSED, "press");
     75            {
     76                // Update hotkey status before sending the event,
     77                // else the status will be outdated when processing the GUI event.
     78                HotkeyInputHandler(ev);
     79                ret = IN_HANDLED;
     80
     81                if (ev->ev.type == SDL_HOTKEYDOWN)
     82                    obj->SendEvent(GUIM_PRESSED, "press");
     83                else
     84                    obj->SendEvent(GUIM_RELEASED, "release");
     85            }
    7586    }
    7687
    7788    else if (ev->ev.type == SDL_MOUSEMOTION)
    7889    {
    7990        // Yes the mouse position is stored as float to avoid
  • source/gui/GUIbase.h

     
    1 /* Copyright (C) 2015 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
    55 * it under the terms of the GNU General Public License as published by
    66 * the Free Software Foundation, either version 2 of the License, or
    enum EGUIMessageType  
    7070    GUIM_MOUSE_RELEASE_RIGHT,
    7171    GUIM_MOUSE_WHEEL_UP,
    7272    GUIM_MOUSE_WHEEL_DOWN,
    7373    GUIM_SETTINGS_UPDATED,  // SGUIMessage.m_Value = name of setting
    7474    GUIM_PRESSED,
     75    GUIM_RELEASED,
    7576    GUIM_DOUBLE_PRESSED,
    7677    GUIM_MOUSE_MOTION,
    7778    GUIM_LOAD,              // Called when an object is added to the GUI.
    7879    GUIM_GOT_FOCUS,
    7980    GUIM_LOST_FOCUS,