From 0d33d005a5cca0dfea7c3d6b822cef62d2253a60 Mon Sep 17 00:00:00 2001 From: greye Date: Sat, 10 Nov 2012 21:30:16 +0400 Subject: [PATCH] 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;