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;
///< 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.
virtual void setPlayerBirthsign (const std::string& id) = 0;

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

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

@ -214,6 +214,29 @@ void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index)
return;
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();
updateSpellPowers();
}

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

@ -318,7 +318,7 @@ namespace MWMechanics
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();
@ -326,11 +326,9 @@ namespace MWMechanics
*world->getPlayer().getPlayer().get<ESM::NPC>()->mBase;
player.mRace = race;
player.mFlags |= ESM::NPC::Female;
if (male) {
player.mFlags ^= ESM::NPC::Female;
}
player.mHead = head;
player.mHair = hair;
player.setIsMale(male);
world->createRecord(player);

@ -64,7 +64,7 @@ namespace MWMechanics
virtual void setPlayerName (const std::string& 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.
virtual void setPlayerBirthsign (const std::string& id);

@ -48,8 +48,9 @@ namespace MWRender
mNode->setVisible (false);
mCamera->setPosition(mPosition);
mCamera->lookAt(mLookAt);
Ogre::Vector3 scale = mNode->getScale();
mCamera->setPosition(mPosition * scale);
mCamera->lookAt(mLookAt * scale);
mCamera->setNearClipDistance (0.01);
mCamera->setFarClipDistance (1000);
@ -80,6 +81,22 @@ namespace MWRender
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()
: CharacterPreview(MWBase::Environment::get().getWorld()->getPlayer().getPlayer(),
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)
@ -141,4 +160,11 @@ namespace MWRender
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 <OgreMaterialManager.h>
#include <components/esm/loadnpc.hpp>
#include "externalrendering.hpp"
@ -32,6 +33,7 @@ namespace MWRender
virtual void setup (Ogre::SceneManager *sceneManager);
virtual void onSetup();
virtual void rebuild();
protected:
Ogre::TexturePtr mTexture;
@ -77,10 +79,19 @@ namespace MWRender
class RaceSelectionPreview : public CharacterPreview
{
ESM::NPC mBase;
MWWorld::LiveCellRef<ESM::NPC> mRef;
public:
RaceSelectionPreview();
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 {
return (mFlags & Female) == 0;
}
void setIsMale(bool value) {
mFlags |= Female;
if (value) {
mFlags ^= Female;
}
}
};
}
#endif

Loading…
Cancel
Save