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/>.
10 /** @file zoning_gui.cpp */
14 #include "widgets/dropdown_func.h"
15 #include "widget_type.h"
16 #include "window_func.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"
24 #include "core/geometry_func.hpp"
25 #include "core/random_func.hpp"
28 enum ZoningToolbarWidgets
{
36 static const StringID _zone_type_strings
[] = {
43 STR_ZONING_TRACERESTRICT
,
47 static const ZoningEvaluationMode _zone_type_modes
[] = {
57 static ZoningEvaluationMode
DropDownIndexToZoningEvaluationMode(int index
)
59 if (index
< 0 || index
>= (int) lengthof(_zone_type_modes
)) {
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
;
73 struct ZoningWindow
: public Window
{
75 ZoningWindow(WindowDesc
*desc
, int window_number
)
78 this->InitNested(window_number
);
79 this->InvalidateData();
82 virtual void OnPaint()
87 virtual void OnClick(Point pt
, int widget
, int click_count
)
90 case ZTW_OUTER_DROPDOWN
:
91 ShowDropDownMenu(this, _zone_type_strings
, ZoningEvaluationModeToDropDownIndex(_zoning
.outer
), ZTW_OUTER_DROPDOWN
, 0, 0);
94 case ZTW_INNER_DROPDOWN
:
95 ShowDropDownMenu(this, _zone_type_strings
, ZoningEvaluationModeToDropDownIndex(_zoning
.inner
), ZTW_INNER_DROPDOWN
, 0, 0);
100 virtual void OnDropdownSelect(int widget
, int index
)
103 case ZTW_OUTER_DROPDOWN
:
104 SetZoningMode(false, DropDownIndexToZoningEvaluationMode(index
));
107 case ZTW_INNER_DROPDOWN
:
108 SetZoningMode(true, DropDownIndexToZoningEvaluationMode(index
));
111 this->InvalidateData();
114 virtual void SetStringParameters(int widget
) const
117 case ZTW_OUTER_DROPDOWN
:
118 SetDParam(0, _zone_type_strings
[ZoningEvaluationModeToDropDownIndex(_zoning
.outer
)]);
121 case ZTW_INNER_DROPDOWN
:
122 SetDParam(0, _zone_type_strings
[ZoningEvaluationModeToDropDownIndex(_zoning
.inner
)]);
127 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
129 const StringID
*strs
= NULL
;
131 case ZTW_OUTER_DROPDOWN
:
132 case ZTW_INNER_DROPDOWN
:
133 strs
= _zone_type_strings
;
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
),
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
),
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
),
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);