Merge branch 'string_me_along' into 'master'

Yet another string_view MR

See merge request OpenMW/openmw!2333
crashfix_debugdraw
psi29a 2 years ago
commit c260a0d4c2

@ -260,7 +260,7 @@ namespace MWBase
* @param id Identifier for the GMST setting, e.g. "aName"
* @param default Default value if the GMST setting cannot be used.
*/
virtual std::string getGameSettingString(const std::string &id, const std::string &default_) = 0;
virtual std::string_view getGameSettingString(std::string_view id, std::string_view default_) = 0;
virtual void processChangedSettings(const std::set< std::pair<std::string, std::string> >& changed) = 0;

@ -24,6 +24,7 @@
#include "../mwrender/vismask.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwmechanics/npcstats.hpp"
@ -96,7 +97,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
std::string text;
if (MWBase::Environment::get().getWindowManager()->getFullHelp())

@ -15,6 +15,7 @@
#include "../mwrender/renderinginterface.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "classmodel.hpp"
@ -88,7 +89,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -23,6 +23,7 @@
#include "../mwmechanics/weapontype.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "classmodel.hpp"
@ -115,7 +116,7 @@ namespace MWClass
{
const MWWorld::LiveCellRef<ESM::Armor> *ref = ptr.get<ESM::Armor>();
std::string typeGmst;
std::string_view typeGmst;
switch (ref->mBase->mData.mType)
{
@ -194,7 +195,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;
@ -298,7 +299,7 @@ namespace MWClass
if (npc.getClass().isNpc())
{
std::string npcRace = npc.get<ESM::NPC>()->mBase->mRace;
const std::string& npcRace = npc.get<ESM::NPC>()->mBase->mRace;
// Beast races cannot equip shoes / boots, or full helms (head part vs hair part)
const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace);

@ -18,6 +18,7 @@
#include "../mwrender/renderinginterface.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwmechanics/npcstats.hpp"
@ -105,7 +106,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -15,6 +15,7 @@
#include "../mwworld/esmstore.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
@ -152,7 +153,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;
@ -205,7 +206,7 @@ namespace MWClass
if (npc.getClass().isNpc())
{
std::string npcRace = npc.get<ESM::NPC>()->mBase->mRace;
const std::string& npcRace = npc.get<ESM::NPC>()->mBase->mRace;
// Beast races cannot equip shoes / boots, or full helms (head part vs hair part)
const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace);

@ -22,6 +22,7 @@
#include "../mwworld/inventorystore.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/animation.hpp"
#include "../mwrender/objects.hpp"
@ -147,8 +148,8 @@ namespace MWClass
return action;
}
const std::string lockedSound = "LockedChest";
const std::string trapActivationSound = "Disarm Trap Fail";
const std::string_view lockedSound = "LockedChest";
const std::string_view trapActivationSound = "Disarm Trap Fail";
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
MWWorld::InventoryStore& invStore = player.getClass().getInventoryStore(player);
@ -156,9 +157,9 @@ namespace MWClass
bool isLocked = ptr.getCellRef().getLockLevel() > 0;
bool isTrapped = !ptr.getCellRef().getTrap().empty();
bool hasKey = false;
std::string keyName;
std::string_view keyName;
const std::string keyId = ptr.getCellRef().getKey();
const std::string& keyId = ptr.getCellRef().getKey();
if (!keyId.empty())
{
MWWorld::Ptr keyPtr = invStore.search(keyId);
@ -171,7 +172,7 @@ namespace MWClass
if (isLocked && hasKey)
{
MWBase::Environment::get().getWindowManager ()->messageBox (keyName + " #{sKeyUsed}");
MWBase::Environment::get().getWindowManager ()->messageBox(std::string{keyName} + " #{sKeyUsed}");
ptr.getCellRef().unlock();
// using a key disarms the trap
if(isTrapped)
@ -204,7 +205,7 @@ namespace MWClass
}
else
{
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string(), ptr);
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string_view{}, ptr);
action->setSound(lockedSound);
return action;
}
@ -246,7 +247,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()});
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name));
std::string text;
int lockLevel = ptr.getCellRef().getLockLevel();

@ -40,6 +40,7 @@
#include "../mwrender/objects.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "classmodel.hpp"
@ -589,7 +590,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()});
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name));
std::string text;
if (MWBase::Environment::get().getWindowManager()->getFullHelp())

@ -132,7 +132,7 @@ namespace MWClass
ptr.get<ESM::CreatureLevList>();
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
std::string id = MWMechanics::getLevelledItem(ref->mBase, true, prng);
std::string_view id = MWMechanics::getLevelledItem(ref->mBase, true, prng);
if (!id.empty())
{

@ -24,6 +24,7 @@
#include "../mwworld/containerstore.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
@ -118,18 +119,11 @@ namespace MWClass
const std::string_view lockedSound = "LockedDoor";
const std::string_view trapActivationSound = "Disarm Trap Fail";
MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor);
bool isLocked = ptr.getCellRef().getLockLevel() > 0;
bool isTrapped = !ptr.getCellRef().getTrap().empty();
bool hasKey = false;
std::string keyName;
// FIXME: If NPC activate teleporting door, it can lead to crash due to iterator invalidation in the Actors update.
// Make such activation a no-op for now, like how it is in the vanilla game.
if (actor != MWMechanics::getPlayer() && ptr.getCellRef().getTeleport())
{
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string(), ptr);
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string_view{}, ptr);
action->setSound(lockedSound);
return action;
}
@ -150,7 +144,13 @@ namespace MWClass
}
}
const std::string keyId = ptr.getCellRef().getKey();
MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor);
bool isLocked = ptr.getCellRef().getLockLevel() > 0;
bool isTrapped = !ptr.getCellRef().getTrap().empty();
bool hasKey = false;
std::string_view keyName;
const std::string& keyId = ptr.getCellRef().getKey();
if (!keyId.empty())
{
MWWorld::Ptr keyPtr = invStore.search(keyId);
@ -164,7 +164,7 @@ namespace MWClass
if (isLocked && hasKey)
{
if(actor == MWMechanics::getPlayer())
MWBase::Environment::get().getWindowManager()->messageBox(keyName + " #{sKeyUsed}");
MWBase::Environment::get().getWindowManager()->messageBox(std::string{keyName} + " #{sKeyUsed}");
ptr.getCellRef().unlock(); //Call the function here. because that makes sense.
// using a key disarms the trap
if(isTrapped)
@ -236,7 +236,7 @@ namespace MWClass
else
{
// locked, and we can't open.
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string(), ptr);
std::unique_ptr<MWWorld::Action> action = std::make_unique<MWWorld::FailedAction>(std::string_view{}, ptr);
action->setSound(lockedSound);
return action;
}
@ -268,7 +268,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()});
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name));
std::string text;

@ -14,6 +14,7 @@
#include "../mwworld/actioneat.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
@ -100,7 +101,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -19,6 +19,7 @@
#include "../mwphysics/physicssystem.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
@ -151,7 +152,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -14,6 +14,7 @@
#include "../mwworld/cellstore.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
@ -99,7 +100,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -16,6 +16,7 @@
#include "../mwworld/actionsoulgem.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
@ -142,7 +143,7 @@ namespace MWClass
countString = " (" + std::to_string(count) + ")";
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -55,6 +55,7 @@
#include "../mwrender/npcanimation.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
namespace
{
@ -1118,7 +1119,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()});
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name));
if(fullHelp && !ref->mBase->mName.empty() && ptr.getRefData().getCustomData() && ptr.getRefData().getCustomData()->asNpcCustomData().mNpcStats.isWerewolf())
{
info.caption += " (";
@ -1150,7 +1151,7 @@ namespace MWClass
{
MWBase::Environment::get().getWorld()->breakInvisibility(actor);
MWMechanics::CastSpell cast(actor, actor);
std::string recordId = consumable.getCellRef().getRefId();
const std::string& recordId = consumable.getCellRef().getRefId();
MWBase::Environment::get().getLuaManager()->itemConsumed(consumable, actor);
actor.getClass().getContainerStore(actor).remove(consumable, 1, actor);
return cast.cast(recordId);

@ -13,6 +13,7 @@
#include "../mwworld/cellstore.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
@ -92,7 +93,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -14,6 +14,7 @@
#include "../mwworld/cellstore.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
@ -99,7 +100,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -12,6 +12,7 @@
#include "../mwworld/actionrepair.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
@ -101,7 +102,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -20,6 +20,7 @@
#include "../mwmechanics/weapontype.hpp"
#include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
@ -149,7 +150,7 @@ namespace MWClass
MWGui::ToolTipInfo info;
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.caption = MyGUI::TextIterator::toTagsString(MWGui::toUString(name)) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();

@ -45,7 +45,7 @@ namespace MWDialogue
Entry::Entry (const ESM::JournalEntry& record) : mInfoId (record.mInfo), mText (record.mText), mActorName(record.mActorName) {}
std::string Entry::getText() const
const std::string& Entry::getText() const
{
return mText;
}

@ -30,7 +30,7 @@ namespace MWDialogue
Entry (const ESM::JournalEntry& record);
std::string getText() const;
const std::string& getText() const;
void write (ESM::JournalEntry& entry) const;
};

@ -96,7 +96,7 @@ namespace MWDialogue
if(quest.addEntry(entry)) // we are doing slicing on purpose here
{
// Restart all "other" quests with the same name as well
std::string name = quest.getName();
std::string_view name = quest.getName();
for(auto& it : mQuests)
{
if(it.second.isFinished() && Misc::StringUtils::ciEqual(it.second.getName(), name))

@ -23,7 +23,7 @@ namespace MWDialogue
: Topic (state.mTopic), mIndex (state.mState), mFinished (state.mFinished!=0)
{}
std::string Quest::getName() const
std::string_view Quest::getName() const
{
const ESM::Dialogue *dialogue =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().find (mTopic);
@ -33,7 +33,7 @@ namespace MWDialogue
if (iter->mQuestStatus==ESM::DialInfo::QS_Name)
return iter->mResponse;
return "";
return {};
}
int Quest::getIndex() const

@ -24,7 +24,7 @@ namespace MWDialogue
Quest (const ESM::QuestState& state);
std::string getName() const override;
std::string_view getName() const override;
///< May be an empty string
int getIndex() const;

@ -44,7 +44,7 @@ namespace MWDialogue
return mTopic;
}
std::string Topic::getName() const
std::string_view Topic::getName() const
{
return mName;
}

@ -47,7 +47,7 @@ namespace MWDialogue
std::string getTopic() const;
virtual std::string getName() const;
virtual std::string_view getName() const;
void removeLastAddedResponse(std::string_view actorName);

@ -24,6 +24,7 @@
#include "sortfilteritemmodel.hpp"
#include "itemview.hpp"
#include "itemwidget.hpp"
#include "ustring.hpp"
#include "widgets.hpp"
namespace MWGui
@ -151,10 +152,9 @@ namespace MWGui
void AlchemyWindow::initFilter()
{
auto const& wm = MWBase::Environment::get().getWindowManager();
auto const ingredient = wm->getGameSettingString("sIngredients", "Ingredients");
auto const effect = wm->getGameSettingString("sMagicEffects", "Magic Effects");
std::string_view ingredient = wm->getGameSettingString("sIngredients", "Ingredients");
if (mFilterType->getCaption() == ingredient)
if (mFilterType->getCaption() == toUString(ingredient))
mCurrentFilter = FilterType::ByName;
else
mCurrentFilter = FilterType::ByEffect;
@ -166,13 +166,12 @@ namespace MWGui
void AlchemyWindow::switchFilterType(MyGUI::Widget* _sender)
{
auto const& wm = MWBase::Environment::get().getWindowManager();
auto const ingredient = wm->getGameSettingString("sIngredients", "Ingredients");
auto const effect = wm->getGameSettingString("sMagicEffects", "Magic Effects");
MyGUI::UString ingredient = toUString(wm->getGameSettingString("sIngredients", "Ingredients"));
auto *button = _sender->castType<MyGUI::Button>();
if (button->getCaption() == ingredient)
{
button->setCaption(effect);
button->setCaption(toUString(wm->getGameSettingString("sMagicEffects", "Magic Effects")));
mCurrentFilter = FilterType::ByEffect;
}
else

@ -15,6 +15,7 @@
#include "../mwworld/esmstore.hpp"
#include "../mwworld/player.hpp"
#include "ustring.hpp"
#include "widgets.hpp"
namespace
@ -51,7 +52,7 @@ namespace MWGui
MyGUI::Button* okButton;
getWidget(okButton, "OKButton");
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", ""));
okButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &BirthDialog::onOkClicked);
updateBirths();
@ -64,9 +65,9 @@ namespace MWGui
getWidget(okButton, "OKButton");
if (shown)
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", ""));
okButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", {})));
else
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", ""));
okButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
}
void BirthDialog::onOpen()
@ -235,7 +236,7 @@ namespace MWGui
if (!categories[category].spells.empty())
{
MyGUI::TextBox* label = mSpellArea->createWidget<MyGUI::TextBox>("SandBrightText", coord, MyGUI::Align::Default, std::string("Label"));
label->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString(categories[category].label, ""));
label->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString(categories[category].label, {})));
mSpellItems.push_back(label);
coord.top += lineHeight;

@ -18,6 +18,7 @@
#include <components/vfs/manager.hpp>
#include "tooltips.hpp"
#include "ustring.hpp"
namespace
{
@ -37,7 +38,7 @@ namespace MWGui
GenerateClassResultDialog::GenerateClassResultDialog()
: WindowModal("openmw_chargen_generate_class_result.layout")
{
setText("ReflectT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sMessageQuestionAnswer1", ""));
setText("ReflectT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sMessageQuestionAnswer1", {}));
getWidget(mClassImage, "ClassImage");
getWidget(mClassName, "ClassName");
@ -55,11 +56,6 @@ namespace MWGui
center();
}
std::string GenerateClassResultDialog::getClassId() const
{
return mClassName->getCaption();
}
void GenerateClassResultDialog::setClassId(const std::string &classId)
{
mCurrentClassId = classId;
@ -128,9 +124,9 @@ namespace MWGui
getWidget(okButton, "OKButton");
if (shown)
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", ""));
okButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", {})));
else
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", ""));
okButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
}
void PickClassDialog::onOpen()
@ -253,12 +249,12 @@ namespace MWGui
ESM::Class::Specialization specialization = static_cast<ESM::Class::Specialization>(klass->mData.mSpecialization);
static const char *specIds[3] = {
static const std::string_view specIds[3] = {
"sSpecializationCombat",
"sSpecializationMagic",
"sSpecializationStealth"
};
std::string specName = MWBase::Environment::get().getWindowManager()->getGameSettingString(specIds[specialization], specIds[specialization]);
std::string specName{MWBase::Environment::get().getWindowManager()->getGameSettingString(specIds[specialization], specIds[specialization])};
mSpecializationName->setCaption(specName);
ToolTips::createSpecializationToolTip(mSpecializationName, specName, specialization);
@ -388,10 +384,10 @@ namespace MWGui
{
setText("");
ButtonList buttons;
buttons.push_back(MWBase::Environment::get().getWindowManager()->getGameSettingString("sClassChoiceMenu1", ""));
buttons.push_back(MWBase::Environment::get().getWindowManager()->getGameSettingString("sClassChoiceMenu2", ""));
buttons.push_back(MWBase::Environment::get().getWindowManager()->getGameSettingString("sClassChoiceMenu3", ""));
buttons.push_back(MWBase::Environment::get().getWindowManager()->getGameSettingString("sBack", ""));
buttons.emplace_back(MWBase::Environment::get().getWindowManager()->getGameSettingString("sClassChoiceMenu1", {}));
buttons.emplace_back(MWBase::Environment::get().getWindowManager()->getGameSettingString("sClassChoiceMenu2", {}));
buttons.emplace_back(MWBase::Environment::get().getWindowManager()->getGameSettingString("sClassChoiceMenu3", {}));
buttons.emplace_back(MWBase::Environment::get().getWindowManager()->getGameSettingString("sBack", {}));
setButtons(buttons);
}
@ -415,8 +411,8 @@ namespace MWGui
mFavoriteAttribute0->eventClicked += MyGUI::newDelegate(this, &CreateClassDialog::onAttributeClicked);
mFavoriteAttribute1->eventClicked += MyGUI::newDelegate(this, &CreateClassDialog::onAttributeClicked);
setText("MajorSkillT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sSkillClassMajor", ""));
setText("MinorSkillT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sSkillClassMinor", ""));
setText("MajorSkillT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sSkillClassMajor", {}));
setText("MinorSkillT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sSkillClassMinor", {}));
for(int i = 0; i < 5; i++)
{
char theIndex = '0'+i;
@ -431,7 +427,7 @@ namespace MWGui
skill->eventClicked += MyGUI::newDelegate(this, &CreateClassDialog::onSkillClicked);
}
setText("LabelT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sName", ""));
setText("LabelT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sName", {}));
getWidget(mEditName, "EditName");
// Make sure the edit box has focus
@ -535,9 +531,9 @@ namespace MWGui
getWidget(okButton, "OKButton");
if (shown)
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", ""));
okButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", {})));
else
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", ""));
okButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
}
// widget controls
@ -569,12 +565,12 @@ namespace MWGui
void CreateClassDialog::setSpecialization(int id)
{
mSpecializationId = (ESM::Class::Specialization) id;
static const char *specIds[3] = {
static const std::string_view specIds[3] = {
"sSpecializationCombat",
"sSpecializationMagic",
"sSpecializationStealth"
};
std::string specName = MWBase::Environment::get().getWindowManager()->getGameSettingString(specIds[mSpecializationId], specIds[mSpecializationId]);
std::string specName{MWBase::Environment::get().getWindowManager()->getGameSettingString(specIds[mSpecializationId], specIds[mSpecializationId])};
mSpecializationName->setCaption(specName);
ToolTips::createSpecializationToolTip(mSpecializationName, specName, mSpecializationId);
}
@ -674,9 +670,9 @@ namespace MWGui
getWidget(mSpecialization0, "Specialization0");
getWidget(mSpecialization1, "Specialization1");
getWidget(mSpecialization2, "Specialization2");
std::string combat = MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Class::sGmstSpecializationIds[ESM::Class::Combat], "");
std::string magic = MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Class::sGmstSpecializationIds[ESM::Class::Magic], "");
std::string stealth = MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Class::sGmstSpecializationIds[ESM::Class::Stealth], "");
std::string combat{MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Class::sGmstSpecializationIds[ESM::Class::Combat], {})};
std::string magic{MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Class::sGmstSpecializationIds[ESM::Class::Magic], {})};
std::string stealth{MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Class::sGmstSpecializationIds[ESM::Class::Stealth], {})};
mSpecialization0->setCaption(combat);
mSpecialization0->eventMouseButtonClick += MyGUI::newDelegate(this, &SelectSpecializationDialog::onSpecializationClicked);
@ -880,7 +876,7 @@ namespace MWGui
MyGUI::Button* okButton;
getWidget(okButton, "OKButton");
okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &DescriptionDialog::onOkClicked);
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sInputMenu1", ""));
okButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sInputMenu1", {})));
// Make sure the edit box has focus
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);

@ -71,7 +71,6 @@ namespace MWGui
public:
GenerateClassResultDialog();
std::string getClassId() const;
void setClassId(const std::string &classId);
bool exit() override { return false; }

@ -25,6 +25,7 @@
#include "itemwidget.hpp"
#include "sortfilteritemmodel.hpp"
#include "ustring.hpp"
namespace MWGui
{
@ -100,7 +101,7 @@ namespace MWGui
else
{
std::string_view name = item.getClass().getName(item);
mName->setCaption({name.data(), name.size()});
mName->setCaption(toUString(name));
mItemBox->setItem(item);
mItemBox->setUserString ("ToolTipType", "ItemPtr");
mItemBox->setUserData(MWWorld::Ptr(item));
@ -119,19 +120,19 @@ namespace MWGui
switch(mEnchanting.getCastStyle())
{
case ESM::Enchantment::CastOnce:
mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastOnce","Cast Once"));
mTypeButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastOnce", "Cast Once")));
setConstantEffect(false);
break;
case ESM::Enchantment::WhenStrikes:
mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastWhenStrikes", "When Strikes"));
mTypeButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastWhenStrikes", "When Strikes")));
setConstantEffect(false);
break;
case ESM::Enchantment::WhenUsed:
mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastWhenUsed", "When Used"));
mTypeButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastWhenUsed", "When Used")));
setConstantEffect(false);
break;
case ESM::Enchantment::ConstantEffect:
mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastConstant", "Cast Constant"));
mTypeButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastConstant", "Cast Constant")));
setConstantEffect(true);
break;
}

@ -17,6 +17,7 @@
#include "itemmodel.hpp"
#include "itemwidget.hpp"
#include "ustring.hpp"
namespace MWGui
{
@ -170,7 +171,7 @@ namespace MWGui
void ItemChargeView::updateLine(const ItemChargeView::Line& line)
{
std::string_view name = line.mItemPtr.getClass().getName(line.mItemPtr);
line.mText->setCaption({name.data(), name.size()});
line.mText->setCaption(toUString(name));
line.mCharge->setVisible(false);
switch (mDisplayMode)

@ -35,12 +35,12 @@ struct JournalViewModelImpl : JournalViewModel
}
/// \todo replace this nasty BS
static Utf8Span toUtf8Span (std::string const & str)
static Utf8Span toUtf8Span(std::string_view str)
{
if (str.size () == 0)
return Utf8Span (Utf8Point (nullptr), Utf8Point (nullptr));
Utf8Point point = reinterpret_cast <Utf8Point> (str.c_str ());
Utf8Point point = reinterpret_cast<Utf8Point>(str.data());
return Utf8Span (point, point + str.size ());
}
@ -191,11 +191,11 @@ struct JournalViewModelImpl : JournalViewModel
};
void visitQuestNames (bool active_only, std::function <void (const std::string&, bool)> visitor) const override
void visitQuestNames(bool active_only, std::function <void (std::string_view, bool)> visitor) const override
{
MWBase::Journal * journal = MWBase::Environment::get ().getJournal ();
std::set<std::string> visitedQuests;
std::set<std::string, std::less<>> visitedQuests;
// Note that for purposes of the journal GUI, quests are identified by the name, not the ID, so several
// different quest IDs can end up in the same quest log. A quest log should be considered finished
@ -225,7 +225,7 @@ struct JournalViewModelImpl : JournalViewModel
visitor (quest.getName(), isFinished);
visitedQuests.insert(quest.getName());
visitedQuests.emplace(quest.getName());
}
}
}
@ -305,7 +305,7 @@ struct JournalViewModelImpl : JournalViewModel
visitor (toUtf8Span (topic.getName()));
}
void visitTopicNamesStartingWith (Utf8Stream::UnicodeChar character, std::function < void (const std::string&) > visitor) const override
void visitTopicNamesStartingWith(Utf8Stream::UnicodeChar character, std::function < void (std::string_view) > visitor) const override
{
MWBase::Journal * journal = MWBase::Environment::get().getJournal();

@ -73,7 +73,7 @@ namespace MWGui
virtual bool isEmpty () const = 0;
/// walks the active and optionally completed, quests providing the name and completed status
virtual void visitQuestNames (bool active_only, std::function <void (const std::string&, bool)> visitor) const = 0;
virtual void visitQuestNames(bool active_only, std::function <void (std::string_view, bool)> visitor) const = 0;
/// walks over the journal entries related to all quests with the given name
/// If \a questName is empty, simply visits all journal entries
@ -83,7 +83,7 @@ namespace MWGui
virtual void visitTopicName (TopicId topicId, std::function <void (Utf8Span)> visitor) const = 0;
/// walks over the topics whose names start with the character
virtual void visitTopicNamesStartingWith (Utf8Stream::UnicodeChar character, std::function < void (const std::string&) > visitor) const = 0;
virtual void visitTopicNamesStartingWith(Utf8Stream::UnicodeChar character, std::function < void (std::string_view) > visitor) const = 0;
/// walks over the topic entries for the topic specified by its identifier
virtual void visitTopicEntries (TopicId topicId, std::function <void (TopicEntry const &)> visitor) const = 0;

@ -518,7 +518,7 @@ namespace
AddNamesToList(Gui::MWList* list) : mList(list) {}
Gui::MWList* mList;
void operator () (const std::string& name, bool finished=false)
void operator() (std::string_view name, bool finished = false)
{
mList->addItem(name);
}
@ -528,7 +528,7 @@ namespace
SetNamesInactive(Gui::MWList* list) : mList(list) {}
Gui::MWList* mList;
void operator () (const std::string& name, bool finished)
void operator() (std::string_view name, bool finished)
{
if (finished)
{

@ -6,6 +6,8 @@
#include <MyGUI_TextBox.h>
#include <MyGUI_Window.h>
#include "ustring.hpp"
namespace MWGui
{
void Layout::initialise(std::string_view _layout)
@ -45,17 +47,17 @@ namespace MWGui
mMainWidget->setVisible(b);
}
void Layout::setText(std::string_view name, const std::string &caption)
void Layout::setText(std::string_view name, std::string_view caption)
{
MyGUI::Widget* pt;
getWidget(pt, name);
static_cast<MyGUI::TextBox*>(pt)->setCaption(caption);
static_cast<MyGUI::TextBox*>(pt)->setCaption(toUString(caption));
}
void Layout::setTitle(std::string_view title)
{
MyGUI::Window* window = static_cast<MyGUI::Window*>(mMainWidget);
MyGUI::UString uTitle{title.data(), title.size()};
MyGUI::UString uTitle = toUString(title);
if (window->getCaption() != uTitle)
window->setCaptionWithReplacing(uTitle);

@ -61,7 +61,7 @@ namespace MWGui
virtual void setVisible(bool b);
void setText(std::string_view name, const std::string& caption);
void setText(std::string_view name, std::string_view caption);
// NOTE: this assume that mMainWidget is of type Window.
void setTitle(std::string_view title);

@ -17,6 +17,7 @@
#include "../mwrender/characterpreview.hpp"
#include "tooltips.hpp"
#include "ustring.hpp"
namespace
{
@ -105,7 +106,7 @@ namespace MWGui
MyGUI::Button* okButton;
getWidget(okButton, "OKButton");
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", ""));
okButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onOkClicked);
updateRaces();
@ -119,9 +120,9 @@ namespace MWGui
getWidget(okButton, "OKButton");
if (shown)
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", ""));
okButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", {})));
else
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", ""));
okButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
}
void RaceDialog::onOpen()

@ -14,6 +14,7 @@
#include "../mwmechanics/autocalcspell.hpp"
#include "tooltips.hpp"
#include "ustring.hpp"
namespace
{
@ -58,15 +59,15 @@ namespace MWGui
// Setup dynamic stats
getWidget(mHealth, "Health");
mHealth->setTitle(MWBase::Environment::get().getWindowManager()->getGameSettingString("sHealth", ""));
mHealth->setTitle(MWBase::Environment::get().getWindowManager()->getGameSettingString("sHealth", {}));
mHealth->setValue(45, 45);
getWidget(mMagicka, "Magicka");
mMagicka->setTitle(MWBase::Environment::get().getWindowManager()->getGameSettingString("sMagic", ""));
mMagicka->setTitle(MWBase::Environment::get().getWindowManager()->getGameSettingString("sMagic", {}));
mMagicka->setValue(50, 50);
getWidget(mFatigue, "Fatigue");
mFatigue->setTitle(MWBase::Environment::get().getWindowManager()->getGameSettingString("sFatigue", ""));
mFatigue->setTitle(MWBase::Environment::get().getWindowManager()->getGameSettingString("sFatigue", {}));
mFatigue->setValue(160, 160);
// Setup attributes
@ -250,11 +251,11 @@ namespace MWGui
coord2.top += separator->getHeight();
}
void ReviewDialog::addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
void ReviewDialog::addGroup(std::string_view label, MyGUI::IntCoord& coord1, MyGUI::IntCoord& coord2)
{
MyGUI::TextBox* groupWidget = mSkillView->createWidget<MyGUI::TextBox>("SandBrightText", MyGUI::IntCoord(0, coord1.top, coord1.width + coord2.width, coord1.height), MyGUI::Align::Default);
groupWidget->eventMouseWheel += MyGUI::newDelegate(this, &ReviewDialog::onMouseWheel);
groupWidget->setCaption(label);
groupWidget->setCaption(toUString(label));
mSkillWidgets.push_back(groupWidget);
int lineHeight = MWBase::Environment::get().getWindowManager()->getFontHeight() + 2;
@ -262,13 +263,13 @@ namespace MWGui
coord2.top += lineHeight;
}
MyGUI::TextBox* ReviewDialog::addValueItem(const std::string& text, const std::string &value, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
MyGUI::TextBox* ReviewDialog::addValueItem(std::string_view text, const std::string& value, const std::string& state, MyGUI::IntCoord& coord1, MyGUI::IntCoord& coord2)
{
MyGUI::TextBox* skillNameWidget;
MyGUI::TextBox* skillValueWidget;
skillNameWidget = mSkillView->createWidget<MyGUI::TextBox>("SandText", coord1, MyGUI::Align::Default);
skillNameWidget->setCaption(text);
skillNameWidget->setCaption(toUString(text));
skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &ReviewDialog::onMouseWheel);
skillValueWidget = mSkillView->createWidget<MyGUI::TextBox>("SandTextRight", coord2, MyGUI::Align::Default);

@ -76,8 +76,8 @@ namespace MWGui
private:
void addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
MyGUI::TextBox* addValueItem(const std::string& text, const std::string &value, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void addGroup(std::string_view label, MyGUI::IntCoord& coord1, MyGUI::IntCoord& coord2);
MyGUI::TextBox* addValueItem(std::string_view text, const std::string& value, const std::string& state, MyGUI::IntCoord& coord1, MyGUI::IntCoord& coord2);
void addItem(const std::string& text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void addItem(const ESM::Spell* spell, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void updateSkillArea();

@ -38,6 +38,7 @@
#include "../mwbase/windowmanager.hpp"
#include "confirmationdialog.hpp"
#include "ustring.hpp"
namespace
{
@ -584,11 +585,11 @@ namespace MWGui
void SettingsWindow::onButtonToggled(MyGUI::Widget* _sender)
{
std::string on = MWBase::Environment::get().getWindowManager()->getGameSettingString("sOn", "On");
std::string off = MWBase::Environment::get().getWindowManager()->getGameSettingString("sOff", "On");
MyGUI::UString on = toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOn", "On"));
bool newState;
if (_sender->castType<MyGUI::Button>()->getCaption() == on)
{
MyGUI::UString off = toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOff", "Off"));
_sender->castType<MyGUI::Button>()->setCaption(off);
newState = false;
}

@ -146,7 +146,7 @@ namespace MWGui
mDurationValue->setCaption("1");
mMagnitudeMinValue->setCaption("1");
const std::string to = MWBase::Environment::get().getWindowManager()->getGameSettingString("sTo", "-");
const std::string to{MWBase::Environment::get().getWindowManager()->getGameSettingString("sTo", "-")};
mMagnitudeMaxValue->setCaption(to + " 1");
mAreaValue->setCaption("0");
@ -314,7 +314,7 @@ namespace MWGui
}
mEffect.mMagnMax = pos+1;
const std::string to = MWBase::Environment::get().getWindowManager()->getGameSettingString("sTo", "-");
const std::string to{MWBase::Environment::get().getWindowManager()->getGameSettingString("sTo", "-")};
mMagnitudeMaxValue->setCaption(to + " " + MyGUI::utility::toString(pos+1));

@ -67,7 +67,7 @@ namespace MWGui
for (const MagicEffectInfo& effectInfo : effectInfos)
{
if (addNewLine)
sourcesDescription += "\n";
sourcesDescription += '\n';
// if at least one of the effect sources is permanent, the effect will never wear off
if (effectInfo.mPermanent)
@ -84,18 +84,21 @@ namespace MWGui
sourcesDescription += effectInfo.mSource;
if (effect->mData.mFlags & ESM::MagicEffect::TargetSkill)
sourcesDescription += " (" +
MWBase::Environment::get().getWindowManager()->getGameSettingString(
ESM::Skill::sSkillNameIds[effectInfo.mKey.mArg], "") + ")";
{
sourcesDescription += " (";
sourcesDescription += MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Skill::sSkillNameIds[effectInfo.mKey.mArg], {});
sourcesDescription += ')';
}
if (effect->mData.mFlags & ESM::MagicEffect::TargetAttribute)
sourcesDescription += " (" +
MWBase::Environment::get().getWindowManager()->getGameSettingString(
ESM::Attribute::sGmstAttributeIds[effectInfo.mKey.mArg], "") + ")";
{
sourcesDescription += " (";
sourcesDescription += MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Attribute::sGmstAttributeIds[effectInfo.mKey.mArg], {});
sourcesDescription += ')';
}
ESM::MagicEffect::MagnitudeDisplayType displayType = effect->getMagnitudeDisplayType();
if (displayType == ESM::MagicEffect::MDT_TimesInt)
{
std::string timesInt = MWBase::Environment::get().getWindowManager()->getGameSettingString("sXTimesINT", "");
std::string_view timesInt = MWBase::Environment::get().getWindowManager()->getGameSettingString("sXTimesINT", {});
std::stringstream formatter;
formatter << std::fixed << std::setprecision(1) << " " << (effectInfo.mMagnitude / 10.0f) << timesInt;
sourcesDescription += formatter.str();
@ -105,20 +108,27 @@ namespace MWGui
sourcesDescription += ": " + MyGUI::utility::toString(effectInfo.mMagnitude);
if ( displayType == ESM::MagicEffect::MDT_Percentage )
sourcesDescription += MWBase::Environment::get().getWindowManager()->getGameSettingString("spercent", "");
sourcesDescription += MWBase::Environment::get().getWindowManager()->getGameSettingString("spercent", {});
else if ( displayType == ESM::MagicEffect::MDT_Feet )
sourcesDescription += " " + MWBase::Environment::get().getWindowManager()->getGameSettingString("sfeet", "");
{
sourcesDescription += ' ';
sourcesDescription += MWBase::Environment::get().getWindowManager()->getGameSettingString("sfeet", {});
}
else if ( displayType == ESM::MagicEffect::MDT_Level )
{
sourcesDescription += " " + ((effectInfo.mMagnitude > 1) ?
MWBase::Environment::get().getWindowManager()->getGameSettingString("sLevels", "") :
MWBase::Environment::get().getWindowManager()->getGameSettingString("sLevel", "") );
sourcesDescription += ' ';
if (effectInfo.mMagnitude > 1)
sourcesDescription += MWBase::Environment::get().getWindowManager()->getGameSettingString("sLevels", {});
else
sourcesDescription += MWBase::Environment::get().getWindowManager()->getGameSettingString("sLevel", {});
}
else // ESM::MagicEffect::MDT_Points
{
sourcesDescription += " " + ((effectInfo.mMagnitude > 1) ?
MWBase::Environment::get().getWindowManager()->getGameSettingString("spoints", "") :
MWBase::Environment::get().getWindowManager()->getGameSettingString("spoint", "") );
sourcesDescription += ' ';
if (effectInfo.mMagnitude > 1)
sourcesDescription += MWBase::Environment::get().getWindowManager()->getGameSettingString("spoints", {});
else
sourcesDescription += MWBase::Environment::get().getWindowManager()->getGameSettingString("spoint", {});
}
}
if (effectInfo.mRemainingTime > -1 && Settings::Manager::getBool("show effect duration","Game"))

@ -21,11 +21,7 @@ namespace
{
if (left.mType != right.mType)
return left.mType < right.mType;
std::string leftName = Misc::StringUtils::lowerCase(left.mName);
std::string rightName = Misc::StringUtils::lowerCase(right.mName);
return leftName.compare(rightName) < 0;
return Misc::StringUtils::ciLess(left.mName, right.mName);
}
}
@ -57,17 +53,19 @@ namespace MWGui
{
const ESM::MagicEffect *magicEffect =
store.get<ESM::MagicEffect>().find(effectId);
std::string effectIDStr = ESM::MagicEffect::effectIdToString(effectId);
std::string fullEffectName = wm->getGameSettingString(effectIDStr, "");
const std::string& effectIDStr = ESM::MagicEffect::effectIdToString(effectId);
std::string fullEffectName{wm->getGameSettingString(effectIDStr, {})};
if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetSkill && effect.mSkill != -1)
{
fullEffectName += " " + wm->getGameSettingString(ESM::Skill::sSkillNameIds[effect.mSkill], "");
fullEffectName += ' ';
fullEffectName += wm->getGameSettingString(ESM::Skill::sSkillNameIds[effect.mSkill], {});
}
if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetAttribute && effect.mAttribute != -1)
{
fullEffectName += " " + wm->getGameSettingString(ESM::Attribute::sGmstAttributeIds[effect.mAttribute], "");
fullEffectName += ' ';
fullEffectName += wm->getGameSettingString(ESM::Attribute::sGmstAttributeIds[effect.mAttribute], {});
}
std::string convert = Utf8Stream::lowerCaseUtf8(fullEffectName);

@ -158,16 +158,17 @@ namespace MWGui
isInherent = sign->mPowers.exists(spell->mId);
}
const auto windowManager = MWBase::Environment::get().getWindowManager();
if (isInherent)
{
MWBase::Environment::get().getWindowManager()->messageBox("#{sDeleteSpellError}");
windowManager->messageBox("#{sDeleteSpellError}");
}
else
{
// ask for confirmation
mSpellToDelete = spellId;
ConfirmationDialog* dialog = MWBase::Environment::get().getWindowManager()->getConfirmationDialog();
std::string question = MWBase::Environment::get().getWindowManager()->getGameSettingString("sQuestionDeleteSpell", "Delete %s?");
ConfirmationDialog* dialog = windowManager->getConfirmationDialog();
std::string question{windowManager->getGameSettingString("sQuestionDeleteSpell", "Delete %s?")};
question = Misc::StringUtils::format(question, spell->mName);
dialog->askForConfirmation(question);
dialog->eventOkClicked.clear();

@ -23,6 +23,7 @@
#include "../mwmechanics/actorutil.hpp"
#include "tooltips.hpp"
#include "ustring.hpp"
namespace MWGui
{
@ -411,12 +412,12 @@ namespace MWGui
coord2.top += separator->getHeight();
}
void StatsWindow::addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
void StatsWindow::addGroup(std::string_view label, MyGUI::IntCoord& coord1, MyGUI::IntCoord& coord2)
{
MyGUI::TextBox* groupWidget = mSkillView->createWidget<MyGUI::TextBox>("SandBrightText",
MyGUI::IntCoord(0, coord1.top, coord1.width + coord2.width, coord1.height),
MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch);
groupWidget->setCaption(label);
groupWidget->setCaption(toUString(label));
groupWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel);
mSkillWidgets.push_back(groupWidget);
@ -425,12 +426,12 @@ namespace MWGui
coord2.top += lineHeight;
}
std::pair<MyGUI::TextBox*, MyGUI::TextBox*> StatsWindow::addValueItem(const std::string& text, const std::string &value, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
std::pair<MyGUI::TextBox*, MyGUI::TextBox*> StatsWindow::addValueItem(std::string_view text, const std::string &value, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2)
{
MyGUI::TextBox *skillNameWidget, *skillValueWidget;
skillNameWidget = mSkillView->createWidget<MyGUI::TextBox>("SandText", coord1, MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch);
skillNameWidget->setCaption(text);
skillNameWidget->setCaption(toUString(text));
skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel);
skillValueWidget = mSkillView->createWidget<MyGUI::TextBox>("SandTextRight", coord2, MyGUI::Align::Right | MyGUI::Align::Top);
@ -501,7 +502,7 @@ namespace MWGui
esmStore.get<ESM::Attribute>().find(skill->mData.mAttribute);
std::pair<MyGUI::TextBox*, MyGUI::TextBox*> widgets = addValueItem(MWBase::Environment::get().getWindowManager()->getGameSettingString(skillNameId, skillNameId),
"", "normal", coord1, coord2);
{}, "normal", coord1, coord2);
mSkillWidgetMap[skillId] = widgets;
for (int i=0; i<2; ++i)

@ -38,8 +38,8 @@ namespace MWGui
private:
void addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
std::pair<MyGUI::TextBox*, MyGUI::TextBox*> addValueItem(const std::string& text, const std::string &value, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void addGroup(std::string_view label, MyGUI::IntCoord& coord1, MyGUI::IntCoord& coord2);
std::pair<MyGUI::TextBox*, MyGUI::TextBox*> addValueItem(std::string_view text, const std::string &value, const std::string& state, MyGUI::IntCoord& coord1, MyGUI::IntCoord& coord2);
MyGUI::Widget* addItem(const std::string& text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void setFactions (const FactionList& factions);

@ -6,6 +6,8 @@
#include <MyGUI_EditBox.h>
#include <MyGUI_Button.h>
#include "ustring.hpp"
namespace MWGui
{
@ -32,12 +34,12 @@ namespace MWGui
getWidget(okButton, "OKButton");
if (shown)
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", ""));
okButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", {})));
else
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", ""));
okButton->setCaption(toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
}
void TextInputDialog::setTextLabel(const std::string &label)
void TextInputDialog::setTextLabel(std::string_view label)
{
setText("LabelT", label);
}
@ -53,7 +55,7 @@ namespace MWGui
void TextInputDialog::onOkClicked(MyGUI::Widget* _sender)
{
if (mTextEdit->getCaption() == "")
if (mTextEdit->getCaption().empty())
{
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}");
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget (mTextEdit);

@ -14,7 +14,7 @@ namespace MWGui
void setTextInput(const std::string &text);
void setNextButtonShow(bool shown);
void setTextLabel(const std::string &label);
void setTextLabel(std::string_view label);
void onOpen() override;
bool exit() override { return false; }

@ -0,0 +1,15 @@
#ifndef MWGUI_USTRING_H
#define MWGUI_USTRING_H
#include <MyGUI_UString.h>
namespace MWGui
{
// FIXME: Remove once we get a version of MyGUI that supports string_view
inline MyGUI::UString toUString(std::string_view string)
{
return {string.data(), string.size()};
}
}
#endif

@ -17,6 +17,7 @@
#include "../mwworld/esmstore.hpp"
#include "controllers.hpp"
#include "ustring.hpp"
namespace MWGui::Widgets
{
@ -61,7 +62,7 @@ namespace MWGui::Widgets
}
else
{
const std::string &name = MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Skill::sSkillNameIds[mSkillId], "");
MyGUI::UString name = toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Skill::sSkillNameIds[mSkillId], {}));
mSkillNameWidget->setCaption(name);
}
}
@ -147,7 +148,7 @@ namespace MWGui::Widgets
}
else
{
static const char *attributes[8] = {
static const std::string_view attributes[8] = {
"sAttributeStrength",
"sAttributeIntelligence",
"sAttributeWillpower",
@ -157,7 +158,7 @@ namespace MWGui::Widgets
"sAttributePersonality",
"sAttributeLuck"
};
const std::string &name = MWBase::Environment::get().getWindowManager()->getGameSettingString(attributes[mId], "");
MyGUI::UString name = toUString(MWBase::Environment::get().getWindowManager()->getGameSettingString(attributes[mId], {}));
mAttributeNameWidget->setCaption(name);
}
}
@ -390,32 +391,34 @@ namespace MWGui::Widgets
assert(magicEffect);
std::string pt = MWBase::Environment::get().getWindowManager()->getGameSettingString("spoint", "");
std::string pts = MWBase::Environment::get().getWindowManager()->getGameSettingString("spoints", "");
std::string pct = MWBase::Environment::get().getWindowManager()->getGameSettingString("spercent", "");
std::string ft = MWBase::Environment::get().getWindowManager()->getGameSettingString("sfeet", "");
std::string lvl = MWBase::Environment::get().getWindowManager()->getGameSettingString("sLevel", "");
std::string lvls = MWBase::Environment::get().getWindowManager()->getGameSettingString("sLevels", "");
std::string to = " " + MWBase::Environment::get().getWindowManager()->getGameSettingString("sTo", "") + " ";
std::string sec = " " + MWBase::Environment::get().getWindowManager()->getGameSettingString("ssecond", "");
std::string secs = " " + MWBase::Environment::get().getWindowManager()->getGameSettingString("sseconds", "");
std::string_view pt = MWBase::Environment::get().getWindowManager()->getGameSettingString("spoint", {});
std::string_view pts = MWBase::Environment::get().getWindowManager()->getGameSettingString("spoints", {});
std::string_view pct = MWBase::Environment::get().getWindowManager()->getGameSettingString("spercent", {});
std::string_view ft = MWBase::Environment::get().getWindowManager()->getGameSettingString("sfeet", {});
std::string_view lvl = MWBase::Environment::get().getWindowManager()->getGameSettingString("sLevel", {});
std::string_view lvls = MWBase::Environment::get().getWindowManager()->getGameSettingString("sLevels", {});
std::string to = " " + std::string{MWBase::Environment::get().getWindowManager()->getGameSettingString("sTo", {})} + " ";
std::string sec = " " + std::string{MWBase::Environment::get().getWindowManager()->getGameSettingString("ssecond", {})};
std::string secs = " " + std::string{MWBase::Environment::get().getWindowManager()->getGameSettingString("sseconds", {})};
std::string effectIDStr = ESM::MagicEffect::effectIdToString(mEffectParams.mEffectID);
std::string spellLine = MWBase::Environment::get().getWindowManager()->getGameSettingString(effectIDStr, "");
const std::string& effectIDStr = ESM::MagicEffect::effectIdToString(mEffectParams.mEffectID);
std::string spellLine{MWBase::Environment::get().getWindowManager()->getGameSettingString(effectIDStr, {})};
if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetSkill && mEffectParams.mSkill != -1)
{
spellLine += " " + MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Skill::sSkillNameIds[mEffectParams.mSkill], "");
spellLine += ' ';
spellLine += MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Skill::sSkillNameIds[mEffectParams.mSkill], {});
}
if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetAttribute && mEffectParams.mAttribute != -1)
{
spellLine += " " + MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Attribute::sGmstAttributeIds[mEffectParams.mAttribute], "");
spellLine += ' ';
spellLine += MWBase::Environment::get().getWindowManager()->getGameSettingString(ESM::Attribute::sGmstAttributeIds[mEffectParams.mAttribute], {});
}
if (mEffectParams.mMagnMin || mEffectParams.mMagnMax) {
ESM::MagicEffect::MagnitudeDisplayType displayType = magicEffect->getMagnitudeDisplayType();
if ( displayType == ESM::MagicEffect::MDT_TimesInt ) {
std::string timesInt = MWBase::Environment::get().getWindowManager()->getGameSettingString("sXTimesINT", "");
std::string_view timesInt = MWBase::Environment::get().getWindowManager()->getGameSettingString("sXTimesINT", {});
std::stringstream formatter;
formatter << std::fixed << std::setprecision(1) << " " << (mEffectParams.mMagnMin / 10.0f);
@ -433,11 +436,26 @@ namespace MWGui::Widgets
if ( displayType == ESM::MagicEffect::MDT_Percentage )
spellLine += pct;
else if ( displayType == ESM::MagicEffect::MDT_Feet )
spellLine += " " + ft;
{
spellLine += ' ';
spellLine += ft;
}
else if ( displayType == ESM::MagicEffect::MDT_Level )
spellLine += " " + ((mEffectParams.mMagnMin == mEffectParams.mMagnMax && std::abs(mEffectParams.mMagnMin) == 1) ? lvl : lvls );
{
spellLine += ' ';
if (mEffectParams.mMagnMin == mEffectParams.mMagnMax && std::abs(mEffectParams.mMagnMin) == 1)
spellLine += lvl;
else
spellLine += lvls;
}
else // ESM::MagicEffect::MDT_Points
spellLine += " " + ((mEffectParams.mMagnMin == mEffectParams.mMagnMax && std::abs(mEffectParams.mMagnMin) == 1) ? pt : pts );
{
spellLine += ' ';
if (mEffectParams.mMagnMin == mEffectParams.mMagnMax && std::abs(mEffectParams.mMagnMin) == 1)
spellLine += pt;
else
spellLine += pts;
}
}
}
@ -449,7 +467,9 @@ namespace MWGui::Widgets
if (mEffectParams.mDuration > 0 && !(magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration))
{
spellLine += " " + MWBase::Environment::get().getWindowManager()->getGameSettingString("sfor", "") + " " + MyGUI::utility::toString(mEffectParams.mDuration) + ((mEffectParams.mDuration == 1) ? sec : secs);
spellLine += ' ';
spellLine += MWBase::Environment::get().getWindowManager()->getGameSettingString("sfor", {});
spellLine += ' ' + MyGUI::utility::toString(mEffectParams.mDuration) + ((mEffectParams.mDuration == 1) ? sec : secs);
}
if (mEffectParams.mArea > 0)
@ -460,13 +480,15 @@ namespace MWGui::Widgets
// potions have no target
if (!mEffectParams.mNoTarget)
{
std::string on = MWBase::Environment::get().getWindowManager()->getGameSettingString("sonword", "");
spellLine += ' ';
spellLine += MWBase::Environment::get().getWindowManager()->getGameSettingString("sonword", {});
spellLine += ' ';
if (mEffectParams.mRange == ESM::RT_Self)
spellLine += " " + on + " " + MWBase::Environment::get().getWindowManager()->getGameSettingString("sRangeSelf", "");
spellLine += MWBase::Environment::get().getWindowManager()->getGameSettingString("sRangeSelf", {});
else if (mEffectParams.mRange == ESM::RT_Touch)
spellLine += " " + on + " " + MWBase::Environment::get().getWindowManager()->getGameSettingString("sRangeTouch", "");
spellLine += MWBase::Environment::get().getWindowManager()->getGameSettingString("sRangeTouch", {});
else if (mEffectParams.mRange == ESM::RT_Target)
spellLine += " " + on + " " + MWBase::Environment::get().getWindowManager()->getGameSettingString("sRangeTarget", "");
spellLine += MWBase::Environment::get().getWindowManager()->getGameSettingString("sRangeTarget", {});
}
}
@ -517,10 +539,10 @@ namespace MWGui::Widgets
mBarTextWidget->setCaption(out.str().c_str());
}
}
void MWDynamicStat::setTitle(const std::string& text)
void MWDynamicStat::setTitle(std::string_view text)
{
if (mTextWidget)
mTextWidget->setCaption(text);
mTextWidget->setCaption(toUString(text));
}
MWDynamicStat::~MWDynamicStat()

@ -282,7 +282,7 @@ namespace MWGui
MWDynamicStat();
void setValue(int value, int max);
void setTitle(const std::string& text);
void setTitle(std::string_view text);
int getValue() const { return mValue; }
int getMax() const { return mMax; }

@ -124,6 +124,7 @@
#include "itemchargeview.hpp"
#include "keyboardnavigation.hpp"
#include "resourceskin.hpp"
#include "ustring.hpp"
namespace MWGui
{
@ -752,7 +753,7 @@ namespace MWGui
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.data(), message.size()}));
mDialogueWindow->addMessageBox(MyGUI::LanguageManager::getInstance().replaceTags(toUString(message)));
} else if (showInDialogueMode != MWGui::ShowInDialogueMode_Only) {
mMessageBoxManager->createMessageBox(message);
}
@ -783,7 +784,7 @@ namespace MWGui
return mMessageBoxManager->readPressedButton();
}
std::string WindowManager::getGameSettingString(const std::string &id, const std::string &default_)
std::string_view WindowManager::getGameSettingString(std::string_view id, std::string_view default_)
{
const ESM::GameSetting *setting = mStore->get<ESM::GameSetting>().search(id);

@ -289,7 +289,7 @@ namespace MWGui
* @param id Identifier for the GMST setting, e.g. "aName"
* @param default Default value if the GMST setting cannot be used.
*/
std::string getGameSettingString(const std::string &id, const std::string &default_) override;
std::string_view getGameSettingString(std::string_view id, std::string_view default_) override;
void processChangedSettings(const Settings::CategorySettingVector& changed) override;

@ -19,7 +19,7 @@ namespace MWMechanics
{
/// @return ID of resulting item, or empty if none
inline std::string getLevelledItem (const ESM::LevelledListBase* levItem, bool creature, Misc::Rng::Generator& prng)
inline std::string_view getLevelledItem(const ESM::LevelledListBase* levItem, bool creature, Misc::Rng::Generator& prng)
{
const std::vector<ESM::LevelledListBase::LevelItem>& items = levItem->mList;
@ -27,9 +27,9 @@ namespace MWMechanics
int playerLevel = player.getClass().getCreatureStats(player).getLevel();
if (Misc::Rng::roll0to99(prng) < levItem->mChanceNone)
return std::string();
return {};
std::vector<std::string> candidates;
std::vector<std::string_view> candidates;
int highestLevel = 0;
for (const auto& levelledItem : items)
{
@ -42,7 +42,7 @@ namespace MWMechanics
if (creature)
allLevels = levItem->mFlags & ESM::CreatureLevList::AllLevels;
std::pair<int, std::string> highest = std::make_pair(-1, "");
std::pair<int, std::string_view> highest = {-1, {}};
for (const auto& levelledItem : items)
{
if (playerLevel >= levelledItem.mLevel
@ -54,14 +54,14 @@ namespace MWMechanics
}
}
if (candidates.empty())
return std::string();
std::string item = candidates[Misc::Rng::rollDice(candidates.size(), prng)];
return {};
std::string_view item = candidates[Misc::Rng::rollDice(candidates.size(), prng)];
// Vanilla doesn't fail on nonexistent items in levelled lists
if (!MWBase::Environment::get().getWorld()->getStore().find(Misc::StringUtils::lowerCase(item)))
if (!MWBase::Environment::get().getWorld()->getStore().find(item))
{
Log(Debug::Warning) << "Warning: ignoring nonexistent item '" << item << "' in levelled list '" << levItem->mId << "'";
return std::string();
return {};
}
// Is this another levelled item or a real item?

@ -267,7 +267,7 @@ void MWMechanics::NpcStats::increaseSkill(int skillIndex, const ESM::Class &clas
/// \todo check if character is the player, if levelling is ever implemented for NPCs
MWBase::Environment::get().getWindowManager()->playSound("skillraise");
std::string message = MWBase::Environment::get().getWindowManager ()->getGameSettingString ("sNotifyMessage39", "");
std::string message{MWBase::Environment::get().getWindowManager()->getGameSettingString("sNotifyMessage39", {})};
message = Misc::StringUtils::format(message, ("#{" + ESM::Skill::sSkillNameIds[skillIndex] + "}"), static_cast<int>(base));
if (readBook)

@ -64,7 +64,7 @@ namespace
else
{
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
std::string itemId = MWMechanics::getLevelledItem(itemPtr.get<ESM::ItemLevList>()->mBase, false, prng);
std::string_view itemId = MWMechanics::getLevelledItem(itemPtr.get<ESM::ItemLevList>()->mBase, false, prng);
if (itemId.empty())
return;
MWWorld::ManualRef manualRef(MWBase::Environment::get().getWorld()->getStore(), itemId, 1);

@ -124,8 +124,8 @@ void MWState::StateManager::askLoadRecent()
std::vector<std::string> buttons;
buttons.emplace_back("#{sYes}");
buttons.emplace_back("#{sNo}");
std::string tag("%s");
std::string message = MWBase::Environment::get().getWindowManager()->getGameSettingString("sLoadLastSaveMsg", tag);
std::string_view tag = "%s";
std::string message{MWBase::Environment::get().getWindowManager()->getGameSettingString("sLoadLastSaveMsg", tag)};
size_t pos = message.find(tag);
message.replace(pos, tag.length(), lastSave.mProfile.mDescription);
MWBase::Environment::get().getWindowManager()->interactiveMessageBox(message, buttons);

@ -543,7 +543,7 @@ void MWWorld::ContainerStore::fillNonRandom (const ESM::InventoryList& items, co
mResolved = false;
}
void MWWorld::ContainerStore::addInitialItem (const std::string& id, const std::string& owner, int count,
void MWWorld::ContainerStore::addInitialItem(std::string_view id, const std::string& owner, int count,
Misc::Rng::Generator* prng, bool topLevel)
{
if (count == 0) return; //Don't restock with nothing.
@ -584,7 +584,7 @@ void MWWorld::ContainerStore::addInitialItemImp(const MWWorld::Ptr& ptr, const s
}
else
{
std::string itemId = MWMechanics::getLevelledItem(ptr.get<ESM::ItemLevList>()->mBase, false, *prng);
std::string_view itemId = MWMechanics::getLevelledItem(ptr.get<ESM::ItemLevList>()->mBase, false, *prng);
if (itemId.empty())
return;
addInitialItem(itemId, owner, count, prng, false);

@ -126,7 +126,7 @@ namespace MWWorld
std::weak_ptr<ResolutionListener> mResolutionListener;
ContainerStoreIterator addImp (const Ptr& ptr, int count, bool markModified = true);
void addInitialItem (const std::string& id, const std::string& owner, int count, Misc::Rng::Generator* prng, bool topLevel=true);
void addInitialItem(std::string_view id, const std::string& owner, int count, Misc::Rng::Generator* prng, bool topLevel=true);
void addInitialItemImp (const MWWorld::Ptr& ptr, const std::string& owner, int count, Misc::Rng::Generator* prng, bool topLevel=true);
template<typename T>

@ -3694,7 +3694,7 @@ namespace MWWorld
for (int i=0; i<numCreatures; ++i)
{
std::string selectedCreature = MWMechanics::getLevelledItem(list, true, mPrng);
std::string_view selectedCreature = MWMechanics::getLevelledItem(list, true, mPrng);
if (selectedCreature.empty())
continue;

@ -7,11 +7,14 @@
#include <string>
#include <string_view>
#include <stdexcept>
#include <vector>
namespace Misc::StringUtils
{
namespace Details
struct Details
{
std::vector<std::string> mMemorySafety;
// Allow to convert complex arguments to C-style strings for format() function
template <typename T>
T argument(T value) noexcept
@ -22,7 +25,9 @@ namespace Misc::StringUtils
template <typename T>
T const * argument(std::basic_string_view<T> const & value) noexcept
{
return value.data();
// TODO: switch to a format function that doesn't require null termination
auto& inserted = mMemorySafety.emplace_back(value);
return inserted.c_str();
}
template <typename T>
@ -30,7 +35,7 @@ namespace Misc::StringUtils
{
return value.c_str();
}
}
};
// Requires some C++11 features:
// 1. std::string needs to be contiguous
@ -39,12 +44,13 @@ namespace Misc::StringUtils
template <typename ... Args>
std::string format(const char* fmt, Args const & ... args)
{
const int size = std::snprintf(nullptr, 0, fmt, Details::argument(args) ...);
Details details;
const int size = std::snprintf(nullptr, 0, fmt, details.argument(args) ...);
if (size < 0)
throw std::runtime_error(std::string("Failed to compute resulting string size: ") + std::strerror(errno));
// Note: sprintf also writes a trailing null character. We should remove it.
std::string ret(static_cast<std::size_t>(size) + 1, '\0');
if (std::sprintf(ret.data(), fmt, Details::argument(args) ...) < 0)
if (std::sprintf(ret.data(), fmt, details.argument(args) ...) < 0)
throw std::runtime_error(std::string("Failed to format string: ") + std::strerror(errno));
ret.erase(static_cast<std::size_t>(size));
return ret;

@ -27,9 +27,9 @@ namespace Gui
MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView");
}
void MWList::addItem(const std::string& name)
void MWList::addItem(std::string_view name)
{
mItems.push_back(name);
mItems.emplace_back(name);
}
void MWList::addSeparator()
@ -152,9 +152,11 @@ namespace Gui
eventWidgetSelected(_sender);
}
MyGUI::Button *MWList::getItemWidget(const std::string& name)
MyGUI::Button* MWList::getItemWidget(std::string_view name)
{
return mScrollView->findWidget (getName() + "_item_" + name)->castType<MyGUI::Button>();
std::string search = getName() + "_item_";
search += name;
return mScrollView->findWidget(search)->castType<MyGUI::Button>();
}
void MWList::scrollToTop()

@ -36,14 +36,14 @@ namespace Gui
*/
void adjustSize();
void addItem(const std::string& name);
void addItem(std::string_view name);
void addSeparator(); ///< add a seperator between the current and the next item.
void removeItem(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::Button* getItemWidget(const std::string& name);
MyGUI::Button* getItemWidget(std::string_view name);
///< get widget for an item name, useful to set up tooltip
void scrollToTop();

Loading…
Cancel
Save