| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#if !defined( INCLUDED_NAMEDENTITY_H ) |
| 23 |
#define INCLUDED_NAMEDENTITY_H |
| 24 |
|
| 25 |
#include "entitylib.h" |
| 26 |
#include "eclasslib.h" |
| 27 |
#include "generic/callback.h" |
| 28 |
#include "nameable.h" |
| 29 |
#include "entity.h" |
| 30 |
|
| 31 |
#include <set> |
| 32 |
|
| 33 |
class NameCallbackSet |
| 34 |
{ |
| 35 |
typedef std::set<NameCallback> NameCallbacks; |
| 36 |
NameCallbacks m_callbacks; |
| 37 |
public: |
| 38 |
void insert( const NameCallback& callback ){ |
| 39 |
m_callbacks.insert( callback ); |
| 40 |
} |
| 41 |
void erase( const NameCallback& callback ){ |
| 42 |
m_callbacks.erase( callback ); |
| 43 |
} |
| 44 |
void changed( const char* name ) const { |
| 45 |
for ( NameCallbacks::const_iterator i = m_callbacks.begin(); i != m_callbacks.end(); ++i ) |
| 46 |
{ |
| 47 |
( *i )( name ); |
| 48 |
} |
| 49 |
} |
| 50 |
}; |
| 51 |
|
| 52 |
class NamedEntity : public Nameable |
| 53 |
{ |
| 54 |
EntityKeyValues& m_entity; |
| 55 |
NameCallbackSet m_changed; |
| 56 |
CopiedString m_name; |
| 57 |
public: |
| 58 |
NamedEntity( EntityKeyValues& entity ) : m_entity( entity ){ |
| 59 |
} |
| 60 |
const char* name() const { |
| 61 |
if ( string_empty( m_name.c_str() ) ) { |
| 62 |
return m_entity.getEntityClass().name(); |
| 63 |
} |
| 64 |
return m_name.c_str(); |
| 65 |
} |
| 66 |
const char* classname() const { |
| 67 |
return m_entity.getEntityClass().name(); |
| 68 |
} |
| 69 |
void attach( const NameCallback& callback ){ |
| 70 |
m_changed.insert( callback ); |
| 71 |
} |
| 72 |
void detach( const NameCallback& callback ){ |
| 73 |
m_changed.erase( callback ); |
| 74 |
} |
| 75 |
|
| 76 |
void identifierChanged( const char* value ){ |
| 77 |
if ( string_empty( value ) ) { |
| 78 |
m_changed.changed( m_entity.getEntityClass().name() ); |
| 79 |
} |
| 80 |
else |
| 81 |
{ |
| 82 |
m_changed.changed( value ); |
| 83 |
} |
| 84 |
m_name = value; |
| 85 |
} |
| 86 |
typedef MemberCaller<NamedEntity, void(const char*), &NamedEntity::identifierChanged> IdentifierChangedCaller; |
| 87 |
}; |
| 88 |
|
| 89 |
class RenderableNamedEntity : public OpenGLRenderable |
| 90 |
{ |
| 91 |
const NamedEntity& m_named; |
| 92 |
const Vector3& m_position; |
| 93 |
public: |
| 94 |
RenderableNamedEntity( const NamedEntity& named, const Vector3& position ) |
| 95 |
: m_named( named ), m_position( position ){ |
| 96 |
} |
| 97 |
void render( RenderStateFlags state ) const { |
| 98 |
glRasterPos3fv( vector3_to_array( m_position ) ); |
| 99 |
GlobalOpenGL().drawString( g_showTargetNames ? m_named.name() : m_named.classname() ); |
| 100 |
} |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
#endif |