From cac662ca981dc0cdb19872f4c40e46b97bf7b365 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 14 Apr 2012 17:47:44 +0200 Subject: [PATCH 01/30] basic tooltips --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/engine.cpp | 16 +++---- apps/openmw/mwgui/tooltips.cpp | 63 ++++++++++++++++++++++++++++ apps/openmw/mwgui/tooltips.hpp | 30 +++++++++++++ apps/openmw/mwgui/window_manager.cpp | 10 +++++ apps/openmw/mwgui/window_manager.hpp | 2 + files/mygui/CMakeLists.txt | 1 + files/mygui/openmw_tooltips.xml | 21 ++++++++++ 8 files changed, 136 insertions(+), 9 deletions(-) create mode 100644 apps/openmw/mwgui/tooltips.cpp create mode 100644 apps/openmw/mwgui/tooltips.hpp create mode 100644 files/mygui/openmw_tooltips.xml diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index c4b3776ed6..a37dbf7af2 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -25,7 +25,7 @@ add_openmw_dir (mwinput add_openmw_dir (mwgui layouts text_input widgets race class birth review window_manager console dialogue dialogue_history window_base stats_window messagebox journalwindow charactercreation - map_window window_pinnable_base cursorreplace + map_window window_pinnable_base cursorreplace tooltips ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 2d3c872dd7..36a2cb645b 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -133,14 +133,6 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) if (mUseSound) mEnvironment.mSoundManager->update (evt.timeSinceLastFrame); - // update GUI - Ogre::RenderWindow* window = mOgre->getWindow(); - mEnvironment.mWindowManager->wmUpdateFps(window->getLastFPS(), - window->getTriangleCount(), - window->getBatchCount()); - - mEnvironment.mWindowManager->onFrame(mEnvironment.mFrameDuration); - // global scripts mEnvironment.mGlobalScripts->run (mEnvironment); @@ -171,6 +163,14 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) // update world mEnvironment.mWorld->update (evt.timeSinceLastFrame); + // update GUI + Ogre::RenderWindow* window = mOgre->getWindow(); + mEnvironment.mWindowManager->wmUpdateFps(window->getLastFPS(), + window->getTriangleCount(), + window->getBatchCount()); + + mEnvironment.mWindowManager->onFrame(mEnvironment.mFrameDuration); + // report focus object (for debugging) if (mReportFocus) updateFocusReport (mEnvironment.mFrameDuration); diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp new file mode 100644 index 0000000000..d7c61c51a6 --- /dev/null +++ b/apps/openmw/mwgui/tooltips.cpp @@ -0,0 +1,63 @@ +#include "tooltips.hpp" + +using namespace MWGui; +using namespace MyGUI; + +ToolTips::ToolTips() : + Layout("openmw_tooltips.xml") + , mGameMode(true) +{ + getWidget(mTextToolTip, "TextToolTip"); + getWidget(mTextToolTipBox, "TextToolTipBox"); + getWidget(mDynamicToolTipBox, "DynamicToolTipBox"); + + mDynamicToolTipBox->setVisible(false); + + // turn off mouse focus so that getMouseFocusWidget returns the correct widget, + // even if the mouse is over the tooltip + mDynamicToolTipBox->setNeedMouseFocus(false); + mTextToolTipBox->setNeedMouseFocus(false); + mTextToolTip->setNeedMouseFocus(false); + mMainWidget->setNeedMouseFocus(false); +} + +void ToolTips::onFrame(float frameDuration) +{ + /// \todo Store a MWWorld::Ptr in the widget user data, retrieve it here and construct a tooltip dynamically + + const IntSize &viewSize = RenderManager::getInstance().getViewSize(); + + Widget* focus = InputManager::getInstance().getMouseFocusWidget(); + if (focus == 0) 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()); + const IntSize &textSize = mTextToolTip->getTextSize(); + + IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24); + + IntSize size = textSize + IntSize(12, 12); + // make the tooltip stay completely in the viewport + if ((tooltipPosition.left + size.width) > viewSize.width) + { + tooltipPosition.left = viewSize.width - size.width; + } + if ((tooltipPosition.top + size.height) > viewSize.height) + { + tooltipPosition.top = viewSize.height - size.height; + } + + setCoord(tooltipPosition.left, tooltipPosition.top, size.width, size.height); +} + +void ToolTips::enterGameMode() +{ + mGameMode = true; +} + +void ToolTips::enterGuiMode() +{ + mGameMode = false; +} diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp new file mode 100644 index 0000000000..aa929ff510 --- /dev/null +++ b/apps/openmw/mwgui/tooltips.hpp @@ -0,0 +1,30 @@ + +#ifndef MWGUI_TOOLTIPS_H +#define MWGUI_TOOLTIPS_H + +#include + +namespace MWGui +{ + class ToolTips : public OEngine::GUI::Layout + { + public: + ToolTips(); + + void onFrame(float frameDuration); + + void enterGameMode(); + void enterGuiMode(); + + void adjustScreen(int screenWidth, int screenHeight); + + private: + MyGUI::EditBox* mTextToolTip; + MyGUI::Widget* mTextToolTipBox; + + MyGUI::Widget* mDynamicToolTipBox; + + bool mGameMode; + }; +} +#endif diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 34d62ba080..1ef5cae421 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -7,6 +7,7 @@ #include "map_window.hpp" #include "stats_window.hpp" #include "messagebox.hpp" +#include "tooltips.hpp" #include "../mwmechanics/mechanicsmanager.hpp" #include "../mwinput/inputmanager.hpp" @@ -31,6 +32,7 @@ WindowManager::WindowManager(MWWorld::Environment& environment, , map(NULL) , menu(NULL) , stats(NULL) + , mToolTips(NULL) , mMessageBoxManager(NULL) , console(NULL) , mJournal(NULL) @@ -80,6 +82,7 @@ WindowManager::WindowManager(MWWorld::Environment& environment, mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); dialogueWindow = new DialogueWindow(*this,environment); + mToolTips = new ToolTips(); // The HUD is always on hud->setVisible(true); @@ -118,6 +121,7 @@ WindowManager::~WindowManager() delete stats; delete mJournal; delete dialogueWindow; + delete mToolTips; delete mCharGen; @@ -183,6 +187,11 @@ void WindowManager::updateVisible() // Mouse is visible whenever we're not in game mode MyGUI::PointerManager::getInstance().setVisible(isGuiMode()); + if (mode == GM_Game) + mToolTips->enterGameMode(); + else + mToolTips->enterGuiMode(); + switch(mode) { case GM_Game: // If in game mode, don't show anything. @@ -408,6 +417,7 @@ void WindowManager::onDialogueWindowBye() void WindowManager::onFrame (float frameDuration) { mMessageBoxManager->onFrame(frameDuration); + mToolTips->onFrame(frameDuration); } const ESMS::ESMStore& WindowManager::getStore() const diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 2b53560baf..1cbd8f6a6f 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -62,6 +62,7 @@ namespace MWGui class Console; class JournalWindow; class CharacterCreation; + class ToolTips; class TextInputDialog; class InfoBoxDialog; @@ -196,6 +197,7 @@ namespace MWGui HUD *hud; MapWindow *map; MainMenu *menu; + ToolTips *mToolTips; StatsWindow *stats; MessageBoxManager *mMessageBoxManager; Console *console; diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index e3a7b9999c..49055d2ede 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -50,6 +50,7 @@ configure_file("${SDIR}/openmw_messagebox_layout.xml" "${DDIR}/openmw_messagebox configure_file("${SDIR}/openmw_interactive_messagebox_layout.xml" "${DDIR}/openmw_interactive_messagebox_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_journal_layout.xml" "${DDIR}/openmw_journal_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_journal_skin.xml" "${DDIR}/openmw_journal_skin.xml" COPYONLY) +configure_file("${SDIR}/openmw_tooltips.xml" "${DDIR}/openmw_tooltips.xml" COPYONLY) configure_file("${SDIR}/smallbars.png" "${DDIR}/smallbars.png" COPYONLY) configure_file("${SDIR}/transparent.png" "${DDIR}/transparent.png" COPYONLY) configure_file("${SDIR}/EBGaramond-Regular.ttf" "${DDIR}/EBGaramond-Regular.ttf" COPYONLY) diff --git a/files/mygui/openmw_tooltips.xml b/files/mygui/openmw_tooltips.xml new file mode 100644 index 0000000000..76df7b9a74 --- /dev/null +++ b/files/mygui/openmw_tooltips.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + From d37bc9cba8d6d9bd9afe07dd48c5981171b812fe Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 15 Apr 2012 17:10:08 +0200 Subject: [PATCH 02/30] basic mouse-over info for in-game objects --- apps/openmw/mwgui/tooltips.cpp | 412 +++++++++++++++++++++++++-- apps/openmw/mwgui/tooltips.hpp | 6 + apps/openmw/mwgui/window_manager.cpp | 5 + apps/openmw/mwgui/window_manager.hpp | 2 + apps/openmw/mwrender/shadows.cpp | 5 +- apps/openmw/mwworld/world.cpp | 12 + files/mygui/openmw_tooltips.xml | 10 +- 7 files changed, 426 insertions(+), 26 deletions(-) diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index d7c61c51a6..7f45bdbddc 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -6,6 +6,7 @@ using namespace MyGUI; ToolTips::ToolTips() : Layout("openmw_tooltips.xml") , mGameMode(true) + , mFocusChanged(true) { getWidget(mTextToolTip, "TextToolTip"); getWidget(mTextToolTipBox, "TextToolTipBox"); @@ -27,29 +28,389 @@ void ToolTips::onFrame(float frameDuration) const IntSize &viewSize = RenderManager::getInstance().getViewSize(); - Widget* focus = InputManager::getInstance().getMouseFocusWidget(); - if (focus == 0) 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()); - const IntSize &textSize = mTextToolTip->getTextSize(); - - IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24); - - IntSize size = textSize + IntSize(12, 12); - // make the tooltip stay completely in the viewport - if ((tooltipPosition.left + size.width) > viewSize.width) + if (!mGameMode) { - tooltipPosition.left = viewSize.width - size.width; - } - if ((tooltipPosition.top + size.height) > viewSize.height) - { - tooltipPosition.top = viewSize.height - size.height; - } + mDynamicToolTipBox->setVisible(false); - setCoord(tooltipPosition.left, tooltipPosition.top, size.width, size.height); + Widget* focus = InputManager::getInstance().getMouseFocusWidget(); + if (focus == 0) 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()); + const IntSize &textSize = mTextToolTip->getTextSize(); + + IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24); + + IntSize size = textSize + IntSize(12, 12); + // make the tooltip stay completely in the viewport + if ((tooltipPosition.left + size.width) > viewSize.width) + { + tooltipPosition.left = viewSize.width - size.width; + } + if ((tooltipPosition.top + size.height) > viewSize.height) + { + tooltipPosition.top = viewSize.height - size.height; + } + + setCoord(tooltipPosition.left, tooltipPosition.top, size.width, size.height); + } + else + { + mTextToolTipBox->setVisible(false); + + 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) + + tooltipSize = box->getTextSize() + IntSize(12,12); + + 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(); + + 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); + } + + // -------------------- 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); + + /// \todo Lock level, trap (retrieve GMST) + + tooltipSize = box->getTextSize() + IntSize(12,12); + + mDynamicToolTipBox->setVisible(true); + } + + // -------------------- Potion ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Potion).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); + } + + // -------------------- Apparatus ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Apparatus).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); + } + + // -------------------- 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 weight, armor value, value, durability.. + + tooltipSize = box->getTextSize() + IntSize(12,12); + + mDynamicToolTipBox->setVisible(true); + } + + // -------------------- Book ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Book).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); + } + + // -------------------- Clothing ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Clothing).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); + } + + // -------------------- 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 + + tooltipSize = box->getTextSize() + IntSize(12,12); + + mDynamicToolTipBox->setVisible(true); + } + + // -------------------- Light ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Light).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(ref->base->name != ""); + } + + // -------------------- Tool ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Tool).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); + } + + // -------------------- Miscellaneous ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Miscellaneous).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); + } + + // -------------------- Probe ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Probe).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); + } + + // -------------------- 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); + + /// \todo + + tooltipSize = box->getTextSize() + IntSize(12,12); + + mDynamicToolTipBox->setVisible(true); + } + + // -------------------- Weapon ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Weapon).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); + } + + // -------------------- Activator ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Activator).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(ref->base->name != ""); + } + + else + { + // object without tooltip + mDynamicToolTipBox->setVisible(false); + } + + // 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); + } } void ToolTips::enterGameMode() @@ -61,3 +422,12 @@ void ToolTips::enterGuiMode() { mGameMode = false; } + +void ToolTips::setFocusObject(const MWWorld::Ptr& focus) +{ + if (focus != mFocusObject) + { + mFocusObject = focus; + mFocusChanged = true; + } +} diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index aa929ff510..3052abb7a4 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -3,6 +3,7 @@ #define MWGUI_TOOLTIPS_H #include +#include "../mwworld/ptr.hpp" namespace MWGui { @@ -16,6 +17,8 @@ namespace MWGui void enterGameMode(); void enterGuiMode(); + void setFocusObject(const MWWorld::Ptr& focus); + void adjustScreen(int screenWidth, int screenHeight); private: @@ -24,6 +27,9 @@ namespace MWGui MyGUI::Widget* mDynamicToolTipBox; + MWWorld::Ptr mFocusObject; + bool mFocusChanged; + bool mGameMode; }; } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 1ef5cae421..909be0ac2f 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -492,3 +492,8 @@ int WindowManager::toggleFps() Settings::Manager::setInt("fps", "HUD", showFPSLevel); return showFPSLevel; } + +void WindowManager::setFocusObject(const MWWorld::Ptr& focus) +{ + mToolTips->setFocusObject(focus); +} diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 1cbd8f6a6f..d5f0683b86 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -158,6 +158,8 @@ namespace MWGui void setPlayerPos(const float x, const float y); ///< set player position in map space void setPlayerDir(const float x, const float y); ///< set player view direction in map space + void setFocusObject(const MWWorld::Ptr& focus); + void toggleFogOfWar(); int toggleFps(); diff --git a/apps/openmw/mwrender/shadows.cpp b/apps/openmw/mwrender/shadows.cpp index bf5602f438..9a4ae7243c 100644 --- a/apps/openmw/mwrender/shadows.cpp +++ b/apps/openmw/mwrender/shadows.cpp @@ -66,7 +66,10 @@ void Shadows::recreate() if (split) { mPSSMSetup = new PSSMShadowCameraSetup(); - mPSSMSetup->setSplitPadding(5); + + // Make sure to keep this in sync with the camera's near clip distance! + mPSSMSetup->setSplitPadding(mRendering->getCamera()->getNearClipDistance()); + mPSSMSetup->calculateSplitPoints(3, mRendering->getCamera()->getNearClipDistance(), mShadowFar); const Real adjustFactors[3] = {64, 64, 64}; diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 1c64039d4c..4719a25cf4 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -13,6 +13,7 @@ #include "../mwsound/soundmanager.hpp" +#include "../mwgui/window_manager.hpp" #include "ptr.hpp" #include "environment.hpp" @@ -737,6 +738,17 @@ namespace MWWorld mWeatherManager->update (duration); + // inform the GUI about focused object + try + { + mEnvironment.mWindowManager->setFocusObject(getPtrViaHandle(mFacedHandle)); + } + catch (std::runtime_error&) + { + MWWorld::Ptr null; + mEnvironment.mWindowManager->setFocusObject(null); + } + if (!mRendering->occlusionQuerySupported()) { // cast a ray from player to sun to detect if the sun is visible diff --git a/files/mygui/openmw_tooltips.xml b/files/mygui/openmw_tooltips.xml index 76df7b9a74..26fc1eeab5 100644 --- a/files/mygui/openmw_tooltips.xml +++ b/files/mygui/openmw_tooltips.xml @@ -1,11 +1,12 @@ - + - - + + + @@ -13,7 +14,8 @@ - + + From 705d4c6d54f94bad23fdf07efedc5842f73322de Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 15 Apr 2012 21:14:14 +0200 Subject: [PATCH 03/30] mostly complete --- apps/openmw/mwgui/stats_window.cpp | 16 +- apps/openmw/mwgui/stats_window.hpp | 2 +- apps/openmw/mwgui/tooltips.cpp | 720 ++++++++++++++------------- apps/openmw/mwgui/tooltips.hpp | 24 +- apps/openmw/mwgui/window_manager.cpp | 2 +- files/mygui/openmw_tooltips.xml | 2 +- 6 files changed, 406 insertions(+), 360 deletions(-) diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 675e5141fa..23f93cd1b2 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 f2731e545c..1ce3db98dc 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 7f45bdbddc..4c435e3bf6 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,351 +78,16 @@ void ToolTips::onFrame(float frameDuration) if (!mFocusObject.isEmpty()) { - if (mFocusChanged) - { - for (size_t i=0; igetChildCount(); ++i) - { - mDynamicToolTipBox->_destroyChildWidget(mDynamicToolTipBox->getChildAt(i)); - } + IntSize tooltipSize = getToolTipViaPtr(); - // this the maximum width of the tooltip before it starts word-wrapping - setCoord(0, 0, 300, 300); + tooltipSize += IntSize(6,6); // padding, adjust for skin - 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) - - tooltipSize = box->getTextSize() + IntSize(12,12); - - 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(); - - 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); - } - - // -------------------- 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); - - /// \todo Lock level, trap (retrieve GMST) - - tooltipSize = box->getTextSize() + IntSize(12,12); - - mDynamicToolTipBox->setVisible(true); - } - - // -------------------- Potion ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Potion).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); - } - - // -------------------- Apparatus ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Apparatus).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); - } - - // -------------------- 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 weight, armor value, value, durability.. - - tooltipSize = box->getTextSize() + IntSize(12,12); - - mDynamicToolTipBox->setVisible(true); - } - - // -------------------- Book ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Book).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); - } - - // -------------------- Clothing ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Clothing).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); - } - - // -------------------- 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 - - tooltipSize = box->getTextSize() + IntSize(12,12); - - mDynamicToolTipBox->setVisible(true); - } - - // -------------------- Light ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Light).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(ref->base->name != ""); - } - - // -------------------- Tool ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Tool).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); - } - - // -------------------- Miscellaneous ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Miscellaneous).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); - } - - // -------------------- Probe ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Probe).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); - } - - // -------------------- 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); - - /// \todo - - tooltipSize = box->getTextSize() + IntSize(12,12); - - mDynamicToolTipBox->setVisible(true); - } - - // -------------------- Weapon ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Weapon).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); - } - - // -------------------- Activator ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Activator).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(ref->base->name != ""); - } - - else - { - // object without tooltip - mDynamicToolTipBox->setVisible(false); - } - - // 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; + // 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); @@ -425,9 +106,346 @@ void ToolTips::enterGuiMode() void ToolTips::setFocusObject(const MWWorld::Ptr& focus) { - if (focus != mFocusObject) + mFocusObject = focus; +} + +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) { - mFocusObject = focus; - mFocusChanged = true; + mDynamicToolTipBox->_destroyChildWidget(mDynamicToolTipBox->getChildAt(i)); + } + + // this the maximum width of the tooltip before it starts word-wrapping + setCoord(0, 0, 300, 300); + + IntSize tooltipSize; + + // -------------------- Door ------------------------------- + if (mFocusObject.getTypeName() == typeid(ESM::Door).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); + + 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; + } + + 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 = createToolTip(ref->base->name, text); + } + + // -------------------- 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(); + + tooltipSize = createToolTip(ref->base->name, ""); + } + + // -------------------- 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(); + + tooltipSize = createToolTip(ref->base->name, ""); + } + + // -------------------- Container ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Container).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); + + std::string text; + + 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 = createToolTip(ref->base->name, text); + } + + // -------------------- Potion ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Potion).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); + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } + + // -------------------- Apparatus ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Apparatus).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); + + 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); + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } + + // -------------------- Armor ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Armor).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); + + /// \todo magic effects, armor type (medium/light/heavy) + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sArmorRating", "Armor Rating") + ": " + toString(ref->base->data.armor); + + /// \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 = createImageToolTip(ref->base->name, ref->base->icon, text); + } + + // -------------------- Book ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Book).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); + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } + + // -------------------- Clothing ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Clothing).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); + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } + + // -------------------- Ingredient ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Ingredient).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); + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } + + // -------------------- Light ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Light).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); + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } + + // -------------------- Tool ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Tool).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); + + 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 = createImageToolTip(ref->base->name, ref->base->icon, text); + } + + // -------------------- Miscellaneous ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Miscellaneous).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); + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + } + + // -------------------- Probe ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Probe).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); + + 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 = createImageToolTip(ref->base->name, ref->base->icon, text); + } + + // -------------------- Repair ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Repair).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); + + 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 = createImageToolTip(ref->base->name, ref->base->icon, text); + } + + // -------------------- Weapon ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Weapon).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); + + /// \todo weapon damage, magic effects, health (condition) + + std::string text; + text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); + text += getValueString(ref->base->data.value); + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, ""); + } + + // -------------------- Activator ------------------------------- + else if (mFocusObject.getTypeName() == typeid(ESM::Activator).name()) + { + ESMS::LiveCellRef* ref = mFocusObject.get(); + + tooltipSize = createToolTip(ref->base->name, ""); + } + + else + { + // object without tooltip + mDynamicToolTipBox->setVisible(false); + } + + return tooltipSize; +} + +void ToolTips::findImageExtension(std::string& image) +{ + int len = image.size(); + if (len < 4) return; + + 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'; } } + +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); + + std::string realImage = "icons\\" + image; + findImageExtension(realImage); + + const int imageSize = 32; + + 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); + + IntSize captionSize = captionWidget->getTextSize(); + IntSize textSize = textWidget->getTextSize(); + + captionSize += IntSize(imageSize, 0); // adjust for image + IntSize totalSize = IntSize( std::max(textSize.width, captionSize.width), ((realText != "") ? textSize.height : 0) + imageSize ); + + ImageBox* imageWidget = mDynamicToolTipBox->createWidget("ImageBox", + IntCoord((totalSize.width - captionSize.width)/2, 0, imageSize, imageSize), + Align::Left | Align::Top, "ToolTipImage"); + imageWidget->setImageTexture(realImage); + + captionWidget->setCoord( (totalSize.width - captionSize.width)/2 + imageSize, (32-captionSize.height)/2, captionSize.width-imageSize, captionSize.height); + + mDynamicToolTipBox->setVisible(caption != ""); + + return totalSize; +} + +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); + + 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 : "")); + + mDynamicToolTipBox->setVisible(caption != ""); + + return box->getTextSize(); +} + +std::string ToolTips::toString(const float value) +{ + std::ostringstream stream; + stream << std::setprecision(3) << value; + return stream.str(); +} + +std::string ToolTips::toString(const int value) +{ + std::ostringstream stream; + stream << value; + return stream.str(); +} + +std::string ToolTips::getValueString(const int value) +{ + 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 3052abb7a4..cb1af73499 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 909be0ac2f..8ed2050cc0 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 26fc1eeab5..1d55bd12f1 100644 --- a/files/mygui/openmw_tooltips.xml +++ b/files/mygui/openmw_tooltips.xml @@ -6,7 +6,7 @@ - + From 5d9648d6457b5b3e812fbfadb4c4a24a093a6f9c Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 15 Apr 2012 22:00:28 +0200 Subject: [PATCH 04/30] fix const reference --- apps/openmw/mwgui/stats_window.cpp | 2 +- apps/openmw/mwgui/stats_window.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 23f93cd1b2..3746728833 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -251,7 +251,7 @@ 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& tooltip, 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; diff --git a/apps/openmw/mwgui/stats_window.hpp b/apps/openmw/mwgui/stats_window.hpp index 1ce3db98dc..66655a055f 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& tooltip, 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(); From 194ecf274c09140ffd0afa73b9ac359efc0ef15c Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 16 Apr 2012 00:16:35 +0200 Subject: [PATCH 05/30] attribute tooltips --- apps/openmw/mwgui/stats_window.cpp | 97 ++++++++++++++++++++++++++++++ apps/openmw/mwgui/stats_window.hpp | 2 + apps/openmw/mwgui/tooltips.cpp | 83 +++++++++++++++---------- apps/openmw/mwgui/tooltips.hpp | 8 +-- files/mygui/openmw_tooltips.xml | 10 --- 5 files changed, 153 insertions(+), 47 deletions(-) diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 3746728833..cf279faf7f 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -72,6 +72,8 @@ StatsWindow::StatsWindow (WindowManager& parWindowManager) MyGUI::WindowPtr t = static_cast(mMainWidget); t->eventWindowChangeCoord += MyGUI::newDelegate(this, &StatsWindow::onWindowResize); + + setupToolTips(); } void StatsWindow::onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos) @@ -394,3 +396,98 @@ void StatsWindow::onPinToggled() { 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"); +} diff --git a/apps/openmw/mwgui/stats_window.hpp b/apps/openmw/mwgui/stats_window.hpp index 66655a055f..075c08dd32 100644 --- a/apps/openmw/mwgui/stats_window.hpp +++ b/apps/openmw/mwgui/stats_window.hpp @@ -57,6 +57,8 @@ namespace MWGui void addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void updateScroller(); + void setupToolTips(); + void onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos); void onWindowResize(MyGUI::Window* window); diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 4c435e3bf6..4dcb1cda78 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -11,8 +11,6 @@ ToolTips::ToolTips(WindowManager* windowManager) : , mGameMode(true) , mWindowManager(windowManager) { - getWidget(mTextToolTip, "TextToolTip"); - getWidget(mTextToolTipBox, "TextToolTipBox"); getWidget(mDynamicToolTipBox, "DynamicToolTipBox"); mDynamicToolTipBox->setVisible(false); @@ -20,8 +18,6 @@ ToolTips::ToolTips(WindowManager* windowManager) : // turn off mouse focus so that getMouseFocusWidget returns the correct widget, // even if the mouse is over the tooltip mDynamicToolTipBox->setNeedMouseFocus(false); - mTextToolTipBox->setNeedMouseFocus(false); - mTextToolTip->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 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)); + } + const IntSize &viewSize = RenderManager::getInstance().getViewSize(); if (!mGameMode) { - mDynamicToolTipBox->setVisible(false); - mTextToolTipBox->setVisible(true); - Widget* focus = InputManager::getInstance().getMouseFocusWidget(); 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); + mDynamicToolTipBox->setVisible(false); return; } // this the maximum width of the tooltip before it starts word-wrapping setCoord(0, 0, 300, 300); - mTextToolTip->setCaption(text); - const IntSize &textSize = mTextToolTip->getTextSize(); + IntSize tooltipSize; + + std::string type = focus->getUserString("ToolTipType"); + std::string text = focus->getUserString("ToolTipText"); + if (type == "") + { + mDynamicToolTipBox->setVisible(false); + return; + } + else if (type == "Text") + tooltipSize = createToolTip(text); + else if (type == "CaptionText") + { + std::string caption = focus->getUserString("ToolTipCaption"); + 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); - IntSize size = textSize + IntSize(6, 6); + IntSize size = tooltipSize + IntSize(6, 6); // make the tooltip stay completely in the viewport if ((tooltipPosition.left + size.width) > viewSize.width) { @@ -74,8 +87,6 @@ void ToolTips::onFrame(float frameDuration) } else { - mTextToolTipBox->setVisible(false); - if (!mFocusObject.isEmpty()) { IntSize tooltipSize = getToolTipViaPtr(); @@ -111,14 +122,6 @@ void ToolTips::setFocusObject(const MWWorld::Ptr& focus) 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)); - } - // this the maximum width of the tooltip before it starts word-wrapping setCoord(0, 0, 300, 300); @@ -337,7 +340,7 @@ IntSize ToolTips::getToolTipViaPtr () text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += getValueString(ref->base->data.value); - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, ""); + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); } // -------------------- Activator ------------------------------- @@ -375,7 +378,7 @@ IntSize ToolTips::createImageToolTip(const std::string& caption, const std::stri { // remove the first newline (easier this way) std::string realText = text; - if (realText.size() > 0) + if (realText.size() > 0 && realText[0] == '\n') realText.erase(0, 1); std::string realImage = "icons\\" + image; @@ -389,6 +392,7 @@ IntSize ToolTips::createImageToolTip(const std::string& caption, const std::stri EditBox* textWidget = mDynamicToolTipBox->createWidget("SandText", IntCoord(0, imageSize, 300, 262), Align::Stretch, "ToolTipText"); textWidget->setProperty("Static", "true"); textWidget->setProperty("MultiLine", "true"); + textWidget->setProperty("WordWrap", "true"); textWidget->setCaption(realText); 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) std::string realText = text; - if (realText.size() > 0) + if (realText.size() > 0 && realText[0] == '\n') realText.erase(0, 1); 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->setProperty("WordWrap", "true"); box->setCaption(caption + (realText != "" ? "\n#BF9959" + realText : "")); mDynamicToolTipBox->setVisible(caption != ""); @@ -428,6 +433,20 @@ IntSize ToolTips::createToolTip(const std::string& caption, const std::string& t return box->getTextSize(); } +IntSize ToolTips::createToolTip(const std::string& text) +{ + EditBox* box = mDynamicToolTipBox->createWidget("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::ostringstream stream; diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index cb1af73499..7a2dded114 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -21,12 +21,7 @@ namespace MWGui void setFocusObject(const MWWorld::Ptr& focus); - void adjustScreen(int screenWidth, int screenHeight); - private: - MyGUI::EditBox* mTextToolTip; - MyGUI::Widget* mTextToolTipBox; - MyGUI::Widget* mDynamicToolTipBox; WindowManager* mWindowManager; @@ -44,6 +39,9 @@ namespace MWGui MyGUI::IntSize createToolTip(const std::string& caption, const std::string& text); ///< @return requested tooltip size + MyGUI::IntSize createToolTip(const std::string& text); + ///< @return requested tooltip size + std::string getValueString(const int value); ///< get "Value: X" string or "" if value is 0 diff --git a/files/mygui/openmw_tooltips.xml b/files/mygui/openmw_tooltips.xml index 1d55bd12f1..2d5a5da9f2 100644 --- a/files/mygui/openmw_tooltips.xml +++ b/files/mygui/openmw_tooltips.xml @@ -3,16 +3,6 @@ - - - - - - - - - - From f5ab127a39dd06a3b94ae5a9b839f255069f1b0c Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 16 Apr 2012 15:00:44 +0200 Subject: [PATCH 06/30] toggleFullHelp --- apps/openmw/mwgui/tooltips.cpp | 114 ++++++++++++++++++++----- apps/openmw/mwgui/tooltips.hpp | 6 +- apps/openmw/mwgui/window_manager.cpp | 5 ++ apps/openmw/mwgui/window_manager.hpp | 1 + apps/openmw/mwscript/docs/vmformat.txt | 3 +- apps/openmw/mwscript/guiextensions.cpp | 21 ++++- 6 files changed, 128 insertions(+), 22 deletions(-) diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 4dcb1cda78..25361ffcc6 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -10,6 +10,7 @@ ToolTips::ToolTips(WindowManager* windowManager) : Layout("openmw_tooltips.xml") , mGameMode(true) , mWindowManager(windowManager) + , mFullHelp(false) { getWidget(mDynamicToolTipBox, "DynamicToolTipBox"); @@ -67,7 +68,9 @@ void ToolTips::onFrame(float frameDuration) { std::string caption = focus->getUserString("ToolTipCaption"); std::string image = focus->getUserString("ToolTipImage"); - tooltipSize = createImageToolTip(caption, image, text); + std::string sizeString = focus->getUserString("ToolTipImageSize"); + int size = (sizeString != "" ? boost::lexical_cast(sizeString) : 32); + tooltipSize = createImageToolTip(caption, image, size, text); } IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24); @@ -179,6 +182,11 @@ IntSize ToolTips::getToolTipViaPtr () if (ref->ref.trap != "") text += "\n" + mWindowManager->getGameSettingString("sTrapped", "Trapped!"); + if (mFullHelp) { + text += "\n Owner: " + ref->ref.owner; + text += "\n Script: " + ref->base->script; + } + tooltipSize = createToolTip(ref->base->name, text); } @@ -192,7 +200,12 @@ IntSize ToolTips::getToolTipViaPtr () text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += getValueString(ref->base->data.value); - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + if (mFullHelp) { + text += "\n Owner: " + ref->ref.owner; + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); } // -------------------- Apparatus ------------------------------- @@ -205,7 +218,12 @@ IntSize ToolTips::getToolTipViaPtr () text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += getValueString(ref->base->data.value); - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + if (mFullHelp) { + text += "\n Owner: " + ref->ref.owner; + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); } // -------------------- Armor ------------------------------- @@ -222,7 +240,12 @@ IntSize ToolTips::getToolTipViaPtr () text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += getValueString(ref->base->data.value); - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + if (mFullHelp) { + text += "\n Owner: " + ref->ref.owner; + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); } // -------------------- Book ------------------------------- @@ -234,7 +257,12 @@ IntSize ToolTips::getToolTipViaPtr () text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += getValueString(ref->base->data.value); - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + if (mFullHelp) { + text += "\n Owner: " + ref->ref.owner; + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); } // -------------------- Clothing ------------------------------- @@ -247,7 +275,12 @@ IntSize ToolTips::getToolTipViaPtr () text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += getValueString(ref->base->data.value); - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + if (mFullHelp) { + text += "\n Owner: " + ref->ref.owner; + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); } // -------------------- Ingredient ------------------------------- @@ -260,7 +293,12 @@ IntSize ToolTips::getToolTipViaPtr () text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += getValueString(ref->base->data.value); - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + if (mFullHelp) { + text += "\n Owner: " + ref->ref.owner; + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); } // -------------------- Light ------------------------------- @@ -272,7 +310,12 @@ IntSize ToolTips::getToolTipViaPtr () text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += getValueString(ref->base->data.value); - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + if (mFullHelp) { + text += "\n Owner: " + ref->ref.owner; + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); } // -------------------- Tool ------------------------------- @@ -286,7 +329,12 @@ IntSize ToolTips::getToolTipViaPtr () text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += getValueString(ref->base->data.value); - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + if (mFullHelp) { + text += "\n Owner: " + ref->ref.owner; + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); } // -------------------- Miscellaneous ------------------------------- @@ -298,7 +346,12 @@ IntSize ToolTips::getToolTipViaPtr () text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += getValueString(ref->base->data.value); - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + if (mFullHelp) { + text += "\n Owner: " + ref->ref.owner; + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); } // -------------------- Probe ------------------------------- @@ -312,7 +365,12 @@ IntSize ToolTips::getToolTipViaPtr () text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += getValueString(ref->base->data.value); - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + if (mFullHelp) { + text += "\n Owner: " + ref->ref.owner; + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); } // -------------------- Repair ------------------------------- @@ -326,7 +384,12 @@ IntSize ToolTips::getToolTipViaPtr () text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += getValueString(ref->base->data.value); - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + if (mFullHelp) { + text += "\n Owner: " + ref->ref.owner; + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); } // -------------------- Weapon ------------------------------- @@ -340,7 +403,12 @@ IntSize ToolTips::getToolTipViaPtr () text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); text += getValueString(ref->base->data.value); - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, text); + if (mFullHelp) { + text += "\n Owner: " + ref->ref.owner; + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); } // -------------------- Activator ------------------------------- @@ -348,7 +416,12 @@ IntSize ToolTips::getToolTipViaPtr () { ESMS::LiveCellRef* ref = mFocusObject.get(); - tooltipSize = createToolTip(ref->base->name, ""); + std::string text; + if (mFullHelp) { + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createToolTip(ref->base->name, text); } else @@ -374,7 +447,7 @@ void ToolTips::findImageExtension(std::string& image) } } -IntSize ToolTips::createImageToolTip(const std::string& caption, const std::string& image, const std::string& text) +IntSize ToolTips::createImageToolTip(const std::string& caption, const std::string& image, const int imageSize, const std::string& text) { // remove the first newline (easier this way) std::string realText = text; @@ -384,12 +457,10 @@ IntSize ToolTips::createImageToolTip(const std::string& caption, const std::stri std::string realImage = "icons\\" + image; findImageExtension(realImage); - const int imageSize = 32; - 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"); + EditBox* textWidget = mDynamicToolTipBox->createWidget("SandText", IntCoord(0, imageSize, 300, 300-imageSize), Align::Stretch, "ToolTipText"); textWidget->setProperty("Static", "true"); textWidget->setProperty("MultiLine", "true"); textWidget->setProperty("WordWrap", "true"); @@ -407,7 +478,7 @@ IntSize ToolTips::createImageToolTip(const std::string& caption, const std::stri Align::Left | Align::Top, "ToolTipImage"); imageWidget->setImageTexture(realImage); - captionWidget->setCoord( (totalSize.width - captionSize.width)/2 + imageSize, (32-captionSize.height)/2, captionSize.width-imageSize, captionSize.height); + captionWidget->setCoord( (totalSize.width - captionSize.width)/2 + imageSize, (imageSize-captionSize.height)/2, captionSize.width-imageSize, captionSize.height); mDynamicToolTipBox->setVisible(caption != ""); @@ -468,3 +539,8 @@ std::string ToolTips::getValueString(const int value) else return "\n" + mWindowManager->getGameSettingString("sValue", "Value") + ": " + toString(value); } + +void ToolTips::toggleFullHelp() +{ + mFullHelp = !mFullHelp; +} diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index 7a2dded114..f546f3976e 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -19,6 +19,8 @@ namespace MWGui void enterGameMode(); void enterGuiMode(); + void toggleFullHelp(); ///< show extra info in item tooltips (owner, script) + void setFocusObject(const MWWorld::Ptr& focus); private: @@ -33,7 +35,7 @@ namespace MWGui MyGUI::IntSize getToolTipViaPtr (); ///< @return requested tooltip size - MyGUI::IntSize createImageToolTip(const std::string& caption, const std::string& image, const std::string& text); + MyGUI::IntSize createImageToolTip(const std::string& caption, const std::string& image, const int imageSize, const std::string& text); ///< @return requested tooltip size MyGUI::IntSize createToolTip(const std::string& caption, const std::string& text); @@ -49,6 +51,8 @@ namespace MWGui std::string toString(const int value); bool mGameMode; + + bool mFullHelp; }; } #endif diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 8ed2050cc0..b18ee4e432 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -497,3 +497,8 @@ void WindowManager::setFocusObject(const MWWorld::Ptr& focus) { mToolTips->setFocusObject(focus); } + +void WindowManager::toggleFullHelp() +{ + mToolTips->toggleFullHelp(); +} diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index d5f0683b86..d76d15dd4c 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -161,6 +161,7 @@ namespace MWGui void setFocusObject(const MWWorld::Ptr& focus); void toggleFogOfWar(); + void toggleFullHelp(); ///< show extra info in item tooltips (owner, script) int toggleFps(); ///< toggle fps display @return resulting fps level diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 58960aac47..378b2412a5 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -144,4 +144,5 @@ op 0x200014d: ModDisposition op 0x200014e: ModDisposition, explicit reference op 0x200014f: ForceGreeting op 0x2000150: ForceGreeting, explicit reference -opcodes 0x2000151-0x3ffffff unused +op 0x2000151: ToggleFullHelp +opcodes 0x2000152-0x3ffffff unused diff --git a/apps/openmw/mwscript/guiextensions.cpp b/apps/openmw/mwscript/guiextensions.cpp index 426378efca..f7be161d62 100644 --- a/apps/openmw/mwscript/guiextensions.cpp +++ b/apps/openmw/mwscript/guiextensions.cpp @@ -80,6 +80,19 @@ namespace MWScript } }; + class OpToggleFullHelp : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + InterpreterContext& context = + static_cast (runtime.getContext()); + + context.getEnvironment().mWindowManager->toggleFullHelp(); + } + }; + const int opcodeEnableBirthMenu = 0x200000e; const int opcodeEnableClassMenu = 0x200000f; const int opcodeEnableNameMenu = 0x2000010; @@ -93,6 +106,7 @@ namespace MWScript const int opcodeShowRestMenu = 0x2000018; const int opcodeGetButtonPressed = 0x2000137; const int opcodeToggleFogOfWar = 0x2000145; + const int opcodeToggleFullHelp = 0x2000151; void registerExtensions (Compiler::Extensions& extensions) { @@ -101,7 +115,7 @@ namespace MWScript extensions.registerInstruction ("enablenamemenu", "", opcodeEnableNameMenu); extensions.registerInstruction ("enableracemenu", "", opcodeEnableRaceMenu); extensions.registerInstruction ("enablestatsreviewmenu", "", - opcodeEnableStatsReviewMenu); +opcodeEnableStatsReviewMenu); extensions.registerInstruction ("enableinventorymenu", "", opcodeEnableInventoryMenu); extensions.registerInstruction ("enablemagicmenu", "", opcodeEnableMagicMenu); @@ -117,6 +131,9 @@ namespace MWScript extensions.registerInstruction ("togglefogofwar", "", opcodeToggleFogOfWar); extensions.registerInstruction ("tfow", "", opcodeToggleFogOfWar); + + extensions.registerInstruction ("togglefullhelp", "", opcodeToggleFullHelp); + extensions.registerInstruction ("tfh", "", opcodeToggleFullHelp); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -154,6 +171,8 @@ namespace MWScript interpreter.installSegment5 (opcodeGetButtonPressed, new OpGetButtonPressed); interpreter.installSegment5 (opcodeToggleFogOfWar, new OpToggleFogOfWar); + + interpreter.installSegment5 (opcodeToggleFullHelp, new OpToggleFullHelp); } } } From b3dc1931a947b03a0895bb854eff3fd4d4e5fb25 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 16 Apr 2012 15:48:01 +0200 Subject: [PATCH 07/30] general GUI refactoring, part 1 --- apps/openmw/mwgui/review.cpp | 37 ++++++++++------------- apps/openmw/mwgui/review.hpp | 9 +----- apps/openmw/mwgui/stats_window.cpp | 47 +++++++++++++----------------- apps/openmw/mwgui/stats_window.hpp | 9 +----- files/mygui/openmw_button.skin.xml | 10 +++---- files/mygui/openmw_edit.skin.xml | 4 +-- files/mygui/openmw_list.skin.xml | 10 +++---- libs/openengine/gui/layout.hpp | 14 +++++++++ 8 files changed, 64 insertions(+), 76 deletions(-) diff --git a/apps/openmw/mwgui/review.cpp b/apps/openmw/mwgui/review.cpp index cb0d9969c6..dbd832580e 100644 --- a/apps/openmw/mwgui/review.cpp +++ b/apps/openmw/mwgui/review.cpp @@ -28,21 +28,25 @@ ReviewDialog::ReviewDialog(WindowManager& parWindowManager) getWidget(nameWidget, "NameText"); getWidget(button, "NameButton"); button->setCaption(mWindowManager.getGameSettingString("sName", "")); + adjustButtonSize(button); button->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onNameClicked);; getWidget(raceWidget, "RaceText"); getWidget(button, "RaceButton"); button->setCaption(mWindowManager.getGameSettingString("sRace", "")); + adjustButtonSize(button); button->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onRaceClicked);; getWidget(classWidget, "ClassText"); getWidget(button, "ClassButton"); button->setCaption(mWindowManager.getGameSettingString("sClass", "")); + adjustButtonSize(button); button->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onClassClicked);; getWidget(birthSignWidget, "SignText"); getWidget(button, "SignButton"); button->setCaption(mWindowManager.getGameSettingString("sBirthSign", "")); + adjustButtonSize(button); button->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onBirthSignClicked);; // Setup dynamic stats @@ -181,13 +185,14 @@ void ReviewDialog::setSkillValue(ESM::Skill::SkillEnum skillId, const MWMechanic { float modified = value.getModified(), base = value.getBase(); std::string text = boost::lexical_cast(std::floor(modified)); - ColorStyle style = CS_Normal; + std::string state = "normal"; if (modified > base) - style = CS_Super; + state = "increased"; else if (modified < base) - style = CS_Sub; + state = "decreased"; - setStyledText(widget, style, text); + widget->setCaption(text); + widget->_setWidgetState(state); } } @@ -210,17 +215,6 @@ void ReviewDialog::configureSkills(const std::vector& major, const std::vec } } -void ReviewDialog::setStyledText(MyGUI::TextBox* widget, ColorStyle style, const std::string &value) -{ - widget->setCaption(value); - if (style == CS_Super) - widget->setTextColour(MyGUI::Colour(0, 1, 0)); - else if (style == CS_Sub) - widget->setTextColour(MyGUI::Colour(1, 0, 0)); - else - widget->setTextColour(MyGUI::Colour(1, 1, 1)); -} - void ReviewDialog::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { MyGUI::ImageBox* separator = skillClientWidget->createWidget("MW_HLine", MyGUI::IntCoord(10, coord1.top, coord1.width + coord2.width - 4, 18), MyGUI::Align::Default); @@ -240,7 +234,7 @@ void ReviewDialog::addGroup(const std::string &label, MyGUI::IntCoord &coord1, M coord2.top += lineHeight; } -MyGUI::TextBox* ReviewDialog::addValueItem(const std::string text, const std::string &value, ColorStyle style, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) +MyGUI::TextBox* ReviewDialog::addValueItem(const std::string text, const std::string &value, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { MyGUI::TextBox* skillNameWidget; MyGUI::TextBox* skillValueWidget; @@ -249,7 +243,8 @@ MyGUI::TextBox* ReviewDialog::addValueItem(const std::string text, const std::st skillNameWidget->setCaption(text); skillValueWidget = skillClientWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Default); - setStyledText(skillValueWidget, style, value); + skillValueWidget->setCaption(value); + skillValueWidget->_setWidgetState(state); skillWidgets.push_back(skillNameWidget); skillWidgets.push_back(skillValueWidget); @@ -295,12 +290,12 @@ void ReviewDialog::addSkills(const SkillList &skills, const std::string &titleId float base = stat.getBase(); float modified = stat.getModified(); - ColorStyle style = CS_Normal; + std::string state = "normal"; if (modified > base) - style = CS_Super; + state = "increased"; else if (modified < base) - style = CS_Sub; - MyGUI::TextBox* widget = addValueItem(mWindowManager.getGameSettingString(skillNameId, skillNameId), boost::lexical_cast(static_cast(modified)), style, coord1, coord2); + state = "decreased"; + MyGUI::TextBox* widget = addValueItem(mWindowManager.getGameSettingString(skillNameId, skillNameId), boost::lexical_cast(static_cast(modified)), state, coord1, coord2); skillWidgetMap[skillId] = widget; } } diff --git a/apps/openmw/mwgui/review.hpp b/apps/openmw/mwgui/review.hpp index 588c1b6b5d..76ca5a2d76 100644 --- a/apps/openmw/mwgui/review.hpp +++ b/apps/openmw/mwgui/review.hpp @@ -69,17 +69,10 @@ namespace MWGui void onBirthSignClicked(MyGUI::Widget* _sender); private: - enum ColorStyle - { - CS_Sub, - CS_Normal, - CS_Super - }; - void setStyledText(MyGUI::TextBox* widget, ColorStyle style, const std::string &value); 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 &value, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void updateScroller(); void updateSkillArea(); diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index cf279faf7f..42194740f1 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -113,17 +113,6 @@ void StatsWindow::setPlayerName(const std::string& playerName) static_cast(mMainWidget)->setCaption(playerName); } -void StatsWindow::setStyledText(MyGUI::TextBox* widget, ColorStyle style, const std::string &value) -{ - widget->setCaption(value); - if (style == CS_Super) - widget->setTextColour(MyGUI::Colour(0, 1, 0)); - else if (style == CS_Sub) - widget->setTextColour(MyGUI::Colour(1, 0, 0)); - else - widget->setTextColour(MyGUI::Colour(1, 1, 1)); -} - void StatsWindow::setValue (const std::string& id, const MWMechanics::Stat& value) { static const char *ids[] = @@ -140,12 +129,15 @@ void StatsWindow::setValue (const std::string& id, const MWMechanics::Stat& valueString << value.getModified(); setText (id, valueString.str()); + MyGUI::TextBox* box; + getWidget(box, id); + if (value.getModified()>value.getBase()) - setTextColor (id, 0, 1, 0); + box->_setWidgetState("increased"); else if (value.getModified()_setWidgetState("decreased"); else - setTextColor (id, 1, 1, 1); + box->_setWidgetState("normal"); break; } @@ -195,13 +187,14 @@ void StatsWindow::setValue(const ESM::Skill::SkillEnum parSkill, const MWMechani { float modified = value.getModified(), base = value.getBase(); std::string text = boost::lexical_cast(std::floor(modified)); - ColorStyle style = CS_Normal; + std::string state = "normal"; if (modified > base) - style = CS_Super; + state = "increased"; else if (modified < base) - style = CS_Sub; + state = "decreased"; - setStyledText(widget, style, text); + widget->setCaption(text); + widget->_setWidgetState(state); } } @@ -253,7 +246,7 @@ 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& tooltip, 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, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { MyGUI::TextBox *skillNameWidget, *skillValueWidget; @@ -265,7 +258,8 @@ MyGUI::TextBox* StatsWindow::addValueItem(const std::string& text, const std::st skillValueWidget = skillClientWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Default); skillValueWidget->setUserString("ToolTipType", "Text"); skillValueWidget->setUserString("ToolTipText", tooltip); - setStyledText(skillValueWidget, style, value); + skillValueWidget->setCaption(value); + skillValueWidget->_setWidgetState(state); skillWidgets.push_back(skillNameWidget); skillWidgets.push_back(skillValueWidget); @@ -311,12 +305,13 @@ void StatsWindow::addSkills(const SkillList &skills, const std::string &titleId, float base = stat.getBase(); float modified = stat.getModified(); - ColorStyle style = CS_Normal; + std::string state = "normal"; if (modified > base) - style = CS_Super; + state = "increased"; else if (modified < base) - style = CS_Sub; - MyGUI::TextBox* widget = addValueItem(mWindowManager.getGameSettingString(skillNameId, skillNameId), "", boost::lexical_cast(static_cast(modified)), style, coord1, coord2); + state = "decreased"; + MyGUI::TextBox* widget = addValueItem(mWindowManager.getGameSettingString(skillNameId, skillNameId), "", + boost::lexical_cast(static_cast(modified)), state, coord1, coord2); skillWidgetMap[skillId] = widget; } } @@ -377,10 +372,10 @@ void StatsWindow::updateSkillArea() addValueItem(mWindowManager.getGameSettingString("sReputation", "Reputation"), mWindowManager.getGameSettingString("sSkillsMenuReputationHelp", ""), - boost::lexical_cast(static_cast(reputation)), CS_Normal, coord1, coord2); + boost::lexical_cast(static_cast(reputation)), "normal", coord1, coord2); addValueItem(mWindowManager.getGameSettingString("sBounty", "Bounty"), mWindowManager.getGameSettingString("sCrimeHelp", ""), - boost::lexical_cast(static_cast(bounty)), CS_Normal, coord1, coord2); + boost::lexical_cast(static_cast(bounty)), "normal", coord1, coord2); clientHeight = coord1.top; updateScroller(); diff --git a/apps/openmw/mwgui/stats_window.hpp b/apps/openmw/mwgui/stats_window.hpp index 075c08dd32..ecbc82894e 100644 --- a/apps/openmw/mwgui/stats_window.hpp +++ b/apps/openmw/mwgui/stats_window.hpp @@ -43,17 +43,10 @@ namespace MWGui void updateSkillArea(); private: - enum ColorStyle - { - CS_Sub, - CS_Normal, - CS_Super - }; - void setStyledText(MyGUI::TextBox* widget, ColorStyle style, const std::string &value); 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& tooltip, 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, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void updateScroller(); diff --git a/files/mygui/openmw_button.skin.xml b/files/mygui/openmw_button.skin.xml index 1c68930264..b88e994066 100644 --- a/files/mygui/openmw_button.skin.xml +++ b/files/mygui/openmw_button.skin.xml @@ -47,7 +47,6 @@ - @@ -59,11 +58,10 @@ - - - - - + + + + diff --git a/files/mygui/openmw_edit.skin.xml b/files/mygui/openmw_edit.skin.xml index a86317d620..02fee4b179 100644 --- a/files/mygui/openmw_edit.skin.xml +++ b/files/mygui/openmw_edit.skin.xml @@ -13,7 +13,7 @@ - + @@ -34,7 +34,7 @@ - + diff --git a/files/mygui/openmw_list.skin.xml b/files/mygui/openmw_list.skin.xml index 0ac8e03ba6..5ec975a1b0 100644 --- a/files/mygui/openmw_list.skin.xml +++ b/files/mygui/openmw_list.skin.xml @@ -180,10 +180,10 @@ - - - - + + + + @@ -219,7 +219,7 @@ - <_BasisSkin type="MainSkin" offset = "0 0 0 0" align = "ALIGN_LEFT ALIGN_TOP"/> + diff --git a/libs/openengine/gui/layout.hpp b/libs/openengine/gui/layout.hpp index 05a23e8aea..b95dcc4a55 100644 --- a/libs/openengine/gui/layout.hpp +++ b/libs/openengine/gui/layout.hpp @@ -115,6 +115,13 @@ namespace GUI static_cast(pt)->setCaption(caption); } + void setState(const std::string& widget, const std::string& state) + { + MyGUI::Widget* pt; + getWidget(pt, widget); + pt->_setWidgetState(state); + } + void setTextColor(const std::string& name, float r, float g, float b) { MyGUI::Widget* pt; @@ -131,6 +138,13 @@ namespace GUI pt->setImageTexture(imgName); } + void adjustButtonSize(MyGUI::Button* button) + { + // adjust size of button to fit its text + MyGUI::IntSize size = button->getTextSize(); + button->setSize(size.width + 24, button->getSize().height); + } + protected: MyGUI::Widget* mMainWidget; From 14377ba789ee001503a6441cd713d08b55db0d76 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 16 Apr 2012 17:30:57 +0200 Subject: [PATCH 08/30] window caption fix --- apps/openmw/mwgui/stats_window.cpp | 1 + libs/openengine/gui/layout.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 42194740f1..b007fc1d40 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -111,6 +111,7 @@ void StatsWindow::setBar(const std::string& name, const std::string& tname, int void StatsWindow::setPlayerName(const std::string& playerName) { static_cast(mMainWidget)->setCaption(playerName); + adjustWindowCaption(); } void StatsWindow::setValue (const std::string& id, const MWMechanics::Stat& value) diff --git a/libs/openengine/gui/layout.hpp b/libs/openengine/gui/layout.hpp index b95dcc4a55..bda8935af2 100644 --- a/libs/openengine/gui/layout.hpp +++ b/libs/openengine/gui/layout.hpp @@ -85,7 +85,7 @@ namespace GUI // adjust the size of the window caption so that all text is visible // NOTE: this assumes that mMainWidget is of type Window. MyGUI::TextBox* box = static_cast(mMainWidget)->getCaptionWidget(); - box->setSize(box->getTextSize().width + 48, box->getSize().height); + box->setSize(box->getTextSize().width + 24, box->getSize().height); // in order to trigger alignment updates, we need to update the parent // mygui doesn't provide a proper way of doing this, so we are just changing size From 424a90aa92fd766db35316b3fafe6be7342951f7 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 16 Apr 2012 17:46:54 +0200 Subject: [PATCH 09/30] back & ok button caption --- apps/openmw/mwgui/birth.cpp | 2 ++ apps/openmw/mwgui/class.cpp | 2 ++ apps/openmw/mwgui/race.cpp | 5 ++--- apps/openmw/mwgui/review.cpp | 2 ++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/birth.cpp b/apps/openmw/mwgui/birth.cpp index e9c15fab4a..100356e28e 100644 --- a/apps/openmw/mwgui/birth.cpp +++ b/apps/openmw/mwgui/birth.cpp @@ -28,10 +28,12 @@ BirthDialog::BirthDialog(WindowManager& parWindowManager) // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); + backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BirthDialog::onBackClicked); MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); + okButton->setCaption(mWindowManager.getGameSettingString("sOK", "")); okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BirthDialog::onOkClicked); updateBirths(); diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index 75e534b42a..791e24f2a2 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -29,10 +29,12 @@ GenerateClassResultDialog::GenerateClassResultDialog(WindowManager& parWindowMan // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); + backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &GenerateClassResultDialog::onBackClicked); MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); + okButton->setCaption(mWindowManager.getGameSettingString("sOK", "")); okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &GenerateClassResultDialog::onOkClicked); } diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index 880c0bc520..9a84f551c2 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -72,10 +72,12 @@ RaceDialog::RaceDialog(WindowManager& parWindowManager) // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); + backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onBackClicked); MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); + okButton->setCaption(mWindowManager.getGameSettingString("sOK", "")); okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onOkClicked); updateRaces(); @@ -94,15 +96,12 @@ void RaceDialog::setNextButtonShow(bool shown) // TODO: All hardcoded coords for buttons are temporary, will be replaced with a dynamic system. if (shown) { - okButton->setCaption("Next"); - // Adjust back button when next is shown backButton->setCoord(MyGUI::IntCoord(471 - 18, 397, 53, 23)); okButton->setCoord(MyGUI::IntCoord(532 - 18, 397, 42 + 18, 23)); } else { - okButton->setCaption("OK"); backButton->setCoord(MyGUI::IntCoord(471, 397, 53, 23)); okButton->setCoord(MyGUI::IntCoord(532, 397, 42, 23)); } diff --git a/apps/openmw/mwgui/review.cpp b/apps/openmw/mwgui/review.cpp index dbd832580e..f531fe5364 100644 --- a/apps/openmw/mwgui/review.cpp +++ b/apps/openmw/mwgui/review.cpp @@ -93,10 +93,12 @@ ReviewDialog::ReviewDialog(WindowManager& parWindowManager) // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); + backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onBackClicked); MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); + okButton->setCaption(mWindowManager.getGameSettingString("sOK", "")); okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onOkClicked); } From cfa37b0e7721ee17e98f08ee3b9588783a27271c Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 16 Apr 2012 19:14:05 +0200 Subject: [PATCH 10/30] fix another bunch of gui stuff, some strings were untranslated and buttons were not resized to fit their text --- apps/openmw/mwgui/birth.cpp | 22 ++---- apps/openmw/mwgui/class.cpp | 73 +++++++++---------- apps/openmw/mwgui/map_window.cpp | 8 +- apps/openmw/mwgui/race.cpp | 19 ++--- apps/openmw/mwgui/review.cpp | 6 +- apps/openmw/mwgui/text_input.cpp | 16 ++-- apps/openmw/mwgui/tooltips.hpp | 12 +++ ...w_chargen_generate_class_result_layout.xml | 12 +-- files/mygui/openmw_text.skin.xml | 6 +- 9 files changed, 92 insertions(+), 82 deletions(-) diff --git a/apps/openmw/mwgui/birth.cpp b/apps/openmw/mwgui/birth.cpp index 100356e28e..44c165743d 100644 --- a/apps/openmw/mwgui/birth.cpp +++ b/apps/openmw/mwgui/birth.cpp @@ -25,7 +25,6 @@ BirthDialog::BirthDialog(WindowManager& parWindowManager) birthList->eventListMouseItemActivate += MyGUI::newDelegate(this, &BirthDialog::onSelectBirth); birthList->eventListChangePosition += MyGUI::newDelegate(this, &BirthDialog::onSelectBirth); - // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); @@ -48,21 +47,16 @@ void BirthDialog::setNextButtonShow(bool shown) MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); - // TODO: All hardcoded coords for buttons are temporary, will be replaced with a dynamic system. if (shown) - { - okButton->setCaption("Next"); - - // Adjust back button when next is shown - backButton->setCoord(MyGUI::IntCoord(375 - 18, 340, 53, 23)); - okButton->setCoord(MyGUI::IntCoord(431 - 18, 340, 42 + 18, 23)); - } + okButton->setCaption(mWindowManager.getGameSettingString("sNext", "")); else - { - okButton->setCaption("OK"); - backButton->setCoord(MyGUI::IntCoord(375, 340, 53, 23)); - okButton->setCoord(MyGUI::IntCoord(431, 340, 42, 23)); - } + okButton->setCaption(mWindowManager.getGameSettingString("sOK", "")); + + int okButtonWidth = okButton->getTextSize().width + 24; + int backButtonWidth = backButton->getTextSize().width + 24; + + okButton->setCoord(473 - okButtonWidth, 340, okButtonWidth, 23); + backButton->setCoord(473 - okButtonWidth - backButtonWidth - 6, 340, backButtonWidth, 23); } void BirthDialog::open() diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index 791e24f2a2..9f1fc5d2a5 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -26,7 +26,6 @@ GenerateClassResultDialog::GenerateClassResultDialog(WindowManager& parWindowMan getWidget(classImage, "ClassImage"); getWidget(className, "ClassName"); - // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); @@ -36,6 +35,11 @@ GenerateClassResultDialog::GenerateClassResultDialog(WindowManager& parWindowMan getWidget(okButton, "OKButton"); okButton->setCaption(mWindowManager.getGameSettingString("sOK", "")); okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &GenerateClassResultDialog::onOkClicked); + + int okButtonWidth = okButton->getTextSize().width + 24; + int backButtonWidth = backButton->getTextSize().width + 24; + okButton->setCoord(315 - okButtonWidth, 219, okButtonWidth, 23); + backButton->setCoord(315 - okButtonWidth - backButtonWidth - 6, 219, backButtonWidth, 23); } void GenerateClassResultDialog::open() @@ -104,7 +108,6 @@ PickClassDialog::PickClassDialog(WindowManager& parWindowManager) getWidget(classImage, "ClassImage"); - // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PickClassDialog::onBackClicked); @@ -125,21 +128,16 @@ void PickClassDialog::setNextButtonShow(bool shown) MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); - // TODO: All hardcoded coords for buttons are temporary, will be replaced with a dynamic system. if (shown) - { - okButton->setCaption("Next"); - - // Adjust back button when next is shown - backButton->setCoord(MyGUI::IntCoord(382 - 18, 265, 53, 23)); - okButton->setCoord(MyGUI::IntCoord(434 - 18, 265, 42 + 18, 23)); - } + okButton->setCaption(mWindowManager.getGameSettingString("sNext", "")); else - { - okButton->setCaption("OK"); - backButton->setCoord(MyGUI::IntCoord(382, 265, 53, 23)); - okButton->setCoord(MyGUI::IntCoord(434, 265, 42, 23)); - } + okButton->setCaption(mWindowManager.getGameSettingString("sOK", "")); + + int okButtonWidth = okButton->getTextSize().width + 24; + int backButtonWidth = backButton->getTextSize().width + 24; + + okButton->setCoord(476 - okButtonWidth, 265, okButtonWidth, 23); + backButton->setCoord(476 - okButtonWidth - backButtonWidth - 6, 265, backButtonWidth, 23); } void PickClassDialog::open() @@ -425,9 +423,9 @@ CreateClassDialog::CreateClassDialog(WindowManager& parWindowManager) // Make sure the edit box has focus MyGUI::InputManager::getInstance().setKeyFocusWidget(editName); - // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr descriptionButton; getWidget(descriptionButton, "DescriptionButton"); + descriptionButton->setCaption(mWindowManager.getGameSettingString("sCreateClassMenu1", "")); descriptionButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CreateClassDialog::onDescriptionClicked); MyGUI::ButtonPtr backButton; @@ -509,32 +507,27 @@ std::vector CreateClassDialog::getMinorSkills() const void CreateClassDialog::setNextButtonShow(bool shown) { - MyGUI::ButtonPtr descriptionButton; - getWidget(descriptionButton, "DescriptionButton"); - MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); - // TODO: All hardcoded coords for buttons are temporary, will be replaced with a dynamic system. - if (shown) - { - okButton->setCaption("Next"); + MyGUI::ButtonPtr descriptionButton; + getWidget(descriptionButton, "DescriptionButton"); - // Adjust back button when next is shown - descriptionButton->setCoord(MyGUI::IntCoord(207 - 18, 158, 143, 23)); - backButton->setCoord(MyGUI::IntCoord(356 - 18, 158, 53, 23)); - okButton->setCoord(MyGUI::IntCoord(417 - 18, 158, 42 + 18, 23)); - } + if (shown) + okButton->setCaption(mWindowManager.getGameSettingString("sNext", "")); else - { - okButton->setCaption("OK"); - descriptionButton->setCoord(MyGUI::IntCoord(207, 158, 143, 23)); - backButton->setCoord(MyGUI::IntCoord(356, 158, 53, 23)); - okButton->setCoord(MyGUI::IntCoord(417, 158, 42, 23)); - } + okButton->setCaption(mWindowManager.getGameSettingString("sOK", "")); + + int okButtonWidth = okButton->getTextSize().width + 24; + int backButtonWidth = backButton->getTextSize().width + 24; + int descriptionButtonWidth = descriptionButton->getTextSize().width + 24; + + okButton->setCoord(459 - okButtonWidth, 158, okButtonWidth, 23); + backButton->setCoord(459 - okButtonWidth - backButtonWidth - 6, 158, backButtonWidth, 23); + descriptionButton->setCoord(459 - okButtonWidth - backButtonWidth - descriptionButtonWidth - 12, 158, descriptionButtonWidth, 23); } void CreateClassDialog::open() @@ -681,11 +674,12 @@ SelectSpecializationDialog::SelectSpecializationDialog(WindowManager& parWindowM specialization2->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSpecializationDialog::onSpecializationClicked); specializationId = ESM::Class::Combat; - // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr cancelButton; getWidget(cancelButton, "CancelButton"); cancelButton->setCaption(mWindowManager.getGameSettingString("sCancel", "")); cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSpecializationDialog::onCancelClicked); + int buttonWidth = cancelButton->getTextSize().width + 24; + cancelButton->setCoord(216 - buttonWidth, 90, buttonWidth, 21); } // widget controls @@ -730,11 +724,12 @@ SelectAttributeDialog::SelectAttributeDialog(WindowManager& parWindowManager) attribute->eventClicked += MyGUI::newDelegate(this, &SelectAttributeDialog::onAttributeClicked); } - // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr cancelButton; getWidget(cancelButton, "CancelButton"); cancelButton->setCaption(mWindowManager.getGameSettingString("sCancel", "")); cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectAttributeDialog::onCancelClicked); + int buttonWidth = cancelButton->getTextSize().width + 24; + cancelButton->setCoord(186 - buttonWidth, 180, buttonWidth, 21); } // widget controls @@ -819,11 +814,12 @@ SelectSkillDialog::SelectSkillDialog(WindowManager& parWindowManager) } } - // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr cancelButton; getWidget(cancelButton, "CancelButton"); cancelButton->setCaption(mWindowManager.getGameSettingString("sCancel", "")); cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSkillDialog::onCancelClicked); + int buttonWidth = cancelButton->getTextSize().width + 24; + cancelButton->setCoord(447 - buttonWidth, 218, buttonWidth, 21); } // widget controls @@ -849,11 +845,12 @@ DescriptionDialog::DescriptionDialog(WindowManager& parWindowManager) getWidget(textEdit, "TextEdit"); - // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &DescriptionDialog::onOkClicked); okButton->setCaption(mWindowManager.getGameSettingString("sInputMenu1", "")); + int buttonWidth = okButton->getTextSize().width + 24; + okButton->setCoord(234 - buttonWidth, 214, buttonWidth, 24); // Make sure the edit box has focus MyGUI::InputManager::getInstance().setKeyFocusWidget(textEdit); diff --git a/apps/openmw/mwgui/map_window.cpp b/apps/openmw/mwgui/map_window.cpp index 0e9d57c3c2..e0c828fdc4 100644 --- a/apps/openmw/mwgui/map_window.cpp +++ b/apps/openmw/mwgui/map_window.cpp @@ -29,6 +29,9 @@ MapWindow::MapWindow(WindowManager& parWindowManager) : getWidget(mButton, "WorldButton"); mButton->eventMouseButtonClick += MyGUI::newDelegate(this, &MapWindow::onWorldButtonClicked); + mButton->setCaption(mWindowManager.getGameSettingString("sWorld", "")); + int width = mButton->getTextSize().width + 24; + mButton->setCoord(mMainWidget->getSize().width - width - 22, mMainWidget->getSize().height - 64, width, 22); MyGUI::Button* eventbox; getWidget(eventbox, "EventBox"); @@ -97,7 +100,10 @@ void MapWindow::onWorldButtonClicked(MyGUI::Widget* _sender) mGlobalMap->setVisible(mGlobal); mLocalMap->setVisible(!mGlobal); - mButton->setCaption( mGlobal ? "Local" : "World" ); + mButton->setCaption( mGlobal ? mWindowManager.getGameSettingString("sWorld", "") : + mWindowManager.getGameSettingString("sLocal", "")); + int width = mButton->getTextSize().width + 24; + mButton->setCoord(mMainWidget->getSize().width - width - 22, mMainWidget->getSize().height - 64, width, 22); } void MapWindow::onPinToggled() diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index 9a84f551c2..275759c9f7 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -69,7 +69,6 @@ RaceDialog::RaceDialog(WindowManager& parWindowManager) setText("SpellPowerT", mWindowManager.getGameSettingString("sRaceMenu7", "Specials")); getWidget(spellPowerList, "SpellPowerList"); - // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); @@ -93,18 +92,16 @@ void RaceDialog::setNextButtonShow(bool shown) MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); - // TODO: All hardcoded coords for buttons are temporary, will be replaced with a dynamic system. if (shown) - { - // Adjust back button when next is shown - backButton->setCoord(MyGUI::IntCoord(471 - 18, 397, 53, 23)); - okButton->setCoord(MyGUI::IntCoord(532 - 18, 397, 42 + 18, 23)); - } + okButton->setCaption(mWindowManager.getGameSettingString("sNext", "")); else - { - backButton->setCoord(MyGUI::IntCoord(471, 397, 53, 23)); - okButton->setCoord(MyGUI::IntCoord(532, 397, 42, 23)); - } + okButton->setCaption(mWindowManager.getGameSettingString("sOK", "")); + + int okButtonWidth = okButton->getTextSize().width + 24; + int backButtonWidth = backButton->getTextSize().width + 24; + + okButton->setCoord(574 - okButtonWidth, 397, okButtonWidth, 23); + backButton->setCoord(574 - okButtonWidth - backButtonWidth - 6, 397, backButtonWidth, 23); } void RaceDialog::open() diff --git a/apps/openmw/mwgui/review.cpp b/apps/openmw/mwgui/review.cpp index f531fe5364..7dfe514def 100644 --- a/apps/openmw/mwgui/review.cpp +++ b/apps/openmw/mwgui/review.cpp @@ -90,7 +90,6 @@ ReviewDialog::ReviewDialog(WindowManager& parWindowManager) static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &ReviewDialog::onWindowResize); - // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); @@ -100,6 +99,11 @@ ReviewDialog::ReviewDialog(WindowManager& parWindowManager) getWidget(okButton, "OKButton"); okButton->setCaption(mWindowManager.getGameSettingString("sOK", "")); okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onOkClicked); + + int backButtonWidth = backButton->getTextSize().width + 24; + int okButtonWidth = okButton->getTextSize().width + 24; + okButton->setCoord(502 - okButtonWidth, 372, okButtonWidth, 23); + backButton->setCoord(502 - okButtonWidth - backButtonWidth - 6, 372, backButtonWidth, 23); } void ReviewDialog::open() diff --git a/apps/openmw/mwgui/text_input.cpp b/apps/openmw/mwgui/text_input.cpp index 8ac07e7668..7d84a9b9fd 100644 --- a/apps/openmw/mwgui/text_input.cpp +++ b/apps/openmw/mwgui/text_input.cpp @@ -12,7 +12,6 @@ TextInputDialog::TextInputDialog(WindowManager& parWindowManager) getWidget(textEdit, "TextEdit"); textEdit->eventEditSelectAccept += newDelegate(this, &TextInputDialog::onTextAccepted); - // TODO: These buttons should be managed by a Dialog class MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TextInputDialog::onOkClicked); @@ -25,16 +24,15 @@ void TextInputDialog::setNextButtonShow(bool shown) { MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); + if (shown) - { - okButton->setCaption("Next"); - okButton->setCoord(MyGUI::IntCoord(264 - 18, 60, 42 + 18, 23)); - } + okButton->setCaption(mWindowManager.getGameSettingString("sNext", "")); else - { - okButton->setCaption("OK"); - okButton->setCoord(MyGUI::IntCoord(264, 60, 42, 23)); - } + okButton->setCaption(mWindowManager.getGameSettingString("sOK", "")); + + int okButtonWidth = okButton->getTextSize().width + 24; + + okButton->setCoord(306 - okButtonWidth, 60, okButtonWidth, 23); } void TextInputDialog::setTextLabel(const std::string &label) diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index f546f3976e..a3447eb441 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -9,6 +9,18 @@ namespace MWGui { class WindowManager; + // Info about tooltip that is supplied by the MWWorld::Class object + // Not used yet, but it will replace the if-else-if blocks in tooltips.cpp + struct ToolTipInfo + { + public: + std::string caption; + std::string text; + std::string image; + + /// \todo enchantments (armor, cloth, weapons), magic effects (potions, ingredients) + }; + class ToolTips : public OEngine::GUI::Layout { public: diff --git a/files/mygui/openmw_chargen_generate_class_result_layout.xml b/files/mygui/openmw_chargen_generate_class_result_layout.xml index 7ec926eb05..26ebe17e1f 100644 --- a/files/mygui/openmw_chargen_generate_class_result_layout.xml +++ b/files/mygui/openmw_chargen_generate_class_result_layout.xml @@ -1,27 +1,29 @@ - + - + + + - + - + - + diff --git a/files/mygui/openmw_text.skin.xml b/files/mygui/openmw_text.skin.xml index 6ae14c558b..9f87c93b3c 100644 --- a/files/mygui/openmw_text.skin.xml +++ b/files/mygui/openmw_text.skin.xml @@ -94,19 +94,19 @@ - + - + - + From f1b80c6ff7441f7e1b91d6e3c1b166c275dbdedc Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 16 Apr 2012 19:23:24 +0200 Subject: [PATCH 11/30] fixed text input box --- files/mygui/openmw_text_input_layout.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/files/mygui/openmw_text_input_layout.xml b/files/mygui/openmw_text_input_layout.xml index 6a7ad27f01..c8f76b2575 100644 --- a/files/mygui/openmw_text_input_layout.xml +++ b/files/mygui/openmw_text_input_layout.xml @@ -4,10 +4,10 @@ - + - + From 53b48196f953c388546899d4f209a92809e324db Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 16 Apr 2012 19:30:52 +0200 Subject: [PATCH 12/30] add interface for tooltips to MWWorld::Class --- apps/openmw/mwworld/class.cpp | 10 ++++++++++ apps/openmw/mwworld/class.hpp | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index d49b98d0fb..c886f2348f 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -173,4 +173,14 @@ namespace MWWorld { throw std::runtime_error ("class does not have an down sound"); } + + MWGui::ToolTipInfo Class::getToolTipInfo (const Ptr& ptr) + { + throw std::runtime_error ("class does not have a tool tip"); + } + + bool Class::hasToolTip (const Ptr& ptr) + { + return false; + } } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index e474e9b926..5441b874d5 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -12,6 +12,7 @@ #include "physicssystem.hpp" #include "../mwrender/renderinginterface.hpp" +#include "../mwgui/tooltips.hpp" namespace Ogre { @@ -86,6 +87,12 @@ namespace MWWorld ///< Return creature stats or throw an exception, if class does not have creature stats /// (default implementation: throw an exceoption) + virtual bool hasToolTip (const Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const Ptr& ptr) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual MWMechanics::NpcStats& getNpcStats (const Ptr& ptr) const; ///< Return NPC stats or throw an exception, if class does not have NPC stats /// (default implementation: throw an exceoption) From 282f37b1b71e04ad51cddc35ac924d2435bd6265 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 16 Apr 2012 19:34:46 +0200 Subject: [PATCH 13/30] fix compilation --- apps/openmw/mwworld/class.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index c886f2348f..10368901b7 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -174,12 +174,12 @@ namespace MWWorld throw std::runtime_error ("class does not have an down sound"); } - MWGui::ToolTipInfo Class::getToolTipInfo (const Ptr& ptr) + MWGui::ToolTipInfo Class::getToolTipInfo (const Ptr& ptr) const { throw std::runtime_error ("class does not have a tool tip"); } - bool Class::hasToolTip (const Ptr& ptr) + bool Class::hasToolTip (const Ptr& ptr) const { return false; } From c4825cdb4300391cb84963abdc63c3e9f35df9fb Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 16 Apr 2012 20:20:18 +0200 Subject: [PATCH 14/30] fixed gold pickup sound for international MW versions, fix npc tooltip --- apps/openmw/mwclass/misc.cpp | 5 +++-- apps/openmw/mwgui/tooltips.cpp | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 84099caaaf..5963440423 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -7,6 +7,7 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" +#include "../mwworld/world.hpp" #include "../mwworld/environment.hpp" #include "../mwrender/objects.hpp" @@ -90,7 +91,7 @@ namespace MWClass ESMS::LiveCellRef *ref = ptr.get(); - if (ref->base->name =="Gold") + if (ref->base->name == environment.mWorld->getStore().gameSettings.search("sGold")->str) { return std::string("Item Gold Up"); } @@ -102,7 +103,7 @@ namespace MWClass ESMS::LiveCellRef *ref = ptr.get(); - if (ref->base->name =="Gold") + if (ref->base->name == environment.mWorld->getStore().gameSettings.search("sGold")->str) { return std::string("Item Gold Down"); } diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 25361ffcc6..ce31741689 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -158,7 +158,12 @@ IntSize ToolTips::getToolTipViaPtr () /// \todo We don't want tooltips for NPCs in combat mode. ESMS::LiveCellRef* ref = mFocusObject.get(); - tooltipSize = createToolTip(ref->base->name, ""); + std::string text; + if (mFullHelp) { + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createToolTip(ref->base->name, text); } // -------------------- Creature ------------------------------- @@ -167,7 +172,12 @@ IntSize ToolTips::getToolTipViaPtr () /// \todo We don't want tooltips for Creatures in combat mode. ESMS::LiveCellRef* ref = mFocusObject.get(); - tooltipSize = createToolTip(ref->base->name, ""); + std::string text; + if (mFullHelp) { + text += "\n Script: " + ref->base->script; + } + + tooltipSize = createToolTip(ref->base->name, text); } // -------------------- Container ------------------------------- From cdd4d83d9e4a73ba10e83ee3ae93662783f39056 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 16 Apr 2012 22:58:16 +0200 Subject: [PATCH 15/30] moved the tooltip info to the appropriate MWWorld::Class classes --- apps/openmw/mwclass/activator.cpp | 27 ++- apps/openmw/mwclass/activator.hpp | 6 + apps/openmw/mwclass/apparatus.cpp | 35 +++ apps/openmw/mwclass/apparatus.hpp | 6 + apps/openmw/mwclass/armor.cpp | 49 ++++ apps/openmw/mwclass/armor.hpp | 6 + apps/openmw/mwclass/book.cpp | 35 +++ apps/openmw/mwclass/book.hpp | 6 + apps/openmw/mwclass/clothing.cpp | 36 +++ apps/openmw/mwclass/clothing.hpp | 6 + apps/openmw/mwclass/container.cpp | 36 +++ apps/openmw/mwclass/container.hpp | 6 + apps/openmw/mwclass/creature.cpp | 25 ++ apps/openmw/mwclass/creature.hpp | 6 + apps/openmw/mwclass/door.cpp | 42 ++++ apps/openmw/mwclass/door.hpp | 6 + apps/openmw/mwclass/ingredient.cpp | 36 +++ apps/openmw/mwclass/ingredient.hpp | 6 + apps/openmw/mwclass/light.cpp | 36 +++ apps/openmw/mwclass/light.hpp | 6 + apps/openmw/mwclass/lockpick.cpp | 39 +++ apps/openmw/mwclass/lockpick.hpp | 6 + apps/openmw/mwclass/misc.cpp | 42 ++++ apps/openmw/mwclass/misc.hpp | 6 + apps/openmw/mwclass/npc.cpp | 25 ++ apps/openmw/mwclass/npc.hpp | 6 + apps/openmw/mwclass/potion.cpp | 36 +++ apps/openmw/mwclass/potion.hpp | 6 + apps/openmw/mwclass/probe.cpp | 39 +++ apps/openmw/mwclass/probe.hpp | 6 + apps/openmw/mwclass/repair.cpp | 39 +++ apps/openmw/mwclass/repair.hpp | 6 + apps/openmw/mwclass/weapon.cpp | 41 ++++ apps/openmw/mwclass/weapon.hpp | 6 + apps/openmw/mwgui/tooltips.cpp | 343 +++------------------------ apps/openmw/mwgui/tooltips.hpp | 19 +- apps/openmw/mwgui/window_manager.cpp | 5 + apps/openmw/mwgui/window_manager.hpp | 1 + apps/openmw/mwworld/class.cpp | 2 +- apps/openmw/mwworld/class.hpp | 2 +- 40 files changed, 769 insertions(+), 323 deletions(-) diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index 6749a2bfd1..1f6badce98 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -7,7 +7,8 @@ #include #include "../mwworld/ptr.hpp" - +#include "../mwworld/environment.hpp" +#include "../mwgui/window_manager.hpp" namespace MWClass { @@ -63,4 +64,28 @@ namespace MWClass registerClass (typeid (ESM::Activator).name(), instance); } + + bool Activator::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Activator::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + + std::string text; + if (environment.mWindowManager->getFullHelp()) + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/activator.hpp b/apps/openmw/mwclass/activator.hpp index 08be8a5ff1..e5d826e58e 100644 --- a/apps/openmw/mwclass/activator.hpp +++ b/apps/openmw/mwclass/activator.hpp @@ -18,6 +18,12 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; ///< Return name of the script attached to ptr diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index 90db40b5ae..16e5d8f6ec 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -8,9 +8,13 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" #include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" #include "../mwrender/objects.hpp" +#include "../mwgui/window_manager.hpp" +#include "../mwgui/tooltips.hpp" + #include "../mwsound/soundmanager.hpp" namespace MWClass @@ -94,4 +98,35 @@ namespace MWClass { return std::string("Item Apparatus Down"); } + + bool Apparatus::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Apparatus::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + info.icon = ref->base->icon; + + std::string text; + text += "\n" + environment.mWorld->getStore().gameSettings.search("sQuality")->str + ": " + MWGui::ToolTips::toString(ref->base->data.quality); + text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); + text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); + + if (environment.mWindowManager->getFullHelp()) { + text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + } + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/apparatus.hpp b/apps/openmw/mwclass/apparatus.hpp index 861610f6cc..d942ac0cb6 100644 --- a/apps/openmw/mwclass/apparatus.hpp +++ b/apps/openmw/mwclass/apparatus.hpp @@ -28,6 +28,12 @@ namespace MWClass virtual int getValue (const MWWorld::Ptr& ptr) const; ///< Return trade value of the object. Throws an exception, if the object can't be traded. + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + static void registerSelf(); virtual std::string getUpSoundId (const MWWorld::Ptr& ptr) const; diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 8e1f81136b..dd343b25d0 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -16,6 +16,8 @@ #include "../mwrender/objects.hpp" +#include "../mwgui/window_manager.hpp" + #include "../mwsound/soundmanager.hpp" namespace MWClass @@ -196,4 +198,51 @@ namespace MWClass else return std::string("Item Armor Heavy Down"); } + + bool Armor::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Armor::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + info.icon = ref->base->icon; + + std::string text; + + // get armor type string (light/medium/heavy) + int armorType = getEquipmentSkill(ptr, environment); + std::string typeText; + if (armorType == ESM::Skill::LightArmor) + typeText = environment.mWorld->getStore().gameSettings.search("sLight")->str; + else if (armorType == ESM::Skill::MediumArmor) + typeText = environment.mWorld->getStore().gameSettings.search("sMedium")->str; + else + typeText = environment.mWorld->getStore().gameSettings.search("sHeavy")->str; + + text += "\n" + environment.mWorld->getStore().gameSettings.search("sArmorRating")->str + ": " + MWGui::ToolTips::toString(ref->base->data.armor); + + /// \todo store the current armor health somewhere + text += "\n" + environment.mWorld->getStore().gameSettings.search("sCondition")->str + ": " + MWGui::ToolTips::toString(ref->base->data.health); + + text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight) + " (" + typeText + ")"; + text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); + + if (environment.mWindowManager->getFullHelp()) { + text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + } + + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index de5ca39835..36366db737 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -40,6 +40,12 @@ namespace MWClass /// Return the index of the skill this item corresponds to when equiopped or -1, if there is /// no such skill. + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual int getValue (const MWWorld::Ptr& ptr) const; ///< Return trade value of the object. Throws an exception, if the object can't be traded. diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 9069d94765..f60f879361 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -8,9 +8,12 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" #include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" #include "../mwrender/objects.hpp" +#include "../mwgui/window_manager.hpp" + #include "../mwsound/soundmanager.hpp" namespace MWClass @@ -96,4 +99,36 @@ namespace MWClass { return std::string("Item Book Down"); } + + bool Book::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Book::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + info.icon = ref->base->icon; + + std::string text; + + text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); + text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); + + if (environment.mWindowManager->getFullHelp()) { + text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + } + + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp index 4738187cd6..8ed99db912 100644 --- a/apps/openmw/mwclass/book.hpp +++ b/apps/openmw/mwclass/book.hpp @@ -25,6 +25,12 @@ namespace MWClass virtual std::string getScript (const MWWorld::Ptr& ptr) const; ///< Return name of the script attached to ptr + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual int getValue (const MWWorld::Ptr& ptr) const; ///< Return trade value of the object. Throws an exception, if the object can't be traded. diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 672a2b60a0..6835ad2ede 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -9,6 +9,10 @@ #include "../mwworld/actiontake.hpp" #include "../mwworld/environment.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/world.hpp" + +#include "../mwgui/tooltips.hpp" +#include "../mwgui/window_manager.hpp" #include "../mwrender/objects.hpp" @@ -161,4 +165,36 @@ namespace MWClass } return std::string("Item Clothes Down"); } + + bool Clothing::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Clothing::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + info.icon = ref->base->icon; + + std::string text; + + text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); + text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); + + if (environment.mWindowManager->getFullHelp()) { + text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + } + + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index 97e09012d5..04bab0edc8 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -34,6 +34,12 @@ namespace MWClass /// Return the index of the skill this item corresponds to when equiopped or -1, if there is /// no such skill. + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual int getValue (const MWWorld::Ptr& ptr) const; ///< Return trade value of the object. Throws an exception, if the object can't be traded. diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 29b3331ba9..23c640dc97 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -10,6 +10,10 @@ #include "../mwworld/containerstore.hpp" #include "../mwworld/customdata.hpp" #include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" + +#include "../mwgui/window_manager.hpp" +#include "../mwgui/tooltips.hpp" #include "../mwrender/objects.hpp" @@ -137,4 +141,36 @@ namespace MWClass registerClass (typeid (ESM::Container).name(), instance); } + + bool Container::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Container::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + + std::string text; + if (ref->ref.lockLevel > 0) + text += "\n" + environment.mWorld->getStore().gameSettings.search("sLockLevel")->str + ": " + MWGui::ToolTips::toString(ref->ref.lockLevel); + if (ref->ref.trap != "") + text += "\n" + environment.mWorld->getStore().gameSettings.search("sTrapped")->str; + + if (environment.mWindowManager->getFullHelp()) { + text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + } + + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp index 387714176b..3ff40c9177 100644 --- a/apps/openmw/mwclass/container.hpp +++ b/apps/openmw/mwclass/container.hpp @@ -24,6 +24,12 @@ namespace MWClass const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; ///< Generate action for activation + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual MWWorld::ContainerStore& getContainerStore (const MWWorld::Ptr& ptr) const; ///< Return container store diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 7270fd22b9..8d5a53969b 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -12,6 +12,8 @@ #include "../mwworld/customdata.hpp" #include "../mwworld/containerstore.hpp" +#include "../mwgui/window_manager.hpp" + namespace { struct CustomData : public MWWorld::CustomData @@ -140,4 +142,27 @@ namespace MWClass registerClass (typeid (ESM::Creature).name(), instance); } + + bool Creature::hasToolTip (const MWWorld::Ptr& ptr) const + { + /// \todo We don't want tooltips for Creatures in combat mode. + + return true; + } + + MWGui::ToolTipInfo Creature::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + + std::string text; + if (environment.mWindowManager->getFullHelp()) + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index 8eb45e8381..61d9267f9b 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -32,6 +32,12 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const; ///< Return creature stats diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 9d6c6a78dc..e06fdecda8 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -12,6 +12,9 @@ #include "../mwworld/environment.hpp" #include "../mwworld/world.hpp" +#include "../mwgui/window_manager.hpp" +#include "../mwgui/tooltips.hpp" + #include "../mwrender/objects.hpp" #include "../mwsound/soundmanager.hpp" @@ -142,4 +145,43 @@ namespace MWClass registerClass (typeid (ESM::Door).name(), instance); } + + bool Door::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Door::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + + 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" + environment.mWorld->getStore().gameSettings.search("sTo")->str; + text += "\n"+ref->ref.destCell; + } + + if (ref->ref.lockLevel > 0) + text += "\n" + environment.mWorld->getStore().gameSettings.search("sLockLevel")->str + ": " + MWGui::ToolTips::toString(ref->ref.lockLevel); + if (ref->ref.trap != "") + text += "\n" + environment.mWorld->getStore().gameSettings.search("sTrapped")->str; + + if (environment.mWindowManager->getFullHelp()) + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/door.hpp b/apps/openmw/mwclass/door.hpp index aecb4224cc..c7b7f5d8ce 100644 --- a/apps/openmw/mwclass/door.hpp +++ b/apps/openmw/mwclass/door.hpp @@ -22,6 +22,12 @@ namespace MWClass const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; ///< Generate action for activation + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual void lock (const MWWorld::Ptr& ptr, int lockLevel) const; ///< Lock object diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 9707e79a8f..a22f5c60ad 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -8,6 +8,10 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" #include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" + +#include "../mwgui/window_manager.hpp" +#include "../mwgui/tooltips.hpp" #include "../mwrender/objects.hpp" @@ -92,4 +96,36 @@ namespace MWClass { return std::string("Item Ingredient Down"); } + + bool Ingredient::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Ingredient::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + info.icon = ref->base->icon; + + std::string text; + + text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); + text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); + + if (environment.mWindowManager->getFullHelp()) { + text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + } + + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/ingredient.hpp b/apps/openmw/mwclass/ingredient.hpp index 2d77176727..ba241c2f3b 100644 --- a/apps/openmw/mwclass/ingredient.hpp +++ b/apps/openmw/mwclass/ingredient.hpp @@ -22,6 +22,12 @@ namespace MWClass const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; ///< Generate action for activation + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; ///< Return name of the script attached to ptr diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index f67dd4cf05..c01017aafb 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -10,6 +10,10 @@ #include "../mwworld/nullaction.hpp" #include "../mwworld/environment.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/world.hpp" + +#include "../mwgui/window_manager.hpp" +#include "../mwgui/tooltips.hpp" #include "../mwsound/soundmanager.hpp" @@ -134,4 +138,36 @@ namespace MWClass { return std::string("Item Misc Down"); } + + bool Light::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Light::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + info.icon = ref->base->icon; + + std::string text; + + text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); + text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); + + if (environment.mWindowManager->getFullHelp()) { + text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + } + + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/light.hpp b/apps/openmw/mwclass/light.hpp index bde252c289..347e551907 100644 --- a/apps/openmw/mwclass/light.hpp +++ b/apps/openmw/mwclass/light.hpp @@ -23,6 +23,12 @@ namespace MWClass ///< \return name (the one that is to be presented to the user; not the internal one); /// can return an empty string. + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual boost::shared_ptr activate (const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; ///< Generate action for activation diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 76bc3948f6..36a097babe 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -9,6 +9,9 @@ #include "../mwworld/actiontake.hpp" #include "../mwworld/environment.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/world.hpp" +#include "../mwgui/window_manager.hpp" +#include "../mwgui/tooltips.hpp" #include "../mwrender/objects.hpp" @@ -105,4 +108,40 @@ namespace MWClass { return std::string("Item Lockpick Down"); } + + bool Lockpick::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Lockpick::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + info.icon = ref->base->icon; + + std::string text; + + /// \todo store remaining uses somewhere + + text += "\n" + environment.mWorld->getStore().gameSettings.search("sUses")->str + ": " + MWGui::ToolTips::toString(ref->base->data.uses); + text += "\n" + environment.mWorld->getStore().gameSettings.search("sQuality")->str + ": " + MWGui::ToolTips::toString(ref->base->data.quality); + text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); + text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); + + if (environment.mWindowManager->getFullHelp()) { + text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + } + + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp index 1b56234af1..8b5f658f56 100644 --- a/apps/openmw/mwclass/lockpick.hpp +++ b/apps/openmw/mwclass/lockpick.hpp @@ -22,6 +22,12 @@ namespace MWClass const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; ///< Generate action for activation + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; ///< Return name of the script attached to ptr diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 5963440423..8cd2554a10 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -10,10 +10,15 @@ #include "../mwworld/world.hpp" #include "../mwworld/environment.hpp" +#include "../mwgui/window_manager.hpp" +#include "../mwgui/tooltips.hpp" + #include "../mwrender/objects.hpp" #include "../mwsound/soundmanager.hpp" +#include + namespace MWClass { void Miscellaneous::insertObjectRendering (const MWWorld::Ptr& ptr, MWRender::RenderingInterface& renderingInterface) const @@ -109,4 +114,41 @@ namespace MWClass } return std::string("Item Misc Down"); } + + bool Miscellaneous::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Miscellaneous::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + info.icon = ref->base->icon; + + std::string text; + + if (ref->base->name == environment.mWorld->getStore().gameSettings.search("sGold")->str) + info.caption += " (" + boost::lexical_cast(ref->base->data.value) + ")"; + else + { + text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); + text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); + } + + if (environment.mWindowManager->getFullHelp()) { + text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + } + + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/misc.hpp b/apps/openmw/mwclass/misc.hpp index fc002280cf..dda8a352e8 100644 --- a/apps/openmw/mwclass/misc.hpp +++ b/apps/openmw/mwclass/misc.hpp @@ -22,6 +22,12 @@ namespace MWClass const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; ///< Generate action for activation + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; ///< Return name of the script attached to ptr diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index c053ad1306..7f78d53f34 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -19,6 +19,8 @@ #include "../mwworld/inventorystore.hpp" #include "../mwworld/customdata.hpp" +#include "../mwgui/window_manager.hpp" + namespace { const Ogre::Radian kOgrePi (Ogre::Math::PI); @@ -299,4 +301,27 @@ namespace MWClass std::cout << "class npc:" << typeid (ESM::NPC).name(); registerClass (typeid (ESM::NPC).name(), instance); } + + bool Npc::hasToolTip (const MWWorld::Ptr& ptr) const + { + /// \todo We don't want tooltips for NPCs in combat mode. + + return true; + } + + MWGui::ToolTipInfo Npc::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + + std::string text; + if (environment.mWindowManager->getFullHelp()) + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index f210eda5f0..46eccf26a8 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -38,6 +38,12 @@ namespace MWClass virtual MWWorld::ContainerStore& getContainerStore (const MWWorld::Ptr& ptr) const; ///< Return container store + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual MWWorld::InventoryStore& getInventoryStore (const MWWorld::Ptr& ptr) const; ///< Return inventory store diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 642211df3c..2936afd19c 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -8,6 +8,10 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" #include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" + +#include "../mwgui/window_manager.hpp" +#include "../mwgui/tooltips.hpp" #include "../mwrender/objects.hpp" @@ -94,4 +98,36 @@ namespace MWClass { return std::string("Item Potion Down"); } + + bool Potion::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Potion::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + info.icon = ref->base->icon; + + std::string text; + + text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); + text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); + + if (environment.mWindowManager->getFullHelp()) { + text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + } + + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/potion.hpp b/apps/openmw/mwclass/potion.hpp index 7d30179376..7b98fd897f 100644 --- a/apps/openmw/mwclass/potion.hpp +++ b/apps/openmw/mwclass/potion.hpp @@ -22,6 +22,12 @@ namespace MWClass const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; ///< Generate action for activation + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; ///< Return name of the script attached to ptr diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 923c29ee69..c70368642d 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -9,6 +9,9 @@ #include "../mwworld/actiontake.hpp" #include "../mwworld/environment.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/world.hpp" +#include "../mwgui/window_manager.hpp" +#include "../mwgui/tooltips.hpp" #include "../mwrender/objects.hpp" @@ -104,4 +107,40 @@ namespace MWClass { return std::string("Item Probe Down"); } + + bool Probe::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Probe::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + info.icon = ref->base->icon; + + std::string text; + + /// \todo store remaining uses somewhere + + text += "\n" + environment.mWorld->getStore().gameSettings.search("sUses")->str + ": " + MWGui::ToolTips::toString(ref->base->data.uses); + text += "\n" + environment.mWorld->getStore().gameSettings.search("sQuality")->str + ": " + MWGui::ToolTips::toString(ref->base->data.quality); + text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); + text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); + + if (environment.mWindowManager->getFullHelp()) { + text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + } + + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/probe.hpp b/apps/openmw/mwclass/probe.hpp index 232b523645..e454279a19 100644 --- a/apps/openmw/mwclass/probe.hpp +++ b/apps/openmw/mwclass/probe.hpp @@ -22,6 +22,12 @@ namespace MWClass const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; ///< Generate action for activation + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; ///< Return name of the script attached to ptr diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index d6433f5df5..2befdaac93 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -8,6 +8,9 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" #include "../mwworld/environment.hpp" +#include "../mwworld/world.hpp" +#include "../mwgui/window_manager.hpp" +#include "../mwgui/tooltips.hpp" #include "../mwrender/objects.hpp" @@ -94,4 +97,40 @@ namespace MWClass { return std::string("Item Repair Down"); } + + bool Repair::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Repair::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + info.icon = ref->base->icon; + + std::string text; + + /// \todo store remaining uses somewhere + + text += "\n" + environment.mWorld->getStore().gameSettings.search("sUses")->str + ": " + MWGui::ToolTips::toString(ref->base->data.uses); + text += "\n" + environment.mWorld->getStore().gameSettings.search("sQuality")->str + ": " + MWGui::ToolTips::toString(ref->base->data.quality); + text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); + text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); + + if (environment.mWindowManager->getFullHelp()) { + text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + } + + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/repair.hpp b/apps/openmw/mwclass/repair.hpp index 0a9d9c2535..2b8eba2f4b 100644 --- a/apps/openmw/mwclass/repair.hpp +++ b/apps/openmw/mwclass/repair.hpp @@ -22,6 +22,12 @@ namespace MWClass const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; ///< Generate action for activation + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual std::string getScript (const MWWorld::Ptr& ptr) const; ///< Return name of the script attached to ptr diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 7790e6a80b..1fb8715729 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -9,6 +9,10 @@ #include "../mwworld/actiontake.hpp" #include "../mwworld/environment.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/world.hpp" + +#include "../mwgui/window_manager.hpp" +#include "../mwgui/tooltips.hpp" #include "../mwrender/objects.hpp" @@ -245,4 +249,41 @@ namespace MWClass return std::string("Item Misc Down"); } + + bool Weapon::hasToolTip (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return (ref->base->name != ""); + } + + MWGui::ToolTipInfo Weapon::getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + MWGui::ToolTipInfo info; + info.caption = ref->base->name; + info.icon = ref->base->icon; + + std::string text; + + /// \todo weapon type, damage + + /// \todo store the current weapon health somewhere + text += "\n" + environment.mWorld->getStore().gameSettings.search("sCondition")->str + ": " + MWGui::ToolTips::toString(ref->base->data.health); + + text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); + text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); + + if (environment.mWindowManager->getFullHelp()) { + text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); + text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); + } + + info.text = text; + + return info; + } } diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index 505c45645f..1956ec1a94 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -22,6 +22,12 @@ namespace MWClass const MWWorld::Ptr& actor, const MWWorld::Environment& environment) const; ///< Generate action for activation + virtual bool hasToolTip (const MWWorld::Ptr& ptr) const; + ///< @return true if this object has a tooltip when focused (default implementation: false) + + virtual MWGui::ToolTipInfo getToolTipInfo (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const; + ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. + virtual bool hasItemHealth (const MWWorld::Ptr& ptr) const; ///< \return Item health data available? diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index ce31741689..345ed847b3 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -1,6 +1,8 @@ #include "tooltips.hpp" #include "window_manager.hpp" +#include "../mwworld/class.hpp" + #include using namespace MWGui; @@ -130,314 +132,24 @@ IntSize ToolTips::getToolTipViaPtr () IntSize tooltipSize; - // -------------------- Door ------------------------------- - if (mFocusObject.getTypeName() == typeid(ESM::Door).name()) + const MWWorld::Class& object = MWWorld::Class::get (mFocusObject); + if (!object.hasToolTip(mFocusObject)) { - ESMS::LiveCellRef* ref = mFocusObject.get(); - - 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; - } - - 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 = createToolTip(ref->base->name, text); + mDynamicToolTipBox->setVisible(false); } - - // -------------------- 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(); - - std::string text; - if (mFullHelp) { - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createToolTip(ref->base->name, text); - } - - // -------------------- 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(); - - std::string text; - if (mFullHelp) { - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createToolTip(ref->base->name, text); - } - - // -------------------- Container ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Container).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); - - std::string text; - - 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!"); - - if (mFullHelp) { - text += "\n Owner: " + ref->ref.owner; - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createToolTip(ref->base->name, text); - } - - // -------------------- Potion ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Potion).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); - - if (mFullHelp) { - text += "\n Owner: " + ref->ref.owner; - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); - } - - // -------------------- Apparatus ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Apparatus).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); - - 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); - - if (mFullHelp) { - text += "\n Owner: " + ref->ref.owner; - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); - } - - // -------------------- Armor ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Armor).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); - - /// \todo magic effects, armor type (medium/light/heavy) - std::string text; - text += "\n" + mWindowManager->getGameSettingString("sArmorRating", "Armor Rating") + ": " + toString(ref->base->data.armor); - - /// \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); - - if (mFullHelp) { - text += "\n Owner: " + ref->ref.owner; - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); - } - - // -------------------- Book ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Book).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); - - if (mFullHelp) { - text += "\n Owner: " + ref->ref.owner; - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); - } - - // -------------------- Clothing ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Clothing).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); - - if (mFullHelp) { - text += "\n Owner: " + ref->ref.owner; - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); - } - - // -------------------- Ingredient ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Ingredient).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); - - if (mFullHelp) { - text += "\n Owner: " + ref->ref.owner; - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); - } - - // -------------------- Light ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Light).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); - - if (mFullHelp) { - text += "\n Owner: " + ref->ref.owner; - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); - } - - // -------------------- Tool ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Tool).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); - - 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); - - if (mFullHelp) { - text += "\n Owner: " + ref->ref.owner; - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); - } - - // -------------------- Miscellaneous ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Miscellaneous).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); - - if (mFullHelp) { - text += "\n Owner: " + ref->ref.owner; - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); - } - - // -------------------- Probe ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Probe).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); - - 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); - - if (mFullHelp) { - text += "\n Owner: " + ref->ref.owner; - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); - } - - // -------------------- Repair ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Repair).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); - - 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); - - if (mFullHelp) { - text += "\n Owner: " + ref->ref.owner; - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); - } - - // -------------------- Weapon ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Weapon).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); - - /// \todo weapon damage, magic effects, health (condition) - - std::string text; - text += "\n" + mWindowManager->getGameSettingString("sWeight", "Weight") + ": " + toString(ref->base->data.weight); - text += getValueString(ref->base->data.value); - - if (mFullHelp) { - text += "\n Owner: " + ref->ref.owner; - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createImageToolTip(ref->base->name, ref->base->icon, 32, text); - } - - // -------------------- Activator ------------------------------- - else if (mFocusObject.getTypeName() == typeid(ESM::Activator).name()) - { - ESMS::LiveCellRef* ref = mFocusObject.get(); - - std::string text; - if (mFullHelp) { - text += "\n Script: " + ref->base->script; - } - - tooltipSize = createToolTip(ref->base->name, text); - } - else { - // object without tooltip - mDynamicToolTipBox->setVisible(false); + mDynamicToolTipBox->setVisible(true); + + ToolTipInfo info = object.getToolTipInfo(mFocusObject, mWindowManager->getEnvironment()); + if (info.icon == "") + { + tooltipSize= createToolTip(info.caption, info.text); + } + else + { + tooltipSize = createImageToolTip(info.caption, info.icon, 32, info.text); + } } return tooltipSize; @@ -490,8 +202,6 @@ IntSize ToolTips::createImageToolTip(const std::string& caption, const std::stri captionWidget->setCoord( (totalSize.width - captionSize.width)/2 + imageSize, (imageSize-captionSize.height)/2, captionSize.width-imageSize, captionSize.height); - mDynamicToolTipBox->setVisible(caption != ""); - return totalSize; } @@ -509,8 +219,6 @@ IntSize ToolTips::createToolTip(const std::string& caption, const std::string& t box->setProperty("WordWrap", "true"); box->setCaption(caption + (realText != "" ? "\n#BF9959" + realText : "")); - mDynamicToolTipBox->setVisible(caption != ""); - return box->getTextSize(); } @@ -523,8 +231,6 @@ IntSize ToolTips::createToolTip(const std::string& text) box->setProperty("WordWrap", "true"); box->setCaption(text); - mDynamicToolTipBox->setVisible(text != ""); - return box->getTextSize(); } @@ -542,15 +248,28 @@ std::string ToolTips::toString(const int value) return stream.str(); } -std::string ToolTips::getValueString(const int value) +std::string ToolTips::getValueString(const int value, const std::string& prefix) { if (value == 0) return ""; else - return "\n" + mWindowManager->getGameSettingString("sValue", "Value") + ": " + toString(value); + return "\n" + prefix + ": " + toString(value); +} + +std::string ToolTips::getMiscString(const std::string& text, const std::string& prefix) +{ + if (text == "") + return ""; + else + return "\n" + prefix + ": " + text; } void ToolTips::toggleFullHelp() { mFullHelp = !mFullHelp; } + +bool ToolTips::getFullHelp() const +{ + return mFullHelp; +} diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index a3447eb441..46aab38761 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -10,13 +10,12 @@ namespace MWGui class WindowManager; // Info about tooltip that is supplied by the MWWorld::Class object - // Not used yet, but it will replace the if-else-if blocks in tooltips.cpp struct ToolTipInfo { public: std::string caption; std::string text; - std::string image; + std::string icon; /// \todo enchantments (armor, cloth, weapons), magic effects (potions, ingredients) }; @@ -32,9 +31,19 @@ namespace MWGui void enterGuiMode(); void toggleFullHelp(); ///< show extra info in item tooltips (owner, script) + bool getFullHelp() const; void setFocusObject(const MWWorld::Ptr& focus); + static std::string getValueString(const int value, const std::string& prefix); + ///< @return "prefix: value" or "" if value is 0 + + static std::string getMiscString(const std::string& text, const std::string& prefix); + ///< @return "prefix: text" or "" if text is empty + + static std::string toString(const float value); + static std::string toString(const int value); + private: MyGUI::Widget* mDynamicToolTipBox; @@ -56,12 +65,6 @@ namespace MWGui MyGUI::IntSize createToolTip(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; bool mFullHelp; diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index b18ee4e432..f49bcfaf84 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -502,3 +502,8 @@ void WindowManager::toggleFullHelp() { mToolTips->toggleFullHelp(); } + +bool WindowManager::getFullHelp() const +{ + return mToolTips->getFullHelp(); +} diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index d76d15dd4c..1b1eff1dc9 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -162,6 +162,7 @@ namespace MWGui void toggleFogOfWar(); void toggleFullHelp(); ///< show extra info in item tooltips (owner, script) + bool getFullHelp() const; int toggleFps(); ///< toggle fps display @return resulting fps level diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 10368901b7..aaf19963d6 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -174,7 +174,7 @@ namespace MWWorld throw std::runtime_error ("class does not have an down sound"); } - MWGui::ToolTipInfo Class::getToolTipInfo (const Ptr& ptr) const + MWGui::ToolTipInfo Class::getToolTipInfo (const Ptr& ptr, MWWorld::Environment& environment) const { throw std::runtime_error ("class does not have a tool tip"); } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 5441b874d5..1b7b8b66ab 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -90,7 +90,7 @@ namespace MWWorld virtual bool hasToolTip (const Ptr& ptr) const; ///< @return true if this object has a tooltip when focused (default implementation: false) - virtual MWGui::ToolTipInfo getToolTipInfo (const Ptr& ptr) const; + virtual MWGui::ToolTipInfo getToolTipInfo (const Ptr& ptr, MWWorld::Environment& environment) const; ///< @return the content of the tool tip to be displayed. raises exception if the object has no tooltip. virtual MWMechanics::NpcStats& getNpcStats (const Ptr& ptr) const; From c044fadcc303ad9f5621a75a21bc54770844e5df Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 17 Apr 2012 15:31:16 +0200 Subject: [PATCH 16/30] show weapon type & damage in the tooltip --- apps/openmw/mwclass/weapon.cpp | 53 ++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 1fb8715729..d2ea92126b 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -269,10 +269,59 @@ namespace MWClass std::string text; - /// \todo weapon type, damage + // weapon type & damage. arrows / bolts don't have his info. + if (ref->base->data.type < 12) + { + text += "\n" + environment.mWorld->getStore().gameSettings.search("sType")->str + " "; + + std::map > mapping; + mapping[ESM::Weapon::ShortBladeOneHand] = std::make_pair("sSkillShortblade", "sOneHanded"); + mapping[ESM::Weapon::LongBladeOneHand] = std::make_pair("sSkillLongblade", "sOneHanded"); + mapping[ESM::Weapon::LongBladeTwoHand] = std::make_pair("sSkillLongblade", "sTwoHanded"); + mapping[ESM::Weapon::BluntOneHand] = std::make_pair("sSkillBluntweapon", "sOneHanded"); + mapping[ESM::Weapon::BluntTwoClose] = std::make_pair("sSkillBluntweapon", "sTwoHanded"); + mapping[ESM::Weapon::BluntTwoWide] = std::make_pair("sSkillBluntweapon", "sTwoHanded"); + mapping[ESM::Weapon::SpearTwoWide] = std::make_pair("sSkillSpear", "sTwoHanded"); + mapping[ESM::Weapon::AxeOneHand] = std::make_pair("sSkillAxe", "sOneHanded"); + mapping[ESM::Weapon::AxeTwoHand] = std::make_pair("sSkillAxe", "sTwoHanded"); + mapping[ESM::Weapon::MarksmanBow] = std::make_pair("sSkillMarksman", ""); + mapping[ESM::Weapon::MarksmanCrossbow] = std::make_pair("sSkillMarksman", ""); + mapping[ESM::Weapon::MarksmanThrown] = std::make_pair("sSkillMarksman", ""); + + std::string type = mapping[ref->base->data.type].first; + std::string oneOrTwoHanded = mapping[ref->base->data.type].second; + + text += environment.mWorld->getStore().gameSettings.search(type)->str + + ((oneOrTwoHanded != "") ? ", " + environment.mWorld->getStore().gameSettings.search(oneOrTwoHanded)->str : ""); + + // weapon damage + if (ref->base->data.type >= 9) + { + // marksman + text += "\n" + environment.mWorld->getStore().gameSettings.search("sAttack")->str + ": " + + MWGui::ToolTips::toString(static_cast(ref->base->data.chop[0])) + + " - " + MWGui::ToolTips::toString(static_cast(ref->base->data.chop[1])); + } + else + { + // Chop + text += "\n" + environment.mWorld->getStore().gameSettings.search("sChop")->str + ": " + + MWGui::ToolTips::toString(static_cast(ref->base->data.chop[0])) + + " - " + MWGui::ToolTips::toString(static_cast(ref->base->data.chop[1])); + // Slash + text += "\n" + environment.mWorld->getStore().gameSettings.search("sSlash")->str + ": " + + MWGui::ToolTips::toString(static_cast(ref->base->data.slash[0])) + + " - " + MWGui::ToolTips::toString(static_cast(ref->base->data.slash[1])); + // Thrust + text += "\n" + environment.mWorld->getStore().gameSettings.search("sThrust")->str + ": " + + MWGui::ToolTips::toString(static_cast(ref->base->data.thrust[0])) + + " - " + MWGui::ToolTips::toString(static_cast(ref->base->data.thrust[1])); + } + } /// \todo store the current weapon health somewhere - text += "\n" + environment.mWorld->getStore().gameSettings.search("sCondition")->str + ": " + MWGui::ToolTips::toString(ref->base->data.health); + if (ref->base->data.type < 11) // thrown weapons and arrows/bolts don't have health, only quantity + text += "\n" + environment.mWorld->getStore().gameSettings.search("sCondition")->str + ": " + MWGui::ToolTips::toString(ref->base->data.health); text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); From c2fdacc84fc5f1a3f69a9e2f1c74ff875f9d6d8b Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 17 Apr 2012 15:51:02 +0200 Subject: [PATCH 17/30] show the creature name for soul gems (if any) --- apps/openmw/mwclass/misc.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 8cd2554a10..222ac1b782 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -132,6 +132,12 @@ namespace MWClass info.caption = ref->base->name; info.icon = ref->base->icon; + if (ref->ref.soul != "") + { + const ESM::Creature *creature = environment.mWorld->getStore().creatures.search(ref->ref.soul); + info.caption += " (" + creature->name + ")"; + } + std::string text; if (ref->base->name == environment.mWorld->getStore().gameSettings.search("sGold")->str) From 8eb06363449bb638882b77ff28c0ce19901bcda0 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 17 Apr 2012 16:00:13 +0200 Subject: [PATCH 18/30] restored gui-mode tooltips --- apps/openmw/mwgui/tooltips.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 345ed847b3..fd44c7d9be 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -89,6 +89,7 @@ void ToolTips::onFrame(float frameDuration) } setCoord(tooltipPosition.left, tooltipPosition.top, size.width, size.height); + mDynamicToolTipBox->setVisible(true); } else { From 94993b515c7abade56d4885d46ea305ea42c7947 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 17 Apr 2012 16:49:28 +0200 Subject: [PATCH 19/30] clean up and tooltip padding --- apps/openmw/mwgui/tooltips.cpp | 100 +++++++++++++++------------------ apps/openmw/mwgui/tooltips.hpp | 8 +-- 2 files changed, 45 insertions(+), 63 deletions(-) diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index fd44c7d9be..ab766dc56a 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -47,9 +47,6 @@ void ToolTips::onFrame(float frameDuration) 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"); @@ -60,11 +57,11 @@ void ToolTips::onFrame(float frameDuration) return; } else if (type == "Text") - tooltipSize = createToolTip(text); + tooltipSize = createToolTip(text, "", 0, ""); else if (type == "CaptionText") { std::string caption = focus->getUserString("ToolTipCaption"); - tooltipSize = createToolTip(caption, text); + tooltipSize = createToolTip(caption, "", 0, text); } else if (type == "ImageCaptionText") { @@ -72,23 +69,22 @@ void ToolTips::onFrame(float frameDuration) std::string image = focus->getUserString("ToolTipImage"); std::string sizeString = focus->getUserString("ToolTipImageSize"); int size = (sizeString != "" ? boost::lexical_cast(sizeString) : 32); - tooltipSize = createImageToolTip(caption, image, size, text); + tooltipSize = createToolTip(caption, image, size, text); } IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24); - IntSize size = tooltipSize + IntSize(6, 6); // make the tooltip stay completely in the viewport - if ((tooltipPosition.left + size.width) > viewSize.width) + if ((tooltipPosition.left + tooltipSize.width) > viewSize.width) { - tooltipPosition.left = viewSize.width - size.width; + tooltipPosition.left = viewSize.width - tooltipSize.width; } - if ((tooltipPosition.top + size.height) > viewSize.height) + if ((tooltipPosition.top + tooltipSize.height) > viewSize.height) { - tooltipPosition.top = viewSize.height - size.height; + tooltipPosition.top = viewSize.height - tooltipSize.height; } - setCoord(tooltipPosition.left, tooltipPosition.top, size.width, size.height); + setCoord(tooltipPosition.left, tooltipPosition.top, tooltipSize.width, tooltipSize.height); mDynamicToolTipBox->setVisible(true); } else @@ -97,8 +93,6 @@ void ToolTips::onFrame(float frameDuration) { IntSize tooltipSize = getToolTipViaPtr(); - tooltipSize += IntSize(6,6); // padding, adjust for skin - // 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, @@ -145,11 +139,11 @@ IntSize ToolTips::getToolTipViaPtr () ToolTipInfo info = object.getToolTipInfo(mFocusObject, mWindowManager->getEnvironment()); if (info.icon == "") { - tooltipSize= createToolTip(info.caption, info.text); + tooltipSize = createToolTip(info.caption, "", 0, info.text); } else { - tooltipSize = createImageToolTip(info.caption, info.icon, 32, info.text); + tooltipSize = createToolTip(info.caption, info.icon, 32, info.text); } } @@ -170,71 +164,65 @@ void ToolTips::findImageExtension(std::string& image) } } -IntSize ToolTips::createImageToolTip(const std::string& caption, const std::string& image, const int imageSize, const std::string& text) +IntSize ToolTips::createToolTip(const std::string& caption, const std::string& image, const int imageSize, const std::string& text) { // remove the first newline (easier this way) std::string realText = text; if (realText.size() > 0 && realText[0] == '\n') realText.erase(0, 1); + // this the maximum width of the tooltip before it starts word-wrapping + setCoord(0, 0, 300, 300); + + const IntPoint padding(8, 8); + + const int imageCaptionHPadding = 8; + const int imageCaptionVPadding = 4; + std::string realImage = "icons\\" + image; findImageExtension(realImage); 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, 300-imageSize), Align::Stretch, "ToolTipText"); + IntSize captionSize = captionWidget->getTextSize(); + + int captionHeight = std::max(captionSize.height, imageSize); + + EditBox* textWidget = mDynamicToolTipBox->createWidget("SandText", IntCoord(0, captionHeight+imageCaptionVPadding, 300, 300-captionHeight-imageCaptionVPadding), Align::Stretch, "ToolTipText"); textWidget->setProperty("Static", "true"); textWidget->setProperty("MultiLine", "true"); textWidget->setProperty("WordWrap", "true"); textWidget->setCaption(realText); - textWidget->setTextAlign(Align::HCenter); - - IntSize captionSize = captionWidget->getTextSize(); + textWidget->setTextAlign(Align::HCenter | Align::Top); IntSize textSize = textWidget->getTextSize(); captionSize += IntSize(imageSize, 0); // adjust for image - IntSize totalSize = IntSize( std::max(textSize.width, captionSize.width), ((realText != "") ? textSize.height : 0) + imageSize ); + IntSize totalSize = IntSize( std::max(textSize.width, captionSize.width + ((image != "") ? imageCaptionHPadding : 0)), + ((realText != "") ? textSize.height + imageCaptionVPadding : 0) + captionHeight ); - ImageBox* imageWidget = mDynamicToolTipBox->createWidget("ImageBox", - IntCoord((totalSize.width - captionSize.width)/2, 0, imageSize, imageSize), - Align::Left | Align::Top, "ToolTipImage"); - imageWidget->setImageTexture(realImage); + if (image != "") + { + ImageBox* imageWidget = mDynamicToolTipBox->createWidget("ImageBox", + IntCoord((totalSize.width - captionSize.width - imageCaptionHPadding)/2, 0, imageSize, imageSize), + Align::Left | Align::Top, "ToolTipImage"); + imageWidget->setImageTexture(realImage); + imageWidget->setPosition (imageWidget->getPosition() + padding); + } - captionWidget->setCoord( (totalSize.width - captionSize.width)/2 + imageSize, (imageSize-captionSize.height)/2, captionSize.width-imageSize, captionSize.height); + captionWidget->setCoord( (totalSize.width - captionSize.width)/2 + imageSize, + (captionHeight-captionSize.height)/2, + captionSize.width-imageSize, + captionSize.height); + + captionWidget->setPosition (captionWidget->getPosition() + padding); + textWidget->setPosition (textWidget->getPosition() + IntPoint(0, padding.top)); // only apply vertical padding, the horizontal works automatically due to Align::HCenter + + totalSize += IntSize(padding.left*2, padding.top*2); return totalSize; } -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[0] == '\n') - realText.erase(0, 1); - - 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->setProperty("WordWrap", "true"); - box->setCaption(caption + (realText != "" ? "\n#BF9959" + realText : "")); - - return box->getTextSize(); -} - -IntSize ToolTips::createToolTip(const std::string& text) -{ - EditBox* box = mDynamicToolTipBox->createWidget("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); - - return box->getTextSize(); -} - std::string ToolTips::toString(const float value) { std::ostringstream stream; diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index 46aab38761..d84a1093be 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -56,13 +56,7 @@ namespace MWGui MyGUI::IntSize getToolTipViaPtr (); ///< @return requested tooltip size - MyGUI::IntSize createImageToolTip(const std::string& caption, const std::string& image, const int imageSize, const std::string& text); - ///< @return requested tooltip size - - MyGUI::IntSize createToolTip(const std::string& caption, const std::string& text); - ///< @return requested tooltip size - - MyGUI::IntSize createToolTip(const std::string& text); + MyGUI::IntSize createToolTip(const std::string& caption, const std::string& image, const int imageSize, const std::string& text); ///< @return requested tooltip size bool mGameMode; From 2e57cf5730ed326d45f1c828d158bb6bb408d1c7 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 17 Apr 2012 18:47:51 +0200 Subject: [PATCH 20/30] fixed the tooltip for doors leading to exteriors, fixed map window cell name --- apps/openmw/mwclass/door.cpp | 26 ++++++++++++++++++++++---- apps/openmw/mwgui/window_manager.cpp | 5 ++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index e06fdecda8..794d57d1c2 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -164,12 +164,30 @@ namespace MWClass 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 != "")) + if (ref->ref.teleport) { + std::string dest; + if (ref->ref.destCell != "") + { + // door leads to an interior, use interior name as tooltip + dest = ref->ref.destCell; + } + else + { + // door leads to exterior, use cell name (if any), otherwise translated region name + int x,y; + environment.mWorld->positionToIndex (ref->ref.doorDest.pos[0], ref->ref.doorDest.pos[1], x, y); + const ESM::Cell* cell = environment.mWorld->getStore().cells.findExt(x,y); + if (cell->name != "") + dest = cell->name; + else + { + const ESM::Region* region = environment.mWorld->getStore().regions.search(cell->region); + dest = region->name; + } + } text += "\n" + environment.mWorld->getStore().gameSettings.search("sTo")->str; - text += "\n"+ref->ref.destCell; + text += "\n"+dest; } if (ref->ref.lockLevel > 0) diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index f49bcfaf84..0188a15b31 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -433,7 +433,10 @@ void WindowManager::changeCell(MWWorld::Ptr::CellStore* cell) if (cell->cell->name != "") name = cell->cell->name; else - name = cell->cell->region; + { + const ESM::Region* region = environment.mWorld->getStore().regions.search(cell->cell->region); + name = region->name; + } map->setCellName( name ); From d568b27b9272ca46670b59ffba4b85336d79cb76 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 18 Apr 2012 16:53:56 +0200 Subject: [PATCH 21/30] spell widget i18n improvements (used e.g. in birth menu) --- apps/openmw/mwclass/weapon.cpp | 30 +++++++++++++++++++++++ apps/openmw/mwgui/tooltips.cpp | 44 +++++++++++++++++++--------------- apps/openmw/mwgui/tooltips.hpp | 14 +++++++++-- apps/openmw/mwgui/widgets.cpp | 20 +++++++++++----- 4 files changed, 81 insertions(+), 27 deletions(-) diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index d2ea92126b..bfb5074b04 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -326,6 +326,36 @@ namespace MWClass text += "\n" + environment.mWorld->getStore().gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); text += MWGui::ToolTips::getValueString(ref->base->data.value, environment.mWorld->getStore().gameSettings.search("sValue")->str); + // this should be going into a custom mygui widget MWEnchantment + /* + // enchantments + if (ref->base->enchant != "") + { + const ESM::Enchantment* enchant = environment.mWorld->getStore().enchants.search(ref->base->enchant); + if (enchant->data.type == ESM::Enchantment::CastOnce) + text += "\n" + environment.mWorld->getStore().gameSettings.search("sItemCastOnce")->str; + else if (enchant->data.type == ESM::Enchantment::WhenStrikes) + text += "\n" + environment.mWorld->getStore().gameSettings.search("sItemCastWhenStrikes")->str; + else if (enchant->data.type == ESM::Enchantment::WhenUsed) + text += "\n" + environment.mWorld->getStore().gameSettings.search("sItemCastWhenUsed")->str; + else if (enchant->data.type == ESM::Enchantment::ConstantEffect) + text += "\n" + environment.mWorld->getStore().gameSettings.search("sItemCastConstant")->str; + + if (enchant->data.type == ESM::Enchantment::WhenStrikes + || enchant->data.type == ESM::Enchantment::WhenUsed) + { + /// \todo store the current enchantment charge somewhere + // info.currentCharge = enchant->data.charge; + //info.totalCharge = enchant->data.charge; + } + } + */ + if (ref->base->enchant != "") + { + const ESM::Enchantment* enchant = environment.mWorld->getStore().enchants.search(ref->base->enchant); + info.enchant = enchant; + } + if (environment.mWindowManager->getFullHelp()) { text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index ab766dc56a..5c69cedb62 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -51,26 +51,35 @@ void ToolTips::onFrame(float frameDuration) std::string type = focus->getUserString("ToolTipType"); std::string text = focus->getUserString("ToolTipText"); + + ToolTipInfo info; + if (type == "") { mDynamicToolTipBox->setVisible(false); return; - } + } else if (type == "Text") - tooltipSize = createToolTip(text, "", 0, ""); + { + info.caption = text; + } else if (type == "CaptionText") { std::string caption = focus->getUserString("ToolTipCaption"); - tooltipSize = createToolTip(caption, "", 0, text); + info.caption = caption; + info.text = text; } else if (type == "ImageCaptionText") { std::string caption = focus->getUserString("ToolTipCaption"); std::string image = focus->getUserString("ToolTipImage"); std::string sizeString = focus->getUserString("ToolTipImageSize"); - int size = (sizeString != "" ? boost::lexical_cast(sizeString) : 32); - tooltipSize = createToolTip(caption, image, size, text); + + info.text = text; + info.caption = caption; + info.icon = image; } + tooltipSize = createToolTip(info); IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24); @@ -137,14 +146,7 @@ IntSize ToolTips::getToolTipViaPtr () mDynamicToolTipBox->setVisible(true); ToolTipInfo info = object.getToolTipInfo(mFocusObject, mWindowManager->getEnvironment()); - if (info.icon == "") - { - tooltipSize = createToolTip(info.caption, "", 0, info.text); - } - else - { - tooltipSize = createToolTip(info.caption, info.icon, 32, info.text); - } + tooltipSize = createToolTip(info); } return tooltipSize; @@ -164,12 +166,16 @@ void ToolTips::findImageExtension(std::string& image) } } -IntSize ToolTips::createToolTip(const std::string& caption, const std::string& image, const int imageSize, const std::string& text) +IntSize ToolTips::createToolTip(const ToolTipInfo& info) { + std::string caption = info.caption; + std::string image = info.icon; + int imageSize = (image != "") ? 32 : 0; + std::string text = info.text; + // remove the first newline (easier this way) - std::string realText = text; - if (realText.size() > 0 && realText[0] == '\n') - realText.erase(0, 1); + if (text.size() > 0 && text[0] == '\n') + text.erase(0, 1); // this the maximum width of the tooltip before it starts word-wrapping setCoord(0, 0, 300, 300); @@ -193,13 +199,13 @@ IntSize ToolTips::createToolTip(const std::string& caption, const std::string& i textWidget->setProperty("Static", "true"); textWidget->setProperty("MultiLine", "true"); textWidget->setProperty("WordWrap", "true"); - textWidget->setCaption(realText); + textWidget->setCaption(text); textWidget->setTextAlign(Align::HCenter | Align::Top); IntSize textSize = textWidget->getTextSize(); captionSize += IntSize(imageSize, 0); // adjust for image IntSize totalSize = IntSize( std::max(textSize.width, captionSize.width + ((image != "") ? imageCaptionHPadding : 0)), - ((realText != "") ? textSize.height + imageCaptionVPadding : 0) + captionHeight ); + ((text != "") ? textSize.height + imageCaptionVPadding : 0) + captionHeight ); if (image != "") { diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index d84a1093be..c00faba869 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -13,11 +13,21 @@ namespace MWGui struct ToolTipInfo { public: + ToolTipInfo() : + enchant(0), + effects(0) + { + }; + std::string caption; std::string text; std::string icon; - /// \todo enchantments (armor, cloth, weapons), magic effects (potions, ingredients) + // enchantment (for cloth, armor, weapons) + const ESM::Enchantment* enchant; + + // effects (for potions, ingredients) + const ESM::EffectList* effects; }; class ToolTips : public OEngine::GUI::Layout @@ -56,7 +66,7 @@ namespace MWGui MyGUI::IntSize getToolTipViaPtr (); ///< @return requested tooltip size - MyGUI::IntSize createToolTip(const std::string& caption, const std::string& image, const int imageSize, const std::string& text); + MyGUI::IntSize createToolTip(const ToolTipInfo& info); ///< @return requested tooltip size bool mGameMode; diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 74603aaf1c..c833834681 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -290,6 +290,12 @@ void MWSpellEffect::updateWidgets() { if (magicEffect) { + std::string pt = mWindowManager->getGameSettingString("spoint", ""); + std::string pts = mWindowManager->getGameSettingString("spoints", ""); + std::string to = " " + mWindowManager->getGameSettingString("sTo", "") + " "; + std::string sec = " " + mWindowManager->getGameSettingString("ssecond", ""); + std::string secs = " " + mWindowManager->getGameSettingString("sseconds", ""); + // TODO: Get name of effect from GMST std::string spellLine = ""; if (effect.skill >= 0 && effect.skill < ESM::Skill::Length) @@ -313,22 +319,24 @@ void MWSpellEffect::updateWidgets() if (effect.magnMin >= 0 || effect.magnMax >= 0) { if (effect.magnMin == effect.magnMax) - spellLine += " " + boost::lexical_cast(effect.magnMin) + " pts"; + spellLine += " " + boost::lexical_cast(effect.magnMin) + " " + ((effect.magnMin == 1) ? pt : pts); else { - spellLine += " " + boost::lexical_cast(effect.magnMin) + " to " + boost::lexical_cast(effect.magnMin) + " pts"; + spellLine += " " + boost::lexical_cast(effect.magnMin) + to + boost::lexical_cast(effect.magnMin) + " " + pts; } } if (effect.duration >= 0) { - spellLine += " for " + boost::lexical_cast(effect.duration) + " secs"; + spellLine += " " + mWindowManager->getGameSettingString("sfor", "") + " " + boost::lexical_cast(effect.duration) + ((effect.duration == 1) ? sec : secs); } + + std::string on = mWindowManager->getGameSettingString("sonword", ""); if (effect.range == ESM::RT_Self) - spellLine += " on Self"; + spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeSelf", ""); else if (effect.range == ESM::RT_Touch) - spellLine += " on Touch"; + spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTouch", ""); else if (effect.range == ESM::RT_Target) - spellLine += " on Target"; + spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTarget", ""); static_cast(textWidget)->setCaption(spellLine); } else From c7381d44917629cd804875c23ded7ab2d3cbd539 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 18 Apr 2012 18:09:30 +0200 Subject: [PATCH 22/30] adding widget MWEnchantment --- apps/openmw/mwgui/widgets.cpp | 44 +++++++++++++++++++++++++++++++++++ apps/openmw/mwgui/widgets.hpp | 29 ++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index c833834681..568b31455c 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -264,6 +264,50 @@ MWSpell::~MWSpell() { } +/* MWEnchantment */ + +MWEnchantment::MWEnchantment() + : mWindowManager(nullptr) +{ +} + +void MWEnchantment::setEnchantmentId(const std::string &enchantId) +{ + id = enchantId; + updateWidgets(); +} + +void MWEnchantment::createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord) +{ + const ESMS::ESMStore &store = mWindowManager->getStore(); + const ESM::Enchantment *enchant = store.enchants.search(id); + MYGUI_ASSERT(enchant, "enchantment with id '" << id << "' not found"); + + MWSpellEffectPtr effect = nullptr; + std::vector::const_iterator end = enchant->effects.list.end(); + for (std::vector::const_iterator it = enchant->effects.list.begin(); it != end; ++it) + { + effect = creator->createWidget("MW_EffectImage", coord, MyGUI::Align::Default); + effect->setWindowManager(mWindowManager); + effect->setSpellEffect(*it); + effects.push_back(effect); + coord.top += effect->getHeight(); + } +} + +void MWEnchantment::updateWidgets() +{ +} + +void MWEnchantment::initialiseOverride() +{ + Base::initialiseOverride(); +} + +MWEnchantment::~MWEnchantment() +{ +} + /* MWSpellEffect */ MWSpellEffect::MWSpellEffect() diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index a7916285eb..595ee83b64 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -126,7 +126,7 @@ namespace MWGui protected: virtual ~MWSpell(); - virtual void initialiseOverride(); + virtual void initialiseOverride(); private: void updateWidgets(); @@ -137,6 +137,33 @@ namespace MWGui }; typedef MWSpell* MWSpellPtr; + class MYGUI_EXPORT MWEnchantment : public Widget + { + MYGUI_RTTI_DERIVED( MWEnchantment ); + public: + MWEnchantment(); + + typedef MWMechanics::Stat EnchantmentValue; + + void setWindowManager(WindowManager* parWindowManager) { mWindowManager = parWindowManager; } + void setEnchantmentId(const std::string &enchantId); + void createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord); + + const std::string &getSpellId() const { return id; } + + protected: + virtual ~MWEnchantment(); + + virtual void initialiseOverride(); + + private: + void updateWidgets(); + + WindowManager* mWindowManager; + std::string id; + }; + typedef MWEnchantment* MWEnchantmentPtr; + class MYGUI_EXPORT MWSpellEffect : public Widget { MYGUI_RTTI_DERIVED( MWSpellEffect ); From 4889902b9879aecdf45542b2d5584052de15cb9e Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 18 Apr 2012 21:18:53 +0200 Subject: [PATCH 23/30] magic effect widget improvements, read name of effect from GMST and don't show duration/target for constant effects --- apps/openmw/mwgui/birth.cpp | 2 +- apps/openmw/mwgui/widgets.cpp | 180 ++++++++++++++++++++++++++++--- apps/openmw/mwgui/widgets.hpp | 6 +- files/mygui/openmw_list.skin.xml | 4 + 4 files changed, 178 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwgui/birth.cpp b/apps/openmw/mwgui/birth.cpp index 44c165743d..046017204f 100644 --- a/apps/openmw/mwgui/birth.cpp +++ b/apps/openmw/mwgui/birth.cpp @@ -202,7 +202,7 @@ void BirthDialog::updateSpells() MyGUI::IntCoord spellCoord = coord; spellCoord.height = 24; // TODO: This should be fetched from the skin somehow, or perhaps a widget in the layout as a template? - spellWidget->createEffectWidgets(spellItems, spellArea, spellCoord); + spellWidget->createEffectWidgets(spellItems, spellArea, spellCoord, category); coord.top = spellCoord.top; ++i; diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 568b31455c..58cfee991b 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -222,7 +222,7 @@ void MWSpell::setSpellId(const std::string &spellId) updateWidgets(); } -void MWSpell::createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord) +void MWSpell::createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, const int category) { const ESMS::ESMStore &store = mWindowManager->getStore(); const ESM::Spell *spell = store.spells.search(id); @@ -234,6 +234,7 @@ void MWSpell::createEffectWidgets(std::vector &effects, MyGUI: { effect = creator->createWidget("MW_EffectImage", coord, MyGUI::Align::Default); effect->setWindowManager(mWindowManager); + effect->setConstant(category == 0); effect->setSpellEffect(*it); effects.push_back(effect); coord.top += effect->getHeight(); @@ -340,8 +341,7 @@ void MWSpellEffect::updateWidgets() std::string sec = " " + mWindowManager->getGameSettingString("ssecond", ""); std::string secs = " " + mWindowManager->getGameSettingString("sseconds", ""); - // TODO: Get name of effect from GMST - std::string spellLine = ""; + std::string spellLine = effectIDToString(effect.effectID); if (effect.skill >= 0 && effect.skill < ESM::Skill::Length) { spellLine += " " + mWindowManager->getGameSettingString(ESM::Skill::sSkillNameIds[effect.skill], ""); @@ -369,18 +369,24 @@ void MWSpellEffect::updateWidgets() spellLine += " " + boost::lexical_cast(effect.magnMin) + to + boost::lexical_cast(effect.magnMin) + " " + pts; } } - if (effect.duration >= 0) + + // constant effects have no duration and no target + if (!mIsConstant) { - spellLine += " " + mWindowManager->getGameSettingString("sfor", "") + " " + boost::lexical_cast(effect.duration) + ((effect.duration == 1) ? sec : secs); + if (effect.duration >= 0) + { + spellLine += " " + mWindowManager->getGameSettingString("sfor", "") + " " + boost::lexical_cast(effect.duration) + ((effect.duration == 1) ? sec : secs); + } + + std::string on = mWindowManager->getGameSettingString("sonword", ""); + if (effect.range == ESM::RT_Self) + spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeSelf", ""); + else if (effect.range == ESM::RT_Touch) + spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTouch", ""); + else if (effect.range == ESM::RT_Target) + spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTarget", ""); } - std::string on = mWindowManager->getGameSettingString("sonword", ""); - if (effect.range == ESM::RT_Self) - spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeSelf", ""); - else if (effect.range == ESM::RT_Touch) - spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTouch", ""); - else if (effect.range == ESM::RT_Target) - spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTarget", ""); static_cast(textWidget)->setCaption(spellLine); } else @@ -394,6 +400,156 @@ void MWSpellEffect::updateWidgets() } } +std::string MWSpellEffect::effectIDToString(const short effectID) +{ + // Map effect ID to GMST name + // http://www.uesp.net/morrow/hints/mweffects.shtml + std::map names; + names[85] ="sEffectAbsorbAttribute"; + names[88] ="sEffectAbsorbFatigue"; + names[86] ="sEffectAbsorbHealth"; + names[87] ="sEffectAbsorbSpellPoints"; + names[89] ="sEffectAbsorbSkill"; + names[63] ="sEffectAlmsiviIntervention"; + names[47] ="sEffectBlind"; + names[123] ="sEffectBoundBattleAxe"; + names[129] ="sEffectBoundBoots"; + names[127] ="sEffectBoundCuirass"; + names[120] ="sEffectBoundDagger"; + names[131] ="sEffectBoundGloves"; + names[128] ="sEffectBoundHelm"; + names[125] ="sEffectBoundLongbow"; + names[121] ="sEffectBoundLongsword"; + names[122] ="sEffectBoundMace"; + names[130] ="sEffectBoundShield"; + names[124] ="sEffectBoundSpear"; + names[7] ="sEffectBurden"; + names[50] ="sEffectCalmCreature"; + names[49] ="sEffectCalmHumanoid"; + names[40] ="sEffectChameleon"; + names[44] ="sEffectCharm"; + names[118] ="sEffectCommandCreatures"; + names[119] ="sEffectCommandHumanoids"; + names[132] ="sEffectCorpus"; // NB this typo. (bethesda made it) + names[70] ="sEffectCureBlightDisease"; + names[69] ="sEffectCureCommonDisease"; + names[71] ="sEffectCureCorprusDisease"; + names[73] ="sEffectCureParalyzation"; + names[72] ="sEffectCurePoison"; + names[22] ="sEffectDamageAttribute"; + names[25] ="sEffectDamageFatigue"; + names[23] ="sEffectDamageHealth"; + names[24] ="sEffectDamageMagicka"; + names[26] ="sEffectDamageSkill"; + names[54] ="sEffectDemoralizeCreature"; + names[53] ="sEffectDemoralizeHumanoid"; + names[64] ="sEffectDetectAnimal"; + names[65] ="sEffectDetectEnchantment"; + names[66] ="sEffectDetectKey"; + names[38] ="sEffectDisintegrateArmor"; + names[37] ="sEffectDisintegrateWeapon"; + names[57] ="sEffectDispel"; + names[62] ="sEffectDivineIntervention"; + names[17] ="sEffectDrainAttribute"; + names[20] ="sEffectDrainFatigue"; + names[18] ="sEffectDrainHealth"; + names[19] ="sEffectDrainSpellpoints"; + names[21] ="sEffectDrainSkill"; + names[8] ="sEffectFeather"; + names[14] ="sEffectFireDamage"; + names[4] ="sEffectFireShield"; + names[117] ="sEffectFortifyAttackBonus"; + names[79] ="sEffectFortifyAttribute"; + names[82] ="sEffectFortifyFatigue"; + names[80] ="sEffectFortifyHealth"; + names[81] ="sEffectFortifySpellpoints"; + names[84] ="sEffectFortifyMagickaMultiplier"; + names[83] ="sEffectFortifySkill"; + names[52] ="sEffectFrenzyCreature"; + names[51] ="sEffectFrenzyHumanoid"; + names[16] ="sEffectFrostDamage"; + names[6] ="sEffectFrostShield"; + names[39] ="sEffectInvisibility"; + names[9] ="sEffectJump"; + names[10] ="sEffectLevitate"; + names[41] ="sEffectLight"; + names[5] ="sEffectLightningShield"; + names[12] ="sEffectLock"; + names[60] ="sEffectMark"; + names[43] ="sEffectNightEye"; + names[13] ="sEffectOpen"; + names[45] ="sEffectParalyze"; + names[27] ="sEffectPoison"; + names[56] ="sEffectRallyCreature"; + names[55] ="sEffectRallyHumanoid"; + names[61] ="sEffectRecall"; + names[68] ="sEffectReflect"; + names[100] ="sEffectRemoveCurse"; + names[95] ="sEffectResistBlightDisease"; + names[94] ="sEffectResistCommonDisease"; + names[96] ="sEffectResistCorprusDisease"; + names[90] ="sEffectResistFire"; + names[91] ="sEffectResistFrost"; + names[93] ="sEffectResistMagicka"; + names[98] ="sEffectResistNormalWeapons"; + names[99] ="sEffectResistParalysis"; + names[97] ="sEffectResistPoison"; + names[92] ="sEffectResistShock"; + names[74] ="sEffectRestoreAttribute"; + names[77] ="sEffectRestoreFatigue"; + names[75] ="sEffectRestoreHealth"; + names[76] ="sEffectRestoreSpellPoints"; + names[78] ="sEffectRestoreSkill"; + names[42] ="sEffectSanctuary"; + names[3] ="sEffectShield"; + names[15] ="sEffectShockDamage"; + names[46] ="sEffectSilence"; + names[11] ="sEffectSlowFall"; + names[58] ="sEffectSoultrap"; + names[48] ="sEffectSound"; + names[67] ="sEffectSpellAbsorption"; + names[136] ="sEffectStuntedMagicka"; + names[106] ="sEffectSummonAncestralGhost"; + names[110] ="sEffectSummonBonelord"; + names[108] ="sEffectSummonLeastBonewalker"; + names[134] ="sEffectSummonCenturionSphere"; + names[103] ="sEffectSummonClannfear"; + names[104] ="sEffectSummonDaedroth"; + names[105] ="sEffectSummonDremora"; + names[114] ="sEffectSummonFlameAtronach"; + names[115] ="sEffectSummonFrostAtronach"; + names[113] ="sEffectSummonGoldenSaint"; + names[109] ="sEffectSummonGreaterBonewalker"; + names[112] ="sEffectSummonHunger"; + names[102] ="sEffectSummonScamp"; + names[107] ="sEffectSummonSkeletalMinion"; + names[116] ="sEffectSummonStormAtronach"; + names[111] ="sEffectSummonWingedTwilight"; + names[135] ="sEffectSunDamage"; + names[1] ="sEffectSwiftSwim"; + names[59] ="sEffectTelekinesis"; + names[101] ="sEffectTurnUndead"; + names[133] ="sEffectVampirism"; + names[0] ="sEffectWaterBreathing"; + names[2] ="sEffectWaterWalking"; + names[33] ="sEffectWeaknesstoBlightDisease"; + names[32] ="sEffectWeaknesstoCommonDisease"; + names[34] ="sEffectWeaknesstoCorprusDisease"; + names[28] ="sEffectWeaknesstoFire"; + names[29] ="sEffectWeaknesstoFrost"; + names[31] ="sEffectWeaknesstoMagicka"; + names[36] ="sEffectWeaknesstoNormalWeapons"; + names[35] ="sEffectWeaknesstoPoison"; + names[30] ="sEffectWeaknesstoShock"; + + assert(names.find(effectID) != names.end() && "Unimplemented effect type"); + std::string res = mWindowManager->getGameSettingString(names[effectID], ""); + if (res == "") + std::cout << "Warning: Unknown effect name " << names[effectID] << std::endl; + + return res; +} + MWSpellEffect::~MWSpellEffect() { } diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index 595ee83b64..8ac27795d5 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -119,7 +119,7 @@ namespace MWGui void setWindowManager(WindowManager* parWindowManager) { mWindowManager = parWindowManager; } void setSpellId(const std::string &id); - void createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord); + void createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, const int category); const std::string &getSpellId() const { return id; } @@ -174,6 +174,9 @@ namespace MWGui void setWindowManager(WindowManager* parWindowManager) { mWindowManager = parWindowManager; } void setSpellEffect(SpellEffectValue value); + void setConstant(bool constant) { mIsConstant = constant; } + + std::string effectIDToString(const short effectID); const SpellEffectValue &getSpellEffect() const { return effect; } @@ -188,6 +191,7 @@ namespace MWGui WindowManager* mWindowManager; SpellEffectValue effect; + bool mIsConstant; // constant effect MyGUI::ImageBox* imageWidget; MyGUI::TextBox* textWidget; }; diff --git a/files/mygui/openmw_list.skin.xml b/files/mygui/openmw_list.skin.xml index 5ec975a1b0..02075ad1a6 100644 --- a/files/mygui/openmw_list.skin.xml +++ b/files/mygui/openmw_list.skin.xml @@ -184,6 +184,10 @@ + + + + From 934caf7a2b7efca4f69e2cc3040be41ffe5a42aa Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 19 Apr 2012 01:16:41 +0200 Subject: [PATCH 24/30] removed --report-focus which is now useless --- apps/openmw/engine.cpp | 51 ------------------------------------------ apps/openmw/engine.hpp | 6 ----- apps/openmw/main.cpp | 4 ---- readme.txt | 1 - 4 files changed, 62 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 36a2cb645b..77cb80b0d1 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -72,47 +72,6 @@ void OMW::Engine::executeLocalScripts() localScripts.setIgnore (MWWorld::Ptr()); } -void OMW::Engine::updateFocusReport (float duration) -{ - - if ((mFocusTDiff += duration)>0.25) - { - mFocusTDiff = 0; - - std::string name; - - std::string handle = mEnvironment.mWorld->getFacedHandle(); - - if (!handle.empty()) - { - // the faced handle is not updated immediately, so on a cell change it might - // point to an object that doesn't exist anymore - // therefore, we are catching the "Unknown Ogre handle" exception that occurs in this case - try - { - MWWorld::Ptr ptr = mEnvironment.mWorld->getPtrViaHandle (handle); - - if (!ptr.isEmpty()){ - name = MWWorld::Class::get (ptr).getName (ptr); - - } - } - catch (std::runtime_error& e) - {} - } - - if (name!=mFocusName) - { - mFocusName = name; - - if (mFocusName.empty()) - std::cout << "Unfocus" << std::endl; - else - std::cout << "Focus: " << name << std::endl; - } - } -} - void OMW::Engine::setAnimationVerbose(bool animverbose){ if(animverbose){ NifOgre::NIFLoader::getSingletonPtr()->setOutputAnimFiles(true); @@ -170,10 +129,6 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) window->getBatchCount()); mEnvironment.mWindowManager->onFrame(mEnvironment.mFrameDuration); - - // report focus object (for debugging) - if (mReportFocus) - updateFocusReport (mEnvironment.mFrameDuration); } catch (const std::exception& e) { @@ -191,7 +146,6 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager) , mNewGame (false) , mUseSound (true) , mCompileAll (false) - , mReportFocus (false) , mFocusTDiff (0) , mScriptContext (0) , mFSStrict (false) @@ -303,11 +257,6 @@ void OMW::Engine::setNewGame(bool newGame) mNewGame = newGame; } -void OMW::Engine::setReportFocus (bool report) -{ - mReportFocus = report; -} - // Initialise and enter main loop. void OMW::Engine::go() diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 6eae20cc0f..a95d4cb5c3 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -73,7 +73,6 @@ namespace OMW bool mNewGame; bool mUseSound; bool mCompileAll; - bool mReportFocus; float mFocusTDiff; std::string mFocusName; std::map mFallbackMap; @@ -100,8 +99,6 @@ namespace OMW void executeLocalScripts(); - void updateFocusReport (float duration); - virtual bool frameRenderingQueued (const Ogre::FrameEvent& evt); public: @@ -144,9 +141,6 @@ namespace OMW /// Start as a new game. void setNewGame(bool newGame); - /// Write name of focussed object to cout - void setReportFocus (bool report); - /// Initialise and enter main loop. void go(); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index df52faab14..68aa12fb36 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -155,9 +155,6 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat "\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n" "\n\twin1252 - Western European (Latin) alphabet, used by default") - ("report-focus", bpo::value()->implicit_value(true) - ->default_value(false), "write name of focussed object to cout") - ("fallback", bpo::value()->default_value(FallbackMap(), "") ->multitoken()->composing(), "fallback values") @@ -265,7 +262,6 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.setSoundUsage(!variables["nosound"].as()); engine.setScriptsVerbosity(variables["script-verbose"].as()); engine.setCompileAll(variables["script-all"].as()); - engine.setReportFocus(variables["report-focus"].as()); engine.setAnimationVerbose(variables["anim-verbose"].as()); engine.setFallbackValues(variables["fallback"].as().mMap); diff --git a/readme.txt b/readme.txt index 52c4e11a24..53f4a4c59e 100644 --- a/readme.txt +++ b/readme.txt @@ -87,7 +87,6 @@ Allowed options: win1252 - Western European (Latin) alphabet, used by default - --report-focus [=arg(=1)] (=0) write name of focussed object to cout --fallback arg fallback values From cca39978d413205e83e548ac2e2050fbb9cbbc09 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 29 Apr 2012 17:46:09 +0200 Subject: [PATCH 25/30] changed messagebox text colors --- files/mygui/openmw_interactive_messagebox_layout.xml | 2 +- files/mygui/openmw_messagebox_layout.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/files/mygui/openmw_interactive_messagebox_layout.xml b/files/mygui/openmw_interactive_messagebox_layout.xml index 744f212276..b8a71c670d 100644 --- a/files/mygui/openmw_interactive_messagebox_layout.xml +++ b/files/mygui/openmw_interactive_messagebox_layout.xml @@ -5,7 +5,7 @@ - + diff --git a/files/mygui/openmw_messagebox_layout.xml b/files/mygui/openmw_messagebox_layout.xml index 81d1c0a57e..c99c00a49e 100644 --- a/files/mygui/openmw_messagebox_layout.xml +++ b/files/mygui/openmw_messagebox_layout.xml @@ -8,7 +8,7 @@ - + From 397a97814510816284268ed3ef56714eace95324 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 29 Apr 2012 18:57:26 +0200 Subject: [PATCH 26/30] DispositionEdit tweaks --- files/mygui/openmw_dialogue_window_layout.xml | 2 +- files/mygui/openmw_dialogue_window_skin.xml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/files/mygui/openmw_dialogue_window_layout.xml b/files/mygui/openmw_dialogue_window_layout.xml index 29a3b511ec..b0e437074c 100644 --- a/files/mygui/openmw_dialogue_window_layout.xml +++ b/files/mygui/openmw_dialogue_window_layout.xml @@ -16,7 +16,7 @@ - + diff --git a/files/mygui/openmw_dialogue_window_skin.xml b/files/mygui/openmw_dialogue_window_skin.xml index ecdec8a5c0..31ce626be0 100644 --- a/files/mygui/openmw_dialogue_window_skin.xml +++ b/files/mygui/openmw_dialogue_window_skin.xml @@ -8,12 +8,12 @@ - - + + - + From f733382f749dc3d7755534adcb3f2db7bacee067 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 30 Apr 2012 00:57:41 +0200 Subject: [PATCH 27/30] tooltip now contains info about item enchantment --- apps/openmw/mwclass/armor.cpp | 2 + apps/openmw/mwclass/book.cpp | 2 + apps/openmw/mwclass/clothing.cpp | 2 + apps/openmw/mwclass/weapon.cpp | 30 +--------- apps/openmw/mwgui/dialogue.cpp | 10 +++- apps/openmw/mwgui/dialogue.hpp | 1 + apps/openmw/mwgui/tooltips.cpp | 83 +++++++++++++++++++++++++--- apps/openmw/mwgui/tooltips.hpp | 3 +- apps/openmw/mwgui/widgets.cpp | 35 +++++++++++- apps/openmw/mwgui/widgets.hpp | 21 ++++++- apps/openmw/mwgui/window_manager.cpp | 1 + files/mygui/openmw_text.skin.xml | 5 ++ 12 files changed, 153 insertions(+), 42 deletions(-) diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index a01b28a21c..fb34e4c883 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -242,6 +242,8 @@ namespace MWClass text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); } + info.enchant = ref->base->enchant; + info.text = text; return info; diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index aa87b009be..ab659b4805 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -130,6 +130,8 @@ namespace MWClass text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); } + info.enchant = ref->base->enchant; + info.text = text; return info; diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 669407d84d..620b664cc4 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -195,6 +195,8 @@ namespace MWClass text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); } + info.enchant = ref->base->enchant; + info.text = text; return info; diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 1caedce62b..fcfaebcb7a 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -328,35 +328,7 @@ namespace MWClass text += "\n" + store.gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); text += MWGui::ToolTips::getValueString(ref->base->data.value, store.gameSettings.search("sValue")->str); - // this should be going into a custom mygui widget MWEnchantment - /* - // enchantments - if (ref->base->enchant != "") - { - const ESM::Enchantment* enchant = environment.mWorld->getStore().enchants.search(ref->base->enchant); - if (enchant->data.type == ESM::Enchantment::CastOnce) - text += "\n" + environment.mWorld->getStore().gameSettings.search("sItemCastOnce")->str; - else if (enchant->data.type == ESM::Enchantment::WhenStrikes) - text += "\n" + environment.mWorld->getStore().gameSettings.search("sItemCastWhenStrikes")->str; - else if (enchant->data.type == ESM::Enchantment::WhenUsed) - text += "\n" + environment.mWorld->getStore().gameSettings.search("sItemCastWhenUsed")->str; - else if (enchant->data.type == ESM::Enchantment::ConstantEffect) - text += "\n" + environment.mWorld->getStore().gameSettings.search("sItemCastConstant")->str; - - if (enchant->data.type == ESM::Enchantment::WhenStrikes - || enchant->data.type == ESM::Enchantment::WhenUsed) - { - /// \todo store the current enchantment charge somewhere - // info.currentCharge = enchant->data.charge; - //info.totalCharge = enchant->data.charge; - } - } - */ - if (ref->base->enchant != "") - { - const ESM::Enchantment* enchant = store.enchants.search(ref->base->enchant); - info.enchant = enchant; - } + info.enchant = ref->base->enchant; if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 2386cf9a32..aec405f46d 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -50,9 +50,9 @@ DialogueWindow::DialogueWindow(WindowManager& parWindowManager) //An EditBox cannot receive mouse click events, so we use an //invisible widget on top of the editbox to receive them - /// \todo scrolling the dialogue history with the mouse wheel doesn't work using this solution getWidget(eventbox, "EventBox"); eventbox->eventMouseButtonClick += MyGUI::newDelegate(this, &DialogueWindow::onHistoryClicked); + eventbox->eventMouseWheel += MyGUI::newDelegate(this, &DialogueWindow::onMouseWheel); //Topics list getWidget(topicsList, "TopicsList"); @@ -88,6 +88,14 @@ void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender) } } +void DialogueWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel) +{ + if (history->getVScrollPosition() - _rel*0.3 < 0) + history->setVScrollPosition(0); + else + history->setVScrollPosition(history->getVScrollPosition() - _rel*0.3); +} + void DialogueWindow::open() { topicsList->removeAllItems(); diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp index 61e8c124c5..5921ca57a2 100644 --- a/apps/openmw/mwgui/dialogue.hpp +++ b/apps/openmw/mwgui/dialogue.hpp @@ -45,6 +45,7 @@ namespace MWGui void onSelectTopic(MyGUI::ListBox* _sender, size_t _index); void onByeClicked(MyGUI::Widget* _sender); void onHistoryClicked(MyGUI::Widget* _sender); + void onMouseWheel(MyGUI::Widget* _sender, int _rel); private: void updateOptions(); diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index ef30b88d7c..f5b140ec1c 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -1,7 +1,10 @@ #include "tooltips.hpp" -#include "window_manager.hpp" +#include "window_manager.hpp" +#include "widgets.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/world.hpp" +#include "../mwbase/environment.hpp" #include @@ -177,6 +180,21 @@ IntSize ToolTips::createToolTip(const ToolTipInfo& info) if (text.size() > 0 && text[0] == '\n') text.erase(0, 1); + const ESM::Enchantment* enchant; + const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); + if (info.enchant != "") + { + enchant = store.enchants.search(info.enchant); + if (enchant->data.type == ESM::Enchantment::CastOnce) + text += "\n" + store.gameSettings.search("sItemCastOnce")->str; + else if (enchant->data.type == ESM::Enchantment::WhenStrikes) + text += "\n" + store.gameSettings.search("sItemCastWhenStrikes")->str; + else if (enchant->data.type == ESM::Enchantment::WhenUsed) + text += "\n" + store.gameSettings.search("sItemCastWhenUsed")->str; + else if (enchant->data.type == ESM::Enchantment::ConstantEffect) + text += "\n" + store.gameSettings.search("sItemCastConstant")->str; + } + // this the maximum width of the tooltip before it starts word-wrapping setCoord(0, 0, 300, 300); @@ -207,13 +225,55 @@ IntSize ToolTips::createToolTip(const ToolTipInfo& info) IntSize totalSize = IntSize( std::max(textSize.width, captionSize.width + ((image != "") ? imageCaptionHPadding : 0)), ((text != "") ? textSize.height + imageCaptionVPadding : 0) + captionHeight ); - if (image != "") + if (info.enchant != "") { - ImageBox* imageWidget = mDynamicToolTipBox->createWidget("ImageBox", - IntCoord((totalSize.width - captionSize.width - imageCaptionHPadding)/2, 0, imageSize, imageSize), - Align::Left | Align::Top, "ToolTipImage"); - imageWidget->setImageTexture(realImage); - imageWidget->setPosition (imageWidget->getPosition() + padding); + Widget* enchantArea = mDynamicToolTipBox->createWidget("", + IntCoord(0, totalSize.height, 300, 300-totalSize.height), + Align::Stretch, "ToolTipEnchantArea"); + + IntCoord coord(0, 6, totalSize.width, 24); + + Widgets::MWEnchantmentPtr enchantWidget = enchantArea->createWidget + ("MW_StatName", coord, Align::Default, "ToolTipEnchantWidget"); + enchantWidget->setWindowManager(mWindowManager); + enchantWidget->setEnchantmentId(info.enchant); + + std::vector enchantEffectItems; + enchantWidget->createEffectWidgets(enchantEffectItems, enchantArea, coord, true, (enchant->data.type == ESM::Enchantment::ConstantEffect)); + totalSize.height += coord.top-6; + totalSize.width = std::max(totalSize.width, coord.width); + + if (enchant->data.type == ESM::Enchantment::WhenStrikes + || enchant->data.type == ESM::Enchantment::WhenUsed) + { + /// \todo store the current enchantment charge somewhere + int charge = enchant->data.charge; + + const int chargeWidth = 204; + + TextBox* chargeText = enchantArea->createWidget("SandText", IntCoord(0, 0, 10, 18), Align::Default, "ToolTipEnchantChargeText"); + chargeText->setCaption(store.gameSettings.search("sCharges")->str); + chargeText->setProperty("Static", "true"); + const int chargeTextWidth = chargeText->getTextSize().width + 5; + + const int chargeAndTextWidth = chargeWidth + chargeTextWidth; + chargeText->setCoord((totalSize.width - chargeAndTextWidth)/2, coord.top+6, chargeTextWidth, 18); + + IntCoord chargeCoord; + if (totalSize.width < chargeWidth) + { + totalSize.width = chargeWidth; + chargeCoord = IntCoord(0, coord.top+6, chargeWidth, 18); + } + else + { + chargeCoord = IntCoord((totalSize.width - chargeAndTextWidth)/2 + chargeTextWidth, coord.top+6, chargeWidth, 18); + } + Widgets::MWDynamicStatPtr chargeWidget = enchantArea->createWidget + ("MW_ChargeBar", chargeCoord, Align::Default, "ToolTipEnchantCharge"); + chargeWidget->setValue(charge, charge); + totalSize.height += 24; + } } captionWidget->setCoord( (totalSize.width - captionSize.width)/2 + imageSize, @@ -224,6 +284,15 @@ IntSize ToolTips::createToolTip(const ToolTipInfo& info) captionWidget->setPosition (captionWidget->getPosition() + padding); textWidget->setPosition (textWidget->getPosition() + IntPoint(0, padding.top)); // only apply vertical padding, the horizontal works automatically due to Align::HCenter + if (image != "") + { + ImageBox* imageWidget = mDynamicToolTipBox->createWidget("ImageBox", + IntCoord((totalSize.width - captionSize.width - imageCaptionHPadding)/2, 0, imageSize, imageSize), + Align::Left | Align::Top, "ToolTipImage"); + imageWidget->setImageTexture(realImage); + imageWidget->setPosition (imageWidget->getPosition() + padding); + } + totalSize += IntSize(padding.left*2, padding.top*2); return totalSize; diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index c00faba869..fafe471a57 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -14,7 +14,6 @@ namespace MWGui { public: ToolTipInfo() : - enchant(0), effects(0) { }; @@ -24,7 +23,7 @@ namespace MWGui std::string icon; // enchantment (for cloth, armor, weapons) - const ESM::Enchantment* enchant; + std::string enchant; // effects (for potions, ingredients) const ESM::EffectList* effects; diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 58cfee991b..769220f7bb 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -238,6 +238,7 @@ void MWSpell::createEffectWidgets(std::vector &effects, MyGUI: effect->setSpellEffect(*it); effects.push_back(effect); coord.top += effect->getHeight(); + coord.width = std::max(coord.width, effect->getRequestedWidth()); } } @@ -278,22 +279,49 @@ void MWEnchantment::setEnchantmentId(const std::string &enchantId) updateWidgets(); } -void MWEnchantment::createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord) +void MWEnchantment::createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, bool center, bool constant) { const ESMS::ESMStore &store = mWindowManager->getStore(); const ESM::Enchantment *enchant = store.enchants.search(id); MYGUI_ASSERT(enchant, "enchantment with id '" << id << "' not found"); + // We don't know the width of all the elements beforehand, so we do it in + // 2 steps: first, create all widgets and check their width MWSpellEffectPtr effect = nullptr; std::vector::const_iterator end = enchant->effects.list.end(); + int maxwidth = coord.width; for (std::vector::const_iterator it = enchant->effects.list.begin(); it != end; ++it) { effect = creator->createWidget("MW_EffectImage", coord, MyGUI::Align::Default); effect->setWindowManager(mWindowManager); effect->setSpellEffect(*it); + effect->setConstant(constant); effects.push_back(effect); + + if (effect->getRequestedWidth() > maxwidth) + maxwidth = effect->getRequestedWidth(); + coord.top += effect->getHeight(); } + + // then adjust the size for all widgets + for (std::vector::iterator it = effects.begin(); it != effects.end(); ++it) + { + effect = static_cast(*it); + bool needcenter = center && (maxwidth > effect->getRequestedWidth()); + int diff = maxwidth - effect->getRequestedWidth(); + if (needcenter) + { + effect->setCoord(diff/2, effect->getCoord().top, effect->getRequestedWidth(), effect->getCoord().height); + } + else + { + effect->setCoord(0, effect->getCoord().top, effect->getRequestedWidth(), effect->getCoord().height); + } + } + + // inform the parent about width + coord.width = maxwidth; } void MWEnchantment::updateWidgets() @@ -315,6 +343,8 @@ MWSpellEffect::MWSpellEffect() : mWindowManager(nullptr) , imageWidget(nullptr) , textWidget(nullptr) + , mRequestedWidth(0) + , mIsConstant(0) { } @@ -366,7 +396,7 @@ void MWSpellEffect::updateWidgets() spellLine += " " + boost::lexical_cast(effect.magnMin) + " " + ((effect.magnMin == 1) ? pt : pts); else { - spellLine += " " + boost::lexical_cast(effect.magnMin) + to + boost::lexical_cast(effect.magnMin) + " " + pts; + spellLine += " " + boost::lexical_cast(effect.magnMin) + to + boost::lexical_cast(effect.magnMax) + " " + pts; } } @@ -388,6 +418,7 @@ void MWSpellEffect::updateWidgets() } static_cast(textWidget)->setCaption(spellLine); + mRequestedWidth = textWidget->getTextSize().width + 24; } else static_cast(textWidget)->setCaption(""); diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index 8ac27795d5..b4915ac6aa 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -119,6 +119,14 @@ namespace MWGui void setWindowManager(WindowManager* parWindowManager) { mWindowManager = parWindowManager; } void setSpellId(const std::string &id); + + /** + * @param vector to store the created effect widgets + * @param parent widget + * @param coordinates to use, will be expanded if more space is needed + * @param spell category, if this is 0, this means the spell effects are permanent and won't display e.g. duration + * @param center the effect widgets horizontally + */ void createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, const int category); const std::string &getSpellId() const { return id; } @@ -147,7 +155,15 @@ namespace MWGui void setWindowManager(WindowManager* parWindowManager) { mWindowManager = parWindowManager; } void setEnchantmentId(const std::string &enchantId); - void createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord); + + /** + * @param vector to store the created effect widgets + * @param parent widget + * @param coordinates to use, will be expanded if more space is needed + * @param center the effect widgets horizontally + * @param are the effects of this enchantment constant? + */ + void createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, bool center, bool constant); const std::string &getSpellId() const { return id; } @@ -180,6 +196,8 @@ namespace MWGui const SpellEffectValue &getSpellEffect() const { return effect; } + int getRequestedWidth() const { return mRequestedWidth; } + protected: virtual ~MWSpellEffect(); @@ -194,6 +212,7 @@ namespace MWGui bool mIsConstant; // constant effect MyGUI::ImageBox* imageWidget; MyGUI::TextBox* textWidget; + int mRequestedWidth; }; typedef MWSpellEffect* MWSpellEffectPtr; diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index a3e44f65bf..ccf558de50 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -104,6 +104,7 @@ WindowManager::WindowManager( MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); diff --git a/files/mygui/openmw_text.skin.xml b/files/mygui/openmw_text.skin.xml index 9f87c93b3c..36d97e1538 100644 --- a/files/mygui/openmw_text.skin.xml +++ b/files/mygui/openmw_text.skin.xml @@ -93,6 +93,11 @@ + + + + + From b82c39c8be6976e3386b413e4a49298dd6e49e3a Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 30 Apr 2012 01:08:10 +0200 Subject: [PATCH 28/30] renamed Widgets::MWEnchantment to Widgets::MWEffectList so it can be reused for potion effects --- apps/openmw/mwclass/potion.cpp | 2 ++ apps/openmw/mwgui/tooltips.cpp | 2 +- apps/openmw/mwgui/widgets.cpp | 14 +++++++------- apps/openmw/mwgui/widgets.hpp | 10 +++++----- apps/openmw/mwgui/window_manager.cpp | 2 +- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 12ce622ee1..edf82cee45 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -124,6 +124,8 @@ namespace MWClass text += "\n" + store.gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); text += MWGui::ToolTips::getValueString(ref->base->data.value, store.gameSettings.search("sValue")->str); + ESM::EffectList list = ref->base->effects; + if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); text += MWGui::ToolTips::getMiscString(ref->base->script, "Script"); diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index f5b140ec1c..0cab26b2c7 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -233,7 +233,7 @@ IntSize ToolTips::createToolTip(const ToolTipInfo& info) IntCoord coord(0, 6, totalSize.width, 24); - Widgets::MWEnchantmentPtr enchantWidget = enchantArea->createWidget + Widgets::MWEffectListPtr enchantWidget = enchantArea->createWidget ("MW_StatName", coord, Align::Default, "ToolTipEnchantWidget"); enchantWidget->setWindowManager(mWindowManager); enchantWidget->setEnchantmentId(info.enchant); diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index 769220f7bb..f327a9c1ec 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -266,20 +266,20 @@ MWSpell::~MWSpell() { } -/* MWEnchantment */ +/* MWEffectList */ -MWEnchantment::MWEnchantment() +MWEffectList::MWEffectList() : mWindowManager(nullptr) { } -void MWEnchantment::setEnchantmentId(const std::string &enchantId) +void MWEffectList::setEnchantmentId(const std::string &enchantId) { id = enchantId; updateWidgets(); } -void MWEnchantment::createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, bool center, bool constant) +void MWEffectList::createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, bool center, bool constant) { const ESMS::ESMStore &store = mWindowManager->getStore(); const ESM::Enchantment *enchant = store.enchants.search(id); @@ -324,16 +324,16 @@ void MWEnchantment::createEffectWidgets(std::vector &effects, coord.width = maxwidth; } -void MWEnchantment::updateWidgets() +void MWEffectList::updateWidgets() { } -void MWEnchantment::initialiseOverride() +void MWEffectList::initialiseOverride() { Base::initialiseOverride(); } -MWEnchantment::~MWEnchantment() +MWEffectList::~MWEffectList() { } diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index b4915ac6aa..51ad516786 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -145,11 +145,11 @@ namespace MWGui }; typedef MWSpell* MWSpellPtr; - class MYGUI_EXPORT MWEnchantment : public Widget + class MYGUI_EXPORT MWEffectList : public Widget { - MYGUI_RTTI_DERIVED( MWEnchantment ); + MYGUI_RTTI_DERIVED( MWEffectList ); public: - MWEnchantment(); + MWEffectList(); typedef MWMechanics::Stat EnchantmentValue; @@ -168,7 +168,7 @@ namespace MWGui const std::string &getSpellId() const { return id; } protected: - virtual ~MWEnchantment(); + virtual ~MWEffectList(); virtual void initialiseOverride(); @@ -178,7 +178,7 @@ namespace MWGui WindowManager* mWindowManager; std::string id; }; - typedef MWEnchantment* MWEnchantmentPtr; + typedef MWEffectList* MWEffectListPtr; class MYGUI_EXPORT MWSpellEffect : public Widget { diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index ccf558de50..0f2df53e1a 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -104,7 +104,7 @@ WindowManager::WindowManager( MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); From 22f524f8d52408bbca31af711b745889ef32ad1f Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 30 Apr 2012 01:53:22 +0200 Subject: [PATCH 29/30] potion effects in tooltip --- apps/openmw/mwclass/potion.cpp | 2 +- apps/openmw/mwgui/birth.cpp | 2 +- apps/openmw/mwgui/tooltips.cpp | 30 ++++++++++++++- apps/openmw/mwgui/widgets.cpp | 70 ++++++++++++++++++++-------------- apps/openmw/mwgui/widgets.hpp | 20 ++++++---- 5 files changed, 84 insertions(+), 40 deletions(-) diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index edf82cee45..07e7663b38 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -124,7 +124,7 @@ namespace MWClass text += "\n" + store.gameSettings.search("sWeight")->str + ": " + MWGui::ToolTips::toString(ref->base->data.weight); text += MWGui::ToolTips::getValueString(ref->base->data.value, store.gameSettings.search("sValue")->str); - ESM::EffectList list = ref->base->effects; + info.effects = &ref->base->effects; if (MWBase::Environment::get().getWindowManager()->getFullHelp()) { text += MWGui::ToolTips::getMiscString(ref->ref.owner, "Owner"); diff --git a/apps/openmw/mwgui/birth.cpp b/apps/openmw/mwgui/birth.cpp index 046017204f..cb15eaf15b 100644 --- a/apps/openmw/mwgui/birth.cpp +++ b/apps/openmw/mwgui/birth.cpp @@ -202,7 +202,7 @@ void BirthDialog::updateSpells() MyGUI::IntCoord spellCoord = coord; spellCoord.height = 24; // TODO: This should be fetched from the skin somehow, or perhaps a widget in the layout as a template? - spellWidget->createEffectWidgets(spellItems, spellArea, spellCoord, category); + spellWidget->createEffectWidgets(spellItems, spellArea, spellCoord, (category == 0) ? MWEffectList::EF_Constant : 0); coord.top = spellCoord.top; ++i; diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 0cab26b2c7..90b5baa679 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -225,6 +225,31 @@ IntSize ToolTips::createToolTip(const ToolTipInfo& info) IntSize totalSize = IntSize( std::max(textSize.width, captionSize.width + ((image != "") ? imageCaptionHPadding : 0)), ((text != "") ? textSize.height + imageCaptionVPadding : 0) + captionHeight ); + if (info.effects != 0) + { + Widget* effectArea = mDynamicToolTipBox->createWidget("", + IntCoord(0, totalSize.height, 300, 300-totalSize.height), + Align::Stretch, "ToolTipEffectArea"); + + IntCoord coord(0, 6, totalSize.width, 24); + + /** + * \todo + * the various potion effects should appear in the tooltip depending if the player + * has enough skill in alchemy to know about the effects of this potion. + */ + + Widgets::MWEffectListPtr effectsWidget = effectArea->createWidget + ("MW_StatName", coord, Align::Default, "ToolTipEffectsWidget"); + effectsWidget->setWindowManager(mWindowManager); + effectsWidget->setEffectList(info.effects); + + std::vector effectItems; + effectsWidget->createEffectWidgets(effectItems, effectArea, coord, true, Widgets::MWEffectList::EF_Potion); + totalSize.height += coord.top-6; + totalSize.width = std::max(totalSize.width, coord.width); + } + if (info.enchant != "") { Widget* enchantArea = mDynamicToolTipBox->createWidget("", @@ -236,10 +261,11 @@ IntSize ToolTips::createToolTip(const ToolTipInfo& info) Widgets::MWEffectListPtr enchantWidget = enchantArea->createWidget ("MW_StatName", coord, Align::Default, "ToolTipEnchantWidget"); enchantWidget->setWindowManager(mWindowManager); - enchantWidget->setEnchantmentId(info.enchant); + enchantWidget->setEffectList(&enchant->effects); std::vector enchantEffectItems; - enchantWidget->createEffectWidgets(enchantEffectItems, enchantArea, coord, true, (enchant->data.type == ESM::Enchantment::ConstantEffect)); + int flag = (enchant->data.type == ESM::Enchantment::ConstantEffect) ? Widgets::MWEffectList::EF_Constant : 0; + enchantWidget->createEffectWidgets(enchantEffectItems, enchantArea, coord, true, flag); totalSize.height += coord.top-6; totalSize.width = std::max(totalSize.width, coord.width); diff --git a/apps/openmw/mwgui/widgets.cpp b/apps/openmw/mwgui/widgets.cpp index f327a9c1ec..2f5af64736 100644 --- a/apps/openmw/mwgui/widgets.cpp +++ b/apps/openmw/mwgui/widgets.cpp @@ -222,7 +222,7 @@ void MWSpell::setSpellId(const std::string &spellId) updateWidgets(); } -void MWSpell::createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, const int category) +void MWSpell::createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, int flags) { const ESMS::ESMStore &store = mWindowManager->getStore(); const ESM::Spell *spell = store.spells.search(id); @@ -234,7 +234,7 @@ void MWSpell::createEffectWidgets(std::vector &effects, MyGUI: { effect = creator->createWidget("MW_EffectImage", coord, MyGUI::Align::Default); effect->setWindowManager(mWindowManager); - effect->setConstant(category == 0); + effect->setFlags(flags); effect->setSpellEffect(*it); effects.push_back(effect); coord.top += effect->getHeight(); @@ -270,32 +270,29 @@ MWSpell::~MWSpell() MWEffectList::MWEffectList() : mWindowManager(nullptr) + , mEffectList(0) { } -void MWEffectList::setEnchantmentId(const std::string &enchantId) +void MWEffectList::setEffectList(const ESM::EffectList* list) { - id = enchantId; + mEffectList = list; updateWidgets(); } -void MWEffectList::createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, bool center, bool constant) +void MWEffectList::createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, bool center, int flags) { - const ESMS::ESMStore &store = mWindowManager->getStore(); - const ESM::Enchantment *enchant = store.enchants.search(id); - MYGUI_ASSERT(enchant, "enchantment with id '" << id << "' not found"); - // We don't know the width of all the elements beforehand, so we do it in // 2 steps: first, create all widgets and check their width MWSpellEffectPtr effect = nullptr; - std::vector::const_iterator end = enchant->effects.list.end(); + std::vector::const_iterator end = mEffectList->list.end(); int maxwidth = coord.width; - for (std::vector::const_iterator it = enchant->effects.list.begin(); it != end; ++it) + for (std::vector::const_iterator it = mEffectList->list.begin(); it != end; ++it) { effect = creator->createWidget("MW_EffectImage", coord, MyGUI::Align::Default); effect->setWindowManager(mWindowManager); + effect->setFlags(flags); effect->setSpellEffect(*it); - effect->setConstant(constant); effects.push_back(effect); if (effect->getRequestedWidth() > maxwidth) @@ -344,7 +341,7 @@ MWSpellEffect::MWSpellEffect() , imageWidget(nullptr) , textWidget(nullptr) , mRequestedWidth(0) - , mIsConstant(0) + , mFlags(0) { } @@ -359,6 +356,18 @@ void MWSpellEffect::updateWidgets() if (!mWindowManager) return; + // lists effects that have no magnitude (e.g. invisiblity) + /// \todo this list is probably incomplete + std::vector effectsWithoutMagnitude; + effectsWithoutMagnitude.push_back("sEffectInvisibility"); + effectsWithoutMagnitude.push_back("sEffectStuntedMagicka"); + effectsWithoutMagnitude.push_back("sEffectParalyze"); + + // lists effects that have no duration (e.g. open lock) + /// \todo this list is probably incomplete + std::vector effectsWithoutDuration; + effectsWithoutDuration.push_back("sEffectOpen"); + const ESMS::ESMStore &store = mWindowManager->getStore(); const ESM::MagicEffect *magicEffect = store.magicEffects.search(effect.effectID); if (textWidget) @@ -371,7 +380,8 @@ void MWSpellEffect::updateWidgets() std::string sec = " " + mWindowManager->getGameSettingString("ssecond", ""); std::string secs = " " + mWindowManager->getGameSettingString("sseconds", ""); - std::string spellLine = effectIDToString(effect.effectID); + std::string effectIDStr = effectIDToString(effect.effectID); + std::string spellLine = mWindowManager->getGameSettingString(effectIDStr, ""); if (effect.skill >= 0 && effect.skill < ESM::Skill::Length) { spellLine += " " + mWindowManager->getGameSettingString(ESM::Skill::sSkillNameIds[effect.skill], ""); @@ -390,7 +400,9 @@ void MWSpellEffect::updateWidgets() }; spellLine += " " + mWindowManager->getGameSettingString(attributes[effect.attribute], ""); } - if (effect.magnMin >= 0 || effect.magnMax >= 0) + + bool hasMagnitude = (std::find(effectsWithoutMagnitude.begin(), effectsWithoutMagnitude.end(), effectIDStr) == effectsWithoutMagnitude.end()); + if ((effect.magnMin >= 0 || effect.magnMax >= 0) && hasMagnitude) { if (effect.magnMin == effect.magnMax) spellLine += " " + boost::lexical_cast(effect.magnMin) + " " + ((effect.magnMin == 1) ? pt : pts); @@ -401,20 +413,25 @@ void MWSpellEffect::updateWidgets() } // constant effects have no duration and no target - if (!mIsConstant) + if (!(mFlags & MWEffectList::EF_Constant)) { - if (effect.duration >= 0) + bool hasDuration = (std::find(effectsWithoutDuration.begin(), effectsWithoutDuration.end(), effectIDStr) == effectsWithoutDuration.end()); + if (effect.duration >= 0 && hasDuration) { spellLine += " " + mWindowManager->getGameSettingString("sfor", "") + " " + boost::lexical_cast(effect.duration) + ((effect.duration == 1) ? sec : secs); } - std::string on = mWindowManager->getGameSettingString("sonword", ""); - if (effect.range == ESM::RT_Self) - spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeSelf", ""); - else if (effect.range == ESM::RT_Touch) - spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTouch", ""); - else if (effect.range == ESM::RT_Target) - spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTarget", ""); + // potions have no target + if (!(mFlags & MWEffectList::EF_Potion)) + { + std::string on = mWindowManager->getGameSettingString("sonword", ""); + if (effect.range == ESM::RT_Self) + spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeSelf", ""); + else if (effect.range == ESM::RT_Touch) + spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTouch", ""); + else if (effect.range == ESM::RT_Target) + spellLine += " " + on + " " + mWindowManager->getGameSettingString("sRangeTarget", ""); + } } static_cast(textWidget)->setCaption(spellLine); @@ -574,11 +591,8 @@ std::string MWSpellEffect::effectIDToString(const short effectID) names[30] ="sEffectWeaknesstoShock"; assert(names.find(effectID) != names.end() && "Unimplemented effect type"); - std::string res = mWindowManager->getGameSettingString(names[effectID], ""); - if (res == "") - std::cout << "Warning: Unknown effect name " << names[effectID] << std::endl; - return res; + return names[effectID]; } MWSpellEffect::~MWSpellEffect() diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index 51ad516786..a1caa3c946 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -153,19 +153,23 @@ namespace MWGui typedef MWMechanics::Stat EnchantmentValue; + enum EffectFlags + { + EF_Potion = 0x01, // potions have no target (target is always the player) + EF_Constant = 0x02 // constant effect means that duration will not be displayed + }; + void setWindowManager(WindowManager* parWindowManager) { mWindowManager = parWindowManager; } - void setEnchantmentId(const std::string &enchantId); + void setEffectList(const ESM::EffectList* list); /** * @param vector to store the created effect widgets * @param parent widget * @param coordinates to use, will be expanded if more space is needed * @param center the effect widgets horizontally - * @param are the effects of this enchantment constant? + * @param various flags, see MWEffectList::EffectFlags */ - void createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, bool center, bool constant); - - const std::string &getSpellId() const { return id; } + void createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, bool center, int flags); protected: virtual ~MWEffectList(); @@ -176,7 +180,7 @@ namespace MWGui void updateWidgets(); WindowManager* mWindowManager; - std::string id; + const ESM::EffectList* mEffectList; }; typedef MWEffectList* MWEffectListPtr; @@ -190,7 +194,7 @@ namespace MWGui void setWindowManager(WindowManager* parWindowManager) { mWindowManager = parWindowManager; } void setSpellEffect(SpellEffectValue value); - void setConstant(bool constant) { mIsConstant = constant; } + void setFlags(int flags) { mFlags = flags; } std::string effectIDToString(const short effectID); @@ -209,7 +213,7 @@ namespace MWGui WindowManager* mWindowManager; SpellEffectValue effect; - bool mIsConstant; // constant effect + int mFlags; MyGUI::ImageBox* imageWidget; MyGUI::TextBox* textWidget; int mRequestedWidth; From 2f0a69160cffefdba93a70eb9aa5f818e0237643 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 30 Apr 2012 02:10:55 +0200 Subject: [PATCH 30/30] small fix --- apps/openmw/mwgui/widgets.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/widgets.hpp b/apps/openmw/mwgui/widgets.hpp index a1caa3c946..c0e62533d8 100644 --- a/apps/openmw/mwgui/widgets.hpp +++ b/apps/openmw/mwgui/widgets.hpp @@ -125,9 +125,9 @@ namespace MWGui * @param parent widget * @param coordinates to use, will be expanded if more space is needed * @param spell category, if this is 0, this means the spell effects are permanent and won't display e.g. duration - * @param center the effect widgets horizontally + * @param various flags, see MWEffectList::EffectFlags */ - void createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, const int category); + void createEffectWidgets(std::vector &effects, MyGUI::WidgetPtr creator, MyGUI::IntCoord &coord, int flags); const std::string &getSpellId() const { return id; }