CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

TAB.CPP (16069B)


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