File: qd_inventory_cell.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (294 lines) | stat: -rw-r--r-- 7,724 bytes parent folder | download | duplicates (2)
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
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef QDENGINE_QDCORE_QD_INVENTORY_CELL_H
#define QDENGINE_QDCORE_QD_INVENTORY_CELL_H

#include "qdengine/parser/xml_fwd.h"
#include "qdengine/qdcore/qd_sprite.h"

namespace Common {
class WriteStream;
}

namespace QDEngine {

class qdGameObjectAnimated;

//! Описание ячейки инвентори.
class qdInventoryCellType {
public:
	qdInventoryCellType() : _type(0) { }
	explicit qdInventoryCellType(int tp) : _type(tp) { }
	~qdInventoryCellType() {
		_sprite.free();
	}

	int type() const {
		return _type;
	}
	void set_type(int tp) {
		_type = tp;
	}

	void set_sprite_file(const Common::Path fname) {
		_sprite.set_file(fname);
	}
	const Common::Path sprite_file() const {
		return _sprite.file();
	}

	const qdSprite *sprite() const {
		return &_sprite;
	}

	bool load_resources() const;
	void free_resources() const;

	bool load_script(const xml::tag *p);
	bool save_script(Common::WriteStream &fh, int indent = 0) const;

	const Vect2i &size() const {
		return _sprite.size();
	}

private:
	//! Тип ячейки.
	int _type;
	//! Внешний вид ячейки.
	mutable qdSprite _sprite;
};

inline bool operator == (const qdInventoryCellType &f, const qdInventoryCellType &s) {
	return ((f.type() == s.type()) && (f.sprite() == s.sprite()));
}

inline bool operator == (const qdInventoryCellType &f, int type) {
	return f.type() == type;
}

typedef Std::vector<qdInventoryCellType> qdInventoryCellTypeVector;

//! Ячейка инвентори.
class qdInventoryCell {
public:
	qdInventoryCell();
	qdInventoryCell(const qdInventoryCellType &tp);
	qdInventoryCell(const qdInventoryCell &cl);
	~qdInventoryCell() { }

	qdInventoryCell &operator = (const qdInventoryCell &cl);

	int type() const {
		return _type;
	}
	void set_type(int tp) {
		_type = tp;
	}

	const qdSprite *sprite() const {
		return _sprite;
	}
	void set_sprite(const qdSprite *spr) {
		_sprite = spr;
	}

	qdGameObjectAnimated *object() const {
		return _object;
	}
	void set_object(qdGameObjectAnimated *obj);

	bool is_empty() const {
		if (!_object) return true;
		else return false;
	}

	const Vect2i &size() const {
		if (sprite())
			return sprite()->size();

		static Vect2i z = Vect2i(0, 0);
		return z;
	}

	int size_x() const {
		if (sprite()) return sprite()->size_x();
		else return 0;
	}
	int size_y() const {
		if (sprite()) return sprite()->size_y();
		else return 0;
	}

	void redraw(int x, int y, bool inactive_mode = false) const;

	bool load_resources();
	bool free_resources();

	//! Загрузка данных из сэйва.
	bool load_data(Common::SeekableReadStream &fh, int save_version);
	//! Запись данных в сэйв.
	bool save_data(Common::WriteStream &fh) const;

	static void set_shadow(uint32 color, int alpha) {
		_shadow_color = color;
		_shadow_alpha = alpha;
	}

private:
	//! Тип ячейки.
	int _type;

	//! Внешний вид ячейки.
	/**
	Указывает на _sprite из qdInventoryCellType соответствующего типа.
	*/
	const qdSprite *_sprite;

	//! Объект, который лежит в ячейке.
	mutable qdGameObjectAnimated *_object;

	static uint32 _shadow_color;
	static int _shadow_alpha;
};

typedef Std::vector<qdInventoryCell> qdInventoryCellVector;

//! Группа ячеек инвентори.
class qdInventoryCellSet {
public:
	qdInventoryCellSet();
	qdInventoryCellSet(int x, int y, int sx, int sy, int16 addit_sx, int16 addit_sy, const qdInventoryCellType &tp);
	qdInventoryCellSet(const qdInventoryCellSet &set);
	~qdInventoryCellSet();

	qdInventoryCellSet &operator = (const qdInventoryCellSet &set);

	const Vect2s screen_pos() const {
		return _screen_pos + g_engine->screen_offset();
	}
	void set_screen_pos(const Vect2s &pos) {
		_screen_pos = pos;
	}

	grScreenRegion screen_region() const;
	const grScreenRegion &last_screen_region() const {
		return _last_screen_region;
	}

	int cell_index(const qdGameObjectAnimated *obj) const;
	Vect2s cell_position(int cell_idx) const;

	const Vect2s &size() const {
		return _size;
	}
	void set_size(const Vect2s &sz) {
		assert(sz.x && sz.y);
		qdInventoryCell t;
		if (_size.x != 0)//предполагаю, что либо оба равны либо оба неравны 0
			t = _cells.front();
		_size = sz;
		_cells.resize((sz.x + _additional_cells.x) * (sz.y + _additional_cells.y));
		Common::fill(_cells.begin(), _cells.end(), t);
	}

	void set_cell_type(const qdInventoryCellType &tp) {
		Common::fill(_cells.begin(), _cells.end(), tp);
	}

	bool hit(const Vect2s &pos) const;
	void set_mouse_hover_object(qdGameObjectAnimated *obj);

	void pre_redraw() const;
	void redraw(int offs_x = 0, int offs_y = 0, bool inactive_mode = false) const;
	void post_redraw();

	bool put_object(qdGameObjectAnimated *p);
	bool put_object(qdGameObjectAnimated *p, const Vect2s &pos);
	bool remove_object(qdGameObjectAnimated *p);
	qdGameObjectAnimated *get_object(const Vect2s &pos) const;
	bool is_object_in_list(const qdGameObjectAnimated *p) const;

	bool load_script(const xml::tag *p);
	bool save_script(Common::WriteStream &fh, int indent = 0) const;

	//! Загрузка данных из сэйва.
	bool load_data(Common::SeekableReadStream &fh, int save_version);
	//! Запись данных в сэйв.
	bool save_data(Common::WriteStream &fh) const;

	bool init(const qdInventoryCellTypeVector &tp);

	const qdInventoryCellVector &cells() const {
		return _cells;
	}
	int num_cells() const {
		return _cells.size();
	}

	bool load_resources();
	bool free_resources();

	void objects_quant(float dt);

	Vect2s additional_cells() const {
		return _additional_cells;
	}
	void set_additional_cells(Vect2s val) {
		_additional_cells = val;
		// Изменили кол-во доп. ячеек - изменяем и всех кол-во массива ячеек
		set_size(size());
	}

	//! Скроллинг
	void scroll_left();
	void scroll_right();
	void scroll_up();
	void scroll_down();

	void debug_log() const;

private:
	// Имеет ли область полного инвентори сета объекты
	bool has_rect_objects(int left, int top, int right, int bottom) const;

	//! Размер группы.
	/**
	В группе _size.x * _size.y ячеек.
	*/
	Vect2s _size;
	//! Дополнительне ячейки по x и y
	Vect2s _additional_cells;
	//! Смещение по x и y (с него выводятся ячекйки в количестве _size)
	Vect2s _cells_shift;
	//! Ячейки.
	qdInventoryCellVector _cells;
	//! Экранные координаты центра первой ячейки группы.
	Vect2s _screen_pos;

	grScreenRegion _last_screen_region;
};

typedef Std::vector<qdInventoryCellSet> qdInventoryCellSetVector;

} // namespace QDEngine

#endif // QDENGINE_QDCORE_QD_INVENTORY_CELL_H