2010-09-20 13:17:02 +02:00
|
|
|
#include "widgets.hpp"
|
|
|
|
|
2013-10-06 19:46:04 -05:00
|
|
|
#include <iomanip>
|
|
|
|
|
2022-06-04 15:26:36 +02:00
|
|
|
#include <MyGUI_Button.h>
|
2013-07-05 19:17:00 +02:00
|
|
|
#include <MyGUI_ControllerManager.h>
|
2013-03-03 13:11:02 +01:00
|
|
|
#include <MyGUI_ImageBox.h>
|
|
|
|
#include <MyGUI_ProgressBar.h>
|
2023-11-23 19:52:18 +01:00
|
|
|
#include <MyGUI_UString.h>
|
2013-03-03 13:11:02 +01:00
|
|
|
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm/attr.hpp>
|
|
|
|
#include <components/esm3/loadmgef.hpp>
|
|
|
|
#include <components/esm3/loadspel.hpp>
|
2022-06-29 00:32:11 +02:00
|
|
|
#include <components/misc/resourcehelpers.hpp>
|
|
|
|
#include <components/resource/resourcesystem.hpp>
|
|
|
|
|
2012-08-12 14:36:46 +02:00
|
|
|
#include "../mwbase/environment.hpp"
|
2012-08-12 18:11:09 +02:00
|
|
|
#include "../mwbase/windowmanager.hpp"
|
2012-08-12 14:36:46 +02:00
|
|
|
|
2023-04-04 20:52:33 +02:00
|
|
|
#include "../mwmechanics/magiceffects.hpp"
|
|
|
|
|
2015-01-10 02:50:43 +01:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
|
2022-01-22 22:44:02 +01:00
|
|
|
namespace MWGui::Widgets
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
|
|
|
/* MWSkill */
|
2010-09-20 13:17:02 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWSkill::MWSkill()
|
2023-06-06 17:24:22 +02:00
|
|
|
: mSkillNameWidget(nullptr)
|
2018-10-09 10:21:12 +04:00
|
|
|
, mSkillValueWidget(nullptr)
|
2010-09-20 13:17:02 +02:00
|
|
|
{
|
|
|
|
}
|
2013-04-17 18:56:48 -04:00
|
|
|
|
2023-06-06 17:24:22 +02:00
|
|
|
void MWSkill::setSkillId(ESM::RefId skill)
|
2010-09-20 13:17:02 +02:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
mSkillId = skill;
|
|
|
|
updateWidgets();
|
2010-09-20 13:17:02 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWSkill::setSkillValue(const SkillValue& value)
|
|
|
|
{
|
|
|
|
mValue = value;
|
|
|
|
updateWidgets();
|
|
|
|
}
|
2010-09-20 13:17:02 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWSkill::updateWidgets()
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
if (mSkillNameWidget)
|
|
|
|
{
|
2023-06-06 17:24:22 +02:00
|
|
|
const ESM::Skill* skill = MWBase::Environment::get().getESMStore()->get<ESM::Skill>().search(mSkillId);
|
2023-05-29 17:56:14 +02:00
|
|
|
if (skill == nullptr)
|
2023-05-21 16:39:32 +02:00
|
|
|
mSkillNameWidget->setCaption({});
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
2023-05-29 17:56:14 +02:00
|
|
|
mSkillNameWidget->setCaption(skill->mName);
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
|
|
|
if (mSkillValueWidget)
|
|
|
|
{
|
|
|
|
SkillValue::Type modified = mValue.getModified(), base = mValue.getBase();
|
2015-01-10 03:01:01 +01:00
|
|
|
mSkillValueWidget->setCaption(MyGUI::utility::toString(modified));
|
2013-04-17 18:56:48 -04:00
|
|
|
if (modified > base)
|
|
|
|
mSkillValueWidget->_setWidgetState("increased");
|
|
|
|
else if (modified < base)
|
|
|
|
mSkillValueWidget->_setWidgetState("decreased");
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
2013-04-17 18:56:48 -04:00
|
|
|
mSkillValueWidget->_setWidgetState("normal");
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2012-03-20 20:24:36 +01:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWSkill::onClicked(MyGUI::Widget* _sender)
|
|
|
|
{
|
|
|
|
eventClicked(this);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2010-09-20 13:17:02 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWSkill::~MWSkill() {}
|
2010-09-20 13:17:02 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWSkill::initialiseOverride()
|
|
|
|
{
|
|
|
|
Base::initialiseOverride();
|
2010-09-20 13:17:02 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
assignWidget(mSkillNameWidget, "StatName");
|
|
|
|
assignWidget(mSkillValueWidget, "StatValue");
|
2010-09-24 15:28:14 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MyGUI::Button* button;
|
2018-10-09 10:21:12 +04:00
|
|
|
assignWidget(button, "StatNameButton");
|
|
|
|
if (button)
|
2010-09-20 13:17:02 +02:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
mSkillNameWidget = button;
|
|
|
|
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWSkill::onClicked);
|
2010-09-20 13:17:02 +02:00
|
|
|
}
|
2013-04-17 18:56:48 -04:00
|
|
|
|
|
|
|
button = nullptr;
|
|
|
|
assignWidget(button, "StatValueButton");
|
|
|
|
if (button)
|
2010-09-20 13:17:02 +02:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
mSkillValueWidget = button;
|
|
|
|
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWSkill::onClicked);
|
2010-09-20 13:17:02 +02:00
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2010-09-20 13:17:02 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
/* MWAttribute */
|
2010-09-20 13:17:02 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWAttribute::MWAttribute()
|
2023-08-03 20:21:44 +02:00
|
|
|
: mAttributeNameWidget(nullptr)
|
2018-10-09 10:21:12 +04:00
|
|
|
, mAttributeValueWidget(nullptr)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-08-03 20:21:44 +02:00
|
|
|
void MWAttribute::setAttributeId(ESM::RefId attributeId)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2022-08-24 22:16:03 +02:00
|
|
|
mId = attributeId;
|
2013-04-17 18:56:48 -04:00
|
|
|
updateWidgets();
|
|
|
|
}
|
2012-08-12 14:36:46 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWAttribute::setAttributeValue(const AttributeValue& value)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
mValue = value;
|
|
|
|
updateWidgets();
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWAttribute::onClicked(MyGUI::Widget* _sender)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
eventClicked(this);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWAttribute::updateWidgets()
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
if (mAttributeNameWidget)
|
|
|
|
{
|
2023-06-18 16:21:06 +02:00
|
|
|
const ESM::Attribute* attribute
|
|
|
|
= MWBase::Environment::get().getESMStore()->get<ESM::Attribute>().search(mId);
|
|
|
|
if (!attribute)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2023-05-21 16:39:32 +02:00
|
|
|
mAttributeNameWidget->setCaption({});
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2023-11-22 22:02:06 +01:00
|
|
|
mAttributeNameWidget->setCaption(MyGUI::UString(attribute->mName));
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mAttributeValueWidget)
|
|
|
|
{
|
|
|
|
int modified = mValue.getModified(), base = mValue.getBase();
|
2022-08-24 22:16:03 +02:00
|
|
|
mAttributeValueWidget->setCaption(MyGUI::utility::toString(modified));
|
2013-04-17 18:56:48 -04:00
|
|
|
if (modified > base)
|
|
|
|
mAttributeValueWidget->_setWidgetState("increased");
|
|
|
|
else if (modified < base)
|
|
|
|
mAttributeValueWidget->_setWidgetState("decreased");
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
2013-04-17 18:56:48 -04:00
|
|
|
mAttributeValueWidget->_setWidgetState("normal");
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2010-09-20 13:36:55 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWAttribute::initialiseOverride()
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
Base::initialiseOverride();
|
2012-11-06 00:34:11 +04:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
assignWidget(mAttributeNameWidget, "StatName");
|
|
|
|
assignWidget(mAttributeValueWidget, "StatValue");
|
2010-09-21 12:34:47 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MyGUI::Button* button;
|
2018-10-09 10:21:12 +04:00
|
|
|
assignWidget(button, "StatNameButton");
|
|
|
|
if (button)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
|
|
|
mAttributeNameWidget = button;
|
|
|
|
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWAttribute::onClicked);
|
|
|
|
}
|
2010-09-21 12:34:47 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
button = nullptr;
|
|
|
|
assignWidget(button, "StatValueButton");
|
|
|
|
if (button)
|
|
|
|
{
|
|
|
|
mAttributeValueWidget = button;
|
|
|
|
button->eventMouseButtonClick += MyGUI::newDelegate(this, &MWAttribute::onClicked);
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2010-09-20 13:36:55 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
/* MWSpell */
|
2010-09-20 13:36:55 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWSpell::MWSpell()
|
|
|
|
: mSpellNameWidget(nullptr)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
|
|
|
}
|
2010-09-20 13:36:55 +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
|
|
|
void MWSpell::setSpellId(const ESM::RefId& spellId)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2014-09-26 17:12:48 +02:00
|
|
|
mId = spellId;
|
2013-04-17 18:56:48 -04:00
|
|
|
updateWidgets();
|
|
|
|
}
|
2010-09-21 12:34:47 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWSpell::createEffectWidgets(
|
|
|
|
std::vector<MyGUI::Widget*>& effects, MyGUI::Widget* creator, MyGUI::IntCoord& coord, int flags)
|
|
|
|
{
|
2023-04-20 21:07:53 +02:00
|
|
|
const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
const ESM::Spell* spell = store.get<ESM::Spell>().search(mId);
|
2014-09-13 04:07:40 +02:00
|
|
|
MYGUI_ASSERT(spell, "spell with id '" << mId << "' not found");
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2024-03-25 13:50:23 +00:00
|
|
|
for (const ESM::IndexedENAMstruct& effectInfo : spell->mEffects.mList)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
MWSpellEffectPtr effect
|
2014-09-13 04:07:40 +02:00
|
|
|
= creator->createWidget<MWSpellEffect>("MW_EffectImage", coord, MyGUI::Align::Default);
|
2013-04-17 18:56:48 -04:00
|
|
|
SpellEffectParams params;
|
2024-03-25 13:50:23 +00:00
|
|
|
params.mEffectID = effectInfo.mData.mEffectID;
|
|
|
|
params.mSkill = ESM::Skill::indexToRefId(effectInfo.mData.mSkill);
|
|
|
|
params.mAttribute = ESM::Attribute::indexToRefId(effectInfo.mData.mAttribute);
|
|
|
|
params.mDuration = effectInfo.mData.mDuration;
|
|
|
|
params.mMagnMin = effectInfo.mData.mMagnMin;
|
|
|
|
params.mMagnMax = effectInfo.mData.mMagnMax;
|
|
|
|
params.mRange = effectInfo.mData.mRange;
|
2015-03-06 23:19:57 +13:00
|
|
|
params.mIsConstant = (flags & MWEffectList::EF_Constant) != 0;
|
2013-04-17 18:56:48 -04:00
|
|
|
params.mNoTarget = (flags & MWEffectList::EF_NoTarget);
|
2019-05-06 23:48:13 +00:00
|
|
|
params.mNoMagnitude = (flags & MWEffectList::EF_NoMagnitude);
|
2014-09-13 04:07:40 +02:00
|
|
|
effect->setSpellEffect(params);
|
2013-04-17 18:56:48 -04:00
|
|
|
effects.push_back(effect);
|
|
|
|
coord.top += effect->getHeight();
|
|
|
|
coord.width = std::max(coord.width, effect->getRequestedWidth());
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2012-04-18 18:09:30 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWSpell::updateWidgets()
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
if (mSpellNameWidget && MWBase::Environment::get().getWindowManager())
|
|
|
|
{
|
2023-04-20 21:07:53 +02:00
|
|
|
const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
|
2012-04-18 18:09:30 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
const ESM::Spell* spell = store.get<ESM::Spell>().search(mId);
|
|
|
|
if (spell)
|
|
|
|
mSpellNameWidget->setCaption(spell->mName);
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
2023-05-21 16:39:32 +02:00
|
|
|
mSpellNameWidget->setCaption({});
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2012-04-18 18:09:30 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWSpell::initialiseOverride()
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
Base::initialiseOverride();
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
assignWidget(mSpellNameWidget, "StatName");
|
|
|
|
}
|
2012-05-24 14:47:57 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWSpell::~MWSpell() {}
|
2012-04-30 00:57:41 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
/* MWEffectList */
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWEffectList::MWEffectList()
|
|
|
|
: mEffectList(0)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWEffectList::setEffectList(const SpellEffectList& list)
|
2012-04-30 00:57:41 +02:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
mEffectList = list;
|
|
|
|
updateWidgets();
|
2012-04-30 00:57:41 +02:00
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWEffectList::createEffectWidgets(
|
|
|
|
std::vector<MyGUI::Widget*>& effects, MyGUI::Widget* creator, MyGUI::IntCoord& coord, bool center, int flags)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
// We don't know the width of all the elements beforehand, so we do it in
|
|
|
|
// 2 steps: first, create all widgets and check their width....
|
2018-10-09 10:21:12 +04:00
|
|
|
MWSpellEffectPtr effect = nullptr;
|
2013-04-17 18:56:48 -04:00
|
|
|
int maxwidth = coord.width;
|
|
|
|
|
|
|
|
for (auto& effectInfo : mEffectList)
|
2012-04-30 00:57:41 +02:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
effect = creator->createWidget<MWSpellEffect>("MW_EffectImage", coord, MyGUI::Align::Default);
|
|
|
|
effectInfo.mIsConstant = (flags & EF_Constant) || effectInfo.mIsConstant;
|
2019-03-02 13:27:59 +04:00
|
|
|
effectInfo.mNoTarget = (flags & EF_NoTarget) || effectInfo.mNoTarget;
|
2019-05-06 23:48:13 +00:00
|
|
|
effectInfo.mNoMagnitude = (flags & EF_NoMagnitude) || effectInfo.mNoMagnitude;
|
2019-03-02 13:27:59 +04:00
|
|
|
effect->setSpellEffect(effectInfo);
|
2013-04-17 18:56:48 -04:00
|
|
|
effects.push_back(effect);
|
|
|
|
if (effect->getRequestedWidth() > maxwidth)
|
|
|
|
maxwidth = effect->getRequestedWidth();
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
coord.top += effect->getHeight();
|
2012-04-30 00:57:41 +02:00
|
|
|
}
|
2012-04-18 18:09:30 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
// ... then adjust the size for all widgets
|
|
|
|
for (MyGUI::Widget* effectWidget : effects)
|
|
|
|
{
|
2018-10-09 10:21:12 +04:00
|
|
|
effect = effectWidget->castType<MWSpellEffect>();
|
|
|
|
bool needcenter = center && (maxwidth > effect->getRequestedWidth());
|
2013-04-17 18:56:48 -04:00
|
|
|
int diff = maxwidth - effect->getRequestedWidth();
|
2019-03-02 13:27:59 +04:00
|
|
|
if (needcenter)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
|
|
|
effect->setCoord(
|
|
|
|
diff / 2, effect->getCoord().top, effect->getRequestedWidth(), effect->getCoord().height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
effect->setCoord(0, effect->getCoord().top, effect->getRequestedWidth(), effect->getCoord().height);
|
|
|
|
}
|
|
|
|
}
|
2012-10-03 15:06:54 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
// inform the parent about width
|
|
|
|
coord.width = maxwidth;
|
|
|
|
}
|
2012-10-03 15:06:54 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWEffectList::updateWidgets() {}
|
2012-10-03 15:06:54 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWEffectList::initialiseOverride()
|
2012-05-24 14:47:57 +02:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
Base::initialiseOverride();
|
2012-05-24 14:47:57 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWEffectList::~MWEffectList() {}
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
SpellEffectList MWEffectList::effectListFromESM(const ESM::EffectList* effects)
|
2012-05-24 14:47:57 +02:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
SpellEffectList result;
|
2024-03-25 13:50:23 +00:00
|
|
|
for (const ESM::IndexedENAMstruct& effectInfo : effects->mList)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
|
|
|
SpellEffectParams params;
|
2024-03-25 13:50:23 +00:00
|
|
|
params.mEffectID = effectInfo.mData.mEffectID;
|
|
|
|
params.mSkill = ESM::Skill::indexToRefId(effectInfo.mData.mSkill);
|
|
|
|
params.mAttribute = ESM::Attribute::indexToRefId(effectInfo.mData.mAttribute);
|
|
|
|
params.mDuration = effectInfo.mData.mDuration;
|
|
|
|
params.mMagnMin = effectInfo.mData.mMagnMin;
|
|
|
|
params.mMagnMax = effectInfo.mData.mMagnMax;
|
|
|
|
params.mRange = effectInfo.mData.mRange;
|
|
|
|
params.mArea = effectInfo.mData.mArea;
|
2013-04-17 18:56:48 -04:00
|
|
|
result.push_back(params);
|
|
|
|
}
|
|
|
|
return result;
|
2012-05-24 14:47:57 +02:00
|
|
|
}
|
2012-04-30 01:53:22 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
/* MWSpellEffect */
|
|
|
|
|
|
|
|
MWSpellEffect::MWSpellEffect()
|
2018-10-09 10:21:12 +04:00
|
|
|
: mImageWidget(nullptr)
|
|
|
|
, mTextWidget(nullptr)
|
2013-04-17 18:56:48 -04:00
|
|
|
, mRequestedWidth(0)
|
2012-10-11 18:26:29 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWSpellEffect::setSpellEffect(const SpellEffectParams& params)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
mEffectParams = params;
|
|
|
|
updateWidgets();
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWSpellEffect::updateWidgets()
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
if (!mEffectParams.mKnown)
|
2012-05-24 14:47:57 +02:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
mTextWidget->setCaption("?");
|
2019-09-02 17:13:56 +00:00
|
|
|
mTextWidget->setCoord(sIconOffset / 2, mTextWidget->getCoord().top, mTextWidget->getCoord().width,
|
2013-04-17 18:56:48 -04:00
|
|
|
mTextWidget->getCoord().height); // Compensates for the missing image when effect is not known
|
|
|
|
mRequestedWidth = mTextWidget->getTextSize().width + sIconOffset;
|
2023-05-21 16:39:32 +02:00
|
|
|
mImageWidget->setImageTexture({});
|
2022-09-22 21:26:05 +03:00
|
|
|
return;
|
2010-09-21 12:34:47 +02:00
|
|
|
}
|
2012-10-03 15:06:54 +02:00
|
|
|
|
2023-04-20 21:07:53 +02:00
|
|
|
const MWWorld::ESMStore& store = *MWBase::Environment::get().getESMStore();
|
2012-10-03 15:06:54 +02:00
|
|
|
|
2023-10-28 01:27:29 +03:00
|
|
|
const ESM::MagicEffect* magicEffect = store.get<ESM::MagicEffect>().find(mEffectParams.mEffectID);
|
2023-05-28 15:10:53 +02:00
|
|
|
const ESM::Attribute* attribute = store.get<ESM::Attribute>().search(mEffectParams.mAttribute);
|
2023-08-03 20:21:44 +02:00
|
|
|
const ESM::Skill* skill = store.get<ESM::Skill>().search(mEffectParams.mSkill);
|
2010-09-21 12:34:47 +02:00
|
|
|
|
2023-03-20 19:59:11 +01:00
|
|
|
auto windowManager = MWBase::Environment::get().getWindowManager();
|
|
|
|
|
|
|
|
std::string_view pt = windowManager->getGameSettingString("spoint", {});
|
|
|
|
std::string_view pts = windowManager->getGameSettingString("spoints", {});
|
|
|
|
std::string_view pct = windowManager->getGameSettingString("spercent", {});
|
|
|
|
std::string_view ft = windowManager->getGameSettingString("sfeet", {});
|
|
|
|
std::string_view lvl = windowManager->getGameSettingString("sLevel", {});
|
|
|
|
std::string_view lvls = windowManager->getGameSettingString("sLevels", {});
|
|
|
|
std::string to = " " + std::string{ windowManager->getGameSettingString("sTo", {}) } + " ";
|
|
|
|
std::string sec = " " + std::string{ windowManager->getGameSettingString("ssecond", {}) };
|
|
|
|
std::string secs = " " + std::string{ windowManager->getGameSettingString("sseconds", {}) };
|
|
|
|
|
2023-05-29 17:56:14 +02:00
|
|
|
std::string spellLine = MWMechanics::getMagicEffectString(*magicEffect, attribute, skill);
|
2010-10-20 21:39:18 +02:00
|
|
|
|
2024-02-15 01:50:49 +03:00
|
|
|
if ((mEffectParams.mMagnMin || mEffectParams.mMagnMax) && !mEffectParams.mNoMagnitude)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2014-06-29 17:02:29 +02:00
|
|
|
ESM::MagicEffect::MagnitudeDisplayType displayType = magicEffect->getMagnitudeDisplayType();
|
|
|
|
if (displayType == ESM::MagicEffect::MDT_TimesInt)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2023-03-20 19:59:11 +01:00
|
|
|
std::string_view timesInt = windowManager->getGameSettingString("sXTimesINT", {});
|
2022-08-24 22:16:03 +02:00
|
|
|
std::stringstream formatter;
|
2010-10-20 21:39:18 +02:00
|
|
|
|
2013-10-06 19:46:04 -05:00
|
|
|
formatter << std::fixed << std::setprecision(1) << " " << (mEffectParams.mMagnMin / 10.0f);
|
2019-05-05 21:27:48 +03:00
|
|
|
if (mEffectParams.mMagnMin != mEffectParams.mMagnMax)
|
2013-10-09 00:08:11 -05:00
|
|
|
formatter << to << (mEffectParams.mMagnMax / 10.0f);
|
2022-08-24 22:16:03 +02:00
|
|
|
formatter << timesInt;
|
2013-10-06 19:46:04 -05:00
|
|
|
|
2015-01-10 03:01:01 +01:00
|
|
|
spellLine += formatter.str();
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2024-02-15 01:50:49 +03:00
|
|
|
else if (displayType != ESM::MagicEffect::MDT_None)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2020-05-23 23:12:56 +03:00
|
|
|
spellLine += " " + MyGUI::utility::toString(mEffectParams.mMagnMin);
|
|
|
|
if (mEffectParams.mMagnMin != mEffectParams.mMagnMax)
|
|
|
|
spellLine += to + MyGUI::utility::toString(mEffectParams.mMagnMax);
|
|
|
|
|
2014-11-05 00:46:33 +13:00
|
|
|
if (displayType == ESM::MagicEffect::MDT_Percentage)
|
|
|
|
spellLine += pct;
|
|
|
|
else if (displayType == ESM::MagicEffect::MDT_Feet)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
2022-08-24 22:16:03 +02:00
|
|
|
spellLine += ' ';
|
|
|
|
spellLine += ft;
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
|
|
|
else if (displayType == ESM::MagicEffect::MDT_Level)
|
|
|
|
{
|
2015-01-10 03:01:01 +01:00
|
|
|
spellLine += ' ';
|
|
|
|
if (mEffectParams.mMagnMin == mEffectParams.mMagnMax && std::abs(mEffectParams.mMagnMin) == 1)
|
|
|
|
spellLine += lvl;
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
2015-01-10 03:01:01 +01:00
|
|
|
spellLine += lvls;
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
|
|
|
else // ESM::MagicEffect::MDT_Points
|
|
|
|
{
|
2022-08-24 22:16:03 +02:00
|
|
|
spellLine += ' ';
|
2013-04-17 18:56:48 -04:00
|
|
|
if (mEffectParams.mMagnMin == mEffectParams.mMagnMax && std::abs(mEffectParams.mMagnMin) == 1)
|
|
|
|
spellLine += pt;
|
|
|
|
else
|
2022-08-24 22:16:03 +02:00
|
|
|
spellLine += pts;
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// constant effects have no duration and no target
|
|
|
|
if (!mEffectParams.mIsConstant)
|
2010-10-20 21:39:18 +02:00
|
|
|
{
|
2020-05-23 23:12:56 +03:00
|
|
|
if (!(magicEffect->mData.mFlags & ESM::MagicEffect::AppliedOnce))
|
2022-08-24 22:16:03 +02:00
|
|
|
mEffectParams.mDuration = std::max(1, mEffectParams.mDuration);
|
2010-10-20 21:39:18 +02:00
|
|
|
|
2014-11-05 00:46:33 +13:00
|
|
|
if (mEffectParams.mDuration > 0 && !(magicEffect->mData.mFlags & ESM::MagicEffect::NoDuration))
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2022-08-24 22:16:03 +02:00
|
|
|
spellLine += ' ';
|
2023-03-20 19:59:11 +01:00
|
|
|
spellLine += windowManager->getGameSettingString("sfor", {});
|
2013-04-17 18:56:48 -04:00
|
|
|
spellLine += ' ' + MyGUI::utility::toString(mEffectParams.mDuration)
|
|
|
|
+ ((mEffectParams.mDuration == 1) ? sec : secs);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2010-10-20 21:39:18 +02:00
|
|
|
|
2022-08-24 22:16:03 +02:00
|
|
|
if (mEffectParams.mArea > 0)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
spellLine += " #{sin} " + MyGUI::utility::toString(mEffectParams.mArea) + " #{sfootarea}";
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
// potions have no target
|
|
|
|
if (!mEffectParams.mNoTarget)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2022-08-24 22:16:03 +02:00
|
|
|
spellLine += ' ';
|
2023-03-20 19:59:11 +01:00
|
|
|
spellLine += windowManager->getGameSettingString("sonword", {});
|
2022-08-24 22:16:03 +02:00
|
|
|
spellLine += ' ';
|
2013-04-17 18:56:48 -04:00
|
|
|
if (mEffectParams.mRange == ESM::RT_Self)
|
2023-03-20 19:59:11 +01:00
|
|
|
spellLine += windowManager->getGameSettingString("sRangeSelf", {});
|
2013-04-17 18:56:48 -04:00
|
|
|
else if (mEffectParams.mRange == ESM::RT_Touch)
|
2023-03-20 19:59:11 +01:00
|
|
|
spellLine += windowManager->getGameSettingString("sRangeTouch", {});
|
2013-04-17 18:56:48 -04:00
|
|
|
else if (mEffectParams.mRange == ESM::RT_Target)
|
2023-03-20 19:59:11 +01:00
|
|
|
spellLine += windowManager->getGameSettingString("sRangeTarget", {});
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2010-10-20 21:39:18 +02:00
|
|
|
|
2014-09-13 04:07:40 +02:00
|
|
|
mTextWidget->setCaptionWithReplacing(spellLine);
|
2013-04-17 18:56:48 -04:00
|
|
|
mRequestedWidth = mTextWidget->getTextSize().width + sIconOffset;
|
2012-09-10 11:20:27 +02:00
|
|
|
|
2022-06-29 00:32:11 +02:00
|
|
|
mImageWidget->setImageTexture(Misc::ResourceHelpers::correctIconPath(
|
|
|
|
magicEffect->mIcon, MWBase::Environment::get().getResourceSystem()->getVFS()));
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2014-09-26 17:12:48 +02:00
|
|
|
MWSpellEffect::~MWSpellEffect() {}
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWSpellEffect::initialiseOverride()
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
Base::initialiseOverride();
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
assignWidget(mTextWidget, "Text");
|
|
|
|
assignWidget(mImageWidget, "Image");
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
/* MWDynamicStat */
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWDynamicStat::MWDynamicStat()
|
|
|
|
: mValue(0)
|
|
|
|
, mMax(1)
|
2018-10-09 10:21:12 +04:00
|
|
|
, mTextWidget(nullptr)
|
|
|
|
, mBarWidget(nullptr)
|
|
|
|
, mBarTextWidget(nullptr)
|
2013-04-17 18:56:48 -04:00
|
|
|
{
|
|
|
|
}
|
2012-09-10 11:20:27 +02:00
|
|
|
|
2017-08-29 18:04:31 +04:00
|
|
|
void MWDynamicStat::setValue(int cur, int max)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2017-08-29 18:04:31 +04:00
|
|
|
mValue = cur;
|
2013-04-17 18:56:48 -04:00
|
|
|
mMax = max;
|
2012-09-10 11:20:27 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
if (mBarWidget)
|
|
|
|
{
|
|
|
|
mBarWidget->setProgressRange(std::max(0, mMax));
|
2022-08-24 22:16:03 +02:00
|
|
|
mBarWidget->setProgressPosition(std::max(0, mValue));
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2012-09-10 11:20:27 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
if (mBarTextWidget)
|
|
|
|
{
|
2014-01-02 21:48:33 +01:00
|
|
|
std::stringstream out;
|
|
|
|
out << mValue << "/" << mMax;
|
2023-11-22 22:02:06 +01:00
|
|
|
mBarTextWidget->setCaption(out.str());
|
2013-04-17 18:56:48 -04:00
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2022-08-24 22:16:03 +02:00
|
|
|
void MWDynamicStat::setTitle(std::string_view text)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
if (mTextWidget)
|
2023-11-22 22:02:06 +01:00
|
|
|
mTextWidget->setCaption(MyGUI::UString(text));
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2012-09-10 11:20:27 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
MWDynamicStat::~MWDynamicStat() {}
|
2012-09-10 11:20:27 +02:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
void MWDynamicStat::initialiseOverride()
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-04-17 18:56:48 -04:00
|
|
|
Base::initialiseOverride();
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2013-04-17 18:56:48 -04:00
|
|
|
assignWidget(mTextWidget, "Text");
|
|
|
|
assignWidget(mBarWidget, "Bar");
|
|
|
|
assignWidget(mBarTextWidget, "BarText");
|
2012-09-10 11:20:27 +02:00
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|