From 50867e8d87b3efefb566016fa54d6094cb15430c Mon Sep 17 00:00:00 2001 From: greye Date: Sat, 10 Nov 2012 19:57:50 +0400 Subject: [PATCH 1/3] fix gender selection update, main model visibility and couple of crashes --- apps/openmw/mwgui/charactercreation.cpp | 4 +-- apps/openmw/mwgui/race.cpp | 43 ++++++++++++++++++------- apps/openmw/mwgui/race.hpp | 1 + apps/openmw/mwrender/animation.cpp | 1 - apps/openmw/mwrender/player.cpp | 9 ++++-- 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/apps/openmw/mwgui/charactercreation.cpp b/apps/openmw/mwgui/charactercreation.cpp index 477846055..1719c5768 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 ff7c01ade..fbebbe897 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,8 @@ void RaceDialog::open() MWBase::Environment::get().getWorld ()->setupExternalRendering (*mPreview); mPreview->update (0); + setRaceId(mPreview->getPrototype().mRace); + mPreviewImage->setImageTexture ("CharacterHeadPreview"); } @@ -174,11 +177,21 @@ void RaceDialog::onHeadRotate(MyGUI::ScrollBar*, size_t _position) void RaceDialog::onSelectPreviousGender(MyGUI::Widget*) { mGenderIndex = wrap(mGenderIndex - 1, 2); + + mFaceIndex = 0; + mHairIndex = 0; + + updatePreview(); } void RaceDialog::onSelectNextGender(MyGUI::Widget*) { mGenderIndex = wrap(mGenderIndex + 1, 2); + + mFaceIndex = 0; + mHairIndex = 0; + + updatePreview(); } void RaceDialog::onSelectPreviousFace(MyGUI::Widget*) @@ -215,6 +228,18 @@ void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index) mCurrentRaceId = *raceId; + mFaceIndex = 0; + mHairIndex = 0; + + updatePreview(); + updateSkills(); + updateSpellPowers(); +} + +// update widget content + +void RaceDialog::updatePreview() +{ ESM::NPC record = mPreview->getPrototype(); record.mRace = mCurrentRaceId; record.setIsMale(mGenderIndex == 0); @@ -222,27 +247,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 ec73d1c3a..fbed39baf 100644 --- a/apps/openmw/mwgui/race.hpp +++ b/apps/openmw/mwgui/race.hpp @@ -78,6 +78,7 @@ namespace MWGui void updateRaces(); void updateSkills(); void updateSpellPowers(); + void updatePreview(); MyGUI::ImageBox* mPreviewImage; MyGUI::ListBox* mRaceList; diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index ef92497e5..2a3b8cf43 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 857878811..be2a793e8 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) From 0d33d005a5cca0dfea7c3d6b822cef62d2253a60 Mon Sep 17 00:00:00 2001 From: greye Date: Sat, 10 Nov 2012 21:30:16 +0400 Subject: [PATCH 2/3] head/hair selection --- apps/openmw/mwgui/race.cpp | 54 ++++++++++++++++++++++++++++++++------ apps/openmw/mwgui/race.hpp | 1 + 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index fbebbe897..fd64c6342 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -110,6 +110,7 @@ void RaceDialog::open() mPreview->update (0); setRaceId(mPreview->getPrototype().mRace); + recountParts(); mPreviewImage->setImageTexture ("CharacterHeadPreview"); } @@ -146,6 +147,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; @@ -178,9 +208,7 @@ void RaceDialog::onSelectPreviousGender(MyGUI::Widget*) { mGenderIndex = wrap(mGenderIndex - 1, 2); - mFaceIndex = 0; - mHairIndex = 0; - + recountParts(); updatePreview(); } @@ -188,30 +216,32 @@ void RaceDialog::onSelectNextGender(MyGUI::Widget*) { mGenderIndex = wrap(mGenderIndex + 1, 2); - mFaceIndex = 0; - mHairIndex = 0; - + 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); + updatePreview(); } void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index) @@ -228,14 +258,22 @@ void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index) mCurrentRaceId = *raceId; - mFaceIndex = 0; - mHairIndex = 0; + 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() diff --git a/apps/openmw/mwgui/race.hpp b/apps/openmw/mwgui/race.hpp index fbed39baf..e0dc3306a 100644 --- a/apps/openmw/mwgui/race.hpp +++ b/apps/openmw/mwgui/race.hpp @@ -79,6 +79,7 @@ namespace MWGui void updateSkills(); void updateSpellPowers(); void updatePreview(); + void recountParts(); MyGUI::ImageBox* mPreviewImage; MyGUI::ListBox* mRaceList; From 623e00531d2e1ba50cb53ee0a2dc94a03113056a Mon Sep 17 00:00:00 2001 From: greye Date: Sat, 10 Nov 2012 21:54:43 +0400 Subject: [PATCH 3/3] fix reentering race selection --- apps/openmw/mwgui/race.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/race.cpp b/apps/openmw/mwgui/race.cpp index fd64c6342..d2714fb51 100644 --- a/apps/openmw/mwgui/race.cpp +++ b/apps/openmw/mwgui/race.cpp @@ -109,8 +109,15 @@ void RaceDialog::open() MWBase::Environment::get().getWorld ()->setupExternalRendering (*mPreview); mPreview->update (0); - setRaceId(mPreview->getPrototype().mRace); + 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"); } @@ -240,7 +247,7 @@ void RaceDialog::onSelectPreviousHair(MyGUI::Widget*) void RaceDialog::onSelectNextHair(MyGUI::Widget*) { - mHairIndex = wrap(mHairIndex - 1, mHairCount); + mHairIndex = wrap(mHairIndex + 1, mHairCount); updatePreview(); }