Created a class for char gen, and starting moving code to it

actorid
Cris Mihalache 13 years ago
parent a17c193f56
commit 4b758376be

1
.gitignore vendored

@ -7,3 +7,4 @@ Docs/mainpage.hpp
CMakeFiles CMakeFiles
*/CMakeFiles */CMakeFiles
CMakeCache.txt CMakeCache.txt
data

@ -23,7 +23,7 @@ add_openmw_dir (mwinput
add_openmw_dir (mwgui add_openmw_dir (mwgui
layouts text_input widgets race class birth review window_manager console dialogue layouts text_input widgets race class birth review window_manager console dialogue
dialogue_history window_base stats_window messagebox journalwindow dialogue_history window_base stats_window messagebox journalwindow character_creation
) )
add_openmw_dir (mwdialogue add_openmw_dir (mwdialogue

@ -45,6 +45,15 @@ namespace MWGui
GW_ALL = 0xFF GW_ALL = 0xFF
}; };
// Character creation dialogs
enum CharGen
{
GEN_Name,
GEN_Race,
GEN_Class,
GEN_Sign
};
} }
#endif #endif

@ -1,7 +1,6 @@
#include "window_manager.hpp" #include "window_manager.hpp"
#include "layouts.hpp" #include "layouts.hpp"
#include "text_input.hpp" #include "text_input.hpp"
#include "race.hpp"
#include "class.hpp" #include "class.hpp"
#include "birth.hpp" #include "birth.hpp"
#include "review.hpp" #include "review.hpp"
@ -15,6 +14,7 @@
#include "console.hpp" #include "console.hpp"
#include "journalwindow.hpp" #include "journalwindow.hpp"
#include "character_creation.hpp"
#include <assert.h> #include <assert.h>
#include <iostream> #include <iostream>
@ -25,13 +25,10 @@ using namespace MWGui;
WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment, WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment,
const Compiler::Extensions& extensions, int fpsLevel, bool newGame) const Compiler::Extensions& extensions, int fpsLevel, bool newGame)
: environment(environment) : environment(environment)
, nameDialog(nullptr)
, raceDialog(nullptr)
, dialogueWindow(nullptr) , dialogueWindow(nullptr)
, classChoiceDialog(nullptr) , classChoiceDialog(nullptr)
, generateClassQuestionDialog(nullptr) , generateClassQuestionDialog(nullptr)
, generateClassResultDialog(nullptr) , generateClassResultDialog(nullptr)
, pickClassDialog(nullptr)
, createClassDialog(nullptr) , createClassDialog(nullptr)
, birthSignDialog(nullptr) , birthSignDialog(nullptr)
, reviewDialog(nullptr) , reviewDialog(nullptr)
@ -44,6 +41,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment
{ {
showFPSLevel = fpsLevel; showFPSLevel = fpsLevel;
/// REMOVE
creationStage = NotStarted; creationStage = NotStarted;
//Register own widgets with MyGUI //Register own widgets with MyGUI
@ -68,6 +66,8 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment
// The HUD is always on // The HUD is always on
hud->setVisible(true); hud->setVisible(true);
mCharGen = new CharacterCreation(this);
// Setup player stats // Setup player stats
for (int i = 0; i < ESM::Attribute::Length; ++i) for (int i = 0; i < ESM::Attribute::Length; ++i)
{ {
@ -102,13 +102,10 @@ WindowManager::~WindowManager()
delete inventory; delete inventory;
#endif #endif
delete nameDialog;
delete raceDialog;
delete dialogueWindow; delete dialogueWindow;
delete classChoiceDialog; delete classChoiceDialog;
delete generateClassQuestionDialog; delete generateClassQuestionDialog;
delete generateClassResultDialog; delete generateClassResultDialog;
delete pickClassDialog;
delete createClassDialog; delete createClassDialog;
delete birthSignDialog; delete birthSignDialog;
delete reviewDialog; delete reviewDialog;
@ -129,6 +126,11 @@ void WindowManager::cleanupGarbage()
} }
} }
MWMechanics::MechanicsManager* WindowManager::getMechanicsManager()
{
return environment.mMechanicsManager;
}
void WindowManager::update() void WindowManager::update()
{ {
cleanupGarbage(); cleanupGarbage();
@ -178,7 +180,7 @@ void WindowManager::updateVisible()
gui->setVisiblePointer(isGuiMode()); gui->setVisiblePointer(isGuiMode());
// If in game mode, don't show anything. // If in game mode, don't show anything.
if(mode == GM_Game) if(mode == GM_Game) //Use a switch/case structure
{ {
return; return;
} }
@ -196,40 +198,21 @@ void WindowManager::updateVisible()
return; return;
} }
if (mode == GM_Name) if (mode == GM_Name) //Combine this with all char-gen related if statements
{ {
if (nameDialog) mCharGen->spawnDialog(GM_Name);
removeDialog(nameDialog);
nameDialog = new TextInputDialog(*this);
std::string sName = getGameSettingString("sName", "Name");
nameDialog->setTextLabel(sName);
nameDialog->setTextInput(playerName);
nameDialog->setNextButtonShow(creationStage >= NameChosen);
nameDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onNameDialogDone);
nameDialog->open();
return; return;
} }
if (mode == GM_Race) if (mode == GM_Race) //Combine this with all char-gen related if statements
{ {
if (raceDialog) mCharGen->spawnDialog(GM_Race);
removeDialog(raceDialog);
raceDialog = new RaceDialog(*this);
raceDialog->setNextButtonShow(creationStage >= RaceChosen);
raceDialog->setRaceId(playerRaceId);
raceDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onRaceDialogDone);
raceDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onRaceDialogBack);
raceDialog->open();
return; return;
} }
if (mode == GM_Class) if (mode == GM_Class)
{ {
if (classChoiceDialog) mCharGen->spawnDialog(GM_Class);
removeDialog(classChoiceDialog);
classChoiceDialog = new ClassChoiceDialog(*this);
classChoiceDialog->eventButtonSelected = MyGUI::newDelegate(this, &WindowManager::onClassChoice);
classChoiceDialog->open();
return; return;
} }
@ -246,14 +229,7 @@ void WindowManager::updateVisible()
if (mode == GM_ClassPick) if (mode == GM_ClassPick)
{ {
if (pickClassDialog) mCharGen->spawnDialog(GM_ClassPick);
removeDialog(pickClassDialog);
pickClassDialog = new PickClassDialog(*this);
pickClassDialog->setNextButtonShow(creationStage >= ClassChosen);
pickClassDialog->setClassId(playerClass.name);
pickClassDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onPickClassDialogDone);
pickClassDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onPickClassDialogBack);
pickClassDialog->open();
return; return;
} }
@ -286,7 +262,7 @@ void WindowManager::updateVisible()
if (reviewDialog) if (reviewDialog)
removeDialog(reviewDialog); removeDialog(reviewDialog);
reviewDialog = new ReviewDialog(*this); reviewDialog = new ReviewDialog(*this);
reviewDialog->setPlayerName(playerName); //reviewDialog->setPlayerName(playerName); //Move this to Chargen as part of refactoring
reviewDialog->setRace(playerRaceId); reviewDialog->setRace(playerRaceId);
reviewDialog->setClass(playerClass); reviewDialog->setClass(playerClass);
reviewDialog->setBirthSign(playerBirthSignId); reviewDialog->setBirthSign(playerBirthSignId);
@ -420,10 +396,10 @@ void WindowManager::setValue (const std::string& id, const MWMechanics::DynamicS
void WindowManager::setValue (const std::string& id, const std::string& value) void WindowManager::setValue (const std::string& id, const std::string& value)
{ {
stats->setValue (id, value); stats->setValue (id, value);
if (id=="name") /*if (id=="name")
playerName = value; playerName = value;
else if (id=="race") else if (id=="race")
playerRaceId = value; playerRaceId = value;*/ //Move this to chargen
} }
void WindowManager::setValue (const std::string& id, int value) void WindowManager::setValue (const std::string& id, int value)
@ -505,49 +481,6 @@ const std::string &WindowManager::getGameSettingString(const std::string &id, co
return default_; return default_;
} }
void WindowManager::onNameDialogDone(WindowBase* parWindow)
{
if (nameDialog)
{
playerName = nameDialog->getTextInput();
environment.mMechanicsManager->setPlayerName(playerName);
removeDialog(nameDialog);
}
// Go to next dialog if name was previously chosen
if (creationStage == ReviewNext)
setGuiMode(GM_Review);
else if (creationStage >= NameChosen)
setGuiMode(GM_Race);
else
{
creationStage = NameChosen;
setGuiMode(GM_Game);
}
}
void WindowManager::onRaceDialogDone(WindowBase* parWindow)
{
if (raceDialog)
{
playerRaceId = raceDialog->getRaceId();
if (!playerRaceId.empty())
environment.mMechanicsManager->setPlayerRace(playerRaceId, raceDialog->getGender() == RaceDialog::GM_Male);
removeDialog(raceDialog);
}
// Go to next dialog if race was previously chosen
if (creationStage == ReviewNext)
setGuiMode(GM_Review);
else if(creationStage >= RaceChosen)
setGuiMode(GM_Class);
else
{
creationStage = RaceChosen;
setGuiMode(GM_Game);
}
}
void WindowManager::onDialogueWindowBye() void WindowManager::onDialogueWindowBye()
{ {
if (dialogueWindow) if (dialogueWindow)
@ -558,44 +491,6 @@ void WindowManager::onDialogueWindowBye()
setGuiMode(GM_Game); setGuiMode(GM_Game);
} }
void WindowManager::onRaceDialogBack()
{
if (raceDialog)
{
playerRaceId = raceDialog->getRaceId();
if (!playerRaceId.empty())
environment.mMechanicsManager->setPlayerRace(playerRaceId, raceDialog->getGender() == RaceDialog::GM_Male);
removeDialog(raceDialog);
}
setGuiMode(GM_Name);
}
void WindowManager::onClassChoice(int _index)
{
if (classChoiceDialog)
{
removeDialog(classChoiceDialog);
}
switch(_index)
{
case ClassChoiceDialog::Class_Generate:
setGuiMode(GM_ClassGenerate);
break;
case ClassChoiceDialog::Class_Pick:
setGuiMode(GM_ClassPick);
break;
case ClassChoiceDialog::Class_Create:
setGuiMode(GM_ClassCreate);
break;
case ClassChoiceDialog::Class_Back:
setGuiMode(GM_Race);
break;
};
}
void WindowManager::onFrame (float frameDuration) void WindowManager::onFrame (float frameDuration)
{ {
mMessageBoxManager->onFrame(frameDuration); mMessageBoxManager->onFrame(frameDuration);
@ -828,43 +723,9 @@ void WindowManager::onGenerateClassDone(WindowBase* parWindow)
} }
} }
MWWorld::World* WindowManager::getWorld()
void WindowManager::onPickClassDialogDone(WindowBase* parWindow)
{ {
if (pickClassDialog) return environment.mWorld;
{
const std::string &classId = pickClassDialog->getClassId();
if (!classId.empty())
environment.mMechanicsManager->setPlayerClass(classId);
const ESM::Class *klass = environment.mWorld->getStore().classes.find(classId);
if (klass)
playerClass = *klass;
removeDialog(pickClassDialog);
}
// Go to next dialog if class was previously chosen
if (creationStage == ReviewNext)
setGuiMode(GM_Review);
else if (creationStage >= ClassChosen)
setGuiMode(GM_Birth);
else
{
creationStage = ClassChosen;
setGuiMode(GM_Game);
}
}
void WindowManager::onPickClassDialogBack()
{
if (pickClassDialog)
{
const std::string classId = pickClassDialog->getClassId();
if (!classId.empty())
environment.mMechanicsManager->setPlayerClass(classId);
removeDialog(pickClassDialog);
}
setGuiMode(GM_Class);
} }
void WindowManager::onCreateClassDialogDone(WindowBase* parWindow) void WindowManager::onCreateClassDialogDone(WindowBase* parWindow)

@ -32,6 +32,12 @@ namespace Compiler
namespace MWWorld namespace MWWorld
{ {
class Environment; class Environment;
class World;
}
namespace MWMechanics
{
class MechanicsManager;
} }
namespace OEngine namespace OEngine
@ -52,14 +58,13 @@ namespace MWGui
class InventoryWindow; class InventoryWindow;
class Console; class Console;
class JournalWindow; class JournalWindow;
class CharacterCreation;
class TextInputDialog; class TextInputDialog;
class InfoBoxDialog; class InfoBoxDialog;
class RaceDialog;
class DialogueWindow; class DialogueWindow;
class ClassChoiceDialog; class ClassChoiceDialog;
class GenerateClassResultDialog; class GenerateClassResultDialog;
class PickClassDialog;
class CreateClassDialog; class CreateClassDialog;
class BirthDialog; class BirthDialog;
class ReviewDialog; class ReviewDialog;
@ -94,13 +99,12 @@ namespace MWGui
JournalWindow* mJournal; JournalWindow* mJournal;
// Character creation // Character creation
TextInputDialog *nameDialog; CharacterCreation* mCharGen;
RaceDialog *raceDialog;
DialogueWindow *dialogueWindow; DialogueWindow *dialogueWindow;
ClassChoiceDialog *classChoiceDialog; ClassChoiceDialog *classChoiceDialog;
InfoBoxDialog *generateClassQuestionDialog; InfoBoxDialog *generateClassQuestionDialog;
GenerateClassResultDialog *generateClassResultDialog; GenerateClassResultDialog *generateClassResultDialog;
PickClassDialog *pickClassDialog;
CreateClassDialog *createClassDialog; CreateClassDialog *createClassDialog;
BirthDialog *birthSignDialog; BirthDialog *birthSignDialog;
ReviewDialog *reviewDialog; ReviewDialog *reviewDialog;
@ -112,9 +116,9 @@ namespace MWGui
std::string generateClass; std::string generateClass;
// Various stats about player as needed by window manager // Various stats about player as needed by window manager
std::string playerName;
ESM::Class playerClass; ESM::Class playerClass;
std::string playerRaceId, playerBirthSignId; std::string playerRaceId; ///REMOVE
std::string playerBirthSignId;
std::map<ESM::Attribute::AttributeID, MWMechanics::Stat<int> > playerAttributes; std::map<ESM::Attribute::AttributeID, MWMechanics::Stat<int> > playerAttributes;
SkillList playerMajorSkills, playerMinorSkills; SkillList playerMajorSkills, playerMinorSkills;
std::map<ESM::Skill::SkillEnum, MWMechanics::Stat<float> > playerSkillValues; std::map<ESM::Skill::SkillEnum, MWMechanics::Stat<float> > playerSkillValues;
@ -156,8 +160,6 @@ namespace MWGui
// allowed settings. // allowed settings.
void updateVisible(); void updateVisible();
void setGuiMode(GuiMode newMode);
int showFPSLevel; int showFPSLevel;
float mFPS; float mFPS;
size_t mTriangleCount; size_t mTriangleCount;
@ -169,6 +171,10 @@ namespace MWGui
const Compiler::Extensions& extensions, int fpsLevel, bool newGame); const Compiler::Extensions& extensions, int fpsLevel, bool newGame);
virtual ~WindowManager(); virtual ~WindowManager();
void setGuiMode(GuiMode newMode);
MWMechanics::MechanicsManager* getMechanicsManager();
MWWorld::World* getWorld();
/** /**
* Should be called each frame to update windows/gui elements. * Should be called each frame to update windows/gui elements.
* This could mean updating sizes of gui elements or opening * This could mean updating sizes of gui elements or opening
@ -281,26 +287,12 @@ namespace MWGui
void onDialogueWindowBye(); void onDialogueWindowBye();
// Character generation: Name dialog
void onNameDialogDone(WindowBase* parWindow);
// Character generation: Race dialog
void onRaceDialogDone(WindowBase* parWindow);
void onRaceDialogBack();
// Character generation: Choose class process
void onClassChoice(int _index);
// Character generation: Generate Class // Character generation: Generate Class
void showClassQuestionDialog(); void showClassQuestionDialog();
void onClassQuestionChosen(int _index); void onClassQuestionChosen(int _index);
void onGenerateClassBack(); void onGenerateClassBack();
void onGenerateClassDone(WindowBase* parWindow); void onGenerateClassDone(WindowBase* parWindow);
// Character generation: Pick Class dialog
void onPickClassDialogDone(WindowBase* parWindow);
void onPickClassDialogBack();
// Character generation: Create Class dialog // Character generation: Create Class dialog
void onCreateClassDialogDone(WindowBase* parWindow); void onCreateClassDialogDone(WindowBase* parWindow);
void onCreateClassDialogBack(); void onCreateClassDialogBack();
@ -314,6 +306,7 @@ namespace MWGui
void onReviewDialogBack(); void onReviewDialogBack();
void onReviewActivateDialog(int parDialog); void onReviewActivateDialog(int parDialog);
/// REMOVE
enum CreationStageEnum enum CreationStageEnum
{ {
NotStarted, NotStarted,
@ -326,6 +319,7 @@ namespace MWGui
// Which state the character creating is in, controls back/next/ok buttons // Which state the character creating is in, controls back/next/ok buttons
CreationStageEnum creationStage; CreationStageEnum creationStage;
/// /REMOVE
}; };
template<typename T> template<typename T>

Loading…
Cancel
Save