Git Product home page Git Product logo

Comments (12)

bradallred avatar bradallred commented on August 15, 2024

would EventMgr::RegisterEventMonitor work? similar to how GC already employs that for monitoring global mouse movement.

from gemrb.

lynxlynxlynx avatar lynxlynxlynx commented on August 15, 2024

Kinda works. All other keys get detected immediately, but tab enters the monitor only after several presses. Doesn't seem to be a timing thing. Quite peculiar.

diff --git a/gemrb/core/GUI/GameControl.cpp b/gemrb/core/GUI/GameControl.cpp
index 50b1bd7a4..1e655a38f 100644
--- a/gemrb/core/GUI/GameControl.cpp
+++ b/gemrb/core/GUI/GameControl.cpp
@@ -119,6 +119,8 @@ GameControl::GameControl(const Region& frame)
 
        EventMgr::EventCallback* cb = new MethodCallback<GameControl, const Event&, bool>(this, &GameControl::OnGlobalMouseMove);
        EventMgr::RegisterEventMonitor(cb, Event::MouseMoveMask);
+       EventMgr::EventCallback *cb2 = new MethodCallback<GameControl, const Event&, bool>(this, &GameControl::DispatchEvent);
+       EventMgr::RegisterEventMonitor(cb2, Event::KeyDownMask);
 }
 
 //TODO:
@@ -592,6 +594,24 @@ void GameControl::DrawSelf(Region screen, const Region& /*clip*/)
        }
 }
 
+// this existly only so tab can be handled
+// it's used both for tooltips everywhere and hp display on game control
+bool GameControl::DispatchEvent(const Event& event)
+{
+       if (event.keyboard.keycode == GEM_TAB) {
+               Game *game = core->GetGame();
+               if (!game) return false;
+               // show partymember hp/maxhp as overhead text
+               for (int pm=0; pm < game->GetPartySize(false); pm++) {
+                       Actor *pc = game->GetPC(pm, true);
+                       if (!pc) continue;
+                       pc->DisplayHeadHPRatio();
+               }
+               return true;
+       }
+       return false;
+}
+
 /** Key Press Event */
 bool GameControl::OnKeyPress(const KeyboardEvent& Key, unsigned short mod)
 {
@@ -630,11 +650,7 @@ bool GameControl::OnKeyPress(const KeyboardEvent& Key, unsigned short mod)
                        break;
                case GEM_TAB:
                        // show partymember hp/maxhp as overhead text
-                       for (int pm=0; pm < game->GetPartySize(false); pm++) {
-                               Actor *pc = game->GetPC(pm, true);
-                               if (!pc) continue;
-                               pc->DisplayHeadHPRatio();
-                       }
+                       // this is handled in DispatchEvent due to tab having two functions
                        break;
                case GEM_ESCAPE:
                        core->SetEventFlag(EF_ACTION|EF_RESETTARGET);
diff --git a/gemrb/core/GUI/GameControl.h b/gemrb/core/GUI/GameControl.h
index fc80b87d4..10021f6ec 100644
--- a/gemrb/core/GUI/GameControl.h
+++ b/gemrb/core/GUI/GameControl.h
@@ -178,6 +178,8 @@ public:
        /** Mouse Over Event */
        void OnMouseOver(const MouseEvent&);
        void OnMouseDrag(const MouseEvent& /*me*/);
+       /** Currently only deals with the GEM_TAB exception */
+       bool DispatchEvent(const Event& event);
 
        /** Mouse Button Down */
        void OnMouseDown(const MouseEvent& /*me*/, unsigned short Mod);
diff --git a/gemrb/plugins/GUIScript/GUIScript.cpp b/gemrb/plugins/GUIScript/GUIScript.cpp
index 745a1991b..a7f2187ff 100644
--- a/gemrb/plugins/GUIScript/GUIScript.cpp
+++ b/gemrb/plugins/GUIScript/GUIScript.cpp
@@ -13167,6 +13167,7 @@ bool GUIScript::Init(void)
                return false;
        }
        PyRun_SimpleString( "GEMRB_VERSION = '" GEMRB_STRING "'" );
+//     PyModule_AddStringConstant(pGemRB, "GEMRB_VERSION", GEMRB_STRING);
 
        // Detect GameType if it was set to auto
        if (stricmp( core->GameType, "auto" ) == 0) {

from gemrb.

bradallred avatar bradallred commented on August 15, 2024

might have something to do with repeat key events (just shooting in the dark)

from gemrb.

lynxlynxlynx avatar lynxlynxlynx commented on August 15, 2024

I doubt it, it's reproducible way over the threshold. Just holding it down of course get the results faster.

from gemrb.

bradallred avatar bradallred commented on August 15, 2024

it looks like the event monitor stuff at the bottom of EventMgr::DispatchEvent just needs to be moved to the top below e.time = GetTickCount();.

from gemrb.

lynxlynxlynx avatar lynxlynxlynx commented on August 15, 2024

not so simple, since then it eats up all input and you can't get past the first screen. :)

from gemrb.

bradallred avatar bradallred commented on August 15, 2024

wait why not? the monitors don't (shouldn't) eat events:

EventCallback* cb = it->second.get();
(*cb)(e);

it is just invoking them. the problem is that hot key code runs before it and that does cause a return before the monitors run.

from gemrb.

bradallred avatar bradallred commented on August 15, 2024

oh, but apparently WindowManager gets its events via a monitor, so yeah, not that simple. Hmmm.

from gemrb.

bradallred avatar bradallred commented on August 15, 2024

maybe WindowManager shouldn't eat GEM_TAB by using a hotkey, and instead handle that in its own monitor callback, same as GC.

from gemrb.

lynxlynxlynx avatar lynxlynxlynx commented on August 15, 2024

I'll try it tomorrow; please fix the opcodes before you forget.

from gemrb.

lynxlynxlynx avatar lynxlynxlynx commented on August 15, 2024

yeah, that does it nicely. It now triggers also out of gc for some reason, but that's nothing to lose sleep over.

from gemrb.

bradallred avatar bradallred commented on August 15, 2024

heh, some might say that is a feature :)

I think if we cared we would have to do go back to using a hot key and have the GEM_TAB case of WindowManager::HotKey return hoverWin != gameWin so that it will consume the key only if the mouse is over a window. It doesn't matter to me; i can see the appeal of both.

I'll open an issue for the opcodes, I wont be back in town until Monday.

from gemrb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.