summaryrefslogtreecommitdiff
path: root/src/town_gui.cpp
diff options
context:
space:
mode:
authorGabda <gabda87@gmail.com>2019-01-05 14:22:07 +0100
committerCharles Pigott <charlespigott@googlemail.com>2019-08-17 21:45:20 +0100
commitb870596f153c17d9aa915ca67b8f6414d73cb31f (patch)
treee1d321b8a5987a6a4511b61e160b73af890a332a /src/town_gui.cpp
parentd986f01d078553640528e2d334627bf552a60931 (diff)
downloadopenttd-b870596f153c17d9aa915ca67b8f6414d73cb31f.tar.xz
Add #6887: Option to show zone inside local authority boundary of towns
Can be found at town information > local authority window Layout for button is same as Graph Keys Turn on/off for every town individually
Diffstat (limited to 'src/town_gui.cpp')
-rw-r--r--src/town_gui.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index f9670e84e..0436e87e0 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -33,6 +33,7 @@
#include "genworld.h"
#include "stringfilter_type.h"
#include "widgets/dropdown_func.h"
+#include "town_kdtree.h"
#include "widgets/town_widget.h"
@@ -40,12 +41,15 @@
#include "safeguards.h"
+TownKdtree _town_local_authority_kdtree(&Kdtree_TownXYFunc);
+
typedef GUIList<const Town*> GUITownList;
static const NWidgetPart _nested_town_authority_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TA_CAPTION), SetDataTip(STR_LOCAL_AUTHORITY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
+ NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TA_ZONE_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_LOCAL_AUTHORITY_ZONE, STR_LOCAL_AUTHORITY_ZONE_TOOLTIP),
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
@@ -113,6 +117,7 @@ public:
this->sel_index = -1;
}
+ this->SetWidgetLoweredState(WID_TA_ZONE_BUTTON, this->town->show_zone);
this->SetWidgetDisabledState(WID_TA_EXECUTE, this->sel_index == -1);
this->DrawWidgets();
@@ -258,6 +263,18 @@ public:
void OnClick(Point pt, int widget, int click_count) override
{
switch (widget) {
+ case WID_TA_ZONE_BUTTON: {
+ bool new_show_state = !this->town->show_zone;
+ TownID index = this->town->index;
+
+ new_show_state ? _town_local_authority_kdtree.Insert(index) : _town_local_authority_kdtree.Remove(index);
+
+ this->town->show_zone = new_show_state;
+ this->SetWidgetLoweredState(widget, new_show_state);
+ MarkWholeScreenDirty();
+ break;
+ }
+
case WID_TA_COMMAND_LIST: {
int y = this->GetRowFromWidget(pt.y, WID_TA_COMMAND_LIST, 1, FONT_HEIGHT_NORMAL);
if (!IsInsideMM(y, 0, 5)) return;
@@ -1274,3 +1291,8 @@ void ShowFoundTownWindow()
if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
AllocateWindowDescFront<FoundTownWindow>(&_found_town_desc, 0);
}
+
+void InitializeTownGui()
+{
+ _town_local_authority_kdtree.Clear();
+}