The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
mp::options::manager Class Reference

#include <mp_options.hpp>

Public Member Functions

 manager (const config &gamecfg, CVideo &video, gui::scrollpane *pane, const config &initial_value)
 Constructor. More...
 
 ~manager ()
 
void set_values (const config &values)
 Set the current values the options. More...
 
void set_era (const std::string &id)
 Sets the selected era. More...
 
void set_scenario (const std::string &id)
 Sets the selected scenario. More...
 
void set_campaign (const std::string &id)
 Sets the selected campaign. More...
 
void set_modifications (const std::vector< std::string > &ids)
 Sets the activated modifications. More...
 
void layout_widgets (int startx, int starty, int w)
 
void process_event ()
 
void hide_children (bool hide=true)
 
const configget_values ()
 Returns the the values for each option. More...
 
void init_widgets ()
 
void restore_defaults (const std::string &component)
 
bool has_options () const
 

Private Member Functions

void init_info (const config &cfg, const std::string &key)
 Adds the necessary information about the specified component to options_info_. More...
 
configget_value_cfg (const std::string &id)
 Returns the node which holds the selected value of an option. More...
 
const configget_value_cfg_or_empty (const std::string &id) const
 Returns the node which holds the selected value of an option. More...
 
const configget_option_info_cfg (const std::string &id) const
 Returns the information about an option. More...
 
const configget_component_cfg (const std::string &id) const
 
config::any_child get_option_parent (const std::string &id) const
 Finds the parent node of an options. More...
 
config::attribute_value get_stored_value (const std::string &id) const
 Retrieves the saved value for a certain option, or the default, if there's no such. More...
 
config::attribute_value get_default_value (const std::string &id) const
 Retrieves the default value for a certain option. More...
 
void extract_values (const std::string &key, const std::string &id)
 Writes all the values for the options of a certain component from a specified window into values_. More...
 
void update_values ()
 
bool is_active (const std::string &id) const
 

Static Private Member Functions

static bool is_valid_option (const std::string &key, const config &option)
 Decides whether a config is a sane option node or not. More...
 

Private Attributes

config options_info_
 Stores needed info about each element and their configuration options. More...
 
config values_
 Stores the selected values for each option. More...
 
CVideovideo_
 The screen to display the dialog on. More...
 
gui::scrollpanepane_
 The scrollarea to put the widgets on. More...
 
std::string era_
 The id of the selected era. More...
 
std::string scenario_
 The id of the selected [multiplayer] or [campaign]. More...
 
bool is_campaign_
 
std::vector< std::stringmodifications_
 The ids of the selected modifications. More...
 
std::map< std::string,
option_display * > 
widgets_
 
std::vector< option_display * > widgets_ordered_
 

Detailed Description

Definition at line 150 of file mp_options.hpp.

Constructor & Destructor Documentation

mp::options::manager::manager ( const config gamecfg,
CVideo video,
gui::scrollpane pane,
const config initial_value 
)

Constructor.

Parameters
gamecfgThe config object holding all eras, scenarios and modifications.
displayThe screen to display the dialog on.
initial_valueThe initial values for each option.

Definition at line 110 of file mp_options.cpp.

References config::all_children_range(), DBG_MP, get_stored_value(), get_value_cfg(), i, init_info(), init_widgets(), is_valid_option(), and options_info_.

mp::options::manager::~manager ( )

Definition at line 142 of file mp_options.cpp.

References widgets_ordered_.

Member Function Documentation

void mp::options::manager::extract_values ( const std::string key,
const std::string id 
)
private

Writes all the values for the options of a certain component from a specified window into values_.

Parameters
keyThe component's type.
idThe component's id.

Definition at line 323 of file mp_options.cpp.

References config::all_children_range(), config::find_child(), get_value_cfg(), is_valid_option(), options_info_, and widgets_.

Referenced by update_values().

const config & mp::options::manager::get_component_cfg ( const std::string id) const
private

Definition at line 284 of file mp_options.cpp.

References e, config::find_child(), and options_info_.

Referenced by restore_defaults().

config::attribute_value mp::options::manager::get_default_value ( const std::string id) const
private

Retrieves the default value for a certain option.

Parameters
idThe id of the option.
Returns
The default value for this option.

Definition at line 316 of file mp_options.cpp.

References get_option_info_cfg().

Referenced by get_stored_value(), and restore_defaults().

const config & mp::options::manager::get_option_info_cfg ( const std::string id) const
private

Returns the information about an option.

Parameters
idThe id of the option.
Returns
The config object which contains the settings of the option, or an empty config if the option was not found.

Definition at line 269 of file mp_options.cpp.

References config::all_children_range(), i, and options_info_.

Referenced by get_default_value().

config::any_child mp::options::manager::get_option_parent ( const std::string id) const
private

Finds the parent node of an options.

Parameters
idThe id of the option.
Returns
A config::any_child object containing the key and the data of the parent node, or "" for the key and an empty config if the option was not found.

Definition at line 252 of file mp_options.cpp.

References config::all_children_range(), i, and options_info_.

Referenced by get_value_cfg().

config::attribute_value mp::options::manager::get_stored_value ( const std::string id) const
private

Retrieves the saved value for a certain option, or the default, if there's no such.

Parameters
idThe id of the option.
Returns
The value saved in values_ for this option or its specified default value if a saved value can't be found.

Definition at line 303 of file mp_options.cpp.

References get_default_value(), and get_value_cfg_or_empty().

Referenced by init_widgets(), and manager().

config & mp::options::manager::get_value_cfg ( const std::string id)
private

Returns the node which holds the selected value of an option.

If that node is not yet created, the function creates it.

Parameters
idThe id of the option.
Returns
A reference to the config which the value for this option should be written into.

Definition at line 213 of file mp_options.cpp.

References config::add_child(), config::any_child::cfg, config::empty(), config::find_child(), get_option_parent(), get_value_cfg_or_empty(), lg::info(), config::any_child::key, and values_.

Referenced by extract_values(), and manager().

const config & mp::options::manager::get_value_cfg_or_empty ( const std::string id) const
private

Returns the node which holds the selected value of an option.

If that node is not yet created, the function returns an empty config.

Parameters
idThe id of the option.
Returns
A reference to the config which the value for this option should be written into or an empty config if that doesn't exist.

Definition at line 237 of file mp_options.cpp.

References config::all_children_range(), i, and values_.

Referenced by get_stored_value(), and get_value_cfg().

const config & mp::options::manager::get_values ( )

Returns the the values for each option.

Returns
A config containing the values.

Definition at line 207 of file mp_options.cpp.

References update_values(), and values_.

Referenced by mp::configure::get_parameters().

bool mp::options::manager::has_options ( ) const

Definition at line 105 of file mp_options.cpp.

References widgets_.

Referenced by mp::configure::configure().

void mp::options::manager::hide_children ( bool  hide = true)

Definition at line 197 of file mp_options.cpp.

References i, and widgets_.

Referenced by mp::configure::hide_children().

void mp::options::manager::init_info ( const config cfg,
const std::string key 
)
private

Adds the necessary information about the specified component to options_info_.

Parameters
cfgThe component's data.
keyThe component's type.

Definition at line 37 of file mp_options.cpp.

References config::add_child(), config::all_children_range(), config::child(), config::child_range(), preferences::options(), and options_info_.

Referenced by manager().

void mp::options::manager::init_widgets ( )
bool mp::options::manager::is_active ( const std::string id) const
private

Definition at line 356 of file mp_options.cpp.

References era_, gui2::event::find(), modifications_, and scenario_.

Referenced by init_widgets().

bool mp::options::manager::is_valid_option ( const std::string key,
const config option 
)
staticprivate

Decides whether a config is a sane option node or not.

A valid option node:

  • Must have an id field.
  • Its key must be "slider", "entry" or "checkbox"
Parameters
keyThe option's key.
optionThe option's data.
Returns
True if the option is valid, false if not.

Definition at line 350 of file mp_options.cpp.

References config::empty().

Referenced by extract_values(), manager(), and restore_defaults().

void mp::options::manager::layout_widgets ( int  startx,
int  starty,
int  w 
)

Definition at line 178 of file mp_options.cpp.

References pane_, and widgets_ordered_.

Referenced by mp::configure::layout_children().

void mp::options::manager::process_event ( )

Definition at line 189 of file mp_options.cpp.

References i, and widgets_ordered_.

Referenced by mp::configure::process_event_impl().

void mp::options::manager::restore_defaults ( const std::string component)
void mp::options::manager::set_campaign ( const std::string id)

Sets the selected campaign.

Whenever show_dialog is called, only options for the campaign scenario will be displayed.

Parameters
idThe campaign's id.

Definition at line 167 of file mp_options.cpp.

References is_campaign_, and scenario_.

Referenced by mp::configure::configure().

void mp::options::manager::set_era ( const std::string id)

Sets the selected era.

Whenever show_dialog is called, only options for the selected era will be displayed.

Parameters
idThe era's id.

Definition at line 156 of file mp_options.cpp.

References preferences::era(), and era_.

Referenced by mp::configure::configure().

void mp::options::manager::set_modifications ( const std::vector< std::string > &  ids)

Sets the activated modifications.

Whenever show_dialog is called, only options for the activated modifications will be displayed.

Parameters
idsThe ids of the modifications

Definition at line 173 of file mp_options.cpp.

References preferences::modifications(), and modifications_.

Referenced by mp::configure::configure().

void mp::options::manager::set_scenario ( const std::string id)

Sets the selected scenario.

Whenever show_dialog is called, only options for the selected scenario will be displayed.

Parameters
idThe scenario's id.

Definition at line 161 of file mp_options.cpp.

References is_campaign_, and scenario_.

Referenced by mp::configure::configure().

void mp::options::manager::set_values ( const config values)

Set the current values the options.

This overrides ALL previously set values, even if a not all options are provided a new value for.

Parameters
valuesThe new values for each option.

Definition at line 151 of file mp_options.cpp.

References c, and values_.

void mp::options::manager::update_values ( )
private

Definition at line 336 of file mp_options.cpp.

References era_, extract_values(), is_campaign_, modifications_, and scenario_.

Referenced by get_values().

Member Data Documentation

std::string mp::options::manager::era_
private

The id of the selected era.

Definition at line 239 of file mp_options.hpp.

Referenced by is_active(), set_era(), and update_values().

bool mp::options::manager::is_campaign_
private

Definition at line 243 of file mp_options.hpp.

Referenced by set_campaign(), set_scenario(), and update_values().

std::vector<std::string> mp::options::manager::modifications_
private

The ids of the selected modifications.

Definition at line 245 of file mp_options.hpp.

Referenced by is_active(), set_modifications(), and update_values().

config mp::options::manager::options_info_
private

Stores needed info about each element and their configuration options.

Definition at line 227 of file mp_options.hpp.

Referenced by extract_values(), get_component_cfg(), get_option_info_cfg(), get_option_parent(), init_info(), init_widgets(), and manager().

gui::scrollpane* mp::options::manager::pane_
private

The scrollarea to put the widgets on.

Definition at line 236 of file mp_options.hpp.

Referenced by layout_widgets().

std::string mp::options::manager::scenario_
private

The id of the selected [multiplayer] or [campaign].

Definition at line 242 of file mp_options.hpp.

Referenced by is_active(), set_campaign(), set_scenario(), and update_values().

config mp::options::manager::values_
private

Stores the selected values for each option.

Definition at line 230 of file mp_options.hpp.

Referenced by get_value_cfg(), get_value_cfg_or_empty(), get_values(), and set_values().

CVideo& mp::options::manager::video_
private

The screen to display the dialog on.

Definition at line 233 of file mp_options.hpp.

Referenced by init_widgets().

std::map<std::string, option_display*> mp::options::manager::widgets_
private
std::vector<option_display*> mp::options::manager::widgets_ordered_
private

Definition at line 248 of file mp_options.hpp.

Referenced by init_widgets(), layout_widgets(), process_event(), and ~manager().


The documentation for this class was generated from the following files: