-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenview.hpp
executable file
·192 lines (156 loc) · 5.29 KB
/
screenview.hpp
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#ifndef SCREENVIEW_HPP
#define SCREENVIEW_HPP
#include "view.hpp"
#include "event.hpp"
#include "text.hpp"
#include "sound.hpp"
const unsigned int tileSize = 48;
const unsigned int mapViewTileSize = 8;
extern const float selectionBoxRed, selectionBoxGreen, selectionBoxBlue;
class TextDisplay;
class TextInput;
void printChatText(const std::string &str, playerID id);
class ScreenView :public EventListener, public View
{
public:
ScreenView(Model *model, CommandQueue *commandQueue, playerID playerId);
~ScreenView();
void redraw(); // Draw the model, UI, etc on the screen
void timepass(float dt);
void receiveChat(const std::string &str, playerID id);
void playSoundAt(int x, int y, Sound *s);
// User input
bool keyDown(SDL_keysym sym);
bool keyUp(SDL_keysym sym);
bool mouseDown(int x, int y, int button, int mod);
bool mouseUp(int x, int y, int button);
bool mouseMotion(int x, int y, int xrel, int yrel);
int getSelectionSize();
void onSetPlayerId(playerID id);
protected:
bool mouseDownWorld(int x, int y, int button, int mod);
bool mouseDownHud(int x, int y, int button, int mod);
bool mouseDownMinimap(int x, int y, int button, int mod);
bool mouseDownStatus(int x, int y, int button, int mod);
bool mouseDownUnitStatus(int x, int y, int button, int mod);
bool mouseDownScrapyardStatus(int x, int y, int button, int mod);
bool mouseDownSelectedUnits(int x, int y, int button, int mod);
void mouseUpHud(int x, int y, int button);
void mouseUpMinimap(int x, int y, int button);
void mouseDragMinimap(int x, int y);
void mouseScroll(float dt);
CommandCard *getCommandCard();
void pressCommandButton(CommandButton *button);
bool isOnScreen(int x, int y);
// Drawing
void drawHUD();
void drawTooltip(float x, float y, const char *str);
void drawMain();
void drawUnit(Model::Unit *unit);
void drawProjectile(const Model::Projectile *p);
void drawMapView();
void drawMinimap();
void drawMinimapBox();
void drawStatus();
void drawCommandCard();
void drawScrapyardStatus();
void drawSelectedUnits();
void drawUnitStatus();
void drawGeneralStatus();
void drawEffects();
// Debug
void drawNetworkStatus();
// Utility
void mouseToWorld(float *x, float *y);
void cullSelected();
bool pressHotkey(SDLKey key);
void generateMinimap();
// Selections and hotkeys
typedef std::set<unitID> UnitSet;
UnitSet selection;
UnitSet hotkeys[10];
int scrapyardHotkeys[10];
int hotkeysHeld;
int selectedScrapyard;
double nextSpeechTime;
// Update the selection, but restrict to units that match this player's id.
void addToSelection(unitID id);
void addToSelection(UnitSet::iterator unitsBegin, UnitSet::iterator unitsEnd);
void removeFromSelection(unitID id);
void playMove(unitID id);
void playAcknowledge(unitID id);
void playRetreat(unitID id);
void playAttack(unitID id);
void unitSpeech(Sound *sound);
bool isHudArea(int x, int y);
bool isMinimapArea(int x, int y);
bool isStatusArea(int x, int y);
void writeChat(const std::string &str);
void clipCamera();
void centerCameraAt(float x, float y);
bool mapView;
bool showUnitStatus;
// Camera position and movement
float cameraX, cameraY;
float mapCameraX, mapCameraY;
bool arrowHeldLeft, arrowHeldRight, arrowHeldUp, arrowHeldDown;
float mapViewTransition;
// Mouse tracking and dragging
float dragStartX, dragStartY; // In world coordinates
float mouseX, mouseY; // In world coordinates
float screenMouseX, screenMouseY;
bool dragging;
double doubleClickTime;
int dragMode; // -1 remove, 0 normal, 1 add
Command::CommandType pendingCommand, pendingUnitCommand;
// HUD state
int hudButtonPressedX, hudButtonPressedY; // Location of the currently pressed button, or -1 for none
TextDisplay *messages;
TextInput *input;
// Minimap
unsigned minimapTexID;
bool draggingMinimap;
};
const int buttonDoubleClick = -1;
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
class TextDisplay : public EventListener
{
public:
TextDisplay(float x, float y, float width, float height, TextParams textParams, bool alignToBottom, bool startEnabled = true);
void redraw();
bool isOpaque();
void timepass(float dt);
void setTimeout(float timeout);
void println(std::string line);
void clear();
protected:
float timeout;
float x, y, width, height;
bool alignToBottom;
typedef std::deque< std::pair<float,std::string> > LineList; //(expiration,string) pairs
LineList lines;
TextParams textParams;
};
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
class TextInput :public EventListener
{
public:
TextInput(float x, float y, TextParams fontToUse, bool startEnabled = true);
bool keyDown(SDL_keysym sym);
bool keyUp(SDL_keysym sym);
void redraw();
bool isOpaque();
//void setFont(TextParams fontToUse) {fontName= fontToUse;)
std::string getString();
int getResult(); // 0=still inputting; 1=OK; -1=cancelled
void reset();
protected:
float x, y;
int cursorPos;
std::string str;
int result;
TextParams fontName;
};
#endif