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