diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index cfccb53c36..d5bf6158fd 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -241,13 +241,12 @@ namespace MWBase /** No guarantee of actually closing the window **/ virtual void exitCurrentGuiMode() = 0; - virtual void messageBox (const std::string& message, enum MWGui::ShowInDialogueMode showInDialogueMode = MWGui::ShowInDialogueMode_IfPossible) = 0; + virtual void messageBox(std::string_view message, enum MWGui::ShowInDialogueMode showInDialogueMode = MWGui::ShowInDialogueMode_IfPossible) = 0; /// Puts message into a queue to show on the next update. Thread safe alternative for messageBox. virtual void scheduleMessageBox(std::string message, enum MWGui::ShowInDialogueMode showInDialogueMode = MWGui::ShowInDialogueMode_IfPossible) = 0; - virtual void staticMessageBox(const std::string& message) = 0; + virtual void staticMessageBox(std::string_view message) = 0; virtual void removeStaticMessageBox() = 0; - virtual void interactiveMessageBox (const std::string& message, - const std::vector& buttons = std::vector(), bool block=false) = 0; + virtual void interactiveMessageBox(std::string_view message, const std::vector& buttons = {}, bool block = false) = 0; /// returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox) virtual int readPressedButton() = 0; diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index f3df6d37e4..0eb4ff3e59 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -283,18 +283,18 @@ namespace MWClass return ref->mBase->mData.mArmor * armorSkill / static_cast(iBaseArmorSkill); } - std::pair Armor::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const + std::pair Armor::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const { const MWWorld::InventoryStore& invStore = npc.getClass().getInventoryStore(npc); if (getItemHealth(ptr) == 0) - return std::make_pair(0, "#{sInventoryMessage1}"); + return {0, "#{sInventoryMessage1}"}; // slots that this item can be equipped in std::pair, bool> slots_ = getEquipmentSlots(ptr); if (slots_.first.empty()) - return std::make_pair(0, ""); + return {0, {}}; if (npc.getClass().isNpc()) { @@ -309,9 +309,9 @@ namespace MWClass for(std::vector::iterator itr = parts.begin(); itr != parts.end(); ++itr) { if((*itr).mPart == ESM::PRT_Head) - return std::make_pair(0, "#{sNotifyMessage13}"); + return {0, "#{sNotifyMessage13}"}; if((*itr).mPart == ESM::PRT_LFoot || (*itr).mPart == ESM::PRT_RFoot) - return std::make_pair(0, "#{sNotifyMessage14}"); + return {0, "#{sNotifyMessage14}"}; } } } @@ -327,13 +327,13 @@ namespace MWClass { const MWWorld::LiveCellRef *ref = weapon->get(); if (MWMechanics::getWeaponType(ref->mBase->mData.mType)->mFlags & ESM::WeaponType::TwoHanded) - return std::make_pair(3,""); + return {3, {}}; } - return std::make_pair(1,""); + return {1, {}}; } } - return std::make_pair(1,""); + return {1, {}}; } std::unique_ptr Armor::use (const MWWorld::Ptr& ptr, bool force) const diff --git a/apps/openmw/mwclass/armor.hpp b/apps/openmw/mwclass/armor.hpp index 8906a22e52..5c9732f2ca 100644 --- a/apps/openmw/mwclass/armor.hpp +++ b/apps/openmw/mwclass/armor.hpp @@ -65,7 +65,7 @@ namespace MWClass const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. - std::pair canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; + std::pair canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const override; ///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. \n /// Second item in the pair specifies the error message diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index a6f7c79713..8d74f18eab 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -195,13 +195,13 @@ namespace MWClass return record->mId; } - std::pair Clothing::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const + std::pair Clothing::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const { // slots that this item can be equipped in std::pair, bool> slots_ = getEquipmentSlots(ptr); if (slots_.first.empty()) - return std::make_pair(0, ""); + return {0, {}}; if (npc.getClass().isNpc()) { @@ -216,14 +216,14 @@ namespace MWClass for(std::vector::iterator itr = parts.begin(); itr != parts.end(); ++itr) { if((*itr).mPart == ESM::PRT_Head) - return std::make_pair(0, "#{sNotifyMessage13}"); + return {0, "#{sNotifyMessage13}"}; if((*itr).mPart == ESM::PRT_LFoot || (*itr).mPart == ESM::PRT_RFoot) - return std::make_pair(0, "#{sNotifyMessage15}"); + return {0, "#{sNotifyMessage15}"}; } } } - return std::make_pair (1, ""); + return {1, {}}; } std::unique_ptr Clothing::use (const MWWorld::Ptr& ptr, bool force) const diff --git a/apps/openmw/mwclass/clothing.hpp b/apps/openmw/mwclass/clothing.hpp index 6b014a188d..beca02f77a 100644 --- a/apps/openmw/mwclass/clothing.hpp +++ b/apps/openmw/mwclass/clothing.hpp @@ -57,7 +57,7 @@ namespace MWClass const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. - std::pair canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; + std::pair canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const override; ///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. /// Second item in the pair specifies the error message diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index da96024ed0..e4cbd3838f 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -224,16 +224,16 @@ namespace MWClass return ref->mBase->mData.mWeight; } - std::pair Light::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const + std::pair Light::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const { const MWWorld::LiveCellRef *ref = ptr.get(); if (!(ref->mBase->mData.mFlags & ESM::Light::Carry)) - return std::make_pair(0,""); + return {0, {}}; - return std::make_pair(1,""); + return {1, {}}; } - std::string Light::getSound(const MWWorld::ConstPtr& ptr) const + std::string_view Light::getSound(const MWWorld::ConstPtr& ptr) const { return ptr.get()->mBase->mSound; } diff --git a/apps/openmw/mwclass/light.hpp b/apps/openmw/mwclass/light.hpp index 8fd2f24d70..f803b523a3 100644 --- a/apps/openmw/mwclass/light.hpp +++ b/apps/openmw/mwclass/light.hpp @@ -72,9 +72,9 @@ namespace MWClass bool canSell (const MWWorld::ConstPtr& item, int npcServices) const override; - std::pair canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; + std::pair canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const override; - std::string getSound(const MWWorld::ConstPtr& ptr) const override; + std::string_view getSound(const MWWorld::ConstPtr& ptr) const override; }; } diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index e19b998f4c..cbe251ebcb 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -137,14 +137,14 @@ namespace MWClass return MWWorld::Ptr(cell.insert(ref), &cell); } - std::pair Lockpick::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const + std::pair Lockpick::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const { // Do not allow equip tools from inventory during attack if (MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(npc) && MWBase::Environment::get().getWindowManager()->isGuiMode()) - return std::make_pair(0, "#{sCantEquipWeapWarning}"); + return {0, "#{sCantEquipWeapWarning}"}; - return std::make_pair(1, ""); + return {1, {}}; } bool Lockpick::canSell (const MWWorld::ConstPtr& item, int npcServices) const diff --git a/apps/openmw/mwclass/lockpick.hpp b/apps/openmw/mwclass/lockpick.hpp index ff2d07a9fc..f34579c38d 100644 --- a/apps/openmw/mwclass/lockpick.hpp +++ b/apps/openmw/mwclass/lockpick.hpp @@ -47,7 +47,7 @@ namespace MWClass const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. - std::pair canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; + std::pair canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const override; std::unique_ptr use (const MWWorld::Ptr& ptr, bool force=false) const override; ///< Generate action for using via inventory menu diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index f188c672a2..9f44555c5a 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -499,7 +499,7 @@ namespace MWClass for (std::vector::const_iterator it = parts.begin(); it != parts.end(); ++it) { - std::string partname = female ? it->mFemale : it->mMale; + std::string_view partname = female ? it->mFemale : it->mMale; if (partname.empty()) partname = female ? it->mMale : it->mFemale; const ESM::BodyPart* part = MWBase::Environment::get().getWorld()->getStore().get().search(partname); @@ -1400,7 +1400,7 @@ namespace MWClass return ref->mBase->mNpdt.mGold; } - bool Npc::isClass(const MWWorld::ConstPtr& ptr, const std::string &className) const + bool Npc::isClass(const MWWorld::ConstPtr& ptr, std::string_view className) const { return Misc::StringUtils::ciEqual(ptr.get()->mBase->mClass, className); } diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index cb1b146faf..ebe9b03318 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -149,7 +149,7 @@ namespace MWClass int getBaseGold(const MWWorld::ConstPtr& ptr) const override; - bool isClass(const MWWorld::ConstPtr& ptr, const std::string &className) const override; + bool isClass(const MWWorld::ConstPtr& ptr, std::string_view className) const override; bool canSwim (const MWWorld::ConstPtr &ptr) const override; diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index 105ee7e937..0383027f58 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -137,14 +137,14 @@ namespace MWClass return MWWorld::Ptr(cell.insert(ref), &cell); } - std::pair Probe::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const + std::pair Probe::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const { // Do not allow equip tools from inventory during attack if (MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(npc) && MWBase::Environment::get().getWindowManager()->isGuiMode()) - return std::make_pair(0, "#{sCantEquipWeapWarning}"); + return {0, "#{sCantEquipWeapWarning}"}; - return std::make_pair(1, ""); + return {1, {}}; } bool Probe::canSell (const MWWorld::ConstPtr& item, int npcServices) const diff --git a/apps/openmw/mwclass/probe.hpp b/apps/openmw/mwclass/probe.hpp index d45a870f97..1583887960 100644 --- a/apps/openmw/mwclass/probe.hpp +++ b/apps/openmw/mwclass/probe.hpp @@ -47,7 +47,7 @@ namespace MWClass const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; ///< Return name of inventory icon. - std::pair canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; + std::pair canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const override; std::unique_ptr use (const MWWorld::Ptr& ptr, bool force=false) const override; ///< Generate action for using via inventory menu diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 7f2347a988..fd57b5df6b 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -271,28 +271,28 @@ namespace MWClass return record->mId; } - std::pair Weapon::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const + std::pair Weapon::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const { if (hasItemHealth(ptr) && getItemHealth(ptr) == 0) - return std::make_pair(0, "#{sInventoryMessage1}"); + return {0, "#{sInventoryMessage1}"}; // Do not allow equip weapons from inventory during attack if (MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(npc) && MWBase::Environment::get().getWindowManager()->isGuiMode()) - return std::make_pair(0, "#{sCantEquipWeapWarning}"); + return {0, "#{sCantEquipWeapWarning}"}; std::pair, bool> slots_ = getEquipmentSlots(ptr); if (slots_.first.empty()) - return std::make_pair (0, ""); + return {0, {}}; int type = ptr.get()->mBase->mData.mType; if(MWMechanics::getWeaponType(type)->mFlags & ESM::WeaponType::TwoHanded) { - return std::make_pair (2, ""); + return {2, {}}; } - return std::make_pair(1, ""); + return {1, {}}; } std::unique_ptr Weapon::use (const MWWorld::Ptr& ptr, bool force) const diff --git a/apps/openmw/mwclass/weapon.hpp b/apps/openmw/mwclass/weapon.hpp index deef3ef5e0..ec0d63a65e 100644 --- a/apps/openmw/mwclass/weapon.hpp +++ b/apps/openmw/mwclass/weapon.hpp @@ -63,7 +63,7 @@ namespace MWClass const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const override; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. - std::pair canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; + std::pair canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const override; ///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. /// Second item in the pair specifies the error message diff --git a/apps/openmw/mwgui/alchemywindow.cpp b/apps/openmw/mwgui/alchemywindow.cpp index c0174f3f73..157567c404 100644 --- a/apps/openmw/mwgui/alchemywindow.cpp +++ b/apps/openmw/mwgui/alchemywindow.cpp @@ -126,7 +126,7 @@ namespace MWGui if (count == 1) winMgr->messageBox("#{sPotionSuccess}"); else - winMgr->messageBox("#{sPotionSuccess} "+mNameEdit->getCaption()+" ("+std::to_string(count)+")"); + winMgr->messageBox("#{sPotionSuccess} "+mNameEdit->getCaption().asUTF8()+" ("+std::to_string(count)+")"); break; case MWMechanics::Alchemy::Result_NoEffects: case MWMechanics::Alchemy::Result_RandomFailure: diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index a359efae52..e7e30b76cf 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -539,7 +539,7 @@ namespace MWGui if (!force) { - std::pair canEquip = ptr.getClass().canBeEquipped(ptr, player); + auto canEquip = ptr.getClass().canBeEquipped(ptr, player); if (canEquip.first == 0) { diff --git a/apps/openmw/mwgui/loadingscreen.cpp b/apps/openmw/mwgui/loadingscreen.cpp index e52b1b24ba..f80b24cccd 100644 --- a/apps/openmw/mwgui/loadingscreen.cpp +++ b/apps/openmw/mwgui/loadingscreen.cpp @@ -189,7 +189,7 @@ namespace MWGui // we may still want to show the label if the caller requested it if (mImportantLabel) { - MWBase::Environment::get().getWindowManager()->messageBox(mLoadingText->getCaption()); + MWBase::Environment::get().getWindowManager()->messageBox(mLoadingText->getCaption().asUTF8()); mImportantLabel = false; } } diff --git a/apps/openmw/mwgui/messagebox.cpp b/apps/openmw/mwgui/messagebox.cpp index e9190ffceb..e1ea0a46b9 100644 --- a/apps/openmw/mwgui/messagebox.cpp +++ b/apps/openmw/mwgui/messagebox.cpp @@ -89,11 +89,11 @@ namespace MWGui } } - void MessageBoxManager::createMessageBox (const std::string& message, bool stat) + void MessageBoxManager::createMessageBox(std::string_view message, bool stat) { MessageBox *box = new MessageBox(*this, message); box->mCurrentTime = 0; - std::string realMessage = MyGUI::LanguageManager::getInstance().replaceTags(message); + auto realMessage = MyGUI::LanguageManager::getInstance().replaceTags({message.data(), message.size()}); box->mMaxTime = realMessage.length()*mMessageBoxSpeed; if(stat) @@ -122,7 +122,7 @@ namespace MWGui mStaticMessageBox = nullptr; } - bool MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector& buttons) + bool MessageBoxManager::createInteractiveMessageBox(std::string_view message, const std::vector& buttons) { if (mInterMessageBoxe != nullptr) { @@ -132,7 +132,7 @@ namespace MWGui mInterMessageBoxe = nullptr; } - mInterMessageBoxe = new InteractiveMessageBox(*this, message, buttons); + mInterMessageBoxe = new InteractiveMessageBox(*this, std::string{message}, buttons); mLastButtonPressed = -1; return true; @@ -178,7 +178,7 @@ namespace MWGui messageBox->setVisible(value); } - MessageBox::MessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message) + MessageBox::MessageBox(MessageBoxManager& parMessageBoxManager, std::string_view message) : Layout("openmw_messagebox.layout") , mCurrentTime(0) , mMaxTime(0) diff --git a/apps/openmw/mwgui/messagebox.hpp b/apps/openmw/mwgui/messagebox.hpp index 59118ce6c2..7552bb50d6 100644 --- a/apps/openmw/mwgui/messagebox.hpp +++ b/apps/openmw/mwgui/messagebox.hpp @@ -21,9 +21,9 @@ namespace MWGui MessageBoxManager (float timePerChar); ~MessageBoxManager (); void onFrame (float frameDuration); - void createMessageBox (const std::string& message, bool stat = false); + void createMessageBox(std::string_view message, bool stat = false); void removeStaticMessageBox (); - bool createInteractiveMessageBox (const std::string& message, const std::vector& buttons); + bool createInteractiveMessageBox(std::string_view message, const std::vector& buttons); bool isInteractiveMessageBox (); int getMessagesCount(); @@ -61,8 +61,7 @@ namespace MWGui class MessageBox : public Layout { public: - MessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message); - void setMessage (const std::string& message); + MessageBox (MessageBoxManager& parMessageBoxManager, std::string_view message); const std::string& getMessage() { return mMessage; }; int getHeight (); void update (int height); diff --git a/apps/openmw/mwgui/quickkeysmenu.cpp b/apps/openmw/mwgui/quickkeysmenu.cpp index 9aa110adcb..d028c263b9 100644 --- a/apps/openmw/mwgui/quickkeysmenu.cpp +++ b/apps/openmw/mwgui/quickkeysmenu.cpp @@ -434,7 +434,7 @@ namespace MWGui } else if (key->type == Type_Magic) { - std::string spellId = key->id; + const std::string& spellId = key->id; // Make sure the player still has this spell MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); @@ -534,8 +534,7 @@ namespace MWGui break; } case Type_Magic: - std::string spellId = button->getUserString("Spell"); - key.mId = spellId; + key.mId = button->getUserString("Spell"); break; } diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index af95b49a88..2c1edbdd0c 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -714,7 +714,7 @@ namespace MWGui popGuiMode(); } - void WindowManager::interactiveMessageBox(const std::string &message, const std::vector &buttons, bool block) + void WindowManager::interactiveMessageBox(std::string_view message, const std::vector &buttons, bool block) { mMessageBoxManager->createInteractiveMessageBox(message, buttons); updateVisible(); @@ -749,10 +749,10 @@ namespace MWGui } } - void WindowManager::messageBox (const std::string& message, enum MWGui::ShowInDialogueMode showInDialogueMode) + void WindowManager::messageBox(std::string_view message, enum MWGui::ShowInDialogueMode showInDialogueMode) { if (getMode() == GM_Dialogue && showInDialogueMode != MWGui::ShowInDialogueMode_Never) { - mDialogueWindow->addMessageBox(MyGUI::LanguageManager::getInstance().replaceTags(message)); + mDialogueWindow->addMessageBox(MyGUI::LanguageManager::getInstance().replaceTags({message.data(), message.size()})); } else if (showInDialogueMode != MWGui::ShowInDialogueMode_Only) { mMessageBoxManager->createMessageBox(message); } @@ -763,7 +763,7 @@ namespace MWGui mScheduledMessageBoxes.lock()->emplace_back(std::move(message), showInDialogueMode); } - void WindowManager::staticMessageBox(const std::string& message) + void WindowManager::staticMessageBox(std::string_view message) { mMessageBoxManager->createMessageBox(message, true); } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 81ece9ee1f..4f97c1d07f 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -272,12 +272,11 @@ namespace MWGui ///Gracefully attempts to exit the topmost GUI mode void exitCurrentGuiMode() override; - void messageBox (const std::string& message, enum MWGui::ShowInDialogueMode showInDialogueMode = MWGui::ShowInDialogueMode_IfPossible) override; + void messageBox(std::string_view message, enum MWGui::ShowInDialogueMode showInDialogueMode = MWGui::ShowInDialogueMode_IfPossible) override; void scheduleMessageBox (std::string message, enum MWGui::ShowInDialogueMode showInDialogueMode = MWGui::ShowInDialogueMode_IfPossible) override; - void staticMessageBox(const std::string& message) override; + void staticMessageBox(std::string_view message) override; void removeStaticMessageBox() override; - void interactiveMessageBox (const std::string& message, - const std::vector& buttons = std::vector(), bool block=false) override; + void interactiveMessageBox(std::string_view message, const std::vector& buttons = {}, bool block = false) override; int readPressedButton () override; ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 2a80b6c20b..7aab3ec1d9 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -567,7 +567,7 @@ namespace MWRender size_t Animation::detectBlendMask(const osg::Node* node) const { - static const char sBlendMaskRoots[sNumBlendMasks][32] = { + static const std::string_view sBlendMaskRoots[sNumBlendMasks] = { "", /* Lower body / character root */ "Bip01 Spine1", /* Torso */ "Bip01 L Clavicle", /* Left arm */ @@ -742,7 +742,7 @@ namespace MWRender for(auto iterKey = keys.begin(); iterKey != keys.end(); ++iterKey) { - if(iterKey->second.starts_with(textKey) == 0) + if(iterKey->second.starts_with(textKey)) return iterKey->first; } } diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 8c6758c85b..deb44c14d5 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -816,10 +816,10 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g return false; } - if (!mSoundsDisabled) + if (!mSoundsDisabled && group == MWWorld::InventoryStore::Slot_CarriedLeft) { const MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr); - MWWorld::ConstContainerStoreIterator csi = inv.getSlot(group < 0 ? MWWorld::InventoryStore::Slot_Helmet : group); + MWWorld::ConstContainerStoreIterator csi = inv.getSlot(group); if (csi != inv.end()) { const auto soundId = csi->getClass().getSound(*csi); diff --git a/apps/openmw/mwrender/util.cpp b/apps/openmw/mwrender/util.cpp index 1c7497c395..9b0d1b389d 100644 --- a/apps/openmw/mwrender/util.cpp +++ b/apps/openmw/mwrender/util.cpp @@ -32,7 +32,7 @@ class TextureOverrideVisitor : public osg::NodeVisitor } traverse(node); } - std::string mTexture; + std::string_view mTexture; Resource::ResourceSystem* mResourcesystem; }; diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 6490d07d05..633bcf88a2 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -185,7 +185,7 @@ namespace MWScript mLocals->mFloats.at (index) = value; } - void InterpreterContext::messageBox (const std::string& message, + void InterpreterContext::messageBox(std::string_view message, const std::vector& buttons) { if (buttons.empty()) diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index c53dd88ab3..d36671a7d2 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -61,7 +61,7 @@ namespace MWScript using Interpreter::Context::messageBox; - void messageBox (const std::string& message, + void messageBox(std::string_view message, const std::vector& buttons) override; void report (const std::string& message) override; diff --git a/apps/openmw/mwscript/soundextensions.cpp b/apps/openmw/mwscript/soundextensions.cpp index 1e0ad12946..744f94b02a 100644 --- a/apps/openmw/mwscript/soundextensions.cpp +++ b/apps/openmw/mwscript/soundextensions.cpp @@ -36,7 +36,7 @@ namespace MWScript std::string file{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - std::string text{runtime.getStringLiteral(runtime[0].mInteger)}; + std::string_view text = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); MWBase::Environment::get().getSoundManager()->say (ptr, file); diff --git a/apps/openmw/mwworld/actionequip.cpp b/apps/openmw/mwworld/actionequip.cpp index 8ce3a130ab..426f4dd7b8 100644 --- a/apps/openmw/mwworld/actionequip.cpp +++ b/apps/openmw/mwworld/actionequip.cpp @@ -34,7 +34,7 @@ namespace MWWorld if (!mForce) { - std::pair result = object.getClass().canBeEquipped (object, actor); + auto result = object.getClass().canBeEquipped (object, actor); // display error message if the player tried to equip something if (!result.second.empty() && actor == MWMechanics::getPlayer()) diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 7639b5d8b6..93009c26cb 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -325,9 +325,9 @@ namespace MWWorld throw std::runtime_error ("class can't be enchanted"); } - std::pair Class::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const + std::pair Class::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const { - return std::make_pair (1, ""); + return {1, {}}; } void Class::adjustPosition(const MWWorld::Ptr& ptr, bool force) const @@ -449,7 +449,7 @@ namespace MWWorld throw std::runtime_error("class does not support base gold"); } - bool Class::isClass(const MWWorld::ConstPtr& ptr, const std::string &className) const + bool Class::isClass(const MWWorld::ConstPtr& ptr, std::string_view className) const { return false; } @@ -478,9 +478,9 @@ namespace MWWorld return encumbrance / capacity; } - std::string Class::getSound(const MWWorld::ConstPtr&) const + std::string_view Class::getSound(const MWWorld::ConstPtr&) const { - return std::string(); + return {}; } int Class::getBaseFightRating(const ConstPtr &ptr) const diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index 4cc16ee7f2..1b1f1b4924 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -281,7 +281,7 @@ namespace MWWorld virtual const std::string& applyEnchantment(const MWWorld::ConstPtr& ptr, const std::string& enchId, int enchCharge, const std::string& newName) const; ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it. - virtual std::pair canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const; + virtual std::pair canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const; ///< Return 0 if player cannot equip item. 1 if can equip. 2 if it's twohanded weapon. 3 if twohanded weapon conflicts with that. /// Second item in the pair specifies the error message @@ -345,7 +345,7 @@ namespace MWWorld virtual int getBaseGold(const MWWorld::ConstPtr& ptr) const; - virtual bool isClass(const MWWorld::ConstPtr& ptr, const std::string &className) const; + virtual bool isClass(const MWWorld::ConstPtr& ptr, std::string_view className) const; virtual DoorState getDoorState (const MWWorld::ConstPtr &ptr) const; /// This does not actually cause the door to move. Use World::activateDoor instead. @@ -354,7 +354,7 @@ namespace MWWorld virtual void respawn (const MWWorld::Ptr& ptr) const {} /// Returns sound id - virtual std::string getSound(const MWWorld::ConstPtr& ptr) const; + virtual std::string_view getSound(const MWWorld::ConstPtr& ptr) const; virtual int getBaseFightRating (const MWWorld::ConstPtr& ptr) const; diff --git a/apps/openmw/mwworld/failedaction.cpp b/apps/openmw/mwworld/failedaction.cpp index ec8314712e..3d5ca55690 100644 --- a/apps/openmw/mwworld/failedaction.cpp +++ b/apps/openmw/mwworld/failedaction.cpp @@ -7,7 +7,7 @@ namespace MWWorld { - FailedAction::FailedAction(const std::string &msg, const Ptr& target) + FailedAction::FailedAction(std::string_view msg, const Ptr& target) : Action(false, target), mMessage(msg) { } diff --git a/apps/openmw/mwworld/failedaction.hpp b/apps/openmw/mwworld/failedaction.hpp index 2a201cdb3b..80fd53cc79 100644 --- a/apps/openmw/mwworld/failedaction.hpp +++ b/apps/openmw/mwworld/failedaction.hpp @@ -8,12 +8,12 @@ namespace MWWorld { class FailedAction : public Action { - std::string mMessage; + std::string_view mMessage; void executeImp(const Ptr &actor) override; public: - FailedAction(const std::string &message = std::string(), const Ptr& target = Ptr()); + FailedAction(std::string_view message = {}, const Ptr& target = Ptr()); }; } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 5864537c4b..18b33616cd 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -2971,7 +2971,7 @@ namespace MWWorld { MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor); - std::string message; + std::string_view message; MWWorld::SpellCastState result = MWWorld::SpellCastState::Success; bool isPlayer = (actor == getPlayerPtr()); diff --git a/apps/openmw_test_suite/mwscript/test_utils.hpp b/apps/openmw_test_suite/mwscript/test_utils.hpp index 67173810ca..407572e961 100644 --- a/apps/openmw_test_suite/mwscript/test_utils.hpp +++ b/apps/openmw_test_suite/mwscript/test_utils.hpp @@ -154,7 +154,7 @@ namespace void setLocalFloat(int index, float value) override { mLocals.setFloat(index, value); }; - void messageBox(const std::string& message, const std::vector& buttons) override {}; + void messageBox(std::string_view message, const std::vector& buttons) override {}; void report(const std::string& message) override {}; diff --git a/components/interpreter/context.hpp b/components/interpreter/context.hpp index 7ff627be0a..c78b572353 100644 --- a/components/interpreter/context.hpp +++ b/components/interpreter/context.hpp @@ -27,10 +27,10 @@ namespace Interpreter virtual void setLocalFloat (int index, float value) = 0; - virtual void messageBox (const std::string& message, + virtual void messageBox(std::string_view message, const std::vector& buttons) = 0; - void messageBox (const std::string& message) + void messageBox(std::string_view message) { std::vector empty; messageBox (message, empty); diff --git a/components/sceneutil/util.cpp b/components/sceneutil/util.cpp index 52b7be1798..b533d805e3 100644 --- a/components/sceneutil/util.cpp +++ b/components/sceneutil/util.cpp @@ -171,7 +171,7 @@ float makeOsgColorComponent(unsigned int value, unsigned int shift) return float((value >> shift) & 0xFFu) / 255.0f; } -bool hasUserDescription(const osg::Node* node, const std::string& pattern) +bool hasUserDescription(const osg::Node* node, std::string_view pattern) { if (node == nullptr) return false; diff --git a/components/sceneutil/util.hpp b/components/sceneutil/util.hpp index 18bf8c7728..5494198252 100644 --- a/components/sceneutil/util.hpp +++ b/components/sceneutil/util.hpp @@ -87,7 +87,7 @@ namespace SceneUtil float makeOsgColorComponent (unsigned int value, unsigned int shift); - bool hasUserDescription(const osg::Node* node, const std::string& pattern); + bool hasUserDescription(const osg::Node* node, std::string_view pattern); osg::ref_ptr addEnchantedGlow(osg::ref_ptr node, Resource::ResourceSystem* resourceSystem, const osg::Vec4f& glowColor, float glowDuration=-1);