File: editor.h

package info (click to toggle)
btanks 0.9.8083-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 43,616 kB
  • sloc: cpp: 46,425; ansic: 12,005; xml: 4,262; python: 313; sh: 13; makefile: 13
file content (143 lines) | stat: -rw-r--r-- 4,202 bytes parent folder | download | duplicates (5)
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
#ifndef BTANKS_EDITOR_H__
#define BTANKS_EDITOR_H__

/* Battle Tanks Game
 * Copyright (C) 2006-2009 Battle Tanks team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

/* 
 * Additional rights can be granted beyond the GNU General Public License 
 * on the terms provided in the Exception. If you modify this file, 
 * you may extend this exception to your version of the file, 
 * but you are not obligated to do so. If you do not wish to provide this
 * exception without modification, you must delete this exception statement
 * from your version and license this file solely under the GPL without exception. 
*/

#include "sl08/sl08.h"
#include "sdlx/sdlx.h"
#include "sdlx/rect.h"
#include "menu/container.h"
#include "alarm.h"
#include <string>
#include <deque>
#include "command.h"

class OpenMapDialog;
class TilesetDialog;
class Hud;
class LayerListDialog;
class BaseBrush; 
class AddObjectDialog;
class ObjectPropertiesDialog;
class ScrollList;
class MorphDialog;
class ResizeDialog;

namespace sdlx {
	class Font;
	class Surface;
}
class Object;

class Editor : public Container {
public: 
	Editor();
	void init(int argc, char **argv);
	void run();
	void deinit();	
	
	void loadMap(const std::string &map);

	void addCommand(Command &cmd);
	Command &currentCommand();
	void undo();
	void redo();
	
	void moveObjectHack(Object *object, const v2<int>& screen_pos);
	
private: 
	virtual bool onKey(const SDL_keysym sym); //from ::Control
	virtual bool onMouse(const int button, const bool pressed, const int x, const int y);
	virtual bool onMouseMotion(const int state, const int x, const int y, const int xrel, const int yrel);

	void render(sdlx::Surface &surface, const float dt);

	//slots:	
	sl08::slot1<bool, float, Editor> on_tick_slot;
	bool onTick(float dt);

	sl08::slot2<bool, const SDL_keysym, const bool, Editor> on_key_slot;
	bool onKeySignal(const SDL_keysym sym, const bool pressed);
	
	sl08::slot4<bool, const int, const bool, const int, const int, Editor> on_mouse_slot;
	bool onMouseSignal(const int button, const bool pressed, const int x, const int y);
	
	sl08::slot5<bool, const int, const int, const int, const int, const int, Editor> on_mouse_motion_slot;
	bool onMouseMotionSignal(const int state, const int x, const int y, const int xrel, const int yrel);
	
	sl08::slot1<void, const SDL_Event &, Editor> on_event_slot;
	void onEvent(const SDL_Event &event);
	
	void displayStatusMessage(const Object *o);
	void updateLayers();

	OpenMapDialog *_map_picker;
	Hud *_hud;
	TilesetDialog *_tileset_dialog;
	LayerListDialog * _layers_dialog;
	AddObjectDialog * _add_object;
	ResizeDialog *_resize_map;

	std::deque<std::pair<std::string, std::string> > _morph_boxes;
	MorphDialog *_morph_dialog;
	
	sdlx::Rect map_pos;
	v2<float> map_dir;
	v2<int> _tile_size;
	std::string _map_base, _map_file;

	int _loading_bar_total, _loading_bar_now;

	//slots: 
	sl08::slot1<void, const int, Editor> reset_slot;
	void resetLoadingBar(const int total);
	sl08::slot2<void, const int, const char *, Editor> notify_slot;
	void notifyLoadingBar(const int progress, const char *what);
	
	int _current_layer_z;
	BaseBrush *_brush;
	v2<int> _last_tile_painted;
	
	std::string _layer_name;
	Alarm _layer_name_invisible, _layer_invisible;
	const sdlx::Font *_small_font;

	std::deque<Command> undo_queue, redo_queue;

	bool _render_objects;
	const Object *_highlight_object;
	bool _dragging, _selecting;
	v2<int> _selection1, _selection2;

	v2<int> mouse_pos; 
	
	ObjectPropertiesDialog *_object_properties;
};

#endif