HELP.CPP (24428B)
1 // 2 // Copyright 2020 Electronic Arts Inc. 3 // 4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 5 // software: you can redistribute it and/or modify it under the terms of 6 // the GNU General Public License as published by the Free Software Foundation, 7 // either version 3 of the License, or (at your option) any later version. 8 9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 10 // in the hope that it will be useful, but with permitted additional restrictions 11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 12 // distributed with this program. You should have received a copy of the 13 // GNU General Public License along with permitted additional restrictions 14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection 15 16 /* $Header: /CounterStrike/HELP.CPP 1 3/03/97 10:24a Joe_bostic $ */ 17 /*********************************************************************************************** 18 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S *** 19 *********************************************************************************************** 20 * * 21 * Project Name : Command & Conquer * 22 * * 23 * File Name : HELP.CPP * 24 * * 25 * Programmer : Joe L. Bostic * 26 * * 27 * Start Date : 11/18/94 * 28 * * 29 * Last Update : September 22, 1995 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * HelpClass::Draw_Help -- Display the help message (if necessary). * 34 * HelpClass::HelpClass -- Default constructor for the help processor. * 35 * HelpClass::Help_AI -- Handles the help text logic. * 36 * HelpClass::Help_Text -- Assigns text as the current help text. * 37 * HelpClass::Init_Clear -- Sets help system to a known state. * 38 * HelpClass::Overlap_List -- Returns with offset list for cells under help text. * 39 * HelpClass::Scroll_Map -- Makes sure scrolling doesn't leave text shards. * 40 * HelpClass::Set_Cost -- Initiates the second line of help text showing item cost. * 41 * HelpClass::Set_Tactical_Position -- Sets the position of the tactical map. * 42 * HelpClass::Set_Tactical_Position -- Sets the tactical map position. * 43 * HelpClass::Set_Tactical_Position -- Sets the tactical map position. * 44 * HelpClass::Set_Text -- Determines the overlap list and draw coordinates. * 45 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 46 47 #include "function.h" 48 49 /* 50 ** This is the holding buffer for the text overlap list. This buffer must be in the near 51 ** data segment. It will be filled in by the Set_Text() function. 52 */ 53 //short const HelpClass::OverlapList[60] = { // Can't be const - it's expected to be written to. ST - 2/7/2019 5:16PM 54 short HelpClass::OverlapList[60] = { 55 REFRESH_EOL 56 }; 57 58 char const * HelpClass::HelpText; 59 60 61 /*********************************************************************************************** 62 * HelpClass::HelpClass -- Default constructor for the help processor. * 63 * * 64 * The help processor is initialized by this routine. It merely sets up the help engine * 65 * to the default state. The default state will not display any help text. Call the * 66 * Help_Text() function to enable help processing. * 67 * * 68 * INPUT: none * 69 * * 70 * OUTPUT: none * 71 * * 72 * WARNINGS: none * 73 * * 74 * HISTORY: * 75 * 11/18/1994 JLB : Created. * 76 *=============================================================================================*/ 77 HelpClass::HelpClass(void) : 78 HelpX(0), 79 HelpY(0), 80 HelpWidth(0), 81 IsRight(false), 82 Cost(0), 83 X(0), 84 Y(0), 85 DrawX(0), 86 DrawY(0), 87 Width(0), 88 Text(TXT_NONE), 89 Color(LTGREY), 90 CountDownTimer(0) 91 { 92 } 93 94 95 /*********************************************************************************************** 96 * HelpClass::Init_Clear -- Sets help system to a known state. * 97 * * 98 * INPUT: none * 99 * * 100 * OUTPUT: none * 101 * * 102 * WARNINGS: none * 103 * * 104 * HISTORY: * 105 * 12/24/1994 JLB : Created. * 106 *=============================================================================================*/ 107 void HelpClass::Init_Clear(void) 108 { 109 TabClass::Init_Clear(); 110 111 Set_Text(TXT_NONE); 112 } 113 114 115 /*********************************************************************************************** 116 * HelpClass::Overlap_List -- Returns with offset list for cells under help text. * 117 * * 118 * Use this routine to fetch an offset list for the cells under the text displayed. If * 119 * there is no text displayed, then the list will consist of just the terminator code. * 120 * * 121 * INPUT: none * 122 * * 123 * OUTPUT: Returns with a pointer to the offset list for the help text overlap. The offset * 124 * list is based on the tactical map upper left corner cell. * 125 * * 126 * WARNINGS: none * 127 * * 128 * HISTORY: * 129 * 11/18/1994 JLB : Created. * 130 *=============================================================================================*/ 131 short const * HelpClass::Overlap_List(void) const 132 { 133 if (Text == TXT_NONE || CountDownTimer) { 134 ((short &)(OverlapList[0])) = REFRESH_EOL; 135 } 136 return(OverlapList); 137 } 138 139 140 /*********************************************************************************************** 141 * HelpClass::Help_AI -- Handles the help text logic. * 142 * * 143 * This routine handles tracking the mouse position to see if the mouse remains stationary * 144 * for the required amount of time. If the time requirement has been met, then it flags * 145 * the help system to display the help text the next time the Draw_Help() function is * 146 * called. * 147 * * 148 * INPUT: key -- Keyboard input code. * 149 * * 150 * x,y -- Mouse coordinates. * 151 * * 152 * OUTPUT: none * 153 * * 154 * WARNINGS: This routine must be called once and only once per game frame (15 times per * 155 * second). * 156 * * 157 * HISTORY: * 158 * 11/18/1994 JLB : Created. * 159 * 12/31/1994 JLB : Uses mouse coordinates as passed in. * 160 *=============================================================================================*/ 161 void HelpClass::AI(KeyNumType &key, int x, int y) 162 { 163 if (!CountDownTimer && !IsRight && (x != X || y != Y)) { 164 Help_Text(TXT_NONE); 165 } 166 167 /* 168 ** Process the countdown timer only if it hasn't already expired and there is 169 ** a real help text message to display. 170 */ 171 if (CountDownTimer && !HelpText && Text != TXT_NONE) { 172 173 /* 174 ** If the mouse has moved, then reset the timer since a moving mouse is not 175 ** supposed to bring up the help text. 176 */ 177 if (!IsRight && (X != x || Y != y)) { 178 X = x; 179 Y = y; 180 CountDownTimer = HELP_DELAY; 181 Help_Text(TXT_NONE); 182 } else { 183 184 /* 185 ** If the delay has expired, then the text must be drawn. Build the help text 186 ** overlay list at this time. Better to do it now, when we KNOW it is needed, then 187 ** to do it earlier when it might not be needed. 188 */ 189 Set_Text(Text); 190 } 191 } 192 193 TabClass::AI(key, x, y); 194 } 195 196 197 /*********************************************************************************************** 198 * HelpClass::Help_Text -- Assigns text as the current help text. * 199 * * 200 * Use this routine to change the help text that will pop up if the cursor isn't moved * 201 * for the help delay duration. Call this routine as often as desired. * 202 * * 203 * INPUT: text -- The text number for the help text to use. * 204 * * 205 * OUTPUT: none * 206 * * 207 * WARNINGS: none * 208 * * 209 * HISTORY: * 210 * 11/18/1994 JLB : Created. * 211 *=============================================================================================*/ 212 void HelpClass::Help_Text(int text, int x, int y, int color, bool quick) 213 { 214 if (text != Text) { 215 216 /* 217 ** If there is an existing text message, then flag the map to redraw the underlying 218 ** icons so that the text message is erased. 219 */ 220 if (Text != TXT_NONE) { 221 Refresh_Cells(Coord_Cell(TacticalCoord), &OverlapList[0]); 222 } 223 224 /* 225 ** Record the position of the mouse. This recorded position will be used to determine 226 ** if the mouse has moved. A moving mouse prevents the help text from popping up. 227 */ 228 X = x; 229 if (x == -1) X = Get_Mouse_X(); 230 Y = y; 231 if (y == -1) Y = Get_Mouse_Y(); 232 IsRight = (y != -1) || (x != -1); 233 234 if (quick) { 235 CountDownTimer = 1; 236 } else { 237 CountDownTimer = HELP_DELAY; 238 } 239 240 /* 241 ** All help text prints in the same color for E3 242 */ 243 //Color = color; 244 color = color; 245 Color = HELP_TEXT_COLOR; 246 Text = text; 247 Cost = 0; 248 } 249 } 250 251 252 /*********************************************************************************************** 253 * HelpClass::Draw_Help -- Display the help message (if necessary). * 254 * * 255 * This function will print the help text if it thinks it should. The timer and text * 256 * message can control whether this occurs. If there is no help text or the countdown timer * 257 * has not expired, then no text will be printed. * 258 * * 259 * INPUT: none * 260 * * 261 * OUTPUT: none * 262 * * 263 * WARNINGS: none * 264 * * 265 * HISTORY: * 266 * 11/18/1994 JLB : Created. * 267 *=============================================================================================*/ 268 void HelpClass::Draw_It(bool forced) 269 { 270 TabClass::Draw_It(forced); 271 272 forced = false; // TCTCTCTC 273 if (Text != TXT_NONE && (forced || !CountDownTimer)) { 274 275 if (LogicPage->Lock()) { 276 Plain_Text_Print(Text, DrawX, DrawY, Color, BLACK, TPF_MAP|TPF_NOSHADOW); 277 LogicPage->Draw_Rect(DrawX-1, DrawY-1, DrawX+Width+1, DrawY+FontHeight, Color); 278 279 if (Cost) { 280 char buffer[15]; 281 sprintf(buffer, "$%d", Cost); 282 int width = String_Pixel_Width(buffer); 283 284 Plain_Text_Print(buffer, DrawX, DrawY+FontHeight, Color, BLACK, TPF_MAP|TPF_NOSHADOW); 285 LogicPage->Draw_Rect(DrawX-1, DrawY+FontHeight, DrawX+width+1, DrawY+FontHeight+FontHeight-1, Color); 286 LogicPage->Draw_Line(DrawX, DrawY+FontHeight, DrawX+min(width+1, Width)-1, DrawY+FontHeight, BLACK); 287 } 288 LogicPage->Unlock(); 289 } 290 } 291 } 292 293 294 /*********************************************************************************************** 295 * HelpClass::Set_Text -- Determines the overlap list and draw coordinates. * 296 * * 297 * This routine is used to build the overlap list -- used for icon refreshing. It also * 298 * determines if the text can fit on the screen and makes adjustments so that it will. * 299 * * 300 * INPUT: text -- The text number to set the help system to use. * 301 * * 302 * OUTPUT: none * 303 * * 304 * WARNINGS: none * 305 * * 306 * HISTORY: * 307 * 11/18/1994 JLB : Created. * 308 * 12/11/1994 JLB : Won't draw past tactical map edges. * 309 *=============================================================================================*/ 310 void HelpClass::Set_Text(int text) 311 { 312 if (text != TXT_NONE) { 313 Text = text; 314 Plain_Text_Print(TXT_NONE, 0, 0, 0, 0, TPF_MAP|TPF_NOSHADOW); 315 Width = String_Pixel_Width(Text_String(Text)); 316 if (IsRight) { 317 DrawX = X - Width; 318 DrawY = Y; 319 } else { 320 int right = TacPixelX + Lepton_To_Pixel(TacLeptonWidth) - 3*RESFACTOR; 321 int bottom = TacPixelY + Lepton_To_Pixel(TacLeptonHeight) - 1*RESFACTOR; 322 323 DrawX = X+X_OFFSET; 324 DrawY = Y+Y_OFFSET; 325 if (DrawX + Width > right) { 326 DrawX -= (DrawX+Width) - right; 327 } 328 if (DrawY + 10*RESFACTOR > bottom) { 329 DrawY -= (DrawY+10*RESFACTOR) - bottom; 330 } 331 if (DrawX < TacPixelX+1) DrawX = TacPixelX+1; 332 if (DrawY < TacPixelY+1) DrawY = TacPixelY+1; 333 } 334 memcpy((void*)OverlapList, Text_Overlap_List(Text_String(Text), DrawX-1, DrawY), sizeof(OverlapList)); 335 *(short *)&OverlapList[ARRAY_SIZE(OverlapList)-1] = REFRESH_EOL; 336 } 337 } 338 339 340 /*********************************************************************************************** 341 * HelpClass::Scroll_Map -- Makes sure scrolling doesn't leave text shards. * 342 * * 343 * This routine intercepts the map scrolling request and then makes sure that if, in fact, * 344 * the map is going to scroll, then reset and erase the help text so that it doesn't * 345 * mess up the display. * 346 * * 347 * INPUT: facing -- The direction to scroll (unused by this routine). * 348 * * 349 * really -- If the scroll is actually going to occur, rather than just be examined * 350 * for legality, then this parameter will be true. If this parameter is * 351 * true, then the help text is reset. * 352 * * 353 * OUTPUT: Returns if it can, or did, scroll in the requested direction. * 354 * * 355 * WARNINGS: none * 356 * * 357 * HISTORY: * 358 * 12/15/1994 JLB : Created. * 359 *=============================================================================================*/ 360 bool HelpClass::Scroll_Map(DirType facing, int & distance, bool really) 361 { 362 if (really) { 363 Help_Text(TXT_NONE); 364 } 365 return(TabClass::Scroll_Map(facing, distance, really)); 366 } 367 368 369 /*********************************************************************************************** 370 * HelpClass::Set_Cost -- Initiates the second line of help text showing item cost. * 371 * * 372 * Use this routine after the Help_Text() function to activate the second line. The second * 373 * line displays a cost. Typically, this is used by the sidebar to display the cost of the * 374 * specified item. * 375 * * 376 * INPUT: cost -- The cost to associate with this help text. If this value is zero, then * 377 * no second line is displayed, so don't pass in zero. * 378 * * 379 * OUTPUT: none * 380 * * 381 * WARNINGS: none * 382 * * 383 * HISTORY: * 384 * 01/09/1995 JLB : Created. * 385 *=============================================================================================*/ 386 void HelpClass::Set_Cost(int cost) 387 { 388 Cost = cost; 389 } 390 391 392 /*********************************************************************************************** 393 * HelpClass::Set_Tactical_Position -- Sets the position of the tactical map. * 394 * * 395 * This routine will set the position of the tactical map. At this class level, it merely * 396 * makes sure that the help text disappears when this happens. The lower level classes * 397 * actually change the map's position. * 398 * * 399 * INPUT: coord -- The new coordinate to make the upper left corner of the visible display. * 400 * * 401 * OUTPUT: none * 402 * * 403 * WARNINGS: none * 404 * * 405 * HISTORY: * 406 * 09/22/1995 JLB : Created. * 407 *=============================================================================================*/ 408 void HelpClass::Set_Tactical_Position(COORDINATE coord) 409 { 410 if (TacticalCoord != coord) { 411 Help_Text(TXT_NONE); 412 } 413 TabClass::Set_Tactical_Position(coord); 414 }