Freeciv21
Develop your civilization from humble roots to a global empire
editor.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  part of Freeciv21. Freeciv21 is free software: you can redistribute it
4  and/or modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation, either version 3 of the
6  License, or (at your option) any later version. You should have received
7  a copy of the GNU General Public License along with Freeciv21. If not,
8  see https://www.gnu.org/licenses/.
9 **************************************************************************/
10 
11 #pragma once
12 
13 #include "fc_types.h"
14 
15 /* See client/gui-gtk-3.0/editprop.c for instructions
16  * on how to add more object types. */
24 
26 };
27 
40 
42 };
43 
45  ETM_PAINT = 0,
49 
51 };
52 
53 void editor_init();
54 void editor_clear();
55 void editor_free();
56 
58 
59 bool editor_is_active();
61 void editor_set_tool(enum editor_tool_type emt);
62 const struct tile *editor_get_current_tile();
63 void editor_set_current_tile(const struct tile *ptile);
64 
66  enum editor_tool_mode etm);
69  enum editor_tool_mode etm);
71  enum editor_tool_mode etm);
73 const char *editor_tool_get_mode_name(enum editor_tool_type ett,
74  enum editor_tool_mode etm);
75 
78 void editor_tool_set_size(enum editor_tool_type ett, int size);
79 
82 void editor_tool_set_count(enum editor_tool_type ett, int count);
83 
86 void editor_tool_set_applied_player(enum editor_tool_type, int player_no);
87 
92 void editor_tool_set_value(enum editor_tool_type ett, int value);
93 const char *editor_tool_get_value_name(enum editor_tool_type ett, int value);
94 
95 const char *editor_tool_get_name(enum editor_tool_type ett);
96 QPixmap *editor_tool_get_sprite(enum editor_tool_type ett);
97 const char *editor_tool_get_tooltip(enum editor_tool_type ett);
98 
99 const char *editor_get_mode_tooltip(enum editor_tool_mode etm);
100 QPixmap *editor_get_mode_sprite(enum editor_tool_mode etm);
101 
102 struct edit_buffer;
104 
106  EKM_NONE = 0,
107  EKM_SHIFT = 1 << 0,
108  EKM_ALT = 1 << 1,
109  EKM_CTRL = 1 << 2
110 };
111 
114 
118 };
119 
120 void editor_mouse_button_press(int canvas_x, int canvas_y, int button,
121  int modifiers);
122 void editor_mouse_button_release(int canvas_x, int canvas_y, int button,
123  int modifiers);
124 void editor_mouse_move(int canvas_x, int canvas_y, int modifiers);
125 
126 void editor_apply_tool(const struct tile *ptile, bool part_of_selection);
128 
130 void editor_selection_add(const struct tile *ptile);
131 void editor_selection_remove(const struct tile *ptile);
132 bool editor_tile_is_selected(const struct tile *ptile);
134 const struct tile *editor_get_selection_center();
135 
137 
138 /* These type flags determine what an edit buffer
139  * will copy from its source tiles. Multiple flags
140  * may be set via bitwise OR. */
142  EBT_TERRAIN = 1 << 0,
143  EBT_RESOURCE = 1 << 1,
144  EBT_SPECIAL = 1 << 2,
145  EBT_BASE = 1 << 3,
146  EBT_ROAD = 1 << 4,
147  EBT_UNIT = 1 << 5,
148  EBT_CITY = 1 << 6,
149 
150  // Equal to the bitwise OR of all preceding flags.
151  EBT_ALL = (1 << 7) - 1
152 };
153 
155 void edit_buffer_free(struct edit_buffer *ebuf);
156 void edit_buffer_clear(struct edit_buffer *ebuf);
157 void edit_buffer_set_origin(struct edit_buffer *ebuf,
158  const struct tile *ptile);
159 const struct tile *edit_buffer_get_origin(const struct edit_buffer *ebuf);
160 bool edit_buffer_has_type(const struct edit_buffer *ebuf, int type);
161 void edit_buffer_copy(struct edit_buffer *ebuf, const struct tile *ptile);
162 void edit_buffer_copy_square(struct edit_buffer *ebuf,
163  const struct tile *center, int radius);
164 void edit_buffer_paste(struct edit_buffer *ebuf, const struct tile *dest);
165 int edit_buffer_get_status_string(const struct edit_buffer *ebuf, char *buf,
166  int buflen);
167 
168 // Iterates over all type flags set for the given buffer.
169 #define edit_buffer_type_iterate(ARG_ebuf, NAME_type) \
170  do { \
171  int NAME_type; \
172  if (!(ARG_ebuf)) { \
173  break; \
174  } \
175  for (NAME_type = 1; NAME_type < EBT_ALL; NAME_type <<= 1) { \
176  if (!(edit_buffer_has_type((ARG_ebuf), NAME_type))) { \
177  continue; \
178  }
179 
180 #define edit_buffer_type_iterate_end \
181  } \
182  } \
183  while (false)
int edit_buffer_get_status_string(const struct edit_buffer *ebuf, char *buf, int buflen)
Fill the supplied buffer with a translated string describing the edit buffer's current state.
Definition: editor.cpp:1872
void editor_selection_remove(const struct tile *ptile)
Remove the given tile from the current selection.
Definition: editor.cpp:1098
const struct tile * editor_get_current_tile()
Get the tile that the user's mouse pointer is currently over.
Definition: editor.cpp:1021
bool edit_buffer_has_type(const struct edit_buffer *ebuf, int type)
Returns TRUE if the edit buffer was created with the given type flag.
Definition: editor.cpp:1923
const char * editor_tool_get_mode_name(enum editor_tool_type ett, enum editor_tool_mode etm)
Returns the translated string name for the given mode.
Definition: editor.cpp:1779
const char * editor_get_mode_tooltip(enum editor_tool_mode etm)
Returns a translated tooltip string assumed to be used for the toggle button for this tool mode in th...
Definition: editor.cpp:1817
int editor_tool_get_size(enum editor_tool_type ett)
Returns the current size parameter for the given editor tools.
Definition: editor.cpp:1210
editor_tool_mode
Definition: editor.h:44
@ ETM_PASTE
Definition: editor.h:48
@ NUM_EDITOR_TOOL_MODES
Definition: editor.h:50
@ ETM_ERASE
Definition: editor.h:46
@ ETM_PAINT
Definition: editor.h:45
@ ETM_COPY
Definition: editor.h:47
edit_buffer_types
Definition: editor.h:141
@ EBT_RESOURCE
Definition: editor.h:143
@ EBT_CITY
Definition: editor.h:148
@ EBT_UNIT
Definition: editor.h:147
@ EBT_BASE
Definition: editor.h:145
@ EBT_ALL
Definition: editor.h:151
@ EBT_ROAD
Definition: editor.h:146
@ EBT_TERRAIN
Definition: editor.h:142
@ EBT_SPECIAL
Definition: editor.h:144
void editor_mouse_button_press(int canvas_x, int canvas_y, int button, int modifiers)
Handle a user's mouse button press at the given point on the map canvas.
Definition: editor.cpp:659
void editor_set_current_tile(const struct tile *ptile)
Sets the tile currently assumed to be under the user's mouse pointer.
Definition: editor.cpp:1009
void editor_mouse_move(int canvas_x, int canvas_y, int modifiers)
Handle the mouse moving over the map canvas.
Definition: editor.cpp:860
enum editor_tool_mode editor_tool_get_mode(enum editor_tool_type ett)
Get the mode for the tool.
Definition: editor.cpp:324
bool editor_tool_has_value_erase(enum editor_tool_type ett)
Returns TRUE if erase mode for the given tool erases by sub-value instead of any object corresponding...
Definition: editor.cpp:1368
void editor_tool_set_count(enum editor_tool_type ett, int count)
Sets the 'count' parameter of the tool to the given value.
Definition: editor.cpp:1255
struct edit_buffer * editor_get_copy_buffer()
Returns the copy buffer for the given tool.
Definition: editor.cpp:1768
void editor_tool_toggle_mode(enum editor_tool_type ett, enum editor_tool_mode etm)
Toggle the current tool mode between the given mode and ETM_PAINT (or ETM_COPY for the copy & paste t...
Definition: editor.cpp:1034
void editor_selection_add(const struct tile *ptile)
Add the given tile to the current selection.
Definition: editor.cpp:1087
int editor_tool_get_value(enum editor_tool_type ett)
Get the current tool sub-value.
Definition: editor.cpp:395
void editor_tool_set_applied_player(enum editor_tool_type, int player_no)
Sets the editor tool's applied player number to the given value.
Definition: editor.cpp:1344
void editor_set_tool(enum editor_tool_type emt)
Set the current tool to be used by the editor.
Definition: editor.cpp:260
void editor_tool_cycle_mode(enum editor_tool_type ett)
Set the editor tool mode to the next available mode.
Definition: editor.cpp:1050
void editor_free()
Free the client's editor.
Definition: editor.cpp:247
void editor_ruleset_changed()
Adjust editor for changed ruleset.
Definition: editor.cpp:171
int editor_tool_get_count(enum editor_tool_type ett)
Returns the 'count' parameter for the editor tool.
Definition: editor.cpp:1244
void edit_buffer_copy(struct edit_buffer *ebuf, const struct tile *ptile)
Append a single tile to the copy buffer.
Definition: editor.cpp:1484
void editor_tool_set_size(enum editor_tool_type ett, int size)
Sets the size parameter for the given tool.
Definition: editor.cpp:1221
const char * editor_tool_get_tooltip(enum editor_tool_type ett)
Returns a translated "tooltip" description for the given tool type.
Definition: editor.cpp:1319
bool editor_tool_is_usable(enum editor_tool_type ett)
Returns TRUE if the given tool should be made available to the user via the editor GUI.
Definition: editor.cpp:345
void editor_init()
Initialize the client's editor state information to some suitable default values.
Definition: editor.cpp:184
bool editor_tool_has_applied_player(enum editor_tool_type ett)
Returns TRUE if the given tool makes use of the editor's applied player number.
Definition: editor.cpp:1356
const struct tile * edit_buffer_get_origin(const struct edit_buffer *ebuf)
Return the previously set origin, or nullptr if none.
Definition: editor.cpp:1912
void editor_notify_edit_finished()
Notify the server that a batch of edits has completed.
Definition: editor.cpp:892
bool editor_tool_has_size(enum editor_tool_type ett)
Return TRUE if the given editor tool uses the 'size' parameter.
Definition: editor.cpp:1199
void edit_buffer_clear(struct edit_buffer *ebuf)
Remove all copy data stored in the edit buffer.
Definition: editor.cpp:1449
void editor_clear()
Clear the editor data which is game dependent.
Definition: editor.cpp:236
QPixmap * editor_get_mode_sprite(enum editor_tool_mode etm)
Returns the editor sprite corresponding to the tool mode.
Definition: editor.cpp:1839
void editor_tool_set_value(enum editor_tool_type ett, int value)
Set the value ID for the given tool.
Definition: editor.cpp:383
bool editor_tool_has_value(enum editor_tool_type ett)
Returns TRUE if the given tool type has sub-values (e.g.
Definition: editor.cpp:371
mouse_button_values
Definition: editor.h:112
@ MOUSE_BUTTON_OTHER
Definition: editor.h:113
@ MOUSE_BUTTON_LEFT
Definition: editor.h:115
@ MOUSE_BUTTON_RIGHT
Definition: editor.h:117
@ MOUSE_BUTTON_MIDDLE
Definition: editor.h:116
void editor_mouse_button_release(int canvas_x, int canvas_y, int button, int modifiers)
Handle the release of a mouse button click.
Definition: editor.cpp:792
const char * editor_tool_get_name(enum editor_tool_type ett)
Get the translated name of the given tool type.
Definition: editor.cpp:1151
enum editor_tool_type editor_get_tool()
Get the current tool used by the editor.
Definition: editor.cpp:276
void edit_buffer_copy_square(struct edit_buffer *ebuf, const struct tile *center, int radius)
Copy from a square region of half-width 'radius' centered around 'center' into the buffer.
Definition: editor.cpp:1466
void editor_apply_tool_to_selection()
Apply the current editor tool to all tiles in the current selection.
Definition: editor.cpp:1120
void editor_apply_tool(const struct tile *ptile, bool part_of_selection)
Apply the current editor tool to the given tile.
Definition: editor.cpp:904
bool editor_tile_is_selected(const struct tile *ptile)
Returns TRUE if the given tile is selected.
Definition: editor.cpp:1109
void edit_buffer_set_origin(struct edit_buffer *ebuf, const struct tile *ptile)
Set the "origin" for subsequent copy operations.
Definition: editor.cpp:1900
bool editor_is_active()
Returns TRUE if the client is in edit mode.
Definition: editor.cpp:335
void edit_buffer_paste(struct edit_buffer *ebuf, const struct tile *dest)
Paste the entire contents of the edit buffer using 'dest' as the origin.
Definition: editor.cpp:1734
const struct tile * editor_get_selection_center()
Returns the "center" tile of a group of selected tiles, or nullptr.
Definition: editor.cpp:1936
bool editor_tool_has_mode(enum editor_tool_type ett, enum editor_tool_mode etm)
Return TRUE if the given tool supports the given mode.
Definition: editor.cpp:302
editor_object_type
Definition: editor.h:17
@ OBJTYPE_PLAYER
Definition: editor.h:22
@ OBJTYPE_UNIT
Definition: editor.h:20
@ OBJTYPE_STARTPOS
Definition: editor.h:19
@ OBJTYPE_GAME
Definition: editor.h:23
@ NUM_OBJTYPES
Definition: editor.h:25
@ OBJTYPE_CITY
Definition: editor.h:21
@ OBJTYPE_TILE
Definition: editor.h:18
const char * editor_tool_get_value_name(enum editor_tool_type ett, int value)
Get the translated name of the given tool value.
Definition: editor.cpp:1164
int editor_tool_get_applied_player(enum editor_tool_type ett)
Returns the current applied player number for the editor tool.
Definition: editor.cpp:1333
void editor_selection_clear()
Unselect all selected tiles.
Definition: editor.cpp:1076
struct edit_buffer * edit_buffer_new(int type_flags)
Create a new edit buffer corresponding to all types set in 'type_flags'.
Definition: editor.cpp:1413
editor_keyboard_modifiers
Definition: editor.h:105
@ EKM_CTRL
Definition: editor.h:109
@ EKM_SHIFT
Definition: editor.h:107
@ EKM_ALT
Definition: editor.h:108
@ EKM_NONE
Definition: editor.h:106
struct unit * editor_unit_virtual_create()
Creates a virtual unit (like unit_virtual_create) based on the current editor state.
Definition: editor.cpp:1385
bool editor_tool_has_count(enum editor_tool_type ett)
Return TRUE if it is meaningful for the given tool to use the 'count' parameter.
Definition: editor.cpp:1233
editor_tool_type
Definition: editor.h:28
@ ETT_ROAD
Definition: editor.h:32
@ ETT_TERRAIN_SPECIAL
Definition: editor.h:31
@ ETT_UNIT
Definition: editor.h:34
@ ETT_VISION
Definition: editor.h:36
@ ETT_STARTPOS
Definition: editor.h:38
@ ETT_TERRITORY
Definition: editor.h:37
@ NUM_EDITOR_TOOL_TYPES
Definition: editor.h:41
@ ETT_CITY
Definition: editor.h:35
@ ETT_COPYPASTE
Definition: editor.h:39
@ ETT_TERRAIN_RESOURCE
Definition: editor.h:30
@ ETT_MILITARY_BASE
Definition: editor.h:33
@ ETT_TERRAIN
Definition: editor.h:29
void edit_buffer_free(struct edit_buffer *ebuf)
Free all memory allocated for the edit buffer.
Definition: editor.cpp:1431
QPixmap * editor_tool_get_sprite(enum editor_tool_type ett)
Returns a sprite containing an icon for the given tool type.
Definition: editor.cpp:1267
void editor_tool_set_mode(enum editor_tool_type ett, enum editor_tool_mode etm)
Set the mode for the editor tool.
Definition: editor.cpp:288
size_t size
Definition: specvec.h:64
int type_flags
Definition: editor.cpp:54
Definition: tile.h:42
Definition: unit.h:134