Show snow on depot tiles. (Looks weird my ass)
[openttd-joker.git] / src / zoning_gui.cpp
blobb7b1a9322c55ba84815f834c4fde3081c0faa7a5
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file zoning_gui.cpp */
12 #include "stdafx.h"
13 #include "openttd.h"
14 #include "widgets/dropdown_func.h"
15 #include "widget_type.h"
16 #include "window_func.h"
17 #include "gui.h"
18 #include "viewport_func.h"
19 #include "sound_func.h"
20 #include "table/sprites.h"
21 #include "table/strings.h"
22 #include "strings_func.h"
23 #include "gfx_func.h"
24 #include "core/geometry_func.hpp"
25 #include "core/random_func.hpp"
26 #include "zoning.h"
28 enum ZoningToolbarWidgets {
29 ZTW_OUTER = 4,
30 ZTW_OUTER_DROPDOWN,
31 ZTW_INNER,
32 ZTW_INNER_DROPDOWN,
33 ZTW_CAPTION
36 static const StringID _zone_type_strings[] = {
37 STR_ZONING_NO_ZONING,
38 STR_ZONING_AUTHORITY,
39 STR_ZONING_CAN_BUILD,
40 STR_ZONING_STA_CATCH,
41 STR_ZONING_BUL_UNSER,
42 STR_ZONING_IND_UNSER,
43 STR_ZONING_TRACERESTRICT,
44 INVALID_STRING_ID
47 static const ZoningEvaluationMode _zone_type_modes[] = {
48 ZEM_NOTHING,
49 ZEM_AUTHORITY,
50 ZEM_CAN_BUILD,
51 ZEM_STA_CATCH,
52 ZEM_BUL_UNSER,
53 ZEM_IND_UNSER,
54 ZEM_TRACERESTRICT,
57 static ZoningEvaluationMode DropDownIndexToZoningEvaluationMode(int index)
59 if (index < 0 || index >= (int) lengthof(_zone_type_modes)) {
60 return ZEM_NOTHING;
62 return _zone_type_modes[index];
65 static int ZoningEvaluationModeToDropDownIndex(ZoningEvaluationMode ev_mode)
67 for (int i = 0; i < (int) lengthof(_zone_type_modes); i++) {
68 if (_zone_type_modes[i] == ev_mode) return i;
70 NOT_REACHED();
73 struct ZoningWindow : public Window {
75 ZoningWindow(WindowDesc *desc, int window_number)
76 : Window(desc)
78 this->InitNested(window_number);
79 this->InvalidateData();
82 virtual void OnPaint()
84 this->DrawWidgets();
87 virtual void OnClick(Point pt, int widget, int click_count)
89 switch (widget) {
90 case ZTW_OUTER_DROPDOWN:
91 ShowDropDownMenu(this, _zone_type_strings, ZoningEvaluationModeToDropDownIndex(_zoning.outer), ZTW_OUTER_DROPDOWN, 0, 0);
92 break;
94 case ZTW_INNER_DROPDOWN:
95 ShowDropDownMenu(this, _zone_type_strings, ZoningEvaluationModeToDropDownIndex(_zoning.inner), ZTW_INNER_DROPDOWN, 0, 0);
96 break;
100 virtual void OnDropdownSelect(int widget, int index)
102 switch(widget) {
103 case ZTW_OUTER_DROPDOWN:
104 SetZoningMode(false, DropDownIndexToZoningEvaluationMode(index));
105 break;
107 case ZTW_INNER_DROPDOWN:
108 SetZoningMode(true, DropDownIndexToZoningEvaluationMode(index));
109 break;
111 this->InvalidateData();
114 virtual void SetStringParameters(int widget) const
116 switch (widget) {
117 case ZTW_OUTER_DROPDOWN:
118 SetDParam(0, _zone_type_strings[ZoningEvaluationModeToDropDownIndex(_zoning.outer)]);
119 break;
121 case ZTW_INNER_DROPDOWN:
122 SetDParam(0, _zone_type_strings[ZoningEvaluationModeToDropDownIndex(_zoning.inner)]);
123 break;
127 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
129 const StringID *strs = nullptr;
130 switch (widget) {
131 case ZTW_OUTER_DROPDOWN:
132 case ZTW_INNER_DROPDOWN:
133 strs = _zone_type_strings;
134 break;
136 if (strs != nullptr) {
137 while (*strs != INVALID_STRING_ID) {
138 *size = maxdim(*size, GetStringBoundingBox(*strs++));
141 size->width += padding.width;
142 size->height = FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM;
146 static const NWidgetPart _nested_zoning_widgets[] = {
147 NWidget(NWID_HORIZONTAL),
148 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
149 NWidget(WWT_CAPTION, COLOUR_GREY, ZTW_CAPTION), SetDataTip(STR_ZONING_TOOLBAR, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
150 NWidget(WWT_SHADEBOX, COLOUR_GREY),
151 NWidget(WWT_STICKYBOX, COLOUR_GREY),
152 EndContainer(),
154 NWidget(WWT_PANEL, COLOUR_GREY),
155 NWidget(NWID_HORIZONTAL, COLOUR_GREY), SetPIP(10, 3, 10),
156 NWidget(NWID_VERTICAL, COLOUR_GREY), SetPadding(5, 0, 5, 0),
157 NWidget(WWT_TEXT, COLOUR_GREY), SetDataTip(STR_ZONING_OUTER, STR_NULL), SetResize(1, 0), SetPadding(1, 6, 1, 6),
158 NWidget(WWT_TEXT, COLOUR_GREY, ZTW_OUTER),
159 NWidget(WWT_TEXT, COLOUR_GREY), SetDataTip(STR_ZONING_INNER, STR_NULL), SetResize(1, 0), SetPadding(1, 6, 1, 6),
160 NWidget(WWT_TEXT, COLOUR_GREY, ZTW_INNER),
161 EndContainer(),
162 NWidget(NWID_VERTICAL, COLOUR_GREY), SetPadding(5, 0, 5, 0),
163 NWidget(WWT_DROPDOWN, COLOUR_GREY, ZTW_OUTER_DROPDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
164 NWidget(WWT_TEXT, COLOUR_GREY),
165 NWidget(WWT_DROPDOWN, COLOUR_GREY, ZTW_INNER_DROPDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
166 NWidget(WWT_TEXT, COLOUR_GREY),
167 EndContainer(),
168 EndContainer(),
169 EndContainer()
172 static WindowDesc _zoning_desc (
173 WDP_CENTER, "zoning_gui", 0, 0,
174 WC_ZONING_TOOLBAR, WC_NONE,
176 _nested_zoning_widgets, lengthof(_nested_zoning_widgets)
179 void ShowZoningToolbar()
181 AllocateWindowDescFront<ZoningWindow>(&_zoning_desc, 0);