ScummVM API documentation
notebookpopup.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_NOTEBOOKPOPUP_H
23 #define NANCY_UI_NOTEBOOKPOPUP_H
24 
25 #include "engines/nancy/commontypes.h"
26 #include "engines/nancy/renderobject.h"
27 #include "engines/nancy/misc/hypertext.h"
28 
29 namespace Nancy {
30 
31 struct NancyInput;
32 struct UINB;
33 
34 namespace UI {
35 
36 // Nancy 10+ notebook popup. Driven by the UINB chunk: overlay image + two
37 // tab buttons.
39 public:
40  NotebookPopup();
41  ~NotebookPopup() override = default;
42 
43  void init() override;
44  void registerGraphics() override;
45  void updateGraphics() override;
46  void handleInput(NancyInput &input);
47 
48  void open();
49  void close();
50  void toggle() { if (_isVisible) close(); else open(); }
51 
52  // Nancy 11+ lazily populates the notebook via a hidden "prep scene" run when
53  // it opens. Returns that scene ID (UINB header.linkbackScene), or kNoScene
54  // (9999) for games without one (e.g. Nancy 10), which populate inline.
55  int16 getPrepSceneID() const;
56 
57  // Re-render the active tab's text content into the text rect.
58  // Called automatically on open() and on tab switch; Scene also
59  // invokes it after a ModifyListEntry AR runs while the popup is open.
60  void refreshContent();
61 
62 private:
63  static const uint kNumTabs = 2;
64 
65  enum WidgetState {
66  kStatePressed = 0,
67  kStateHover = 1,
68  kStateIdle = 2,
69  kStateDisabled = 3
70  };
71 
72  void drawBackground();
73  void drawTabs();
74  void drawTab(uint index, bool drawHover = false);
75  // Blit the active tab's title image ("CASE JOURNAL" / "TASKS") into the
76  // header strip above the text area.
77  void drawCaption();
78  // Full content rebuild: lay the active tab's text out into the scratch
79  // surface, then paint the visible slice. Expensive; only call when the text
80  // itself changes (open, tab switch, checkbox toggle, ModifyListEntry).
81  void drawContent();
82  // Lay the active tab's text out into _fullSurface (the expensive step).
83  void layoutText();
84  // Blit the currently-visible vertical slice of _fullSurface into the popup
85  // and rebuild the checkbox hit rects. Cheap; safe to call every scroll step.
86  void paintVisibleText();
87  // Re-composite the whole popup at the current scroll position without
88  // re-laying out the text. Used while dragging the scrollbar.
89  void redrawScroll();
90  // Paint foreground widgets (close button, scrollbar) on top of the
91  // already-drawn background + content layers.
92  void drawForeground();
93  void drawCloseButton(bool hovered);
94  void drawScrollbar(UIButtonState state);
95 
96  // Play a popup button's click sound (close X and the tab buttons), like the
97  // inventory popup. Falls back to the shared button-click slot in the header.
98  void playButtonClickSound(const UIButtonRecord &button);
99 
100  // Returns the on-popup-surface bounding rect of the slider thumb at
101  // the current scroll position (in popup-local coords).
102  Common::Rect computeThumbRect() const;
103 
104  // Convert a chunk-space destRect into popup-local coordinates.
105  Common::Rect toPopupLocal(const Common::Rect &chunkRect, bool useGameFrame) const;
106  Common::Point popupLocalMouse(const Common::Point &screenMouse) const;
107 
108  // The UINB tab id of the Journal (book) tab. Nancy 13 renumbered the tab
109  // ids from {1,2} to {0,1}, so the Journal id dropped from 1 to 0.
110  uint16 notebookJournalTabId() const;
111 
112  // Clear the taskbar badge for the active tab (Journal = sub 0, Tasks = sub 1).
113  void clearActiveTabNotification();
114 
115  // Populate HypertextParser's text-line list with the active tab's
116  // entries.
117  void buildTextLines();
118 
119  // Tasklist checkboxes. Rebuild the popup-local hit rects for the clickable
120  // (unchecked) checkboxes from the mark hotspots recorded during drawContent.
121  void buildCheckboxRects(const Common::Rect &localTextRect, int scrollY, int visibleH);
122  // Check off a task if its completion event flag is set, else play the
123  // "not finished yet" line.
124  void toggleCheckbox(uint entryIndex);
125  // Play a random checkbox voice line: actionable = "finished with that",
126  // !actionable = "can't check that off yet".
127  void playCheckboxSound(bool actionable);
128 
129  const UINB *_uinbData;
130 
131  Graphics::ManagedSurface _overlayImage; // popup background image
132  Graphics::ManagedSurface _closeButtonImage; // header.secondaryButton.primaryImageName
133 
134  bool _closeButtonHovered = false;
135  bool _tabHovered = false;
136  int _activeTab; // 0..1, matching UINB::tabs index
137 
138  // Scrollbar state. Driven by header.slider.
139  float _scrollPos = 0.0f; // [0, 1]: 0 = top, 1 = bottom
140  bool _scrollbarDragging = false;
141  bool _scrollbarHovered = false;
142  int _scrollbarGrabOffset = 0;
143 
144  // Deferred "I'm finished with that" voice: checking a task off plays an
145  // immediate click, then this fires the spoken line a beat later (0 = none).
146  uint32 _completeVoiceTime = 0;
147 
148  // Tasklist checkboxes: popup-local hit rects for the clickable (unchecked)
149  // boxes and the task-entry index each maps to. Rebuilt every drawContent().
150  Common::Array<Common::Rect> _checkboxRects;
151  Common::Array<uint> _checkboxEntryIndices;
152  // Task-entry index for each mark buildTextLines emits, in draw order, so
153  // the recorded mark hotspots can be mapped back to their entries.
154  Common::Array<uint> _markEntryIndices;
155 
156  // journalEntries HashMap keys: _surfaceID = 3 holds task entries,
157  // _surfaceID = 4 holds journal entries.
158  enum NotebookTab {
159  kNotebookTabTasks = 3,
160  kNotebookTabJournal = 4
161  };
162 };
163 
164 } // End of namespace UI
165 } // End of namespace Nancy
166 
167 #endif // NANCY_UI_NOTEBOOKPOPUP_H
Definition: managed_surface.h:51
Definition: rect.h:536
Definition: input.h:41
Definition: soundequalizerpuzzle.h:27
Definition: hypertext.h:32
Definition: commontypes.h:400
Definition: renderobject.h:36
Definition: rect.h:144
Definition: notebookpopup.h:38
Definition: actionmanager.h:32
Definition: enginedata.h:788