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 TransparencyOptionBits _transparency_lock; |
|
16 TransparencyOptionBits _invisibility_opt; |
16 |
17 |
17 enum TransparencyToolbarWidgets{ |
18 enum TransparencyToolbarWidgets{ |
18 TTW_WIDGET_SIGNS = 3, ///< Make signs background transparent |
19 TTW_WIDGET_SIGNS = 3, ///< Make signs background transparent |
19 TTW_WIDGET_TREES, ///< Make trees transparent |
20 TTW_WIDGET_TREES, ///< Make trees transparent |
20 TTW_WIDGET_HOUSES, ///< Make houses transparent |
21 TTW_WIDGET_HOUSES, ///< Make houses transparent |
23 TTW_WIDGET_BRIDGES, ///< Make bridges transparent |
24 TTW_WIDGET_BRIDGES, ///< Make bridges transparent |
24 TTW_WIDGET_STRUCTURES, ///< Make unmovable structures transparent |
25 TTW_WIDGET_STRUCTURES, ///< Make unmovable structures transparent |
25 TTW_WIDGET_CATENARY, ///< Make catenary transparent |
26 TTW_WIDGET_CATENARY, ///< Make catenary transparent |
26 TTW_WIDGET_LOADING, ///< Make loading indicators transparent |
27 TTW_WIDGET_LOADING, ///< Make loading indicators transparent |
27 TTW_WIDGET_END, ///< End of toggle buttons |
28 TTW_WIDGET_END, ///< End of toggle buttons |
|
29 |
|
30 /* Panel with buttons for invisibility */ |
|
31 TTW_BUTTONS = 12, ///< Panel with 'invisibility' buttons |
28 }; |
32 }; |
29 |
33 |
30 static void TransparencyToolbWndProc(Window *w, WindowEvent *e) |
34 static void TransparencyToolbWndProc(Window *w, WindowEvent *e) |
31 { |
35 { |
32 switch (e->event) { |
36 switch (e->event) { |
39 |
43 |
40 DrawWindowWidgets(w); |
44 DrawWindowWidgets(w); |
41 for (uint i = TO_SIGNS; i < TO_END; i++) { |
45 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); |
46 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 } |
47 } |
|
48 |
|
49 /* Do not draw button for invisible loading indicators */ |
|
50 for (uint i = 0; i < 8; i++) { |
|
51 if (i < TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) { |
|
52 DrawFrameRect(i * 22, 38, i * 22 + 19, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); |
|
53 } else if (i == TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) { |
|
54 DrawFrameRect(i * 22, 38, i * 22 + 41, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); |
|
55 } else { // i > TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS |
|
56 DrawFrameRect((i + 1) * 22, 38, (i + 1) * 22 + 19, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); |
|
57 } |
|
58 } |
|
59 |
44 break; |
60 break; |
45 |
61 |
46 case WE_CLICK: |
62 case WE_CLICK: |
47 if (e->we.click.widget >= TTW_WIDGET_SIGNS && e->we.click.widget < TTW_WIDGET_END) { |
63 if (e->we.click.widget >= TTW_WIDGET_SIGNS && e->we.click.widget < TTW_WIDGET_END) { |
48 if (_ctrl_pressed) { |
64 if (_ctrl_pressed) { |
53 /* toggle the bit of the transparencies variable and play a sound */ |
69 /* toggle the bit of the transparencies variable and play a sound */ |
54 ToggleTransparency((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS)); |
70 ToggleTransparency((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS)); |
55 SndPlayFx(SND_15_BEEP); |
71 SndPlayFx(SND_15_BEEP); |
56 MarkWholeScreenDirty(); |
72 MarkWholeScreenDirty(); |
57 } |
73 } |
|
74 } else if (e->we.click.widget == TTW_BUTTONS) { |
|
75 uint x = e->we.click.pt.x / 22; |
|
76 |
|
77 if (x > TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) x--; |
|
78 if (x > TTW_WIDGET_CATENARY - TTW_WIDGET_SIGNS) break; |
|
79 |
|
80 ToggleInvisibility((TransparencyOption)x); |
|
81 SndPlayFx(SND_15_BEEP); |
|
82 |
|
83 /* Redraw whole screen only if transparency is set */ |
|
84 if (IsTransparencySet((TransparencyOption)x)) { |
|
85 MarkWholeScreenDirty(); |
|
86 } else { |
|
87 w->InvalidateWidget(TTW_BUTTONS); |
|
88 } |
58 } |
89 } |
|
90 |
59 break; |
91 break; |
60 } |
92 } |
61 } |
93 } |
62 |
94 |
63 static const Widget _transparency_widgets[] = { |
95 static const Widget _transparency_widgets[] = { |
75 { WWT_IMGBTN, RESIZE_NONE, 7, 110, 152, 14, 35, SPR_IMG_BRIDGE, STR_TRANSPARENT_BRIDGES_DESC}, |
107 { WWT_IMGBTN, RESIZE_NONE, 7, 110, 152, 14, 35, SPR_IMG_BRIDGE, STR_TRANSPARENT_BRIDGES_DESC}, |
76 { WWT_IMGBTN, RESIZE_NONE, 7, 153, 174, 14, 35, SPR_IMG_TRANSMITTER, STR_TRANSPARENT_STRUCTURES_DESC}, |
108 { WWT_IMGBTN, RESIZE_NONE, 7, 153, 174, 14, 35, SPR_IMG_TRANSMITTER, STR_TRANSPARENT_STRUCTURES_DESC}, |
77 { WWT_IMGBTN, RESIZE_NONE, 7, 175, 196, 14, 35, SPR_BUILD_X_ELRAIL, STR_TRANSPARENT_CATENARY_DESC}, |
109 { 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}, |
110 { WWT_IMGBTN, RESIZE_NONE, 7, 197, 218, 14, 35, SPR_IMG_TRAINLIST, STR_TRANSPARENT_LOADING_DESC}, |
79 |
111 |
|
112 { WWT_PANEL, RESIZE_NONE, 7, 0, 218, 36, 48, 0x0, STR_TRANSPARENT_INVISIBLE_DESC}, |
|
113 |
80 { WIDGETS_END}, |
114 { WIDGETS_END}, |
81 }; |
115 }; |
82 |
116 |
83 static const WindowDesc _transparency_desc = { |
117 static const WindowDesc _transparency_desc = { |
84 WDP_ALIGN_TBR, 58+36, 219, 36, 219, 36, |
118 WDP_ALIGN_TBR, 58+36, 219, 49, 219, 49, |
85 WC_TRANSPARENCY_TOOLBAR, WC_NONE, |
119 WC_TRANSPARENCY_TOOLBAR, WC_NONE, |
86 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, |
120 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, |
87 _transparency_widgets, |
121 _transparency_widgets, |
88 TransparencyToolbWndProc |
122 TransparencyToolbWndProc |
89 }; |
123 }; |