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
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "ags/shared/gui/gui_inv.h"
24 #include "ags/shared/gui/gui_main.h"
25 #include "ags/engine/ac/draw.h"
26 #include "ags/shared/ac/game_setup_struct.h"
27 #include "ags/engine/ac/game_state.h"
28 #include "ags/engine/ac/character_extras.h"
29 #include "ags/shared/ac/sprite_cache.h"
30 #include "ags/shared/gfx/bitmap.h"
31
32 namespace AGS3 {
33
34
35
36
37
38
39
40
41 namespace AGS {
42 namespace Shared {
43
GetCharacterId() const44 int GUIInvWindow::GetCharacterId() const {
45 if (CharId < 0)
46 return _GP(game).playercharacter;
47
48 return CharId;
49 }
50
Draw(Bitmap * ds)51 void GUIInvWindow::Draw(Bitmap *ds) {
52 const bool enabled = IsGUIEnabled(this);
53 if (!enabled && (_G(gui_disabled_style) == GUIDIS_BLACKOUT))
54 return;
55
56 // backwards compatibility
57 _GP(play).inv_numinline = ColCount;
58 _GP(play).inv_numdisp = RowCount * ColCount;
59 _GP(play).obsolete_inv_numorder = _G(charextra)[_GP(game).playercharacter].invorder_count;
60 // if the user changes top_inv_item, switch into backwards
61 // compatibiltiy mode
62 if (_GP(play).inv_top)
63 _GP(play).inv_backwards_compatibility = 1;
64 if (_GP(play).inv_backwards_compatibility)
65 TopItem = _GP(play).inv_top;
66
67 // draw the items
68 const int leftmost_x = X;
69 int at_x = X;
70 int at_y = Y;
71 int lastItem = TopItem + (ColCount * RowCount);
72 if (lastItem > _G(charextra)[GetCharacterId()].invorder_count)
73 lastItem = _G(charextra)[GetCharacterId()].invorder_count;
74
75 for (int item = TopItem; item < lastItem; ++item) {
76 // draw inv graphic
77 draw_gui_sprite(ds, _GP(game).invinfo[_G(charextra)[GetCharacterId()].invorder[item]].pic, at_x, at_y, true);
78 at_x += data_to_game_coord(ItemWidth);
79
80 // go to next row when appropriate
81 if ((item - TopItem) % ColCount == (ColCount - 1)) {
82 at_x = leftmost_x;
83 at_y += data_to_game_coord(ItemHeight);
84 }
85 }
86
87 if (!enabled &&
88 _G(gui_disabled_style) == GUIDIS_GREYOUT &&
89 _GP(play).inventory_greys_out == 1) {
90 // darken the inventory when disabled
91 GUI::DrawDisabledEffect(ds, RectWH(X, Y, Width, Height));
92 }
93 }
94
95 } // namespace Shared
96 } // namespace AGS
97 } // namespace AGS3
98