settings.c
branch0.5
changeset 5461 03285c9589f9
parent 5460 c86169e59c08
child 5480 497f842b10bf
equal deleted inserted replaced
5460:c86169e59c08 5461:03285c9589f9
    38 #include "newgrf.h"
    38 #include "newgrf.h"
    39 #include "newgrf_config.h"
    39 #include "newgrf_config.h"
    40 #include "genworld.h"
    40 #include "genworld.h"
    41 #include "date.h"
    41 #include "date.h"
    42 #include "rail.h"
    42 #include "rail.h"
       
    43 #include "news.h"
    43 #ifdef WITH_FREETYPE
    44 #ifdef WITH_FREETYPE
    44 #include "gfx.h"
    45 #include "gfx.h"
    45 #include "fontcache.h"
    46 #include "fontcache.h"
    46 #endif
    47 #endif
    47 
    48 
  1179 };
  1180 };
  1180 #endif /* WIN32 */
  1181 #endif /* WIN32 */
  1181 
  1182 
  1182 static const SettingDescGlobVarList _misc_settings[] = {
  1183 static const SettingDescGlobVarList _misc_settings[] = {
  1183 	SDTG_MMANY("display_opt",     SLE_UINT8, S, 0, _display_opt,       (DO_SHOW_TOWN_NAMES|DO_SHOW_STATION_NAMES|DO_SHOW_SIGNS|DO_FULL_ANIMATION|DO_FULL_DETAIL|DO_TRANS_BUILDINGS|DO_WAYPOINTS), "SHOW_TOWN_NAMES|SHOW_STATION_NAMES|SHOW_SIGNS|FULL_ANIMATION|TRANS_BUILDINGS|FULL_DETAIL|WAYPOINTS", STR_NULL, NULL),
  1184 	SDTG_MMANY("display_opt",     SLE_UINT8, S, 0, _display_opt,       (DO_SHOW_TOWN_NAMES|DO_SHOW_STATION_NAMES|DO_SHOW_SIGNS|DO_FULL_ANIMATION|DO_FULL_DETAIL|DO_TRANS_BUILDINGS|DO_WAYPOINTS), "SHOW_TOWN_NAMES|SHOW_STATION_NAMES|SHOW_SIGNS|FULL_ANIMATION|TRANS_BUILDINGS|FULL_DETAIL|WAYPOINTS", STR_NULL, NULL),
  1184 	  SDTG_VAR("news_display_opt", SLE_UINT, S, 0, _news_display_opt,0xAAAAAAAA,0,0xAAAAAAAA,0,STR_NULL, NULL), // default to all full messages: 10101010101010101010 = 0xAAAAAAAA
       
  1185 	 SDTG_BOOL("news_ticker_sound",          S, 0, _news_ticker_sound,     true,    STR_NULL, NULL),
  1185 	 SDTG_BOOL("news_ticker_sound",          S, 0, _news_ticker_sound,     true,    STR_NULL, NULL),
  1186 	 SDTG_BOOL("fullscreen",                 S, 0, _fullscreen,           false,    STR_NULL, NULL),
  1186 	 SDTG_BOOL("fullscreen",                 S, 0, _fullscreen,           false,    STR_NULL, NULL),
  1187 	  SDTG_STR("videodriver",      SLE_STRB,C|S,0, _ini_videodriver,       NULL,    STR_NULL, NULL),
  1187 	  SDTG_STR("videodriver",      SLE_STRB,C|S,0, _ini_videodriver,       NULL,    STR_NULL, NULL),
  1188 	  SDTG_STR("musicdriver",      SLE_STRB,C|S,0, _ini_musicdriver,       NULL,    STR_NULL, NULL),
  1188 	  SDTG_STR("musicdriver",      SLE_STRB,C|S,0, _ini_musicdriver,       NULL,    STR_NULL, NULL),
  1189 	  SDTG_STR("sounddriver",      SLE_STRB,C|S,0, _ini_sounddriver,       NULL,    STR_NULL, NULL),
  1189 	  SDTG_STR("sounddriver",      SLE_STRB,C|S,0, _ini_sounddriver,       NULL,    STR_NULL, NULL),
  1493 #undef NC
  1493 #undef NC
  1494 #undef MS
  1494 #undef MS
  1495 #undef NO
  1495 #undef NO
  1496 #undef CR
  1496 #undef CR
  1497 
  1497 
       
  1498 static uint NewsDisplayLoadConfig(IniFile *ini, const char *grpname)
       
  1499 {
       
  1500 	IniGroup *group = ini_getgroup(ini, grpname, -1);
       
  1501 	IniItem *item;
       
  1502 	/* By default, set everything to full (0xAAAAAAAA = 1010101010101010) */
       
  1503 	uint res = 0xAAAAAAAA;
       
  1504 
       
  1505 	/* If no group exists, return everything FULL */
       
  1506 	if (group == NULL) return res;
       
  1507 
       
  1508 	for (item = group->item; item != NULL; item = item->next) {
       
  1509 		int news_item = -1;
       
  1510 		int i;
       
  1511 		for (i = 0; i < NT_END; i++) {
       
  1512 			if (strcasecmp(item->name, _news_display_name[i]) == 0) {
       
  1513 				news_item = i;
       
  1514 				break;
       
  1515 			}
       
  1516 		}
       
  1517 		if (news_item == -1) {
       
  1518 			DEBUG(misc, 0)("Invalid display option: %s", item->name);
       
  1519 			continue;
       
  1520 		}
       
  1521 
       
  1522 		if (strcasecmp(item->value, "full") == 0) {
       
  1523 			SB(res, news_item * 2, 2, 2);
       
  1524 		} else if (strcasecmp(item->value, "off") == 0) {
       
  1525 			SB(res, news_item * 2, 2, 0);
       
  1526 		} else if (strcasecmp(item->value, "summarized") == 0) {
       
  1527 			SB(res, news_item * 2, 2, 1);
       
  1528 		} else {
       
  1529 			DEBUG(misc, 0)("Invalid display value: %s", item->value);
       
  1530 			continue;
       
  1531 		}
       
  1532 	}
       
  1533 
       
  1534 	return res;
       
  1535 }
  1498 
  1536 
  1499 /* Load a GRF configuration from the given group name */
  1537 /* Load a GRF configuration from the given group name */
  1500 static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
  1538 static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
  1501 {
  1539 {
  1502 	IniGroup *group = ini_getgroup(ini, grpname, -1);
  1540 	IniGroup *group = ini_getgroup(ini, grpname, -1);
  1547 	}
  1585 	}
  1548 
  1586 
  1549 	return first;
  1587 	return first;
  1550 }
  1588 }
  1551 
  1589 
       
  1590 static void NewsDisplaySaveConfig(IniFile *ini, const char *grpname, uint news_display)
       
  1591 {
       
  1592 	IniGroup *group = ini_getgroup(ini, grpname, -1);
       
  1593 	IniItem **item;
       
  1594 	int i;
       
  1595 
       
  1596 	if (group == NULL) return;
       
  1597 	group->item = NULL;
       
  1598 	item = &group->item;
       
  1599 
       
  1600 	for (i = 0; i < NT_END; i++) {
       
  1601 		const char *value;
       
  1602 		int v = GB(news_display, i * 2, 2);
       
  1603 
       
  1604 		value = (v == 0 ? "off" : (v == 1 ? "summarized" : "full"));
       
  1605 
       
  1606 		*item = ini_item_alloc(group, _news_display_name[i], strlen(_news_display_name[i]));
       
  1607 		(*item)->value = (char*)pool_strdup(&ini->pool, value, strlen(value));
       
  1608 		item = &(*item)->next;
       
  1609 	}
       
  1610 }
  1552 
  1611 
  1553 /* Save a GRF configuration to the given group name */
  1612 /* Save a GRF configuration to the given group name */
  1554 static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *list)
  1613 static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *list)
  1555 {
  1614 {
  1556 	IniGroup *group = ini_getgroup(ini, grpname, -1);
  1615 	IniGroup *group = ini_getgroup(ini, grpname, -1);
  1596 {
  1655 {
  1597 	IniFile *ini = ini_load(_config_file);
  1656 	IniFile *ini = ini_load(_config_file);
  1598 	HandleSettingDescs(ini, ini_load_settings, ini_load_setting_list);
  1657 	HandleSettingDescs(ini, ini_load_settings, ini_load_setting_list);
  1599 	_grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
  1658 	_grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
  1600 	_grfconfig_static  = GRFLoadConfig(ini, "newgrf-static", true);
  1659 	_grfconfig_static  = GRFLoadConfig(ini, "newgrf-static", true);
       
  1660 	_news_display_opt  = NewsDisplayLoadConfig(ini, "news_display");
  1601 	ini_free(ini);
  1661 	ini_free(ini);
  1602 }
  1662 }
  1603 
  1663 
  1604 /** Save the values to the configuration file */
  1664 /** Save the values to the configuration file */
  1605 void SaveToConfig(void)
  1665 void SaveToConfig(void)
  1606 {
  1666 {
  1607 	IniFile *ini = ini_load(_config_file);
  1667 	IniFile *ini = ini_load(_config_file);
  1608 	HandleSettingDescs(ini, ini_save_settings, ini_save_setting_list);
  1668 	HandleSettingDescs(ini, ini_save_settings, ini_save_setting_list);
  1609 	GRFSaveConfig(ini, "newgrf", _grfconfig_newgame);
  1669 	GRFSaveConfig(ini, "newgrf", _grfconfig_newgame);
  1610 	GRFSaveConfig(ini, "newgrf-static", _grfconfig_static);
  1670 	GRFSaveConfig(ini, "newgrf-static", _grfconfig_static);
       
  1671 	NewsDisplaySaveConfig(ini, "news_display", _news_display_opt);
  1611 	ini_save(_config_file, ini);
  1672 	ini_save(_config_file, ini);
  1612 	ini_free(ini);
  1673 	ini_free(ini);
  1613 }
  1674 }
  1614 
  1675 
  1615 static const SettingDesc *GetSettingDescription(uint index)
  1676 static const SettingDesc *GetSettingDescription(uint index)
  1815 	SaveSettings(_patch_settings, &_patches);
  1876 	SaveSettings(_patch_settings, &_patches);
  1816 }
  1877 }
  1817 
  1878 
  1818 void CheckConfig(void)
  1879 void CheckConfig(void)
  1819 {
  1880 {
  1820 	// fix up news_display_opt from old to new
       
  1821 	int i;
       
  1822 	uint32 tmp;
       
  1823 	for (i = 0, tmp = _news_display_opt; i != 10; i++, tmp >>= 2) {
       
  1824 		if ((tmp & 0x3) == 0x3) { // old settings
       
  1825 			_news_display_opt = 0xAAAAAAAA; // set all news-messages to full 1010101010...
       
  1826 			break;
       
  1827 		}
       
  1828 	}
       
  1829 
       
  1830 	// Increase old default values for pf_maxdepth and pf_maxlength
  1881 	// Increase old default values for pf_maxdepth and pf_maxlength
  1831 	// to support big networks.
  1882 	// to support big networks.
  1832 	if (_patches_newgame.pf_maxdepth == 16 && _patches_newgame.pf_maxlength == 512) {
  1883 	if (_patches_newgame.pf_maxdepth == 16 && _patches_newgame.pf_maxlength == 512) {
  1833 		_patches_newgame.pf_maxdepth = 48;
  1884 		_patches_newgame.pf_maxdepth = 48;
  1834 		_patches_newgame.pf_maxlength = 4096;
  1885 		_patches_newgame.pf_maxlength = 4096;