Use string_view in the remaining Class methods and push string_views closer to the MyGUI boundary

crashfix_debugdraw
Evil Eye 2 years ago
parent a5a0d26976
commit 0df45a90b3

@ -241,13 +241,12 @@ namespace MWBase
/** No guarantee of actually closing the window **/ /** No guarantee of actually closing the window **/
virtual void exitCurrentGuiMode() = 0; 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. /// 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 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 removeStaticMessageBox() = 0;
virtual void interactiveMessageBox (const std::string& message, virtual void interactiveMessageBox(std::string_view message, const std::vector<std::string>& buttons = {}, bool block = false) = 0;
const std::vector<std::string>& buttons = std::vector<std::string>(), bool block=false) = 0;
/// returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox) /// returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox)
virtual int readPressedButton() = 0; virtual int readPressedButton() = 0;

@ -283,18 +283,18 @@ namespace MWClass
return ref->mBase->mData.mArmor * armorSkill / static_cast<float>(iBaseArmorSkill); return ref->mBase->mData.mArmor * armorSkill / static_cast<float>(iBaseArmorSkill);
} }
std::pair<int, std::string> Armor::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const std::pair<int, std::string_view> Armor::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const
{ {
const MWWorld::InventoryStore& invStore = npc.getClass().getInventoryStore(npc); const MWWorld::InventoryStore& invStore = npc.getClass().getInventoryStore(npc);
if (getItemHealth(ptr) == 0) if (getItemHealth(ptr) == 0)
return std::make_pair(0, "#{sInventoryMessage1}"); return {0, "#{sInventoryMessage1}"};
// slots that this item can be equipped in // slots that this item can be equipped in
std::pair<std::vector<int>, bool> slots_ = getEquipmentSlots(ptr); std::pair<std::vector<int>, bool> slots_ = getEquipmentSlots(ptr);
if (slots_.first.empty()) if (slots_.first.empty())
return std::make_pair(0, ""); return {0, {}};
if (npc.getClass().isNpc()) if (npc.getClass().isNpc())
{ {
@ -309,9 +309,9 @@ namespace MWClass
for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr) for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr)
{ {
if((*itr).mPart == ESM::PRT_Head) 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) 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<ESM::Weapon> *ref = weapon->get<ESM::Weapon>(); const MWWorld::LiveCellRef<ESM::Weapon> *ref = weapon->get<ESM::Weapon>();
if (MWMechanics::getWeaponType(ref->mBase->mData.mType)->mFlags & ESM::WeaponType::TwoHanded) 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<MWWorld::Action> Armor::use (const MWWorld::Ptr& ptr, bool force) const std::unique_ptr<MWWorld::Action> Armor::use (const MWWorld::Ptr& ptr, bool force) const

@ -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; 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. ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; std::pair<int, std::string_view> 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 ///< 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 /// Second item in the pair specifies the error message

@ -195,13 +195,13 @@ namespace MWClass
return record->mId; return record->mId;
} }
std::pair<int, std::string> Clothing::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const std::pair<int, std::string_view> Clothing::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const
{ {
// slots that this item can be equipped in // slots that this item can be equipped in
std::pair<std::vector<int>, bool> slots_ = getEquipmentSlots(ptr); std::pair<std::vector<int>, bool> slots_ = getEquipmentSlots(ptr);
if (slots_.first.empty()) if (slots_.first.empty())
return std::make_pair(0, ""); return {0, {}};
if (npc.getClass().isNpc()) if (npc.getClass().isNpc())
{ {
@ -216,14 +216,14 @@ namespace MWClass
for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr) for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr)
{ {
if((*itr).mPart == ESM::PRT_Head) 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) 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<MWWorld::Action> Clothing::use (const MWWorld::Ptr& ptr, bool force) const std::unique_ptr<MWWorld::Action> Clothing::use (const MWWorld::Ptr& ptr, bool force) const

@ -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; 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. ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; std::pair<int, std::string_view> 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. ///< 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 /// Second item in the pair specifies the error message

@ -224,16 +224,16 @@ namespace MWClass
return ref->mBase->mData.mWeight; return ref->mBase->mData.mWeight;
} }
std::pair<int, std::string> Light::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const std::pair<int, std::string_view> Light::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const
{ {
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>(); const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
if (!(ref->mBase->mData.mFlags & ESM::Light::Carry)) 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<ESM::Light>()->mBase->mSound; return ptr.get<ESM::Light>()->mBase->mSound;
} }

@ -72,9 +72,9 @@ namespace MWClass
bool canSell (const MWWorld::ConstPtr& item, int npcServices) const override; bool canSell (const MWWorld::ConstPtr& item, int npcServices) const override;
std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; std::pair<int, std::string_view> 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;
}; };
} }

@ -137,14 +137,14 @@ namespace MWClass
return MWWorld::Ptr(cell.insert(ref), &cell); return MWWorld::Ptr(cell.insert(ref), &cell);
} }
std::pair<int, std::string> Lockpick::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const std::pair<int, std::string_view> Lockpick::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const
{ {
// Do not allow equip tools from inventory during attack // Do not allow equip tools from inventory during attack
if (MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(npc) if (MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(npc)
&& MWBase::Environment::get().getWindowManager()->isGuiMode()) && 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 bool Lockpick::canSell (const MWWorld::ConstPtr& item, int npcServices) const

@ -47,7 +47,7 @@ namespace MWClass
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
///< Return name of inventory icon. ///< Return name of inventory icon.
std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; std::pair<int, std::string_view> canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const override;
std::unique_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override; std::unique_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override;
///< Generate action for using via inventory menu ///< Generate action for using via inventory menu

@ -499,7 +499,7 @@ namespace MWClass
for (std::vector<ESM::PartReference>::const_iterator it = parts.begin(); it != parts.end(); ++it) for (std::vector<ESM::PartReference>::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()) if (partname.empty())
partname = female ? it->mMale : it->mFemale; partname = female ? it->mMale : it->mFemale;
const ESM::BodyPart* part = MWBase::Environment::get().getWorld()->getStore().get<ESM::BodyPart>().search(partname); const ESM::BodyPart* part = MWBase::Environment::get().getWorld()->getStore().get<ESM::BodyPart>().search(partname);
@ -1400,7 +1400,7 @@ namespace MWClass
return ref->mBase->mNpdt.mGold; 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<ESM::NPC>()->mBase->mClass, className); return Misc::StringUtils::ciEqual(ptr.get<ESM::NPC>()->mBase->mClass, className);
} }

@ -149,7 +149,7 @@ namespace MWClass
int getBaseGold(const MWWorld::ConstPtr& ptr) const override; 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; bool canSwim (const MWWorld::ConstPtr &ptr) const override;

@ -137,14 +137,14 @@ namespace MWClass
return MWWorld::Ptr(cell.insert(ref), &cell); return MWWorld::Ptr(cell.insert(ref), &cell);
} }
std::pair<int, std::string> Probe::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const std::pair<int, std::string_view> Probe::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const
{ {
// Do not allow equip tools from inventory during attack // Do not allow equip tools from inventory during attack
if (MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(npc) if (MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(npc)
&& MWBase::Environment::get().getWindowManager()->isGuiMode()) && 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 bool Probe::canSell (const MWWorld::ConstPtr& item, int npcServices) const

@ -47,7 +47,7 @@ namespace MWClass
const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override; const std::string& getInventoryIcon(const MWWorld::ConstPtr& ptr) const override;
///< Return name of inventory icon. ///< Return name of inventory icon.
std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; std::pair<int, std::string_view> canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const override;
std::unique_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override; std::unique_ptr<MWWorld::Action> use (const MWWorld::Ptr& ptr, bool force=false) const override;
///< Generate action for using via inventory menu ///< Generate action for using via inventory menu

@ -271,28 +271,28 @@ namespace MWClass
return record->mId; return record->mId;
} }
std::pair<int, std::string> Weapon::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const std::pair<int, std::string_view> Weapon::canBeEquipped(const MWWorld::ConstPtr& ptr, const MWWorld::Ptr& npc) const
{ {
if (hasItemHealth(ptr) && getItemHealth(ptr) == 0) if (hasItemHealth(ptr) && getItemHealth(ptr) == 0)
return std::make_pair(0, "#{sInventoryMessage1}"); return {0, "#{sInventoryMessage1}"};
// Do not allow equip weapons from inventory during attack // Do not allow equip weapons from inventory during attack
if (MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(npc) if (MWBase::Environment::get().getMechanicsManager()->isAttackingOrSpell(npc)
&& MWBase::Environment::get().getWindowManager()->isGuiMode()) && MWBase::Environment::get().getWindowManager()->isGuiMode())
return std::make_pair(0, "#{sCantEquipWeapWarning}"); return {0, "#{sCantEquipWeapWarning}"};
std::pair<std::vector<int>, bool> slots_ = getEquipmentSlots(ptr); std::pair<std::vector<int>, bool> slots_ = getEquipmentSlots(ptr);
if (slots_.first.empty()) if (slots_.first.empty())
return std::make_pair (0, ""); return {0, {}};
int type = ptr.get<ESM::Weapon>()->mBase->mData.mType; int type = ptr.get<ESM::Weapon>()->mBase->mData.mType;
if(MWMechanics::getWeaponType(type)->mFlags & ESM::WeaponType::TwoHanded) 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<MWWorld::Action> Weapon::use (const MWWorld::Ptr& ptr, bool force) const std::unique_ptr<MWWorld::Action> Weapon::use (const MWWorld::Ptr& ptr, bool force) const

@ -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; 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. ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const override; std::pair<int, std::string_view> 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. ///< 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 /// Second item in the pair specifies the error message

@ -126,7 +126,7 @@ namespace MWGui
if (count == 1) if (count == 1)
winMgr->messageBox("#{sPotionSuccess}"); winMgr->messageBox("#{sPotionSuccess}");
else else
winMgr->messageBox("#{sPotionSuccess} "+mNameEdit->getCaption()+" ("+std::to_string(count)+")"); winMgr->messageBox("#{sPotionSuccess} "+mNameEdit->getCaption().asUTF8()+" ("+std::to_string(count)+")");
break; break;
case MWMechanics::Alchemy::Result_NoEffects: case MWMechanics::Alchemy::Result_NoEffects:
case MWMechanics::Alchemy::Result_RandomFailure: case MWMechanics::Alchemy::Result_RandomFailure:

@ -539,7 +539,7 @@ namespace MWGui
if (!force) if (!force)
{ {
std::pair<int, std::string> canEquip = ptr.getClass().canBeEquipped(ptr, player); auto canEquip = ptr.getClass().canBeEquipped(ptr, player);
if (canEquip.first == 0) if (canEquip.first == 0)
{ {

@ -189,7 +189,7 @@ namespace MWGui
// we may still want to show the label if the caller requested it // we may still want to show the label if the caller requested it
if (mImportantLabel) if (mImportantLabel)
{ {
MWBase::Environment::get().getWindowManager()->messageBox(mLoadingText->getCaption()); MWBase::Environment::get().getWindowManager()->messageBox(mLoadingText->getCaption().asUTF8());
mImportantLabel = false; mImportantLabel = false;
} }
} }

@ -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); MessageBox *box = new MessageBox(*this, message);
box->mCurrentTime = 0; 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; box->mMaxTime = realMessage.length()*mMessageBoxSpeed;
if(stat) if(stat)
@ -122,7 +122,7 @@ namespace MWGui
mStaticMessageBox = nullptr; mStaticMessageBox = nullptr;
} }
bool MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons) bool MessageBoxManager::createInteractiveMessageBox(std::string_view message, const std::vector<std::string>& buttons)
{ {
if (mInterMessageBoxe != nullptr) if (mInterMessageBoxe != nullptr)
{ {
@ -132,7 +132,7 @@ namespace MWGui
mInterMessageBoxe = nullptr; mInterMessageBoxe = nullptr;
} }
mInterMessageBoxe = new InteractiveMessageBox(*this, message, buttons); mInterMessageBoxe = new InteractiveMessageBox(*this, std::string{message}, buttons);
mLastButtonPressed = -1; mLastButtonPressed = -1;
return true; return true;
@ -178,7 +178,7 @@ namespace MWGui
messageBox->setVisible(value); messageBox->setVisible(value);
} }
MessageBox::MessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message) MessageBox::MessageBox(MessageBoxManager& parMessageBoxManager, std::string_view message)
: Layout("openmw_messagebox.layout") : Layout("openmw_messagebox.layout")
, mCurrentTime(0) , mCurrentTime(0)
, mMaxTime(0) , mMaxTime(0)

@ -21,9 +21,9 @@ namespace MWGui
MessageBoxManager (float timePerChar); MessageBoxManager (float timePerChar);
~MessageBoxManager (); ~MessageBoxManager ();
void onFrame (float frameDuration); void onFrame (float frameDuration);
void createMessageBox (const std::string& message, bool stat = false); void createMessageBox(std::string_view message, bool stat = false);
void removeStaticMessageBox (); void removeStaticMessageBox ();
bool createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons); bool createInteractiveMessageBox(std::string_view message, const std::vector<std::string>& buttons);
bool isInteractiveMessageBox (); bool isInteractiveMessageBox ();
int getMessagesCount(); int getMessagesCount();
@ -61,8 +61,7 @@ namespace MWGui
class MessageBox : public Layout class MessageBox : public Layout
{ {
public: public:
MessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message); MessageBox (MessageBoxManager& parMessageBoxManager, std::string_view message);
void setMessage (const std::string& message);
const std::string& getMessage() { return mMessage; }; const std::string& getMessage() { return mMessage; };
int getHeight (); int getHeight ();
void update (int height); void update (int height);

@ -434,7 +434,7 @@ namespace MWGui
} }
else if (key->type == Type_Magic) 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 // Make sure the player still has this spell
MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player); MWMechanics::CreatureStats& stats = player.getClass().getCreatureStats(player);
@ -534,8 +534,7 @@ namespace MWGui
break; break;
} }
case Type_Magic: case Type_Magic:
std::string spellId = button->getUserString("Spell"); key.mId = button->getUserString("Spell");
key.mId = spellId;
break; break;
} }

@ -714,7 +714,7 @@ namespace MWGui
popGuiMode(); popGuiMode();
} }
void WindowManager::interactiveMessageBox(const std::string &message, const std::vector<std::string> &buttons, bool block) void WindowManager::interactiveMessageBox(std::string_view message, const std::vector<std::string> &buttons, bool block)
{ {
mMessageBoxManager->createInteractiveMessageBox(message, buttons); mMessageBoxManager->createInteractiveMessageBox(message, buttons);
updateVisible(); 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) { 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) { } else if (showInDialogueMode != MWGui::ShowInDialogueMode_Only) {
mMessageBoxManager->createMessageBox(message); mMessageBoxManager->createMessageBox(message);
} }
@ -763,7 +763,7 @@ namespace MWGui
mScheduledMessageBoxes.lock()->emplace_back(std::move(message), showInDialogueMode); 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); mMessageBoxManager->createMessageBox(message, true);
} }

@ -272,12 +272,11 @@ namespace MWGui
///Gracefully attempts to exit the topmost GUI mode ///Gracefully attempts to exit the topmost GUI mode
void exitCurrentGuiMode() override; 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 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 removeStaticMessageBox() override;
void interactiveMessageBox (const std::string& message, void interactiveMessageBox(std::string_view message, const std::vector<std::string>& buttons = {}, bool block = false) override;
const std::vector<std::string>& buttons = std::vector<std::string>(), bool block=false) override;
int readPressedButton () override; ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox) int readPressedButton () override; ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox)

@ -567,7 +567,7 @@ namespace MWRender
size_t Animation::detectBlendMask(const osg::Node* node) const 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 */ "", /* Lower body / character root */
"Bip01 Spine1", /* Torso */ "Bip01 Spine1", /* Torso */
"Bip01 L Clavicle", /* Left arm */ "Bip01 L Clavicle", /* Left arm */
@ -742,7 +742,7 @@ namespace MWRender
for(auto iterKey = keys.begin(); iterKey != keys.end(); ++iterKey) 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; return iterKey->first;
} }
} }

@ -816,10 +816,10 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g
return false; return false;
} }
if (!mSoundsDisabled) if (!mSoundsDisabled && group == MWWorld::InventoryStore::Slot_CarriedLeft)
{ {
const MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr); 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()) if (csi != inv.end())
{ {
const auto soundId = csi->getClass().getSound(*csi); const auto soundId = csi->getClass().getSound(*csi);

@ -32,7 +32,7 @@ class TextureOverrideVisitor : public osg::NodeVisitor
} }
traverse(node); traverse(node);
} }
std::string mTexture; std::string_view mTexture;
Resource::ResourceSystem* mResourcesystem; Resource::ResourceSystem* mResourcesystem;
}; };

@ -185,7 +185,7 @@ namespace MWScript
mLocals->mFloats.at (index) = value; mLocals->mFloats.at (index) = value;
} }
void InterpreterContext::messageBox (const std::string& message, void InterpreterContext::messageBox(std::string_view message,
const std::vector<std::string>& buttons) const std::vector<std::string>& buttons)
{ {
if (buttons.empty()) if (buttons.empty())

@ -61,7 +61,7 @@ namespace MWScript
using Interpreter::Context::messageBox; using Interpreter::Context::messageBox;
void messageBox (const std::string& message, void messageBox(std::string_view message,
const std::vector<std::string>& buttons) override; const std::vector<std::string>& buttons) override;
void report (const std::string& message) override; void report (const std::string& message) override;

@ -36,7 +36,7 @@ namespace MWScript
std::string file{runtime.getStringLiteral(runtime[0].mInteger)}; std::string file{runtime.getStringLiteral(runtime[0].mInteger)};
runtime.pop(); runtime.pop();
std::string text{runtime.getStringLiteral(runtime[0].mInteger)}; std::string_view text = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
MWBase::Environment::get().getSoundManager()->say (ptr, file); MWBase::Environment::get().getSoundManager()->say (ptr, file);

@ -34,7 +34,7 @@ namespace MWWorld
if (!mForce) if (!mForce)
{ {
std::pair <int, std::string> result = object.getClass().canBeEquipped (object, actor); auto result = object.getClass().canBeEquipped (object, actor);
// display error message if the player tried to equip something // display error message if the player tried to equip something
if (!result.second.empty() && actor == MWMechanics::getPlayer()) if (!result.second.empty() && actor == MWMechanics::getPlayer())

@ -325,9 +325,9 @@ namespace MWWorld
throw std::runtime_error ("class can't be enchanted"); throw std::runtime_error ("class can't be enchanted");
} }
std::pair<int, std::string> Class::canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const std::pair<int, std::string_view> 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 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"); 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; return false;
} }
@ -478,9 +478,9 @@ namespace MWWorld
return encumbrance / capacity; 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 int Class::getBaseFightRating(const ConstPtr &ptr) const

@ -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; 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. ///< Creates a new record using \a ptr as template, with the given name and the given enchantment applied to it.
virtual std::pair<int, std::string> canBeEquipped(const MWWorld::ConstPtr &ptr, const MWWorld::Ptr &npc) const; virtual std::pair<int, std::string_view> 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. ///< 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 /// Second item in the pair specifies the error message
@ -345,7 +345,7 @@ namespace MWWorld
virtual int getBaseGold(const MWWorld::ConstPtr& ptr) const; 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; virtual DoorState getDoorState (const MWWorld::ConstPtr &ptr) const;
/// This does not actually cause the door to move. Use World::activateDoor instead. /// 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 {} virtual void respawn (const MWWorld::Ptr& ptr) const {}
/// Returns sound id /// 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; virtual int getBaseFightRating (const MWWorld::ConstPtr& ptr) const;

@ -7,7 +7,7 @@
namespace MWWorld 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) : Action(false, target), mMessage(msg)
{ } { }

@ -8,12 +8,12 @@ namespace MWWorld
{ {
class FailedAction : public Action class FailedAction : public Action
{ {
std::string mMessage; std::string_view mMessage;
void executeImp(const Ptr &actor) override; void executeImp(const Ptr &actor) override;
public: public:
FailedAction(const std::string &message = std::string(), const Ptr& target = Ptr()); FailedAction(std::string_view message = {}, const Ptr& target = Ptr());
}; };
} }

@ -2971,7 +2971,7 @@ namespace MWWorld
{ {
MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor); MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor);
std::string message; std::string_view message;
MWWorld::SpellCastState result = MWWorld::SpellCastState::Success; MWWorld::SpellCastState result = MWWorld::SpellCastState::Success;
bool isPlayer = (actor == getPlayerPtr()); bool isPlayer = (actor == getPlayerPtr());

@ -154,7 +154,7 @@ namespace
void setLocalFloat(int index, float value) override { mLocals.setFloat(index, value); }; void setLocalFloat(int index, float value) override { mLocals.setFloat(index, value); };
void messageBox(const std::string& message, const std::vector<std::string>& buttons) override {}; void messageBox(std::string_view message, const std::vector<std::string>& buttons) override {};
void report(const std::string& message) override {}; void report(const std::string& message) override {};

@ -27,10 +27,10 @@ namespace Interpreter
virtual void setLocalFloat (int index, float value) = 0; 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<std::string>& buttons) = 0; const std::vector<std::string>& buttons) = 0;
void messageBox (const std::string& message) void messageBox(std::string_view message)
{ {
std::vector<std::string> empty; std::vector<std::string> empty;
messageBox (message, empty); messageBox (message, empty);

@ -171,7 +171,7 @@ float makeOsgColorComponent(unsigned int value, unsigned int shift)
return float((value >> shift) & 0xFFu) / 255.0f; 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) if (node == nullptr)
return false; return false;

@ -87,7 +87,7 @@ namespace SceneUtil
float makeOsgColorComponent (unsigned int value, unsigned int shift); 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<GlowUpdater> addEnchantedGlow(osg::ref_ptr<osg::Node> node, Resource::ResourceSystem* resourceSystem, const osg::Vec4f& glowColor, float glowDuration=-1); osg::ref_ptr<GlowUpdater> addEnchantedGlow(osg::ref_ptr<osg::Node> node, Resource::ResourceSystem* resourceSystem, const osg::Vec4f& glowColor, float glowDuration=-1);

Loading…
Cancel
Save