src/settings.cpp
branchnoai
changeset 10294 7798ae816af8
parent 10249 58810805030e
child 10455 22c441f5adf9
equal deleted inserted replaced
10292:7856e972f8aa 10294:7798ae816af8
  1646 #undef NC
  1646 #undef NC
  1647 #undef MS
  1647 #undef MS
  1648 #undef NO
  1648 #undef NO
  1649 #undef CR
  1649 #undef CR
  1650 
  1650 
  1651 static uint NewsDisplayLoadConfig(IniFile *ini, const char *grpname)
  1651 static void NewsDisplayLoadConfig(IniFile *ini, const char *grpname)
  1652 {
  1652 {
  1653 	IniGroup *group = ini_getgroup(ini, grpname, -1);
  1653 	IniGroup *group = ini_getgroup(ini, grpname, -1);
  1654 	IniItem *item;
  1654 	IniItem *item;
  1655 	/* By default, set everything to full (0xAAAAAAAA = 1010101010101010) */
  1655 
  1656 	uint res = 0xAAAAAAAA;
  1656 	/* If no group exists, return */
  1657 
  1657 	if (group == NULL) return;
  1658 	/* If no group exists, return everything full */
       
  1659 	if (group == NULL) return res;
       
  1660 
  1658 
  1661 	for (item = group->item; item != NULL; item = item->next) {
  1659 	for (item = group->item; item != NULL; item = item->next) {
  1662 		int news_item = -1;
  1660 		int news_item = -1;
  1663 		for (int i = 0; i < NT_END; i++) {
  1661 		for (int i = 0; i < NT_END; i++) {
  1664 			if (strcasecmp(item->name, _news_display_name[i]) == 0) {
  1662 			if (strcasecmp(item->name, _news_type_data[i].name) == 0) {
  1665 				news_item = i;
  1663 				news_item = i;
  1666 				break;
  1664 				break;
  1667 			}
  1665 			}
  1668 		}
  1666 		}
  1669 		if (news_item == -1) {
  1667 		if (news_item == -1) {
  1670 			DEBUG(misc, 0, "Invalid display option: %s", item->name);
  1668 			DEBUG(misc, 0, "Invalid display option: %s", item->name);
  1671 			continue;
  1669 			continue;
  1672 		}
  1670 		}
  1673 
  1671 
  1674 		if (strcasecmp(item->value, "full") == 0) {
  1672 		if (strcasecmp(item->value, "full") == 0) {
  1675 			SB(res, news_item * 2, 2, 2);
  1673 			_news_type_data[news_item].display = ND_FULL;
  1676 		} else if (strcasecmp(item->value, "off") == 0) {
  1674 		} else if (strcasecmp(item->value, "off") == 0) {
  1677 			SB(res, news_item * 2, 2, 0);
  1675 			_news_type_data[news_item].display = ND_OFF;
  1678 		} else if (strcasecmp(item->value, "summarized") == 0) {
  1676 		} else if (strcasecmp(item->value, "summarized") == 0) {
  1679 			SB(res, news_item * 2, 2, 1);
  1677 			_news_type_data[news_item].display = ND_SUMMARY;
  1680 		} else {
  1678 		} else {
  1681 			DEBUG(misc, 0, "Invalid display value: %s", item->value);
  1679 			DEBUG(misc, 0, "Invalid display value: %s", item->value);
  1682 			continue;
  1680 			continue;
  1683 		}
  1681 		}
  1684 	}
  1682 	}
  1685 
       
  1686 	return res;
       
  1687 }
  1683 }
  1688 
  1684 
  1689 /* Load a GRF configuration from the given group name */
  1685 /* Load a GRF configuration from the given group name */
  1690 static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
  1686 static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_static)
  1691 {
  1687 {
  1737 	}
  1733 	}
  1738 
  1734 
  1739 	return first;
  1735 	return first;
  1740 }
  1736 }
  1741 
  1737 
  1742 static void NewsDisplaySaveConfig(IniFile *ini, const char *grpname, uint news_display)
  1738 static void NewsDisplaySaveConfig(IniFile *ini, const char *grpname)
  1743 {
  1739 {
  1744 	IniGroup *group = ini_getgroup(ini, grpname, -1);
  1740 	IniGroup *group = ini_getgroup(ini, grpname, -1);
  1745 	IniItem **item;
  1741 	IniItem **item;
  1746 
  1742 
  1747 	if (group == NULL) return;
  1743 	if (group == NULL) return;
  1748 	group->item = NULL;
  1744 	group->item = NULL;
  1749 	item = &group->item;
  1745 	item = &group->item;
  1750 
  1746 
  1751 	for (int i = 0; i < NT_END; i++) {
  1747 	for (int i = 0; i < NT_END; i++) {
  1752 		const char *value;
  1748 		const char *value;
  1753 		int v = GB(news_display, i * 2, 2);
  1749 		int v = _news_type_data[i].display;
  1754 
  1750 
  1755 		value = (v == 0 ? "off" : (v == 1 ? "summarized" : "full"));
  1751 		value = (v == ND_OFF ? "off" : (v == ND_SUMMARY ? "summarized" : "full"));
  1756 
  1752 
  1757 		*item = ini_item_alloc(group, _news_display_name[i], strlen(_news_display_name[i]));
  1753 		*item = ini_item_alloc(group, _news_type_data[i].name, strlen(_news_type_data[i].name));
  1758 		(*item)->value = (char*)pool_strdup(&ini->pool, value, strlen(value));
  1754 		(*item)->value = (char*)pool_strdup(&ini->pool, value, strlen(value));
  1759 		item = &(*item)->next;
  1755 		item = &(*item)->next;
  1760 	}
  1756 	}
  1761 }
  1757 }
  1762 
  1758 
  1839 	IniFile *ini = ini_load(_config_file);
  1835 	IniFile *ini = ini_load(_config_file);
  1840 	ResetCurrencies(false); // Initialize the array of curencies, without preserving the custom one
  1836 	ResetCurrencies(false); // Initialize the array of curencies, without preserving the custom one
  1841 	HandleSettingDescs(ini, ini_load_settings, ini_load_setting_list);
  1837 	HandleSettingDescs(ini, ini_load_settings, ini_load_setting_list);
  1842 	_grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
  1838 	_grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
  1843 	_grfconfig_static  = GRFLoadConfig(ini, "newgrf-static", true);
  1839 	_grfconfig_static  = GRFLoadConfig(ini, "newgrf-static", true);
  1844 	_news_display_opt  = NewsDisplayLoadConfig(ini, "news_display");
  1840 	NewsDisplayLoadConfig(ini, "news_display");
  1845 	CheckDifficultyLevels();
  1841 	CheckDifficultyLevels();
  1846 	ini_free(ini);
  1842 	ini_free(ini);
  1847 }
  1843 }
  1848 
  1844 
  1849 /** Save the values to the configuration file */
  1845 /** Save the values to the configuration file */
  1851 {
  1847 {
  1852 	IniFile *ini = ini_load(_config_file);
  1848 	IniFile *ini = ini_load(_config_file);
  1853 	HandleSettingDescs(ini, ini_save_settings, ini_save_setting_list);
  1849 	HandleSettingDescs(ini, ini_save_settings, ini_save_setting_list);
  1854 	GRFSaveConfig(ini, "newgrf", _grfconfig_newgame);
  1850 	GRFSaveConfig(ini, "newgrf", _grfconfig_newgame);
  1855 	GRFSaveConfig(ini, "newgrf-static", _grfconfig_static);
  1851 	GRFSaveConfig(ini, "newgrf-static", _grfconfig_static);
  1856 	NewsDisplaySaveConfig(ini, "news_display", _news_display_opt);
  1852 	NewsDisplaySaveConfig(ini, "news_display");
  1857 	SaveVersionInConfig(ini);
  1853 	SaveVersionInConfig(ini);
  1858 	ini_save(_config_file, ini);
  1854 	ini_save(_config_file, ini);
  1859 	ini_free(ini);
  1855 	ini_free(ini);
  1860 }
  1856 }
  1861 
  1857