mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 20:39:40 +00:00
Fix not playable body parts appearing in the race selection menu.
This commit is contained in:
parent
0f0cc0e3e3
commit
e27e53f607
6 changed files with 99 additions and 54 deletions
|
@ -627,10 +627,10 @@ std::string bodyPartFlags(int flags)
|
||||||
std::string properties = "";
|
std::string properties = "";
|
||||||
if (flags == 0) properties += "[None] ";
|
if (flags == 0) properties += "[None] ";
|
||||||
if (flags & ESM::BodyPart::BPF_Female) properties += "Female ";
|
if (flags & ESM::BodyPart::BPF_Female) properties += "Female ";
|
||||||
if (flags & ESM::BodyPart::BPF_Playable) properties += "Playable ";
|
if (flags & ESM::BodyPart::BPF_NotPlayable) properties += "NotPlayable ";
|
||||||
int unused = (0xFFFFFFFF ^
|
int unused = (0xFFFFFFFF ^
|
||||||
(ESM::BodyPart::BPF_Female|
|
(ESM::BodyPart::BPF_Female|
|
||||||
ESM::BodyPart::BPF_Playable));
|
ESM::BodyPart::BPF_NotPlayable));
|
||||||
if (flags & unused) properties += "Invalid ";
|
if (flags & unused) properties += "Invalid ";
|
||||||
properties += str(boost::format("(0x%08X)") % flags);
|
properties += str(boost::format("(0x%08X)") % flags);
|
||||||
return properties;
|
return properties;
|
||||||
|
|
|
@ -140,9 +140,6 @@ void ContainerBase::onSelectedItem(MyGUI::Widget* _sender)
|
||||||
|
|
||||||
if (isInventory())
|
if (isInventory())
|
||||||
{
|
{
|
||||||
const MWWorld::Store<ESM::GameSetting> &gmst =
|
|
||||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
|
||||||
|
|
||||||
// the player is trying to sell an item, check if the merchant accepts it
|
// the player is trying to sell an item, check if the merchant accepts it
|
||||||
if (!MWBase::Environment::get().getWindowManager()->getTradeWindow()->npcAcceptsItem(object))
|
if (!MWBase::Environment::get().getWindowManager()->getTradeWindow()->npcAcceptsItem(object))
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,6 +19,49 @@
|
||||||
using namespace MWGui;
|
using namespace MWGui;
|
||||||
using namespace Widgets;
|
using namespace Widgets;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
int wrap(int index, int max)
|
||||||
|
{
|
||||||
|
if (index < 0)
|
||||||
|
return max - 1;
|
||||||
|
else if (index >= max)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
int countParts(const std::string &part, const std::string &race, bool male)
|
||||||
|
{
|
||||||
|
/// \todo loop through the whole store for appropriate bodyparts instead of looking for fixed IDs
|
||||||
|
const MWWorld::Store<ESM::BodyPart> &store =
|
||||||
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::BodyPart>();
|
||||||
|
|
||||||
|
std::string prefix =
|
||||||
|
"b_n_" + race + ((male) ? "_m_" : "_f_") + part;
|
||||||
|
|
||||||
|
std::string suffix;
|
||||||
|
suffix.reserve(prefix.size() + 3);
|
||||||
|
|
||||||
|
int count = -1;
|
||||||
|
do {
|
||||||
|
++count;
|
||||||
|
suffix = "_" + (boost::format("%02d") % (count + 1)).str();
|
||||||
|
}
|
||||||
|
while (store.search(prefix + suffix) != 0);
|
||||||
|
|
||||||
|
if (count == 0 && part == "hair") {
|
||||||
|
count = -1;
|
||||||
|
do {
|
||||||
|
++count;
|
||||||
|
suffix = (boost::format("%02d") % (count + 1)).str();
|
||||||
|
}
|
||||||
|
while (store.search(prefix + suffix) != 0);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RaceDialog::RaceDialog(MWBase::WindowManager& parWindowManager)
|
RaceDialog::RaceDialog(MWBase::WindowManager& parWindowManager)
|
||||||
: WindowModal("openmw_chargen_race.layout", parWindowManager)
|
: WindowModal("openmw_chargen_race.layout", parWindowManager)
|
||||||
, mGenderIndex(0)
|
, mGenderIndex(0)
|
||||||
|
@ -144,45 +187,6 @@ void RaceDialog::setRaceId(const std::string &raceId)
|
||||||
updateSpellPowers();
|
updateSpellPowers();
|
||||||
}
|
}
|
||||||
|
|
||||||
int wrap(int index, int max)
|
|
||||||
{
|
|
||||||
if (index < 0)
|
|
||||||
return max - 1;
|
|
||||||
else if (index >= max)
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
int countParts(const std::string &part, const std::string &race, bool male)
|
|
||||||
{
|
|
||||||
const MWWorld::Store<ESM::BodyPart> &store =
|
|
||||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::BodyPart>();
|
|
||||||
|
|
||||||
std::string prefix =
|
|
||||||
"b_n_" + race + ((male) ? "_m_" : "_f_") + part;
|
|
||||||
|
|
||||||
std::string suffix;
|
|
||||||
suffix.reserve(prefix.size() + 3);
|
|
||||||
|
|
||||||
int count = -1;
|
|
||||||
do {
|
|
||||||
++count;
|
|
||||||
suffix = "_" + (boost::format("%02d") % (count + 1)).str();
|
|
||||||
}
|
|
||||||
while (store.search(prefix + suffix) != 0);
|
|
||||||
|
|
||||||
if (count == 0 && part == "hair") {
|
|
||||||
count = -1;
|
|
||||||
do {
|
|
||||||
++count;
|
|
||||||
suffix = (boost::format("%02d") % (count + 1)).str();
|
|
||||||
}
|
|
||||||
while (store.search(prefix + suffix) != 0);
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RaceDialog::close()
|
void RaceDialog::close()
|
||||||
{
|
{
|
||||||
delete mPreview;
|
delete mPreview;
|
||||||
|
@ -229,28 +233,67 @@ void RaceDialog::onSelectNextGender(MyGUI::Widget*)
|
||||||
|
|
||||||
void RaceDialog::onSelectPreviousFace(MyGUI::Widget*)
|
void RaceDialog::onSelectPreviousFace(MyGUI::Widget*)
|
||||||
{
|
{
|
||||||
|
do
|
||||||
mFaceIndex = wrap(mFaceIndex - 1, mFaceCount);
|
mFaceIndex = wrap(mFaceIndex - 1, mFaceCount);
|
||||||
|
while (!isFacePlayable());
|
||||||
updatePreview();
|
updatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RaceDialog::onSelectNextFace(MyGUI::Widget*)
|
void RaceDialog::onSelectNextFace(MyGUI::Widget*)
|
||||||
{
|
{
|
||||||
|
do
|
||||||
mFaceIndex = wrap(mFaceIndex + 1, mFaceCount);
|
mFaceIndex = wrap(mFaceIndex + 1, mFaceCount);
|
||||||
|
while (!isFacePlayable());
|
||||||
updatePreview();
|
updatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RaceDialog::onSelectPreviousHair(MyGUI::Widget*)
|
void RaceDialog::onSelectPreviousHair(MyGUI::Widget*)
|
||||||
{
|
{
|
||||||
|
do
|
||||||
mHairIndex = wrap(mHairIndex - 1, mHairCount);
|
mHairIndex = wrap(mHairIndex - 1, mHairCount);
|
||||||
|
while (!isHairPlayable());
|
||||||
updatePreview();
|
updatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RaceDialog::onSelectNextHair(MyGUI::Widget*)
|
void RaceDialog::onSelectNextHair(MyGUI::Widget*)
|
||||||
{
|
{
|
||||||
|
do
|
||||||
mHairIndex = wrap(mHairIndex + 1, mHairCount);
|
mHairIndex = wrap(mHairIndex + 1, mHairCount);
|
||||||
|
while (!isHairPlayable());
|
||||||
updatePreview();
|
updatePreview();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RaceDialog::isFacePlayable()
|
||||||
|
{
|
||||||
|
std::string prefix =
|
||||||
|
"b_n_" + mCurrentRaceId + ((mGenderIndex == 0) ? "_m_" : "_f_");
|
||||||
|
|
||||||
|
std::string headIndex = (boost::format("%02d") % (mFaceIndex + 1)).str();
|
||||||
|
|
||||||
|
const MWWorld::Store<ESM::BodyPart> &parts =
|
||||||
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::BodyPart>();
|
||||||
|
|
||||||
|
if (parts.search(prefix + "head_" + headIndex) == 0)
|
||||||
|
return !(parts.find(prefix + "head" + headIndex)->mData.mFlags & ESM::BodyPart::BPF_NotPlayable);
|
||||||
|
else
|
||||||
|
return !(parts.find(prefix + "head_" + headIndex)->mData.mFlags & ESM::BodyPart::BPF_NotPlayable);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RaceDialog::isHairPlayable()
|
||||||
|
{
|
||||||
|
std::string prefix =
|
||||||
|
"b_n_" + mCurrentRaceId + ((mGenderIndex == 0) ? "_m_" : "_f_");
|
||||||
|
|
||||||
|
std::string hairIndex = (boost::format("%02d") % (mHairIndex + 1)).str();
|
||||||
|
|
||||||
|
const MWWorld::Store<ESM::BodyPart> &parts =
|
||||||
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::BodyPart>();
|
||||||
|
if (parts.search(prefix + "hair_" + hairIndex) == 0)
|
||||||
|
return !(parts.find(prefix + "hair" + hairIndex)->mData.mFlags & ESM::BodyPart::BPF_NotPlayable);
|
||||||
|
else
|
||||||
|
return !(parts.find(prefix + "hair_" + hairIndex)->mData.mFlags & ESM::BodyPart::BPF_NotPlayable);
|
||||||
|
}
|
||||||
|
|
||||||
void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index)
|
void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index)
|
||||||
{
|
{
|
||||||
if (_index == MyGUI::ITEM_NONE)
|
if (_index == MyGUI::ITEM_NONE)
|
||||||
|
@ -273,11 +316,16 @@ void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index)
|
||||||
|
|
||||||
void RaceDialog::recountParts()
|
void RaceDialog::recountParts()
|
||||||
{
|
{
|
||||||
|
mFaceCount = countParts("head", mCurrentRaceId, mGenderIndex == 0);
|
||||||
|
mHairCount = countParts("hair", mCurrentRaceId, mGenderIndex == 0);
|
||||||
|
|
||||||
mFaceIndex = 0;
|
mFaceIndex = 0;
|
||||||
mHairIndex = 0;
|
mHairIndex = 0;
|
||||||
|
|
||||||
mFaceCount = countParts("head", mCurrentRaceId, mGenderIndex == 0);
|
while (!isHairPlayable())
|
||||||
mHairCount = countParts("hair", mCurrentRaceId, mGenderIndex == 0);
|
mHairIndex = wrap(mHairIndex + 1, mHairCount);
|
||||||
|
while (!isFacePlayable())
|
||||||
|
mFaceIndex = wrap(mFaceIndex + 1, mFaceCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// update widget content
|
// update widget content
|
||||||
|
|
|
@ -81,6 +81,9 @@ namespace MWGui
|
||||||
void updatePreview();
|
void updatePreview();
|
||||||
void recountParts();
|
void recountParts();
|
||||||
|
|
||||||
|
bool isHairPlayable();
|
||||||
|
bool isFacePlayable();
|
||||||
|
|
||||||
MyGUI::ImageBox* mPreviewImage;
|
MyGUI::ImageBox* mPreviewImage;
|
||||||
MyGUI::ListBox* mRaceList;
|
MyGUI::ListBox* mRaceList;
|
||||||
MyGUI::ScrollBar* mHeadRotate;
|
MyGUI::ScrollBar* mHeadRotate;
|
||||||
|
|
|
@ -129,9 +129,6 @@ namespace MWGui
|
||||||
MWWorld::Ptr gold;
|
MWWorld::Ptr gold;
|
||||||
MWWorld::ContainerStore& playerStore = mWindowManager.getInventoryWindow()->getContainerStore();
|
MWWorld::ContainerStore& playerStore = mWindowManager.getInventoryWindow()->getContainerStore();
|
||||||
|
|
||||||
const MWWorld::Store<ESM::GameSetting> &gmst =
|
|
||||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
|
|
||||||
|
|
||||||
for (MWWorld::ContainerStoreIterator it = playerStore.begin();
|
for (MWWorld::ContainerStoreIterator it = playerStore.begin();
|
||||||
it != playerStore.end(); ++it)
|
it != playerStore.end(); ++it)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,7 +33,7 @@ struct BodyPart
|
||||||
enum Flags
|
enum Flags
|
||||||
{
|
{
|
||||||
BPF_Female = 1,
|
BPF_Female = 1,
|
||||||
BPF_Playable = 2
|
BPF_NotPlayable = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
enum MeshType
|
enum MeshType
|
||||||
|
|
Loading…
Reference in a new issue