Base framework for GUI2 Help Browser

This commit is contained in:
Charles Dang 2017-03-23 22:58:37 +11:00
parent c8ed96f0eb
commit 3281df4e2f
7 changed files with 338 additions and 2 deletions

View file

@ -0,0 +1,203 @@
#textdomain wesnoth-lib
#define _GUI_TOPIC_TREE
[tree_view]
id = "topic_tree"
definition = "default"
horizontal_scrollbar_mode = "never"
vertical_scrollbar_mode = "always"
indentation_step_size = 20
[node]
id = "topic"
[node_definition]
[row]
[column]
horizontal_grow = "true"
[toggle_panel]
id = "tree_view_node_label"
[grid]
[row]
[column]
border = "all"
border_size = 5
[image]
id = "topic_icon"
label = "help/topic.png"
linked_group = "images"
[/image]
[/column]
[column]
border = "all"
border_size = 5
[label]
id = "topic_name"
linked_group = "names"
[/label]
[/column]
[column]
border = "all"
border_size = 5
[spacer]
width = 5
[/spacer]
[/column]
[/row]
[/grid]
[/toggle_panel]
[/column]
[/row]
[/node_definition]
[/node]
[/tree_view]
#enddef
[window]
id = "help_browser"
description = "Battle for Wesnoth Help."
[resolution]
definition = "default"
automatic_placement = "true"
vertical_placement = "center"
horizontal_placement = "center"
[tooltip]
id = "tooltip_large"
[/tooltip]
[helptip]
id = "tooltip_large"
[/helptip]
[linked_group]
id = "images"
fixed_width = true
[/linked_group]
[linked_group]
id = "names"
fixed_width = true
[/linked_group]
[grid]
[row]
grow_factor = 1
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "title"
label = _ "Battle For Wesnoth Help"
[/label]
[/column]
[/row]
[row]
[column]
grow_factor = 1
[grid]
[row]
grow_factor = 0
[column]
border = "all"
border_size = 5
horizontal_grow = true
vertical_grow = true
{_GUI_TOPIC_TREE}
[/column]
[column]
grow_factor = 1
#[multi_page]
# id = "help_text_pages"
# [page_definition]
# [row]
# grow_factor = 1
# [column]
border = "all"
border_size = 5
horizontal_grow = true
vertical_grow = true
[scroll_label]
definition = "default"
id = "topic_text"
[/scroll_label]
# [/column]
# [/row]
# [/page_definition]
#[/multi_page]
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "cancel"
label = _ "Close"
[/button]
[/column]
[/row]
[/grid]
[/resolution]
[/window]
#undef _GUI_TOPIC_TREE

View file

@ -586,6 +586,8 @@
<Unit filename="../../src/gui/dialogs/game_version.hpp" />
<Unit filename="../../src/gui/dialogs/gamestate_inspector.cpp" />
<Unit filename="../../src/gui/dialogs/gamestate_inspector.hpp" />
<Unit filename="../../src/gui/dialogs/help_browser.cpp" />
<Unit filename="../../src/gui/dialogs/help_browser.hpp" />
<Unit filename="../../src/gui/dialogs/helper.hpp" />
<Unit filename="../../src/gui/dialogs/hotkey_bind.cpp" />
<Unit filename="../../src/gui/dialogs/hotkey_bind.hpp" />

View file

@ -198,6 +198,7 @@ gui/dialogs/game_save.cpp
gui/dialogs/game_stats.cpp
gui/dialogs/game_version.cpp
gui/dialogs/gamestate_inspector.cpp
gui/dialogs/help_browser.cpp
gui/dialogs/hotkey_bind.cpp
gui/dialogs/label_settings.cpp
gui/dialogs/language_selection.cpp

View file

@ -0,0 +1,68 @@
/*
Copyright (C) 2017 by Charles Dang <exodia339@gmail.com>
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 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/help_browser.hpp"
#include "game_config_manager.hpp"
#include "gui/auxiliary/find_widget.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/image.hpp"
#include "gui/widgets/multi_page.hpp"
#include "gui/widgets/scroll_label.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/text_box.hpp"
#include "gui/widgets/tree_view.hpp"
#include "gui/widgets/window.hpp"
#ifdef GUI2_EXPERIMENTAL_LISTBOX
#include "gui/widgets/list.hpp"
#else
#include "gui/widgets/listbox.hpp"
#endif
#include "help/help.hpp"
namespace gui2
{
namespace dialogs
{
REGISTER_DIALOG(help_browser)
help_browser::help_browser()
: initial_topic_("introduction")
, help_cfg_(game_config_manager::get()->game_config().child("help"))
{
}
void help_browser::pre_show(window& window)
{
tree_view& topic_tree = find_widget<tree_view>(&window, "topic_tree", false);
for(const auto& topic : help_cfg_.child_range("topic")) {
std::map<std::string, string_map> data;
string_map item;
item["label"] = topic["title"];
data.emplace("topic_name", item);
topic_tree.add_node("topic", data);
}
}
} // namespace dialogs
} // namespace gui2

View file

@ -0,0 +1,54 @@
/*
Copyright (C) 2017 by Charles Dang <exodia339@gmail.com>
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 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_HELP_BROWSER_HPP_INCLUDED
#define GUI_DIALOGS_HELP_BROWSER_HPP_INCLUDED
#include "gui/dialogs/modal_dialog.hpp"
class config;
class CVideo;
namespace gui2
{
namespace dialogs
{
/** Help browser dialog. */
class help_browser : public modal_dialog
{
public:
help_browser();
static void display(CVideo& video)
{
help_browser().show(video);
}
private:
std::string initial_topic_;
const config& help_cfg_;
/** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
/** Inherited from modal_dialog. */
void pre_show(window& window);
};
} // namespace dialogs
} // namespace gui2
#endif

View file

@ -23,18 +23,19 @@
#include "game_launcher.hpp"
#include "game_preferences.hpp"
#include "gettext.hpp"
#include "log.hpp"
#include "gui/auxiliary/find_widget.hpp"
#include "gui/auxiliary/tips.hpp"
#include "gui/core/timer.hpp"
#include "gui/dialogs/core_selection.hpp"
#include "gui/dialogs/debug_clock.hpp"
#include "gui/dialogs/game_version.hpp"
#include "gui/dialogs/help_browser.hpp"
#include "gui/dialogs/language_selection.hpp"
#include "gui/dialogs/lua_interpreter.hpp"
#include "gui/dialogs/message.hpp"
#include "gui/dialogs/multiplayer/mp_method_selection.hpp"
#include "gui/dialogs/multiplayer/mp_host_game_prompt.hpp"
#include "gui/dialogs/multiplayer/mp_method_selection.hpp"
#include "log.hpp"
//#define DEBUG_TOOLTIP
#ifdef DEBUG_TOOLTIP
#include "gui/dialogs/tooltip.hpp"
@ -297,6 +298,10 @@ void title_screen::pre_show(window& win)
// Help
//
register_button(win, "help", hotkey::HOTKEY_HELP, [](window& w) {
//if(gui2::new_widgets) {
gui2::dialogs::help_browser::display(w.video());
//}
help::help_manager help_manager(&game_config_manager::get()->game_config());
help::show_help(w.video());
});

View file

@ -65,6 +65,7 @@
#include "gui/dialogs/game_save.hpp"
#include "gui/dialogs/game_stats.hpp"
#include "gui/dialogs/gamestate_inspector.hpp"
#include "gui/dialogs/help_browser.hpp"
#include "gui/dialogs/hotkey_bind.hpp"
#include "gui/dialogs/label_settings.hpp"
#include "gui/dialogs/language_selection.hpp"
@ -426,6 +427,7 @@ BOOST_AUTO_TEST_CASE(test_gui2)
test<game_stats>();
test<gamestate_inspector>();
test<generator_settings>();
//test<help_browser>();
test<hotkey_bind>();
test<install_dependencies>();
test<language_selection>();
@ -509,6 +511,7 @@ BOOST_AUTO_TEST_CASE(test_gui2)
"mp_join_game",
"terrain_layers",
"attack_predictions",
"help_browser",
};
std::sort(list.begin(), list.end());
std::sort(omitted.begin(), omitted.end());