Changeset - r23800:f8cc74842443
[Not reviewed]
master
0 10 0
Gabda - 5 years ago 2019-01-05 13:22:07
gabda87@gmail.com
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
10 files changed with 82 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/core/kdtree.hpp
Show inline comments
 
@@ -373,6 +373,17 @@ public:
 
	}
 

	
 
	/**
 
	 * Clear the tree.
 
	 */
 
	void Clear()
 
	{
 
		this->nodes.clear();
 
		this->free_list.clear();
 
		this->unbalanced = 0;
 
		return;
 
	}
 

	
 
	/**
 
	 * Reconstruct the tree with the same elements, letting it be fully balanced.
 
	 */
 
	void Rebuild()
src/lang/english.txt
Show inline comments
 
@@ -3122,6 +3122,8 @@ STR_TOWN_VIEW_RENAME_TOWN_BUTTON        
 

	
 
# Town local authority window
 
STR_LOCAL_AUTHORITY_CAPTION                                     :{WHITE}{TOWN} local authority
 
STR_LOCAL_AUTHORITY_ZONE                                        :{BLACK}Zone
 
STR_LOCAL_AUTHORITY_ZONE_TOOLTIP                                :{BLACK}Show zone within local authority boundaries
 
STR_LOCAL_AUTHORITY_COMPANY_RATINGS                             :{BLACK}Transport company ratings:
 
STR_LOCAL_AUTHORITY_COMPANY_RATING                              :{YELLOW}{COMPANY} {COMPANY_NUM}: {ORANGE}{STRING}
 
STR_LOCAL_AUTHORITY_ACTIONS_TITLE                               :{BLACK}Actions available:
src/misc.cpp
Show inline comments
 
@@ -47,6 +47,7 @@ void InitializeAirportGui();
 
void InitializeDockGui();
 
void InitializeGraphGui();
 
void InitializeObjectGui();
 
void InitializeTownGui();
 
void InitializeIndustries();
 
void InitializeObjects();
 
void InitializeTrees();
 
@@ -97,6 +98,7 @@ void InitializeGame(uint size_x, uint si
 
	InitializeDockGui();
 
	InitializeGraphGui();
 
	InitializeObjectGui();
 
	InitializeTownGui();
 
	InitializeAIGui();
 
	InitializeTrees();
 
	InitializeIndustries();
src/script/api/script_window.hpp
Show inline comments
 
@@ -2495,6 +2495,7 @@ public:
 
	/** Widgets of the #TownAuthorityWindow class. */
 
	enum TownAuthorityWidgets {
 
		WID_TA_CAPTION                               = ::WID_TA_CAPTION,                               ///< Caption of window.
 
		WID_TA_ZONE_BUTTON                           = ::WID_TA_ZONE_BUTTON,                           ///< Turn on/off showing local authority zone.
 
		WID_TA_RATING_INFO                           = ::WID_TA_RATING_INFO,                           ///< Overview with ratings for each company.
 
		WID_TA_COMMAND_LIST                          = ::WID_TA_COMMAND_LIST,                          ///< List of commands for the player.
 
		WID_TA_SCROLLBAR                             = ::WID_TA_SCROLLBAR,                             ///< Scrollbar of the list of commands.
src/town.h
Show inline comments
 
@@ -101,6 +101,8 @@ struct Town : TownPool::PoolItem<&_town_
 
	bool larger_town;                ///< if this is a larger town and should grow more quickly
 
	TownLayout layout;               ///< town specific road layout
 

	
 
	bool show_zone;                  ///< NOSAVE: mark town to show the local authority zone in the viewports
 

	
 
	std::list<PersistentStorage *> psa_list;
 

	
 
	/**
src/town_cmd.cpp
Show inline comments
 
@@ -1746,6 +1746,7 @@ static void DoCreateTown(Town *t, TileIn
 
	 * similar towns they're unlikely to grow all in one tick */
 
	t->grow_counter = t->index % TOWN_GROWTH_TICKS;
 
	t->growth_rate = TownTicksToGameTicks(250);
 
	t->show_zone = false;
 

	
 
	_town_kdtree.Insert(t->index);
 

	
src/town_gui.cpp
Show inline comments
 
@@ -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();
 
}
src/town_kdtree.h
Show inline comments
 
@@ -15,6 +15,8 @@
 

	
 
inline uint16 Kdtree_TownXYFunc(TownID tid, int dim) { return (dim == 0) ? TileX(Town::Get(tid)->xy) : TileY(Town::Get(tid)->xy); }
 
typedef Kdtree<TownID, decltype(&Kdtree_TownXYFunc), uint16, int> TownKdtree;
 

	
 
extern TownKdtree _town_kdtree;
 
extern TownKdtree _town_local_authority_kdtree;
 

	
 
#endif
src/viewport.cpp
Show inline comments
 
@@ -83,6 +83,7 @@
 
#include "window_gui.h"
 
#include "linkgraph/linkgraph_gui.h"
 
#include "viewport_kdtree.h"
 
#include "town_kdtree.h"
 
#include "viewport_sprite_sorter.h"
 
#include "bridge_map.h"
 
#include "company_base.h"
 
@@ -1039,11 +1040,48 @@ static void DrawTileHighlightType(const 
 
}
 

	
 
/**
 
 * Highlights tiles insede local authority of selected towns.
 
 * @param *ti TileInfo Tile that is being drawn
 
 */
 
static void HighlightTownLocalAuthorityTiles(const TileInfo *ti)
 
{
 
	/* Going through cases in order of computational time. */
 

	
 
	if (_town_local_authority_kdtree.Count() == 0) return;
 

	
 
	/* Tile belongs to town regardless of distance from town. */
 
	if (GetTileType(ti->tile) == MP_HOUSE) {
 
		if (!Town::GetByTile(ti->tile)->show_zone) return;
 

	
 
		DrawTileSelectionRect(ti, PALETTE_CRASH);
 
		return;
 
	}
 

	
 
	/* If the closest town in the highlighted list is far, we can stop searching. */
 
	TownID tid = _town_local_authority_kdtree.FindNearest(TileX(ti->tile), TileY(ti->tile));
 
	Town *closest_highlighted_town = Town::Get(tid);
 

	
 
	if (DistanceManhattan(ti->tile, closest_highlighted_town->xy) >= _settings_game.economy.dist_local_authority) return;
 

	
 
	/* Tile is inside of the local autrhority distance of a highlighted town,
 
	   but it is possible that a non-highlighted town is even closer. */
 
	Town *closest_town = ClosestTownFromTile(ti->tile, _settings_game.economy.dist_local_authority);
 

	
 
	if (closest_town->show_zone) {
 
		DrawTileSelectionRect(ti, PALETTE_CRASH);
 
	}
 

	
 
}
 

	
 
/**
 
 * Checks if the specified tile is selected and if so draws selection using correct selectionstyle.
 
 * @param *ti TileInfo Tile that is being drawn
 
 */
 
static void DrawTileSelection(const TileInfo *ti)
 
{
 
	/* Highlight tiles insede local authority of selected towns. */
 
	HighlightTownLocalAuthorityTiles(ti);
 

	
 
	/* Draw a red error square? */
 
	bool is_redsq = _thd.redsq == ti->tile;
 
	if (is_redsq) DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING);
src/widgets/town_widget.h
Show inline comments
 
@@ -25,6 +25,7 @@ enum TownDirectoryWidgets {
 
/** Widgets of the #TownAuthorityWindow class. */
 
enum TownAuthorityWidgets {
 
	WID_TA_CAPTION,      ///< Caption of window.
 
	WID_TA_ZONE_BUTTON,  ///< Turn on/off showing local authority zone.
 
	WID_TA_RATING_INFO,  ///< Overview with ratings for each company.
 
	WID_TA_COMMAND_LIST, ///< List of commands for the player.
 
	WID_TA_SCROLLBAR,    ///< Scrollbar of the list of commands.
0 comments (0 inline, 0 general)