Convert the MP server selection dialog,
...including the server list dialog, to the new widget library. (The listbox widget needs some redesigning since it starts it looks rather bad with two columns (which can be fixed with a small hack but rather find a cleaner way in general).)
This commit is contained in:
parent
7808ddb06f
commit
d2580054b8
8 changed files with 694 additions and 7 deletions
206
data/gui/default/window/mp_connect.cfg
Normal file
206
data/gui/default/window/mp_connect.cfg
Normal file
|
@ -0,0 +1,206 @@
|
|||
###
|
||||
### Definition of the window to connect to the MP server
|
||||
###
|
||||
|
||||
[window]
|
||||
id = "mp_connect"
|
||||
description = "Addon server connection 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 = _ "Connect to Server"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
[label]
|
||||
definition = "default"
|
||||
|
||||
label = _ "You will now connect to the multiplayer server."
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
grow_factor = 0
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
definition = "default"
|
||||
|
||||
label = _ "Server:"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_grow = "true"
|
||||
|
||||
[text_box]
|
||||
id = "host_name"
|
||||
definition = "default"
|
||||
history = "mp_connect_history"
|
||||
|
||||
label = ""
|
||||
[/text_box]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
[spacer]
|
||||
definition = "default"
|
||||
[/spacer]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
|
||||
[spacer]
|
||||
definition = "default"
|
||||
[/spacer]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "list"
|
||||
definition = "default"
|
||||
|
||||
label = _ "View List"
|
||||
[/button]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
|
||||
[spacer]
|
||||
definition = "default"
|
||||
[/spacer]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "ok"
|
||||
definition = "default"
|
||||
|
||||
size_text = _ "Connect"
|
||||
label = _ "Connect"
|
||||
[/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]
|
200
data/gui/default/window/mp_server_list.cfg
Normal file
200
data/gui/default/window/mp_server_list.cfg
Normal file
|
@ -0,0 +1,200 @@
|
|||
###
|
||||
### Definition of the window to select a predefined mp server.
|
||||
###
|
||||
|
||||
[window]
|
||||
id = "mp_server_list"
|
||||
description = "MP Server list 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 = _ "Connect to Server"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 0
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "left"
|
||||
|
||||
[label]
|
||||
definition = "default"
|
||||
|
||||
label = _ "You will now connect to the multiplayer server."
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[row]
|
||||
grow_factor = 1
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
|
||||
horizontal_grow = "true"
|
||||
vertical_grow = "true"
|
||||
|
||||
[listbox]
|
||||
id = "server_list"
|
||||
definition = "default"
|
||||
|
||||
assume_fixed_row_size = "true"
|
||||
|
||||
[header]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
[label]
|
||||
definition = "default"
|
||||
|
||||
label = _ "Name"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
[label]
|
||||
definition = "default"
|
||||
|
||||
label = _ "Address"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/header]
|
||||
|
||||
[list_definition]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
[toggle_button]
|
||||
id = "name"
|
||||
definition = "listbox_text"
|
||||
[/toggle_button]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
[toggle_button]
|
||||
id = "address"
|
||||
definition = "listbox_text"
|
||||
[/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]
|
||||
|
||||
[spacer]
|
||||
definition = "default"
|
||||
[/spacer]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
border = "all"
|
||||
border_size = 5
|
||||
horizontal_alignment = "right"
|
||||
|
||||
[button]
|
||||
id = "ok"
|
||||
definition = "default"
|
||||
|
||||
label = _ "Select"
|
||||
[/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]
|
|
@ -72,6 +72,7 @@ wesnoth_source = \
|
|||
gui/dialogs/addon_connect.cpp \
|
||||
gui/dialogs/dialog.cpp \
|
||||
gui/dialogs/language_selection.cpp \
|
||||
gui/dialogs/mp_connect.cpp \
|
||||
gui/dialogs/mp_method_selection.cpp \
|
||||
gui/widgets/button.cpp \
|
||||
gui/widgets/canvas.cpp \
|
||||
|
|
201
src/gui/dialogs/mp_connect.cpp
Normal file
201
src/gui/dialogs/mp_connect.cpp
Normal file
|
@ -0,0 +1,201 @@
|
|||
/* $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/mp_connect.hpp"
|
||||
|
||||
#include "foreach.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
#include "gui/widgets/button.hpp"
|
||||
#include "gui/widgets/listbox.hpp"
|
||||
#include "gui/widgets/widget.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "gui/widgets/window_builder.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/text_box.hpp"
|
||||
#include "log.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 {
|
||||
|
||||
namespace {
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIWindowWML
|
||||
* @order = 2_mp_server_list
|
||||
*
|
||||
* == Multiplayer server list ==
|
||||
*
|
||||
* This shows the dialog with a list of predefined multiplayer servers.
|
||||
*
|
||||
* @start_table = container
|
||||
* server_list listbox Listbox with the predefined servers to
|
||||
* connect to.
|
||||
* # [name] - Widgets which shows the name of the
|
||||
* server.
|
||||
* # address - The address/host_name of the server.
|
||||
* @end_table
|
||||
*/
|
||||
|
||||
class tmp_server_list : public tdialog
|
||||
{
|
||||
public:
|
||||
tmp_server_list() :
|
||||
host_name_()
|
||||
{}
|
||||
|
||||
const std::string& host_name() const { return host_name_; }
|
||||
|
||||
private:
|
||||
std::string host_name_;
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
twindow build_window(CVideo& video)
|
||||
{ return build(video, get_id(MP_SERVER_LIST)); }
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
void pre_show(CVideo& video, twindow& window);
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
void post_show(twindow& window);
|
||||
};
|
||||
|
||||
void tmp_server_list::pre_show(CVideo& video, twindow& window)
|
||||
{
|
||||
tlistbox* list =
|
||||
dynamic_cast<tlistbox*>(window.find_widget("server_list", false));
|
||||
VALIDATE(list, missing_widget("server_list"));
|
||||
|
||||
const std::vector<game_config::server_info>&
|
||||
pref_servers = preferences::server_list();
|
||||
|
||||
foreach(const game_config::server_info& server, pref_servers) {
|
||||
|
||||
std::map<std::string, tlistbox::titem> data;
|
||||
data.insert(std::make_pair("name", tlistbox::titem(server.name, "")));
|
||||
data.insert(std::make_pair(
|
||||
"address", tlistbox::titem(server.address, "")));
|
||||
|
||||
list->add_item(data);
|
||||
}
|
||||
|
||||
window.recalculate_size();
|
||||
}
|
||||
|
||||
void tmp_server_list::post_show(twindow& window)
|
||||
{
|
||||
if(get_retval() == tbutton::OK) {
|
||||
|
||||
const tlistbox* list =
|
||||
dynamic_cast<tlistbox*>(window.find_widget("server_list", false));
|
||||
assert(list);
|
||||
|
||||
const tgrid* row = list->get_row_grid(list->get_selected_row());
|
||||
assert(row);
|
||||
|
||||
const tcontrol* address =
|
||||
dynamic_cast<const tcontrol*>(row->find_widget("address", false));
|
||||
assert(address);
|
||||
|
||||
host_name_ = address->label();
|
||||
}
|
||||
}
|
||||
|
||||
void callback_view_list_button(twidget* caller)
|
||||
{
|
||||
assert(caller);
|
||||
|
||||
tmp_connect* mp_connect = dynamic_cast<tmp_connect*>(caller->dialog());
|
||||
assert(mp_connect);
|
||||
|
||||
mp_connect->show_server_list();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIWindowWML
|
||||
* @order = 2_mp_connect
|
||||
*
|
||||
* == Multiplayer connect ==
|
||||
*
|
||||
* This shows the dialog to the MP server to connect to.
|
||||
*
|
||||
* @start_table = container
|
||||
* host_name text_box The name of the server to connect to.
|
||||
* [list] button Shows a dialog with a list of predefined
|
||||
* servers to connect to.
|
||||
* @end_table
|
||||
*/
|
||||
|
||||
twindow tmp_connect::build_window(CVideo& video)
|
||||
{
|
||||
return build(video, get_id(MP_CONNECT));
|
||||
}
|
||||
|
||||
void tmp_connect::pre_show(CVideo& video, twindow& window)
|
||||
{
|
||||
assert(!video_);
|
||||
assert(!host_name_widget_);
|
||||
video_ = &video;
|
||||
|
||||
host_name_widget_ =
|
||||
dynamic_cast<ttext_box*>(window.find_widget("host_name", false));
|
||||
VALIDATE(host_name_widget_, missing_widget("host_name"));
|
||||
|
||||
host_name_widget_->set_text(preferences::network_host());
|
||||
window.keyboard_capture(host_name_widget_);
|
||||
|
||||
// Set view list callback button.
|
||||
tbutton *view_list =
|
||||
dynamic_cast<tbutton*>(window.find_widget("list", false));
|
||||
if(view_list) {
|
||||
view_list->set_callback_mouse_left_click(callback_view_list_button);
|
||||
}
|
||||
}
|
||||
|
||||
void tmp_connect::post_show(twindow& window)
|
||||
{
|
||||
if(get_retval() == tbutton::OK) {
|
||||
host_name_widget_->save_to_history();
|
||||
host_name_= host_name_widget_->get_text();
|
||||
preferences::set_network_host(host_name_);
|
||||
}
|
||||
|
||||
video_ = 0;
|
||||
host_name_widget_ = 0;
|
||||
}
|
||||
|
||||
void tmp_connect::show_server_list()
|
||||
{
|
||||
assert(video_);
|
||||
assert(host_name_widget_);
|
||||
|
||||
tmp_server_list dlg;
|
||||
dlg.show(*video_);
|
||||
|
||||
if(dlg.get_retval() == tbutton::OK) {
|
||||
host_name_widget_->set_text(dlg.host_name());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
61
src/gui/dialogs/mp_connect.hpp
Normal file
61
src/gui/dialogs/mp_connect.hpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* $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_MP_CONNECT_HPP_INCLUDED
|
||||
#define GUI_DIALOGS_MP_CONNECT_HPP_INCLUDED
|
||||
|
||||
#include "gui/dialogs/dialog.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
class twidget;
|
||||
class ttext_box;
|
||||
|
||||
class tmp_connect : public tdialog
|
||||
{
|
||||
public:
|
||||
tmp_connect() :
|
||||
host_name_(),
|
||||
video_(0),
|
||||
host_name_widget_(0)
|
||||
{}
|
||||
|
||||
const std::string& host_name() const { return host_name_; }
|
||||
|
||||
private:
|
||||
std::string host_name_;
|
||||
|
||||
/** Used in show in order to show list. */
|
||||
CVideo* video_;
|
||||
|
||||
/** Widget for the host name. */
|
||||
ttext_box* host_name_widget_;
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
twindow build_window(CVideo& video);
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
void pre_show(CVideo& video, twindow& window);
|
||||
|
||||
/** Inherited from tdialog. */
|
||||
void post_show(twindow& window);
|
||||
public:
|
||||
friend void callback_view_list_button(twidget* caller);
|
||||
void show_server_list();
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
|
@ -84,7 +84,9 @@ static void fill_window_types()
|
|||
{
|
||||
window_type_list[ADDON_CONNECT] = "addon_connect";
|
||||
window_type_list[LANGUAGE_SELECTION] = "language_selection";
|
||||
window_type_list[MP_CONNECT] = "mp_connect";
|
||||
window_type_list[MP_METHOD_SELECTION] = "mp_method_selection";
|
||||
window_type_list[MP_SERVER_LIST] = "mp_server_list";
|
||||
}
|
||||
|
||||
const std::string& get_id(const twindow_type window_type)
|
||||
|
|
|
@ -34,10 +34,12 @@ namespace gui2 {
|
|||
extern bool new_widgets;
|
||||
|
||||
enum twindow_type {
|
||||
ADDON_CONNECT, //<! The addon connection dialog.
|
||||
ADDON_CONNECT, //<! The addon server connection dialog.
|
||||
LANGUAGE_SELECTION, //<! The language selection dialog.
|
||||
MP_CONNECT, //<! The mp server connection dialog.
|
||||
MP_METHOD_SELECTION, //<! The dialog which allows you to choose the kind
|
||||
//! mp game the user wants to play.
|
||||
MP_SERVER_LIST, //<! The mp server list dialog.
|
||||
|
||||
DUMMY //<! Dummy always the last one.
|
||||
};
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include "dialogs.hpp"
|
||||
#include "game_config.hpp"
|
||||
#include "gettext.hpp"
|
||||
#include "gui/dialogs/mp_connect.hpp"
|
||||
#include "gui/widgets/button.hpp"
|
||||
#include "log.hpp"
|
||||
#include "multiplayer.hpp"
|
||||
#include "multiplayer_ui.hpp"
|
||||
|
@ -134,13 +136,25 @@ static server_type open_connection(game_display& disp, const std::string& origin
|
|||
std::string h = original_host;
|
||||
|
||||
if(h.empty()) {
|
||||
gui::dialog d(disp, _("Connect to Host"), "", gui::OK_CANCEL);
|
||||
d.set_textbox(_("Choose host to connect to: "), preferences::network_host());
|
||||
d.add_button( new server_button(disp.video()), gui::dialog::BUTTON_EXTRA);
|
||||
if(d.show() || d.textbox_text().empty()) {
|
||||
return ABORT_SERVER;
|
||||
if(gui2::new_widgets) {
|
||||
gui2::tmp_connect dlg;
|
||||
|
||||
dlg.show(disp.video());
|
||||
if(dlg.get_retval() == gui2::tbutton::OK) {
|
||||
h = dlg.host_name();
|
||||
} else {
|
||||
return ABORT_SERVER;
|
||||
}
|
||||
|
||||
} else {
|
||||
gui::dialog d(disp, _("Connect to Host"), "", gui::OK_CANCEL);
|
||||
d.set_textbox(_("Choose host to connect to: "), preferences::network_host());
|
||||
d.add_button( new server_button(disp.video()), gui::dialog::BUTTON_EXTRA);
|
||||
if(d.show() || d.textbox_text().empty()) {
|
||||
return ABORT_SERVER;
|
||||
}
|
||||
h = d.textbox_text();
|
||||
}
|
||||
h = d.textbox_text();
|
||||
}
|
||||
|
||||
network::connection sock;
|
||||
|
|
Loading…
Add table
Reference in a new issue