HELP.CPP 24 KB

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