From 705d4c6d54f94bad23fdf07efedc5842f73322de Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 15 Apr 2012 21:14:14 +0200 Subject: [PATCH] mostly complete --- apps/openmw/mwgui/stats_window.cpp | 16 +- apps/openmw/mwgui/stats_window.hpp | 2 +- apps/openmw/mwgui/tooltips.cpp | 590 ++++++++++++++------------- apps/openmw/mwgui/tooltips.hpp | 24 +- apps/openmw/mwgui/window_manager.cpp | 2 +- files/mygui/openmw_tooltips.xml | 2 +- 6 files changed, 341 insertions(+), 295 deletions(-) diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 675e5141f..23f93cd1b 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -251,14 +251,18 @@ void StatsWindow::addGroup(const std::string &label, MyGUI::IntCoord &coord1, My coord2.top += lineHeight; } -MyGUI::TextBox* StatsWindow::addValueItem(const std::string text, const std::string &value, ColorStyle style, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) +MyGUI::TextBox* StatsWindow::addValueItem(const std::string text, const std::string& tooltip, const std::string &value, ColorStyle style, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { MyGUI::TextBox *skillNameWidget, *skillValueWidget; skillNameWidget = skillClientWidget->createWidget("SandText", coord1, MyGUI::Align::Default); skillNameWidget->setCaption(text); + skillNameWidget->setUserString("ToolTipType", "Text"); + skillNameWidget->setUserString("ToolTipText", tooltip); skillValueWidget = skillClientWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Default); + skillValueWidget->setUserString("ToolTipType", "Text"); + skillValueWidget->setUserString("ToolTipText", tooltip); setStyledText(skillValueWidget, style, value); skillWidgets.push_back(skillNameWidget); @@ -310,7 +314,7 @@ void StatsWindow::addSkills(const SkillList &skills, const std::string &titleId, style = CS_Super; else if (modified < base) style = CS_Sub; - MyGUI::TextBox* widget = addValueItem(mWindowManager.getGameSettingString(skillNameId, skillNameId), boost::lexical_cast(static_cast(modified)), style, coord1, coord2); + MyGUI::TextBox* widget = addValueItem(mWindowManager.getGameSettingString(skillNameId, skillNameId), "", boost::lexical_cast(static_cast(modified)), style, coord1, coord2); skillWidgetMap[skillId] = widget; } } @@ -369,8 +373,12 @@ void StatsWindow::updateSkillArea() if (!skillWidgets.empty()) addSeparator(coord1, coord2); - addValueItem(mWindowManager.getGameSettingString("sReputation", "Reputation"), boost::lexical_cast(static_cast(reputation)), CS_Normal, coord1, coord2); - addValueItem(mWindowManager.getGameSettingString("sBounty", "Bounty"), boost::lexical_cast(static_cast(bounty)), CS_Normal, coord1, coord2); + addValueItem(mWindowManager.getGameSettingString("sReputation", "Reputation"), + mWindowManager.getGameSettingString("sSkillsMenuReputationHelp", ""), + boost::lexical_cast(static_cast(reputation)), CS_Normal, coord1, coord2); + addValueItem(mWindowManager.getGameSettingString("sBounty", "Bounty"), + mWindowManager.getGameSettingString("sCrimeHelp", ""), + boost::lexical_cast(static_cast(bounty)), CS_Normal, coord1, coord2); clientHeight = coord1.top; updateScroller(); diff --git a/apps/openmw/mwgui/stats_window.hpp b/apps/openmw/mwgui/stats_window.hpp index f2731e545..1ce3db98d 100644 --- a/apps/openmw/mwgui/stats_window.hpp +++ b/apps/openmw/mwgui/stats_window.hpp @@ -53,7 +53,7 @@ namespace MWGui void addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); - MyGUI::TextBox* addValueItem(const std::string text, const std::string &value, ColorStyle style, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); + MyGUI::TextBox* addValueItem(const std::string text, const std::string& tooltip, const std::string &value, ColorStyle style, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void updateScroller(); diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 7f45bdbdd..4c435e3bf 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -1,12 +1,15 @@ #include "tooltips.hpp" +#include "window_manager.hpp" + +#include using namespace MWGui; using namespace MyGUI; -ToolTips::ToolTips() : +ToolTips::ToolTips(WindowManager* windowManager) : Layout("openmw_tooltips.xml") , mGameMode(true) - , mFocusChanged(true) + , mWindowManager(windowManager) { getWidget(mTextToolTip, "TextToolTip"); getWidget(mTextToolTipBox, "TextToolTipBox"); @@ -31,19 +34,32 @@ void ToolTips::onFrame(float frameDuration) if (!mGameMode) { mDynamicToolTipBox->setVisible(false); + mTextToolTipBox->setVisible(true); Widget* focus = InputManager::getInstance().getMouseFocusWidget(); - if (focus == 0) return; + if (focus == 0) + { + mTextToolTipBox->setVisible(false); + return; + } + + std::string type = focus->getUserString("ToolTipType"); + std::string text = focus->getUserString("ToolTipText"); + if (type == "" || text == "") + { + mTextToolTipBox->setVisible(false); + return; + } // this the maximum width of the tooltip before it starts word-wrapping setCoord(0, 0, 300, 300); - mTextToolTip->setCaption("Focused: " + focus->getName() + "\nType: " + focus->getTypeName()); + mTextToolTip->setCaption(text); const IntSize &textSize = mTextToolTip->getTextSize(); IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24); - IntSize size = textSize + IntSize(12, 12); + IntSize size = textSize + IntSize(6, 6); // make the tooltip stay completely in the viewport if ((tooltipPosition.left + size.width) > viewSize.width) { @@ -62,372 +78,374 @@ void ToolTips::onFrame(float frameDuration) if (!mFocusObject.isEmpty()) { - if (mFocusChanged) - { - for (size_t i=0; igetChildCount(); ++i) - { - mDynamicToolTipBox->_destroyChildWidget(mDynamicToolTipBox->getChildAt(i)); - } - - // this the maximum width of the tooltip before it starts word-wrapping - setCoord(0, 0, 300, 300); - - IntSize tooltipSize; - - /// \todo Not sure about levelled lists (ESM::CreateLevList and ESM::ItemLevList). I think - /// they are supposed to spawn a concrete object (Creature or item of any type), so - /// the player wouldn't encounter them and we don't have to handle them here. - - // -------------------- Door ------------------------------- - if (mFocusObject.getTypeName() == typeid(ESM::Door).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); - - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setProperty("MultiLine", "true"); - - std::string caption = ref->base->name; - /// \todo If destCell is empty, the teleport target is an exterior cell. In that case we - /// need to fetch that cell (via target position) and retrieve the region name. - if (ref->ref.teleport && (ref->ref.destCell != "")) - { - caption += "\n-"; - caption += "\n"+ref->ref.destCell; - } - box->setCaption(caption); - - /// \todo Lock level, trap (retrieve GMST) + IntSize tooltipSize = getToolTipViaPtr(); - tooltipSize = box->getTextSize() + IntSize(12,12); + tooltipSize += IntSize(6,6); // padding, adjust for skin - mDynamicToolTipBox->setVisible(true); - } - - // -------------------- NPC ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::NPC).name()) - { - /// \todo We don't want tooltips for NPCs in combat mode. - ESMS::LiveCellRef* ref = mFocusObject.get(); - - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); - - tooltipSize = box->getTextSize() + IntSize(12,12); - - mDynamicToolTipBox->setVisible(true); - } - - // -------------------- Creature ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Creature).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); - - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); - - /// \todo - - tooltipSize = box->getTextSize() + IntSize(12,12); - - mDynamicToolTipBox->setVisible(true); - } - - // -------------------- CreatureLevList ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Creature).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + // adjust tooltip size to fit its content, position it above the crosshair + /// \todo Slide the tooltip along the bounding box of the focused object (like in Morrowind) + setCoord(viewSize.width/2 - (tooltipSize.width)/2.f, + viewSize.height/2 - (tooltipSize.height) - 32, + tooltipSize.width, + tooltipSize.height); + } + else + mDynamicToolTipBox->setVisible(false); + } +} - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); +void ToolTips::enterGameMode() +{ + mGameMode = true; +} - /// \todo +void ToolTips::enterGuiMode() +{ + mGameMode = false; +} - tooltipSize = box->getTextSize() + IntSize(12,12); +void ToolTips::setFocusObject(const MWWorld::Ptr& focus) +{ + mFocusObject = focus; +} - mDynamicToolTipBox->setVisible(true); - } +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; igetChildCount(); ++i) + { + mDynamicToolTipBox->_destroyChildWidget(mDynamicToolTipBox->getChildAt(i)); + } - // -------------------- Container ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Container).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + // this the maximum width of the tooltip before it starts word-wrapping + setCoord(0, 0, 300, 300); - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); + IntSize tooltipSize; - /// \todo Lock level, trap (retrieve GMST) + // -------------------- Door ------------------------------- + if (mFocusObject.getTypeName() == typeid(ESM::Door).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - tooltipSize = box->getTextSize() + IntSize(12,12); + std::string text; + /// \todo If destCell is empty, the teleport target is an exterior cell. In that case we + /// need to fetch that cell (via target position) and retrieve the region name. + if (ref->ref.teleport && (ref->ref.destCell != "")) + { + text += "\n" + mWindowManager->getGameSettingString("sTo", "to"); + text += "\n"+ref->ref.destCell; + } - mDynamicToolTipBox->setVisible(true); - } + if (ref->ref.lockLevel > 0) + text += "\n" + mWindowManager->getGameSettingString("sLockLevel", "Lock") + ": " + toString(ref->ref.lockLevel); + if (ref->ref.trap != "") + text += "\n" + mWindowManager->getGameSettingString("sTrapped", "Trapped!"); - // -------------------- Potion ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Potion).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + tooltipSize = createToolTip(ref->base->name, text); + } - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); + // -------------------- NPC ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::NPC).name()) + { + /// \todo We don't want tooltips for NPCs in combat mode. + ESMS::LiveCellRef* ref = mFocusObject.get(); - /// \todo + tooltipSize = createToolTip(ref->base->name, ""); + } - tooltipSize = box->getTextSize() + IntSize(12,12); + // -------------------- Creature ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Creature).name()) + { + /// \todo We don't want tooltips for Creatures in combat mode. + ESMS::LiveCellRef* ref = mFocusObject.get(); - mDynamicToolTipBox->setVisible(true); - } + tooltipSize = createToolTip(ref->base->name, ""); + } - // -------------------- Apparatus ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Apparatus).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + // -------------------- Container ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Container).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); + std::string text; - /// \todo + if (ref->ref.lockLevel > 0) + text += "\n" + mWindowManager->getGameSettingString("sLockLevel", "Lock") + ": " + toString(ref->ref.lockLevel); + if (ref->ref.trap != "") + text += "\n" + mWindowManager->getGameSettingString("sTrapped", "Trapped!"); - tooltipSize = box->getTextSize() + IntSize(12,12); + tooltipSize = createToolTip(ref->base->name, text); + } - mDynamicToolTipBox->setVisible(true); - } + // -------------------- Potion ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Potion).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - // -------------------- Armor ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Armor).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + /// \todo magic effects + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); + text += getValueString(ref->base->data.value); - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } - /// \todo weight, armor value, value, durability.. + // -------------------- Apparatus ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Apparatus).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - tooltipSize = box->getTextSize() + IntSize(12,12); + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sQuality", "Quality") + ": " + toString(ref->base->data.quality); + text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); + text += getValueString(ref->base->data.value); - mDynamicToolTipBox->setVisible(true); - } + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } - // -------------------- Book ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Book).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + // -------------------- Armor ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Armor).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); + /// \todo magic effects, armor type (medium/light/heavy) + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sArmorRating", "Armor Rating") + ": " + toString(ref->base->data.armor); - /// \todo + /// \todo where is the current armor health stored? + //text += "\n" + mWindowManager->getGameSettingString("sCondition", "Condition") + ": " + toString(ref->base->data.health); + text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); + text += getValueString(ref->base->data.value); - tooltipSize = box->getTextSize() + IntSize(12,12); + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } - mDynamicToolTipBox->setVisible(true); - } + // -------------------- Book ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Book).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - // -------------------- Clothing ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Clothing).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); + text += getValueString(ref->base->data.value); - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } - /// \todo + // -------------------- Clothing ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Clothing).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - tooltipSize = box->getTextSize() + IntSize(12,12); + /// \todo magic effects + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); + text += getValueString(ref->base->data.value); - mDynamicToolTipBox->setVisible(true); - } + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } - // -------------------- Ingredient ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Ingredient).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + // -------------------- Ingredient ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Ingredient).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); + /// \todo magic effects + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); + text += getValueString(ref->base->data.value); - /// \todo + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } - tooltipSize = box->getTextSize() + IntSize(12,12); + // -------------------- Light ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Light).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - mDynamicToolTipBox->setVisible(true); - } + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); + text += getValueString(ref->base->data.value); - // -------------------- Light ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Light).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); + // -------------------- Tool ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Tool).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - /// \todo + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sUses", "Uses") + ": " + toString(ref->base->data.uses); + text += "\n" + mWindowManager->getGameSettingString("sQuality", "Quality") + ": " + toString(ref->base->data.quality); + text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); + text += getValueString(ref->base->data.value); - tooltipSize = box->getTextSize() + IntSize(12,12); + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } - mDynamicToolTipBox->setVisible(ref->base->name != ""); - } + // -------------------- Miscellaneous ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Miscellaneous).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - // -------------------- Tool ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Tool).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); + text += getValueString(ref->base->data.value); - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } - /// \todo + // -------------------- Probe ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Probe).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - tooltipSize = box->getTextSize() + IntSize(12,12); + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sUses", "Uses") + ": " + toString(ref->base->data.uses); + text += "\n" + mWindowManager->getGameSettingString("sQuality", "Quality") + ": " + toString(ref->base->data.quality); + text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); + text += getValueString(ref->base->data.value); - mDynamicToolTipBox->setVisible(true); - } + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } - // -------------------- Miscellaneous ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Miscellaneous).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + // -------------------- Repair ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Repair).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sUses", "Uses") + ": " + toString(ref->base->data.uses); + text += "\n" + mWindowManager->getGameSettingString("sQuality", "Quality") + ": " + toString(ref->base->data.quality); + text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); + text += getValueString(ref->base->data.value); - /// \todo + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } - tooltipSize = box->getTextSize() + IntSize(12,12); + // -------------------- Weapon ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Weapon).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - mDynamicToolTipBox->setVisible(true); - } + /// \todo weapon damage, magic effects, health (condition) - // -------------------- Probe ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Probe).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); + text += getValueString(ref->base->data.value); - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, ""); + } - /// \todo + // -------------------- Activator ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Activator).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); - tooltipSize = box->getTextSize() + IntSize(12,12); + tooltipSize = createToolTip(ref->base->name, ""); + } - mDynamicToolTipBox->setVisible(true); - } + else + { + // object without tooltip + mDynamicToolTipBox->setVisible(false); + } - // -------------------- Repair ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Repair).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + return tooltipSize; +} - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); +void ToolTips::findImageExtension(std::string& image) +{ + int len = image.size(); + if (len < 4) return; - /// \todo + if (!Ogre::ResourceGroupManager::getSingleton().resourceExists(Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, image)) + { + // Change texture extension to .dds + image[len-3] = 'd'; + image[len-2] = 'd'; + image[len-1] = 's'; + } +} - tooltipSize = box->getTextSize() + IntSize(12,12); +IntSize ToolTips::createImageToolTip(const std::string& caption, const std::string& image, const std::string& text) +{ + // remove the first newline (easier this way) + std::string realText = text; + if (realText.size() > 0) + realText.erase(0, 1); - mDynamicToolTipBox->setVisible(true); - } + std::string realImage = "icons\\" + image; + findImageExtension(realImage); - // -------------------- Weapon ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Weapon).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + const int imageSize = 32; - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); + EditBox* captionWidget = mDynamicToolTipBox->createWidget("NormalText", IntCoord(0, 0, 300, 300), Align::Left | Align::Top, "ToolTipCaption"); + captionWidget->setProperty("Static", "true"); + captionWidget->setCaption(caption); + EditBox* textWidget = mDynamicToolTipBox->createWidget("SandText", IntCoord(0, imageSize, 300, 262), Align::Stretch, "ToolTipText"); + textWidget->setProperty("Static", "true"); + textWidget->setProperty("MultiLine", "true"); + textWidget->setCaption(realText); + textWidget->setTextAlign(Align::HCenter); - /// \todo + IntSize captionSize = captionWidget->getTextSize(); + IntSize textSize = textWidget->getTextSize(); - tooltipSize = box->getTextSize() + IntSize(12,12); + captionSize += IntSize(imageSize, 0); // adjust for image + IntSize totalSize = IntSize( std::max(textSize.width, captionSize.width), ((realText != "") ? textSize.height : 0) + imageSize ); - mDynamicToolTipBox->setVisible(true); - } + ImageBox* imageWidget = mDynamicToolTipBox->createWidget("ImageBox", + IntCoord((totalSize.width - captionSize.width)/2, 0, imageSize, imageSize), + Align::Left | Align::Top, "ToolTipImage"); + imageWidget->setImageTexture(realImage); - // -------------------- Activator ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Activator).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); + captionWidget->setCoord( (totalSize.width - captionSize.width)/2 + imageSize, (32-captionSize.height)/2, captionSize.width-imageSize, captionSize.height); - EditBox* box = mDynamicToolTipBox->createWidget("MW_TextEdit", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); - box->setTextAlign(Align::HCenter); - box->setProperty("Static", "true"); - box->setCaption(ref->base->name); + mDynamicToolTipBox->setVisible(caption != ""); - /// \todo + return totalSize; +} - tooltipSize = box->getTextSize() + IntSize(12,12); +IntSize ToolTips::createToolTip(const std::string& caption, const std::string& text) +{ + // remove the first newline (easier this way) + std::string realText = text; + if (realText.size() > 0) + realText.erase(0, 1); - mDynamicToolTipBox->setVisible(ref->base->name != ""); - } + EditBox* box = mDynamicToolTipBox->createWidget("NormalText", IntCoord(0, 0, 300, 300), Align::Stretch, "ToolTip"); + box->setTextAlign(Align::HCenter); + box->setProperty("Static", "true"); + box->setProperty("MultiLine", "true"); + box->setCaption(caption + (realText != "" ? "\n#BF9959" + realText : "")); - else - { - // object without tooltip - mDynamicToolTipBox->setVisible(false); - } + mDynamicToolTipBox->setVisible(caption != ""); - // adjust tooltip size to fit its content, position it above the crosshair - /// \todo Slide the tooltip along the bounding box of the focused object (like in Morrowind) - setCoord(viewSize.width/2 - (tooltipSize.width)/2.f, - viewSize.height/2 - (tooltipSize.height) - 32, - tooltipSize.width, - tooltipSize.height); - } - mFocusChanged = false; - } - else - mDynamicToolTipBox->setVisible(false); - } + return box->getTextSize(); } -void ToolTips::enterGameMode() +std::string ToolTips::toString(const float value) { - mGameMode = true; + std::ostringstream stream; + stream << std::setprecision(3) << value; + return stream.str(); } -void ToolTips::enterGuiMode() +std::string ToolTips::toString(const int value) { - mGameMode = false; + std::ostringstream stream; + stream << value; + return stream.str(); } -void ToolTips::setFocusObject(const MWWorld::Ptr& focus) +std::string ToolTips::getValueString(const int value) { - if (focus != mFocusObject) - { - mFocusObject = focus; - mFocusChanged = true; - } + if (value == 0) + return ""; + else + return "\n" + mWindowManager->getGameSettingString("sValue", "Value") + ": " + toString(value); } diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index 3052abb7a..cb1af7349 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -7,10 +7,12 @@ namespace MWGui { + class WindowManager; + class ToolTips : public OEngine::GUI::Layout { public: - ToolTips(); + ToolTips(WindowManager* windowManager); void onFrame(float frameDuration); @@ -27,8 +29,26 @@ namespace MWGui MyGUI::Widget* mDynamicToolTipBox; + WindowManager* mWindowManager; + MWWorld::Ptr mFocusObject; - bool mFocusChanged; + + void findImageExtension(std::string& image); + + MyGUI::IntSize getToolTipViaPtr (); + ///< @return requested tooltip size + + MyGUI::IntSize createImageToolTip(const std::string& caption, const std::string& image, const std::string& text); + ///< @return requested tooltip size + + MyGUI::IntSize createToolTip(const std::string& caption, const std::string& text); + ///< @return requested tooltip size + + std::string getValueString(const int value); + ///< get "Value: X" string or "" if value is 0 + + std::string toString(const float value); + std::string toString(const int value); bool mGameMode; }; diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 909be0ac2..8ed2050cc 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -82,7 +82,7 @@ WindowManager::WindowManager(MWWorld::Environment& environment, mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); dialogueWindow = new DialogueWindow(*this,environment); - mToolTips = new ToolTips(); + mToolTips = new ToolTips(this); // The HUD is always on hud->setVisible(true); diff --git a/files/mygui/openmw_tooltips.xml b/files/mygui/openmw_tooltips.xml index 26fc1eeab..1d55bd12f 100644 --- a/files/mygui/openmw_tooltips.xml +++ b/files/mygui/openmw_tooltips.xml @@ -6,7 +6,7 @@ - +