From b309d245c5db4fa12832292572033fc092d98b1c Mon Sep 17 00:00:00 2001 From: gugus Date: Sun, 15 Apr 2012 17:52:39 +0200 Subject: [PATCH 001/118] cleaning up hircine work --- apps/openmw/CMakeLists.txt | 4 +- apps/openmw/mwclass/apparatus.cpp | 10 + apps/openmw/mwclass/apparatus.hpp | 3 + apps/openmw/mwclass/armor.cpp | 8 + apps/openmw/mwclass/armor.hpp | 3 + apps/openmw/mwclass/book.cpp | 8 + apps/openmw/mwclass/book.hpp | 3 + apps/openmw/mwclass/clothing.cpp | 8 + apps/openmw/mwclass/clothing.hpp | 3 + apps/openmw/mwclass/container.cpp | 7 +- apps/openmw/mwclass/ingredient.cpp | 8 + apps/openmw/mwclass/ingredient.hpp | 3 + apps/openmw/mwclass/light.cpp | 8 + apps/openmw/mwclass/light.hpp | 3 + apps/openmw/mwclass/lockpick.cpp | 8 + apps/openmw/mwclass/lockpick.hpp | 3 + apps/openmw/mwclass/misc.cpp | 8 + apps/openmw/mwclass/misc.hpp | 3 + apps/openmw/mwclass/potion.cpp | 9 + apps/openmw/mwclass/potion.hpp | 3 + apps/openmw/mwclass/probe.cpp | 8 + apps/openmw/mwclass/probe.hpp | 3 + apps/openmw/mwclass/repair.cpp | 8 + apps/openmw/mwclass/repair.hpp | 3 + apps/openmw/mwclass/weapon.cpp | 9 + apps/openmw/mwclass/weapon.hpp | 5 + apps/openmw/mwgui/container.cpp | 191 ++++++++++++++++++ apps/openmw/mwgui/container.hpp | 62 ++++++ apps/openmw/mwgui/window_manager.cpp | 4 +- apps/openmw/mwgui/window_manager.hpp | 6 +- apps/openmw/mwworld/actionopen.cpp | 21 ++ apps/openmw/mwworld/actionopen.hpp | 22 ++ apps/openmw/mwworld/containerstore.cpp | 30 +++ apps/openmw/mwworld/containerstore.hpp | 2 + files/mygui/CMakeLists.txt | 1 + .../mygui/openmw_container_window_layout.xml | 24 +++ 36 files changed, 506 insertions(+), 6 deletions(-) create mode 100644 apps/openmw/mwgui/container.cpp create mode 100644 apps/openmw/mwgui/container.hpp create mode 100644 apps/openmw/mwworld/actionopen.cpp create mode 100644 apps/openmw/mwworld/actionopen.hpp create mode 100644 files/mygui/openmw_container_window_layout.xml diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 2630098f5..6fb8a24c3 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -24,7 +24,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 + dialogue_history window_base stats_window messagebox journalwindow charactercreation container ) add_openmw_dir (mwdialogue @@ -45,7 +45,7 @@ add_openmw_dir (mwsound add_openmw_dir (mwworld refdata world physicssystem scene environment globals class action nullaction actionteleport containerstore actiontalk actiontake manualref player cellfunctors - cells localscripts customdata weather inventorystore ptr + cells localscripts customdata weather inventorystore ptr actionopen ) add_openmw_dir (mwclass diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index e95fb572f..8ac589db6 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -86,4 +86,14 @@ namespace MWClass { return std::string("Item Apparatus Down"); } + + + std::string Apparatus::getInventoryIcon (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->icon; + } + } diff --git a/apps/openmw/mwclass/apparatus.hpp b/apps/openmw/mwclass/apparatus.hpp index c0849e1fe..2d1175951 100644 --- a/apps/openmw/mwclass/apparatus.hpp +++ b/apps/openmw/mwclass/apparatus.hpp @@ -32,6 +32,9 @@ namespace MWClass virtual std::string getDownSoundId (const MWWorld::Ptr& ptr) const; ///< Return the put down sound Id + + virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; + ///< Return name of inventory icon. }; } diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index e1c2734f0..597094a45 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -188,4 +188,12 @@ namespace MWClass else return std::string("Item Armor Heavy Down"); } + + std::string Armor::getInventoryIcon (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->icon; + } } diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index 2b66ff828..aada97eec 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -47,6 +47,9 @@ namespace MWClass virtual std::string getDownSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const; ///< Return the put down sound Id + + virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; + ///< Return name of inventory icon. }; } diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 0a81ebafb..f22191f26 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -88,4 +88,12 @@ namespace MWClass { return std::string("Item Book Down"); } + std::string Book::getInventoryIcon (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->icon; + } + } diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp index ccbbfb4b2..2d37bffea 100644 --- a/apps/openmw/mwclass/book.hpp +++ b/apps/openmw/mwclass/book.hpp @@ -32,6 +32,9 @@ namespace MWClass virtual std::string getDownSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const; ///< Return the put down sound Id + + virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; + ///< Return name of inventory icon. }; } diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 4fe19ada4..176ab26dc 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -153,4 +153,12 @@ namespace MWClass } return std::string("Item Clothes Down"); } + + std::string Clothing::getInventoryIcon (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->icon; + } } diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index 171b06246..b7084a4d5 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -41,6 +41,9 @@ namespace MWClass virtual std::string getDownSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const; ///< Return the put down sound Id + + virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; + ///< Return name of inventory icon. }; } diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index c58a25c03..dd5f3add3 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -12,6 +12,7 @@ #include "../mwworld/environment.hpp" #include "../mwrender/objects.hpp" +#include "../mwworld/actionopen.hpp" #include "../mwsound/soundmanager.hpp" @@ -81,6 +82,7 @@ namespace MWClass const std::string lockedSound = "LockedChest"; const std::string trapActivationSound = "Disarm Trap Fail"; + if (ptr.getCellRef().lockLevel>0) { // TODO check for key @@ -94,7 +96,8 @@ namespace MWClass if(ptr.getCellRef().trap.empty()) { // Not trapped, Inventory GUI goes here - return boost::shared_ptr (new MWWorld::NullAction); + //return boost::shared_ptr (new MWWorld::NullAction); + return boost::shared_ptr (new MWWorld::ActionOpen(ptr)); } else { @@ -137,4 +140,6 @@ namespace MWClass registerClass (typeid (ESM::Container).name(), instance); } + + } diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 1a7edf632..7b96817e9 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -84,4 +84,12 @@ namespace MWClass { return std::string("Item Ingredient Down"); } + + std::string Ingredient::getInventoryIcon (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->icon; + } } diff --git a/apps/openmw/mwclass/ingredient.hpp b/apps/openmw/mwclass/ingredient.hpp index 9463dcf8d..f79534868 100644 --- a/apps/openmw/mwclass/ingredient.hpp +++ b/apps/openmw/mwclass/ingredient.hpp @@ -32,6 +32,9 @@ namespace MWClass virtual std::string getDownSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const; ///< Return the put down sound Id + + virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; + ///< Return name of inventory icon. }; } diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index e2e63a89b..50fc39023 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -126,4 +126,12 @@ namespace MWClass { return std::string("Item Misc Down"); } + + std::string Light::getInventoryIcon (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->icon; + } } diff --git a/apps/openmw/mwclass/light.hpp b/apps/openmw/mwclass/light.hpp index 46a4d60ba..bd04401ce 100644 --- a/apps/openmw/mwclass/light.hpp +++ b/apps/openmw/mwclass/light.hpp @@ -41,6 +41,9 @@ namespace MWClass virtual std::string getDownSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const; ///< Return the put down sound Id + + virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; + ///< Return name of inventory icon. }; } diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 3dda2f4af..49300eb09 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -97,4 +97,12 @@ namespace MWClass { return std::string("Item Lockpick Down"); } + + std::string Lockpick::getInventoryIcon (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->icon; + } } diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp index 0c9189c54..4d5938a69 100644 --- a/apps/openmw/mwclass/lockpick.hpp +++ b/apps/openmw/mwclass/lockpick.hpp @@ -36,6 +36,9 @@ namespace MWClass virtual std::string getDownSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const; ///< Return the put down sound Id + + virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; + ///< Return name of inventory icon. }; } diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 864fc1e38..cd06d1073 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -100,4 +100,12 @@ namespace MWClass } return std::string("Item Misc Down"); } + + std::string Miscellaneous::getInventoryIcon (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->icon; + } } diff --git a/apps/openmw/mwclass/misc.hpp b/apps/openmw/mwclass/misc.hpp index b07964f99..39d771dc9 100644 --- a/apps/openmw/mwclass/misc.hpp +++ b/apps/openmw/mwclass/misc.hpp @@ -32,6 +32,9 @@ namespace MWClass virtual std::string getDownSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const; ///< Return the put down sound Id + + virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; + ///< Return name of inventory icon. }; } diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 4ab374590..a50d19736 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -86,4 +86,13 @@ namespace MWClass { return std::string("Item Potion Down"); } + + + std::string Potion::getInventoryIcon (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->icon; + } } diff --git a/apps/openmw/mwclass/potion.hpp b/apps/openmw/mwclass/potion.hpp index be9e713fb..5eb9a3e46 100644 --- a/apps/openmw/mwclass/potion.hpp +++ b/apps/openmw/mwclass/potion.hpp @@ -32,6 +32,9 @@ namespace MWClass virtual std::string getDownSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const; ///< Return the put down sound Id + + virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; + ///< Return name of inventory icon. }; } diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 4b4d79a73..3f8dc2a44 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -96,4 +96,12 @@ namespace MWClass { return std::string("Item Probe Down"); } + + std::string Probe::getInventoryIcon (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->icon; + } } diff --git a/apps/openmw/mwclass/probe.hpp b/apps/openmw/mwclass/probe.hpp index 1507d65aa..1d9ce7d86 100644 --- a/apps/openmw/mwclass/probe.hpp +++ b/apps/openmw/mwclass/probe.hpp @@ -36,6 +36,9 @@ namespace MWClass virtual std::string getDownSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const; ///< Return the put down sound Id + + virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; + ///< Return name of inventory icon. }; } diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index 758bf4079..bafb84bca 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -86,4 +86,12 @@ namespace MWClass { return std::string("Item Repair Down"); } + + std::string Repair::getInventoryIcon (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->icon; + } } diff --git a/apps/openmw/mwclass/repair.hpp b/apps/openmw/mwclass/repair.hpp index 17b606f4c..3b8260f9d 100644 --- a/apps/openmw/mwclass/repair.hpp +++ b/apps/openmw/mwclass/repair.hpp @@ -32,6 +32,9 @@ namespace MWClass virtual std::string getDownSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const; ///< Return the put down sound Id + + virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; + ///< Return name of inventory icon. }; } diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 20db0cf38..9d3d40646 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -237,4 +237,13 @@ namespace MWClass return std::string("Item Misc Down"); } + + + std::string Weapon::getInventoryIcon (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->icon; + } } diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index f863c0bfe..31fee9b4b 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -47,6 +47,11 @@ namespace MWClass virtual std::string getDownSoundId (const MWWorld::Ptr& ptr, const MWWorld::Environment& environment) const; ///< Return the put down sound Id + + virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; + ///< Return name of inventory icon. + + }; } diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp new file mode 100644 index 000000000..c09a1bf58 --- /dev/null +++ b/apps/openmw/mwgui/container.cpp @@ -0,0 +1,191 @@ +#include "container.hpp" + +#include +#include +#include "window_manager.hpp" +#include "widgets.hpp" + +#include "../mwworld/environment.hpp" +#include "../mwworld/manualref.hpp" +#include +#include +#include + +#include +#include +#include "../mwclass/container.hpp" +#include "../mwworld/containerstore.hpp" +#include + + +using namespace MWGui; +using namespace Widgets; + + +ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment) + : WindowBase("openmw_container_window_layout.xml", parWindowManager), + mEnvironment(environment) +{ + setText("_Main", "Name of Container"); + setVisible(false); + + getWidget(containerWidget, "Items"); + getWidget(takeButton, "TakeButton"); + getWidget(closeButton, "CloseButton"); + + setText("CloseButton","Close"); + setText("TakeButton","Take All"); + + //ctor +} + +ContainerWindow::~ContainerWindow() +{ + //dtor + + + + +} + +void ContainerWindow::setName(std::string contName) +{ + setText("_Main", contName); +} + + + +void ContainerWindow::open(MWWorld::Ptr& container) +{ + setName(MWWorld::Class::get(container).getName(container)); + //MWWorld::ContainerStore* containerStore = container.getContainerStore(); + + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(container).getContainerStore(container); + + + MWWorld::ManualRef furRef (mWindowManager.getStore(), "fur_cuirass"); + furRef.getPtr().getRefData().setCount (5); + MWWorld::ManualRef bukkitRef (mWindowManager.getStore(), "misc_com_bucket_01"); + MWWorld::ManualRef broomRef (mWindowManager.getStore(), "misc_com_broom_01"); + MWWorld::ManualRef goldRef (mWindowManager.getStore(), "gold_100"); + + containerStore.add(furRef.getPtr()); + containerStore.add(furRef.getPtr()); + containerStore.add(furRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(goldRef.getPtr()); + + + + // ESMS::LiveCellRef *ref = iter->get(); + + + int x = 4; + int y = 4; + int count = 0; + + for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) + { + std::string path = std::string("icons\\"); + + + path += iter.getInventoryIcon(); +// switch (iter.getType()) +// { +// +// case MWWorld::ContainerStore::Type_Potion: +// path += iter->get()->base->icon; +// break; +// case MWWorld::ContainerStore::Type_Apparatus: +// path += iter->get()->base->icon; +// break; +// case MWWorld::ContainerStore::Type_Armor: +// path += iter->get()->base->icon; +// break; +// case MWWorld::ContainerStore::Type_Book: +// path += iter->get()->base->icon; +// break; +// case MWWorld::ContainerStore::Type_Clothing: +// path += iter->get()->base->icon; +// break; +// case MWWorld::ContainerStore::Type_Ingredient: +// path += iter->get()->base->icon; +// break; +// case MWWorld::ContainerStore::Type_Light: +// path += iter->get()->base->icon; +// break; +// case MWWorld::ContainerStore::Type_Lockpick: +// path += iter->get()->base->icon; +// break; +// case MWWorld::ContainerStore::Type_Miscellaneous: +// path += iter->get()->base->icon; +// break; +// case MWWorld::ContainerStore::Type_Probe: +// path += iter->get()->base->icon; +// break; +// case MWWorld::ContainerStore::Type_Repair: +// path += iter->get()->base->icon; +// break; +// case MWWorld::ContainerStore::Type_Weapon: +// path += iter->get()->base->icon; +// break; +// +// +// } + count++; + + if(count % 8 == 0) + { + y += 36; + x = 4; + count = 0; + } + x += 36; + + + MyGUI::ImageBox* image = containerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); + MyGUI::TextBox* text = containerWidget->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); + + if(iter->getRefData().getCount() > 1) + text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); + + + containerWidgets.push_back(image); + + + int pos = path.rfind("."); + path.erase(pos); + path.append(".dds"); + + //std::cout << path << std::endl; + image->setImageTexture(path); + } + + + setVisible(true); +} + +void Update() +{ + +} + diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp new file mode 100644 index 000000000..e027f48fe --- /dev/null +++ b/apps/openmw/mwgui/container.hpp @@ -0,0 +1,62 @@ +#ifndef MGUI_CONTAINER_H +#define MGUI_CONTAINER_H + +#include +#include "../mwclass/container.hpp" +#include +#include +#include +#include +#include "window_base.hpp" +#include "../mwworld/ptr.hpp" +#include "../mwworld/containerstore.hpp" + +namespace MWWorld +{ + class Environment; +} + +namespace MyGUI +{ + class Gui; + class Widget; +} + +namespace MWGui +{ + class WindowManager; +} + + +namespace MWGui +{ + + + class ContainerWindow : public WindowBase + { + public: + ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment); + + + void open(MWWorld::Ptr& container); + void setName(std::string contName); + void Update(); + + virtual ~ContainerWindow(); + protected: + private: + MWWorld::Environment& mEnvironment; + std::vector containerWidgets; + MyGUI::WidgetPtr containerWidget; + + MyGUI::ButtonPtr takeButton; + MyGUI::ButtonPtr closeButton; + + + + + + //MWWorld::Ptr& mContainer; + }; +} +#endif // CONTAINER_H diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index fa6dedc77..741066896 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -6,6 +6,7 @@ #include "dialogue_history.hpp" #include "stats_window.hpp" #include "messagebox.hpp" +#include "container.hpp" #include "../mwmechanics/mechanicsmanager.hpp" #include "../mwinput/inputmanager.hpp" @@ -52,6 +53,7 @@ WindowManager::WindowManager(MWWorld::Environment& environment, mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); dialogueWindow = new DialogueWindow(*this,environment); + containerWindow = new ContainerWindow(*this,environment); // The HUD is always on hud->setVisible(true); @@ -90,7 +92,7 @@ WindowManager::~WindowManager() delete stats; delete mJournal; delete dialogueWindow; - + delete containerWindow; delete mCharGen; cleanupGarbage(); diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 582f438e8..cbe0edad9 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -62,7 +62,7 @@ namespace MWGui class Console; class JournalWindow; class CharacterCreation; - + class ContainerWindow; class TextInputDialog; class InfoBoxDialog; class DialogueWindow; @@ -127,6 +127,8 @@ namespace MWGui MWGui::DialogueWindow* getDialogueWindow() {return dialogueWindow;} + MWGui::ContainerWindow* getContainerWindow() {return containerWindow;} + MyGUI::Gui* getGui() const { return gui; } void wmUpdateFps(float fps, size_t triangleCount, size_t batchCount) @@ -191,7 +193,7 @@ namespace MWGui Console *console; JournalWindow* mJournal; DialogueWindow *dialogueWindow; - + ContainerWindow *containerWindow; CharacterCreation* mCharGen; // Various stats about player as needed by window manager diff --git a/apps/openmw/mwworld/actionopen.cpp b/apps/openmw/mwworld/actionopen.cpp new file mode 100644 index 000000000..c7b066d8e --- /dev/null +++ b/apps/openmw/mwworld/actionopen.cpp @@ -0,0 +1,21 @@ +#include "actionopen.hpp" + +#include "environment.hpp" +#include "class.hpp" +#include "world.hpp" +#include "containerstore.hpp" +#include "../mwclass/container.hpp" +#include "../mwgui/window_manager.hpp" +#include "../mwgui/container.hpp" + +namespace MWWorld +{ + ActionOpen::ActionOpen (const MWWorld::Ptr& container) : mContainer (container) { + mContainer = container; + } + + void ActionOpen::execute (Environment& environment) + { + environment.mWindowManager->getContainerWindow()->open(mContainer); + } +} diff --git a/apps/openmw/mwworld/actionopen.hpp b/apps/openmw/mwworld/actionopen.hpp new file mode 100644 index 000000000..7c660e4c9 --- /dev/null +++ b/apps/openmw/mwworld/actionopen.hpp @@ -0,0 +1,22 @@ + +#ifndef GAME_MWWORLD_ACTIONOPEN_H +#define GAME_MWWORLD_ACTIONOPEN_H + +#include "action.hpp" +#include "ptr.hpp" + + +namespace MWWorld +{ + class ActionOpen : public Action + { + Ptr mContainer; + + public: + ActionOpen (const Ptr& container); + ///< \param The Container the Player has activated. + virtual void execute (Environment& environment); + }; +} + +#endif // ACTIONOPEN_H diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 2800b6f3c..16de93332 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -457,3 +457,33 @@ bool MWWorld::operator!= (const ContainerStoreIterator& left, const ContainerSto { return !(left==right); } + + +std::string MWWorld::ContainerStoreIterator::getInventoryIcon() +{ + Ptr ptr; + + switch (mType) + { + case ContainerStore::Type_Potion: ptr = MWWorld::Ptr (&*mPotion, 0); break; + case ContainerStore::Type_Apparatus: ptr = MWWorld::Ptr (&*mApparatus, 0); break; + case ContainerStore::Type_Armor: ptr = MWWorld::Ptr (&*mArmor, 0); break; + case ContainerStore::Type_Book: ptr = MWWorld::Ptr (&*mBook, 0); break; + case ContainerStore::Type_Clothing: ptr = MWWorld::Ptr (&*mClothing, 0); break; + case ContainerStore::Type_Ingredient: ptr = MWWorld::Ptr (&*mIngredient, 0); break; + case ContainerStore::Type_Light: ptr = MWWorld::Ptr (&*mLight, 0); break; + case ContainerStore::Type_Lockpick: ptr = MWWorld::Ptr (&*mLockpick, 0); break; + case ContainerStore::Type_Miscellaneous: ptr = MWWorld::Ptr (&*mMiscellaneous, 0); break; + case ContainerStore::Type_Probe: ptr = MWWorld::Ptr (&*mProbe, 0); break; + case ContainerStore::Type_Repair: ptr = MWWorld::Ptr (&*mRepair, 0); break; + case ContainerStore::Type_Weapon: ptr = MWWorld::Ptr (&*mWeapon, 0); break; + } + + if (ptr.isEmpty()) + throw std::runtime_error ("invalid iterator"); + + + std::string s = ptr.getInventoryIcon(); + + return s; +} diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index da5424fe0..fc6283442 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -161,6 +161,8 @@ namespace MWWorld const ContainerStore *getContainerStore() const; + std::string getInventoryIcon(); + friend class ContainerStore; }; diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index 9a6cde7ba..c24bd59f4 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -38,6 +38,7 @@ configure_file("${SDIR}/openmw_chargen_review_layout.xml" "${DDIR}/openmw_charge configure_file("${SDIR}/openmw_dialogue_window_layout.xml" "${DDIR}/openmw_dialogue_window_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_dialogue_window_skin.xml" "${DDIR}/openmw_dialogue_window_skin.xml" COPYONLY) configure_file("${SDIR}/openmw_inventory_window_layout.xml" "${DDIR}/openmw_inventory_window_layout.xml" COPYONLY) +configure_file("${SDIR}/openmw_container_window_layout.xml" "${DDIR}/openmw_container_window_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_layers.xml" "${DDIR}/openmw_layers.xml" COPYONLY) configure_file("${SDIR}/openmw_mainmenu_layout.xml" "${DDIR}/openmw_mainmenu_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_mainmenu_skin.xml" "${DDIR}/openmw_mainmenu_skin.xml" COPYONLY) diff --git a/files/mygui/openmw_container_window_layout.xml b/files/mygui/openmw_container_window_layout.xml new file mode 100644 index 000000000..a9de14880 --- /dev/null +++ b/files/mygui/openmw_container_window_layout.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + From 78c8a22cd16bef3ca0efc1479b8ceb777aac77af Mon Sep 17 00:00:00 2001 From: gugus Date: Sun, 15 Apr 2012 19:32:41 +0200 Subject: [PATCH 002/118] more clean up. The container GUI shows up now --- apps/openmw/mwgui/container.cpp | 95 ++++++++++++-------------- apps/openmw/mwgui/mode.hpp | 1 + apps/openmw/mwgui/window_manager.cpp | 5 ++ apps/openmw/mwworld/actionopen.cpp | 1 + apps/openmw/mwworld/containerstore.cpp | 2 +- 5 files changed, 52 insertions(+), 52 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index c09a1bf58..7a3d5b240 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -27,7 +27,7 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro mEnvironment(environment) { setText("_Main", "Name of Container"); - setVisible(false); + center(); getWidget(containerWidget, "Items"); getWidget(takeButton, "TakeButton"); @@ -35,17 +35,10 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro setText("CloseButton","Close"); setText("TakeButton","Take All"); - - //ctor } ContainerWindow::~ContainerWindow() { - //dtor - - - - } void ContainerWindow::setName(std::string contName) @@ -108,49 +101,49 @@ void ContainerWindow::open(MWWorld::Ptr& container) std::string path = std::string("icons\\"); - path += iter.getInventoryIcon(); -// switch (iter.getType()) -// { -// -// case MWWorld::ContainerStore::Type_Potion: -// path += iter->get()->base->icon; -// break; -// case MWWorld::ContainerStore::Type_Apparatus: -// path += iter->get()->base->icon; -// break; -// case MWWorld::ContainerStore::Type_Armor: -// path += iter->get()->base->icon; -// break; -// case MWWorld::ContainerStore::Type_Book: -// path += iter->get()->base->icon; -// break; -// case MWWorld::ContainerStore::Type_Clothing: -// path += iter->get()->base->icon; -// break; -// case MWWorld::ContainerStore::Type_Ingredient: -// path += iter->get()->base->icon; -// break; -// case MWWorld::ContainerStore::Type_Light: -// path += iter->get()->base->icon; -// break; -// case MWWorld::ContainerStore::Type_Lockpick: -// path += iter->get()->base->icon; -// break; -// case MWWorld::ContainerStore::Type_Miscellaneous: -// path += iter->get()->base->icon; -// break; -// case MWWorld::ContainerStore::Type_Probe: -// path += iter->get()->base->icon; -// break; -// case MWWorld::ContainerStore::Type_Repair: -// path += iter->get()->base->icon; -// break; -// case MWWorld::ContainerStore::Type_Weapon: -// path += iter->get()->base->icon; -// break; -// -// -// } + //path += iter.getInventoryIcon(); + switch (iter.getType()) + { + + case MWWorld::ContainerStore::Type_Potion: + path += iter->get()->base->icon; + break; + case MWWorld::ContainerStore::Type_Apparatus: + path += iter->get()->base->icon; + break; + case MWWorld::ContainerStore::Type_Armor: + path += iter->get()->base->icon; + break; + case MWWorld::ContainerStore::Type_Book: + path += iter->get()->base->icon; + break; + case MWWorld::ContainerStore::Type_Clothing: + path += iter->get()->base->icon; + break; + case MWWorld::ContainerStore::Type_Ingredient: + path += iter->get()->base->icon; + break; + case MWWorld::ContainerStore::Type_Light: + path += iter->get()->base->icon; + break; + case MWWorld::ContainerStore::Type_Lockpick: + path += iter->get()->base->icon; + break; + case MWWorld::ContainerStore::Type_Miscellaneous: + path += iter->get()->base->icon; + break; + case MWWorld::ContainerStore::Type_Probe: + path += iter->get()->base->icon; + break; + case MWWorld::ContainerStore::Type_Repair: + path += iter->get()->base->icon; + break; + case MWWorld::ContainerStore::Type_Weapon: + path += iter->get()->base->icon; + break; + + + } count++; if(count % 8 == 0) diff --git a/apps/openmw/mwgui/mode.hpp b/apps/openmw/mwgui/mode.hpp index 55f0952ce..48670e9a5 100644 --- a/apps/openmw/mwgui/mode.hpp +++ b/apps/openmw/mwgui/mode.hpp @@ -7,6 +7,7 @@ namespace MWGui { GM_Game, // Game mode, only HUD GM_Inventory, // Inventory mode + GM_Container, GM_MainMenu, // Main menu mode GM_Console, // Console mode diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 06bbb3a30..34048c935 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -181,6 +181,7 @@ void WindowManager::updateVisible() console->disable(); mJournal->setVisible(false); dialogueWindow->setVisible(false); + containerWindow->setVisible(false); // Mouse is visible whenever we're not in game mode MyGUI::PointerManager::getInstance().setVisible(isGuiMode()); @@ -216,8 +217,12 @@ void WindowManager::updateVisible() // Show the windows we want map -> setVisible( (eff & GW_Map) != 0 ); stats -> setVisible( (eff & GW_Stats) != 0 ); + break; } + case GM_Container: + containerWindow->setVisible(true); + break; case GM_Dialogue: dialogueWindow->open(); break; diff --git a/apps/openmw/mwworld/actionopen.cpp b/apps/openmw/mwworld/actionopen.cpp index c7b066d8e..aa4a67b2b 100644 --- a/apps/openmw/mwworld/actionopen.cpp +++ b/apps/openmw/mwworld/actionopen.cpp @@ -16,6 +16,7 @@ namespace MWWorld void ActionOpen::execute (Environment& environment) { + environment.mWindowManager->setGuiMode(MWGui::GuiMode::GM_Container); environment.mWindowManager->getContainerWindow()->open(mContainer); } } diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 16de93332..3f1b7ea2c 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -483,7 +483,7 @@ std::string MWWorld::ContainerStoreIterator::getInventoryIcon() throw std::runtime_error ("invalid iterator"); - std::string s = ptr.getInventoryIcon(); + std::string s = "";//ptr.getInventoryIcon(); return s; } From 58d05fa503f9117ae7ddc6288cbeb421c73b83cc Mon Sep 17 00:00:00 2001 From: gugus Date: Sun, 15 Apr 2012 20:56:45 +0200 Subject: [PATCH 003/118] more clean-up. Container window shows up! But there is no working close button. --- apps/openmw/mwgui/container.cpp | 45 ++------------------------ apps/openmw/mwworld/class.cpp | 5 +++ apps/openmw/mwworld/class.hpp | 3 ++ apps/openmw/mwworld/containerstore.cpp | 32 +----------------- apps/openmw/mwworld/containerstore.hpp | 2 -- files/mygui/core.xml | 1 + 6 files changed, 12 insertions(+), 76 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 7a3d5b240..2defad207 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -16,6 +16,7 @@ #include "../mwclass/container.hpp" #include "../mwworld/containerstore.hpp" #include +#include "../mwworld/class.hpp" using namespace MWGui; @@ -101,49 +102,7 @@ void ContainerWindow::open(MWWorld::Ptr& container) std::string path = std::string("icons\\"); - //path += iter.getInventoryIcon(); - switch (iter.getType()) - { - - case MWWorld::ContainerStore::Type_Potion: - path += iter->get()->base->icon; - break; - case MWWorld::ContainerStore::Type_Apparatus: - path += iter->get()->base->icon; - break; - case MWWorld::ContainerStore::Type_Armor: - path += iter->get()->base->icon; - break; - case MWWorld::ContainerStore::Type_Book: - path += iter->get()->base->icon; - break; - case MWWorld::ContainerStore::Type_Clothing: - path += iter->get()->base->icon; - break; - case MWWorld::ContainerStore::Type_Ingredient: - path += iter->get()->base->icon; - break; - case MWWorld::ContainerStore::Type_Light: - path += iter->get()->base->icon; - break; - case MWWorld::ContainerStore::Type_Lockpick: - path += iter->get()->base->icon; - break; - case MWWorld::ContainerStore::Type_Miscellaneous: - path += iter->get()->base->icon; - break; - case MWWorld::ContainerStore::Type_Probe: - path += iter->get()->base->icon; - break; - case MWWorld::ContainerStore::Type_Repair: - path += iter->get()->base->icon; - break; - case MWWorld::ContainerStore::Type_Weapon: - path += iter->get()->base->icon; - break; - - - } + path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); count++; if(count % 8 == 0) diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index d49b98d0f..2dd8aee1e 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -173,4 +173,9 @@ namespace MWWorld { throw std::runtime_error ("class does not have an down sound"); } + + std::string Class::getInventoryIcon (const MWWorld::Ptr& ptr) const + { + throw std::runtime_error ("class does not have any inventory icon"); + } } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index e474e9b92..eaa0d5f6f 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -174,6 +174,9 @@ namespace MWWorld virtual std::string getDownSoundId (const Ptr& ptr, const MWWorld::Environment& environment) const; ///< Return the down sound ID of \a ptr or throw an exception, if class does not support ID retrieval /// (default implementation: throw an exception) + + virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; + ///< Return name of inventory icon. }; } diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 3f1b7ea2c..86ee15e58 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -456,34 +456,4 @@ bool MWWorld::operator== (const ContainerStoreIterator& left, const ContainerSto bool MWWorld::operator!= (const ContainerStoreIterator& left, const ContainerStoreIterator& right) { return !(left==right); -} - - -std::string MWWorld::ContainerStoreIterator::getInventoryIcon() -{ - Ptr ptr; - - switch (mType) - { - case ContainerStore::Type_Potion: ptr = MWWorld::Ptr (&*mPotion, 0); break; - case ContainerStore::Type_Apparatus: ptr = MWWorld::Ptr (&*mApparatus, 0); break; - case ContainerStore::Type_Armor: ptr = MWWorld::Ptr (&*mArmor, 0); break; - case ContainerStore::Type_Book: ptr = MWWorld::Ptr (&*mBook, 0); break; - case ContainerStore::Type_Clothing: ptr = MWWorld::Ptr (&*mClothing, 0); break; - case ContainerStore::Type_Ingredient: ptr = MWWorld::Ptr (&*mIngredient, 0); break; - case ContainerStore::Type_Light: ptr = MWWorld::Ptr (&*mLight, 0); break; - case ContainerStore::Type_Lockpick: ptr = MWWorld::Ptr (&*mLockpick, 0); break; - case ContainerStore::Type_Miscellaneous: ptr = MWWorld::Ptr (&*mMiscellaneous, 0); break; - case ContainerStore::Type_Probe: ptr = MWWorld::Ptr (&*mProbe, 0); break; - case ContainerStore::Type_Repair: ptr = MWWorld::Ptr (&*mRepair, 0); break; - case ContainerStore::Type_Weapon: ptr = MWWorld::Ptr (&*mWeapon, 0); break; - } - - if (ptr.isEmpty()) - throw std::runtime_error ("invalid iterator"); - - - std::string s = "";//ptr.getInventoryIcon(); - - return s; -} +} \ No newline at end of file diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index fc6283442..da5424fe0 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -161,8 +161,6 @@ namespace MWWorld const ContainerStore *getContainerStore() const; - std::string getInventoryIcon(); - friend class ContainerStore; }; diff --git a/files/mygui/core.xml b/files/mygui/core.xml index 7417328cf..8e256ca9c 100644 --- a/files/mygui/core.xml +++ b/files/mygui/core.xml @@ -20,6 +20,7 @@ + From 489261a6ae514dafe2aea679bbca17c1c52cf46b Mon Sep 17 00:00:00 2001 From: gugus Date: Sun, 15 Apr 2012 21:02:54 +0200 Subject: [PATCH 004/118] Close button works. --- apps/openmw/mwgui/container.cpp | 10 +++++++++- apps/openmw/mwgui/container.hpp | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 2defad207..3f27351a9 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -29,11 +29,14 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro { setText("_Main", "Name of Container"); center(); + adjustWindowCaption(); getWidget(containerWidget, "Items"); getWidget(takeButton, "TakeButton"); getWidget(closeButton, "CloseButton"); + closeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onByeClicked); + setText("CloseButton","Close"); setText("TakeButton","Take All"); } @@ -136,8 +139,13 @@ void ContainerWindow::open(MWWorld::Ptr& container) setVisible(true); } -void Update() +void ContainerWindow::Update() { } +void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) +{ + mEnvironment.mWindowManager->setGuiMode(MWGui::GuiMode::GM_Game); +} + diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index e027f48fe..76905a681 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -53,7 +53,7 @@ namespace MWGui MyGUI::ButtonPtr closeButton; - + void onByeClicked(MyGUI::Widget* _sender); //MWWorld::Ptr& mContainer; From f902c8fa6f154db5dd5383878781cc817c2dd01f Mon Sep 17 00:00:00 2001 From: pchan3 Date: Wed, 18 Apr 2012 22:35:35 +1000 Subject: [PATCH 005/118] Fixes on Namespace issue & more. --- apps/openmw/mwgui/container.cpp | 73 ++++++++++++++++++++++++------ apps/openmw/mwworld/actionopen.cpp | 2 +- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 3f27351a9..094b958db 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -28,7 +28,7 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro mEnvironment(environment) { setText("_Main", "Name of Container"); - center(); + //center(); adjustWindowCaption(); getWidget(containerWidget, "Items"); @@ -90,7 +90,54 @@ void ContainerWindow::open(MWWorld::Ptr& container) containerStore.add(bukkitRef.getPtr()); containerStore.add(bukkitRef.getPtr()); containerStore.add(goldRef.getPtr()); - + containerStore.add(furRef.getPtr()); + containerStore.add(furRef.getPtr()); + containerStore.add(furRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(goldRef.getPtr()); + containerStore.add(furRef.getPtr()); + containerStore.add(furRef.getPtr()); + containerStore.add(furRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(broomRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(bukkitRef.getPtr()); + containerStore.add(goldRef.getPtr()); // ESMS::LiveCellRef *ref = iter->get(); @@ -103,39 +150,35 @@ void ContainerWindow::open(MWWorld::Ptr& container) for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) { std::string path = std::string("icons\\"); - - path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); count++; - if(count % 8 == 0) + MyGUI::ImageBox* image = containerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); + MyGUI::TextBox* text = containerWidget->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); + + x += 36; + if(count % 20 == 0) { y += 36; x = 4; count = 0; } - x += 36; - - - MyGUI::ImageBox* image = containerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); - MyGUI::TextBox* text = containerWidget->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); if(iter->getRefData().getCount() > 1) text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); - containerWidgets.push_back(image); - int pos = path.rfind("."); path.erase(pos); path.append(".dds"); - //std::cout << path << std::endl; image->setImageTexture(path); } + + setVisible(true); } @@ -146,6 +189,8 @@ void ContainerWindow::Update() void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) { - mEnvironment.mWindowManager->setGuiMode(MWGui::GuiMode::GM_Game); + mEnvironment.mWindowManager->setGuiMode(GM_Game); + + setVisible(false); } diff --git a/apps/openmw/mwworld/actionopen.cpp b/apps/openmw/mwworld/actionopen.cpp index aa4a67b2b..e245989d7 100644 --- a/apps/openmw/mwworld/actionopen.cpp +++ b/apps/openmw/mwworld/actionopen.cpp @@ -16,7 +16,7 @@ namespace MWWorld void ActionOpen::execute (Environment& environment) { - environment.mWindowManager->setGuiMode(MWGui::GuiMode::GM_Container); + environment.mWindowManager->setGuiMode(MWGui::GM_Container); environment.mWindowManager->getContainerWindow()->open(mContainer); } } From 215d4e1739a016b094e6ccb5dda3e06e175df4ae Mon Sep 17 00:00:00 2001 From: pchan3 Date: Wed, 18 Apr 2012 23:09:13 +1000 Subject: [PATCH 006/118] Made adjustments to keep container window within the viewscreen. --- apps/openmw/mwgui/container.cpp | 4 ++++ files/mygui/openmw_container_window_layout.xml | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 094b958db..7c63f95d0 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -28,6 +28,10 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro mEnvironment(environment) { setText("_Main", "Name of Container"); + + int w = MyGUI::RenderManager::getInstance().getViewSize().width; + int h = MyGUI::RenderManager::getInstance().getViewSize().height; + setCoord(w-600,h-300,600,300); //center(); adjustWindowCaption(); diff --git a/files/mygui/openmw_container_window_layout.xml b/files/mygui/openmw_container_window_layout.xml index a9de14880..7fce9e187 100644 --- a/files/mygui/openmw_container_window_layout.xml +++ b/files/mygui/openmw_container_window_layout.xml @@ -1,13 +1,13 @@ - + - - + - --> + From 1e8d894e1c9562010847fe4a5632055bab1093b3 Mon Sep 17 00:00:00 2001 From: gugus Date: Sat, 21 Apr 2012 10:51:01 +0200 Subject: [PATCH 007/118] Starting inventory window --- apps/openmw/mwgui/container.cpp | 21 +++++++++++++++++-- apps/openmw/mwgui/container.hpp | 1 + apps/openmw/mwgui/inventorywindow.cpp | 11 ++++++++++ apps/openmw/mwgui/inventorywindow.hpp | 30 +++++++++++++++++++++++++++ apps/openmw/mwgui/window_manager.cpp | 7 ++++++- apps/openmw/mwgui/window_manager.hpp | 2 ++ 6 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 apps/openmw/mwgui/inventorywindow.cpp create mode 100644 apps/openmw/mwgui/inventorywindow.hpp diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 3f27351a9..bc3bcf475 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -41,6 +41,23 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro setText("TakeButton","Take All"); } +ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,std::string guiFile) + : WindowBase(guiFile, parWindowManager), + mEnvironment(environment) +{ + setText("_Main", "Name of Container"); + //center(); + adjustWindowCaption(); + + getWidget(containerWidget, "Items"); + //getWidget(takeButton, "TakeButton"); + //getWidget(closeButton, "CloseButton"); + + //closeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onByeClicked); + + //setText("CloseButton","Close"); + //setText("TakeButton","Take All"); +} ContainerWindow::~ContainerWindow() { } @@ -60,7 +77,7 @@ void ContainerWindow::open(MWWorld::Ptr& container) MWWorld::ContainerStore& containerStore = MWWorld::Class::get(container).getContainerStore(container); - MWWorld::ManualRef furRef (mWindowManager.getStore(), "fur_cuirass"); + /*MWWorld::ManualRef furRef (mWindowManager.getStore(), "fur_cuirass"); furRef.getPtr().getRefData().setCount (5); MWWorld::ManualRef bukkitRef (mWindowManager.getStore(), "misc_com_bucket_01"); MWWorld::ManualRef broomRef (mWindowManager.getStore(), "misc_com_broom_01"); @@ -89,7 +106,7 @@ void ContainerWindow::open(MWWorld::Ptr& container) containerStore.add(bukkitRef.getPtr()); containerStore.add(bukkitRef.getPtr()); containerStore.add(bukkitRef.getPtr()); - containerStore.add(goldRef.getPtr()); + containerStore.add(goldRef.getPtr());*/ diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 76905a681..3802d21af 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -36,6 +36,7 @@ namespace MWGui { public: ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment); + ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,std::string guiFile); void open(MWWorld::Ptr& container); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp new file mode 100644 index 000000000..7f3884bc1 --- /dev/null +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -0,0 +1,11 @@ +#include "inventorywindow.hpp" + +namespace MWGui +{ + + InventoryWindow::InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment) + :ContainerWindow(parWindowManager,environment,"openmw_inventory_window_layout.xml") + { + } + +} \ No newline at end of file diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp new file mode 100644 index 000000000..ce177014a --- /dev/null +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -0,0 +1,30 @@ +#ifndef MGUI_Inventory_H +#define MGUI_Inventory_H + +#include "container.hpp" +namespace MWWorld +{ + class Environment; +} + +namespace MyGUI +{ + class Gui; + class Widget; +} + +namespace MWGui +{ + class WindowManager; +} + + +namespace MWGui +{ + class InventoryWindow : public MWGui::ContainerWindow + { + public: + InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment); + }; +} +#endif // Inventory_H diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 34048c935..065141963 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -8,6 +8,7 @@ #include "stats_window.hpp" #include "messagebox.hpp" #include "container.hpp" +#include "inventorywindow.hpp" #include "../mwmechanics/mechanicsmanager.hpp" #include "../mwinput/inputmanager.hpp" @@ -82,6 +83,7 @@ WindowManager::WindowManager(MWWorld::Environment& environment, mMessageBoxManager = new MessageBoxManager(this); dialogueWindow = new DialogueWindow(*this,environment); containerWindow = new ContainerWindow(*this,environment); + mInventoryWindow = new InventoryWindow(*this,environment); // The HUD is always on hud->setVisible(true); @@ -121,6 +123,7 @@ WindowManager::~WindowManager() delete mJournal; delete dialogueWindow; delete containerWindow; + delete mInventoryWindow; delete mCharGen; cleanupGarbage(); @@ -182,6 +185,7 @@ void WindowManager::updateVisible() mJournal->setVisible(false); dialogueWindow->setVisible(false); containerWindow->setVisible(false); + mInventoryWindow->setVisible(false); // Mouse is visible whenever we're not in game mode MyGUI::PointerManager::getInstance().setVisible(isGuiMode()); @@ -217,11 +221,12 @@ void WindowManager::updateVisible() // Show the windows we want map -> setVisible( (eff & GW_Map) != 0 ); stats -> setVisible( (eff & GW_Stats) != 0 ); - + mInventoryWindow->setVisible(true); break; } case GM_Container: containerWindow->setVisible(true); + mInventoryWindow->setVisible(true); break; case GM_Dialogue: dialogueWindow->open(); diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 4f54b41b8..438a99a0e 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -63,6 +63,7 @@ namespace MWGui class JournalWindow; class CharacterCreation; class ContainerWindow; + class InventoryWindow; class TextInputDialog; class InfoBoxDialog; class DialogueWindow; @@ -204,6 +205,7 @@ namespace MWGui JournalWindow* mJournal; DialogueWindow *dialogueWindow; ContainerWindow *containerWindow; + InventoryWindow *mInventoryWindow; CharacterCreation* mCharGen; // Various stats about player as needed by window manager From 33654535c19b22f103bcf547dc337620d6ac5feb Mon Sep 17 00:00:00 2001 From: gugus Date: Sat, 21 Apr 2012 11:05:30 +0200 Subject: [PATCH 008/118] The inventory window now display the inventory of the player --- apps/openmw/mwgui/container.hpp | 2 +- apps/openmw/mwgui/inventorywindow.cpp | 23 +++++++++++++++++++++++ apps/openmw/mwgui/inventorywindow.hpp | 2 ++ apps/openmw/mwgui/window_manager.cpp | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 3802d21af..5bb019233 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -44,8 +44,8 @@ namespace MWGui void Update(); virtual ~ContainerWindow(); + protected: - private: MWWorld::Environment& mEnvironment; std::vector containerWidgets; MyGUI::WidgetPtr containerWidget; diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 7f3884bc1..188cc3796 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -1,5 +1,23 @@ #include "inventorywindow.hpp" +#include +#include +#include "window_manager.hpp" +#include "widgets.hpp" +#include "../mwworld/environment.hpp" +#include "../mwworld/manualref.hpp" +#include +#include +#include + +#include +#include +#include "../mwclass/container.hpp" +#include "../mwworld/containerstore.hpp" +#include +#include "../mwworld/class.hpp" +#include "../mwworld/world.hpp" +#include "../mwworld/player.hpp" namespace MWGui { @@ -8,4 +26,9 @@ namespace MWGui { } + void InventoryWindow::openInventory() + { + open(mEnvironment.mWorld->getPlayer().getPlayer()); + } + } \ No newline at end of file diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index ce177014a..bf9be4375 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -25,6 +25,8 @@ namespace MWGui { public: InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment); + + void openInventory(); }; } #endif // Inventory_H diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 065141963..c15f7077d 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -222,11 +222,13 @@ void WindowManager::updateVisible() map -> setVisible( (eff & GW_Map) != 0 ); stats -> setVisible( (eff & GW_Stats) != 0 ); mInventoryWindow->setVisible(true); + mInventoryWindow->openInventory(); break; } case GM_Container: containerWindow->setVisible(true); mInventoryWindow->setVisible(true); + mInventoryWindow->openInventory(); break; case GM_Dialogue: dialogueWindow->open(); From d4e9b62436dd691380f1ba78fdc161843503a4c5 Mon Sep 17 00:00:00 2001 From: gugus Date: Sat, 21 Apr 2012 11:11:40 +0200 Subject: [PATCH 009/118] oups forgot to modify CMake --- apps/openmw/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 769bcc6c3..f37f8dae4 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 container - map_window window_pinnable_base cursorreplace + map_window window_pinnable_base cursorreplace inventorywindow ) add_openmw_dir (mwdialogue From 25432d97d2d325639fe280d8530e1933d1206cdd Mon Sep 17 00:00:00 2001 From: gugus Date: Sat, 21 Apr 2012 20:35:45 +0200 Subject: [PATCH 010/118] trying to get selected item. Doesn't work. --- apps/openmw/mwgui/container.cpp | 17 +++++++++++------ apps/openmw/mwgui/container.hpp | 6 +++--- files/mygui/openmw_container_window_layout.xml | 10 +++++----- files/mygui/openmw_inventory_window_layout.xml | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 2c09d6b29..9071c9b35 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -35,7 +35,7 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro //center(); adjustWindowCaption(); - getWidget(containerWidget, "Items"); + getWidget(mContainerWidget, "Items"); getWidget(takeButton, "TakeButton"); getWidget(closeButton, "CloseButton"); @@ -43,6 +43,7 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro setText("CloseButton","Close"); setText("TakeButton","Take All"); + mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); } ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,std::string guiFile) @@ -52,8 +53,7 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro setText("_Main", "Name of Container"); //center(); adjustWindowCaption(); - - getWidget(containerWidget, "Items"); + getWidget(mContainerWidget, "Items"); //getWidget(takeButton, "TakeButton"); //getWidget(closeButton, "CloseButton"); @@ -61,6 +61,7 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro //setText("CloseButton","Close"); //setText("TakeButton","Take All"); + mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); } ContainerWindow::~ContainerWindow() { @@ -126,8 +127,8 @@ void ContainerWindow::open(MWWorld::Ptr& container) path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); count++; - MyGUI::ImageBox* image = containerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); - MyGUI::TextBox* text = containerWidget->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); + MyGUI::ImageBox* image = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); + MyGUI::TextBox* text = mContainerWidget->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); x += 36; if(count % 20 == 0) @@ -140,7 +141,7 @@ void ContainerWindow::open(MWWorld::Ptr& container) if(iter->getRefData().getCount() > 1) text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); - containerWidgets.push_back(image); + mContainerWidgets.push_back(image); int pos = path.rfind("."); path.erase(pos); @@ -167,3 +168,7 @@ void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) setVisible(false); } +void ContainerWindow::onSelectedItem(MyGUI::ItemBox* _sender, size_t _index) +{ + std::cout << "selected!"; +} \ No newline at end of file diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 5bb019233..0e68baf02 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -47,15 +47,15 @@ namespace MWGui protected: MWWorld::Environment& mEnvironment; - std::vector containerWidgets; - MyGUI::WidgetPtr containerWidget; + std::vector mContainerWidgets; + MyGUI::ItemBoxPtr mContainerWidget; MyGUI::ButtonPtr takeButton; MyGUI::ButtonPtr closeButton; void onByeClicked(MyGUI::Widget* _sender); - + void onSelectedItem(MyGUI::ItemBox* _sender, size_t _index); //MWWorld::Ptr& mContainer; }; diff --git a/files/mygui/openmw_container_window_layout.xml b/files/mygui/openmw_container_window_layout.xml index 7fce9e187..31b036468 100644 --- a/files/mygui/openmw_container_window_layout.xml +++ b/files/mygui/openmw_container_window_layout.xml @@ -1,19 +1,19 @@ - + - + - + diff --git a/files/mygui/openmw_inventory_window_layout.xml b/files/mygui/openmw_inventory_window_layout.xml index c69b6d8fe..766cacdb1 100644 --- a/files/mygui/openmw_inventory_window_layout.xml +++ b/files/mygui/openmw_inventory_window_layout.xml @@ -14,7 +14,7 @@ - + From 1b02b503a231dde098c7318b466db583e1da106c Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 22 Apr 2012 21:06:08 +0200 Subject: [PATCH 011/118] gcc compile fix --- apps/openmw/mwgui/container.cpp | 4 ++-- apps/openmw/mwgui/container.hpp | 2 +- apps/openmw/mwgui/inventorywindow.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 9071c9b35..ac9330fdc 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -74,7 +74,7 @@ void ContainerWindow::setName(std::string contName) -void ContainerWindow::open(MWWorld::Ptr& container) +void ContainerWindow::open(MWWorld::Ptr container) { setName(MWWorld::Class::get(container).getName(container)); //MWWorld::ContainerStore* containerStore = container.getContainerStore(); @@ -171,4 +171,4 @@ void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) void ContainerWindow::onSelectedItem(MyGUI::ItemBox* _sender, size_t _index) { std::cout << "selected!"; -} \ No newline at end of file +} diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 0e68baf02..a7787b373 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -39,7 +39,7 @@ namespace MWGui ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,std::string guiFile); - void open(MWWorld::Ptr& container); + void open(MWWorld::Ptr container); void setName(std::string contName); void Update(); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 188cc3796..81a190290 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -31,4 +31,4 @@ namespace MWGui open(mEnvironment.mWorld->getPlayer().getPlayer()); } -} \ No newline at end of file +} From a6419c3596a123584df3ed8a25e4650a9a3e655b Mon Sep 17 00:00:00 2001 From: gugus Date: Thu, 26 Apr 2012 19:35:45 +0200 Subject: [PATCH 012/118] Clicking on an item is now detected. Trying to have items follow the mouse position, but it doesn't work yet. --- apps/openmw/mwgui/container.cpp | 25 +++++++++++++++++++------ apps/openmw/mwgui/container.hpp | 3 ++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 9071c9b35..e3d7574f3 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -43,7 +43,7 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro setText("CloseButton","Close"); setText("TakeButton","Take All"); - mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); + //mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); } ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,std::string guiFile) @@ -61,7 +61,7 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro //setText("CloseButton","Close"); //setText("TakeButton","Take All"); - mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); + //mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); } ContainerWindow::~ContainerWindow() { @@ -128,8 +128,9 @@ void ContainerWindow::open(MWWorld::Ptr& container) count++; MyGUI::ImageBox* image = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); - MyGUI::TextBox* text = mContainerWidget->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); - + MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); + image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); + image->eventMouseMove += MyGUI::newDelegate(this,&ContainerWindow::onMouseMove); x += 36; if(count % 20 == 0) { @@ -141,7 +142,7 @@ void ContainerWindow::open(MWWorld::Ptr& container) if(iter->getRefData().getCount() > 1) text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); - mContainerWidgets.push_back(image); + //mContainerWidgets.push_back(image); int pos = path.rfind("."); path.erase(pos); @@ -168,7 +169,19 @@ void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) setVisible(false); } -void ContainerWindow::onSelectedItem(MyGUI::ItemBox* _sender, size_t _index) +void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender) { + _sender->detachFromWidget(); + _sender->attachToWidget(mContainerWidget->getParent()->getParent()); + std::cout << mContainerWidget->getParent()->getParent()->getName(); + _sender->setUserString("drag","on"); std::cout << "selected!"; +} + +void ContainerWindow::onMouseMove(MyGUI::Widget* _sender, int _left, int _top) +{ + if(_sender->getUserString("drag") == "on") + { + _sender->setPosition(_left,_top); + } } \ No newline at end of file diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 0e68baf02..6ac9a814f 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -55,7 +55,8 @@ namespace MWGui void onByeClicked(MyGUI::Widget* _sender); - void onSelectedItem(MyGUI::ItemBox* _sender, size_t _index); + void onSelectedItem(MyGUI::Widget* _sender); + void onMouseMove(MyGUI::Widget* _sender, int _left, int _top); //MWWorld::Ptr& mContainer; }; From 5603cb312cd6f00f06fe88597e5d2e202d53e292 Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 27 Apr 2012 20:54:39 +0200 Subject: [PATCH 013/118] Objects can now be selected and follow mouse movements. --- apps/openmw/mwgui/container.cpp | 37 +++++++++++++++++++-------- apps/openmw/mwgui/container.hpp | 9 ++++--- apps/openmw/mwgui/inventorywindow.cpp | 4 +-- apps/openmw/mwgui/inventorywindow.hpp | 2 +- apps/openmw/mwgui/window_manager.cpp | 11 +++++--- files/mygui/openmw_layers.xml | 1 + 6 files changed, 45 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index e3d7574f3..b3fe7adfb 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -17,15 +17,17 @@ #include "../mwworld/containerstore.hpp" #include #include "../mwworld/class.hpp" +#include "../mwinput/inputmanager.hpp" using namespace MWGui; using namespace Widgets; -ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment) +ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget) : WindowBase("openmw_container_window_layout.xml", parWindowManager), - mEnvironment(environment) + mEnvironment(environment), + mDragAndDropWidget(dragAndDropWidget) { setText("_Main", "Name of Container"); @@ -43,17 +45,24 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro setText("CloseButton","Close"); setText("TakeButton","Take All"); + + mIsOnDragAndDrop = false; + mDraggedWidget = 0; //mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); } -ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,std::string guiFile) +ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget,std::string guiFile) : WindowBase(guiFile, parWindowManager), - mEnvironment(environment) + mEnvironment(environment), + mDragAndDropWidget(dragAndDropWidget) { setText("_Main", "Name of Container"); //center(); adjustWindowCaption(); getWidget(mContainerWidget, "Items"); + + mIsOnDragAndDrop = false; + mDraggedWidget = 0; //getWidget(takeButton, "TakeButton"); //getWidget(closeButton, "CloseButton"); @@ -130,7 +139,7 @@ void ContainerWindow::open(MWWorld::Ptr& container) MyGUI::ImageBox* image = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); - image->eventMouseMove += MyGUI::newDelegate(this,&ContainerWindow::onMouseMove); + //image->eventMouseMove += MyGUI::newDelegate(this,&ContainerWindow::onMouseMove); x += 36; if(count % 20 == 0) { @@ -159,7 +168,12 @@ void ContainerWindow::open(MWWorld::Ptr& container) void ContainerWindow::Update() { - + if(mIsOnDragAndDrop) + { + if(mDraggedWidget) + mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); + else mIsOnDragAndDrop = false; //If this happens, there is a bug. + } } void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) @@ -171,17 +185,20 @@ void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender) { + mIsOnDragAndDrop = true; _sender->detachFromWidget(); - _sender->attachToWidget(mContainerWidget->getParent()->getParent()); - std::cout << mContainerWidget->getParent()->getParent()->getName(); + _sender->attachToWidget(mDragAndDropWidget); + //std::cout << mContainerWidget->getParent()->getParent()->getName(); _sender->setUserString("drag","on"); + mDraggedWidget = _sender; std::cout << "selected!"; } void ContainerWindow::onMouseMove(MyGUI::Widget* _sender, int _left, int _top) { - if(_sender->getUserString("drag") == "on") + /*if(_sender->getUserString("drag") == "on") { _sender->setPosition(_left,_top); - } + + }*/ } \ No newline at end of file diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 6ac9a814f..2d1aa3ac0 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -35,8 +35,9 @@ namespace MWGui class ContainerWindow : public WindowBase { public: - ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment); - ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,std::string guiFile); + ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget); + ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget, + std::string guiFile); void open(MWWorld::Ptr& container); @@ -52,7 +53,9 @@ namespace MWGui MyGUI::ButtonPtr takeButton; MyGUI::ButtonPtr closeButton; - + MyGUI::Widget* mDragAndDropWidget; + bool mIsOnDragAndDrop; + MyGUI::Widget* mDraggedWidget; void onByeClicked(MyGUI::Widget* _sender); void onSelectedItem(MyGUI::Widget* _sender); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 188cc3796..efc9106e9 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -21,8 +21,8 @@ namespace MWGui { - InventoryWindow::InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment) - :ContainerWindow(parWindowManager,environment,"openmw_inventory_window_layout.xml") + InventoryWindow::InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget) + :ContainerWindow(parWindowManager,environment,dragAndDropWidget,"openmw_inventory_window_layout.xml") { } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index bf9be4375..c60889d73 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -24,7 +24,7 @@ namespace MWGui class InventoryWindow : public MWGui::ContainerWindow { public: - InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment); + InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget); void openInventory(); }; diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index c15f7077d..f2adfe1e1 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -65,7 +65,7 @@ WindowManager::WindowManager(MWWorld::Environment& environment, // Set up the GUI system mGuiManager = new OEngine::GUI::MyGUIManager(mOgre->getWindow(), mOgre->getScene(), false, logpath); gui = mGuiManager->getGui(); - + //Register own widgets with MyGUI MyGUI::FactoryManager::getInstance().registerFactory("Widget"); @@ -74,6 +74,9 @@ WindowManager::WindowManager(MWWorld::Environment& environment, int w = MyGUI::RenderManager::getInstance().getViewSize().width; int h = MyGUI::RenderManager::getInstance().getViewSize().height; + MyGUI::Widget* dragAndDropWidget = gui->createWidgetT("Widget","",0,0,w,h,MyGUI::Align::Default,"DragAndDrop","DragAndDropWidget"); + dragAndDropWidget->setVisible(false); + hud = new HUD(w,h, showFPSLevel); menu = new MainMenu(w,h); map = new MapWindow(*this); @@ -82,8 +85,8 @@ WindowManager::WindowManager(MWWorld::Environment& environment, mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); dialogueWindow = new DialogueWindow(*this,environment); - containerWindow = new ContainerWindow(*this,environment); - mInventoryWindow = new InventoryWindow(*this,environment); + containerWindow = new ContainerWindow(*this,environment,dragAndDropWidget); + mInventoryWindow = new InventoryWindow(*this,environment,dragAndDropWidget); // The HUD is always on hud->setVisible(true); @@ -422,6 +425,8 @@ void WindowManager::onDialogueWindowBye() void WindowManager::onFrame (float frameDuration) { mMessageBoxManager->onFrame(frameDuration); + mInventoryWindow->Update(); + containerWindow->Update(); } const ESMS::ESMStore& WindowManager::getStore() const diff --git a/files/mygui/openmw_layers.xml b/files/mygui/openmw_layers.xml index a83eb970a..81cd99fea 100644 --- a/files/mygui/openmw_layers.xml +++ b/files/mygui/openmw_layers.xml @@ -10,4 +10,5 @@ + From 5f8c08b18b65443805dd5f73802497d0d4c87e5c Mon Sep 17 00:00:00 2001 From: gugus Date: Mon, 30 Apr 2012 13:01:18 +0200 Subject: [PATCH 014/118] some work for dropping objects. --- apps/openmw/mwgui/container.cpp | 69 ++++++++++++++++----------- apps/openmw/mwgui/container.hpp | 37 ++++++++------ apps/openmw/mwgui/inventorywindow.cpp | 4 +- apps/openmw/mwgui/inventorywindow.hpp | 2 +- apps/openmw/mwgui/window_manager.cpp | 33 ++++++++----- apps/openmw/mwgui/window_manager.hpp | 10 ++-- 6 files changed, 93 insertions(+), 62 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index b3fe7adfb..d5eb8cff7 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -24,10 +24,10 @@ using namespace MWGui; using namespace Widgets; -ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget) +ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop) : WindowBase("openmw_container_window_layout.xml", parWindowManager), mEnvironment(environment), - mDragAndDropWidget(dragAndDropWidget) + mDragAndDrop(dragAndDrop) { setText("_Main", "Name of Container"); @@ -42,27 +42,23 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro getWidget(closeButton, "CloseButton"); closeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onByeClicked); - + mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onContainerClicked); setText("CloseButton","Close"); setText("TakeButton","Take All"); - mIsOnDragAndDrop = false; - mDraggedWidget = 0; //mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); } -ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget,std::string guiFile) +ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop,std::string guiFile) : WindowBase(guiFile, parWindowManager), mEnvironment(environment), - mDragAndDropWidget(dragAndDropWidget) + mDragAndDrop(dragAndDrop) { setText("_Main", "Name of Container"); //center(); adjustWindowCaption(); getWidget(mContainerWidget, "Items"); - - mIsOnDragAndDrop = false; - mDraggedWidget = 0; + mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onContainerClicked); //getWidget(takeButton, "TakeButton"); //getWidget(closeButton, "CloseButton"); @@ -151,7 +147,7 @@ void ContainerWindow::open(MWWorld::Ptr& container) if(iter->getRefData().getCount() > 1) text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); - //mContainerWidgets.push_back(image); + //mContainerWidgets int pos = path.rfind("."); path.erase(pos); @@ -168,37 +164,56 @@ void ContainerWindow::open(MWWorld::Ptr& container) void ContainerWindow::Update() { - if(mIsOnDragAndDrop) + if(mDragAndDrop->mIsOnDragAndDrop) { - if(mDraggedWidget) - mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); - else mIsOnDragAndDrop = false; //If this happens, there is a bug. + if(mDragAndDrop->mDraggedWidget) + mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); + else mDragAndDrop->mIsOnDragAndDrop = false; //If this happens, there is a bug. } } void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) { - mEnvironment.mWindowManager->setGuiMode(GM_Game); - - setVisible(false); + if(!mDragAndDrop->mIsOnDragAndDrop) + { + mEnvironment.mWindowManager->setGuiMode(GM_Game); + setVisible(false); + } } void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender) { - mIsOnDragAndDrop = true; - _sender->detachFromWidget(); - _sender->attachToWidget(mDragAndDropWidget); - //std::cout << mContainerWidget->getParent()->getParent()->getName(); - _sender->setUserString("drag","on"); - mDraggedWidget = _sender; - std::cout << "selected!"; + if(!mDragAndDrop->mIsOnDragAndDrop) + { + mDragAndDrop->mIsOnDragAndDrop = true; + _sender->detachFromWidget(); + _sender->attachToWidget(mDragAndDrop->mDragAndDropWidget); + //std::cout << mContainerWidget->getParent()->getParent()->getName(); + _sender->setUserString("drag","on"); + mDragAndDrop->mDraggedWidget = _sender; + mDragAndDrop->mContainerWindow = const_cast(this); + std::cout << "selected!"; + } } void ContainerWindow::onMouseMove(MyGUI::Widget* _sender, int _left, int _top) { /*if(_sender->getUserString("drag") == "on") { - _sender->setPosition(_left,_top); - + _sender->setPosition(_left,_top); + }*/ +} + +void ContainerWindow::onContainerClicked(MyGUI::Widget* _sender) +{ + std::cout << "container clicked"; + if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here + { + mDragAndDrop->mIsOnDragAndDrop = false; + mDragAndDrop->mDraggedWidget->detachFromWidget(); + mDragAndDrop->mDraggedWidget->attachToWidget(mContainerWidget); + mDragAndDrop->mDraggedWidget = 0; + mDragAndDrop->mContainerWindow = 0; + } } \ No newline at end of file diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 2d1aa3ac0..742bb06f0 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -18,47 +18,54 @@ namespace MWWorld namespace MyGUI { - class Gui; - class Widget; + class Gui; + class Widget; } namespace MWGui { class WindowManager; + class ContainerWindow; } namespace MWGui { - + class DragAndDrop + { + public: + bool mIsOnDragAndDrop; + ContainerWindow* mContainerWindow; + MyGUI::Widget* mDraggedWidget; + MyGUI::Widget* mDragAndDropWidget; + }; class ContainerWindow : public WindowBase { - public: - ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget); - ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget, - std::string guiFile); + public: + ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop); + ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop, + std::string guiFile); - void open(MWWorld::Ptr& container); - void setName(std::string contName); - void Update(); + void open(MWWorld::Ptr& container); + void setName(std::string contName); + void Update(); - virtual ~ContainerWindow(); + virtual ~ContainerWindow(); - protected: + protected: MWWorld::Environment& mEnvironment; std::vector mContainerWidgets; MyGUI::ItemBoxPtr mContainerWidget; MyGUI::ButtonPtr takeButton; MyGUI::ButtonPtr closeButton; - MyGUI::Widget* mDragAndDropWidget; - bool mIsOnDragAndDrop; - MyGUI::Widget* mDraggedWidget; + DragAndDrop* mDragAndDrop; void onByeClicked(MyGUI::Widget* _sender); void onSelectedItem(MyGUI::Widget* _sender); + void onContainerClicked(MyGUI::Widget* _sender); void onMouseMove(MyGUI::Widget* _sender, int _left, int _top); //MWWorld::Ptr& mContainer; diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index efc9106e9..cf2cfb537 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -21,8 +21,8 @@ namespace MWGui { - InventoryWindow::InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget) - :ContainerWindow(parWindowManager,environment,dragAndDropWidget,"openmw_inventory_window_layout.xml") + InventoryWindow::InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop) + :ContainerWindow(parWindowManager,environment,dragAndDrop,"openmw_inventory_window_layout.xml") { } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index c60889d73..184cab183 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -24,7 +24,7 @@ namespace MWGui class InventoryWindow : public MWGui::ContainerWindow { public: - InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,MyGUI::Widget* dragAndDropWidget); + InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop); void openInventory(); }; diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index f2adfe1e1..9db7892e2 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -36,7 +36,7 @@ WindowManager::WindowManager(MWWorld::Environment& environment, , mMessageBoxManager(NULL) , console(NULL) , mJournal(NULL) - , dialogueWindow(nullptr) + , mDialogueWindow(nullptr) , mCharGen(NULL) , playerClass() , playerName() @@ -77,6 +77,12 @@ WindowManager::WindowManager(MWWorld::Environment& environment, MyGUI::Widget* dragAndDropWidget = gui->createWidgetT("Widget","",0,0,w,h,MyGUI::Align::Default,"DragAndDrop","DragAndDropWidget"); dragAndDropWidget->setVisible(false); + DragAndDrop* mDragAndDrop = new DragAndDrop(); + mDragAndDrop->mIsOnDragAndDrop = false; + mDragAndDrop->mDraggedWidget = 0; + mDragAndDrop->mDragAndDropWidget = dragAndDropWidget; + mDragAndDrop->mContainerWindow = 0; + hud = new HUD(w,h, showFPSLevel); menu = new MainMenu(w,h); map = new MapWindow(*this); @@ -84,9 +90,9 @@ WindowManager::WindowManager(MWWorld::Environment& environment, console = new Console(w,h, environment, extensions); mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); - dialogueWindow = new DialogueWindow(*this,environment); - containerWindow = new ContainerWindow(*this,environment,dragAndDropWidget); - mInventoryWindow = new InventoryWindow(*this,environment,dragAndDropWidget); + mDialogueWindow = new DialogueWindow(*this,environment); + mContainerWindow = new ContainerWindow(*this,environment,mDragAndDrop); + mInventoryWindow = new InventoryWindow(*this,environment,mDragAndDrop); // The HUD is always on hud->setVisible(true); @@ -124,10 +130,11 @@ WindowManager::~WindowManager() delete menu; delete stats; delete mJournal; - delete dialogueWindow; - delete containerWindow; + delete mDialogueWindow; + delete mContainerWindow; delete mInventoryWindow; delete mCharGen; + delete mDragAndDrop; cleanupGarbage(); } @@ -186,8 +193,8 @@ void WindowManager::updateVisible() stats->setVisible(false); console->disable(); mJournal->setVisible(false); - dialogueWindow->setVisible(false); - containerWindow->setVisible(false); + mDialogueWindow->setVisible(false); + mContainerWindow->setVisible(false); mInventoryWindow->setVisible(false); // Mouse is visible whenever we're not in game mode @@ -229,12 +236,12 @@ void WindowManager::updateVisible() break; } case GM_Container: - containerWindow->setVisible(true); + mContainerWindow->setVisible(true); mInventoryWindow->setVisible(true); mInventoryWindow->openInventory(); break; case GM_Dialogue: - dialogueWindow->open(); + mDialogueWindow->open(); break; case GM_InterMessageBox: if(!mMessageBoxManager->isInteractiveMessageBox()) { @@ -413,11 +420,11 @@ const std::string &WindowManager::getGameSettingString(const std::string &id, co void WindowManager::onDialogueWindowBye() { - if (dialogueWindow) + if (mDialogueWindow) { //FIXME set some state and stuff? //removeDialog(dialogueWindow); - dialogueWindow->setVisible(false); + mDialogueWindow->setVisible(false); } setGuiMode(GM_Game); } @@ -426,7 +433,7 @@ void WindowManager::onFrame (float frameDuration) { mMessageBoxManager->onFrame(frameDuration); mInventoryWindow->Update(); - containerWindow->Update(); + mContainerWindow->Update(); } const ESMS::ESMStore& WindowManager::getStore() const diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 438a99a0e..a666b5854 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -63,6 +63,7 @@ namespace MWGui class JournalWindow; class CharacterCreation; class ContainerWindow; + class DragAndDrop; class InventoryWindow; class TextInputDialog; class InfoBoxDialog; @@ -126,9 +127,9 @@ namespace MWGui updateVisible(); } - MWGui::DialogueWindow* getDialogueWindow() {return dialogueWindow;} + MWGui::DialogueWindow* getDialogueWindow() {return mDialogueWindow;} - MWGui::ContainerWindow* getContainerWindow() {return containerWindow;} + MWGui::ContainerWindow* getContainerWindow() {return mContainerWindow;} MyGUI::Gui* getGui() const { return gui; } @@ -203,8 +204,9 @@ namespace MWGui MessageBoxManager *mMessageBoxManager; Console *console; JournalWindow* mJournal; - DialogueWindow *dialogueWindow; - ContainerWindow *containerWindow; + DialogueWindow *mDialogueWindow; + ContainerWindow *mContainerWindow; + DragAndDrop* mDragAndDrop; InventoryWindow *mInventoryWindow; CharacterCreation* mCharGen; From 60ad6f01d40af09443868ed9019173db460ea850 Mon Sep 17 00:00:00 2001 From: gugus Date: Sun, 6 May 2012 11:04:07 +0200 Subject: [PATCH 015/118] another step towards drand and drop. --- apps/openmw/mwgui/container.cpp | 104 ++++++++++++++++++++++---------- apps/openmw/mwgui/container.hpp | 8 +++ 2 files changed, 81 insertions(+), 31 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index d5eb8cff7..083ce2f64 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -22,12 +22,29 @@ using namespace MWGui; using namespace Widgets; +class ItemWidget: public MyGUI::ImageBox +{ +public: + ItemWidget() + :ImageBox() + { + } + virtual ~ItemWidget() + { + } + + void setPtr(MWWorld::Ptr &ptr,int pos){mPtr = ptr;mPos = pos;} + + MWWorld::Ptr mPtr; + int mPos; +}; ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop) : WindowBase("openmw_container_window_layout.xml", parWindowManager), mEnvironment(environment), - mDragAndDrop(dragAndDrop) + mDragAndDrop(dragAndDrop), + mContainer() { setText("_Main", "Name of Container"); @@ -52,7 +69,8 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop,std::string guiFile) : WindowBase(guiFile, parWindowManager), mEnvironment(environment), - mDragAndDrop(dragAndDrop) + mDragAndDrop(dragAndDrop), + mContainer() { setText("_Main", "Name of Container"); //center(); @@ -81,11 +99,18 @@ void ContainerWindow::setName(std::string contName) void ContainerWindow::open(MWWorld::Ptr& container) { + mContainer = container; setName(MWWorld::Class::get(container).getName(container)); //MWWorld::ContainerStore* containerStore = container.getContainerStore(); + drawItems(); + setVisible(true); +} - MWWorld::ContainerStore& containerStore = MWWorld::Class::get(container).getContainerStore(container); - +void ContainerWindow::drawItems() +{ + MyGUI::Gui::getInstance().destroyWidgets(mContainerWidget->getEnumerator()); + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); + //mContainerWidget-> /*MWWorld::ManualRef furRef (mWindowManager.getStore(), "fur_cuirass"); furRef.getPtr().getRefData().setCount (5); @@ -121,45 +146,45 @@ void ContainerWindow::open(MWWorld::Ptr& container) // ESMS::LiveCellRef *ref = iter->get(); - int x = 4; int y = 4; int count = 0; + for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) { - std::string path = std::string("icons\\"); - path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); count++; - - MyGUI::ImageBox* image = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); - MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); - image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); - //image->eventMouseMove += MyGUI::newDelegate(this,&ContainerWindow::onMouseMove); - x += 36; - if(count % 20 == 0) + if(iter->getRefData().getCount() > 0) { + std::string path = std::string("icons\\"); + path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); + ItemWidget* image = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); + MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); + image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); + //image->setPtr(*iter,count); + image->mPos = count; + + //image->mPtr = *iter; + //image->eventMouseMove += MyGUI::newDelegate(this,&ContainerWindow::onMouseMove); + /*x += 36; + if(count % 20 == 0) + { y += 36; x = 4; count = 0; + }*/ + + if(iter->getRefData().getCount() > 1) + text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); + //mContainerWidgets + + int pos = path.rfind("."); + path.erase(pos); + path.append(".dds"); + //std::cout << path << std::endl; + image->setImageTexture(path); } - - if(iter->getRefData().getCount() > 1) - text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); - - //mContainerWidgets - - int pos = path.rfind("."); - path.erase(pos); - path.append(".dds"); - //std::cout << path << std::endl; - image->setImageTexture(path); - } - - - - - setVisible(true); + } } void ContainerWindow::Update() @@ -188,10 +213,26 @@ void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender) mDragAndDrop->mIsOnDragAndDrop = true; _sender->detachFromWidget(); _sender->attachToWidget(mDragAndDrop->mDragAndDropWidget); + + ItemWidget* item = static_cast(_sender); + + int count = 0; + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); + for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) + { + count++; + if(count == item->mPos) + { + iter->getRefData().setCount(0); + break; + } + } + //containerStore. //std::cout << mContainerWidget->getParent()->getParent()->getName(); _sender->setUserString("drag","on"); mDragAndDrop->mDraggedWidget = _sender; mDragAndDrop->mContainerWindow = const_cast(this); + drawItems(); std::cout << "selected!"; } } @@ -210,6 +251,7 @@ void ContainerWindow::onContainerClicked(MyGUI::Widget* _sender) std::cout << "container clicked"; if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here { + //mContainer.getContainerStore()->add(mDragAndDrop->mDraggedWidget-> mDragAndDrop->mIsOnDragAndDrop = false; mDragAndDrop->mDraggedWidget->detachFromWidget(); mDragAndDrop->mDraggedWidget->attachToWidget(mContainerWidget); diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 742bb06f0..b8f76a355 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -10,6 +10,7 @@ #include "window_base.hpp" #include "../mwworld/ptr.hpp" #include "../mwworld/containerstore.hpp" +#include namespace MWWorld { @@ -38,6 +39,8 @@ namespace MWGui ContainerWindow* mContainerWindow; MyGUI::Widget* mDraggedWidget; MyGUI::Widget* mDragAndDropWidget; + + MWWorld::Ptr mItem; }; class ContainerWindow : public WindowBase @@ -63,6 +66,11 @@ namespace MWGui MyGUI::ButtonPtr closeButton; DragAndDrop* mDragAndDrop; + MWWorld::Ptr mContainer; + bool mIsValid;//is in the right GUI Mode + + void drawItems(); + void onByeClicked(MyGUI::Widget* _sender); void onSelectedItem(MyGUI::Widget* _sender); void onContainerClicked(MyGUI::Widget* _sender); From e9134717d62c95b6d16c2c8e515516a5a372c136 Mon Sep 17 00:00:00 2001 From: gugus Date: Tue, 8 May 2012 12:59:47 +0200 Subject: [PATCH 016/118] the GUI part of drag and drop is working --- apps/openmw/mwgui/container.cpp | 42 ++++++++++------------------ apps/openmw/mwgui/itemwidget.hpp | 18 ++++++++++++ apps/openmw/mwgui/window_manager.cpp | 2 ++ 3 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 apps/openmw/mwgui/itemwidget.hpp diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 083ce2f64..454dd05c3 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -18,26 +18,11 @@ #include #include "../mwworld/class.hpp" #include "../mwinput/inputmanager.hpp" +#include "itemwidget.hpp" using namespace MWGui; using namespace Widgets; -class ItemWidget: public MyGUI::ImageBox -{ -public: - ItemWidget() - :ImageBox() - { - } - virtual ~ItemWidget() - { - } - - void setPtr(MWWorld::Ptr &ptr,int pos){mPtr = ptr;mPos = pos;} - - MWWorld::Ptr mPtr; - int mPos; -}; ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop) @@ -149,39 +134,36 @@ void ContainerWindow::drawItems() int x = 4; int y = 4; int count = 0; - + int index = 0; for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) { - count++; + index++; if(iter->getRefData().getCount() > 0) { + count++; std::string path = std::string("icons\\"); path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); ItemWidget* image = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); - //image->setPtr(*iter,count); - image->mPos = count; - - //image->mPtr = *iter; + image->mPos = index; + image->mPtr = *iter; //image->eventMouseMove += MyGUI::newDelegate(this,&ContainerWindow::onMouseMove); - /*x += 36; + x += 36; if(count % 20 == 0) { y += 36; x = 4; count = 0; - }*/ + } if(iter->getRefData().getCount() > 1) text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); - //mContainerWidgets int pos = path.rfind("."); path.erase(pos); path.append(".dds"); - //std::cout << path << std::endl; image->setImageTexture(path); } } @@ -251,7 +233,13 @@ void ContainerWindow::onContainerClicked(MyGUI::Widget* _sender) std::cout << "container clicked"; if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here { - //mContainer.getContainerStore()->add(mDragAndDrop->mDraggedWidget-> + ItemWidget* item = static_cast(mDragAndDrop->mDraggedWidget); + std::cout << item->mPos << item->mPtr.getTypeName(); + if(item->mPtr.getContainerStore() == 0) std::cout << "nocontainer!"; + std::cout << item->mPtr.getContainerStore()->getType(item->mPtr); + MWWorld::Ptr ptr = item->mPtr; + //MWWorld::World + //mContainer.getContainerStore()->add(item->mPtr); mDragAndDrop->mIsOnDragAndDrop = false; mDragAndDrop->mDraggedWidget->detachFromWidget(); mDragAndDrop->mDraggedWidget->attachToWidget(mContainerWidget); diff --git a/apps/openmw/mwgui/itemwidget.hpp b/apps/openmw/mwgui/itemwidget.hpp new file mode 100644 index 000000000..ff65bfd4d --- /dev/null +++ b/apps/openmw/mwgui/itemwidget.hpp @@ -0,0 +1,18 @@ +#ifndef MWGUI_ITEM_WIDGET_H +#define MWGUI_ITEM_WIDGET_H +#include +#include "../mwworld/ptr.hpp" + +namespace MWGui +{ + class ItemWidget: public MyGUI::ImageBox + { + MYGUI_RTTI_DERIVED( ItemWidget ) + public: + + MWWorld::Ptr mPtr; + int mPos; + }; +} + +#endif \ No newline at end of file diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 9db7892e2..e72f635bf 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -9,6 +9,7 @@ #include "messagebox.hpp" #include "container.hpp" #include "inventorywindow.hpp" +#include "itemwidget.hpp" #include "../mwmechanics/mechanicsmanager.hpp" #include "../mwinput/inputmanager.hpp" @@ -68,6 +69,7 @@ WindowManager::WindowManager(MWWorld::Environment& environment, //Register own widgets with MyGUI MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); // Get size info from the Gui object assert(gui); From 9dd65dce30b4910b11d1b89f66d2bed10c06d0c3 Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 11 May 2012 11:52:07 +0200 Subject: [PATCH 017/118] Finished merging. --- apps/openmw/mwgui/container.cpp | 10 ++++------ apps/openmw/mwgui/container.hpp | 5 ++--- apps/openmw/mwgui/inventorywindow.cpp | 8 ++++---- apps/openmw/mwgui/inventorywindow.hpp | 2 +- apps/openmw/mwgui/tooltips.cpp | 2 +- apps/openmw/mwgui/window_manager.cpp | 6 +++--- apps/openmw/mwrender/objects.cpp | 4 ++-- apps/openmw/mwworld/actionopen.cpp | 8 ++++---- apps/openmw/mwworld/actionopen.hpp | 2 +- 9 files changed, 22 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 454dd05c3..b4f38b4e1 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -5,7 +5,7 @@ #include "window_manager.hpp" #include "widgets.hpp" -#include "../mwworld/environment.hpp" +#include "../mwbase/environment.hpp" #include "../mwworld/manualref.hpp" #include #include @@ -25,9 +25,8 @@ using namespace MWGui; using namespace Widgets; -ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop) +ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) : WindowBase("openmw_container_window_layout.xml", parWindowManager), - mEnvironment(environment), mDragAndDrop(dragAndDrop), mContainer() { @@ -51,9 +50,8 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Enviro //mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); } -ContainerWindow::ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop,std::string guiFile) +ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop,std::string guiFile) : WindowBase(guiFile, parWindowManager), - mEnvironment(environment), mDragAndDrop(dragAndDrop), mContainer() { @@ -183,7 +181,7 @@ void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) { if(!mDragAndDrop->mIsOnDragAndDrop) { - mEnvironment.mWindowManager->setGuiMode(GM_Game); + MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game); setVisible(false); } } diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index b8f76a355..08ac7eba2 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -46,8 +46,8 @@ namespace MWGui class ContainerWindow : public WindowBase { public: - ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop); - ContainerWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop, + ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); + ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop, std::string guiFile); @@ -58,7 +58,6 @@ namespace MWGui virtual ~ContainerWindow(); protected: - MWWorld::Environment& mEnvironment; std::vector mContainerWidgets; MyGUI::ItemBoxPtr mContainerWidget; diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index cf2cfb537..3ae2ee9eb 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -4,7 +4,7 @@ #include "window_manager.hpp" #include "widgets.hpp" -#include "../mwworld/environment.hpp" +#include "../mwbase/environment.hpp" #include "../mwworld/manualref.hpp" #include #include @@ -21,14 +21,14 @@ namespace MWGui { - InventoryWindow::InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop) - :ContainerWindow(parWindowManager,environment,dragAndDrop,"openmw_inventory_window_layout.xml") + InventoryWindow::InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) + :ContainerWindow(parWindowManager,dragAndDrop,"openmw_inventory_window_layout.xml") { } void InventoryWindow::openInventory() { - open(mEnvironment.mWorld->getPlayer().getPlayer()); + open(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); } } \ No newline at end of file diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 184cab183..21f27b12f 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -24,7 +24,7 @@ namespace MWGui class InventoryWindow : public MWGui::ContainerWindow { public: - InventoryWindow(WindowManager& parWindowManager,MWWorld::Environment& environment,DragAndDrop* dragAndDrop); + InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); void openInventory(); }; diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 9d7a7ee87..757563efa 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -165,7 +165,7 @@ void ToolTips::findImageExtension(std::string& image) } } -IntSize ToolTips::createToolTip(const ToolTipInfo& info) +IntSize ToolTips::createToolTip(const MWGui::ToolTipInfo& info) { std::string caption = info.caption; std::string image = info.icon; diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index ccd51d9db..db5a51f0c 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -95,9 +95,9 @@ WindowManager::WindowManager( console = new Console(w,h, extensions); mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); - mDialogueWindow = new DialogueWindow(*this,environment); - mContainerWindow = new ContainerWindow(*this,environment,mDragAndDrop); - mInventoryWindow = new InventoryWindow(*this,environment,mDragAndDrop); + mDialogueWindow = new DialogueWindow(*this); + mContainerWindow = new ContainerWindow(*this,mDragAndDrop); + mInventoryWindow = new InventoryWindow(*this,mDragAndDrop); mToolTips = new ToolTips(this); // The HUD is always on diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 27c3f818e..b9efcd3f5 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -219,7 +219,7 @@ void Objects::insertLight (const MWWorld::Ptr& ptr, float r, float g, float b, f info.type = LT_Normal; // random starting phase for the animation - info.time = Ogre::Math::RangeRandom(0, 2 * M_PI); + info.time = Ogre::Math::RangeRandom(0, 2 * Ogre::Math::PI); // adjust the lights depending if we're in an interior or exterior cell // quadratic means the light intensity falls off quite fast, resulting in a @@ -367,7 +367,7 @@ void Objects::update(const float dt) // Light animation (pulse & flicker) it->time += dt; - const float phase = std::fmod(static_cast (it->time), (32 * 2 * M_PI)) * 20; + const float phase = std::fmod(static_cast (it->time), static_cast(32 * 2 * Ogre::Math::PI)) * 20; float pulseConstant; // These formulas are just guesswork, but they work pretty well diff --git a/apps/openmw/mwworld/actionopen.cpp b/apps/openmw/mwworld/actionopen.cpp index e245989d7..e450585e6 100644 --- a/apps/openmw/mwworld/actionopen.cpp +++ b/apps/openmw/mwworld/actionopen.cpp @@ -1,6 +1,6 @@ #include "actionopen.hpp" -#include "environment.hpp" +#include "../mwbase/environment.hpp" #include "class.hpp" #include "world.hpp" #include "containerstore.hpp" @@ -14,9 +14,9 @@ namespace MWWorld mContainer = container; } - void ActionOpen::execute (Environment& environment) + void ActionOpen::execute () { - environment.mWindowManager->setGuiMode(MWGui::GM_Container); - environment.mWindowManager->getContainerWindow()->open(mContainer); + MWBase::Environment::get().getWindowManager()->setGuiMode(MWGui::GM_Container); + MWBase::Environment::get().getWindowManager()->getContainerWindow()->open(mContainer); } } diff --git a/apps/openmw/mwworld/actionopen.hpp b/apps/openmw/mwworld/actionopen.hpp index 7c660e4c9..eff26c78c 100644 --- a/apps/openmw/mwworld/actionopen.hpp +++ b/apps/openmw/mwworld/actionopen.hpp @@ -15,7 +15,7 @@ namespace MWWorld public: ActionOpen (const Ptr& container); ///< \param The Container the Player has activated. - virtual void execute (Environment& environment); + virtual void execute (); }; } From cfb7aa4343e17fc810e0be72da1c965e72bd9673 Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 11 May 2012 12:50:30 +0200 Subject: [PATCH 018/118] Drag and drop works. There is a bug with item count when doing d&d. Clean-up time :p --- apps/openmw/mwgui/container.cpp | 11 ++++++----- apps/openmw/mwgui/container.hpp | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index b4f38b4e1..fd69e1a65 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -203,6 +203,7 @@ void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender) count++; if(count == item->mPos) { + mDragAndDrop->mStore.add(*iter); iter->getRefData().setCount(0); break; } @@ -232,16 +233,16 @@ void ContainerWindow::onContainerClicked(MyGUI::Widget* _sender) if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here { ItemWidget* item = static_cast(mDragAndDrop->mDraggedWidget); - std::cout << item->mPos << item->mPtr.getTypeName(); + std::cout << item->mPos << (*mDragAndDrop->mStore.begin()).getTypeName(); if(item->mPtr.getContainerStore() == 0) std::cout << "nocontainer!"; - std::cout << item->mPtr.getContainerStore()->getType(item->mPtr); - MWWorld::Ptr ptr = item->mPtr; - //MWWorld::World - //mContainer.getContainerStore()->add(item->mPtr); + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); + containerStore.add(*mDragAndDrop->mStore.begin()); + mDragAndDrop->mStore.clear(); mDragAndDrop->mIsOnDragAndDrop = false; mDragAndDrop->mDraggedWidget->detachFromWidget(); mDragAndDrop->mDraggedWidget->attachToWidget(mContainerWidget); mDragAndDrop->mDraggedWidget = 0; mDragAndDrop->mContainerWindow = 0; + drawItems(); } } \ No newline at end of file diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 08ac7eba2..0d047bacf 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -39,7 +39,7 @@ namespace MWGui ContainerWindow* mContainerWindow; MyGUI::Widget* mDraggedWidget; MyGUI::Widget* mDragAndDropWidget; - + MWWorld::ContainerStore mStore; MWWorld::Ptr mItem; }; From 007a202debacd911a918a96f6cc40bf03158abe3 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 11 May 2012 16:34:36 +0200 Subject: [PATCH 019/118] cleanup 1 --- apps/openmw/mwgui/container.cpp | 2 +- apps/openmw/mwgui/container.hpp | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index b040f9d7a..8c3625468 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -180,7 +180,7 @@ void ContainerWindow::Update() } } -void ContainerWindow::onByeClicked(MyGUI::Widget* _sender) +void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender) { if(!mDragAndDrop->mIsOnDragAndDrop) { diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 33a12968b..607138f96 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -69,12 +69,10 @@ namespace MWGui void drawItems(); - void onByeClicked(MyGUI::Widget* _sender); + void onCloseButtonClicked(MyGUI::Widget* _sender); void onSelectedItem(MyGUI::Widget* _sender); void onContainerClicked(MyGUI::Widget* _sender); void onMouseMove(MyGUI::Widget* _sender, int _left, int _top); - - //MWWorld::Ptr& mContainer; }; } #endif // CONTAINER_H From 3a6fde5039dcfc4dfc5c8525ebff075db93e94d3 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 11 May 2012 16:58:07 +0200 Subject: [PATCH 020/118] cleanup 2 --- apps/openmw/mwgui/container.cpp | 58 ++++++++++--------- apps/openmw/mwgui/container.hpp | 1 + .../mygui/openmw_container_window_layout.xml | 16 +---- 3 files changed, 36 insertions(+), 39 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 7daa28775..b46dfdf53 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -1,24 +1,24 @@ #include "container.hpp" -#include -#include #include "window_manager.hpp" #include "widgets.hpp" +#include "itemwidget.hpp" #include "../mwbase/environment.hpp" #include "../mwworld/manualref.hpp" +#include "../mwworld/world.hpp" +#include "../mwworld/containerstore.hpp" +#include "../mwworld/class.hpp" +#include "../mwclass/container.hpp" +#include "../mwinput/inputmanager.hpp" + #include #include #include - #include #include -#include "../mwclass/container.hpp" -#include "../mwworld/containerstore.hpp" + #include -#include "../mwworld/class.hpp" -#include "../mwinput/inputmanager.hpp" -#include "itemwidget.hpp" using namespace MWGui; @@ -32,22 +32,26 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dr { setText("_Main", "Name of Container"); - int w = MyGUI::RenderManager::getInstance().getViewSize().width; - int h = MyGUI::RenderManager::getInstance().getViewSize().height; - setCoord(w-600,h-300,600,300); - //center(); - adjustWindowCaption(); - getWidget(mContainerWidget, "Items"); getWidget(mTakeButton, "TakeButton"); getWidget(mCloseButton, "CloseButton"); mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onCloseButtonClicked); + mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onTakeAllButtonClicked); mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onContainerClicked); - setText("CloseButton","Close"); - setText("TakeButton","Take All"); - //mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); + setText("CloseButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sClose")->str); + setText("TakeButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTakeAll")->str); + + // adjust buttons size to fit text + int closeButtonWidth = mCloseButton->getTextSize().width+24; + int takeButtonWidth = mTakeButton->getTextSize().width+24; + mCloseButton->setCoord(600-20-closeButtonWidth, mCloseButton->getCoord().top, closeButtonWidth, mCloseButton->getCoord().height); + mTakeButton->setCoord(600-20-closeButtonWidth-takeButtonWidth-8, mTakeButton->getCoord().top, takeButtonWidth, mTakeButton->getCoord().height); + + int w = MyGUI::RenderManager::getInstance().getViewSize().width; + int h = MyGUI::RenderManager::getInstance().getViewSize().height; + setCoord(w-600,h-300,600,300); } ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop,std::string guiFile) @@ -56,18 +60,9 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dr mContainer() { setText("_Main", "Name of Container"); - //center(); adjustWindowCaption(); getWidget(mContainerWidget, "Items"); mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onContainerClicked); - //getWidget(takeButton, "TakeButton"); - //getWidget(closeButton, "CloseButton"); - - //closeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onByeClicked); - - //setText("CloseButton","Close"); - //setText("TakeButton","Take All"); - //mContainerWidget->eventMouseItemActivate += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); } ContainerWindow::~ContainerWindow() { @@ -76,6 +71,7 @@ ContainerWindow::~ContainerWindow() void ContainerWindow::setName(std::string contName) { setText("_Main", contName); + adjustWindowCaption(); } @@ -189,6 +185,16 @@ void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender) } } +void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender) +{ + if(!mDragAndDrop->mIsOnDragAndDrop) + { + /// \todo + MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game); + setVisible(false); + } +} + void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender) { if(!mDragAndDrop->mIsOnDragAndDrop) diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index db1f973e7..ad029ae80 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -70,6 +70,7 @@ namespace MWGui void drawItems(); void onCloseButtonClicked(MyGUI::Widget* _sender); + void onTakeAllButtonClicked(MyGUI::Widget* _sender); void onSelectedItem(MyGUI::Widget* _sender); void onContainerClicked(MyGUI::Widget* _sender); void onMouseMove(MyGUI::Widget* _sender, int _left, int _top); diff --git a/files/mygui/openmw_container_window_layout.xml b/files/mygui/openmw_container_window_layout.xml index 31b036468..25156c5a2 100644 --- a/files/mygui/openmw_container_window_layout.xml +++ b/files/mygui/openmw_container_window_layout.xml @@ -3,22 +3,12 @@ - - - - - - - - - + + + From ed6ff0a94ac090d3357ee6885c2f4fb309530db6 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 13:12:37 +0200 Subject: [PATCH 021/118] cleanup 3 --- apps/openmw/mwgui/container.cpp | 304 ++++++++---------- apps/openmw/mwgui/container.hpp | 40 ++- apps/openmw/mwgui/inventorywindow.cpp | 2 +- apps/openmw/mwgui/inventorywindow.hpp | 2 +- .../mygui/openmw_container_window_layout.xml | 9 +- .../mygui/openmw_inventory_window_layout.xml | 9 +- files/mygui/openmw_scroll_skin.xml | 1 - 7 files changed, 173 insertions(+), 194 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index b46dfdf53..b4d369806 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -25,177 +25,23 @@ using namespace MWGui; using namespace Widgets; -ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) - : WindowBase("openmw_container_window_layout.xml", parWindowManager), - mDragAndDrop(dragAndDrop), - mContainer() -{ - setText("_Main", "Name of Container"); - - getWidget(mContainerWidget, "Items"); - getWidget(mTakeButton, "TakeButton"); - getWidget(mCloseButton, "CloseButton"); - - mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onCloseButtonClicked); - mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onTakeAllButtonClicked); - mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onContainerClicked); - - setText("CloseButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sClose")->str); - setText("TakeButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTakeAll")->str); - - // adjust buttons size to fit text - int closeButtonWidth = mCloseButton->getTextSize().width+24; - int takeButtonWidth = mTakeButton->getTextSize().width+24; - mCloseButton->setCoord(600-20-closeButtonWidth, mCloseButton->getCoord().top, closeButtonWidth, mCloseButton->getCoord().height); - mTakeButton->setCoord(600-20-closeButtonWidth-takeButtonWidth-8, mTakeButton->getCoord().top, takeButtonWidth, mTakeButton->getCoord().height); - - int w = MyGUI::RenderManager::getInstance().getViewSize().width; - int h = MyGUI::RenderManager::getInstance().getViewSize().height; - setCoord(w-600,h-300,600,300); -} - -ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop,std::string guiFile) +ContainerBase::ContainerBase(WindowManager& parWindowManager,DragAndDrop* dragAndDrop,std::string guiFile) : WindowBase(guiFile, parWindowManager), mDragAndDrop(dragAndDrop), mContainer() { - setText("_Main", "Name of Container"); - adjustWindowCaption(); getWidget(mContainerWidget, "Items"); - mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onContainerClicked); + getWidget(mItemView, "ItemView"); + + mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerBase::onContainerClicked); + static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &ContainerBase::onWindowResize); } -ContainerWindow::~ContainerWindow() + +ContainerBase::~ContainerBase() { } -void ContainerWindow::setName(std::string contName) -{ - setText("_Main", contName); - adjustWindowCaption(); -} - - - -void ContainerWindow::open(MWWorld::Ptr container) -{ - mContainer = container; - setName(MWWorld::Class::get(container).getName(container)); - //MWWorld::ContainerStore* containerStore = container.getContainerStore(); - drawItems(); - setVisible(true); -} - -void ContainerWindow::drawItems() -{ - while (mContainerWidget->getChildCount()) - { - MyGUI::Gui::getInstance().destroyWidget(mContainerWidget->getChildAt(0)); - } - MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); - //mContainerWidget-> - - /*MWWorld::ManualRef furRef (mWindowManager.getStore(), "fur_cuirass"); - furRef.getPtr().getRefData().setCount (5); - MWWorld::ManualRef bukkitRef (mWindowManager.getStore(), "misc_com_bucket_01"); - MWWorld::ManualRef broomRef (mWindowManager.getStore(), "misc_com_broom_01"); - MWWorld::ManualRef goldRef (mWindowManager.getStore(), "gold_100"); - - containerStore.add(furRef.getPtr()); - containerStore.add(furRef.getPtr()); - containerStore.add(furRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(broomRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(bukkitRef.getPtr()); - containerStore.add(goldRef.getPtr());*/ - - - // ESMS::LiveCellRef *ref = iter->get(); - - int x = 4; - int y = 4; - int count = 0; - int index = 0; - - for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) - { - index++; - if(iter->getRefData().getCount() > 0) - { - count++; - std::string path = std::string("icons\\"); - path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); - ItemWidget* image = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); - MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); - image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem); - image->mPos = index; - image->mPtr = *iter; - //image->eventMouseMove += MyGUI::newDelegate(this,&ContainerWindow::onMouseMove); - x += 36; - if(count % 20 == 0) - { - y += 36; - x = 4; - count = 0; - } - - if(iter->getRefData().getCount() > 1) - text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); - - int pos = path.rfind("."); - path.erase(pos); - path.append(".dds"); - image->setImageTexture(path); - } - } -} - -void ContainerWindow::Update() -{ - if(mDragAndDrop->mIsOnDragAndDrop) - { - if(mDragAndDrop->mDraggedWidget) - mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); - else mDragAndDrop->mIsOnDragAndDrop = false; //If this happens, there is a bug. - } -} - -void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender) -{ - if(!mDragAndDrop->mIsOnDragAndDrop) - { - MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game); - setVisible(false); - } -} - -void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender) -{ - if(!mDragAndDrop->mIsOnDragAndDrop) - { - /// \todo - MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game); - setVisible(false); - } -} - -void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender) +void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) { if(!mDragAndDrop->mIsOnDragAndDrop) { @@ -221,22 +67,13 @@ void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender) //std::cout << mContainerWidget->getParent()->getParent()->getName(); _sender->setUserString("drag","on"); mDragAndDrop->mDraggedWidget = _sender; - mDragAndDrop->mContainerWindow = const_cast(this); + mDragAndDrop->mContainerWindow = const_cast(this); drawItems(); std::cout << "selected!"; } } -void ContainerWindow::onMouseMove(MyGUI::Widget* _sender, int _left, int _top) -{ - /*if(_sender->getUserString("drag") == "on") - { - _sender->setPosition(_left,_top); - - }*/ -} - -void ContainerWindow::onContainerClicked(MyGUI::Widget* _sender) +void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) { std::cout << "container clicked"; if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here @@ -255,3 +92,124 @@ void ContainerWindow::onContainerClicked(MyGUI::Widget* _sender) drawItems(); } } + +void ContainerBase::onWindowResize(MyGUI::Window* window) +{ +} + +void ContainerBase::setName(std::string contName) +{ + setText("_Main", contName); + adjustWindowCaption(); +} + +void ContainerBase::open(MWWorld::Ptr container) +{ + mContainer = container; + setName(MWWorld::Class::get(container).getName(container)); + drawItems(); + setVisible(true); +} + +void ContainerBase::drawItems() +{ + while (mContainerWidget->getChildCount()) + { + MyGUI::Gui::getInstance().destroyWidget(mContainerWidget->getChildAt(0)); + } + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); + + int x = 4; + int y = 4; + int count = 0; + int index = 0; + + for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) + { + index++; + if(iter->getRefData().getCount() > 0) + { + count++; + std::string path = std::string("icons\\"); + path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); + ItemWidget* image = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); + MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); + image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerBase::onSelectedItem); + image->mPos = index; + image->mPtr = *iter; + x += 36; + if(count % 20 == 0) + { + y += 36; + x = 4; + count = 0; + } + + if(iter->getRefData().getCount() > 1) + text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); + + int pos = path.rfind("."); + path.erase(pos); + path.append(".dds"); + image->setImageTexture(path); + } + } +} + +void ContainerBase::Update() +{ + if(mDragAndDrop->mIsOnDragAndDrop) + { + if(mDragAndDrop->mDraggedWidget) + mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); + else mDragAndDrop->mIsOnDragAndDrop = false; //If this happens, there is a bug. + } +} + +// ------------------------------------------------------------------------------------------------ + +ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) + : ContainerBase(parWindowManager, dragAndDrop, "openmw_container_window_layout.xml") +{ + getWidget(mTakeButton, "TakeButton"); + getWidget(mCloseButton, "CloseButton"); + + mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onCloseButtonClicked); + mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onTakeAllButtonClicked); + + setText("CloseButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sClose")->str); + setText("TakeButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTakeAll")->str); + + // adjust buttons size to fit text + int closeButtonWidth = mCloseButton->getTextSize().width+24; + int takeButtonWidth = mTakeButton->getTextSize().width+24; + mCloseButton->setCoord(600-20-closeButtonWidth, mCloseButton->getCoord().top, closeButtonWidth, mCloseButton->getCoord().height); + mTakeButton->setCoord(600-20-closeButtonWidth-takeButtonWidth-8, mTakeButton->getCoord().top, takeButtonWidth, mTakeButton->getCoord().height); + + int w = MyGUI::RenderManager::getInstance().getViewSize().width; + int h = MyGUI::RenderManager::getInstance().getViewSize().height; + setCoord(w-600,h-300,600,300); +} + +ContainerWindow::~ContainerWindow() +{ +} + +void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender) +{ + if(!mDragAndDrop->mIsOnDragAndDrop) + { + MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game); + setVisible(false); + } +} + +void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender) +{ + if(!mDragAndDrop->mIsOnDragAndDrop) + { + /// \todo + MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game); + setVisible(false); + } +} diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index ad029ae80..84b63abc8 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -27,6 +27,7 @@ namespace MWGui { class WindowManager; class ContainerWindow; + class ContainerBase; } @@ -36,44 +37,55 @@ namespace MWGui { public: bool mIsOnDragAndDrop; - ContainerWindow* mContainerWindow; + ContainerBase* mContainerWindow; MyGUI::Widget* mDraggedWidget; MyGUI::Widget* mDragAndDropWidget; MWWorld::ContainerStore mStore; MWWorld::Ptr mItem; }; - class ContainerWindow : public WindowBase + class ContainerBase : public WindowBase { public: - ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); - ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop, - std::string guiFile); + ContainerBase(WindowManager& parWindowManager, DragAndDrop* dragAndDrop, std::string guiFile); + virtual ~ContainerBase(); void open(MWWorld::Ptr container); void setName(std::string contName); void Update(); + protected: + MyGUI::ScrollView* mItemView; + MyGUI::Widget* mContainerWidget; + + DragAndDrop* mDragAndDrop; + MWWorld::Ptr mContainer; + + void onSelectedItem(MyGUI::Widget* _sender); + void onContainerClicked(MyGUI::Widget* _sender); + void onWindowResize(MyGUI::Window* window); + + void drawItems(); + }; + + class ContainerWindow : public ContainerBase + { + public: + ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); + virtual ~ContainerWindow(); protected: std::vector mContainerWidgets; - MyGUI::ItemBoxPtr mContainerWidget; - MyGUI::ButtonPtr mTakeButton; - MyGUI::ButtonPtr mCloseButton; - DragAndDrop* mDragAndDrop; + MyGUI::Button* mTakeButton; + MyGUI::Button* mCloseButton; - MWWorld::Ptr mContainer; bool mIsValid;//is in the right GUI Mode - void drawItems(); void onCloseButtonClicked(MyGUI::Widget* _sender); void onTakeAllButtonClicked(MyGUI::Widget* _sender); - void onSelectedItem(MyGUI::Widget* _sender); - void onContainerClicked(MyGUI::Widget* _sender); - void onMouseMove(MyGUI::Widget* _sender, int _left, int _top); }; } #endif // CONTAINER_H diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index cb628ba4a..416be5367 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -22,7 +22,7 @@ namespace MWGui { InventoryWindow::InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) - :ContainerWindow(parWindowManager,dragAndDrop,"openmw_inventory_window_layout.xml") + : ContainerBase(parWindowManager,dragAndDrop,"openmw_inventory_window_layout.xml") { } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 21f27b12f..152f8b0d0 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -21,7 +21,7 @@ namespace MWGui namespace MWGui { - class InventoryWindow : public MWGui::ContainerWindow + class InventoryWindow : public MWGui::ContainerBase { public: InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); diff --git a/files/mygui/openmw_container_window_layout.xml b/files/mygui/openmw_container_window_layout.xml index 25156c5a2..9679519d4 100644 --- a/files/mygui/openmw_container_window_layout.xml +++ b/files/mygui/openmw_container_window_layout.xml @@ -3,8 +3,13 @@ - - + + + + + + + diff --git a/files/mygui/openmw_inventory_window_layout.xml b/files/mygui/openmw_inventory_window_layout.xml index 766cacdb1..40d89f221 100644 --- a/files/mygui/openmw_inventory_window_layout.xml +++ b/files/mygui/openmw_inventory_window_layout.xml @@ -3,7 +3,7 @@ - + @@ -14,7 +14,12 @@ - + + + + + + diff --git a/files/mygui/openmw_scroll_skin.xml b/files/mygui/openmw_scroll_skin.xml index 39437d54e..64e467661 100644 --- a/files/mygui/openmw_scroll_skin.xml +++ b/files/mygui/openmw_scroll_skin.xml @@ -4,7 +4,6 @@ - From 7723044df0009c58beb4fc4a1c00478cf352a147 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 13:30:34 +0200 Subject: [PATCH 022/118] added the item tooltips --- apps/openmw/mwgui/container.cpp | 5 +++-- apps/openmw/mwgui/itemwidget.hpp | 3 +-- apps/openmw/mwgui/tooltips.cpp | 9 ++++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index b4d369806..65df9a9dd 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -80,7 +80,7 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) { ItemWidget* item = static_cast(mDragAndDrop->mDraggedWidget); std::cout << item->mPos << (*mDragAndDrop->mStore.begin()).getTypeName(); - if(item->mPtr.getContainerStore() == 0) std::cout << "nocontainer!"; + if((*item->getUserData()).getContainerStore() == 0) std::cout << "nocontainer!"; MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); containerStore.add(*mDragAndDrop->mStore.begin()); mDragAndDrop->mStore.clear(); @@ -135,8 +135,9 @@ void ContainerBase::drawItems() ItemWidget* image = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerBase::onSelectedItem); + image->setUserString("ToolTipType", "ItemPtr"); + image->setUserData(*iter); image->mPos = index; - image->mPtr = *iter; x += 36; if(count % 20 == 0) { diff --git a/apps/openmw/mwgui/itemwidget.hpp b/apps/openmw/mwgui/itemwidget.hpp index ff65bfd4d..0b204b10e 100644 --- a/apps/openmw/mwgui/itemwidget.hpp +++ b/apps/openmw/mwgui/itemwidget.hpp @@ -10,9 +10,8 @@ namespace MWGui MYGUI_RTTI_DERIVED( ItemWidget ) public: - MWWorld::Ptr mPtr; int mPos; }; } -#endif \ No newline at end of file +#endif diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 7dc1ecba7..baa38f430 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -61,12 +61,14 @@ void ToolTips::onFrame(float frameDuration) else if (type == "Text") { info.text = text; + tooltipSize = createToolTip(info); } else if (type == "CaptionText") { std::string caption = focus->getUserString("ToolTipCaption"); info.caption = caption; info.text = text; + tooltipSize = createToolTip(info); } else if (type == "ImageCaptionText") { @@ -77,8 +79,13 @@ void ToolTips::onFrame(float frameDuration) info.text = text; info.caption = caption; info.icon = image; + tooltipSize = createToolTip(info); + } + else if (type == "ItemPtr") + { + mFocusObject = *focus->getUserData(); + tooltipSize = getToolTipViaPtr(); } - tooltipSize = createToolTip(info); IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24); From d64fccec6fe71e9eca42750edf4043aa17a65c06 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 13:46:03 +0200 Subject: [PATCH 023/118] display the item count in the tooltip --- apps/openmw/mwclass/activator.cpp | 2 +- apps/openmw/mwclass/apparatus.cpp | 2 +- apps/openmw/mwclass/armor.cpp | 2 +- apps/openmw/mwclass/book.cpp | 2 +- apps/openmw/mwclass/clothing.cpp | 2 +- apps/openmw/mwclass/ingredient.cpp | 2 +- apps/openmw/mwclass/light.cpp | 2 +- apps/openmw/mwclass/lockpick.cpp | 2 +- apps/openmw/mwclass/misc.cpp | 2 +- apps/openmw/mwclass/potion.cpp | 2 +- apps/openmw/mwclass/probe.cpp | 2 +- apps/openmw/mwclass/repair.cpp | 2 +- apps/openmw/mwclass/weapon.cpp | 2 +- apps/openmw/mwgui/container.cpp | 11 ++++++----- apps/openmw/mwgui/container.hpp | 3 +-- apps/openmw/mwgui/tooltips.cpp | 8 ++++++++ apps/openmw/mwgui/tooltips.hpp | 3 +++ 17 files changed, 31 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index 6faaacf31..505f61f4c 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -79,7 +79,7 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name; + info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); std::string text; if (MWBase::Environment::get().getWindowManager()->getFullHelp()) diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index 24d08b804..0ce01024d 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -122,7 +122,7 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name; + info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->base->icon; const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 1598085f3..9bd5f03d6 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -220,7 +220,7 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name; + info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->base->icon; std::string text; diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 72ebb4b80..3d8adf014 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -119,7 +119,7 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name; + info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->base->icon; const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 57d5e1a64..e81bb7419 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -188,7 +188,7 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name; + info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->base->icon; const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 7a1cea7ff..c0186da37 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -120,7 +120,7 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name; + info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->base->icon; const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index 49c80b011..d9af2e73f 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -163,7 +163,7 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name; + info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->base->icon; const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index 89cff2855..5bb677646 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -132,7 +132,7 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name; + info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->base->icon; const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 76444318b..70ba16c03 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -138,7 +138,7 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name; + info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->base->icon; const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 51d3fefae..ffc838639 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -122,7 +122,7 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name; + info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->base->icon; const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 5161301e0..1e713f0a5 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -131,7 +131,7 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name; + info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->base->icon; const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index ce68843ed..5666a95a5 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -121,7 +121,7 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name; + info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->base->icon; std::string text; diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index ed31606d0..3865358bd 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -272,7 +272,7 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name; + info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); info.icon = ref->base->icon; const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 65df9a9dd..792010f38 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -34,7 +34,6 @@ ContainerBase::ContainerBase(WindowManager& parWindowManager,DragAndDrop* dragAn getWidget(mItemView, "ItemView"); mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerBase::onContainerClicked); - static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &ContainerBase::onWindowResize); } ContainerBase::~ContainerBase() @@ -93,10 +92,6 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) } } -void ContainerBase::onWindowResize(MyGUI::Window* window) -{ -} - void ContainerBase::setName(std::string contName) { setText("_Main", contName); @@ -190,12 +185,18 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dr int w = MyGUI::RenderManager::getInstance().getViewSize().width; int h = MyGUI::RenderManager::getInstance().getViewSize().height; setCoord(w-600,h-300,600,300); + + static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &ContainerWindow::onWindowResize); } ContainerWindow::~ContainerWindow() { } +void ContainerWindow::onWindowResize(MyGUI::Window* window) +{ +} + void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender) { if(!mDragAndDrop->mIsOnDragAndDrop) diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 84b63abc8..2552922f8 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -63,7 +63,6 @@ namespace MWGui void onSelectedItem(MyGUI::Widget* _sender); void onContainerClicked(MyGUI::Widget* _sender); - void onWindowResize(MyGUI::Window* window); void drawItems(); }; @@ -83,7 +82,7 @@ namespace MWGui bool mIsValid;//is in the right GUI Mode - + void onWindowResize(MyGUI::Window* window); void onCloseButtonClicked(MyGUI::Widget* _sender); void onTakeAllButtonClicked(MyGUI::Widget* _sender); }; diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index baa38f430..aa189b2e8 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -357,6 +357,14 @@ std::string ToolTips::getMiscString(const std::string& text, const std::string& return "\n" + prefix + ": " + text; } +std::string ToolTips::getCountString(const int value) +{ + if (value == 1) + return ""; + else + return " (" + boost::lexical_cast(value) + ")"; +} + void ToolTips::toggleFullHelp() { mFullHelp = !mFullHelp; diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index fafe471a5..d20360a79 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -53,6 +53,9 @@ namespace MWGui static std::string toString(const float value); static std::string toString(const int value); + static std::string getCountString(const int value); + ///< @return blank string if count is 1, or else " (value)" + private: MyGUI::Widget* mDynamicToolTipBox; From 722af60337e4faecc0e13a2ba2eefd8f244eebb7 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 14:01:59 +0200 Subject: [PATCH 024/118] implemented the "Take all" button --- apps/openmw/mwgui/container.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 792010f38..0b264d48c 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -9,6 +9,7 @@ #include "../mwworld/world.hpp" #include "../mwworld/containerstore.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/player.hpp" #include "../mwclass/container.hpp" #include "../mwinput/inputmanager.hpp" @@ -210,7 +211,22 @@ void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender) { if(!mDragAndDrop->mIsOnDragAndDrop) { - /// \todo + // transfer everything into the player's inventory + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); + + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + MWWorld::ContainerStore& playerStore = MWWorld::Class::get(player).getContainerStore(player); + + for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) + { + if(iter->getRefData().getCount() > 0) + { + playerStore.add(*iter); + } + } + + containerStore.clear(); + MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game); setVisible(false); } From a31a9e51d3e3b853ca02db3d667fd417dbf2d5df Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 14:29:49 +0200 Subject: [PATCH 025/118] add the sound for item drag&drop --- apps/openmw/mwclass/misc.cpp | 15 ++++++++++----- apps/openmw/mwgui/container.cpp | 20 ++++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 70ba16c03..936dc4558 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -138,11 +138,18 @@ namespace MWClass ptr.get(); MWGui::ToolTipInfo info; - info.caption = ref->base->name + MWGui::ToolTips::getCountString(ptr.getRefData().getCount()); - info.icon = ref->base->icon; const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); + int count = ptr.getRefData().getCount(); + // gold has count both as reference count and as value, multiply them together to get real count + bool isGold = (ref->base->name == store.gameSettings.search("sGold")->str); + if (isGold) + count *= ref->base->data.value; + + info.caption = ref->base->name + MWGui::ToolTips::getCountString(count); + info.icon = ref->base->icon; + if (ref->ref.soul != "") { const ESM::Creature *creature = store.creatures.search(ref->ref.soul); @@ -151,9 +158,7 @@ namespace MWClass std::string text; - if (ref->base->name == store.gameSettings.search("sGold")->str) - info.caption += " (" + boost::lexical_cast(ref->base->data.value) + ")"; - else + if (!isGold) { 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); diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 0b264d48c..661495559 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -12,6 +12,7 @@ #include "../mwworld/player.hpp" #include "../mwclass/container.hpp" #include "../mwinput/inputmanager.hpp" +#include "../mwsound/soundmanager.hpp" #include #include @@ -53,34 +54,41 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) int count = 0; MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); + MWWorld::Ptr object; for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) { count++; if(count == item->mPos) { mDragAndDrop->mStore.add(*iter); + object = *iter; iter->getRefData().setCount(0); break; } } - //containerStore. - //std::cout << mContainerWidget->getParent()->getParent()->getName(); + + std::string sound = MWWorld::Class::get(object).getUpSoundId(object); + MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); + _sender->setUserString("drag","on"); mDragAndDrop->mDraggedWidget = _sender; mDragAndDrop->mContainerWindow = const_cast(this); drawItems(); - std::cout << "selected!"; } } void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) { - std::cout << "container clicked"; if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here { ItemWidget* item = static_cast(mDragAndDrop->mDraggedWidget); - std::cout << item->mPos << (*mDragAndDrop->mStore.begin()).getTypeName(); - if((*item->getUserData()).getContainerStore() == 0) std::cout << "nocontainer!"; + + MWWorld::Ptr object = *item->getUserData(); + assert(object.getContainerStore() && "Item is not in a container!"); + + std::string sound = MWWorld::Class::get(object).getDownSoundId(object); + MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); containerStore.add(*mDragAndDrop->mStore.begin()); mDragAndDrop->mStore.clear(); From 1abf70692cb2381886e9586a66d766333fbd42b6 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 18:24:47 +0200 Subject: [PATCH 026/118] added a scrollbar to the item container, dynamic positioning of items, fixed the item count display bug --- apps/openmw/mwgui/container.cpp | 24 ++++++++++++------- apps/openmw/mwgui/inventorywindow.cpp | 6 +++++ apps/openmw/mwgui/inventorywindow.hpp | 3 +++ .../mygui/openmw_container_window_layout.xml | 6 ++--- .../mygui/openmw_inventory_window_layout.xml | 2 +- files/mygui/openmw_list.skin.xml | 3 ++- files/mygui/openmw_scroll_skin.xml | 5 ++++ 7 files changed, 35 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 661495559..d79693114 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -125,7 +125,8 @@ void ContainerBase::drawItems() int x = 4; int y = 4; - int count = 0; + int maxHeight = mItemView->getSize().height - 48; + int index = 0; for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) @@ -133,21 +134,21 @@ void ContainerBase::drawItems() index++; if(iter->getRefData().getCount() > 0) { - count++; std::string path = std::string("icons\\"); path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); ItemWidget* image = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); - MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label")); + MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(14, 14, 18, 18), MyGUI::Align::Default, std::string("Label")); + text->setTextAlign(MyGUI::Align::Right); + text->setNeedMouseFocus(false); image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerBase::onSelectedItem); image->setUserString("ToolTipType", "ItemPtr"); image->setUserData(*iter); image->mPos = index; - x += 36; - if(count % 20 == 0) - { y += 36; - x = 4; - count = 0; + if (y > maxHeight) + { + x += 36; + y = 4; } if(iter->getRefData().getCount() > 1) @@ -158,7 +159,11 @@ void ContainerBase::drawItems() path.append(".dds"); image->setImageTexture(path); } - } + } + + MyGUI::IntSize size = MyGUI::IntSize(std::max(mItemView->getSize().width, x), 2048); + mItemView->setCanvasSize(size); + mContainerWidget->setSize(size); } void ContainerBase::Update() @@ -204,6 +209,7 @@ ContainerWindow::~ContainerWindow() void ContainerWindow::onWindowResize(MyGUI::Window* window) { + drawItems(); } void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 416be5367..b85380968 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -24,6 +24,7 @@ namespace MWGui InventoryWindow::InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) : ContainerBase(parWindowManager,dragAndDrop,"openmw_inventory_window_layout.xml") { + static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize); } void InventoryWindow::openInventory() @@ -31,4 +32,9 @@ namespace MWGui open(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); } + void InventoryWindow::onWindowResize(MyGUI::Window* _sender) + { + drawItems(); + } + } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 152f8b0d0..813fc88ab 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -27,6 +27,9 @@ namespace MWGui InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); void openInventory(); + + protected: + void onWindowResize(MyGUI::Window* _sender); }; } #endif // Inventory_H diff --git a/files/mygui/openmw_container_window_layout.xml b/files/mygui/openmw_container_window_layout.xml index 9679519d4..26fe0a3d3 100644 --- a/files/mygui/openmw_container_window_layout.xml +++ b/files/mygui/openmw_container_window_layout.xml @@ -4,10 +4,10 @@ - - + + - + diff --git a/files/mygui/openmw_inventory_window_layout.xml b/files/mygui/openmw_inventory_window_layout.xml index 40d89f221..a347a510e 100644 --- a/files/mygui/openmw_inventory_window_layout.xml +++ b/files/mygui/openmw_inventory_window_layout.xml @@ -15,7 +15,7 @@ - + diff --git a/files/mygui/openmw_list.skin.xml b/files/mygui/openmw_list.skin.xml index 89cc73123..213e8470f 100644 --- a/files/mygui/openmw_list.skin.xml +++ b/files/mygui/openmw_list.skin.xml @@ -131,6 +131,7 @@ + @@ -143,7 +144,7 @@ - + diff --git a/files/mygui/openmw_scroll_skin.xml b/files/mygui/openmw_scroll_skin.xml index 64e467661..70fad3f4b 100644 --- a/files/mygui/openmw_scroll_skin.xml +++ b/files/mygui/openmw_scroll_skin.xml @@ -7,4 +7,9 @@ + + + + + From e714b77df8a5ea34b1b8295688ebe6350832fc2d Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 18:28:14 +0200 Subject: [PATCH 027/118] small fix --- apps/openmw/mwgui/container.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index d79693114..ba9a3213d 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -161,7 +161,7 @@ void ContainerBase::drawItems() } } - MyGUI::IntSize size = MyGUI::IntSize(std::max(mItemView->getSize().width, x), 2048); + MyGUI::IntSize size = MyGUI::IntSize(std::max(mItemView->getSize().width, x), mItemView->getSize().height); mItemView->setCanvasSize(size); mContainerWidget->setSize(size); } From 19e8e84f9ac4224c785a68799c645f7cad276464 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 18:50:19 +0200 Subject: [PATCH 028/118] more cleanup, removed the redundant ItemWidget and use widget userdata --- apps/openmw/mwgui/container.cpp | 68 ++++++++++++---------------- apps/openmw/mwgui/itemwidget.hpp | 17 ------- apps/openmw/mwgui/window_manager.cpp | 2 - 3 files changed, 30 insertions(+), 57 deletions(-) delete mode 100644 apps/openmw/mwgui/itemwidget.hpp diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index ba9a3213d..1f6a6f2f6 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -2,7 +2,6 @@ #include "window_manager.hpp" #include "widgets.hpp" -#include "itemwidget.hpp" #include "../mwbase/environment.hpp" #include "../mwworld/manualref.hpp" @@ -50,22 +49,9 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) _sender->detachFromWidget(); _sender->attachToWidget(mDragAndDrop->mDragAndDropWidget); - ItemWidget* item = static_cast(_sender); - - int count = 0; - MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); - MWWorld::Ptr object; - for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) - { - count++; - if(count == item->mPos) - { - mDragAndDrop->mStore.add(*iter); - object = *iter; - iter->getRefData().setCount(0); - break; - } - } + MWWorld::Ptr object = *_sender->getUserData(); + mDragAndDrop->mStore.add(object); + object.getRefData().setCount(0); std::string sound = MWWorld::Class::get(object).getUpSoundId(object); MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); @@ -81,9 +67,7 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) { if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here { - ItemWidget* item = static_cast(mDragAndDrop->mDraggedWidget); - - MWWorld::Ptr object = *item->getUserData(); + MWWorld::Ptr object = *mDragAndDrop->mDraggedWidget->getUserData(); assert(object.getContainerStore() && "Item is not in a container!"); std::string sound = MWWorld::Class::get(object).getDownSoundId(object); @@ -123,8 +107,8 @@ void ContainerBase::drawItems() } MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); - int x = 4; - int y = 4; + int x = 0; + int y = 0; int maxHeight = mItemView->getSize().height - 48; int index = 0; @@ -136,28 +120,36 @@ void ContainerBase::drawItems() { std::string path = std::string("icons\\"); path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); - ItemWidget* image = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default); - MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(14, 14, 18, 18), MyGUI::Align::Default, std::string("Label")); - text->setTextAlign(MyGUI::Align::Right); - text->setNeedMouseFocus(false); - image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerBase::onSelectedItem); - image->setUserString("ToolTipType", "ItemPtr"); - image->setUserData(*iter); - image->mPos = index; - y += 36; - if (y > maxHeight) - { - x += 36; - y = 4; - } - if(iter->getRefData().getCount() > 1) - text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); + // background widget (for the "equipped" frame and magic item background image) + bool isMagic = (MWWorld::Class::get(*iter).getEnchantment(*iter) != ""); + MyGUI::Widget* backgroundWidget = mContainerWidget->createWidget(isMagic ? "ItemBackgroundMagic" : "ItemBackground", MyGUI::IntCoord(x, y, 42, 42), MyGUI::Align::Default); + backgroundWidget->setUserString("ToolTipType", "ItemPtr"); + backgroundWidget->setUserData(*iter); + backgroundWidget->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerBase::onSelectedItem); + // image + ImageBox* image = backgroundWidget->createWidget("ImageBox", MyGUI::IntCoord(5, 5, 32, 32), MyGUI::Align::Default); int pos = path.rfind("."); path.erase(pos); path.append(".dds"); image->setImageTexture(path); + image->setNeedMouseFocus(false); + + // text widget that shows item count + MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(14, 14, 18, 18), MyGUI::Align::Default, std::string("Label")); + text->setTextAlign(MyGUI::Align::Right); + text->setNeedMouseFocus(false); + + y += 36; + if (y > maxHeight) + { + x += 36; + y = 0; + } + + if(iter->getRefData().getCount() > 1) + text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); } } diff --git a/apps/openmw/mwgui/itemwidget.hpp b/apps/openmw/mwgui/itemwidget.hpp deleted file mode 100644 index 0b204b10e..000000000 --- a/apps/openmw/mwgui/itemwidget.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef MWGUI_ITEM_WIDGET_H -#define MWGUI_ITEM_WIDGET_H -#include -#include "../mwworld/ptr.hpp" - -namespace MWGui -{ - class ItemWidget: public MyGUI::ImageBox - { - MYGUI_RTTI_DERIVED( ItemWidget ) - public: - - int mPos; - }; -} - -#endif diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 95fe3492a..6dfdc3bb4 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -9,7 +9,6 @@ #include "messagebox.hpp" #include "container.hpp" #include "inventorywindow.hpp" -#include "itemwidget.hpp" #include "tooltips.hpp" #include "scrollwindow.hpp" #include "bookwindow.hpp" @@ -77,7 +76,6 @@ WindowManager::WindowManager( //Register own widgets with MyGUI 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 54c23c74224e273dbbe576fd72cbb571e944e4c0 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 19:48:01 +0200 Subject: [PATCH 029/118] show the background texture for enchanted items in inventory/container --- apps/openmw/mwgui/container.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 1f6a6f2f6..e2be9147c 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -59,6 +59,8 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) _sender->setUserString("drag","on"); mDragAndDrop->mDraggedWidget = _sender; mDragAndDrop->mContainerWindow = const_cast(this); + // hide the count text + _sender->getChildAt(0)->getChildAt(0)->setVisible(false); drawItems(); } } @@ -123,9 +125,11 @@ void ContainerBase::drawItems() // background widget (for the "equipped" frame and magic item background image) bool isMagic = (MWWorld::Class::get(*iter).getEnchantment(*iter) != ""); - MyGUI::Widget* backgroundWidget = mContainerWidget->createWidget(isMagic ? "ItemBackgroundMagic" : "ItemBackground", MyGUI::IntCoord(x, y, 42, 42), MyGUI::Align::Default); + MyGUI::ImageBox* backgroundWidget = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 42, 42), MyGUI::Align::Default); backgroundWidget->setUserString("ToolTipType", "ItemPtr"); backgroundWidget->setUserData(*iter); + backgroundWidget->setImageTexture( isMagic ? "textures\\menu_icon_magic.dds" : ""); + backgroundWidget->setProperty("ImageCoord", "0 0 42 42"); backgroundWidget->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerBase::onSelectedItem); // image @@ -137,7 +141,7 @@ void ContainerBase::drawItems() image->setNeedMouseFocus(false); // text widget that shows item count - MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(14, 14, 18, 18), MyGUI::Align::Default, std::string("Label")); + MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(0, 14, 32, 18), MyGUI::Align::Default, std::string("Label")); text->setTextAlign(MyGUI::Align::Right); text->setNeedMouseFocus(false); From f3c88adc0b6f8ff8cb86d49ec6d5ee50cdcd365c Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 20:06:44 +0200 Subject: [PATCH 030/118] items can now also be dropped on another item (and will be placed in container) --- apps/openmw/mwgui/container.cpp | 2 ++ apps/openmw/mwgui/tooltips.cpp | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index e2be9147c..448ae6482 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -63,6 +63,8 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) _sender->getChildAt(0)->getChildAt(0)->setVisible(false); drawItems(); } + else + onContainerClicked(mContainerWidget); } void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index aa189b2e8..67479e3f9 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -29,8 +29,6 @@ ToolTips::ToolTips(WindowManager* windowManager) : void ToolTips::onFrame(float frameDuration) { - /// \todo Store a MWWorld::Ptr in the widget user data, retrieve it here and construct a tooltip dynamically - MyGUI::Gui::getInstance().destroyWidget(mDynamicToolTipBox); mDynamicToolTipBox = mMainWidget->createWidget("HUD_Box", IntCoord(0, 0, mMainWidget->getCoord().width, mMainWidget->getCoord().height), @@ -110,6 +108,7 @@ void ToolTips::onFrame(float frameDuration) // 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) + /// relevant link: http://www.ogre3d.org/tikiwiki/ObjectTextDisplay setCoord(std::max(0, viewSize.width/2 - (tooltipSize.width)/2), std::max(0, viewSize.height/2 - (tooltipSize.height) - 32), tooltipSize.width, From e6e50f4ad41a4b3bc5c1f50661953cdd71de5d98 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 20:14:19 +0200 Subject: [PATCH 031/118] fix items getting cut off --- apps/openmw/mwgui/container.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 448ae6482..84b1582cb 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -147,10 +147,10 @@ void ContainerBase::drawItems() text->setTextAlign(MyGUI::Align::Right); text->setNeedMouseFocus(false); - y += 36; + y += 42; if (y > maxHeight) { - x += 36; + x += 42; y = 0; } @@ -159,7 +159,7 @@ void ContainerBase::drawItems() } } - MyGUI::IntSize size = MyGUI::IntSize(std::max(mItemView->getSize().width, x), mItemView->getSize().height); + MyGUI::IntSize size = MyGUI::IntSize(std::max(mItemView->getSize().width, x+42), mItemView->getSize().height); mItemView->setCanvasSize(size); mContainerWidget->setSize(size); } From 24e54a81bdf91a0b832d613324fcb1f9c7c5ec02 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 20:28:12 +0200 Subject: [PATCH 032/118] don't show icons in the inventory tooltips, exactly like MW does --- apps/openmw/mwgui/tooltips.cpp | 6 ++++-- apps/openmw/mwgui/tooltips.hpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 67479e3f9..7fc29f8c3 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -82,7 +82,7 @@ void ToolTips::onFrame(float frameDuration) else if (type == "ItemPtr") { mFocusObject = *focus->getUserData(); - tooltipSize = getToolTipViaPtr(); + tooltipSize = getToolTipViaPtr(false); } IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24); @@ -134,7 +134,7 @@ void ToolTips::setFocusObject(const MWWorld::Ptr& focus) mFocusObject = focus; } -IntSize ToolTips::getToolTipViaPtr () +IntSize ToolTips::getToolTipViaPtr (bool image) { // this the maximum width of the tooltip before it starts word-wrapping setCoord(0, 0, 300, 300); @@ -151,6 +151,8 @@ IntSize ToolTips::getToolTipViaPtr () mDynamicToolTipBox->setVisible(true); ToolTipInfo info = object.getToolTipInfo(mFocusObject); + if (!image) + info.icon = ""; tooltipSize = createToolTip(info); } diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index d20360a79..8d0970965 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -65,7 +65,7 @@ namespace MWGui void findImageExtension(std::string& image); - MyGUI::IntSize getToolTipViaPtr (); + MyGUI::IntSize getToolTipViaPtr (bool image=true); ///< @return requested tooltip size MyGUI::IntSize createToolTip(const ToolTipInfo& info); From fd18c95c5f812ff86009b8833db23aae3385adf4 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 20:35:50 +0200 Subject: [PATCH 033/118] implemented filters (no gui yet) --- apps/openmw/mwgui/container.cpp | 9 ++++++++- apps/openmw/mwgui/container.hpp | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 84b1582cb..c4407152d 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -29,6 +29,7 @@ using namespace Widgets; ContainerBase::ContainerBase(WindowManager& parWindowManager,DragAndDrop* dragAndDrop,std::string guiFile) : WindowBase(guiFile, parWindowManager), mDragAndDrop(dragAndDrop), + mFilter(MWWorld::ContainerStore::Type_All), mContainer() { getWidget(mContainerWidget, "Items"); @@ -95,6 +96,12 @@ void ContainerBase::setName(std::string contName) adjustWindowCaption(); } +void ContainerBase::setFilter(int filter) +{ + mFilter = filter; + drawItems(); +} + void ContainerBase::open(MWWorld::Ptr container) { mContainer = container; @@ -117,7 +124,7 @@ void ContainerBase::drawItems() int index = 0; - for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) + for (MWWorld::ContainerStoreIterator iter (containerStore.begin(mFilter)); iter!=containerStore.end(); ++iter) { index++; if(iter->getRefData().getCount() > 0) diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 2552922f8..a34d22c77 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -52,6 +52,7 @@ namespace MWGui void open(MWWorld::Ptr container); void setName(std::string contName); + void setFilter(int filter); ///< set category filter void Update(); protected: @@ -61,6 +62,8 @@ namespace MWGui DragAndDrop* mDragAndDrop; MWWorld::Ptr mContainer; + int mFilter; + void onSelectedItem(MyGUI::Widget* _sender); void onContainerClicked(MyGUI::Widget* _sender); From 8e6c9434009d390d055fe154b705c310d8c03696 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 20:39:21 +0200 Subject: [PATCH 034/118] "take all"-button sound (first item) --- apps/openmw/mwgui/container.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index c4407152d..39bd577af 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -236,11 +236,21 @@ void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender) MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWWorld::ContainerStore& playerStore = MWWorld::Class::get(player).getContainerStore(player); + int i=0; for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) { if(iter->getRefData().getCount() > 0) { playerStore.add(*iter); + + if (i==0) + { + // play the sound of the first object + std::string sound = MWWorld::Class::get(*iter).getUpSoundId(*iter); + MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); + } + + ++i; } } From 0114bf948c8d4397a40a509f4d2d88725c9a29ed Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 21:28:04 +0200 Subject: [PATCH 035/118] revised filters --- apps/openmw/mwgui/container.cpp | 30 ++++++++++++++--- apps/openmw/mwgui/container.hpp | 13 ++++++-- apps/openmw/mwgui/inventorywindow.cpp | 11 +++++++ apps/openmw/mwgui/inventorywindow.hpp | 11 +++++++ .../mygui/openmw_container_window_layout.xml | 4 +-- .../mygui/openmw_inventory_window_layout.xml | 32 +++++++++++-------- 6 files changed, 80 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 39bd577af..2de8e2bb3 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -29,7 +29,7 @@ using namespace Widgets; ContainerBase::ContainerBase(WindowManager& parWindowManager,DragAndDrop* dragAndDrop,std::string guiFile) : WindowBase(guiFile, parWindowManager), mDragAndDrop(dragAndDrop), - mFilter(MWWorld::ContainerStore::Type_All), + mFilter(ContainerBase::Filter_All), mContainer() { getWidget(mContainerWidget, "Items"); @@ -96,7 +96,7 @@ void ContainerBase::setName(std::string contName) adjustWindowCaption(); } -void ContainerBase::setFilter(int filter) +void ContainerBase::setFilter(ContainerBase::Filter filter) { mFilter = filter; drawItems(); @@ -124,10 +124,32 @@ void ContainerBase::drawItems() int index = 0; - for (MWWorld::ContainerStoreIterator iter (containerStore.begin(mFilter)); iter!=containerStore.end(); ++iter) + + bool onlyMagic = false; + int categories; + if (mFilter == Filter_All) + categories = MWWorld::ContainerStore::Type_All; + else if (mFilter == Filter_Weapon) + categories = MWWorld::ContainerStore::Type_Weapon; + else if (mFilter == Filter_Apparel) + categories = MWWorld::ContainerStore::Type_Clothing + MWWorld::ContainerStore::Type_Armor; + else if (mFilter == Filter_Magic) + { + categories = MWWorld::ContainerStore::Type_Clothing + MWWorld::ContainerStore::Type_Armor + + MWWorld::ContainerStore::Type_Weapon + MWWorld::ContainerStore::Type_Book + + MWWorld::ContainerStore::Type_Potion; + onlyMagic = true; + } + else if (mFilter == Filter_Misc) + { + categories = MWWorld::ContainerStore::Type_Miscellaneous + MWWorld::ContainerStore::Type_Book + + MWWorld::ContainerStore::Type_Ingredient; + } + + for (MWWorld::ContainerStoreIterator iter (containerStore.begin(categories)); iter!=containerStore.end(); ++iter) { index++; - if(iter->getRefData().getCount() > 0) + if(iter->getRefData().getCount() > 0 && !(onlyMagic && MWWorld::Class::get(*iter).getEnchantment(*iter) == "" && iter->getTypeName() != typeid(ESM::Potion).name())) { std::string path = std::string("icons\\"); path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index a34d22c77..a8c12bb6a 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -50,9 +50,18 @@ namespace MWGui ContainerBase(WindowManager& parWindowManager, DragAndDrop* dragAndDrop, std::string guiFile); virtual ~ContainerBase(); + enum Filter + { + Filter_All = 0x01, + Filter_Weapon = 0x02, + Filter_Apparel = 0x03, + Filter_Magic = 0x04, + Filter_Misc = 0x05 + }; + void open(MWWorld::Ptr container); void setName(std::string contName); - void setFilter(int filter); ///< set category filter + void setFilter(Filter filter); ///< set category filter void Update(); protected: @@ -62,7 +71,7 @@ namespace MWGui DragAndDrop* mDragAndDrop; MWWorld::Ptr mContainer; - int mFilter; + Filter mFilter; void onSelectedItem(MyGUI::Widget* _sender); void onContainerClicked(MyGUI::Widget* _sender); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index b85380968..738ab578a 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -25,11 +25,22 @@ namespace MWGui : ContainerBase(parWindowManager,dragAndDrop,"openmw_inventory_window_layout.xml") { static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize); + + getWidget(mAvatar, "Avatar"); + getWidget(mEncumbranceBar, "EncumbranceBar"); + getWidget(mEncumbranceText, "EncumbranceBarT"); + getWidget(mFilterAll, "AllButton"); + getWidget(mFilterWeapon, "WeaponButton"); + getWidget(mFilterApparel, "ApparelButton"); + getWidget(mFilterMagic, "MagicButton"); + getWidget(mFilterMisc, "MiscButton"); } void InventoryWindow::openInventory() { open(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); + + onWindowResize(static_cast(mMainWidget)); } void InventoryWindow::onWindowResize(MyGUI::Window* _sender) diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 813fc88ab..db105a2f8 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -29,6 +29,17 @@ namespace MWGui void openInventory(); protected: + MyGUI::Widget* mAvatar; + MyGUI::TextBox* mArmorRating; + MyGUI::ProgressBar* mEncumbranceBar; + MyGUI::TextBox* mEncumbranceText; + + MyGUI::Button* mFilterAll; + MyGUI::Button* mFilterWeapon; + MyGUI::Button* mFilterApparel; + MyGUI::Button* mFilterMagic; + MyGUI::Button* mFilterMisc; + void onWindowResize(MyGUI::Window* _sender); }; } diff --git a/files/mygui/openmw_container_window_layout.xml b/files/mygui/openmw_container_window_layout.xml index 26fe0a3d3..7b14f5b58 100644 --- a/files/mygui/openmw_container_window_layout.xml +++ b/files/mygui/openmw_container_window_layout.xml @@ -5,9 +5,9 @@ - + - + diff --git a/files/mygui/openmw_inventory_window_layout.xml b/files/mygui/openmw_inventory_window_layout.xml index a347a510e..b2b32ea2c 100644 --- a/files/mygui/openmw_inventory_window_layout.xml +++ b/files/mygui/openmw_inventory_window_layout.xml @@ -4,30 +4,36 @@ - - + + + + + + - - + + + + - - + + - + - - - - - - + + + + + + From 902309a554f96370f652ec4bb32dd141d7a60815 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 21:44:33 +0200 Subject: [PATCH 036/118] working filters --- apps/openmw/mwclass/book.cpp | 8 +++++ apps/openmw/mwclass/book.hpp | 3 ++ apps/openmw/mwgui/inventorywindow.cpp | 46 +++++++++++++++++++++++++++ apps/openmw/mwgui/inventorywindow.hpp | 1 + 4 files changed, 58 insertions(+) diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 3d8adf014..f58eac7ec 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -140,4 +140,12 @@ namespace MWClass return info; } + + std::string Book::getEnchantment (const MWWorld::Ptr& ptr) const + { + ESMS::LiveCellRef *ref = + ptr.get(); + + return ref->base->enchant; + } } diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp index fd6e38e04..6858bac7f 100644 --- a/apps/openmw/mwclass/book.hpp +++ b/apps/openmw/mwclass/book.hpp @@ -44,6 +44,9 @@ namespace MWClass virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const; ///< Return name of inventory icon. + + virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const; + ///< @return the enchantment ID if the object is enchanted, otherwise an empty string }; } diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 738ab578a..7e02a63e8 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -34,6 +34,38 @@ namespace MWGui getWidget(mFilterApparel, "ApparelButton"); getWidget(mFilterMagic, "MagicButton"); getWidget(mFilterMisc, "MiscButton"); + + mFilterAll->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sAllTab")->str); + mFilterWeapon->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sWeaponTab")->str); + mFilterApparel->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sApparelTab")->str); + mFilterMagic->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sMagicTab")->str); + mFilterMisc->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sMiscTab")->str); + + // adjust size of buttons to fit text + int curX = 0; + mFilterAll->setSize( mFilterAll->getTextSize().width + 24, mFilterAll->getSize().height ); + curX += mFilterAll->getTextSize().width + 24 + 4; + + mFilterWeapon->setPosition(curX, mFilterWeapon->getPosition().top); + mFilterWeapon->setSize( mFilterWeapon->getTextSize().width + 24, mFilterWeapon->getSize().height ); + curX += mFilterWeapon->getTextSize().width + 24 + 4; + + mFilterApparel->setPosition(curX, mFilterApparel->getPosition().top); + mFilterApparel->setSize( mFilterApparel->getTextSize().width + 24, mFilterApparel->getSize().height ); + curX += mFilterApparel->getTextSize().width + 24 + 4; + + mFilterMagic->setPosition(curX, mFilterMagic->getPosition().top); + mFilterMagic->setSize( mFilterMagic->getTextSize().width + 24, mFilterMagic->getSize().height ); + curX += mFilterMagic->getTextSize().width + 24 + 4; + + mFilterMisc->setPosition(curX, mFilterMisc->getPosition().top); + mFilterMisc->setSize( mFilterMisc->getTextSize().width + 24, mFilterMisc->getSize().height ); + + mFilterAll->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); + mFilterWeapon->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); + mFilterApparel->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); + mFilterMagic->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); + mFilterMisc->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); } void InventoryWindow::openInventory() @@ -48,4 +80,18 @@ namespace MWGui drawItems(); } + void InventoryWindow::onFilterChanged(MyGUI::Widget* _sender) + { + if (_sender == mFilterAll) + setFilter(ContainerBase::Filter_All); + else if (_sender == mFilterWeapon) + setFilter(ContainerBase::Filter_Weapon); + else if (_sender == mFilterApparel) + setFilter(ContainerBase::Filter_Apparel); + else if (_sender == mFilterMagic) + setFilter(ContainerBase::Filter_Magic); + else if (_sender == mFilterMisc) + setFilter(ContainerBase::Filter_Misc); + } + } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index db105a2f8..63188e84b 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -41,6 +41,7 @@ namespace MWGui MyGUI::Button* mFilterMisc; void onWindowResize(MyGUI::Window* _sender); + void onFilterChanged(MyGUI::Widget* _sender); }; } #endif // Inventory_H From 822e5fbe1e2c01cfc93079edf7bcffb88b97adab Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 22:00:15 +0200 Subject: [PATCH 037/118] add indication which filter is selected --- apps/openmw/mwgui/inventorywindow.cpp | 10 ++++++++++ files/mygui/openmw_button.skin.xml | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 7e02a63e8..340c03562 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -66,6 +66,8 @@ namespace MWGui mFilterApparel->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); mFilterMagic->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); mFilterMisc->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); + + mFilterAll->setStateSelected(true); } void InventoryWindow::openInventory() @@ -92,6 +94,14 @@ namespace MWGui setFilter(ContainerBase::Filter_Magic); else if (_sender == mFilterMisc) setFilter(ContainerBase::Filter_Misc); + + mFilterAll->setStateSelected(false); + mFilterWeapon->setStateSelected(false); + mFilterApparel->setStateSelected(false); + mFilterMagic->setStateSelected(false); + mFilterMisc->setStateSelected(false); + + static_cast(_sender)->setStateSelected(true); } } diff --git a/files/mygui/openmw_button.skin.xml b/files/mygui/openmw_button.skin.xml index b88e99406..9efcf776f 100644 --- a/files/mygui/openmw_button.skin.xml +++ b/files/mygui/openmw_button.skin.xml @@ -62,6 +62,10 @@ + + + + From 78b06d0ebfc7e3a2ebf63d7a5fe9c9f92031b617 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 12 May 2012 22:44:12 +0200 Subject: [PATCH 038/118] inventory window pinning --- apps/openmw/mwgui/container.cpp | 39 +++++++++++-------- apps/openmw/mwgui/container.hpp | 13 ++++--- apps/openmw/mwgui/inventorywindow.cpp | 16 +++++++- apps/openmw/mwgui/inventorywindow.hpp | 5 ++- apps/openmw/mwgui/window_manager.cpp | 10 +++++ apps/openmw/mwgui/window_manager.hpp | 2 + .../mygui/openmw_inventory_window_layout.xml | 2 +- libs/openengine/gui/layout.hpp | 7 ++++ 8 files changed, 69 insertions(+), 25 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 2de8e2bb3..8742bf4f7 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -26,14 +26,16 @@ using namespace MWGui; using namespace Widgets; -ContainerBase::ContainerBase(WindowManager& parWindowManager,DragAndDrop* dragAndDrop,std::string guiFile) - : WindowBase(guiFile, parWindowManager), +ContainerBase::ContainerBase(DragAndDrop* dragAndDrop) : mDragAndDrop(dragAndDrop), - mFilter(ContainerBase::Filter_All), - mContainer() + mFilter(ContainerBase::Filter_All) { - getWidget(mContainerWidget, "Items"); - getWidget(mItemView, "ItemView"); +} + +void ContainerBase::setWidgets(Widget* containerWidget, ScrollView* itemView) +{ + mContainerWidget = containerWidget; + mItemView = itemView; mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerBase::onContainerClicked); } @@ -90,24 +92,16 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) } } -void ContainerBase::setName(std::string contName) -{ - setText("_Main", contName); - adjustWindowCaption(); -} - void ContainerBase::setFilter(ContainerBase::Filter filter) { mFilter = filter; drawItems(); } -void ContainerBase::open(MWWorld::Ptr container) +void ContainerBase::openContainer(MWWorld::Ptr container) { mContainer = container; - setName(MWWorld::Class::get(container).getName(container)); drawItems(); - setVisible(true); } void ContainerBase::drawItems() @@ -206,11 +200,18 @@ void ContainerBase::Update() // ------------------------------------------------------------------------------------------------ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) - : ContainerBase(parWindowManager, dragAndDrop, "openmw_container_window_layout.xml") + : ContainerBase(dragAndDrop) + , WindowBase("openmw_container_window_layout.xml", parWindowManager) { getWidget(mTakeButton, "TakeButton"); getWidget(mCloseButton, "CloseButton"); + MyGUI::ScrollView* itemView; + MyGUI::Widget* containerWidget; + getWidget(containerWidget, "Items"); + getWidget(itemView, "ItemView"); + setWidgets(containerWidget, itemView); + mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onCloseButtonClicked); mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onTakeAllButtonClicked); @@ -239,6 +240,12 @@ void ContainerWindow::onWindowResize(MyGUI::Window* window) drawItems(); } +void ContainerWindow::open(MWWorld::Ptr container) +{ + openContainer(container); + setTitle(MWWorld::Class::get(container).getName(container)); +} + void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender) { if(!mDragAndDrop->mIsOnDragAndDrop) diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index a8c12bb6a..7fe04cd48 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -44,10 +44,10 @@ namespace MWGui MWWorld::Ptr mItem; }; - class ContainerBase : public WindowBase + class ContainerBase { public: - ContainerBase(WindowManager& parWindowManager, DragAndDrop* dragAndDrop, std::string guiFile); + ContainerBase(DragAndDrop* dragAndDrop); virtual ~ContainerBase(); enum Filter @@ -59,8 +59,9 @@ namespace MWGui Filter_Misc = 0x05 }; - void open(MWWorld::Ptr container); - void setName(std::string contName); + void setWidgets(MyGUI::Widget* containerWidget, MyGUI::ScrollView* itemView); ///< only call once + + void openContainer(MWWorld::Ptr container); void setFilter(Filter filter); ///< set category filter void Update(); @@ -79,13 +80,15 @@ namespace MWGui void drawItems(); }; - class ContainerWindow : public ContainerBase + class ContainerWindow : public ContainerBase, public WindowBase { public: ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); virtual ~ContainerWindow(); + void open(MWWorld::Ptr container); + protected: std::vector mContainerWidgets; diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 340c03562..560e940d8 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -22,7 +22,8 @@ namespace MWGui { InventoryWindow::InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) - : ContainerBase(parWindowManager,dragAndDrop,"openmw_inventory_window_layout.xml") + : ContainerBase(dragAndDrop) + , WindowPinnableBase("openmw_inventory_window_layout.xml", parWindowManager) { static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize); @@ -35,6 +36,12 @@ namespace MWGui getWidget(mFilterMagic, "MagicButton"); getWidget(mFilterMisc, "MiscButton"); + MyGUI::ScrollView* itemView; + MyGUI::Widget* containerWidget; + getWidget(containerWidget, "Items"); + getWidget(itemView, "ItemView"); + setWidgets(containerWidget, itemView); + mFilterAll->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sAllTab")->str); mFilterWeapon->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sWeaponTab")->str); mFilterApparel->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sApparelTab")->str); @@ -72,7 +79,7 @@ namespace MWGui void InventoryWindow::openInventory() { - open(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); + openContainer(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); onWindowResize(static_cast(mMainWidget)); } @@ -104,4 +111,9 @@ namespace MWGui static_cast(_sender)->setStateSelected(true); } + void InventoryWindow::onPinToggled() + { + mWindowManager.setWeaponVisibility(!mPinned); + } + } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 63188e84b..dd4ff90b6 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -2,6 +2,8 @@ #define MGUI_Inventory_H #include "container.hpp" +#include "window_pinnable_base.hpp" + namespace MWWorld { class Environment; @@ -21,7 +23,7 @@ namespace MWGui namespace MWGui { - class InventoryWindow : public MWGui::ContainerBase + class InventoryWindow : public ContainerBase, public WindowPinnableBase { public: InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); @@ -42,6 +44,7 @@ namespace MWGui void onWindowResize(MyGUI::Window* _sender); void onFilterChanged(MyGUI::Widget* _sender); + void onPinToggled(); }; } #endif // Inventory_H diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 6dfdc3bb4..249f1fcfd 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -548,3 +548,13 @@ bool WindowManager::getFullHelp() const { return mToolTips->getFullHelp(); } + +void WindowManager::setWeaponVisibility(bool visible) +{ + hud->weapBox->setVisible(visible); +} + +void WindowManager::setSpellVisibility(bool visible) +{ + hud->spellBox->setVisible(visible); +} diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index c3fb2b9f9..1ea4f267f 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -180,6 +180,8 @@ namespace MWGui void setHMSVisibility(bool visible); // sets the visibility of the hud minimap void setMinimapVisibility(bool visible); + void setWeaponVisibility(bool visible); + void setSpellVisibility(bool visible); template void removeDialog(T*& dialog); ///< Casts to OEngine::GUI::Layout and calls removeDialog, then resets pointer to nullptr. diff --git a/files/mygui/openmw_inventory_window_layout.xml b/files/mygui/openmw_inventory_window_layout.xml index b2b32ea2c..0e8abf45b 100644 --- a/files/mygui/openmw_inventory_window_layout.xml +++ b/files/mygui/openmw_inventory_window_layout.xml @@ -1,7 +1,7 @@ - + diff --git a/libs/openengine/gui/layout.hpp b/libs/openengine/gui/layout.hpp index bda8935af..abcc01753 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 setTitle(const std::string& title) + { + // NOTE: this assume that mMainWidget is of type Window. + static_cast(mMainWidget)->setCaption(title); + adjustWindowCaption(); + } + void setState(const std::string& widget, const std::string& state) { MyGUI::Widget* pt; From f31853d30bfca002dec038169f60d3f89eaa89a1 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 13 May 2012 01:27:17 +0200 Subject: [PATCH 039/118] mouse wheel works when mouse is over an item --- apps/openmw/mwgui/container.cpp | 12 +++++++++++- apps/openmw/mwgui/container.hpp | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 8742bf4f7..fd83bddfc 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -38,6 +38,7 @@ void ContainerBase::setWidgets(Widget* containerWidget, ScrollView* itemView) mItemView = itemView; mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerBase::onContainerClicked); + mContainerWidget->eventMouseWheel += MyGUI::newDelegate(this, &ContainerWindow::onMouseWheel); } ContainerBase::~ContainerBase() @@ -92,6 +93,14 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) } } +void ContainerBase::onMouseWheel(MyGUI::Widget* _sender, int _rel) +{ + if (mItemView->getViewOffset().left + _rel*0.3 > 0) + mItemView->setViewOffset(MyGUI::IntPoint(0, 0)); + else + mItemView->setViewOffset(MyGUI::IntPoint(mItemView->getViewOffset().left + _rel*0.3, 0)); +} + void ContainerBase::setFilter(ContainerBase::Filter filter) { mFilter = filter; @@ -155,7 +164,8 @@ void ContainerBase::drawItems() backgroundWidget->setUserData(*iter); backgroundWidget->setImageTexture( isMagic ? "textures\\menu_icon_magic.dds" : ""); backgroundWidget->setProperty("ImageCoord", "0 0 42 42"); - backgroundWidget->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerBase::onSelectedItem); + backgroundWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerBase::onSelectedItem); + backgroundWidget->eventMouseWheel += MyGUI::newDelegate(this, &ContainerBase::onMouseWheel); // image ImageBox* image = backgroundWidget->createWidget("ImageBox", MyGUI::IntCoord(5, 5, 32, 32), MyGUI::Align::Default); diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 7fe04cd48..6bfee1346 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -76,6 +76,7 @@ namespace MWGui void onSelectedItem(MyGUI::Widget* _sender); void onContainerClicked(MyGUI::Widget* _sender); + void onMouseWheel(MyGUI::Widget* _sender, int _rel); void drawItems(); }; From d266b4fe87a5a7377d5846076562339b18415539 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 13 May 2012 10:18:17 +0200 Subject: [PATCH 040/118] hide the cursor during drag&drop and don't allow hotkeys that change guimode --- apps/openmw/mwgui/container.cpp | 11 +++++++++-- apps/openmw/mwgui/window_manager.cpp | 5 +++++ apps/openmw/mwgui/window_manager.hpp | 2 ++ apps/openmw/mwinput/inputmanager.cpp | 21 ++++++++++++++++++++- apps/openmw/mwinput/inputmanager.hpp | 2 ++ 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index fd83bddfc..0236e17c2 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -60,12 +60,14 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) std::string sound = MWWorld::Class::get(object).getUpSoundId(object); MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); - _sender->setUserString("drag","on"); mDragAndDrop->mDraggedWidget = _sender; mDragAndDrop->mContainerWindow = const_cast(this); // hide the count text _sender->getChildAt(0)->getChildAt(0)->setVisible(false); drawItems(); + + MWBase::Environment::get().getInputManager()->setDragDrop(true); + MWBase::Environment::get().getWindowManager()->setMouseVisible(false); } else onContainerClicked(mContainerWidget); @@ -90,6 +92,9 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) mDragAndDrop->mDraggedWidget = 0; mDragAndDrop->mContainerWindow = 0; drawItems(); + + MWBase::Environment::get().getInputManager()->setDragDrop(false); + MWBase::Environment::get().getWindowManager()->setMouseVisible(true); } } @@ -146,7 +151,9 @@ void ContainerBase::drawItems() else if (mFilter == Filter_Misc) { categories = MWWorld::ContainerStore::Type_Miscellaneous + MWWorld::ContainerStore::Type_Book - + MWWorld::ContainerStore::Type_Ingredient; + + MWWorld::ContainerStore::Type_Ingredient + MWWorld::ContainerStore::Type_Repair + + MWWorld::ContainerStore::Type_Lockpick + MWWorld::ContainerStore::Type_Light + + MWWorld::ContainerStore::Type_Apparatus; } for (MWWorld::ContainerStoreIterator iter (containerStore.begin(categories)); iter!=containerStore.end(); ++iter) diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 249f1fcfd..067d67ca4 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -558,3 +558,8 @@ void WindowManager::setSpellVisibility(bool visible) { hud->spellBox->setVisible(visible); } + +void WindowManager::setMouseVisible(bool visible) +{ + MyGUI::PointerManager::getInstance().setVisible(visible); +} diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 1ea4f267f..b55b425a8 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -166,6 +166,8 @@ namespace MWGui void setFocusObject(const MWWorld::Ptr& focus); + void setMouseVisible(bool visible); + void toggleFogOfWar(); void toggleFullHelp(); ///< show extra info in item tooltips (owner, script) bool getFullHelp() const; diff --git a/apps/openmw/mwinput/inputmanager.cpp b/apps/openmw/mwinput/inputmanager.cpp index 9026cdf64..4d79eb321 100644 --- a/apps/openmw/mwinput/inputmanager.cpp +++ b/apps/openmw/mwinput/inputmanager.cpp @@ -88,6 +88,8 @@ namespace MWInput MWGui::WindowManager &windows; OMW::Engine& mEngine; + bool mDragDrop; + /* InputImpl Methods */ @@ -143,6 +145,9 @@ namespace MWInput { using namespace MWGui; + if (mDragDrop) + return; + GuiMode mode = windows.getMode(); // Toggle between game mode and inventory mode @@ -159,6 +164,9 @@ namespace MWInput { using namespace MWGui; + if (mDragDrop) + return; + GuiMode mode = windows.getMode(); // Switch to console mode no matter what mode we are currently @@ -219,7 +227,8 @@ namespace MWInput poller(input), player(_player), windows(_windows), - mEngine (engine) + mEngine (engine), + mDragDrop(false) { using namespace OEngine::Input; using namespace OEngine::Render; @@ -319,6 +328,11 @@ namespace MWInput poller.bind(A_Crouch, KC_LCONTROL); } + void setDragDrop(bool dragDrop) + { + mDragDrop = dragDrop; + } + //NOTE: Used to check for movement keys void update () { @@ -426,4 +440,9 @@ namespace MWInput { impl->update(); } + + void MWInputManager::setDragDrop(bool dragDrop) + { + impl->setDragDrop(dragDrop); + } } diff --git a/apps/openmw/mwinput/inputmanager.hpp b/apps/openmw/mwinput/inputmanager.hpp index 721c77d9f..158d05f0e 100644 --- a/apps/openmw/mwinput/inputmanager.hpp +++ b/apps/openmw/mwinput/inputmanager.hpp @@ -50,6 +50,8 @@ namespace MWInput void update(); + void setDragDrop(bool dragDrop); + void setGuiMode(MWGui::GuiMode mode); }; } From 3a93df8db4d58479c5c82fa103339787d4f2743a Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 13 May 2012 11:25:35 +0200 Subject: [PATCH 041/118] dynamic inventory layout like morrowind --- apps/openmw/mwgui/container.cpp | 17 +++--- apps/openmw/mwgui/inventorywindow.cpp | 8 +++ apps/openmw/mwgui/inventorywindow.hpp | 3 + apps/openmw/mwgui/tooltips.cpp | 12 ++++ apps/openmw/mwgui/tooltips.hpp | 4 ++ apps/openmw/mwgui/window_manager.cpp | 7 +++ apps/openmw/mwgui/window_manager.hpp | 3 +- .../mygui/openmw_inventory_window_layout.xml | 57 +++++++++++-------- 8 files changed, 78 insertions(+), 33 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 0236e17c2..1b165f995 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -66,8 +66,7 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) _sender->getChildAt(0)->getChildAt(0)->setVisible(false); drawItems(); - MWBase::Environment::get().getInputManager()->setDragDrop(true); - MWBase::Environment::get().getWindowManager()->setMouseVisible(false); + MWBase::Environment::get().getWindowManager()->setDragDrop(true); } else onContainerClicked(mContainerWidget); @@ -93,8 +92,7 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) mDragAndDrop->mContainerWindow = 0; drawItems(); - MWBase::Environment::get().getInputManager()->setDragDrop(false); - MWBase::Environment::get().getWindowManager()->setMouseVisible(true); + MWBase::Environment::get().getWindowManager()->setDragDrop(false); } } @@ -128,7 +126,7 @@ void ContainerBase::drawItems() int x = 0; int y = 0; - int maxHeight = mItemView->getSize().height - 48; + int maxHeight = mItemView->getSize().height - 58; int index = 0; @@ -195,7 +193,12 @@ void ContainerBase::drawItems() } if(iter->getRefData().getCount() > 1) - text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); + { + if (iter->getRefData().getCount() > 9999) + text->setCaption(boost::lexical_cast(iter->getRefData().getCount()/1000.f) + "k"); + else + text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); + } } } @@ -209,7 +212,7 @@ void ContainerBase::Update() if(mDragAndDrop->mIsOnDragAndDrop) { if(mDragAndDrop->mDraggedWidget) - mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); + mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition() - MyGUI::IntPoint(21, 21)); else mDragAndDrop->mIsOnDragAndDrop = false; //If this happens, there is a bug. } } diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 560e940d8..4bd4fe88c 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -35,6 +35,8 @@ namespace MWGui getWidget(mFilterApparel, "ApparelButton"); getWidget(mFilterMagic, "MagicButton"); getWidget(mFilterMisc, "MiscButton"); + getWidget(mLeftPane, "LeftPane"); + getWidget(mRightPane, "RightPane"); MyGUI::ScrollView* itemView; MyGUI::Widget* containerWidget; @@ -86,6 +88,12 @@ namespace MWGui void InventoryWindow::onWindowResize(MyGUI::Window* _sender) { + const float aspect = 0.5; // fixed aspect ratio for the left pane + mLeftPane->setSize( (_sender->getSize().height-44) * aspect, _sender->getSize().height-44 ); + mRightPane->setCoord( mLeftPane->getPosition().left + (_sender->getSize().height-44) * aspect + 4, + mRightPane->getPosition().top, + _sender->getSize().width - 12 - (_sender->getSize().height-44) * aspect - 15, + _sender->getSize().height-44 ); drawItems(); } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index dd4ff90b6..f16dcf433 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -36,6 +36,9 @@ namespace MWGui MyGUI::ProgressBar* mEncumbranceBar; MyGUI::TextBox* mEncumbranceText; + MyGUI::Widget* mLeftPane; + MyGUI::Widget* mRightPane; + MyGUI::Button* mFilterAll; MyGUI::Button* mFilterWeapon; MyGUI::Button* mFilterApparel; diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 7fc29f8c3..635e9481b 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -16,6 +16,7 @@ ToolTips::ToolTips(WindowManager* windowManager) : , mGameMode(true) , mWindowManager(windowManager) , mFullHelp(false) + , mEnabled(true) { getWidget(mDynamicToolTipBox, "DynamicToolTipBox"); @@ -27,6 +28,11 @@ ToolTips::ToolTips(WindowManager* windowManager) : mMainWidget->setNeedMouseFocus(false); } +void ToolTips::setEnabled(bool enabled) +{ + mEnabled = enabled; +} + void ToolTips::onFrame(float frameDuration) { MyGUI::Gui::getInstance().destroyWidget(mDynamicToolTipBox); @@ -36,6 +42,12 @@ void ToolTips::onFrame(float frameDuration) const IntSize &viewSize = RenderManager::getInstance().getViewSize(); + if (!mEnabled) + { + mDynamicToolTipBox->setVisible(false); + return; + } + if (!mGameMode) { Widget* focus = InputManager::getInstance().getMouseFocusWidget(); diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index 8d0970965..87b9e97bf 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -39,6 +39,8 @@ namespace MWGui void enterGameMode(); void enterGuiMode(); + void setEnabled(bool enabled); + void toggleFullHelp(); ///< show extra info in item tooltips (owner, script) bool getFullHelp() const; @@ -73,6 +75,8 @@ namespace MWGui bool mGameMode; + bool mEnabled; + bool mFullHelp; }; } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 067d67ca4..47fae2003 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -563,3 +563,10 @@ void WindowManager::setMouseVisible(bool visible) { MyGUI::PointerManager::getInstance().setVisible(visible); } + +void WindowManager::setDragDrop(bool dragDrop) +{ + mToolTips->setEnabled(!dragDrop); + MWBase::Environment::get().getInputManager()->setDragDrop(dragDrop); + setMouseVisible(!dragDrop); +} diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index b55b425a8..5dfcf6470 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -166,7 +166,8 @@ namespace MWGui void setFocusObject(const MWWorld::Ptr& focus); - void setMouseVisible(bool visible); + void setMouseVisible(bool visible); + void setDragDrop(bool dragDrop); void toggleFogOfWar(); void toggleFullHelp(); ///< show extra info in item tooltips (owner, script) diff --git a/files/mygui/openmw_inventory_window_layout.xml b/files/mygui/openmw_inventory_window_layout.xml index 0e8abf45b..cd6e1469e 100644 --- a/files/mygui/openmw_inventory_window_layout.xml +++ b/files/mygui/openmw_inventory_window_layout.xml @@ -3,37 +3,44 @@ - - - - - - + + + + + + + + + + + + + + + + + - - - - - - + - - - - - + + + + + + + + + + + + + + - - - - - - - - From a47d29c184f335f86f9c3972c8bbc253cad91944 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 13 May 2012 16:41:00 +0200 Subject: [PATCH 042/118] fix the inventory window overlapping with over windows in default layout --- apps/openmw/mwgui/container.cpp | 5 +++-- apps/openmw/mwgui/inventorywindow.cpp | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 1b165f995..de7419b80 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -245,10 +245,11 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dr mTakeButton->setCoord(600-20-closeButtonWidth-takeButtonWidth-8, mTakeButton->getCoord().top, takeButtonWidth, mTakeButton->getCoord().height); int w = MyGUI::RenderManager::getInstance().getViewSize().width; - int h = MyGUI::RenderManager::getInstance().getViewSize().height; - setCoord(w-600,h-300,600,300); + //int h = MyGUI::RenderManager::getInstance().getViewSize().height; static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &ContainerWindow::onWindowResize); + + setCoord(w-600,0,600,300); } ContainerWindow::~ContainerWindow() diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 4bd4fe88c..23e4949f7 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -77,6 +77,8 @@ namespace MWGui mFilterMisc->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); mFilterAll->setStateSelected(true); + + setCoord(0, 342, 600, 258); } void InventoryWindow::openInventory() From 967fb13fca9d0e4c9265c9840643b0070e7d80ef Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 13 May 2012 18:14:03 +0200 Subject: [PATCH 043/118] remove the old inventory code, split HUD, map and mainmenu into seperate implementation files --- apps/openmw/CMakeLists.txt | 4 +- apps/openmw/mwgui/{layouts.cpp => hud.cpp} | 97 +-------- apps/openmw/mwgui/hud.hpp | 50 +++++ apps/openmw/mwgui/layouts.hpp | 236 --------------------- apps/openmw/mwgui/mainmenu.hpp | 16 ++ apps/openmw/mwgui/map_window.cpp | 94 +++++++- apps/openmw/mwgui/map_window.hpp | 30 ++- apps/openmw/mwgui/window_manager.cpp | 3 +- 8 files changed, 190 insertions(+), 340 deletions(-) rename apps/openmw/mwgui/{layouts.cpp => hud.cpp} (72%) create mode 100644 apps/openmw/mwgui/hud.hpp delete mode 100644 apps/openmw/mwgui/layouts.hpp create mode 100644 apps/openmw/mwgui/mainmenu.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index be99cefdd..5ecb2eea8 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -23,10 +23,10 @@ add_openmw_dir (mwinput ) add_openmw_dir (mwgui - layouts text_input widgets race class birth review window_manager console dialogue + 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 tooltips scrollwindow bookwindow list - formatting itemwidget inventorywindow container + formatting itemwidget inventorywindow container hud ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwgui/layouts.cpp b/apps/openmw/mwgui/hud.cpp similarity index 72% rename from apps/openmw/mwgui/layouts.cpp rename to apps/openmw/mwgui/hud.cpp index 21302d7c1..ffee9f6c7 100644 --- a/apps/openmw/mwgui/layouts.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -1,18 +1,14 @@ -#include "layouts.hpp" - -#include "../mwmechanics/mechanicsmanager.hpp" -#include "window_manager.hpp" +#include "hud.hpp" #include -#include -#include -#undef min -#undef max +#include + +#include + using namespace MWGui; - HUD::HUD(int width, int height, int fpsLevel) : Layout("openmw_hud_layout.xml") , health(NULL) @@ -247,86 +243,3 @@ void HUD::setBottomRightVisibility(bool effectBoxVisible, bool minimapBoxVisible effectBox->setVisible(effectBoxVisible); } -LocalMapBase::LocalMapBase() - : mCurX(0) - , mCurY(0) - , mInterior(false) - , mFogOfWar(true) - , mLocalMap(NULL) - , mPrefix() - , mChanged(true) - , mLayout(NULL) - , mLastPositionX(0.0f) - , mLastPositionY(0.0f) - , mLastDirectionX(0.0f) - , mLastDirectionY(0.0f) -{ -} - -void LocalMapBase::init(MyGUI::ScrollView* widget, OEngine::GUI::Layout* layout) -{ - mLocalMap = widget; - mLayout = layout; -} - -void LocalMapBase::setCellPrefix(const std::string& prefix) -{ - mPrefix = prefix; - mChanged = true; -} - -void LocalMapBase::toggleFogOfWar() -{ - mFogOfWar = !mFogOfWar; - applyFogOfWar(); -} - -void LocalMapBase::applyFogOfWar() -{ - for (int mx=0; mx<3; ++mx) - { - for (int my=0; my<3; ++my) - { - std::string name = "Map_" + boost::lexical_cast(mx) + "_" - + boost::lexical_cast(my); - std::string image = mPrefix+"_"+ boost::lexical_cast(mCurX + (mx-1)) + "_" - + boost::lexical_cast(mCurY + (mInterior ? (my-1) : -1*(my-1))); - MyGUI::ImageBox* fog; - mLayout->getWidget(fog, name+"_fog"); - fog->setImageTexture(mFogOfWar ? - ((MyGUI::RenderManager::getInstance().getTexture(image+"_fog") != 0) ? image+"_fog" - : "black.png" ) - : ""); - } - } -} - -void LocalMapBase::setActiveCell(const int x, const int y, bool interior) -{ - if (x==mCurX && y==mCurY && mInterior==interior && !mChanged) return; // don't do anything if we're still in the same cell - for (int mx=0; mx<3; ++mx) - { - for (int my=0; my<3; ++my) - { - std::string name = "Map_" + boost::lexical_cast(mx) + "_" - + boost::lexical_cast(my); - - std::string image = mPrefix+"_"+ boost::lexical_cast(x + (mx-1)) + "_" - + boost::lexical_cast(y + (interior ? (my-1) : -1*(my-1))); - - MyGUI::ImageBox* box; - mLayout->getWidget(box, name); - - if (MyGUI::RenderManager::getInstance().getTexture(image) != 0) - box->setImageTexture(image); - else - box->setImageTexture("black.png"); - } - } - mInterior = interior; - mCurX = x; - mCurY = y; - mChanged = false; - applyFogOfWar(); -} - diff --git a/apps/openmw/mwgui/hud.hpp b/apps/openmw/mwgui/hud.hpp new file mode 100644 index 000000000..831707511 --- /dev/null +++ b/apps/openmw/mwgui/hud.hpp @@ -0,0 +1,50 @@ +#include "map_window.hpp" + +#include + +#include "../mwmechanics/stat.hpp" + +namespace MWGui +{ + class HUD : public OEngine::GUI::Layout, public LocalMapBase + { + public: + HUD(int width, int height, int fpsLevel); + void setStats(int h, int hmax, int m, int mmax, int s, int smax); + void setWeapIcon(const char *str); + void setSpellIcon(const char *str); + void setWeapStatus(int s, int smax); + void setSpellStatus(int s, int smax); + void setEffect(const char *img); + void setValue (const std::string& id, const MWMechanics::DynamicStat& value); + void setFPS(float fps); + void setTriangleCount(size_t count); + void setBatchCount(size_t count); + void setPlayerDir(const float x, const float y); + void setPlayerPos(const float x, const float y); + void setBottomLeftVisibility(bool hmsVisible, bool weapVisible, bool spellVisible); + void setBottomRightVisibility(bool effectBoxVisible, bool minimapVisible); + void setFpsLevel(const int level); + + MyGUI::ProgressPtr health, magicka, stamina; + MyGUI::Widget *weapBox, *spellBox; + MyGUI::ImageBox *weapImage, *spellImage; + MyGUI::ProgressPtr weapStatus, spellStatus; + MyGUI::Widget *effectBox, *minimapBox; + MyGUI::ImageBox* effect1; + MyGUI::ScrollView* minimap; + MyGUI::ImageBox* compass; + MyGUI::ImageBox* crosshair; + + MyGUI::WidgetPtr fpsbox; + MyGUI::TextBox* fpscounter; + MyGUI::TextBox* trianglecounter; + MyGUI::TextBox* batchcounter; + + private: + // bottom left elements + int hmsBaseLeft, weapBoxBaseLeft, spellBoxBaseLeft; + // bottom right elements + int minimapBoxBaseRight, effectBoxBaseRight; + }; +} diff --git a/apps/openmw/mwgui/layouts.hpp b/apps/openmw/mwgui/layouts.hpp deleted file mode 100644 index 19d96d2ef..000000000 --- a/apps/openmw/mwgui/layouts.hpp +++ /dev/null @@ -1,236 +0,0 @@ -#ifndef MWGUI_LAYOUTS_H -#define MWGUI_LAYOUTS_H - -#include - -#include -#include - -#include -#include -#include -#include - -#include "../mwmechanics/stat.hpp" -#include "window_base.hpp" - -#include - -/* - This file contains classes corresponding to window layouts - defined in resources/mygui/ *.xml. - - Each class inherites GUI::Layout and loads the XML file, and - provides some helper functions to manipulate the elements of the - window. - - The windows are never created or destroyed (except at startup and - shutdown), they are only hid. You can control visibility with - setVisible(). - */ - -namespace MWGui -{ - class LocalMapBase - { - public: - LocalMapBase(); - void init(MyGUI::ScrollView* widget, OEngine::GUI::Layout* layout); - - void setCellPrefix(const std::string& prefix); - void setActiveCell(const int x, const int y, bool interior=false); - - void toggleFogOfWar(); - - protected: - int mCurX, mCurY; - bool mInterior; - MyGUI::ScrollView* mLocalMap; - std::string mPrefix; - bool mChanged; - bool mFogOfWar; - - void applyFogOfWar(); - - OEngine::GUI::Layout* mLayout; - - float mLastPositionX; - float mLastPositionY; - float mLastDirectionX; - float mLastDirectionY; - }; - - class HUD : public OEngine::GUI::Layout, public LocalMapBase - { - public: - HUD(int width, int height, int fpsLevel); - void setStats(int h, int hmax, int m, int mmax, int s, int smax); - void setWeapIcon(const char *str); - void setSpellIcon(const char *str); - void setWeapStatus(int s, int smax); - void setSpellStatus(int s, int smax); - void setEffect(const char *img); - void setValue (const std::string& id, const MWMechanics::DynamicStat& value); - void setFPS(float fps); - void setTriangleCount(size_t count); - void setBatchCount(size_t count); - void setPlayerDir(const float x, const float y); - void setPlayerPos(const float x, const float y); - void setBottomLeftVisibility(bool hmsVisible, bool weapVisible, bool spellVisible); - void setBottomRightVisibility(bool effectBoxVisible, bool minimapVisible); - void setFpsLevel(const int level); - - MyGUI::ProgressPtr health, magicka, stamina; - MyGUI::Widget *weapBox, *spellBox; - MyGUI::ImageBox *weapImage, *spellImage; - MyGUI::ProgressPtr weapStatus, spellStatus; - MyGUI::Widget *effectBox, *minimapBox; - MyGUI::ImageBox* effect1; - MyGUI::ScrollView* minimap; - MyGUI::ImageBox* compass; - MyGUI::ImageBox* crosshair; - - MyGUI::WidgetPtr fpsbox; - MyGUI::TextBox* fpscounter; - MyGUI::TextBox* trianglecounter; - MyGUI::TextBox* batchcounter; - - private: - // bottom left elements - int hmsBaseLeft, weapBoxBaseLeft, spellBoxBaseLeft; - // bottom right elements - int minimapBoxBaseRight, effectBoxBaseRight; - }; - - class MainMenu : public OEngine::GUI::Layout - { - public: - MainMenu(int w, int h) - : Layout("openmw_mainmenu_layout.xml") - { - setCoord(0,0,w,h); - } - }; - -#if 0 - class InventoryWindow : public OEngine::GUI::Layout - { - public: - enum CategoryMode - { - CM_All = 0, // All items - CM_Weapon = 1, // Only weapons - CM_Apparel = 2, // Apparel - CM_Magic = 3, // Magic - CM_Misc = 4 // Misc - }; - - InventoryWindow () - : Layout("openmw_inventory_window_layout.xml") - , categoryMode(CM_All) - - // color should be fetched from skin - , activeColor(0, 0, 1) - , inactiveColor(0.7, 0.7, 0.7) - { - setCoord(0, 200, 600, 400); - - // These are just demo values, you should replace these with - // real calls from outside the class later. - - mMainWidget->setCaption("Glass Frostsword"); - setText("EncumbranceBarT", "176/210"); - - MyGUI::ProgressPtr pt; - getWidget(pt, "EncumbranceBar"); - pt->setProgressRange(210); - pt->setProgressPosition(176); - - MyGUI::WidgetPtr avatar; - getWidget(avatar, "Avatar"); - - // Adjust armor rating text to bottom of avatar widget - MyGUI::TextBox* armor_rating; - getWidget(armor_rating, "ArmorRating"); - armor_rating->setCaption("Armor: 11"); - MyGUI::IntCoord coord = armor_rating->getCoord(); - coord.top = avatar->getCoord().height - 4 - coord.height; - armor_rating->setCoord(coord); - - names[0] = "All"; - names[1] = "Weapon"; - names[2] = "Apparel"; - names[3] = "Magic"; - names[4] = "Misc"; - - boost::array categories = { { - CM_All, CM_Weapon, CM_Apparel, CM_Magic, CM_Misc - } }; - - // Initialize buttons with text and adjust sizes, also mark All as active button - int margin = 2; - int last_x = 0; - for (int i = 0; i < categories.size(); ++i) - { - CategoryMode mode = categories[i]; - std::string name = names[mode]; - name += "Button"; - setText(name, names[mode]); - getWidget(buttons[mode], name); - - MyGUI::ButtonPtr &button_pt = buttons[mode]; - if (mode == CM_All) - button_pt->setTextColour(activeColor); - else - button_pt->setTextColour(inactiveColor); - MyGUI::IntCoord coord = button_pt->getCoord(); - coord.left = last_x; - last_x += coord.width + margin; - button_pt->setCoord(coord); - - button_pt->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onCategorySelected); - } - } - - void setCategory(CategoryMode mode) - { - MyGUI::ButtonPtr pt = getCategoryButton(categoryMode); - pt->setTextColour(inactiveColor); - - pt = getCategoryButton(mode); - pt->setTextColour(activeColor); - categoryMode = mode; - } - - MyGUI::ButtonPtr getCategoryButton(CategoryMode mode) - { - return buttons[mode]; - } - - void onCategorySelected(MyGUI::Widget *widget) - { - boost::array categories = { { - CM_All, CM_Weapon, CM_Apparel, CM_Magic, CM_Misc - } }; - - for (int i = 0; i < categories.size(); ++i) - { - CategoryMode mode = categories[i]; - if (widget == buttons[mode]) - { - setCategory(mode); - return; - } - } - } - - CategoryMode categoryMode; // Current category filter - MyGUI::ButtonPtr buttons[5]; // Button pointers - std::string names[5]; // Names of category buttons - - MyGUI::Colour activeColor; - MyGUI::Colour inactiveColor; - }; -#endif -} -#endif diff --git a/apps/openmw/mwgui/mainmenu.hpp b/apps/openmw/mwgui/mainmenu.hpp new file mode 100644 index 000000000..b32f2d900 --- /dev/null +++ b/apps/openmw/mwgui/mainmenu.hpp @@ -0,0 +1,16 @@ +#include + +namespace MWGui +{ + + class MainMenu : public OEngine::GUI::Layout + { + public: + MainMenu(int w, int h) + : Layout("openmw_mainmenu_layout.xml") + { + setCoord(0,0,w,h); + } + }; + +} diff --git a/apps/openmw/mwgui/map_window.cpp b/apps/openmw/mwgui/map_window.cpp index e0c828fdc..d3541f774 100644 --- a/apps/openmw/mwgui/map_window.cpp +++ b/apps/openmw/mwgui/map_window.cpp @@ -1,17 +1,95 @@ #include "map_window.hpp" #include "window_manager.hpp" -/* -#include "../mwmechanics/mechanicsmanager.hpp" -#include -#include -#include +#include -#undef min -#undef max -*/ using namespace MWGui; +LocalMapBase::LocalMapBase() + : mCurX(0) + , mCurY(0) + , mInterior(false) + , mFogOfWar(true) + , mLocalMap(NULL) + , mPrefix() + , mChanged(true) + , mLayout(NULL) + , mLastPositionX(0.0f) + , mLastPositionY(0.0f) + , mLastDirectionX(0.0f) + , mLastDirectionY(0.0f) +{ +} + +void LocalMapBase::init(MyGUI::ScrollView* widget, OEngine::GUI::Layout* layout) +{ + mLocalMap = widget; + mLayout = layout; +} + +void LocalMapBase::setCellPrefix(const std::string& prefix) +{ + mPrefix = prefix; + mChanged = true; +} + +void LocalMapBase::toggleFogOfWar() +{ + mFogOfWar = !mFogOfWar; + applyFogOfWar(); +} + +void LocalMapBase::applyFogOfWar() +{ + for (int mx=0; mx<3; ++mx) + { + for (int my=0; my<3; ++my) + { + std::string name = "Map_" + boost::lexical_cast(mx) + "_" + + boost::lexical_cast(my); + std::string image = mPrefix+"_"+ boost::lexical_cast(mCurX + (mx-1)) + "_" + + boost::lexical_cast(mCurY + (mInterior ? (my-1) : -1*(my-1))); + MyGUI::ImageBox* fog; + mLayout->getWidget(fog, name+"_fog"); + fog->setImageTexture(mFogOfWar ? + ((MyGUI::RenderManager::getInstance().getTexture(image+"_fog") != 0) ? image+"_fog" + : "black.png" ) + : ""); + } + } +} + +void LocalMapBase::setActiveCell(const int x, const int y, bool interior) +{ + if (x==mCurX && y==mCurY && mInterior==interior && !mChanged) return; // don't do anything if we're still in the same cell + for (int mx=0; mx<3; ++mx) + { + for (int my=0; my<3; ++my) + { + std::string name = "Map_" + boost::lexical_cast(mx) + "_" + + boost::lexical_cast(my); + + std::string image = mPrefix+"_"+ boost::lexical_cast(x + (mx-1)) + "_" + + boost::lexical_cast(y + (interior ? (my-1) : -1*(my-1))); + + MyGUI::ImageBox* box; + mLayout->getWidget(box, name); + + if (MyGUI::RenderManager::getInstance().getTexture(image) != 0) + box->setImageTexture(image); + else + box->setImageTexture("black.png"); + } + } + mInterior = interior; + mCurX = x; + mCurY = y; + mChanged = false; + applyFogOfWar(); +} + +// ------------------------------------------------------------------------------------------ + MapWindow::MapWindow(WindowManager& parWindowManager) : MWGui::WindowPinnableBase("openmw_map_window_layout.xml", parWindowManager), mGlobal(false) diff --git a/apps/openmw/mwgui/map_window.hpp b/apps/openmw/mwgui/map_window.hpp index d14221a40..e7318f4e4 100644 --- a/apps/openmw/mwgui/map_window.hpp +++ b/apps/openmw/mwgui/map_window.hpp @@ -1,11 +1,39 @@ #ifndef MWGUI_MAPWINDOW_H #define MWGUI_MAPWINDOW_H -#include "layouts.hpp" #include "window_pinnable_base.hpp" namespace MWGui { + class LocalMapBase + { + public: + LocalMapBase(); + void init(MyGUI::ScrollView* widget, OEngine::GUI::Layout* layout); + + void setCellPrefix(const std::string& prefix); + void setActiveCell(const int x, const int y, bool interior=false); + + void toggleFogOfWar(); + + protected: + int mCurX, mCurY; + bool mInterior; + MyGUI::ScrollView* mLocalMap; + std::string mPrefix; + bool mChanged; + bool mFogOfWar; + + void applyFogOfWar(); + + OEngine::GUI::Layout* mLayout; + + float mLastPositionX; + float mLastPositionY; + float mLastDirectionX; + float mLastDirectionY; + }; + class MapWindow : public MWGui::WindowPinnableBase, public LocalMapBase { public: diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 47fae2003..290e0029a 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -1,5 +1,4 @@ #include "window_manager.hpp" -#include "layouts.hpp" #include "text_input.hpp" #include "review.hpp" #include "dialogue.hpp" @@ -13,6 +12,8 @@ #include "scrollwindow.hpp" #include "bookwindow.hpp" #include "list.hpp" +#include "hud.hpp" +#include "mainmenu.hpp" #include "../mwmechanics/mechanicsmanager.hpp" #include "../mwinput/inputmanager.hpp" From 6c9f75b322d54c0079d9ad95299b014da51b19c9 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 13 May 2012 18:35:56 +0200 Subject: [PATCH 044/118] some unfinished work for dropping objects into the gameworld --- apps/openmw/mwgui/hud.cpp | 26 +++++++++++++++++++++++++- apps/openmw/mwgui/hud.hpp | 8 +++++++- apps/openmw/mwgui/window_manager.cpp | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index ffee9f6c7..47bf27799 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -6,10 +6,14 @@ #include +#include "../mwbase/environment.hpp" + +#include "window_manager.hpp" +#include "container.hpp" using namespace MWGui; -HUD::HUD(int width, int height, int fpsLevel) +HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop) : Layout("openmw_hud_layout.xml") , health(NULL) , magicka(NULL) @@ -32,6 +36,7 @@ HUD::HUD(int width, int height, int fpsLevel) , spellBoxBaseLeft(0) , effectBoxBaseRight(0) , minimapBoxBaseRight(0) + , mDragAndDrop(dragAndDrop) { setCoord(0,0, width, height); @@ -80,6 +85,8 @@ HUD::HUD(int width, int height, int fpsLevel) setEffect("icons\\s\\tx_s_chameleon.dds"); LocalMapBase::init(minimap, this); + + mMainWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onWorldClicked); } void HUD::setFpsLevel(int level) @@ -243,3 +250,20 @@ void HUD::setBottomRightVisibility(bool effectBoxVisible, bool minimapBoxVisible effectBox->setVisible(effectBoxVisible); } +void HUD::onWorldClicked(MyGUI::Widget* _sender) +{ + if (mDragAndDrop->mIsOnDragAndDrop) + { + // drop item into the gameworld + + + mDragAndDrop->mStore.clear(); + mDragAndDrop->mIsOnDragAndDrop = false; + MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget); + mDragAndDrop->mDraggedWidget = 0; + mDragAndDrop->mContainerWindow = 0; + + MWBase::Environment::get().getWindowManager()->setDragDrop(false); + } +} + diff --git a/apps/openmw/mwgui/hud.hpp b/apps/openmw/mwgui/hud.hpp index 831707511..22b1b8738 100644 --- a/apps/openmw/mwgui/hud.hpp +++ b/apps/openmw/mwgui/hud.hpp @@ -6,10 +6,12 @@ namespace MWGui { + class DragAndDrop; + class HUD : public OEngine::GUI::Layout, public LocalMapBase { public: - HUD(int width, int height, int fpsLevel); + HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop); void setStats(int h, int hmax, int m, int mmax, int s, int smax); void setWeapIcon(const char *str); void setSpellIcon(const char *str); @@ -46,5 +48,9 @@ namespace MWGui int hmsBaseLeft, weapBoxBaseLeft, spellBoxBaseLeft; // bottom right elements int minimapBoxBaseRight, effectBoxBaseRight; + + DragAndDrop* mDragAndDrop; + + void onWorldClicked(MyGUI::Widget* _sender); }; } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 290e0029a..bb533e698 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -99,7 +99,6 @@ WindowManager::WindowManager( mDragAndDrop->mDragAndDropWidget = dragAndDropWidget; mDragAndDrop->mContainerWindow = 0; - hud = new HUD(w,h, showFPSLevel); menu = new MainMenu(w,h); map = new MapWindow(*this); stats = new StatsWindow(*this); @@ -109,6 +108,7 @@ WindowManager::WindowManager( mDialogueWindow = new DialogueWindow(*this); mContainerWindow = new ContainerWindow(*this,mDragAndDrop); mInventoryWindow = new InventoryWindow(*this,mDragAndDrop); + hud = new HUD(w,h, showFPSLevel, mDragAndDrop); mToolTips = new ToolTips(this); mScrollWindow = new ScrollWindow(*this); mBookWindow = new BookWindow(*this); From d3e162ec830087be3cd04a5ff51ae90192bedab8 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 14 May 2012 17:41:17 +0200 Subject: [PATCH 045/118] dropping items works --- apps/openmw/mwgui/container.cpp | 2 + apps/openmw/mwgui/container.hpp | 1 - apps/openmw/mwgui/hud.cpp | 18 +++++ apps/openmw/mwworld/scene.cpp | 135 ++++++++++++++++++++------------ apps/openmw/mwworld/scene.hpp | 4 + apps/openmw/mwworld/world.cpp | 5 ++ apps/openmw/mwworld/world.hpp | 3 + 7 files changed, 119 insertions(+), 49 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index de7419b80..99a4b686e 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -184,6 +184,8 @@ void ContainerBase::drawItems() MyGUI::TextBox* text = image->createWidget("SandBrightText", MyGUI::IntCoord(0, 14, 32, 18), MyGUI::Align::Default, std::string("Label")); text->setTextAlign(MyGUI::Align::Right); text->setNeedMouseFocus(false); + text->setTextShadow(true); + text->setTextShadowColour(MyGUI::Colour(0,0,0)); y += 42; if (y > maxHeight) diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 6bfee1346..88fc55217 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -41,7 +41,6 @@ namespace MWGui MyGUI::Widget* mDraggedWidget; MyGUI::Widget* mDragAndDropWidget; MWWorld::ContainerStore mStore; - MWWorld::Ptr mItem; }; class ContainerBase diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 47bf27799..80c02cd82 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -7,6 +7,10 @@ #include #include "../mwbase/environment.hpp" +#include "../mwsound/soundmanager.hpp" +#include "../mwworld/class.hpp" +#include "../mwworld/world.hpp" +#include "../mwworld/player.hpp" #include "window_manager.hpp" #include "container.hpp" @@ -255,7 +259,21 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender) if (mDragAndDrop->mIsOnDragAndDrop) { // drop item into the gameworld + MWWorld::Ptr object = *mDragAndDrop->mStore.begin(); + float* playerPos; + playerPos = MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getRefData().getPosition().pos; + MWWorld::Ptr::CellStore* cell = MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getCell(); /// \todo this might be a different cell + + ESM::Position& pos = object.getRefData().getPosition(); + pos.pos[0] = playerPos[0]; + pos.pos[1] = playerPos[1]; + pos.pos[2] = playerPos[2]; + + MWBase::Environment::get().getWorld()->insertObject(object, cell); + + std::string sound = MWWorld::Class::get(object).getDownSoundId(object); + MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); mDragAndDrop->mStore.clear(); mDragAndDrop->mIsOnDragAndDrop = false; diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 6f9f3ed3e..1d4f078d5 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -15,39 +15,40 @@ #include "cellfunctors.hpp" -namespace { - -template -void insertCellRefList(MWRender::RenderingManager& rendering, - T& cellRefList, ESMS::CellStore &cell, MWWorld::PhysicsSystem& physics) +namespace { - if (!cellRefList.list.empty()) + + template + void insertCellRefList(MWRender::RenderingManager& rendering, + T& cellRefList, ESMS::CellStore &cell, MWWorld::PhysicsSystem& physics) { - const MWWorld::Class& class_ = - MWWorld::Class::get (MWWorld::Ptr (&*cellRefList.list.begin(), &cell)); - - for (typename T::List::iterator it = cellRefList.list.begin(); - it != cellRefList.list.end(); it++) + if (!cellRefList.list.empty()) { - if (it->mData.getCount() || it->mData.isEnabled()) - { - MWWorld::Ptr ptr (&*it, &cell); + const MWWorld::Class& class_ = + MWWorld::Class::get (MWWorld::Ptr (&*cellRefList.list.begin(), &cell)); - try + for (typename T::List::iterator it = cellRefList.list.begin(); + it != cellRefList.list.end(); it++) + { + if (it->mData.getCount() || it->mData.isEnabled()) { - rendering.addObject(ptr); - class_.insertObject(ptr, physics); - class_.enable (ptr); - } - catch (const std::exception& e) - { - std::string error ("error during rendering: "); - std::cerr << error + e.what() << std::endl; + MWWorld::Ptr ptr (&*it, &cell); + + try + { + rendering.addObject(ptr); + class_.insertObject(ptr, physics); + class_.enable (ptr); + } + catch (const std::exception& e) + { + std::string error ("error during rendering: "); + std::cerr << error + e.what() << std::endl; + } } } } } -} } @@ -300,30 +301,68 @@ namespace MWWorld mCellChanged = false; } -void Scene::insertCell(ESMS::CellStore &cell) -{ - // Loop through all references in the cell - insertCellRefList(mRendering, cell.activators, cell, *mPhysics); - insertCellRefList(mRendering, cell.potions, cell, *mPhysics); - insertCellRefList(mRendering, cell.appas, cell, *mPhysics); - insertCellRefList(mRendering, cell.armors, cell, *mPhysics); - insertCellRefList(mRendering, cell.books, cell, *mPhysics); - insertCellRefList(mRendering, cell.clothes, cell, *mPhysics); - insertCellRefList(mRendering, cell.containers, cell, *mPhysics); - insertCellRefList(mRendering, cell.creatures, cell, *mPhysics); - insertCellRefList(mRendering, cell.doors, cell, *mPhysics); - insertCellRefList(mRendering, cell.ingreds, cell, *mPhysics); - insertCellRefList(mRendering, cell.creatureLists, cell, *mPhysics); - insertCellRefList(mRendering, cell.itemLists, cell, *mPhysics); - insertCellRefList(mRendering, cell.lights, cell, *mPhysics); - insertCellRefList(mRendering, cell.lockpicks, cell, *mPhysics); - insertCellRefList(mRendering, cell.miscItems, cell, *mPhysics); - insertCellRefList(mRendering, cell.npcs, cell, *mPhysics); - insertCellRefList(mRendering, cell.probes, cell, *mPhysics); - insertCellRefList(mRendering, cell.repairs, cell, *mPhysics); - insertCellRefList(mRendering, cell.statics, cell, *mPhysics); - insertCellRefList(mRendering, cell.weapons, cell, *mPhysics); -} + void Scene::insertCell(ESMS::CellStore &cell) + { + // Loop through all references in the cell + insertCellRefList(mRendering, cell.activators, cell, *mPhysics); + insertCellRefList(mRendering, cell.potions, cell, *mPhysics); + insertCellRefList(mRendering, cell.appas, cell, *mPhysics); + insertCellRefList(mRendering, cell.armors, cell, *mPhysics); + insertCellRefList(mRendering, cell.books, cell, *mPhysics); + insertCellRefList(mRendering, cell.clothes, cell, *mPhysics); + insertCellRefList(mRendering, cell.containers, cell, *mPhysics); + insertCellRefList(mRendering, cell.creatures, cell, *mPhysics); + insertCellRefList(mRendering, cell.doors, cell, *mPhysics); + insertCellRefList(mRendering, cell.ingreds, cell, *mPhysics); + insertCellRefList(mRendering, cell.creatureLists, cell, *mPhysics); + insertCellRefList(mRendering, cell.itemLists, cell, *mPhysics); + insertCellRefList(mRendering, cell.lights, cell, *mPhysics); + insertCellRefList(mRendering, cell.lockpicks, cell, *mPhysics); + insertCellRefList(mRendering, cell.miscItems, cell, *mPhysics); + insertCellRefList(mRendering, cell.npcs, cell, *mPhysics); + insertCellRefList(mRendering, cell.probes, cell, *mPhysics); + insertCellRefList(mRendering, cell.repairs, cell, *mPhysics); + insertCellRefList(mRendering, cell.statics, cell, *mPhysics); + insertCellRefList(mRendering, cell.weapons, cell, *mPhysics); + } + void Scene::insertObject(MWWorld::Ptr ptr, Ptr::CellStore* cell) + { + ptr.mCell = cell; + + mRendering.addObject(ptr); + MWWorld::Class::get(ptr).insertObject(ptr, *mPhysics); + MWWorld::Class::get(ptr).enable(ptr); + + std::string type = ptr.getTypeName(); + + // insert into the correct CellRefList + if (type == typeid(ESM::Potion).name()) + cell->potions.list.push_back( *ptr.get() ); + else if (type == typeid(ESM::Apparatus).name()) + cell->appas.list.push_back( *ptr.get() ); + else if (type == typeid(ESM::Armor).name()) + cell->armors.list.push_back( *ptr.get() ); + else if (type == typeid(ESM::Book).name()) + cell->books.list.push_back( *ptr.get() ); + else if (type == typeid(ESM::Clothing).name()) + cell->clothes.list.push_back( *ptr.get() ); + else if (type == typeid(ESM::Ingredient).name()) + cell->ingreds.list.push_back( *ptr.get() ); + else if (type == typeid(ESM::Light).name()) + cell->lights.list.push_back( *ptr.get() ); + else if (type == typeid(ESM::Tool).name()) + cell->lockpicks.list.push_back( *ptr.get() ); + else if (type == typeid(ESM::Repair).name()) + cell->repairs.list.push_back( *ptr.get() ); + else if (type == typeid(ESM::Probe).name()) + cell->probes.list.push_back( *ptr.get() ); + else if (type == typeid(ESM::Weapon).name()) + cell->weapons.list.push_back( *ptr.get() ); + else if (type == typeid(ESM::Miscellaneous).name()) + cell->miscItems.list.push_back( *ptr.get() ); + else + throw std::runtime_error("Trying to insert object of unhandled type"); + } } diff --git a/apps/openmw/mwworld/scene.hpp b/apps/openmw/mwworld/scene.hpp index 1a9f2f271..857ee50d1 100644 --- a/apps/openmw/mwworld/scene.hpp +++ b/apps/openmw/mwworld/scene.hpp @@ -100,6 +100,10 @@ namespace MWWorld void insertCell(ESMS::CellStore &cell); + /// this method is only meant for dropping objects into the gameworld from a container + /// and thus only handles object types that can be placed in a container + void insertObject(MWWorld::Ptr object, Ptr::CellStore* cell); + void update (float duration); }; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 4adaf7918..d2b687742 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -948,4 +948,9 @@ namespace MWWorld mRendering->toggleWater(); } + void World::insertObject(MWWorld::Ptr ptr, Ptr::CellStore* cell) + { + mWorldScene->insertObject(ptr, cell); + } + } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 7359f8b90..3b56dea97 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -263,6 +263,9 @@ namespace MWWorld void update (float duration); + void insertObject (MWWorld::Ptr ptr, Ptr::CellStore* cell); + ///< insert object in a given cell + /// \note this method is only meant for dropping items into the gameworld from a container }; } From 933a40de14f1dc64c6d74685388841dca0fbc54d Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 14 May 2012 21:37:43 +0200 Subject: [PATCH 046/118] better floating object label positioning. --- apps/openmw/mwgui/tooltips.cpp | 15 ++++++--- apps/openmw/mwgui/tooltips.hpp | 5 +++ apps/openmw/mwgui/window_manager.cpp | 5 +++ apps/openmw/mwgui/window_manager.hpp | 1 + apps/openmw/mwrender/renderingmanager.cpp | 39 +++++++++++++++++++++++ apps/openmw/mwrender/renderingmanager.hpp | 4 +++ apps/openmw/mwworld/world.cpp | 19 ++++++++++- 7 files changed, 82 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 635e9481b..6f8434535 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -17,6 +17,8 @@ ToolTips::ToolTips(WindowManager* windowManager) : , mWindowManager(windowManager) , mFullHelp(false) , mEnabled(true) + , mFocusToolTipX(0.0) + , mFocusToolTipY(0.0) { getWidget(mDynamicToolTipBox, "DynamicToolTipBox"); @@ -118,11 +120,8 @@ void ToolTips::onFrame(float frameDuration) { IntSize tooltipSize = getToolTipViaPtr(); - // 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) - /// relevant link: http://www.ogre3d.org/tikiwiki/ObjectTextDisplay - setCoord(std::max(0, viewSize.width/2 - (tooltipSize.width)/2), - std::max(0, viewSize.height/2 - (tooltipSize.height) - 32), + setCoord(viewSize.width/2 - tooltipSize.width/2, + std::max(0, int(mFocusToolTipY*viewSize.height - tooltipSize.height)), tooltipSize.width, tooltipSize.height); } @@ -387,3 +386,9 @@ bool ToolTips::getFullHelp() const { return mFullHelp; } + +void ToolTips::setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y) +{ + mFocusToolTipX = (min_x + max_x) / 2; + mFocusToolTipY = min_y; +} diff --git a/apps/openmw/mwgui/tooltips.hpp b/apps/openmw/mwgui/tooltips.hpp index 87b9e97bf..4be0baff9 100644 --- a/apps/openmw/mwgui/tooltips.hpp +++ b/apps/openmw/mwgui/tooltips.hpp @@ -45,6 +45,8 @@ namespace MWGui bool getFullHelp() const; void setFocusObject(const MWWorld::Ptr& focus); + void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y); + ///< set the screen-space position of the tooltip for focused object static std::string getValueString(const int value, const std::string& prefix); ///< @return "prefix: value" or "" if value is 0 @@ -73,6 +75,9 @@ namespace MWGui MyGUI::IntSize createToolTip(const ToolTipInfo& info); ///< @return requested tooltip size + float mFocusToolTipX; + float mFocusToolTipY; + bool mGameMode; bool mEnabled; diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index bb533e698..c93d5303c 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -540,6 +540,11 @@ void WindowManager::setFocusObject(const MWWorld::Ptr& focus) mToolTips->setFocusObject(focus); } +void WindowManager::setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y) +{ + mToolTips->setFocusObjectScreenCoords(min_x, min_y, max_x, max_y); +} + void WindowManager::toggleFullHelp() { mToolTips->toggleFullHelp(); diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 5dfcf6470..cff93266c 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -165,6 +165,7 @@ namespace MWGui void setPlayerDir(const float x, const float y); ///< set player view direction in map space void setFocusObject(const MWWorld::Ptr& focus); + void setFocusObjectScreenCoords(float min_x, float min_y, float max_x, float max_y); void setMouseVisible(bool visible); void setDragDrop(bool dragDrop); diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index a95a179c6..f795ed372 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -518,4 +518,43 @@ void RenderingManager::switchToExterior() mRendering.getScene()->setCameraRelativeRendering(true); } +Ogre::Vector4 RenderingManager::boundingBoxToScreen(Ogre::AxisAlignedBox bounds) +{ + Ogre::Matrix4 mat = mRendering.getCamera()->getViewMatrix(); + + const Ogre::Vector3* corners = bounds.getAllCorners(); + + float min_x = 1.0f, max_x = 0.0f, min_y = 1.0f, max_y = 0.0f; + + // expand the screen-space bounding-box so that it completely encloses + // the object's AABB + for (int i=0; i<8; i++) + { + Ogre::Vector3 corner = corners[i]; + + // multiply the AABB corner vertex by the view matrix to + // get a camera-space vertex + corner = mat * corner; + + // make 2D relative/normalized coords from the view-space vertex + // by dividing out the Z (depth) factor -- this is an approximation + float x = corner.x / corner.z + 0.5; + float y = corner.y / corner.z + 0.5; + + if (x < min_x) + min_x = x; + + if (x > max_x) + max_x = x; + + if (y < min_y) + min_y = y; + + if (y > max_y) + max_y = y; + } + + return Vector4(min_x, min_y, max_x, max_y); +} + } // namespace diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 0d11b3d57..8b457997d 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -151,6 +151,10 @@ class RenderingManager: private RenderingInterface { ///< Skip the animation for the given MW-reference for one frame. Calls to this function for /// references that are currently not in the rendered scene should be ignored. + Ogre::Vector4 boundingBoxToScreen(Ogre::AxisAlignedBox bounds); + ///< transform the specified bounding box (in world coordinates) into screen coordinates. + /// @return packed vector4 (min_x, min_y, max_x, max_y) + private: void setAmbientMode(); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index d2b687742..0474d894c 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -768,7 +768,24 @@ namespace MWWorld // inform the GUI about focused object try { - MWBase::Environment::get().getWindowManager()->setFocusObject(getPtrViaHandle(mFacedHandle)); + MWWorld::Ptr object = getPtrViaHandle(mFacedHandle); + MWBase::Environment::get().getWindowManager()->setFocusObject(object); + + // retrieve object dimensions so we know where to place the floating label + Ogre::SceneNode* node = object.getRefData().getBaseNode(); + Ogre::AxisAlignedBox bounds; + int i; + for (i=0; inumAttachedObjects(); ++i) + { + Ogre::MovableObject* ob = node->getAttachedObject(i); + bounds.merge(ob->getWorldBoundingBox()); + } + if (bounds.isFinite()) + { + Vector4 screenCoords = mRendering->boundingBoxToScreen(bounds); + MWBase::Environment::get().getWindowManager()->setFocusObjectScreenCoords( + screenCoords[0], screenCoords[1], screenCoords[2], screenCoords[3]); + } } catch (std::runtime_error&) { From 320cc7d020f3d68a1104d8207f8020ed0933f6bd Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 11:02:50 +0200 Subject: [PATCH 047/118] implemented ctrl and shift-keys for item drag&drop (take all, take 1) --- apps/openmw/mwgui/container.cpp | 74 +++++++++++++++++++--------- apps/openmw/mwgui/container.hpp | 7 ++- apps/openmw/mwinput/inputmanager.cpp | 39 ++++++++++++--- apps/openmw/mwinput/inputmanager.hpp | 3 ++ 4 files changed, 89 insertions(+), 34 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 99a4b686e..82b695a2b 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -49,29 +49,49 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) { if(!mDragAndDrop->mIsOnDragAndDrop) { - mDragAndDrop->mIsOnDragAndDrop = true; - _sender->detachFromWidget(); - _sender->attachToWidget(mDragAndDrop->mDragAndDropWidget); + int count = (*_sender->getUserData()).getRefData().getCount(); - MWWorld::Ptr object = *_sender->getUserData(); - mDragAndDrop->mStore.add(object); - object.getRefData().setCount(0); - - std::string sound = MWWorld::Class::get(object).getUpSoundId(object); - MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); - - mDragAndDrop->mDraggedWidget = _sender; - mDragAndDrop->mContainerWindow = const_cast(this); - // hide the count text - _sender->getChildAt(0)->getChildAt(0)->setVisible(false); - drawItems(); - - MWBase::Environment::get().getWindowManager()->setDragDrop(true); + if (MWBase::Environment::get().getInputManager()->getShiftDown() || count == 1) + { + onSelectedItemImpl(_sender, count); + } + else if (MWBase::Environment::get().getInputManager()->getCtrlDown()) + { + onSelectedItemImpl(_sender, 1); + } + else + { + /// \todo count selection window + onSelectedItemImpl(_sender, count); + } } else onContainerClicked(mContainerWidget); } +void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) +{ + mDragAndDrop->mIsOnDragAndDrop = true; + _sender->detachFromWidget(); + _sender->attachToWidget(mDragAndDrop->mDragAndDropWidget); + + MWWorld::Ptr object = *_sender->getUserData(); + int originalCount = object.getRefData().getCount(); + object.getRefData().setCount(count); + mDragAndDrop->mStore.add(object); + object.getRefData().setCount(originalCount - count); + + std::string sound = MWWorld::Class::get(object).getUpSoundId(object); + MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); + + mDragAndDrop->mDraggedWidget = _sender; + mDragAndDrop->mContainerWindow = const_cast(this); + static_cast(_sender->getChildAt(0)->getChildAt(0))->setCaption(getCountString((*mDragAndDrop->mStore.begin()).getRefData().getCount())); + drawItems(); + + MWBase::Environment::get().getWindowManager()->setDragDrop(true); +} + void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) { if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here @@ -154,6 +174,8 @@ void ContainerBase::drawItems() + MWWorld::ContainerStore::Type_Apparatus; } + /// \todo performance improvement: don't create/destroy all the widgets everytime the container window changes size, only reposition them + for (MWWorld::ContainerStoreIterator iter (containerStore.begin(categories)); iter!=containerStore.end(); ++iter) { index++; @@ -194,13 +216,7 @@ void ContainerBase::drawItems() y = 0; } - if(iter->getRefData().getCount() > 1) - { - if (iter->getRefData().getCount() > 9999) - text->setCaption(boost::lexical_cast(iter->getRefData().getCount()/1000.f) + "k"); - else - text->setCaption(boost::lexical_cast(iter->getRefData().getCount())); - } + text->setCaption(getCountString(iter->getRefData().getCount())); } } @@ -209,6 +225,16 @@ void ContainerBase::drawItems() mContainerWidget->setSize(size); } +std::string ContainerBase::getCountString(const int count) +{ + if (count == 1) + return ""; + if (count > 9999) + return boost::lexical_cast(count/1000.f) + "k"; + else + return boost::lexical_cast(count); +} + void ContainerBase::Update() { if(mDragAndDrop->mIsOnDragAndDrop) diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 88fc55217..5cdc8ef1d 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -74,9 +74,12 @@ namespace MWGui Filter mFilter; void onSelectedItem(MyGUI::Widget* _sender); + void onSelectedItemImpl(MyGUI::Widget* _sender, int count); void onContainerClicked(MyGUI::Widget* _sender); void onMouseWheel(MyGUI::Widget* _sender, int _rel); + std::string getCountString(const int count); + void drawItems(); }; @@ -90,13 +93,9 @@ namespace MWGui void open(MWWorld::Ptr container); protected: - std::vector mContainerWidgets; - MyGUI::Button* mTakeButton; MyGUI::Button* mCloseButton; - bool mIsValid;//is in the right GUI Mode - void onWindowResize(MyGUI::Window* window); void onCloseButtonClicked(MyGUI::Widget* _sender); void onTakeAllButtonClicked(MyGUI::Widget* _sender); diff --git a/apps/openmw/mwinput/inputmanager.cpp b/apps/openmw/mwinput/inputmanager.cpp index 4d79eb321..787f12f25 100644 --- a/apps/openmw/mwinput/inputmanager.cpp +++ b/apps/openmw/mwinput/inputmanager.cpp @@ -60,7 +60,7 @@ namespace MWInput A_CycleWeaponRight, A_ToggleSneak, //Toggles Sneak, add Push-Sneak later A_ToggleWalk, //Toggle Walking/Running - A_Crouch, + A_Crouch, A_QuickSave, A_QuickLoad, @@ -69,6 +69,8 @@ namespace MWInput A_ToggleWeapon, A_ToggleSpell, + A_Shift, + A_ToggleFps, // Toggle FPS display (this is temporary) A_LAST // Marker for the last item @@ -90,6 +92,14 @@ namespace MWInput bool mDragDrop; + bool mShiftDown; + bool mCtrlDown; + +public: + bool getShiftDown() { return mShiftDown; } + bool getCtrlDown() { return mCtrlDown; } + +private: /* InputImpl Methods */ @@ -228,7 +238,9 @@ namespace MWInput player(_player), windows(_windows), mEngine (engine), - mDragDrop(false) + mDragDrop(false), + mShiftDown(false), + mCtrlDown(false) { using namespace OEngine::Input; using namespace OEngine::Render; @@ -323,9 +335,11 @@ namespace MWInput poller.bind(A_MoveRight, KC_D); poller.bind(A_MoveForward, KC_W); poller.bind(A_MoveBackward, KC_S); - - poller.bind(A_Jump, KC_E); - poller.bind(A_Crouch, KC_LCONTROL); + + poller.bind(A_Jump, KC_E); + poller.bind(A_Crouch, KC_LCONTROL); + + poller.bind(A_Shift, KC_LSHIFT); } void setDragDrop(bool dragDrop) @@ -347,6 +361,9 @@ namespace MWInput // event callbacks (which may crash) windows.update(); + mShiftDown = poller.isDown(A_Shift); + mCtrlDown = poller.isDown(A_Crouch); + // Disable movement in Gui mode if (windows.isGuiMode()) return; @@ -378,7 +395,7 @@ namespace MWInput else player.setForwardBackward (0); - if (poller.isDown(A_Jump)) + if (poller.isDown(A_Jump)) player.setUpDown (1); else if (poller.isDown(A_Crouch)) player.setUpDown (-1); @@ -445,4 +462,14 @@ namespace MWInput { impl->setDragDrop(dragDrop); } + + bool MWInputManager::getShiftDown() + { + return impl->getShiftDown(); + } + + bool MWInputManager::getCtrlDown() + { + return impl->getCtrlDown(); + } } diff --git a/apps/openmw/mwinput/inputmanager.hpp b/apps/openmw/mwinput/inputmanager.hpp index 158d05f0e..9e46e59a3 100644 --- a/apps/openmw/mwinput/inputmanager.hpp +++ b/apps/openmw/mwinput/inputmanager.hpp @@ -50,6 +50,9 @@ namespace MWInput void update(); + bool getShiftDown(); + bool getCtrlDown(); + void setDragDrop(bool dragDrop); void setGuiMode(MWGui::GuiMode mode); From 24a0fecd37576cc3045e7cf69011d1f2472b8487 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 12:51:51 +0200 Subject: [PATCH 048/118] implemented item count selection dialog --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwgui/class.hpp | 2 +- apps/openmw/mwgui/container.cpp | 42 ++++---- apps/openmw/mwgui/container.hpp | 2 + apps/openmw/mwgui/countdialog.cpp | 110 +++++++++++++++++++++ apps/openmw/mwgui/countdialog.hpp | 39 ++++++++ apps/openmw/mwgui/window_manager.cpp | 3 + apps/openmw/mwgui/window_manager.hpp | 3 + files/mygui/CMakeLists.txt | 1 + files/mygui/openmw_count_window_layout.xml | 27 +++++ 10 files changed, 211 insertions(+), 20 deletions(-) create mode 100644 apps/openmw/mwgui/countdialog.cpp create mode 100644 apps/openmw/mwgui/countdialog.hpp create mode 100644 files/mygui/openmw_count_window_layout.xml diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 5ecb2eea8..972c7f2e4 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -26,7 +26,7 @@ add_openmw_dir (mwgui 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 tooltips scrollwindow bookwindow list - formatting itemwidget inventorywindow container hud + formatting itemwidget inventorywindow container hud countdialog ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwgui/class.hpp b/apps/openmw/mwgui/class.hpp index 0e3348086..6f0138aa4 100644 --- a/apps/openmw/mwgui/class.hpp +++ b/apps/openmw/mwgui/class.hpp @@ -34,7 +34,7 @@ namespace MWGui typedef delegates::CMultiDelegate1 EventHandle_Int; /** Event : Button was clicked.\n - signature : void method(MyGUI::WidgetPtr widget, int index)\n + signature : void method(int index)\n */ EventHandle_Int eventButtonSelected; diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 82b695a2b..afcd398a4 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -1,7 +1,12 @@ #include "container.hpp" -#include "window_manager.hpp" -#include "widgets.hpp" +#include +#include +#include +#include +#include + +#include #include "../mwbase/environment.hpp" #include "../mwworld/manualref.hpp" @@ -13,14 +18,9 @@ #include "../mwinput/inputmanager.hpp" #include "../mwsound/soundmanager.hpp" -#include -#include -#include -#include -#include - -#include - +#include "window_manager.hpp" +#include "widgets.hpp" +#include "countdialog.hpp" using namespace MWGui; using namespace Widgets; @@ -49,7 +49,10 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) { if(!mDragAndDrop->mIsOnDragAndDrop) { - int count = (*_sender->getUserData()).getRefData().getCount(); + mSelectedItem = _sender; + + MWWorld::Ptr object = (*_sender->getUserData()); + int count = object.getRefData().getCount(); if (MWBase::Environment::get().getInputManager()->getShiftDown() || count == 1) { @@ -61,8 +64,10 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) } else { - /// \todo count selection window - onSelectedItemImpl(_sender, count); + CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); + dialog->open(MWWorld::Class::get(object).getName(object), count); + dialog->eventOkClicked.clear(); + dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::onSelectedItemImpl); } } else @@ -72,10 +77,10 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) { mDragAndDrop->mIsOnDragAndDrop = true; - _sender->detachFromWidget(); - _sender->attachToWidget(mDragAndDrop->mDragAndDropWidget); + mSelectedItem->detachFromWidget(); + mSelectedItem->attachToWidget(mDragAndDrop->mDragAndDropWidget); - MWWorld::Ptr object = *_sender->getUserData(); + MWWorld::Ptr object = *mSelectedItem->getUserData(); int originalCount = object.getRefData().getCount(); object.getRefData().setCount(count); mDragAndDrop->mStore.add(object); @@ -84,9 +89,10 @@ void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) std::string sound = MWWorld::Class::get(object).getUpSoundId(object); MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); - mDragAndDrop->mDraggedWidget = _sender; + mDragAndDrop->mDraggedWidget = mSelectedItem; mDragAndDrop->mContainerWindow = const_cast(this); - static_cast(_sender->getChildAt(0)->getChildAt(0))->setCaption(getCountString((*mDragAndDrop->mStore.begin()).getRefData().getCount())); + static_cast(mSelectedItem->getChildAt(0)->getChildAt(0))->setCaption( + getCountString((*mDragAndDrop->mStore.begin()).getRefData().getCount())); drawItems(); MWBase::Environment::get().getWindowManager()->setDragDrop(true); diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 5cdc8ef1d..20dc16cca 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -68,6 +68,8 @@ namespace MWGui MyGUI::ScrollView* mItemView; MyGUI::Widget* mContainerWidget; + MyGUI::Widget* mSelectedItem; + DragAndDrop* mDragAndDrop; MWWorld::Ptr mContainer; diff --git a/apps/openmw/mwgui/countdialog.cpp b/apps/openmw/mwgui/countdialog.cpp new file mode 100644 index 000000000..dc7e75e0e --- /dev/null +++ b/apps/openmw/mwgui/countdialog.cpp @@ -0,0 +1,110 @@ +#include "countdialog.hpp" + +#include + +#include "../mwbase/environment.hpp" +#include "../mwworld/world.hpp" + +namespace MWGui +{ + CountDialog::CountDialog(WindowManager& parWindowManager) : + WindowBase("openmw_count_window_layout.xml", parWindowManager) + { + getWidget(mSlider, "CountSlider"); + getWidget(mItemEdit, "ItemEdit"); + getWidget(mItemText, "ItemText"); + getWidget(mLabelText, "LabelText"); + getWidget(mOkButton, "OkButton"); + getWidget(mCancelButton, "CancelButton"); + + mOkButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sOk")->str); + mCancelButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sCancel")->str); + mLabelText->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTake")->str); + + mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CountDialog::onCancelButtonClicked); + mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CountDialog::onOkButtonClicked); + mItemEdit->eventEditTextChange += MyGUI::newDelegate(this, &CountDialog::onEditTextChange); + mSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &CountDialog::onSliderMoved); + } + + void CountDialog::open(const std::string& item, const int maxCount) + { + setVisible(true); + + MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); + + mSlider->setScrollRange(maxCount); + mItemText->setCaption(item); + + int width = std::max(mItemText->getTextSize().width + 128, 320); + setCoord(viewSize.width/2 - width/2, + viewSize.height/2 - mMainWidget->getHeight()/2, + width, + mMainWidget->getHeight()); + + // make other gui elements inaccessible while this dialog is open + MyGUI::InputManager::getInstance().addWidgetModal(mMainWidget); + + MyGUI::InputManager::getInstance().setKeyFocusWidget(mItemEdit); + + mSlider->setScrollPosition(maxCount-1); + mItemEdit->setCaption(boost::lexical_cast(maxCount)); + + int okButtonWidth = mOkButton->getTextSize().width + 24; + mOkButton->setCoord(width - 30 - okButtonWidth, + mOkButton->getTop(), + okButtonWidth, + mOkButton->getHeight()); + + int cancelButtonWidth = mCancelButton->getTextSize().width + 24; + mCancelButton->setCoord(width - 30 - okButtonWidth - cancelButtonWidth - 8, + mCancelButton->getTop(), + cancelButtonWidth, + mCancelButton->getHeight()); + } + + void CountDialog::onCancelButtonClicked(MyGUI::Widget* _sender) + { + close(); + } + + void CountDialog::onOkButtonClicked(MyGUI::Widget* _sender) + { + eventOkClicked(NULL, mSlider->getScrollPosition()+1); + + close(); + } + + void CountDialog::onEditTextChange(MyGUI::EditBox* _sender) + { + if (_sender->getCaption() == "") + return; + + unsigned int count; + try + { + count = boost::lexical_cast(_sender->getCaption()); + } + catch (std::bad_cast&) + { + count = 1; + } + if (count > mSlider->getScrollRange()) + { + count = mSlider->getScrollRange(); + } + mSlider->setScrollPosition(count-1); + onSliderMoved(mSlider, count-1); + } + + void CountDialog::onSliderMoved(MyGUI::ScrollBar* _sender, size_t _position) + { + mItemEdit->setCaption(boost::lexical_cast(_position+1)); + } + + void CountDialog::close() + { + setVisible(false); + MyGUI::InputManager::getInstance().removeWidgetModal(mMainWidget); + } +} diff --git a/apps/openmw/mwgui/countdialog.hpp b/apps/openmw/mwgui/countdialog.hpp new file mode 100644 index 000000000..b6c836c9d --- /dev/null +++ b/apps/openmw/mwgui/countdialog.hpp @@ -0,0 +1,39 @@ +#ifndef MWGUI_COUNTDIALOG_H +#define MWGUI_COUNTDIALOG_H + +#include "window_base.hpp" + +namespace MWGui +{ + class CountDialog : public WindowBase + { + public: + CountDialog(WindowManager& parWindowManager); + void open(const std::string& item, const int maxCount); + + typedef MyGUI::delegates::CMultiDelegate2 EventHandle_WidgetInt; + + /** Event : Ok button was clicked.\n + signature : void method(MyGUI::Widget* _sender, int _count)\n + */ + EventHandle_WidgetInt eventOkClicked; + + private: + MyGUI::ScrollBar* mSlider; + MyGUI::EditBox* mItemEdit; + MyGUI::TextBox* mItemText; + MyGUI::TextBox* mLabelText; + MyGUI::Button* mOkButton; + MyGUI::Button* mCancelButton; + + void onCancelButtonClicked(MyGUI::Widget* _sender); + void onOkButtonClicked(MyGUI::Widget* _sender); + void onEditTextChange(MyGUI::EditBox* _sender); + void onSliderMoved(MyGUI::ScrollBar* _sender, size_t _position); + + void close(); + }; + +} + +#endif diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index c93d5303c..a068de7d9 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -14,6 +14,7 @@ #include "list.hpp" #include "hud.hpp" #include "mainmenu.hpp" +#include "countdialog.hpp" #include "../mwmechanics/mechanicsmanager.hpp" #include "../mwinput/inputmanager.hpp" @@ -46,6 +47,7 @@ WindowManager::WindowManager( , mDialogueWindow(nullptr) , mBookWindow(NULL) , mScrollWindow(NULL) + , mCountDialog(NULL) , mCharGen(NULL) , playerClass() , playerName() @@ -112,6 +114,7 @@ WindowManager::WindowManager( mToolTips = new ToolTips(this); mScrollWindow = new ScrollWindow(*this); mBookWindow = new BookWindow(*this); + mCountDialog = new CountDialog(*this); // The HUD is always on hud->setVisible(true); diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index cff93266c..3f5df5789 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -71,6 +71,7 @@ namespace MWGui class InfoBoxDialog; class DialogueWindow; class MessageBoxManager; + class CountDialog; struct ClassPoint { @@ -133,6 +134,7 @@ namespace MWGui MWGui::BookWindow* getBookWindow() {return mBookWindow;} MWGui::ScrollWindow* getScrollWindow() {return mScrollWindow;} + MWGui::CountDialog* getCountDialog() {return mCountDialog;} MyGUI::Gui* getGui() const { return gui; } @@ -223,6 +225,7 @@ namespace MWGui InventoryWindow *mInventoryWindow; ScrollWindow* mScrollWindow; BookWindow* mBookWindow; + CountDialog* mCountDialog; CharacterCreation* mCharGen; diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index ae9ddd395..2ee823d2a 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -55,6 +55,7 @@ configure_file("${SDIR}/openmw_tooltips.xml" "${DDIR}/openmw_tooltips.xml" COPYO configure_file("${SDIR}/openmw_scroll_layout.xml" "${DDIR}/openmw_scroll_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_scroll_skin.xml" "${DDIR}/openmw_scroll_skin.xml" COPYONLY) configure_file("${SDIR}/openmw_book_layout.xml" "${DDIR}/openmw_book_layout.xml" COPYONLY) +configure_file("${SDIR}/openmw_count_window_layout.xml" "${DDIR}/openmw_count_window_layout.xml" COPYONLY) configure_file("${SDIR}/atlas1.cfg" "${DDIR}/atlas1.cfg" COPYONLY) configure_file("${SDIR}/smallbars.png" "${DDIR}/smallbars.png" COPYONLY) configure_file("${SDIR}/transparent.png" "${DDIR}/transparent.png" COPYONLY) diff --git a/files/mygui/openmw_count_window_layout.xml b/files/mygui/openmw_count_window_layout.xml new file mode 100644 index 000000000..38ba7644f --- /dev/null +++ b/files/mygui/openmw_count_window_layout.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + From 7fbee0d488383d7e7aeddd1c46a0a7b436768ccd Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 13:00:26 +0200 Subject: [PATCH 049/118] use MyGUI::InputManager instead of MWInputManager to detect ctrl/shift --- apps/openmw/mwgui/container.cpp | 6 ++---- apps/openmw/mwgui/container.hpp | 1 - apps/openmw/mwgui/hud.cpp | 1 - apps/openmw/mwgui/window_manager.cpp | 1 - apps/openmw/mwinput/inputmanager.cpp | 29 +--------------------------- apps/openmw/mwinput/inputmanager.hpp | 3 --- 6 files changed, 3 insertions(+), 38 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index afcd398a4..d926346d3 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -54,11 +54,11 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) MWWorld::Ptr object = (*_sender->getUserData()); int count = object.getRefData().getCount(); - if (MWBase::Environment::get().getInputManager()->getShiftDown() || count == 1) + if (MyGUI::InputManager::getInstance().isShiftPressed() || count == 1) { onSelectedItemImpl(_sender, count); } - else if (MWBase::Environment::get().getInputManager()->getCtrlDown()) + else if (MyGUI::InputManager::getInstance().isControlPressed()) { onSelectedItemImpl(_sender, 1); } @@ -90,7 +90,6 @@ void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); mDragAndDrop->mDraggedWidget = mSelectedItem; - mDragAndDrop->mContainerWindow = const_cast(this); static_cast(mSelectedItem->getChildAt(0)->getChildAt(0))->setCaption( getCountString((*mDragAndDrop->mStore.begin()).getRefData().getCount())); drawItems(); @@ -115,7 +114,6 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) mDragAndDrop->mDraggedWidget->detachFromWidget(); mDragAndDrop->mDraggedWidget->attachToWidget(mContainerWidget); mDragAndDrop->mDraggedWidget = 0; - mDragAndDrop->mContainerWindow = 0; drawItems(); MWBase::Environment::get().getWindowManager()->setDragDrop(false); diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 20dc16cca..b90044ab5 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -37,7 +37,6 @@ namespace MWGui { public: bool mIsOnDragAndDrop; - ContainerBase* mContainerWindow; MyGUI::Widget* mDraggedWidget; MyGUI::Widget* mDragAndDropWidget; MWWorld::ContainerStore mStore; diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 80c02cd82..482047b9b 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -279,7 +279,6 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender) mDragAndDrop->mIsOnDragAndDrop = false; MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget); mDragAndDrop->mDraggedWidget = 0; - mDragAndDrop->mContainerWindow = 0; MWBase::Environment::get().getWindowManager()->setDragDrop(false); } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index a068de7d9..8624699cd 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -99,7 +99,6 @@ WindowManager::WindowManager( mDragAndDrop->mIsOnDragAndDrop = false; mDragAndDrop->mDraggedWidget = 0; mDragAndDrop->mDragAndDropWidget = dragAndDropWidget; - mDragAndDrop->mContainerWindow = 0; menu = new MainMenu(w,h); map = new MapWindow(*this); diff --git a/apps/openmw/mwinput/inputmanager.cpp b/apps/openmw/mwinput/inputmanager.cpp index 787f12f25..8f8f1e1ee 100644 --- a/apps/openmw/mwinput/inputmanager.cpp +++ b/apps/openmw/mwinput/inputmanager.cpp @@ -69,8 +69,6 @@ namespace MWInput A_ToggleWeapon, A_ToggleSpell, - A_Shift, - A_ToggleFps, // Toggle FPS display (this is temporary) A_LAST // Marker for the last item @@ -92,14 +90,6 @@ namespace MWInput bool mDragDrop; - bool mShiftDown; - bool mCtrlDown; - -public: - bool getShiftDown() { return mShiftDown; } - bool getCtrlDown() { return mCtrlDown; } - -private: /* InputImpl Methods */ @@ -238,9 +228,7 @@ private: player(_player), windows(_windows), mEngine (engine), - mDragDrop(false), - mShiftDown(false), - mCtrlDown(false) + mDragDrop(false) { using namespace OEngine::Input; using namespace OEngine::Render; @@ -338,8 +326,6 @@ private: poller.bind(A_Jump, KC_E); poller.bind(A_Crouch, KC_LCONTROL); - - poller.bind(A_Shift, KC_LSHIFT); } void setDragDrop(bool dragDrop) @@ -361,9 +347,6 @@ private: // event callbacks (which may crash) windows.update(); - mShiftDown = poller.isDown(A_Shift); - mCtrlDown = poller.isDown(A_Crouch); - // Disable movement in Gui mode if (windows.isGuiMode()) return; @@ -462,14 +445,4 @@ private: { impl->setDragDrop(dragDrop); } - - bool MWInputManager::getShiftDown() - { - return impl->getShiftDown(); - } - - bool MWInputManager::getCtrlDown() - { - return impl->getCtrlDown(); - } } diff --git a/apps/openmw/mwinput/inputmanager.hpp b/apps/openmw/mwinput/inputmanager.hpp index 9e46e59a3..158d05f0e 100644 --- a/apps/openmw/mwinput/inputmanager.hpp +++ b/apps/openmw/mwinput/inputmanager.hpp @@ -50,9 +50,6 @@ namespace MWInput void update(); - bool getShiftDown(); - bool getCtrlDown(); - void setDragDrop(bool dragDrop); void setGuiMode(MWGui::GuiMode mode); From b18ee198b4b882879a9722d8e93630dca379f94b Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 16:47:23 +0200 Subject: [PATCH 050/118] use a raycast to determine where to place object, if distance is too far drop it on the ground --- apps/openmw/mwgui/container.cpp | 2 +- apps/openmw/mwgui/hud.cpp | 47 +++++++++++++++++++----- apps/openmw/mwgui/hud.hpp | 1 + apps/openmw/mwgui/window_manager.cpp | 1 - apps/openmw/mwworld/physicssystem.cpp | 25 ++++++++++++- apps/openmw/mwworld/physicssystem.hpp | 3 ++ apps/openmw/mwworld/world.cpp | 52 +++++++++++++++++++++++++-- apps/openmw/mwworld/world.hpp | 14 ++++++-- files/mygui/openmw.pointer.xml | 5 +++ files/mygui/openmw_layers.xml | 3 +- files/mygui/openmw_resources.xml | 7 ++++ 11 files changed, 142 insertions(+), 18 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index d926346d3..bab0051b8 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -244,7 +244,7 @@ void ContainerBase::Update() if(mDragAndDrop->mIsOnDragAndDrop) { if(mDragAndDrop->mDraggedWidget) - mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition() - MyGUI::IntPoint(21, 21)); + mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); else mDragAndDrop->mIsOnDragAndDrop = false; //If this happens, there is a bug. } } diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 482047b9b..b99276440 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -91,6 +91,7 @@ HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop) LocalMapBase::init(minimap, this); mMainWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onWorldClicked); + mMainWidget->eventMouseMove += MyGUI::newDelegate(this, &HUD::onWorldMouseOver); } void HUD::setFpsLevel(int level) @@ -261,16 +262,19 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender) // drop item into the gameworld MWWorld::Ptr object = *mDragAndDrop->mStore.begin(); - float* playerPos; - playerPos = MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getRefData().getPosition().pos; - MWWorld::Ptr::CellStore* cell = MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getCell(); /// \todo this might be a different cell + MWWorld::World* world = MWBase::Environment::get().getWorld(); - ESM::Position& pos = object.getRefData().getPosition(); - pos.pos[0] = playerPos[0]; - pos.pos[1] = playerPos[1]; - pos.pos[2] = playerPos[2]; + MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); + MyGUI::IntPoint cursorPosition = MyGUI::InputManager::getInstance().getMousePosition(); + float mouseX = cursorPosition.left / float(viewSize.width); + float mouseY = cursorPosition.top / float(viewSize.height); - MWBase::Environment::get().getWorld()->insertObject(object, cell); + if (world->canPlaceObject(mouseX, mouseY)) + world->placeObject(object, mouseX, mouseY); + else + world->dropObjectOnGround(object); + + MyGUI::PointerManager::getInstance().setPointer("arrow"); std::string sound = MWWorld::Class::get(object).getDownSoundId(object); MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); @@ -284,3 +288,30 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender) } } +void HUD::onWorldMouseOver(MyGUI::Widget* _sender, int x, int y) +{ + if (mDragAndDrop->mIsOnDragAndDrop) + { + MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); + MyGUI::IntPoint cursorPosition = MyGUI::InputManager::getInstance().getMousePosition(); + float mouseX = cursorPosition.left / float(viewSize.width); + float mouseY = cursorPosition.top / float(viewSize.height); + + MWWorld::World* world = MWBase::Environment::get().getWorld(); + + // if we can't drop the object at the wanted position, show the "drop on ground" cursor. + bool canDrop = world->canPlaceObject(mouseX, mouseY); + + if (!canDrop) + MyGUI::PointerManager::getInstance().setPointer("drop_ground"); + else + MyGUI::PointerManager::getInstance().setPointer("arrow"); + + } + else + { + MyGUI::PointerManager::getInstance().setPointer("arrow"); + /// \todo make it possible to pick up objects with the mouse, if inventory or container window is open + } +} + diff --git a/apps/openmw/mwgui/hud.hpp b/apps/openmw/mwgui/hud.hpp index 22b1b8738..cccfb0541 100644 --- a/apps/openmw/mwgui/hud.hpp +++ b/apps/openmw/mwgui/hud.hpp @@ -52,5 +52,6 @@ namespace MWGui DragAndDrop* mDragAndDrop; void onWorldClicked(MyGUI::Widget* _sender); + void onWorldMouseOver(MyGUI::Widget* _sender, int x, int y); }; } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 8624699cd..a4788ad3b 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -576,5 +576,4 @@ void WindowManager::setDragDrop(bool dragDrop) { mToolTips->setEnabled(!dragDrop); MWBase::Environment::get().getInputManager()->setDragDrop(dragDrop); - setMouseVisible(!dragDrop); } diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index fb13e37c6..808c712a0 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -80,7 +80,7 @@ namespace MWWorld Ray centerRay = mRender.getCamera()->getCameraToViewportRay( mRender.getViewport()->getWidth()/2, mRender.getViewport()->getHeight()/2); - btVector3 result(centerRay.getPoint(500*extent).x,-centerRay.getPoint(500*extent).z,centerRay.getPoint(500*extent).y); + btVector3 result(centerRay.getPoint(500*extent).x,-centerRay.getPoint(500*extent).z,centerRay.getPoint(500*extent).y); /// \todo make this distance (ray length) configurable return result; } @@ -95,6 +95,29 @@ namespace MWWorld return !(result.first == ""); } + std::pair PhysicsSystem::castRay(float mouseX, float mouseY) + { + Ogre::Ray ray = mRender.getCamera()->getCameraToViewportRay( + mouseX, + mouseY); + Ogre::Vector3 from = ray.getOrigin(); + Ogre::Vector3 to = ray.getPoint(200); /// \todo make this distance (ray length) configurable + + btVector3 _from, _to; + // OGRE to MW coordinates + _from = btVector3(from.x, -from.z, from.y); + _to = btVector3(to.x, -to.z, to.y); + + std::pair result = mEngine->rayTest(_from, _to); + + if (result.first == "") + return std::make_pair(false, Ogre::Vector3()); + else + { + return std::make_pair(true, ray.getPoint(200*result.second)); /// \todo make this distance (ray length) configurable + } + } + void PhysicsSystem::doPhysics(float dt, const std::vector >& actors) { //set the DebugRenderingMode. To disable it,set it to 0 diff --git a/apps/openmw/mwworld/physicssystem.hpp b/apps/openmw/mwworld/physicssystem.hpp index 1af6bcca2..9b03d2124 100644 --- a/apps/openmw/mwworld/physicssystem.hpp +++ b/apps/openmw/mwworld/physicssystem.hpp @@ -53,6 +53,9 @@ namespace MWWorld // cast ray, return true if it hit something bool castRay(const Ogre::Vector3& from, const Ogre::Vector3& to); + std::pair castRay(float mouseX, float mouseY); + ///< cast ray from the mouse, return true if it hit something and the first result (in OGRE coordinates) + void insertObjectPhysics(const MWWorld::Ptr& ptr, std::string model); void insertActorPhysics(const MWWorld::Ptr&, std::string model); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 0474d894c..973407b0c 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -965,9 +965,57 @@ namespace MWWorld mRendering->toggleWater(); } - void World::insertObject(MWWorld::Ptr ptr, Ptr::CellStore* cell) + bool World::placeObject(MWWorld::Ptr object, float cursorX, float cursorY) { - mWorldScene->insertObject(ptr, cell); + std::pair result = mPhysics->castRay(cursorX, cursorY); + + if (!result.first) + return false; + + MWWorld::Ptr::CellStore* cell; + if (isCellExterior()) + { + int cellX, cellY; + positionToIndex(result.second[0], -result.second[2], cellX, cellY); + cell = mCells.getExterior(cellX, cellY); + } + else + cell = getPlayer().getPlayer().getCell(); + + ESM::Position& pos = object.getRefData().getPosition(); + pos.pos[0] = result.second[0]; + pos.pos[1] = -result.second[2]; + pos.pos[2] = result.second[1]; + + mWorldScene->insertObject(object, cell); + + /// \todo retrieve the bounds of the object and translate it accordingly + + return true; } + bool World::canPlaceObject(float cursorX, float cursorY) + { + std::pair result = mPhysics->castRay(cursorX, cursorY); + + /// \todo also check if the wanted position is on a flat surface, and not e.g. against a vertical wall! + + if (!result.first) + return false; + return true; + } + + void World::dropObjectOnGround(MWWorld::Ptr object) + { + MWWorld::Ptr::CellStore* cell = getPlayer().getPlayer().getCell(); + + float* playerPos = getPlayer().getPlayer().getRefData().getPosition().pos; + + ESM::Position& pos = object.getRefData().getPosition(); + pos.pos[0] = playerPos[0]; + pos.pos[1] = playerPos[1]; + pos.pos[2] = playerPos[2]; + + mWorldScene->insertObject(object, cell); + } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 3b56dea97..1ed6a976e 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -263,9 +263,17 @@ namespace MWWorld void update (float duration); - void insertObject (MWWorld::Ptr ptr, Ptr::CellStore* cell); - ///< insert object in a given cell - /// \note this method is only meant for dropping items into the gameworld from a container + bool placeObject(MWWorld::Ptr object, float cursorX, float cursorY); + ///< place an object into the gameworld at the specified cursor position + /// @param object + /// @param cursor X (relative 0-1) + /// @param cursor Y (relative 0-1) + /// @return true if the object was placed, or false if it was rejected because the position is too far away + + void dropObjectOnGround(MWWorld::Ptr object); + + bool canPlaceObject(float cursorX, float cursorY); + ///< @return true if it is possible to place on object at specified cursor location }; } diff --git a/files/mygui/openmw.pointer.xml b/files/mygui/openmw.pointer.xml index 0fbef2fdf..42ee5d435 100644 --- a/files/mygui/openmw.pointer.xml +++ b/files/mygui/openmw.pointer.xml @@ -26,4 +26,9 @@ + + + + + diff --git a/files/mygui/openmw_layers.xml b/files/mygui/openmw_layers.xml index 81cd99fea..a5044fb78 100644 --- a/files/mygui/openmw_layers.xml +++ b/files/mygui/openmw_layers.xml @@ -8,7 +8,6 @@ + - - diff --git a/files/mygui/openmw_resources.xml b/files/mygui/openmw_resources.xml index b2bd90d10..4c509ae13 100644 --- a/files/mygui/openmw_resources.xml +++ b/files/mygui/openmw_resources.xml @@ -36,6 +36,13 @@ + + + + + + + From ab6336b745ca83e96cecb81185ec8912fcf37661 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 18:05:53 +0200 Subject: [PATCH 051/118] using items via the inventory is now possible by dragging them on the avatar (only implemented for books right now) --- apps/openmw/engine.cpp | 18 +------- apps/openmw/mwclass/book.cpp | 6 +++ apps/openmw/mwclass/book.hpp | 3 ++ apps/openmw/mwgui/bookwindow.cpp | 14 ++++-- apps/openmw/mwgui/bookwindow.hpp | 2 + apps/openmw/mwgui/container.cpp | 7 +-- apps/openmw/mwgui/container.hpp | 8 ++++ apps/openmw/mwgui/inventorywindow.cpp | 62 +++++++++++++++++++++++---- apps/openmw/mwgui/inventorywindow.hpp | 3 ++ apps/openmw/mwgui/scrollwindow.cpp | 14 ++++-- apps/openmw/mwgui/scrollwindow.hpp | 2 + apps/openmw/mwworld/actiontake.cpp | 5 ++- apps/openmw/mwworld/ptr.hpp | 5 +++ apps/openmw/mwworld/world.cpp | 27 ++++++++++++ apps/openmw/mwworld/world.hpp | 3 ++ 15 files changed, 144 insertions(+), 35 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 85b0557b1..a9e7c82b0 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -437,25 +437,11 @@ void OMW::Engine::activate() return; } - MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr); - boost::shared_ptr action = MWWorld::Class::get (ptr).activate (ptr, MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); - interpreterContext.activate (ptr, action); - - std::string script = MWWorld::Class::get (ptr).getScript (ptr); - - if (!script.empty()) - { - MWBase::Environment::get().getWorld()->getLocalScripts().setIgnore (ptr); - MWBase::Environment::get().getScriptManager()->run (script, interpreterContext); - } - - if (!interpreterContext.hasActivationBeenHandled()) - { - interpreterContext.executeActivation(); - } + // execute action and script + MWBase::Environment::get().getWorld()->executeActionScript(ptr, action); } void OMW::Engine::screenshot() diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index f58eac7ec..a107d9b21 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -148,4 +148,10 @@ namespace MWClass return ref->base->enchant; } + + boost::shared_ptr Book::use (const MWWorld::Ptr& ptr) const + { + return boost::shared_ptr(new MWWorld::ActionRead(ptr)); + } + } diff --git a/apps/openmw/mwclass/book.hpp b/apps/openmw/mwclass/book.hpp index 6858bac7f..ee3aac8d8 100644 --- a/apps/openmw/mwclass/book.hpp +++ b/apps/openmw/mwclass/book.hpp @@ -47,6 +47,9 @@ namespace MWClass virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string + + virtual boost::shared_ptr use (const MWWorld::Ptr& ptr) const; + ///< Generate action for using via inventory menu }; } diff --git a/apps/openmw/mwgui/bookwindow.cpp b/apps/openmw/mwgui/bookwindow.cpp index 8de45984c..c6411175d 100644 --- a/apps/openmw/mwgui/bookwindow.cpp +++ b/apps/openmw/mwgui/bookwindow.cpp @@ -52,7 +52,7 @@ void BookWindow::open (MWWorld::Ptr book) clearPages(); mCurrentPage = 0; - MWBase::Environment::get().getSoundManager()->playSound3D (book, "book open", 1.0, 1.0); + MWBase::Environment::get().getSoundManager()->playSound ("book open", 1.0, 1.0); ESMS::LiveCellRef *ref = mBook.get(); @@ -77,18 +77,26 @@ void BookWindow::open (MWWorld::Ptr book) } updatePages(); + + setTakeButtonShow(true); +} + +void BookWindow::setTakeButtonShow(bool show) +{ + mTakeButton->setVisible(show); } void BookWindow::onCloseButtonClicked (MyGUI::Widget* _sender) { - MWBase::Environment::get().getSoundManager()->playSound3D (mBook, "book close", 1.0, 1.0); + // no 3d sounds because the object could be in a container. + MWBase::Environment::get().getSoundManager()->playSound ("book close", 1.0, 1.0); MWBase::Environment::get().getInputManager()->setGuiMode(MWGui::GM_Game); } void BookWindow::onTakeButtonClicked (MyGUI::Widget* _sender) { - MWBase::Environment::get().getSoundManager()->playSound3D (mBook, "Item Book Up", 1.0, 1.0, MWSound::Play_NoTrack); + MWBase::Environment::get().getSoundManager()->playSound ("Item Book Up", 1.0, 1.0, MWSound::Play_NoTrack); MWWorld::ActionTake take(mBook); take.execute(); diff --git a/apps/openmw/mwgui/bookwindow.hpp b/apps/openmw/mwgui/bookwindow.hpp index fcea1d11f..9ea011433 100644 --- a/apps/openmw/mwgui/bookwindow.hpp +++ b/apps/openmw/mwgui/bookwindow.hpp @@ -11,7 +11,9 @@ namespace MWGui { public: BookWindow(WindowManager& parWindowManager); + void open(MWWorld::Ptr book); + void setTakeButtonShow(bool show); protected: void onNextPageButtonClicked (MyGUI::Widget* _sender); diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index bab0051b8..ff7bb889e 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -92,6 +92,9 @@ void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) mDragAndDrop->mDraggedWidget = mSelectedItem; static_cast(mSelectedItem->getChildAt(0)->getChildAt(0))->setCaption( getCountString((*mDragAndDrop->mStore.begin()).getRefData().getCount())); + + mDragAndDrop->mWasInInventory = isInventory(); + drawItems(); MWBase::Environment::get().getWindowManager()->setDragDrop(true); @@ -111,9 +114,7 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) containerStore.add(*mDragAndDrop->mStore.begin()); mDragAndDrop->mStore.clear(); mDragAndDrop->mIsOnDragAndDrop = false; - mDragAndDrop->mDraggedWidget->detachFromWidget(); - mDragAndDrop->mDraggedWidget->attachToWidget(mContainerWidget); - mDragAndDrop->mDraggedWidget = 0; + MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget); drawItems(); MWBase::Environment::get().getWindowManager()->setDragDrop(false); diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index b90044ab5..8a1307967 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -36,10 +36,16 @@ namespace MWGui class DragAndDrop { public: + DragAndDrop() : + mWasInInventory(false) + { + } + bool mIsOnDragAndDrop; MyGUI::Widget* mDraggedWidget; MyGUI::Widget* mDragAndDropWidget; MWWorld::ContainerStore mStore; + bool mWasInInventory; // was the item in inventory before it was dragged }; class ContainerBase @@ -81,6 +87,8 @@ namespace MWGui std::string getCountString(const int count); + virtual bool isInventory() { return false; } + void drawItems(); }; diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 23e4949f7..e9c3af7d4 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -1,23 +1,33 @@ #include "inventorywindow.hpp" -#include -#include -#include "window_manager.hpp" -#include "widgets.hpp" -#include "../mwbase/environment.hpp" -#include "../mwworld/manualref.hpp" #include #include #include - #include #include + +#include + #include "../mwclass/container.hpp" #include "../mwworld/containerstore.hpp" -#include #include "../mwworld/class.hpp" #include "../mwworld/world.hpp" #include "../mwworld/player.hpp" +#include "../mwbase/environment.hpp" +#include "../mwworld/manualref.hpp" + +#include "../mwscript/scriptmanager.hpp" +#include "../mwscript/compilercontext.hpp" +#include "../mwscript/interpretercontext.hpp" +#include "../mwscript/extensions.hpp" +#include "../mwscript/globalscripts.hpp" + + +#include "window_manager.hpp" +#include "widgets.hpp" +#include "bookwindow.hpp" +#include "scrollwindow.hpp" + namespace MWGui { @@ -38,6 +48,8 @@ namespace MWGui getWidget(mLeftPane, "LeftPane"); getWidget(mRightPane, "RightPane"); + mAvatar->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onAvatarClicked); + MyGUI::ScrollView* itemView; MyGUI::Widget* containerWidget; getWidget(containerWidget, "Items"); @@ -126,4 +138,38 @@ namespace MWGui mWindowManager.setWeaponVisibility(!mPinned); } + void InventoryWindow::onAvatarClicked(MyGUI::Widget* _sender) + { + if (mDragAndDrop->mIsOnDragAndDrop) + { + MWWorld::Ptr ptr = *mDragAndDrop->mStore.begin(); + + boost::shared_ptr action = MWWorld::Class::get(ptr).use(ptr); + + // execute action and script + MWBase::Environment::get().getWorld()->executeActionScript(ptr, action); + + // this is necessary for books/scrolls: if they are already in the player's inventory, + // the "Take" button should not be visible. + // NOTE: the take button is "reset" when the window opens, so we can safely do the following + // without screwing up future book windows + if (mDragAndDrop->mWasInInventory) + { + mWindowManager.getBookWindow()->setTakeButtonShow(false); + mWindowManager.getScrollWindow()->setTakeButtonShow(false); + } + + // put back in inventory + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); + containerStore.add(ptr); + drawItems(); + + mDragAndDrop->mStore.clear(); + mDragAndDrop->mIsOnDragAndDrop = false; + MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget); + + mWindowManager.setDragDrop(false); + } + } + } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index f16dcf433..b09ff8521 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -47,7 +47,10 @@ namespace MWGui void onWindowResize(MyGUI::Window* _sender); void onFilterChanged(MyGUI::Widget* _sender); + void onAvatarClicked(MyGUI::Widget* _sender); void onPinToggled(); + + virtual bool isInventory() { return true; } }; } #endif // Inventory_H diff --git a/apps/openmw/mwgui/scrollwindow.cpp b/apps/openmw/mwgui/scrollwindow.cpp index 38e2f77c1..877864cfe 100644 --- a/apps/openmw/mwgui/scrollwindow.cpp +++ b/apps/openmw/mwgui/scrollwindow.cpp @@ -25,7 +25,8 @@ ScrollWindow::ScrollWindow (WindowManager& parWindowManager) : void ScrollWindow::open (MWWorld::Ptr scroll) { - MWBase::Environment::get().getSoundManager()->playSound3D (scroll, "scroll", 1.0, 1.0); + // no 3d sounds because the object could be in a container. + MWBase::Environment::get().getSoundManager()->playSound ("scroll", 1.0, 1.0); mScroll = scroll; @@ -41,18 +42,25 @@ void ScrollWindow::open (MWWorld::Ptr scroll) mTextView->setCanvasSize(410, mTextView->getSize().height); mTextView->setViewOffset(MyGUI::IntPoint(0,0)); + + setTakeButtonShow(true); +} + +void ScrollWindow::setTakeButtonShow(bool show) +{ + mTakeButton->setVisible(show); } void ScrollWindow::onCloseButtonClicked (MyGUI::Widget* _sender) { - MWBase::Environment::get().getSoundManager()->playSound3D (mScroll, "scroll", 1.0, 1.0); + MWBase::Environment::get().getSoundManager()->playSound ("scroll", 1.0, 1.0); MWBase::Environment::get().getInputManager()->setGuiMode (GM_Game); } void ScrollWindow::onTakeButtonClicked (MyGUI::Widget* _sender) { - MWBase::Environment::get().getSoundManager()->playSound3D (mScroll, "Item Book Up", 1.0, 1.0, MWSound::Play_NoTrack); + MWBase::Environment::get().getSoundManager()->playSound ("Item Book Up", 1.0, 1.0, MWSound::Play_NoTrack); MWWorld::ActionTake take(mScroll); take.execute(); diff --git a/apps/openmw/mwgui/scrollwindow.hpp b/apps/openmw/mwgui/scrollwindow.hpp index 918a3d3ef..d58596b4b 100644 --- a/apps/openmw/mwgui/scrollwindow.hpp +++ b/apps/openmw/mwgui/scrollwindow.hpp @@ -11,7 +11,9 @@ namespace MWGui { public: ScrollWindow (WindowManager& parWindowManager); + void open (MWWorld::Ptr scroll); + void setTakeButtonShow(bool show); protected: void onCloseButtonClicked (MyGUI::Widget* _sender); diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index b1e2e1fc3..384cb3ffe 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -18,7 +18,8 @@ namespace MWWorld MWWorld::Class::get (player).getContainerStore (player).add (mObject); - // remove from world - MWBase::Environment::get().getWorld()->deleteObject (mObject); + // remove from world, if the item is currently in the world (it could also be in a container) + if (mObject.isInCell()) + MWBase::Environment::get().getWorld()->deleteObject (mObject); } } diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index d6e485f41..4cf3e98da 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -77,6 +77,11 @@ namespace MWWorld return mCell; } + bool isInCell() const + { + return (mCell != 0); + } + void setContainerStore (ContainerStore *store); ///< Must not be called on references that are in a cell. diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 973407b0c..ce7821280 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -17,6 +17,13 @@ #include "../mwgui/window_manager.hpp" +#include "../mwscript/scriptmanager.hpp" +#include "../mwscript/compilercontext.hpp" +#include "../mwscript/interpretercontext.hpp" +#include "../mwscript/extensions.hpp" +#include "../mwscript/globalscripts.hpp" + + #include "ptr.hpp" #include "class.hpp" #include "player.hpp" @@ -1018,4 +1025,24 @@ namespace MWWorld mWorldScene->insertObject(object, cell); } + + void World::executeActionScript(MWWorld::Ptr ptr, boost::shared_ptr action) + { + MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr); + + action->execute(); + + // execute script + interpreterContext.activate (ptr, action); + std::string script = MWWorld::Class::get (ptr).getScript (ptr); + if (!script.empty()) + { + getLocalScripts().setIgnore (ptr); + MWBase::Environment::get().getScriptManager()->run (script, interpreterContext); + } + if (!interpreterContext.hasActivationBeenHandled()) + { + interpreterContext.executeActivation(); + } + } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index 1ed6a976e..c1d4ace20 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -274,6 +274,9 @@ namespace MWWorld bool canPlaceObject(float cursorX, float cursorY); ///< @return true if it is possible to place on object at specified cursor location + + void executeActionScript(MWWorld::Ptr ptr, boost::shared_ptr action); + ///< execute the activation script of an object (when activating the object with space, or when activating it via the inventory) }; } From 765881a61d8b770ff2509f287953198b6dafb721 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 18:20:32 +0200 Subject: [PATCH 052/118] equipping items in the inventorywindow (there is no visual indication yet) --- apps/openmw/mwgui/inventorywindow.cpp | 55 +++++++++++++++++++-------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index e9c3af7d4..956961b63 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -144,24 +144,49 @@ namespace MWGui { MWWorld::Ptr ptr = *mDragAndDrop->mStore.begin(); - boost::shared_ptr action = MWWorld::Class::get(ptr).use(ptr); - - // execute action and script - MWBase::Environment::get().getWorld()->executeActionScript(ptr, action); - - // this is necessary for books/scrolls: if they are already in the player's inventory, - // the "Take" button should not be visible. - // NOTE: the take button is "reset" when the window opens, so we can safely do the following - // without screwing up future book windows - if (mDragAndDrop->mWasInInventory) + // can the object be equipped? + std::pair, bool> slots = MWWorld::Class::get(ptr).getEquipmentSlots(ptr); + if (slots.first.empty()) { - mWindowManager.getBookWindow()->setTakeButtonShow(false); - mWindowManager.getScrollWindow()->setTakeButtonShow(false); + // can't be equipped, try to use instead + boost::shared_ptr action = MWWorld::Class::get(ptr).use(ptr); + + // execute action and script + MWBase::Environment::get().getWorld()->executeActionScript(ptr, action); + + // this is necessary for books/scrolls: if they are already in the player's inventory, + // the "Take" button should not be visible. + // NOTE: the take button is "reset" when the window opens, so we can safely do the following + // without screwing up future book windows + if (mDragAndDrop->mWasInInventory) + { + mWindowManager.getBookWindow()->setTakeButtonShow(false); + mWindowManager.getScrollWindow()->setTakeButtonShow(false); + } + + // put back in inventory + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); + containerStore.add(ptr); + } + else + { + // put back in inventory + MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + invStore.add(ptr); + + // get a ContainerStoreIterator to the item we just re-added into the inventory + MWWorld::ContainerStoreIterator it = invStore.begin(); + MWWorld::ContainerStoreIterator nextIt = ++it; + while (nextIt != invStore.end()) + { + ++it; + ++nextIt; + } + + // equip the item in the first available slot + invStore.equip(slots.first.front(), it); } - // put back in inventory - MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); - containerStore.add(ptr); drawItems(); mDragAndDrop->mStore.clear(); From 71de10cb7ed0e19db20e050f37df41bec65ef480 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 20:33:34 +0200 Subject: [PATCH 053/118] equipping items works, but only if you have more than one of the item that you're equipping --- apps/openmw/mwgui/container.cpp | 57 +++++++++++++++++++++- apps/openmw/mwgui/container.hpp | 12 +++++ apps/openmw/mwgui/inventorywindow.cpp | 66 +++++++++++++++++++++++--- apps/openmw/mwgui/inventorywindow.hpp | 2 + apps/openmw/mwworld/containerstore.cpp | 5 +- apps/openmw/mwworld/containerstore.hpp | 4 +- apps/openmw/mwworld/inventorystore.cpp | 7 +++ apps/openmw/mwworld/inventorystore.hpp | 3 ++ 8 files changed, 145 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index ff7bb889e..6bf6a589e 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -81,6 +81,8 @@ void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) mSelectedItem->attachToWidget(mDragAndDrop->mDragAndDropWidget); MWWorld::Ptr object = *mSelectedItem->getUserData(); + _unequipItem(object); + int originalCount = object.getRefData().getCount(); object.getRefData().setCount(count); mDragAndDrop->mStore.add(object); @@ -90,6 +92,7 @@ void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); mDragAndDrop->mDraggedWidget = mSelectedItem; + static_cast(mSelectedItem)->setImageTexture(""); // remove the background texture (not visible during drag) static_cast(mSelectedItem->getChildAt(0)->getChildAt(0))->setCaption( getCountString((*mDragAndDrop->mStore.begin()).getRefData().getCount())); @@ -181,9 +184,46 @@ void ContainerBase::drawItems() /// \todo performance improvement: don't create/destroy all the widgets everytime the container window changes size, only reposition them + std::vector< std::pair > items; + + std::vector equippedItems = getEquippedItems(); + + // filter out the equipped items of categories we don't want + std::vector unwantedItems = equippedItems; for (MWWorld::ContainerStoreIterator iter (containerStore.begin(categories)); iter!=containerStore.end(); ++iter) + { + std::vector::iterator found = std::find(unwantedItems.begin(), unwantedItems.end(), *iter); + if (found != unwantedItems.end()) + { + unwantedItems.erase(found); + } + } + // now erase everything that's still in unwantedItems. + for (std::vector::iterator it=unwantedItems.begin(); + it != unwantedItems.end(); ++it) + { + equippedItems.erase(std::find(unwantedItems.begin(), unwantedItems.end(), *it)); + } + // and add the items that are left (= have the correct category) + for (std::vector::const_iterator it=equippedItems.begin(); + it != equippedItems.end(); ++it) + { + items.push_back( std::make_pair(*it, ItemState_Equipped) ); + } + + // now add the regular items + for (MWWorld::ContainerStoreIterator iter (containerStore.begin(categories)); iter!=containerStore.end(); ++iter) + { + /// \todo sorting + if (std::find(equippedItems.begin(), equippedItems.end(), *iter) == equippedItems.end()) + items.push_back( std::make_pair(*iter, ItemState_Normal) ); + } + + for (std::vector< std::pair >::const_iterator it=items.begin(); + it != items.end(); ++it) { index++; + const MWWorld::Ptr* iter = &((*it).first); if(iter->getRefData().getCount() > 0 && !(onlyMagic && MWWorld::Class::get(*iter).getEnchantment(*iter) == "" && iter->getTypeName() != typeid(ESM::Potion).name())) { std::string path = std::string("icons\\"); @@ -194,7 +234,22 @@ void ContainerBase::drawItems() MyGUI::ImageBox* backgroundWidget = mContainerWidget->createWidget("ImageBox", MyGUI::IntCoord(x, y, 42, 42), MyGUI::Align::Default); backgroundWidget->setUserString("ToolTipType", "ItemPtr"); backgroundWidget->setUserData(*iter); - backgroundWidget->setImageTexture( isMagic ? "textures\\menu_icon_magic.dds" : ""); + + std::string backgroundTex = "textures\\menu_icon"; + if (isMagic) + backgroundTex += "_magic"; + if (it->second == ItemState_Normal) + { + if (!isMagic) + backgroundTex = ""; + } + else if (it->second == ItemState_Equipped) + { + backgroundTex += "_equip"; + } + backgroundTex += ".dds"; + + backgroundWidget->setImageTexture(backgroundTex); backgroundWidget->setProperty("ImageCoord", "0 0 42 42"); backgroundWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerBase::onSelectedItem); backgroundWidget->eventMouseWheel += MyGUI::newDelegate(this, &ContainerBase::onMouseWheel); diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 8a1307967..9f994be16 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -63,6 +63,15 @@ namespace MWGui Filter_Misc = 0x05 }; + enum ItemState + { + ItemState_Normal = 0x01, + ItemState_Equipped = 0x02, + + // unimplemented + ItemState_Barter = 0x03 + }; + void setWidgets(MyGUI::Widget* containerWidget, MyGUI::ScrollView* itemView); ///< only call once void openContainer(MWWorld::Ptr container); @@ -87,7 +96,10 @@ namespace MWGui std::string getCountString(const int count); + // to be reimplemented by InventoryWindow virtual bool isInventory() { return false; } + virtual std::vector getEquippedItems() { return std::vector(); } + virtual void _unequipItem(MWWorld::Ptr item) { ; } void drawItems(); }; diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 956961b63..e466c34d1 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -151,6 +151,8 @@ namespace MWGui // can't be equipped, try to use instead boost::shared_ptr action = MWWorld::Class::get(ptr).use(ptr); + std::cout << "Item can't be equipped" << std::endl; + // execute action and script MWBase::Environment::get().getWorld()->executeActionScript(ptr, action); @@ -172,19 +174,31 @@ namespace MWGui { // put back in inventory MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); - invStore.add(ptr); - // get a ContainerStoreIterator to the item we just re-added into the inventory - MWWorld::ContainerStoreIterator it = invStore.begin(); - MWWorld::ContainerStoreIterator nextIt = ++it; - while (nextIt != invStore.end()) + MWWorld::ContainerStoreIterator it = invStore.add(ptr); + + // retrieve iterator to the item we just re-added (if stacking didn't happen). + // if stacking happened, the iterator was already returned by the add() call + /// \todo this does not work! + if (it == invStore.end()) { - ++it; - ++nextIt; + std::cout << "stacking didn't happen" << std::endl; + for (MWWorld::ContainerStoreIterator it2 = invStore.begin(); + it2 != invStore.end(); ++it2) + { + if (*it2 == ptr) + { + std::cout << "found iterator" << std::endl; + it = it2; + return; + } + } } // equip the item in the first available slot invStore.equip(slots.first.front(), it); + + std::cout << "Equipped item in slot " << slots.first.front() << std::endl; } drawItems(); @@ -197,4 +211,42 @@ namespace MWGui } } + std::vector InventoryWindow::getEquippedItems() + { + MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + + std::vector items; + + for (int slot=0; slot < MWWorld::InventoryStore::Slots; ++slot) + { + MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); + if (it != invStore.end()) + { + std::cout << "slot " << slot << " is equipped" << std::endl; + items.push_back(*it); + } + else + { + std::cout << "slot " << slot << " is empty " << std::endl; + } + + } + + return items; + } + + void InventoryWindow::_unequipItem(MWWorld::Ptr item) + { + MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + + for (int slot=0; slot < MWWorld::InventoryStore::Slots; ++slot) + { + MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); + if (it != invStore.end() && *it == item) + { + invStore._freeSlot(slot); + return; + } + } + } } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index b09ff8521..18dc913fc 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -51,6 +51,8 @@ namespace MWGui void onPinToggled(); virtual bool isInventory() { return true; } + virtual std::vector getEquippedItems(); + virtual void _unequipItem(MWWorld::Ptr item); }; } #endif // Inventory_H diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index ee1b620cd..2e69de9c3 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -58,7 +58,7 @@ bool MWWorld::ContainerStore::stacks(const Ptr& ptr1, const Ptr& ptr2) return false; } -void MWWorld::ContainerStore::add (const Ptr& ptr) +MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr) { int type = getType(ptr); @@ -71,12 +71,13 @@ void MWWorld::ContainerStore::add (const Ptr& ptr) iter->getRefData().setCount( iter->getRefData().getCount() + ptr.getRefData().getCount() ); flagAsModified(); - return; + return iter; } } // if we got here, this means no stacking addImpl(ptr); + return end(); } void MWWorld::ContainerStore::addImpl (const Ptr& ptr) diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index 3cb3f3bdc..26c9f55a3 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -66,13 +66,15 @@ namespace MWWorld ContainerStoreIterator end(); - void add (const Ptr& ptr); + ContainerStoreIterator add (const Ptr& ptr); ///< Add the item pointed to by \a ptr to this container. (Stacks automatically if needed) /// /// \note The item pointed to is not required to exist beyond this function call. /// /// \attention Do not add items to an existing stack by increasing the count instead of /// calling this function! + /// + /// @return if stacking happened, return iterator to the item that was stacked against, otherwise end() iterator protected: void addImpl (const Ptr& ptr); diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index 3e535793c..b38167d70 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -97,6 +97,13 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite flagAsModified(); } +void MWWorld::InventoryStore::_freeSlot(int slot) +{ + mSlots[slot] = end(); + + flagAsModified(); +} + MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot) { if (slot<0 || slot>=static_cast (mSlots.size())) diff --git a/apps/openmw/mwworld/inventorystore.hpp b/apps/openmw/mwworld/inventorystore.hpp index 05fc651ee..303604f4d 100644 --- a/apps/openmw/mwworld/inventorystore.hpp +++ b/apps/openmw/mwworld/inventorystore.hpp @@ -60,6 +60,9 @@ namespace MWWorld void equip (int slot, const ContainerStoreIterator& iterator); ///< \note \a iteartor can be an end-iterator + void _freeSlot(int slot); + ///< this method is dangerous, as it doesn't do re-stacking items - you probably want to use equip() + ContainerStoreIterator getSlot (int slot); void autoEquip (const MWMechanics::NpcStats& stats); From ca4fa21d64256244615a4fe86ffa2126be79ec35 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 20:51:19 +0200 Subject: [PATCH 054/118] removed the attempt to unify activation and use scripts which was incorrect --- apps/openmw/engine.cpp | 18 ++++++++++++++++-- apps/openmw/mwgui/inventorywindow.cpp | 5 +++-- apps/openmw/mwworld/world.cpp | 27 --------------------------- apps/openmw/mwworld/world.hpp | 3 --- 4 files changed, 19 insertions(+), 34 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index a9e7c82b0..85b0557b1 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -437,11 +437,25 @@ void OMW::Engine::activate() return; } + MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr); + boost::shared_ptr action = MWWorld::Class::get (ptr).activate (ptr, MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); - // execute action and script - MWBase::Environment::get().getWorld()->executeActionScript(ptr, action); + interpreterContext.activate (ptr, action); + + std::string script = MWWorld::Class::get (ptr).getScript (ptr); + + if (!script.empty()) + { + MWBase::Environment::get().getWorld()->getLocalScripts().setIgnore (ptr); + MWBase::Environment::get().getScriptManager()->run (script, interpreterContext); + } + + if (!interpreterContext.hasActivationBeenHandled()) + { + interpreterContext.executeActivation(); + } } void OMW::Engine::screenshot() diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index e466c34d1..ef41bf10a 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -153,8 +153,9 @@ namespace MWGui std::cout << "Item can't be equipped" << std::endl; - // execute action and script - MWBase::Environment::get().getWorld()->executeActionScript(ptr, action); + action->execute(); + + /// \todo scripts // this is necessary for books/scrolls: if they are already in the player's inventory, // the "Take" button should not be visible. diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index ce7821280..973407b0c 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -17,13 +17,6 @@ #include "../mwgui/window_manager.hpp" -#include "../mwscript/scriptmanager.hpp" -#include "../mwscript/compilercontext.hpp" -#include "../mwscript/interpretercontext.hpp" -#include "../mwscript/extensions.hpp" -#include "../mwscript/globalscripts.hpp" - - #include "ptr.hpp" #include "class.hpp" #include "player.hpp" @@ -1025,24 +1018,4 @@ namespace MWWorld mWorldScene->insertObject(object, cell); } - - void World::executeActionScript(MWWorld::Ptr ptr, boost::shared_ptr action) - { - MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr); - - action->execute(); - - // execute script - interpreterContext.activate (ptr, action); - std::string script = MWWorld::Class::get (ptr).getScript (ptr); - if (!script.empty()) - { - getLocalScripts().setIgnore (ptr); - MWBase::Environment::get().getScriptManager()->run (script, interpreterContext); - } - if (!interpreterContext.hasActivationBeenHandled()) - { - interpreterContext.executeActivation(); - } - } } diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index c1d4ace20..1ed6a976e 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -274,9 +274,6 @@ namespace MWWorld bool canPlaceObject(float cursorX, float cursorY); ///< @return true if it is possible to place on object at specified cursor location - - void executeActionScript(MWWorld::Ptr ptr, boost::shared_ptr action); - ///< execute the activation script of an object (when activating the object with space, or when activating it via the inventory) }; } From 175623bf22ab3608231524fae7164d05bb2154ae Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 21:44:57 +0200 Subject: [PATCH 055/118] change the drag&drop to not use a seperate containerstore --- apps/openmw/mwgui/container.cpp | 40 ++++++++++++++++++--------- apps/openmw/mwgui/container.hpp | 7 +++-- apps/openmw/mwgui/hud.cpp | 6 ++-- apps/openmw/mwgui/inventorywindow.cpp | 34 +++++++---------------- 4 files changed, 45 insertions(+), 42 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 6bf6a589e..66ccfd50f 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -83,10 +83,9 @@ void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) MWWorld::Ptr object = *mSelectedItem->getUserData(); _unequipItem(object); - int originalCount = object.getRefData().getCount(); - object.getRefData().setCount(count); - mDragAndDrop->mStore.add(object); - object.getRefData().setCount(originalCount - count); + mDragAndDrop->mDraggedCount = count; + + mDragAndDrop->mDraggedFrom = this; std::string sound = MWWorld::Class::get(object).getUpSoundId(object); MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); @@ -94,7 +93,7 @@ void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) mDragAndDrop->mDraggedWidget = mSelectedItem; static_cast(mSelectedItem)->setImageTexture(""); // remove the background texture (not visible during drag) static_cast(mSelectedItem->getChildAt(0)->getChildAt(0))->setCaption( - getCountString((*mDragAndDrop->mStore.begin()).getRefData().getCount())); + getCountString(mDragAndDrop->mDraggedCount)); mDragAndDrop->mWasInInventory = isInventory(); @@ -108,19 +107,27 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here { MWWorld::Ptr object = *mDragAndDrop->mDraggedWidget->getUserData(); - assert(object.getContainerStore() && "Item is not in a container!"); - std::string sound = MWWorld::Class::get(object).getDownSoundId(object); - MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); + if (mDragAndDrop->mDraggedFrom != this) + { + assert(object.getContainerStore() && "Item is not in a container!"); + + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); + int origCount = object.getRefData().getCount(); + object.getRefData().setCount (mDragAndDrop->mDraggedCount); + containerStore.add(object); + object.getRefData().setCount (origCount - mDragAndDrop->mDraggedCount); + } - MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); - containerStore.add(*mDragAndDrop->mStore.begin()); - mDragAndDrop->mStore.clear(); mDragAndDrop->mIsOnDragAndDrop = false; MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget); drawItems(); + mDragAndDrop->mDraggedFrom->drawItems(); MWBase::Environment::get().getWindowManager()->setDragDrop(false); + + std::string sound = MWWorld::Class::get(object).getDownSoundId(object); + MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); } } @@ -224,7 +231,14 @@ void ContainerBase::drawItems() { index++; const MWWorld::Ptr* iter = &((*it).first); - if(iter->getRefData().getCount() > 0 && !(onlyMagic && MWWorld::Class::get(*iter).getEnchantment(*iter) == "" && iter->getTypeName() != typeid(ESM::Potion).name())) + + int displayCount = iter->getRefData().getCount(); + if (mDragAndDrop->mIsOnDragAndDrop && *iter == *mDragAndDrop->mDraggedWidget->getUserData()) + { + std::cout << "beep" << std::endl; + displayCount -= mDragAndDrop->mDraggedCount; +} + if(displayCount > 0 && !(onlyMagic && MWWorld::Class::get(*iter).getEnchantment(*iter) == "" && iter->getTypeName() != typeid(ESM::Potion).name())) { std::string path = std::string("icons\\"); path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); @@ -276,7 +290,7 @@ void ContainerBase::drawItems() y = 0; } - text->setCaption(getCountString(iter->getRefData().getCount())); + text->setCaption(getCountString(displayCount)); } } diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 9f994be16..a19f9e91f 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -44,7 +44,8 @@ namespace MWGui bool mIsOnDragAndDrop; MyGUI::Widget* mDraggedWidget; MyGUI::Widget* mDragAndDropWidget; - MWWorld::ContainerStore mStore; + ContainerBase* mDraggedFrom; + int mDraggedCount; bool mWasInInventory; // was the item in inventory before it was dragged }; @@ -77,6 +78,8 @@ namespace MWGui void openContainer(MWWorld::Ptr container); void setFilter(Filter filter); ///< set category filter void Update(); + void drawItems(); + protected: MyGUI::ScrollView* mItemView; @@ -100,8 +103,6 @@ namespace MWGui virtual bool isInventory() { return false; } virtual std::vector getEquippedItems() { return std::vector(); } virtual void _unequipItem(MWWorld::Ptr item) { ; } - - void drawItems(); }; class ContainerWindow : public ContainerBase, public WindowBase diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index b99276440..90adb80d5 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -260,7 +260,7 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender) if (mDragAndDrop->mIsOnDragAndDrop) { // drop item into the gameworld - MWWorld::Ptr object = *mDragAndDrop->mStore.begin(); + MWWorld::Ptr object = *mDragAndDrop->mDraggedWidget->getUserData(); MWWorld::World* world = MWBase::Environment::get().getWorld(); @@ -279,7 +279,9 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender) std::string sound = MWWorld::Class::get(object).getDownSoundId(object); MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); - mDragAndDrop->mStore.clear(); + // remove object from the container it was coming from + object.getRefData().setCount(0); + mDragAndDrop->mIsOnDragAndDrop = false; MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget); mDragAndDrop->mDraggedWidget = 0; diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index ef41bf10a..0c8ac459f 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -142,7 +142,7 @@ namespace MWGui { if (mDragAndDrop->mIsOnDragAndDrop) { - MWWorld::Ptr ptr = *mDragAndDrop->mStore.begin(); + MWWorld::Ptr ptr = *mDragAndDrop->mDraggedWidget->getUserData(); // can the object be equipped? std::pair, bool> slots = MWWorld::Class::get(ptr).getEquipmentSlots(ptr); @@ -166,49 +166,35 @@ namespace MWGui mWindowManager.getBookWindow()->setTakeButtonShow(false); mWindowManager.getScrollWindow()->setTakeButtonShow(false); } - - // put back in inventory - MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); - containerStore.add(ptr); } else { - // put back in inventory MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); - MWWorld::ContainerStoreIterator it = invStore.add(ptr); - - // retrieve iterator to the item we just re-added (if stacking didn't happen). - // if stacking happened, the iterator was already returned by the add() call - /// \todo this does not work! - if (it == invStore.end()) + // retrieve iterator to the item + MWWorld::ContainerStoreIterator it = invStore.begin(); + for (; it != invStore.end(); ++it) { - std::cout << "stacking didn't happen" << std::endl; - for (MWWorld::ContainerStoreIterator it2 = invStore.begin(); - it2 != invStore.end(); ++it2) + if (*it == ptr) { - if (*it2 == ptr) - { - std::cout << "found iterator" << std::endl; - it = it2; - return; - } + break; } } + assert(it != invStore.end()); + // equip the item in the first available slot invStore.equip(slots.first.front(), it); std::cout << "Equipped item in slot " << slots.first.front() << std::endl; } - drawItems(); - - mDragAndDrop->mStore.clear(); mDragAndDrop->mIsOnDragAndDrop = false; MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget); mWindowManager.setDragDrop(false); + + drawItems(); } } From d3a53ae0b8f295cff46f0dfafa01d576e8aac15f Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 22:01:09 +0200 Subject: [PATCH 056/118] removed the _freeSlot method which is now unneeded --- apps/openmw/mwgui/inventorywindow.cpp | 2 +- apps/openmw/mwworld/inventorystore.cpp | 7 ------- apps/openmw/mwworld/inventorystore.hpp | 3 --- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 0c8ac459f..5e33d4600 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -231,7 +231,7 @@ namespace MWGui MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); if (it != invStore.end() && *it == item) { - invStore._freeSlot(slot); + invStore.equip(slot, invStore.end()); return; } } diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index b38167d70..3e535793c 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -97,13 +97,6 @@ void MWWorld::InventoryStore::equip (int slot, const ContainerStoreIterator& ite flagAsModified(); } -void MWWorld::InventoryStore::_freeSlot(int slot) -{ - mSlots[slot] = end(); - - flagAsModified(); -} - MWWorld::ContainerStoreIterator MWWorld::InventoryStore::getSlot (int slot) { if (slot<0 || slot>=static_cast (mSlots.size())) diff --git a/apps/openmw/mwworld/inventorystore.hpp b/apps/openmw/mwworld/inventorystore.hpp index 303604f4d..05fc651ee 100644 --- a/apps/openmw/mwworld/inventorystore.hpp +++ b/apps/openmw/mwworld/inventorystore.hpp @@ -60,9 +60,6 @@ namespace MWWorld void equip (int slot, const ContainerStoreIterator& iterator); ///< \note \a iteartor can be an end-iterator - void _freeSlot(int slot); - ///< this method is dangerous, as it doesn't do re-stacking items - you probably want to use equip() - ContainerStoreIterator getSlot (int slot); void autoEquip (const MWMechanics::NpcStats& stats); From e9ea1fba4e85ab99fc030ace36512f64d1140d9c Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 22:31:52 +0200 Subject: [PATCH 057/118] fixed typo getCapacity method --- apps/openmw/mwclass/container.cpp | 2 +- apps/openmw/mwclass/container.hpp | 2 +- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/creature.hpp | 2 +- apps/openmw/mwclass/npc.cpp | 2 +- apps/openmw/mwclass/npc.hpp | 2 +- apps/openmw/mwworld/class.cpp | 2 +- apps/openmw/mwworld/class.hpp | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 2e0d2d866..e9b8ce31f 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -180,7 +180,7 @@ namespace MWClass return info; } - float Container::getCapactiy (const MWWorld::Ptr& ptr) const + float Container::getCapacity (const MWWorld::Ptr& ptr) const { ESMS::LiveCellRef *ref = ptr.get(); diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp index 61a0d912b..44f0fe927 100644 --- a/apps/openmw/mwclass/container.hpp +++ b/apps/openmw/mwclass/container.hpp @@ -36,7 +36,7 @@ namespace MWClass virtual std::string getScript (const MWWorld::Ptr& ptr) const; ///< Return name of the script attached to ptr - virtual float getCapactiy (const MWWorld::Ptr& ptr) const; + virtual float getCapacity (const MWWorld::Ptr& ptr) const; ///< Return total weight that fits into the object. Throws an exception, if the object can't /// hold other objects. diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index c2623500d..653fabd08 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -166,7 +166,7 @@ namespace MWClass return info; } - float Creature::getCapactiy (const MWWorld::Ptr& ptr) const + float Creature::getCapacity (const MWWorld::Ptr& ptr) const { const MWMechanics::CreatureStats& stats = getCreatureStats (ptr); return stats.mAttributes[0].getModified()*5; diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index 7224d3ee1..9d9491579 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -52,7 +52,7 @@ namespace MWClass virtual std::string getScript (const MWWorld::Ptr& ptr) const; ///< Return name of the script attached to ptr - virtual float getCapactiy (const MWWorld::Ptr& ptr) const; + virtual float getCapacity (const MWWorld::Ptr& ptr) const; ///< Return total weight that fits into the object. Throws an exception, if the object can't /// hold other objects. diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 556798bf4..db0a6460c 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -324,7 +324,7 @@ namespace MWClass return info; } - float Npc::getCapactiy (const MWWorld::Ptr& ptr) const + float Npc::getCapacity (const MWWorld::Ptr& ptr) const { const MWMechanics::CreatureStats& stats = getCreatureStats (ptr); return stats.mAttributes[0].getModified()*5; diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 0cfad0347..ef154bad4 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -74,7 +74,7 @@ namespace MWClass ///< Return desired movement vector (determined based on movement settings, /// stance and stats). - virtual float getCapactiy (const MWWorld::Ptr& ptr) const; + virtual float getCapacity (const MWWorld::Ptr& ptr) const; ///< Return total weight that fits into the object. Throws an exception, if the object can't /// hold other objects. diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index c014fb375..15bc405ce 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -142,7 +142,7 @@ namespace MWWorld throw std::logic_error ("value not supported by this class"); } - float Class::getCapactiy (const MWWorld::Ptr& ptr) const + float Class::getCapacity (const MWWorld::Ptr& ptr) const { throw std::runtime_error ("capacity not supported by this class"); } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 7bf13d822..a8f2aba17 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -164,7 +164,7 @@ namespace MWWorld ///< Return trade value of the object. Throws an exception, if the object can't be traded. /// (default implementation: throws an exception) - virtual float getCapactiy (const MWWorld::Ptr& ptr) const; + virtual float getCapacity (const MWWorld::Ptr& ptr) const; ///< Return total weight that fits into the object. Throws an exception, if the object can't /// hold other objects. /// (default implementation: throws an exception) From 3f4ce327270e862cdd91667ea3782984d9bf56b2 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 22:45:46 +0200 Subject: [PATCH 058/118] implemented player encumbrance bar --- apps/openmw/mwgui/container.cpp | 2 ++ apps/openmw/mwgui/container.hpp | 1 + apps/openmw/mwgui/hud.cpp | 1 + apps/openmw/mwgui/inventorywindow.cpp | 21 ++++++++++++++++++++- apps/openmw/mwgui/inventorywindow.hpp | 4 ++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 66ccfd50f..52714fd22 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -297,6 +297,8 @@ void ContainerBase::drawItems() MyGUI::IntSize size = MyGUI::IntSize(std::max(mItemView->getSize().width, x+42), mItemView->getSize().height); mItemView->setCanvasSize(size); mContainerWidget->setSize(size); + + notifyContentChanged(); } std::string ContainerBase::getCountString(const int count) diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index a19f9e91f..d93cdd187 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -80,6 +80,7 @@ namespace MWGui void Update(); void drawItems(); + virtual void notifyContentChanged() { } protected: MyGUI::ScrollView* mItemView; diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 90adb80d5..d327653f0 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -281,6 +281,7 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender) // remove object from the container it was coming from object.getRefData().setCount(0); + mDragAndDrop->mDraggedFrom->notifyContentChanged(); mDragAndDrop->mIsOnDragAndDrop = false; MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 5e33d4600..8eb4b7bb1 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -95,9 +95,12 @@ namespace MWGui void InventoryWindow::openInventory() { - openContainer(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + openContainer(player); onWindowResize(static_cast(mMainWidget)); + + updateEncumbranceBar(); } void InventoryWindow::onWindowResize(MyGUI::Window* _sender) @@ -236,4 +239,20 @@ namespace MWGui } } } + + void InventoryWindow::updateEncumbranceBar() + { + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + + float capacity = MWWorld::Class::get(player).getCapacity(player); + float encumbrance = MWWorld::Class::get(player).getEncumbrance(player); + mEncumbranceBar->setProgressRange(capacity); + mEncumbranceBar->setProgressPosition(encumbrance); + mEncumbranceText->setCaption( boost::lexical_cast(int(encumbrance)) + "/" + boost::lexical_cast(int(capacity)) ); + } + + void InventoryWindow::notifyContentChanged() + { + updateEncumbranceBar(); + } } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 18dc913fc..c1a36bd56 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -30,6 +30,8 @@ namespace MWGui void openInventory(); + virtual void notifyContentChanged(); + protected: MyGUI::Widget* mAvatar; MyGUI::TextBox* mArmorRating; @@ -50,6 +52,8 @@ namespace MWGui void onAvatarClicked(MyGUI::Widget* _sender); void onPinToggled(); + void updateEncumbranceBar(); + virtual bool isInventory() { return true; } virtual std::vector getEquippedItems(); virtual void _unequipItem(MWWorld::Ptr item); From 5a43fe3e5ff3d2d6fedb15d56f43291663dc40d3 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 22:48:14 +0200 Subject: [PATCH 059/118] remove debug prints --- apps/openmw/mwgui/container.cpp | 1 - apps/openmw/mwgui/inventorywindow.cpp | 10 ---------- 2 files changed, 11 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 52714fd22..6d80c16ed 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -235,7 +235,6 @@ void ContainerBase::drawItems() int displayCount = iter->getRefData().getCount(); if (mDragAndDrop->mIsOnDragAndDrop && *iter == *mDragAndDrop->mDraggedWidget->getUserData()) { - std::cout << "beep" << std::endl; displayCount -= mDragAndDrop->mDraggedCount; } if(displayCount > 0 && !(onlyMagic && MWWorld::Class::get(*iter).getEnchantment(*iter) == "" && iter->getTypeName() != typeid(ESM::Potion).name())) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 8eb4b7bb1..dbf335e5f 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -154,8 +154,6 @@ namespace MWGui // can't be equipped, try to use instead boost::shared_ptr action = MWWorld::Class::get(ptr).use(ptr); - std::cout << "Item can't be equipped" << std::endl; - action->execute(); /// \todo scripts @@ -188,8 +186,6 @@ namespace MWGui // equip the item in the first available slot invStore.equip(slots.first.front(), it); - - std::cout << "Equipped item in slot " << slots.first.front() << std::endl; } mDragAndDrop->mIsOnDragAndDrop = false; @@ -212,14 +208,8 @@ namespace MWGui MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); if (it != invStore.end()) { - std::cout << "slot " << slot << " is equipped" << std::endl; items.push_back(*it); } - else - { - std::cout << "slot " << slot << " is empty " << std::endl; - } - } return items; From 0f811edb4705c31c930bd11d7bf976319a1ca4dc Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 22:54:28 +0200 Subject: [PATCH 060/118] fixed a bug with dropping items on the ground --- apps/openmw/mwgui/hud.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index d327653f0..96c971c4e 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -280,7 +280,7 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender) MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); // remove object from the container it was coming from - object.getRefData().setCount(0); + object.getRefData().setCount(object.getRefData().getCount() - mDragAndDrop->mDraggedCount); mDragAndDrop->mDraggedFrom->notifyContentChanged(); mDragAndDrop->mIsOnDragAndDrop = false; From 477f1b42ab48495c320f02a32caa4aa99b994f0c Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 15 May 2012 23:28:04 +0200 Subject: [PATCH 061/118] fixed another item dropping bug --- apps/openmw/mwgui/container.cpp | 11 +++++++++++ apps/openmw/mwgui/container.hpp | 2 +- apps/openmw/mwgui/hud.cpp | 5 ++++- apps/openmw/mwgui/inventorywindow.cpp | 6 ++++++ apps/openmw/mwgui/inventorywindow.hpp | 1 + 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 6d80c16ed..5ae943ea4 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -118,6 +118,17 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) containerStore.add(object); object.getRefData().setCount (origCount - mDragAndDrop->mDraggedCount); } + else + { + // check that we don't exceed the allowed weight (only for containers, not for inventory) + if (isInventory()) + { + float curWeight = MWWorld::Class::get(mContainer).getEncumbrance(mContainer); + float capacity = MWWorld::Class::get(mContainer).getCapacity(mContainer); + + + } + } mDragAndDrop->mIsOnDragAndDrop = false; MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget); diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index d93cdd187..174f18f9a 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -77,7 +77,7 @@ namespace MWGui void openContainer(MWWorld::Ptr container); void setFilter(Filter filter); ///< set category filter - void Update(); + virtual void Update(); void drawItems(); virtual void notifyContentChanged() { } diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 96c971c4e..c15801da4 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -269,6 +269,9 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender) float mouseX = cursorPosition.left / float(viewSize.width); float mouseY = cursorPosition.top / float(viewSize.height); + int origCount = object.getRefData().getCount(); + object.getRefData().setCount(mDragAndDrop->mDraggedCount); + if (world->canPlaceObject(mouseX, mouseY)) world->placeObject(object, mouseX, mouseY); else @@ -280,7 +283,7 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender) MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); // remove object from the container it was coming from - object.getRefData().setCount(object.getRefData().getCount() - mDragAndDrop->mDraggedCount); + object.getRefData().setCount(origCount - mDragAndDrop->mDraggedCount); mDragAndDrop->mDraggedFrom->notifyContentChanged(); mDragAndDrop->mIsOnDragAndDrop = false; diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index dbf335e5f..a1e73d0ed 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -242,7 +242,13 @@ namespace MWGui } void InventoryWindow::notifyContentChanged() + { + } + + void InventoryWindow::Update() { updateEncumbranceBar(); + + ContainerBase::Update(); } } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index c1a36bd56..ae0d80986 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -30,6 +30,7 @@ namespace MWGui void openInventory(); + virtual void Update(); virtual void notifyContentChanged(); protected: From 2fa7ce0c1903fed551da09300f65bc5389416b25 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 00:02:05 +0200 Subject: [PATCH 062/118] equipping works also when the item wasn't in player inventory before. --- apps/openmw/mwgui/inventorywindow.cpp | 39 +++++++++++++++--- apps/openmw/mwworld/containerstore.cpp | 57 +++++++++++++++++++------- apps/openmw/mwworld/containerstore.hpp | 16 +++++++- 3 files changed, 90 insertions(+), 22 deletions(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index a1e73d0ed..b3da52b02 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -172,20 +172,47 @@ namespace MWGui { MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); - // retrieve iterator to the item MWWorld::ContainerStoreIterator it = invStore.begin(); - for (; it != invStore.end(); ++it) + + if (mDragAndDrop->mDraggedFrom != this) { - if (*it == ptr) + // add item to the player's inventory + int origCount = ptr.getRefData().getCount(); + ptr.getRefData().setCount(origCount - mDragAndDrop->mDraggedCount); + it = invStore.add(ptr); + (*it).getRefData().setCount(mDragAndDrop->mDraggedCount); + } + else + { + // retrieve iterator to the item + for (; it != invStore.end(); ++it) { - break; + if (*it == ptr) + { + break; + } } } assert(it != invStore.end()); - // equip the item in the first available slot - invStore.equip(slots.first.front(), it); + // equip the item in the first free slot + for (std::vector::const_iterator slot=slots.first.begin(); + slot!=slots.first.end(); ++slot) + { + // if all slots are occupied, replace the last slot + if (slot == --slots.first.end()) + { + invStore.equip(*slot, it); + break; + } + + if (invStore.getSlot(*slot) == invStore.end()) + { + invStore.equip(*slot, it); + break; + } + } } mDragAndDrop->mIsOnDragAndDrop = false; diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 2e69de9c3..eca720603 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -76,29 +76,31 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr) } // if we got here, this means no stacking - addImpl(ptr); - return end(); + return addImpl(ptr); } -void MWWorld::ContainerStore::addImpl (const Ptr& ptr) +MWWorld::ContainerStoreIterator MWWorld::ContainerStore::addImpl (const Ptr& ptr) { + ContainerStoreIterator it = begin(); + switch (getType(ptr)) { - case Type_Potion: potions.list.push_back (*ptr.get()); break; - case Type_Apparatus: appas.list.push_back (*ptr.get()); break; - case Type_Armor: armors.list.push_back (*ptr.get()); break; - case Type_Book: books.list.push_back (*ptr.get()); break; - case Type_Clothing: clothes.list.push_back (*ptr.get()); break; - case Type_Ingredient: ingreds.list.push_back (*ptr.get()); break; - case Type_Light: lights.list.push_back (*ptr.get()); break; - case Type_Lockpick: lockpicks.list.push_back (*ptr.get()); break; - case Type_Miscellaneous: miscItems.list.push_back (*ptr.get()); break; - case Type_Probe: probes.list.push_back (*ptr.get()); break; - case Type_Repair: repairs.list.push_back (*ptr.get()); break; - case Type_Weapon: weapons.list.push_back (*ptr.get()); break; + case Type_Potion: potions.list.push_back (*ptr.get()); it = ContainerStoreIterator(this, --potions.list.end()); break; + case Type_Apparatus: appas.list.push_back (*ptr.get()); it = ContainerStoreIterator(this, --appas.list.end()); break; + case Type_Armor: armors.list.push_back (*ptr.get()); it = ContainerStoreIterator(this, --armors.list.end()); break; + case Type_Book: books.list.push_back (*ptr.get()); it = ContainerStoreIterator(this, --books.list.end()); break; + case Type_Clothing: clothes.list.push_back (*ptr.get()); it = ContainerStoreIterator(this, --clothes.list.end()); break; + case Type_Ingredient: ingreds.list.push_back (*ptr.get()); it = ContainerStoreIterator(this, --ingreds.list.end()); break; + case Type_Light: lights.list.push_back (*ptr.get()); it = ContainerStoreIterator(this, --lights.list.end()); break; + case Type_Lockpick: lockpicks.list.push_back (*ptr.get()); it = ContainerStoreIterator(this, --lockpicks.list.end()); break; + case Type_Miscellaneous: miscItems.list.push_back (*ptr.get()); it = ContainerStoreIterator(this, --miscItems.list.end()); break; + case Type_Probe: probes.list.push_back (*ptr.get()); it = ContainerStoreIterator(this, --probes.list.end()); break; + case Type_Repair: repairs.list.push_back (*ptr.get()); it = ContainerStoreIterator(this, --repairs.list.end()); break; + case Type_Weapon: weapons.list.push_back (*ptr.get()); it = ContainerStoreIterator(this, --weapons.list.end()); break; } flagAsModified(); + return it; } void MWWorld::ContainerStore::fill (const ESM::InventoryList& items, const ESMS::ESMStore& store) @@ -231,6 +233,31 @@ MWWorld::ContainerStoreIterator::ContainerStoreIterator (int mask, ContainerStor nextType(); } +MWWorld::ContainerStoreIterator::ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator iterator) + : mType(MWWorld::ContainerStore::Type_Potion), mMask(MWWorld::ContainerStore::Type_All), mContainer(container), mPotion(iterator){} +MWWorld::ContainerStoreIterator::ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator iterator) + : mType(MWWorld::ContainerStore::Type_Apparatus), mMask(MWWorld::ContainerStore::Type_All), mContainer(container), mApparatus(iterator){} +MWWorld::ContainerStoreIterator::ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator iterator) + : mType(MWWorld::ContainerStore::Type_Armor), mMask(MWWorld::ContainerStore::Type_All), mContainer(container), mArmor(iterator){} +MWWorld::ContainerStoreIterator::ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator iterator) + : mType(MWWorld::ContainerStore::Type_Book), mMask(MWWorld::ContainerStore::Type_All), mContainer(container), mBook(iterator){} +MWWorld::ContainerStoreIterator::ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator iterator) + : mType(MWWorld::ContainerStore::Type_Clothing), mMask(MWWorld::ContainerStore::Type_All), mContainer(container), mClothing(iterator){} +MWWorld::ContainerStoreIterator::ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator iterator) + : mType(MWWorld::ContainerStore::Type_Ingredient), mMask(MWWorld::ContainerStore::Type_All), mContainer(container), mIngredient(iterator){} +MWWorld::ContainerStoreIterator::ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator iterator) + : mType(MWWorld::ContainerStore::Type_Light), mMask(MWWorld::ContainerStore::Type_All), mContainer(container), mLight(iterator){} +MWWorld::ContainerStoreIterator::ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator iterator) + : mType(MWWorld::ContainerStore::Type_Lockpick), mMask(MWWorld::ContainerStore::Type_All), mContainer(container), mLockpick(iterator){} +MWWorld::ContainerStoreIterator::ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator iterator) + : mType(MWWorld::ContainerStore::Type_Miscellaneous), mMask(MWWorld::ContainerStore::Type_All), mContainer(container), mMiscellaneous(iterator){} +MWWorld::ContainerStoreIterator::ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator iterator) + : mType(MWWorld::ContainerStore::Type_Probe), mMask(MWWorld::ContainerStore::Type_All), mContainer(container), mProbe(iterator){} +MWWorld::ContainerStoreIterator::ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator iterator) + : mType(MWWorld::ContainerStore::Type_Repair), mMask(MWWorld::ContainerStore::Type_All), mContainer(container), mRepair(iterator){} +MWWorld::ContainerStoreIterator::ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator iterator) + : mType(MWWorld::ContainerStore::Type_Weapon), mMask(MWWorld::ContainerStore::Type_All), mContainer(container), mWeapon(iterator){} + void MWWorld::ContainerStoreIterator::incType() { if (mType==0) diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index 26c9f55a3..96c97415d 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -77,7 +77,7 @@ namespace MWWorld /// @return if stacking happened, return iterator to the item that was stacked against, otherwise end() iterator protected: - void addImpl (const Ptr& ptr); + ContainerStoreIterator addImpl (const Ptr& ptr); ///< Add the item to this container (no stacking) virtual bool stacks (const Ptr& ptr1, const Ptr& ptr2); @@ -143,6 +143,20 @@ namespace MWWorld ContainerStoreIterator (int mask, ContainerStore *container); ///< Begin-iterator + // construct iterator using a CellRefList iterator + ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator); + ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator); + ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator); + ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator); + ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator); + ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator); + ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator); + ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator); + ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator); + ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator); + ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator); + ContainerStoreIterator (ContainerStore *container, ESMS::CellRefList::List::iterator); + void incType(); void nextType(); From f8c20ef77f934939a9489fbd7c89f632cf36a9c6 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 00:20:24 +0200 Subject: [PATCH 063/118] don't allow putting items into a container if the weight is exceeded. --- apps/openmw/mwgui/container.cpp | 41 ++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 5ae943ea4..b7e0bf8b5 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -107,26 +107,45 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here { MWWorld::Ptr object = *mDragAndDrop->mDraggedWidget->getUserData(); + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); if (mDragAndDrop->mDraggedFrom != this) { assert(object.getContainerStore() && "Item is not in a container!"); - MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); - int origCount = object.getRefData().getCount(); - object.getRefData().setCount (mDragAndDrop->mDraggedCount); - containerStore.add(object); - object.getRefData().setCount (origCount - mDragAndDrop->mDraggedCount); - } - else - { + // check that we don't exceed the allowed weight (only for containers, not for inventory) - if (isInventory()) + if (!isInventory()) { - float curWeight = MWWorld::Class::get(mContainer).getEncumbrance(mContainer); float capacity = MWWorld::Class::get(mContainer).getCapacity(mContainer); - + // try adding the item, and if weight is exceeded, just remove it again. + int origCount = object.getRefData().getCount(); + object.getRefData().setCount(mDragAndDrop->mDraggedCount); + MWWorld::ContainerStoreIterator it = containerStore.add(object); + + float curWeight = MWWorld::Class::get(mContainer).getEncumbrance(mContainer); + if (curWeight > capacity) + { + it->getRefData().setCount(0); + object.getRefData().setCount(origCount); + // user notification + MWBase::Environment::get().getWindowManager()-> + messageBox(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sContentsMessage3")->str, std::vector()); + return; + } + else + { + object.getRefData().setCount(origCount - mDragAndDrop->mDraggedCount); + } + std::cout << "container weight " << curWeight << "/" << capacity << std::endl; + } + else + { + int origCount = object.getRefData().getCount(); + object.getRefData().setCount (mDragAndDrop->mDraggedCount); + containerStore.add(object); + object.getRefData().setCount (origCount - mDragAndDrop->mDraggedCount); } } From c5d685c780c119f676c7bcff9dc53aa057f7a1db Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 14:28:57 +0200 Subject: [PATCH 064/118] added an assert --- apps/openmw/mwgui/container.cpp | 6 ++++-- apps/openmw/mwgui/inventorywindow.cpp | 1 + apps/openmw/mwgui/window_manager.cpp | 2 ++ libs/openengine/gui/layout.hpp | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index b7e0bf8b5..844d5d89a 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -239,7 +239,9 @@ void ContainerBase::drawItems() for (std::vector::iterator it=unwantedItems.begin(); it != unwantedItems.end(); ++it) { - equippedItems.erase(std::find(unwantedItems.begin(), unwantedItems.end(), *it)); + std::vector::iterator found = std::find(unwantedItems.begin(), unwantedItems.end(), *it); + assert(found != unwantedItems.end()); + equippedItems.erase(found); } // and add the items that are left (= have the correct category) for (std::vector::const_iterator it=equippedItems.begin(); @@ -266,7 +268,7 @@ void ContainerBase::drawItems() if (mDragAndDrop->mIsOnDragAndDrop && *iter == *mDragAndDrop->mDraggedWidget->getUserData()) { displayCount -= mDragAndDrop->mDraggedCount; -} + } if(displayCount > 0 && !(onlyMagic && MWWorld::Class::get(*iter).getEnchantment(*iter) == "" && iter->getTypeName() != typeid(ESM::Potion).name())) { std::string path = std::string("icons\\"); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index b3da52b02..7160fa4f8 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -209,6 +209,7 @@ namespace MWGui if (invStore.getSlot(*slot) == invStore.end()) { + // slot is not occupied invStore.equip(*slot, it); break; } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index a4788ad3b..5c005835c 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -151,6 +151,8 @@ WindowManager::~WindowManager() delete mToolTips; delete mCharGen; delete mDragAndDrop; + delete mBookWindow; + delete mScrollWindow; cleanupGarbage(); } diff --git a/libs/openengine/gui/layout.hpp b/libs/openengine/gui/layout.hpp index abcc01753..d9eefe051 100644 --- a/libs/openengine/gui/layout.hpp +++ b/libs/openengine/gui/layout.hpp @@ -71,7 +71,7 @@ namespace GUI void shutdown() { - MyGUI::LayoutManager::getInstance().unloadLayout(mListWindowRoot); + MyGUI::Gui::getInstance().destroyWidget(mMainWidget); mListWindowRoot.clear(); } From 6a0cb32b7ee781857cec0fcc4676ce3607bfb339 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 14:30:02 +0200 Subject: [PATCH 065/118] removed unnecessary code --- apps/openmw/mwgui/container.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 844d5d89a..bdb06dd26 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -424,19 +424,16 @@ void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender) int i=0; for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter) { - if(iter->getRefData().getCount() > 0) + playerStore.add(*iter); + + if (i==0) { - playerStore.add(*iter); - - if (i==0) - { - // play the sound of the first object - std::string sound = MWWorld::Class::get(*iter).getUpSoundId(*iter); - MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); - } - - ++i; + // play the sound of the first object + std::string sound = MWWorld::Class::get(*iter).getUpSoundId(*iter); + MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); } + + ++i; } containerStore.clear(); From 398a7dc65c0e8875f08d458661639d777abb9488 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 14:32:48 +0200 Subject: [PATCH 066/118] crash fix (hopefully) --- apps/openmw/mwgui/container.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index bdb06dd26..20bef98b9 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -239,8 +239,8 @@ void ContainerBase::drawItems() for (std::vector::iterator it=unwantedItems.begin(); it != unwantedItems.end(); ++it) { - std::vector::iterator found = std::find(unwantedItems.begin(), unwantedItems.end(), *it); - assert(found != unwantedItems.end()); + std::vector::iterator found = std::find(equippedItems.begin(), equippedItems.end(), *it); + assert(found != equippedItems.end()); equippedItems.erase(found); } // and add the items that are left (= have the correct category) From 9a01e18b29f08eda5a2bb603c30b995df645975c Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 15:00:20 +0200 Subject: [PATCH 067/118] fix some MessageBox code that was using deleted pointers sometimes --- apps/openmw/mwgui/messagebox.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index c103bcb8b..a6b9025ce 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -15,6 +15,13 @@ void MessageBoxManager::onFrame (float frameDuration) std::vector::iterator it; for(it = mTimers.begin(); it != mTimers.end();) { + // if this messagebox is already deleted, remove the timer and move on + if (std::find(mMessageBoxes.begin(), mMessageBoxes.end(), it->messageBox) == mMessageBoxes.end()) + { + it = mTimers.erase(it); + continue; + } + it->current += frameDuration; if(it->current >= it->max) { From 9c4243782ee51dca419a617dc3d2677953fcbb17 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 15:17:55 +0200 Subject: [PATCH 068/118] sorting items --- apps/openmw/mwgui/container.cpp | 52 +++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 20bef98b9..8bb3976da 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -26,6 +26,47 @@ using namespace MWGui; using namespace Widgets; +namespace +{ + bool compareType(std::string type1, std::string type2) + { + // this defines the sorting order of types. types that are first in the vector, appear before other types. + std::vector mapping; + mapping.push_back( typeid(ESM::Weapon).name() ); + mapping.push_back( typeid(ESM::Armor).name() ); + mapping.push_back( typeid(ESM::Clothing).name() ); + mapping.push_back( typeid(ESM::Potion).name() ); + mapping.push_back( typeid(ESM::Ingredient).name() ); + mapping.push_back( typeid(ESM::Apparatus).name() ); + mapping.push_back( typeid(ESM::Book).name() ); + mapping.push_back( typeid(ESM::Light).name() ); + mapping.push_back( typeid(ESM::Miscellaneous).name() ); + mapping.push_back( typeid(ESM::Tool).name() ); + mapping.push_back( typeid(ESM::Repair).name() ); + mapping.push_back( typeid(ESM::Probe).name() ); + + assert( std::find(mapping.begin(), mapping.end(), type1) != mapping.end() ); + assert( std::find(mapping.begin(), mapping.end(), type2) != mapping.end() ); + + return std::find(mapping.begin(), mapping.end(), type1) < std::find(mapping.begin(), mapping.end(), type2); + } + + bool sortItems(MWWorld::Ptr left, MWWorld::Ptr right) + { + if (left.getTypeName() == right.getTypeName()) + { + int cmp = MWWorld::Class::get(left).getName(left).compare( + MWWorld::Class::get(right).getName(right)); + return cmp < 0; + } + else + { + return compareType(left.getTypeName(), right.getTypeName()); + } + } +} + + ContainerBase::ContainerBase(DragAndDrop* dragAndDrop) : mDragAndDrop(dragAndDrop), mFilter(ContainerBase::Filter_All) @@ -251,11 +292,18 @@ void ContainerBase::drawItems() } // now add the regular items + std::vector regularItems; for (MWWorld::ContainerStoreIterator iter (containerStore.begin(categories)); iter!=containerStore.end(); ++iter) { - /// \todo sorting if (std::find(equippedItems.begin(), equippedItems.end(), *iter) == equippedItems.end()) - items.push_back( std::make_pair(*iter, ItemState_Normal) ); + regularItems.push_back(*iter); + } + + // sort them and add + std::sort(regularItems.begin(), regularItems.end(), sortItems); + for (std::vector::const_iterator it=regularItems.begin(); it!=regularItems.end(); ++it) + { + items.push_back( std::make_pair(*it, ItemState_Normal) ); } for (std::vector< std::pair >::const_iterator it=items.begin(); From 0f1e09d2c1959eeb42204d6b888c3108bb369f3f Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 16:08:55 +0200 Subject: [PATCH 069/118] make Class::use method return an equip action for equippable items, add sound for equipping --- apps/openmw/CMakeLists.txt | 1 + apps/openmw/mwclass/armor.cpp | 8 +++ apps/openmw/mwclass/armor.hpp | 5 ++ apps/openmw/mwclass/clothing.cpp | 8 +++ apps/openmw/mwclass/clothing.hpp | 4 ++ apps/openmw/mwclass/weapon.cpp | 8 +++ apps/openmw/mwclass/weapon.hpp | 5 ++ apps/openmw/mwgui/inventorywindow.cpp | 79 +++++++-------------------- apps/openmw/mwworld/actionequip.cpp | 54 ++++++++++++++++++ apps/openmw/mwworld/actionequip.hpp | 21 +++++++ 10 files changed, 133 insertions(+), 60 deletions(-) create mode 100644 apps/openmw/mwworld/actionequip.cpp create mode 100644 apps/openmw/mwworld/actionequip.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 972c7f2e4..c105f28b1 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -48,6 +48,7 @@ add_openmw_dir (mwworld refdata world physicssystem scene globals class action nullaction actionteleport containerstore actiontalk actiontake manualref player cellfunctors cells localscripts customdata weather inventorystore ptr actionopen actionread + actionequip ) add_openmw_dir (mwclass diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index abd351fb4..83c0120c7 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -9,6 +9,7 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" +#include "../mwworld/actionequip.hpp" #include "../mwworld/inventorystore.hpp" #include "../mwworld/world.hpp" @@ -264,4 +265,11 @@ namespace MWClass return ref->base->enchant; } + + boost::shared_ptr Armor::use (const MWWorld::Ptr& ptr) const + { + MWBase::Environment::get().getSoundManager()->playSound (getUpSoundId(ptr), 1.0, 1.0); + + return boost::shared_ptr(new MWWorld::ActionEquip(ptr)); + } } diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index 9842c5020..a63806162 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -61,6 +61,11 @@ namespace MWClass virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string + + virtual boost::shared_ptr use (const MWWorld::Ptr& ptr) + const; + ///< Generate action for using via inventory menu + }; } diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index 181af35cd..11b515faf 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -9,6 +9,7 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" +#include "../mwworld/actionequip.hpp" #include "../mwworld/inventorystore.hpp" #include "../mwworld/world.hpp" @@ -217,4 +218,11 @@ namespace MWClass return ref->base->enchant; } + + boost::shared_ptr Clothing::use (const MWWorld::Ptr& ptr) const + { + MWBase::Environment::get().getSoundManager()->playSound (getUpSoundId(ptr), 1.0, 1.0); + + return boost::shared_ptr(new MWWorld::ActionEquip(ptr)); + } } diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index 64b857e26..aba317be0 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -55,6 +55,10 @@ namespace MWClass virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string + + virtual boost::shared_ptr use (const MWWorld::Ptr& ptr) + const; + ///< Generate action for using via inventory menu }; } diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index ab5a57a3d..482d618b0 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -9,6 +9,7 @@ #include "../mwworld/ptr.hpp" #include "../mwworld/actiontake.hpp" +#include "../mwworld/actionequip.hpp" #include "../mwworld/inventorystore.hpp" #include "../mwworld/world.hpp" @@ -355,4 +356,11 @@ namespace MWClass return ref->base->enchant; } + + boost::shared_ptr Weapon::use (const MWWorld::Ptr& ptr) const + { + MWBase::Environment::get().getSoundManager()->playSound (getUpSoundId(ptr), 1.0, 1.0); + + return boost::shared_ptr(new MWWorld::ActionEquip(ptr)); + } } diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index 9f9a3c4c8..92d703b4a 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -61,6 +61,11 @@ namespace MWClass virtual std::string getEnchantment (const MWWorld::Ptr& ptr) const; ///< @return the enchantment ID if the object is enchanted, otherwise an empty string + + virtual boost::shared_ptr use (const MWWorld::Ptr& ptr) + const; + ///< Generate action for using via inventory menu + }; } diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 7160fa4f8..9773867ec 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -147,73 +147,32 @@ namespace MWGui { MWWorld::Ptr ptr = *mDragAndDrop->mDraggedWidget->getUserData(); - // can the object be equipped? - std::pair, bool> slots = MWWorld::Class::get(ptr).getEquipmentSlots(ptr); - if (slots.first.empty()) - { - // can't be equipped, try to use instead - boost::shared_ptr action = MWWorld::Class::get(ptr).use(ptr); - - action->execute(); - - /// \todo scripts - - // this is necessary for books/scrolls: if they are already in the player's inventory, - // the "Take" button should not be visible. - // NOTE: the take button is "reset" when the window opens, so we can safely do the following - // without screwing up future book windows - if (mDragAndDrop->mWasInInventory) - { - mWindowManager.getBookWindow()->setTakeButtonShow(false); - mWindowManager.getScrollWindow()->setTakeButtonShow(false); - } - } - else + if (mDragAndDrop->mDraggedFrom != this) { + // add item to the player's inventory MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); - MWWorld::ContainerStoreIterator it = invStore.begin(); - if (mDragAndDrop->mDraggedFrom != this) - { - // add item to the player's inventory - int origCount = ptr.getRefData().getCount(); - ptr.getRefData().setCount(origCount - mDragAndDrop->mDraggedCount); - it = invStore.add(ptr); - (*it).getRefData().setCount(mDragAndDrop->mDraggedCount); - } - else - { - // retrieve iterator to the item - for (; it != invStore.end(); ++it) - { - if (*it == ptr) - { - break; - } - } - } + int origCount = ptr.getRefData().getCount(); + ptr.getRefData().setCount(origCount - mDragAndDrop->mDraggedCount); + it = invStore.add(ptr); + (*it).getRefData().setCount(mDragAndDrop->mDraggedCount); + } - assert(it != invStore.end()); + /// \todo scripts - // equip the item in the first free slot - for (std::vector::const_iterator slot=slots.first.begin(); - slot!=slots.first.end(); ++slot) - { - // if all slots are occupied, replace the last slot - if (slot == --slots.first.end()) - { - invStore.equip(*slot, it); - break; - } + boost::shared_ptr action = MWWorld::Class::get(ptr).use(ptr); + + action->execute(); - if (invStore.getSlot(*slot) == invStore.end()) - { - // slot is not occupied - invStore.equip(*slot, it); - break; - } - } + // this is necessary for books/scrolls: if they are already in the player's inventory, + // the "Take" button should not be visible. + // NOTE: the take button is "reset" when the window opens, so we can safely do the following + // without screwing up future book windows + if (mDragAndDrop->mWasInInventory) + { + mWindowManager.getBookWindow()->setTakeButtonShow(false); + mWindowManager.getScrollWindow()->setTakeButtonShow(false); } mDragAndDrop->mIsOnDragAndDrop = false; diff --git a/apps/openmw/mwworld/actionequip.cpp b/apps/openmw/mwworld/actionequip.cpp new file mode 100644 index 000000000..f3bb256fd --- /dev/null +++ b/apps/openmw/mwworld/actionequip.cpp @@ -0,0 +1,54 @@ +#include "actionequip.hpp" + +#include "../mwbase/environment.hpp" +#include "../mwworld/world.hpp" +#include "../mwworld/inventorystore.hpp" +#include "../mwworld/player.hpp" + +namespace MWWorld +{ + ActionEquip::ActionEquip (const MWWorld::Ptr& object) : mObject (object) + { + } + + void ActionEquip::execute () + { + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(player).getContainerStore(player)); + + // slots that this item can be equipped in + std::pair, bool> slots = MWWorld::Class::get(mObject).getEquipmentSlots(mObject); + + // retrieve ContainerStoreIterator to the item + MWWorld::ContainerStoreIterator it = invStore.begin(); + for (; it != invStore.end(); ++it) + { + if (*it == mObject) + { + break; + } + } + + assert(it != invStore.end()); + + // equip the item in the first free slot + for (std::vector::const_iterator slot=slots.first.begin(); + slot!=slots.first.end(); ++slot) + { + // if all slots are occupied, replace the last slot + if (slot == --slots.first.end()) + { + invStore.equip(*slot, it); + break; + } + + if (invStore.getSlot(*slot) == invStore.end()) + { + // slot is not occupied + invStore.equip(*slot, it); + break; + } + } + } +} + diff --git a/apps/openmw/mwworld/actionequip.hpp b/apps/openmw/mwworld/actionequip.hpp new file mode 100644 index 000000000..6cf3640f8 --- /dev/null +++ b/apps/openmw/mwworld/actionequip.hpp @@ -0,0 +1,21 @@ +#ifndef GAME_MWWORLD_ACTIONEQUIP_H +#define GAME_MWWORLD_ACTIONEQUIP_H + +#include "action.hpp" +#include "ptr.hpp" + +namespace MWWorld +{ + class ActionEquip : public Action + { + Ptr mObject; + + public: + /// @param item to equip + ActionEquip (const Ptr& object); + + virtual void execute (); + }; +} + +#endif From 4b5d6ce311f7c31461951ebb7675344931eb30f7 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 17:22:25 +0200 Subject: [PATCH 070/118] allow stacking gold --- apps/openmw/mwclass/misc.cpp | 18 +++++++++++----- apps/openmw/mwworld/containerstore.cpp | 29 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 936dc4558..d8e0553b9 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -1,6 +1,8 @@ #include "misc.hpp" +#include + #include #include @@ -142,12 +144,18 @@ namespace MWClass const ESMS::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); int count = ptr.getRefData().getCount(); - // gold has count both as reference count and as value, multiply them together to get real count - bool isGold = (ref->base->name == store.gameSettings.search("sGold")->str); - if (isGold) - count *= ref->base->data.value; - info.caption = ref->base->name + MWGui::ToolTips::getCountString(count); + bool isGold = (ref->base->name == store.gameSettings.search("sGold")->str); + if (isGold && count == 1) + count = ref->base->data.value; + + std::string countString; + if (!isGold) + countString = MWGui::ToolTips::getCountString(count); + else // gold displays its count also if it's 1. + countString = " (" + boost::lexical_cast(count) + ")"; + + info.caption = ref->base->name + countString; info.icon = ref->base->icon; if (ref->ref.soul != "") diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index eca720603..9b5afea74 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -7,6 +7,9 @@ #include +#include "../mwbase/environment.hpp" +#include "../mwworld/world.hpp" + #include "manualref.hpp" #include "refdata.hpp" #include "class.hpp" @@ -62,6 +65,32 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr) { int type = getType(ptr); + // gold needs special treatment because it uses several different meshes + if (MWWorld::Class::get(ptr).getName(ptr) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + { + ESMS::LiveCellRef *gold = + ptr.get(); + + int goldValue = (ptr.getRefData().getCount() == 1) ? gold->base->data.value : ptr.getRefData().getCount(); + + for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) + { + if (MWWorld::Class::get(*iter).getName(*iter) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + { + ESMS::LiveCellRef *ref = + iter->get(); + + if (iter->getRefData().getCount() == 1) + iter->getRefData().setCount(ref->base->data.value + goldValue); + else + iter->getRefData().setCount(iter->getRefData().getCount() + goldValue); + + flagAsModified(); + return iter; + } + } + } + // determine whether to stack or not for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) { From 6d34e61dbd2d34a25d7194ea5507048747d7ea38 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 19:18:50 +0200 Subject: [PATCH 071/118] don't stack gold if it has a script (not used in MW, but some mods might) --- apps/openmw/mwworld/containerstore.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 9b5afea74..5dfc9a177 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -75,7 +75,8 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr) for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) { - if (MWWorld::Class::get(*iter).getName(*iter) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + if (MWWorld::Class::get(*iter).getName(*iter) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str + && MWWorld::Class::get(*iter).getScript(*iter) == "" && MWWorld::Class::get(ptr).getScript(ptr) == "") { ESMS::LiveCellRef *ref = iter->get(); @@ -89,6 +90,10 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr) return iter; } } + + // if we get here, no already existing gold was found in the container + // we still need special handling because gold in a container should always have the real gold value as reference count. + ptr.getRefData().setCount(goldValue); } // determine whether to stack or not From f73d3ad33fa79fd99ce49ce549a98e313de48f4b Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 21:27:02 +0200 Subject: [PATCH 072/118] fix to the "drop object on ground" feature. still crashes for gold. --- apps/openmw/mwworld/scene.cpp | 91 ++++++++++++++++++++++++++++------- apps/openmw/mwworld/world.cpp | 24 ++++++++- 2 files changed, 96 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 1d4f078d5..311f8770b 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -328,41 +328,96 @@ namespace MWWorld void Scene::insertObject(MWWorld::Ptr ptr, Ptr::CellStore* cell) { - ptr.mCell = cell; - - mRendering.addObject(ptr); - MWWorld::Class::get(ptr).insertObject(ptr, *mPhysics); - MWWorld::Class::get(ptr).enable(ptr); - std::string type = ptr.getTypeName(); + MWWorld::Ptr newPtr; + // insert into the correct CellRefList if (type == typeid(ESM::Potion).name()) - cell->potions.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->potions.list.push_back( *ref ); + } else if (type == typeid(ESM::Apparatus).name()) - cell->appas.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->appas.list.push_back( *ref ); + } else if (type == typeid(ESM::Armor).name()) - cell->armors.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->armors.list.push_back( *ref ); + } else if (type == typeid(ESM::Book).name()) - cell->books.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->books.list.push_back( *ref ); + } else if (type == typeid(ESM::Clothing).name()) - cell->clothes.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->clothes.list.push_back( *ref ); + } else if (type == typeid(ESM::Ingredient).name()) - cell->ingreds.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->ingreds.list.push_back( *ref ); + } else if (type == typeid(ESM::Light).name()) - cell->lights.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->lights.list.push_back( *ref ); + } else if (type == typeid(ESM::Tool).name()) - cell->lockpicks.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->lockpicks.list.push_back( *ref ); + } else if (type == typeid(ESM::Repair).name()) - cell->repairs.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->repairs.list.push_back( *ref ); + } else if (type == typeid(ESM::Probe).name()) - cell->probes.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->probes.list.push_back( *ref ); + } else if (type == typeid(ESM::Weapon).name()) - cell->weapons.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + newPtr = MWWorld::Ptr(ref, cell); + cell->weapons.list.push_back( *ref ); + } else if (type == typeid(ESM::Miscellaneous).name()) - cell->miscItems.list.push_back( *ptr.get() ); + { + ESMS::LiveCellRef* ref = ptr.get(); + cell->miscItems.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->miscItems.list.back(), cell); + } else throw std::runtime_error("Trying to insert object of unhandled type"); + + + + newPtr.getRefData().setCount(ptr.getRefData().getCount()); + ptr.getRefData().setCount(0); + newPtr.getRefData().enable(); + + mRendering.addObject(newPtr); + MWWorld::Class::get(newPtr).insertObject(newPtr, *mPhysics); + MWWorld::Class::get(newPtr).enable(newPtr); + } } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 973407b0c..0672d5f3b 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -21,7 +21,7 @@ #include "class.hpp" #include "player.hpp" #include "weather.hpp" - +#include "manualref.hpp" #include "refdata.hpp" #include "globals.hpp" #include "cellfunctors.hpp" @@ -982,6 +982,28 @@ namespace MWWorld else cell = getPlayer().getPlayer().getCell(); + // if this is gold, we need to fetch the correct mesh depending on the amount of gold. + if (MWWorld::Class::get(object).getName(object) == getStore().gameSettings.search("sGold")->str) + { + int goldAmount = object.getRefData().getCount(); + + std::string base = "Gold_001"; + if (goldAmount >= 5) + base = "Gold_005"; + else if (goldAmount >= 10) + base = "Gold_010"; + else if (goldAmount >= 25) + base = "Gold_025"; + else if (goldAmount >= 100) + base = "Gold_100"; + + std::cout << "using " << base << std::endl; + MWWorld::ManualRef newRef (getStore(), base); + object = newRef.getPtr(); + object.getRefData().setCount(goldAmount); + object.mCell = cell; + } + ESM::Position& pos = object.getRefData().getPosition(); pos.pos[0] = result.second[0]; pos.pos[1] = -result.second[2]; From 5875ce51286fca173550d8ddea8c880ecac7710f Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 22:13:56 +0200 Subject: [PATCH 073/118] select the correct gold base object (still crashing) --- apps/openmw/mwworld/world.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 0672d5f3b..2f8deeff9 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -988,20 +988,19 @@ namespace MWWorld int goldAmount = object.getRefData().getCount(); std::string base = "Gold_001"; - if (goldAmount >= 5) - base = "Gold_005"; - else if (goldAmount >= 10) - base = "Gold_010"; + if (goldAmount >= 100) + base = "Gold_100"; else if (goldAmount >= 25) base = "Gold_025"; - else if (goldAmount >= 100) - base = "Gold_100"; + else if (goldAmount >= 10) + base = "Gold_010"; + else if (goldAmount >= 5) + base = "Gold_005"; std::cout << "using " << base << std::endl; MWWorld::ManualRef newRef (getStore(), base); object = newRef.getPtr(); object.getRefData().setCount(goldAmount); - object.mCell = cell; } ESM::Position& pos = object.getRefData().getPosition(); From 178ad876d74acc405026e604c780f391f56bcbcc Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 22:17:13 +0200 Subject: [PATCH 074/118] fix for objects other than Miscellaneous. --- apps/openmw/mwworld/scene.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 311f8770b..8fa7658c6 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -336,68 +336,68 @@ namespace MWWorld if (type == typeid(ESM::Potion).name()) { ESMS::LiveCellRef* ref = ptr.get(); - newPtr = MWWorld::Ptr(ref, cell); cell->potions.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->potions.list.back(), cell); } else if (type == typeid(ESM::Apparatus).name()) { ESMS::LiveCellRef* ref = ptr.get(); - newPtr = MWWorld::Ptr(ref, cell); cell->appas.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->appas.list.back(), cell); } else if (type == typeid(ESM::Armor).name()) { ESMS::LiveCellRef* ref = ptr.get(); - newPtr = MWWorld::Ptr(ref, cell); cell->armors.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->armors.list.back(), cell); } else if (type == typeid(ESM::Book).name()) { ESMS::LiveCellRef* ref = ptr.get(); - newPtr = MWWorld::Ptr(ref, cell); cell->books.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->books.list.back(), cell); } else if (type == typeid(ESM::Clothing).name()) { ESMS::LiveCellRef* ref = ptr.get(); - newPtr = MWWorld::Ptr(ref, cell); cell->clothes.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->clothes.list.back(), cell); } else if (type == typeid(ESM::Ingredient).name()) { ESMS::LiveCellRef* ref = ptr.get(); - newPtr = MWWorld::Ptr(ref, cell); cell->ingreds.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->ingreds.list.back(), cell); } else if (type == typeid(ESM::Light).name()) { ESMS::LiveCellRef* ref = ptr.get(); - newPtr = MWWorld::Ptr(ref, cell); cell->lights.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->lights.list.back(), cell); } else if (type == typeid(ESM::Tool).name()) { ESMS::LiveCellRef* ref = ptr.get(); - newPtr = MWWorld::Ptr(ref, cell); cell->lockpicks.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->lockpicks.list.back(), cell); } else if (type == typeid(ESM::Repair).name()) { ESMS::LiveCellRef* ref = ptr.get(); - newPtr = MWWorld::Ptr(ref, cell); cell->repairs.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->repairs.list.back(), cell); } else if (type == typeid(ESM::Probe).name()) { ESMS::LiveCellRef* ref = ptr.get(); - newPtr = MWWorld::Ptr(ref, cell); cell->probes.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->probes.list.back(), cell); } else if (type == typeid(ESM::Weapon).name()) { ESMS::LiveCellRef* ref = ptr.get(); - newPtr = MWWorld::Ptr(ref, cell); cell->weapons.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->weapons.list.back(), cell); } else if (type == typeid(ESM::Miscellaneous).name()) { From fca9f1fc5f29de49e4767656b61e819d0f9da941 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 16 May 2012 22:56:54 +0200 Subject: [PATCH 075/118] gold dropping works without crash, but the code needs clean up. --- apps/openmw/mwworld/scene.cpp | 43 ++++++++++++++++++++++++++++++++--- apps/openmw/mwworld/world.cpp | 21 ----------------- 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 8fa7658c6..af7e21d7f 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -9,6 +9,9 @@ #include "../mwgui/window_manager.hpp" +#include "../mwworld/world.hpp" /// FIXME +#include "../mwworld/manualref.hpp" /// FIXME + #include "ptr.hpp" #include "player.hpp" #include "class.hpp" @@ -326,6 +329,8 @@ namespace MWWorld insertCellRefList(mRendering, cell.weapons, cell, *mPhysics); } + + /// \todo this whole code needs major clean up, and doesn't belong in this class. void Scene::insertObject(MWWorld::Ptr ptr, Ptr::CellStore* cell) { std::string type = ptr.getTypeName(); @@ -401,9 +406,41 @@ namespace MWWorld } else if (type == typeid(ESM::Miscellaneous).name()) { - ESMS::LiveCellRef* ref = ptr.get(); - cell->miscItems.list.push_back( *ref ); - newPtr = MWWorld::Ptr(&cell->miscItems.list.back(), cell); + + // if this is gold, we need to fetch the correct mesh depending on the amount of gold. + if (MWWorld::Class::get(ptr).getName(ptr) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + { + int goldAmount = ptr.getRefData().getCount(); + + std::string base = "Gold_001"; + if (goldAmount >= 100) + base = "Gold_100"; + else if (goldAmount >= 25) + base = "Gold_025"; + else if (goldAmount >= 10) + base = "Gold_010"; + else if (goldAmount >= 5) + base = "Gold_005"; + + MWWorld::ManualRef newRef (MWBase::Environment::get().getWorld()->getStore(), base); + + ESMS::LiveCellRef* ref = newRef.getPtr().get(); + + cell->miscItems.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->miscItems.list.back(), cell); + + ESM::Position& p = newPtr.getRefData().getPosition(); + p.pos[0] = ptr.getRefData().getPosition().pos[0]; + p.pos[1] = ptr.getRefData().getPosition().pos[1]; + p.pos[2] = ptr.getRefData().getPosition().pos[2]; + } + else + { + ESMS::LiveCellRef* ref = ptr.get(); + + cell->miscItems.list.push_back( *ref ); + newPtr = MWWorld::Ptr(&cell->miscItems.list.back(), cell); + } } else throw std::runtime_error("Trying to insert object of unhandled type"); diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 2f8deeff9..b324ee1a0 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -982,27 +982,6 @@ namespace MWWorld else cell = getPlayer().getPlayer().getCell(); - // if this is gold, we need to fetch the correct mesh depending on the amount of gold. - if (MWWorld::Class::get(object).getName(object) == getStore().gameSettings.search("sGold")->str) - { - int goldAmount = object.getRefData().getCount(); - - std::string base = "Gold_001"; - if (goldAmount >= 100) - base = "Gold_100"; - else if (goldAmount >= 25) - base = "Gold_025"; - else if (goldAmount >= 10) - base = "Gold_010"; - else if (goldAmount >= 5) - base = "Gold_005"; - - std::cout << "using " << base << std::endl; - MWWorld::ManualRef newRef (getStore(), base); - object = newRef.getPtr(); - object.getRefData().setCount(goldAmount); - } - ESM::Position& pos = object.getRefData().getPosition(); pos.pos[0] = result.second[0]; pos.pos[1] = -result.second[2]; From c5185cf2e4f750845594986e0ee87edf74148e22 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 May 2012 12:09:53 +0200 Subject: [PATCH 076/118] drop item on avatar from external container bugfix --- apps/openmw/mwgui/container.cpp | 2 -- apps/openmw/mwgui/container.hpp | 6 ------ apps/openmw/mwgui/inventorywindow.cpp | 3 ++- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 8bb3976da..3656a8919 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -136,8 +136,6 @@ void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) static_cast(mSelectedItem->getChildAt(0)->getChildAt(0))->setCaption( getCountString(mDragAndDrop->mDraggedCount)); - mDragAndDrop->mWasInInventory = isInventory(); - drawItems(); MWBase::Environment::get().getWindowManager()->setDragDrop(true); diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 174f18f9a..fe4ffc285 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -36,17 +36,11 @@ namespace MWGui class DragAndDrop { public: - DragAndDrop() : - mWasInInventory(false) - { - } - bool mIsOnDragAndDrop; MyGUI::Widget* mDraggedWidget; MyGUI::Widget* mDragAndDropWidget; ContainerBase* mDraggedFrom; int mDraggedCount; - bool mWasInInventory; // was the item in inventory before it was dragged }; class ContainerBase diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 9773867ec..4f16152ea 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -157,6 +157,7 @@ namespace MWGui ptr.getRefData().setCount(origCount - mDragAndDrop->mDraggedCount); it = invStore.add(ptr); (*it).getRefData().setCount(mDragAndDrop->mDraggedCount); + ptr = *it; } /// \todo scripts @@ -169,7 +170,7 @@ namespace MWGui // the "Take" button should not be visible. // NOTE: the take button is "reset" when the window opens, so we can safely do the following // without screwing up future book windows - if (mDragAndDrop->mWasInInventory) + if (mDragAndDrop->mDraggedFrom == this) { mWindowManager.getBookWindow()->setTakeButtonShow(false); mWindowManager.getScrollWindow()->setTakeButtonShow(false); From 8cc49ae2b9a0976a8b88ace36c9710010bbb873b Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 May 2012 12:55:48 +0200 Subject: [PATCH 077/118] xml files update (layout tweak, added double quotation marks to font) --- files/mygui/openmw.font.xml | 1 + files/mygui/openmw_container_window_layout.xml | 6 +++--- files/mygui/openmw_inventory_window_layout.xml | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/files/mygui/openmw.font.xml b/files/mygui/openmw.font.xml index 252499a5f..73d491e04 100644 --- a/files/mygui/openmw.font.xml +++ b/files/mygui/openmw.font.xml @@ -13,6 +13,7 @@ + diff --git a/files/mygui/openmw_container_window_layout.xml b/files/mygui/openmw_container_window_layout.xml index 7b14f5b58..cb66fadc1 100644 --- a/files/mygui/openmw_container_window_layout.xml +++ b/files/mygui/openmw_container_window_layout.xml @@ -5,9 +5,9 @@ - - - + + + diff --git a/files/mygui/openmw_inventory_window_layout.xml b/files/mygui/openmw_inventory_window_layout.xml index cd6e1469e..4d63b03c2 100644 --- a/files/mygui/openmw_inventory_window_layout.xml +++ b/files/mygui/openmw_inventory_window_layout.xml @@ -27,8 +27,9 @@ - - + + + From 630241c8e2c95c6c0ab01ea681e3cb6c796653ca Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 May 2012 13:12:38 +0200 Subject: [PATCH 078/118] load the AIDT (AI data) for creatures in the ESM loader, which also contains the Services enum. --- apps/openmw/mwgui/dialogue.cpp | 2 ++ apps/openmw/mwgui/list.cpp | 7 ------- apps/openmw/mwgui/list.hpp | 2 +- components/esm/loadcrea.cpp | 12 +++++++++--- components/esm/loadcrea.hpp | 12 ++++++++++++ 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 45163017a..1116eb272 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -145,6 +145,7 @@ void DialogueWindow::setKeywords(std::list keyWords) { topicsList->addItem(*it); } + topicsList->adjustSize(); } void DialogueWindow::removeKeyword(std::string keyWord) @@ -154,6 +155,7 @@ void DialogueWindow::removeKeyword(std::string keyWord) topicsList->removeItem(keyWord); pTopicsText.erase(keyWord); } + topicsList->adjustSize(); } void addColorInString(std::string& str, const std::string& keyword,std::string color1, std::string color2) diff --git a/apps/openmw/mwgui/list.cpp b/apps/openmw/mwgui/list.cpp index d66cc6f89..33f5a6fd1 100644 --- a/apps/openmw/mwgui/list.cpp +++ b/apps/openmw/mwgui/list.cpp @@ -28,8 +28,6 @@ void MWList::initialiseOverride() void MWList::addItem(const std::string& name) { mItems.push_back(name); - - redraw(); } void MWList::adjustSize() @@ -67,7 +65,6 @@ void MWList::redraw(bool scrollbarShown) mItemHeight += height + spacing; } mScrollView->setCanvasSize(mClient->getSize().width + (_scrollBarWidth-scrollBarWidth), std::max(mItemHeight, mClient->getSize().height)); - mScrollView->setViewOffset(MyGUI::IntPoint(0,0)); if (!scrollbarShown && mItemHeight > mClient->getSize().height) redraw(true); @@ -93,15 +90,11 @@ void MWList::removeItem(const std::string& name) { assert( std::find(mItems.begin(), mItems.end(), name) != mItems.end() ); mItems.erase( std::find(mItems.begin(), mItems.end(), name) ); - - redraw(); } void MWList::clear() { mItems.clear(); - - redraw(); } void MWList::onMouseWheel(MyGUI::Widget* _sender, int _rel) diff --git a/apps/openmw/mwgui/list.hpp b/apps/openmw/mwgui/list.hpp index a2e9afcd1..76ca5257f 100644 --- a/apps/openmw/mwgui/list.hpp +++ b/apps/openmw/mwgui/list.hpp @@ -26,7 +26,7 @@ namespace MWGui EventHandle_String eventItemSelected; /** - * Call after the size of the list changed + * Call after the size of the list changed, or items were inserted/removed */ void adjustSize(); diff --git a/components/esm/loadcrea.cpp b/components/esm/loadcrea.cpp index 651d9a318..8af3526a0 100644 --- a/components/esm/loadcrea.cpp +++ b/components/esm/loadcrea.cpp @@ -19,9 +19,15 @@ void Creature::load(ESMReader &esm, const std::string& id) inventory.load(esm); - // More subrecords: + if (esm.isNextSub("AIDT")) + { + esm.getHExact(&AI, sizeof(AI)); + hasAI = true; + } + else + hasAI = false; - // AIDT - data (12 bytes, unknown) + // More subrecords: // AI_W - wander (14 bytes, i don't understand it) // short distance // byte duration @@ -33,8 +39,8 @@ void Creature::load(ESMReader &esm, const std::string& id) // AI_F - follow? // AI_E - escort? // AI_A - activate? - esm.skipRecord(); + } } diff --git a/components/esm/loadcrea.hpp b/components/esm/loadcrea.hpp index 3c334ebbd..c3c5b181e 100644 --- a/components/esm/loadcrea.hpp +++ b/components/esm/loadcrea.hpp @@ -51,6 +51,15 @@ struct Creature int gold; }; // 96 bytes + struct AIDTstruct + { + // These are probabilities + char hello, u1, fight, flee, alarm, u2, u3, u4; + // The last u's might be the skills that this NPC can train you + // in? + int services; // See the NPC::Services enum + }; // 12 bytes + NPDTstruct data; int flags; @@ -61,6 +70,9 @@ struct Creature // Defined in loadcont.hpp InventoryList inventory; + bool hasAI; + AIDTstruct AI; + std::string mId; void load(ESMReader &esm, const std::string& id); From 0c1d06d9f767b3860886478d61beb18f4da8fb63 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 May 2012 13:36:25 +0200 Subject: [PATCH 079/118] added some trade window stuff, which does nothing yet. --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwgui/inventorywindow.hpp | 18 +--------- apps/openmw/mwgui/tradewindow.cpp | 10 ++++++ apps/openmw/mwgui/tradewindow.hpp | 41 ++++++++++++++++++++++ apps/openmw/mwgui/window_manager.hpp | 2 ++ files/mygui/openmw_trade_window_layout.xml | 24 +++++++++++++ 6 files changed, 79 insertions(+), 18 deletions(-) create mode 100644 apps/openmw/mwgui/tradewindow.cpp create mode 100644 apps/openmw/mwgui/tradewindow.hpp create mode 100644 files/mygui/openmw_trade_window_layout.xml diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index c105f28b1..9e5aeb684 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -26,7 +26,7 @@ add_openmw_dir (mwgui 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 tooltips scrollwindow bookwindow list - formatting itemwidget inventorywindow container hud countdialog + formatting itemwidget inventorywindow container hud countdialog tradewindow ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index ae0d80986..07aeeeafd 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -4,23 +4,6 @@ #include "container.hpp" #include "window_pinnable_base.hpp" -namespace MWWorld -{ - class Environment; -} - -namespace MyGUI -{ - class Gui; - class Widget; -} - -namespace MWGui -{ - class WindowManager; -} - - namespace MWGui { class InventoryWindow : public ContainerBase, public WindowPinnableBase @@ -60,4 +43,5 @@ namespace MWGui virtual void _unequipItem(MWWorld::Ptr item); }; } + #endif // Inventory_H diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp new file mode 100644 index 000000000..45a82eecb --- /dev/null +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -0,0 +1,10 @@ +#include "tradewindow.hpp" + +namespace MWGui +{ + TradeWindow::TradeWindow(WindowManager& parWindowManager) : + WindowBase("openmw_trade_window_layout.xml", parWindowManager), + ContainerBase(NULL) // no drag&drop + { + } +} diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp new file mode 100644 index 000000000..f04f83c0d --- /dev/null +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -0,0 +1,41 @@ +#ifndef MWGUI_TRADEWINDOW_H +#define MWGUI_TRADEWINDOW_H + +#include "container.hpp" +#include "window_base.hpp" + +namespace MyGUI +{ + class Gui; + class Widget; +} + +namespace MWGui +{ + class WindowManager; +} + + +namespace MWGui +{ + class TradeWindow : public ContainerBase, public WindowBase + { + public: + TradeWindow(WindowManager& parWindowManager); + + //virtual void Update(); + //virtual void notifyContentChanged(); + + protected: + MyGUI::Button* mFilterAll; + MyGUI::Button* mFilterWeapon; + MyGUI::Button* mFilterApparel; + MyGUI::Button* mFilterMagic; + MyGUI::Button* mFilterMisc; + + void onWindowResize(MyGUI::Window* _sender); + void onFilterChanged(MyGUI::Widget* _sender); + }; +} + +#endif diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 3f5df5789..8c9eec16d 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -72,6 +72,7 @@ namespace MWGui class DialogueWindow; class MessageBoxManager; class CountDialog; + class TradeWindow; struct ClassPoint { @@ -226,6 +227,7 @@ namespace MWGui ScrollWindow* mScrollWindow; BookWindow* mBookWindow; CountDialog* mCountDialog; + TradeWindow* mTradeWindow; CharacterCreation* mCharGen; diff --git a/files/mygui/openmw_trade_window_layout.xml b/files/mygui/openmw_trade_window_layout.xml new file mode 100644 index 000000000..e5c45cdd0 --- /dev/null +++ b/files/mygui/openmw_trade_window_layout.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + From 66abfd17abd7719a7f5eae985e869802b0652604 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 May 2012 14:13:35 +0200 Subject: [PATCH 080/118] check the container's "Organic" flag before trying to place items inside. --- apps/openmw/mwgui/container.cpp | 18 +++++++++++++++--- apps/openmw/mwgui/hud.cpp | 5 +++++ apps/openmw/mwgui/hud.hpp | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 3656a8919..978e10fc4 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -143,7 +143,7 @@ void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) { - if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here + if(mDragAndDrop->mIsOnDragAndDrop) //drop item here { MWWorld::Ptr object = *mDragAndDrop->mDraggedWidget->getUserData(); MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); @@ -152,6 +152,20 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) { assert(object.getContainerStore() && "Item is not in a container!"); + // check the container's Organic flag (if this is a container). container with Organic flag doesn't allow putting items inside + if (mContainer.getTypeName() == typeid(ESM::Container).name()) + { + ESMS::LiveCellRef* ref = mContainer.get(); + if (ref->base->flags & ESM::Container::Organic) + { + // user notification + MWBase::Environment::get().getWindowManager()-> + messageBox(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sContentsMessage2")->str, std::vector()); + return; + } + } + + int origCount = object.getRefData().getCount(); // check that we don't exceed the allowed weight (only for containers, not for inventory) if (!isInventory()) @@ -159,7 +173,6 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) float capacity = MWWorld::Class::get(mContainer).getCapacity(mContainer); // try adding the item, and if weight is exceeded, just remove it again. - int origCount = object.getRefData().getCount(); object.getRefData().setCount(mDragAndDrop->mDraggedCount); MWWorld::ContainerStoreIterator it = containerStore.add(object); @@ -181,7 +194,6 @@ void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) } else { - int origCount = object.getRefData().getCount(); object.getRefData().setCount (mDragAndDrop->mDraggedCount); containerStore.add(object); object.getRefData().setCount (origCount - mDragAndDrop->mDraggedCount); diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index c15801da4..395ca79c5 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -92,6 +92,7 @@ HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop) mMainWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &HUD::onWorldClicked); mMainWidget->eventMouseMove += MyGUI::newDelegate(this, &HUD::onWorldMouseOver); + mMainWidget->eventMouseLostFocus += MyGUI::newDelegate(this, &HUD::onWorldMouseLostFocus); } void HUD::setFpsLevel(int level) @@ -321,3 +322,7 @@ void HUD::onWorldMouseOver(MyGUI::Widget* _sender, int x, int y) } } +void HUD::onWorldMouseLostFocus(MyGUI::Widget* _sender, MyGUI::Widget* _new) +{ + MyGUI::PointerManager::getInstance().setPointer("arrow"); +} diff --git a/apps/openmw/mwgui/hud.hpp b/apps/openmw/mwgui/hud.hpp index cccfb0541..d588113dd 100644 --- a/apps/openmw/mwgui/hud.hpp +++ b/apps/openmw/mwgui/hud.hpp @@ -53,5 +53,6 @@ namespace MWGui void onWorldClicked(MyGUI::Widget* _sender); void onWorldMouseOver(MyGUI::Widget* _sender, int x, int y); + void onWorldMouseLostFocus(MyGUI::Widget* _sender, MyGUI::Widget* _new); }; } From 0dc5e5919b11906d69fde2ec9a7a253f15c8900d Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 May 2012 14:54:03 +0200 Subject: [PATCH 081/118] show the Barter entry in the dialogue gui for npcs/creatures that buy/sell stuff. doesn't work for the Creeper for some reason, but Mudcrab Merchant works. --- apps/openmw/mwdialogue/dialoguemanager.cpp | 30 +++++++++++++++++ apps/openmw/mwgui/dialogue.cpp | 13 +++++++- apps/openmw/mwgui/dialogue.hpp | 7 ++++ apps/openmw/mwgui/list.cpp | 39 ++++++++++++++++------ apps/openmw/mwgui/list.hpp | 3 +- 5 files changed, 79 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 7baf589c4..496cc4f7f 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -767,6 +767,36 @@ namespace MWDialogue } } + // check the available services of this actor + int services = 0; + if (mActor.getTypeName() == typeid(ESM::NPC).name()) + { + ESMS::LiveCellRef* ref = mActor.get(); + if (ref->base->hasAI) + services = ref->base->AI.services; + } + else if (mActor.getTypeName() == typeid(ESM::Creature).name()) + { + ESMS::LiveCellRef* ref = mActor.get(); + if (ref->base->hasAI) + services = ref->base->AI.services; + } + + if (services & ESM::NPC::Weapon + || services & ESM::NPC::Armor + || services & ESM::NPC::Clothing + || services & ESM::NPC::Books + || services & ESM::NPC::Ingredients + || services & ESM::NPC::Picks + || services & ESM::NPC::Probes + || services & ESM::NPC::Lights + || services & ESM::NPC::Apparatus + || services & ESM::NPC::RepairItem + || services & ESM::NPC::Misc) + win->setShowTrade(true); + else + win->setShowTrade(false); + // sort again, because the previous sort was case-sensitive keywordList.sort(stringCompareNoCase); win->setKeywords(keywordList); diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 1116eb272..3f6ec0376 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -40,6 +40,7 @@ std::string::size_type find_str_ci(const std::string& str, const std::string& su DialogueWindow::DialogueWindow(WindowManager& parWindowManager) : WindowBase("openmw_dialogue_window_layout.xml", parWindowManager) , mEnabled(true) + , mShowTrade(false) { // Centre dialog center(); @@ -141,6 +142,15 @@ void DialogueWindow::startDialogue(std::string npcName) void DialogueWindow::setKeywords(std::list keyWords) { topicsList->clear(); + + bool anyService = mShowTrade; + + if (mShowTrade) + topicsList->addItem(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarter")->str); + + if (anyService) + topicsList->addSeparator(); + for(std::list::iterator it = keyWords.begin(); it != keyWords.end(); it++) { topicsList->addItem(*it); @@ -194,7 +204,8 @@ std::string DialogueWindow::parseText(std::string text) for(unsigned int i = 0;igetItemCount();i++) { std::string keyWord = topicsList->getItemNameAt(i); - addColorInString(text,keyWord,"#686EBA","#B29154"); + if (keyWord != "") + addColorInString(text,keyWord,"#686EBA","#B29154"); } return text; } diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp index a29e73799..225ef37a4 100644 --- a/apps/openmw/mwgui/dialogue.hpp +++ b/apps/openmw/mwgui/dialogue.hpp @@ -47,6 +47,10 @@ namespace MWGui void askQuestion(std::string question); void goodbye(); + // various service button visibilities, depending if the npc/creature talked to has these services + // make sure to call these before setKeywords() + void setShowTrade(bool show) { mShowTrade = show; } + protected: void onSelectTopic(std::string topic); void onByeClicked(MyGUI::Widget* _sender); @@ -61,6 +65,9 @@ namespace MWGui */ std::string parseText(std::string text); + // various service button visibilities, depending if the npc/creature talked to has these services + bool mShowTrade; + bool mEnabled; DialogueHistory* history; diff --git a/apps/openmw/mwgui/list.cpp b/apps/openmw/mwgui/list.cpp index 33f5a6fd1..661fb2e68 100644 --- a/apps/openmw/mwgui/list.cpp +++ b/apps/openmw/mwgui/list.cpp @@ -30,6 +30,11 @@ void MWList::addItem(const std::string& name) mItems.push_back(name); } +void MWList::addSeparator() +{ + mItems.push_back(""); +} + void MWList::adjustSize() { redraw(); @@ -50,19 +55,31 @@ void MWList::redraw(bool scrollbarShown) for (std::vector::const_iterator it=mItems.begin(); it!=mItems.end(); ++it) { - MyGUI::Button* button = mScrollView->createWidget( - "MW_ListLine", MyGUI::IntCoord(0, mItemHeight, mScrollView->getSize().width - scrollBarWidth - 2, 24), - MyGUI::Align::Left | MyGUI::Align::Top, getName() + "_item_" + (*it)); - button->setCaption((*it)); - button->getSubWidgetText()->setWordWrap(true); - button->getSubWidgetText()->setTextAlign(MyGUI::Align::Left); - button->eventMouseWheel += MyGUI::newDelegate(this, &MWList::onMouseWheel); - button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWList::onItemSelected); + if (*it != "") + { + MyGUI::Button* button = mScrollView->createWidget( + "MW_ListLine", MyGUI::IntCoord(0, mItemHeight, mScrollView->getSize().width - scrollBarWidth - 2, 24), + MyGUI::Align::Left | MyGUI::Align::Top, getName() + "_item_" + (*it)); + button->setCaption((*it)); + button->getSubWidgetText()->setWordWrap(true); + button->getSubWidgetText()->setTextAlign(MyGUI::Align::Left); + button->eventMouseWheel += MyGUI::newDelegate(this, &MWList::onMouseWheel); + button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWList::onItemSelected); - int height = button->getTextSize().height; - button->setSize(MyGUI::IntSize(button->getSize().width, height)); + int height = button->getTextSize().height; + button->setSize(MyGUI::IntSize(button->getSize().width, height)); - mItemHeight += height + spacing; + mItemHeight += height + spacing; + } + else + { + MyGUI::ImageBox* separator = mScrollView->createWidget("MW_HLine", + MyGUI::IntCoord(2, mItemHeight, mScrollView->getWidth()-4, 18), + MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); + separator->setNeedMouseFocus(false); + + mItemHeight += 18 + spacing; + } } mScrollView->setCanvasSize(mClient->getSize().width + (_scrollBarWidth-scrollBarWidth), std::max(mItemHeight, mClient->getSize().height)); diff --git a/apps/openmw/mwgui/list.hpp b/apps/openmw/mwgui/list.hpp index 76ca5257f..2b765c2e1 100644 --- a/apps/openmw/mwgui/list.hpp +++ b/apps/openmw/mwgui/list.hpp @@ -31,10 +31,11 @@ namespace MWGui void adjustSize(); void addItem(const std::string& name); + void addSeparator(); ///< add a seperator between the current and the next item. void removeItem(const std::string& name); bool hasItem(const std::string& name); unsigned int getItemCount(); - std::string getItemNameAt(unsigned int at); + std::string getItemNameAt(unsigned int at); ///< \attention if there are separators, this method will return "" at the place where the separator is void clear(); protected: From 5da4da820e41df0d9fde8ef585188460db58140a Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 May 2012 17:15:44 +0200 Subject: [PATCH 082/118] beginnings of trade window layout. --- apps/openmw/mwdialogue/dialoguemanager.cpp | 2 +- apps/openmw/mwgui/dialogue.cpp | 35 +++++++++++++++------- apps/openmw/mwgui/dialogue.hpp | 6 +++- apps/openmw/mwgui/tradewindow.cpp | 5 ++++ apps/openmw/mwgui/tradewindow.hpp | 4 +++ apps/openmw/mwgui/window_manager.cpp | 4 +++ apps/openmw/mwgui/window_manager.hpp | 1 + files/mygui/CMakeLists.txt | 1 + 8 files changed, 45 insertions(+), 13 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 496cc4f7f..2c4de7be1 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -637,7 +637,7 @@ namespace MWDialogue //initialise the GUI MWBase::Environment::get().getInputManager()->setGuiMode(MWGui::GM_Dialogue); MWGui::DialogueWindow* win = MWBase::Environment::get().getWindowManager()->getDialogueWindow(); - win->startDialogue(MWWorld::Class::get (actor).getName (actor)); + win->startDialogue(actor, MWWorld::Class::get (actor).getName (actor)); //setup the list of topics known by the actor. Topics who are also on the knownTopics list will be added to the GUI updateTopics(); diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 3f6ec0376..953657565 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -1,11 +1,4 @@ #include "dialogue.hpp" -#include "dialogue_history.hpp" -#include "window_manager.hpp" -#include "widgets.hpp" -#include "list.hpp" -#include "components/esm_store/store.hpp" -#include "../mwbase/environment.hpp" -#include "../mwdialogue/dialoguemanager.hpp" #include #include @@ -14,6 +7,17 @@ #include #include +#include + +#include "../mwbase/environment.hpp" +#include "../mwdialogue/dialoguemanager.hpp" + +#include "dialogue_history.hpp" +#include "window_manager.hpp" +#include "widgets.hpp" +#include "list.hpp" +#include "tradewindow.hpp" + using namespace MWGui; using namespace Widgets; @@ -59,9 +63,7 @@ DialogueWindow::DialogueWindow(WindowManager& parWindowManager) //Topics list getWidget(topicsList, "TopicsList"); - //topicsList->eventListSelectAccept += MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic); topicsList->eventItemSelected += MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic); - //topicsList->eventListChangePosition += MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic); MyGUI::ButtonPtr byeButton; getWidget(byeButton, "ByeButton"); @@ -117,6 +119,9 @@ void DialogueWindow::open() history->eraseText(0,history->getTextLength()); updateOptions(); setVisible(true); + + // hide all sub-dialogues of the dialog window (trade window, persuasion, etc) + mWindowManager.getTradeWindow()->setVisible(false); } void DialogueWindow::onByeClicked(MyGUI::Widget* _sender) @@ -128,12 +133,20 @@ void DialogueWindow::onSelectTopic(std::string topic) { if (!mEnabled) return; - MWBase::Environment::get().getDialogueManager()->keywordSelected(lower_string(topic)); + if (topic == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarter")->str) + { + /// \todo check if the player is allowed to trade with this actor (e.g. faction rank high enough)? + mWindowManager.getTradeWindow()->startTrade(mActor); + } + + else + MWBase::Environment::get().getDialogueManager()->keywordSelected(lower_string(topic)); } -void DialogueWindow::startDialogue(std::string npcName) +void DialogueWindow::startDialogue(MWWorld::Ptr actor, std::string npcName) { mEnabled = true; + mActor = actor; topicsList->setEnabled(true); static_cast(mMainWidget)->setCaption(npcName); adjustWindowCaption(); diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp index 225ef37a4..7f69f972c 100644 --- a/apps/openmw/mwgui/dialogue.hpp +++ b/apps/openmw/mwgui/dialogue.hpp @@ -4,6 +4,8 @@ #include "window_base.hpp" #include +#include "../mwworld/ptr.hpp" + namespace MWGui { class WindowManager; @@ -38,7 +40,7 @@ namespace MWGui */ EventHandle_Void eventBye; - void startDialogue(std::string npcName); + void startDialogue(MWWorld::Ptr actor, std::string npcName); void stopDialogue(); void setKeywords(std::list keyWord); void removeKeyword(std::string keyWord); @@ -70,6 +72,8 @@ namespace MWGui bool mEnabled; + MWWorld::Ptr mActor; // actor being talked to + DialogueHistory* history; Widgets::MWList* topicsList; MyGUI::ProgressPtr pDispositionBar; diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 45a82eecb..cd38aa731 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -7,4 +7,9 @@ namespace MWGui ContainerBase(NULL) // no drag&drop { } + + void TradeWindow::startTrade(MWWorld::Ptr actor) + { + ContainerBase::openContainer(actor); + } } diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index f04f83c0d..5fc5b98b6 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -4,6 +4,8 @@ #include "container.hpp" #include "window_base.hpp" +#include "../mwworld/ptr.hpp" + namespace MyGUI { class Gui; @@ -23,6 +25,8 @@ namespace MWGui public: TradeWindow(WindowManager& parWindowManager); + void startTrade(MWWorld::Ptr actor); + //virtual void Update(); //virtual void notifyContentChanged(); diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 5c005835c..245b364c9 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -15,6 +15,7 @@ #include "hud.hpp" #include "mainmenu.hpp" #include "countdialog.hpp" +#include "tradewindow.hpp" #include "../mwmechanics/mechanicsmanager.hpp" #include "../mwinput/inputmanager.hpp" @@ -48,6 +49,7 @@ WindowManager::WindowManager( , mBookWindow(NULL) , mScrollWindow(NULL) , mCountDialog(NULL) + , mTradeWindow(NULL) , mCharGen(NULL) , playerClass() , playerName() @@ -114,6 +116,7 @@ WindowManager::WindowManager( mScrollWindow = new ScrollWindow(*this); mBookWindow = new BookWindow(*this); mCountDialog = new CountDialog(*this); + mTradeWindow = new TradeWindow(*this); // The HUD is always on hud->setVisible(true); @@ -153,6 +156,7 @@ WindowManager::~WindowManager() delete mDragAndDrop; delete mBookWindow; delete mScrollWindow; + delete mTradeWindow; cleanupGarbage(); } diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 8c9eec16d..52869ff55 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -136,6 +136,7 @@ namespace MWGui MWGui::BookWindow* getBookWindow() {return mBookWindow;} MWGui::ScrollWindow* getScrollWindow() {return mScrollWindow;} MWGui::CountDialog* getCountDialog() {return mCountDialog;} + MWGui::TradeWindow* getTradeWindow() {return mTradeWindow;} MyGUI::Gui* getGui() const { return gui; } diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index 2ee823d2a..cacfb7c5a 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -56,6 +56,7 @@ configure_file("${SDIR}/openmw_scroll_layout.xml" "${DDIR}/openmw_scroll_layout. configure_file("${SDIR}/openmw_scroll_skin.xml" "${DDIR}/openmw_scroll_skin.xml" COPYONLY) configure_file("${SDIR}/openmw_book_layout.xml" "${DDIR}/openmw_book_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_count_window_layout.xml" "${DDIR}/openmw_count_window_layout.xml" COPYONLY) +configure_file("${SDIR}/openmw_trade_window_layout.xml" "${DDIR}/openmw_trade_window_layout.xml" COPYONLY) configure_file("${SDIR}/atlas1.cfg" "${DDIR}/atlas1.cfg" COPYONLY) configure_file("${SDIR}/smallbars.png" "${DDIR}/smallbars.png" COPYONLY) configure_file("${SDIR}/transparent.png" "${DDIR}/transparent.png" COPYONLY) From 4213b4370ff87a7986df41eabd7e9757325b8d88 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 May 2012 19:53:04 +0200 Subject: [PATCH 083/118] trade window shows up and shows the vendor's inventory items. --- apps/openmw/mwgui/container.cpp | 53 ++++++++-------- apps/openmw/mwgui/inventorywindow.cpp | 7 --- apps/openmw/mwgui/tradewindow.cpp | 72 ++++++++++++++++++++++ apps/openmw/mwgui/window_manager.cpp | 2 +- files/mygui/openmw_trade_window_layout.xml | 21 ++++--- 5 files changed, 115 insertions(+), 40 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 978e10fc4..eb02c5826 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -88,31 +88,34 @@ ContainerBase::~ContainerBase() void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) { - if(!mDragAndDrop->mIsOnDragAndDrop) + if (mDragAndDrop) { - mSelectedItem = _sender; - - MWWorld::Ptr object = (*_sender->getUserData()); - int count = object.getRefData().getCount(); - - if (MyGUI::InputManager::getInstance().isShiftPressed() || count == 1) + if(!mDragAndDrop->mIsOnDragAndDrop) { - onSelectedItemImpl(_sender, count); - } - else if (MyGUI::InputManager::getInstance().isControlPressed()) - { - onSelectedItemImpl(_sender, 1); + mSelectedItem = _sender; + + MWWorld::Ptr object = (*_sender->getUserData()); + int count = object.getRefData().getCount(); + + if (MyGUI::InputManager::getInstance().isShiftPressed() || count == 1) + { + onSelectedItemImpl(_sender, count); + } + else if (MyGUI::InputManager::getInstance().isControlPressed()) + { + onSelectedItemImpl(_sender, 1); + } + else + { + CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); + dialog->open(MWWorld::Class::get(object).getName(object), count); + dialog->eventOkClicked.clear(); + dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::onSelectedItemImpl); + } } else - { - CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); - dialog->open(MWWorld::Class::get(object).getName(object), count); - dialog->eventOkClicked.clear(); - dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::onSelectedItemImpl); - } + onContainerClicked(mContainerWidget); } - else - onContainerClicked(mContainerWidget); } void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) @@ -143,6 +146,8 @@ void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) void ContainerBase::onContainerClicked(MyGUI::Widget* _sender) { + if (mDragAndDrop == NULL) return; + if(mDragAndDrop->mIsOnDragAndDrop) //drop item here { MWWorld::Ptr object = *mDragAndDrop->mDraggedWidget->getUserData(); @@ -323,7 +328,7 @@ void ContainerBase::drawItems() const MWWorld::Ptr* iter = &((*it).first); int displayCount = iter->getRefData().getCount(); - if (mDragAndDrop->mIsOnDragAndDrop && *iter == *mDragAndDrop->mDraggedWidget->getUserData()) + if (mDragAndDrop != NULL && mDragAndDrop->mIsOnDragAndDrop && *iter == *mDragAndDrop->mDraggedWidget->getUserData()) { displayCount -= mDragAndDrop->mDraggedCount; } @@ -402,7 +407,7 @@ std::string ContainerBase::getCountString(const int count) void ContainerBase::Update() { - if(mDragAndDrop->mIsOnDragAndDrop) + if(mDragAndDrop != NULL && mDragAndDrop->mIsOnDragAndDrop) { if(mDragAndDrop->mDraggedWidget) mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); @@ -462,7 +467,7 @@ void ContainerWindow::open(MWWorld::Ptr container) void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender) { - if(!mDragAndDrop->mIsOnDragAndDrop) + if(mDragAndDrop == NULL || !mDragAndDrop->mIsOnDragAndDrop) { MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game); setVisible(false); @@ -471,7 +476,7 @@ void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender) void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender) { - if(!mDragAndDrop->mIsOnDragAndDrop) + if(mDragAndDrop == NULL || !mDragAndDrop->mIsOnDragAndDrop) { // transfer everything into the player's inventory MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 4f16152ea..92c0553f6 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -16,13 +16,6 @@ #include "../mwbase/environment.hpp" #include "../mwworld/manualref.hpp" -#include "../mwscript/scriptmanager.hpp" -#include "../mwscript/compilercontext.hpp" -#include "../mwscript/interpretercontext.hpp" -#include "../mwscript/extensions.hpp" -#include "../mwscript/globalscripts.hpp" - - #include "window_manager.hpp" #include "widgets.hpp" #include "bookwindow.hpp" diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index cd38aa731..09557b196 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -1,15 +1,87 @@ #include "tradewindow.hpp" +#include "../mwbase/environment.hpp" +#include "../mwworld/world.hpp" + namespace MWGui { TradeWindow::TradeWindow(WindowManager& parWindowManager) : WindowBase("openmw_trade_window_layout.xml", parWindowManager), ContainerBase(NULL) // no drag&drop { + getWidget(mFilterAll, "AllButton"); + getWidget(mFilterWeapon, "WeaponButton"); + getWidget(mFilterApparel, "ApparelButton"); + getWidget(mFilterMagic, "MagicButton"); + getWidget(mFilterMisc, "MiscButton"); + + MyGUI::ScrollView* itemView; + MyGUI::Widget* containerWidget; + getWidget(containerWidget, "Items"); + getWidget(itemView, "ItemView"); + setWidgets(containerWidget, itemView); + + mFilterAll->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sAllTab")->str); + mFilterWeapon->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sWeaponTab")->str); + mFilterApparel->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sApparelTab")->str); + mFilterMagic->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sMagicTab")->str); + mFilterMisc->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sMiscTab")->str); + + // adjust size of buttons to fit text + int curX = 0; + mFilterAll->setSize( mFilterAll->getTextSize().width + 24, mFilterAll->getSize().height ); + curX += mFilterAll->getTextSize().width + 24 + 4; + + mFilterWeapon->setPosition(curX, mFilterWeapon->getPosition().top); + mFilterWeapon->setSize( mFilterWeapon->getTextSize().width + 24, mFilterWeapon->getSize().height ); + curX += mFilterWeapon->getTextSize().width + 24 + 4; + + mFilterApparel->setPosition(curX, mFilterApparel->getPosition().top); + mFilterApparel->setSize( mFilterApparel->getTextSize().width + 24, mFilterApparel->getSize().height ); + curX += mFilterApparel->getTextSize().width + 24 + 4; + + mFilterMagic->setPosition(curX, mFilterMagic->getPosition().top); + mFilterMagic->setSize( mFilterMagic->getTextSize().width + 24, mFilterMagic->getSize().height ); + curX += mFilterMagic->getTextSize().width + 24 + 4; + + mFilterMisc->setPosition(curX, mFilterMisc->getPosition().top); + mFilterMisc->setSize( mFilterMisc->getTextSize().width + 24, mFilterMisc->getSize().height ); + + mFilterAll->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged); + mFilterWeapon->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged); + mFilterApparel->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged); + mFilterMagic->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged); + mFilterMisc->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged); + + mFilterAll->setStateSelected(true); } void TradeWindow::startTrade(MWWorld::Ptr actor) { ContainerBase::openContainer(actor); + + setVisible(true); + } + + void TradeWindow::onFilterChanged(MyGUI::Widget* _sender) + { + if (_sender == mFilterAll) + setFilter(ContainerBase::Filter_All); + else if (_sender == mFilterWeapon) + setFilter(ContainerBase::Filter_Weapon); + else if (_sender == mFilterApparel) + setFilter(ContainerBase::Filter_Apparel); + else if (_sender == mFilterMagic) + setFilter(ContainerBase::Filter_Magic); + else if (_sender == mFilterMisc) + setFilter(ContainerBase::Filter_Misc); + + mFilterAll->setStateSelected(false); + mFilterWeapon->setStateSelected(false); + mFilterApparel->setStateSelected(false); + mFilterMagic->setStateSelected(false); + mFilterMisc->setStateSelected(false); + + static_cast(_sender)->setStateSelected(true); } } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index f6e48a28a..1593c6b19 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -108,6 +108,7 @@ WindowManager::WindowManager( console = new Console(w,h, extensions); mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); + mTradeWindow = new TradeWindow(*this); mDialogueWindow = new DialogueWindow(*this); mContainerWindow = new ContainerWindow(*this,mDragAndDrop); mInventoryWindow = new InventoryWindow(*this,mDragAndDrop); @@ -116,7 +117,6 @@ WindowManager::WindowManager( mScrollWindow = new ScrollWindow(*this); mBookWindow = new BookWindow(*this); mCountDialog = new CountDialog(*this); - mTradeWindow = new TradeWindow(*this); // The HUD is always on hud->setVisible(true); diff --git a/files/mygui/openmw_trade_window_layout.xml b/files/mygui/openmw_trade_window_layout.xml index e5c45cdd0..15d313c4d 100644 --- a/files/mygui/openmw_trade_window_layout.xml +++ b/files/mygui/openmw_trade_window_layout.xml @@ -2,16 +2,10 @@ - - - - - - - + - + @@ -19,6 +13,17 @@ + + + + + + + + + + + From 6ae642aa069efabd7eb3d643e9906eb5ffa4d8ec Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 May 2012 21:15:48 +0200 Subject: [PATCH 084/118] complete trade window layout --- apps/openmw/mwgui/container.cpp | 2 - apps/openmw/mwgui/dialogue.cpp | 2 + apps/openmw/mwgui/tradewindow.cpp | 77 +++++++++++++++++++--- apps/openmw/mwgui/tradewindow.hpp | 15 +++++ apps/openmw/mwgui/window_manager.cpp | 6 ++ apps/openmw/mwgui/window_manager.hpp | 3 +- files/mygui/openmw_trade_window_layout.xml | 36 ++++++++-- 7 files changed, 122 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index eb02c5826..078a5e370 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -470,7 +470,6 @@ void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender) if(mDragAndDrop == NULL || !mDragAndDrop->mIsOnDragAndDrop) { MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game); - setVisible(false); } } @@ -502,6 +501,5 @@ void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender) containerStore.clear(); MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game); - setVisible(false); } } diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 953657565..e8db4b6d1 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -17,6 +17,7 @@ #include "widgets.hpp" #include "list.hpp" #include "tradewindow.hpp" +#include "inventorywindow.hpp" using namespace MWGui; using namespace Widgets; @@ -137,6 +138,7 @@ void DialogueWindow::onSelectTopic(std::string topic) { /// \todo check if the player is allowed to trade with this actor (e.g. faction rank high enough)? mWindowManager.getTradeWindow()->startTrade(mActor); + mWindowManager.setGuiMode(GM_Barter); } else diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 09557b196..31e0722aa 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -3,24 +3,49 @@ #include "../mwbase/environment.hpp" #include "../mwworld/world.hpp" +#include "window_manager.hpp" + namespace MWGui { TradeWindow::TradeWindow(WindowManager& parWindowManager) : WindowBase("openmw_trade_window_layout.xml", parWindowManager), ContainerBase(NULL) // no drag&drop { - getWidget(mFilterAll, "AllButton"); - getWidget(mFilterWeapon, "WeaponButton"); - getWidget(mFilterApparel, "ApparelButton"); - getWidget(mFilterMagic, "MagicButton"); - getWidget(mFilterMisc, "MiscButton"); - MyGUI::ScrollView* itemView; MyGUI::Widget* containerWidget; getWidget(containerWidget, "Items"); getWidget(itemView, "ItemView"); setWidgets(containerWidget, itemView); + getWidget(mFilterAll, "AllButton"); + getWidget(mFilterWeapon, "WeaponButton"); + getWidget(mFilterApparel, "ApparelButton"); + getWidget(mFilterMagic, "MagicButton"); + getWidget(mFilterMisc, "MiscButton"); + + getWidget(mMaxSaleButton, "MaxSaleButton"); + getWidget(mCancelButton, "CancelButton"); + getWidget(mOfferButton, "OfferButton"); + getWidget(mPlayerGold, "PlayerGold"); + getWidget(mMerchantGold, "MerchantGold"); + getWidget(mIncreaseButton, "IncreaseButton"); + getWidget(mDecreaseButton, "DecreaseButton"); + getWidget(mTotalBalance, "TotalBalance"); + getWidget(mTotalBalanceLabel, "TotalBalanceLabel"); + getWidget(mBottomPane, "BottomPane"); + + // this GMST doesn't seem to get retrieved - even though i can clearly see it in the CS !??!? + mMaxSaleButton->setCaption(mWindowManager.getGameSettingString("sMaxSale", "Max. Sale")); + + mCancelButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sCancel")->str); + mOfferButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sOffer")->str); +/* + mTotalBalanceLabel->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTotalCost")->str); + mTotalBalanceLabel->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTotalSold")->str); + mPlayerGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sYourGold")->str); + mMerchantGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sSellerGold")->str); + +*/ mFilterAll->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sAllTab")->str); mFilterWeapon->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sWeaponTab")->str); mFilterApparel->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sApparelTab")->str); @@ -47,20 +72,42 @@ namespace MWGui mFilterMisc->setPosition(curX, mFilterMisc->getPosition().top); mFilterMisc->setSize( mFilterMisc->getTextSize().width + 24, mFilterMisc->getSize().height ); + mFilterAll->setStateSelected(true); + mFilterAll->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged); mFilterWeapon->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged); mFilterApparel->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged); mFilterMagic->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged); mFilterMisc->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged); - mFilterAll->setStateSelected(true); + mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onCancelButtonClicked); + mOfferButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onOfferButtonClicked); + + mMaxSaleButton->setSize(MyGUI::IntSize(mMaxSaleButton->getTextSize().width + 24, mMaxSaleButton->getHeight())); + + int cancelButtonWidth = mCancelButton->getTextSize().width + 24; + mCancelButton->setCoord(mBottomPane->getWidth()-cancelButtonWidth, + mCancelButton->getTop(), + cancelButtonWidth, + mCancelButton->getHeight()); + + int offerButtonWidth = mOfferButton->getTextSize().width + 24; + mOfferButton->setCoord(mBottomPane->getWidth()-cancelButtonWidth-offerButtonWidth-8, + mOfferButton->getTop(), + offerButtonWidth, + mOfferButton->getHeight()); + + setCoord(400, 0, 400, 300); + + static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &TradeWindow::onWindowResize); } void TradeWindow::startTrade(MWWorld::Ptr actor) { ContainerBase::openContainer(actor); - setVisible(true); + setTitle(MWWorld::Class::get(actor).getName(actor)); + adjustWindowCaption(); } void TradeWindow::onFilterChanged(MyGUI::Widget* _sender) @@ -84,4 +131,18 @@ namespace MWGui static_cast(_sender)->setStateSelected(true); } + + void TradeWindow::onWindowResize(MyGUI::Window* _sender) + { + drawItems(); + } + + void TradeWindow::onOfferButtonClicked(MyGUI::Widget* _sender) + { + } + + void TradeWindow::onCancelButtonClicked(MyGUI::Widget* _sender) + { + mWindowManager.setGuiMode(GM_Game); + } } diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index 5fc5b98b6..1f937d06e 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -37,8 +37,23 @@ namespace MWGui MyGUI::Button* mFilterMagic; MyGUI::Button* mFilterMisc; + MyGUI::Button* mIncreaseButton; + MyGUI::Button* mDecreaseButton; + MyGUI::TextBox* mTotalBalanceLabel; + MyGUI::TextBox* mTotalBalance; + + MyGUI::Widget* mBottomPane; + + MyGUI::Button* mMaxSaleButton; + MyGUI::Button* mCancelButton; + MyGUI::Button* mOfferButton; + MyGUI::TextBox* mPlayerGold; + MyGUI::TextBox* mMerchantGold; + void onWindowResize(MyGUI::Window* _sender); void onFilterChanged(MyGUI::Widget* _sender); + void onOfferButtonClicked(MyGUI::Widget* _sender); + void onCancelButtonClicked(MyGUI::Widget* _sender); }; } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 1593c6b19..e970de2e6 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -215,6 +215,7 @@ void WindowManager::updateVisible() mInventoryWindow->setVisible(false); mScrollWindow->setVisible(false); mBookWindow->setVisible(false); + mTradeWindow->setVisible(false); // Mouse is visible whenever we're not in game mode MyGUI::PointerManager::getInstance().setVisible(isGuiMode()); @@ -273,6 +274,11 @@ void WindowManager::updateVisible() case GM_Dialogue: mDialogueWindow->open(); break; + case GM_Barter: + mInventoryWindow->setVisible(true); + mInventoryWindow->openInventory(); + mTradeWindow->setVisible(true); + break; case GM_InterMessageBox: if(!mMessageBoxManager->isInteractiveMessageBox()) { setGuiMode(GM_Game); diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 52869ff55..82c494191 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -130,9 +130,8 @@ namespace MWGui } MWGui::DialogueWindow* getDialogueWindow() {return mDialogueWindow;} - MWGui::ContainerWindow* getContainerWindow() {return mContainerWindow;} - + MWGui::InventoryWindow* getInventoryWindow() {return mInventoryWindow;} MWGui::BookWindow* getBookWindow() {return mBookWindow;} MWGui::ScrollWindow* getScrollWindow() {return mScrollWindow;} MWGui::CountDialog* getCountDialog() {return mCountDialog;} diff --git a/files/mygui/openmw_trade_window_layout.xml b/files/mygui/openmw_trade_window_layout.xml index 15d313c4d..076924322 100644 --- a/files/mygui/openmw_trade_window_layout.xml +++ b/files/mygui/openmw_trade_window_layout.xml @@ -1,11 +1,11 @@ - + - + @@ -14,14 +14,36 @@ - - - + + + + - - + + + + + + + + + + + + + + + + + + + + + + + From 41efea4c1d637b61e3f6be6757d2ae5478f5fcf1 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 May 2012 21:56:16 +0200 Subject: [PATCH 085/118] in the trade window, don't show items that the merchant has equipped. --- apps/openmw/mwgui/container.cpp | 9 ++-- apps/openmw/mwgui/container.hpp | 3 ++ apps/openmw/mwgui/inventorywindow.cpp | 19 ++++++-- apps/openmw/mwgui/inventorywindow.hpp | 2 + apps/openmw/mwgui/tradewindow.cpp | 52 +++++++++++++++++++--- apps/openmw/mwgui/tradewindow.hpp | 8 ++++ apps/openmw/mwgui/window_manager.cpp | 2 +- files/mygui/openmw_trade_window_layout.xml | 4 +- 8 files changed, 85 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 078a5e370..6f8ca4730 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -300,10 +300,13 @@ void ContainerBase::drawItems() equippedItems.erase(found); } // and add the items that are left (= have the correct category) - for (std::vector::const_iterator it=equippedItems.begin(); - it != equippedItems.end(); ++it) + if (!ignoreEquippedItems()) { - items.push_back( std::make_pair(*it, ItemState_Equipped) ); + for (std::vector::const_iterator it=equippedItems.begin(); + it != equippedItems.end(); ++it) + { + items.push_back( std::make_pair(*it, ItemState_Equipped) ); + } } // now add the regular items diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index fe4ffc285..956382f23 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -98,6 +98,9 @@ namespace MWGui virtual bool isInventory() { return false; } virtual std::vector getEquippedItems() { return std::vector(); } virtual void _unequipItem(MWWorld::Ptr item) { ; } + + // to be reimplemented by TradeWindow + virtual bool ignoreEquippedItems() { return false; } }; class ContainerWindow : public ContainerBase, public WindowBase diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 92c0553f6..ebba395ff 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -84,13 +84,13 @@ namespace MWGui mFilterAll->setStateSelected(true); setCoord(0, 342, 600, 258); + + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + openContainer(player); } void InventoryWindow::openInventory() { - MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); - openContainer(player); - onWindowResize(static_cast(mMainWidget)); updateEncumbranceBar(); @@ -232,4 +232,17 @@ namespace MWGui ContainerBase::Update(); } + + int InventoryWindow::getPlayerGold() + { + MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + + for (MWWorld::ContainerStoreIterator it = invStore.begin(); + it != invStore.end(); ++it) + { + if (MWWorld::Class::get(*it).getName(*it) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + return it->getRefData().getCount(); + } + return 0; + } } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 07aeeeafd..e53402bbd 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -16,6 +16,8 @@ namespace MWGui virtual void Update(); virtual void notifyContentChanged(); + int getPlayerGold(); + protected: MyGUI::Widget* mAvatar; MyGUI::TextBox* mArmorRating; diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 31e0722aa..8348b6066 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -1,15 +1,20 @@ #include "tradewindow.hpp" +#include + #include "../mwbase/environment.hpp" #include "../mwworld/world.hpp" +#include "../mwworld/inventorystore.hpp" #include "window_manager.hpp" +#include "inventorywindow.hpp" namespace MWGui { TradeWindow::TradeWindow(WindowManager& parWindowManager) : - WindowBase("openmw_trade_window_layout.xml", parWindowManager), - ContainerBase(NULL) // no drag&drop + WindowBase("openmw_trade_window_layout.xml", parWindowManager) + , ContainerBase(NULL) // no drag&drop + , mCurrentBalance(0) { MyGUI::ScrollView* itemView; MyGUI::Widget* containerWidget; @@ -40,9 +45,6 @@ namespace MWGui mCancelButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sCancel")->str); mOfferButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sOffer")->str); /* - mTotalBalanceLabel->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTotalCost")->str); - mTotalBalanceLabel->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTotalSold")->str); - mPlayerGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sYourGold")->str); mMerchantGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sSellerGold")->str); */ @@ -108,6 +110,10 @@ namespace MWGui setTitle(MWWorld::Class::get(actor).getName(actor)); adjustWindowCaption(); + + mCurrentBalance = 0; + + updateLabels(); } void TradeWindow::onFilterChanged(MyGUI::Widget* _sender) @@ -145,4 +151,40 @@ namespace MWGui { mWindowManager.setGuiMode(GM_Game); } + + void TradeWindow::updateLabels() + { + mPlayerGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sYourGold")->str + + " " + boost::lexical_cast(mWindowManager.getInventoryWindow()->getPlayerGold())); + + if (mCurrentBalance > 0) + { + mTotalBalanceLabel->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTotalSold")->str); + mTotalBalance->setCaption(boost::lexical_cast(mCurrentBalance)); + } + else + { + mTotalBalanceLabel->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTotalCost")->str); + mTotalBalance->setCaption(boost::lexical_cast(-mCurrentBalance)); + } + } + + + std::vector TradeWindow::getEquippedItems() + { + MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + + std::vector items; + + for (int slot=0; slot < MWWorld::InventoryStore::Slots; ++slot) + { + MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); + if (it != invStore.end()) + { + items.push_back(*it); + } + } + + return items; + } } diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index 1f937d06e..dd28fcb8b 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -50,10 +50,18 @@ namespace MWGui MyGUI::TextBox* mPlayerGold; MyGUI::TextBox* mMerchantGold; + int mCurrentBalance; + void onWindowResize(MyGUI::Window* _sender); void onFilterChanged(MyGUI::Widget* _sender); void onOfferButtonClicked(MyGUI::Widget* _sender); void onCancelButtonClicked(MyGUI::Widget* _sender); + + // don't show items that the NPC has equipped in his trade-window. + virtual bool ignoreEquippedItems() { return true; } + virtual std::vector getEquippedItems(); + + void updateLabels(); }; } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index e970de2e6..e12fb851e 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -108,10 +108,10 @@ WindowManager::WindowManager( console = new Console(w,h, extensions); mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); + mInventoryWindow = new InventoryWindow(*this,mDragAndDrop); mTradeWindow = new TradeWindow(*this); mDialogueWindow = new DialogueWindow(*this); mContainerWindow = new ContainerWindow(*this,mDragAndDrop); - mInventoryWindow = new InventoryWindow(*this,mDragAndDrop); hud = new HUD(w,h, showFPSLevel, mDragAndDrop); mToolTips = new ToolTips(this); mScrollWindow = new ScrollWindow(*this); diff --git a/files/mygui/openmw_trade_window_layout.xml b/files/mygui/openmw_trade_window_layout.xml index 076924322..b6a93e697 100644 --- a/files/mygui/openmw_trade_window_layout.xml +++ b/files/mygui/openmw_trade_window_layout.xml @@ -22,10 +22,10 @@ - + - + From 9a3fd96a0cc8a86ae31add0539778a586800fba6 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 May 2012 22:24:47 +0200 Subject: [PATCH 086/118] display the merchant gold. --- apps/openmw/mwgui/tradewindow.cpp | 43 +++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 8348b6066..c6b677d8b 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -44,10 +44,7 @@ namespace MWGui mCancelButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sCancel")->str); mOfferButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sOffer")->str); -/* - mMerchantGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sSellerGold")->str); -*/ mFilterAll->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sAllTab")->str); mFilterWeapon->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sWeaponTab")->str); mFilterApparel->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sApparelTab")->str); @@ -167,15 +164,51 @@ namespace MWGui mTotalBalanceLabel->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTotalCost")->str); mTotalBalance->setCaption(boost::lexical_cast(-mCurrentBalance)); } - } + // retrieve merchant gold + int gold = 0; + MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + for (MWWorld::ContainerStoreIterator it = invStore.begin(); + it != invStore.end(); ++it) + { + if (MWWorld::Class::get(*it).getName(*it) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + gold = it->getRefData().getCount(); + } + + int merchantgold; + if (mContainer.getTypeName() == typeid(ESM::NPC).name()) + { + ESMS::LiveCellRef* ref = mContainer.get(); + if (ref->base->npdt52.gold == -10) + merchantgold = ref->base->npdt12.gold; + else + merchantgold = ref->base->npdt52.gold; + } + else // ESM::Creature + { + ESMS::LiveCellRef* ref = mContainer.get(); + merchantgold = ref->base->data.gold; + } + gold += merchantgold; + + mMerchantGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sSellerGold")->str + + " " + boost::lexical_cast(gold)); + } std::vector TradeWindow::getEquippedItems() { - MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + std::vector items; + if (mContainer.getTypeName() == typeid(ESM::Creature).name()) + { + // creatures don't have equipment slots. + return items; + } + + MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + for (int slot=0; slot < MWWorld::InventoryStore::Slots; ++slot) { MWWorld::ContainerStoreIterator it = invStore.getSlot(slot); From 3cacc8feec26ef71d117d53a098b73e571c6f685 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 17 May 2012 23:22:41 +0200 Subject: [PATCH 087/118] add re-stocking items to containers (though restocking isn't implemented) --- apps/openmw/mwworld/containerstore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 5dfc9a177..b32bcd5d9 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -150,7 +150,7 @@ void MWWorld::ContainerStore::fill (const ESM::InventoryList& items, const ESMS: continue; } - ref.getPtr().getRefData().setCount (iter->count); + ref.getPtr().getRefData().setCount (std::abs(iter->count)); /// \todo implement item restocking (indicated by negative count) add (ref.getPtr()); } From adf055029219ec9525820b9996cdafa4d376d73e Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 May 2012 00:14:31 +0200 Subject: [PATCH 088/118] fixed a wrong label. --- apps/openmw/mwgui/tradewindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index c6b677d8b..97c66b9dc 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -43,7 +43,7 @@ namespace MWGui mMaxSaleButton->setCaption(mWindowManager.getGameSettingString("sMaxSale", "Max. Sale")); mCancelButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sCancel")->str); - mOfferButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sOffer")->str); + mOfferButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarterDialog8")->str); mFilterAll->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sAllTab")->str); mFilterWeapon->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sWeaponTab")->str); From e2400ca7b2949f0238a24d5ebe7bd657b2f362f7 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 May 2012 15:51:33 +0200 Subject: [PATCH 089/118] only show items in the trade window that the NPC actually trades (services enum) --- apps/openmw/mwgui/container.cpp | 5 ++- apps/openmw/mwgui/container.hpp | 3 +- apps/openmw/mwgui/tradewindow.cpp | 59 +++++++++++++++++++++++++++++-- apps/openmw/mwgui/tradewindow.hpp | 4 +++ 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 6f8ca4730..9ff4b8d4a 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -309,11 +309,14 @@ void ContainerBase::drawItems() } } + std::vector ignoreItems = itemsToIgnore(); + // now add the regular items std::vector regularItems; for (MWWorld::ContainerStoreIterator iter (containerStore.begin(categories)); iter!=containerStore.end(); ++iter) { - if (std::find(equippedItems.begin(), equippedItems.end(), *iter) == equippedItems.end()) + if (std::find(equippedItems.begin(), equippedItems.end(), *iter) == equippedItems.end() + && std::find(ignoreItems.begin(), ignoreItems.end(), *iter) == ignoreItems.end()) regularItems.push_back(*iter); } diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 956382f23..563b22bc3 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -94,13 +94,12 @@ namespace MWGui std::string getCountString(const int count); - // to be reimplemented by InventoryWindow virtual bool isInventory() { return false; } virtual std::vector getEquippedItems() { return std::vector(); } virtual void _unequipItem(MWWorld::Ptr item) { ; } - // to be reimplemented by TradeWindow virtual bool ignoreEquippedItems() { return false; } + virtual std::vector itemsToIgnore() { return std::vector(); } }; class ContainerWindow : public ContainerBase, public WindowBase diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 97c66b9dc..e5fc47764 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -197,8 +197,6 @@ namespace MWGui std::vector TradeWindow::getEquippedItems() { - - std::vector items; if (mContainer.getTypeName() == typeid(ESM::Creature).name()) @@ -220,4 +218,61 @@ namespace MWGui return items; } + + bool TradeWindow::npcAcceptsItem(MWWorld::Ptr item) + { + int services = 0; + if (mContainer.getTypeName() == typeid(ESM::NPC).name()) + { + ESMS::LiveCellRef* ref = mContainer.get(); + if (ref->base->hasAI) + services = ref->base->AI.services; + } + else if (mContainer.getTypeName() == typeid(ESM::Creature).name()) + { + ESMS::LiveCellRef* ref = mContainer.get(); + if (ref->base->hasAI) + services = ref->base->AI.services; + } + + if (item.getTypeName() == typeid(ESM::Weapon).name()) + return services & ESM::NPC::Weapon; + else if (item.getTypeName() == typeid(ESM::Armor).name()) + return services & ESM::NPC::Armor; + else if (item.getTypeName() == typeid(ESM::Clothing).name()) + return services & ESM::NPC::Clothing; + else if (item.getTypeName() == typeid(ESM::Book).name()) + return services & ESM::NPC::Books; + else if (item.getTypeName() == typeid(ESM::Ingredient).name()) + return services & ESM::NPC::Ingredients; + else if (item.getTypeName() == typeid(ESM::Tool).name()) + return services & ESM::NPC::Picks; + else if (item.getTypeName() == typeid(ESM::Probe).name()) + return services & ESM::NPC::Probes; + else if (item.getTypeName() == typeid(ESM::Light).name()) + return services & ESM::NPC::Lights; + else if (item.getTypeName() == typeid(ESM::Apparatus).name()) + return services & ESM::NPC::Apparatus; + else if (item.getTypeName() == typeid(ESM::Repair).name()) + return services & ESM::NPC::RepairItem; + else if (item.getTypeName() == typeid(ESM::Miscellaneous).name()) + return services & ESM::NPC::Misc; + + return false; + } + + std::vector TradeWindow::itemsToIgnore() + { + std::vector items; + MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + + for (MWWorld::ContainerStoreIterator it = invStore.begin(); + it != invStore.end(); ++it) + { + if (!npcAcceptsItem(*it)) + items.push_back(*it); + } + + return items; + } } diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index dd28fcb8b..5e762cbe5 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -30,6 +30,8 @@ namespace MWGui //virtual void Update(); //virtual void notifyContentChanged(); + bool npcAcceptsItem(MWWorld::Ptr item); + protected: MyGUI::Button* mFilterAll; MyGUI::Button* mFilterWeapon; @@ -61,6 +63,8 @@ namespace MWGui virtual bool ignoreEquippedItems() { return true; } virtual std::vector getEquippedItems(); + virtual std::vector itemsToIgnore(); + void updateLabels(); }; } From 50a8eb05d96d975f702a4d3cfced0a0b37929acb Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 May 2012 17:27:55 +0200 Subject: [PATCH 090/118] transfering items between player and merchant works and shows a red frame for bought/sold items. --- apps/openmw/mwgui/container.cpp | 162 ++++++++++++++++++++++++-- apps/openmw/mwgui/container.hpp | 22 +++- apps/openmw/mwgui/dialogue.cpp | 8 +- apps/openmw/mwgui/inventorywindow.cpp | 10 ++ apps/openmw/mwgui/inventorywindow.hpp | 6 + apps/openmw/mwgui/map_window.cpp | 3 +- apps/openmw/mwgui/stats_window.cpp | 3 +- apps/openmw/mwgui/tradewindow.cpp | 10 +- apps/openmw/mwgui/tradewindow.hpp | 3 + 9 files changed, 201 insertions(+), 26 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 9ff4b8d4a..e51e22ecd 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -21,6 +21,8 @@ #include "window_manager.hpp" #include "widgets.hpp" #include "countdialog.hpp" +#include "tradewindow.hpp" +#include "inventorywindow.hpp" using namespace MWGui; using namespace Widgets; @@ -88,37 +90,120 @@ ContainerBase::~ContainerBase() void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) { - if (mDragAndDrop) + mSelectedItem = _sender; + + if (mDragAndDrop && !isTrading()) { if(!mDragAndDrop->mIsOnDragAndDrop) { - mSelectedItem = _sender; - MWWorld::Ptr object = (*_sender->getUserData()); int count = object.getRefData().getCount(); if (MyGUI::InputManager::getInstance().isShiftPressed() || count == 1) { - onSelectedItemImpl(_sender, count); + startDragItem(_sender, count); } else if (MyGUI::InputManager::getInstance().isControlPressed()) { - onSelectedItemImpl(_sender, 1); + startDragItem(_sender, 1); } else { CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); dialog->open(MWWorld::Class::get(object).getName(object), count); dialog->eventOkClicked.clear(); - dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::onSelectedItemImpl); + dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::startDragItem); } } else onContainerClicked(mContainerWidget); } + else + { + MWWorld::Ptr object = (*_sender->getUserData()); + int count = object.getRefData().getCount(); + + if (std::find(mBoughtItems.begin(), mBoughtItems.end(), object) != mBoughtItems.end()) + { + if (MyGUI::InputManager::getInstance().isShiftPressed() || count == 1) + { + sellAlreadyBoughtItem(NULL, count); + } + else if (MyGUI::InputManager::getInstance().isControlPressed()) + { + sellAlreadyBoughtItem(NULL, 1); + } + else + { + CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); + dialog->open(MWWorld::Class::get(object).getName(object), count); + dialog->eventOkClicked.clear(); + dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::sellAlreadyBoughtItem); + } + } + else + { + if (MyGUI::InputManager::getInstance().isShiftPressed() || count == 1) + { + sellItem(NULL, count); + } + else if (MyGUI::InputManager::getInstance().isControlPressed()) + { + sellItem(NULL, 1); + } + else + { + CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); + dialog->open(MWWorld::Class::get(object).getName(object), count); + dialog->eventOkClicked.clear(); + dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::sellItem); + } + } + } } -void ContainerBase::onSelectedItemImpl(MyGUI::Widget* _sender, int count) +void ContainerBase::sellAlreadyBoughtItem(MyGUI::Widget* _sender, int count) +{ + MWWorld::Ptr object = *mSelectedItem->getUserData(); + assert( std::find(mBoughtItems.begin(), mBoughtItems.end(), object) != mBoughtItems.end() ); + + if (count == object.getRefData().getCount()) + mBoughtItems.erase( std::find(mBoughtItems.begin(), mBoughtItems.end(), object) ); + + if (isInventory()) + { + MWBase::Environment::get().getWindowManager()->getTradeWindow()->readdBarteredItem(*mSelectedItem->getUserData(), count); + MWBase::Environment::get().getWindowManager()->getTradeWindow()->drawItems(); + } + else + { + MWBase::Environment::get().getWindowManager()->getInventoryWindow()->readdBarteredItem(*mSelectedItem->getUserData(), count); + MWBase::Environment::get().getWindowManager()->getInventoryWindow()->drawItems(); + } + + drawItems(); +} + +void ContainerBase::sellItem(MyGUI::Widget* _sender, int count) +{ + MWWorld::Ptr newPtr; + if (isInventory()) + { + newPtr = MWBase::Environment::get().getWindowManager()->getTradeWindow()->addBarteredItem(*mSelectedItem->getUserData(), count); + mSoldItems.push_back(newPtr); + MWBase::Environment::get().getWindowManager()->getTradeWindow()->drawItems(); + } + else + { + newPtr = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->addBarteredItem(*mSelectedItem->getUserData(), count); + mSoldItems.push_back(newPtr); + MWBase::Environment::get().getWindowManager()->getInventoryWindow()->drawItems(); + } + + drawItems(); +} + +void ContainerBase::startDragItem(MyGUI::Widget* _sender, int count) { mDragAndDrop->mIsOnDragAndDrop = true; mSelectedItem->detachFromWidget(); @@ -281,6 +366,14 @@ void ContainerBase::drawItems() std::vector equippedItems = getEquippedItems(); + // add bartered items (always at the beginning) + std::sort(mBoughtItems.begin(), mBoughtItems.end(), sortItems); + for (std::vector::iterator it=mBoughtItems.begin(); + it != mBoughtItems.end(); ++it) + { + items.push_back( std::make_pair(*it, ItemState_Barter) ); + } + // filter out the equipped items of categories we don't want std::vector unwantedItems = equippedItems; for (MWWorld::ContainerStoreIterator iter (containerStore.begin(categories)); iter!=containerStore.end(); ++iter) @@ -316,7 +409,8 @@ void ContainerBase::drawItems() for (MWWorld::ContainerStoreIterator iter (containerStore.begin(categories)); iter!=containerStore.end(); ++iter) { if (std::find(equippedItems.begin(), equippedItems.end(), *iter) == equippedItems.end() - && std::find(ignoreItems.begin(), ignoreItems.end(), *iter) == ignoreItems.end()) + && std::find(ignoreItems.begin(), ignoreItems.end(), *iter) == ignoreItems.end() + && std::find(mBoughtItems.begin(), mBoughtItems.end(), *iter) == mBoughtItems.end()) regularItems.push_back(*iter); } @@ -338,7 +432,7 @@ void ContainerBase::drawItems() { displayCount -= mDragAndDrop->mDraggedCount; } - if(displayCount > 0 && !(onlyMagic && MWWorld::Class::get(*iter).getEnchantment(*iter) == "" && iter->getTypeName() != typeid(ESM::Potion).name())) + if(displayCount > 0 && !(onlyMagic && it->second != ItemState_Barter && MWWorld::Class::get(*iter).getEnchantment(*iter) == "" && iter->getTypeName() != typeid(ESM::Potion).name())) { std::string path = std::string("icons\\"); path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter); @@ -361,10 +455,17 @@ void ContainerBase::drawItems() { backgroundTex += "_equip"; } + else if (it->second == ItemState_Barter) + { + backgroundTex += "_barter"; + } backgroundTex += ".dds"; backgroundWidget->setImageTexture(backgroundTex); - backgroundWidget->setProperty("ImageCoord", "0 0 42 42"); + if (it->second == ItemState_Barter && !isMagic) + backgroundWidget->setProperty("ImageCoord", "2 2 42 42"); + else + backgroundWidget->setProperty("ImageCoord", "0 0 42 42"); backgroundWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerBase::onSelectedItem); backgroundWidget->eventMouseWheel += MyGUI::newDelegate(this, &ContainerBase::onMouseWheel); @@ -421,6 +522,47 @@ void ContainerBase::Update() } } +MWWorld::Ptr ContainerBase::readdBarteredItem(MWWorld::Ptr item, int count) +{ + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); + + int origCount = item.getRefData().getCount(); + item.getRefData().setCount(count); + MWWorld::ContainerStoreIterator it = containerStore.add(item); + item.getRefData().setCount(origCount - count); + + if (origCount - count == 0) + mSoldItems.erase( std::find(mSoldItems.begin(), mSoldItems.end(), item) ); + + return *it; +} + +MWWorld::Ptr ContainerBase::addBarteredItem(MWWorld::Ptr item, int count) +{ + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); + + int origCount = item.getRefData().getCount(); + item.getRefData().setCount(count); + MWWorld::ContainerStoreIterator it = containerStore.add(item); + item.getRefData().setCount(origCount - count); + + mBoughtItems.push_back(*it); + return *it; +} + +void ContainerBase::removeBarteredItem(MWWorld::Ptr item, int count) +{ + MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); + + for (MWWorld::ContainerStoreIterator it(containerStore.begin()); it != containerStore.end(); ++it) + { + if (*it == item) + { + item.getRefData().setCount(item.getRefData().getCount() - count); + } + } +} + // ------------------------------------------------------------------------------------------------ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 563b22bc3..43a04ae70 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -62,13 +62,15 @@ namespace MWGui { ItemState_Normal = 0x01, ItemState_Equipped = 0x02, - - // unimplemented ItemState_Barter = 0x03 }; void setWidgets(MyGUI::Widget* containerWidget, MyGUI::ScrollView* itemView); ///< only call once + MWWorld::Ptr addBarteredItem(MWWorld::Ptr item, int count); + MWWorld::Ptr readdBarteredItem(MWWorld::Ptr item, int count); + void removeBarteredItem(MWWorld::Ptr item, int count); + void openContainer(MWWorld::Ptr container); void setFilter(Filter filter); ///< set category filter virtual void Update(); @@ -87,17 +89,31 @@ namespace MWGui Filter mFilter; + std::vector mBoughtItems; + std::vector mSoldItems; + void onSelectedItem(MyGUI::Widget* _sender); - void onSelectedItemImpl(MyGUI::Widget* _sender, int count); void onContainerClicked(MyGUI::Widget* _sender); void onMouseWheel(MyGUI::Widget* _sender, int _rel); + /// start dragging an item (drag & drop) + void startDragItem(MyGUI::Widget* _sender, int count); + + /// sell an item from this container + void sellItem(MyGUI::Widget* _sender, int count); + + /// sell an item from this container, that was previously just bought + void sellAlreadyBoughtItem(MyGUI::Widget* _sender, int count); + std::string getCountString(const int count); + virtual bool isTradeWindow() { return false; } virtual bool isInventory() { return false; } virtual std::vector getEquippedItems() { return std::vector(); } virtual void _unequipItem(MWWorld::Ptr item) { ; } + virtual bool isTrading() { return false; } + virtual bool ignoreEquippedItems() { return false; } virtual std::vector itemsToIgnore() { return std::vector(); } }; diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index e8db4b6d1..9f5e252fd 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -120,9 +120,6 @@ void DialogueWindow::open() history->eraseText(0,history->getTextLength()); updateOptions(); setVisible(true); - - // hide all sub-dialogues of the dialog window (trade window, persuasion, etc) - mWindowManager.getTradeWindow()->setVisible(false); } void DialogueWindow::onByeClicked(MyGUI::Widget* _sender) @@ -137,8 +134,8 @@ void DialogueWindow::onSelectTopic(std::string topic) if (topic == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarter")->str) { /// \todo check if the player is allowed to trade with this actor (e.g. faction rank high enough)? - mWindowManager.getTradeWindow()->startTrade(mActor); mWindowManager.setGuiMode(GM_Barter); + mWindowManager.getTradeWindow()->startTrade(mActor); } else @@ -150,8 +147,7 @@ void DialogueWindow::startDialogue(MWWorld::Ptr actor, std::string npcName) mEnabled = true; mActor = actor; topicsList->setEnabled(true); - static_cast(mMainWidget)->setCaption(npcName); - adjustWindowCaption(); + setTitle(npcName); } void DialogueWindow::setKeywords(std::list keyWords) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index ebba395ff..856ff1896 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -27,6 +27,7 @@ namespace MWGui InventoryWindow::InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) : ContainerBase(dragAndDrop) , WindowPinnableBase("openmw_inventory_window_layout.xml", parWindowManager) + , mTrading(false) { static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize); @@ -94,6 +95,8 @@ namespace MWGui onWindowResize(static_cast(mMainWidget)); updateEncumbranceBar(); + + mTrading = false; } void InventoryWindow::onWindowResize(MyGUI::Window* _sender) @@ -245,4 +248,11 @@ namespace MWGui } return 0; } + + void InventoryWindow::startTrade() + { + mTrading = true; + mBoughtItems.clear(); + mSoldItems.clear(); + } } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index e53402bbd..e544b788a 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -13,6 +13,9 @@ namespace MWGui void openInventory(); + /// start trading, disables item drag&drop + void startTrade(); + virtual void Update(); virtual void notifyContentChanged(); @@ -33,6 +36,8 @@ namespace MWGui MyGUI::Button* mFilterMagic; MyGUI::Button* mFilterMisc; + bool mTrading; + void onWindowResize(MyGUI::Window* _sender); void onFilterChanged(MyGUI::Widget* _sender); void onAvatarClicked(MyGUI::Widget* _sender); @@ -40,6 +45,7 @@ namespace MWGui void updateEncumbranceBar(); + virtual bool isTrading() { return mTrading; } virtual bool isInventory() { return true; } virtual std::vector getEquippedItems(); virtual void _unequipItem(MWWorld::Ptr item); diff --git a/apps/openmw/mwgui/map_window.cpp b/apps/openmw/mwgui/map_window.cpp index d3541f774..9000d2fcb 100644 --- a/apps/openmw/mwgui/map_window.cpp +++ b/apps/openmw/mwgui/map_window.cpp @@ -121,8 +121,7 @@ MapWindow::MapWindow(WindowManager& parWindowManager) : void MapWindow::setCellName(const std::string& cellName) { - static_cast(mMainWidget)->setCaption(cellName); - adjustWindowCaption(); + setTitle(cellName); } void MapWindow::setPlayerPos(const float x, const float y) diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 186668222..43099e936 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -128,8 +128,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(); + setTitle(playerName); } void StatsWindow::setValue (const std::string& id, const MWMechanics::Stat& value) diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index e5fc47764..9f491242b 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -103,13 +103,17 @@ namespace MWGui void TradeWindow::startTrade(MWWorld::Ptr actor) { - ContainerBase::openContainer(actor); - setTitle(MWWorld::Class::get(actor).getName(actor)); - adjustWindowCaption(); mCurrentBalance = 0; + mWindowManager.getInventoryWindow()->startTrade(); + + mBoughtItems.clear(); + mSoldItems.clear(); + + ContainerBase::openContainer(actor); + updateLabels(); } diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index 5e762cbe5..5ab2d0d79 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -63,6 +63,9 @@ namespace MWGui virtual bool ignoreEquippedItems() { return true; } virtual std::vector getEquippedItems(); + virtual bool isTrading() { return true; } + virtual bool isTradeWindow() { return true; } + virtual std::vector itemsToIgnore(); void updateLabels(); From 342a244e31a5a59713cc0b58ee17d8152761db42 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 May 2012 17:36:20 +0200 Subject: [PATCH 091/118] NPC now doesn't buy items of types that he shouldn't accept. --- apps/openmw/mwgui/container.cpp | 12 ++++++++++++ apps/openmw/mwgui/inventorywindow.cpp | 9 +++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index e51e22ecd..7d9fd4363 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -123,6 +123,18 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) MWWorld::Ptr object = (*_sender->getUserData()); int count = object.getRefData().getCount(); + if (isInventory()) + { + // the player is trying to sell an item, check if the merchant accepts it + if (!MWBase::Environment::get().getWindowManager()->getTradeWindow()->npcAcceptsItem(object)) + { + // user notification "i don't buy this item" + MWBase::Environment::get().getWindowManager()-> + messageBox(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarterDialog4")->str, std::vector()); + return; + } + } + if (std::find(mBoughtItems.begin(), mBoughtItems.end(), object) != mBoughtItems.end()) { if (MyGUI::InputManager::getInstance().isShiftPressed() || count == 1) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 856ff1896..e08a2ba4f 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -92,11 +92,14 @@ namespace MWGui void InventoryWindow::openInventory() { - onWindowResize(static_cast(mMainWidget)); - updateEncumbranceBar(); mTrading = false; + + mBoughtItems.clear(); + mSoldItems.clear(); + + onWindowResize(static_cast(mMainWidget)); } void InventoryWindow::onWindowResize(MyGUI::Window* _sender) @@ -252,7 +255,5 @@ namespace MWGui void InventoryWindow::startTrade() { mTrading = true; - mBoughtItems.clear(); - mSoldItems.clear(); } } From fb47681fbd61310037f29ca0095cda55615e451e Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 May 2012 17:58:33 +0200 Subject: [PATCH 092/118] fix a bug, some cleanup --- apps/openmw/mwgui/container.cpp | 33 ++++++++++++--------------- apps/openmw/mwgui/container.hpp | 3 --- apps/openmw/mwgui/countdialog.cpp | 5 ++-- apps/openmw/mwgui/countdialog.hpp | 2 +- apps/openmw/mwgui/hud.cpp | 1 - apps/openmw/mwgui/inventorywindow.cpp | 8 +------ apps/openmw/mwgui/inventorywindow.hpp | 3 +-- apps/openmw/mwgui/tradewindow.hpp | 3 --- apps/openmw/mwgui/window_manager.cpp | 12 +++++++--- 9 files changed, 30 insertions(+), 40 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 7d9fd4363..d0fd06a70 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -109,8 +109,9 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) } else { + std::string message = MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTake")->str; CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); - dialog->open(MWWorld::Class::get(object).getName(object), count); + dialog->open(MWWorld::Class::get(object).getName(object), message, count); dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::startDragItem); } @@ -135,6 +136,10 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) } } + bool buying = isTradeWindow(); // buying or selling? + std::string message = buying ? MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sQuanityMenuMessage02")->str + : MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sQuanityMenuMessage01")->str; + if (std::find(mBoughtItems.begin(), mBoughtItems.end(), object) != mBoughtItems.end()) { if (MyGUI::InputManager::getInstance().isShiftPressed() || count == 1) @@ -148,7 +153,7 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) else { CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); - dialog->open(MWWorld::Class::get(object).getName(object), count); + dialog->open(MWWorld::Class::get(object).getName(object), message, count); dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::sellAlreadyBoughtItem); } @@ -166,7 +171,7 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) else { CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog(); - dialog->open(MWWorld::Class::get(object).getName(object), count); + dialog->open(MWWorld::Class::get(object).getName(object), message, count); dialog->eventOkClicked.clear(); dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerBase::sellItem); } @@ -202,13 +207,15 @@ void ContainerBase::sellItem(MyGUI::Widget* _sender, int count) if (isInventory()) { newPtr = MWBase::Environment::get().getWindowManager()->getTradeWindow()->addBarteredItem(*mSelectedItem->getUserData(), count); - mSoldItems.push_back(newPtr); + if (std::find(mSoldItems.begin(), mSoldItems.end(), newPtr) == mSoldItems.end()) + mSoldItems.push_back(newPtr); MWBase::Environment::get().getWindowManager()->getTradeWindow()->drawItems(); } else { newPtr = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->addBarteredItem(*mSelectedItem->getUserData(), count); - mSoldItems.push_back(newPtr); + if (std::find(mSoldItems.begin(), mSoldItems.end(), newPtr) == mSoldItems.end()) + mSoldItems.push_back(newPtr); MWBase::Environment::get().getWindowManager()->getInventoryWindow()->drawItems(); } @@ -510,8 +517,6 @@ void ContainerBase::drawItems() MyGUI::IntSize size = MyGUI::IntSize(std::max(mItemView->getSize().width, x+42), mItemView->getSize().height); mItemView->setCanvasSize(size); mContainerWidget->setSize(size); - - notifyContentChanged(); } std::string ContainerBase::getCountString(const int count) @@ -524,16 +529,6 @@ std::string ContainerBase::getCountString(const int count) return boost::lexical_cast(count); } -void ContainerBase::Update() -{ - if(mDragAndDrop != NULL && mDragAndDrop->mIsOnDragAndDrop) - { - if(mDragAndDrop->mDraggedWidget) - mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); - else mDragAndDrop->mIsOnDragAndDrop = false; //If this happens, there is a bug. - } -} - MWWorld::Ptr ContainerBase::readdBarteredItem(MWWorld::Ptr item, int count) { MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); @@ -558,7 +553,9 @@ MWWorld::Ptr ContainerBase::addBarteredItem(MWWorld::Ptr item, int count) MWWorld::ContainerStoreIterator it = containerStore.add(item); item.getRefData().setCount(origCount - count); - mBoughtItems.push_back(*it); + if (std::find(mBoughtItems.begin(), mBoughtItems.end(), *it) == mBoughtItems.end()) + mBoughtItems.push_back(*it); + return *it; } diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 43a04ae70..58d4548ee 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -73,11 +73,8 @@ namespace MWGui void openContainer(MWWorld::Ptr container); void setFilter(Filter filter); ///< set category filter - virtual void Update(); void drawItems(); - virtual void notifyContentChanged() { } - protected: MyGUI::ScrollView* mItemView; MyGUI::Widget* mContainerWidget; diff --git a/apps/openmw/mwgui/countdialog.cpp b/apps/openmw/mwgui/countdialog.cpp index dc7e75e0e..16e3f9aab 100644 --- a/apps/openmw/mwgui/countdialog.cpp +++ b/apps/openmw/mwgui/countdialog.cpp @@ -19,7 +19,6 @@ namespace MWGui mOkButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sOk")->str); mCancelButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sCancel")->str); - mLabelText->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTake")->str); mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CountDialog::onCancelButtonClicked); mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CountDialog::onOkButtonClicked); @@ -27,10 +26,12 @@ namespace MWGui mSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &CountDialog::onSliderMoved); } - void CountDialog::open(const std::string& item, const int maxCount) + void CountDialog::open(const std::string& item, const std::string& message, const int maxCount) { setVisible(true); + mLabelText->setCaption(message); + MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize(); mSlider->setScrollRange(maxCount); diff --git a/apps/openmw/mwgui/countdialog.hpp b/apps/openmw/mwgui/countdialog.hpp index b6c836c9d..aac17b846 100644 --- a/apps/openmw/mwgui/countdialog.hpp +++ b/apps/openmw/mwgui/countdialog.hpp @@ -9,7 +9,7 @@ namespace MWGui { public: CountDialog(WindowManager& parWindowManager); - void open(const std::string& item, const int maxCount); + void open(const std::string& item, const std::string& message, const int maxCount); typedef MyGUI::delegates::CMultiDelegate2 EventHandle_WidgetInt; diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 395ca79c5..34d5ece98 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -285,7 +285,6 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender) // remove object from the container it was coming from object.getRefData().setCount(origCount - mDragAndDrop->mDraggedCount); - mDragAndDrop->mDraggedFrom->notifyContentChanged(); mDragAndDrop->mIsOnDragAndDrop = false; MyGUI::Gui::getInstance().destroyWidget(mDragAndDrop->mDraggedWidget); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index e08a2ba4f..ca629d51d 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -228,15 +228,9 @@ namespace MWGui mEncumbranceText->setCaption( boost::lexical_cast(int(encumbrance)) + "/" + boost::lexical_cast(int(capacity)) ); } - void InventoryWindow::notifyContentChanged() - { - } - - void InventoryWindow::Update() + void InventoryWindow::update() { updateEncumbranceBar(); - - ContainerBase::Update(); } int InventoryWindow::getPlayerGold() diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index e544b788a..59aaf7859 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -16,8 +16,7 @@ namespace MWGui /// start trading, disables item drag&drop void startTrade(); - virtual void Update(); - virtual void notifyContentChanged(); + void update(); int getPlayerGold(); diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index 5ab2d0d79..b96abc7e2 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -27,9 +27,6 @@ namespace MWGui void startTrade(MWWorld::Ptr actor); - //virtual void Update(); - //virtual void notifyContentChanged(); - bool npcAcceptsItem(MWWorld::Ptr item); protected: diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index e12fb851e..abbdcbcc1 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -97,7 +97,7 @@ WindowManager::WindowManager( MyGUI::Widget* dragAndDropWidget = gui->createWidgetT("Widget","",0,0,w,h,MyGUI::Align::Default,"DragAndDrop","DragAndDropWidget"); dragAndDropWidget->setVisible(false); - DragAndDrop* mDragAndDrop = new DragAndDrop(); + mDragAndDrop = new DragAndDrop(); mDragAndDrop->mIsOnDragAndDrop = false; mDragAndDrop->mDraggedWidget = 0; mDragAndDrop->mDragAndDropWidget = dragAndDropWidget; @@ -468,9 +468,15 @@ void WindowManager::onDialogueWindowBye() void WindowManager::onFrame (float frameDuration) { mMessageBoxManager->onFrame(frameDuration); - mInventoryWindow->Update(); - mContainerWindow->Update(); mToolTips->onFrame(frameDuration); + + if (mDragAndDrop->mIsOnDragAndDrop) + { + assert(mDragAndDrop->mDraggedWidget); + mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); + } + + mInventoryWindow->update(); } const ESMS::ESMStore& WindowManager::getStore() const From db49e2c04668744a9d3372a7b7c4c67972a009b2 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 May 2012 20:53:24 +0200 Subject: [PATCH 093/118] bought/sold items now use a separate ContainerStore, this fixes a stacking issue among other things --- apps/openmw/mwgui/container.cpp | 76 +++++++++++++-------------- apps/openmw/mwgui/container.hpp | 14 +++-- apps/openmw/mwgui/inventorywindow.cpp | 1 - apps/openmw/mwgui/tradewindow.cpp | 23 ++++---- 4 files changed, 56 insertions(+), 58 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index d0fd06a70..14a500b69 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -182,19 +182,15 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) void ContainerBase::sellAlreadyBoughtItem(MyGUI::Widget* _sender, int count) { MWWorld::Ptr object = *mSelectedItem->getUserData(); - assert( std::find(mBoughtItems.begin(), mBoughtItems.end(), object) != mBoughtItems.end() ); - - if (count == object.getRefData().getCount()) - mBoughtItems.erase( std::find(mBoughtItems.begin(), mBoughtItems.end(), object) ); if (isInventory()) { - MWBase::Environment::get().getWindowManager()->getTradeWindow()->readdBarteredItem(*mSelectedItem->getUserData(), count); + MWBase::Environment::get().getWindowManager()->getTradeWindow()->addItem(object, count); MWBase::Environment::get().getWindowManager()->getTradeWindow()->drawItems(); } else { - MWBase::Environment::get().getWindowManager()->getInventoryWindow()->readdBarteredItem(*mSelectedItem->getUserData(), count); + MWBase::Environment::get().getWindowManager()->getInventoryWindow()->addItem(object, count); MWBase::Environment::get().getWindowManager()->getInventoryWindow()->drawItems(); } @@ -203,19 +199,14 @@ void ContainerBase::sellAlreadyBoughtItem(MyGUI::Widget* _sender, int count) void ContainerBase::sellItem(MyGUI::Widget* _sender, int count) { - MWWorld::Ptr newPtr; if (isInventory()) { - newPtr = MWBase::Environment::get().getWindowManager()->getTradeWindow()->addBarteredItem(*mSelectedItem->getUserData(), count); - if (std::find(mSoldItems.begin(), mSoldItems.end(), newPtr) == mSoldItems.end()) - mSoldItems.push_back(newPtr); + MWBase::Environment::get().getWindowManager()->getTradeWindow()->addBarteredItem(*mSelectedItem->getUserData(), count); MWBase::Environment::get().getWindowManager()->getTradeWindow()->drawItems(); } else { - newPtr = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->addBarteredItem(*mSelectedItem->getUserData(), count); - if (std::find(mSoldItems.begin(), mSoldItems.end(), newPtr) == mSoldItems.end()) - mSoldItems.push_back(newPtr); + MWBase::Environment::get().getWindowManager()->getInventoryWindow()->addBarteredItem(*mSelectedItem->getUserData(), count); MWBase::Environment::get().getWindowManager()->getInventoryWindow()->drawItems(); } @@ -385,10 +376,16 @@ void ContainerBase::drawItems() std::vector equippedItems = getEquippedItems(); - // add bartered items (always at the beginning) - std::sort(mBoughtItems.begin(), mBoughtItems.end(), sortItems); - for (std::vector::iterator it=mBoughtItems.begin(); - it != mBoughtItems.end(); ++it) + // add bought items (always at the beginning) + std::vector boughtItems; + for (MWWorld::ContainerStoreIterator it (mBoughtItems.begin()); it!=mBoughtItems.end(); ++it) + { + boughtItems.push_back(*it); + } + std::sort(boughtItems.begin(), boughtItems.end(), sortItems); + + for (std::vector::iterator it=boughtItems.begin(); + it != boughtItems.end(); ++it) { items.push_back( std::make_pair(*it, ItemState_Barter) ); } @@ -529,49 +526,50 @@ std::string ContainerBase::getCountString(const int count) return boost::lexical_cast(count); } -MWWorld::Ptr ContainerBase::readdBarteredItem(MWWorld::Ptr item, int count) +void ContainerBase::addBarteredItem(MWWorld::Ptr item, int count) { - MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); - int origCount = item.getRefData().getCount(); item.getRefData().setCount(count); - MWWorld::ContainerStoreIterator it = containerStore.add(item); + MWWorld::ContainerStoreIterator it = mBoughtItems.add(item); item.getRefData().setCount(origCount - count); - - if (origCount - count == 0) - mSoldItems.erase( std::find(mSoldItems.begin(), mSoldItems.end(), item) ); - - return *it; } -MWWorld::Ptr ContainerBase::addBarteredItem(MWWorld::Ptr item, int count) +void ContainerBase::addItem(MWWorld::Ptr item, int count) { MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); - int origCount = item.getRefData().getCount(); + int origCount = item.getRefData().getCount(); + item.getRefData().setCount(count); MWWorld::ContainerStoreIterator it = containerStore.add(item); + item.getRefData().setCount(origCount - count); - - if (std::find(mBoughtItems.begin(), mBoughtItems.end(), *it) == mBoughtItems.end()) - mBoughtItems.push_back(*it); - - return *it; } -void ContainerBase::removeBarteredItem(MWWorld::Ptr item, int count) +void ContainerBase::transferBoughtItems() { MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); - for (MWWorld::ContainerStoreIterator it(containerStore.begin()); it != containerStore.end(); ++it) + for (MWWorld::ContainerStoreIterator it(mBoughtItems.begin()); it != mBoughtItems.end(); ++it) { - if (*it == item) - { - item.getRefData().setCount(item.getRefData().getCount() - count); - } + containerStore.add(*it); } } +void ContainerBase::returnBoughtItems(MWWorld::ContainerStore& store) +{ + for (MWWorld::ContainerStoreIterator it(mBoughtItems.begin()); it != mBoughtItems.end(); ++it) + { + store.add(*it); + } +} + +MWWorld::ContainerStore& ContainerBase::getContainerStore() +{ + MWWorld::ContainerStore& store = MWWorld::Class::get(mContainer).getContainerStore(mContainer); + return store; +} + // ------------------------------------------------------------------------------------------------ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index 58d4548ee..d300f4497 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -67,9 +67,13 @@ namespace MWGui void setWidgets(MyGUI::Widget* containerWidget, MyGUI::ScrollView* itemView); ///< only call once - MWWorld::Ptr addBarteredItem(MWWorld::Ptr item, int count); - MWWorld::Ptr readdBarteredItem(MWWorld::Ptr item, int count); - void removeBarteredItem(MWWorld::Ptr item, int count); + void addBarteredItem(MWWorld::Ptr item, int count); + void addItem(MWWorld::Ptr item, int count); + + void transferBoughtItems(); ///< transfer bought items into the inventory + void returnBoughtItems(MWWorld::ContainerStore& store); ///< return bought items into the specified ContainerStore + + MWWorld::ContainerStore& getContainerStore(); void openContainer(MWWorld::Ptr container); void setFilter(Filter filter); ///< set category filter @@ -86,8 +90,8 @@ namespace MWGui Filter mFilter; - std::vector mBoughtItems; - std::vector mSoldItems; + // bought items are put in a separate ContainerStore so that they don't stack with other (not bought) items. + MWWorld::ContainerStore mBoughtItems; void onSelectedItem(MyGUI::Widget* _sender); void onContainerClicked(MyGUI::Widget* _sender); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index ca629d51d..8bc9661e4 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -97,7 +97,6 @@ namespace MWGui mTrading = false; mBoughtItems.clear(); - mSoldItems.clear(); onWindowResize(static_cast(mMainWidget)); } diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 9f491242b..fb70e0045 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -110,7 +110,6 @@ namespace MWGui mWindowManager.getInventoryWindow()->startTrade(); mBoughtItems.clear(); - mSoldItems.clear(); ContainerBase::openContainer(actor); @@ -146,10 +145,19 @@ namespace MWGui void TradeWindow::onOfferButtonClicked(MyGUI::Widget* _sender) { + transferBoughtItems(); + mWindowManager.getInventoryWindow()->transferBoughtItems(); + + mWindowManager.setGuiMode(GM_Game); } void TradeWindow::onCancelButtonClicked(MyGUI::Widget* _sender) { + // i give you back your stuff! + returnBoughtItems(mWindowManager.getInventoryWindow()->getContainerStore()); + // now gimme back my stuff! + mWindowManager.getInventoryWindow()->returnBoughtItems(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + mWindowManager.setGuiMode(GM_Game); } @@ -169,16 +177,6 @@ namespace MWGui mTotalBalance->setCaption(boost::lexical_cast(-mCurrentBalance)); } - // retrieve merchant gold - int gold = 0; - MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); - for (MWWorld::ContainerStoreIterator it = invStore.begin(); - it != invStore.end(); ++it) - { - if (MWWorld::Class::get(*it).getName(*it) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) - gold = it->getRefData().getCount(); - } - int merchantgold; if (mContainer.getTypeName() == typeid(ESM::NPC).name()) { @@ -193,10 +191,9 @@ namespace MWGui ESMS::LiveCellRef* ref = mContainer.get(); merchantgold = ref->base->data.gold; } - gold += merchantgold; mMerchantGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sSellerGold")->str - + " " + boost::lexical_cast(gold)); + + " " + boost::lexical_cast(merchantgold)); } std::vector TradeWindow::getEquippedItems() From c004f5d570bc387b3c7b8910254b295a7f360391 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 May 2012 22:06:25 +0200 Subject: [PATCH 094/118] adjust the "total cost"/"total sold" value when trading items, added some checks with respective user notifications --- apps/openmw/mwgui/container.cpp | 10 +++- apps/openmw/mwgui/container.hpp | 1 + apps/openmw/mwgui/tradewindow.cpp | 76 ++++++++++++++++++++++++++ apps/openmw/mwgui/tradewindow.hpp | 3 + apps/openmw/mwworld/containerstore.hpp | 2 +- 5 files changed, 89 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 14a500b69..710e30b74 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -186,11 +186,13 @@ void ContainerBase::sellAlreadyBoughtItem(MyGUI::Widget* _sender, int count) if (isInventory()) { MWBase::Environment::get().getWindowManager()->getTradeWindow()->addItem(object, count); + MWBase::Environment::get().getWindowManager()->getTradeWindow()->buyFromNpc(object, count); MWBase::Environment::get().getWindowManager()->getTradeWindow()->drawItems(); } else { MWBase::Environment::get().getWindowManager()->getInventoryWindow()->addItem(object, count); + MWBase::Environment::get().getWindowManager()->getTradeWindow()->sellToNpc(object, count); MWBase::Environment::get().getWindowManager()->getInventoryWindow()->drawItems(); } @@ -199,14 +201,18 @@ void ContainerBase::sellAlreadyBoughtItem(MyGUI::Widget* _sender, int count) void ContainerBase::sellItem(MyGUI::Widget* _sender, int count) { + MWWorld::Ptr object = *mSelectedItem->getUserData(); + if (isInventory()) { - MWBase::Environment::get().getWindowManager()->getTradeWindow()->addBarteredItem(*mSelectedItem->getUserData(), count); + MWBase::Environment::get().getWindowManager()->getTradeWindow()->addBarteredItem(object, count); + MWBase::Environment::get().getWindowManager()->getTradeWindow()->buyFromNpc(object, count); MWBase::Environment::get().getWindowManager()->getTradeWindow()->drawItems(); } else { - MWBase::Environment::get().getWindowManager()->getInventoryWindow()->addBarteredItem(*mSelectedItem->getUserData(), count); + MWBase::Environment::get().getWindowManager()->getInventoryWindow()->addBarteredItem(object, count); + MWBase::Environment::get().getWindowManager()->getTradeWindow()->sellToNpc(object, count); MWBase::Environment::get().getWindowManager()->getInventoryWindow()->drawItems(); } diff --git a/apps/openmw/mwgui/container.hpp b/apps/openmw/mwgui/container.hpp index d300f4497..66cac82ce 100644 --- a/apps/openmw/mwgui/container.hpp +++ b/apps/openmw/mwgui/container.hpp @@ -74,6 +74,7 @@ namespace MWGui void returnBoughtItems(MWWorld::ContainerStore& store); ///< return bought items into the specified ContainerStore MWWorld::ContainerStore& getContainerStore(); + MWWorld::ContainerStore& getBoughtItems() { return mBoughtItems; } void openContainer(MWWorld::Ptr container); void setFilter(Filter filter); ///< set category filter diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index fb70e0045..06e91d787 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -145,6 +145,64 @@ namespace MWGui void TradeWindow::onOfferButtonClicked(MyGUI::Widget* _sender) { + // were there any items traded at all? + MWWorld::ContainerStore& playerBought = mWindowManager.getInventoryWindow()->getBoughtItems(); + MWWorld::ContainerStore& merchantBought = getBoughtItems(); + + bool traded=false; + for (MWWorld::ContainerStoreIterator it = playerBought.begin(); + it != playerBought.end(); ++it) + { + if (it->getRefData().getCount() > 0) + traded = true; + } + for (MWWorld::ContainerStoreIterator it = merchantBought.begin(); + it != merchantBought.end(); ++it) + { + if (it->getRefData().getCount() > 0) + traded = true; + } + if (!traded) + { + // user notification + MWBase::Environment::get().getWindowManager()-> + messageBox(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarterDialog11")->str, std::vector()); + return; + } + + // check if the player can afford this + if (mCurrentBalance < 0 && mWindowManager.getInventoryWindow()->getPlayerGold() < std::abs(mCurrentBalance)) + { + // user notification + MWBase::Environment::get().getWindowManager()-> + messageBox(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarterDialog1")->str, std::vector()); + return; + } + + // check if the merchant can afford this + int merchantgold; + if (mContainer.getTypeName() == typeid(ESM::NPC).name()) + { + ESMS::LiveCellRef* ref = mContainer.get(); + if (ref->base->npdt52.gold == -10) + merchantgold = ref->base->npdt12.gold; + else + merchantgold = ref->base->npdt52.gold; + } + else // ESM::Creature + { + ESMS::LiveCellRef* ref = mContainer.get(); + merchantgold = ref->base->data.gold; + } + if (mCurrentBalance > 0 && merchantgold < mCurrentBalance) + { + // user notification + MWBase::Environment::get().getWindowManager()-> + messageBox(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarterDialog2")->str, std::vector()); + return; + } + + // success! make the item transfer. transferBoughtItems(); mWindowManager.getInventoryWindow()->transferBoughtItems(); @@ -276,4 +334,22 @@ namespace MWGui return items; } + + void TradeWindow::sellToNpc(MWWorld::Ptr item, int count) + { + /// \todo price adjustment depending on merchantile skill + + mCurrentBalance -= MWWorld::Class::get(item).getValue(item) * count; + + updateLabels(); + } + + void TradeWindow::buyFromNpc(MWWorld::Ptr item, int count) + { + /// \todo price adjustment depending on merchantile skill + + mCurrentBalance += MWWorld::Class::get(item).getValue(item) * count; + + updateLabels(); + } } diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index b96abc7e2..8da96d37e 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -27,6 +27,9 @@ namespace MWGui void startTrade(MWWorld::Ptr actor); + void sellToNpc(MWWorld::Ptr item, int count); ///< only used for adjusting the gold balance + void buyFromNpc(MWWorld::Ptr item, int count); ///< only used for adjusting the gold balance + bool npcAcceptsItem(MWWorld::Ptr item); protected: diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index 96c97415d..f850b01fa 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -74,7 +74,7 @@ namespace MWWorld /// \attention Do not add items to an existing stack by increasing the count instead of /// calling this function! /// - /// @return if stacking happened, return iterator to the item that was stacked against, otherwise end() iterator + /// @return if stacking happened, return iterator to the item that was stacked against, otherwise iterator to the newly inserted item. protected: ContainerStoreIterator addImpl (const Ptr& ptr); From c30b9e4bb91fa3e6fa98f072b79b000fecd13f49 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 May 2012 22:21:44 +0200 Subject: [PATCH 095/118] add/remove gold from the player at the end of the transaction. --- apps/openmw/mwgui/tradewindow.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 06e91d787..641ffa833 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -5,6 +5,7 @@ #include "../mwbase/environment.hpp" #include "../mwworld/world.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwworld/manualref.hpp" #include "window_manager.hpp" #include "inventorywindow.hpp" @@ -206,6 +207,31 @@ namespace MWGui transferBoughtItems(); mWindowManager.getInventoryWindow()->transferBoughtItems(); + // add or remove gold from the player. + bool goldFound = false; + MWWorld::Ptr gold; + MWWorld::ContainerStore& playerStore = mWindowManager.getInventoryWindow()->getContainerStore(); + for (MWWorld::ContainerStoreIterator it = playerStore.begin(); + it != playerStore.end(); ++it) + { + if (MWWorld::Class::get(*it).getName(*it) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + { + goldFound = true; + gold = *it; + } + } + if (goldFound) + { + gold.getRefData().setCount(gold.getRefData().getCount() + mCurrentBalance); + } + else + { + assert(mCurrentBalance > 0); + MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001"); + ref.getPtr().getRefData().setCount(mCurrentBalance); + playerStore.add(ref.getPtr()); + } + mWindowManager.setGuiMode(GM_Game); } From 498530fad7244b8fe39f96003ab676f344a99bc7 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 18 May 2012 22:24:19 +0200 Subject: [PATCH 096/118] container iterator fix --- apps/openmw/mwworld/containerstore.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index ee1b620cd..44eb0ac70 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -228,6 +228,11 @@ MWWorld::ContainerStoreIterator::ContainerStoreIterator (int mask, ContainerStor : mType (0), mMask (mask), mContainer (container) { nextType(); + + if (mType==-1 || (**this).getRefData().getCount()) + return; + + ++*this; } void MWWorld::ContainerStoreIterator::incType() @@ -249,7 +254,7 @@ void MWWorld::ContainerStoreIterator::nextType() { incType(); - if (mType & mMask) + if ((mType & mMask) && mType>0) if (resetIterator()) break; } From f28f36f2621e9803e1a830120e31609b8994548f Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 May 2012 22:27:27 +0200 Subject: [PATCH 097/118] added sounds to trade window --- apps/openmw/mwgui/container.cpp | 6 ++++++ apps/openmw/mwgui/tradewindow.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 710e30b74..871989fab 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -196,6 +196,9 @@ void ContainerBase::sellAlreadyBoughtItem(MyGUI::Widget* _sender, int count) MWBase::Environment::get().getWindowManager()->getInventoryWindow()->drawItems(); } + std::string sound = MWWorld::Class::get(object).getUpSoundId(object); + MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); + drawItems(); } @@ -216,6 +219,9 @@ void ContainerBase::sellItem(MyGUI::Widget* _sender, int count) MWBase::Environment::get().getWindowManager()->getInventoryWindow()->drawItems(); } + std::string sound = MWWorld::Class::get(object).getUpSoundId(object); + MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); + drawItems(); } diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 641ffa833..b1beccc26 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -6,6 +6,7 @@ #include "../mwworld/world.hpp" #include "../mwworld/inventorystore.hpp" #include "../mwworld/manualref.hpp" +#include "../mwsound/soundmanager.hpp" #include "window_manager.hpp" #include "inventorywindow.hpp" @@ -232,6 +233,9 @@ namespace MWGui playerStore.add(ref.getPtr()); } + std::string sound = "Item Gold Up"; + MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); + mWindowManager.setGuiMode(GM_Game); } From 656b08f6209bb496bc158e7ae151b9288df57c08 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 May 2012 22:32:06 +0200 Subject: [PATCH 098/118] removed the workaround for the ContainerStore bug. --- apps/openmw/mwgui/tradewindow.cpp | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index b1beccc26..047d1da1e 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -150,21 +150,7 @@ namespace MWGui // were there any items traded at all? MWWorld::ContainerStore& playerBought = mWindowManager.getInventoryWindow()->getBoughtItems(); MWWorld::ContainerStore& merchantBought = getBoughtItems(); - - bool traded=false; - for (MWWorld::ContainerStoreIterator it = playerBought.begin(); - it != playerBought.end(); ++it) - { - if (it->getRefData().getCount() > 0) - traded = true; - } - for (MWWorld::ContainerStoreIterator it = merchantBought.begin(); - it != merchantBought.end(); ++it) - { - if (it->getRefData().getCount() > 0) - traded = true; - } - if (!traded) + if (playerBought.begin() == playerBought.end() && merchantBought.begin() == merchantBought.end()) { // user notification MWBase::Environment::get().getWindowManager()-> From 41466fc5fc38bba602ce8c2115a078811ae97a53 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 18 May 2012 23:00:31 +0200 Subject: [PATCH 099/118] gold label fix, and don't allow selling gold --- apps/openmw/mwgui/container.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 871989fab..85a399450 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -127,7 +127,9 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender) if (isInventory()) { // the player is trying to sell an item, check if the merchant accepts it - if (!MWBase::Environment::get().getWindowManager()->getTradeWindow()->npcAcceptsItem(object)) + // also, don't allow selling gold (let's be better than Morrowind at this, can we?) + if (!MWBase::Environment::get().getWindowManager()->getTradeWindow()->npcAcceptsItem(object) + || MWWorld::Class::get(object).getName(object) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) { // user notification "i don't buy this item" MWBase::Environment::get().getWindowManager()-> @@ -533,7 +535,7 @@ std::string ContainerBase::getCountString(const int count) if (count == 1) return ""; if (count > 9999) - return boost::lexical_cast(count/1000.f) + "k"; + return boost::lexical_cast(int(count/1000.f)) + "k"; else return boost::lexical_cast(count); } From 1006411c0200de3259608fc70f1e1cf5df7d225b Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 19 May 2012 00:06:11 +0200 Subject: [PATCH 100/118] small fix for mygui log being spammed with errors --- apps/openmw/mwgui/container.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 85a399450..5595825fc 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -489,7 +489,8 @@ void ContainerBase::drawItems() { backgroundTex += "_barter"; } - backgroundTex += ".dds"; + if (backgroundTex != "") + backgroundTex += ".dds"; backgroundWidget->setImageTexture(backgroundTex); if (it->second == ItemState_Barter && !isMagic) From 9ca579ba63de52d8590692dd96dd5c57dc93c699 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 19 May 2012 00:36:01 +0200 Subject: [PATCH 101/118] slightly revamped gold stacking, now always uses the gold_001 base object to be script-friendly --- apps/openmw/mwworld/containerstore.cpp | 48 +++++++++++++++----------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index ada5b444a..b669508b2 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -5,6 +5,8 @@ #include #include +#include + #include #include "../mwbase/environment.hpp" @@ -32,6 +34,12 @@ namespace return sum; } + + bool compare_string_ci(std::string str1, std::string str2) + { + boost::algorithm::to_lower(str1); + return str1 == str2; + } } MWWorld::ContainerStore::ContainerStore() : mStateId (0), mCachedWeight (0), mWeightUpToDate (false) {} @@ -65,35 +73,35 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& ptr) { int type = getType(ptr); - // gold needs special treatment because it uses several different meshes + // gold needs special handling: when it is inserted into a container, the base object automatically becomes Gold_001 + // this ensures that gold piles of different sizes stack with each other (also, several scripts rely on Gold_001 for detecting player gold) if (MWWorld::Class::get(ptr).getName(ptr) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) { ESMS::LiveCellRef *gold = ptr.get(); - int goldValue = (ptr.getRefData().getCount() == 1) ? gold->base->data.value : ptr.getRefData().getCount(); - - for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) + if (compare_string_ci(gold->ref.refID, "gold_001") + || compare_string_ci(gold->ref.refID, "gold_005") + || compare_string_ci(gold->ref.refID, "gold_010") + || compare_string_ci(gold->ref.refID, "gold_025") + || compare_string_ci(gold->ref.refID, "gold_100")) { - if (MWWorld::Class::get(*iter).getName(*iter) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str - && MWWorld::Class::get(*iter).getScript(*iter) == "" && MWWorld::Class::get(ptr).getScript(ptr) == "") + MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001"); + + int count = (ptr.getRefData().getCount() == 1) ? gold->base->data.value : ptr.getRefData().getCount(); + ref.getPtr().getRefData().setCount(count); + for (MWWorld::ContainerStoreIterator iter (begin(type)); iter!=end(); ++iter) { - ESMS::LiveCellRef *ref = - iter->get(); - - if (iter->getRefData().getCount() == 1) - iter->getRefData().setCount(ref->base->data.value + goldValue); - else - iter->getRefData().setCount(iter->getRefData().getCount() + goldValue); - - flagAsModified(); - return iter; + if (compare_string_ci((*iter).get()->ref.refID, "gold_001")) + { + (*iter).getRefData().setCount( (*iter).getRefData().getCount() + count); + flagAsModified(); + return iter; + } } - } - // if we get here, no already existing gold was found in the container - // we still need special handling because gold in a container should always have the real gold value as reference count. - ptr.getRefData().setCount(goldValue); + return addImpl(ref.getPtr()); + } } // determine whether to stack or not From 24ce88de2a2c871bf06ca4d7c8d30167d5afe8df Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 19 May 2012 14:19:21 +0200 Subject: [PATCH 102/118] working mygui tag replacement system for GMST strings --- apps/openmw/mwgui/stats_window.cpp | 45 +++++++++++++++----- apps/openmw/mwgui/stats_window.hpp | 12 ++++-- apps/openmw/mwgui/tradewindow.cpp | 6 --- apps/openmw/mwgui/window_manager.cpp | 48 ++++++++++++---------- apps/openmw/mwgui/window_manager.hpp | 13 +++++- files/mygui/openmw_trade_window_layout.xml | 24 +++++++---- 6 files changed, 98 insertions(+), 50 deletions(-) diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 43099e936..fac2a05f9 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -1,13 +1,19 @@ #include "stats_window.hpp" -#include "../mwmechanics/mechanicsmanager.hpp" -#include "window_manager.hpp" - #include #include #include + #include +#include "../mwmechanics/mechanicsmanager.hpp" +#include "../mwworld/world.hpp" +#include "../mwworld/player.hpp" +#include "../mwbase/environment.hpp" + +#include "window_manager.hpp" + + using namespace MWGui; const int StatsWindow::lineHeight = 18; @@ -24,11 +30,12 @@ StatsWindow::StatsWindow (WindowManager& parWindowManager) , skillValues() , skillWidgetMap() , factionWidgetMap() - , factions() + , mFactions() , birthSignId() , reputation(0) , bounty(0) , skillWidgets() + , mChanged(true) { setCoord(0,0,498, 342); @@ -128,7 +135,8 @@ void StatsWindow::setBar(const std::string& name, const std::string& tname, int void StatsWindow::setPlayerName(const std::string& playerName) { - setTitle(playerName); + static_cast(mMainWidget)->setCaption(playerName); + adjustWindowCaption(); } void StatsWindow::setValue (const std::string& id, const MWMechanics::Stat& value) @@ -235,9 +243,24 @@ void StatsWindow::configureSkills (const std::vector& major, const std::vec } } -void StatsWindow::setFactions (const std::vector& factions) +void StatsWindow::onFrame () { - this->factions = factions; + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + MWMechanics::NpcStats PCstats = MWWorld::Class::get(player).getNpcStats(player); + + setFactions(PCstats.mFactionRank); + + if (mChanged) + updateSkillArea(); +} + +void StatsWindow::setFactions (const FactionList& factions) +{ + if (mFactions != factions) + { + mFactions = factions; + mChanged = true; + } } void StatsWindow::setBirthSign (const std::string& signId) @@ -345,6 +368,8 @@ void StatsWindow::addSkills(const SkillList &skills, const std::string &titleId, void StatsWindow::updateSkillArea() { + mChanged = false; + for (std::vector::iterator it = skillWidgets.begin(); it != skillWidgets.end(); ++it) { MyGUI::Gui::getInstance().destroyWidget(*it); @@ -366,15 +391,15 @@ void StatsWindow::updateSkillArea() const ESMS::ESMStore &store = mWindowManager.getStore(); - if (!factions.empty()) + if (!mFactions.empty()) { // Add a line separator if there are items above if (!skillWidgets.empty()) addSeparator(coord1, coord2); addGroup(mWindowManager.getGameSettingString("sFaction", "Faction"), coord1, coord2); - FactionList::const_iterator end = factions.end(); - for (FactionList::const_iterator it = factions.begin(); it != end; ++it) + FactionList::const_iterator end = mFactions.end(); + for (FactionList::const_iterator it = mFactions.begin(); it != end; ++it) { const ESM::Faction *faction = store.factions.find(it->first); addItem(faction->name, coord1, coord2); diff --git a/apps/openmw/mwgui/stats_window.hpp b/apps/openmw/mwgui/stats_window.hpp index 08c5148ec..ecda22ee0 100644 --- a/apps/openmw/mwgui/stats_window.hpp +++ b/apps/openmw/mwgui/stats_window.hpp @@ -18,13 +18,15 @@ namespace MWGui class StatsWindow : public WindowPinnableBase { public: - typedef std::pair Faction; - typedef std::vector FactionList; + typedef std::map FactionList; typedef std::vector SkillList; StatsWindow(WindowManager& parWindowManager); + /// automatically updates all the data in the stats window, but only if it has changed. + void onFrame(); + void setBar(const std::string& name, const std::string& tname, int val, int max); void setPlayerName(const std::string& playerName); @@ -36,7 +38,7 @@ namespace MWGui void setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::Stat& value); void configureSkills (const SkillList& major, const SkillList& minor); - void setFactions (const std::vector& factions); + void setFactions (const FactionList& factions); void setBirthSign (const std::string &signId); void setReputation (int reputation) { this->reputation = reputation; } void setBounty (int bounty) { this->bounty = bounty; } @@ -69,11 +71,13 @@ namespace MWGui std::map > skillValues; std::map skillWidgetMap; std::map factionWidgetMap; - FactionList factions; ///< Stores a list of factions and the current rank + FactionList mFactions; ///< Stores a list of factions and the current rank std::string birthSignId; int reputation, bounty; std::vector skillWidgets; //< Skills and other information + bool mChanged; + protected: virtual void onPinToggled(); }; diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 047d1da1e..2dcf7c7f8 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -47,12 +47,6 @@ namespace MWGui mCancelButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sCancel")->str); mOfferButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarterDialog8")->str); - mFilterAll->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sAllTab")->str); - mFilterWeapon->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sWeaponTab")->str); - mFilterApparel->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sApparelTab")->str); - mFilterMagic->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sMagicTab")->str); - mFilterMisc->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sMiscTab")->str); - // adjust size of buttons to fit text int curX = 0; mFilterAll->setSize( mFilterAll->getTextSize().width + 24, mFilterAll->getSize().height ); diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index f447c78e4..9246af1fe 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -40,7 +40,7 @@ WindowManager::WindowManager( , hud(NULL) , map(NULL) , menu(NULL) - , stats(NULL) + , mStatsWindow(NULL) , mToolTips(NULL) , mMessageBoxManager(NULL) , console(NULL) @@ -89,6 +89,8 @@ WindowManager::WindowManager( MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &WindowManager::onRetrieveTag); + // Get size info from the Gui object assert(gui); int w = MyGUI::RenderManager::getInstance().getViewSize().width; @@ -104,7 +106,7 @@ WindowManager::WindowManager( menu = new MainMenu(w,h); map = new MapWindow(*this); - stats = new StatsWindow(*this); + mStatsWindow = new StatsWindow(*this); console = new Console(w,h, extensions); mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); @@ -146,7 +148,7 @@ WindowManager::~WindowManager() delete hud; delete map; delete menu; - delete stats; + delete mStatsWindow; delete mJournal; delete mDialogueWindow; delete mContainerWindow; @@ -207,7 +209,7 @@ void WindowManager::updateVisible() // Start out by hiding everything except the HUD map->setVisible(false); menu->setVisible(false); - stats->setVisible(false); + mStatsWindow->setVisible(false); console->disable(); mJournal->setVisible(false); mDialogueWindow->setVisible(false); @@ -261,7 +263,7 @@ void WindowManager::updateVisible() // Show the windows we want map -> setVisible( (eff & GW_Map) != 0 ); - stats -> setVisible( (eff & GW_Stats) != 0 ); + mStatsWindow -> setVisible( (eff & GW_Stats) != 0 ); mInventoryWindow->setVisible(true); mInventoryWindow->openInventory(); break; @@ -299,7 +301,7 @@ void WindowManager::updateVisible() void WindowManager::setValue (const std::string& id, const MWMechanics::Stat& value) { - stats->setValue (id, value); + mStatsWindow->setValue (id, value); static const char *ids[] = { @@ -329,13 +331,13 @@ void WindowManager::setValue (const std::string& id, const MWMechanics::Stat& value) { - stats->setValue(parSkill, value); + mStatsWindow->setValue(parSkill, value); playerSkillValues[parSkill] = value; } void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicStat& value) { - stats->setValue (id, value); + mStatsWindow->setValue (id, value); hud->setValue (id, value); if (id == "HBar") { @@ -368,7 +370,7 @@ MWMechanics::DynamicStat WindowManager::getValue(const std::string& id) void WindowManager::setValue (const std::string& id, const std::string& value) { - stats->setValue (id, value); + mStatsWindow->setValue (id, value); if (id=="name") playerName = value; else if (id=="race") @@ -377,46 +379,41 @@ void WindowManager::setValue (const std::string& id, const std::string& value) void WindowManager::setValue (const std::string& id, int value) { - stats->setValue (id, value); + mStatsWindow->setValue (id, value); } void WindowManager::setPlayerClass (const ESM::Class &class_) { playerClass = class_; - stats->setValue("class", playerClass.name); + mStatsWindow->setValue("class", playerClass.name); } void WindowManager::configureSkills (const SkillList& major, const SkillList& minor) { - stats->configureSkills (major, minor); + mStatsWindow->configureSkills (major, minor); playerMajorSkills = major; playerMinorSkills = minor; } -void WindowManager::setFactions (const FactionList& factions) -{ - stats->setFactions (factions); -} - void WindowManager::setBirthSign (const std::string &signId) { - stats->setBirthSign (signId); + mStatsWindow->setBirthSign (signId); playerBirthSignId = signId; } void WindowManager::setReputation (int reputation) { - stats->setReputation (reputation); + mStatsWindow->setReputation (reputation); } void WindowManager::setBounty (int bounty) { - stats->setBounty (bounty); + mStatsWindow->setBounty (bounty); } void WindowManager::updateSkillArea() { - stats->updateSkillArea(); + mStatsWindow->updateSkillArea(); } void WindowManager::removeDialog(OEngine::GUI::Layout*dialog) @@ -477,6 +474,8 @@ void WindowManager::onFrame (float frameDuration) } mInventoryWindow->update(); + + mStatsWindow->onFrame(); } const ESMS::ESMStore& WindowManager::getStore() const @@ -598,3 +597,10 @@ void WindowManager::setDragDrop(bool dragDrop) mToolTips->setEnabled(!dragDrop); MWBase::Environment::get().getInputManager()->setDragDrop(dragDrop); } + +void WindowManager::onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _result) +{ + const ESM::GameSetting *setting = MWBase::Environment::get().getWorld()->getStore().gameSettings.search(_tag); + if (setting && setting->type == ESM::VT_String) + _result = setting->str; +} diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 82c494191..cdcace85d 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -14,11 +14,15 @@ #include #include +#include "MyGUI_UString.h" + #include #include #include + #include "../mwmechanics/stat.hpp" #include "../mwworld/ptr.hpp" + #include "mode.hpp" namespace MyGUI @@ -157,7 +161,6 @@ namespace MWGui void setPlayerClass (const ESM::Class &class_); ///< set current class of player void configureSkills (const SkillList& major, const SkillList& minor); ///< configure skill groups, each set contains the skill ID for that group. - void setFactions (const FactionList& factions); ///< set faction and rank to display on stat window, use an empty vector to disable void setBirthSign (const std::string &signId); ///< set birth sign to display on stat window, use an empty string to disable. void setReputation (int reputation); ///< set the current reputation value void setBounty (int bounty); ///< set the current bounty value @@ -216,7 +219,7 @@ namespace MWGui MapWindow *map; MainMenu *menu; ToolTips *mToolTips; - StatsWindow *stats; + StatsWindow *mStatsWindow; MessageBoxManager *mMessageBoxManager; Console *console; JournalWindow* mJournal; @@ -270,6 +273,12 @@ namespace MWGui size_t mBatchCount; void onDialogueWindowBye(); + + /** + * Called when MyGUI tries to retrieve a tag. This usually corresponds to a GMST string, + * so this method will retrieve the GMST with the name \a _tag and place the result in \a _result + */ + void onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _result); }; template diff --git a/files/mygui/openmw_trade_window_layout.xml b/files/mygui/openmw_trade_window_layout.xml index b6a93e697..8a4e00433 100644 --- a/files/mygui/openmw_trade_window_layout.xml +++ b/files/mygui/openmw_trade_window_layout.xml @@ -6,11 +6,21 @@ - - - - - + + + + + + + + + + + + + + + @@ -36,8 +46,8 @@ - - + + From 7ef0ad4e39c46d514681fac994a5ccbcf8d26e72 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 19 May 2012 14:55:09 +0200 Subject: [PATCH 103/118] show faction & birthsign in the stats window --- apps/openmw/mwgui/charactercreation.cpp | 2 -- apps/openmw/mwgui/inventorywindow.cpp | 11 ++++------ apps/openmw/mwgui/inventorywindow.hpp | 2 +- apps/openmw/mwgui/stats_window.cpp | 15 +++++++++++++- apps/openmw/mwgui/stats_window.hpp | 5 +++-- apps/openmw/mwgui/window_manager.cpp | 9 +-------- apps/openmw/mwgui/window_manager.hpp | 2 -- .../mygui/openmw_inventory_window_layout.xml | 20 ++++++++++++++----- 8 files changed, 38 insertions(+), 28 deletions(-) diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp index 7a86ba9ac..afb168d32 100644 --- a/apps/openmw/mwgui/charactercreation.cpp +++ b/apps/openmw/mwgui/charactercreation.cpp @@ -173,7 +173,6 @@ void CharacterCreation::spawnDialog(const char id) mWM->removeDialog(mBirthSignDialog); mBirthSignDialog = new BirthDialog(*mWM); mBirthSignDialog->setNextButtonShow(mCreationStage >= CSE_BirthSignChosen); - mBirthSignDialog->setBirthId(mPlayerBirthSignId); mBirthSignDialog->eventDone += MyGUI::newDelegate(this, &CharacterCreation::onBirthSignDialogDone); mBirthSignDialog->eventBack += MyGUI::newDelegate(this, &CharacterCreation::onBirthSignDialogBack); mBirthSignDialog->open(); @@ -414,7 +413,6 @@ void CharacterCreation::onBirthSignDialogDone(WindowBase* parWindow) if (mBirthSignDialog) { mPlayerBirthSignId = mBirthSignDialog->getBirthId(); - mWM->setBirthSign(mPlayerBirthSignId); if (!mPlayerBirthSignId.empty()) MWBase::Environment::get().getMechanicsManager()->setPlayerBirthsign(mPlayerBirthSignId); mWM->removeDialog(mBirthSignDialog); diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 8bc9661e4..a0326debc 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -50,12 +50,6 @@ namespace MWGui getWidget(itemView, "ItemView"); setWidgets(containerWidget, itemView); - mFilterAll->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sAllTab")->str); - mFilterWeapon->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sWeaponTab")->str); - mFilterApparel->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sApparelTab")->str); - mFilterMagic->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sMagicTab")->str); - mFilterMisc->setCaption (MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sMiscTab")->str); - // adjust size of buttons to fit text int curX = 0; mFilterAll->setSize( mFilterAll->getTextSize().width + 24, mFilterAll->getSize().height ); @@ -227,8 +221,11 @@ namespace MWGui mEncumbranceText->setCaption( boost::lexical_cast(int(encumbrance)) + "/" + boost::lexical_cast(int(capacity)) ); } - void InventoryWindow::update() + void InventoryWindow::onFrame() { + if (!mMainWidget->getVisible()) + return; + updateEncumbranceBar(); } diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp index 59aaf7859..fdb443829 100644 --- a/apps/openmw/mwgui/inventorywindow.hpp +++ b/apps/openmw/mwgui/inventorywindow.hpp @@ -16,7 +16,7 @@ namespace MWGui /// start trading, disables item drag&drop void startTrade(); - void update(); + void onFrame(); int getPlayerGold(); diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index fac2a05f9..30d63033b 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -245,11 +245,16 @@ void StatsWindow::configureSkills (const std::vector& major, const std::vec void StatsWindow::onFrame () { + if (mMainWidget->getVisible()) + return; + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWMechanics::NpcStats PCstats = MWWorld::Class::get(player).getNpcStats(player); setFactions(PCstats.mFactionRank); + setBirthSign(MWBase::Environment::get().getWorld()->getPlayer().getBirthsign()); + if (mChanged) updateSkillArea(); } @@ -265,7 +270,11 @@ void StatsWindow::setFactions (const FactionList& factions) void StatsWindow::setBirthSign (const std::string& signId) { - birthSignId = signId; + if (signId != birthSignId) + { + birthSignId = signId; + mChanged = true; + } } void StatsWindow::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) @@ -376,6 +385,10 @@ void StatsWindow::updateSkillArea() } skillWidgets.clear(); + skillScrollerWidget->setScrollPosition(0); + onScrollChangePosition(skillScrollerWidget, 0); + clientHeight = 0; + const int valueSize = 40; MyGUI::IntCoord coord1(10, 0, skillClientWidget->getWidth() - (10 + valueSize), 18); MyGUI::IntCoord coord2(coord1.left + coord1.width, coord1.top, valueSize, coord1.height); diff --git a/apps/openmw/mwgui/stats_window.hpp b/apps/openmw/mwgui/stats_window.hpp index ecda22ee0..677b32935 100644 --- a/apps/openmw/mwgui/stats_window.hpp +++ b/apps/openmw/mwgui/stats_window.hpp @@ -38,8 +38,6 @@ namespace MWGui void setValue(const ESM::Skill::SkillEnum parSkill, const MWMechanics::Stat& value); void configureSkills (const SkillList& major, const SkillList& minor); - void setFactions (const FactionList& factions); - void setBirthSign (const std::string &signId); void setReputation (int reputation) { this->reputation = reputation; } void setBounty (int bounty) { this->bounty = bounty; } void updateSkillArea(); @@ -54,6 +52,9 @@ namespace MWGui void setupToolTips(); + void setFactions (const FactionList& factions); + void setBirthSign (const std::string &signId); + void onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos); void onWindowResize(MyGUI::Window* window); void onMouseWheel(MyGUI::Widget* _sender, int _rel); diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index 9246af1fe..2cacf2346 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -54,7 +54,6 @@ WindowManager::WindowManager( , playerClass() , playerName() , playerRaceId() - , playerBirthSignId() , playerAttributes() , playerMajorSkills() , playerMinorSkills() @@ -395,12 +394,6 @@ void WindowManager::configureSkills (const SkillList& major, const SkillList& mi playerMinorSkills = minor; } -void WindowManager::setBirthSign (const std::string &signId) -{ - mStatsWindow->setBirthSign (signId); - playerBirthSignId = signId; -} - void WindowManager::setReputation (int reputation) { mStatsWindow->setReputation (reputation); @@ -473,7 +466,7 @@ void WindowManager::onFrame (float frameDuration) mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition()); } - mInventoryWindow->update(); + mInventoryWindow->onFrame(); mStatsWindow->onFrame(); } diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index cdcace85d..22fe973a5 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -161,7 +161,6 @@ namespace MWGui void setPlayerClass (const ESM::Class &class_); ///< set current class of player void configureSkills (const SkillList& major, const SkillList& minor); ///< configure skill groups, each set contains the skill ID for that group. - void setBirthSign (const std::string &signId); ///< set birth sign to display on stat window, use an empty string to disable. void setReputation (int reputation); ///< set the current reputation value void setBounty (int bounty); ///< set the current bounty value void updateSkillArea(); ///< update display of skills, factions, birth sign, reputation and bounty @@ -238,7 +237,6 @@ namespace MWGui ESM::Class playerClass; std::string playerName; std::string playerRaceId; - std::string playerBirthSignId; std::map > playerAttributes; SkillList playerMajorSkills, playerMinorSkills; std::map > playerSkillValues; diff --git a/files/mygui/openmw_inventory_window_layout.xml b/files/mygui/openmw_inventory_window_layout.xml index 4d63b03c2..86ef65324 100644 --- a/files/mygui/openmw_inventory_window_layout.xml +++ b/files/mygui/openmw_inventory_window_layout.xml @@ -35,11 +35,21 @@ - - - - - + + + + + + + + + + + + + + + From 7a4de0ed1d527c018bc5f565ed9d007b8a6a82bb Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 19 May 2012 15:32:32 +0200 Subject: [PATCH 104/118] changed more gui stuff to use the new tag system --- apps/openmw/mwgui/birth.cpp | 1 - apps/openmw/mwgui/class.cpp | 3 -- apps/openmw/mwgui/race.cpp | 1 - apps/openmw/mwgui/review.cpp | 5 ---- apps/openmw/mwgui/stats_window.cpp | 6 ---- apps/openmw/mwgui/tradewindow.cpp | 6 ---- files/mygui/openmw_chargen_birth_layout.xml | 2 +- files/mygui/openmw_chargen_class_layout.xml | 2 +- .../openmw_chargen_create_class_layout.xml | 2 +- ...w_chargen_generate_class_result_layout.xml | 2 +- files/mygui/openmw_chargen_race_layout.xml | 2 +- files/mygui/openmw_chargen_review_layout.xml | 30 ++++++++++++++----- .../mygui/openmw_inventory_window_layout.xml | 6 +--- files/mygui/openmw_stats_window_layout.xml | 24 +++++++++++---- files/mygui/openmw_trade_window_layout.xml | 12 ++++++-- 15 files changed, 55 insertions(+), 49 deletions(-) diff --git a/apps/openmw/mwgui/birth.cpp b/apps/openmw/mwgui/birth.cpp index cb15eaf15..49f90d1a0 100644 --- a/apps/openmw/mwgui/birth.cpp +++ b/apps/openmw/mwgui/birth.cpp @@ -27,7 +27,6 @@ BirthDialog::BirthDialog(WindowManager& parWindowManager) MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); - backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BirthDialog::onBackClicked); MyGUI::ButtonPtr okButton; diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index e654f7c90..3e41fa6b1 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -28,7 +28,6 @@ GenerateClassResultDialog::GenerateClassResultDialog(WindowManager& parWindowMan MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); - backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &GenerateClassResultDialog::onBackClicked); MyGUI::ButtonPtr okButton; @@ -111,7 +110,6 @@ PickClassDialog::PickClassDialog(WindowManager& parWindowManager) MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &PickClassDialog::onBackClicked); - backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); @@ -432,7 +430,6 @@ CreateClassDialog::CreateClassDialog(WindowManager& parWindowManager) MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CreateClassDialog::onBackClicked); - backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); MyGUI::ButtonPtr okButton; getWidget(okButton, "OKButton"); diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index 275759c9f..f18bdb41f 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -71,7 +71,6 @@ RaceDialog::RaceDialog(WindowManager& parWindowManager) MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); - backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onBackClicked); MyGUI::ButtonPtr okButton; diff --git a/apps/openmw/mwgui/review.cpp b/apps/openmw/mwgui/review.cpp index 81a87b07b..5059efb34 100644 --- a/apps/openmw/mwgui/review.cpp +++ b/apps/openmw/mwgui/review.cpp @@ -27,25 +27,21 @@ ReviewDialog::ReviewDialog(WindowManager& parWindowManager) ButtonPtr button; 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);; @@ -92,7 +88,6 @@ ReviewDialog::ReviewDialog(WindowManager& parWindowManager) MyGUI::ButtonPtr backButton; getWidget(backButton, "BackButton"); - backButton->setCaption(mWindowManager.getGameSettingString("sBack", "")); backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ReviewDialog::onBackClicked); MyGUI::ButtonPtr okButton; diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 30d63033b..06576b42b 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -49,12 +49,6 @@ StatsWindow::StatsWindow (WindowManager& parWindowManager) { "Attrib6", "sAttributeEndurance" }, { "Attrib7", "sAttributePersonality" }, { "Attrib8", "sAttributeLuck" }, - { "Health_str", "sHealth" }, - { "Magicka_str", "sMagic" }, - { "Fatigue_str", "sFatigue" }, - { "Level_str", "sLevel" }, - { "Race_str", "sRace" }, - { "Class_str", "sClass" }, { 0, 0 } }; diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 2dcf7c7f8..3570ea6a3 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -41,12 +41,6 @@ namespace MWGui getWidget(mTotalBalanceLabel, "TotalBalanceLabel"); getWidget(mBottomPane, "BottomPane"); - // this GMST doesn't seem to get retrieved - even though i can clearly see it in the CS !??!? - mMaxSaleButton->setCaption(mWindowManager.getGameSettingString("sMaxSale", "Max. Sale")); - - mCancelButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sCancel")->str); - mOfferButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarterDialog8")->str); - // adjust size of buttons to fit text int curX = 0; mFilterAll->setSize( mFilterAll->getTextSize().width + 24, mFilterAll->getSize().height ); diff --git a/files/mygui/openmw_chargen_birth_layout.xml b/files/mygui/openmw_chargen_birth_layout.xml index bce3f585d..0599ab863 100644 --- a/files/mygui/openmw_chargen_birth_layout.xml +++ b/files/mygui/openmw_chargen_birth_layout.xml @@ -15,7 +15,7 @@ - + diff --git a/files/mygui/openmw_chargen_class_layout.xml b/files/mygui/openmw_chargen_class_layout.xml index bf49810c8..38fa606ab 100644 --- a/files/mygui/openmw_chargen_class_layout.xml +++ b/files/mygui/openmw_chargen_class_layout.xml @@ -55,7 +55,7 @@ - + diff --git a/files/mygui/openmw_chargen_create_class_layout.xml b/files/mygui/openmw_chargen_create_class_layout.xml index 3b7d91b00..be6a10e0c 100644 --- a/files/mygui/openmw_chargen_create_class_layout.xml +++ b/files/mygui/openmw_chargen_create_class_layout.xml @@ -56,7 +56,7 @@ - + diff --git a/files/mygui/openmw_chargen_generate_class_result_layout.xml b/files/mygui/openmw_chargen_generate_class_result_layout.xml index 26ebe17e1..9a6ed4f2e 100644 --- a/files/mygui/openmw_chargen_generate_class_result_layout.xml +++ b/files/mygui/openmw_chargen_generate_class_result_layout.xml @@ -21,7 +21,7 @@ - + diff --git a/files/mygui/openmw_chargen_race_layout.xml b/files/mygui/openmw_chargen_race_layout.xml index 6887b12c5..a9b072f5e 100644 --- a/files/mygui/openmw_chargen_race_layout.xml +++ b/files/mygui/openmw_chargen_race_layout.xml @@ -61,7 +61,7 @@ - + diff --git a/files/mygui/openmw_chargen_review_layout.xml b/files/mygui/openmw_chargen_review_layout.xml index c713eb477..57bb3b124 100644 --- a/files/mygui/openmw_chargen_review_layout.xml +++ b/files/mygui/openmw_chargen_review_layout.xml @@ -5,10 +5,18 @@ - - - - + + + + + + + + + + + + @@ -17,9 +25,15 @@ - - - + + + + + + + + + @@ -42,7 +56,7 @@ - + diff --git a/files/mygui/openmw_inventory_window_layout.xml b/files/mygui/openmw_inventory_window_layout.xml index 86ef65324..b38e15fc7 100644 --- a/files/mygui/openmw_inventory_window_layout.xml +++ b/files/mygui/openmw_inventory_window_layout.xml @@ -7,11 +7,7 @@ - - - - - + diff --git a/files/mygui/openmw_stats_window_layout.xml b/files/mygui/openmw_stats_window_layout.xml index 9406fe6bd..8b6080227 100644 --- a/files/mygui/openmw_stats_window_layout.xml +++ b/files/mygui/openmw_stats_window_layout.xml @@ -7,9 +7,15 @@ - - - + + + + + + + + + @@ -20,9 +26,15 @@ - - - + + + + + + + + + diff --git a/files/mygui/openmw_trade_window_layout.xml b/files/mygui/openmw_trade_window_layout.xml index 8a4e00433..83d7557d9 100644 --- a/files/mygui/openmw_trade_window_layout.xml +++ b/files/mygui/openmw_trade_window_layout.xml @@ -51,9 +51,15 @@ - - - + + + + + + + + + From 4fb30544d4b101437dc0411c57cc62afd0a9cb02 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 19 May 2012 16:00:00 +0200 Subject: [PATCH 105/118] more gui files cleanup --- apps/openmw/mwgui/container.cpp | 3 --- apps/openmw/mwgui/dialogue.cpp | 1 - apps/openmw/mwgui/hud.cpp | 3 --- apps/openmw/mwgui/map_window.cpp | 5 ----- files/mygui/openmw_container_window_layout.xml | 8 ++++++-- files/mygui/openmw_dialogue_window_layout.xml | 2 +- files/mygui/openmw_hud_layout.xml | 11 +++++++---- files/mygui/openmw_map_window_layout.xml | 4 +++- files/mygui/openmw_trade_window_layout.xml | 2 +- 9 files changed, 18 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 5595825fc..be21987ef 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -603,9 +603,6 @@ ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dr mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onCloseButtonClicked); mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onTakeAllButtonClicked); - setText("CloseButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sClose")->str); - setText("TakeButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTakeAll")->str); - // adjust buttons size to fit text int closeButtonWidth = mCloseButton->getTextSize().width+24; int takeButtonWidth = mTakeButton->getTextSize().width+24; diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 9f5e252fd..53ab98aeb 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -69,7 +69,6 @@ DialogueWindow::DialogueWindow(WindowManager& parWindowManager) MyGUI::ButtonPtr byeButton; getWidget(byeButton, "ByeButton"); byeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &DialogueWindow::onByeClicked); - byeButton->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGoodbye")->str); getWidget(pDispositionBar, "Disposition"); getWidget(pDispositionText,"DispositionText"); diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 34d5ece98..4a65458df 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -77,9 +77,6 @@ HUD::HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop) getWidget(trianglecounter, "TriangleCounter"); getWidget(batchcounter, "BatchCounter"); - compass->setImageTexture("textures\\compass.dds"); - crosshair->setImageTexture("textures\\target.dds"); - // These are just demo values, you should replace these with // real calls from outside the class later. setWeapIcon("icons\\w\\tx_knife_iron.dds"); diff --git a/apps/openmw/mwgui/map_window.cpp b/apps/openmw/mwgui/map_window.cpp index 9000d2fcb..78ca70798 100644 --- a/apps/openmw/mwgui/map_window.cpp +++ b/apps/openmw/mwgui/map_window.cpp @@ -95,11 +95,6 @@ MapWindow::MapWindow(WindowManager& parWindowManager) : mGlobal(false) { setCoord(500,0,320,300); - setText("WorldButton", "World"); - setImage("Compass", "textures\\compass.dds"); - - // Obviously you should override this later on - setCellName("No Cell Loaded"); getWidget(mLocalMap, "LocalMap"); getWidget(mGlobalMap, "GlobalMap"); diff --git a/files/mygui/openmw_container_window_layout.xml b/files/mygui/openmw_container_window_layout.xml index cb66fadc1..ae9b0bfdf 100644 --- a/files/mygui/openmw_container_window_layout.xml +++ b/files/mygui/openmw_container_window_layout.xml @@ -12,8 +12,12 @@ - - + + + + + + diff --git a/files/mygui/openmw_dialogue_window_layout.xml b/files/mygui/openmw_dialogue_window_layout.xml index d45de4bd4..1271a287b 100644 --- a/files/mygui/openmw_dialogue_window_layout.xml +++ b/files/mygui/openmw_dialogue_window_layout.xml @@ -24,7 +24,7 @@ - + diff --git a/files/mygui/openmw_hud_layout.xml b/files/mygui/openmw_hud_layout.xml index 2dafa7298..0c5ffba6a 100644 --- a/files/mygui/openmw_hud_layout.xml +++ b/files/mygui/openmw_hud_layout.xml @@ -62,7 +62,10 @@ - + + + + @@ -85,9 +88,9 @@ - - + + + - + + + diff --git a/files/mygui/openmw_trade_window_layout.xml b/files/mygui/openmw_trade_window_layout.xml index 83d7557d9..c8a9f2523 100644 --- a/files/mygui/openmw_trade_window_layout.xml +++ b/files/mygui/openmw_trade_window_layout.xml @@ -58,7 +58,7 @@ - + From 2a4c55f1abd5cd00b62ce920bf954d66dc745fc2 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 19 May 2012 16:04:34 +0200 Subject: [PATCH 106/118] use Class::getInventoryStore instead of casting ContainerStore. --- apps/openmw/mwgui/inventorywindow.cpp | 8 ++++---- apps/openmw/mwgui/tradewindow.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index a0326debc..49b441af3 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -142,7 +142,7 @@ namespace MWGui if (mDragAndDrop->mDraggedFrom != this) { // add item to the player's inventory - MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + MWWorld::ContainerStore& invStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); MWWorld::ContainerStoreIterator it = invStore.begin(); int origCount = ptr.getRefData().getCount(); @@ -179,7 +179,7 @@ namespace MWGui std::vector InventoryWindow::getEquippedItems() { - MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + MWWorld::InventoryStore& invStore = MWWorld::Class::get(mContainer).getInventoryStore(mContainer); std::vector items; @@ -197,7 +197,7 @@ namespace MWGui void InventoryWindow::_unequipItem(MWWorld::Ptr item) { - MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + MWWorld::InventoryStore& invStore = MWWorld::Class::get(mContainer).getInventoryStore(mContainer); for (int slot=0; slot < MWWorld::InventoryStore::Slots; ++slot) { @@ -231,7 +231,7 @@ namespace MWGui int InventoryWindow::getPlayerGold() { - MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + MWWorld::InventoryStore& invStore = MWWorld::Class::get(mContainer).getInventoryStore(mContainer); for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it) diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 3570ea6a3..60cc06cb8 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -268,7 +268,7 @@ namespace MWGui return items; } - MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + MWWorld::InventoryStore& invStore = MWWorld::Class::get(mContainer).getInventoryStore(mContainer); for (int slot=0; slot < MWWorld::InventoryStore::Slots; ++slot) { @@ -327,7 +327,7 @@ namespace MWGui std::vector TradeWindow::itemsToIgnore() { std::vector items; - MWWorld::InventoryStore& invStore = static_cast(MWWorld::Class::get(mContainer).getContainerStore(mContainer)); + MWWorld::ContainerStore& invStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer); for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it) From 92d9e070fb6e2cc634f9cde03b807544457a8b37 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 19 May 2012 16:10:13 +0200 Subject: [PATCH 107/118] small tweak to getPlayerGold() method --- apps/openmw/mwgui/inventorywindow.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 49b441af3..59be6a495 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -21,6 +21,19 @@ #include "bookwindow.hpp" #include "scrollwindow.hpp" +namespace +{ + std::string toLower (const std::string& name) + { + std::string lowerCase; + + std::transform (name.begin(), name.end(), std::back_inserter (lowerCase), + (int(*)(int)) std::tolower); + + return lowerCase; + } +} + namespace MWGui { @@ -236,7 +249,7 @@ namespace MWGui for (MWWorld::ContainerStoreIterator it = invStore.begin(); it != invStore.end(); ++it) { - if (MWWorld::Class::get(*it).getName(*it) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + if (toLower(it->getCellRef().refID) == "gold_001") return it->getRefData().getCount(); } return 0; From 876b369ca544d8a3321fe6448329e3c089e5b6c7 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 19 May 2012 16:28:10 +0200 Subject: [PATCH 108/118] minor tooltip fix --- apps/openmw/mwgui/tooltips.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 6f8434535..e986b59be 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -298,6 +298,9 @@ IntSize ToolTips::createToolTip(const MWGui::ToolTipInfo& info) const int chargeTextWidth = chargeText->getTextSize().width + 5; const int chargeAndTextWidth = chargeWidth + chargeTextWidth; + + totalSize.width = std::max(totalSize.width, chargeAndTextWidth); + chargeText->setCoord((totalSize.width - chargeAndTextWidth)/2, coord.top+6, chargeTextWidth, 18); IntCoord chargeCoord; From 8d52ee27dcaa8b70841eaa0f127d97afb031b565 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 20 May 2012 22:06:54 +0200 Subject: [PATCH 109/118] attribute tooltips now use a new system that allows complex tooltips to be defined entirely through layout files --- apps/openmw/mwgui/stats_window.cpp | 146 ++++++++++++++++------------- apps/openmw/mwgui/tooltips.cpp | 64 +++++++++++-- files/mygui/openmw_tooltips.xml | 20 ++++ 3 files changed, 160 insertions(+), 70 deletions(-) diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 06576b42b..480b85265 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -459,91 +459,109 @@ void StatsWindow::setupToolTips() const ESMS::ESMStore &store = mWindowManager.getStore(); MyGUI::Widget* widget; + /// \todo move this into the .layout file! + 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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeStrength")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sStrDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeStrength")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sStrDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeIntelligence")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sIntDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeIntelligence")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sIntDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeWillpower")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sWilDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeWillpower")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sWilDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeAgility")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sAgiDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeAgility")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sAgiDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeSpeed")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sSpdDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeSpeed")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sSpdDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeEndurance")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sEndDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeEndurance")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sEndDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributePersonality")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sPerDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributePersonality")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sPerDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeLuck")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sLucDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\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"); + widget->setUserString("ToolTipType", "Layout"); + widget->setUserString("ToolTipLayout", "AttributeToolTip"); + widget->setUserString("Caption_AttributeName", store.gameSettings.find ("sAttributeLuck")->str); + widget->setUserString("Caption_AttributeDescription", store.gameSettings.find ("sLucDesc")->str); + widget->setUserString("ImageTexture_AttributeImage", "icons\\k\\attribute_luck.dds"); } diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index e986b59be..edb93320d 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -42,11 +42,16 @@ void ToolTips::onFrame(float frameDuration) IntCoord(0, 0, mMainWidget->getCoord().width, mMainWidget->getCoord().height), Align::Stretch, "DynamicToolTipBox"); + // start by hiding everything + for (unsigned int i=0; i < mMainWidget->getChildCount(); ++i) + { + mMainWidget->getChildAt(i)->setVisible(false); + } + const IntSize &viewSize = RenderManager::getInstance().getViewSize(); if (!mEnabled) { - mDynamicToolTipBox->setVisible(false); return; } @@ -55,7 +60,6 @@ void ToolTips::onFrame(float frameDuration) Widget* focus = InputManager::getInstance().getMouseFocusWidget(); if (focus == 0) { - mDynamicToolTipBox->setVisible(false); return; } @@ -67,7 +71,6 @@ void ToolTips::onFrame(float frameDuration) ToolTipInfo info; if (type == "") { - mDynamicToolTipBox->setVisible(false); return; } else if (type == "Text") @@ -98,6 +101,54 @@ void ToolTips::onFrame(float frameDuration) mFocusObject = *focus->getUserData(); tooltipSize = getToolTipViaPtr(false); } + else if (type == "Layout") + { + // tooltip defined in the layout + MyGUI::Widget* tooltip; + getWidget(tooltip, focus->getUserString("ToolTipLayout")); + + tooltip->setVisible(true); + tooltip->setCoord(0, 0, 300, 300); + + tooltipSize = MyGUI::IntSize(0,0); + + std::map userStrings = focus->getUserStrings(); + for (std::map::iterator it = userStrings.begin(); + it != userStrings.end(); ++it) + { + if (it->first == "ToolTipType" + || it->first == "ToolTipLayout") + continue; + + + size_t underscorePos = it->first.find("_"); + std::string propertyKey = it->first.substr(0, underscorePos); + std::string widgetName = it->first.substr(underscorePos+1, it->first.size()-(underscorePos+1)); + + MyGUI::Widget* w; + getWidget(w, widgetName); + w->setProperty(propertyKey, it->second); + } + + for (unsigned int i=0; igetChildCount(); ++i) + { + MyGUI::Widget* w = tooltip->getChildAt(i); + + if (w->isUserString("AutoResizeHorizontal")) + { + MyGUI::TextBox* text = w->castType(); + tooltipSize.width = std::max(tooltipSize.width, w->getLeft() + text->getTextSize().width + 8); + } + + if (w->isUserString("AutoResizeVertical")) + { + MyGUI::TextBox* text = w->castType(); + tooltipSize.height = std::max(tooltipSize.height, w->getTop() + text->getTextSize().height + 8); + } + } + + tooltip->setCoord(0, 0, tooltipSize.width, tooltipSize.height); + } IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24); @@ -112,7 +163,6 @@ void ToolTips::onFrame(float frameDuration) } setCoord(tooltipPosition.left, tooltipPosition.top, tooltipSize.width, tooltipSize.height); - mDynamicToolTipBox->setVisible(true); } else { @@ -124,9 +174,9 @@ void ToolTips::onFrame(float frameDuration) std::max(0, int(mFocusToolTipY*viewSize.height - tooltipSize.height)), tooltipSize.width, tooltipSize.height); + + mDynamicToolTipBox->setVisible(true); } - else - mDynamicToolTipBox->setVisible(false); } } @@ -186,6 +236,8 @@ void ToolTips::findImageExtension(std::string& image) IntSize ToolTips::createToolTip(const MWGui::ToolTipInfo& info) { + mDynamicToolTipBox->setVisible(true); + std::string caption = info.caption; std::string image = info.icon; int imageSize = (image != "") ? 32 : 0; diff --git a/files/mygui/openmw_tooltips.xml b/files/mygui/openmw_tooltips.xml index 2d5a5da9f..3c6c98ea9 100644 --- a/files/mygui/openmw_tooltips.xml +++ b/files/mygui/openmw_tooltips.xml @@ -8,6 +8,26 @@ + + + + + + + + + + + + + + + + + + + + From 1c7110fbf5022a7f3025866c51ebc91a1957105b Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 20 May 2012 22:45:30 +0200 Subject: [PATCH 110/118] birthsign tooltip --- apps/openmw/mwgui/stats_window.cpp | 61 +++++++++++++++++++++++++++++- apps/openmw/mwgui/stats_window.hpp | 2 +- apps/openmw/mwgui/tooltips.cpp | 4 ++ files/mygui/openmw_text.skin.xml | 3 ++ files/mygui/openmw_tooltips.xml | 18 +++++++++ 5 files changed, 85 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 480b85265..092ceaeb6 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -322,7 +322,7 @@ MyGUI::TextBox* StatsWindow::addValueItem(const std::string& text, const std::st return skillValueWidget; } -void StatsWindow::addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) +MyGUI::Widget* StatsWindow::addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { MyGUI::TextBox* skillNameWidget; @@ -334,6 +334,8 @@ void StatsWindow::addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI coord1.top += lineHeight; coord2.top += lineHeight; + + return skillNameWidget; } void StatsWindow::addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) @@ -422,7 +424,62 @@ void StatsWindow::updateSkillArea() addGroup(mWindowManager.getGameSettingString("sBirthSign", "Sign"), coord1, coord2); const ESM::BirthSign *sign = store.birthSigns.find(birthSignId); - addItem(sign->name, coord1, coord2); + MyGUI::Widget* w = addItem(sign->name, coord1, coord2); + w->setUserString("ToolTipType", "Layout"); + w->setUserString("ToolTipLayout", "BirthSignToolTip"); + std::string image = sign->texture; + image.replace(image.size()-3, 3, "dds"); + w->setUserString("ImageTexture_BirthSignImage", "textures\\" + image); + std::string text; + + text += sign->name; + text += "\n#BF9959" + sign->description; + + std::vector abilities, powers, spells; + + std::vector::const_iterator it = sign->powers.list.begin(); + std::vector::const_iterator end = sign->powers.list.end(); + for (; it != end; ++it) + { + const std::string &spellId = *it; + const ESM::Spell *spell = store.spells.search(spellId); + if (!spell) + continue; // Skip spells which cannot be found + ESM::Spell::SpellType type = static_cast(spell->data.type); + if (type != ESM::Spell::ST_Spell && type != ESM::Spell::ST_Ability && type != ESM::Spell::ST_Power) + continue; // We only want spell, ability and powers. + + if (type == ESM::Spell::ST_Ability) + abilities.push_back(spellId); + else if (type == ESM::Spell::ST_Power) + powers.push_back(spellId); + else if (type == ESM::Spell::ST_Spell) + spells.push_back(spellId); + } + + struct{ const std::vector &spells; std::string label; } categories[3] = { + {abilities, "sBirthsignmenu1"}, + {powers, "sPowers"}, + {spells, "sBirthsignmenu2"} + }; + + for (int category = 0; category < 3; ++category) + { + for (std::vector::const_iterator it = categories[category].spells.begin(); it != categories[category].spells.end(); ++it) + { + if (it == categories[category].spells.begin()) + { + text += std::string("\n#DDC79E") + std::string("#{") + categories[category].label + "}"; + } + + const std::string &spellId = *it; + + const ESM::Spell *spell = store.spells.search(spellId); + text += "\n#BF9959" + spell->name; + } + } + + w->setUserString("Caption_BirthSignText", text); } // Add a line separator if there are items above diff --git a/apps/openmw/mwgui/stats_window.hpp b/apps/openmw/mwgui/stats_window.hpp index 677b32935..fe7be0459 100644 --- a/apps/openmw/mwgui/stats_window.hpp +++ b/apps/openmw/mwgui/stats_window.hpp @@ -47,7 +47,7 @@ namespace MWGui 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, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); - void addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); + MyGUI::Widget* addItem(const std::string text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void updateScroller(); void setupToolTips(); diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index edb93320d..47907ec94 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -139,12 +139,16 @@ void ToolTips::onFrame(float frameDuration) MyGUI::TextBox* text = w->castType(); tooltipSize.width = std::max(tooltipSize.width, w->getLeft() + text->getTextSize().width + 8); } + else + tooltipSize.width = std::max(tooltipSize.width, w->getLeft() + w->getWidth() + 8); if (w->isUserString("AutoResizeVertical")) { MyGUI::TextBox* text = w->castType(); tooltipSize.height = std::max(tooltipSize.height, w->getTop() + text->getTextSize().height + 8); } + else + tooltipSize.height = std::max(tooltipSize.height, w->getTop() + w->getHeight() + 8); } tooltip->setCoord(0, 0, tooltipSize.width, tooltipSize.height); diff --git a/files/mygui/openmw_text.skin.xml b/files/mygui/openmw_text.skin.xml index 36d97e153..6b62f618d 100644 --- a/files/mygui/openmw_text.skin.xml +++ b/files/mygui/openmw_text.skin.xml @@ -1,6 +1,8 @@ + + @@ -15,6 +17,7 @@ + diff --git a/files/mygui/openmw_tooltips.xml b/files/mygui/openmw_tooltips.xml index 3c6c98ea9..1913095a8 100644 --- a/files/mygui/openmw_tooltips.xml +++ b/files/mygui/openmw_tooltips.xml @@ -28,6 +28,24 @@ + + + + + + + + + + + + + + + + + + From 6518eb7794a6e4a7bbe0291c9780e81e0a5b97f2 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 20 May 2012 22:55:14 +0200 Subject: [PATCH 111/118] some cleanup --- apps/openmw/mwgui/stats_window.cpp | 10 ++++++---- apps/openmw/mwgui/tooltips.cpp | 25 ++----------------------- files/mygui/openmw_tooltips.xml | 13 +++++++++++++ 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 092ceaeb6..33d9f02c8 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -302,13 +302,15 @@ MyGUI::TextBox* StatsWindow::addValueItem(const std::string& text, const std::st skillNameWidget = skillClientWidget->createWidget("SandText", coord1, MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); skillNameWidget->setCaption(text); - skillNameWidget->setUserString("ToolTipType", "Text"); - skillNameWidget->setUserString("ToolTipText", tooltip); + skillNameWidget->setUserString("ToolTipType", "Layout"); + skillNameWidget->setUserString("ToolTipLayout", "TextToolTip"); + skillNameWidget->setUserString("Caption_Text", tooltip); skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); skillValueWidget = skillClientWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Right | MyGUI::Align::Top); - skillValueWidget->setUserString("ToolTipType", "Text"); - skillValueWidget->setUserString("ToolTipText", tooltip); + skillNameWidget->setUserString("ToolTipType", "Layout"); + skillNameWidget->setUserString("ToolTipLayout", "TextToolTip"); + skillNameWidget->setUserString("Caption_Text", tooltip); skillValueWidget->setCaption(value); skillValueWidget->_setWidgetState(state); skillValueWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 47907ec94..df06bd93e 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -72,29 +72,6 @@ void ToolTips::onFrame(float frameDuration) if (type == "") { return; - } - else if (type == "Text") - { - info.text = text; - tooltipSize = createToolTip(info); - } - else if (type == "CaptionText") - { - std::string caption = focus->getUserString("ToolTipCaption"); - info.caption = caption; - info.text = text; - tooltipSize = createToolTip(info); - } - else if (type == "ImageCaptionText") - { - std::string caption = focus->getUserString("ToolTipCaption"); - std::string image = focus->getUserString("ToolTipImage"); - std::string sizeString = focus->getUserString("ToolTipImageSize"); - - info.text = text; - info.caption = caption; - info.icon = image; - tooltipSize = createToolTip(info); } else if (type == "ItemPtr") { @@ -153,6 +130,8 @@ void ToolTips::onFrame(float frameDuration) tooltip->setCoord(0, 0, tooltipSize.width, tooltipSize.height); } + else + throw std::runtime_error ("unknown tooltip type"); IntPoint tooltipPosition = InputManager::getInstance().getMousePosition() + IntPoint(0, 24); diff --git a/files/mygui/openmw_tooltips.xml b/files/mygui/openmw_tooltips.xml index 1913095a8..414991664 100644 --- a/files/mygui/openmw_tooltips.xml +++ b/files/mygui/openmw_tooltips.xml @@ -8,6 +8,19 @@ + + + + + + + + + + + + + From 8ce472742485c586a04635714bf4205741fdd6cf Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 21 May 2012 01:58:11 +0200 Subject: [PATCH 112/118] skill tooltips --- apps/openmw/mwgui/stats_window.cpp | 48 +++++++++++++++++++++++------- apps/openmw/mwgui/stats_window.hpp | 2 +- apps/openmw/mwgui/tooltips.cpp | 14 ++++++--- components/esm/loadskil.cpp | 29 ++++++++++++++++++ components/esm/loadskil.hpp | 1 + files/mygui/openmw_tooltips.xml | 37 +++++++++++++++++++++++ 6 files changed, 116 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 33d9f02c8..fbc439b23 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -296,21 +296,15 @@ 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, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) +MyGUI::TextBox* StatsWindow::addValueItem(const std::string& text, const std::string &value, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { MyGUI::TextBox *skillNameWidget, *skillValueWidget; skillNameWidget = skillClientWidget->createWidget("SandText", coord1, MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); skillNameWidget->setCaption(text); - skillNameWidget->setUserString("ToolTipType", "Layout"); - skillNameWidget->setUserString("ToolTipLayout", "TextToolTip"); - skillNameWidget->setUserString("Caption_Text", tooltip); skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); skillValueWidget = skillClientWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Right | MyGUI::Align::Top); - skillNameWidget->setUserString("ToolTipType", "Layout"); - skillNameWidget->setUserString("ToolTipLayout", "TextToolTip"); - skillNameWidget->setUserString("Caption_Text", tooltip); skillValueWidget->setCaption(value); skillValueWidget->_setWidgetState(state); skillValueWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); @@ -362,13 +356,34 @@ void StatsWindow::addSkills(const SkillList &skills, const std::string &titleId, float base = stat.getBase(); float modified = stat.getModified(); + const ESM::Skill* skill = mWindowManager.getStore().skills.search(skillId); + assert(skill); + + std::string icon = "icons\\k\\" + ESM::Skill::sIconNames[skillId]; + + const ESM::Attribute* attr = mWindowManager.getStore().attributes.search(skill->data.attribute); + assert(attr); + std::string state = "normal"; if (modified > base) state = "increased"; else if (modified < base) state = "decreased"; - MyGUI::TextBox* widget = addValueItem(mWindowManager.getGameSettingString(skillNameId, skillNameId), "", + MyGUI::TextBox* widget = addValueItem(mWindowManager.getGameSettingString(skillNameId, skillNameId), boost::lexical_cast(static_cast(modified)), state, coord1, coord2); + + for (int i=0; i<2; ++i) + { + skillWidgets[skillWidgets.size()-1-i]->setUserString("ToolTipType", "Layout"); + skillWidgets[skillWidgets.size()-1-i]->setUserString("ToolTipLayout", "SkillToolTip"); + skillWidgets[skillWidgets.size()-1-i]->setUserString("Caption_SkillName", "#{"+skillNameId+"}"); + skillWidgets[skillWidgets.size()-1-i]->setUserString("Caption_SkillDescription", skill->description); + skillWidgets[skillWidgets.size()-1-i]->setUserString("Caption_SkillAttribute", "#{sGoverningAttribute}: #{" + attr->name + "}"); + skillWidgets[skillWidgets.size()-1-i]->setUserString("ImageTexture_SkillImage", icon); + skillWidgets[skillWidgets.size()-1-i]->setUserString("Caption_SkillProgressText", "0/100"); + skillWidgets[skillWidgets.size()-1-i]->setUserString("Range_SkillProgress", "100"); + } + skillWidgetMap[skillId] = widget; } } @@ -489,12 +504,25 @@ void StatsWindow::updateSkillArea() addSeparator(coord1, coord2); addValueItem(mWindowManager.getGameSettingString("sReputation", "Reputation"), - mWindowManager.getGameSettingString("sSkillsMenuReputationHelp", ""), boost::lexical_cast(static_cast(reputation)), "normal", coord1, coord2); + + for (int i=0; i<2; ++i) + { + skillWidgets[skillWidgets.size()-1-i]->setUserString("ToolTipType", "Layout"); + skillWidgets[skillWidgets.size()-1-i]->setUserString("ToolTipLayout", "TextToolTip"); + skillWidgets[skillWidgets.size()-1-i]->setUserString("Caption_Text", "#{sSkillsMenuReputationHelp}"); + } + addValueItem(mWindowManager.getGameSettingString("sBounty", "Bounty"), - mWindowManager.getGameSettingString("sCrimeHelp", ""), boost::lexical_cast(static_cast(bounty)), "normal", coord1, coord2); + for (int i=0; i<2; ++i) + { + skillWidgets[skillWidgets.size()-1-i]->setUserString("ToolTipType", "Layout"); + skillWidgets[skillWidgets.size()-1-i]->setUserString("ToolTipLayout", "TextToolTip"); + skillWidgets[skillWidgets.size()-1-i]->setUserString("Caption_Text", "#{sCrimeHelp}"); + } + clientHeight = coord1.top; updateScroller(); } diff --git a/apps/openmw/mwgui/stats_window.hpp b/apps/openmw/mwgui/stats_window.hpp index fe7be0459..50a83bb29 100644 --- a/apps/openmw/mwgui/stats_window.hpp +++ b/apps/openmw/mwgui/stats_window.hpp @@ -46,7 +46,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, const std::string& state, 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); MyGUI::Widget* 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 df06bd93e..52ba391a6 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -87,7 +87,7 @@ void ToolTips::onFrame(float frameDuration) tooltip->setVisible(true); tooltip->setCoord(0, 0, 300, 300); - tooltipSize = MyGUI::IntSize(0,0); + tooltipSize = MyGUI::IntSize(0, tooltip->getSize().height); std::map userStrings = focus->getUserStrings(); for (std::map::iterator it = userStrings.begin(); @@ -122,10 +122,16 @@ void ToolTips::onFrame(float frameDuration) if (w->isUserString("AutoResizeVertical")) { MyGUI::TextBox* text = w->castType(); - tooltipSize.height = std::max(tooltipSize.height, w->getTop() + text->getTextSize().height + 8); + int height = text->getTextSize().height; + if (height > w->getHeight()) + { + tooltipSize += MyGUI::IntSize(0, height - w->getHeight()); + } + if (height < w->getHeight()) + { + tooltipSize -= MyGUI::IntSize(0, w->getHeight() - height); + } } - else - tooltipSize.height = std::max(tooltipSize.height, w->getTop() + w->getHeight() + 8); } tooltip->setCoord(0, 0, tooltipSize.width, tooltipSize.height); diff --git a/components/esm/loadskil.cpp b/components/esm/loadskil.cpp index aa7103efc..52869f440 100644 --- a/components/esm/loadskil.cpp +++ b/components/esm/loadskil.cpp @@ -31,6 +31,35 @@ namespace ESM "sSkillSpeechcraft", "sSkillHandtohand", }; + const std::string Skill::sIconNames[Length] = { + "combat_block.dds", + "combat_armor.dds", + "combat_mediumarmor.dds", + "combat_heavyarmor.dds", + "combat_blunt.dds", + "combat_longblade.dds", + "combat_axe.dds", + "combat_spear.dds", + "combat_athletics.dds", + "magic_enchant.dds", + "magic_destruction.dds", + "magic_alteration.dds", + "magic_illusion.dds", + "magic_conjuration.dds", + "magic_mysticism.dds", + "magic_restoration.dds", + "magic_alchemy.dds", + "magic_unarmored.dds", + "stealth_security.dds", + "stealth_sneak.dds", + "stealth_acrobatics.dds", + "stealth_lightarmor.dds", + "stealth_shortblade.dds", + "stealth_marksman.dds", + "stealth_mercantile.dds", + "stealth_speechcraft.dds", + "stealth_handtohand.dds", + }; const boost::array Skill::skillIds = {{ Block, Armorer, diff --git a/components/esm/loadskil.hpp b/components/esm/loadskil.hpp index 836f70205..f56ec2fcb 100644 --- a/components/esm/loadskil.hpp +++ b/components/esm/loadskil.hpp @@ -64,6 +64,7 @@ struct Skill Length }; static const std::string sSkillNameIds[Length]; + static const std::string sIconNames[Length]; static const boost::array skillIds; void load(ESMReader &esm); diff --git a/files/mygui/openmw_tooltips.xml b/files/mygui/openmw_tooltips.xml index 414991664..af4d26775 100644 --- a/files/mygui/openmw_tooltips.xml +++ b/files/mygui/openmw_tooltips.xml @@ -41,6 +41,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 4a009fc2bbe625b33de6c9635a831163afc3aa8a Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 21 May 2012 02:58:06 +0200 Subject: [PATCH 113/118] faction tooltip (doesn't handle player having max. rank) --- apps/openmw/mwgui/stats_window.cpp | 44 ++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index fbc439b23..de12559ca 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -428,8 +428,48 @@ void StatsWindow::updateSkillArea() for (FactionList::const_iterator it = mFactions.begin(); it != end; ++it) { const ESM::Faction *faction = store.factions.find(it->first); - addItem(faction->name, coord1, coord2); - // TODO: Faction rank should be placed in tooltip + MyGUI::Widget* w = addItem(faction->name, coord1, coord2); + + std::string text; + + text += std::string("#DDC79E") + faction->name; + text += std::string("\n#BF9959") + faction->ranks[it->second]; + + if (it->second < 10) + { + // player doesn't have max rank yet + text += std::string("\n\n#DDC79E#{sNextRank} ") + faction->ranks[it->second+1]; + + ESM::RankData rankData = faction->data.rankData[it->second+1]; + const ESM::Attribute* attr1 = mWindowManager.getStore().attributes.search(faction->data.attribute1); + const ESM::Attribute* attr2 = mWindowManager.getStore().attributes.search(faction->data.attribute2); + assert(attr1 && attr2); + + text += "\n#BF9959#{" + attr1->name + "}: " + boost::lexical_cast(rankData.attribute1) + + ", #{" + attr2->name + "}: " + boost::lexical_cast(rankData.attribute2); + + text += "\n\n#DDC79E#{sFavoriteSkills}"; + text += "\n#BF9959"; + for (int i=0; i<6; ++i) + { + const ESM::Skill* skill = mWindowManager.getStore().skills.search(faction->data.skillID[i]); + assert(skill); + text += "#{"+ESM::Skill::sSkillNameIds[faction->data.skillID[i]]+"}"; + if (i<5) + text += ", "; + } + + text += "\n"; + + if (rankData.skill1 > 0) + text += "\n#{sNeedOneSkill} " + boost::lexical_cast(rankData.skill1); + if (rankData.skill2 > 0) + text += "\n#{sNeedTwoSkills} " + boost::lexical_cast(rankData.skill2); + } + + w->setUserString("ToolTipType", "Layout"); + w->setUserString("ToolTipLayout", "TextToolTip"); + w->setUserString("Caption_Text", text); } } From 76d71f86bcab17a547c8515d7b40acb7b2a0f43a Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 21 May 2012 03:10:55 +0200 Subject: [PATCH 114/118] fixed a faction case folding issue --- apps/openmw/mwclass/npc.cpp | 8 ++++++-- apps/openmw/mwdialogue/dialoguemanager.cpp | 6 +++--- apps/openmw/mwmechanics/npcstats.hpp | 1 + apps/openmw/mwscript/statsextensions.cpp | 6 ++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index db0a6460c..e7f6cc527 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -3,6 +3,8 @@ #include +#include + #include #include @@ -56,13 +58,15 @@ namespace MWClass // NPC stats if (!ref->base->faction.empty()) { + std::string faction = ref->base->faction; + boost::algorithm::to_lower(faction); if(ref->base->npdt52.gold != -10) { - data->mNpcStats.mFactionRank[ref->base->faction] = (int)ref->base->npdt52.rank; + data->mNpcStats.mFactionRank[faction] = (int)ref->base->npdt52.rank; } else { - data->mNpcStats.mFactionRank[ref->base->faction] = (int)ref->base->npdt12.rank; + data->mNpcStats.mFactionRank[faction] = (int)ref->base->npdt12.rank; } } diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 2c4de7be1..dbd826127 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -206,7 +206,7 @@ namespace MWDialogue if(!NPCstats.mFactionRank.empty()) { std::string NPCFaction = NPCstats.mFactionRank.begin()->first; - if(PCstats.mFactionRank.find(NPCFaction) != PCstats.mFactionRank.end()) sameFaction = 1; + if(PCstats.mFactionRank.find(toLower(NPCFaction)) != PCstats.mFactionRank.end()) sameFaction = 1; } if(!selectCompare(comp,sameFaction,select.i)) return false; } @@ -525,7 +525,7 @@ namespace MWDialogue //MWWorld::Class npcClass = MWWorld::Class::get(actor); MWMechanics::NpcStats stats = MWWorld::Class::get(actor).getNpcStats(actor); - std::map::iterator it = stats.mFactionRank.find(info.npcFaction); + std::map::iterator it = stats.mFactionRank.find(toLower(info.npcFaction)); if(it!=stats.mFactionRank.end()) { //check rank @@ -542,7 +542,7 @@ namespace MWDialogue if(!info.pcFaction.empty()) { MWMechanics::NpcStats stats = MWWorld::Class::get(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()).getNpcStats(MWBase::Environment::get().getWorld()->getPlayer().getPlayer()); - std::map::iterator it = stats.mFactionRank.find(info.pcFaction); + std::map::iterator it = stats.mFactionRank.find(toLower(info.pcFaction)); if(it!=stats.mFactionRank.end()) { //check rank diff --git a/apps/openmw/mwmechanics/npcstats.hpp b/apps/openmw/mwmechanics/npcstats.hpp index feac5d4d3..972863b72 100644 --- a/apps/openmw/mwmechanics/npcstats.hpp +++ b/apps/openmw/mwmechanics/npcstats.hpp @@ -20,6 +20,7 @@ namespace MWMechanics { // NPCs other than the player can only have one faction. But for the sake of consistency // we use the same data structure for the PC and the NPCs. + /// \note the faction key must be in lowercase std::map mFactionRank; Stat mSkill[27]; diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index cad52e593..d23519281 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -1,6 +1,8 @@ #include "statsextensions.hpp" +#include + #include #include @@ -362,6 +364,7 @@ namespace MWScript factionID = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); } + boost::algorithm::to_lower(factionID); if(factionID != "") { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); @@ -390,6 +393,7 @@ namespace MWScript factionID = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); } + boost::algorithm::to_lower(factionID); if(factionID != "") { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); @@ -422,6 +426,7 @@ namespace MWScript factionID = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); } + boost::algorithm::to_lower(factionID); if(factionID != "") { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); @@ -459,6 +464,7 @@ namespace MWScript factionID = MWWorld::Class::get(ptr).getNpcStats(ptr).mFactionRank.begin()->first; } } + boost::algorithm::to_lower(factionID); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); if(factionID!="") { From 1079bb26778afcf454b7aa0f01e0edee6574e53b Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 21 May 2012 05:14:07 +0200 Subject: [PATCH 115/118] finished tooltips for everything in the stats window, some gui refactoring --- apps/openmw/mwgui/hud.cpp | 18 ++--- apps/openmw/mwgui/hud.hpp | 1 - apps/openmw/mwgui/stats_window.cpp | 52 +++++++++++++ apps/openmw/mwgui/tooltips.cpp | 12 ++- files/mygui/openmw_hud_layout.xml | 30 ++++++-- files/mygui/openmw_stats_window_layout.xml | 88 ++++++++++++++++++---- files/mygui/openmw_tooltips.xml | 79 ++++++++++++++++++- 7 files changed, 242 insertions(+), 38 deletions(-) diff --git a/apps/openmw/mwgui/hud.cpp b/apps/openmw/mwgui/hud.cpp index 4a65458df..892bd6c7a 100644 --- a/apps/openmw/mwgui/hud.cpp +++ b/apps/openmw/mwgui/hud.cpp @@ -129,16 +129,6 @@ void HUD::setBatchCount(size_t count) batchcounter->setCaption(boost::lexical_cast(count)); } -void HUD::setStats(int h, int hmax, int m, int mmax, int s, int smax) -{ - health->setProgressRange(hmax); - health->setProgressPosition(h); - magicka->setProgressRange(mmax); - magicka->setProgressPosition(m); - stamina->setProgressRange(smax); - stamina->setProgressPosition(s); -} - void HUD::setWeapIcon(const char *str) { weapImage->setImageTexture(str); @@ -176,19 +166,27 @@ void HUD::setValue(const std::string& id, const MWMechanics::DynamicStat& v for (int i=0; ids[i]; ++i) if (ids[i]==id) { + MyGUI::Widget* w; + std::string valStr = boost::lexical_cast(value.getCurrent()) + "/" + boost::lexical_cast(value.getModified()); switch (i) { case 0: health->setProgressRange (value.getModified()); health->setProgressPosition (value.getCurrent()); + getWidget(w, "HealthFrame"); + w->setUserString("Caption_HealthDescription", "#{sHealthDesc}\n" + valStr); break; case 1: magicka->setProgressRange (value.getModified()); magicka->setProgressPosition (value.getCurrent()); + getWidget(w, "MagickaFrame"); + w->setUserString("Caption_HealthDescription", "#{sIntDesc}\n" + valStr); break; case 2: stamina->setProgressRange (value.getModified()); stamina->setProgressPosition (value.getCurrent()); + getWidget(w, "FatigueFrame"); + w->setUserString("Caption_HealthDescription", "#{sFatDesc}\n" + valStr); break; } } diff --git a/apps/openmw/mwgui/hud.hpp b/apps/openmw/mwgui/hud.hpp index d588113dd..81f64ee50 100644 --- a/apps/openmw/mwgui/hud.hpp +++ b/apps/openmw/mwgui/hud.hpp @@ -12,7 +12,6 @@ namespace MWGui { public: HUD(int width, int height, int fpsLevel, DragAndDrop* dragAndDrop); - void setStats(int h, int hmax, int m, int mmax, int s, int smax); void setWeapIcon(const char *str); void setSpellIcon(const char *str); void setWeapStatus(int s, int smax); diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index de12559ca..eba51c26f 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -172,11 +172,32 @@ void StatsWindow::setValue (const std::string& id, const MWMechanics::DynamicSta }; for (int i=0; ids[i]; ++i) + { if (ids[i]==id) { std::string id (ids[i]); setBar (id, id + "T", value.getCurrent(), value.getModified()); + + // health, magicka, fatigue tooltip + MyGUI::Widget* w; + std::string valStr = boost::lexical_cast(value.getCurrent()) + "/" + boost::lexical_cast(value.getModified()); + if (i==0) + { + getWidget(w, "Health"); + w->setUserString("Caption_HealthDescription", "#{sHealthDesc}\n" + valStr); + } + else if (i==1) + { + getWidget(w, "Magicka"); + w->setUserString("Caption_HealthDescription", "#{sIntDesc}\n" + valStr); + } + else if (i==2) + { + getWidget(w, "Fatigue"); + w->setUserString("Caption_HealthDescription", "#{sFatDesc}\n" + valStr); + } } + } } void StatsWindow::setValue (const std::string& id, const std::string& value) @@ -417,6 +438,37 @@ void StatsWindow::updateSkillArea() const ESMS::ESMStore &store = mWindowManager.getStore(); + // race tooltip + const ESM::Race* playerRace = store.races.find (MWBase::Environment::get().getWorld()->getPlayer().getRace()); + MyGUI::Widget* raceWidget; + getWidget(raceWidget, "RaceText"); + raceWidget->setUserString("Caption_CenteredCaption", playerRace->name); + raceWidget->setUserString("Caption_CenteredCaptionText", playerRace->description); + getWidget(raceWidget, "Race_str"); + raceWidget->setUserString("Caption_CenteredCaption", playerRace->name); + raceWidget->setUserString("Caption_CenteredCaptionText", playerRace->description); + + // class tooltip + MyGUI::Widget* classWidget; + const ESM::Class& playerClass = MWBase::Environment::get().getWorld()->getPlayer().getClass(); + int spec = playerClass.data.specialization; + std::string specStr; + if (spec == 0) + specStr = "#{sSpecializationCombat}"; + else if (spec == 1) + specStr = "#{sSpecializationMagic}"; + else if (spec == 2) + specStr = "#{sSpecializationStealth}"; + + getWidget(classWidget, "ClassText"); + classWidget->setUserString("Caption_ClassName", playerClass.name); + classWidget->setUserString("Caption_ClassDescription", playerClass.description); + classWidget->setUserString("Caption_ClassSpecialisation", "#{sSpecialization}: " + specStr); + getWidget(classWidget, "Class_str"); + classWidget->setUserString("Caption_ClassName", playerClass.name); + classWidget->setUserString("Caption_ClassDescription", playerClass.description); + classWidget->setUserString("Caption_ClassSpecialisation", "#{sSpecialization}: " + specStr); + if (!mFactions.empty()) { // Add a line separator if there are items above diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 52ba391a6..3ade598ba 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -85,9 +85,14 @@ void ToolTips::onFrame(float frameDuration) getWidget(tooltip, focus->getUserString("ToolTipLayout")); tooltip->setVisible(true); - tooltip->setCoord(0, 0, 300, 300); + if (!tooltip->isUserString("DontResize")) + { + tooltip->setCoord(0, 0, 450, 300); // this is the maximum width of the tooltip before it starts word-wrapping - tooltipSize = MyGUI::IntSize(0, tooltip->getSize().height); + tooltipSize = MyGUI::IntSize(0, tooltip->getSize().height); + } + else + tooltipSize = tooltip->getSize(); std::map userStrings = focus->getUserStrings(); for (std::map::iterator it = userStrings.begin(); @@ -116,7 +121,7 @@ void ToolTips::onFrame(float frameDuration) MyGUI::TextBox* text = w->castType(); tooltipSize.width = std::max(tooltipSize.width, w->getLeft() + text->getTextSize().width + 8); } - else + else if (!tooltip->isUserString("DontResize")) tooltipSize.width = std::max(tooltipSize.width, w->getLeft() + w->getWidth() + 8); if (w->isUserString("AutoResizeVertical")) @@ -133,7 +138,6 @@ void ToolTips::onFrame(float frameDuration) } } } - tooltip->setCoord(0, 0, tooltipSize.width, tooltipSize.height); } else diff --git a/files/mygui/openmw_hud_layout.xml b/files/mygui/openmw_hud_layout.xml index 0c5ffba6a..0aabc3e3e 100644 --- a/files/mygui/openmw_hud_layout.xml +++ b/files/mygui/openmw_hud_layout.xml @@ -3,12 +3,30 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/files/mygui/openmw_stats_window_layout.xml b/files/mygui/openmw_stats_window_layout.xml index 8b6080227..4729e3bca 100644 --- a/files/mygui/openmw_stats_window_layout.xml +++ b/files/mygui/openmw_stats_window_layout.xml @@ -7,37 +7,95 @@ - - + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + - - - diff --git a/files/mygui/openmw_tooltips.xml b/files/mygui/openmw_tooltips.xml index af4d26775..a1673d346 100644 --- a/files/mygui/openmw_tooltips.xml +++ b/files/mygui/openmw_tooltips.xml @@ -21,6 +21,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -78,6 +134,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -88,8 +165,6 @@ - - From 40c52c5d09eb9e16c2bdc371e4bfb26ac8a91793 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 21 May 2012 05:19:20 +0200 Subject: [PATCH 116/118] max faction rank crashfix --- apps/openmw/mwgui/stats_window.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index eba51c26f..1dd82cf6a 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -487,7 +487,7 @@ void StatsWindow::updateSkillArea() text += std::string("#DDC79E") + faction->name; text += std::string("\n#BF9959") + faction->ranks[it->second]; - if (it->second < 10) + if (it->second < 9) { // player doesn't have max rank yet text += std::string("\n\n#DDC79E#{sNextRank} ") + faction->ranks[it->second+1]; From b2d207130d88d17f4b944b44c9e9609092bcf778 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 21 May 2012 08:14:22 +0200 Subject: [PATCH 117/118] vastly improved look of the GUI, skin background textures now use tiling instead of stretching --- files/mygui/openmw_box.skin.xml | 32 ++++++++--- files/mygui/openmw_button.skin.xml | 32 ++++++++--- files/mygui/openmw_hud_box.skin.xml | 36 ++++++++++--- files/mygui/openmw_list.skin.xml | 25 +++++++-- files/mygui/openmw_windows.skin.xml | 82 ++++++++++++++++++++--------- 5 files changed, 156 insertions(+), 51 deletions(-) diff --git a/files/mygui/openmw_box.skin.xml b/files/mygui/openmw_box.skin.xml index c1952794c..2a54edd60 100644 --- a/files/mygui/openmw_box.skin.xml +++ b/files/mygui/openmw_box.skin.xml @@ -6,23 +6,39 @@ as around the sections of the stats window, or around popup info windows --> - - + + + + + + - - + + + + + + - - + + + + + + - - + + + + + + diff --git a/files/mygui/openmw_button.skin.xml b/files/mygui/openmw_button.skin.xml index 9efcf776f..491b3f47b 100644 --- a/files/mygui/openmw_button.skin.xml +++ b/files/mygui/openmw_button.skin.xml @@ -3,23 +3,39 @@ - - + + + + + + - - + + + + + + - - + + + + + + - - + + + + + + diff --git a/files/mygui/openmw_hud_box.skin.xml b/files/mygui/openmw_hud_box.skin.xml index bf1b0056a..86b63fcf6 100644 --- a/files/mygui/openmw_hud_box.skin.xml +++ b/files/mygui/openmw_hud_box.skin.xml @@ -3,18 +3,38 @@ - - + + + + + + - - + + + + + + + - - + + + + + + + - - + + + + + + + + diff --git a/files/mygui/openmw_list.skin.xml b/files/mygui/openmw_list.skin.xml index 213e8470f..e1fbc49b6 100644 --- a/files/mygui/openmw_list.skin.xml +++ b/files/mygui/openmw_list.skin.xml @@ -6,13 +6,32 @@ - - + + + + + + + + + + + + + + + + + + + + + @@ -144,7 +163,7 @@ - + diff --git a/files/mygui/openmw_windows.skin.xml b/files/mygui/openmw_windows.skin.xml index 7c194ea5d..b379f84ce 100644 --- a/files/mygui/openmw_windows.skin.xml +++ b/files/mygui/openmw_windows.skin.xml @@ -17,14 +17,22 @@ - - + + + + + + - - + + + + + + @@ -66,29 +74,45 @@ - - + + + + + + - - + + + + + + - - + + + + + + - - + + + + + + @@ -120,20 +144,32 @@ - - + + + + + + - - + + + + + + - - + + + + + + @@ -171,12 +207,8 @@ - - - - - - + + @@ -218,6 +250,7 @@ + @@ -294,6 +327,7 @@ + From 789dfe1c8865e24f1b398735521f3d48e83e0631 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 21 May 2012 09:50:02 +0200 Subject: [PATCH 118/118] fix a bug with water reflection plane height --- apps/openmw/mwrender/water.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwrender/water.cpp b/apps/openmw/mwrender/water.cpp index c81f23f54..840b94e41 100644 --- a/apps/openmw/mwrender/water.cpp +++ b/apps/openmw/mwrender/water.cpp @@ -155,10 +155,10 @@ void Water::changeCell(const ESM::Cell* cell) { mTop = cell->water; + setHeight(mTop); + if(!(cell->data.flags & cell->Interior)) mWaterNode->setPosition(getSceneNodeCoordinates(cell->data.gridX, cell->data.gridY)); - else - setHeight(mTop); } void Water::setHeight(const float height)