diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp index 4778460551..1719c57687 100644 --- a/apps/openmw/mwgui/charactercreation.cpp +++ b/apps/openmw/mwgui/charactercreation.cpp @@ -461,10 +461,10 @@ void CharacterCreation::onRaceDialogBack() if (mRaceDialog) { const ESM::NPC &data = mRaceDialog->getResult(); - mPlayerRaceId = data.mId; + mPlayerRaceId = data.mRace; if (!mPlayerRaceId.empty()) { MWBase::Environment::get().getMechanicsManager()->setPlayerRace( - data.mId, + data.mRace, data.isMale(), data.mHead, data.mHair diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index ff7c01ade6..d2714fb510 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -5,6 +5,7 @@ #include #include +#include #include "../mwworld/esmstore.hpp" @@ -108,6 +109,16 @@ void RaceDialog::open() MWBase::Environment::get().getWorld ()->setupExternalRendering (*mPreview); mPreview->update (0); + const ESM::NPC proto = mPreview->getPrototype(); + setRaceId(proto.mRace); + recountParts(); + + std::string index = proto.mHead.substr(proto.mHead.size() - 2, 2); + mFaceIndex = boost::lexical_cast(index) - 1; + + index = proto.mHair.substr(proto.mHair.size() - 2, 2); + mHairIndex = boost::lexical_cast(index) - 1; + mPreviewImage->setImageTexture ("CharacterHeadPreview"); } @@ -143,6 +154,35 @@ int wrap(int index, int max) return index; } +int countParts(const std::string &part, const std::string &race, bool male) +{ + const MWWorld::Store &store = + MWBase::Environment::get().getWorld()->getStore().get(); + + 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() { delete mPreview; @@ -174,31 +214,41 @@ void RaceDialog::onHeadRotate(MyGUI::ScrollBar*, size_t _position) void RaceDialog::onSelectPreviousGender(MyGUI::Widget*) { mGenderIndex = wrap(mGenderIndex - 1, 2); + + recountParts(); + updatePreview(); } void RaceDialog::onSelectNextGender(MyGUI::Widget*) { mGenderIndex = wrap(mGenderIndex + 1, 2); + + recountParts(); + updatePreview(); } void RaceDialog::onSelectPreviousFace(MyGUI::Widget*) { mFaceIndex = wrap(mFaceIndex - 1, mFaceCount); + updatePreview(); } void RaceDialog::onSelectNextFace(MyGUI::Widget*) { mFaceIndex = wrap(mFaceIndex + 1, mFaceCount); + updatePreview(); } void RaceDialog::onSelectPreviousHair(MyGUI::Widget*) { mHairIndex = wrap(mHairIndex - 1, mHairCount); + updatePreview(); } void RaceDialog::onSelectNextHair(MyGUI::Widget*) { - mHairIndex = wrap(mHairIndex - 1, mHairCount); + mHairIndex = wrap(mHairIndex + 1, mHairCount); + updatePreview(); } void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index) @@ -215,6 +265,26 @@ void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index) mCurrentRaceId = *raceId; + recountParts(); + + updatePreview(); + updateSkills(); + updateSpellPowers(); +} + +void RaceDialog::recountParts() +{ + mFaceIndex = 0; + mHairIndex = 0; + + mFaceCount = countParts("head", mCurrentRaceId, mGenderIndex == 0); + mHairCount = countParts("hair", mCurrentRaceId, mGenderIndex == 0); +} + +// update widget content + +void RaceDialog::updatePreview() +{ ESM::NPC record = mPreview->getPrototype(); record.mRace = mCurrentRaceId; record.setIsMale(mGenderIndex == 0); @@ -222,27 +292,21 @@ void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index) std::string prefix = "b_n_" + mCurrentRaceId + ((record.isMale()) ? "_m_" : "_f_"); - record.mHead = prefix + "head_01"; - record.mHair = prefix + "hair_01"; + std::string headIndex = (boost::format("%02d") % (mFaceIndex + 1)).str(); + std::string hairIndex = (boost::format("%02d") % (mHairIndex + 1)).str(); + + record.mHead = prefix + "head_" + headIndex; + record.mHair = prefix + "hair_" + hairIndex; const MWWorld::Store &parts = MWBase::Environment::get().getWorld()->getStore().get(); if (parts.search(record.mHair) == 0) { - record.mHair = prefix + "hair01"; + record.mHair = prefix + "hair" + hairIndex; } - - mFaceIndex = 0; - mHairIndex = 0; - mPreview->setPrototype(record); - - updateSkills(); - updateSpellPowers(); } -// update widget content - void RaceDialog::updateRaces() { mRaceList->removeAllItems(); diff --git a/apps/openmw/mwgui/race.hpp b/apps/openmw/mwgui/race.hpp index ec73d1c3a4..e0dc3306a8 100644 --- a/apps/openmw/mwgui/race.hpp +++ b/apps/openmw/mwgui/race.hpp @@ -78,6 +78,8 @@ namespace MWGui void updateRaces(); void updateSkills(); void updateSpellPowers(); + void updatePreview(); + void recountParts(); MyGUI::ImageBox* mPreviewImage; MyGUI::ListBox* mRaceList; diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index ef92497e55..2a3b8cf437 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -7,7 +7,6 @@ #include #include - namespace MWRender { diff --git a/apps/openmw/mwrender/player.cpp b/apps/openmw/mwrender/player.cpp index 8578788118..be2a793e8d 100644 --- a/apps/openmw/mwrender/player.cpp +++ b/apps/openmw/mwrender/player.cpp @@ -310,10 +310,13 @@ namespace MWRender void Player::setAnimation(NpcAnimation *anim) { - if (mAnimation) { - delete mAnimation; - } + delete mAnimation; mAnimation = anim; + + mPlayerNode->setVisible( + mVanity.enabled || mPreviewMode || !mFirstPersonView, + false + ); } void Player::setHeight(float height)