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/commontypes.h"
26 #include "engines/nancy/renderobject.h"
27 
28 namespace Nancy {
29 
30 struct NancyInput;
31 struct INV;
32 struct UIIV;
33 
34 namespace State {
35 class Scene;
36 }
37 
38 namespace UI {
39 
40 // Nancy 10+ inventory popup (replaces the always-visible InventoryBox of
41 // pre-Nancy-10 games). Driven by the UIIV chunk (popup graphics + slot
42 // rects + filter buttons) and the INV chunk (per-item descriptions/icons).
43 class InventoryPopup : public RenderObject {
44 public:
46  ~InventoryPopup() override = default;
47 
48  void init() override;
49  void handleInput(NancyInput &input);
50 
51  bool isOpen() const { return _isVisible; }
52  void open();
53  void close();
54 
55  // The taskbar's inventory button toggles the popup; convenience helper.
56  void toggle() { if (_isVisible) close(); else open(); }
57 
58  // Re-render the slot grid. Called by Scene whenever the inventory
59  // contents change while the popup is open.
60  void refreshGrid();
61 
62  enum FilterType {
63  kFilterAll = 0,
64  kFilterViewable = 1,
65  kFilterPortable = 2,
66  };
67 
68  enum WidgetState {
69  kStatePressed = 0,
70  kStateHover = 1,
71  kStateIdle = 2,
72  kStateDisabled = 3
73  };
74 
75 private:
76  static const uint kSlotsPerPage = 16;
77  static const uint kNumFilters = 3;
78 
79  void drawBackground();
80  void drawSlot(uint slotIndex, int16 itemId, bool highlighted = false);
81  void drawFilterTabs();
82  void drawFilterTab(uint index, bool drawHover = false);
83  void drawFilterCaption();
84  void drawCloseButton(bool hovered);
85  void drawScrollbar(UIButtonState state);
86  void rebuildVisibleList();
87 
88  // Reconcile the shared, save-persisted inventory order list with the items
89  // the player actually owns: drop stale entries and append any owned items
90  // missing from it (in item-ID order). Fixes up saves made before ordering
91  // was tracked in one pass, instead of one item at a time. Returns true if
92  // the order list was changed.
93  bool syncOrderWithInventory();
94 
95  bool itemMatchesFilter(int16 itemID) const;
96  void setActiveFilterIndex(uint index);
97 
98  // Play a popup button's click sound (the filter tabs and the close X),
99  // falling back to the shared button-click slot in the popup header when the
100  // button carries no sound of its own.
101  void playButtonClickSound(const UIButtonRecord &button);
102 
103  // Apply the current scrollbar position to the page index, clamping
104  // to the number of pages required by the active filter.
105  void updatePageFromScroll();
106 
107  // Returns the on-popup-surface bounding rect of the slider thumb at
108  // the current scroll position (in popup-local coords).
109  Common::Rect computeSliderRect() const;
110 
111  const UIIV *_uiivData = nullptr;
112  const INV *_invData = nullptr;
113 
114  Graphics::ManagedSurface _overlayImage; // popup background image
115  Graphics::ManagedSurface _itemIcons; // per-item icon sheet
116 
117  bool _closeButtonHovered = false;
118 
119  uint _activeFilterIndex = 0;
120 
121  // Page index within the active filter (0-based).
122  uint _currentPage = 0;
123 
124  // Items the player owns that match the active filter, in inventory
125  // order. The on-screen grid is a 16-item window into this array.
126  Common::Array<int16> _visibleItems;
127 
128  // Item ID currently shown in each of the 16 slots (-1 if empty).
129  int16 _slotItemIDs[kSlotsPerPage];
130 
131  // Slot the cursor is currently hovering over (-1 if none). The hovered
132  // occupied slot is drawn with the item's highlighted (blue-glow) sprite.
133  int _hoveredSlot = -1;
134 
135  // Slider state. Driven by header.slider.
136  float _scrollPos = 0.0f; // [0, 1]: 0 = top page, 1 = bottom page
137  bool _scrollbarDragging = false;
138  bool _scrollbarHovered = false;
139  int _scrollbarGrabOffset = 0; // mouse-y minus thumb-top at click time
140 
141  bool _filterHovered = false;
142 };
143 
144 } // End of namespace UI
145 } // End of namespace Nancy
146 
147 #endif // NANCY_UI_INVENTORYPOPUP_H
Definition: managed_surface.h:51
Definition: inventorypopup.h:43
Definition: rect.h:536
Definition: input.h:41
Definition: soundequalizerpuzzle.h:27
Definition: commontypes.h:400
Definition: renderobject.h:36
Definition: enginedata.h:114
Definition: enginedata.h:769
Definition: actionmanager.h:32