Added dialog for picking class from a list.
parent
07b1b21b29
commit
eec34e9f0e
@ -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
|
@ -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…
Reference in New Issue