1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-06-20 17:11:33 +00:00

Merge branch 'string_me_along' into 'master'

Yet another string_view MR

See merge request OpenMW/openmw!2333
This commit is contained in:
psi29a 2022-08-25 08:53:28 +00:00
commit c260a0d4c2
64 changed files with 295 additions and 219 deletions

View file

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

View file

@ -24,6 +24,7 @@
#include "../mwrender/vismask.hpp" #include "../mwrender/vismask.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
@ -96,7 +97,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; std::string text;
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) if (MWBase::Environment::get().getWindowManager()->getFullHelp())

View file

@ -15,6 +15,7 @@
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
@ -88,7 +89,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; info.icon = ref->mBase->mIcon;
std::string text; std::string text;

View file

@ -23,6 +23,7 @@
#include "../mwmechanics/weapontype.hpp" #include "../mwmechanics/weapontype.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
@ -115,7 +116,7 @@ namespace MWClass
{ {
const MWWorld::LiveCellRef<ESM::Armor> *ref = ptr.get<ESM::Armor>(); const MWWorld::LiveCellRef<ESM::Armor> *ref = ptr.get<ESM::Armor>();
std::string typeGmst; std::string_view typeGmst;
switch (ref->mBase->mData.mType) switch (ref->mBase->mData.mType)
{ {
@ -194,7 +195,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; info.icon = ref->mBase->mIcon;
std::string text; std::string text;
@ -298,7 +299,7 @@ namespace MWClass
if (npc.getClass().isNpc()) 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) // 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); const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace);

View file

@ -18,6 +18,7 @@
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwmechanics/npcstats.hpp" #include "../mwmechanics/npcstats.hpp"
@ -105,7 +106,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; info.icon = ref->mBase->mIcon;
std::string text; std::string text;

View file

@ -15,6 +15,7 @@
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
@ -152,7 +153,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; info.icon = ref->mBase->mIcon;
std::string text; std::string text;
@ -205,7 +206,7 @@ namespace MWClass
if (npc.getClass().isNpc()) 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) // 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); const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(npcRace);

View file

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

View file

@ -40,6 +40,7 @@
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "classmodel.hpp" #include "classmodel.hpp"
@ -589,7 +590,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; std::string text;
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) if (MWBase::Environment::get().getWindowManager()->getFullHelp())

View file

@ -132,7 +132,7 @@ namespace MWClass
ptr.get<ESM::CreatureLevList>(); ptr.get<ESM::CreatureLevList>();
auto& prng = MWBase::Environment::get().getWorld()->getPrng(); 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()) if (!id.empty())
{ {

View file

@ -24,6 +24,7 @@
#include "../mwworld/containerstore.hpp" #include "../mwworld/containerstore.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
@ -118,18 +119,11 @@ namespace MWClass
const std::string_view lockedSound = "LockedDoor"; const std::string_view lockedSound = "LockedDoor";
const std::string_view trapActivationSound = "Disarm Trap Fail"; 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. // 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. // Make such activation a no-op for now, like how it is in the vanilla game.
if (actor != MWMechanics::getPlayer() && ptr.getCellRef().getTeleport()) 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); action->setSound(lockedSound);
return action; 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()) if (!keyId.empty())
{ {
MWWorld::Ptr keyPtr = invStore.search(keyId); MWWorld::Ptr keyPtr = invStore.search(keyId);
@ -164,7 +164,7 @@ namespace MWClass
if (isLocked && hasKey) if (isLocked && hasKey)
{ {
if(actor == MWMechanics::getPlayer()) 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. ptr.getCellRef().unlock(); //Call the function here. because that makes sense.
// using a key disarms the trap // using a key disarms the trap
if(isTrapped) if(isTrapped)
@ -236,7 +236,7 @@ namespace MWClass
else else
{ {
// locked, and we can't open. // 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); action->setSound(lockedSound);
return action; return action;
} }
@ -268,7 +268,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; std::string text;

View file

@ -14,6 +14,7 @@
#include "../mwworld/actioneat.hpp" #include "../mwworld/actioneat.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
@ -100,7 +101,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; info.icon = ref->mBase->mIcon;
std::string text; std::string text;

View file

@ -19,6 +19,7 @@
#include "../mwphysics/physicssystem.hpp" #include "../mwphysics/physicssystem.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
@ -151,7 +152,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; info.icon = ref->mBase->mIcon;
std::string text; std::string text;

View file

@ -14,6 +14,7 @@
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
@ -99,7 +100,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; info.icon = ref->mBase->mIcon;
std::string text; std::string text;

View file

@ -16,6 +16,7 @@
#include "../mwworld/actionsoulgem.hpp" #include "../mwworld/actionsoulgem.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
@ -142,7 +143,7 @@ namespace MWClass
countString = " (" + std::to_string(count) + ")"; countString = " (" + std::to_string(count) + ")";
std::string_view name = getName(ptr); 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; info.icon = ref->mBase->mIcon;
std::string text; std::string text;

View file

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

View file

@ -13,6 +13,7 @@
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
@ -92,7 +93,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; info.icon = ref->mBase->mIcon;
std::string text; std::string text;

View file

@ -14,6 +14,7 @@
#include "../mwworld/cellstore.hpp" #include "../mwworld/cellstore.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
@ -99,7 +100,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; info.icon = ref->mBase->mIcon;
std::string text; std::string text;

View file

@ -12,6 +12,7 @@
#include "../mwworld/actionrepair.hpp" #include "../mwworld/actionrepair.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
@ -101,7 +102,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; info.icon = ref->mBase->mIcon;
std::string text; std::string text;

View file

@ -20,6 +20,7 @@
#include "../mwmechanics/weapontype.hpp" #include "../mwmechanics/weapontype.hpp"
#include "../mwgui/tooltips.hpp" #include "../mwgui/tooltips.hpp"
#include "../mwgui/ustring.hpp"
#include "../mwrender/objects.hpp" #include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp" #include "../mwrender/renderinginterface.hpp"
@ -149,7 +150,7 @@ namespace MWClass
MWGui::ToolTipInfo info; MWGui::ToolTipInfo info;
std::string_view name = getName(ptr); 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; info.icon = ref->mBase->mIcon;
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();

View file

@ -45,7 +45,7 @@ namespace MWDialogue
Entry::Entry (const ESM::JournalEntry& record) : mInfoId (record.mInfo), mText (record.mText), mActorName(record.mActorName) {} 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; return mText;
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -25,6 +25,7 @@
#include "itemwidget.hpp" #include "itemwidget.hpp"
#include "sortfilteritemmodel.hpp" #include "sortfilteritemmodel.hpp"
#include "ustring.hpp"
namespace MWGui namespace MWGui
{ {
@ -100,7 +101,7 @@ namespace MWGui
else else
{ {
std::string_view name = item.getClass().getName(item); std::string_view name = item.getClass().getName(item);
mName->setCaption({name.data(), name.size()}); mName->setCaption(toUString(name));
mItemBox->setItem(item); mItemBox->setItem(item);
mItemBox->setUserString ("ToolTipType", "ItemPtr"); mItemBox->setUserString ("ToolTipType", "ItemPtr");
mItemBox->setUserData(MWWorld::Ptr(item)); mItemBox->setUserData(MWWorld::Ptr(item));
@ -119,19 +120,19 @@ namespace MWGui
switch(mEnchanting.getCastStyle()) switch(mEnchanting.getCastStyle())
{ {
case ESM::Enchantment::CastOnce: 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); setConstantEffect(false);
break; break;
case ESM::Enchantment::WhenStrikes: 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); setConstantEffect(false);
break; break;
case ESM::Enchantment::WhenUsed: 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); setConstantEffect(false);
break; break;
case ESM::Enchantment::ConstantEffect: 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); setConstantEffect(true);
break; break;
} }

View file

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

View file

@ -35,12 +35,12 @@ struct JournalViewModelImpl : JournalViewModel
} }
/// \todo replace this nasty BS /// \todo replace this nasty BS
static Utf8Span toUtf8Span (std::string const & str) static Utf8Span toUtf8Span(std::string_view str)
{ {
if (str.size () == 0) if (str.size () == 0)
return Utf8Span (Utf8Point (nullptr), Utf8Point (nullptr)); 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 ()); 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 (); 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 // 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 // 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); visitor (quest.getName(), isFinished);
visitedQuests.insert(quest.getName()); visitedQuests.emplace(quest.getName());
} }
} }
} }
@ -305,7 +305,7 @@ struct JournalViewModelImpl : JournalViewModel
visitor (toUtf8Span (topic.getName())); 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(); MWBase::Journal * journal = MWBase::Environment::get().getJournal();

View file

@ -73,7 +73,7 @@ namespace MWGui
virtual bool isEmpty () const = 0; virtual bool isEmpty () const = 0;
/// walks the active and optionally completed, quests providing the name and completed status /// 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 /// walks over the journal entries related to all quests with the given name
/// If \a questName is empty, simply visits all journal entries /// 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; virtual void visitTopicName (TopicId topicId, std::function <void (Utf8Span)> visitor) const = 0;
/// walks over the topics whose names start with the character /// 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 /// 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; virtual void visitTopicEntries (TopicId topicId, std::function <void (TopicEntry const &)> visitor) const = 0;

View file

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

View file

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

View file

@ -61,7 +61,7 @@ namespace MWGui
virtual void setVisible(bool b); 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. // NOTE: this assume that mMainWidget is of type Window.
void setTitle(std::string_view title); void setTitle(std::string_view title);

View file

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

View file

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

View file

@ -76,8 +76,8 @@ namespace MWGui
private: private:
void addSkills(const SkillList &skills, const std::string &titleId, const std::string &titleDefault, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); 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 addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void addGroup(std::string_view 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); 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 std::string& text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void addItem(const ESM::Spell* spell, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); void addItem(const ESM::Spell* spell, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2);
void updateSkillArea(); void updateSkillArea();

View file

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

View file

@ -146,7 +146,7 @@ namespace MWGui
mDurationValue->setCaption("1"); mDurationValue->setCaption("1");
mMagnitudeMinValue->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"); mMagnitudeMaxValue->setCaption(to + " 1");
mAreaValue->setCaption("0"); mAreaValue->setCaption("0");
@ -314,7 +314,7 @@ namespace MWGui
} }
mEffect.mMagnMax = pos+1; 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)); mMagnitudeMaxValue->setCaption(to + " " + MyGUI::utility::toString(pos+1));

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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

View file

@ -17,6 +17,7 @@
#include "../mwworld/esmstore.hpp" #include "../mwworld/esmstore.hpp"
#include "controllers.hpp" #include "controllers.hpp"
#include "ustring.hpp"
namespace MWGui::Widgets namespace MWGui::Widgets
{ {
@ -61,7 +62,7 @@ namespace MWGui::Widgets
} }
else 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); mSkillNameWidget->setCaption(name);
} }
} }
@ -147,7 +148,7 @@ namespace MWGui::Widgets
} }
else else
{ {
static const char *attributes[8] = { static const std::string_view attributes[8] = {
"sAttributeStrength", "sAttributeStrength",
"sAttributeIntelligence", "sAttributeIntelligence",
"sAttributeWillpower", "sAttributeWillpower",
@ -157,7 +158,7 @@ namespace MWGui::Widgets
"sAttributePersonality", "sAttributePersonality",
"sAttributeLuck" "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); mAttributeNameWidget->setCaption(name);
} }
} }
@ -390,32 +391,34 @@ namespace MWGui::Widgets
assert(magicEffect); assert(magicEffect);
std::string pt = MWBase::Environment::get().getWindowManager()->getGameSettingString("spoint", ""); std::string_view pt = MWBase::Environment::get().getWindowManager()->getGameSettingString("spoint", {});
std::string pts = MWBase::Environment::get().getWindowManager()->getGameSettingString("spoints", ""); std::string_view pts = MWBase::Environment::get().getWindowManager()->getGameSettingString("spoints", {});
std::string pct = MWBase::Environment::get().getWindowManager()->getGameSettingString("spercent", ""); std::string_view pct = MWBase::Environment::get().getWindowManager()->getGameSettingString("spercent", {});
std::string ft = MWBase::Environment::get().getWindowManager()->getGameSettingString("sfeet", ""); std::string_view ft = MWBase::Environment::get().getWindowManager()->getGameSettingString("sfeet", {});
std::string lvl = MWBase::Environment::get().getWindowManager()->getGameSettingString("sLevel", ""); std::string_view lvl = MWBase::Environment::get().getWindowManager()->getGameSettingString("sLevel", {});
std::string lvls = MWBase::Environment::get().getWindowManager()->getGameSettingString("sLevels", ""); std::string_view lvls = MWBase::Environment::get().getWindowManager()->getGameSettingString("sLevels", {});
std::string to = " " + MWBase::Environment::get().getWindowManager()->getGameSettingString("sTo", "") + " "; std::string to = " " + std::string{MWBase::Environment::get().getWindowManager()->getGameSettingString("sTo", {})} + " ";
std::string sec = " " + MWBase::Environment::get().getWindowManager()->getGameSettingString("ssecond", ""); std::string sec = " " + std::string{MWBase::Environment::get().getWindowManager()->getGameSettingString("ssecond", {})};
std::string secs = " " + MWBase::Environment::get().getWindowManager()->getGameSettingString("sseconds", ""); std::string secs = " " + std::string{MWBase::Environment::get().getWindowManager()->getGameSettingString("sseconds", {})};
std::string effectIDStr = ESM::MagicEffect::effectIdToString(mEffectParams.mEffectID); const std::string& effectIDStr = ESM::MagicEffect::effectIdToString(mEffectParams.mEffectID);
std::string spellLine = MWBase::Environment::get().getWindowManager()->getGameSettingString(effectIDStr, ""); std::string spellLine{MWBase::Environment::get().getWindowManager()->getGameSettingString(effectIDStr, {})};
if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetSkill && mEffectParams.mSkill != -1) 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) 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) { if (mEffectParams.mMagnMin || mEffectParams.mMagnMax) {
ESM::MagicEffect::MagnitudeDisplayType displayType = magicEffect->getMagnitudeDisplayType(); ESM::MagicEffect::MagnitudeDisplayType displayType = magicEffect->getMagnitudeDisplayType();
if ( displayType == ESM::MagicEffect::MDT_TimesInt ) { 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; std::stringstream formatter;
formatter << std::fixed << std::setprecision(1) << " " << (mEffectParams.mMagnMin / 10.0f); formatter << std::fixed << std::setprecision(1) << " " << (mEffectParams.mMagnMin / 10.0f);
@ -433,11 +436,26 @@ namespace MWGui::Widgets
if ( displayType == ESM::MagicEffect::MDT_Percentage ) if ( displayType == ESM::MagicEffect::MDT_Percentage )
spellLine += pct; spellLine += pct;
else if ( displayType == ESM::MagicEffect::MDT_Feet ) else if ( displayType == ESM::MagicEffect::MDT_Feet )
spellLine += " " + ft; {
spellLine += ' ';
spellLine += ft;
}
else if ( displayType == ESM::MagicEffect::MDT_Level ) 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 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)) 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) if (mEffectParams.mArea > 0)
@ -460,13 +480,15 @@ namespace MWGui::Widgets
// potions have no target // potions have no target
if (!mEffectParams.mNoTarget) 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) 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) 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) 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()); mBarTextWidget->setCaption(out.str().c_str());
} }
} }
void MWDynamicStat::setTitle(const std::string& text) void MWDynamicStat::setTitle(std::string_view text)
{ {
if (mTextWidget) if (mTextWidget)
mTextWidget->setCaption(text); mTextWidget->setCaption(toUString(text));
} }
MWDynamicStat::~MWDynamicStat() MWDynamicStat::~MWDynamicStat()

View file

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

View file

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

View file

@ -289,7 +289,7 @@ namespace MWGui
* @param id Identifier for the GMST setting, e.g. "aName" * @param id Identifier for the GMST setting, e.g. "aName"
* @param default Default value if the GMST setting cannot be used. * @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; void processChangedSettings(const Settings::CategorySettingVector& changed) override;

View file

@ -19,7 +19,7 @@ namespace MWMechanics
{ {
/// @return ID of resulting item, or empty if none /// @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; const std::vector<ESM::LevelledListBase::LevelItem>& items = levItem->mList;
@ -27,9 +27,9 @@ namespace MWMechanics
int playerLevel = player.getClass().getCreatureStats(player).getLevel(); int playerLevel = player.getClass().getCreatureStats(player).getLevel();
if (Misc::Rng::roll0to99(prng) < levItem->mChanceNone) 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; int highestLevel = 0;
for (const auto& levelledItem : items) for (const auto& levelledItem : items)
{ {
@ -42,7 +42,7 @@ namespace MWMechanics
if (creature) if (creature)
allLevels = levItem->mFlags & ESM::CreatureLevList::AllLevels; 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) for (const auto& levelledItem : items)
{ {
if (playerLevel >= levelledItem.mLevel if (playerLevel >= levelledItem.mLevel
@ -54,14 +54,14 @@ namespace MWMechanics
} }
} }
if (candidates.empty()) if (candidates.empty())
return std::string(); return {};
std::string item = candidates[Misc::Rng::rollDice(candidates.size(), prng)]; std::string_view item = candidates[Misc::Rng::rollDice(candidates.size(), prng)];
// Vanilla doesn't fail on nonexistent items in levelled lists // 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 << "'"; 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? // Is this another levelled item or a real item?

View file

@ -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 /// \todo check if character is the player, if levelling is ever implemented for NPCs
MWBase::Environment::get().getWindowManager()->playSound("skillraise"); 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)); message = Misc::StringUtils::format(message, ("#{" + ESM::Skill::sSkillNameIds[skillIndex] + "}"), static_cast<int>(base));
if (readBook) if (readBook)

View file

@ -64,7 +64,7 @@ namespace
else else
{ {
auto& prng = MWBase::Environment::get().getWorld()->getPrng(); 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()) if (itemId.empty())
return; return;
MWWorld::ManualRef manualRef(MWBase::Environment::get().getWorld()->getStore(), itemId, 1); MWWorld::ManualRef manualRef(MWBase::Environment::get().getWorld()->getStore(), itemId, 1);

View file

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

View file

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

View file

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

View file

@ -3694,7 +3694,7 @@ namespace MWWorld
for (int i=0; i<numCreatures; ++i) 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()) if (selectedCreature.empty())
continue; continue;

View file

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

View file

@ -27,9 +27,9 @@ namespace Gui
MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView"); 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() void MWList::addSeparator()
@ -152,9 +152,11 @@ namespace Gui
eventWidgetSelected(_sender); 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() void MWList::scrollToTop()

View file

@ -36,14 +36,14 @@ namespace Gui
*/ */
void adjustSize(); 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 addSeparator(); ///< add a seperator between the current and the next item.
void removeItem(const std::string& name); void removeItem(const std::string& name);
unsigned int getItemCount(); 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 std::string getItemNameAt(unsigned int at); ///< \attention if there are separators, this method will return "" at the place where the separator is
void clear(); 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 ///< get widget for an item name, useful to set up tooltip
void scrollToTop(); void scrollToTop();