Added dialog for picking class from a list.

actorid
Jan Borsodi 14 years ago
parent 07b1b21b29
commit eec34e9f0e

@ -37,6 +37,7 @@ set(GAMEGUI_HEADER
mwgui/layouts.hpp mwgui/layouts.hpp
mwgui/text_input.hpp mwgui/text_input.hpp
mwgui/race.hpp mwgui/race.hpp
mwgui/class.hpp
mwgui/window_manager.hpp mwgui/window_manager.hpp
mwgui/console.hpp mwgui/console.hpp
) )
@ -46,6 +47,7 @@ set(GAMEGUI
mwgui/console.cpp mwgui/console.cpp
mwgui/text_input.cpp mwgui/text_input.cpp
mwgui/race.cpp mwgui/race.cpp
mwgui/class.cpp
) )
source_group(apps\\openmw\\mwgui FILES ${GAMEGUI_HEADER} ${GAMEGUI}) source_group(apps\\openmw\\mwgui FILES ${GAMEGUI_HEADER} ${GAMEGUI})

@ -0,0 +1,223 @@
#include "class.hpp"
#include "../mwworld/environment.hpp"
#include "../mwworld/world.hpp"
#include "window_manager.hpp"
#include "components/esm_store/store.hpp"
#include <assert.h>
#include <iterator>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
using namespace MWGui;
PickClassDialog::PickClassDialog(MWWorld::Environment& environment, MyGUI::IntSize gameWindowSize)
: Layout("openmw_chargen_class_layout.xml")
, environment(environment)
{
// Centre dialog
MyGUI::IntCoord coord = mMainWidget->getCoord();
coord.left = (gameWindowSize.width - coord.width)/2;
coord.top = (gameWindowSize.height - coord.height)/2;
mMainWidget->setCoord(coord);
WindowManager *wm = environment.mWindowManager;
setText("SpecializationT", wm->getGameSettingString("sChooseClassMenu1", "Specialization"));
getWidget(specializationName, "SpecializationName");
setText("FavoriteAttributesT", wm->getGameSettingString("sChooseClassMenu2", "Favorite Attributes:"));
getWidget(favoriteAttribute0, "FavoriteAttribute0");
getWidget(favoriteAttribute1, "FavoriteAttribute1");
setText("MajorSkillT", wm->getGameSettingString("sChooseClassMenu3", "Major Skills:"));
getWidget(majorSkill0, "MajorSkill0");
getWidget(majorSkill1, "MajorSkill1");
getWidget(majorSkill2, "MajorSkill2");
getWidget(majorSkill3, "MajorSkill3");
getWidget(majorSkill4, "MajorSkill4");
setText("MinorSkillT", wm->getGameSettingString("sChooseClassMenu4", "Minor Skills:"));
getWidget(minorSkill0, "MinorSkill0");
getWidget(minorSkill1, "MinorSkill1");
getWidget(minorSkill2, "MinorSkill2");
getWidget(minorSkill3, "MinorSkill3");
getWidget(minorSkill4, "MinorSkill4");
getWidget(classList, "ClassList");
classList->setScrollVisible(true);
classList->eventListSelectAccept = MyGUI::newDelegate(this, &PickClassDialog::onSelectClass);
classList->eventListMouseItemActivate = MyGUI::newDelegate(this, &PickClassDialog::onSelectClass);
classList->eventListChangePosition = MyGUI::newDelegate(this, &PickClassDialog::onSelectClass);
getWidget(classImage, "ClassImage");
// TODO: These buttons should be managed by a Dialog class
MyGUI::ButtonPtr backButton;
getWidget(backButton, "BackButton");
backButton->eventMouseButtonClick = MyGUI::newDelegate(this, &PickClassDialog::onBackClicked);
MyGUI::ButtonPtr okButton;
getWidget(okButton, "OKButton");
okButton->eventMouseButtonClick = MyGUI::newDelegate(this, &PickClassDialog::onOkClicked);
updateClasses();
updateStats();
}
void PickClassDialog::setNextButtonShow(bool shown)
{
MyGUI::ButtonPtr backButton;
getWidget(backButton, "BackButton");
MyGUI::ButtonPtr okButton;
getWidget(okButton, "OKButton");
// TODO: All hardcoded coords for buttons are temporary, will be replaced with a dynamic system.
if (shown)
{
okButton->setCaption("Next");
// Adjust back button when next is shown
backButton->setCoord(MyGUI::IntCoord(382 - 18, 265, 53, 23));
okButton->setCoord(MyGUI::IntCoord(434 - 18, 265, 42 + 18, 23));
}
else
{
okButton->setCaption("OK");
backButton->setCoord(MyGUI::IntCoord(382, 265, 53, 23));
okButton->setCoord(MyGUI::IntCoord(434, 265, 42, 23));
}
}
void PickClassDialog::open()
{
updateClasses();
updateStats();
setVisible(true);
}
void PickClassDialog::setClassId(const std::string &classId)
{
currentClassId = classId;
classList->setIndexSelected(MyGUI::ITEM_NONE);
size_t count = classList->getItemCount();
for (size_t i = 0; i < count; ++i)
{
if (boost::iequals(*classList->getItemDataAt<std::string>(i), classId))
{
classList->setIndexSelected(i);
break;
}
}
updateStats();
}
// widget controls
void PickClassDialog::onOkClicked(MyGUI::Widget* _sender)
{
eventDone();
}
void PickClassDialog::onBackClicked(MyGUI::Widget* _sender)
{
eventBack();
}
void PickClassDialog::onSelectClass(MyGUI::List* _sender, size_t _index)
{
if (_index == MyGUI::ITEM_NONE)
return;
const std::string *classId = classList->getItemDataAt<std::string>(_index);
if (boost::iequals(currentClassId, *classId))
return;
currentClassId = *classId;
updateStats();
}
// update widget content
void PickClassDialog::updateClasses()
{
classList->removeAllItems();
ESMS::ESMStore &store = environment.mWorld->getStore();
ESMS::RecListT<ESM::Class>::MapType::const_iterator it = store.classes.list.begin();
ESMS::RecListT<ESM::Class>::MapType::const_iterator end = store.classes.list.end();
int index = 0;
for (; it != end; ++it)
{
const ESM::Class &klass = it->second;
bool playable = (klass.data.isPlayable != 0);
if (!playable) // Only display playable classes
continue;
const std::string &id = it->first;
classList->addItem(klass.name, id);
if (boost::iequals(id, currentClassId))
classList->setIndexSelected(index);
++index;
}
}
void PickClassDialog::updateStats()
{
if (currentClassId.empty())
return;
WindowManager *wm = environment.mWindowManager;
ESMS::ESMStore &store = environment.mWorld->getStore();
const ESM::Class *klass = store.classes.find(currentClassId);
ESM::Class::Specialization specialization = static_cast<ESM::Class::Specialization>(klass->data.specialization);
static const char *specIds[3] = {
"sSpecializationCombat",
"sSpecializationMagic",
"sSpecializationStealth"
};
specializationName->setCaption(wm->getGameSettingString(specIds[specialization], specIds[specialization]));
static const char *attributes[8] = {
"sAttributeStrength",
"sAttributeIntelligence",
"sAttributeWillpower",
"sAttributeAgility",
"sAttributeSpeed",
"sAttributeEndurance",
"sAttributePersonality",
"sAttributeLuck"
};
favoriteAttribute0->setCaption(wm->getGameSettingString(attributes[klass->data.attribute[0]], ""));
favoriteAttribute1->setCaption(wm->getGameSettingString(attributes[klass->data.attribute[1]], ""));
MyGUI::StaticTextPtr skills[2][5] = {
{
majorSkill0,
majorSkill1,
majorSkill2,
majorSkill3,
majorSkill4
},
{
minorSkill0,
minorSkill1,
minorSkill2,
minorSkill3,
minorSkill4
}
};
for (int i = 0; i < 5; ++i)
{
skills[0][i]->setCaption(wm->getGameSettingString(ESM::Skill::sSkillNameIds[klass->data.skills[i][0]], ""));
skills[1][i]->setCaption(wm->getGameSettingString(ESM::Skill::sSkillNameIds[klass->data.skills[i][1]], ""));
}
classImage->setImageTexture(std::string("textures\\levelup\\") + currentClassId + ".dds");
}

@ -0,0 +1,68 @@
#ifndef MWGUI_CLASS_H
#define MWGUI_CLASS_H
#include <components/esm_store/store.hpp>
#include <openengine/gui/layout.hpp>
namespace MWWorld
{
class Environment;
}
/*
This file contains the dialogs for choosing a class.
Layout is defined by resources/mygui/openmw_chargen_class_layout.xml.
*/
namespace MWGui
{
using namespace MyGUI;
class PickClassDialog : public OEngine::GUI::Layout
{
public:
PickClassDialog(MWWorld::Environment& environment, MyGUI::IntSize gameWindowSize);
const std::string &getClassId() const { return currentClassId; }
void setClassId(const std::string &classId);
void setNextButtonShow(bool shown);
void open();
// Events
typedef delegates::CDelegate0 EventHandle_Void;
/** Event : Back button clicked.\n
signature : void method()\n
*/
EventHandle_Void eventBack;
/** Event : Dialog finished, OK button clicked.\n
signature : void method()\n
*/
EventHandle_Void eventDone;
protected:
void onSelectClass(MyGUI::List* _sender, size_t _index);
void onOkClicked(MyGUI::Widget* _sender);
void onBackClicked(MyGUI::Widget* _sender);
private:
void updateClasses();
void updateStats();
MWWorld::Environment& environment;
MyGUI::StaticImagePtr classImage;
MyGUI::ListPtr classList;
MyGUI::StaticTextPtr specializationName;
MyGUI::StaticTextPtr favoriteAttribute0, favoriteAttribute1;
MyGUI::StaticTextPtr majorSkill0, majorSkill1, majorSkill2, majorSkill3, majorSkill4;
MyGUI::StaticTextPtr minorSkill0, minorSkill1, minorSkill2, minorSkill3, minorSkill4;
std::string currentClassId;
};
}
#endif

@ -2,6 +2,7 @@
#include "layouts.hpp" #include "layouts.hpp"
#include "text_input.hpp" #include "text_input.hpp"
#include "race.hpp" #include "race.hpp"
#include "class.hpp"
#include "../mwmechanics/mechanicsmanager.hpp" #include "../mwmechanics/mechanicsmanager.hpp"
#include "../mwinput/inputmanager.hpp" #include "../mwinput/inputmanager.hpp"
@ -19,6 +20,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment
: environment(environment) : environment(environment)
, nameDialog(nullptr) , nameDialog(nullptr)
, raceDialog(nullptr) , raceDialog(nullptr)
, pickClassDialog(nullptr)
, nameChosen(false) , nameChosen(false)
, raceChosen(false) , raceChosen(false)
, classChosen(false) , classChosen(false)
@ -63,6 +65,7 @@ WindowManager::~WindowManager()
delete nameDialog; delete nameDialog;
delete raceDialog; delete raceDialog;
delete pickClassDialog;
} }
void WindowManager::updateVisible() void WindowManager::updateVisible()
@ -122,6 +125,17 @@ void WindowManager::updateVisible()
return; return;
} }
if (mode == GM_Class)
{
if (!pickClassDialog)
pickClassDialog = new PickClassDialog(environment, gui->getViewSize());
pickClassDialog->setNextButtonShow(classChosen);
pickClassDialog->eventDone = MyGUI::newDelegate(this, &WindowManager::onPickClassDialogDone);
pickClassDialog->eventBack = MyGUI::newDelegate(this, &WindowManager::onPickClassDialogBack);
pickClassDialog->open();
return;
}
if(mode == GM_Inventory) if(mode == GM_Inventory)
{ {
// Ah, inventory mode. First, compute the effective set of // Ah, inventory mode. First, compute the effective set of
@ -288,3 +302,38 @@ void WindowManager::onRaceDialogBack()
environment.mInputManager->setGuiMode(GM_Name); environment.mInputManager->setGuiMode(GM_Name);
} }
void WindowManager::onPickClassDialogDone()
{
pickClassDialog->eventDone = MWGui::PickClassDialog::EventHandle_Void();
bool goNext = classChosen; // Go to next dialog if class was previously chosen
classChosen = true;
if (pickClassDialog)
{
pickClassDialog->setVisible(false);
//environment.mMechanicsManager->setPlayerClass(pickClassDialog->getClassId());
}
updateCharacterGeneration();
if (reviewNext)
environment.mInputManager->setGuiMode(GM_Review);
else if (goNext)
environment.mInputManager->setGuiMode(GM_Birth);
else
environment.mInputManager->setGuiMode(GM_Game);
}
void WindowManager::onPickClassDialogBack()
{
if (pickClassDialog)
{
pickClassDialog->setVisible(false);
//environment.mMechanicsManager->setPlayerClass(pickClassDialog->getClassId());
}
updateCharacterGeneration();
environment.mInputManager->setGuiMode(GM_Race);
}

@ -43,6 +43,7 @@ namespace MWGui
class TextInputDialog; class TextInputDialog;
class RaceDialog; class RaceDialog;
class PickClassDialog;
class WindowManager class WindowManager
{ {
@ -59,6 +60,7 @@ namespace MWGui
// Character creation // Character creation
TextInputDialog *nameDialog; TextInputDialog *nameDialog;
RaceDialog *raceDialog; RaceDialog *raceDialog;
PickClassDialog *pickClassDialog;
// Which dialogs have been shown, controls back/next/ok buttons // Which dialogs have been shown, controls back/next/ok buttons
bool nameChosen; bool nameChosen;
@ -184,6 +186,10 @@ namespace MWGui
// Character generation: Race dialog // Character generation: Race dialog
void onRaceDialogDone(); void onRaceDialogDone();
void onRaceDialogBack(); void onRaceDialogBack();
// Character generation: Pick Class dialog
void onPickClassDialogDone();
void onPickClassDialogBack();
}; };
} }
#endif #endif

@ -35,6 +35,13 @@ struct Class
RepairItem = 0x20000 RepairItem = 0x20000
}; };
enum Specialization
{
Combat = 0,
Magic = 1,
Stealth = 2
};
struct CLDTstruct struct CLDTstruct
{ {
int attribute[2]; // Attributes that get class bonus int attribute[2]; // Attributes that get class bonus

@ -43,6 +43,7 @@ configure_file("${SDIR}/openmw_hud_energybar.skin.xml" "${DDIR}/openmw_hud_energ
configure_file("${SDIR}/openmw_hud_layout.xml" "${DDIR}/openmw_hud_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_hud_layout.xml" "${DDIR}/openmw_hud_layout.xml" COPYONLY)
configure_file("${SDIR}/openmw_text_input_layout.xml" "${DDIR}/openmw_text_input_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_text_input_layout.xml" "${DDIR}/openmw_text_input_layout.xml" COPYONLY)
configure_file("${SDIR}/openmw_chargen_race_layout.xml" "${DDIR}/openmw_chargen_race_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_chargen_race_layout.xml" "${DDIR}/openmw_chargen_race_layout.xml" COPYONLY)
configure_file("${SDIR}/openmw_chargen_class_layout.xml" "${DDIR}/openmw_chargen_class_layout.xml" COPYONLY)
configure_file("${SDIR}/openmw_inventory_window_layout.xml" "${DDIR}/openmw_inventory_window_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_inventory_window_layout.xml" "${DDIR}/openmw_inventory_window_layout.xml" COPYONLY)
configure_file("${SDIR}/openmw_layers.xml" "${DDIR}/openmw_layers.xml" COPYONLY) configure_file("${SDIR}/openmw_layers.xml" "${DDIR}/openmw_layers.xml" COPYONLY)
configure_file("${SDIR}/openmw_mainmenu_layout.xml" "${DDIR}/openmw_mainmenu_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_mainmenu_layout.xml" "${DDIR}/openmw_mainmenu_layout.xml" COPYONLY)

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout">
<!-- correct size is 491 302, adjust when skin is changed to a dialog -->
<Widget type="Window" skin="MW_Window" layer="Windows" position="0 0 499 330" name="_Main">
<!-- Class list -->
<Widget type="List" skin="MW_List" position="14 13 181 131" name="ClassList" />
<!-- Class image -->
<Widget type="Widget" skin="MW_Box" position="212 9 265 138" align="ALIGN_LEFT ALIGN_TOP">
<Widget type="StaticImage" skin="StaticImage" position="2 2 261 134" name="ClassImage" align="ALIGN_LEFT ALIGN_TOP" />
</Widget>
<!-- Specialization -->
<Widget type="Widget" skin="" position="15 152 484 178" align="ALIGN_LEFT ALIGN_TOP">
<Widget type="StaticText" skin="HeaderText" position="0 0 162 18" name="SpecializationT" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_Caption" value="Specialization:"/>
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<Widget type="StaticText" skin="SandText" position="0 18 162 18" name="SpecializationName" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<!-- Favorite Attributes -->
<Widget type="StaticText" skin="HeaderText" position="0 41 162 18" name="FavoriteAttributesT" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_Caption" value="Favorite Attributes:"/>
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<Widget type="StaticText" skin="SandText" position="0 59 162 18" name="FavoriteAttribute0" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<Widget type="StaticText" skin="SandText" position="0 77 162 18" name="FavoriteAttribute1" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<!-- Major Skills -->
<Widget type="StaticText" skin="HeaderText" position="162 0 162 18" name="MajorSkillT" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_Caption" value="Major Skills:"/>
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<Widget type="StaticText" skin="SandText" position="162 18 162 18" name="MajorSkill0" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<Widget type="StaticText" skin="SandText" position="162 36 162 18" name="MajorSkill1" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<Widget type="StaticText" skin="SandText" position="162 54 162 18" name="MajorSkill2" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<Widget type="StaticText" skin="SandText" position="162 72 162 18" name="MajorSkill3" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<Widget type="StaticText" skin="SandText" position="162 90 162 18" name="MajorSkill4" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<!-- Minor Skills -->
<Widget type="StaticText" skin="HeaderText" position="325 0 162 18" name="MinorSkillT" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_Caption" value="Minor Skills:"/>
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<Widget type="StaticText" skin="SandText" position="325 18 162 18" name="MinorSkill0" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<Widget type="StaticText" skin="SandText" position="325 36 162 18" name="MinorSkill1" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<Widget type="StaticText" skin="SandText" position="325 54 162 18" name="MinorSkill2" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<Widget type="StaticText" skin="SandText" position="325 72 162 18" name="MinorSkill3" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
<Widget type="StaticText" skin="SandText" position="325 90 162 18" name="MinorSkill4" align="ALIGN_LEFT ALIGN_TOP">
<Property key="Widget_AlignText" value="ALIGN_LEFT ALIGN_TOP"/>
</Widget>
</Widget>
<!-- Dialog buttons -->
<Widget type="Button" skin="MW_Button" position="382 265 53 23" name="BackButton">
<Property key="Widget_Caption" value="Back"/>
</Widget>
<Widget type="Button" skin="MW_Button" position="434 265 42 23" name="OKButton">
<Property key="Widget_Caption" value="OK"/>
</Widget>
</Widget>
</MyGUI>
Loading…
Cancel
Save