-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.h
178 lines (133 loc) · 4.58 KB
/
dialog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#ifndef dialog_h
#define dialog_h
#include "camera.h"
#include "object.h"
#include <SDL2/SDL.h>
class SDL_Surface;
class Character;
class SDLButton;
class SDLTextButton;
class Craft;
/********************************************************************/
class Dialog : public View {
public:
Dialog(int x, int y, int width, int height, bool modal=false);
virtual ~Dialog();
void setBackgroundColor(const SDL_Color& bgcolor);
const SDL_Color& getBackgroundColor() const { return background_color_; }
virtual void do_render(Camera* camera, double delay_in_ms) override;
void drawTitle(SDLCamera* sdl_camera, const std::string& title);
virtual bool handleEvent(Camera* camera) override;
bool hasFocus(int mouse_x, int mouse_y);
bool killMe() const { return kill_me_; }
virtual Position tilePosition() const = 0;
SDL_Rect getTitleRect(int extension=0) const;
SDL_Rect getKillRect() const;
SDL_Rect getMinimizeRect(int extension=0) const;
SDL_Rect getCenterRect() const;
protected:
bool buttonClicked(SDLButton* button, Position mouse_position);
protected:
int x_;
int y_;
int width_;
int height_;
bool modal_;
SDL_Color background_color_;
SDL_Surface* surface_;
bool kill_me_ = false;
bool grabbing_ = false;
int rel_grab_x_ = 0;
int rel_grab_y_ = 0;
bool minimized_ = false;
};
/********************************************************************/
class ModalDialog : public Dialog {
public:
ModalDialog(const std::string& title, int x, int y, int width, int height);
virtual ~ModalDialog();
virtual Position tilePosition() const override {
return Position{-1,-1};
}
virtual void do_render(Camera* camera, double delay_in_ms) override;
virtual bool handleEvent(Camera* camera) override;
protected:
std::string title_;
};
/********************************************************************/
class RobotDialog : public Dialog {
public:
RobotDialog(Character* robot, int mouse_x = 50, int mouse_y = 50);
virtual ~RobotDialog();
Character* robot() const { return robot_; }
virtual Position tilePosition() const override;
virtual void do_render(Camera* camera, double delay_in_ms) override;
virtual bool handleEvent(Camera* camera) override;
private:
Character* robot_ = nullptr;
SDLTextButton* drop_button_ = nullptr;
std::vector<SDLButton*> buttons_;
};
/********************************************************************/
class ObjectDialog : public Dialog {
public:
virtual ~ObjectDialog();
Object* object() const { return object_; }
virtual Position tilePosition() const override;
virtual void do_render(Camera* camera, double delay_in_ms) override;
static ObjectDialog* createDialog(Object* object, int x, int y);
protected:
ObjectDialog(Object* object, int mouse_x = 50, int mouse_y = 50);
protected:
Object* object_;
};
class MotorDialog : public ObjectDialog {
public:
MotorDialog(Motor* object, int mouse_x = 50, int mouse_y = 50);
virtual ~MotorDialog();
virtual void do_render(Camera* camera, double delay_in_ms) override;
protected:
Motor* motor_;
};
class CommandCenterDialog : public ObjectDialog {
public:
CommandCenterDialog(CommandCenter* object, int mouse_x = 50, int mouse_y = 50);
virtual ~CommandCenterDialog();
virtual void do_render(Camera* camera, double delay_in_ms) override;
protected:
std::vector<SDLButton*> buttons_;
CommandCenter* command_center_;
};
struct CraftOccButton {
Craft* craft;
int occurrence;
SDLButton* button;
};
class CrafterDialog : public ObjectDialog {
public:
CrafterDialog(Object* object, int mouse_x = 50, int mouse_y = 50);
virtual ~CrafterDialog();
virtual void do_render(Camera* camera, double delay_in_ms) override;
virtual bool handleEvent(Camera* camera) override;
protected:
virtual void execute();
void addCraft(int occ=1, bool in_object_too=true);
void selectCraft(Craft* craft);
protected:
std::string craft_button_label_;
SDLTextButton* one_button_ = nullptr;
SDLTextButton* ten_button_ = nullptr;
SDLTextButton* craft_button_ = nullptr;
Craft* selected_craft_ = nullptr;
std::vector< std::pair<Craft*,SDLButton*> > recipe_buttons_;
std::vector< CraftOccButton > craft_buttons_;
};
class SmelterDialog : public CrafterDialog {
public:
SmelterDialog(Object* object, int mouse_x = 50, int mouse_y = 50);
virtual ~SmelterDialog();
protected:
virtual void execute() override;
};
/********************************************************************/
#endif // dialog_h