src/transparency_gui.cpp
branchNewGRF_ports
changeset 6878 7d1ff2f621c7
parent 6877 889301acc299
child 10184 fcf5fb2548eb
equal deleted inserted replaced
6877:889301acc299 6878:7d1ff2f621c7
    10 
    10 
    11 #include "table/sprites.h"
    11 #include "table/sprites.h"
    12 #include "table/strings.h"
    12 #include "table/strings.h"
    13 
    13 
    14 TransparencyOptionBits _transparency_opt;
    14 TransparencyOptionBits _transparency_opt;
       
    15 TransparencyOptionBits _transparency_lock;
    15 
    16 
    16 enum TransparencyToolbarWidgets{
    17 enum TransparencyToolbarWidgets{
    17 	/* Widgets not toggled when pressing the X key */
       
    18 	TTW_WIDGET_SIGNS = 3,    ///< Make signs background transparent
    18 	TTW_WIDGET_SIGNS = 3,    ///< Make signs background transparent
    19 
       
    20 	/* Widgets toggled when pressing the X key */
       
    21 	TTW_WIDGET_TREES,        ///< Make trees transparent
    19 	TTW_WIDGET_TREES,        ///< Make trees transparent
    22 	TTW_WIDGET_HOUSES,       ///< Make houses transparent
    20 	TTW_WIDGET_HOUSES,       ///< Make houses transparent
    23 	TTW_WIDGET_INDUSTRIES,   ///< Make Industries transparent
    21 	TTW_WIDGET_INDUSTRIES,   ///< Make Industries transparent
    24 	TTW_WIDGET_BUILDINGS,    ///< Make player buildings and structures transparent
    22 	TTW_WIDGET_BUILDINGS,    ///< Make player buildings and structures transparent
    25 	TTW_WIDGET_BRIDGES,      ///< Make bridges transparent
    23 	TTW_WIDGET_BRIDGES,      ///< Make bridges transparent
    26 	TTW_WIDGET_STRUCTURES,   ///< Make unmovable structures transparent
    24 	TTW_WIDGET_STRUCTURES,   ///< Make unmovable structures transparent
    27 	TTW_WIDGET_LOADING,      ///< Make loading indicators transperent
    25 	TTW_WIDGET_CATENARY,     ///< Make catenary transparent
       
    26 	TTW_WIDGET_LOADING,      ///< Make loading indicators transparent
    28 	TTW_WIDGET_END,          ///< End of toggle buttons
    27 	TTW_WIDGET_END,          ///< End of toggle buttons
    29 };
    28 };
    30 
    29 
    31 static void TransparencyToolbWndProc(Window *w, WindowEvent *e)
    30 static void TransparencyToolbWndProc(Window *w, WindowEvent *e)
    32 {
    31 {
    37 			for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_END; i++) {
    36 			for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_END; i++) {
    38 				w->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS)));
    37 				w->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS)));
    39 			}
    38 			}
    40 
    39 
    41 			DrawWindowWidgets(w);
    40 			DrawWindowWidgets(w);
       
    41 			for (uint i = TO_SIGNS; i < TO_END; i++) {
       
    42 				if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, w->widget[TTW_WIDGET_SIGNS + i].left + 1, w->widget[TTW_WIDGET_SIGNS + i].top + 1);
       
    43 			}
    42 			break;
    44 			break;
    43 
    45 
    44 		case WE_CLICK:
    46 		case WE_CLICK:
    45 			if (e->we.click.widget >= TTW_WIDGET_SIGNS) {
    47 			if (e->we.click.widget >= TTW_WIDGET_SIGNS && e->we.click.widget < TTW_WIDGET_END) {
    46 				/* toggle the bit of the transparencies variable when clicking on a widget, and play a sound */
    48 				if (_ctrl_pressed) {
    47 				ToggleTransparency((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS));
    49 					/* toggle the bit of the transparencies lock variable */
    48 				SndPlayFx(SND_15_BEEP);
    50 					ToggleTransparencyLock((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS));
    49 				MarkWholeScreenDirty();
    51 					SetWindowDirty(w);
       
    52 				} else {
       
    53 					/* toggle the bit of the transparencies variable and play a sound */
       
    54 					ToggleTransparency((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS));
       
    55 					SndPlayFx(SND_15_BEEP);
       
    56 					MarkWholeScreenDirty();
       
    57 				}
    50 			}
    58 			}
    51 			break;
    59 			break;
    52 	}
    60 	}
    53 }
    61 }
    54 
    62 
    55 static const Widget _transparency_widgets[] = {
    63 static const Widget _transparency_widgets[] = {
    56 { WWT_CLOSEBOX,   RESIZE_NONE,  7,   0,  10,   0,  13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
    64 { WWT_CLOSEBOX,   RESIZE_NONE,  7,   0,  10,   0,  13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
    57 {  WWT_CAPTION,   RESIZE_NONE,  7,  11, 184,   0,  13, STR_TRANSPARENCY_TOOLB,   STR_018C_WINDOW_TITLE_DRAG_THIS},
    65 {  WWT_CAPTION,   RESIZE_NONE,  7,  11, 206,   0,  13, STR_TRANSPARENCY_TOOLB,   STR_018C_WINDOW_TITLE_DRAG_THIS},
    58 {WWT_STICKYBOX,   RESIZE_NONE,  7, 185, 196,   0,  13, STR_NULL,                 STR_STICKY_BUTTON},
    66 {WWT_STICKYBOX,   RESIZE_NONE,  7, 207, 218,   0,  13, STR_NULL,                 STR_STICKY_BUTTON},
    59 
    67 
    60 /* transparency widgets:
    68 /* transparency widgets:
    61  * transparent signs, trees, houses, industries, player's buildings, bridges, unmovable structures and loading indicators */
    69  * transparent signs, trees, houses, industries, player's buildings, bridges, unmovable structures, catenary and loading indicators */
    62 {   WWT_IMGBTN,   RESIZE_NONE,  7,   0,  21,  14,  35, SPR_IMG_SIGN,         STR_TRANSPARENT_SIGNS_DESC},
    70 {   WWT_IMGBTN,   RESIZE_NONE,  7,   0,  21,  14,  35, SPR_IMG_SIGN,         STR_TRANSPARENT_SIGNS_DESC},
    63 {   WWT_IMGBTN,   RESIZE_NONE,  7,  22,  43,  14,  35, SPR_IMG_PLANTTREES,   STR_TRANSPARENT_TREES_DESC},
    71 {   WWT_IMGBTN,   RESIZE_NONE,  7,  22,  43,  14,  35, SPR_IMG_PLANTTREES,   STR_TRANSPARENT_TREES_DESC},
    64 {   WWT_IMGBTN,   RESIZE_NONE,  7,  44,  65,  14,  35, SPR_IMG_TOWN,         STR_TRANSPARENT_HOUSES_DESC},
    72 {   WWT_IMGBTN,   RESIZE_NONE,  7,  44,  65,  14,  35, SPR_IMG_TOWN,         STR_TRANSPARENT_HOUSES_DESC},
    65 {   WWT_IMGBTN,   RESIZE_NONE,  7,  66,  87,  14,  35, SPR_IMG_INDUSTRY,     STR_TRANSPARENT_INDUSTRIES_DESC},
    73 {   WWT_IMGBTN,   RESIZE_NONE,  7,  66,  87,  14,  35, SPR_IMG_INDUSTRY,     STR_TRANSPARENT_INDUSTRIES_DESC},
    66 {   WWT_IMGBTN,   RESIZE_NONE,  7,  88, 109,  14,  35, SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC},
    74 {   WWT_IMGBTN,   RESIZE_NONE,  7,  88, 109,  14,  35, SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC},
    67 {   WWT_IMGBTN,   RESIZE_NONE,  7, 110, 152,  14,  35, SPR_IMG_BRIDGE,       STR_TRANSPARENT_BRIDGES_DESC},
    75 {   WWT_IMGBTN,   RESIZE_NONE,  7, 110, 152,  14,  35, SPR_IMG_BRIDGE,       STR_TRANSPARENT_BRIDGES_DESC},
    68 {   WWT_IMGBTN,   RESIZE_NONE,  7, 153, 174,  14,  35, SPR_IMG_TRANSMITTER,  STR_TRANSPARENT_STRUCTURES_DESC},
    76 {   WWT_IMGBTN,   RESIZE_NONE,  7, 153, 174,  14,  35, SPR_IMG_TRANSMITTER,  STR_TRANSPARENT_STRUCTURES_DESC},
    69 {   WWT_IMGBTN,   RESIZE_NONE,  7, 175, 196,  14,  35, SPR_IMG_TRAINLIST,    STR_TRANSPARENT_LOADING_DESC},
    77 {   WWT_IMGBTN,   RESIZE_NONE,  7, 175, 196,  14,  35, SPR_BUILD_X_ELRAIL,   STR_TRANSPARENT_CATENARY_DESC},
       
    78 {   WWT_IMGBTN,   RESIZE_NONE,  7, 197, 218,  14,  35, SPR_IMG_TRAINLIST,    STR_TRANSPARENT_LOADING_DESC},
    70 
    79 
    71 {   WIDGETS_END},
    80 {   WIDGETS_END},
    72 };
    81 };
    73 
    82 
    74 static const WindowDesc _transparency_desc = {
    83 static const WindowDesc _transparency_desc = {
    75 	WDP_ALIGN_TBR, 58+36, 197, 36, 197, 36,
    84 	WDP_ALIGN_TBR, 58+36, 219, 36, 219, 36,
    76 	WC_TRANSPARENCY_TOOLBAR, WC_NONE,
    85 	WC_TRANSPARENCY_TOOLBAR, WC_NONE,
    77 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
    86 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
    78 	_transparency_widgets,
    87 	_transparency_widgets,
    79 	TransparencyToolbWndProc
    88 	TransparencyToolbWndProc
    80 };
    89 };