Add initial version the new language selection dialog.

It works but the used widgets look ugly and since scrolling isn't
possible yet only a few languages can be choosen.
This commit is contained in:
Mark de Wever 2008-05-11 17:47:32 +00:00
parent 3802e81182
commit 9adac709e8
11 changed files with 336 additions and 30 deletions

View file

@ -0,0 +1,154 @@
###
### Definition of the window select the language.
###
[window]
id = "language_selection"
description = "Language selection dialog."
[resolution]
definition = "default"
automatic_placement = "true"
vertical_placement = "center"
horizontal_placement = "center"
[grid]
[row]
grow_factor = 0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "title"
label = _ "Language"
[/label]
[/column]
[/row]
[row]
grow_factor = 0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Choose your preferred language:"
[/label]
[/column]
[/row]
[row]
grow_factor = 1
vertical_grow = "true"
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
horizontal_alignment = "right"
[listbox]
id = "language_list"
definition = "default"
assume_fixed_row_size = "true"
[list_definition]
[row]
grow_factor = 1
horizontal_grow = "true"
[column]
border = "all"
border_size = 2
horizontal_alignment = "left"
[toggle_button]
definition = "default"
[/toggle_button]
[/column]
[/row]
[/list_definition]
[/listbox]
[/column]
[/row]
[row]
grow_factor = 0
[column]
grow_factor = 1
horizontal_grow = "true"
[grid]
[row]
grow_factor = 0
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "ok"
definition = "default"
size_text = _ "Change language"
label = _ "Change language"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "cancel"
definition = "default"
label = _ "Cancel"
[/button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/grid]
[/resolution]
[/window]

View file

@ -5,6 +5,7 @@ src/font.cpp
src/game_preferences.cpp src/game_preferences.cpp
src/game_preferences_display.cpp src/game_preferences_display.cpp
src/gui/dialogs/addon_connect.cpp src/gui/dialogs/addon_connect.cpp
src/gui/dialogs/language_selection.cpp
src/gui/widgets/button.cpp src/gui/widgets/button.cpp
src/gui/widgets/canvas.cpp src/gui/widgets/canvas.cpp
src/gui/widgets/control.cpp src/gui/widgets/control.cpp

View file

@ -167,6 +167,7 @@ SET(wesnoth-main_SRC
generate_report.cpp generate_report.cpp
generic_event.cpp generic_event.cpp
gui/dialogs/addon_connect.cpp gui/dialogs/addon_connect.cpp
gui/dialogs/language_selection.cpp
gui/widgets/button.cpp gui/widgets/button.cpp
gui/widgets/canvas.cpp gui/widgets/canvas.cpp
gui/widgets/control.cpp gui/widgets/control.cpp

View file

@ -68,6 +68,7 @@ wesnoth_source = \
generate_report.cpp \ generate_report.cpp \
generic_event.cpp \ generic_event.cpp \
gui/dialogs/addon_connect.cpp \ gui/dialogs/addon_connect.cpp \
gui/dialogs/language_selection.cpp \
gui/widgets/button.cpp \ gui/widgets/button.cpp \
gui/widgets/canvas.cpp \ gui/widgets/canvas.cpp \
gui/widgets/control.cpp \ gui/widgets/control.cpp \

View file

@ -81,6 +81,7 @@ libwesnoth_sources = Split("""
widgets/textbox.cpp widgets/textbox.cpp
widgets/widget.cpp widgets/widget.cpp
wml_exception.cpp wml_exception.cpp
gui/dialogs/language_selection.cpp
gui/dialogs/addon_connect.cpp gui/dialogs/addon_connect.cpp
gui/widgets/button.cpp gui/widgets/button.cpp
gui/widgets/canvas.cpp gui/widgets/canvas.cpp

View file

@ -30,6 +30,7 @@
#include "gamestatus.hpp" #include "gamestatus.hpp"
#include "gettext.hpp" #include "gettext.hpp"
#include "gui/dialogs/addon_connect.hpp" #include "gui/dialogs/addon_connect.hpp"
#include "gui/dialogs/language_selection.hpp"
#include "gui/widgets/button.hpp" #include "gui/widgets/button.hpp"
#include "help.hpp" #include "help.hpp"
#include "hotkeys.hpp" #include "hotkeys.hpp"
@ -1678,41 +1679,60 @@ bool game_controller::play_multiplayer()
bool game_controller::change_language() bool game_controller::change_language()
{ {
const std::vector<language_def>& languages = get_languages(); if(new_widgets) {
std::vector<std::string> langs; gui2::tlanguage_selection dlg;
for (std::vector<language_def>::const_iterator itor = languages.begin(); dlg.show(disp().video());
itor != languages.end(); ++itor) {
if (*itor == get_language()) { if(dlg.get_retval() == gui2::tbutton::OK) {
langs.push_back("*" + itor->language); std::cerr << "OK\n";
} else { if(!no_gui_) {
langs.push_back(itor->language); std::string wm_title_string = _("The Battle for Wesnoth");
} wm_title_string += " - " + game_config::revision;
} SDL_WM_SetCaption(wm_title_string.c_str(), NULL);
}
gui::dialog lmenu(disp(),_("Language"), refresh_game_cfg(true);
_("Choose your preferred language:"), } else {
gui::OK_CANCEL); std::cerr << "Cancel\n";
lmenu.set_menu(langs); }
const int res = lmenu.show();
if(size_t(res) < langs.size()) {
::set_language(languages[res]);
preferences::set_language(languages[res].localename);
if(!no_gui_) {
std::string wm_title_string = _("The Battle for Wesnoth");
wm_title_string += " - " + game_config::revision;
SDL_WM_SetCaption(wm_title_string.c_str(), NULL);
}
refresh_game_cfg(true);
} else { } else {
return false; const std::vector<language_def>& languages = get_languages();
std::vector<std::string> langs;
for (std::vector<language_def>::const_iterator itor = languages.begin();
itor != languages.end(); ++itor) {
if (*itor == get_language()) {
langs.push_back("*" + itor->language);
} else {
langs.push_back(itor->language);
}
}
gui::dialog lmenu(disp(),_("Language"),
_("Choose your preferred language:"),
gui::OK_CANCEL);
lmenu.set_menu(langs);
const int res = lmenu.show();
if(size_t(res) < langs.size()) {
::set_language(languages[res]);
preferences::set_language(languages[res].localename);
if(!no_gui_) {
std::string wm_title_string = _("The Battle for Wesnoth");
wm_title_string += " - " + game_config::revision;
SDL_WM_SetCaption(wm_title_string.c_str(), NULL);
}
refresh_game_cfg(true);
} else {
return false;
}
font::load_font_config();
hotkey::load_descriptions();
} }
font::load_font_config();
hotkey::load_descriptions();
return true; return true;
} }

View file

@ -20,6 +20,7 @@
#include "gui/widgets/window_builder.hpp" #include "gui/widgets/window_builder.hpp"
#include "gui/widgets/settings.hpp" #include "gui/widgets/settings.hpp"
#include "gui/widgets/text_box.hpp" #include "gui/widgets/text_box.hpp"
#include "gui/widgets/vertical_scrollbar.hpp"
#include "log.hpp" #include "log.hpp"
#include "video.hpp" #include "video.hpp"
@ -42,6 +43,16 @@ void taddon_connect::show(CVideo& video)
window.keyboard_capture(host_widget); window.keyboard_capture(host_widget);
} }
tvertical_scrollbar* test_widget = dynamic_cast<tvertical_scrollbar*>(window.get_widget_by_id("test"));
if(test_widget) {
std::cerr << "testing scrollbar\n";
test_widget->set_visible_items(10);
test_widget->set_item_count(200);
test_widget->set_item_position(0);
test_widget->set_step_size(1);
}
retval_ = window.show(true); retval_ = window.show(true);
if(host_widget) { if(host_widget) {

View file

@ -0,0 +1,71 @@
/* $Id$ */
/*
copyright (C) 2008 by mark de wever <koraq@xs4all.nl>
part of the battle for wesnoth project http://www.wesnoth.org/
this program is free software; you can redistribute it and/or modify
it under the terms of the gnu general public license version 2
or at your option any later version.
this program is distributed in the hope that it will be useful,
but without any warranty.
see the copying file for more details.
*/
#include "gui/dialogs/language_selection.hpp"
#include "foreach.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/listbox.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
#include "gui/widgets/window_builder.hpp"
#include "language.hpp"
#include "log.hpp"
#include "preferences.hpp"
#include "video.hpp"
#include "wml_exception.hpp"
#define DBG_GUI LOG_STREAM_INDENT(debug, widget)
#define LOG_GUI LOG_STREAM_INDENT(info, widget)
#define WRN_GUI LOG_STREAM_INDENT(warn, widget)
#define ERR_GUI LOG_STREAM_INDENT(err, widget)
namespace gui2 {
void tlanguage_selection::show(CVideo& video)
{
gui2::init();
twindow window = build(video, get_id(LANGUAGE_SELECTION));
tlistbox* list = dynamic_cast<tlistbox*>(window.get_widget_by_id("language_list"));
VALIDATE(list, "No list defined.");
// Note we only do 15 lines since the listbox can't handle scrolling (yet).
/*const*/ std::vector<language_def>/*&*/ languages = get_languages();
languages.resize(15);
const language_def& current_language = get_language();
foreach(const language_def& lang, languages) {
list->add_item(lang.language);
if(lang == current_language) {
std::cerr << "select row " << list->get_item_count() - 1 << ".\n";
list->select_row(list->get_item_count() - 1);
}
}
window.recalculate_size();
retval_ = window.show(true);
if(retval_ == tbutton::OK) {
const unsigned res = list->get_selected_row();
::set_language(languages[res]);
preferences::set_language(languages[res].localename);
}
}
} // namespace gui2

View file

@ -0,0 +1,43 @@
/* $Id$ */
/*
copyright (c) 2008 by mark de wever <koraq@xs4all.nl>
part of the battle for wesnoth project http://www.wesnoth.org/
this program is free software; you can redistribute it and/or modify
it under the terms of the gnu general public license version 2
or at your option any later version.
this program is distributed in the hope that it will be useful,
but without any warranty.
see the copying file for more details.
*/
#ifndef __GUI_DIALOGS_LANGUAGE_SELECTION_HPP_INCLUDED__
#define __GUI_DIALOGS_LANGUAGE_SELECTION_HPP_INCLUDED__
#include <string>
class CVideo;
namespace gui2 {
class tlanguage_selection
{
public:
tlanguage_selection() :
retval_(0)
{}
void show(CVideo& video);
int get_retval() const { return retval_; }
private:
int retval_;
};
} // namespace gui2
#endif

View file

@ -81,6 +81,7 @@ namespace {
static void fill_window_types() static void fill_window_types()
{ {
window_type_list[ADDON_CONNECT] = "addon_connect"; window_type_list[ADDON_CONNECT] = "addon_connect";
window_type_list[LANGUAGE_SELECTION] = "language_selection";
} }
const std::string& get_id(const twindow_type window_type) const std::string& get_id(const twindow_type window_type)
@ -186,6 +187,7 @@ const std::string& tgui_definition::read(const config& cfg)
* @start_table = window_definition * @start_table = window_definition
* addon_connect The dialog to connect to the addon server * addon_connect The dialog to connect to the addon server
* and maintain locally installed addons. * and maintain locally installed addons.
* language_selection The dialog to select the primairy language.
* @end_table * @end_table
* *
*/ */

View file

@ -31,6 +31,7 @@ namespace gui2 {
enum twindow_type { enum twindow_type {
ADDON_CONNECT, //<! The addon connection dialog. ADDON_CONNECT, //<! The addon connection dialog.
LANGUAGE_SELECTION, //<! The language selection dialog.
DUMMY //<! Dummy always the last one. DUMMY //<! Dummy always the last one.
}; };