Merge pull request #1534 from Areloch/EscapeMenuActionmapFixes

Fix escape menu keybind not working
This commit is contained in:
Brian Roberts 2025-08-11 09:19:24 -05:00 committed by GitHub
commit 0404b743f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 77 additions and 4 deletions

View file

@ -161,6 +161,9 @@ void GuiCrossHairHud::onRender(Point2I offset, const RectI &updateRect)
{ {
if (mFrameTime->getElapsedMs() > 32) if (mFrameTime->getElapsedMs() > 32)
{ {
if (GuiOffscreenCanvas::sActiveOffscreenCanvas)
GuiOffscreenCanvas::sActiveOffscreenCanvas->setActive(false);
GuiOffscreenCanvas::sActiveOffscreenCanvas = NULL; GuiOffscreenCanvas::sActiveOffscreenCanvas = NULL;
mFrameTime->reset(); mFrameTime->reset();
@ -197,6 +200,7 @@ void GuiCrossHairHud::onRender(Point2I offset, const RectI &updateRect)
canvas->setCursorPos(newCursorPos); canvas->setCursorPos(newCursorPos);
canvas->markDirty(); canvas->markDirty();
GuiOffscreenCanvas::sActiveOffscreenCanvas = canvas; GuiOffscreenCanvas::sActiveOffscreenCanvas = canvas;
GuiOffscreenCanvas::sActiveOffscreenCanvas->setActive(true);
break; break;
} }
} }

View file

@ -393,6 +393,7 @@ void GuiCanvas::setWindowTitle(const char *newTitle)
} }
CanvasSizeChangeSignal GuiCanvas::smCanvasSizeChangeSignal; CanvasSizeChangeSignal GuiCanvas::smCanvasSizeChangeSignal;
CanvasSetActiveSignal GuiCanvas::smCanvasSetActiveSignal;
void GuiCanvas::handleResize( WindowId did, S32 width, S32 height ) void GuiCanvas::handleResize( WindowId did, S32 width, S32 height )
{ {
@ -2202,6 +2203,13 @@ StringTableEntry GuiCanvas::getLastInputDeviceType()
return StringTable->EmptyString(); return StringTable->EmptyString();
} }
void GuiCanvas::setActive(bool value)
{
Parent::setActive(value);
GuiCanvas::getCanvasSetActiveSignal().trigger(this, value);
}
DefineEngineMethod( GuiCanvas, getContent, S32, (),, DefineEngineMethod( GuiCanvas, getContent, S32, (),,
"@brief Get the GuiControl which is being used as the content.\n\n" "@brief Get the GuiControl which is being used as the content.\n\n"
@ -3027,3 +3035,11 @@ DefineEngineMethod(GuiCanvas, getLastInputDevice, const char*, (), , "Returns th
{ {
return object->getLastInputDeviceType(); return object->getLastInputDeviceType();
} }
DefineEngineMethod(GuiCanvas, getActiveOffscreenCanvas, S32, (), , "Returns the SimID of the active offscreen canvas, if one exists. If not, returns 0")
{
if (GuiOffscreenCanvas::sActiveOffscreenCanvas && GuiOffscreenCanvas::sActiveOffscreenCanvas->isActive())
return GuiOffscreenCanvas::sActiveOffscreenCanvas->getId();
return 0;
}

View file

@ -86,6 +86,8 @@
class guiCanvas; class guiCanvas;
class Point2I; class Point2I;
typedef Signal<void(GuiCanvas* canvas)> CanvasSizeChangeSignal; typedef Signal<void(GuiCanvas* canvas)> CanvasSizeChangeSignal;
typedef Signal<void(GuiCanvas* canvas, bool isActive)> CanvasSetActiveSignal;
class GuiCanvas : public GuiControl, public IProcessInput class GuiCanvas : public GuiControl, public IProcessInput
{ {
@ -210,10 +212,13 @@ protected:
void checkLockMouseMove( const GuiEvent& event ); void checkLockMouseMove( const GuiEvent& event );
//Signal used to let others know this canvas has changed size. //Signal used to let others know this canvas has changed size.
static CanvasSizeChangeSignal smCanvasSizeChangeSignal; static CanvasSizeChangeSignal smCanvasSizeChangeSignal;
static CanvasSetActiveSignal smCanvasSetActiveSignal;
GuiControl *mMenuBarCtrl; GuiControl *mMenuBarCtrl;
GuiControl* mMenuBackground; GuiControl* mMenuBackground;
bool mConstrainMouse; bool mConstrainMouse;
typedef Signal< void(SetModification modification, SimSet* set, SimObject* object) > SetModificationSignal;
public: public:
DECLARE_CONOBJECT(GuiCanvas); DECLARE_CONOBJECT(GuiCanvas);
DECLARE_CATEGORY( "Gui Core" ); DECLARE_CATEGORY( "Gui Core" );
@ -230,6 +235,7 @@ public:
static void initPersistFields(); static void initPersistFields();
static CanvasSizeChangeSignal& getCanvasSizeChangeSignal() { return smCanvasSizeChangeSignal; } static CanvasSizeChangeSignal& getCanvasSizeChangeSignal() { return smCanvasSizeChangeSignal; }
static CanvasSetActiveSignal& getCanvasSetActiveSignal() { return smCanvasSetActiveSignal; }
/// @name Rendering methods /// @name Rendering methods
/// ///
@ -477,16 +483,18 @@ public:
private: private:
static const U32 MAX_GAMEPADS = 4; ///< The maximum number of supported gamepads static const U32 MAX_GAMEPADS = 4; ///< The maximum number of supported gamepads
protected: protected:
bool mConsumeLastInputEvent; bool mConsumeLastInputEvent;
S32 mLastInputDeviceType; S32 mLastInputDeviceType;
public: public:
void clearMouseRightButtonDown(void) { mMouseRightButtonDown = false; } void clearMouseRightButtonDown(void) { mMouseRightButtonDown = false; }
void clearMouseButtonDown(void) { mMouseButtonDown = false; } void clearMouseButtonDown(void) { mMouseButtonDown = false; }
void setConsumeLastInputEvent(bool flag) { mConsumeLastInputEvent = flag; } void setConsumeLastInputEvent(bool flag) { mConsumeLastInputEvent = flag; }
bool getLastCursorPoint(Point2I& pt) const { pt = mLastCursorPt; return mLastCursorEnabled; } bool getLastCursorPoint(Point2I& pt) const { pt = mLastCursorPt; return mLastCursorEnabled; }
StringTableEntry getLastInputDeviceType(); StringTableEntry getLastInputDeviceType();
void setActive(bool value) override;
}; };
typedef GuiCanvas::KeyTranslationMode KeyboardTranslationMode; typedef GuiCanvas::KeyTranslationMode KeyboardTranslationMode;
DefineEnumType(KeyboardTranslationMode); DefineEnumType(KeyboardTranslationMode);

View file

@ -23,6 +23,7 @@
#include "gui/utility/guiInputCtrl.h" #include "gui/utility/guiInputCtrl.h"
#include "sim/actionMap.h" #include "sim/actionMap.h"
#include "console/engineAPI.h" #include "console/engineAPI.h"
#include "gui/core/guiCanvas.h"
IMPLEMENT_CONOBJECT(GuiInputCtrl); IMPLEMENT_CONOBJECT(GuiInputCtrl);
@ -88,6 +89,22 @@ void GuiInputCtrl::initPersistFields()
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool GuiInputCtrl::onAdd()
{
if (!Parent::onAdd())
return false;
GuiCanvas::getCanvasSetActiveSignal().notify(this, &GuiInputCtrl::handleCanvasSetActive);
return true;
}
void GuiInputCtrl::onRemove()
{
GuiCanvas::getCanvasSetActiveSignal().remove(this, &GuiInputCtrl::handleCanvasSetActive);
Parent::onRemove();
}
bool GuiInputCtrl::onWake() bool GuiInputCtrl::onWake()
{ {
@ -108,8 +125,11 @@ bool GuiInputCtrl::onWake()
if(mActionmap != nullptr) if(mActionmap != nullptr)
{ {
SimSet* actionMapSet = Sim::getActiveActionMapSet(); if (getRoot()->isActive())
actionMapSet->pushObject(mActionmap); {
SimSet* actionMapSet = Sim::getActiveActionMapSet();
actionMapSet->pushObject(mActionmap);
}
} }
setFirstResponder(); setFirstResponder();
@ -152,6 +172,25 @@ void GuiInputCtrl::setActive(bool value)
} }
void GuiInputCtrl::handleCanvasSetActive(GuiCanvas* canvas, bool isActive)
{
if (mActionmap == nullptr)
return;
if (getRoot() == canvas)
{
if (isActive)
{
SimSet* actionMapSet = Sim::getActiveActionMapSet();
actionMapSet->pushObject(mActionmap);
}
else
{
SimSet* actionMapSet = Sim::getActiveActionMapSet();
actionMapSet->removeObject(mActionmap);
}
}
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
static bool isModifierKey( U16 keyCode ) static bool isModifierKey( U16 keyCode )

View file

@ -47,6 +47,9 @@ public:
GuiInputCtrl(); GuiInputCtrl();
bool onAdd() override;
void onRemove() override;
// GuiControl. // GuiControl.
bool onWake() override; bool onWake() override;
void onSleep() override; void onSleep() override;
@ -57,6 +60,8 @@ public:
static void initPersistFields(); static void initPersistFields();
void handleCanvasSetActive(GuiCanvas* canvas, bool isActive);
DECLARE_CONOBJECT(GuiInputCtrl); DECLARE_CONOBJECT(GuiInputCtrl);
DECLARE_CATEGORY( "Gui Other Script" ); DECLARE_CATEGORY( "Gui Other Script" );
DECLARE_DESCRIPTION( "A control that locks the mouse and reports all input events to script." ); DECLARE_DESCRIPTION( "A control that locks the mouse and reports all input events to script." );

View file

@ -50,6 +50,7 @@ function Prototyping::onCreateClientConnection(%this)
dynamicTarget = false; dynamicTarget = false;
canInteract = true; canInteract = true;
maxInteractDistance = "3"; maxInteractDistance = "3";
active = false;
}; };
} }