ScummVM API documentation
cellphonepopup.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_CELLPHONEPOPUP_H
23 #define NANCY_UI_CELLPHONEPOPUP_H
24 
25 #include "engines/nancy/commontypes.h"
26 #include "engines/nancy/enginedata.h"
27 #include "engines/nancy/renderobject.h"
28 
29 namespace Nancy {
30 
31 struct NancyInput;
32 
33 namespace UI {
34 
35 // Nancy 10+ cell phone popup, driven by the UICL chunk.
36 // TODO: email, search, help, browser modes; in-call menu; redial.
37 class CellPhonePopup : public RenderObject {
38 public:
40  ~CellPhonePopup() override = default;
41 
42  void init() override;
43  void registerGraphics() override;
44  void updateGraphics() override;
45  void handleInput(NancyInput &input);
46 
47  void open();
48  void close();
49  void toggle() { if (_isVisible) close(); else open(); }
50 
51  // Swaps the welcome graphic for the No Signal / No Access / Old Email
52  // Only labels and blocks outgoing calls.
53  void setNoSignal(bool noSignal);
54 
55  // Swaps the battery sprite for the low/dead variant.
56  void setBatteryLow(bool low);
57 
58  // Insert or replace a contact (matched by its 11-byte dial pattern).
59  // Used by AR 130 to add/modify entries at runtime.
60  void upsertContact(const UICL::Contact &c);
61 
62  // Append an entry to the search/email results list (mode 0) or the
63  // web bookmarks list (mode 1). Driven by AR 131 (AddSearchLink).
64  void addSearchLink(int16 mode, const Common::String &key,
65  const Common::String &value, int16 extra,
66  int16 flag, int16 eventFlag);
67 
68  // Phone-call return scene. Set before jumping into a conversation scene
69  // so AR 128 (CellPhonePopCellSceneFromStack) can return there without
70  // trampling the global push slot used by closeups/inventory views.
71  void setReturnScene(const SceneChangeDescription &scene);
72  bool consumeReturnScene(SceneChangeDescription &out);
73 
74  // Start an incoming-call sequence: opens the popup, stores the
75  // destination scene, and joins the kPlaceCall state chain so it
76  // rings, picks up, shows the connecting sprite, and changeScenes
77  // into `scene` (AR 128 returns via the setReturnScene slot).
78  void startIncomingCall(const SceneChangeDescription &scene);
79 
80 private:
81  enum ScreenState : int {
82  kWelcome = 0,
83  kDialing = 1,
84  kPlaceCall = 2,
85  kWaitOutgoingRing = 3,
86  kLookupContact = 4,
87  kWaitPickup = 5,
88  kConnected = 6,
89  kInvalidNumber = 7,
90  kWaitInvalid = 8,
91  kDirectory = 9,
92  kOnlineHub = 10, // Online heading + Email / Web sub-buttons
93  kWebList = 11, // web search-results list (AR-131 mode 1)
94  kEmailList = 12, // email message list (AR-131 mode 0)
95  kContentView = 13 // full-text view of a single email / page
96  };
97 
98  void drawChrome();
99  void drawScreenContent();
100  void drawStatusIcons();
101  void drawWebDirLabels();
102  void drawDialLabel();
103  void drawTypeMessage();
104  void drawConnectedLabel();
105  void drawConnectingSprite();
106  void drawDialedNumber();
107  void drawHelpButton(uint state);
108  void drawCloseButton(uint state);
109  void drawStatusLabels();
110  void drawDirectoryList();
111  void drawDirectoryArrows();
112  void drawWelcomeScreen();
113  void drawBackLabel();
114 
115  // Generic list renderer used by web / email modes.
116  void drawLinkList();
117  // Blit a heading sprite (e.g. emailHeading) at its chunk dest. The
118  // heading sits in the title-bar strip above the LCD content.
119  void drawHeading(const UICL::SrcDestRectPair &heading);
120  // Render the opened entry's body text in the LCD area, word-wrapped.
121  void drawContentView();
122  // Enter the content view for a list entry whose AUTOTEXT key is `key`.
123  void openContentView(const Common::String &key, const UICL::SrcDestRectPair &heading);
124  // Web button: open the first url entry as the browser home page (page 0).
125  void openBrowserHome();
126 
127  // Up/down scroll buttons differ by mode: subButtons[1]/[2] for the
128  // directory's narrower list area, [5]/[6] for the taller search /
129  // email / browser-content LCD area.
130  const UICL::ThreeRectWidget &scrollUpButton() const;
131  const UICL::ThreeRectWidget &scrollDownButton() const;
132 
133  // True when the current screen uses the zoomed-in (no-keypad)
134  // chrome variant: search list, email list, and content view.
135  bool isZoomedChromeState() const {
136  return _screenState == kWebList ||
137  _screenState == kEmailList ||
138  _screenState == kContentView;
139  }
140 
141  // True for screens that hide the status icons and "?" button so the
142  // top bar shows only the section heading and the up arrow.
143  bool isSubScreenState() const {
144  return _screenState == kDirectory ||
145  _screenState == kOnlineHub ||
146  isZoomedChromeState();
147  }
148 
149  void resetDialPad();
150  void enterScreenState(ScreenState newState);
151  void appendDigit(byte slotIndex);
152  bool playSoundIfPresent(const Common::Path &soundName);
153  bool callSoundIsStillPlaying() const;
154  void triggerContactCallSceneChange(uint contactIndex);
155  int findContactByDialBuffer() const;
156 
157  uint maxDirectoryRows() const;
158  uint directoryRowAt(const Common::Point &chunkMouse) const;
159  Common::Rect directoryRowRect(uint visibleIndex) const;
160  // Row pitch and first-row Y (screen coords) from the layout data.
161  int rowPitch() const;
162  int rowTopScreen() const;
163  bool isLinkListMode() const { return _screenState == kWebList || _screenState == kEmailList; }
164  bool isOnlineMode() const { return _screenState == kOnlineHub || isLinkListMode(); }
165 
166  // Section headings live in the phone's title-bar strip above the LCD,
167  // so they don't consume a list row. Kept as a hook in case a game
168  // needs an in-LCD title row.
169  uint listTitleRows() const { return 0; }
170 
171  // Layout for the two clickable labels on the Online hub.
172  Common::Rect hubEmailRect() const;
173  Common::Rect hubWebRect() const;
174  void startCallToContact(uint contactIndex);
175  // Visible (deduplicated) row -> raw contact index, or -1.
176  int contactIndexForVisibleRow(uint visibleRow) const;
177  uint deduplicatedContactCount() const;
178  // Entry count for whichever list the popup is currently showing.
179  uint currentListEntryCount() const;
180  // Absolute indices into the current list's backing array that pass
181  // the active filter. Email applies the "Old Email Only" filter
182  // (no-signal -> read messages only); web shows everything.
183  Common::Array<uint> listVisibleIndices() const;
184  // True when the contact's visibility flag is currently unlocked.
185  bool isContactVisible(const UICL::Contact &c) const;
186  // Popup-local rect of the Back hotspot in directory mode.
187  Common::Rect backLabelHitRect() const;
188  // Move the directory selection by delta, scrolling as needed.
189  void moveDirectorySelection(int delta);
190 
191  Common::Point mouseToChunkCoords(const Common::Point &mouse) const;
192 
193  const UICL *_uiclData;
194 
195  // Runtime contact list, seeded from _uiclData->contacts and then
196  // mutable (AR 130 inserts/replaces entries).
198 
199  // Chrome (header.imageName) and sprite atlas (overlayImageName).
200  Graphics::ManagedSurface _overlayImage;
201  Graphics::ManagedSurface _spritesImage;
202 
203  bool _closeButtonHovered = false;
204  bool _scrollUpHovered = false;
205  bool _scrollDownHovered = false;
206 
207  ScreenState _screenState = kWelcome;
208 
209  // Dialed digits as '0'..'9' chars; convert with `c - '0'` to get
210  // the slot index that matches a contact's dial prefix.
211  Common::String _dialedNumber;
212 
213  SoundDescription _callSound;
214 
215  // Resolved during kLookupContact, valid through kWaitPickup; -1 = miss.
216  int _resolvedContact = -1;
217 
218  int _hoveredSlot = -1;
219 
220  // First visible deduplicated contact, and the active row within the page.
221  uint _directoryScroll = 0;
222  uint _directorySelection = 0;
223 
224  // Content-view (single email / page) state.
225  ScreenState _contentReturnState = kOnlineHub;
226  const UICL::SrcDestRectPair *_contentHeading = nullptr;
227  Common::String _contentKey;
228  uint _contentScroll = 0;
229 
230  // In-page hyperlinks: rects (popup-local, recomputed every draw) and
231  // the target CVTX key parsed from each <H>...<L> region of the body.
232  Common::Array<Common::Rect> _contentHotspots;
233  Common::Array<Common::String> _contentHotspotTargets;
234 
235  bool _noSignal = false;
236  bool _batteryLow = false;
237 
238  // Incoming-call destination (set by startIncomingCall, consumed by the
239  // kConnected handler once the player has answered).
240  SceneChangeDescription _pendingCallScene;
241  bool _hasPendingCallScene = false;
242 
243  SceneChangeDescription _returnScene;
244  bool _hasReturnScene = false;
245 };
246 
247 } // End of namespace UI
248 } // End of namespace Nancy
249 
250 #endif // NANCY_UI_CELLPHONEPOPUP_H
Definition: managed_surface.h:51
Definition: str.h:59
Definition: commontypes.h:152
Definition: enginedata.h:577
Definition: enginedata.h:590
Definition: rect.h:524
Definition: path.h:52
Definition: enginedata.h:584
Definition: input.h:41
Definition: soundequalizerpuzzle.h:27
Definition: renderobject.h:36
Definition: rect.h:144
Definition: cellphonepopup.h:37
Definition: enginedata.h:604
Definition: commontypes.h:255
Definition: actionmanager.h:32