ScummVM API documentation
taskbar.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_TASKBAR_H
23 #define NANCY_UI_TASKBAR_H
24 
25 #include "engines/nancy/renderobject.h"
26 
27 namespace Nancy {
28 
29 struct NancyInput;
30 
31 namespace UI {
32 
33 // Always-on bottom-of-screen strip introduced in Nancy 10.
34 // Holds 5 buttons (MENU / inventory / notebook / cellphone / HELP) that
35 // open the various popup UIs handled by Scene.
36 class Taskbar : public RenderObject {
37 public:
38  Taskbar();
39  virtual ~Taskbar() = default;
40 
41  void init() override;
42  void registerGraphics() override;
43  void handleInput(NancyInput &input);
44 
45  // Enable / disable a taskbar button. A disabled button is rendered
46  // in its disabled sprite and ignores clicks.
47  void toggleButton(uint index, bool enabled);
48 
49  // Disable override: keep the disabled sprite active while the current
50  // scene is in [startScene, endScene]. Driven by AR 29 (ControlUIItems,
51  // _flagB != 0).
52  void setDisabledRange(uint buttonIndex, int16 startScene, int16 endScene);
53  void clearButtonOverride(uint buttonIndex);
54 
55  // Notification badge: each button has up to 3 independent notification
56  // sub-categories. The badge shows when any sub-category is set; it
57  // persists across scene changes until cleared (or all sub-cats are
58  // cleared individually). Disabled state takes precedence over the badge.
59  void setNotification(uint buttonIndex, uint subCategory);
60  void clearNotification(uint buttonIndex, uint subCategory);
61  void clearAllNotifications(uint buttonIndex);
62 
63  // Re-evaluate which buttons should currently show their override
64  // sprite. Call after a scene change so the range check kicks in.
65  void updateNotificationStates(int16 currentSceneID);
66 
67  // Restore the disable overrides from the persisted TaskbarData chunk.
68  // Called after a save is loaded so a scene-ranged disable set by an
69  // earlier scene's AR survives the load.
70  void syncFromPuzzleData();
71 
72  // Set a disabled button's rejection-sound mode, from ControlUIItems (AR 29).
73  void setClickSoundMode(uint buttonIndex, uint mode);
74 
75  // Returns the index of the button that was clicked this frame, or -1
76  // if none. Cleared on the next call to handleInput().
77  int getClickedButton() const { return _clickedButton; }
78 
79  // Grey out and disable every taskbar button while a popup (inventory /
80  // notebook / cellphone / conversation) is open, matching the original.
81  void setPopupLockout(bool locked);
82 
83 private:
84  enum ButtonState {
85  kButtonIdle = 0,
86  kButtonHover = 1,
87  kButtonPressed = 2,
88  kButtonDisabled = 3, // popup unavailable; click plays a rejection sound
89  kButtonNotification = 4 // popup has new content (badge sprite)
90  };
91 
92  // Rejection-sound mode for a disabled button (ControlUIItems'
93  // autoOpenOrBadgeSound value). When a disabled button is clicked it plays a
94  // "popup unavailable" line from clickSoundName: the default picks a random
95  // valid one; kClickSound0..2 force a specific one; kClickSoundSilent is mute.
96  enum ClickSoundMode {
97  kClickSoundDefault = 0,
98  kClickSound0 = 10,
99  kClickSound1 = 11,
100  kClickSound2 = 12,
101  kClickSoundSilent = 13
102  };
103 
104  // A scene-ranged disable override for one button. While active and the
105  // current scene is within [startScene, endScene] the button renders in the
106  // disabled state; clicking it then plays the rejection sound (clickSoundMode).
107  struct ButtonOverride {
108  bool active = false;
109  int16 startScene = -1;
110  int16 endScene = -1;
111  uint clickSoundMode = kClickSoundDefault;
112  };
113 
114  static const uint kNumNotificationSubCategories = 3;
115 
116  void drawButton(uint index, ButtonState state);
117  ButtonState restingState(uint index) const;
118  // Mirror one button's override into the persisted TaskbarData chunk.
119  void persistOverride(uint index);
120  // Mirror one button's notification flags into the persisted TaskbarData chunk.
121  void persistNotifications(uint index);
122  // True when the button currently accepts hover/click (not disabled).
123  bool isButtonActive(uint index) const;
124 
125  // Nancy12 replaces the (era-inappropriate) cell phone with a coin purse that
126  // is not clickable but shows Nancy's money when hovered. True only for that
127  // game and button slot.
128  bool isMoneyDisplay(uint index) const;
129  // Draw Nancy's current money over the coin purse button (Nancy12 only).
130  void drawMoney();
131 
132  // Play a normal click sound (the button's clickSound), or the "popup
133  // unavailable" rejection sound for a disabled button.
134  void playClickSound(uint index);
135  void playRejectionSound(uint index);
136 
137  Graphics::ManagedSurface _backgroundImage; // TASK::imageName (e.g. "Frame")
138  Graphics::ManagedSurface _buttonImage; // buttons' primaryImageName (e.g. "UIShared_OVL")
139  int _hoveredButton;
140  int _clickedButton;
141  int16 _currentScene;
142  // Sized to TASK::kNumButtons (the maximum, 6 — Nancy12's coin purse slot).
143  bool _enabled[6];
144  ButtonState _buttonStates[6];
145  ButtonOverride _overrides[6];
146  bool _notifications[6][kNumNotificationSubCategories];
147  // True while a popup is open: every button renders disabled and ignores input.
148  bool _popupLockout = false;
149 };
150 
151 } // End of namespace UI
152 } // End of namespace Nancy
153 
154 #endif // NANCY_UI_TASKBAR_H
Definition: managed_surface.h:51
Definition: taskbar.h:36
Definition: input.h:41
Definition: soundequalizerpuzzle.h:27
Definition: renderobject.h:36
Definition: actionmanager.h:32