about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2009-06-15 08:15:53 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2009-06-15 08:15:53 +0000
commit307cf4aa64b37aa46e14cde09b38a0a4a73330be (patch)
tree6268ff35ccde600d4ba6111ac5ba8404681c3489
parentab171f8f303306f5b45e2ccaa4c47404b11b0256 (diff)
downloadzcatch-307cf4aa64b37aa46e14cde09b38a0a4a73330be.tar.gz
zcatch-307cf4aa64b37aa46e14cde09b38a0a4a73330be.zip
done language selector
-rw-r--r--data/languages/swedish.txt12
-rw-r--r--src/base/system.c7
-rw-r--r--src/base/system.h1
-rw-r--r--src/game/client/components/menus.hpp1
-rw-r--r--src/game/client/components/menus_settings.cpp91
-rw-r--r--src/game/client/gameclient.cpp13
-rw-r--r--src/game/client/gameclient.hpp1
-rw-r--r--src/game/localization.cpp8
-rw-r--r--src/game/variables.hpp2
9 files changed, 108 insertions, 28 deletions
diff --git a/data/languages/swedish.txt b/data/languages/swedish.txt
index ab8719f9..7879d5f8 100644
--- a/data/languages/swedish.txt
+++ b/data/languages/swedish.txt
@@ -124,12 +124,18 @@ Game
 Game info
 == Spel info.
 
+Game over
+== Slutspelat
+
 Game type
 == Speltyp
 
 Game types
 == Speltyper
 
+General
+== Generallt
+
 Graphics
 == Grafik
 
@@ -178,6 +184,9 @@ Kick
 LAN
 == LAN
 
+Language
+== Språk
+
 Lht.
 == Ljusstyrka
 
@@ -423,9 +432,6 @@ You must restart the game for all settings to take effect.
 
 ##### needs translation ####
 
-Game over
-== 
-
 N/A
 == 
 
diff --git a/src/base/system.c b/src/base/system.c
index 067c870f..be2a5d5a 100644
--- a/src/base/system.c
+++ b/src/base/system.c
@@ -1213,6 +1213,13 @@ void gui_messagebox(const char *title, const char *message)
 
 int str_isspace(char c) { return c == ' ' || c == '\n' || c == '\t'; }
 
+char str_uppercase(char c)
+{
+	if(c >= 'a' && c <= 'z')
+		return 'A' + (c-'a');
+	return c;
+}
+
 
 
 static int str_utf8_isstart(char c)
diff --git a/src/base/system.h b/src/base/system.h
index 6ead7239..7a734cfd 100644
--- a/src/base/system.h
+++ b/src/base/system.h
@@ -970,6 +970,7 @@ typedef struct
 void net_stats(NETSTATS *stats);
 
 int str_isspace(char c);
+char str_uppercase(char c);
 
 
 /*
diff --git a/src/game/client/components/menus.hpp b/src/game/client/components/menus.hpp
index 6d304628..7523cf8d 100644
--- a/src/game/client/components/menus.hpp
+++ b/src/game/client/components/menus.hpp
@@ -157,6 +157,7 @@ class MENUS : public COMPONENT
 	void render_serverbrowser(RECT main_view);
 	
 	// found in menus_settings.cpp
+	void render_settings_general(RECT main_view);
 	void render_settings_player(RECT main_view);
 	void render_settings_controls(RECT main_view);
 	void render_settings_graphics(RECT main_view);
diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp
index 8d1b1a4e..3e5fe65f 100644
--- a/src/game/client/components/menus_settings.cpp
+++ b/src/game/client/components/menus_settings.cpp
@@ -64,6 +64,9 @@ void MENUS::render_settings_player(RECT main_view)
 		if(ui_do_edit_box(config.player_name, &button, config.player_name, sizeof(config.player_name), 14.0f))
 			need_sendinfo = true;
 
+		// extra spacing
+		ui_hsplit_t(&main_view, 10.0f, 0, &main_view);
+
 		static int dynamic_camera_button = 0;
 		ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
 		if(ui_do_button(&dynamic_camera_button, localize("Dynamic Camera"), config.cl_mouse_deadzone != 0, &button, ui_draw_checkbox, 0))
@@ -622,21 +625,80 @@ void MENUS::render_settings_sound(RECT main_view)
 	}
 }
 
+struct LANGUAGE
+{
+	LANGUAGE() {}
+	LANGUAGE(const char *n, const char *f) : name(n), filename(f) {}
+	
+	string name;
+	string filename;
+	
+	bool operator<(const LANGUAGE &other) { return name < other.name; }
+};
+
 
-	/*
-static void menu2_render_settings_network(RECT main_view)
+int fs_listdir(const char *dir, FS_LISTDIR_CALLBACK cb, void *user);
+
+void gather_languages(const char *name, int is_dir, void *user)
 {
-	RECT button;
-	ui_vsplit_l(&main_view, 300.0f, &main_view, 0);
+	if(is_dir || name[0] == '.')
+		return;
+		
+	sorted_array<LANGUAGE> &languages = *((sorted_array<LANGUAGE> *)user);
+	char filename[128];
+	str_format(filename, sizeof(filename), "data/languages/%s", name);
+
+	char nicename[128];
+	str_format(nicename, sizeof(nicename), "%s", name);
+	nicename[0] = str_uppercase(nicename[0]);
+	
+	
+	for(char *p = nicename; *p; p++)
+		if(*p == '.')
+			*p = 0;
+	
+	languages.add(LANGUAGE(nicename, filename));
+}
+
+void MENUS::render_settings_general(RECT main_view)
+{
+	static int lanuagelist = 0;
+	static int selected_language = 0;
+	static sorted_array<LANGUAGE> languages;
 	
+	if(languages.size() == 0)
 	{
-		ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
-		ui_do_label(&button, "Rcon Password", 14.0, -1);
-		ui_vsplit_l(&button, 110.0f, 0, &button);
-		ui_vsplit_l(&button, 180.0f, &button, 0);
-		ui_do_edit_box(&config.rcon_password, &button, config.rcon_password, sizeof(config.rcon_password), true);
+		languages.add(LANGUAGE("English", ""));
+		fs_listdir("data/languages", gather_languages, &languages);
+		for(int i = 0; i < languages.size(); i++)
+			if(str_comp(languages[i].filename, config.cl_languagefile) == 0)
+			{
+				selected_language = i;
+				break;
+			}
+	}
+	
+	int old_selected = selected_language;
+	
+	RECT list = main_view;
+	ui_do_listbox_start(&lanuagelist, &list, 24.0f, localize("Language"), languages.size(), selected_language);
+	
+	for(sorted_array<LANGUAGE>::range r = languages.all(); !r.empty(); r.pop_front())
+	{
+		LISTBOXITEM item = ui_do_listbox_nextitem(&r.front());
+		
+		if(item.visible)
+			ui_do_label(&item.rect, r.front().name, 16.0f, -1);
+	}
+	
+	selected_language = ui_do_listbox_end();
+	
+	if(old_selected != selected_language)
+	{
+		str_copy(config.cl_languagefile, languages[selected_language].filename, sizeof(config.cl_languagefile));
+		localization.load(languages[selected_language].filename);
 	}
-}*/
+}
 
 void MENUS::render_settings(RECT main_view)
 {
@@ -654,6 +716,7 @@ void MENUS::render_settings(RECT main_view)
 	RECT button;
 	
 	const char *tabs[] = {
+		localize("General"),
 		localize("Player"),
 		localize("Controls"),
 		localize("Graphics"),
@@ -671,12 +734,14 @@ void MENUS::render_settings(RECT main_view)
 	ui_margin(&main_view, 10.0f, &main_view);
 	
 	if(settings_page == 0)
-		render_settings_player(main_view);
+		render_settings_general(main_view);
 	else if(settings_page == 1)
-		render_settings_controls(main_view);
+		render_settings_player(main_view);
 	else if(settings_page == 2)
-		render_settings_graphics(main_view);
+		render_settings_controls(main_view);
 	else if(settings_page == 3)
+		render_settings_graphics(main_view);
+	else if(settings_page == 4)
 		render_settings_sound(main_view);
 
 	if(need_restart)
diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp
index 752af7cd..fc17b94f 100644
--- a/src/game/client/gameclient.cpp
+++ b/src/game/client/gameclient.cpp
@@ -229,9 +229,6 @@ void GAMECLIENT::on_console_init()
 	input.add(controls);
 	input.add(binds);
 	
-	//	
-	MACRO_REGISTER_COMMAND("language", "s", CFGFLAG_CLIENT, con_language, this, "Sets the language");
-	
 	// add the some console commands
 	MACRO_REGISTER_COMMAND("team", "i", CFGFLAG_CLIENT, con_team, this, "Switch team");
 	MACRO_REGISTER_COMMAND("kill", "", CFGFLAG_CLIENT, con_kill, this, "Kill yourself");
@@ -258,6 +255,9 @@ void GAMECLIENT::on_console_init()
 
 void GAMECLIENT::on_init()
 {
+	// set the language
+	localization.load(config.cl_languagefile);
+	
 	// init all components
 	for(int i = 0; i < all.num; i++)
 		all.components[i]->on_init();
@@ -954,10 +954,3 @@ void GAMECLIENT::con_kill(void *result, void *user_data)
 {
 	((GAMECLIENT*)user_data)->send_kill(-1);
 }
-
-void GAMECLIENT::con_language(void *result, void *user_data)
-{
-	char buf[128];
-	str_format(buf, sizeof(buf), "data/languages/%s.txt", console_arg_string(result, 0));
-	localization.load(buf);
-}
diff --git a/src/game/client/gameclient.hpp b/src/game/client/gameclient.hpp
index 7d8c3701..35b95f27 100644
--- a/src/game/client/gameclient.hpp
+++ b/src/game/client/gameclient.hpp
@@ -31,7 +31,6 @@ class GAMECLIENT
 	int predicted_tick;
 	int last_new_predicted_tick;
 
-	static void con_language(void *result, void *user_data);
 	static void con_team(void *result, void *user_data);
 	static void con_kill(void *result, void *user_data);
 	
diff --git a/src/game/localization.cpp b/src/game/localization.cpp
index f78593b1..cf637eff 100644
--- a/src/game/localization.cpp
+++ b/src/game/localization.cpp
@@ -51,12 +51,18 @@ void LOCALIZATIONDATABASE::add_string(const char *org_str, const char *new_str)
 
 bool LOCALIZATIONDATABASE::load(const char *filename)
 {
+	// empty string means unload
+	if(filename[0] == 0)
+	{
+		strings.clear();
+		return true;
+	}
+	
 	LINEREADER lr;
 	IOHANDLE io = io_open(filename, IOFLAG_READ);
 	if(!io)
 		return false;
 	
-	
 	dbg_msg("localization", "loaded '%s'", filename);
 	strings.clear();
 	
diff --git a/src/game/variables.hpp b/src/game/variables.hpp
index 81f0b073..e0d9fe31 100644
--- a/src/game/variables.hpp
+++ b/src/game/variables.hpp
@@ -27,6 +27,8 @@ MACRO_CONFIG_INT(cl_motd_time, 10, 0, 100, CFGFLAG_CLIENT|CFGFLAG_SAVE, "How lon
 
 MACRO_CONFIG_STR(cl_version_server, 100, "version.teeworlds.com", CFGFLAG_CLIENT|CFGFLAG_SAVE, "Server to use to check for new versions")
 
+MACRO_CONFIG_STR(cl_languagefile, 255, "", CFGFLAG_CLIENT|CFGFLAG_SAVE, "What language file to use")
+
 MACRO_CONFIG_INT(player_use_custom_color, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Toggles usage of custom colors")
 MACRO_CONFIG_INT(player_color_body, 65408, 0, 0, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Player body color")
 MACRO_CONFIG_INT(player_color_feet, 65408, 0, 0, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Player feet color")