Adding initial proof-of-concept version for the MP method selection dialog.

This commit is contained in:
Mark de Wever 2008-05-23 18:25:20 +00:00
parent 08bbd2027d
commit 63ad8892c7
10 changed files with 395 additions and 24 deletions

View file

@ -0,0 +1,222 @@
###
### Definition of the window select the way to access the addon server.
###
[window]
id = "mp_method_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 = _ "Multiplayer"
[/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 = _ "Login:"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
[text_box]
id = "user_name"
definition = "default"
history = "mp_user_name_history"
label = ""
[/text_box]
[/column]
[/row]
[/grid]
[/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 = "method_list"
definition = "default"
assume_fixed_row_size = "true"
[list_definition]
[row]
[column]
grow_factor = 1
horizontal_grow = "true"
[toggle_button]
definition = "listbox_text" # listbox_text_with_icon
[/toggle_button]
[/column]
[/row]
[/list_definition]
[list_data]
[row]
[column]
retval = 1
label = _ "Join Official Server"
tooltip = _ "Log on to the official Wesnoth multiplayer server"
icon = "server.png"
[/column]
[/row]
[row]
[column]
retval = 2
label = _ "Connect to Server"
tooltip = _ "Join a different server"
icon = "serverother.png"
[/column]
[/row]
[row]
[column]
retval = 3
label = _ "Local Game"
tooltip = _ "Play a multiplayer game with the AI or humans sharing the same machine"
icon = "hotseat.png"
[/column]
[/row]
[/list_data]
[/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"
label = _ "Ok"
[/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

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

View file

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

View file

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

View file

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

View file

@ -31,6 +31,7 @@
#include "gettext.hpp"
#include "gui/dialogs/addon_connect.hpp"
#include "gui/dialogs/language_selection.hpp"
#include "gui/dialogs/mp_method_selection.hpp"
#include "gui/widgets/button.hpp"
#include "help.hpp"
#include "hotkeys.hpp"
@ -1578,36 +1579,55 @@ bool game_controller::play_multiplayer()
state_.campaign_type = "multiplayer";
state_.campaign_define = "MULTIPLAYER";
//Print Gui only if the user hasn't specified any server
if( multiplayer_server_.empty() ){
std::vector<std::string> host_or_join;
std::string const pre = IMAGE_PREFIX + std::string("icons/icon-");
char const sep1 = COLUMN_SEPARATOR, sep2 = HELP_STRING_SEPARATOR;
if(new_widgets) {
gui2::tmp_method_selection dlg;
host_or_join.push_back(pre + "server.png"
+ sep1 + _("Join Official Server")
+ sep2 + _("Log on to the official Wesnoth multiplayer server"));
host_or_join.push_back(pre + "serverother.png"
+ sep1 + _("Connect to Server")
+ sep2 + _("Join a different server"));
host_or_join.push_back(pre + "hotseat.png"
+ sep1 + _("Local Game")
+ sep2 + _("Play a multiplayer game with the AI or humans sharing the same machine"));
dlg.show(disp().video());
if(dlg.get_retval() == gui2::tbutton::OK) {
std::cerr << "OK\n";
res = dlg.get_choice();
} else {
std::cerr << "CANCEL\n";
return false;
std::string login = preferences::login();
}
{
gui::dialog d(disp(), _("Multiplayer"), "", gui::OK_CANCEL);
d.set_menu(host_or_join);
d.set_textbox(_("Login: "), login, mp::max_login_size, font::relative_size(250));
res = d.show();
login = d.textbox_text();
} else {
std::vector<std::string> host_or_join;
std::string const pre = IMAGE_PREFIX + std::string("icons/icon-");
char const sep1 = COLUMN_SEPARATOR, sep2 = HELP_STRING_SEPARATOR;
host_or_join.push_back(pre + "server.png"
+ sep1 + _("Join Official Server")
+ sep2 + _("Log on to the official Wesnoth multiplayer server"));
host_or_join.push_back(pre + "serverother.png"
+ sep1 + _("Connect to Server")
+ sep2 + _("Join a different server"));
host_or_join.push_back(pre + "hotseat.png"
+ sep1 + _("Local Game")
+ sep2 + _("Play a multiplayer game with the AI or humans sharing the same machine"));
std::string login = preferences::login();
{
gui::dialog d(disp(), _("Multiplayer"), "", gui::OK_CANCEL);
d.set_menu(host_or_join);
d.set_textbox(_("Login: "), login, mp::max_login_size, font::relative_size(250));
res = d.show();
login = d.textbox_text();
}
if (res < 0)
return false;
preferences::set_login(login);
}
if (res < 0)
return false;
preferences::set_login(login);
}else{
res = 3;

View file

@ -0,0 +1,72 @@
/* $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_method_selection.hpp"
#include "game_preferences.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/listbox.hpp"
#include "gui/widgets/toggle_button.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 {
void tmp_method_selection::show(CVideo& video)
{
gui2::init();
twindow window = build(video, get_id(MP_METHOD_SELECTION));
user_name_ = preferences::login();
ttext_box* user_widget = dynamic_cast<ttext_box*>(window.find_widget("user_name", false));
if(user_widget) {
user_widget->set_text(user_name_);
window.keyboard_capture(user_widget);
}
tlistbox* list = dynamic_cast<tlistbox*>(window.find_widget("method_list", false));
VALIDATE(list, "No list defined.");
list->add_item("Join Official Server");
list->add_item("Connect to Server");
list->add_item("Local Game");
list->select_row(0);
window.recalculate_size();
retval_ = window.show(true);
if(retval_ == tbutton::OK) {
choice_ = list->get_selected_row();
user_widget->save_to_history();
user_name_= user_widget->get_text();
preferences::set_login(user_name_);
}
}
} // namespace gui2

View file

@ -0,0 +1,50 @@
/* $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_METHOD_SELECTION_HPP_INCLUDED__
#define __GUI_DIALOGS_MP_METHOD_SELECTION_HPP_INCLUDED__
#include <string>
class CVideo;
namespace gui2 {
class tmp_method_selection
{
public:
tmp_method_selection() :
retval_(0),
user_name_(),
choice_(-1)
{}
void show(CVideo& video);
int get_retval() const { return retval_; }
const std::string& user_name() const { return user_name_; }
int get_choice() const { return choice_; }
private:
int retval_;
std::string user_name_;
int choice_;
};
} // namespace gui2
#endif

View file

@ -82,6 +82,7 @@ static void fill_window_types()
{
window_type_list[ADDON_CONNECT] = "addon_connect";
window_type_list[LANGUAGE_SELECTION] = "language_selection";
window_type_list[MP_METHOD_SELECTION] = "mp_method_selection";
}
const std::string& get_id(const twindow_type window_type)

View file

@ -33,6 +33,8 @@ namespace gui2 {
enum twindow_type {
ADDON_CONNECT, //<! The addon connection dialog.
LANGUAGE_SELECTION, //<! The language selection dialog.
MP_METHOD_SELECTION, //<! The dialog which allows you to choose the kind
//! mp game the user wants to play.
DUMMY //<! Dummy always the last one.
};