Dragonfly 4.19
A text-based game engine
ViewObject.h
1///
2/// The view object
3///
4
5#ifndef __VIEW_OBJECT_H__
6#define __VIEW_OBJECT_H__
7
8// System includes.
9#include <string>
10
11// Engine includes.
12#include "Color.h"
13#include "Event.h"
14#include "Object.h"
15
16namespace df {
17
18/// Count of number of view object modified attribute categories.
19const int VATTR_COUNT = 6;
20
21/// Categories of view object attributes that indicate modification.
23 VIEW_STRING,
24 VALUE,
25 BORDER,
26 COLOR,
27 LOCATION,
28 DRAW_VALUE,
29};
30
31/// General location of ViewObject on screen.
33 UNDEFINED=-1,
34 TOP_LEFT,
35 TOP_CENTER,
36 TOP_RIGHT,
37 CENTER_LEFT,
38 CENTER_CENTER,
39 CENTER_RIGHT,
40 BOTTOM_LEFT,
41 BOTTOM_CENTER,
42 BOTTOM_RIGHT,
43};
44
45class ViewObject : public Object {
46
47 private:
48 std::string m_view_string; ///< Label for value (e.g., "Points").
49 int m_value; ///< Value displayed (e.g., points).
50 bool m_draw_value; ///< True if should draw value.
51 bool m_border; ///< True if border around display.
52 Color m_color; ///< Color for text (and border).
53 ViewObjectLocation m_location; ///< Location of ViewObject.
54 bool m_vmodified[VATTR_COUNT]; ///< Mod. attrib. since serialize().
55
56 public:
57 /// Construct ViewObject.
58 /// Object settings: SPECTRAL, max altitude.
59 /// ViewObject defaults: border, top_center, default color, draw_value.
61
62 /// Draw view string (and value).
63 /// Return 0 if ok, negative if not.
64 virtual int draw() override;
65
66 /// Handle "view" event if tag matches view_string (others ignored).
67 /// Return 0 if ignored, else 1.
68 virtual int eventHandler(const Event *p_e) override;
69
70 /// Set general location of ViewObject on screen.
71 void setLocation(ViewObjectLocation new_location);
72
73 /// Get general location of ViewObject on screen.
75
76 /// Set true to draw value with display string.
77 void setDrawValue(bool new_draw_value = true);
78
79 /// Get draw value (true if draw value with display string).
80 bool getDrawValue() const;
81
82 /// Set view value.
83 void setValue(int new_value);
84
85 /// Get view value.
86 int getValue() const;
87
88 /// Set view border (true = display border).
89 void setBorder(bool new_border);
90
91 /// Get view border (true = display border).
92 bool getBorder() const;
93
94 /// Set view color.
95 void setColor(Color new_color);
96
97 /// Get view color.
98 Color getColor() const;
99
100 /// Set view display string.
101 void setViewString(std::string new_view_string);
102
103 /// Get view display string.
104 std::string getViewString() const;
105
106 /// Set position of ViewObject, with setting "location" to UNDEFINED.
107 virtual int setPosition(Vector new_pos) override;
108
109 /// Serialize ViewObject attributes to single string.
110 /// Can specify attribute to serialize (default "" means all modified).
111 /// separated by commas.
112 /// If attr is "ALL", serialize all attributes (modified or not).
113 /// Clear m_vmodified[] array for attributes serialized.
114 virtual std::string serialize(std::string attr="") override;
115
116 /// Deserialize string to become attributes.
117 /// Return 0 if no errors, else -1.
118 virtual int deserialize(std::string s) override;
119
120 /// Return true if attribute modified since last serialize.
121 virtual bool isModified(enum ViewObjectAttribute attribute) const;
122
123 /// Return true if any attribute modified since last serialize.
124 virtual bool isModified() const override;
125};
126
127} // end of namespace df
128#endif // __VIEW_OBJECT_H__
Definition: Event.h:15
Definition: Object.h:59
Definition: Vector.h:12
Definition: ViewObject.h:45
virtual int draw() override
Draw view string (and value).
virtual int setPosition(Vector new_pos) override
Set position of ViewObject, with setting "location" to UNDEFINED.
virtual int eventHandler(const Event *p_e) override
Handle "view" event if tag matches view_string (others ignored).
bool m_draw_value
True if should draw value.
Definition: ViewObject.h:50
bool getDrawValue() const
Get draw value (true if draw value with display string).
void setValue(int new_value)
Set view value.
int getValue() const
Get view value.
std::string getViewString() const
Get view display string.
ViewObject()
Construct ViewObject.
void setViewString(std::string new_view_string)
Set view display string.
void setBorder(bool new_border)
Set view border (true = display border).
std::string m_view_string
Label for value (e.g., "Points").
Definition: ViewObject.h:48
bool m_vmodified[VATTR_COUNT]
Mod. attrib. since serialize().
Definition: ViewObject.h:54
int m_value
Value displayed (e.g., points).
Definition: ViewObject.h:49
virtual std::string serialize(std::string attr="") override
Serialize ViewObject attributes to single string.
bool getBorder() const
Get view border (true = display border).
bool m_border
True if border around display.
Definition: ViewObject.h:51
void setColor(Color new_color)
Set view color.
void setLocation(ViewObjectLocation new_location)
Set general location of ViewObject on screen.
virtual bool isModified(enum ViewObjectAttribute attribute) const
Return true if attribute modified since last serialize.
ViewObjectLocation m_location
Location of ViewObject.
Definition: ViewObject.h:53
Color getColor() const
Get view color.
virtual bool isModified() const override
Return true if any attribute modified since last serialize.
virtual int deserialize(std::string s) override
Deserialize string to become attributes.
ViewObjectLocation getLocation() const
Get general location of ViewObject on screen.
Color m_color
Color for text (and border).
Definition: ViewObject.h:52
void setDrawValue(bool new_draw_value=true)
Set true to draw value with display string.
An animation for a sprite.
Definition: Animation.h:15
ViewObjectAttribute
Categories of view object attributes that indicate modification.
Definition: ViewObject.h:22
const int VATTR_COUNT
Count of number of view object modified attribute categories.
Definition: ViewObject.h:19
Color
Colors Dragonfly recognizes.
Definition: Color.h:11
ViewObjectLocation
General location of ViewObject on screen.
Definition: ViewObject.h:32