mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r21161) -Codechange: make the currently used language easier accessible
This commit is contained in:
parent
f195920695
commit
f4e4056aed
|
@ -25,6 +25,7 @@
|
||||||
#include "screenshot.h"
|
#include "screenshot.h"
|
||||||
#include "gfx_func.h"
|
#include "gfx_func.h"
|
||||||
#include "network/network.h"
|
#include "network/network.h"
|
||||||
|
#include "language.h"
|
||||||
|
|
||||||
#include "ai/ai_info.hpp"
|
#include "ai/ai_info.hpp"
|
||||||
#include "company_base.h"
|
#include "company_base.h"
|
||||||
|
@ -120,7 +121,7 @@ char *CrashLog::LogConfiguration(char *buffer, const char *last) const
|
||||||
BlitterFactoryBase::GetCurrentBlitter() == NULL ? "none" : BlitterFactoryBase::GetCurrentBlitter()->GetName(),
|
BlitterFactoryBase::GetCurrentBlitter() == NULL ? "none" : BlitterFactoryBase::GetCurrentBlitter()->GetName(),
|
||||||
BaseGraphics::GetUsedSet() == NULL ? "none" : BaseGraphics::GetUsedSet()->name,
|
BaseGraphics::GetUsedSet() == NULL ? "none" : BaseGraphics::GetUsedSet()->name,
|
||||||
BaseGraphics::GetUsedSet() == NULL ? UINT32_MAX : BaseGraphics::GetUsedSet()->version,
|
BaseGraphics::GetUsedSet() == NULL ? UINT32_MAX : BaseGraphics::GetUsedSet()->version,
|
||||||
StrEmpty(_dynlang.curr_file) ? "none" : _dynlang.curr_file,
|
_current_language == NULL ? "none" : _current_language->file,
|
||||||
_music_driver == NULL ? "none" : _music_driver->GetName(),
|
_music_driver == NULL ? "none" : _music_driver->GetName(),
|
||||||
BaseMusic::GetUsedSet() == NULL ? "none" : BaseMusic::GetUsedSet()->name,
|
BaseMusic::GetUsedSet() == NULL ? "none" : BaseMusic::GetUsedSet()->name,
|
||||||
BaseMusic::GetUsedSet() == NULL ? UINT32_MAX : BaseMusic::GetUsedSet()->version,
|
BaseMusic::GetUsedSet() == NULL ? UINT32_MAX : BaseMusic::GetUsedSet()->version,
|
||||||
|
|
|
@ -56,4 +56,7 @@ struct LanguageMetadata : public LanguagePackHeader {
|
||||||
char file[MAX_PATH]; ///< Name of the file we read this data from.
|
char file[MAX_PATH]; ///< Name of the file we read this data from.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** The currently loaded language. */
|
||||||
|
extern const LanguageMetadata *_current_language;
|
||||||
|
|
||||||
#endif /* LANGUAGE_H */
|
#endif /* LANGUAGE_H */
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "viewport_func.h"
|
#include "viewport_func.h"
|
||||||
#include "core/geometry_func.hpp"
|
#include "core/geometry_func.hpp"
|
||||||
#include "ai/ai.hpp"
|
#include "ai/ai.hpp"
|
||||||
|
#include "language.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
|
@ -190,7 +191,7 @@ struct GameOptionsWindow : Window {
|
||||||
case GOW_ROADSIDE_DROPDOWN: SetDParam(0, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT + this->opt->vehicle.road_side); break;
|
case GOW_ROADSIDE_DROPDOWN: SetDParam(0, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT + this->opt->vehicle.road_side); break;
|
||||||
case GOW_TOWNNAME_DROPDOWN: SetDParam(0, TownName(this->opt->game_creation.town_name)); break;
|
case GOW_TOWNNAME_DROPDOWN: SetDParam(0, TownName(this->opt->game_creation.town_name)); break;
|
||||||
case GOW_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
|
case GOW_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
|
||||||
case GOW_LANG_DROPDOWN: SetDParam(0, SPECSTR_LANGUAGE_START + _dynlang.curr); break;
|
case GOW_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
|
||||||
case GOW_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _num_resolutions ? STR_RES_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
|
case GOW_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _num_resolutions ? STR_RES_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
|
||||||
case GOW_SCREENSHOT_DROPDOWN: SetDParam(0, SPECSTR_SCREENSHOT_START + _cur_screenshot_format); break;
|
case GOW_SCREENSHOT_DROPDOWN: SetDParam(0, SPECSTR_SCREENSHOT_START + _cur_screenshot_format); break;
|
||||||
case GOW_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
|
case GOW_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
|
||||||
|
@ -315,14 +316,18 @@ struct GameOptionsWindow : Window {
|
||||||
|
|
||||||
/* Sort language names */
|
/* Sort language names */
|
||||||
LangList langs;
|
LangList langs;
|
||||||
for (int i = 0; i < _dynlang.num; i++) langs[SPECSTR_LANGUAGE_START + i] = i;
|
int current_lang;
|
||||||
|
for (int i = 0; i < _dynlang.num; i++) {
|
||||||
|
if (&_dynlang.ent[i] == _current_language) current_lang = i;
|
||||||
|
langs[SPECSTR_LANGUAGE_START + i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
DropDownList *list = new DropDownList();
|
DropDownList *list = new DropDownList();
|
||||||
for (LangList::iterator it = langs.begin(); it != langs.end(); it++) {
|
for (LangList::iterator it = langs.begin(); it != langs.end(); it++) {
|
||||||
list->push_back(new DropDownListStringItem((*it).first, (*it).second, false));
|
list->push_back(new DropDownListStringItem((*it).first, (*it).second, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowDropDownList(this, list, _dynlang.curr, GOW_LANG_DROPDOWN);
|
ShowDropDownList(this, list, current_lang, GOW_LANG_DROPDOWN);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
#include "table/control_codes.h"
|
#include "table/control_codes.h"
|
||||||
|
|
||||||
|
const LanguageMetadata *_current_language = NULL; ///< The currently loaded language.
|
||||||
|
|
||||||
DynamicLanguages _dynlang; ///< Language information of the program.
|
DynamicLanguages _dynlang; ///< Language information of the program.
|
||||||
TextDirection _current_text_dir; ///< Text direction of the currently selected language
|
TextDirection _current_text_dir; ///< Text direction of the currently selected language
|
||||||
uint64 _decode_parameters[20]; ///< Global array of string parameters. To access, use #SetDParam.
|
uint64 _decode_parameters[20]; ///< Global array of string parameters. To access, use #SetDParam.
|
||||||
|
@ -1277,7 +1279,7 @@ static char *GetSpecialNameString(char *buff, int ind, int64 *argv, const char *
|
||||||
if (IsInsideMM(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) {
|
if (IsInsideMM(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) {
|
||||||
int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
|
int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
|
||||||
return strecpy(buff,
|
return strecpy(buff,
|
||||||
i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name, last);
|
&_dynlang.ent[i] == _current_language ? _current_language->own_name : _dynlang.ent[i].name, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* resolution size? */
|
/* resolution size? */
|
||||||
|
@ -1382,12 +1384,12 @@ bool ReadLanguagePack(int lang_index)
|
||||||
free(_langpack_offs);
|
free(_langpack_offs);
|
||||||
_langpack_offs = langpack_offs;
|
_langpack_offs = langpack_offs;
|
||||||
|
|
||||||
const char *c_file = strrchr(_dynlang.ent[lang_index].file, PATHSEPCHAR) + 1;
|
_current_language = &_dynlang.ent[lang_index];
|
||||||
|
_current_text_dir = (TextDirection)_current_language->text_dir;
|
||||||
|
const char *c_file = strrchr(_current_language->file, PATHSEPCHAR) + 1;
|
||||||
strecpy(_dynlang.curr_file, c_file, lastof(_dynlang.curr_file));
|
strecpy(_dynlang.curr_file, c_file, lastof(_dynlang.curr_file));
|
||||||
|
SetCurrentGrfLangID(_current_language->newgrflangid);
|
||||||
|
|
||||||
_dynlang.curr = lang_index;
|
|
||||||
_current_text_dir = (TextDirection)lang_pack->text_dir;
|
|
||||||
SetCurrentGrfLangID(_langpack->newgrflangid);
|
|
||||||
InitializeSortedCargoSpecs();
|
InitializeSortedCargoSpecs();
|
||||||
SortIndustryTypes();
|
SortIndustryTypes();
|
||||||
BuildIndustriesLegend();
|
BuildIndustriesLegend();
|
||||||
|
|
|
@ -31,7 +31,6 @@ enum TextDirection {
|
||||||
/** Used for dynamic language support */
|
/** Used for dynamic language support */
|
||||||
struct DynamicLanguages {
|
struct DynamicLanguages {
|
||||||
int num; ///< Number of languages
|
int num; ///< Number of languages
|
||||||
int curr; ///< Currently selected language index
|
|
||||||
char curr_file[MAX_PATH]; ///< Currently selected language file name without path (needed for saving the filename of the loaded language).
|
char curr_file[MAX_PATH]; ///< Currently selected language file name without path (needed for saving the filename of the loaded language).
|
||||||
LanguageMetadata ent[MAX_LANG]; ///< Information about the languages
|
LanguageMetadata ent[MAX_LANG]; ///< Information about the languages
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue