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