ScummVM API documentation
inventorypopup.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 NANCY_UI_INVENTORYPOPUP_H
23 #define NANCY_UI_INVENTORYPOPUP_H
24 
25 #include "engines/nancy/renderobject.h"
26 
27 namespace Nancy {
28 
29 struct NancyInput;
30 struct INV;
31 struct UIIV;
32 
33 namespace State {
34 class Scene;
35 }
36 
37 namespace UI {
38 
39 // Nancy 10+ inventory popup (replaces the always-visible InventoryBox of
40 // pre-Nancy-10 games). Driven by the UIIV chunk (popup graphics + slot
41 // rects + filter buttons) and the INV chunk (per-item descriptions/icons).
42 class InventoryPopup : public RenderObject {
43 public:
45  ~InventoryPopup() override = default;
46 
47  void init() override;
48  void handleInput(NancyInput &input);
49 
50  bool isOpen() const { return _isVisible; }
51  void open();
52  void close();
53 
54  // The taskbar's inventory button toggles the popup; convenience helper.
55  void toggle() { if (_isVisible) close(); else open(); }
56 
57  // Re-render the slot grid. Called by Scene whenever the inventory
58  // contents change while the popup is open.
59  void refreshGrid();
60 
61  enum FilterType {
62  kFilterAll = 0,
63  kFilterViewable = 1,
64  kFilterPortable = 2,
65  };
66 
67  enum WidgetState {
68  kStatePressed = 0,
69  kStateHover = 1,
70  kStateIdle = 2,
71  kStateDisabled = 3
72  };
73 
74 private:
75  static const uint kSlotsPerPage = 16;
76  static const uint kNumFilters = 3;
77 
78  void drawBackground();
79  void drawSlot(uint slotIndex, int16 itemId);
80  void drawFilterTabs();
81  void drawFilterTab(uint index, bool drawHover = false);
82  void drawFilterCaption();
83  void drawCloseButton(WidgetState state);
84  void drawScrollbar(WidgetState state);
85  void rebuildVisibleList();
86  void setActiveFilterIndex(uint index);
87 
88  // Apply the current scrollbar position to the page index, clamping
89  // to the number of pages required by the active filter.
90  void updatePageFromScroll();
91 
92  // Returns the on-popup-surface bounding rect of the slider thumb at
93  // the current scroll position (in popup-local coords).
94  Common::Rect computeSliderRect() const;
95 
96  const UIIV *_uiivData = nullptr;
97  const INV *_invData = nullptr;
98 
99  Graphics::ManagedSurface _overlayImage; // popup background image
100  Graphics::ManagedSurface _itemIcons; // per-item icon sheet
101 
102  bool _closeButtonHovered = false;
103 
104  uint _activeFilterIndex = 0;
105 
106  // Page index within the active filter (0-based).
107  uint _currentPage = 0;
108 
109  // Items the player owns that match the active filter, in inventory
110  // order. The on-screen grid is a 16-item window into this array.
111  Common::Array<int16> _visibleItems;
112 
113  // Item ID currently shown in each of the 16 slots (-1 if empty).
114  int16 _slotItemIDs[kSlotsPerPage];
115 
116  // Slider state. Driven by header.slider.
117  float _scrollPos = 0.0f; // [0, 1]: 0 = top page, 1 = bottom page
118  bool _scrollbarDragging = false;
119  bool _scrollbarHovered = false;
120  int _scrollbarGrabOffset = 0; // mouse-y minus thumb-top at click time
121 
122  bool _filterHovered = false;
123 };
124 
125 } // End of namespace UI
126 } // End of namespace Nancy
127 
128 #endif // NANCY_UI_INVENTORYPOPUP_H
Definition: managed_surface.h:51
Definition: inventorypopup.h:42
Definition: rect.h:524
Definition: input.h:41
Definition: soundequalizerpuzzle.h:27
Definition: renderobject.h:36
Definition: enginedata.h:113
Definition: enginedata.h:704
Definition: actionmanager.h:32