glx@9574: /* $Id$ */ glx@9574: rubidium@10455: /** @file transparency_gui.cpp The transparency GUI. */ rubidium@10455: glx@9574: #include "stdafx.h" glx@9574: #include "openttd.h" glx@9574: #include "gui.h" rubidium@9723: #include "window_gui.h" glx@9574: #include "variables.h" rubidium@9722: #include "transparency.h" rubidium@9723: #include "sound_func.h" rubidium@9722: rubidium@9724: #include "table/sprites.h" rubidium@9724: #include "table/strings.h" rubidium@9724: rubidium@9722: TransparencyOptionBits _transparency_opt; glx@9732: TransparencyOptionBits _transparency_lock; rubidium@9869: TransparencyOptionBits _invisibility_opt; glx@9574: glx@10645: class TransparenciesWindow : public Window glx@9574: { glx@10645: enum TransparencyToolbarWidgets{ glx@10645: TTW_WIDGET_SIGNS = 3, ///< Make signs background transparent glx@10645: TTW_WIDGET_TREES, ///< Make trees transparent glx@10645: TTW_WIDGET_HOUSES, ///< Make houses transparent glx@10645: TTW_WIDGET_INDUSTRIES, ///< Make Industries transparent glx@10645: TTW_WIDGET_BUILDINGS, ///< Make player buildings and structures transparent glx@10645: TTW_WIDGET_BRIDGES, ///< Make bridges transparent glx@10645: TTW_WIDGET_STRUCTURES, ///< Make unmovable structures transparent glx@10645: TTW_WIDGET_CATENARY, ///< Make catenary transparent glx@10645: TTW_WIDGET_LOADING, ///< Make loading indicators transparent glx@10645: TTW_WIDGET_END, ///< End of toggle buttons rubidium@9869: glx@10645: /* Panel with buttons for invisibility */ glx@10645: TTW_BUTTONS = 12, ///< Panel with 'invisibility' buttons glx@10645: }; glx@9574: glx@10645: public: glx@10645: TransparenciesWindow(const WindowDesc *desc, int window_number) : Window(desc, window_number) glx@10645: { glx@10645: this->FindWindowPlacementAndResize(desc); glx@10645: } rubidium@9869: glx@10645: virtual void OnPaint() glx@10645: { glx@10645: /* must be sure that the widgets show the transparency variable changes glx@10645: * also when we use shortcuts */ glx@10645: for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_END; i++) { glx@10645: this->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS))); glx@10645: } rubidium@9869: glx@10645: this->DrawWidgets(); glx@10645: for (uint i = TO_SIGNS; i < TO_END; i++) { glx@10645: if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, this->widget[TTW_WIDGET_SIGNS + i].left + 1, this->widget[TTW_WIDGET_SIGNS + i].top + 1); glx@10645: } glx@10645: glx@10645: /* Do not draw button for invisible loading indicators */ glx@10645: for (uint i = 0; i < 8; i++) { glx@10645: if (i < TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) { glx@10645: DrawFrameRect(i * 22, 38, i * 22 + 19, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); glx@10645: } else if (i == TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) { glx@10645: DrawFrameRect(i * 22, 38, i * 22 + 41, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); glx@10645: } else { // i > TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS glx@10645: DrawFrameRect((i + 1) * 22, 38, (i + 1) * 22 + 19, 46, true, HasBit(_invisibility_opt, i) ? FR_LOWERED : FR_NONE); glx@9574: } glx@10645: } glx@10645: } rubidium@9869: glx@10645: virtual void OnClick(Point pt, int widget) glx@10645: { glx@10645: if (widget >= TTW_WIDGET_SIGNS && widget < TTW_WIDGET_END) { glx@10645: if (_ctrl_pressed) { glx@10645: /* toggle the bit of the transparencies lock variable */ glx@10645: ToggleTransparencyLock((TransparencyOption)(widget - TTW_WIDGET_SIGNS)); glx@10645: this->SetDirty(); glx@10645: } else { glx@10645: /* toggle the bit of the transparencies variable and play a sound */ glx@10645: ToggleTransparency((TransparencyOption)(widget - TTW_WIDGET_SIGNS)); glx@10645: SndPlayFx(SND_15_BEEP); glx@10645: MarkWholeScreenDirty(); glx@10645: } glx@10645: } else if (widget == TTW_BUTTONS) { glx@10645: uint x = pt.x / 22; glx@10645: glx@10645: if (x > TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) x--; glx@10645: if (x > TTW_WIDGET_CATENARY - TTW_WIDGET_SIGNS) return; glx@10645: glx@10645: ToggleInvisibility((TransparencyOption)x); glx@10645: SndPlayFx(SND_15_BEEP); glx@10645: glx@10645: /* Redraw whole screen only if transparency is set */ glx@10645: if (IsTransparencySet((TransparencyOption)x)) { glx@10645: MarkWholeScreenDirty(); glx@10645: } else { glx@10645: this->InvalidateWidget(TTW_BUTTONS); glx@10645: } glx@10645: } glx@9574: } glx@10645: }; glx@9574: glx@9574: static const Widget _transparency_widgets[] = { glx@9574: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, glx@9732: { WWT_CAPTION, RESIZE_NONE, 7, 11, 206, 0, 13, STR_TRANSPARENCY_TOOLB, STR_018C_WINDOW_TITLE_DRAG_THIS}, glx@9732: {WWT_STICKYBOX, RESIZE_NONE, 7, 207, 218, 0, 13, STR_NULL, STR_STICKY_BUTTON}, glx@9574: rubidium@9601: /* transparency widgets: rubidium@9826: * transparent signs, trees, houses, industries, player's buildings, bridges, unmovable structures, catenary and loading indicators */ rubidium@9620: { WWT_IMGBTN, RESIZE_NONE, 7, 0, 21, 14, 35, SPR_IMG_SIGN, STR_TRANSPARENT_SIGNS_DESC}, glx@9574: { WWT_IMGBTN, RESIZE_NONE, 7, 22, 43, 14, 35, SPR_IMG_PLANTTREES, STR_TRANSPARENT_TREES_DESC}, glx@9574: { WWT_IMGBTN, RESIZE_NONE, 7, 44, 65, 14, 35, SPR_IMG_TOWN, STR_TRANSPARENT_HOUSES_DESC}, glx@9574: { WWT_IMGBTN, RESIZE_NONE, 7, 66, 87, 14, 35, SPR_IMG_INDUSTRY, STR_TRANSPARENT_INDUSTRIES_DESC}, glx@9574: { WWT_IMGBTN, RESIZE_NONE, 7, 88, 109, 14, 35, SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC}, glx@9574: { WWT_IMGBTN, RESIZE_NONE, 7, 110, 152, 14, 35, SPR_IMG_BRIDGE, STR_TRANSPARENT_BRIDGES_DESC}, glx@9574: { WWT_IMGBTN, RESIZE_NONE, 7, 153, 174, 14, 35, SPR_IMG_TRANSMITTER, STR_TRANSPARENT_STRUCTURES_DESC}, glx@9732: { WWT_IMGBTN, RESIZE_NONE, 7, 175, 196, 14, 35, SPR_BUILD_X_ELRAIL, STR_TRANSPARENT_CATENARY_DESC}, glx@9732: { WWT_IMGBTN, RESIZE_NONE, 7, 197, 218, 14, 35, SPR_IMG_TRAINLIST, STR_TRANSPARENT_LOADING_DESC}, glx@9574: rubidium@9869: { WWT_PANEL, RESIZE_NONE, 7, 0, 218, 36, 48, 0x0, STR_TRANSPARENT_INVISIBLE_DESC}, rubidium@9869: glx@9574: { WIDGETS_END}, glx@9574: }; glx@9574: glx@9574: static const WindowDesc _transparency_desc = { rubidium@9869: WDP_ALIGN_TBR, 58+36, 219, 49, 219, 49, glx@9574: WC_TRANSPARENCY_TOOLBAR, WC_NONE, glx@9574: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, glx@9574: _transparency_widgets, glx@9574: }; glx@9574: glx@9574: void ShowTransparencyToolbar(void) glx@9574: { glx@10645: AllocateWindowDescFront(&_transparency_desc, 0); glx@9574: }