mirror of
https://github.com/blupi-games/planetblupi
synced 2024-12-30 10:15:36 +01:00
Fix mouse sprites and hovers when an update is doing
Otherwise it's possible to have de desync between the current state of the last update and the last time that the mouse was handled. It works much better now because it's no longer possible to have for example a red cross on the ground when a tomato has finished to grow. The mouse state is immediatly fixed by the update.
This commit is contained in:
parent
67c2103f3c
commit
ad91d25fb8
@ -241,7 +241,8 @@ Update (void)
|
||||
|
||||
g_pEvent->DecorAutoShift ();
|
||||
g_pDecor->Build (clip, posMouse); // build the environment
|
||||
g_pDecor->NextPhase (1); // rebuild the map sometimes
|
||||
g_pEvent->PlayMove (posMouse);
|
||||
g_pDecor->NextPhase (1); // rebuild the map sometimes
|
||||
}
|
||||
|
||||
if (phase == EV_PHASE_BUILD)
|
||||
@ -260,6 +261,13 @@ Update (void)
|
||||
g_pEvent->DemoStep (); // start automatically (eventually) the demo
|
||||
}
|
||||
|
||||
SDL_Event event = {0};
|
||||
event.type = SDL_MOUSEMOTION;
|
||||
event.motion.x = posMouse.x;
|
||||
event.motion.y = posMouse.y;
|
||||
g_pEvent->EventButtons (event, posMouse);
|
||||
g_pEvent->MouseSprite (posMouse);
|
||||
|
||||
g_pEvent->DrawButtons ();
|
||||
|
||||
g_lastPhase = phase;
|
||||
|
@ -274,16 +274,8 @@ CButton::TreatEvent (const SDL_Event & event)
|
||||
|
||||
pos.x = event.button.x;
|
||||
pos.y = event.button.y;
|
||||
if (MouseUp (pos))
|
||||
{
|
||||
/* Simulate a mouse move in order to restore the mouse hover state. */
|
||||
SDL_Event ev = {0};
|
||||
ev.type = SDL_MOUSEMOTION;
|
||||
ev.motion.x = pos.x;
|
||||
ev.motion.y = pos.y;
|
||||
SDL_PushEvent (&ev);
|
||||
if (MouseUp (pos)) // (*)
|
||||
return false;
|
||||
} // (*)
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -5824,10 +5824,7 @@ CEvent::TreatEventBase (const SDL_Event & event)
|
||||
case SDLK_RCTRL:
|
||||
m_keymod |= KMOD_CTRL;
|
||||
if (m_phase == EV_PHASE_BUILD)
|
||||
{
|
||||
m_bFillMouse = true;
|
||||
MouseSprite (GetMousePos ());
|
||||
}
|
||||
else
|
||||
m_bFillMouse = false;
|
||||
return true;
|
||||
@ -5893,7 +5890,6 @@ CEvent::TreatEventBase (const SDL_Event & event)
|
||||
case SDLK_RCTRL:
|
||||
m_keymod &= ~KMOD_CTRL;
|
||||
m_bFillMouse = false;
|
||||
MouseSprite (GetMousePos ());
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@ -5907,8 +5903,6 @@ CEvent::TreatEventBase (const SDL_Event & event)
|
||||
pos.x = event.button.x;
|
||||
pos.y = event.button.y;
|
||||
|
||||
MouseSprite (pos);
|
||||
//? DecorAutoShift(pos);
|
||||
if (EventButtons (event, pos))
|
||||
return true;
|
||||
if (m_phase == EV_PHASE_BUILD)
|
||||
@ -5929,7 +5923,6 @@ CEvent::TreatEventBase (const SDL_Event & event)
|
||||
|
||||
m_oldMousePos = pos;
|
||||
|
||||
MouseSprite (pos);
|
||||
if (EventButtons (event, pos))
|
||||
return true;
|
||||
if (m_phase == EV_PHASE_BUILD)
|
||||
@ -5938,10 +5931,7 @@ CEvent::TreatEventBase (const SDL_Event & event)
|
||||
return true;
|
||||
}
|
||||
if (m_phase == EV_PHASE_PLAY)
|
||||
{
|
||||
if (PlayMove (pos))
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
|
@ -150,18 +150,19 @@ public:
|
||||
void SetWindowSize (Uint8 newScale);
|
||||
void SetUpdateVersion (const std::string & version);
|
||||
|
||||
bool EventButtons (const SDL_Event & event, Point pos);
|
||||
bool PlayMove (Point pos);
|
||||
|
||||
static void PushUserEvent (Sint32 code, void * data = nullptr);
|
||||
|
||||
protected:
|
||||
void DrawTextCenter (const char * text, Sint32 x, Sint32 y, Sint32 font = 0);
|
||||
bool CreateButtons (Sint32 phase);
|
||||
bool EventButtons (const SDL_Event & event, Point pos);
|
||||
bool MouseOnButton (Point pos);
|
||||
Sint32 SearchPhase (Uint32 phase);
|
||||
void DecorShift (Sint32 dx, Sint32 dy);
|
||||
|
||||
bool PlayDown (Point pos, const SDL_Event & event);
|
||||
bool PlayMove (Point pos);
|
||||
bool PlayUp (Point pos);
|
||||
|
||||
Language GetStartLanguage ();
|
||||
|
Loading…
x
Reference in New Issue
Block a user