From 088d01d7275fbf5735ae08d931a90e9782a5e774 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 24 Sep 2014 23:50:28 +0200 Subject: [PATCH 01/15] Minor cleanup --- apps/openmw/mwgui/class.cpp | 12 ------------ files/mygui/openmw_chargen_select_attribute.layout | 4 ++-- files/mygui/openmw_chargen_select_skill.layout | 10 +++++----- .../openmw_chargen_select_specialization.layout | 4 ++-- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwgui/class.cpp b/apps/openmw/mwgui/class.cpp index b661f9945..b4308858a 100644 --- a/apps/openmw/mwgui/class.cpp +++ b/apps/openmw/mwgui/class.cpp @@ -671,8 +671,6 @@ namespace MWGui // Centre dialog center(); - setText("LabelT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sSpecializationMenu1", "")); - getWidget(mSpecialization0, "Specialization0"); getWidget(mSpecialization1, "Specialization1"); getWidget(mSpecialization2, "Specialization2"); @@ -694,7 +692,6 @@ namespace MWGui MyGUI::Button* cancelButton; getWidget(cancelButton, "CancelButton"); - cancelButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sCancel", "")); cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSpecializationDialog::onCancelClicked); } @@ -737,8 +734,6 @@ namespace MWGui // Centre dialog center(); - setText("LabelT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sAttributesMenu1", "")); - for (int i = 0; i < 8; ++i) { Widgets::MWAttributePtr attribute; @@ -752,7 +747,6 @@ namespace MWGui MyGUI::Button* cancelButton; getWidget(cancelButton, "CancelButton"); - cancelButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sCancel", "")); cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectAttributeDialog::onCancelClicked); } @@ -788,11 +782,6 @@ namespace MWGui // Centre dialog center(); - setText("LabelT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sSkillsMenu1", "")); - setText("CombatLabelT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sSpecializationCombat", "")); - setText("MagicLabelT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sSpecializationMagic", "")); - setText("StealthLabelT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sSpecializationStealth", "")); - for(int i = 0; i < 9; i++) { char theIndex = '0'+i; @@ -849,7 +838,6 @@ namespace MWGui MyGUI::Button* cancelButton; getWidget(cancelButton, "CancelButton"); - cancelButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sCancel", "")); cancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSkillDialog::onCancelClicked); } diff --git a/files/mygui/openmw_chargen_select_attribute.layout b/files/mygui/openmw_chargen_select_attribute.layout index a93b5c453..cd722ef3e 100644 --- a/files/mygui/openmw_chargen_select_attribute.layout +++ b/files/mygui/openmw_chargen_select_attribute.layout @@ -5,7 +5,7 @@ - + @@ -22,7 +22,7 @@ - + diff --git a/files/mygui/openmw_chargen_select_skill.layout b/files/mygui/openmw_chargen_select_skill.layout index dc1798995..8d4ffdba2 100644 --- a/files/mygui/openmw_chargen_select_skill.layout +++ b/files/mygui/openmw_chargen_select_skill.layout @@ -5,13 +5,13 @@ - + - + @@ -26,7 +26,7 @@ - + @@ -41,7 +41,7 @@ - + @@ -57,7 +57,7 @@ - + diff --git a/files/mygui/openmw_chargen_select_specialization.layout b/files/mygui/openmw_chargen_select_specialization.layout index 7f8b5e02b..d0b74104b 100644 --- a/files/mygui/openmw_chargen_select_specialization.layout +++ b/files/mygui/openmw_chargen_select_specialization.layout @@ -6,7 +6,7 @@ - + @@ -24,7 +24,7 @@ - + From 62ab35881e60f7729aab1b11e5f66aadf123487c Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 00:03:55 +0200 Subject: [PATCH 02/15] Don't advance skills in werewolf mode (thanks Hrnchamd) --- apps/openmw/mwclass/npc.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 80b6088f2..e8daaf4ff 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -1127,6 +1127,9 @@ namespace MWClass { MWMechanics::NpcStats& stats = getNpcStats (ptr); + if (stats.isWerewolf()) + return; + MWWorld::LiveCellRef *ref = ptr.get(); const ESM::Class *class_ = From 1afcc7adb56c8792577f326735ec1725ab748ad6 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 00:04:38 +0200 Subject: [PATCH 03/15] Add imported font colors from openmw.cfg to MyGUI plugin --- apps/openmw/mwgui/windowmanagerimp.cpp | 42 ++--------------- components/CMakeLists.txt | 2 +- components/widgets/tags.cpp | 57 ++++++++++++++++++++++++ components/widgets/tags.hpp | 16 +++++++ plugins/mygui_resource_plugin/plugin.cpp | 54 +++++++++++++++++++++- plugins/mygui_resource_plugin/plugin.hpp | 5 +++ 6 files changed, 135 insertions(+), 41 deletions(-) create mode 100644 components/widgets/tags.cpp create mode 100644 components/widgets/tags.hpp diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 3bf4e588a..198d293b3 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -19,6 +19,7 @@ #include #include +#include #include "../mwbase/inputmanager.hpp" #include "../mwbase/statemanager.hpp" @@ -991,50 +992,13 @@ namespace MWGui std::string tokenToFind = "sCell="; size_t tokenLength = tokenToFind.length(); - std::string fontcolour = "fontcolour="; - size_t fontcolourLength = fontcolour.length(); - - std::string fontcolourhtml = "fontcolourhtml="; - size_t fontcolourhtmlLength = fontcolourhtml.length(); - if (tag.compare(0, tokenLength, tokenToFind) == 0) { _result = mTranslationDataStorage.translateCellName(tag.substr(tokenLength)); } - else if (tag.compare(0, fontcolourLength, fontcolour) == 0) + else if (Gui::replaceTag(tag, _result, mFallbackMap)) { - std::string fallbackName = "FontColor_color_" + tag.substr(fontcolourLength); - std::map::const_iterator it = mFallbackMap.find(fallbackName); - if (it == mFallbackMap.end()) - throw std::runtime_error("Unknown fallback name: " + fallbackName); - std::string str = it->second; - - std::string ret[3]; - unsigned int j=0; - for(unsigned int i=0;i::const_iterator it = mFallbackMap.find(fallbackName); - if (it == mFallbackMap.end()) - throw std::runtime_error("Unknown fallback name: " + fallbackName); - std::string str = it->second; - - std::string ret[3]; - unsigned int j=0; - for(unsigned int i=0;i + +namespace Gui +{ + +bool replaceTag(const MyGUI::UString& tag, MyGUI::UString& out, const std::map& fallbackSettings) +{ + std::string fontcolour = "fontcolour="; + size_t fontcolourLength = fontcolour.length(); + + std::string fontcolourhtml = "fontcolourhtml="; + size_t fontcolourhtmlLength = fontcolourhtml.length(); + + if (tag.compare(0, fontcolourLength, fontcolour) == 0) + { + std::string fallbackName = "FontColor_color_" + tag.substr(fontcolourLength); + std::map::const_iterator it = fallbackSettings.find(fallbackName); + if (it == fallbackSettings.end()) + throw std::runtime_error("Unknown fallback name: " + fallbackName); + std::string str = it->second; + + std::string ret[3]; + unsigned int j=0; + for(unsigned int i=0;i::const_iterator it = fallbackSettings.find(fallbackName); + if (it == fallbackSettings.end()) + throw std::runtime_error("Unknown fallback name: " + fallbackName); + std::string str = it->second; + + std::string ret[3]; + unsigned int j=0; + for(unsigned int i=0;i +#include +#include + +namespace Gui +{ + +/// Try to replace a tag. Returns true on success and writes the result to \a out. +bool replaceTag (const MyGUI::UString& tag, MyGUI::UString& out, const std::map& fallbackSettings); + +} + +#endif diff --git a/plugins/mygui_resource_plugin/plugin.cpp b/plugins/mygui_resource_plugin/plugin.cpp index 9633bc51b..7b5572e62 100644 --- a/plugins/mygui_resource_plugin/plugin.cpp +++ b/plugins/mygui_resource_plugin/plugin.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -12,10 +13,49 @@ #include #include +#include #include #include +//FIXME: code duplication +namespace boost +{ +struct FallbackMap { + std::map mMap; +}; + +void validate(boost::any &v, std::vector const &tokens, FallbackMap*, int) +{ + if(v.empty()) + { + v = boost::any(FallbackMap()); + } + + FallbackMap *map = boost::any_cast(&v); + + std::map::iterator mapIt; + for(std::vector::const_iterator it=tokens.begin(); it != tokens.end(); ++it) + { + int sep = it->find(","); + if(sep < 1 || sep == (int)it->length()-1) +#if (BOOST_VERSION < 104200) + throw boost::program_options::validation_error("invalid value"); +#else + throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value); +#endif + + std::string key(it->substr(0,sep)); + std::string value(it->substr(sep+1)); + + if((mapIt = map->mMap.find(key)) == map->mMap.end()) + { + map->mMap.insert(std::make_pair (key,value)); + } + } +} +} + namespace MyGUIPlugin { @@ -51,7 +91,9 @@ namespace MyGUIPlugin ("fs-strict", boost::program_options::value()->implicit_value(true)->default_value(false)) ("fallback-archive", boost::program_options::value >()-> default_value(std::vector(), "fallback-archive")->multitoken()) - ("encoding", boost::program_options::value()->default_value("win1252")); + ("encoding", boost::program_options::value()->default_value("win1252")) + ("fallback", boost::program_options::value()->default_value(boost::FallbackMap(), "") + ->multitoken()->composing(), "fallback values"); boost::program_options::notify(variables); @@ -86,6 +128,8 @@ namespace MyGUIPlugin Gui::FontLoader loader(ToUTF8::calculateEncoding(encoding)); loader.loadAllFonts(false); + + mFallbackMap = variables["fallback"].as().mMap; } void ResourcePlugin::registerWidgets() @@ -126,6 +170,8 @@ namespace MyGUIPlugin registerResources(); registerWidgets(); createTransparentBGTexture(); + + MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &ResourcePlugin::onRetrieveTag); } void ResourcePlugin::shutdown() @@ -135,4 +181,10 @@ namespace MyGUIPlugin MYGUI_LOGGING("OpenMW_Resource_Plugin", Info, "shutdown"); } + void ResourcePlugin::onRetrieveTag(const MyGUI::UString& tag, MyGUI::UString& out) + { + if (!Gui::replaceTag(tag, out, mFallbackMap)) + out = tag; + } + } diff --git a/plugins/mygui_resource_plugin/plugin.hpp b/plugins/mygui_resource_plugin/plugin.hpp index 9d035f09c..6a06060d9 100644 --- a/plugins/mygui_resource_plugin/plugin.hpp +++ b/plugins/mygui_resource_plugin/plugin.hpp @@ -2,6 +2,7 @@ #define OPENMW_MYGUI_RESOURCE_PLUGIN_H #include +#include namespace MyGUIPlugin { @@ -40,6 +41,10 @@ namespace MyGUIPlugin void registerResources(); void registerWidgets(); void createTransparentBGTexture(); + + void onRetrieveTag(const MyGUI::UString& tag, MyGUI::UString& out); + + std::map mFallbackMap; }; } From 40587f984d365b2879bae0940e0390e2245e6a1a Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 12:25:57 +0200 Subject: [PATCH 04/15] Implement price-based mercantile skill progress (Fixes #1947), thanks Hrnchamd Correct barter formula (removed erroneous clamping) --- apps/openmw/mwclass/npc.cpp | 4 ++-- apps/openmw/mwclass/npc.hpp | 2 +- apps/openmw/mwgui/tradewindow.cpp | 22 +++++++++++++++------- apps/openmw/mwmechanics/npcstats.cpp | 8 +++++--- apps/openmw/mwmechanics/npcstats.hpp | 4 ++-- apps/openmw/mwworld/class.cpp | 2 +- apps/openmw/mwworld/class.hpp | 2 +- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index e8daaf4ff..dd879305d 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -1123,7 +1123,7 @@ namespace MWClass return cast.cast(id); } - void Npc::skillUsageSucceeded (const MWWorld::Ptr& ptr, int skill, int usageType) const + void Npc::skillUsageSucceeded (const MWWorld::Ptr& ptr, int skill, int usageType, float extraFactor) const { MWMechanics::NpcStats& stats = getNpcStats (ptr); @@ -1137,7 +1137,7 @@ namespace MWClass ref->mBase->mClass ); - stats.useSkill (skill, *class_, usageType); + stats.useSkill (skill, *class_, usageType, extraFactor); } float Npc::getArmorRating (const MWWorld::Ptr& ptr) const diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 71e34e498..05594a530 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -136,7 +136,7 @@ namespace MWClass virtual void adjustScale (const MWWorld::Ptr &ptr, float &scale) const; - virtual void skillUsageSucceeded (const MWWorld::Ptr& ptr, int skill, int usageType) const; + virtual void skillUsageSucceeded (const MWWorld::Ptr& ptr, int skill, int usageType, float extraFactor=1.f) const; ///< Inform actor \a ptr that a skill use has succeeded. virtual void adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const; diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 00f812c11..3d888e468 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -324,12 +324,12 @@ namespace MWGui const MWMechanics::CreatureStats &sellerStats = mPtr.getClass().getCreatureStats(mPtr); const MWMechanics::CreatureStats &playerStats = player.getClass().getCreatureStats(player); - float a1 = std::min(player.getClass().getSkill(player, ESM::Skill::Mercantile), 100); - float b1 = std::min(0.1f * playerStats.getAttribute(ESM::Attribute::Luck).getModified(), 10.f); - float c1 = std::min(0.2f * playerStats.getAttribute(ESM::Attribute::Personality).getModified(), 10.f); - float d1 = std::min(mPtr.getClass().getSkill(mPtr, ESM::Skill::Mercantile), 100); - float e1 = std::min(0.1f * sellerStats.getAttribute(ESM::Attribute::Luck).getModified(), 10.f); - float f1 = std::min(0.2f * sellerStats.getAttribute(ESM::Attribute::Personality).getModified(), 10.f); + float a1 = player.getClass().getSkill(player, ESM::Skill::Mercantile); + float b1 = 0.1f * playerStats.getAttribute(ESM::Attribute::Luck).getModified(); + float c1 = 0.2f * playerStats.getAttribute(ESM::Attribute::Personality).getModified(); + float d1 = mPtr.getClass().getSkill(mPtr, ESM::Skill::Mercantile); + float e1 = 0.1f * sellerStats.getAttribute(ESM::Attribute::Luck).getModified(); + float f1 = 0.2f * sellerStats.getAttribute(ESM::Attribute::Personality).getModified(); float pcTerm = (clampedDisposition - 50 + a1 + b1 + c1) * playerStats.getFatigueTerm(); float npcTerm = (d1 + e1 + f1) * sellerStats.getFatigueTerm(); @@ -352,7 +352,15 @@ namespace MWGui } //skill use! - player.getClass().skillUsageSucceeded(player, ESM::Skill::Mercantile, 0); + float skillGain = 0.f; + int finalPrice = std::abs(mCurrentBalance); + int initialMerchantOffer = std::abs(mCurrentMerchantOffer); + if (!buying && (finalPrice > initialMerchantOffer) && finalPrice > 0) + skillGain = int(100 * (finalPrice - initialMerchantOffer) / float(finalPrice)); + else if (buying && (finalPrice < initialMerchantOffer) && initialMerchantOffer > 0) + skillGain = int(100 * (initialMerchantOffer - finalPrice) / float(initialMerchantOffer)); + + player.getClass().skillUsageSucceeded(player, ESM::Skill::Mercantile, 0, skillGain); } int iBarterSuccessDisposition = gmst.find("iBarterSuccessDisposition")->getInt(); diff --git a/apps/openmw/mwmechanics/npcstats.cpp b/apps/openmw/mwmechanics/npcstats.cpp index 87fb835a7..370c47b1f 100644 --- a/apps/openmw/mwmechanics/npcstats.cpp +++ b/apps/openmw/mwmechanics/npcstats.cpp @@ -107,7 +107,7 @@ bool MWMechanics::NpcStats::isSameFaction (const NpcStats& npcStats) const } float MWMechanics::NpcStats::getSkillGain (int skillIndex, const ESM::Class& class_, int usageType, - int level) const + int level, float extraFactor) const { if (level<0) level = static_cast (getSkill (skillIndex).getBase()); @@ -131,6 +131,8 @@ float MWMechanics::NpcStats::getSkillGain (int skillIndex, const ESM::Class& cla return 0; } + skillFactor *= extraFactor; + const MWWorld::Store &gmst = MWBase::Environment::get().getWorld()->getStore().get(); @@ -167,7 +169,7 @@ float MWMechanics::NpcStats::getSkillGain (int skillIndex, const ESM::Class& cla return 1.0 / ((level+1) * (1.0/skillFactor) * typeFactor * specialisationFactor); } -void MWMechanics::NpcStats::useSkill (int skillIndex, const ESM::Class& class_, int usageType) +void MWMechanics::NpcStats::useSkill (int skillIndex, const ESM::Class& class_, int usageType, float extraFactor) { // Don't increase skills as a werewolf if(mIsWerewolf) @@ -175,7 +177,7 @@ void MWMechanics::NpcStats::useSkill (int skillIndex, const ESM::Class& class_, MWMechanics::SkillValue& value = getSkill (skillIndex); - value.setProgress(value.getProgress() + getSkillGain (skillIndex, class_, usageType)); + value.setProgress(value.getProgress() + getSkillGain (skillIndex, class_, usageType, -1, extraFactor)); if (value.getProgress()>=1) { diff --git a/apps/openmw/mwmechanics/npcstats.hpp b/apps/openmw/mwmechanics/npcstats.hpp index 406db7762..4ea5d4578 100644 --- a/apps/openmw/mwmechanics/npcstats.hpp +++ b/apps/openmw/mwmechanics/npcstats.hpp @@ -81,12 +81,12 @@ namespace MWMechanics ///< Do *this and \a npcStats share a faction? float getSkillGain (int skillIndex, const ESM::Class& class_, int usageType = -1, - int level = -1) const; + int level = -1, float extraFactor=1.f) const; ///< \param usageType: Usage specific factor, specified in the respective skill record; /// -1: use a factor of 1.0 instead. /// \param level Level to base calculation on; -1: use current level. - void useSkill (int skillIndex, const ESM::Class& class_, int usageType = -1); + void useSkill (int skillIndex, const ESM::Class& class_, int usageType = -1, float extraFactor=1.f); ///< Increase skill by usage. void increaseSkill (int skillIndex, const ESM::Class& class_, bool preserveProgress); diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 59fc86d0d..c0654a7f4 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -52,7 +52,7 @@ namespace MWWorld return false; } - void Class::skillUsageSucceeded (const MWWorld::Ptr& ptr, int skill, int usageType) const + void Class::skillUsageSucceeded (const MWWorld::Ptr& ptr, int skill, int usageType, float extraFactor) const { throw std::runtime_error ("class does not represent an actor"); } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 64e83179d..5d9c0a0ea 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -231,7 +231,7 @@ namespace MWWorld /// /// (default implementation: ignore and return false) - virtual void skillUsageSucceeded (const MWWorld::Ptr& ptr, int skill, int usageType) const; + virtual void skillUsageSucceeded (const MWWorld::Ptr& ptr, int skill, int usageType, float extraFactor=1.f) const; ///< Inform actor \a ptr that a skill use has succeeded. /// /// (default implementations: throws an exception) From ad318c1f9dc522594e59b574476f336e5b9b1196 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 15:07:15 +0200 Subject: [PATCH 05/15] Add XML definition file for the MyGUI plugin --- files/mygui/CMakeLists.txt | 1 + files/mygui/OpenMWResourcePlugin.xml | 30 ++++++++++++++++++++++++++++ files/mygui/core_layouteditor.xml | 1 + 3 files changed, 32 insertions(+) create mode 100644 files/mygui/OpenMWResourcePlugin.xml diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index bfd622bd3..323371eb7 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -86,6 +86,7 @@ set(MYGUI_FILES DejaVuLGCSansMono.ttf markers.png ../launcher/images/openmw.png + OpenMWResourcePlugin.xml ) diff --git a/files/mygui/OpenMWResourcePlugin.xml b/files/mygui/OpenMWResourcePlugin.xml new file mode 100644 index 000000000..e1de58a1d --- /dev/null +++ b/files/mygui/OpenMWResourcePlugin.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + ./Plugin_MyGUI_OpenMW_Resources + ./Plugin_MyGUI_OpenMW_Resources_d + + + diff --git a/files/mygui/core_layouteditor.xml b/files/mygui/core_layouteditor.xml index 007b5e638..a945f2aae 100644 --- a/files/mygui/core_layouteditor.xml +++ b/files/mygui/core_layouteditor.xml @@ -1,6 +1,7 @@ + From 206609720280ae35250132b4a7fa8b63a8f4792d Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 15:28:02 +0200 Subject: [PATCH 06/15] Fix incorrect reading of global map state in some cases when the map size changed (Fixes #1946) --- apps/openmw/mwrender/globalmap.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/globalmap.cpp b/apps/openmw/mwrender/globalmap.cpp index d543308ff..6ebcfcd26 100644 --- a/apps/openmw/mwrender/globalmap.cpp +++ b/apps/openmw/mwrender/globalmap.cpp @@ -326,7 +326,8 @@ namespace MWRender mOverlayTexture->getBuffer()->blit(tex->getBuffer(), srcBox, destBox); if (srcBox.left == destBox.left && srcBox.right == destBox.right - && srcBox.top == destBox.top && srcBox.bottom == destBox.bottom) + && srcBox.top == destBox.top && srcBox.bottom == destBox.bottom + && int(image.getWidth()) == mWidth && int(image.getHeight()) == mHeight) mOverlayImage = image; else mOverlayTexture->convertToImage(mOverlayImage); From 6b65502557038c8b050a49e30efe43d53cf0cbc1 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 16:25:08 +0200 Subject: [PATCH 07/15] Add properties for new widget classes to MyGUI plugin --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwgui/dialogue.cpp | 3 +- apps/openmw/mwgui/dialogue.hpp | 12 +- apps/openmw/mwgui/journalwindow.cpp | 15 +- apps/openmw/mwgui/list.cpp | 169 ---------------------- apps/openmw/mwgui/list.hpp | 74 ---------- apps/openmw/mwgui/spellcreationdialog.cpp | 2 +- apps/openmw/mwgui/spellcreationdialog.hpp | 7 +- apps/openmw/mwgui/windowmanagerimp.cpp | 2 +- components/CMakeLists.txt | 2 +- components/widgets/box.cpp | 2 +- components/widgets/list.cpp | 165 +++++++++++++++++++++ components/widgets/list.hpp | 71 +++++++++ files/mygui/OpenMWResourcePlugin.xml | 94 ++++++++---- plugins/mygui_resource_plugin/plugin.cpp | 2 + 15 files changed, 329 insertions(+), 293 deletions(-) delete mode 100644 apps/openmw/mwgui/list.cpp delete mode 100644 apps/openmw/mwgui/list.hpp create mode 100644 components/widgets/list.cpp create mode 100644 components/widgets/list.hpp diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index 0ad2cbd2a..2417091f8 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -32,7 +32,7 @@ add_openmw_dir (mwinput add_openmw_dir (mwgui textinput widgets race class birth review windowmanagerimp console dialogue windowbase statswindow messagebox journalwindow charactercreation - mapwindow windowpinnablebase tooltips scrollwindow bookwindow list + mapwindow windowpinnablebase tooltips scrollwindow bookwindow formatting inventorywindow container hud countdialog tradewindow settingswindow confirmationdialog alchemywindow referenceinterface spellwindow mainmenu quickkeysmenu itemselection spellbuyingwindow loadingscreen levelupdialog waitdialog spellcreationdialog diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 4931c6787..28639a8e1 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwbase/mechanicsmanager.hpp" @@ -17,7 +19,6 @@ #include "../mwdialogue/dialoguemanagerimp.hpp" #include "widgets.hpp" -#include "list.hpp" #include "tradewindow.hpp" #include "spellbuyingwindow.hpp" #include "travelwindow.hpp" diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp index 6f16fcb03..18f1f1555 100644 --- a/apps/openmw/mwgui/dialogue.hpp +++ b/apps/openmw/mwgui/dialogue.hpp @@ -8,14 +8,14 @@ #include "keywordsearch.hpp" +namespace Gui +{ + class MWList; +} + namespace MWGui { class WindowManager; - - namespace Widgets - { - class MWList; - } } /* @@ -169,7 +169,7 @@ namespace MWGui KeywordSearchT mKeywordSearch; BookPage* mHistory; - Widgets::MWList* mTopicsList; + Gui::MWList* mTopicsList; MyGUI::ScrollBar* mScrollBar; MyGUI::Progress* mDispositionBar; MyGUI::EditBox* mDispositionText; diff --git a/apps/openmw/mwgui/journalwindow.cpp b/apps/openmw/mwgui/journalwindow.cpp index bc7fbde15..6cf8bb003 100644 --- a/apps/openmw/mwgui/journalwindow.cpp +++ b/apps/openmw/mwgui/journalwindow.cpp @@ -4,7 +4,6 @@ #include "../mwbase/soundmanager.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwbase/journal.hpp" -#include "list.hpp" #include #include @@ -16,12 +15,12 @@ #include "boost/lexical_cast.hpp" #include +#include #include "bookpage.hpp" #include "windowbase.hpp" #include "journalviewmodel.hpp" #include "journalbooks.hpp" -#include "list.hpp" namespace { @@ -111,10 +110,10 @@ namespace adviseButtonClick (ShowAllBTN, &JournalWindowImpl::notifyShowAll ); adviseButtonClick (ShowActiveBTN, &JournalWindowImpl::notifyShowActive); - MWGui::Widgets::MWList* list = getWidget(QuestsList); + Gui::MWList* list = getWidget(QuestsList); list->eventItemSelected += MyGUI::newDelegate(this, &JournalWindowImpl::notifyQuestClicked); - MWGui::Widgets::MWList* topicsList = getWidget(TopicsList); + Gui::MWList* topicsList = getWidget(TopicsList); topicsList->eventItemSelected += MyGUI::newDelegate(this, &JournalWindowImpl::notifyTopicSelected); { @@ -412,7 +411,7 @@ namespace setVisible (RightTopicIndex, false); setVisible (TopicsList, true); - MWGui::Widgets::MWList* list = getWidget(TopicsList); + Gui::MWList* list = getWidget(TopicsList); list->clear(); AddNamesToList add(list); @@ -435,9 +434,9 @@ namespace struct AddNamesToList { - AddNamesToList(MWGui::Widgets::MWList* list) : mList(list) {} + AddNamesToList(Gui::MWList* list) : mList(list) {} - MWGui::Widgets::MWList* mList; + Gui::MWList* mList; void operator () (const std::string& name) { mList->addItem(name); @@ -455,7 +454,7 @@ namespace setVisible (ShowAllBTN, !mAllQuests); setVisible (ShowActiveBTN, mAllQuests); - MWGui::Widgets::MWList* list = getWidget(QuestsList); + Gui::MWList* list = getWidget(QuestsList); list->clear(); AddNamesToList add(list); diff --git a/apps/openmw/mwgui/list.cpp b/apps/openmw/mwgui/list.cpp deleted file mode 100644 index ff14bcf61..000000000 --- a/apps/openmw/mwgui/list.cpp +++ /dev/null @@ -1,169 +0,0 @@ -#include "list.hpp" - -#include -#include -#include -#include - -namespace MWGui -{ - - namespace Widgets - { - - MWList::MWList() : - mClient(0) - , mScrollView(0) - , mItemHeight(0) - { - } - - void MWList::initialiseOverride() - { - Base::initialiseOverride(); - - assignWidget(mClient, "Client"); - if (mClient == 0) - mClient = this; - - mScrollView = mClient->createWidgetReal( - "MW_ScrollView", MyGUI::FloatCoord(0.0, 0.0, 1.0, 1.0), - MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView"); - } - - void MWList::addItem(const std::string& name) - { - mItems.push_back(name); - } - - void MWList::addSeparator() - { - mItems.push_back(""); - } - - void MWList::adjustSize() - { - redraw(); - } - - void MWList::redraw(bool scrollbarShown) - { - const int _scrollBarWidth = 20; // fetch this from skin? - const int scrollBarWidth = scrollbarShown ? _scrollBarWidth : 0; - const int spacing = 3; - size_t viewPosition = -mScrollView->getViewOffset().top; - - while (mScrollView->getChildCount()) - { - MyGUI::Gui::getInstance().destroyWidget(mScrollView->getChildAt(0)); - } - - mItemHeight = 0; - int i=0; - for (std::vector::const_iterator it=mItems.begin(); - it!=mItems.end(); ++it) - { - if (*it != "") - { - if (mListItemSkin.empty()) - throw std::runtime_error("MWList needs a ListItemSkin property"); - MyGUI::Button* button = mScrollView->createWidget( - mListItemSkin, 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)); - button->setUserData(i); - - mItemHeight += height + spacing; - } - else - { - MyGUI::ImageBox* separator = mScrollView->createWidget("MW_HLine", - MyGUI::IntCoord(2, mItemHeight, mScrollView->getWidth() - scrollBarWidth - 4, 18), - MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); - separator->setNeedMouseFocus(false); - - mItemHeight += 18 + spacing; - } - ++i; - } - - // Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden - mScrollView->setVisibleVScroll(false); - mScrollView->setCanvasSize(mClient->getSize().width, std::max(mItemHeight, mClient->getSize().height)); - mScrollView->setVisibleVScroll(true); - - if (!scrollbarShown && mItemHeight > mClient->getSize().height) - redraw(true); - - size_t viewRange = mScrollView->getCanvasSize().height; - if(viewPosition > viewRange) - viewPosition = viewRange; - mScrollView->setViewOffset(MyGUI::IntPoint(0, viewPosition * -1)); - } - - void MWList::setPropertyOverride(const std::string &_key, const std::string &_value) - { - if (_key == "ListItemSkin") - mListItemSkin = _value; - else - Base::setPropertyOverride(_key, _value); - } - - bool MWList::hasItem(const std::string& name) - { - return (std::find(mItems.begin(), mItems.end(), name) != mItems.end()); - } - - unsigned int MWList::getItemCount() - { - return mItems.size(); - } - - std::string MWList::getItemNameAt(unsigned int at) - { - assert(at < mItems.size() && "List item out of bounds"); - return mItems[at]; - } - - 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) ); - } - - void MWList::clear() - { - mItems.clear(); - } - - void MWList::onMouseWheel(MyGUI::Widget* _sender, int _rel) - { - //NB view offset is negative - if (mScrollView->getViewOffset().top + _rel*0.3 > 0) - mScrollView->setViewOffset(MyGUI::IntPoint(0, 0)); - else - mScrollView->setViewOffset(MyGUI::IntPoint(0, mScrollView->getViewOffset().top + _rel*0.3)); - } - - void MWList::onItemSelected(MyGUI::Widget* _sender) - { - std::string name = _sender->castType()->getCaption(); - int id = *_sender->getUserData(); - eventItemSelected(name, id); - eventWidgetSelected(_sender); - } - - MyGUI::Widget* MWList::getItemWidget(const std::string& name) - { - return mScrollView->findWidget (getName() + "_item_" + name); - } - - } -} diff --git a/apps/openmw/mwgui/list.hpp b/apps/openmw/mwgui/list.hpp deleted file mode 100644 index acf078a2c..000000000 --- a/apps/openmw/mwgui/list.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef MWGUI_LIST_HPP -#define MWGUI_LIST_HPP - -#include - -namespace MWGui -{ - namespace Widgets - { - /** - * \brief a very simple list widget that supports word-wrapping entries - * \note if the width or height of the list changes, you must call adjustSize() method - */ - class MWList : public MyGUI::Widget - { - MYGUI_RTTI_DERIVED(MWList) - public: - MWList(); - - typedef MyGUI::delegates::CMultiDelegate2 EventHandle_StringInt; - typedef MyGUI::delegates::CMultiDelegate1 EventHandle_Widget; - - /** - * Event: Item selected with the mouse. - * signature: void method(std::string itemName, int index) - */ - EventHandle_StringInt eventItemSelected; - - /** - * Event: Item selected with the mouse. - * signature: void method(MyGUI::Widget* sender) - */ - EventHandle_Widget eventWidgetSelected; - - - /** - * Call after the size of the list changed, or items were inserted/removed - */ - 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); ///< \attention if there are separators, this method will return "" at the place where the separator is - void clear(); - - MyGUI::Widget* getItemWidget(const std::string& name); - ///< get widget for an item name, useful to set up tooltip - - virtual void setPropertyOverride(const std::string& _key, const std::string& _value); - - protected: - void initialiseOverride(); - - void redraw(bool scrollbarShown = false); - - void onMouseWheel(MyGUI::Widget* _sender, int _rel); - void onItemSelected(MyGUI::Widget* _sender); - - private: - MyGUI::ScrollView* mScrollView; - MyGUI::Widget* mClient; - std::string mListItemSkin; - - std::vector mItems; - - int mItemHeight; // height of all items - }; - } -} - -#endif diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index e6da3d692..cdab79af1 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -522,7 +522,7 @@ namespace MWGui updateEffectsView (); } - void EffectEditorBase::setWidgets (Widgets::MWList *availableEffectsList, MyGUI::ScrollView *usedEffectsView) + void EffectEditorBase::setWidgets (Gui::MWList *availableEffectsList, MyGUI::ScrollView *usedEffectsView) { mAvailableEffectsList = availableEffectsList; mUsedEffectsView = usedEffectsView; diff --git a/apps/openmw/mwgui/spellcreationdialog.hpp b/apps/openmw/mwgui/spellcreationdialog.hpp index be984c8d4..e77c0eecf 100644 --- a/apps/openmw/mwgui/spellcreationdialog.hpp +++ b/apps/openmw/mwgui/spellcreationdialog.hpp @@ -1,9 +1,10 @@ #ifndef MWGUI_SPELLCREATION_H #define MWGUI_SPELLCREATION_H +#include + #include "windowbase.hpp" #include "referenceinterface.hpp" -#include "list.hpp" #include "widgets.hpp" namespace MWGui @@ -97,7 +98,7 @@ namespace MWGui protected: std::map mButtonMapping; // maps button ID to effect ID - Widgets::MWList* mAvailableEffectsList; + Gui::MWList* mAvailableEffectsList; MyGUI::ScrollView* mUsedEffectsView; EditEffectDialog mAddEffectDialog; @@ -124,7 +125,7 @@ namespace MWGui void updateEffectsView(); void startEditing(); - void setWidgets (Widgets::MWList* availableEffectsList, MyGUI::ScrollView* usedEffectsView); + void setWidgets (Gui::MWList* availableEffectsList, MyGUI::ScrollView* usedEffectsView); virtual void notifyEffectsChanged () {} diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 198d293b3..1b400bb58 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -165,7 +165,7 @@ namespace MWGui MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index c0065937a..baddfd6a2 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -96,7 +96,7 @@ add_component_dir (ogreinit ) add_component_dir (widgets - box imagebutton tags + box imagebutton tags list ) add_component_dir (fontloader diff --git a/components/widgets/box.cpp b/components/widgets/box.cpp index 6ec471b65..e1c148271 100644 --- a/components/widgets/box.cpp +++ b/components/widgets/box.cpp @@ -8,7 +8,7 @@ namespace Gui MyGUI::Widget * parent = w->getParent(); if (parent != 0) { - if (mExpandDirection == MyGUI::Align::Left) + if (mExpandDirection.isLeft()) { int hdiff = getRequestedSize ().width - w->getSize().width; w->setPosition(w->getPosition() - MyGUI::IntPoint(hdiff, 0)); diff --git a/components/widgets/list.cpp b/components/widgets/list.cpp new file mode 100644 index 000000000..86db2fdf4 --- /dev/null +++ b/components/widgets/list.cpp @@ -0,0 +1,165 @@ +#include "list.hpp" + +#include +#include +#include +#include + +namespace Gui +{ + + MWList::MWList() : + mClient(0) + , mScrollView(0) + , mItemHeight(0) + { + } + + void MWList::initialiseOverride() + { + Base::initialiseOverride(); + + assignWidget(mClient, "Client"); + if (mClient == 0) + mClient = this; + + mScrollView = mClient->createWidgetReal( + "MW_ScrollView", MyGUI::FloatCoord(0.0, 0.0, 1.0, 1.0), + MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView"); + } + + void MWList::addItem(const std::string& name) + { + mItems.push_back(name); + } + + void MWList::addSeparator() + { + mItems.push_back(""); + } + + void MWList::adjustSize() + { + redraw(); + } + + void MWList::redraw(bool scrollbarShown) + { + const int _scrollBarWidth = 20; // fetch this from skin? + const int scrollBarWidth = scrollbarShown ? _scrollBarWidth : 0; + const int spacing = 3; + size_t viewPosition = -mScrollView->getViewOffset().top; + + while (mScrollView->getChildCount()) + { + MyGUI::Gui::getInstance().destroyWidget(mScrollView->getChildAt(0)); + } + + mItemHeight = 0; + int i=0; + for (std::vector::const_iterator it=mItems.begin(); + it!=mItems.end(); ++it) + { + if (*it != "") + { + if (mListItemSkin.empty()) + return; + MyGUI::Button* button = mScrollView->createWidget( + mListItemSkin, 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)); + button->setUserData(i); + + mItemHeight += height + spacing; + } + else + { + MyGUI::ImageBox* separator = mScrollView->createWidget("MW_HLine", + MyGUI::IntCoord(2, mItemHeight, mScrollView->getWidth() - scrollBarWidth - 4, 18), + MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); + separator->setNeedMouseFocus(false); + + mItemHeight += 18 + spacing; + } + ++i; + } + + // Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden + mScrollView->setVisibleVScroll(false); + mScrollView->setCanvasSize(mClient->getSize().width, std::max(mItemHeight, mClient->getSize().height)); + mScrollView->setVisibleVScroll(true); + + if (!scrollbarShown && mItemHeight > mClient->getSize().height) + redraw(true); + + size_t viewRange = mScrollView->getCanvasSize().height; + if(viewPosition > viewRange) + viewPosition = viewRange; + mScrollView->setViewOffset(MyGUI::IntPoint(0, viewPosition * -1)); + } + + void MWList::setPropertyOverride(const std::string &_key, const std::string &_value) + { + if (_key == "ListItemSkin") + mListItemSkin = _value; + else + Base::setPropertyOverride(_key, _value); + } + + bool MWList::hasItem(const std::string& name) + { + return (std::find(mItems.begin(), mItems.end(), name) != mItems.end()); + } + + unsigned int MWList::getItemCount() + { + return mItems.size(); + } + + std::string MWList::getItemNameAt(unsigned int at) + { + assert(at < mItems.size() && "List item out of bounds"); + return mItems[at]; + } + + 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) ); + } + + void MWList::clear() + { + mItems.clear(); + } + + void MWList::onMouseWheel(MyGUI::Widget* _sender, int _rel) + { + //NB view offset is negative + if (mScrollView->getViewOffset().top + _rel*0.3 > 0) + mScrollView->setViewOffset(MyGUI::IntPoint(0, 0)); + else + mScrollView->setViewOffset(MyGUI::IntPoint(0, mScrollView->getViewOffset().top + _rel*0.3)); + } + + void MWList::onItemSelected(MyGUI::Widget* _sender) + { + std::string name = _sender->castType()->getCaption(); + int id = *_sender->getUserData(); + eventItemSelected(name, id); + eventWidgetSelected(_sender); + } + + MyGUI::Widget* MWList::getItemWidget(const std::string& name) + { + return mScrollView->findWidget (getName() + "_item_" + name); + } + +} diff --git a/components/widgets/list.hpp b/components/widgets/list.hpp new file mode 100644 index 000000000..8b4955a2d --- /dev/null +++ b/components/widgets/list.hpp @@ -0,0 +1,71 @@ +#ifndef MWGUI_LIST_HPP +#define MWGUI_LIST_HPP + +#include + +namespace Gui +{ + /** + * \brief a very simple list widget that supports word-wrapping entries + * \note if the width or height of the list changes, you must call adjustSize() method + */ + class MWList : public MyGUI::Widget + { + MYGUI_RTTI_DERIVED(MWList) + public: + MWList(); + + typedef MyGUI::delegates::CMultiDelegate2 EventHandle_StringInt; + typedef MyGUI::delegates::CMultiDelegate1 EventHandle_Widget; + + /** + * Event: Item selected with the mouse. + * signature: void method(std::string itemName, int index) + */ + EventHandle_StringInt eventItemSelected; + + /** + * Event: Item selected with the mouse. + * signature: void method(MyGUI::Widget* sender) + */ + EventHandle_Widget eventWidgetSelected; + + + /** + * Call after the size of the list changed, or items were inserted/removed + */ + 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); ///< \attention if there are separators, this method will return "" at the place where the separator is + void clear(); + + MyGUI::Widget* getItemWidget(const std::string& name); + ///< get widget for an item name, useful to set up tooltip + + virtual void setPropertyOverride(const std::string& _key, const std::string& _value); + + protected: + void initialiseOverride(); + + void redraw(bool scrollbarShown = false); + + void onMouseWheel(MyGUI::Widget* _sender, int _rel); + void onItemSelected(MyGUI::Widget* _sender); + + private: + MyGUI::ScrollView* mScrollView; + MyGUI::Widget* mClient; + std::string mListItemSkin; + + std::vector mItems; + + int mItemHeight; // height of all items + }; +} + +#endif diff --git a/files/mygui/OpenMWResourcePlugin.xml b/files/mygui/OpenMWResourcePlugin.xml index e1de58a1d..4b2ad3f7b 100644 --- a/files/mygui/OpenMWResourcePlugin.xml +++ b/files/mygui/OpenMWResourcePlugin.xml @@ -1,30 +1,70 @@ - - - - - - - - - - - - - - - - - - - - - - - - ./Plugin_MyGUI_OpenMW_Resources - ./Plugin_MyGUI_OpenMW_Resources_d - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ./Plugin_MyGUI_OpenMW_Resources + ./Plugin_MyGUI_OpenMW_Resources_d + + diff --git a/plugins/mygui_resource_plugin/plugin.cpp b/plugins/mygui_resource_plugin/plugin.cpp index 7b5572e62..349b440a5 100644 --- a/plugins/mygui_resource_plugin/plugin.cpp +++ b/plugins/mygui_resource_plugin/plugin.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -142,6 +143,7 @@ namespace MyGUIPlugin MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); } void ResourcePlugin::createTransparentBGTexture() From f721b7adfbf2df6bcc35ff9a4bf4955826edca25 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 16:41:27 +0200 Subject: [PATCH 08/15] Change skin files to use ResourceSkin (Skin is deprecated) - now the SkinEditor can load them --- files/mygui/core.skin | 18 +- files/mygui/openmw_box.skin.xml | 42 ++-- files/mygui/openmw_button.skin.xml | 38 ++-- files/mygui/openmw_console.skin.xml | 10 +- files/mygui/openmw_dialogue_window_skin.xml | 6 +- files/mygui/openmw_edit.skin.xml | 18 +- files/mygui/openmw_hud_box.skin.xml | 14 +- files/mygui/openmw_hud_energybar.skin.xml | 62 ++--- files/mygui/openmw_journal_skin.xml | 18 +- files/mygui/openmw_list.skin.xml | 66 +++--- files/mygui/openmw_mainmenu_skin.xml | 2 +- files/mygui/openmw_map_window_skin.xml | 6 +- files/mygui/openmw_progress.skin.xml | 54 ++--- files/mygui/openmw_scroll_skin.xml | 10 +- files/mygui/openmw_text.skin.xml | 78 +++---- files/mygui/openmw_windows.skin.xml | 238 ++++++++++---------- 16 files changed, 340 insertions(+), 340 deletions(-) diff --git a/files/mygui/core.skin b/files/mygui/core.skin index fbcc73d8a..9aa566451 100644 --- a/files/mygui/core.skin +++ b/files/mygui/core.skin @@ -1,19 +1,19 @@ - - + + - + - - - - - + - + + + + + diff --git a/files/mygui/openmw_box.skin.xml b/files/mygui/openmw_box.skin.xml index e1d0e5dec..8ff21807d 100644 --- a/files/mygui/openmw_box.skin.xml +++ b/files/mygui/openmw_box.skin.xml @@ -3,9 +3,9 @@ - + - + @@ -13,8 +13,8 @@ as around the sections of the stats window, or around popup info windows --> - - + + @@ -22,8 +22,8 @@ as around the sections of the stats window, or around popup info windows --> - - + + @@ -31,8 +31,8 @@ as around the sections of the stats window, or around popup info windows --> - - + + @@ -40,30 +40,30 @@ as around the sections of the stats window, or around popup info windows --> - - + + - - + + - - + + - - + + - + - + @@ -72,10 +72,10 @@ 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 9b0783160..9193e3874 100644 --- a/files/mygui/openmw_button.skin.xml +++ b/files/mygui/openmw_button.skin.xml @@ -1,8 +1,8 @@ - + - + @@ -10,8 +10,8 @@ - - + + @@ -19,8 +19,8 @@ - - + + @@ -28,8 +28,8 @@ - - + + @@ -37,30 +37,30 @@ - - + + - - + + - - + + - - + + - + - + @@ -83,5 +83,5 @@ - + diff --git a/files/mygui/openmw_console.skin.xml b/files/mygui/openmw_console.skin.xml index f36d9af46..4190e7976 100644 --- a/files/mygui/openmw_console.skin.xml +++ b/files/mygui/openmw_console.skin.xml @@ -1,20 +1,20 @@ - + - + - + - + - + diff --git a/files/mygui/openmw_dialogue_window_skin.xml b/files/mygui/openmw_dialogue_window_skin.xml index 5d8c98dad..3f7987f7a 100644 --- a/files/mygui/openmw_dialogue_window_skin.xml +++ b/files/mygui/openmw_dialogue_window_skin.xml @@ -1,14 +1,14 @@ - + - + - + diff --git a/files/mygui/openmw_edit.skin.xml b/files/mygui/openmw_edit.skin.xml index 31ba579bb..5ec48f752 100644 --- a/files/mygui/openmw_edit.skin.xml +++ b/files/mygui/openmw_edit.skin.xml @@ -1,17 +1,17 @@ - + - + - + - + @@ -25,9 +25,9 @@ - + - + @@ -39,9 +39,9 @@ - + - + @@ -56,6 +56,6 @@ - + diff --git a/files/mygui/openmw_hud_box.skin.xml b/files/mygui/openmw_hud_box.skin.xml index 770d28425..e7457e7d2 100644 --- a/files/mygui/openmw_hud_box.skin.xml +++ b/files/mygui/openmw_hud_box.skin.xml @@ -1,10 +1,10 @@ - + - + @@ -14,13 +14,13 @@ - + - + - + - + @@ -30,6 +30,6 @@ - + diff --git a/files/mygui/openmw_hud_energybar.skin.xml b/files/mygui/openmw_hud_energybar.skin.xml index c6f4c763c..640133d66 100644 --- a/files/mygui/openmw_hud_energybar.skin.xml +++ b/files/mygui/openmw_hud_energybar.skin.xml @@ -1,109 +1,109 @@ - + - + - - + + - - + + - + - + - - + + - - + + - - + + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + - + diff --git a/files/mygui/openmw_journal_skin.xml b/files/mygui/openmw_journal_skin.xml index d35ce68cf..942c9a4d4 100644 --- a/files/mygui/openmw_journal_skin.xml +++ b/files/mygui/openmw_journal_skin.xml @@ -1,26 +1,26 @@ - - + + - + - + - + - + - + - + @@ -32,5 +32,5 @@ - + diff --git a/files/mygui/openmw_list.skin.xml b/files/mygui/openmw_list.skin.xml index 01270ef23..21b17c8f0 100644 --- a/files/mygui/openmw_list.skin.xml +++ b/files/mygui/openmw_list.skin.xml @@ -1,10 +1,10 @@ - + - + @@ -32,9 +32,9 @@ - + - + @@ -42,11 +42,11 @@ - + - + @@ -76,9 +76,9 @@ - + - + @@ -87,26 +87,26 @@ - + - - + + - + - + - + @@ -120,9 +120,9 @@ - + - + @@ -133,9 +133,9 @@ - + - + @@ -146,58 +146,58 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/files/mygui/openmw_mainmenu_skin.xml b/files/mygui/openmw_mainmenu_skin.xml index af41d3a1e..33c1e7d62 100644 --- a/files/mygui/openmw_mainmenu_skin.xml +++ b/files/mygui/openmw_mainmenu_skin.xml @@ -1,4 +1,4 @@ - + diff --git a/files/mygui/openmw_map_window_skin.xml b/files/mygui/openmw_map_window_skin.xml index 03578f95b..31a70191f 100644 --- a/files/mygui/openmw_map_window_skin.xml +++ b/files/mygui/openmw_map_window_skin.xml @@ -1,11 +1,11 @@ - - + + - + diff --git a/files/mygui/openmw_progress.skin.xml b/files/mygui/openmw_progress.skin.xml index 7b1e413e5..761574c15 100644 --- a/files/mygui/openmw_progress.skin.xml +++ b/files/mygui/openmw_progress.skin.xml @@ -1,94 +1,94 @@ - + - + - - + + - - + + - + - + - - + + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -99,5 +99,5 @@ - + diff --git a/files/mygui/openmw_scroll_skin.xml b/files/mygui/openmw_scroll_skin.xml index e40b5fd52..b0b9dca17 100644 --- a/files/mygui/openmw_scroll_skin.xml +++ b/files/mygui/openmw_scroll_skin.xml @@ -1,15 +1,15 @@ - + - + - + - + - + diff --git a/files/mygui/openmw_text.skin.xml b/files/mygui/openmw_text.skin.xml index b9b30e751..bae094ef6 100644 --- a/files/mygui/openmw_text.skin.xml +++ b/files/mygui/openmw_text.skin.xml @@ -1,6 +1,6 @@ - + - + - + - + - + - + - + - + - + - + @@ -49,28 +49,28 @@ color_misc=0,205,205 # ???? - + - + - + - + - + - + - + - + @@ -83,9 +83,9 @@ color_misc=0,205,205 # ???? - + - + @@ -98,9 +98,9 @@ color_misc=0,205,205 # ???? - + - + @@ -113,49 +113,49 @@ color_misc=0,205,205 # ???? - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/files/mygui/openmw_windows.skin.xml b/files/mygui/openmw_windows.skin.xml index 6a3b31edd..d01bd8ef2 100644 --- a/files/mygui/openmw_windows.skin.xml +++ b/files/mygui/openmw_windows.skin.xml @@ -1,100 +1,100 @@ - + - + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + @@ -106,8 +106,8 @@ - - + + @@ -119,18 +119,18 @@ - + - + - + - + @@ -138,9 +138,9 @@ - + - + @@ -148,45 +148,45 @@ - + - + - + - + - + - + - - + + - - + + - - + + - + - + @@ -195,9 +195,9 @@ - + - + @@ -206,9 +206,9 @@ - + - + @@ -217,9 +217,9 @@ - + - + @@ -228,93 +228,93 @@ - + - + - - + + - - + + - - + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -322,9 +322,9 @@ - + - + @@ -332,9 +332,9 @@ - + - + @@ -342,42 +342,42 @@ - + - + - + - + - + - + - - + + - - + + - - + + - + - + @@ -387,11 +387,11 @@ - + - + @@ -406,7 +406,7 @@ - + - + @@ -551,9 +551,9 @@ - + - + @@ -687,9 +687,9 @@ - + - + @@ -830,9 +830,9 @@ - + - + @@ -861,5 +861,5 @@ - + From 40ce5add59a4387ef7b2be833fac2753042a35eb Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 17:32:44 +0200 Subject: [PATCH 09/15] Don't report crime for attacking an NPC that is already in combat with another NPC (Fixes #1908, Fixes #1821) --- apps/openmw/mwmechanics/mechanicsmanagerimp.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index b0e92d0a8..f908072e3 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -1128,9 +1128,21 @@ namespace MWMechanics } } - // Attacking peaceful NPCs is a crime + // Attacking an NPC that is already in combat with any other NPC is not a crime + AiSequence& seq = ptr.getClass().getCreatureStats(ptr).getAiSequence(); + bool isFightingNpc = false; + for (std::list::const_iterator it = seq.begin(); it != seq.end(); ++it) + { + if ((*it)->getTypeId() == AiPackage::TypeIdCombat) + { + MWWorld::Ptr target = static_cast(*it)->getTarget(); + if (!target.isEmpty() && target.getClass().isNpc()) + isFightingNpc = true; + } + } + if (ptr.getClass().isNpc() && !attacker.isEmpty() && !ptr.getClass().getCreatureStats(ptr).getAiSequence().isInCombat(attacker) - && !isAggressive(ptr, attacker)) + && !isAggressive(ptr, attacker) && !isFightingNpc) commitCrime(attacker, ptr, MWBase::MechanicsManager::OT_Assault); if (!attacker.isEmpty() && (attacker.getClass().getCreatureStats(attacker).getAiSequence().isInCombat(ptr) From 8ad2b95208573b69a8dc31adb0defedec19ac939 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 17:56:46 +0200 Subject: [PATCH 10/15] Revert "AiFollow: return from execute() if target is not player" This reverts commit 061c7813f6362b8ed16d6c79c016e6d5be18fdef. Fixes #1898. --- apps/openmw/mwmechanics/aifollow.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/apps/openmw/mwmechanics/aifollow.cpp b/apps/openmw/mwmechanics/aifollow.cpp index a10f97e78..abde80c71 100644 --- a/apps/openmw/mwmechanics/aifollow.cpp +++ b/apps/openmw/mwmechanics/aifollow.cpp @@ -50,11 +50,6 @@ bool MWMechanics::AiFollow::execute (const MWWorld::Ptr& actor,float duration) ) return true; //Target doesn't exist - // Only the player can be actively followed. AiFollow packages with targets other than the player - // are only used for defining combat alliances, since NPCs will defend whoever they are following or being followed by. - if (target != MWBase::Environment::get().getWorld()->getPlayerPtr()) - return false; - actor.getClass().getCreatureStats(actor).setDrawState(DrawState_Nothing); ESM::Position pos = actor.getRefData().getPosition(); //position of the actor From f56711f443bdf3b90cd2cf4bd894f58747834dc1 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 18:00:32 +0200 Subject: [PATCH 11/15] Fix crash caused by teleportation spells (Fixes #1904) --- apps/openmw/mwmechanics/actors.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 7045a7168..fb387afea 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1175,14 +1175,26 @@ namespace MWMechanics iter->second->updateContinuousVfx(); // Animation/movement update + CharacterController* playerCharacter = NULL; for(PtrControllerMap::iterator iter(mActors.begin()); iter != mActors.end(); ++iter) { if (iter->first.getClass().getCreatureStats(iter->first).getMagicEffects().get( ESM::MagicEffect::Paralyze).getMagnitude() > 0) iter->second->skipAnim(); + + // Handle player last, in case a cell transition occurs by casting a teleportation spell + // (would invalidate the iterator) + if (iter->first.getCellRef().getRefId() == "player") + { + playerCharacter = iter->second; + continue; + } iter->second->update(duration); } + if (playerCharacter) + playerCharacter->update(duration); + for(PtrControllerMap::iterator iter(mActors.begin()); iter != mActors.end(); ++iter) { const MWWorld::Class &cls = iter->first.getClass(); From e4c097b4f7d89fae6b2ed52755bd941df5b907c4 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 19:22:26 +0200 Subject: [PATCH 12/15] Fix wrong default ExpandDirection for AutoSizedButton --- components/widgets/box.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/widgets/box.hpp b/components/widgets/box.hpp index 40e76aca0..ccdc5784b 100644 --- a/components/widgets/box.hpp +++ b/components/widgets/box.hpp @@ -12,6 +12,8 @@ namespace Gui class AutoSizedWidget { public: + AutoSizedWidget() : mExpandDirection(MyGUI::Align::Right) {} + virtual MyGUI::IntSize getRequestedSize() = 0; protected: From 0bc840aadd8473158948e72fc69d1e4523fbf0db Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 20:28:00 +0200 Subject: [PATCH 13/15] Add NumericEditBox widget --- apps/openmw/mwgui/countdialog.cpp | 32 ++++------ apps/openmw/mwgui/countdialog.hpp | 9 ++- apps/openmw/mwgui/tradewindow.cpp | 32 ++++------ apps/openmw/mwgui/tradewindow.hpp | 9 ++- apps/openmw/mwgui/windowmanagerimp.cpp | 10 +--- components/CMakeLists.txt | 2 +- components/widgets/numericeditbox.cpp | 74 ++++++++++++++++++++++++ components/widgets/numericeditbox.hpp | 45 ++++++++++++++ components/widgets/widgets.cpp | 25 ++++++++ components/widgets/widgets.hpp | 12 ++++ files/mygui/openmw_count_window.layout | 2 +- files/mygui/openmw_trade_window.layout | 2 +- plugins/mygui_resource_plugin/plugin.cpp | 12 +--- 13 files changed, 196 insertions(+), 70 deletions(-) create mode 100644 components/widgets/numericeditbox.cpp create mode 100644 components/widgets/numericeditbox.hpp create mode 100644 components/widgets/widgets.cpp create mode 100644 components/widgets/widgets.hpp diff --git a/apps/openmw/mwgui/countdialog.cpp b/apps/openmw/mwgui/countdialog.cpp index 53c33b3c4..24d0af0d7 100644 --- a/apps/openmw/mwgui/countdialog.cpp +++ b/apps/openmw/mwgui/countdialog.cpp @@ -2,6 +2,8 @@ #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" @@ -19,7 +21,7 @@ namespace MWGui mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CountDialog::onCancelButtonClicked); mOkButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CountDialog::onOkButtonClicked); - mItemEdit->eventEditTextChange += MyGUI::newDelegate(this, &CountDialog::onEditTextChange); + mItemEdit->eventValueChanged += MyGUI::newDelegate(this, &CountDialog::onEditValueChanged); mSlider->eventScrollChangePosition += MyGUI::newDelegate(this, &CountDialog::onSliderMoved); // make sure we read the enter key being pressed to accept multiple items mItemEdit->eventEditSelectAccept += MyGUI::newDelegate(this, &CountDialog::onEnterKeyPressed); @@ -46,7 +48,10 @@ namespace MWGui MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mItemEdit); mSlider->setScrollPosition(maxCount-1); - mItemEdit->setCaption(boost::lexical_cast(maxCount)); + + mItemEdit->setMinValue(1); + mItemEdit->setMaxValue(maxCount); + mItemEdit->setValue(maxCount); } void CountDialog::cancel() //Keeping this here as I don't know if anything else relies on it. @@ -80,30 +85,13 @@ namespace MWGui setVisible(false); } - void CountDialog::onEditTextChange(MyGUI::EditBox* _sender) + void CountDialog::onEditValueChanged(int value) { - 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); + mSlider->setScrollPosition(value-1); } void CountDialog::onSliderMoved(MyGUI::ScrollBar* _sender, size_t _position) { - mItemEdit->setCaption(boost::lexical_cast(_position+1)); + mItemEdit->setValue(_position+1); } } diff --git a/apps/openmw/mwgui/countdialog.hpp b/apps/openmw/mwgui/countdialog.hpp index a00b0b223..a54e99cf4 100644 --- a/apps/openmw/mwgui/countdialog.hpp +++ b/apps/openmw/mwgui/countdialog.hpp @@ -3,6 +3,11 @@ #include "windowbase.hpp" +namespace Gui +{ + class NumericEditBox; +} + namespace MWGui { class CountDialog : public WindowModal @@ -22,7 +27,7 @@ namespace MWGui private: MyGUI::ScrollBar* mSlider; - MyGUI::EditBox* mItemEdit; + Gui::NumericEditBox* mItemEdit; MyGUI::TextBox* mItemText; MyGUI::TextBox* mLabelText; MyGUI::Button* mOkButton; @@ -30,7 +35,7 @@ namespace MWGui void onCancelButtonClicked(MyGUI::Widget* _sender); void onOkButtonClicked(MyGUI::Widget* _sender); - void onEditTextChange(MyGUI::EditBox* _sender); + void onEditValueChanged(int value); void onSliderMoved(MyGUI::ScrollBar* _sender, size_t _position); void onEnterKeyPressed(MyGUI::EditBox* _sender); }; diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 3d888e468..081a1e2c2 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -2,6 +2,8 @@ #include +#include + #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwbase/soundmanager.hpp" @@ -86,7 +88,7 @@ namespace MWGui mDecreaseButton->eventMouseButtonPressed += MyGUI::newDelegate(this, &TradeWindow::onDecreaseButtonPressed); mDecreaseButton->eventMouseButtonReleased += MyGUI::newDelegate(this, &TradeWindow::onBalanceButtonReleased); - mTotalBalance->eventEditTextChange += MyGUI::newDelegate(this, &TradeWindow::onBalanceEdited); + mTotalBalance->eventValueChanged += MyGUI::newDelegate(this, &TradeWindow::onBalanceValueChanged); setCoord(400, 0, 400, 300); } @@ -433,21 +435,14 @@ namespace MWGui MyGUI::ControllerManager::getInstance().removeItem(_sender); } - void TradeWindow::onBalanceEdited(MyGUI::EditBox *_sender) + void TradeWindow::onBalanceValueChanged(int value) { - try - { - unsigned int count = boost::lexical_cast(_sender->getCaption()); - mCurrentBalance = count * (mCurrentBalance >= 0 ? 1 : -1); - updateLabels(); - } - catch (std::bad_cast&) - { - if (_sender->getCaption().empty()) - mTotalBalance->setCaption("0"); - else - mTotalBalance->setCaption(boost::lexical_cast(std::abs(mCurrentBalance))); - } + // Entering a "-" sign inverts the buying/selling state + mCurrentBalance = (mCurrentBalance >= 0 ? 1 : -1) * value; + updateLabels(); + + if (value != std::abs(value)) + mTotalBalance->setValue(std::abs(value)); } void TradeWindow::onIncreaseButtonTriggered() @@ -471,19 +466,16 @@ namespace MWGui mPlayerGold->setCaptionWithReplacing("#{sYourGold} " + boost::lexical_cast(playerGold)); - std::string balanceCaption; if (mCurrentBalance > 0) { mTotalBalanceLabel->setCaptionWithReplacing("#{sTotalSold}"); - balanceCaption = boost::lexical_cast(mCurrentBalance); } else { mTotalBalanceLabel->setCaptionWithReplacing("#{sTotalCost}"); - balanceCaption = boost::lexical_cast(-mCurrentBalance); } - if (balanceCaption != mTotalBalance->getCaption().asUTF8()) // Don't reset text cursor if text doesn't need to be changed - mTotalBalance->setCaption(balanceCaption); + + mTotalBalance->setValue(std::abs(mCurrentBalance)); mMerchantGold->setCaptionWithReplacing("#{sSellerGold} " + boost::lexical_cast(getMerchantGold())); } diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index 11c0614b7..47de9215a 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -3,10 +3,9 @@ #include "container.hpp" -namespace MyGUI +namespace Gui { - class Gui; - class Widget; + class NumericEditBox; } namespace MWGui @@ -54,7 +53,7 @@ namespace MWGui MyGUI::Button* mIncreaseButton; MyGUI::Button* mDecreaseButton; MyGUI::TextBox* mTotalBalanceLabel; - MyGUI::EditBox* mTotalBalance; + Gui::NumericEditBox* mTotalBalance; MyGUI::Widget* mBottomPane; @@ -84,7 +83,7 @@ namespace MWGui void onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); void onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); void onBalanceButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id); - void onBalanceEdited(MyGUI::EditBox* _sender); + void onBalanceValueChanged(int value); void onRepeatClick(MyGUI::Widget* widget, MyGUI::ControllerItem* controller); void addRepeatController(MyGUI::Widget* widget); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 1b400bb58..ef7622a62 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -18,7 +18,7 @@ #include -#include +#include #include #include "../mwbase/inputmanager.hpp" @@ -165,13 +165,6 @@ namespace MWGui MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); @@ -179,6 +172,7 @@ namespace MWGui BookPage::registerMyGUIComponents (); ItemView::registerComponents(); ItemWidget::registerComponents(); + Gui::registerAllWidgets(); MyGUI::FactoryManager::getInstance().registerFactory("Controller"); MyGUI::FactoryManager::getInstance().registerFactory("Controller"); diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index baddfd6a2..d0508e9d4 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -96,7 +96,7 @@ add_component_dir (ogreinit ) add_component_dir (widgets - box imagebutton tags list + box imagebutton tags list numericeditbox widgets ) add_component_dir (fontloader diff --git a/components/widgets/numericeditbox.cpp b/components/widgets/numericeditbox.cpp new file mode 100644 index 000000000..5361b3127 --- /dev/null +++ b/components/widgets/numericeditbox.cpp @@ -0,0 +1,74 @@ +#include "numericeditbox.hpp" + +#include + +namespace Gui +{ + + void NumericEditBox::initialiseOverride() + { + Base::initialiseOverride(); + eventEditTextChange += MyGUI::newDelegate(this, &NumericEditBox::onEditTextChange); + + mValue = 0; + setCaption("0"); + } + + void NumericEditBox::shutdownOverride() + { + Base::shutdownOverride(); + eventEditTextChange -= MyGUI::newDelegate(this, &NumericEditBox::onEditTextChange); + } + + void NumericEditBox::onEditTextChange(MyGUI::EditBox *sender) + { + std::string newCaption = sender->getCaption(); + if (newCaption.empty()) + { + return; + } + + try + { + mValue = boost::lexical_cast(newCaption); + int capped = std::min(mMaxValue, std::max(mValue, mMinValue)); + if (capped != mValue) + { + mValue = capped; + setCaption(MyGUI::utility::toString(mValue)); + } + } + catch (boost::bad_lexical_cast&) + { + setCaption(MyGUI::utility::toString(mValue)); + } + + eventValueChanged(mValue); + } + + void NumericEditBox::setValue(int value) + { + if (value != mValue) + { + setCaption(MyGUI::utility::toString(value)); + mValue = value; + } + } + + void NumericEditBox::setMinValue(int minValue) + { + mMinValue = minValue; + } + + void NumericEditBox::setMaxValue(int maxValue) + { + mMaxValue = maxValue; + } + + void NumericEditBox::onKeyLostFocus(MyGUI::Widget* _new) + { + Base::onKeyLostFocus(_new); + setCaption(MyGUI::utility::toString(mValue)); + } + +} diff --git a/components/widgets/numericeditbox.hpp b/components/widgets/numericeditbox.hpp new file mode 100644 index 000000000..bbc0e48f4 --- /dev/null +++ b/components/widgets/numericeditbox.hpp @@ -0,0 +1,45 @@ +#ifndef OPENMW_NUMERIC_EDIT_BOX_H +#define OPENMW_NUMERIC_EDIT_BOX_H + +#include + +namespace Gui +{ + + /** + * @brief A variant of the EditBox that only allows integer inputs + */ + class NumericEditBox : public MyGUI::EditBox + { + MYGUI_RTTI_DERIVED(NumericEditBox) + + public: + NumericEditBox() + : mValue(0), mMinValue(std::numeric_limits().min()), + mMaxValue(std::numeric_limits().max()) + {} + + void initialiseOverride(); + void shutdownOverride(); + + typedef MyGUI::delegates::CMultiDelegate1 EventHandle_ValueChanged; + EventHandle_ValueChanged eventValueChanged; + + /// @note Does not trigger eventValueChanged + void setValue (int value); + + void setMinValue(int minValue); + void setMaxValue(int maxValue); + private: + void onEditTextChange(MyGUI::EditBox* sender); + void onKeyLostFocus(MyGUI::Widget* _new); + + int mValue; + + int mMinValue; + int mMaxValue; + }; + +} + +#endif diff --git a/components/widgets/widgets.cpp b/components/widgets/widgets.cpp new file mode 100644 index 000000000..b35dc88a4 --- /dev/null +++ b/components/widgets/widgets.cpp @@ -0,0 +1,25 @@ +#include "widgets.hpp" + +#include + +#include "list.hpp" +#include "numericeditbox.hpp" +#include "box.hpp" +#include "imagebutton.hpp" + +namespace Gui +{ + + void registerAllWidgets() + { + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + } + +} diff --git a/components/widgets/widgets.hpp b/components/widgets/widgets.hpp new file mode 100644 index 000000000..d17132135 --- /dev/null +++ b/components/widgets/widgets.hpp @@ -0,0 +1,12 @@ +#ifndef OPENMW_COMPONENTS_WIDGETS_H +#define OPENMW_COMPONENTS_WIDGETS_H + +namespace Gui +{ + + /// Register all widgets from this component with MyGUI's factory manager. + void registerAllWidgets(); + +} + +#endif diff --git a/files/mygui/openmw_count_window.layout b/files/mygui/openmw_count_window.layout index 5f3a30af4..c5fe9e2c5 100644 --- a/files/mygui/openmw_count_window.layout +++ b/files/mygui/openmw_count_window.layout @@ -12,7 +12,7 @@ - + diff --git a/files/mygui/openmw_trade_window.layout b/files/mygui/openmw_trade_window.layout index cb00d7d50..b2017661b 100644 --- a/files/mygui/openmw_trade_window.layout +++ b/files/mygui/openmw_trade_window.layout @@ -44,7 +44,7 @@ - + diff --git a/plugins/mygui_resource_plugin/plugin.cpp b/plugins/mygui_resource_plugin/plugin.cpp index 349b440a5..ac4c9a3d4 100644 --- a/plugins/mygui_resource_plugin/plugin.cpp +++ b/plugins/mygui_resource_plugin/plugin.cpp @@ -11,10 +11,8 @@ #include #include -#include -#include #include -#include +#include #include #include @@ -137,13 +135,7 @@ namespace MyGUIPlugin { MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); - MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + Gui::registerAllWidgets(); } void ResourcePlugin::createTransparentBGTexture() From b75b464495a934ed2df6eebb761f3d791721b62a Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 20:39:14 +0200 Subject: [PATCH 14/15] Move Cancel buttons to right side of dialog (Fixes #1715) --- files/mygui/openmw_count_window.layout | 6 +++--- files/mygui/openmw_edit_note.layout | 6 +++--- files/mygui/openmw_savegame_dialog.layout | 7 +++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/files/mygui/openmw_count_window.layout b/files/mygui/openmw_count_window.layout index c5fe9e2c5..29e07d28e 100644 --- a/files/mygui/openmw_count_window.layout +++ b/files/mygui/openmw_count_window.layout @@ -25,12 +25,12 @@ - - - + + + diff --git a/files/mygui/openmw_edit_note.layout b/files/mygui/openmw_edit_note.layout index 4985b5187..652f67f0c 100644 --- a/files/mygui/openmw_edit_note.layout +++ b/files/mygui/openmw_edit_note.layout @@ -22,12 +22,12 @@ - - - + + + diff --git a/files/mygui/openmw_savegame_dialog.layout b/files/mygui/openmw_savegame_dialog.layout index a2b2bcca7..c97e7f815 100644 --- a/files/mygui/openmw_savegame_dialog.layout +++ b/files/mygui/openmw_savegame_dialog.layout @@ -65,13 +65,12 @@ - - - - + + + From 9fbc7ebc026f63dac24bf79f805d2235bf07ec06 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 25 Sep 2014 20:52:27 +0200 Subject: [PATCH 15/15] Tweak CountDialog layout First time using the LayoutEditor. Success! --- files/mygui/openmw_count_window.layout | 31 ++++++++++---------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/files/mygui/openmw_count_window.layout b/files/mygui/openmw_count_window.layout index 29e07d28e..e9a1cb2c8 100644 --- a/files/mygui/openmw_count_window.layout +++ b/files/mygui/openmw_count_window.layout @@ -1,37 +1,30 @@ - - - - + + + - - + - - + - - + - - + - - - - + + - + - + - +