From 3281df4e2f00319b8cc5b84088739d88021231cf Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Thu, 23 Mar 2017 22:58:37 +1100 Subject: [PATCH] Base framework for GUI2 Help Browser --- data/gui/window/help_browser.cfg | 203 ++++++++++++++++++++++++++++ projectfiles/CodeBlocks/wesnoth.cbp | 2 + source_lists/wesnoth | 1 + src/gui/dialogs/help_browser.cpp | 68 ++++++++++ src/gui/dialogs/help_browser.hpp | 54 ++++++++ src/gui/dialogs/title_screen.cpp | 9 +- src/tests/gui/test_gui2.cpp | 3 + 7 files changed, 338 insertions(+), 2 deletions(-) create mode 100644 data/gui/window/help_browser.cfg create mode 100644 src/gui/dialogs/help_browser.cpp create mode 100644 src/gui/dialogs/help_browser.hpp diff --git a/data/gui/window/help_browser.cfg b/data/gui/window/help_browser.cfg new file mode 100644 index 00000000000..ef607514c1b --- /dev/null +++ b/data/gui/window/help_browser.cfg @@ -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 diff --git a/projectfiles/CodeBlocks/wesnoth.cbp b/projectfiles/CodeBlocks/wesnoth.cbp index 56253ad9b02..886fed1b085 100644 --- a/projectfiles/CodeBlocks/wesnoth.cbp +++ b/projectfiles/CodeBlocks/wesnoth.cbp @@ -586,6 +586,8 @@ + + diff --git a/source_lists/wesnoth b/source_lists/wesnoth index 094c18e8759..9e04e629e55 100644 --- a/source_lists/wesnoth +++ b/source_lists/wesnoth @@ -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 diff --git a/src/gui/dialogs/help_browser.cpp b/src/gui/dialogs/help_browser.cpp new file mode 100644 index 00000000000..59270d92854 --- /dev/null +++ b/src/gui/dialogs/help_browser.cpp @@ -0,0 +1,68 @@ +/* + Copyright (C) 2017 by Charles Dang + 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(&window, "topic_tree", false); + + for(const auto& topic : help_cfg_.child_range("topic")) { + std::map data; + string_map item; + + item["label"] = topic["title"]; + data.emplace("topic_name", item); + + topic_tree.add_node("topic", data); + } +} + +} // namespace dialogs +} // namespace gui2 diff --git a/src/gui/dialogs/help_browser.hpp b/src/gui/dialogs/help_browser.hpp new file mode 100644 index 00000000000..24e1169bccb --- /dev/null +++ b/src/gui/dialogs/help_browser.hpp @@ -0,0 +1,54 @@ +/* + Copyright (C) 2017 by Charles Dang + 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 diff --git a/src/gui/dialogs/title_screen.cpp b/src/gui/dialogs/title_screen.cpp index ddf54e26616..b9c33a5a578 100644 --- a/src/gui/dialogs/title_screen.cpp +++ b/src/gui/dialogs/title_screen.cpp @@ -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()); }); diff --git a/src/tests/gui/test_gui2.cpp b/src/tests/gui/test_gui2.cpp index 724b009948d..e1c826cc040 100644 --- a/src/tests/gui/test_gui2.cpp +++ b/src/tests/gui/test_gui2.cpp @@ -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(); test(); test(); + //test(); test(); test(); test(); @@ -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());