Race dialog now gets the list of races and skills from the ESM store.

actorid
Jan Borsodi 15 years ago
parent 1c79a62957
commit 8f6d24bea4

@ -1,13 +1,20 @@
#include "mw_chargen.hpp" #include "mw_chargen.hpp"
#include "../mwworld/environment.hpp"
#include "../mwworld/world.hpp"
#include "components/esm_store/store.hpp"
#include <assert.h> #include <assert.h>
#include <iostream> #include <iostream>
#include <iterator> #include <iterator>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
using namespace MWGui; using namespace MWGui;
RaceDialog::RaceDialog() RaceDialog::RaceDialog(MWWorld::Environment& environment)
: Layout("openmw_chargen_race_layout.xml") : Layout("openmw_chargen_race_layout.xml")
, environment(environment)
, genderIndex(0) , genderIndex(0)
, faceIndex(0) , faceIndex(0)
, hairIndex(0) , hairIndex(0)
@ -60,6 +67,24 @@ RaceDialog::RaceDialog()
updateSpellPowers(); updateSpellPowers();
} }
void RaceDialog::setRace(const std::string &race)
{
currentRace = race;
raceList->setIndexSelected(MyGUI::ITEM_NONE);
size_t count = raceList->getItemCount();
for (size_t i = 0; i < count; ++i)
{
if (boost::iequals(raceList->getItem(i), race))
{
raceList->setIndexSelected(i);
break;
}
}
updateSkills();
updateSpellPowers();
}
int wrap(int index, int max) int wrap(int index, int max)
{ {
if (index < 0) if (index < 0)
@ -109,8 +134,12 @@ void RaceDialog::onSelectNextHair(MyGUI::Widget*)
void RaceDialog::onSelectRace(MyGUI::List* _sender, size_t _index) void RaceDialog::onSelectRace(MyGUI::List* _sender, size_t _index)
{ {
// TODO: Select actual race const std::string race = raceList->getItem(_index);
updateSkills(); if (boost::iequals(currentRace, race))
return;
currentRace = race;
updateSkills();
updateSpellPowers(); updateSpellPowers();
} }
@ -119,14 +148,20 @@ void RaceDialog::onSelectRace(MyGUI::List* _sender, size_t _index)
void RaceDialog::updateRaces() void RaceDialog::updateRaces()
{ {
raceList->removeAllItems(); raceList->removeAllItems();
raceList->addItem("Argonian");
raceList->addItem("Breton"); ESMS::ESMStore &store = environment.mWorld->getStore();
raceList->addItem("Dark Elf");
raceList->addItem("High Elf"); ESMS::RecListT<ESM::Race>::MapType::const_iterator it = store.races.list.begin();
raceList->addItem("Imperial"); ESMS::RecListT<ESM::Race>::MapType::const_iterator end = store.races.list.end();
raceList->addItem("Khajiit"); int index = 0;
raceList->addItem("Nord"); for (; it != end; ++it)
raceList->addItem("Orc"); {
const ESM::Race &race = it->second;
raceList->addItem(race.name);
if (boost::iequals(race.name, currentRace))
raceList->setIndexSelected(index);
++index;
}
} }
void RaceDialog::updateSkills() void RaceDialog::updateSkills()
@ -137,35 +172,35 @@ void RaceDialog::updateSkills()
} }
skillItems.clear(); skillItems.clear();
MyGUI::StaticTextPtr skillName, skillBonus; if (currentRace.empty())
return;
MyGUI::StaticTextPtr skillNameWidget, skillBonusWidget;
const int lineHeight = 18; const int lineHeight = 18;
MyGUI::IntCoord coord1(0, 0, skillList->getWidth() - (40 + 4), 18); MyGUI::IntCoord coord1(0, 0, skillList->getWidth() - (40 + 4), 18);
MyGUI::IntCoord coord2(coord1.left + coord1.width, 0, 40, 18); MyGUI::IntCoord coord2(coord1.left + coord1.width, 0, 40, 18);
const char *inputList[][2] = { ESMS::ESMStore &store = environment.mWorld->getStore();
{"Athletics", "5"}, const ESM::Race *race = store.races.find(currentRace);
{"Destruction", "10"}, int count = sizeof(race->data.bonus)/sizeof(race->data.bonus[0]); // TODO: Find a portable macro for this ARRAYSIZE?
{"Light Armor", "5"}, for (int i = 0; i < count; ++i)
{"Long Blade", "5"},
{"Marksman", "5"},
{"Mysticism", "5"},
{"Short Blade", "10"},
{0,0}
};
for (int i = 0; inputList[i][0]; ++i)
{ {
std::ostringstream name; int skillId = race->data.bonus[i].skill;
name << std::string("SkillName") << i; if (skillId < 0 || skillId > ESM::Skill::Length) // Skip unknown skill indexes
skillName = skillList->createWidget<MyGUI::StaticText>("SandText", coord1, MyGUI::Align::Default, name.str()); continue;
skillName->setCaption(inputList[i][0]);
std::ostringstream bonus; skillNameWidget = skillList->createWidget<MyGUI::StaticText>("SandText", coord1, MyGUI::Align::Default,
bonus << std::string("SkillBonus") << i; std::string("SkillName") + boost::lexical_cast<std::string>(i));
skillBonus = skillList->createWidget<MyGUI::StaticText>("SandTextRight", coord2, MyGUI::Align::Default, bonus.str()); assert(skillId >= 0 && skillId < ESM::Skill::Length);
skillBonus->setCaption(inputList[i][1]); skillNameWidget->setCaption(ESMS::Skill::sSkillNames[skillId]);
skillItems.push_back(skillName); skillBonusWidget = skillList->createWidget<MyGUI::StaticText>("SandTextRight", coord2, MyGUI::Align::Default,
skillItems.push_back(skillBonus); std::string("SkillBonus") + boost::lexical_cast<std::string>(i));
int bonus = race->data.bonus[i].bonus;
skillBonusWidget->setCaption(boost::lexical_cast<std::string>(bonus));
skillItems.push_back(skillNameWidget);
skillItems.push_back(skillBonusWidget);
coord1.top += lineHeight; coord1.top += lineHeight;
coord2.top += lineHeight; coord2.top += lineHeight;

@ -7,6 +7,11 @@
#include <boost/array.hpp> #include <boost/array.hpp>
namespace MWWorld
{
class Environment;
}
/* /*
This file contains classes corresponding to all the dialogs This file contains classes corresponding to all the dialogs
for the character generation, layouts are defined in resources/mygui/ *.xml. for the character generation, layouts are defined in resources/mygui/ *.xml.
@ -27,7 +32,9 @@ namespace MWGui
class RaceDialog : public OEngine::GUI::Layout class RaceDialog : public OEngine::GUI::Layout
{ {
public: public:
RaceDialog(); RaceDialog(MWWorld::Environment& environment);
void setRace(const std::string &race);
protected: protected:
void onHeadRotate(MyGUI::VScroll* _sender, size_t _position); void onHeadRotate(MyGUI::VScroll* _sender, size_t _position);
@ -48,6 +55,8 @@ namespace MWGui
void updateSkills(); void updateSkills();
void updateSpellPowers(); void updateSpellPowers();
MWWorld::Environment& environment;
MyGUI::CanvasPtr appearanceBox; MyGUI::CanvasPtr appearanceBox;
MyGUI::ListPtr raceList; MyGUI::ListPtr raceList;
MyGUI::HScrollPtr headRotate; MyGUI::HScrollPtr headRotate;
@ -60,6 +69,8 @@ namespace MWGui
int genderIndex, faceIndex, hairIndex; int genderIndex, faceIndex, hairIndex;
int faceCount, hairCount; int faceCount, hairCount;
std::string currentRace;
}; };
} }
#endif #endif

@ -26,7 +26,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment
inventory = new InventoryWindow (); inventory = new InventoryWindow ();
console = new Console(w,h, environment, extensions); console = new Console(w,h, environment, extensions);
raceDialog = new RaceDialog (); raceDialog = new RaceDialog (environment);
// The HUD is always on // The HUD is always on
hud->setVisible(true); hud->setVisible(true);

Loading…
Cancel
Save