1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-29 09:32:45 +00:00
OpenMW/apps/openmw/mwgui/widgets.hpp

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

304 lines
9.0 KiB
C++
Raw Normal View History

#ifndef MWGUI_WIDGETS_H
#define MWGUI_WIDGETS_H
#include "../mwmechanics/stat.hpp"
#include <MyGUI_Delegate.h>
#include <MyGUI_TextBox.h>
#include <MyGUI_Widget.h>
2023-06-19 20:41:54 +02:00
#include <components/esm/attr.hpp>
#include <components/esm/refid.hpp>
#include <components/esm3/effectlist.hpp>
#include <components/esm3/loadskil.hpp>
namespace MyGUI
{
class ImageBox;
2015-01-10 02:50:43 +01:00
class ControllerItem;
}
namespace MWBase
{
class WindowManager;
}
/*
This file contains various custom widgets used in OpenMW.
*/
namespace MWGui
{
namespace Widgets
{
class MWEffectList;
2012-05-24 03:48:02 +02:00
struct SpellEffectParams
{
SpellEffectParams()
2015-04-25 13:37:42 -05:00
: mNoTarget(false)
, mIsConstant(false)
2019-05-06 23:48:13 +00:00
, mNoMagnitude(false)
2015-04-25 13:37:42 -05:00
, mKnown(true)
, mEffectID(-1)
, mMagnMin(-1)
, mMagnMax(-1)
, mRange(-1)
, mDuration(-1)
2012-10-11 18:26:29 +02:00
, mArea(0)
{
}
bool mNoTarget; // potion effects for example have no target (target is always the player)
2012-05-24 03:48:02 +02:00
bool mIsConstant; // constant effect means that duration will not be displayed
2019-05-06 23:48:13 +00:00
bool mNoMagnitude; // effect magnitude will not be displayed (e.g ingredients)
2012-05-24 03:48:02 +02:00
bool mKnown; // is this effect known to the player? (If not, will display as a question mark instead)
// value of -1 here means the effect is unknown to the player
short mEffectID;
2023-08-03 20:21:44 +02:00
ESM::RefId mSkill, mAttribute;
// value of -1 here means the value is unavailable
int mMagnMin, mMagnMax, mRange, mDuration;
2012-05-25 16:20:57 +02:00
2012-10-11 18:26:29 +02:00
// value of 0 -> no area effect
int mArea;
2012-05-25 16:20:57 +02:00
bool operator==(const SpellEffectParams& other) const
{
2012-06-04 20:56:13 +02:00
if (mEffectID != other.mEffectID)
return false;
bool involvesAttribute = (mEffectID == 74 // restore attribute
|| mEffectID == 85 // absorb attribute
|| mEffectID == 17 // drain attribute
|| mEffectID == 79 // fortify attribute
|| mEffectID == 22); // damage attribute
bool involvesSkill = (mEffectID == 78 // restore skill
|| mEffectID == 89 // absorb skill
|| mEffectID == 21 // drain skill
|| mEffectID == 83 // fortify skill
|| mEffectID == 26); // damage skill
2012-10-11 18:26:29 +02:00
return ((other.mSkill == mSkill) || !involvesSkill)
&& ((other.mAttribute == mAttribute) && !involvesAttribute) && (other.mArea == mArea);
2012-05-25 16:20:57 +02:00
}
2012-05-24 03:48:02 +02:00
};
typedef std::vector<SpellEffectParams> SpellEffectList;
2020-02-13 21:36:56 +01:00
class MWSkill final : public MyGUI::Widget
{
MYGUI_RTTI_DERIVED(MWSkill)
public:
MWSkill();
typedef MWMechanics::Stat<float> SkillValue;
2023-06-06 17:24:22 +02:00
void setSkillId(ESM::RefId skillId);
void setSkillValue(const SkillValue& value);
2023-06-06 17:24:22 +02:00
ESM::RefId getSkillId() const { return mSkillId; }
const SkillValue& getSkillValue() const { return mValue; }
// Events
typedef MyGUI::delegates::MultiDelegate<MWSkill*> EventHandle_SkillVoid;
/** Event : Skill clicked.\n
signature : void method(MWSkill* _sender)\n
*/
EventHandle_SkillVoid eventClicked;
protected:
2011-01-05 22:18:21 +01:00
virtual ~MWSkill();
void initialiseOverride() override;
void onClicked(MyGUI::Widget* _sender);
2011-01-05 22:18:21 +01:00
private:
void updateWidgets();
2023-06-06 17:24:22 +02:00
ESM::RefId mSkillId;
SkillValue mValue;
2014-09-13 04:07:40 +02:00
MyGUI::TextBox* mSkillNameWidget;
MyGUI::TextBox* mSkillValueWidget;
};
typedef MWSkill* MWSkillPtr;
2020-02-13 21:36:56 +01:00
class MWAttribute final : public MyGUI::Widget
{
MYGUI_RTTI_DERIVED(MWAttribute)
public:
MWAttribute();
typedef MWMechanics::AttributeValue AttributeValue;
2023-08-03 20:21:44 +02:00
void setAttributeId(ESM::RefId attributeId);
void setAttributeValue(const AttributeValue& value);
2023-08-03 20:21:44 +02:00
ESM::RefId getAttributeId() const { return mId; }
const AttributeValue& getAttributeValue() const { return mValue; }
// Events
typedef MyGUI::delegates::MultiDelegate<MWAttribute*> EventHandle_AttributeVoid;
/** Event : Attribute clicked.\n
signature : void method(MWAttribute* _sender)\n
*/
EventHandle_AttributeVoid eventClicked;
protected:
2023-06-19 20:41:54 +02:00
~MWAttribute() override = default;
void initialiseOverride() override;
void onClicked(MyGUI::Widget* _sender);
2011-01-05 22:18:21 +01:00
private:
void updateWidgets();
2023-08-03 20:21:44 +02:00
ESM::RefId mId;
AttributeValue mValue;
2014-09-13 04:07:40 +02:00
MyGUI::TextBox* mAttributeNameWidget;
MyGUI::TextBox* mAttributeValueWidget;
};
typedef MWAttribute* MWAttributePtr;
/**
* @todo remove this class and use MWEffectList instead
*/
class MWSpellEffect;
2020-02-13 21:36:56 +01:00
class MWSpell final : public MyGUI::Widget
{
MYGUI_RTTI_DERIVED(MWSpell)
public:
MWSpell();
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 setSpellId(const ESM::RefId& id);
/**
* @param vector to store the created effect widgets
* @param parent widget
* @param coordinates to use, will be expanded if more space is needed
* @param spell category, if this is 0, this means the spell effects are permanent and won't display e.g.
* duration
2012-04-30 02:10:55 +02:00
* @param various flags, see MWEffectList::EffectFlags
*/
void createEffectWidgets(
std::vector<MyGUI::Widget*>& effects, MyGUI::Widget* creator, MyGUI::IntCoord& coord, int flags);
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
const ESM::RefId& getSpellId() const { return mId; }
protected:
2011-01-05 22:18:21 +01:00
virtual ~MWSpell();
void initialiseOverride() override;
2011-01-05 22:18:21 +01:00
private:
void updateWidgets();
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
ESM::RefId mId;
MyGUI::TextBox* mSpellNameWidget;
};
typedef MWSpell* MWSpellPtr;
2020-02-13 21:36:56 +01:00
class MWEffectList final : public MyGUI::Widget
2012-04-18 18:09:30 +02:00
{
MYGUI_RTTI_DERIVED(MWEffectList)
2012-04-18 18:09:30 +02:00
public:
MWEffectList();
2012-04-18 18:09:30 +02:00
2012-04-30 01:53:22 +02:00
enum EffectFlags
{
EF_NoTarget = 0x01, // potions have no target (target is always the player)
2019-05-06 23:48:13 +00:00
EF_Constant = 0x02, // constant effect means that duration will not be displayed
EF_NoMagnitude = 0x04 // ingredients have no magnitude
2012-04-30 01:53:22 +02:00
};
void setEffectList(const SpellEffectList& list);
static SpellEffectList effectListFromESM(const ESM::EffectList* effects);
/**
* @param vector to store the created effect widgets
* @param parent widget
* @param coordinates to use, will be expanded if more space is needed
* @param center the effect widgets horizontally
2012-04-30 01:53:22 +02:00
* @param various flags, see MWEffectList::EffectFlags
*/
void createEffectWidgets(std::vector<MyGUI::Widget*>& effects, MyGUI::Widget* creator,
MyGUI::IntCoord& coord, bool center, int flags);
2012-04-18 18:09:30 +02:00
protected:
virtual ~MWEffectList();
2012-04-18 18:09:30 +02:00
void initialiseOverride() override;
2012-04-18 18:09:30 +02:00
private:
void updateWidgets();
SpellEffectList mEffectList;
2012-04-18 18:09:30 +02:00
};
typedef MWEffectList* MWEffectListPtr;
2012-04-18 18:09:30 +02:00
2020-02-13 21:36:56 +01:00
class MWSpellEffect final : public MyGUI::Widget
{
MYGUI_RTTI_DERIVED(MWSpellEffect)
public:
MWSpellEffect();
typedef ESM::ENAMstruct SpellEffectValue;
void setSpellEffect(const SpellEffectParams& params);
int getRequestedWidth() const { return mRequestedWidth; }
protected:
2011-01-05 22:18:21 +01:00
virtual ~MWSpellEffect();
void initialiseOverride() override;
2011-01-05 22:18:21 +01:00
private:
static constexpr int sIconOffset = 24;
2022-09-22 21:26:05 +03:00
void updateWidgets();
SpellEffectParams mEffectParams;
MyGUI::ImageBox* mImageWidget;
MyGUI::TextBox* mTextWidget;
int mRequestedWidth;
};
typedef MWSpellEffect* MWSpellEffectPtr;
2020-02-13 21:36:56 +01:00
class MWDynamicStat final : public MyGUI::Widget
{
MYGUI_RTTI_DERIVED(MWDynamicStat)
public:
MWDynamicStat();
void setValue(int value, int max);
void setTitle(std::string_view text);
int getValue() const { return mValue; }
int getMax() const { return mMax; }
protected:
virtual ~MWDynamicStat();
void initialiseOverride() override;
private:
int mValue, mMax;
MyGUI::TextBox* mTextWidget;
2014-09-13 04:07:40 +02:00
MyGUI::ProgressBar* mBarWidget;
MyGUI::TextBox* mBarTextWidget;
};
typedef MWDynamicStat* MWDynamicStatPtr;
}
}
#endif