More tooltip updates. Made the main menu buttons and the in-game resource counters use them.
Fixed space/tab inconsistencies in (though not between) GUI XML files. This was SVN commit r1554.
This commit is contained in:
parent
c16d5ec50c
commit
0382cdd9b1
@ -139,15 +139,16 @@
|
||||
-->
|
||||
<!ATTLIST tooltip
|
||||
name CDATA #REQUIRED
|
||||
sprite CDATA #REQUIRED
|
||||
|
||||
sprite CDATA #IMPLIED
|
||||
anchor CDATA #IMPLIED
|
||||
buffer-zone CDATA #IMPLIED
|
||||
font CDATA #IMPLIED
|
||||
maxwidth CDATA #IMPLIED
|
||||
pos CDATA #IMPLIED
|
||||
offset CDATA #IMPLIED
|
||||
textcolor CDATA #IMPLIED
|
||||
time CDATA #IMPLIED
|
||||
delay CDATA #IMPLIED
|
||||
use-object CDATA #IMPLIED
|
||||
hide-object CDATA #IMPLIED
|
||||
>
|
||||
|
||||
|
||||
|
@ -11,55 +11,34 @@
|
||||
-->
|
||||
|
||||
<object type="empty" name="pregame_gui" size="0 0 100% 100%" z="1" hidden="false">
|
||||
<action on="Load"><![CDATA[
|
||||
// Play main 0 A.D. theme when the main menu starts.
|
||||
<action on="Load"><![CDATA[
|
||||
// Play main 0 A.D. theme when the main menu starts.
|
||||
curr_music = newRandomSound("music", "theme");
|
||||
curr_music.loop();
|
||||
]]></action>
|
||||
]]></action>
|
||||
|
||||
<object type="image" name="pregame-mainmenu-background-image" sprite="pregame-mainmenu-background" size="0 0 100% 100%" z="100" hidden="false" ghost="true"/>
|
||||
|
||||
<object type="button" name="pregame-mainmenu-sp-button" sprite-over="pregame-mainmenu-spbt" size="52.9296875% 23.95833333% 67.578125% 42.317708333%" z="101" hidden="false">
|
||||
<object type="button" name="pregame-mainmenu-sp-button" sprite-over="pregame-mainmenu-spbt" size="52.9296875% 23.95833333% 67.578125% 42.317708333%" z="101" hidden="false"
|
||||
tooltip-style="pregame-mainmenu-tooltip" tooltip="Want to move some Dudes around or test something ? Click here to start a new game on the default map.">
|
||||
<action on="Press"><![CDATA[
|
||||
startLoadingScreen();
|
||||
]]></action>
|
||||
<action on="MouseEnter"><![CDATA[
|
||||
tooltipObject = getGUIObjectByName("pregame-mainmenu-tooltip");
|
||||
tooltipObject.caption = "Want to move some Dudes around or test something ? Click here to start a new game on the default map.";
|
||||
GUIObjectUnhide("pregame-mainmenu-tooltip");
|
||||
]]></action>
|
||||
<action on="MouseLeave"><![CDATA[
|
||||
GUIObjectHide("pregame-mainmenu-tooltip");
|
||||
]]></action>
|
||||
</object>
|
||||
</object>
|
||||
|
||||
<object type="button" name="pregame-mainmenu-mp-button" sprite-over="pregame-mainmenu-mpbt" size="60.80% 48.50% 74.40% 66.55%" z="101" hidden="false">
|
||||
<object type="button" name="pregame-mainmenu-mp-button" sprite-over="pregame-mainmenu-mpbt" size="60.80% 48.50% 74.40% 66.55%" z="101" hidden="false"
|
||||
tooltip-style="pregame-mainmenu-tooltip" tooltip="Tired of playing with yourself? Fight against one or more human players in a multiplayer game.">
|
||||
<action on="Press"><![CDATA[
|
||||
getGUIObjectByName("pregame_subwindow_bkg").hidden = false;
|
||||
getGUIObjectByName("pregame_ip_host").hidden = false;
|
||||
]]></action>
|
||||
<action on="MouseEnter"><![CDATA[
|
||||
tooltipObject = getGUIObjectByName("pregame-mainmenu-tooltip");
|
||||
tooltipObject.caption = "Tired of playing with yourself? Fight against one or more human players in a multiplayer game.";
|
||||
GUIObjectUnhide("pregame-mainmenu-tooltip");
|
||||
]]></action>
|
||||
<action on="MouseLeave"><![CDATA[
|
||||
GUIObjectHide("pregame-mainmenu-tooltip");
|
||||
]]></action>
|
||||
</object>
|
||||
|
||||
|
||||
<object type="button" name="pregame-mainmenu-ed-button" sprite-over="pregame-mainmenu-edbt" size="44.00% 61.50% 62.45% 83.55%" z="101" hidden="false">
|
||||
<object type="button" name="pregame-mainmenu-ed-button" sprite-over="pregame-mainmenu-edbt" size="44.00% 61.50% 62.45% 83.55%" z="101" hidden="false"
|
||||
tooltip-style="pregame-mainmenu-tooltip" tooltip="Come forth and witness a totally non-functioning Editor, a mere shadow of its potential self!">
|
||||
<action on="Press"><![CDATA[
|
||||
]]></action>
|
||||
<action on="MouseEnter"><![CDATA[
|
||||
tooltipObject = getGUIObjectByName("pregame-mainmenu-tooltip");
|
||||
tooltipObject.caption = "Come forth and witness a totally non-functioning Editor, a mere shadow of its potential self!";
|
||||
GUIObjectUnhide("pregame-mainmenu-tooltip");
|
||||
]]></action>
|
||||
<action on="MouseLeave"><![CDATA[
|
||||
GUIObjectHide("pregame-mainmenu-tooltip");
|
||||
]]></action>
|
||||
</object>
|
||||
|
||||
<object type="image" name="pregame-mainmenu-0ad-logo" sprite="pregame-mainmenu-0ad-logo-480x218" size="21.1914062% 3.125% 68.0664062% 31.5104166%" z="102" hidden="false" ghost="true"/>
|
||||
@ -71,43 +50,25 @@
|
||||
]]></action>
|
||||
</object>
|
||||
|
||||
<object type="button" name="pregame-mainmenu-wfg-logo" sprite="pregame-mainmenu-wfg-logo-256x64" size="10 91.666666%-30 25.9765% 100%-30" z="102" hidden="false">
|
||||
<object type="button" name="pregame-mainmenu-wfg-logo" sprite="pregame-mainmenu-wfg-logo-256x64" size="10 91.666666%-30 25.9765% 100%-30" z="102" hidden="false"
|
||||
tooltip-style="pregame-mainmenu-tooltip" tooltip="These are the guys who made this game. Visit them at http://www.wildfiregames.com/0ad/">
|
||||
<action on="Press"><![CDATA[
|
||||
btCode = new Array("GUIObjectHide('mb_main');");
|
||||
messageBox(420, 420, "[icon=0ad_icon] A.D. - History Is Yours For The Taking\nby Wildfire Games, 2002-2005\n\nVersion 0.1.2 (PASAP II)\n\n" +
|
||||
"This is a confidental pre-release version of the game!\n\nVisit http://www.wildfiregames.com/0ad/ " +
|
||||
"to learn more about [icon=0ad_icon] A.D., participate in the community and meet the developers.\n\n", "About [icon=0ad_icon] A.D.", 2, new Array(), btCode);
|
||||
]]></action>
|
||||
<action on="MouseEnter"><![CDATA[
|
||||
tooltipObject = getGUIObjectByName("pregame-mainmenu-tooltip");
|
||||
tooltipObject.caption = "These are the guys who made this game. Visit them at http://www.wildfiregames.com/0ad/";
|
||||
GUIObjectUnhide("pregame-mainmenu-tooltip");
|
||||
]]></action>
|
||||
<action on="MouseLeave"><![CDATA[
|
||||
GUIObjectHide("pregame-mainmenu-tooltip");
|
||||
]]></action>
|
||||
</object>
|
||||
|
||||
<object type="text" name="pregame-mainmenu-tooltip" sprite="tooltip-background" size="69% 6.3802% 97.0703125% 28.125%" font="prospero16" textcolor="255 255 255" z="104" hidden="true" ghost="true">tooltipText</object>
|
||||
<object type="text" name="pregame-mainmenu-tooltip" sprite="pregame-mainmenu-tooltip-background" size="69% 6.3802% 97.0703125% 28.125%" font="prospero16" textcolor="255 255 255" z="104" hidden="true" ghost="true">tooltipText</object>
|
||||
|
||||
<object type="button" name="exit_button" sprite="exit_sprite" sprite-over="exit_sprite-over" size="100%-18 2 100%-2 18" z="104" hidden="false">
|
||||
<object type="button" name="exit_button" sprite="exit_sprite" sprite-over="exit_sprite-over" size="100%-18 2 100%-2 18" z="104" hidden="false"
|
||||
tooltip-style="pregame-mainmenu-tooltip" tooltip="Tired of 0 A.D. ? Click here to leave and reenter the real world.">
|
||||
<action on="Press"><![CDATA[
|
||||
btCaptions = new Array("Yes, let me out!", "Nooooo!");
|
||||
btCode = new Array("exit();", "");
|
||||
messageBox(400, 200, "Do you really want to quit [icon=0ad_icon] A.D.? This will cause a sudden return to reality.", "Confirmation", 0, btCaptions, btCode);
|
||||
]]></action>
|
||||
|
||||
<!-- START temporary code
|
||||
This code only applies to the main menu, I don't know how it'll behave ingame. It is temporary and should be removed as soon as we got proper tooltip support implemented. -->
|
||||
<action on="MouseEnter"><![CDATA[
|
||||
tooltipObject = getGUIObjectByName("pregame-mainmenu-tooltip");
|
||||
tooltipObject.caption = "Tired of 0 A.D. ? Click here to leave and reenter the real world.";
|
||||
GUIObjectUnhide("pregame-mainmenu-tooltip");
|
||||
]]></action>
|
||||
<action on="MouseLeave"><![CDATA[
|
||||
GUIObjectHide("pregame-mainmenu-tooltip");
|
||||
]]></action>
|
||||
<!-- END temporary code -->
|
||||
</object>
|
||||
</object>
|
||||
|
||||
@ -131,7 +92,7 @@
|
||||
]]></action>
|
||||
</object>
|
||||
|
||||
<object type="button" name="pregame_ip_host_titlebar" sprite="0ad_window_title" font="prospero18" z="165" text-align="center" text-valign="center">
|
||||
<object type="button" name="pregame_ip_host_titlebar" sprite="0ad_window_title" font="prospero18" z="165" text-align="center" text-valign="center">
|
||||
<action on="Load"><![CDATA[
|
||||
getGUIObjectByName("pregame_ip_host_titlebar").caption = "Direct IP Connect";
|
||||
setSizeCoord("pregame_ip_host_titlebar", crd_pregame_iphost_titlebar_x, crd_pregame_iphost_titlebar_y, crd_pregame_iphost_titlebar_x+crd_pregame_iphost_titlebar_width, crd_pregame_iphost_titlebar_y+crd_pregame_iphost_titlebar_height, mid_screen, mid_screen, mid_screen, mid_screen);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -67,18 +67,24 @@
|
||||
|
||||
<!-- Generic Icons / malte, 15th nov -->
|
||||
<icon name="0ad_icon" texture="0ad_icon" size="16 16" />
|
||||
<icon name="bullet_icon" texture="bullet_icon" size="8 8" />
|
||||
<icon name="infinity_icon" texture="infinity_icon" size="16 16" />
|
||||
<icon name="bullet_icon" texture="bullet_icon" size="8 8" />
|
||||
<icon name="infinity_icon" texture="infinity_icon" size="16 16" />
|
||||
|
||||
<!-- Commented out until tooltips are implemented as documented.
|
||||
<tooltip name="session_tooltip"
|
||||
maxwidth="300"
|
||||
pos="10 10"
|
||||
time="5"
|
||||
sprite="tooltip-background"
|
||||
font="prospero16"
|
||||
textcolor="255 255 255"
|
||||
<tooltip name="pregame-mainmenu-tooltip"
|
||||
use-object="pregame-mainmenu-tooltip"
|
||||
hide-object="true"
|
||||
delay="0"
|
||||
/>
|
||||
|
||||
<tooltip name="session-tooltip"
|
||||
maxwidth="300"
|
||||
offset="16 32"
|
||||
anchor="top"
|
||||
delay="500"
|
||||
sprite="session-tooltip-background"
|
||||
font="tahoma12"
|
||||
buffer-zone="4"
|
||||
textcolor="0 0 0"
|
||||
/>
|
||||
-->
|
||||
|
||||
</setup>
|
||||
|
@ -211,8 +211,12 @@
|
||||
<image texture="pregame/ui_pregame_mainmenu_edbt_over.png" real-texture-placement="1 1 203 161" size="0 0 100% 100%" />
|
||||
</sprite>
|
||||
|
||||
<sprite name="tooltip-background">
|
||||
<image texture="black_16x16.png" texture-size="0 0 16 16" size="0 0 100% 100%" />
|
||||
<sprite name="pregame-mainmenu-tooltip-background">
|
||||
<image backcolor="0 0 0 85" size="0 0 100% 100%"/>
|
||||
</sprite>
|
||||
|
||||
<sprite name="session-tooltip-background">
|
||||
<image backcolor="255 255 255" size="0 0 100% 100%" border="true" bordercolor="0 0 0"/>
|
||||
</sprite>
|
||||
|
||||
<!--
|
||||
|
@ -14,12 +14,12 @@
|
||||
/>
|
||||
|
||||
<style name="button"
|
||||
sprite="sprite1"
|
||||
sprite-pressed="sprite1-pressed"
|
||||
sprite="sprite1"
|
||||
sprite-pressed="sprite1-pressed"
|
||||
sprite-disabled="sprite1-disabled"
|
||||
sprite-over="sprite1-over"
|
||||
sprite2="sprite1-ch"
|
||||
sprite2-pressed="sprite2-pressed"
|
||||
sprite2="sprite1-ch"
|
||||
sprite2-pressed="sprite2-pressed"
|
||||
sprite2-disabled="sprite2-disabled"
|
||||
/>
|
||||
|
||||
@ -28,7 +28,8 @@
|
||||
text-align="right"
|
||||
font="prospero16"
|
||||
textcolor="255 255 255"
|
||||
ghost="true"
|
||||
tooltip-style="session-tooltip"
|
||||
ghost="false"
|
||||
/>
|
||||
|
||||
<!-- Empty entity portrait. -->
|
||||
@ -36,7 +37,7 @@
|
||||
sprite="ui_portrait_default_square"
|
||||
sprite-over="ui_portrait_default_square-lit"
|
||||
sprite-disabled="ui_portrait_default_square-grey"
|
||||
tooltip-style="session-tooltip"
|
||||
tooltip-style="session-tooltip"
|
||||
text-align="right"
|
||||
textcolor="255 255 255"
|
||||
/>
|
||||
@ -45,7 +46,7 @@
|
||||
sprite="ui_portrait_default_circle"
|
||||
sprite-over="ui_portrait_default_circle-lit"
|
||||
sprite-disabled="ui_portrait_default_circle-grey"
|
||||
tooltip-style="session-tooltip"
|
||||
tooltip-style="session-tooltip"
|
||||
text-align="right"
|
||||
textcolor="255 255 255"
|
||||
/>
|
||||
|
@ -1738,10 +1738,9 @@ void CGUI::Xeromyces_ReadIcon(XMBElement Element, CXeromyces* pFile)
|
||||
|
||||
void CGUI::Xeromyces_ReadTooltip(XMBElement Element, CXeromyces* pFile)
|
||||
{
|
||||
IGUIObject* object = new CTooltip;
|
||||
// Read the tooltip, and store it as a specially-named object
|
||||
|
||||
object->SetName(CStr("__internal(") + CStr(m_InternalNameNumber) + CStr(")"));
|
||||
++m_InternalNameNumber;
|
||||
IGUIObject* object = new CTooltip;
|
||||
|
||||
XMBAttributeList attributes = Element.getAttributes();
|
||||
for (int i=0; i<attributes.Count; ++i)
|
||||
@ -1752,7 +1751,7 @@ void CGUI::Xeromyces_ReadTooltip(XMBElement Element, CXeromyces* pFile)
|
||||
|
||||
if (attr_name == "name")
|
||||
{
|
||||
object->SetName(attr_value);
|
||||
object->SetName("__tooltip_" + attr_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,23 +1,34 @@
|
||||
// CTooltip: GUI object used for tooltips
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "CTooltip.h"
|
||||
#include "CGUI.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
CTooltip::CTooltip()
|
||||
{
|
||||
// If the tooltip is an object by itself:
|
||||
AddSetting(GUIST_float, "buffer-zone");
|
||||
AddSetting(GUIST_CGUIString, "caption");
|
||||
AddSetting(GUIST_CStr, "font");
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
||||
AddSetting(GUIST_int, "time");
|
||||
AddSetting(GUIST_int, "delay");
|
||||
AddSetting(GUIST_CColor, "textcolor");
|
||||
AddSetting(GUIST_int, "maxwidth");
|
||||
AddSetting(GUIST_CPos, "pos");
|
||||
AddSetting(GUIST_CPos, "offset");
|
||||
AddSetting(GUIST_EVAlign, "anchor");
|
||||
|
||||
// If the tooltip is just a reference to another object:
|
||||
AddSetting(GUIST_CStr, "use-object");
|
||||
AddSetting(GUIST_bool, "hide-object");
|
||||
|
||||
// Private settings:
|
||||
AddSetting(GUIST_CPos, "_mousepos");
|
||||
|
||||
GUI<int>::SetSetting(this, "time", 500);
|
||||
// Defaults
|
||||
GUI<int>::SetSetting(this, "delay", 500);
|
||||
GUI<EVAlign>::SetSetting(this, "anchor", EVAlign_Bottom);
|
||||
|
||||
// Set up a blank piece of text, to be replaced with a more
|
||||
@ -40,46 +51,54 @@ void CTooltip::SetupText()
|
||||
if (GUI<CStr>::GetSetting(this, "font", font) != PS_OK || font.Length()==0)
|
||||
font = "default";
|
||||
|
||||
float buffer_zone=0.f;
|
||||
float buffer_zone = 0.f;
|
||||
GUI<float>::GetSetting(this, "buffer-zone", buffer_zone);
|
||||
|
||||
CGUIString caption;
|
||||
GUI<CGUIString>::GetSetting(this, "caption", caption);
|
||||
|
||||
float max_width = 500.f; // TODO: max-width setting
|
||||
int max_width = 0;
|
||||
GUI<int>::GetSetting(this, "maxwidth", max_width);
|
||||
|
||||
*m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, max_width, buffer_zone, this);
|
||||
*m_GeneratedTexts[0] = GetGUI()->GenerateText(caption, font, (float)max_width, buffer_zone, this);
|
||||
|
||||
CPos mousepos, pos;
|
||||
|
||||
// Position the tooltip relative to the mouse:
|
||||
|
||||
CPos mousepos, offset;
|
||||
EVAlign anchor;
|
||||
GUI<CPos>::GetSetting(this, "_mousepos", mousepos);
|
||||
GUI<CPos>::GetSetting(this, "pos", pos);
|
||||
GUI<CPos>::GetSetting(this, "offset", offset);
|
||||
GUI<EVAlign>::GetSetting(this, "anchor", anchor);
|
||||
|
||||
// Position the tooltip relative to the mouse
|
||||
// TODO: Calculate the actual width of the wrapped text and use that.
|
||||
// (m_Size.cx is >max_width if the text wraps, which is not helpful)
|
||||
float textwidth = std::min(m_GeneratedTexts[0]->m_Size.cx, (float)max_width);
|
||||
float textheight = m_GeneratedTexts[0]->m_Size.cy;
|
||||
|
||||
CClientArea size;
|
||||
size.pixel.left = mousepos.x + pos.x;
|
||||
size.pixel.right = size.pixel.left + m_GeneratedTexts[0]->m_Size.cx;
|
||||
size.pixel.left = mousepos.x + offset.x;
|
||||
size.pixel.right = size.pixel.left + textwidth;
|
||||
switch (anchor)
|
||||
{
|
||||
case EVAlign_Top:
|
||||
size.pixel.top = mousepos.y + pos.y;
|
||||
size.pixel.bottom = size.pixel.top + m_GeneratedTexts[0]->m_Size.cy;
|
||||
size.pixel.top = mousepos.y + offset.y;
|
||||
size.pixel.bottom = size.pixel.top + textheight;
|
||||
break;
|
||||
case EVAlign_Bottom:
|
||||
size.pixel.bottom = mousepos.y + pos.y;
|
||||
size.pixel.top = size.pixel.bottom - m_GeneratedTexts[0]->m_Size.cy;
|
||||
size.pixel.bottom = mousepos.y + offset.y;
|
||||
size.pixel.top = size.pixel.bottom - textheight;
|
||||
break;
|
||||
case EVAlign_Center:
|
||||
size.pixel.top = mousepos.y + pos.y - m_GeneratedTexts[0]->m_Size.cy/2.f;
|
||||
size.pixel.bottom = size.pixel.top + m_GeneratedTexts[0]->m_Size.cy;
|
||||
size.pixel.top = mousepos.y + offset.y - textheight/2.f;
|
||||
size.pixel.bottom = size.pixel.top + textwidth;
|
||||
break;
|
||||
default:
|
||||
debug_warn("Invalid EVAlign!");
|
||||
}
|
||||
|
||||
// Adjust it if it's falling off the screen
|
||||
|
||||
// Reposition the tooltip if it's falling off the screen:
|
||||
|
||||
extern int g_xres, g_yres;
|
||||
float screenw = (float)g_xres, screenh = (float)g_yres;
|
||||
|
@ -578,10 +578,10 @@ void GUIRenderer::Draw(DrawCalls &Calls)
|
||||
{
|
||||
glColor4fv(cit->m_BorderColor.FloatArray());
|
||||
glBegin(GL_LINE_LOOP);
|
||||
glVertex3f(cit->m_Vertices.left, cit->m_Vertices.top+1.f, cit->m_DeltaZ);
|
||||
glVertex3f(cit->m_Vertices.right-1.f, cit->m_Vertices.top+1.f, cit->m_DeltaZ);
|
||||
glVertex3f(cit->m_Vertices.right-1.f, cit->m_Vertices.bottom, cit->m_DeltaZ);
|
||||
glVertex3f(cit->m_Vertices.left, cit->m_Vertices.bottom, cit->m_DeltaZ);
|
||||
glVertex3f(cit->m_Vertices.left, cit->m_Vertices.top, cit->m_DeltaZ);
|
||||
glVertex3f(cit->m_Vertices.right, cit->m_Vertices.top, cit->m_DeltaZ);
|
||||
glVertex3f(cit->m_Vertices.right, cit->m_Vertices.bottom, cit->m_DeltaZ);
|
||||
glVertex3f(cit->m_Vertices.left, cit->m_Vertices.bottom, cit->m_DeltaZ);
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
IN MOTION
|
||||
* If the mouse stops, check whether it should have a tooltip and move to
|
||||
'STATIONARY, NO TOOLTIP' or 'STATIONARY, TOOLIP'
|
||||
* If the mouse enters an object with a tooltip delay of 0, switch to 'SHOWING'
|
||||
|
||||
STATIONARY, NO TOOLTIP
|
||||
* If the mouse moves, switch to 'IN MOTION'
|
||||
@ -63,85 +64,131 @@ GUITooltip::GUITooltip()
|
||||
|
||||
const double CooldownTime = 0.25; // TODO: Don't hard-code this value
|
||||
|
||||
static bool GetTooltip(IGUIObject* obj, CStr* &style)
|
||||
static bool GetTooltip(IGUIObject* obj, CStr &style)
|
||||
{
|
||||
if (obj && obj->SettingExists("tooltip-style"))
|
||||
if (obj && obj->SettingExists("tooltip-style")
|
||||
&& GUI<CStr>::GetSetting(obj, "tooltip-style", style) == PS_OK)
|
||||
{
|
||||
// Use GetSettingPointer to avoid unnecessary string-copying.
|
||||
// (The tooltip code is only run once per frame, but efficiency
|
||||
// would be nice anyway.)
|
||||
if (GUI<CStr>::GetSettingPointer(obj, "tooltip-style", style) == PS_OK
|
||||
&& style->Length())
|
||||
|
||||
return true;
|
||||
if (style.Length() == 0)
|
||||
style = "default";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Urgh - this is only a method because it needs to access HandleMessage (which
|
||||
// is 'protected'), so it needs to be friendable (and so not a static function)
|
||||
void GUITooltip::ShowTooltip(IGUIObject* obj, CPos pos, CStr& style, CGUI* gui)
|
||||
static void ShowTooltip(IGUIObject* obj, CPos pos, CStr& style, CGUI* gui)
|
||||
{
|
||||
IGUIObject* tooltipobj = gui->FindObjectByName(style);
|
||||
if (! tooltipobj)
|
||||
{
|
||||
LOG_ONCE(ERROR, "gui", "Cannot find tooltip object named '%s'", (const char*)style);
|
||||
return;
|
||||
}
|
||||
// Unhide the object
|
||||
GUI<bool>::SetSetting(tooltipobj, "hidden", false);
|
||||
|
||||
assert(obj);
|
||||
|
||||
// These shouldn't fail:
|
||||
// Get the object referenced by 'tooltip-style'
|
||||
IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style);
|
||||
if (! tooltipobj)
|
||||
{
|
||||
LOG_ONCE(ERROR, "gui", "Cannot find tooltip named '%s'", (const char*)style);
|
||||
return;
|
||||
}
|
||||
|
||||
IGUIObject* usedobj = tooltipobj; // object actually used to display the tooltip in
|
||||
|
||||
CStr usedObjectName;
|
||||
if (GUI<CStr>::GetSetting(tooltipobj, "use-object", usedObjectName) == PS_OK
|
||||
&& usedObjectName.Length())
|
||||
{
|
||||
usedobj = gui->FindObjectByName(usedObjectName);
|
||||
if (! usedobj)
|
||||
{
|
||||
LOG_ONCE(ERROR, "gui", "Cannot find object named '%s' used by tooltip '%s'", (const char*)usedObjectName, (const char*)style);
|
||||
return;
|
||||
}
|
||||
|
||||
// Unhide the object. (If it had use-object and hide-object="true",
|
||||
// still unhide it, because the used object might be hidden by default)
|
||||
GUI<bool>::SetSetting(usedobj, "hidden", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unhide the object
|
||||
GUI<bool>::SetSetting(usedobj, "hidden", false);
|
||||
|
||||
// Store mouse position inside the CTooltip
|
||||
if (GUI<CPos>::SetSetting(usedobj, "_mousepos", pos) != PS_OK)
|
||||
debug_warn("Failed to set tooltip mouse position");
|
||||
}
|
||||
|
||||
// Retrieve object's 'tooltip' setting
|
||||
CStr text;
|
||||
if (GUI<CStr>::GetSetting(obj, "tooltip", text) != PS_OK)
|
||||
debug_warn("Failed to retrieve tooltip text");
|
||||
debug_warn("Failed to retrieve tooltip text"); // shouldn't fail
|
||||
|
||||
// Set tooltip's caption
|
||||
if (tooltipobj->SetSetting("caption", text) != PS_OK)
|
||||
debug_warn("Failed to set tooltip caption");
|
||||
|
||||
// Store mouse position inside the tooltip
|
||||
if (GUI<CPos>::SetSetting(tooltipobj, "_mousepos", pos) != PS_OK)
|
||||
debug_warn("Failed to set tooltip mouse position");
|
||||
if (usedobj->SetSetting("caption", text) != PS_OK)
|
||||
debug_warn("Failed to set tooltip caption"); // shouldn't fail
|
||||
|
||||
// Make the tooltip object regenerate its text
|
||||
tooltipobj->HandleMessage(SGUIMessage(GUIM_SETTINGS_UPDATED, "caption"));
|
||||
usedobj->HandleMessage(SGUIMessage(GUIM_SETTINGS_UPDATED, "caption"));
|
||||
}
|
||||
|
||||
static void HideTooltip(CStr& style, CGUI* gui)
|
||||
{
|
||||
IGUIObject* tooltipobj = gui->FindObjectByName(style);
|
||||
IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style);
|
||||
if (! tooltipobj)
|
||||
{
|
||||
LOG_ONCE(ERROR, "gui", "Cannot find tooltip object named '%s'", (const char*)style);
|
||||
LOG_ONCE(ERROR, "gui", "Cannot find tooltip named '%s'", (const char*)style);
|
||||
return;
|
||||
}
|
||||
GUI<bool>::SetSetting(tooltipobj, "hidden", true);
|
||||
|
||||
CStr usedObjectName;
|
||||
if (GUI<CStr>::GetSetting(tooltipobj, "use-object", usedObjectName) == PS_OK
|
||||
&& usedObjectName.Length())
|
||||
{
|
||||
IGUIObject* usedobj = gui->FindObjectByName(usedObjectName);
|
||||
if (! usedobj)
|
||||
{
|
||||
LOG_ONCE(ERROR, "gui", "Cannot find object named '%s' used by tooltip '%s'", (const char*)usedObjectName, (const char*)style);
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear the caption
|
||||
usedobj->SetSetting("caption", "");
|
||||
usedobj->HandleMessage(SGUIMessage(GUIM_SETTINGS_UPDATED, "caption"));
|
||||
|
||||
|
||||
bool hideobject = true;
|
||||
GUI<bool>::GetSetting(tooltipobj, "hide-object", hideobject);
|
||||
|
||||
// If hide-object was enabled, hide it
|
||||
if (hideobject)
|
||||
GUI<bool>::SetSetting(usedobj, "hidden", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI<bool>::SetSetting(tooltipobj, "hidden", true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int GetTooltipTime(CStr& style, CGUI* gui)
|
||||
static int GetTooltipDelay(CStr& style, CGUI* gui)
|
||||
{
|
||||
int time = 500; // default value (in msec)
|
||||
int delay = 500; // default value (in msec)
|
||||
|
||||
IGUIObject* tooltipobj = gui->FindObjectByName(style);
|
||||
IGUIObject* tooltipobj = gui->FindObjectByName("__tooltip_"+style);
|
||||
if (! tooltipobj)
|
||||
{
|
||||
LOG_ONCE(ERROR, "gui", "Cannot find tooltip object named '%s'", (const char*)style);
|
||||
return time;
|
||||
return delay;
|
||||
}
|
||||
GUI<int>::GetSetting(tooltipobj, "time", time);
|
||||
return time;
|
||||
GUI<int>::GetSetting(tooltipobj, "delay", delay);
|
||||
return delay;
|
||||
}
|
||||
|
||||
void GUITooltip::Update(IGUIObject* Nearest, CPos MousePos, CGUI* GUI)
|
||||
{
|
||||
// Called once per frame, so efficiency isn't vital
|
||||
|
||||
|
||||
double now = get_time();
|
||||
|
||||
CStr* style = NULL;
|
||||
CStr style;
|
||||
|
||||
int nextstate = -1;
|
||||
|
||||
@ -155,6 +202,13 @@ void GUITooltip::Update(IGUIObject* Nearest, CPos MousePos, CGUI* GUI)
|
||||
else
|
||||
nextstate = ST_STATIONARY_NO_TOOLTIP;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check for movement onto a zero-delayed tooltip
|
||||
if (GetTooltip(Nearest, style) && GetTooltipDelay(style, GUI)==0)
|
||||
|
||||
nextstate = ST_SHOWING;
|
||||
}
|
||||
break;
|
||||
|
||||
case ST_STATIONARY_NO_TOOLTIP:
|
||||
@ -190,31 +244,29 @@ void GUITooltip::Update(IGUIObject* Nearest, CPos MousePos, CGUI* GUI)
|
||||
break;
|
||||
|
||||
case ST_COOLING:
|
||||
if (now >= m_Time)
|
||||
nextstate = ST_IN_MOTION;
|
||||
else if (Nearest != m_PreviousObject && GetTooltip(Nearest, style))
|
||||
if (GetTooltip(Nearest, style))
|
||||
nextstate = ST_SHOWING;
|
||||
else if (now >= m_Time)
|
||||
nextstate = ST_IN_MOTION;
|
||||
break;
|
||||
}
|
||||
|
||||
// Handle state-entry code
|
||||
// Handle state-entry code:
|
||||
|
||||
if (nextstate != -1)
|
||||
{
|
||||
switch (nextstate)
|
||||
{
|
||||
case ST_STATIONARY_TOOLTIP:
|
||||
m_Time = now + (double)GetTooltipTime(*style, GUI) / 1000.;
|
||||
m_Time = now + (double)GetTooltipDelay(style, GUI) / 1000.;
|
||||
break;
|
||||
|
||||
case ST_SHOWING:
|
||||
// show tooltip
|
||||
ShowTooltip(Nearest, MousePos, *style, GUI);
|
||||
m_PreviousTooltipName = *style;
|
||||
ShowTooltip(Nearest, MousePos, style, GUI);
|
||||
m_PreviousTooltipName = style;
|
||||
break;
|
||||
|
||||
case ST_COOLING:
|
||||
// hide the tooltip
|
||||
HideTooltip(m_PreviousTooltipName, GUI);
|
||||
m_Time = now + CooldownTime;
|
||||
break;
|
||||
|
@ -14,7 +14,6 @@ public:
|
||||
void Update(IGUIObject* Nearest, CPos MousePos, CGUI* GUI);
|
||||
|
||||
private:
|
||||
void ShowTooltip(IGUIObject* obj, CPos pos, CStr& style, CGUI* gui);
|
||||
|
||||
int m_State;
|
||||
|
||||
|
@ -118,7 +118,7 @@ struct SGUIText
|
||||
bool m_Bold, m_Italic, m_Underlined;
|
||||
|
||||
/**
|
||||
* *IF* an icon, than this is not NULL.
|
||||
* *IF* an icon, then this is not NULL.
|
||||
*/
|
||||
std::list<SSpriteCall>::pointer m_pSpriteCall;
|
||||
};
|
||||
|
@ -471,7 +471,7 @@ CStr IGUIObject::GetPresentableName() const
|
||||
if (m_Name.Length() <= 12)
|
||||
return m_Name;
|
||||
|
||||
if (m_Name.GetSubstring(0, 10) == CStr("__internal"))
|
||||
if (m_Name.GetSubstring(0, 10) == "__internal")
|
||||
return CStr("[unnamed object]");
|
||||
else
|
||||
return m_Name;
|
||||
|
@ -128,7 +128,10 @@ class IGUIObject
|
||||
friend class CGUI;
|
||||
friend class CInternalCGUIAccessorBase;
|
||||
friend class IGUIScrollBar;
|
||||
friend class GUITooltip;
|
||||
|
||||
// Allow ShowTooltip/HideTooltip (GUITooltip.cpp) to access HandleMessage
|
||||
friend void ShowTooltip(IGUIObject*, CPos, CStr&, CGUI*);
|
||||
friend void HideTooltip(CStr&, CGUI*);
|
||||
|
||||
// Allow getProperty to access things like GetParent()
|
||||
friend JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval* vp);
|
||||
|
Loading…
Reference in New Issue
Block a user