changeset 17645:a758139e348a draft

(svn r22417) -Add: an advanced setting to specify the default palette to use for NewGRFs without action 14 palette information; this makes the default choice independent from the used base graphics and '-i' option.
author frosch <frosch@openttd.org>
date Tue, 03 May 2011 20:30:26 +0000
parents 87028d4260be
children b729cf1c478e
files src/gfxinit.cpp src/lang/english.txt src/newgrf_config.cpp src/settings_gui.cpp src/settings_type.h src/table/settings.ini
diffstat 6 files changed, 33 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/gfxinit.cpp
+++ b/src/gfxinit.cpp
@@ -181,11 +181,14 @@
 
 	/* We know the palette of the base set, so if the base NewGRF is not
 	 * setting one, use the palette of the base set and not the global
-	 * one which might be the wrong palette for this base NewGRF. */
-	PaletteType old_palette_type = _use_palette;
-	_use_palette = used_set->palette;
+	 * one which might be the wrong palette for this base NewGRF.
+	 * The value set here might be overridden via action14 later. */
+	switch (_use_palette) {
+		case PAL_DOS:     master->palette |= GRFP_GRF_DOS;     break;
+		case PAL_WINDOWS: master->palette |= GRFP_GRF_WINDOWS; break;
+		default: break;
+	}
 	FillGRFDetails(master, false);
-	_use_palette = old_palette_type;
 
 	ClrBit(master->flags, GCF_INIT_ONLY);
 	master->next = top;
@@ -263,8 +266,6 @@
 template <class T, size_t Tnum_files, Subdirectory Tsubdir>
 /* static */ const char * const *BaseSet<T, Tnum_files, Tsubdir>::file_names = _graphics_file_names;
 
-extern void UpdateNewGRFConfigPalette();
-
 /**
  * Determine the palette that has to be used.
  *  - forced palette via command line -> leave it that way
@@ -289,8 +290,6 @@
 		default:
 			NOT_REACHED();
 	}
-
-	UpdateNewGRFConfigPalette();
 }
 
 template <class Tbase_set>
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -1223,6 +1223,10 @@
 STR_CONFIG_SETTING_DATE_FORMAT_IN_SAVE_NAMES_SHORT              :short (31-12-2008)
 STR_CONFIG_SETTING_DATE_FORMAT_IN_SAVE_NAMES_ISO                :ISO (2008-12-31)
 
+STR_CONFIG_SETTING_NEWGRF_DEFAULT_PALETTE                       :{LTBLUE}Default palette to assume for NewGRFs not specifying a palette: {ORANGE}{STRING1}
+STR_CONFIG_SETTING_NEWGRF_DEFAULT_PALETTE_DOS                   :DOS palette
+STR_CONFIG_SETTING_NEWGRF_DEFAULT_PALETTE_WIN                   :Windows palette
+
 STR_CONFIG_SETTING_PAUSE_ON_NEW_GAME                            :{LTBLUE}Automatically pause when starting a new game: {ORANGE}{STRING1}
 STR_CONFIG_SETTING_COMMAND_PAUSE_LEVEL                          :{LTBLUE}When paused allow: {ORANGE}{STRING1}
 STR_CONFIG_SETTING_COMMAND_PAUSE_LEVEL_NO_ACTIONS               :no actions
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -141,7 +141,7 @@
 	switch (this->palette & GRFP_GRF_MASK) {
 		case GRFP_GRF_DOS:     pal = PAL_DOS;      break;
 		case GRFP_GRF_WINDOWS: pal = PAL_WINDOWS;  break;
-		default:               pal = _use_palette; break;
+		default:               pal = _settings_client.gui.newgrf_default_palette == 1 ? PAL_WINDOWS : PAL_DOS; break;
 	}
 	SB(this->palette, GRFP_USE_BIT, 1, pal == PAL_WINDOWS ? GRFP_USE_WINDOWS : GRFP_USE_DOS);
 }
@@ -265,16 +265,16 @@
 
 /**
  * Update the palettes of the graphics from the config file.
- * This is needed because the config file gets read and parsed
- * before the palette is chosen (one can configure the base
- * graphics set governing the palette in the config after all).
- * As a result of this we update the settings from the config
- * once we have determined the palette.
+ * Called when changing the default palette in advanced settings.
+ * @param p1 Unused.
+ * @return Always true.
  */
-void UpdateNewGRFConfigPalette()
+bool UpdateNewGRFConfigPalette(int32 p1)
 {
 	for (GRFConfig *c = _grfconfig_newgame; c != NULL; c = c->next) c->SetSuitablePalette();
 	for (GRFConfig *c = _grfconfig_static;  c != NULL; c = c->next) c->SetSuitablePalette();
+	for (GRFConfig *c = _all_grfs;          c != NULL; c = c->next) c->SetSuitablePalette();
+	return true;
 }
 
 /**
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -1383,6 +1383,7 @@
 	SettingEntry("gui.hover_delay"),
 	SettingEntry("gui.toolbar_pos"),
 	SettingEntry("gui.statusbar_pos"),
+	SettingEntry("gui.newgrf_default_palette"),
 	SettingEntry("gui.pause_on_newgame"),
 	SettingEntry("gui.advanced_vehicle_list"),
 	SettingEntry("gui.timetable_in_ticks"),
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -125,6 +125,7 @@
 	bool   ai_developer_tools;               ///< activate AI developer tools
 	bool   scenario_developer;               ///< activate scenario developer: allow modifying NewGRFs in an existing game
 	bool   newgrf_show_old_versions;         ///< whether to show old versions in the NewGRF list
+	uint8  newgrf_default_palette;           ///< default palette to use for NewGRFs without action 14 palette information
 
 	/**
 	 * Returns true when the user has sufficient privileges to edit newgrfs on a running game
--- a/src/table/settings.ini
+++ b/src/table/settings.ini
@@ -38,6 +38,7 @@
 static bool InvalidateNewGRFChangeWindows(int32 p1);
 static bool InvalidateIndustryViewWindow(int32 p1);
 static bool RedrawTownAuthority(int32 p1);
+extern bool UpdateNewGRFConfigPalette(int32 p1);
 
 #ifdef ENABLE_NETWORK
 static bool UpdateClientName(int32 p1);
@@ -2396,6 +2397,18 @@
 def      = false
 
 [SDTC_VAR]
+var      = gui.newgrf_default_palette
+type     = SLE_UINT8
+flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
+guiflags = SGF_MULTISTRING
+def      = 1
+min      = 0
+max      = 1
+str      = STR_CONFIG_SETTING_NEWGRF_DEFAULT_PALETTE
+strval   = STR_CONFIG_SETTING_NEWGRF_DEFAULT_PALETTE_DOS
+proc     = UpdateNewGRFConfigPalette
+
+[SDTC_VAR]
 var      = gui.console_backlog_timeout
 type     = SLE_UINT16
 flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC