2015-08-02 11:29:04 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2015-08-02 09:57:53 +00:00
|
|
|
|
|
|
|
/** @file zoning_gui.cpp */
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "openttd.h"
|
|
|
|
#include "widgets/dropdown_func.h"
|
|
|
|
#include "widget_type.h"
|
|
|
|
#include "window_func.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "viewport_func.h"
|
|
|
|
#include "sound_func.h"
|
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/strings.h"
|
|
|
|
#include "strings_func.h"
|
|
|
|
#include "gfx_func.h"
|
|
|
|
#include "core/geometry_func.hpp"
|
|
|
|
#include "core/random_func.hpp"
|
|
|
|
#include "zoning.h"
|
|
|
|
|
|
|
|
enum ZoningToolbarWidgets {
|
|
|
|
ZTW_OUTER = 4,
|
2015-08-02 11:29:04 +00:00
|
|
|
ZTW_OUTER_DROPDOWN,
|
2015-08-02 09:57:53 +00:00
|
|
|
ZTW_INNER,
|
|
|
|
ZTW_INNER_DROPDOWN,
|
|
|
|
ZTW_CAPTION
|
|
|
|
};
|
|
|
|
|
2015-08-02 11:29:04 +00:00
|
|
|
static const StringID _zone_type_strings[] = {
|
|
|
|
STR_ZONING_NO_ZONING,
|
|
|
|
STR_ZONING_AUTHORITY,
|
|
|
|
STR_ZONING_CAN_BUILD,
|
|
|
|
STR_ZONING_STA_CATCH,
|
2016-01-01 12:17:11 +00:00
|
|
|
STR_ZONING_STA_CATCH_OPEN,
|
2015-08-02 11:29:04 +00:00
|
|
|
STR_ZONING_BUL_UNSER,
|
|
|
|
STR_ZONING_IND_UNSER,
|
2015-10-14 23:23:46 +00:00
|
|
|
STR_ZONING_TRACERESTRICT,
|
2018-10-06 12:01:01 +00:00
|
|
|
STR_ZONING_2x2_GRID,
|
|
|
|
STR_ZONING_3x3_GRID,
|
2020-10-26 03:45:35 +00:00
|
|
|
STR_ZONING_ONE_WAY_ROAD,
|
2015-08-02 11:29:04 +00:00
|
|
|
INVALID_STRING_ID
|
|
|
|
};
|
|
|
|
|
|
|
|
static const ZoningEvaluationMode _zone_type_modes[] = {
|
|
|
|
ZEM_NOTHING,
|
|
|
|
ZEM_AUTHORITY,
|
|
|
|
ZEM_CAN_BUILD,
|
|
|
|
ZEM_STA_CATCH,
|
2016-01-01 12:17:11 +00:00
|
|
|
ZEM_STA_CATCH_WIN,
|
2015-08-02 11:29:04 +00:00
|
|
|
ZEM_BUL_UNSER,
|
|
|
|
ZEM_IND_UNSER,
|
2015-10-14 23:23:46 +00:00
|
|
|
ZEM_TRACERESTRICT,
|
2018-10-06 12:01:01 +00:00
|
|
|
ZEM_2x2_GRID,
|
|
|
|
ZEM_3x3_GRID,
|
2020-10-26 03:45:35 +00:00
|
|
|
ZEM_ONE_WAY_ROAD,
|
2015-08-02 11:29:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static ZoningEvaluationMode DropDownIndexToZoningEvaluationMode(int index)
|
|
|
|
{
|
|
|
|
if (index < 0 || index >= (int) lengthof(_zone_type_modes)) {
|
|
|
|
return ZEM_NOTHING;
|
|
|
|
}
|
|
|
|
return _zone_type_modes[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ZoningEvaluationModeToDropDownIndex(ZoningEvaluationMode ev_mode)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < (int) lengthof(_zone_type_modes); i++) {
|
|
|
|
if (_zone_type_modes[i] == ev_mode) return i;
|
|
|
|
}
|
|
|
|
NOT_REACHED();
|
|
|
|
}
|
2015-08-02 09:57:53 +00:00
|
|
|
|
|
|
|
struct ZoningWindow : public Window {
|
2015-08-02 11:29:04 +00:00
|
|
|
|
|
|
|
ZoningWindow(WindowDesc *desc, int window_number)
|
|
|
|
: Window(desc)
|
|
|
|
{
|
|
|
|
this->InitNested(window_number);
|
|
|
|
this->InvalidateData();
|
2015-08-02 09:57:53 +00:00
|
|
|
}
|
2015-08-02 11:29:04 +00:00
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
2015-08-02 09:57:53 +00:00
|
|
|
this->DrawWidgets();
|
|
|
|
}
|
2015-08-02 11:29:04 +00:00
|
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2015-08-02 09:57:53 +00:00
|
|
|
case ZTW_OUTER_DROPDOWN:
|
2015-08-02 11:29:04 +00:00
|
|
|
ShowDropDownMenu(this, _zone_type_strings, ZoningEvaluationModeToDropDownIndex(_zoning.outer), ZTW_OUTER_DROPDOWN, 0, 0);
|
2015-08-02 09:57:53 +00:00
|
|
|
break;
|
2015-08-02 11:29:04 +00:00
|
|
|
|
2015-08-02 09:57:53 +00:00
|
|
|
case ZTW_INNER_DROPDOWN:
|
2015-08-02 11:29:04 +00:00
|
|
|
ShowDropDownMenu(this, _zone_type_strings, ZoningEvaluationModeToDropDownIndex(_zoning.inner), ZTW_INNER_DROPDOWN, 0, 0);
|
2015-08-02 09:57:53 +00:00
|
|
|
break;
|
2015-08-02 11:29:04 +00:00
|
|
|
}
|
2015-08-02 09:57:53 +00:00
|
|
|
}
|
2015-08-02 11:29:04 +00:00
|
|
|
|
|
|
|
virtual void OnDropdownSelect(int widget, int index)
|
|
|
|
{
|
2015-08-02 09:57:53 +00:00
|
|
|
switch(widget) {
|
|
|
|
case ZTW_OUTER_DROPDOWN:
|
2018-01-22 17:49:53 +00:00
|
|
|
SetZoningMode(false, DropDownIndexToZoningEvaluationMode(index));
|
2015-08-02 09:57:53 +00:00
|
|
|
break;
|
2015-08-02 11:29:04 +00:00
|
|
|
|
2015-08-02 09:57:53 +00:00
|
|
|
case ZTW_INNER_DROPDOWN:
|
2018-01-22 17:49:53 +00:00
|
|
|
SetZoningMode(true, DropDownIndexToZoningEvaluationMode(index));
|
2015-08-02 09:57:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
this->InvalidateData();
|
|
|
|
}
|
2015-08-02 11:29:04 +00:00
|
|
|
|
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
|
|
|
case ZTW_OUTER_DROPDOWN:
|
|
|
|
SetDParam(0, _zone_type_strings[ZoningEvaluationModeToDropDownIndex(_zoning.outer)]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZTW_INNER_DROPDOWN:
|
|
|
|
SetDParam(0, _zone_type_strings[ZoningEvaluationModeToDropDownIndex(_zoning.inner)]);
|
|
|
|
break;
|
2015-08-02 09:57:53 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-02 11:29:04 +00:00
|
|
|
|
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
|
|
|
{
|
2019-04-11 17:14:13 +00:00
|
|
|
const StringID *strs = nullptr;
|
2015-08-02 11:29:04 +00:00
|
|
|
switch (widget) {
|
|
|
|
case ZTW_OUTER_DROPDOWN:
|
|
|
|
case ZTW_INNER_DROPDOWN:
|
|
|
|
strs = _zone_type_strings;
|
|
|
|
break;
|
2015-08-02 09:57:53 +00:00
|
|
|
}
|
2019-04-11 17:14:13 +00:00
|
|
|
if (strs != nullptr) {
|
2015-08-02 11:29:04 +00:00
|
|
|
while (*strs != INVALID_STRING_ID) {
|
2015-08-02 09:57:53 +00:00
|
|
|
*size = maxdim(*size, GetStringBoundingBox(*strs++));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
size->width += padding.width;
|
|
|
|
size->height = FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const NWidgetPart _nested_zoning_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, ZTW_CAPTION), SetDataTip(STR_ZONING_TOOLBAR, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
|
|
|
|
NWidget(WWT_SHADEBOX, COLOUR_GREY),
|
|
|
|
NWidget(WWT_STICKYBOX, COLOUR_GREY),
|
|
|
|
EndContainer(),
|
2015-08-02 11:29:04 +00:00
|
|
|
|
2015-08-02 09:57:53 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY),
|
2015-08-02 11:29:04 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, COLOUR_GREY), SetPIP(10, 3, 10),
|
2015-08-02 09:57:53 +00:00
|
|
|
NWidget(NWID_VERTICAL, COLOUR_GREY), SetPadding(5, 0, 5, 0),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_GREY), SetDataTip(STR_ZONING_OUTER, STR_NULL), SetResize(1, 0), SetPadding(1, 6, 1, 6),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_GREY, ZTW_OUTER),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_GREY), SetDataTip(STR_ZONING_INNER, STR_NULL), SetResize(1, 0), SetPadding(1, 6, 1, 6),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_GREY, ZTW_INNER),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_VERTICAL, COLOUR_GREY), SetPadding(5, 0, 5, 0),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_GREY, ZTW_OUTER_DROPDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_GREY),
|
|
|
|
NWidget(WWT_DROPDOWN, COLOUR_GREY, ZTW_INNER_DROPDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
|
|
|
|
NWidget(WWT_TEXT, COLOUR_GREY),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer()
|
|
|
|
};
|
|
|
|
|
2015-08-02 11:29:04 +00:00
|
|
|
static WindowDesc _zoning_desc (
|
|
|
|
WDP_CENTER, "zoning_gui", 0, 0,
|
2015-08-02 09:57:53 +00:00
|
|
|
WC_ZONING_TOOLBAR, WC_NONE,
|
|
|
|
0,
|
|
|
|
_nested_zoning_widgets, lengthof(_nested_zoning_widgets)
|
|
|
|
);
|
|
|
|
|
2015-08-02 11:29:04 +00:00
|
|
|
void ShowZoningToolbar()
|
|
|
|
{
|
2015-08-02 09:57:53 +00:00
|
|
|
AllocateWindowDescFront<ZoningWindow>(&_zoning_desc, 0);
|
|
|
|
}
|