changeset 17904:d114b7d640d4 draft

(svn r22708) -Feature [FS#4701]: Display option to hide competitors' signs and station names (Zuu)
author planetmaker <planetmaker@openttd.org>
date Mon, 01 Aug 2011 18:41:21 +0000
parents 62089c39f660
children b1f6f7bb52fa
files src/lang/english.txt src/openttd.h src/signs_gui.cpp src/table/misc_settings.ini src/toolbar_gui.cpp src/viewport.cpp
diffstat 6 files changed, 38 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -356,6 +356,7 @@
 STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED                       :Station names displayed
 STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED                           :Waypoint names displayed
 STR_SETTINGS_MENU_SIGNS_DISPLAYED                               :Signs displayed
+STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS                         :Competitor signs and names displayed
 STR_SETTINGS_MENU_FULL_ANIMATION                                :Full animation
 STR_SETTINGS_MENU_FULL_DETAIL                                   :Full detail
 STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS                         :Transparent buildings
--- a/src/openttd.h
+++ b/src/openttd.h
@@ -45,6 +45,7 @@
 	DO_FULL_ANIMATION      = 3, ///< Perform palette animation.
 	DO_FULL_DETAIL         = 5, ///< Also draw details of track and roads.
 	DO_SHOW_WAYPOINT_NAMES = 6, ///< Display waypoint names.
+	DO_SHOW_COMPETITOR_SIGNS = 7, ///< Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are always shown, even if this option is turned off.
 };
 
 extern GameMode _game_mode;
--- a/src/signs_gui.cpp
+++ b/src/signs_gui.cpp
@@ -26,6 +26,7 @@
 #include "string_func.h"
 #include "core/geometry_func.hpp"
 #include "hotkeys.h"
+#include "transparency.h"
 
 #include "table/strings.h"
 #include "table/sprites.h"
@@ -116,11 +117,22 @@
 		return (filter_info.case_sensitive ? strstr(buf1, filter_info.string) : strcasestr(buf1, filter_info.string)) != NULL;
 	}
 
+	/** Filter sign list by owner */
+	static bool CDECL OwnerVisibilityFilter(const Sign * const *a, FilterInfo filter_info)
+	{
+		assert(!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
+		/* Hide sign if non-own signs are hidden in the viewport */
+		return (*a)->owner == _local_company;
+	}
+
 	/** Filter out signs from the sign list that does not match the name filter */
 	void FilterSignList()
 	{
 		FilterInfo filter_info = {this->filter_string, this->match_case};
 		this->signs.Filter(&SignNameFilter, filter_info);
+		if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)) {
+			this->signs.Filter(&OwnerVisibilityFilter, filter_info);
+		}
 	}
 };
 
@@ -199,7 +211,7 @@
 			/* There is no new string -> clear this->filter_string */
 			this->filter_string[0] = '\0';
 
-			this->signs.SetFilterState(false);
+			this->signs.SetFilterState(!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)); // keep sign list filtering active if competitor signs should be hidden
 			this->DisableWidget(SLW_FILTER_CLEAR_BTN);
 		}
 
@@ -374,10 +386,15 @@
 	 */
 	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
 	{
+		if (data == -1) {
+			/* The DO_SHOW_COMPETITOR_SIGNS display option has changed */
+			this->signs.SetFilterState(!StrEmpty(this->filter_string) || !HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
+		}
+
 		/* When there is a filter string, we always need to rebuild the list even if
 		 * the amount of signs in total is unchanged, as the subset of signs that is
 		 * accepted by the filter might has changed. */
-		if (data == 0 || !StrEmpty(this->filter_string)) { // New or deleted sign, or there is a filter string
+		if (data == 0 || data == -1 || !StrEmpty(this->filter_string)) { // New or deleted sign, changed visibility setting or there is a filter string
 			/* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
 			this->signs.ForceRebuild();
 		} else { // Change of sign contents while there is no filter string
--- a/src/table/misc_settings.ini
+++ b/src/table/misc_settings.ini
@@ -37,8 +37,8 @@
 name     = ""display_opt""
 type     = SLE_UINT8
 var      = _display_opt
-def      = (1 << DO_SHOW_TOWN_NAMES | 1 << DO_SHOW_STATION_NAMES | 1 << DO_SHOW_SIGNS | 1 << DO_FULL_ANIMATION | 1 << DO_FULL_DETAIL | 1 << DO_SHOW_WAYPOINT_NAMES)
-full     = ""SHOW_TOWN_NAMES|SHOW_STATION_NAMES|SHOW_SIGNS|FULL_ANIMATION||FULL_DETAIL|WAYPOINTS""
+def      = (1 << DO_SHOW_TOWN_NAMES | 1 << DO_SHOW_STATION_NAMES | 1 << DO_SHOW_SIGNS | 1 << DO_FULL_ANIMATION | 1 << DO_FULL_DETAIL | 1 << DO_SHOW_WAYPOINT_NAMES | 1 << DO_SHOW_COMPETITOR_SIGNS)
+full     = ""SHOW_TOWN_NAMES|SHOW_STATION_NAMES|SHOW_SIGNS|FULL_ANIMATION||FULL_DETAIL|WAYPOINTS|SHOW_COMPETITOR_SIGNS""
 
 [SDTG_BOOL]
 name     = ""news_ticker_sound""
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -42,6 +42,7 @@
 #include "newgrf_debug.h"
 #include "hotkeys.h"
 #include "engine_base.h"
+#include "settings_type.h"
 
 #include "network/network.h"
 #include "network/network_gui.h"
@@ -302,6 +303,7 @@
 	OME_SHOW_STATIONNAMES,
 	OME_SHOW_WAYPOINTNAMES,
 	OME_SHOW_SIGNS,
+	OME_SHOW_COMPETITOR_SIGNS,
 	OME_FULL_ANIMATION,
 	OME_FULL_DETAILS,
 	OME_TRANSPARENTBUILDINGS,
@@ -331,6 +333,7 @@
 	list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES, false, HasBit(_display_opt, DO_SHOW_STATION_NAMES)));
 	list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED,     OME_SHOW_WAYPOINTNAMES, false, HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES)));
 	list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SIGNS_DISPLAYED,         OME_SHOW_SIGNS, false, HasBit(_display_opt, DO_SHOW_SIGNS)));
+	list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS,   OME_SHOW_COMPETITOR_SIGNS, false, HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)));
 	list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_ANIMATION,          OME_FULL_ANIMATION, false, HasBit(_display_opt, DO_FULL_ANIMATION)));
 	list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_DETAIL,             OME_FULL_DETAILS, false, HasBit(_display_opt, DO_FULL_DETAIL)));
 	list->push_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS,   OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES)));
@@ -361,6 +364,10 @@
 		case OME_SHOW_STATIONNAMES:    ToggleBit(_display_opt, DO_SHOW_STATION_NAMES);  break;
 		case OME_SHOW_WAYPOINTNAMES:   ToggleBit(_display_opt, DO_SHOW_WAYPOINT_NAMES); break;
 		case OME_SHOW_SIGNS:           ToggleBit(_display_opt, DO_SHOW_SIGNS);          break;
+		case OME_SHOW_COMPETITOR_SIGNS:
+			ToggleBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS);
+			InvalidateWindowClassesData(WC_SIGN_LIST, -1);
+			break;
 		case OME_FULL_ANIMATION:       ToggleBit(_display_opt, DO_FULL_ANIMATION);      break;
 		case OME_FULL_DETAILS:         ToggleBit(_display_opt, DO_FULL_DETAIL);         break;
 		case OME_TRANSPARENTBUILDINGS: ToggleTransparency(TO_HOUSES);                   break;
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -1186,6 +1186,9 @@
 		/* Don't draw if the display options are disabled */
 		if (!HasBit(_display_opt, is_station ? DO_SHOW_STATION_NAMES : DO_SHOW_WAYPOINT_NAMES)) continue;
 
+		/* Don't draw if station is owned by another company and competitor station names are hidden. Stations owned by none are never ignored. */
+		if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && _local_company != st->owner && st->owner != OWNER_NONE) continue;
+
 		ViewportAddString(dpi, ZOOM_LVL_OUT_4X, &st->sign,
 				is_station ? STR_VIEWPORT_STATION : STR_VIEWPORT_WAYPOINT,
 				(is_station ? STR_VIEWPORT_STATION : STR_VIEWPORT_WAYPOINT) + 1, STR_NULL,
@@ -1201,6 +1204,11 @@
 
 	const Sign *si;
 	FOR_ALL_SIGNS(si) {
+		/* Don't draw if sign is owned by another company and competitor signs should be hidden.
+		 * Note: It is intentional that also signs owned by OWNER_NONE are hidden. Bankrupt
+		 * companies can leave OWNER_NONE signs after them. */
+		if (!HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS) && _local_company != si->owner) continue;
+
 		ViewportAddString(dpi, ZOOM_LVL_OUT_4X, &si->sign,
 				STR_WHITE_SIGN,
 				IsTransparencySet(TO_SIGNS) ? STR_VIEWPORT_SIGN_SMALL_WHITE : STR_VIEWPORT_SIGN_SMALL_BLACK, STR_NULL,