(svn r21161) -Codechange: make the currently used language easier accessible

This commit is contained in:
rubidium 2010-11-13 11:25:58 +00:00
parent f195920695
commit f4e4056aed
5 changed files with 20 additions and 10 deletions

View File

@ -25,6 +25,7 @@
#include "screenshot.h"
#include "gfx_func.h"
#include "network/network.h"
#include "language.h"
#include "ai/ai_info.hpp"
#include "company_base.h"
@ -120,7 +121,7 @@ char *CrashLog::LogConfiguration(char *buffer, const char *last) const
BlitterFactoryBase::GetCurrentBlitter() == NULL ? "none" : BlitterFactoryBase::GetCurrentBlitter()->GetName(),
BaseGraphics::GetUsedSet() == NULL ? "none" : BaseGraphics::GetUsedSet()->name,
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(),
BaseMusic::GetUsedSet() == NULL ? "none" : BaseMusic::GetUsedSet()->name,
BaseMusic::GetUsedSet() == NULL ? UINT32_MAX : BaseMusic::GetUsedSet()->version,

View File

@ -56,4 +56,7 @@ struct LanguageMetadata : public LanguagePackHeader {
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 */

View File

@ -32,6 +32,7 @@
#include "viewport_func.h"
#include "core/geometry_func.hpp"
#include "ai/ai.hpp"
#include "language.h"
#include <map>
#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_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_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_SCREENSHOT_DROPDOWN: SetDParam(0, SPECSTR_SCREENSHOT_START + _cur_screenshot_format); break;
case GOW_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
@ -315,14 +316,18 @@ struct GameOptionsWindow : Window {
/* Sort language names */
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();
for (LangList::iterator it = langs.begin(); it != langs.end(); it++) {
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;
}

View File

@ -40,6 +40,8 @@
#include "table/strings.h"
#include "table/control_codes.h"
const LanguageMetadata *_current_language = NULL; ///< The currently loaded language.
DynamicLanguages _dynlang; ///< Language information of the program.
TextDirection _current_text_dir; ///< Text direction of the currently selected language
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)) {
int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
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? */
@ -1382,12 +1384,12 @@ bool ReadLanguagePack(int lang_index)
free(_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));
SetCurrentGrfLangID(_current_language->newgrflangid);
_dynlang.curr = lang_index;
_current_text_dir = (TextDirection)lang_pack->text_dir;
SetCurrentGrfLangID(_langpack->newgrflangid);
InitializeSortedCargoSpecs();
SortIndustryTypes();
BuildIndustriesLegend();

View File

@ -31,7 +31,6 @@ enum TextDirection {
/** Used for dynamic language support */
struct DynamicLanguages {
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).
LanguageMetadata ent[MAX_LANG]; ///< Information about the languages
};