about summary refs log tree commit diff
path: root/src/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/game')
-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
6 files changed, 91 insertions, 25 deletions
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")