SIDEBAR.H 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. /*
  2. ** Command & Conquer(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: F:\projects\c&c\vcs\code\sidebar.h_v 2.18 16 Oct 1995 16:45:24 JOE_BOSTIC $ */
  19. /***********************************************************************************************
  20. *** 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 ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : SIDEBAR.H *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : October 20, 1994 *
  30. * *
  31. * Last Update : October 20, 1994 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifndef SIDEBAR_H
  37. #define SIDEBAR_H
  38. #include "function.h"
  39. #include "power.h"
  40. #include "factory.h"
  41. class SidebarClass: public PowerClass
  42. {
  43. public:
  44. /*
  45. ** These constants are used to control the sidebar rendering. They are instantiated
  46. ** as enumerations since C++ cannot use "const" in this context.
  47. */
  48. int SideX; // x position for side bar
  49. int SideY; // y position for side bar
  50. int SideBarWidth; // width of the sidebar
  51. int SideWidth; // width of the sidebar
  52. int SideHeight; // height of the sidebar
  53. int TopHeight; // height of top of sidebar
  54. int MaxVisible; // max production icons visible
  55. int ButtonOneWidth; // Button width.
  56. int ButtonTwoWidth; // Button width.
  57. int ButtonThreeWidth; // Button width.
  58. int ButtonHeight; // Button width.
  59. enum SideBarClassEnums {
  60. BUTTON_ACTIVATOR=100, // Button ID for the activator.
  61. SIDEBARWIDTH = 80,
  62. #if 0
  63. SIDE_X=RADAR_X, // The X position of sidebar upper left corner.
  64. SIDE_Y=RADAR_Y+RADAR_HEIGHT, // The Y position of sidebar upper left corner.
  65. SIDE_WIDTH=320-SIDE_X, // Width of the entire sidebar (in pixels).
  66. SIDE_HEIGHT=200-SIDE_Y, // Height of the entire sidebar (in pixels).
  67. TOP_HEIGHT=13, // Height of top section (with repair/sell buttons).
  68. COLUMN_ONE_X=SIDE_X+8, // Sidestrip upper left coordinates...
  69. COLUMN_ONE_Y=SIDE_Y+TOP_HEIGHT,
  70. COLUMN_TWO_X=COLUMN_ONE_X+((SIDE_WIDTH-16)/2)+3,
  71. COLUMN_TWO_Y=SIDE_Y+TOP_HEIGHT,
  72. #if (GERMAN | FRENCH)
  73. //BGA: changes to all buttons
  74. BUTTON_ONE_WIDTH=20, // Button width.
  75. BUTTON_TWO_WIDTH=27, // Button width.
  76. BUTTON_THREE_WIDTH=26, // Button width.
  77. BUTTON_HEIGHT=9, // Button height.
  78. BUTTON_ONE_X=SIDE_X+2, // Left button X coordinate.
  79. BUTTON_ONE_Y=SIDE_Y+2, // Left button Y coordinate.
  80. BUTTON_TWO_X=SIDE_X+24, // Right button X coordinate.
  81. BUTTON_TWO_Y=SIDE_Y+2, // Right button Y coordinate.
  82. BUTTON_THREE_X=SIDE_X+53, // Right button X coordinate.
  83. BUTTON_THREE_Y=SIDE_Y+2, // Right button Y coordinate.
  84. #else
  85. BUTTON_ONE_WIDTH=32, // Button width.
  86. BUTTON_TWO_WIDTH=20, // Button width.
  87. BUTTON_THREE_WIDTH=20, // Button width.
  88. BUTTON_HEIGHT=9, // Button height.
  89. BUTTON_ONE_X=SIDE_X+2, // Left button X coordinate.
  90. BUTTON_ONE_Y=SIDE_Y+2, // Left button Y coordinate.
  91. BUTTON_TWO_X=SIDE_X+36, // Right button X coordinate.
  92. BUTTON_TWO_Y=SIDE_Y+2, // Right button Y coordinate.
  93. BUTTON_THREE_X=SIDE_X+58, // Right button X coordinate.
  94. BUTTON_THREE_Y=SIDE_Y+2, // Right button Y coordinate.
  95. #endif
  96. BUTTON_ONE_WIDTH=32, // Button width.
  97. BUTTON_TWO_WIDTH=20, // Button width.
  98. BUTTON_THREE_WIDTH=20, // Button width.
  99. BUTTON_HEIGHT=9, // Button height.
  100. #endif
  101. COLUMNS=2, // Number of side strips on sidebar.
  102. };
  103. SidebarClass(void);
  104. /*
  105. ** Initialization
  106. */
  107. virtual void One_Time(void); // One-time inits
  108. virtual void Init_Clear(void); // Clears all to known state
  109. virtual void Init_IO(void); // Inits button list
  110. virtual void Init_Theater(TheaterType theater); // Theater-specific inits
  111. virtual void AI(KeyNumType & input, int x, int y);
  112. virtual void Draw_It(bool complete);
  113. virtual void Refresh_Cells(CELL cell, short const *list);
  114. bool Abandon_Production(RTTIType type, int factory);
  115. bool Activate(int control);
  116. bool Add(RTTIType type, int ID);
  117. bool Sidebar_Click(KeyNumType & input, int x, int y);
  118. void Recalc(void);
  119. bool Factory_Link(int factory, RTTIType type, int id);
  120. /*
  121. ** File I/O.
  122. */
  123. virtual void Code_Pointers(void);
  124. virtual void Decode_Pointers(void);
  125. /*
  126. ** Each side strip is managed by this class. It handles all strip specific
  127. ** actions.
  128. */
  129. class StripClass : public StageClass
  130. {
  131. class SelectClass : public ControlClass
  132. {
  133. public:
  134. SelectClass(void);
  135. void Set_Owner(StripClass & strip, int index);
  136. StripClass * Strip;
  137. int Index;
  138. protected:
  139. virtual int Action(unsigned flags, KeyNumType & key);
  140. };
  141. public:
  142. int ObjectWidth;
  143. int ObjectHeight;
  144. int StripWidth;
  145. int LeftEdgeOffset;
  146. int ButtonSpacingOffset;
  147. StripClass(void);
  148. bool Add(RTTIType type, int ID);
  149. bool Abandon_Production(int factory);
  150. bool Scroll(bool up);
  151. bool AI(KeyNumType & input, int x, int y);
  152. void Draw_It(bool complete);
  153. void One_Time(int id);
  154. void Init_Clear(void);
  155. void Init_IO(int id);
  156. void Init_Theater(TheaterType theater);
  157. bool Recalc(void);
  158. void Activate(void);
  159. void Deactivate(void);
  160. void Flag_To_Redraw(void);
  161. bool Factory_Link(int factory, RTTIType type, int id);
  162. void const * Get_Special_Cameo(int type);
  163. /*
  164. ** File I/O.
  165. */
  166. bool Load(FileClass & file);
  167. bool Save(FileClass & file);
  168. void Code_Pointers(void);
  169. void Decode_Pointers(void);
  170. /*
  171. ** Working numbers used when rendering and processing the side strip.
  172. */
  173. enum SideBarGeneralEnums {
  174. BUTTON_UP=200,
  175. BUTTON_DOWN=210,
  176. BUTTON_SELECT=220,
  177. MAX_BUILDABLES=30, // Maximum number of object types in sidebar.
  178. OBJECT_HEIGHT=24, // Pixel height of each buildable object.
  179. OBJECT_WIDTH=32, // Pixel width of each buildable object.
  180. STRIP_WIDTH=35, // Width of strip (not counting border lines).
  181. MAX_VISIBLE=4, // Number of object slots visible at any one time.
  182. SCROLL_RATE=8, // The pixel jump while scrolling (larger is faster).
  183. BUTTON_SPACING_OFFSET = 4, // spacing info for buttons
  184. UP_X_OFFSET=2, // Scroll up arrow coordinates.
  185. UP_Y_OFFSET=MAX_VISIBLE*OBJECT_HEIGHT+1,
  186. DOWN_X_OFFSET=18, // Scroll down arrow coordinates.
  187. DOWN_Y_OFFSET=MAX_VISIBLE*OBJECT_HEIGHT+1,
  188. BUTTON_WIDTH=16, // Width of the mini-scroll button.
  189. BUTTON_HEIGHT=12, // Height of the mini-scroll button.
  190. //LEFT_EDGE_OFFSET=2, // Offset from left edge for building shapes.
  191. TEXT_X_OFFSET=18, // X offset to print "ready" text.
  192. TEXT_Y_OFFSET=15, // Y offset to print "ready" text.
  193. TEXT_COLOR=255, // Color to use for the "Ready" text.
  194. //BUTTON_SPACING_OFFSET = 4, // spacing info for buttons
  195. //LEFT_EDGE_OFFSET=0, // Offset from left edge for building shapes.
  196. //BUTTON_SPACING_OFFSET = 0, // spacing info for buttons
  197. };
  198. /*
  199. ** This is the coordinate of the upper left corner that this side strip
  200. ** uses for rendering.
  201. */
  202. int X,Y;
  203. /*
  204. ** This is a unique identifier for the sidebar strip. Using this identifier,
  205. ** it is possible to differentiate the button messages that arrive from the
  206. ** common input button list. It >MUST< be equal to the strip's index into
  207. ** the Column[] array, because the strip uses it to access the stripclass
  208. ** buttons.
  209. */
  210. int ID;
  211. /*
  212. ** Shape numbers for the shapes in the STRIP.SHP file.
  213. */
  214. enum SideBarStipShapeEnums {
  215. SB_BLANK, // The blank rectangle to use if there are no objects present.
  216. SB_FRAME
  217. };
  218. /*
  219. ** If this particular side strip needs to be redrawn, then this flag
  220. ** will be true.
  221. */
  222. unsigned IsToRedraw:1;
  223. /*
  224. ** If construction is in progress (no other objects in this strip can
  225. ** be started), then this flag will be true. It will be cleared when
  226. ** the strip is free to start production again.
  227. */
  228. unsigned IsBuilding:1;
  229. /*
  230. ** This controls the sidebar slide direction. If this is true, then the sidebar
  231. ** will scroll downward -- revealing previous objects.
  232. */
  233. unsigned IsScrollingDown:1;
  234. /*
  235. ** If the sidebar is scrolling, then this flag is true. Otherwise it is false.
  236. */
  237. unsigned IsScrolling:1;
  238. /*
  239. ** This is the object (sidebar slot) that is flashing. Only one slot can be flashing
  240. ** at any one instant. This is usually the result of a click on the slot and construction
  241. ** has commenced.
  242. */
  243. int Flasher;
  244. /*
  245. ** As the sidebar scrolls up and down, this variable holds the index for the topmost
  246. ** visible sidebar slot.
  247. */
  248. int TopIndex;
  249. /*
  250. ** This is the queued scroll direction and amount. The sidebar
  251. ** will scroll the number of slots indicated by this value. This
  252. ** value is set according to the scroll buttons.
  253. */
  254. int Scroller;
  255. /*
  256. ** The sidebar has smooth scrolling. This is the number of pixels the sidebar
  257. ** has slide down. Thus, if this value were 5, then there would be 5 pixels of
  258. ** the TopIndex-1 sidebar object visible. When the Slid value reaches 24, then
  259. ** the value resets to zero and the TopIndex is decremented. For sliding in the
  260. ** opposite direction, change the IsScrollingDown flag.
  261. */
  262. int Slid;
  263. /*
  264. ** This is the count of the number of sidebar slots that are active.
  265. */
  266. int BuildableCount;
  267. /*
  268. ** This is the array of buildable object types. This array is sorted in the order
  269. ** that it is to be displayed. This array keeps track of which objects are building
  270. ** and ready to be placed. The very nature of this method precludes simultaneous
  271. ** construction of the same object type.
  272. */
  273. typedef struct BuildType {
  274. int BuildableID;
  275. RTTIType BuildableType;
  276. int Factory; // Production manager.
  277. } BuildType;
  278. BuildType Buildables[MAX_BUILDABLES];
  279. /*
  280. ** Pointer to the shape data for small versions of the logos. These are used as
  281. ** placeholder pieces on the side bar.
  282. */
  283. static void const * LogoShapes;
  284. /*
  285. ** This points to the animation sequence of frames used to mark the passage of time
  286. ** as an object is undergoing construction.
  287. */
  288. static void const * ClockShapes;
  289. /*
  290. ** This points to the animation sequence which deals with special
  291. ** shapes which handle non-production based icons.
  292. */
  293. static void const * SpecialShapes[3];
  294. /*
  295. ** This is the last theater that the special palette remap table was loaded
  296. ** for. If the current theater differs from this recorded value, then the
  297. ** remap tables are reloaded.
  298. */
  299. static TheaterType LastTheater;
  300. static ShapeButtonClass UpButton[COLUMNS];
  301. static ShapeButtonClass DownButton[COLUMNS];
  302. static SelectClass SelectButton[COLUMNS][MAX_VISIBLE];
  303. /*
  304. ** This points to the shapes that are used for the clock overlay. This displays
  305. ** progress of construction.
  306. */
  307. static char ClockTranslucentTable[(1+1)*256];
  308. } Column[COLUMNS];
  309. /*
  310. ** If the sidebar is active then this flag is true.
  311. */
  312. unsigned IsSidebarActive:1;
  313. /*
  314. ** This flag tells the rendering system that the sidebar needs to be redrawn.
  315. */
  316. unsigned IsToRedraw:1;
  317. class SBGadgetClass: public GadgetClass {
  318. public:
  319. // SBGadgetClass(void) : GadgetClass(SIDE_X+8, SIDE_Y, SIDE_WIDTH-1, SIDE_HEIGHT-1, LEFTUP) {};
  320. SBGadgetClass(void) : GadgetClass(0,0,0,0,LEFTUP) {};
  321. protected:
  322. virtual int Action(unsigned flags, KeyNumType & key);
  323. };
  324. /*
  325. ** This is the button that is used to collapse and expand the sidebar.
  326. ** These buttons must be available to derived classes, for Save/Load.
  327. */
  328. static ShapeButtonClass Repair;
  329. static ShapeButtonClass Upgrade;
  330. static ShapeButtonClass Zoom;
  331. static SBGadgetClass Background;
  332. /*
  333. ** Pointer to the shape data for the sidebar
  334. */
  335. static void const * SidebarShape1;
  336. static void const * SidebarShape2;
  337. private:
  338. bool Activate_Repair(int control);
  339. bool Activate_Upgrade(int control);
  340. bool Activate_Demolish(int control);
  341. bool Scroll(bool up, int column);
  342. int Which_Column(RTTIType type);
  343. unsigned IsRepairActive:1;
  344. unsigned IsUpgradeActive:1;
  345. unsigned IsDemolishActive:1;
  346. };
  347. #endif