The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
wmi_manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2017 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /**
16  * @file
17  * Declarations for a container for wml_menu_item.
18  */
19 
20 #pragma once
21 
22 #include <map>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 class config;
28 class filter_context;
29 class game_data;
30 struct map_location;
31 class unit_map;
32 class vconfig;
33 
34 namespace game_events
35 {
36 class wml_menu_item;
37 
39 {
40 public:
41  /** wml_menu_item pointers */
42  using item_ptr = std::shared_ptr<wml_menu_item>;
43 
44  wmi_manager();
45  ~wmi_manager();
46 
47  /** Returns true if no menu items are being managed. */
48  bool empty() const
49  {
50  return wml_menu_items_.empty();
51  }
52 
53  /** Erases the item with the provided @a id. */
54  bool erase(const std::string& id);
55 
56  /** Fires the menu item with the given @a id. */
57  bool fire_item(const std::string& id,
58  const map_location& hex,
60  filter_context& fc,
61  unit_map& units) const;
62 
63  /**
64  * Gets the menu item with the specified ID.
65  *
66  * @param id Item id.
67  * @returns Pointer to the relavent item, or nullptr if not found.
68  */
69  item_ptr get_item(const std::string& id) const;
70 
71  /** Returns the menu items that can be shown for the given location. */
72  void get_items(const map_location& hex,
73  std::vector<std::shared_ptr<const wml_menu_item>>& items,
74  std::vector<config>& descriptions,
75  filter_context& fc,
77  unit_map& units) const;
78 
79  /** Initializes the implicit event handlers for inlined [command]s. */
80  void init_handlers() const;
81 
82  void to_config(config& cfg) const;
83 
84  /** Updates or creates (as appropriate) the menu item with the given @a id. */
85  void set_item(const std::string& id, const vconfig& menu_item);
86 
87  /** Sets the current menu items to the "menu_item" children of @a cfg. */
88  void set_menu_items(const config& cfg);
89 
90  /** Gets the number of menu items owned. */
91  size_t size() const
92  {
93  return wml_menu_items_.size();
94  }
95 
96 private:
97  std::map<std::string, item_ptr> wml_menu_items_;
98 };
99 
100 } // end namespace game_events
bool empty() const
Returns true if no menu items are being managed.
Definition: wmi_manager.hpp:48
bool fire_item(const std::string &id, const map_location &hex, game_data &gamedata, filter_context &fc, unit_map &units) const
Fires the menu item with the given id.
Definition: wmi_manager.cpp:79
std::map< std::string, item_ptr > wml_menu_items_
Definition: wmi_manager.hpp:97
std::vector< char_t > string
void get_items(const map_location &hex, std::vector< std::shared_ptr< const wml_menu_item >> &items, std::vector< config > &descriptions, filter_context &fc, game_data &gamedata, unit_map &units) const
Returns the menu items that can be shown for the given location.
void set_item(const std::string &id, const vconfig &menu_item)
Updates or creates (as appropriate) the menu item with the given id.
const std::vector< std::string > items
game_data * gamedata
Definition: resources.cpp:22
item_ptr get_item(const std::string &id) const
Gets the menu item with the specified ID.
bool erase(const std::string &id)
Erases the item with the provided id.
Definition: wmi_manager.cpp:53
std::shared_ptr< wml_menu_item > item_ptr
wml_menu_item pointers
Definition: wmi_manager.hpp:42
~wmi_manager()
Destructor.
Definition: wmi_manager.cpp:48
void set_menu_items(const config &cfg)
Sets the current menu items to the "menu_item" children of cfg.
void to_config(config &cfg) const
Encapsulates the map of the game.
Definition: location.hpp:40
Domain specific events.
Definition: action_wml.cpp:88
A variable-expanding proxy for the config class.
Definition: variable.hpp:42
Container associating units to locations.
Definition: map.hpp:99
void init_handlers() const
Initializes the implicit event handlers for inlined [command]s.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
unit_map * units
Definition: resources.cpp:34
size_t size() const
Gets the number of menu items owned.
Definition: wmi_manager.hpp:91