Debian Codegraph @

plugins/dm.conversation/ConversationEntityFinder.h

raw
1 #pragma once
2
3 #include "i18n.h"
4 #include <string>
5
6 #include "ConversationEntity.h"
7
8 namespace conversation
9 {
10
11 /**
12 * Visitor class to locate and list any <b>atdm:conversation_info</b> entities in
13 * the current map.
14 *
15 * The ConversationEntityFinder will visit each scenegraph node in turn, as per the
16 * behaviour of a scenegraph walker. The classname of each entity visited is
17 * tested against a given value (passed in during construction) which identifies
18 * it as a Conversation entity, and if the test is successful, the entity's
19 * details are added to the target ConversationEntityMap and TreeModel objects
20 * to be populated.
21 */
22 class ConversationEntityFinder :
23 public scene::NodeVisitor
24 {
25 // Name of entity class we are looking for
26 std::string _className;
27
28 // ListStore to populate with results
29 wxutil::TreeModel::Ptr _store;
30 const ConvEntityColumns& _columns;
31
32 // ConversationEntityMap which we also populate
33 ConversationEntityMap& _map;
34
35 public:
36
37 /**
38 * Construct a visitor to populate the given store and ConversationEntityMap.
39 *
40 * The TreeModel provided must contain two columns. The first column
41 * is a string containing the display name of the conversation entity,
42 * which is constructed from the real entity name plus the origin in
43 * brackets for convenience purposes. The second column is a string
44 * containing the raw entity name in the map.
45 *
46 * @param st
47 * The TreeModel to populate.
48 *
49 * @param map
50 * The ConversationEntityMap to populate.
51 *
52 * @param classname
53 * The text classname used to identify a Conversation entity.
54 */
55 ConversationEntityFinder(wxutil::TreeModel::Ptr st,
56 const ConvEntityColumns& columns,
57 ConversationEntityMap& map,
58 const std::string& classname)
59 : _className(classname),
60 _store(st),
61 _columns(columns),
62 _map(map)
63 {}
64
65 /**
66 * NodeVisitor implementation
67 */
68 bool pre(const scene::INodePtr& node)
69 {
70 // Get the entity and check the classname
71 Entity* entity = Node_getEntity(node);
72
73 // Check for conversation entity or worldspawn
74 if (entity != NULL && entity->getKeyValue("classname") == _className)
75 {
76 // Construct the display string
77 std::string name = entity->getKeyValue("name");
78 std::string sDisplay = fmt::format(_("{0} at [ {1} ]"), name, entity->getKeyValue("origin"));
79
80 // Add the entity to the list
81 wxutil::TreeModel::Row row = _store->AddItem();
82
83 row[_columns.displayName] = sDisplay;
84 row[_columns.entityName] = name;
85
86 row.SendItemAdded();
87
88 // Construct an ObjectiveEntity with the node, and add to the map
89 ConversationEntityPtr ce(new ConversationEntity(node));
90 _map.insert(ConversationEntityMap::value_type(name, ce));
91 }
92
93 return true;
94 }
95
96 };
97
98 } // namespace conversation