Debian Codegraph @

plugins/dm.objectives/ObjectiveEntityFinder.h

raw
1 #pragma once
2
3 #include "ObjectiveEntity.h"
4
5 #include "i18n.h"
6
7 #include <string>
8 #include <fmt/format.h>
9 #include "wxutil/dataview/TreeModel.h"
10
11 namespace objectives
12 {
13
14 struct ObjectiveEntityListColumns :
15 public wxutil::TreeModel::ColumnRecord
16 {
17 ObjectiveEntityListColumns() :
18 displayName(add(wxutil::TreeModel::Column::String)),
19 startActive(add(wxutil::TreeModel::Column::Boolean)),
20 entityName(add(wxutil::TreeModel::Column::String))
21 {}
22
23 wxutil::TreeModel::Column displayName;
24 wxutil::TreeModel::Column startActive;
25 wxutil::TreeModel::Column entityName;
26 };
27
28 /**
29 * Visitor class to locate and list any <b>atdm:target_addobjectives</b> entities in
30 * the current map.
31 *
32 * The ObjectiveEntityFinder will visit each scenegraph node in turn, as per the
33 * behaviour of a scenegraph walker. The classname of each entity visited is
34 * tested against a given value (passed in during construction) which identifies
35 * it as an Objectives entity, and if the test is successful, the entity's
36 * details are added to the target ObjectiveEntityMap and GtkListStore objects
37 * to be populated.
38 *
39 * The ObjectiveEntityFinder also keeps a reference to the worldspawn entity so
40 * that the "activate at start" status can be determined (the worldspawn targets
41 * any objective entities that should be active at start).
42 */
43 class ObjectiveEntityFinder
44 : public scene::NodeVisitor
45 {
46 // List of names of entity class we are looking for
47 std::vector<std::string> _classNames;
48
49 // GtkListStore to populate with results
50 const ObjectiveEntityListColumns& _columns;
51 wxutil::TreeModel::Ptr _store;
52
53 // ObjectiveEntityMap which we also populate
54 ObjectiveEntityMap& _map;
55
56 // Worldspawn entity
57 Entity* _worldSpawn;
58
59 public:
60
61 /**
62 * Construct a visitor to populate the given store and ObjectiveEntityMap.
63 *
64 * The GtkListStore provided must contain three columns. The first column
65 * is a G_TYPE_STRING containing the display name of the Objectives entity,
66 * which is constructed from the real entity name plus the origin in
67 * brackets for convenience purposes. The second column is a G_TYPE_BOOL
68 * which is set to TRUE if the entity is activated at start, and FALSE
69 * otherwise. The third column is a G_TYPE_STRING containing the raw entity
70 * name in the map.
71 *
72 * @param st
73 * The GtkListStore to populate.
74 *
75 * @param map
76 * The ObjectiveEntityMap to populate.
77 *
78 * @param classname
79 * The text classname used to identify an Objectives entity.
80 */
81 ObjectiveEntityFinder(wxutil::TreeModel::Ptr st,
82 const ObjectiveEntityListColumns& columns,
83 ObjectiveEntityMap& map,
84 const std::vector<std::string>& classnames)
85 : _classNames(classnames),
86 _columns(columns),
87 _store(st),
88 _map(map),
89 _worldSpawn(NULL)
90 { }
91
92 /**
93 * Return a pointer to the worldspawn entity. This could potentially be
94 * NULL if a worldspawn entity was not found during visitation.
95 */
96 Entity* getWorldSpawn()
97 {
98 return _worldSpawn;
99 }
100
101 /**
102 * @see scene::NodeVisitor::pre()
103 */
104 bool pre(const scene::INodePtr& node);
105
106 };
107
108 }
109