race selection/inventory preview character model update

actorid
greye 12 years ago
parent c3f0dc0dfb
commit b1ef0026a9

@ -62,7 +62,7 @@ namespace MWBase
virtual void setPlayerName (const std::string& name) = 0; virtual void setPlayerName (const std::string& name) = 0;
///< Set player name. ///< Set player name.
virtual void setPlayerRace (const std::string& id, bool male) = 0; virtual void setPlayerRace (const std::string& id, bool male, const std::string &head, const std::string &hair) = 0;
///< Set player race. ///< Set player race.
virtual void setPlayerBirthsign (const std::string& id) = 0; virtual void setPlayerBirthsign (const std::string& id) = 0;

@ -7,6 +7,7 @@
#include "review.hpp" #include "review.hpp"
#include "dialogue.hpp" #include "dialogue.hpp"
#include "mode.hpp" #include "mode.hpp"
#include "inventorywindow.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
@ -459,9 +460,16 @@ void CharacterCreation::onRaceDialogBack()
{ {
if (mRaceDialog) if (mRaceDialog)
{ {
mPlayerRaceId = mRaceDialog->getRaceId(); const ESM::NPC &data = mRaceDialog->getResult();
if (!mPlayerRaceId.empty()) mPlayerRaceId = data.mId;
MWBase::Environment::get().getMechanicsManager()->setPlayerRace(mPlayerRaceId, mRaceDialog->getGender() == RaceDialog::GM_Male); if (!mPlayerRaceId.empty()) {
MWBase::Environment::get().getMechanicsManager()->setPlayerRace(
data.mId,
data.isMale(),
data.mHead,
data.mHair
);
}
mWM->removeDialog(mRaceDialog); mWM->removeDialog(mRaceDialog);
mRaceDialog = 0; mRaceDialog = 0;
} }
@ -474,10 +482,18 @@ void CharacterCreation::onRaceDialogDone(WindowBase* parWindow)
{ {
if (mRaceDialog) if (mRaceDialog)
{ {
mPlayerRaceId = mRaceDialog->getRaceId(); const ESM::NPC &data = mRaceDialog->getResult();
mWM->setValue("race", mPlayerRaceId); mPlayerRaceId = data.mRace;
if (!mPlayerRaceId.empty()) if (!mPlayerRaceId.empty()) {
MWBase::Environment::get().getMechanicsManager()->setPlayerRace(mPlayerRaceId, mRaceDialog->getGender() == RaceDialog::GM_Male); MWBase::Environment::get().getMechanicsManager()->setPlayerRace(
data.mRace,
data.isMale(),
data.mHead,
data.mHair
);
}
mWM->getInventoryWindow()->rebuildAvatar();
mWM->removeDialog(mRaceDialog); mWM->removeDialog(mRaceDialog);
mRaceDialog = 0; mRaceDialog = 0;
} }

@ -28,6 +28,10 @@ namespace MWGui
MWWorld::Ptr getAvatarSelectedItem(int x, int y); MWWorld::Ptr getAvatarSelectedItem(int x, int y);
void rebuildAvatar() {
mPreview.rebuild();
}
protected: protected:
MyGUI::Widget* mAvatar; MyGUI::Widget* mAvatar;
MyGUI::ImageBox* mAvatarImage; MyGUI::ImageBox* mAvatarImage;

@ -214,6 +214,29 @@ void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index)
return; return;
mCurrentRaceId = *raceId; mCurrentRaceId = *raceId;
ESM::NPC record = mPreview->getPrototype();
record.mRace = mCurrentRaceId;
record.setIsMale(mGenderIndex == 0);
std::string prefix =
"b_n_" + mCurrentRaceId + ((record.isMale()) ? "_m_" : "_f_");
record.mHead = prefix + "head_01";
record.mHair = prefix + "hair_01";
const MWWorld::Store<ESM::BodyPart> &parts =
MWBase::Environment::get().getWorld()->getStore().get<ESM::BodyPart>();
if (parts.search(record.mHair) == 0) {
record.mHair = prefix + "hair01";
}
mFaceIndex = 0;
mHairIndex = 0;
mPreview->setPrototype(record);
updateSkills(); updateSkills();
updateSpellPowers(); updateSpellPowers();
} }

@ -34,6 +34,7 @@ namespace MWGui
GM_Female GM_Female
}; };
const ESM::NPC &getResult() const { return mPreview->getPrototype(); }
const std::string &getRaceId() const { return mCurrentRaceId; } const std::string &getRaceId() const { return mCurrentRaceId; }
Gender getGender() const { return mGenderIndex == 0 ? GM_Male : GM_Female; } Gender getGender() const { return mGenderIndex == 0 ? GM_Male : GM_Female; }
// getFace() // getFace()

@ -318,7 +318,7 @@ namespace MWMechanics
mUpdatePlayer = true; mUpdatePlayer = true;
} }
void MechanicsManager::setPlayerRace (const std::string& race, bool male) void MechanicsManager::setPlayerRace (const std::string& race, bool male, const std::string &head, const std::string &hair)
{ {
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
@ -326,11 +326,9 @@ namespace MWMechanics
*world->getPlayer().getPlayer().get<ESM::NPC>()->mBase; *world->getPlayer().getPlayer().get<ESM::NPC>()->mBase;
player.mRace = race; player.mRace = race;
player.mHead = head;
player.mFlags |= ESM::NPC::Female; player.mHair = hair;
if (male) { player.setIsMale(male);
player.mFlags ^= ESM::NPC::Female;
}
world->createRecord(player); world->createRecord(player);

@ -64,7 +64,7 @@ namespace MWMechanics
virtual void setPlayerName (const std::string& name); virtual void setPlayerName (const std::string& name);
///< Set player name. ///< Set player name.
virtual void setPlayerRace (const std::string& id, bool male); virtual void setPlayerRace (const std::string& id, bool male, const std::string &head, const std::string &hair);
///< Set player race. ///< Set player race.
virtual void setPlayerBirthsign (const std::string& id); virtual void setPlayerBirthsign (const std::string& id);

@ -48,8 +48,9 @@ namespace MWRender
mNode->setVisible (false); mNode->setVisible (false);
mCamera->setPosition(mPosition); Ogre::Vector3 scale = mNode->getScale();
mCamera->lookAt(mLookAt); mCamera->setPosition(mPosition * scale);
mCamera->lookAt(mLookAt * scale);
mCamera->setNearClipDistance (0.01); mCamera->setNearClipDistance (0.01);
mCamera->setFarClipDistance (1000); mCamera->setFarClipDistance (1000);
@ -80,6 +81,22 @@ namespace MWRender
delete mAnimation; delete mAnimation;
} }
void CharacterPreview::rebuild()
{
assert(mAnimation);
delete mAnimation;
mAnimation = new NpcAnimation(mCharacter, mNode,
MWWorld::Class::get(mCharacter).getInventoryStore (mCharacter), RV_PlayerPreview);
mNode->setVisible (false);
Ogre::Vector3 scale = mNode->getScale();
mCamera->setPosition(mPosition * scale);
mCamera->lookAt(mLookAt * scale);
onSetup();
}
// -------------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------------
@ -128,8 +145,10 @@ namespace MWRender
RaceSelectionPreview::RaceSelectionPreview() RaceSelectionPreview::RaceSelectionPreview()
: CharacterPreview(MWBase::Environment::get().getWorld()->getPlayer().getPlayer(), : CharacterPreview(MWBase::Environment::get().getWorld()->getPlayer().getPlayer(),
512, 512, "CharacterHeadPreview", Ogre::Vector3(0, 120, -35), Ogre::Vector3(0,125,0)) 512, 512, "CharacterHeadPreview", Ogre::Vector3(0, 120, -35), Ogre::Vector3(0,125,0))
, mRef(&mBase)
{ {
mBase = *mCharacter.get<ESM::NPC>()->mBase;
mCharacter = MWWorld::Ptr(&mRef, mCharacter.getCell());
} }
void RaceSelectionPreview::update(float angle) void RaceSelectionPreview::update(float angle)
@ -141,4 +160,11 @@ namespace MWRender
mNode->setVisible (false); mNode->setVisible (false);
} }
void RaceSelectionPreview::setPrototype(const ESM::NPC &proto)
{
mBase = proto;
mBase.mId = "player";
rebuild();
update(0);
}
} }

@ -4,6 +4,7 @@
#include <OgreRenderTarget.h> #include <OgreRenderTarget.h>
#include <OgreMaterialManager.h> #include <OgreMaterialManager.h>
#include <components/esm/loadnpc.hpp>
#include "externalrendering.hpp" #include "externalrendering.hpp"
@ -32,6 +33,7 @@ namespace MWRender
virtual void setup (Ogre::SceneManager *sceneManager); virtual void setup (Ogre::SceneManager *sceneManager);
virtual void onSetup(); virtual void onSetup();
virtual void rebuild();
protected: protected:
Ogre::TexturePtr mTexture; Ogre::TexturePtr mTexture;
@ -77,10 +79,19 @@ namespace MWRender
class RaceSelectionPreview : public CharacterPreview class RaceSelectionPreview : public CharacterPreview
{ {
ESM::NPC mBase;
MWWorld::LiveCellRef<ESM::NPC> mRef;
public: public:
RaceSelectionPreview(); RaceSelectionPreview();
void update(float angle); void update(float angle);
const ESM::NPC &getPrototype() const {
return mBase;
}
void setPrototype(const ESM::NPC &proto);
}; };
} }

@ -121,6 +121,13 @@ struct NPC
bool isMale() const { bool isMale() const {
return (mFlags & Female) == 0; return (mFlags & Female) == 0;
} }
void setIsMale(bool value) {
mFlags |= Female;
if (value) {
mFlags ^= Female;
}
}
}; };
} }
#endif #endif

Loading…
Cancel
Save