Ticket #3194: gui_hotkey_release_event_v1_debug.patch

File gui_hotkey_release_event_v1_debug.patch, 6.2 KB (added by elexis, 8 years ago)

With all debug warnings to investigate the bug when not calling HotkeyInputHandler.

  • 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">warn("Processing batchtrain PRESS");updateSelectionDetails();</action>
     55        <action on="Release">warn("Processing batchtrain RELEASE");updateSelectionDetails();</action>
     56    </object>
     57
     58    <object hotkey="session.massbarter">
     59        <action on="Press">warn("Processing massbarter PRESS");updateSelectionDetails();</action>
     60        <action on="Release">warn("Processing massbarter 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
  • binaries/data/mods/public/gui/session/selection_panels.js

    g_SelectionPanels.Barter = {  
    112112        let selectionIcon = Engine.GetGUIObjectByName("unitBarterSellSelection[" + data.i + "]");
    113113
    114114        let amountToSell = BARTER_RESOURCE_AMOUNT_TO_SELL;
    115115        if (Engine.HotkeyIsPressed("session.massbarter"))
    116116            amountToSell *= BARTER_BUNCH_MULTIPLIER;
    117 
     117        warn("CHECKING massbarter pressed: " + String(Engine.HotkeyIsPressed("session.massbarter")));
    118118        amount.Sell.caption = "-" + amountToSell;
    119119        let prices = data.unitEntState.barterMarket.prices;
    120120        amount.Buy.caption = "+" + Math.round(prices.sell[g_BarterSell] / prices.buy[data.item] * amountToSell);
    121121
    122122        let resource = getLocalizedResourceName(data.item, "withinSentence");
    g_SelectionPanels.Training = {  
    974974            getTrainingBatchStatus(data.playerState, data.unitEntState.id, data.item, data.selection);
    975975
    976976        let trainNum = buildingsCountToTrainFullBatch || 1;
    977977        if (Engine.HotkeyIsPressed("session.batchtrain"))
    978978            trainNum = buildingsCountToTrainFullBatch * fullBatchSize + remainderBatch;
    979 
     979        warn("CHECKING batchtrain pressed: " + String(Engine.HotkeyIsPressed("session.batchtrain")));
    980980        let neededResources;
    981981        if (template.cost)
    982982            neededResources = Engine.GuiInterfaceCall("GetNeededResources", {
    983983                "cost": multiplyEntityCosts(template, trainNum),
    984984                "player": data.unitEntState.player
  • 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        if (CStr(hotkey) == "session.batchtrain" || CStr(hotkey) == "session.massbarter")
     72            LOGERROR("HandleEvent %s", hotkey);
     73
    7174        std::map<CStr, std::vector<IGUIObject*> >::iterator it = m_HotkeyObjects.find(hotkey);
    7275        if (it != m_HotkeyObjects.end())
    7376            for (IGUIObject* const& obj : it->second)
    74                 obj->SendEvent(GUIM_PRESSED, "press");
     77            {
     78                // Update hotkey status before sending the event,
     79                // else the status will be outdated when processing the GUI event.
     80                HotkeyInputHandler(ev);
     81                ret = IN_HANDLED;
     82
     83                if (ev->ev.type == SDL_HOTKEYDOWN)
     84                    obj->SendEvent(GUIM_PRESSED, "press");
     85                else
     86                    obj->SendEvent(GUIM_RELEASED, "release");
     87            }
    7588    }
    7689
    7790    else if (ev->ev.type == SDL_MOUSEMOTION)
    7891    {
    7992        // 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,
  • source/ps/Hotkey.cpp

     
    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
    InReaction HotkeyInputHandler(const SDL_  
    191191            break;
    192192        }
    193193        return IN_PASS;
    194194
    195195    case SDL_HOTKEYDOWN:
     196    {
     197        const char* hotkey = static_cast<const char*>(ev->ev.user.data1);
     198        if (CStr(hotkey) == "session.batchtrain" || CStr(hotkey) == "session.massbarter")
     199            LOGERROR("HotkeyInputHandler DOWN %s", static_cast<const char*>(ev->ev.user.data1));
    196200        g_HotkeyStatus[static_cast<const char*>(ev->ev.user.data1)] = true;
    197201        return IN_PASS;
    198 
     202    }
    199203    case SDL_HOTKEYUP:
     204    {
     205        const char* hotkey = static_cast<const char*>(ev->ev.user.data1);
     206        if (CStr(hotkey) == "session.batchtrain" || CStr(hotkey) == "session.massbarter")
     207            LOGERROR("HotkeyInputHandler UP %s", static_cast<const char*>(ev->ev.user.data1));
    200208        g_HotkeyStatus[static_cast<const char*>(ev->ev.user.data1)] = false;
    201209        return IN_PASS;
    202 
     210    }
    203211    default:
    204212        return IN_PASS;
    205213    }
    206214
    207215    // Somewhat hackish: