OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
widgets.hpp
Go to the documentation of this file.
1 #ifndef MWGUI_WIDGETS_H
2 #define MWGUI_WIDGETS_H
3 
4 #include "../mwmechanics/stat.hpp"
5 
8 
9 #include <MyGUI_Button.h>
10 #include <MyGUI_EditBox.h>
11 #include <MyGUI_ScrollBar.h>
12 
13 namespace MyGUI
14 {
15  class ImageBox;
16  class ControllerItem;
17 }
18 
19 namespace MWBase
20 {
21  class WindowManager;
22 }
23 
24 /*
25  This file contains various custom widgets used in OpenMW.
26  */
27 
28 namespace MWGui
29 {
30  namespace Widgets
31  {
32  class MWEffectList;
33 
34  void fixTexturePath(std::string &path);
35 
37  {
39  : mNoTarget(false)
40  , mIsConstant(false)
41  , mKnown(true)
42  , mEffectID(-1)
43  , mSkill(-1)
44  , mAttribute(-1)
45  , mMagnMin(-1)
46  , mMagnMax(-1)
47  , mRange(-1)
48  , mDuration(-1)
49  , mArea(0)
50  {
51  }
52 
53  bool mNoTarget; // potion effects for example have no target (target is always the player)
54  bool mIsConstant; // constant effect means that duration will not be displayed
55 
56  bool mKnown; // is this effect known to the player? (If not, will display as a question mark instead)
57 
58  // value of -1 here means the effect is unknown to the player
59  short mEffectID;
60 
61  // value of -1 here means there is no skill/attribute
62  signed char mSkill, mAttribute;
63 
64  // value of -1 here means the value is unavailable
66 
67  // value of 0 -> no area effect
68  int mArea;
69 
70  bool operator==(const SpellEffectParams& other) const
71  {
72  if (mEffectID != other.mEffectID)
73  return false;
74 
75  bool involvesAttribute = (mEffectID == 74 // restore attribute
76  || mEffectID == 85 // absorb attribute
77  || mEffectID == 17 // drain attribute
78  || mEffectID == 79 // fortify attribute
79  || mEffectID == 22); // damage attribute
80  bool involvesSkill = (mEffectID == 78 // restore skill
81  || mEffectID == 89 // absorb skill
82  || mEffectID == 21 // drain skill
83  || mEffectID == 83 // fortify skill
84  || mEffectID == 26); // damage skill
85  return ((other.mSkill == mSkill) || !involvesSkill) && ((other.mAttribute == mAttribute) && !involvesAttribute) && (other.mArea == mArea);
86  }
87  };
88 
89  typedef std::vector<SpellEffectParams> SpellEffectList;
90 
91  class MWSkill : public MyGUI::Widget
92  {
93  MYGUI_RTTI_DERIVED( MWSkill )
94  public:
95  MWSkill();
96 
98 
99  void setSkillId(ESM::Skill::SkillEnum skillId);
100  void setSkillNumber(int skillId);
101  void setSkillValue(const SkillValue& value);
102 
104  const SkillValue& getSkillValue() const { return mValue; }
105 
106  // Events
107  typedef MyGUI::delegates::CMultiDelegate1<MWSkill*> EventHandle_SkillVoid;
108 
113 
114  protected:
115  virtual ~MWSkill();
116 
117  virtual void initialiseOverride();
118 
119  void onClicked(MyGUI::Widget* _sender);
120 
121  private:
122 
123  void updateWidgets();
124 
127  MyGUI::TextBox* mSkillNameWidget;
128  MyGUI::TextBox* mSkillValueWidget;
129  };
130  typedef MWSkill* MWSkillPtr;
131 
132  class MWAttribute : public MyGUI::Widget
133  {
134  MYGUI_RTTI_DERIVED( MWAttribute )
135  public:
136  MWAttribute();
137 
139 
140  void setAttributeId(int attributeId);
141  void setAttributeValue(const AttributeValue& value);
142 
143  int getAttributeId() const { return mId; }
144  const AttributeValue& getAttributeValue() const { return mValue; }
145 
146  // Events
147  typedef MyGUI::delegates::CMultiDelegate1<MWAttribute*> EventHandle_AttributeVoid;
148 
153 
154  protected:
155  virtual ~MWAttribute();
156 
157  virtual void initialiseOverride();
158 
159  void onClicked(MyGUI::Widget* _sender);
160 
161  private:
162 
163  void updateWidgets();
164 
165  int mId;
167  MyGUI::TextBox* mAttributeNameWidget;
168  MyGUI::TextBox* mAttributeValueWidget;
169  };
171 
175  class MWSpellEffect;
176  class MWSpell : public MyGUI::Widget
177  {
178  MYGUI_RTTI_DERIVED( MWSpell )
179  public:
180  MWSpell();
181 
183 
184  void setSpellId(const std::string &id);
185 
193  void createEffectWidgets(std::vector<MyGUI::Widget*> &effects, MyGUI::Widget* creator, MyGUI::IntCoord &coord, int flags);
194 
195  const std::string &getSpellId() const { return mId; }
196 
197  protected:
198  virtual ~MWSpell();
199 
200  virtual void initialiseOverride();
201 
202  private:
203  void updateWidgets();
204 
205  std::string mId;
206  MyGUI::TextBox* mSpellNameWidget;
207  };
208  typedef MWSpell* MWSpellPtr;
209 
210  class MWEffectList : public MyGUI::Widget
211  {
212  MYGUI_RTTI_DERIVED( MWEffectList )
213  public:
214  MWEffectList();
215 
217 
219  {
220  EF_NoTarget = 0x01, // potions have no target (target is always the player)
221  EF_Constant = 0x02 // constant effect means that duration will not be displayed
222  };
223 
224  void setEffectList(const SpellEffectList& list);
225 
226  static SpellEffectList effectListFromESM(const ESM::EffectList* effects);
227 
235  void createEffectWidgets(std::vector<MyGUI::Widget*> &effects, MyGUI::Widget* creator, MyGUI::IntCoord &coord, bool center, int flags);
236 
237  protected:
238  virtual ~MWEffectList();
239 
240  virtual void initialiseOverride();
241 
242  private:
243  void updateWidgets();
244 
246  };
248 
249  class MWSpellEffect : public MyGUI::Widget
250  {
251  MYGUI_RTTI_DERIVED( MWSpellEffect )
252  public:
253  MWSpellEffect();
254 
256 
257  void setSpellEffect(const SpellEffectParams& params);
258 
259  int getRequestedWidth() const { return mRequestedWidth; }
260 
261  protected:
262  virtual ~MWSpellEffect();
263 
264  virtual void initialiseOverride();
265 
266  private:
267 
268  void updateWidgets();
269 
271  MyGUI::ImageBox* mImageWidget;
272  MyGUI::TextBox* mTextWidget;
274  };
276 
277  class MWDynamicStat : public MyGUI::Widget
278  {
279  MYGUI_RTTI_DERIVED( MWDynamicStat )
280  public:
281  MWDynamicStat();
282 
283  void setValue(int value, int max);
284  void setTitle(const std::string& text);
285 
286  int getValue() const { return mValue; }
287  int getMax() const { return mMax; }
288 
289  protected:
290  virtual ~MWDynamicStat();
291 
292  virtual void initialiseOverride();
293 
294  private:
295 
296  int mValue, mMax;
297  MyGUI::TextBox* mTextWidget;
298  MyGUI::ProgressBar* mBarWidget;
299  MyGUI::TextBox* mBarTextWidget;
300  };
302 
303  // Should be removed when upgrading to MyGUI 3.2.2 (current git), it has ScrollBar autorepeat support
304  class MWScrollBar : public MyGUI::ScrollBar
305  {
306  MYGUI_RTTI_DERIVED(MWScrollBar)
307 
308  public:
309  MWScrollBar();
310  virtual ~MWScrollBar();
311 
312  void setRepeat(float trigger, float step);
313 
314  protected:
315  virtual void initialiseOverride();
316  void repeatClick(MyGUI::Widget* _widget, MyGUI::ControllerItem* _controller);
317 
322 
323  private:
324  void onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
325  void onDecreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
326  void onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
327  void onIncreaseButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
328  };
329  }
330 }
331 
332 #endif
bool mEnableRepeat
Definition: widgets.hpp:318
void onDecreaseButtonReleased(MyGUI::Widget *_sender, int _left, int _top, MyGUI::MouseButton _id)
Definition: widgets.cpp:611
static SpellEffectList effectListFromESM(const ESM::EffectList *effects)
Definition: widgets.cpp:339
MyGUI::delegates::CMultiDelegate1< MWSkill * > EventHandle_SkillVoid
Definition: widgets.hpp:107
virtual ~MWSpellEffect()
Definition: widgets.cpp:475
Definition: stat.hpp:108
MWEffectList * MWEffectListPtr
Definition: widgets.hpp:247
virtual ~MWSkill()
Definition: widgets.cpp:85
bool mKnown
Definition: widgets.hpp:56
MWEffectList()
Definition: widgets.cpp:274
MWSpell()
Definition: widgets.cpp:206
MWAttribute * MWAttributePtr
Definition: widgets.hpp:170
Definition: widgets.hpp:176
virtual void initialiseOverride()
Definition: widgets.cpp:527
Definition: widgets.hpp:91
MWSkill()
Definition: widgets.cpp:24
int mValue
Definition: widgets.hpp:296
int mArea
Definition: widgets.hpp:68
void updateWidgets()
Definition: widgets.cpp:374
virtual void initialiseOverride()
Definition: widgets.cpp:180
void setAttributeId(int attributeId)
Definition: widgets.cpp:122
void setSkillId(ESM::Skill::SkillEnum skillId)
Definition: widgets.cpp:31
Definition: widgets.hpp:132
int list(Bsa::BSAFile &bsa, Arguments &info)
Definition: bsatool.cpp:183
MWMechanics::AttributeValue AttributeValue
Definition: widgets.hpp:138
SkillValue mValue
Definition: widgets.hpp:126
Definition: widgets.hpp:210
std::string mId
Definition: widgets.hpp:205
bool mNoTarget
Definition: widgets.hpp:53
ESM::Skill::SkillEnum mSkillId
Definition: widgets.hpp:125
EventHandle_AttributeVoid eventClicked
Definition: widgets.hpp:152
virtual ~MWScrollBar()
Definition: widgets.cpp:547
void updateWidgets()
Definition: widgets.cpp:53
MyGUI::ProgressBar * mBarWidget
Definition: widgets.hpp:298
int mRequestedWidth
Definition: widgets.hpp:273
void updateWidgets()
Definition: widgets.cpp:246
void onIncreaseButtonPressed(MyGUI::Widget *_sender, int _left, int _top, MyGUI::MouseButton _id)
Definition: widgets.cpp:616
Definition: effectlist.hpp:17
int getMax() const
Definition: widgets.hpp:287
MyGUI::TextBox * mTextWidget
Definition: widgets.hpp:272
virtual ~MWDynamicStat()
Definition: widgets.cpp:523
int getValue() const
Definition: widgets.hpp:286
bool mIsConstant
Definition: widgets.hpp:54
MyGUI::TextBox * mAttributeValueWidget
Definition: widgets.hpp:168
SpellEffectParams()
Definition: widgets.hpp:38
void updateWidgets()
Definition: widgets.cpp:326
const AttributeValue & getAttributeValue() const
Definition: widgets.hpp:144
int mMagnMax
Definition: widgets.hpp:65
void createEffectWidgets(std::vector< MyGUI::Widget * > &effects, MyGUI::Widget *creator, MyGUI::IntCoord &coord, int flags)
Definition: widgets.cpp:217
void updateWidgets()
Definition: widgets.cpp:139
int mRange
Definition: widgets.hpp:65
const SkillValue & getSkillValue() const
Definition: widgets.hpp:104
float mRepeatStepTime
Definition: widgets.hpp:320
MWMechanics::Stat< float > SkillValue
Definition: widgets.hpp:97
std::vector< SpellEffectParams > SpellEffectList
Definition: widgets.hpp:89
void setRepeat(float trigger, float step)
Definition: widgets.cpp:567
virtual void initialiseOverride()
Definition: widgets.cpp:261
MWDynamicStat()
Definition: widgets.cpp:489
signed char mSkill
Definition: widgets.hpp:62
Definition: widgets.hpp:36
MyGUI::ImageBox * mImageWidget
Definition: widgets.hpp:271
void setTitle(const std::string &text)
Definition: widgets.cpp:517
int getRequestedWidth() const
Definition: widgets.hpp:259
MyGUI::TextBox * mBarTextWidget
Definition: widgets.hpp:299
virtual ~MWAttribute()
Definition: widgets.cpp:176
void setAttributeValue(const AttributeValue &value)
Definition: widgets.cpp:128
int mId
Definition: widgets.hpp:165
void createEffectWidgets(std::vector< MyGUI::Widget * > &effects, MyGUI::Widget *creator, MyGUI::IntCoord &coord, bool center, int flags)
Definition: widgets.cpp:285
ESM::ENAMstruct SpellEffectValue
Definition: widgets.hpp:255
MWScrollBar()
Definition: widgets.cpp:536
ESM::Skill::SkillEnum getSkillId() const
Definition: widgets.hpp:103
MWMechanics::Stat< int > EnchantmentValue
Definition: widgets.hpp:216
MWAttribute()
Definition: widgets.cpp:115
float mRepeatTriggerTime
Definition: widgets.hpp:319
MWSpellEffect()
Definition: widgets.cpp:361
const std::string & getSpellId() const
Definition: widgets.hpp:195
MyGUI::TextBox * mAttributeNameWidget
Definition: widgets.hpp:167
SpellEffectList mEffectList
Definition: widgets.hpp:245
AttributeValue mValue
Definition: widgets.hpp:166
int mDuration
Definition: widgets.hpp:65
virtual void initialiseOverride()
Definition: widgets.cpp:330
MyGUI::TextBox * mTextWidget
Definition: widgets.hpp:297
virtual ~MWSpell()
Definition: widgets.cpp:268
void onIncreaseButtonReleased(MyGUI::Widget *_sender, int _left, int _top, MyGUI::MouseButton _id)
Definition: widgets.cpp:627
void repeatClick(MyGUI::Widget *_widget, MyGUI::ControllerItem *_controller)
Definition: widgets.cpp:573
void onClicked(MyGUI::Widget *_sender)
Definition: widgets.cpp:134
virtual void initialiseOverride()
Definition: widgets.cpp:551
int getAttributeId() const
Definition: widgets.hpp:143
virtual ~MWEffectList()
Definition: widgets.cpp:335
MyGUI::TextBox * mSkillValueWidget
Definition: widgets.hpp:128
Definition: widgets.hpp:277
MyGUI::TextBox * mSpellNameWidget
Definition: widgets.hpp:206
void setSpellEffect(const SpellEffectParams &params)
Definition: widgets.cpp:368
MWSpell * MWSpellPtr
Definition: widgets.hpp:208
MWSpellEffect * MWSpellEffectPtr
Definition: widgets.hpp:275
EventHandle_SkillVoid eventClicked
Definition: widgets.hpp:112
bool mIsIncreasing
Definition: widgets.hpp:321
void setEffectList(const SpellEffectList &list)
Definition: widgets.cpp:279
void setValue(int value, int max)
Definition: widgets.cpp:498
bool operator==(const SpellEffectParams &other) const
Definition: widgets.hpp:70
MyGUI::TextBox * mSkillNameWidget
Definition: widgets.hpp:127
virtual void initialiseOverride()
Definition: widgets.cpp:479
signed char mAttribute
Definition: widgets.hpp:62
SkillEnum
Definition: loadskil.hpp:45
void setSkillValue(const SkillValue &value)
Definition: widgets.cpp:47
void onClicked(MyGUI::Widget *_sender)
Definition: widgets.cpp:80
void setSpellId(const std::string &id)
Definition: widgets.cpp:211
void setSkillNumber(int skillId)
Definition: widgets.cpp:37
short mEffectID
Definition: widgets.hpp:59
void onDecreaseButtonPressed(MyGUI::Widget *_sender, int _left, int _top, MyGUI::MouseButton _id)
Definition: widgets.cpp:600
void fixTexturePath(std::string &path)
MWMechanics::Stat< int > SpellValue
Definition: widgets.hpp:182
EffectList, ENAM subrecord.
Definition: effectlist.hpp:33
SpellEffectParams mEffectParams
Definition: widgets.hpp:270
MyGUI::delegates::CMultiDelegate1< MWAttribute * > EventHandle_AttributeVoid
Definition: widgets.hpp:147
virtual void initialiseOverride()
Definition: widgets.cpp:89
int mMagnMin
Definition: widgets.hpp:65
MWSkill * MWSkillPtr
Definition: widgets.hpp:130
Definition: widgets.hpp:304
EffectFlags
Definition: widgets.hpp:218
int mMax
Definition: widgets.hpp:296
Definition: widgets.hpp:249
MWDynamicStat * MWDynamicStatPtr
Definition: widgets.hpp:301