1 /* 2 Copyright (C) 2008 - 2018 by the Battle for Wesnoth Project https://www.wesnoth.org/ 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY. 10 11 See the COPYING file for more details. 12 */ 13 14 #pragma once 15 16 #include "game_initialization/create_engine.hpp" 17 #include "gui/widgets/generator.hpp" 18 19 class config; 20 21 namespace gui2 22 { 23 24 class styled_widget; 25 class menu_button; 26 class toggle_button; 27 class tree_view; 28 class tree_view_node; 29 class window; 30 31 namespace dialogs 32 { 33 34 class mp_options_helper 35 { 36 public: 37 mp_options_helper(window& window, ng::create_engine& create_engine); 38 39 void update_all_options(); 40 41 void update_game_options(); 42 void update_era_options(); 43 void update_mod_options(); 44 45 config get_options_config(); 46 47 private: 48 struct option_source 49 { 50 std::string level_type; 51 std::string id; 52 operator <(const option_source & a,const option_source & b)53 friend bool operator<(const option_source& a, const option_source& b) 54 { 55 return std::tie(a.level_type, a.id) < std::tie(b.level_type, b.id); 56 } 57 }; 58 59 int remove_nodes_for_type(const std::string& type); 60 61 using data_map = std::map<std::string, string_map>; 62 63 template <typename T> 64 std::pair<T*, config::attribute_value> add_node_and_get_widget( 65 tree_view_node& option_node, const std::string& id, data_map& data, const config& cfg); 66 67 void display_custom_options(const std::string& type, int node_position, const config& data); 68 69 template<typename T> 70 void update_options_data_map(T* widget, const option_source& source); 71 void update_options_data_map(toggle_button* widget, const option_source& source); 72 73 // NOTE: this cannot be an overload of update_options_data_map since that's a templated function 74 void update_options_data_map_menu_button(menu_button* widget, const option_source& source, const config& cfg); 75 76 void reset_options_data(const option_source& source, bool& handled, bool& halt); 77 78 void update_status_label(); 79 80 ng::create_engine& create_engine_; 81 82 tree_view& options_tree_; 83 styled_widget& no_options_notice_; 84 85 using node_vector = std::vector<tree_view_node*>; 86 87 struct type_node_data 88 { type_node_datagui2::dialogs::mp_options_helper::type_node_data89 type_node_data() : nodes(), position(-1) {} 90 91 node_vector nodes; 92 int position; 93 operator <gui2::dialogs::mp_options_helper::type_node_data94 bool operator<(const type_node_data& data) { 95 return (*this).position < data.position; 96 } 97 }; 98 99 std::map<std::string, type_node_data> node_data_map_; 100 101 std::vector<option_source> visible_options_; 102 std::map<std::string, config> options_data_; 103 }; 104 105 } // namespace dialogs 106 } // namespace gui2 107