1//////////////////////////////////////////////////////////////////////
2// This file is part of Remere's Map Editor
3//////////////////////////////////////////////////////////////////////
4// Remere's Map Editor is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Remere's Map Editor is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//////////////////////////////////////////////////////////////////////
17
18#ifndef RME_MAP_WINDOWS_H_
19#define RME_MAP_WINDOWS_H_
20
21#include "main.h"
22
23#include "dcbutton.h"
24#include "positionctrl.h"
25
26class GameSprite;
27class MapTab;
28
29/**
30 * A toggle button with an item on it.
31 */
32class ItemToggleButton : public DCButton {
33public:
34 ItemToggleButton(wxWindow* parent, RenderSize size, int lookid, wxWindowID id = wxID_ANY) :
35 DCButton(parent, id, wxDefaultPosition, DC_BTN_TOGGLE, size, lookid) { }
36 virtual ~ItemToggleButton() { }
37};
38
39/**
40 * A button with an item on it.
41 */
42class ItemButton : public DCButton {
43public:
44 ItemButton(wxWindow* parent, RenderSize size, uint16_t lookid, wxWindowID id = wxID_ANY) :
45 DCButton(parent, id, wxDefaultPosition, DC_BTN_NORMAL, size, lookid) { }
46 virtual ~ItemButton() { }
47};
48
49/**
50 * The map properties window
51 * Change map size, protocol etc.
52 */
53class MapPropertiesWindow : public wxDialog {
54public:
55 MapPropertiesWindow(wxWindow* parent, MapTab* tab, Editor& editor);
56 virtual ~MapPropertiesWindow();
57
58 void OnChangeVersion(wxCommandEvent&);
59 void OnClientVersionChange(wxCommandEvent&);
60 void OnClickOK(wxCommandEvent&);
61 void OnClickCancel(wxCommandEvent&);
62
63protected:
64 void UpdateProtocolList();
65
66 MapTab* view;
67 Editor& editor;
68 wxSpinCtrl* height_spin;
69 wxSpinCtrl* width_spin;
70 wxChoice* version_choice;
71 wxChoice* protocol_choice;
72 wxTextCtrl* description_ctrl;
73 wxTextCtrl* house_filename_ctrl;
74 wxTextCtrl* spawn_filename_ctrl;
75 wxCheckBox* auto_update_checkbox;
76
77 DECLARE_EVENT_TABLE();
78};
79
80/**
81 * The import map dialog
82 * Allows selection of file path, offset and some weird options.
83 */
84class ImportMapWindow : public wxDialog {
85public:
86 ImportMapWindow(wxWindow* parent, Editor& editor);
87 virtual ~ImportMapWindow();
88
89 void OnClickBrowse(wxCommandEvent&);
90 void OnClickOK(wxCommandEvent&);
91 void OnClickCancel(wxCommandEvent&);
92
93protected:
94 Editor& editor;
95
96 wxTextCtrl* file_text_field;
97 wxSpinCtrl* x_offset_ctrl;
98 wxSpinCtrl* y_offset_ctrl;
99
100 wxChoice* house_options;
101 wxChoice* spawn_options;
102
103 DECLARE_EVENT_TABLE();
104};
105
106/**
107 * The export minimap dialog, select output path and what floors to export.
108 */
109class ExportMiniMapWindow : public wxDialog {
110public:
111 ExportMiniMapWindow(wxWindow* parent, Editor& editor);
112 virtual ~ExportMiniMapWindow();
113
114 void OnClickBrowse(wxCommandEvent&);
115 void OnDirectoryChanged(wxKeyEvent&);
116 void OnFileNameChanged(wxKeyEvent&);
117 void OnClickOK(wxCommandEvent&);
118 void OnClickCancel(wxCommandEvent&);
119 void OnExportTypeChange(wxCommandEvent&);
120
121protected:
122 void CheckValues();
123
124 Editor& editor;
125
126 wxStaticText* error_field;
127 wxTextCtrl* directory_text_field;
128 wxTextCtrl* file_name_text_field;
129 wxChoice* floor_options;
130 wxSpinCtrl* floor_number;
131 wxButton* ok_button;
132
133 DECLARE_EVENT_TABLE();
134};
135
136/**
137 * The export tilesets dialog, select output path.
138 */
139class ExportTilesetsWindow : public wxDialog {
140public:
141 ExportTilesetsWindow(wxWindow* parent, Editor& editor);
142 virtual ~ExportTilesetsWindow();
143
144 void OnClickBrowse(wxCommandEvent&);
145 void OnDirectoryChanged(wxKeyEvent&);
146 void OnFileNameChanged(wxKeyEvent&);
147 void OnClickOK(wxCommandEvent&);
148 void OnClickCancel(wxCommandEvent&);
149
150protected:
151 void CheckValues();
152
153 Editor& editor;
154
155 wxStaticText* error_field;
156 wxTextCtrl* directory_text_field;
157 wxTextCtrl* file_name_text_field;
158 wxButton* ok_button;
159
160 DECLARE_EVENT_TABLE();
161};
162
163/**
164 * Text control that will forward up/down pgup / pgdown keys to parent window
165 */
166class KeyForwardingTextCtrl : public wxTextCtrl {
167public:
168 KeyForwardingTextCtrl(wxWindow* parent, wxWindowID id, const wxString& value = "", const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr) :
169 wxTextCtrl(parent, id, value, pos, size, style, validator, name) { }
170 ~KeyForwardingTextCtrl() { }
171
172 void OnKeyDown(wxKeyEvent&);
173
174 DECLARE_EVENT_TABLE()
175};
176
177/**
178 * The list inside a find dialog
179 * Presents a list of brushes
180 */
181class FindDialogListBox : public wxVListBox {
182public:
183 FindDialogListBox(wxWindow* parent, wxWindowID id);
184 ~FindDialogListBox();
185
186 void Clear();
187 void SetNoMatches();
188 void AddBrush(Brush*);
189 Brush* GetSelectedBrush();
190
191 void OnDrawItem(wxDC& dc, const wxRect& rect, size_t index) const;
192 wxCoord OnMeasureItem(size_t index) const;
193
194protected:
195 bool cleared;
196 bool no_matches;
197 std::vector<Brush*> brushlist;
198};
199
200/**
201 * A wxListBox that can be sorted without using style wxLB_SORT.
202 * wxLB_SORT does not work properly on Windows and causes errors on macOS.
203 */
204class SortableListBox : public wxListBox {
205public:
206 SortableListBox(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
207 SortableListBox(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, int n, const wxString choices[], long style);
208 ~SortableListBox();
209 void Sort();
210
211private:
212 void DoSort();
213};
214
215/**
216 * A generic find dialog
217 * ShowModal will return 0 or the item id for item dialogs
218 * 0 or 1 for brush dialogs
219 */
220class FindDialog : public wxDialog {
221public:
222 FindDialog(wxWindow* parent, wxString title);
223 virtual ~FindDialog();
224
225 void OnKeyDown(wxKeyEvent&);
226 void OnTextChange(wxCommandEvent&);
227 void OnTextIdle(wxTimerEvent&);
228 void OnClickList(wxCommandEvent&);
229 void OnClickOK(wxCommandEvent&);
230 void OnClickCancel(wxCommandEvent&);
231
232 void RefreshContents();
233 virtual const Brush* getResult() const {
234 return result_brush;
235 }
236 virtual int getResultID() const {
237 return result_id;
238 }
239
240protected:
241 virtual void RefreshContentsInternal() = 0;
242 virtual void OnClickListInternal(wxCommandEvent&) = 0;
243 virtual void OnClickOKInternal() = 0;
244
245 FindDialogListBox* item_list;
246 KeyForwardingTextCtrl* search_field;
247 wxTimer idle_input_timer;
248 const Brush* result_brush;
249 int result_id;
250
251 DECLARE_EVENT_TABLE()
252};
253
254/**
255 * Find a brush dialog
256 * Find out what brush was returned through GetResult
257 */
258class FindBrushDialog : public FindDialog {
259public:
260 FindBrushDialog(wxWindow* parent, wxString title = "Jump to Brush");
261 virtual ~FindBrushDialog();
262
263 virtual void RefreshContentsInternal();
264 virtual void OnClickListInternal(wxCommandEvent&);
265 virtual void OnClickOKInternal();
266};
267
268/**
269 * Go to position dialog
270 * Allows entry of 3 coordinates and goes there instantly
271 */
272class GotoPositionDialog : public wxDialog {
273public:
274 GotoPositionDialog(wxWindow* parent, Editor& editor);
275 ~GotoPositionDialog() { }
276
277 void OnClickOK(wxCommandEvent&);
278 void OnClickCancel(wxCommandEvent&);
279
280protected:
281 Editor& editor;
282 PositionCtrl* posctrl;
283 wxTextCtrl* position_field;
284
285 DECLARE_EVENT_TABLE();
286};
287
288/**
289 * Base for the item properties dialogs
290 * There are two versions, one for otbmv4 maps and one for the old maps.
291 * They are declared in old_properties_window / properties_window
292 */
293class ObjectPropertiesWindowBase : public wxDialog {
294public:
295 ObjectPropertiesWindowBase(
296 wxWindow* parent, wxString title,
297 const Map* map, const Tile* tile, Item* item,
298 wxPoint position = wxDefaultPosition
299 );
300 ObjectPropertiesWindowBase(
301 wxWindow* parent, wxString title,
302 const Map* map, const Tile* tile, Spawn* spawn,
303 wxPoint position = wxDefaultPosition
304 );
305 ObjectPropertiesWindowBase(
306 wxWindow* parent, wxString title,
307 const Map* map, const Tile* tile, Creature* creature,
308 wxPoint position = wxDefaultPosition
309 );
310 ObjectPropertiesWindowBase(
311 wxWindow* parent, wxString title, wxPoint position = wxDefaultPosition
312 );
313
314 Item* getItemBeingEdited();
315 Creature* getCreatureBeingEdited();
316 Spawn* getSpawnBeingEdited();
317
318protected:
319 const Map* edit_map;
320 const Tile* edit_tile;
321 Item* edit_item;
322 Creature* edit_creature;
323 Spawn* edit_spawn;
324};
325
326/**
327 * The edit towns dialog, ugly as sin.
328 */
329class EditTownsDialog : public wxDialog {
330public:
331 EditTownsDialog(wxWindow* parent, Editor& editor);
332 virtual ~EditTownsDialog();
333
334 void OnListBoxChange(wxCommandEvent&);
335 void OnClickSelectTemplePosition(wxCommandEvent&);
336 void OnClickAdd(wxCommandEvent&);
337 void OnClickRemove(wxCommandEvent&);
338 void OnClickOK(wxCommandEvent&);
339 void OnClickCancel(wxCommandEvent&);
340 void OnPasteTempleText(wxCommandEvent&);
341 void OnClickImport(wxCommandEvent&);
342 void OnClickExport(wxCommandEvent&);
343
344protected:
345 void BuildListBox(bool doselect);
346 void UpdateSelection(int new_selection);
347 void ExportTownsToXML(const wxString& path);
348 void ImportTownsFromXML(const wxString& path);
349 void ExportTownToXML(const wxString& path, Town* town);
350 void ImportTownFromXML(const wxString& path);
351
352 Editor& editor;
353
354 std::vector<Town*> town_list;
355 uint32_t max_town_id;
356
357 wxListBox* town_listbox;
358 wxString town_name, town_id;
359
360 wxTextCtrl* name_field;
361 wxTextCtrl* id_field;
362
363 PositionCtrl* temple_position;
364 wxButton* remove_button;
365 wxButton* select_position_button;
366
367 wxTextCtrl* paste_temple_field;
368
369 DECLARE_EVENT_TABLE();
370};
371
372
373
374#endif
375