TAB.CPP 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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/TAB.CPP 1 3/03/97 10:25a 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 : TAB.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 12/15/94 *
  26. * *
  27. * Last Update : September 20, 1995 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * TabClass::AI -- Handles player I/O with the tab buttons. *
  32. * TabClass::Draw_It -- Displays the tab buttons as necessary. *
  33. * TabClass::One_Time -- Performs one time initialization of tab handler class. *
  34. * TabClass::Set_Active -- Activates a "filefolder tab" button. *
  35. * TabClass::TabClass -- Default construct for the tab button class. *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #include "function.h"
  38. void const * TabClass::TabShape = NULL;
  39. /***********************************************************************************************
  40. * TabClass::TabClass -- Default construct for the tab button class. *
  41. * *
  42. * The default constructor merely sets the tab buttons to default non-selected state. *
  43. * *
  44. * INPUT: none *
  45. * *
  46. * OUTPUT: none *
  47. * *
  48. * WARNINGS: none *
  49. * *
  50. * HISTORY: *
  51. * 12/15/1994 JLB : Created. *
  52. *=============================================================================================*/
  53. TabClass::TabClass(void) :
  54. FlasherTimer(0),
  55. IsToRedraw(false),
  56. MoneyFlashTimer(0)
  57. {
  58. }
  59. /***********************************************************************************************
  60. * TabClass::Draw_It -- Displays the tab buttons as necessary. *
  61. * *
  62. * This routine is called whenever the display is being redrawn (in some fashion). The *
  63. * parameter can be used to force the tab buttons to redraw completely. The default action *
  64. * is to only redraw if the tab buttons have been explicitly flagged to be redraw. The *
  65. * result of this is the elimination of unnecessary redraws. *
  66. * *
  67. * INPUT: complete -- bool; Force redraw of the entire tab button graphics? *
  68. * *
  69. * OUTPUT: none *
  70. * *
  71. * WARNINGS: none *
  72. * *
  73. * HISTORY: *
  74. * 12/15/1994 JLB : Created. *
  75. * 05/19/1995 JLB : New EVA style. *
  76. *=============================================================================================*/
  77. #define EVA_WIDTH 80
  78. #define TAB_HEIGHT 8
  79. void TabClass::Draw_It(bool complete)
  80. {
  81. SidebarClass::Draw_It(complete);
  82. if (Debug_Map) {
  83. return;
  84. }
  85. // Disable tab drawing for menu, credits buttons etc. ST - 5/27/2019
  86. #if (0)
  87. /*
  88. ** Redraw the top bar imagery if flagged to do so or if the entire display needs
  89. ** to be redrawn.
  90. */
  91. if ((complete || IsToRedraw) && LogicPage->Lock()) {
  92. int width = SeenBuff.Get_Width();
  93. int rightx = width - 1;
  94. int tab_height = TAB_HEIGHT * RESFACTOR;
  95. LogicPage->Fill_Rect(0, 0, rightx, tab_height-1, BLACK);
  96. // LogicPage->Fill_Rect(0, 0, rightx, tab_height-(2 * RESFACTOR), BLACK);
  97. #ifdef WIN32
  98. /*
  99. ** Use the new sidebar art for 640x400
  100. */
  101. CC_Draw_Shape(TabShape, 0, 0, 0, WINDOW_MAIN, SHAPE_NORMAL);
  102. #else
  103. CC_Draw_Shape(TabShape, 2, 0, 0, WINDOW_MAIN, SHAPE_NORMAL);
  104. #endif
  105. Draw_Credits_Tab();
  106. LogicPage->Draw_Line(0, tab_height-(1* RESFACTOR), rightx, tab_height-(1 * RESFACTOR), BLACK);
  107. #ifdef WIN32
  108. Fancy_Text_Print(TXT_TAB_BUTTON_CONTROLS, (EVA_WIDTH/2) * RESFACTOR, 0, &MetalScheme, TBLACK, TPF_METAL12 | TPF_CENTER | TPF_USE_GRAD_PAL);
  109. #else
  110. // Fancy_Text_Print(TXT_TAB_BUTTON_CONTROLS, (EVA_WIDTH/2) * RESFACTOR, 0, &ColorRemaps[PCOLOR_GREY], TBLACK, TPF_6PT_GRAD|TPF_NOSHADOW|TPF_CENTER|TPF_BRIGHT_COLOR);
  111. Fancy_Text_Print(TXT_TAB_BUTTON_CONTROLS, (EVA_WIDTH/2) * RESFACTOR, 0, &ColorRemaps[PCOLOR_GREY], TBLACK, TPF_METAL12|TPF_NOSHADOW|TPF_CENTER|TPF_BRIGHT_COLOR);
  112. #endif //WIN32
  113. if (IsSidebarActive) {
  114. #ifndef WIN32
  115. TabClass::Hilite_Tab(1);
  116. #endif //WIN32
  117. } else {
  118. CC_Draw_Shape(TabShape, 0, width-(EVA_WIDTH * RESFACTOR), 0, WINDOW_MAIN, SHAPE_NORMAL);
  119. Fancy_Text_Print(TXT_TAB_SIDEBAR, width-((EVA_WIDTH/2) * RESFACTOR), 0, &ColorRemaps[PCOLOR_GREY], TBLACK, TPF_METAL12|TPF_NOSHADOW|TPF_CENTER|TPF_BRIGHT_COLOR);
  120. }
  121. LogicPage->Unlock();
  122. }
  123. Credits.Graphic_Logic(complete || IsToRedraw);
  124. #endif
  125. IsToRedraw = false;
  126. }
  127. void TabClass::Draw_Credits_Tab(void)
  128. {
  129. #ifdef WIN32
  130. /*
  131. ** Use the new sidebar art for 640x400
  132. */
  133. CC_Draw_Shape(TabShape, Map.MoneyFlashTimer > 1 ? 8 : 6, (320-EVA_WIDTH) * RESFACTOR, 0, WINDOW_MAIN, SHAPE_NORMAL);
  134. #else
  135. CC_Draw_Shape(TabShape, 4, (320-(EVA_WIDTH*2)) * RESFACTOR, 0, WINDOW_MAIN, SHAPE_NORMAL);
  136. #endif
  137. if (Scen.MissionTimer.Is_Active()) {
  138. bool light = ((int)Scen.MissionTimer < TICKS_PER_MINUTE * Rule.TimerWarning) || Map.FlasherTimer > 0;
  139. #ifdef WIN32
  140. CC_Draw_Shape(TabShape, light ? 4 : 2, 320, 0, WINDOW_MAIN, SHAPE_NORMAL);
  141. #else
  142. CC_Draw_Shape(TabShape, light ? 6 : 5, EVA_WIDTH * RESFACTOR, 0, WINDOW_MAIN, SHAPE_NORMAL);
  143. #endif
  144. }
  145. }
  146. void TabClass::Hilite_Tab(int tab)
  147. {
  148. int xpos = 0;
  149. int text = TXT_TAB_BUTTON_CONTROLS;
  150. int textx = (EVA_WIDTH/2) * RESFACTOR;
  151. if (tab) {
  152. xpos = (320-EVA_WIDTH) * RESFACTOR;
  153. text = TXT_TAB_SIDEBAR;
  154. textx = (320-(EVA_WIDTH/2)) * RESFACTOR;
  155. }
  156. #ifdef WIN32
  157. /*
  158. ** Use the new sidebar art for 640x400
  159. */
  160. CC_Draw_Shape(TabShape, 1, xpos, 0, WINDOW_MAIN, SHAPE_NORMAL);
  161. MetalScheme.Color = 128+6;
  162. Fancy_Text_Print(TXT_TAB_BUTTON_CONTROLS, (EVA_WIDTH/2) * RESFACTOR, 0, &MetalScheme, TBLACK, TPF_METAL12 | TPF_CENTER | TPF_USE_GRAD_PAL);
  163. MetalScheme.Color = 128;
  164. #else
  165. CC_Draw_Shape(TabShape, 1 + (tab ? 0 : 2), xpos, 0, WINDOW_MAIN, SHAPE_NORMAL);
  166. Fancy_Text_Print(text, textx, 0, &ColorRemaps[PCOLOR_GREY], TBLACK, TPF_METAL12|TPF_NOSHADOW|TPF_CENTER|TPF_BRIGHT_COLOR);
  167. // Fancy_Text_Print(text, textx, 0, &ColorRemaps[PCOLOR_GREY], TBLACK, TPF_6PT_GRAD|TPF_NOSHADOW|TPF_CENTER|TPF_BRIGHT_COLOR);
  168. #endif
  169. }
  170. /***********************************************************************************************
  171. * TabClass::AI -- Handles player I/O with the tab buttons. *
  172. * *
  173. * This routine is called every game tick and passed whatever key the player has supplied. *
  174. * If the input selects a tab button, then the graphic gets updated accordingly. *
  175. * *
  176. * INPUT: input -- The player's input character (might be mouse click). *
  177. * *
  178. * x,y -- Mouse coordinates at time of input. *
  179. * *
  180. * OUTPUT: none *
  181. * *
  182. * WARNINGS: none *
  183. * *
  184. * HISTORY: *
  185. * 12/15/1994 JLB : Created. *
  186. * 12/31/1994 JLB : Uses mouse coordinate parameters. *
  187. * 05/31/1995 JLB : Fixed to handle mouse shape properly. *
  188. * 08/25/1995 JLB : Handles new scrolling option. *
  189. *=============================================================================================*/
  190. void TabClass::AI(KeyNumType &input, int x, int y)
  191. {
  192. if (y >= 0 && y < (TAB_HEIGHT * RESFACTOR) && x < (SeenBuff.Get_Width() - 1) && x > 0) {
  193. bool ok = false;
  194. int width = SeenBuff.Get_Width();
  195. /*
  196. ** If the mouse is at the top of the screen, then the tab bars only work
  197. ** in certain areas. If the special scroll modification is not active, then
  198. ** the tabs never work when the mouse is at the top of the screen.
  199. */
  200. if (y > 0) {
  201. ok = true;
  202. }
  203. if (ok) {
  204. if (input == KN_LMOUSE) {
  205. int sel = -1;
  206. if (x < EVA_WIDTH * RESFACTOR) sel = 0;
  207. #ifndef WIN32 // No Sidebar tab in hires - sidebar is always active.
  208. if (x > (320-80) * RESFACTOR) sel = 1;
  209. #endif //WIN32
  210. if (sel >= 0) {
  211. Set_Active(sel);
  212. input = KN_NONE;
  213. }
  214. }
  215. Override_Mouse_Shape(MOUSE_NORMAL, false);
  216. }
  217. }
  218. if (MoneyFlashTimer == 1) {
  219. IsToRedraw = true;
  220. Flag_To_Redraw(false);
  221. }
  222. Credits.AI();
  223. SidebarClass::AI(input, x, y);
  224. }
  225. /***********************************************************************************************
  226. * TabClass::Set_Active -- Activates a "filefolder tab" button. *
  227. * *
  228. * This function is used to activate one of the file folder tab buttons that appear at the *
  229. * top edge of the screen. *
  230. * *
  231. * INPUT: select -- The button to activate. 0 = left button, 1=next button, etc. *
  232. * *
  233. * OUTPUT: none *
  234. * *
  235. * WARNINGS: none *
  236. * *
  237. * HISTORY: *
  238. * 12/15/1994 JLB : Created. *
  239. *=============================================================================================*/
  240. void TabClass::Set_Active(int select)
  241. {
  242. switch (select) {
  243. case 0:
  244. Queue_Options();
  245. break;
  246. case 1:
  247. Map.SidebarClass::Activate(-1);
  248. break;
  249. default:
  250. break;
  251. }
  252. }
  253. /***********************************************************************************************
  254. * TabClass::One_Time -- Performs one time initialization of tab handler class. *
  255. * *
  256. * This routine will perform any one time initializations of the tab handler class. This *
  257. * typically includes the loading of the shapes that appear on it. *
  258. * *
  259. * INPUT: none *
  260. * *
  261. * OUTPUT: none *
  262. * *
  263. * WARNINGS: none *
  264. * *
  265. * HISTORY: *
  266. * 09/20/1995 JLB : Created. *
  267. *=============================================================================================*/
  268. void TabClass::One_Time(void)
  269. {
  270. SidebarClass::One_Time();
  271. RawFileClass file("tabs.shp");
  272. TabShape = MFCD::Retrieve("TABS.SHP");
  273. }
  274. void TabClass::Flash_Money(void)
  275. {
  276. IsToRedraw = true;
  277. Flag_To_Redraw(false);
  278. MoneyFlashTimer = 7;
  279. }