1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
5  * file distributed with this source distribution.
6  *
7  * Additional copyright for this file:
8  * Copyright (C) 1999-2000 Revolution Software Ltd.
9  * This code is based on source code created by Revolution Software,
10  * used with permission.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25  *
26  */
27 
28 #ifndef ICB_ICONMENU_H_INCLUDED
29 #define ICB_ICONMENU_H_INCLUDED
30 
31 // Include headers needed by this class.
32 #include "engines/icb/common/px_string.h"
33 #include "engines/icb/common/px_common.h"
34 #include "engines/icb/common/px_bitmap.h"
35 #include "engines/icb/player.h"
36 #include "engines/icb/icon_list.h"
37 #include "engines/icb/icon_menu_pc.h"
38 
39 namespace ICB {
40 
41 // Use globals as it reduces rdata storage on PSX
42 extern const char *global_nothing_selected;
43 
44 #define ICON_MENU_LOG "icon_menu_log.txt"
45 
46 // This defines the maximum number of icons that can be in the menu.
47 #define ICON_MENU_MAX_ICONS 15 // NB: CHECK PADDING IMPLICATIONS FOR PSX BEFORE CHANGING THIS!
48 
49 // This is the standard number of frames in each icon.
50 #define ICON_FRAME_COUNT 2
51 
52 // Controls how fast the highlight flashes.
53 #define ICON_MENU_HIGHLIGHT_SPEED 5
54 
55 // This controls the flash rate of the added medipacks and ammo clips.
56 #define ICON_MENU_ADDED_FLASHRATE 4
57 
58 // This controls the flashrate of the email-waiting symbol.
59 #define ICON_MENU_EMAIL_FLASHRATE 24
60 
61 // These define the names of the off-screen indicator arrows.
62 #define ICON_MENU_OFF_SCREEN_LEFT "left_arrow"
63 #define ICON_MENU_OFF_SCREEN_RIGHT "right_arrow"
64 
65 // These are names for the ammo and healthcare stuff.
66 #define ARMS_GUN_NAME "gun"
67 #define ARMS_AMMO_NAME "ammo"
68 #define ARMS_HEALTH_NAME "health_pack"
69 #define EMAIL_ARRIVED_NAME "mail"
70 
71 // Used for telling which way we are scrolling / if we are scrolling
72 #define ICON_MENU_SCROLL_NONE 0
73 #define ICON_MENU_SCROLL_LEFT 1
74 #define ICON_MENU_SCROLL_RIGHT 2
75 
76 // struct _icon_menu_duplicates
77 // This structure must be passed into the icon menu upon activation, whereupon the information in it
78 // will be used to add a count to the number of each item currently in the menu.
79 struct _icon_menu_duplicates {
80 	uint8 s_nNumItems;
81 	uint8 s_pnItemCounts[ICON_MENU_MAX_ICONS];
82 
83 	// Initialisation.
_icon_menu_duplicates_icon_menu_duplicates84 	_icon_menu_duplicates() { s_nNumItems = 0; }
85 };
86 
87 // This class presents a set of icons to the user and runs the selection interface.  It is packaged as a separate
88 // class because it is used by the Remora, the speech system and the inventory.
89 class _icon_menu {
90 public:
91 	// Default constructor and destructor.
92 	_icon_menu();
~_icon_menu()93 	~_icon_menu() {}
94 
95 	// If the menu is up, call this to process its logic and draw the menu.
96 	bool8 CycleIconMenu(const _input &sKeyboardState);
97 
98 	// Draw the special armed inventory
99 	void DrawArmedMenu(const int32 nBullets, const int32 maxBullets, const int32 nClips, const int32 maxClips);
100 
101 	// And this draws it each cycle.
102 	void DrawIconMenu();
103 
104 	// Call this to close the menu down.
105 	void CloseDownIconMenu();
106 
107 	// This is the main function for running a menu selection.
108 	void Activate(const _icon_list *pIconList, const _icon_menu_duplicates &sDuplicates, bool8 bAllowEscape, uint32 nSelected);
109 
110 	// A funstion to recreate/load the icon surfaces after task switching
111 	void ReActivate();
112 
113 	// This reports whether or not the icon menu is active.
IsActive()114 	bool8 IsActive() const { return ((m_eIconMenuGameState == ACTIVE) ? TRUE8 : FALSE8); }
115 
116 	// This says whether or not there is currently a valid selection (i.e. player is 'holding' something.)
IsHolding()117 	bool8 IsHolding() const { return (m_bValidSelection); }
118 
119 	// This draws the current selection for as long as it is still 'held'.
120 	void CycleHoldingLogic();
121 
122 	// These handle the logic and drawing for adding medipacks and clips.
123 	void SetAddingClipsCount(uint32 nNumClips);
124 	void SetAddingMedipacksCount(uint32 nNumMedipacks);
125 	bool8 IsAdding() const;
126 	void CycleAddingLogic();
127 	void DrawAdding();
128 
129 	// An icon needs to flash when an email arrives.  This mechanism borrows the logic from the medipacks and clips above.
130 	void SetEmailArrived();
ClearEmailArrived()131 	void ClearEmailArrived() { m_bEmailArrived = FALSE8; }
132 
133 	// This reports the last menu selection if one is available.
134 	const char *GetLastSelection();
135 	uint32 GetLastSelectionHash() const;
136 
137 	// This clears the selection.
ClearSelection()138 	void ClearSelection() { m_bValidSelection = FALSE8; }
139 
GetTransparencyKey()140 	uint32 GetTransparencyKey() const { return (m_nTransparentKey); }
141 	void SetTransparencyColourKey();
142 
143 	// These are used for PSX smoothing.  (Won't do any harm on the PC.)
144 	void PreloadIcon(const char *pcIconPath, const char *pcIconName);
145 
146 private:
147 	int32 GetScrollingPosition(const int32 nInputX, uint32 &nIconIndex);
148 
149 	enum IconMenuGameState { INACTIVE = 0, ACTIVE };
150 
151 	IconMenuGameState m_eIconMenuGameState; // Current state of the icon menu object.
152 	const _icon_list *m_pIconList;          // Pointer to the list of icons to run the selection for.
153 	uint32 m_nLastSelection;                // Stores the last selection made by the chooser.
154 	uint32 m_nSelectedIcon;                 // Stores the icon currently centred in the screen.
155 	uint32 m_nHighlightCounter;             // Used to control frequency of highlight flashing.
156 	const char *m_pcSelectedIconName;       // Name of the currently selected icon.
157 	uint32 m_nSelectedIconHash;             // Hash of the currently selected icon.
158 	uint32 m_nIconClusterHash;              // Icon cluster hash value.
159 	_icon_menu_duplicates m_sDuplicates;    // Count of any duplicate items.
160 	uint32 m_nGlobalClusterHash;            // Hash value for the global cluster.
161 
162 	uint32 m_pnIconSurfaceIDs[ICON_MENU_MAX_ICONS];   // IDs of surfaces where non-highlighted icons are stored.
163 	uint32 m_pnHiLiteSurfaceIDs[ICON_MENU_MAX_ICONS]; // IDs of surfaces for storing highlighted versions.
164 	uint32 m_nLeftArrowID;                            // The left-off screen arrow.
165 	uint32 m_nRightArrowID;                           // Highlighted version of it.
166 	uint32 m_nLeftArrowHiLiteID;                      // The right-off screen arrow.
167 	uint32 m_nRightArrowHiLiteID;                     // Highlighted version of it.
168 	uint32 m_nAddedClipsSurface;                      // Surface for the flashing of added clips.
169 	uint32 m_nAddedMedipacksSurface;                  // Surface for the flashing of added medipacks.
170 	uint32 m_nEmailArrivedSurface;                    // Surface for the email-arrived icon.
171 	uint32 m_nMenuY;                                  // The y height to draw the menu at
172 	uint32 m_nTransparentKey;                         // Use this colour for transparency in blitting.
173 	char m_pcGlobalClusterFile[MAXLEN_CLUSTER_URL];   // The global cluster file.
174 	char m_pcIconCluster[MAXLEN_CLUSTER_URL];         // Icon cluster name.
175 
176 	bool8 m_bValidSelection;   // Gets set true when a selection is made and false when it is read.
177 	bool8 m_nKeyLock;          // Stops key-repeat.
178 	bool8 m_bHighlightVisible; // Whether or not the highlight is visible on the selected icon.
179 	bool8 m_bAllowEscape;      // Allows backstep to escape from the menu if true.
180 
181 	bool8 m_bWiderThanScreen; // Set to true when the icons won't all fit on the screen.
182 	uint8 m_nScrollCycles;    // Count of how many game cycles we have been scrolling
183 	uint8 m_nLastIconIndex;   // the last selected icon index used for scrolling
184 	uint8 m_nScrollDirection; // which direction we are scrolling
185 
186 	uint8 m_nAddedMedipacks;  // Gets set to cause flashing of added medipacks.
187 	uint8 m_nAddedClips;      // Gets set to cause flashing of added clips.
188 	uint8 m_nAddedSymbol;     // Indicates which 'adding' icon to display.
189 	uint8 m_nAddedFlashCount; // Used to control the flashing of added medipacs and clips.
190 
191 	bool8 m_bEmailArrived;      // Used to flag the arrival of an email.
192 	uint8 m_nMaxIconsDisplayed; // Holds current maximum icons that can be displayed.
193 	uint8 m_bPad2;
194 	uint8 m_bPad3;
195 
196 	// Here I block the use of the default '='.
_icon_menu(const _icon_menu &)197 	_icon_menu(const _icon_menu &) {}
198 
199 	void operator=(const _icon_menu &) {}
200 
201 	// Private functions used only in this class.
202 	void CloseDownIconMenuDisplay();
203 
204 	void SetUpOffScreenArrows();
205 	void SetupAdding(const char *pcIconName, uint32 &nSurfaceID);
206 	void CloseDownAdding();
207 };
208 
209 extern _icon_menu *g_oIconMenu;
210 }
211 
212 #endif // #if !defined( ICONMENU_H_INCLUDED )
213