1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 12:32:36 +00:00
OpenMW/apps/openmw/mwgui/race.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

470 lines
15 KiB
C++
Raw Normal View History

#include "race.hpp"
2015-01-10 02:50:43 +01:00
#include <MyGUI_Gui.h>
#include <MyGUI_ImageBox.h>
#include <MyGUI_ListBox.h>
#include <MyGUI_ScrollBar.h>
2023-11-23 19:52:18 +01:00
#include <MyGUI_UString.h>
2015-01-10 02:50:43 +01:00
2015-05-20 02:18:20 +02:00
#include <osg/Texture2D>
2018-08-14 23:05:43 +04:00
#include <components/debug/debuglog.hpp>
#include <components/esm3/loadbody.hpp>
#include <components/esm3/loadrace.hpp>
2023-07-16 20:46:54 +02:00
#include <components/myguiplatform/myguitexture.hpp>
#include <components/settings/values.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/windowmanager.hpp"
2015-01-10 03:56:06 +01:00
#include "../mwrender/characterpreview.hpp"
#include "../mwworld/esmstore.hpp"
#include "tooltips.hpp"
namespace
{
2013-04-17 18:56:48 -04:00
int wrap(int index, int max)
{
if (index < 0)
return max - 1;
else if (index >= max)
return 0;
else
return index;
}
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
bool sortRaces(const std::pair<ESM::RefId, std::string>& left, const std::pair<ESM::RefId, std::string>& right)
{
return left.second.compare(right.second) < 0;
}
}
2013-04-17 18:56:48 -04:00
namespace MWGui
{
RaceDialog::RaceDialog(osg::Group* parent, Resource::ResourceSystem* resourceSystem)
2013-04-17 18:56:48 -04:00
: WindowModal("openmw_chargen_race.layout")
, mParent(parent)
2015-05-20 02:18:20 +02:00
, mResourceSystem(resourceSystem)
2013-04-17 18:56:48 -04:00
, mGenderIndex(0)
, mFaceIndex(0)
, mHairIndex(0)
, mCurrentAngle(0)
, mPreviewDirty(true)
2013-04-17 18:56:48 -04:00
{
// Centre dialog
center();
setText("AppearanceT",
MWBase::Environment::get().getWindowManager()->getGameSettingString("sRaceMenu1", "Appearance"));
getWidget(mPreviewImage, "PreviewImage");
mPreviewImage->eventMouseWheel += MyGUI::newDelegate(this, &RaceDialog::onPreviewScroll);
2013-04-17 18:56:48 -04:00
getWidget(mHeadRotate, "HeadRotate");
mHeadRotate->setScrollRange(1000);
mHeadRotate->setScrollPosition(500);
mHeadRotate->setScrollViewPage(50);
mHeadRotate->setScrollPage(50);
2014-10-01 23:24:03 +02:00
mHeadRotate->setScrollWheelPage(50);
2013-04-17 18:56:48 -04:00
mHeadRotate->eventScrollChangePosition += MyGUI::newDelegate(this, &RaceDialog::onHeadRotate);
// Set up next/previous buttons
MyGUI::Button *prevButton, *nextButton;
setText("GenderChoiceT",
MWBase::Environment::get().getWindowManager()->getGameSettingString("sRaceMenu2", "Change Sex"));
getWidget(prevButton, "PrevGenderButton");
getWidget(nextButton, "NextGenderButton");
prevButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onSelectPreviousGender);
nextButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onSelectNextGender);
setText("FaceChoiceT",
MWBase::Environment::get().getWindowManager()->getGameSettingString("sRaceMenu3", "Change Face"));
getWidget(prevButton, "PrevFaceButton");
getWidget(nextButton, "NextFaceButton");
prevButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onSelectPreviousFace);
nextButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onSelectNextFace);
setText("HairChoiceT",
MWBase::Environment::get().getWindowManager()->getGameSettingString("sRaceMenu4", "Change Hair"));
getWidget(prevButton, "PrevHairButton");
getWidget(nextButton, "NextHairButton");
prevButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onSelectPreviousHair);
nextButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onSelectNextHair);
setText("RaceT", MWBase::Environment::get().getWindowManager()->getGameSettingString("sRaceMenu5", "Race"));
getWidget(mRaceList, "RaceList");
mRaceList->setScrollVisible(true);
mRaceList->eventListSelectAccept += MyGUI::newDelegate(this, &RaceDialog::onAccept);
2013-04-17 18:56:48 -04:00
mRaceList->eventListChangePosition += MyGUI::newDelegate(this, &RaceDialog::onSelectRace);
setText("SkillsT",
MWBase::Environment::get().getWindowManager()->getGameSettingString("sBonusSkillTitle", "Skill Bonus"));
getWidget(mSkillList, "SkillList");
setText("SpellPowerT",
MWBase::Environment::get().getWindowManager()->getGameSettingString("sRaceMenu7", "Specials"));
getWidget(mSpellPowerList, "SpellPowerList");
MyGUI::Button* backButton;
getWidget(backButton, "BackButton");
backButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onBackClicked);
MyGUI::Button* okButton;
getWidget(okButton, "OKButton");
okButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
2013-04-17 18:56:48 -04:00
okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &RaceDialog::onOkClicked);
2013-04-17 18:56:48 -04:00
updateRaces();
updateSkills();
updateSpellPowers();
}
void RaceDialog::setNextButtonShow(bool shown)
{
MyGUI::Button* okButton;
getWidget(okButton, "OKButton");
if (shown)
okButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sNext", {})));
2013-04-17 18:56:48 -04:00
else
okButton->setCaption(
MyGUI::UString(MWBase::Environment::get().getWindowManager()->getGameSettingString("sOK", {})));
2013-04-17 18:56:48 -04:00
}
void RaceDialog::onOpen()
2013-04-17 18:56:48 -04:00
{
WindowModal::onOpen();
2012-09-24 00:42:05 +02:00
2013-04-17 18:56:48 -04:00
updateRaces();
updateSkills();
updateSpellPowers();
2012-09-24 00:42:05 +02:00
2018-10-09 10:21:12 +04:00
mPreviewImage->setRenderItemTexture(nullptr);
2014-08-13 19:30:46 +02:00
2018-10-09 10:21:12 +04:00
mPreview.reset(nullptr);
mPreviewTexture.reset(nullptr);
2014-08-13 19:30:46 +02:00
2022-05-29 13:24:48 +02:00
mPreview = std::make_unique<MWRender::RaceSelectionPreview>(mParent, mResourceSystem);
2015-05-20 02:18:20 +02:00
mPreview->rebuild();
mPreview->setAngle(mCurrentAngle);
2014-08-13 19:30:46 +02:00
2022-05-29 13:24:48 +02:00
mPreviewTexture
= std::make_unique<osgMyGUI::OSGTexture>(mPreview->getTexture(), mPreview->getTextureStateSet());
2015-05-20 02:18:20 +02:00
mPreviewImage->setRenderItemTexture(mPreviewTexture.get());
mPreviewImage->getSubWidgetMain()->_setUVSet(MyGUI::FloatRect(0.f, 0.f, 1.f, 1.f));
2015-05-20 02:18:20 +02:00
const ESM::NPC& proto = mPreview->getPrototype();
2013-04-17 18:56:48 -04:00
setRaceId(proto.mRace);
2017-04-14 23:19:48 +04:00
setGender(proto.isMale() ? GM_Male : GM_Female);
2013-04-17 18:56:48 -04:00
recountParts();
2012-11-10 21:54:43 +04:00
for (size_t i = 0; i < mAvailableHeads.size(); ++i)
{
if (mAvailableHeads[i] == proto.mHead)
mFaceIndex = i;
}
for (size_t i = 0; i < mAvailableHairs.size(); ++i)
{
if (mAvailableHairs[i] == proto.mHair)
mHairIndex = i;
}
mPreviewDirty = true;
size_t initialPos = mHeadRotate->getScrollRange() / 2 + mHeadRotate->getScrollRange() / 10;
mHeadRotate->setScrollPosition(initialPos);
onHeadRotate(mHeadRotate, initialPos);
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mRaceList);
}
2013-04-17 18:56:48 -04:00
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
void RaceDialog::setRaceId(const ESM::RefId& raceId)
{
2013-04-17 18:56:48 -04:00
mCurrentRaceId = raceId;
mRaceList->setIndexSelected(MyGUI::ITEM_NONE);
size_t count = mRaceList->getItemCount();
for (size_t i = 0; i < count; ++i)
{
if (*mRaceList->getItemDataAt<ESM::RefId>(i) == raceId)
2013-04-17 18:56:48 -04:00
{
mRaceList->setIndexSelected(i);
break;
}
}
2013-04-17 18:56:48 -04:00
updateSkills();
updateSpellPowers();
}
void RaceDialog::onClose()
2013-04-17 18:56:48 -04:00
{
WindowModal::onClose();
2018-10-09 10:21:12 +04:00
mPreviewImage->setRenderItemTexture(nullptr);
2015-05-20 02:18:20 +02:00
2018-10-09 10:21:12 +04:00
mPreviewTexture.reset(nullptr);
mPreview.reset(nullptr);
2013-04-17 18:56:48 -04:00
}
2012-09-24 00:42:05 +02:00
2013-04-17 18:56:48 -04:00
// widget controls
2013-04-17 18:56:48 -04:00
void RaceDialog::onOkClicked(MyGUI::Widget* _sender)
{
if (mRaceList->getIndexSelected() == MyGUI::ITEM_NONE)
return;
eventDone(this);
}
2013-04-17 18:56:48 -04:00
void RaceDialog::onBackClicked(MyGUI::Widget* _sender)
{
eventBack();
}
void RaceDialog::onPreviewScroll(MyGUI::Widget*, int _delta)
{
size_t oldPos = mHeadRotate->getScrollPosition();
size_t maxPos = mHeadRotate->getScrollRange() - 1;
size_t scrollPage = mHeadRotate->getScrollWheelPage();
if (_delta < 0)
mHeadRotate->setScrollPosition(oldPos + std::min(maxPos - oldPos, scrollPage));
else
mHeadRotate->setScrollPosition(oldPos - std::min(oldPos, scrollPage));
onHeadRotate(mHeadRotate, mHeadRotate->getScrollPosition());
}
void RaceDialog::onHeadRotate(MyGUI::ScrollBar* scroll, size_t _position)
2013-04-17 18:56:48 -04:00
{
float angle = (float(_position) / (scroll->getScrollRange() - 1) - 0.5f) * osg::PI * 2;
2015-05-20 02:18:20 +02:00
mPreview->setAngle(angle);
mCurrentAngle = angle;
2013-04-17 18:56:48 -04:00
}
2013-04-17 18:56:48 -04:00
void RaceDialog::onSelectPreviousGender(MyGUI::Widget*)
{
mGenderIndex = wrap(mGenderIndex - 1, 2);
2013-04-17 18:56:48 -04:00
recountParts();
updatePreview();
}
2013-04-17 18:56:48 -04:00
void RaceDialog::onSelectNextGender(MyGUI::Widget*)
{
mGenderIndex = wrap(mGenderIndex + 1, 2);
2013-04-17 18:56:48 -04:00
recountParts();
updatePreview();
}
2013-04-17 18:56:48 -04:00
void RaceDialog::onSelectPreviousFace(MyGUI::Widget*)
{
2013-04-17 19:38:13 -04:00
mFaceIndex = wrap(mFaceIndex - 1, mAvailableHeads.size());
2013-04-17 18:56:48 -04:00
updatePreview();
}
2013-04-17 18:56:48 -04:00
void RaceDialog::onSelectNextFace(MyGUI::Widget*)
{
2013-04-17 19:38:13 -04:00
mFaceIndex = wrap(mFaceIndex + 1, mAvailableHeads.size());
2013-04-17 18:56:48 -04:00
updatePreview();
}
2013-04-17 18:56:48 -04:00
void RaceDialog::onSelectPreviousHair(MyGUI::Widget*)
{
2013-04-17 19:38:13 -04:00
mHairIndex = wrap(mHairIndex - 1, mAvailableHairs.size());
2013-04-17 18:56:48 -04:00
updatePreview();
}
2013-04-17 18:56:48 -04:00
void RaceDialog::onSelectNextHair(MyGUI::Widget*)
{
2013-04-17 19:38:13 -04:00
mHairIndex = wrap(mHairIndex + 1, mAvailableHairs.size());
2013-04-17 18:56:48 -04:00
updatePreview();
}
2013-04-17 18:56:48 -04:00
void RaceDialog::onSelectRace(MyGUI::ListBox* _sender, size_t _index)
{
if (_index == MyGUI::ITEM_NONE)
return;
ESM::RefId& raceId = *mRaceList->getItemDataAt<ESM::RefId>(_index);
if (mCurrentRaceId == raceId)
2013-04-17 18:56:48 -04:00
return;
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
mCurrentRaceId = raceId;
2013-04-17 18:56:48 -04:00
recountParts();
2013-04-17 18:56:48 -04:00
updatePreview();
updateSkills();
updateSpellPowers();
}
void RaceDialog::onAccept(MyGUI::ListBox* _sender, size_t _index)
{
onSelectRace(_sender, _index);
if (mRaceList->getIndexSelected() == MyGUI::ITEM_NONE)
return;
eventDone(this);
}
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
void RaceDialog::getBodyParts(int part, std::vector<ESM::RefId>& out)
{
2013-04-17 19:38:13 -04:00
out.clear();
2023-04-20 21:07:53 +02:00
const MWWorld::Store<ESM::BodyPart>& store = MWBase::Environment::get().getESMStore()->get<ESM::BodyPart>();
2013-04-17 19:38:13 -04:00
for (const ESM::BodyPart& bodypart : store)
2013-04-17 19:38:13 -04:00
{
if (bodypart.mData.mFlags & ESM::BodyPart::BPF_NotPlayable)
continue;
if (bodypart.mData.mType != ESM::BodyPart::MT_Skin)
continue;
if (bodypart.mData.mPart != static_cast<ESM::BodyPart::MeshPart>(part))
continue;
if (mGenderIndex != (bodypart.mData.mFlags & ESM::BodyPart::BPF_Female))
continue;
if (ESM::isFirstPersonBodyPart(bodypart))
2013-04-17 19:38:13 -04:00
continue;
if (bodypart.mRace == mCurrentRaceId)
2013-04-17 19:38:13 -04:00
out.push_back(bodypart.mId);
}
}
2013-04-17 18:56:48 -04:00
void RaceDialog::recountParts()
{
2013-04-17 19:38:13 -04:00
getBodyParts(ESM::BodyPart::MP_Hair, mAvailableHairs);
getBodyParts(ESM::BodyPart::MP_Head, mAvailableHeads);
2013-04-17 18:56:48 -04:00
mFaceIndex = 0;
mHairIndex = 0;
}
2012-11-10 21:30:16 +04:00
2013-04-17 18:56:48 -04:00
// update widget content
2013-04-17 18:56:48 -04:00
void RaceDialog::updatePreview()
{
2015-05-20 02:18:20 +02:00
ESM::NPC record = mPreview->getPrototype();
2013-04-17 18:56:48 -04:00
record.mRace = mCurrentRaceId;
record.setIsMale(mGenderIndex == 0);
if (mFaceIndex >= 0 && mFaceIndex < int(mAvailableHeads.size()))
record.mHead = mAvailableHeads[mFaceIndex];
if (mHairIndex >= 0 && mHairIndex < int(mAvailableHairs.size()))
record.mHair = mAvailableHairs[mHairIndex];
try
{
2015-05-20 02:18:20 +02:00
mPreview->setPrototype(record);
}
catch (std::exception& e)
{
2018-08-14 23:05:43 +04:00
Log(Debug::Error) << "Error creating preview: " << e.what();
}
}
2013-04-17 18:56:48 -04:00
void RaceDialog::updateRaces()
{
mRaceList->removeAllItems();
2023-04-20 21:07:53 +02:00
const MWWorld::Store<ESM::Race>& races = MWBase::Environment::get().getESMStore()->get<ESM::Race>();
2011-04-21 10:49:45 +02:00
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
std::vector<std::pair<ESM::RefId, std::string>> items; // ID, name
for (const ESM::Race& race : races)
2013-04-17 18:56:48 -04:00
{
bool playable = race.mData.mFlags & ESM::Race::Playable;
2013-04-17 18:56:48 -04:00
if (!playable) // Only display playable races
continue;
2020-10-17 12:26:35 +04:00
items.emplace_back(race.mId, race.mName);
}
std::sort(items.begin(), items.end(), sortRaces);
int index = 0;
for (auto& item : items)
{
mRaceList->addItem(item.second, item.first);
if (item.first == mCurrentRaceId)
2013-04-17 18:56:48 -04:00
mRaceList->setIndexSelected(index);
++index;
}
2010-09-14 21:55:41 +02:00
}
2013-04-17 18:56:48 -04:00
void RaceDialog::updateSkills()
2010-09-14 21:55:41 +02:00
{
for (MyGUI::Widget* widget : mSkillItems)
2013-04-17 18:56:48 -04:00
{
MyGUI::Gui::getInstance().destroyWidget(widget);
2013-04-17 18:56:48 -04:00
}
mSkillItems.clear();
2013-04-17 18:56:48 -04:00
if (mCurrentRaceId.empty())
return;
2013-04-17 18:56:48 -04:00
Widgets::MWSkillPtr skillWidget;
2023-07-16 20:46:54 +02:00
const int lineHeight = Settings::gui().mFontSize + 2;
2013-04-17 18:56:48 -04:00
MyGUI::IntCoord coord1(0, 0, mSkillList->getWidth(), 18);
2023-04-20 21:07:53 +02:00
const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
2013-04-17 18:56:48 -04:00
const ESM::Race* race = store.get<ESM::Race>().find(mCurrentRaceId);
2023-06-03 10:45:32 +02:00
for (const auto& bonus : race->mData.mBonus)
2013-04-17 18:56:48 -04:00
{
2023-06-06 17:24:22 +02:00
ESM::RefId skill = ESM::Skill::indexToRefId(bonus.mSkill);
if (skill.empty()) // Skip unknown skill indexes
2013-04-17 18:56:48 -04:00
continue;
2023-06-03 10:45:32 +02:00
skillWidget = mSkillList->createWidget<Widgets::MWSkill>("MW_StatNameValue", coord1, MyGUI::Align::Default);
2023-06-06 17:24:22 +02:00
skillWidget->setSkillId(skill);
2023-06-03 10:45:32 +02:00
skillWidget->setSkillValue(Widgets::MWSkill::SkillValue(static_cast<float>(bonus.mBonus), 0.f));
2023-06-06 17:24:22 +02:00
ToolTips::createSkillToolTip(skillWidget, skill);
2013-04-17 18:56:48 -04:00
mSkillItems.push_back(skillWidget);
2013-04-17 18:56:48 -04:00
coord1.top += lineHeight;
}
2010-09-14 21:55:41 +02:00
}
2013-04-17 18:56:48 -04:00
void RaceDialog::updateSpellPowers()
2010-09-14 21:55:41 +02:00
{
for (MyGUI::Widget* widget : mSpellPowerItems)
2013-04-17 18:56:48 -04:00
{
MyGUI::Gui::getInstance().destroyWidget(widget);
2013-04-17 18:56:48 -04:00
}
mSpellPowerItems.clear();
2013-04-17 18:56:48 -04:00
if (mCurrentRaceId.empty())
return;
2023-07-16 20:46:54 +02:00
const int lineHeight = Settings::gui().mFontSize + 2;
2022-08-17 21:51:36 +04:00
MyGUI::IntCoord coord(0, 0, mSpellPowerList->getWidth(), lineHeight);
2023-04-20 21:07:53 +02:00
const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
2013-04-17 18:56:48 -04:00
const ESM::Race* race = store.get<ESM::Race>().find(mCurrentRaceId);
int i = 0;
for (const ESM::RefId& spellpower : race->mPowers.mList)
2013-04-17 18:56:48 -04:00
{
Widgets::MWSpellPtr spellPowerWidget = mSpellPowerList->createWidget<Widgets::MWSpell>(
"MW_StatName", coord, MyGUI::Align::Default, std::string("SpellPower") + MyGUI::utility::toString(i));
2013-04-17 18:56:48 -04:00
spellPowerWidget->setSpellId(spellpower);
spellPowerWidget->setUserString("ToolTipType", "Spell");
spellPowerWidget->setUserString("Spell", spellpower.serialize());
2013-04-17 18:56:48 -04:00
mSpellPowerItems.push_back(spellPowerWidget);
2013-04-17 18:56:48 -04:00
coord.top += lineHeight;
++i;
}
2010-09-14 21:55:41 +02:00
}
2015-01-10 03:56:06 +01:00
const ESM::NPC& RaceDialog::getResult() const
{
2015-05-20 02:18:20 +02:00
return mPreview->getPrototype();
2015-01-10 03:56:06 +01:00
}
}