Fix hover effect not regenerating after mousedown events, minor GUI code cleanup, and fix #2414

This was SVN commit r14819.
This commit is contained in:
JoshuaJB
2014-03-07 22:43:57 +00:00
parent c8bdd993c0
commit fb65288463
5 changed files with 40 additions and 41 deletions
@@ -928,44 +928,28 @@
size="0 100%-212 212 100%"
type="image"
sprite="mapPanel"
z="20"
>
<!-- Idle Worker Button -->
<object size="100%-80 100%-80 100%-5 100%-5">
<!-- TODO: We should disable this button if there are no idle workers. -->
<object type="button"
hotkey="selection.idleworker"
>
<action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action>
<action on="MouseEnter">Engine.GetGUIObjectByName("idleOverlay").sprite = "stretched:session/minimap-idle-highlight.png";</action>
<action on="MouseLeave">Engine.GetGUIObjectByName("idleOverlay").sprite = "stretched:session/minimap-idle.png";</action>
<action on="MouseLeftPress">Engine.GetGUIObjectByName("idleOverlay").sprite = "stretched:session/minimap-idle.png";</action>
<action on="MouseLeftRelease">Engine.GetGUIObjectByName("idleOverlay").sprite = "stretched:session/minimap-idle-highlight.png";</action>
</object>
</object>
<object name="minimap"
type="minimap"
type="minimap" z="20"
size="8 8 100%-8 100%-8"
>
<action on="WorldClick">handleMinimapEvent(arguments[0]);</action>
</object>
<object name="minimapOverlay" size="4 4 100%-4 100%-4" type="image" sprite="stretched:session/minimap_circle_modern.png" ghost="true"/>
<!-- Idle Worker Button -->
<object size="100%-36 100%-36 100%-5 100%-5">
<!-- TODO: should highlight the button if there's non-zero idle workers -->
<object name="idle-overlay" size="-85 -85 100% 100%" type="image" sprite="stretched:session/minimap-idle.png" ghost="true"/>
<!-- Since we don't support non-rectangular buttons, we approximate the area using 3 rectangles TODO: Make this cleaner -->
<object type="button"
tooltip_style="sessionToolTip"
tooltip="Find idle worker"
hotkey="selection.idleworker"
>
<action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action>
</object>
<object type="button"
tooltip_style="sessionToolTip"
tooltip="Find idle worker"
size="15 -15 100% 0"
>
<action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action>
</object>
<object type="button"
tooltip_style="sessionToolTip"
tooltip="Find idle worker"
size="-15 15 0 100%"
>
<action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action>
</object>
</object>
<object name="idleOverlay" z="100" size="100%-125 100%-125 100%-5 100%-5" type="image" sprite="stretched:session/minimap-idle.png" ghost="true"/>
</object>
<!-- ================================ ================================ -->
+4 -9
View File
@@ -129,14 +129,9 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
// pNearest will after this point at the hovered object, possibly NULL
pNearest = FindObjectUnderMouse();
// Is placed in the UpdateMouseOver function
//if (ev->ev.type == SDL_MOUSEMOTION && pNearest)
// pNearest->ScriptEvent("mousemove");
// Now we'll call UpdateMouseOver on *all* objects,
// we'll input the one hovered, and they will each
// update their own data and send messages accordingly
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
&IGUIObject::UpdateMouseOver,
pNearest);
@@ -232,10 +227,10 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
GUI<>::RecurseObject(GUIRR_HIDDEN, m_BaseObject,
&IGUIObject::ResetStates);
// It will have reset the mouse over of the current hovered, so we'll
// have to restore that
if (pNearest)
pNearest->m_MouseHovering = true;
// Since the hover state will have been reset, we reload it.
GUI<IGUIObject*>::RecurseObject(GUIRR_HIDDEN | GUIRR_GHOST, m_BaseObject,
&IGUIObject::UpdateMouseOver,
pNearest);
}
}
catch (PSERROR_GUI& e)
+1 -1
View File
@@ -514,7 +514,7 @@ protected:
// Pointer to parent
IGUIObject *m_pParent;
//This represents the last click time for each mouse button
double m_LastClickTime[6];
+15
View File
@@ -199,6 +199,21 @@ void CMiniMap::HandleMessage(SGUIMessage &Message)
} // switch
}
bool CMiniMap::MouseOver()
{
// Get the mouse position.
CPos mousePos = GetMousePos();
// Get the position of the center of the minimap.
CPos minimapCenter = CPos(m_CachedActualSize.left + m_CachedActualSize.GetWidth() / 2.0, m_CachedActualSize.bottom - m_CachedActualSize.GetHeight() / 2.0);
// Take the magnitude of the difference of the mouse position and minimap center.
double distFromCenter = sqrt(pow((mousePos.x - minimapCenter.x), 2) + pow((mousePos.y - minimapCenter.y), 2));
// If the distance is less then the radius of the minimap (half the width) the mouse is over the minimap.
if (distFromCenter < m_CachedActualSize.GetWidth() / 2.0)
return true;
else
return false;
}
void CMiniMap::GetMouseWorldCoordinates(float& x, float& z)
{
// Determine X and Z according to proportion of mouse position and minimap
+5
View File
@@ -39,6 +39,11 @@ protected:
*/
virtual void HandleMessage(SGUIMessage &Message);
/**
* @see IGUIObject#MouseOver()
*/
virtual bool MouseOver();
// create the minimap textures
void CreateTextures();