forked from aburch/simutrans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simmenu.h
357 lines (305 loc) · 9.18 KB
/
simmenu.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/*
* Copyright (c) 2008 prissi
*
* This file is part of the Simutrans project under the artistic license.
*
* New configurable OOP tool system
*/
#ifndef simmenu_h
#define simmenu_h
#include <string>
#include "besch/sound_besch.h"
#include "dataobj/translator.h"
#include "simtypes.h"
#include "simworld.h"
template<class T> class vector_tpl;
template<class T> class slist_tpl;
class werkzeug_waehler_t;
class spieler_t;
class toolbar_t;
class memory_rw_t;
enum {
// general tools
WKZ_ABFRAGE=0,
WKZ_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TOOL,
WKZ_LINE_TOOL,
WKZ_DEPOT_TOOL,
WKZ_PWDHASH_TOOL,
WKZ_SET_PLAYER_TOOL,
WKZ_TRAFFIC_LIGHT_TOOL,
WKZ_CHANGE_CITY_TOOL,
WKZ_RENAME_TOOL,
WKZ_ADD_MESSAGE_TOOL,
WKZ_TOGGLE_RESERVATION,
WKZ_VIEW_OWNER,
WKZ_HIDE_UNDER_CURSOR,
SIMPLE_TOOL_COUNT,
SIMPLE_TOOL = 0x2000
};
enum {
// dialoge tools
WKZ_HELP = 0,
WKZ_OPTIONEN,
WKZ_MINIMAP,
WKZ_LINEOVERVIEW,
WKZ_MESSAGES,
WKZ_FINANCES,
WKZ_PLAYERS,
WKZ_DISPLAYOPTIONS,
WKZ_SOUND,
WKZ_LANGUAGE,
WKZ_PLAYERCOLOR,
WKZ_JUMP,
WKZ_LOAD,
WKZ_SAVE,
WKZ_LIST_HALT,
WKZ_LIST_CONVOI,
WKZ_LIST_TOWN,
WKZ_LIST_GOODS,
WKZ_LIST_FACTORY,
WKZ_LIST_CURIOSITY,
WKZ_EDIT_FACTORY,
WKZ_EDIT_ATTRACTION,
WKZ_EDIT_HOUSE,
WKZ_EDIT_TREE,
WKZ_ENLARGE_MAP,
WKZ_LIST_LABEL,
WKZ_CLIMATES,
WKZ_SETTINGS,
WKZ_GAMEINFO,
DIALOGE_TOOL_COUNT,
DIALOGE_TOOL = 0x4000
};
enum {
// toolbars
WKZ_MAINMENU = 0,
TOOLBAR_TOOL = 0x8000u
};
class werkzeug_t {
protected:
image_id icon;
/*
* value to trigger this command (see documentation)
* must be initialized in constructor
*/
uint16 id;
const char *default_param;
public:
uint16 get_id() { return id; }
static werkzeug_t *dummy;
// for key loockup
static vector_tpl<werkzeug_t *>char_to_tool;
image_id cursor;
sint16 ok_sound;
sint8 offset;
enum {
WFL_SHIFT = 1,
WFL_CTRL = 2,
WFL_LOCAL = 4
};
uint8 flags; // flags are set before init/work/move is called
bool is_ctrl_pressed() { return flags & WFL_CTRL; }
bool is_shift_pressed() { return flags & WFL_SHIFT; }
bool is_local_execution() { return flags & WFL_LOCAL; }
uint16 command_key;// key to toggle action for this function
static vector_tpl<werkzeug_t *> general_tool;
static vector_tpl<werkzeug_t *> simple_tool;
static vector_tpl<werkzeug_t *> dialog_tool;
static vector_tpl<toolbar_t *> toolbar_tool;
static void update_toolbars(karte_t *welt);
// since only a single toolstr a time can be visible ...
static char toolstr[1024];
static void init_menu();
static void exit_menu();
static void read_menu(const std::string &objfilename);
werkzeug_t() : id(0xFFFFu) { cursor = icon = IMG_LEER; ok_sound = NO_SOUND; offset = Z_PLAN; default_param = NULL; command_key = 0; }
virtual ~werkzeug_t() {}
virtual image_id get_icon(spieler_t *) const { return icon; }
void set_icon(image_id i) { icon = i; }
// returns default_param of this tool for player sp
// if sp==NULL returns default_param that was used to create the tool
virtual const char* get_default_param(spieler_t* = NULL) const { return default_param; }
void set_default_param(const char* str) { default_param = str; }
// transfer additional information in networkgames
virtual void rdwr_custom_data(uint8 /* player_nr */, memory_rw_t*) { }
// this will draw the tool with some indication, if active
virtual bool is_selected(const karte_t *welt) const;
// when true, local execution would do no harm
virtual bool is_init_network_save() const { return false; }
virtual bool is_move_network_save(spieler_t *) const { return false; }
// if is_work_network_save()==false
// and is_work_here_network_save(...)==false
// then work-command is sent over network
virtual bool is_work_network_save() const { return false; }
virtual bool is_work_here_network_save(karte_t *, spieler_t *, koord3d) { return false; }
// will draw a dark frame, if selected
virtual void draw_after( karte_t *w, koord pos ) const;
virtual const char *get_tooltip(const spieler_t *) const { return NULL; }
// returning false on init will automatically invoke previous tool
virtual bool init( karte_t *, spieler_t * ) { return true; }
// returning true on exit will have werkzeug_waehler resets to query-tool on right-click
virtual bool exit( karte_t *, spieler_t * ) { return true; }
/* the return string can have different meanings:
* NULL: ok
* "": unspecified error
* "blabla": errors message, will be handled and translated as appropriate
* check: called before work (and move too?) koord3d already valid coordinate, checks visibility
* work / move should depend on undergroundmode for not network safe tools
*/
virtual const char *check_pos( karte_t *, spieler_t *, koord3d );
virtual const char *work( karte_t *, spieler_t *, koord3d ) { return NULL; }
virtual const char *move( karte_t *, spieler_t *, uint16 /* buttonstate */, koord3d ) { return ""; }
};
/*
* Class for tools that work only on ground (kartenboden)
*/
class kartenboden_werkzeug_t : public werkzeug_t {
public:
char const* check_pos(karte_t*, spieler_t*, koord3d) OVERRIDE;
};
/*
* Class for tools needing two clicks (e.g. building ways).
* Dragging is also possible.
* @author Gerd Wachsmuth
*/
class two_click_werkzeug_t : public werkzeug_t {
public:
two_click_werkzeug_t() : werkzeug_t() {
MEMZERO(start_marker);
}
void rdwr_custom_data(uint8 player_nr, memory_rw_t*) OVERRIDE;
bool init(karte_t*, spieler_t*) OVERRIDE;
bool exit(karte_t* const welt, spieler_t* const sp) OVERRIDE { return init(welt, sp); }
char const* work(karte_t*, spieler_t*, koord3d) OVERRIDE;
char const* move(karte_t*, spieler_t*, uint16 /* buttonstate */, koord3d) OVERRIDE;
bool is_move_network_save(spieler_t*) const OVERRIDE { return true; }
bool is_work_here_network_save(karte_t*, spieler_t *, koord3d) OVERRIDE;
bool is_first_click(spieler_t *sp) const;
void cleanup( spieler_t *, bool delete_start_marker );
private:
/*
* This routine should fill marked_tiles.
*/
virtual void mark_tiles( karte_t *, spieler_t *, const koord3d &start, const koord3d &end ) = 0;
/*
* This routine is called, if the real work should be done.
* If the tool supports single clicks, end is sometimes == koord3d::invalid.
* Returned string is passed by work/move.
*/
virtual const char *do_work( karte_t *, spieler_t *, const koord3d &start, const koord3d &end ) = 0;
/*
* Can the tool start/end on pos? If it is the second click, start is the position of the first click
* 0 = no
* 1 = This tool can work on this tile (with single click)
* 2 = On this tile can dragging start/end
* 3 = Both (1 and 2)
* error will contain an error message (if this is != NULL, return value should be 0).
*/
virtual uint8 is_valid_pos( karte_t *, spieler_t *, const koord3d &pos, const char *&error, const koord3d &start ) = 0;
virtual image_id get_marker_image();
bool first_click_var[MAX_PLAYER_COUNT];
koord3d start[MAX_PLAYER_COUNT];
void start_at( karte_t *, spieler_t *, koord3d &new_start );
zeiger_t *start_marker[MAX_PLAYER_COUNT];
protected:
slist_tpl< zeiger_t* > marked[MAX_PLAYER_COUNT];
};
/* toolbar are a new overclass */
class toolbar_t : public werkzeug_t {
public:
// size of icons
koord iconsize;
private:
const char *helpfile;
werkzeug_waehler_t *wzw;
slist_tpl<werkzeug_t *>tools;
public:
toolbar_t( const char *t, const char *h, koord size ) : werkzeug_t()
{
default_param = t;
helpfile = h;
wzw = NULL;
iconsize = size;
}
char const* get_tooltip(spieler_t const*) const OVERRIDE { return translator::translate(default_param); }
werkzeug_waehler_t *get_werkzeug_waehler() const { return wzw; }
image_id get_icon(spieler_t*) const OVERRIDE;
bool is_selected(karte_t const*) const OVERRIDE;
bool is_init_network_save() const OVERRIDE { return true; }
bool is_work_network_save() const OVERRIDE { return true; }
bool is_move_network_save(spieler_t*) const OVERRIDE { return true; }
// show this toolbar
bool init(karte_t*, spieler_t*) OVERRIDE;
// close this toolbar
bool exit(karte_t*, spieler_t*) OVERRIDE;
void update(karte_t *, spieler_t *); // just refresh content
void append(werkzeug_t *w) { tools.append(w); }
};
// create new instance of tool
werkzeug_t *create_tool(int toolnr);
#endif