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