summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorplanetmaker <planetmaker@openttd.org>2011-08-01 18:41:21 +0000
committerplanetmaker <planetmaker@openttd.org>2011-08-01 18:41:21 +0000
commit3fb66890eeb3689e645fa6d520aecc0c0908031f (patch)
tree695d9f02f415bb5510338170b622b22dca8ea256
parent536fc4246189cb13a8848dc71bedc00a79c7031a (diff)
downloadopenttd-3fb66890eeb3689e645fa6d520aecc0c0908031f.tar.xz
(svn r22708) -Feature [FS#4701]: Display option to hide competitors' signs and station names (Zuu)
-rw-r--r--src/lang/english.txt1
-rw-r--r--src/openttd.h1
-rw-r--r--src/signs_gui.cpp21
-rw-r--r--src/table/misc_settings.ini4
-rw-r--r--src/toolbar_gui.cpp7
-rw-r--r--src/viewport.cpp8
6 files changed, 38 insertions, 4 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index bf46717f8..109a2e70a 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -356,6 +356,7 @@ STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED :Town names disp
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
diff --git a/src/openttd.h b/src/openttd.h
index b98008493..40a78c48c 100644
--- a/src/openttd.h
+++ b/src/openttd.h
@@ -45,6 +45,7 @@ enum DisplayOptions {
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;
diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp
index d64be87e1..e0ab72e01 100644
--- 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 @@ struct SignList {
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 @@ struct SignListWindow : QueryStringBaseWindow, SignList {
/* 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 @@ struct SignListWindow : QueryStringBaseWindow, SignList {
*/
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
diff --git a/src/table/misc_settings.ini b/src/table/misc_settings.ini
index 7dd85b7a5..71fc33ca0 100644
--- a/src/table/misc_settings.ini
+++ b/src/table/misc_settings.ini
@@ -37,8 +37,8 @@ to = SL_MAX_VERSION
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""
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index 7328dfeed..c59f13123 100644
--- 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 @@ enum OptionMenuEntries {
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 @@ static CallBackFunction ToolbarOptionsClick(Window *w)
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 @@ static CallBackFunction MenuClickSettings(int index)
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;
diff --git a/src/viewport.cpp b/src/viewport.cpp
index 16e6bb0b5..dcfe4cf01 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -1186,6 +1186,9 @@ static void ViewportAddStationNames(DrawPixelInfo *dpi)
/* 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 @@ static void ViewportAddSigns(DrawPixelInfo *dpi)
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,