ScummVM API documentation
qd_inventory_cell.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef QDENGINE_QDCORE_QD_INVENTORY_CELL_H
23#define QDENGINE_QDCORE_QD_INVENTORY_CELL_H
24
25#include "qdengine/parser/xml_fwd.h"
26#include "qdengine/qdcore/qd_sprite.h"
27
28namespace Common {
29class WriteStream;
30}
31
32namespace QDEngine {
33
34class qdGameObjectAnimated;
35
38public:
39 qdInventoryCellType() : _type(0) { }
40 explicit qdInventoryCellType(int tp) : _type(tp) { }
42 _sprite.free();
43 }
44
45 int type() const {
46 return _type;
47 }
48 void set_type(int tp) {
49 _type = tp;
50 }
51
52 void set_sprite_file(const Common::Path &fname) {
53 _sprite.set_file(fname);
54 }
55 const Common::Path sprite_file() const {
56 return _sprite.file();
57 }
58
59 const qdSprite *sprite() const {
60 return &_sprite;
61 }
62
63 bool load_resources() const;
64 void free_resources() const;
65
66 bool load_script(const xml::tag *p);
67 bool save_script(Common::WriteStream &fh, int indent = 0) const;
68
69 const Vect2i &size() const {
70 return _sprite.size();
71 }
72
73private:
75 int _type;
77 mutable qdSprite _sprite;
78};
79
80inline bool operator == (const qdInventoryCellType &f, const qdInventoryCellType &s) {
81 return ((f.type() == s.type()) && (f.sprite() == s.sprite()));
82}
83
84inline bool operator == (const qdInventoryCellType &f, int type) {
85 return f.type() == type;
86}
87
88typedef Std::vector<qdInventoryCellType> qdInventoryCellTypeVector;
89
92public:
97
98 qdInventoryCell &operator = (const qdInventoryCell &cl);
99
100 int type() const {
101 return _type;
102 }
103 void set_type(int tp) {
104 _type = tp;
105 }
106
107 const qdSprite *sprite() const {
108 return _sprite;
109 }
110 void set_sprite(const qdSprite *spr) {
111 _sprite = spr;
112 }
113
114 qdGameObjectAnimated *object() const {
115 return _object;
116 }
117 void set_object(qdGameObjectAnimated *obj);
118
119 bool is_empty() const {
120 if (!_object) return true;
121 else return false;
122 }
123
124 const Vect2i &size() const {
125 if (sprite())
126 return sprite()->size();
127
128 static Vect2i z = Vect2i(0, 0);
129 return z;
130 }
131
132 int size_x() const {
133 if (sprite()) return sprite()->size_x();
134 else return 0;
135 }
136 int size_y() const {
137 if (sprite()) return sprite()->size_y();
138 else return 0;
139 }
140
141 void redraw(int x, int y, bool inactive_mode = false) const;
142
143 bool load_resources();
144 bool free_resources();
145
147 bool load_data(Common::SeekableReadStream &fh, int save_version);
150
151 static void set_shadow(uint32 color, int alpha) {
152 _shadow_color = color;
153 _shadow_alpha = alpha;
154 }
155
156private:
158 int _type;
159
161
164 const qdSprite *_sprite;
165
167 mutable qdGameObjectAnimated *_object;
168
169 static uint32 _shadow_color;
170 static int _shadow_alpha;
171};
172
173typedef Std::vector<qdInventoryCell> qdInventoryCellVector;
174
177public:
179 qdInventoryCellSet(int x, int y, int sx, int sy, int16 addit_sx, int16 addit_sy, const qdInventoryCellType &tp);
182
183 qdInventoryCellSet &operator = (const qdInventoryCellSet &set);
184
185 const Vect2s screen_pos() const {
186 return _screen_pos + g_engine->screen_offset();
187 }
188 void set_screen_pos(const Vect2s &pos) {
189 _screen_pos = pos;
190 }
191
192 grScreenRegion screen_region() const;
193 const grScreenRegion &last_screen_region() const {
194 return _last_screen_region;
195 }
196
197 int cell_index(const qdGameObjectAnimated *obj) const;
198 Vect2s cell_position(int cell_idx) const;
199
200 const Vect2s &size() const {
201 return _size;
202 }
203 void set_size(const Vect2s &sz) {
204 assert(sz.x && sz.y);
206 if (_size.x != 0)//предполагаю, что либо оба равны либо оба неравны 0
207 t = _cells.front();
208 _size = sz;
209 _cells.resize((sz.x + _additional_cells.x) * (sz.y + _additional_cells.y));
210 Common::fill(_cells.begin(), _cells.end(), t);
211 }
212
213 void set_cell_type(const qdInventoryCellType &tp) {
214 Common::fill(_cells.begin(), _cells.end(), tp);
215 }
216
217 bool hit(const Vect2s &pos) const;
218 void set_mouse_hover_object(qdGameObjectAnimated *obj);
219
220 void pre_redraw() const;
221 void redraw(int offs_x = 0, int offs_y = 0, bool inactive_mode = false) const;
222 void post_redraw();
223
224 bool put_object(qdGameObjectAnimated *p);
225 bool put_object(qdGameObjectAnimated *p, const Vect2s &pos);
226 bool remove_object(qdGameObjectAnimated *p);
227 qdGameObjectAnimated *get_object(const Vect2s &pos) const;
228 bool is_object_in_list(const qdGameObjectAnimated *p) const;
229
230 bool load_script(const xml::tag *p);
231 bool save_script(Common::WriteStream &fh, int indent = 0) const;
232
234 bool load_data(Common::SeekableReadStream &fh, int save_version);
237
238 bool init(const qdInventoryCellTypeVector &tp);
239
240 const qdInventoryCellVector &cells() const {
241 return _cells;
242 }
243 int num_cells() const {
244 return _cells.size();
245 }
246
247 bool load_resources();
248 bool free_resources();
249
250 void objects_quant(float dt);
251
252 Vect2s additional_cells() const {
253 return _additional_cells;
254 }
255 void set_additional_cells(Vect2s val) {
256 _additional_cells = val;
257 // Изменили кол-во доп. ячеек - изменяем и всех кол-во массива ячеек
258 set_size(size());
259 }
260
263 void scroll_right();
264 void scroll_up();
265 void scroll_down();
266
267 void debug_log() const;
268
269private:
270 // Имеет ли область полного инвентори сета объекты
271 bool has_rect_objects(int left, int top, int right, int bottom) const;
272
274
277 Vect2s _size;
279 Vect2s _additional_cells;
281 Vect2s _cells_shift;
285 Vect2s _screen_pos;
286
287 grScreenRegion _last_screen_region;
288};
289
291
292} // namespace QDEngine
293
294#endif // QDENGINE_QDCORE_QD_INVENTORY_CELL_H
iterator end()
Definition: array.h:380
T & front()
Definition: array.h:218
size_type size() const
Definition: array.h:316
void resize(size_type newSize)
Definition: array.h:412
iterator begin()
Definition: array.h:375
Definition: path.h:52
Definition: stream.h:745
Definition: stream.h:77
Definition: xmath.h:268
Definition: xmath.h:419
Прямоугольная область на экране.
Definition: gr_screen_region.h:31
Dynamic object.
Definition: qd_game_object_animated.h:37
Ячейка инвентори.
Definition: qd_inventory_cell.h:91
bool load_data(Common::SeekableReadStream &fh, int save_version)
Загрузка данных из сэйва.
bool save_data(Common::WriteStream &fh) const
Запись данных в сэйв.
Группа ячеек инвентори.
Definition: qd_inventory_cell.h:176
void scroll_left()
Скроллинг
bool load_data(Common::SeekableReadStream &fh, int save_version)
Загрузка данных из сэйва.
bool save_data(Common::WriteStream &fh) const
Запись данных в сэйв.
Описание ячейки инвентори.
Definition: qd_inventory_cell.h:37
Спрайт.
Definition: qd_sprite.h:39
XML тег.
Definition: xml_tag.h:33
signed char * fill(signed char *first, signed char *last, Value val)
Definition: algorithm.h:168
Definition: algorithm.h:29
Базовый класс для игровых ресурсов.
Definition: console.h:28