Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tab duplicity #52

Closed
lynxlynxlynx opened this issue Jul 5, 2017 · 12 comments
Closed

tab duplicity #52

lynxlynxlynx opened this issue Jul 5, 2017 · 12 comments

Comments

@lynxlynxlynx
Copy link
Collaborator

tab is used for two things:

  • immediately trigger a tooltip
  • show the hp/maxhp overhead text for party/friendlies, iff pressed over the gamecontrol

the first we do in the wm via a hotkey, the other in gc manually. So the hp display never shows up, because the wm eats the event, It can only be achieved because the code is not strict — by using ctrl-tab or other mod keys.

It sounds awkward to check for the gc in WindowManager::HotKey, so I'm looking for ideas.

@bradallred
Copy link
Owner

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

@lynxlynxlynx
Copy link
Collaborator Author

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) {

@bradallred
Copy link
Owner

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

@lynxlynxlynx
Copy link
Collaborator Author

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

@bradallred
Copy link
Owner

bradallred commented Jul 5, 2017

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();.

@lynxlynxlynx
Copy link
Collaborator Author

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

@bradallred
Copy link
Owner

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.

@bradallred
Copy link
Owner

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

@bradallred
Copy link
Owner

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

@lynxlynxlynx
Copy link
Collaborator Author

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

@lynxlynxlynx
Copy link
Collaborator Author

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

@bradallred
Copy link
Owner

bradallred commented Jul 6, 2017

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.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants