Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/GUITooltip.cpp
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
const double CooldownTime = 0.25; // TODO: Don't hard-code this value | const double CooldownTime = 0.25; // TODO: Don't hard-code this value | ||||
bool GUITooltip::GetTooltip(IGUIObject* obj, CStr& style) | bool GUITooltip::GetTooltip(IGUIObject* obj, CStr& style) | ||||
{ | { | ||||
if (obj && obj->SettingExists("_icon_tooltip_style") && obj->MouseOverIcon()) | if (obj && obj->SettingExists("_icon_tooltip_style") && obj->MouseOverIcon()) | ||||
{ | { | ||||
style = GUI<CStr>::GetSetting(obj, "_icon_tooltip_style"); | style = obj->GetSetting<CStr>("_icon_tooltip_style"); | ||||
if (!GUI<CStrW>::GetSetting(obj, "_icon_tooltip").empty()) | if (!obj->GetSetting<CStrW>("_icon_tooltip").empty()) | ||||
{ | { | ||||
if (style.empty()) | if (style.empty()) | ||||
style = "default"; | style = "default"; | ||||
m_IsIconTooltip = true; | m_IsIconTooltip = true; | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
if (obj && obj->SettingExists("tooltip_style")) | if (obj && obj->SettingExists("tooltip_style")) | ||||
{ | { | ||||
style = GUI<CStr>::GetSetting(obj, "tooltip_style"); | style = obj->GetSetting<CStr>("tooltip_style"); | ||||
if (!GUI<CStrW>::GetSetting(obj, "tooltip").empty()) | if (!obj->GetSetting<CStrW>("tooltip").empty()) | ||||
{ | { | ||||
if (style.empty()) | if (style.empty()) | ||||
style = "default"; | style = "default"; | ||||
m_IsIconTooltip = false; | m_IsIconTooltip = false; | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
Show All 11 Lines | void GUITooltip::ShowTooltip(IGUIObject* obj, const CPos& pos, const CStr& style, CGUI& pGUI) | ||||
if (!tooltipobj) | if (!tooltipobj) | ||||
{ | { | ||||
LOGERROR("Cannot find tooltip named '%s'", style.c_str()); | LOGERROR("Cannot find tooltip named '%s'", style.c_str()); | ||||
return; | return; | ||||
} | } | ||||
IGUIObject* usedobj = tooltipobj; // object actually used to display the tooltip in | IGUIObject* usedobj = tooltipobj; // object actually used to display the tooltip in | ||||
const CStr& usedObjectName = GUI<CStr>::GetSetting(tooltipobj, "use_object"); | const CStr& usedObjectName = tooltipobj->GetSetting<CStr>("use_object"); | ||||
if (!usedObjectName.empty()) | if (!usedObjectName.empty()) | ||||
{ | { | ||||
usedobj = pGUI.FindObjectByName(usedObjectName); | usedobj = pGUI.FindObjectByName(usedObjectName); | ||||
if (!usedobj) | if (!usedobj) | ||||
{ | { | ||||
LOGERROR("Cannot find object named '%s' used by tooltip '%s'", usedObjectName.c_str(), style.c_str()); | LOGERROR("Cannot find object named '%s' used by tooltip '%s'", usedObjectName.c_str(), style.c_str()); | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
else if (GUI<CPos>::SetSetting(usedobj, "_mousepos", pos) != PSRETURN_OK) | else if (GUI<CPos>::SetSetting(usedobj, "_mousepos", pos) != PSRETURN_OK) | ||||
debug_warn(L"Failed to set tooltip mouse position"); | debug_warn(L"Failed to set tooltip mouse position"); | ||||
GUI<bool>::SetSetting(usedobj, "hidden", false); | GUI<bool>::SetSetting(usedobj, "hidden", false); | ||||
const CStrW& text = GUI<CStrW>::GetSetting(obj, m_IsIconTooltip ? "_icon_tooltip" : "tooltip"); | const CStrW& text = obj->GetSetting<CStrW>(m_IsIconTooltip ? "_icon_tooltip" : "tooltip"); | ||||
if (usedobj->SetSetting("caption", text) != PSRETURN_OK) | if (usedobj->SetSetting("caption", text) != PSRETURN_OK) | ||||
debug_warn(L"Failed to set tooltip caption"); | debug_warn(L"Failed to set tooltip caption"); | ||||
SGUIMessage msg(GUIM_SETTINGS_UPDATED, "caption"); | SGUIMessage msg(GUIM_SETTINGS_UPDATED, "caption"); | ||||
usedobj->HandleMessage(msg); | usedobj->HandleMessage(msg); | ||||
} | } | ||||
void GUITooltip::HideTooltip(const CStr& style, CGUI& pGUI) | void GUITooltip::HideTooltip(const CStr& style, CGUI& pGUI) | ||||
{ | { | ||||
if (style.empty()) | if (style.empty()) | ||||
return; | return; | ||||
IGUIObject* tooltipobj = pGUI.FindObjectByName("__tooltip_" + style); | IGUIObject* tooltipobj = pGUI.FindObjectByName("__tooltip_" + style); | ||||
if (!tooltipobj) | if (!tooltipobj) | ||||
{ | { | ||||
LOGERROR("Cannot find tooltip named '%s'", style.c_str()); | LOGERROR("Cannot find tooltip named '%s'", style.c_str()); | ||||
return; | return; | ||||
} | } | ||||
const CStr& usedObjectName = GUI<CStr>::GetSetting(tooltipobj, "use_object"); | const CStr& usedObjectName = tooltipobj->GetSetting<CStr>("use_object"); | ||||
if (!usedObjectName.empty()) | if (!usedObjectName.empty()) | ||||
{ | { | ||||
IGUIObject* usedobj = pGUI.FindObjectByName(usedObjectName); | IGUIObject* usedobj = pGUI.FindObjectByName(usedObjectName); | ||||
if (!usedobj) | if (!usedobj) | ||||
{ | { | ||||
LOGERROR("Cannot find object named '%s' used by tooltip '%s'", usedObjectName.c_str(), style.c_str()); | LOGERROR("Cannot find object named '%s' used by tooltip '%s'", usedObjectName.c_str(), style.c_str()); | ||||
return; | return; | ||||
} | } | ||||
usedobj->SetSetting("caption", L""); | usedobj->SetSetting("caption", L""); | ||||
SGUIMessage msg(GUIM_SETTINGS_UPDATED, "caption"); | SGUIMessage msg(GUIM_SETTINGS_UPDATED, "caption"); | ||||
usedobj->HandleMessage(msg); | usedobj->HandleMessage(msg); | ||||
if (GUI<bool>::GetSetting(tooltipobj, "hide_object")) | if (tooltipobj->GetSetting<bool>("hide_object")) | ||||
GUI<bool>::SetSetting(usedobj, "hidden", true); | GUI<bool>::SetSetting(usedobj, "hidden", true); | ||||
} | } | ||||
else | else | ||||
GUI<bool>::SetSetting(tooltipobj, "hidden", true); | GUI<bool>::SetSetting(tooltipobj, "hidden", true); | ||||
} | } | ||||
static int GetTooltipDelay(const CStr& style, CGUI& pGUI) | static i32 GetTooltipDelay(const CStr& style, CGUI& pGUI) | ||||
{ | { | ||||
IGUIObject* tooltipobj = pGUI.FindObjectByName("__tooltip_" + style); | IGUIObject* tooltipobj = pGUI.FindObjectByName("__tooltip_" + style); | ||||
if (!tooltipobj) | if (!tooltipobj) | ||||
{ | { | ||||
LOGERROR("Cannot find tooltip object named '%s'", style.c_str()); | LOGERROR("Cannot find tooltip object named '%s'", style.c_str()); | ||||
return 500; | return 500; | ||||
} | } | ||||
return GUI<int>::GetSetting(tooltipobj, "delay"); | return tooltipobj->GetSetting<i32>("delay"); | ||||
} | } | ||||
void GUITooltip::Update(IGUIObject* Nearest, const CPos& MousePos, CGUI& GUI) | void GUITooltip::Update(IGUIObject* Nearest, const CPos& MousePos, CGUI& GUI) | ||||
{ | { | ||||
// Called once per frame, so efficiency isn't vital | // Called once per frame, so efficiency isn't vital | ||||
double now = timer_Time(); | double now = timer_Time(); | ||||
CStr style; | CStr style; | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator