attribute tooltips

actorid
scrawl 13 years ago
parent 0a223196e8
commit 194ecf274c

@ -72,6 +72,8 @@ StatsWindow::StatsWindow (WindowManager& parWindowManager)
MyGUI::WindowPtr t = static_cast<MyGUI::WindowPtr>(mMainWidget); MyGUI::WindowPtr t = static_cast<MyGUI::WindowPtr>(mMainWidget);
t->eventWindowChangeCoord += MyGUI::newDelegate(this, &StatsWindow::onWindowResize); t->eventWindowChangeCoord += MyGUI::newDelegate(this, &StatsWindow::onWindowResize);
setupToolTips();
} }
void StatsWindow::onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos) void StatsWindow::onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos)
@ -394,3 +396,98 @@ void StatsWindow::onPinToggled()
{ {
mWindowManager.setHMSVisibility(!mPinned); mWindowManager.setHMSVisibility(!mPinned);
} }
void StatsWindow::setupToolTips()
{
const ESMS::ESMStore &store = mWindowManager.getStore();
MyGUI::Widget* widget;
getWidget(widget, "Attrib1");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeStrength")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sStrDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_strength.dds");
getWidget(widget, "AttribVal1");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeStrength")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sStrDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_strength.dds");
getWidget(widget, "Attrib2");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeIntelligence")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sIntDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_int.dds");
getWidget(widget, "AttribVal2");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeIntelligence")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sIntDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_int.dds");
getWidget(widget, "Attrib3");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeWillpower")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sWilDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_wilpower.dds");
getWidget(widget, "AttribVal3");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeWillpower")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sWilDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_wilpower.dds");
getWidget(widget, "Attrib4");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeAgility")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sAgiDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_agility.dds");
getWidget(widget, "AttribVal4");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeAgility")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sAgiDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_agility.dds");
getWidget(widget, "Attrib5");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeSpeed")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sSpdDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_speed.dds");
getWidget(widget, "AttribVal5");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeSpeed")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sSpdDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_speed.dds");
getWidget(widget, "Attrib6");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeEndurance")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sEndDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_endurance.dds");
getWidget(widget, "AttribVal6");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeEndurance")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sEndDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_endurance.dds");
getWidget(widget, "Attrib7");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributePersonality")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sPerDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_personality.dds");
getWidget(widget, "AttribVal7");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributePersonality")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sPerDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_personality.dds");
getWidget(widget, "Attrib8");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeLuck")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sLucDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_luck.dds");
getWidget(widget, "AttribVal8");
widget->setUserString("ToolTipType", "ImageCaptionText");
widget->setUserString("ToolTipCaption", store.gameSettings.find ("sAttributeLuck")->str);
widget->setUserString("ToolTipText", store.gameSettings.find ("sLucDesc")->str);
widget->setUserString("ToolTipImage", "k\\attribute_luck.dds");
}

@ -57,6 +57,8 @@ namespace MWGui
void addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void updateScroller(); void updateScroller();
void setupToolTips();
void onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos); void onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos);
void onWindowResize(MyGUI::Window* window); void onWindowResize(MyGUI::Window* window);

@ -11,8 +11,6 @@ ToolTips::ToolTips(WindowManager* windowManager) :
, mGameMode(true) , mGameMode(true)
, mWindowManager(windowManager) , mWindowManager(windowManager)
{ {
getWidget(mTextToolTip, "TextToolTip");
getWidget(mTextToolTipBox, "TextToolTipBox");
getWidget(mDynamicToolTipBox, "DynamicToolTipBox"); getWidget(mDynamicToolTipBox, "DynamicToolTipBox");
mDynamicToolTipBox->setVisible(false); mDynamicToolTipBox->setVisible(false);
@ -20,8 +18,6 @@ ToolTips::ToolTips(WindowManager* windowManager) :
// turn off mouse focus so that getMouseFocusWidget returns the correct widget, // turn off mouse focus so that getMouseFocusWidget returns the correct widget,
// even if the mouse is over the tooltip // even if the mouse is over the tooltip
mDynamicToolTipBox->setNeedMouseFocus(false); mDynamicToolTipBox->setNeedMouseFocus(false);
mTextToolTipBox->setNeedMouseFocus(false);
mTextToolTip->setNeedMouseFocus(false);
mMainWidget->setNeedMouseFocus(false); mMainWidget->setNeedMouseFocus(false);
} }
@ -29,37 +25,54 @@ void ToolTips::onFrame(float frameDuration)
{ {
/// \todo Store a MWWorld::Ptr in the widget user data, retrieve it here and construct a tooltip dynamically /// \todo Store a MWWorld::Ptr in the widget user data, retrieve it here and construct a tooltip dynamically
/// \todo we are destroying/creating the tooltip widgets every frame here,
/// because the tooltip might change (e.g. when trap is activated)
/// is there maybe a better way (listener when the object changes)?
for (size_t i=0; i<mDynamicToolTipBox->getChildCount(); ++i)
{
mDynamicToolTipBox->_destroyChildWidget(mDynamicToolTipBox->getChildAt(i));
}
const IntSize &viewSize = RenderManager::getInstance().getViewSize(); const IntSize &viewSize = RenderManager::getInstance().getViewSize();
if (!mGameMode) if (!mGameMode)
{ {
mDynamicToolTipBox->setVisible(false);
mTextToolTipBox->setVisible(true);
Widget* focus = InputManager::getInstance().getMouseFocusWidget(); Widget* focus = InputManager::getInstance().getMouseFocusWidget();
if (focus == 0) if (focus == 0)
{ {
mTextToolTipBox->setVisible(false); mDynamicToolTipBox->setVisible(false);
return; return;
} }
// this the maximum width of the tooltip before it starts word-wrapping
setCoord(0, 0, 300, 300);
IntSize tooltipSize;
std::string type = focus->getUserString("ToolTipType"); std::string type = focus->getUserString("ToolTipType");
std::string text = focus->getUserString("ToolTipText"); std::string text = focus->getUserString("ToolTipText");
if (type == "" || text == "") if (type == "")
{ {
mTextToolTipBox->setVisible(false); mDynamicToolTipBox->setVisible(false);
return; return;
} }
else if (type == "Text")
// this the maximum width of the tooltip before it starts word-wrapping tooltipSize = createToolTip(text);
setCoord(0, 0, 300, 300); else if (type == "CaptionText")
{
mTextToolTip->setCaption(text); std::string caption = focus->getUserString("ToolTipCaption");
const IntSize &textSize = mTextToolTip->getTextSize(); tooltipSize = createToolTip(caption, text);
}
else if (type == "ImageCaptionText")
{
std::string caption = focus->getUserString("ToolTipCaption");
std::string image = focus->getUserString("ToolTipImage");
tooltipSize = createImageToolTip(caption, image, text);
}
IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24); IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24);
IntSize size = textSize + IntSize(6, 6); IntSize size = tooltipSize + IntSize(6, 6);
// make the tooltip stay completely in the viewport // make the tooltip stay completely in the viewport
if ((tooltipPosition.left + size.width) > viewSize.width) if ((tooltipPosition.left + size.width) > viewSize.width)
{ {
@ -74,8 +87,6 @@ void ToolTips::onFrame(float frameDuration)
} }
else else
{ {
mTextToolTipBox->setVisible(false);
if (!mFocusObject.isEmpty()) if (!mFocusObject.isEmpty())
{ {
IntSize tooltipSize = getToolTipViaPtr(); IntSize tooltipSize = getToolTipViaPtr();
@ -111,14 +122,6 @@ void ToolTips::setFocusObject(const MWWorld::Ptr& focus)
IntSize ToolTips::getToolTipViaPtr () IntSize ToolTips::getToolTipViaPtr ()
{ {
/// \todo we are destroying/creating the tooltip widgets every frame here,
/// because the tooltip might change (e.g. when trap is activated)
/// is there maybe a better way (listener when the object changes)?
for (size_t i=0; i<mDynamicToolTipBox->getChildCount(); ++i)
{
mDynamicToolTipBox->_destroyChildWidget(mDynamicToolTipBox->getChildAt(i));
}
// this the maximum width of the tooltip before it starts word-wrapping // this the maximum width of the tooltip before it starts word-wrapping
setCoord(0, 0, 300, 300); setCoord(0, 0, 300, 300);
@ -337,7 +340,7 @@ IntSize ToolTips::getToolTipViaPtr ()
text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight);
text += getValueString(ref->base->data.value); text += getValueString(ref->base->data.value);
tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, ""); tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text);
} }
// -------------------- Activator ------------------------------- // -------------------- Activator -------------------------------
@ -375,7 +378,7 @@ IntSize ToolTips::createImageToolTip(const std::string& caption, const std::stri
{ {
// remove the first newline (easier this way) // remove the first newline (easier this way)
std::string realText = text; std::string realText = text;
if (realText.size() > 0) if (realText.size() > 0 && realText[0] == '\n')
realText.erase(0, 1); realText.erase(0, 1);
std::string realImage = "icons\\" + image; std::string realImage = "icons\\" + image;
@ -389,6 +392,7 @@ IntSize ToolTips::createImageToolTip(const std::string& caption, const std::stri
EditBox* textWidget = mDynamicToolTipBox->createWidget<EditBox>("SandText", IntCoord(0, imageSize, 300, 262), Align::Stretch, "ToolTipText"); EditBox* textWidget = mDynamicToolTipBox->createWidget<EditBox>("SandText", IntCoord(0, imageSize, 300, 262), Align::Stretch, "ToolTipText");
textWidget->setProperty("Static", "true"); textWidget->setProperty("Static", "true");
textWidget->setProperty("MultiLine", "true"); textWidget->setProperty("MultiLine", "true");
textWidget->setProperty("WordWrap", "true");
textWidget->setCaption(realText); textWidget->setCaption(realText);
textWidget->setTextAlign(Align::HCenter); textWidget->setTextAlign(Align::HCenter);
@ -414,13 +418,14 @@ IntSize ToolTips::createToolTip(const std::string& caption, const std::string& t
{ {
// remove the first newline (easier this way) // remove the first newline (easier this way)
std::string realText = text; std::string realText = text;
if (realText.size() > 0) if (realText.size() > 0 && realText[0] == '\n')
realText.erase(0, 1); realText.erase(0, 1);
EditBox* box = mDynamicToolTipBox->createWidget<EditBox>("NormalText", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); EditBox* box = mDynamicToolTipBox->createWidget<EditBox>("NormalText", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip");
box->setTextAlign(Align::HCenter); box->setTextAlign(Align::HCenter);
box->setProperty("Static", "true"); box->setProperty("Static", "true");
box->setProperty("MultiLine", "true"); box->setProperty("MultiLine", "true");
box->setProperty("WordWrap", "true");
box->setCaption(caption + (realText != "" ? "\n#BF9959" + realText : "")); box->setCaption(caption + (realText != "" ? "\n#BF9959" + realText : ""));
mDynamicToolTipBox->setVisible(caption != ""); mDynamicToolTipBox->setVisible(caption != "");
@ -428,6 +433,20 @@ IntSize ToolTips::createToolTip(const std::string& caption, const std::string& t
return box->getTextSize(); return box->getTextSize();
} }
IntSize ToolTips::createToolTip(const std::string& text)
{
EditBox* box = mDynamicToolTipBox->createWidget<EditBox>("SandText", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip");
box->setTextAlign(Align::HCenter);
box->setProperty("Static", "true");
box->setProperty("MultiLine", "true");
box->setProperty("WordWrap", "true");
box->setCaption(text);
mDynamicToolTipBox->setVisible(text != "");
return box->getTextSize();
}
std::string ToolTips::toString(const float value) std::string ToolTips::toString(const float value)
{ {
std::ostringstream stream; std::ostringstream stream;

@ -21,12 +21,7 @@ namespace MWGui
void setFocusObject(const MWWorld::Ptr& focus); void setFocusObject(const MWWorld::Ptr& focus);
void adjustScreen(int screenWidth, int screenHeight);
private: private:
MyGUI::EditBox* mTextToolTip;
MyGUI::Widget* mTextToolTipBox;
MyGUI::Widget* mDynamicToolTipBox; MyGUI::Widget* mDynamicToolTipBox;
WindowManager* mWindowManager; WindowManager* mWindowManager;
@ -44,6 +39,9 @@ namespace MWGui
MyGUI::IntSize createToolTip(const std::string& caption, const std::string& text); MyGUI::IntSize createToolTip(const std::string& caption, const std::string& text);
///< @return requested tooltip size ///< @return requested tooltip size
MyGUI::IntSize createToolTip(const std::string& text);
///< @return requested tooltip size
std::string getValueString(const int value); std::string getValueString(const int value);
///< get "Value: X" string or "" if value is 0 ///< get "Value: X" string or "" if value is 0

@ -3,16 +3,6 @@
<MyGUI type="Layout"> <MyGUI type="Layout">
<Widget type="Widget" layer="Popup" position="0 0 300 300" name="_Main"> <Widget type="Widget" layer="Popup" position="0 0 300 300" name="_Main">
<!-- Simple text-only tooltip -->
<Widget type="Widget" skin="HUD_Box" position="0 0 300 300" align="Stretch" name="TextToolTipBox">
<Property key="Visible" value="false"/>
<Widget type="EditBox" skin="NormalText" position="0 0 300 300" align="Stretch" name="TextToolTip">
<Property key="WordWrap" value="true"/>
<Property key="Static" value="true"/>
<Property key="TextAlign" value="Left Top"/>
</Widget>
</Widget>
<!-- Dynamically constructed tooltip goes here --> <!-- Dynamically constructed tooltip goes here -->
<Widget type="Widget" skin="HUD_Box" position="0 0 300 300" align="Stretch" name="DynamicToolTipBox"> <Widget type="Widget" skin="HUD_Box" position="0 0 300 300" align="Stretch" name="DynamicToolTipBox">
<Property key="Visible" value="false"/> <Property key="Visible" value="false"/>

Loading…
Cancel
Save