First attempt to fix bug #11966,

it is now possible to change the language in the editor by pressing
alt-l. The only problem are the menu buttons, they will only show the
right language after a restart. I'm not sure if it'll be fixed before
the 1.0 release...propably not.
This commit is contained in:
Bram Ridder 2005-09-17 14:01:49 +00:00
parent 56296d4b74
commit 34c984bf25
5 changed files with 64 additions and 2 deletions

View file

@ -212,6 +212,14 @@ name=editor
shift=no
[/hotkey]
[hotkey]
command="changelanguage"
key="l"
cmd=no
alt=yes
shift=no
[/hotkey]
#else
[hotkey]
command="zoomin"
@ -412,6 +420,14 @@ name=editor
alt=no
shift=no
[/hotkey]
[hotkey]
command="changelanguage"
key="l"
ctrl=no
alt=yes
shift=no
[/hotkey]
#endif

View file

@ -21,6 +21,7 @@
#include "../game_config.hpp"
#include "../gettext.hpp"
#include "../key.hpp"
#include "../language.hpp"
#include "../widgets/menu.hpp"
#include "../pathfind.hpp"
#include "../playlevel.hpp"
@ -42,6 +43,7 @@
#include <cctype>
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <cmath>
@ -155,7 +157,7 @@ void map_editor::load_tooltips()
std::string text = "";
const std::vector<std::string> &menu_items = (*it).items();
if (menu_items.size() == 1) {
if (menu_items.size() == 1) {
if(menu_items.back() == "editdraw")
text = _("Draw tiles");
else if(menu_items.back() == "editfloodfill")
@ -357,6 +359,39 @@ void map_editor::right_click(const gamemap::location hex_clicked ) {
}
}
// Set the language...
void map_editor::change_language() {
std::vector<language_def> langdefs = get_languages();
// this only works because get_languages() returns a fresh vector at each calls
// unless show_gui cleans the "*" flag
const std::vector<language_def>::iterator current = std::find(langdefs.begin(),langdefs.end(),get_language());
if(current != langdefs.end()) {
(*current).language = "*" + (*current).language;
}
// prepare a copy with just the labels for the list to be displayed
std::vector<std::string> langs;
langs.reserve(langdefs.size());
std::transform(langdefs.begin(),langdefs.end(),std::back_inserter(langs),languagedef_name);
const int res = gui::show_dialog(gui_,NULL,_("Language"),
_("Choose your preferred language:"),
gui::OK_CANCEL,&langs);
if(size_t(res) < langs.size()) {
::set_language(known_languages[res]);
preferences::set_language(known_languages[res].localename);
game_config_.reset_translation();
// Reload tooltips and menu items
load_tooltips();
}
font::load_font_config();
hotkey::load_descriptions();
}
void map_editor::edit_save_as() {
const std::string default_dir =
@ -698,6 +733,7 @@ bool map_editor::can_execute_command(hotkey::HOTKEY_COMMAND command) const {
case hotkey::HOTKEY_EDIT_SELECT_ALL:
case hotkey::HOTKEY_EDIT_DRAW:
case hotkey::HOTKEY_EDIT_REFRESH:
case hotkey::HOTKEY_LANGUAGE:
return true;
default:
return false;

View file

@ -91,6 +91,9 @@ public:
/// Recalculate layout and redraw everything.
void redraw_everything();
// Change the language in_game
virtual void change_language();
// Methods inherited from command_executor. Used to perform
// operations on menu/hotkey commands.
virtual void toggle_grid();

View file

@ -107,6 +107,8 @@ const struct {
{ hotkey::HOTKEY_CHAT_LOG, "chatlog", N_("View Chat Log"), false },
{ hotkey::HOTKEY_USER_CMD, "command", N_("Enter user command"), false },
{ hotkey::HOTKEY_LANGUAGE, "changelanguage", N_("Change language"), true },
{ hotkey::HOTKEY_NULL, NULL, NULL, true }
};
@ -644,6 +646,10 @@ void execute_command(display& disp, HOTKEY_COMMAND command, command_executor* ex
if(executor)
executor->edit_refresh();
break;
case HOTKEY_LANGUAGE:
if(executor)
executor->change_language();
break;
default:
std::cerr << "command_executor: unknown command number " << command << ", ignoring.\n";
break;

View file

@ -41,7 +41,7 @@ enum HOTKEY_COMMAND {
HOTKEY_LABEL_TERRAIN, HOTKEY_SHOW_ENEMY_MOVES, HOTKEY_BEST_ENEMY_MOVES,
HOTKEY_DELAY_SHROUD, HOTKEY_UPDATE_SHROUD, HOTKEY_CONTINUE_MOVE,
HOTKEY_SEARCH, HOTKEY_SPEAK_ALLY, HOTKEY_SPEAK_ALL, HOTKEY_HELP,
HOTKEY_CHAT_LOG,
HOTKEY_CHAT_LOG, HOTKEY_LANGUAGE,
//editing specific commands
HOTKEY_EDIT_SET_TERRAIN,
@ -162,6 +162,7 @@ public:
virtual void show_help() {}
virtual void show_chat_log() {}
virtual void user_command() {}
virtual void change_language() {}
// Map editor stuff.
virtual void edit_set_terrain() {}