Added standalone options configuration dialog for GUI2

This commit is contained in:
Charles Dang 2016-09-02 09:28:30 +11:00
parent cc01b38f00
commit faed98a651
11 changed files with 522 additions and 298 deletions

View file

@ -263,278 +263,6 @@
#enddef
#define _GUI_MP_CREATE_OPTIONS_PANEL
[row]
grow_factor = 0
[column]
border = "all"
border_size = 5
[label]
id = "no_options_notice"
definition = "default"
label = _ "There are no custom options available for the selected era, game, or modification."
[/label]
[/column]
[/row]
[row]
grow_factor = 1
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
vertical_grow = "true"
[tree_view]
id = "custom_options"
definition = "default"
horizontal_scrollbar_mode = "never"
vertical_scrollbar_mode = "auto"
indentation_step_size = 25
[node]
id = "option_node"
unfolded = true
[node_definition]
[row]
[column]
[toggle_button]
id = "tree_view_node_icon"
definition = "tree_view_node"
[/toggle_button]
[/column]
[column]
grow_factor = 1
border = "left,right"
border_size = 5
horizontal_grow = "true"
[label]
id = "tree_view_node_label"
[/label]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "option_checkbox_node"
unfolded = true
[node_definition]
[row]
[column]
border = "all"
border_size = 5
horizontal_grow = "true"
[toggle_button]
id = "option_checkbox"
definition = "default"
[/toggle_button]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "option_menu_button_node"
unfolded = true
[node_definition]
[row]
[column]
border = "all"
border_size = 5
[label]
id = "menu_button_label"
definition = "default_small"
linked_group = "custom_options_labels"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
[menu_button]
id = "option_menu_button"
[/menu_button]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "option_slider_node"
unfolded = true
[node_definition]
[row]
[column]
border = "all"
border_size = 5
[label]
id = "slider_label"
definition = "default_small"
linked_group = "custom_options_labels"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
[slider]
id = "option_slider"
definition = "default"
step_size = 1
[/slider]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "option_text_entry_node"
unfolded = true
[node_definition]
[row]
[column]
border = "all"
border_size = 5
[label]
id = "text_entry_label"
definition = "default_small"
linked_group = "custom_options_labels"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
[text_box]
id = "option_text_entry"
definition = "default"
[/text_box]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "options_default_button"
unfolded = true
[node_definition]
[row]
grow_factor = 1
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "reset_option_values"
definition = "default"
label = _ "Defaults"
[/button]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "options_spacer_node"
unfolded = true
[node_definition]
[row]
grow_factor = 0
[column]
[spacer]
height = 10
[/spacer]
[/column]
[/row]
[/node_definition]
[/node]
[/tree_view]
[/column]
[/row]
#enddef
#define _GUI_MP_CREATE_MAP_SETTINGS
[row]
grow_factor = 0
@ -1254,6 +982,8 @@
[/row]
#enddef
{./mp_create_game/custom_options_tree.cfg}
[window]
id = "mp_create_game"
description = "MP create game dialog."

View file

@ -0,0 +1,275 @@
#
# Not a dialog, but a common portion of dialog layout used in at least two dialogs
#
#define _GUI_MP_CREATE_OPTIONS_PANEL
[row]
grow_factor = 0
[column]
border = "all"
border_size = 5
[label]
id = "no_options_notice"
definition = "default"
label = _ "There are no custom options available for the selected era, game, or modification."
[/label]
[/column]
[/row]
[row]
grow_factor = 1
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
vertical_grow = "true"
[tree_view]
id = "custom_options"
definition = "default"
horizontal_scrollbar_mode = "never"
vertical_scrollbar_mode = "auto"
indentation_step_size = 25
[node]
id = "option_node"
unfolded = true
[node_definition]
[row]
[column]
[toggle_button]
id = "tree_view_node_icon"
definition = "tree_view_node"
[/toggle_button]
[/column]
[column]
grow_factor = 1
border = "left,right"
border_size = 5
horizontal_grow = "true"
[label]
id = "tree_view_node_label"
[/label]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "option_checkbox_node"
unfolded = true
[node_definition]
[row]
[column]
border = "all"
border_size = 5
horizontal_grow = "true"
[toggle_button]
id = "option_checkbox"
definition = "default"
[/toggle_button]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "option_menu_button_node"
unfolded = true
[node_definition]
[row]
[column]
border = "all"
border_size = 5
[label]
id = "menu_button_label"
definition = "default_small"
linked_group = "custom_options_labels"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
[menu_button]
id = "option_menu_button"
[/menu_button]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "option_slider_node"
unfolded = true
[node_definition]
[row]
[column]
border = "all"
border_size = 5
[label]
id = "slider_label"
definition = "default_small"
linked_group = "custom_options_labels"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
[slider]
id = "option_slider"
definition = "default"
step_size = 1
[/slider]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "option_text_entry_node"
unfolded = true
[node_definition]
[row]
[column]
border = "all"
border_size = 5
[label]
id = "text_entry_label"
definition = "default_small"
linked_group = "custom_options_labels"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
[text_box]
id = "option_text_entry"
definition = "default"
[/text_box]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "options_default_button"
unfolded = true
[node_definition]
[row]
grow_factor = 1
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "reset_option_values"
definition = "default"
label = _ "Defaults"
[/button]
[/column]
[/row]
[/node_definition]
[/node]
[node]
id = "options_spacer_node"
unfolded = true
[node_definition]
[row]
grow_factor = 0
[column]
[spacer]
height = 10
[/spacer]
[/column]
[/row]
[/node_definition]
[/node]
[/tree_view]
[/column]
[/row]
#enddef

View file

@ -0,0 +1,128 @@
#textdomain wesnoth-lib
###
### Definition of the window to set custom option values in SP
###
{./mp_create_game/custom_options_tree.cfg}
[window]
id = "sp_options_configure"
description = "SP custom option configre dialog"
[resolution]
definition = "default"
automatic_placement = "true"
vertical_placement = "center"
horizontal_placement = "center"
maximum_height = 700
[tooltip]
id = "tooltip"
[/tooltip]
[helptip]
id = "tooltip"
[/helptip]
[grid]
[row]
grow_factor = 0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "title"
label = _ "Configure Options"
[/label]
[/column]
[/row]
[row]
grow_factor = 0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Configure settings for the selected custom modifications."
[/label]
[/column]
[/row]
[row]
grow_factor = 1
[column]
horizontal_grow = "true"
vertical_grow = "true"
{GUI_FORCE_WIDGET_MINIMUM_SIZE 500 0 (
[grid]
{_GUI_MP_CREATE_OPTIONS_PANEL}
[/grid]
)}
[/column]
[/row]
[row]
grow_factor = 0
[column]
grow_factor = 0
horizontal_alignment = "right"
[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]
#undef _GUI_MP_CREATE_OPTIONS_PANEL

View file

@ -623,6 +623,8 @@
<Unit filename="../../src/gui/dialogs/select_orb_colors.hpp" />
<Unit filename="../../src/gui/dialogs/simple_item_selector.cpp" />
<Unit filename="../../src/gui/dialogs/simple_item_selector.hpp" />
<Unit filename="../../src/gui/dialogs/sp_options_configure.cpp" />
<Unit filename="../../src/gui/dialogs/sp_options_configure.hpp" />
<Unit filename="../../src/gui/dialogs/theme_list.cpp" />
<Unit filename="../../src/gui/dialogs/theme_list.hpp" />
<Unit filename="../../src/gui/dialogs/tip.cpp" />

View file

@ -841,6 +841,7 @@ set(wesnoth-main_SRC
gui/dialogs/screenshot_notification.cpp
gui/dialogs/select_orb_colors.cpp
gui/dialogs/simple_item_selector.cpp
gui/dialogs/sp_options_configure.hpp
gui/dialogs/multiplayer/synced_choice_wait.cpp
gui/dialogs/theme_list.cpp
gui/dialogs/title_screen.cpp

View file

@ -418,6 +418,7 @@ wesnoth_sources = Split("""
gui/dialogs/screenshot_notification.cpp
gui/dialogs/select_orb_colors.cpp
gui/dialogs/simple_item_selector.cpp
gui/dialogs/sp_options_configure.hpp
gui/dialogs/theme_list.cpp
gui/dialogs/tip.cpp
gui/dialogs/title_screen.cpp

View file

@ -17,6 +17,7 @@
#include "game_config_manager.hpp"
#include "gui/dialogs/campaign_selection.hpp"
#include "gui/dialogs/message.hpp"
#include "gui/dialogs/sp_options_configure.hpp"
#include "gui/widgets/window.hpp"
#include "multiplayer.hpp"
#include "multiplayer_configure.hpp"
@ -115,47 +116,32 @@ bool enter_create_mode(CVideo& video, const config& game_config, saved_game& sta
);
}
create_eng.prepare_for_new_level();
create_eng.get_parameters();
if(!state.valid()) {
ERR_NG << "Cannot load scenario with id=" << state.get_scenario_id() << std::endl;
return false;
}
configure_canceled = !enter_configure_mode(video, game_config_manager::get()->game_config(), state, local_players_only);
configure_canceled = !enter_configure_mode(video, game_config_manager::get()->game_config(), state, create_eng, local_players_only);
} while (configure_canceled);
return true;
}
bool enter_configure_mode(CVideo& video, const config& game_config, saved_game& state, bool local_players_only)\
bool enter_configure_mode(CVideo& video, const config& game_config, saved_game& state, ng::create_engine& create_eng, bool local_players_only)
{
bool connect_canceled;
do {
connect_canceled = false;
gui2::tsp_options_configure dlg(create_eng);
mp::ui::result res;
dlg.show(video);
{
mp::configure ui(video, 0, game_config, gamechat, gamelist, state, local_players_only);
mp::run_lobby_loop(video, ui);
res = ui.get_result();
ui.get_parameters();
}
if(dlg.get_retval() == gui2::twindow::OK) {
create_eng.prepare_for_new_level();
create_eng.get_parameters();
switch (res) {
case mp::ui::CREATE:
connect_canceled = !enter_connect_mode(video, game_config, state, local_players_only);
break;
case mp::ui::QUIT:
default:
return false;
}
} while (connect_canceled);
enter_connect_mode(video, game_config, state, local_players_only);
}
return true;
return dlg.get_retval() == gui2::twindow::OK;
}
bool enter_connect_mode(CVideo& video, const config& game_config, saved_game& state, bool local_players_only)

View file

@ -26,7 +26,7 @@ bool enter_create_mode(CVideo& video, const config& game_config,
saved_game& state, jump_to_campaign_info jump_to, bool local_players_only = true);
bool enter_configure_mode(CVideo& video, const config& game_config,
saved_game& state, bool local_players_only = true);
saved_game& state, ng::create_engine& create_eng, bool local_players_only = true);
bool enter_connect_mode(CVideo& video, const config& game_config,
saved_game& state, bool local_players_only = true);

View file

@ -0,0 +1,49 @@
/*
Copyright (C) 2008 - 2016 by 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 as published by
the Free Software Foundation; either version 2 of the License, 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.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/dialogs/sp_options_configure.hpp"
#include "gui/widgets/settings.hpp"
namespace gui2
{
REGISTER_DIALOG(sp_options_configure)
tsp_options_configure::tsp_options_configure(ng::create_engine& create_engine)
: create_engine_(create_engine)
, config_engine_()
, options_manager_()
{
set_restore(true);
config_engine_.reset(new ng::configure_engine(create_engine_.get_state()));
config_engine_->update_initial_cfg(create_engine_.current_level().data());
}
void tsp_options_configure::pre_show(twindow& window)
{
options_manager_.reset(new tmp_options_helper(window, create_engine_));
options_manager_->update_options_list();
}
void tsp_options_configure::post_show(twindow& window)
{
if(window.get_retval() == twindow::OK) {
config_engine_->set_options(options_manager_->get_options_config());
}
}
} // namespace gui2

View file

@ -0,0 +1,49 @@
/*
Copyright (C) 2008 - 2016 by 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 as published by
the Free Software Foundation; either version 2 of the License, 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_SP_CONFIGURE_OPTIONS_HPP_INCLUDED
#define GUI_DIALOGS_SP_CONFIGURE_OPTIONS_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
#include "gui/dialogs/multiplayer/plugin_executor.hpp"
#include "gui/dialogs/multiplayer/mp_options_helper.hpp"
#include "game_initialization/create_engine.hpp"
#include "game_initialization/configure_engine.hpp"
namespace gui2
{
class tsp_options_configure : public tdialog, private plugin_executor
{
public:
explicit tsp_options_configure(ng::create_engine& create_engine);
private:
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(twindow& window);
/** Inherited from tdialog. */
void post_show(twindow& window);
ng::create_engine& create_engine_;
std::unique_ptr<ng::configure_engine> config_engine_;
std::unique_ptr<tmp_options_helper> options_manager_;
};
} // namespace gui2
#endif

View file

@ -80,6 +80,7 @@
#include "gui/dialogs/simple_item_selector.hpp"
#include "gui/dialogs/screenshot_notification.hpp"
#include "gui/dialogs/select_orb_colors.hpp"
#include "gui/dialogs/sp_options_configure.hpp"
#include "gui/dialogs/theme_list.hpp"
#include "gui/dialogs/title_screen.hpp"
#include "gui/dialogs/tip.hpp"
@ -421,6 +422,7 @@ BOOST_AUTO_TEST_CASE(test_gui2)
test<gui2::tsimple_item_selector>();
test<gui2::tscreenshot_notification>();
test<gui2::tselect_orb_colors>();
//test<gui2::tsp_options_configure>();
test<gui2::ttheme_list>();
test<gui2::ttitle_screen>();
test<gui2::ttransient_message>();
@ -486,6 +488,7 @@ BOOST_AUTO_TEST_CASE(test_gui2)
"unit_advance",
"mp_host_game_prompt",
"mp_create_game",
"sp_options_configure",
};
std::sort(list.begin(), list.end());
std::sort(omitted.begin(), omitted.end());