| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "inode.h" |
| 4 |
#include "ientity.h" |
| 5 |
#include <memory> |
| 6 |
#include "wxutil/dataview/TreeModel.h" |
| 7 |
|
| 8 |
#include "Conversation.h" |
| 9 |
|
| 10 |
namespace conversation |
| 11 |
{ |
| 12 |
|
| 13 |
struct ConvEntityColumns : |
| 14 |
public wxutil::TreeModel::ColumnRecord |
| 15 |
{ |
| 16 |
ConvEntityColumns() : |
| 17 |
displayName(add(wxutil::TreeModel::Column::String)), |
| 18 |
entityName(add(wxutil::TreeModel::Column::String)) |
| 19 |
{} |
| 20 |
|
| 21 |
wxutil::TreeModel::Column displayName; |
| 22 |
wxutil::TreeModel::Column entityName; |
| 23 |
}; |
| 24 |
|
| 25 |
struct ConversationColumns : |
| 26 |
public wxutil::TreeModel::ColumnRecord |
| 27 |
{ |
| 28 |
ConversationColumns() : |
| 29 |
index(add(wxutil::TreeModel::Column::Integer)), |
| 30 |
name(add(wxutil::TreeModel::Column::String)) |
| 31 |
{} |
| 32 |
|
| 33 |
wxutil::TreeModel::Column index; // conversation index |
| 34 |
wxutil::TreeModel::Column name; // conversation name |
| 35 |
}; |
| 36 |
|
| 37 |
/** |
| 38 |
* Representation of a single conversation entity (atdm:conversation_info). |
| 39 |
* |
| 40 |
* In The Dark Mod, conversations are stored as numbered spawnargs on a conversation |
| 41 |
* entity, e.g. <b>conv_1_name</b>. Each conversation entity can contain any number |
| 42 |
* of conversations described in this way. |
| 43 |
* |
| 44 |
* The ConversationEntity class provides an object-oriented view of the conversation |
| 45 |
* information, by wrapping a pointer to an Entity and providing methods to |
| 46 |
* retrieve and manipulate conversation information without seeing the spawnargs |
| 47 |
* directly. When changes are completed, the ConversationEntity::writeToEntity() |
| 48 |
* method is invoked to save all changes in the form of spawnargs. |
| 49 |
* |
| 50 |
* @see Entity |
| 51 |
*/ |
| 52 |
class ConversationEntity |
| 53 |
{ |
| 54 |
// The actual entity's world node and entity pointer |
| 55 |
scene::INodeWeakPtr _entityNode; |
| 56 |
|
| 57 |
// Indexed conversations |
| 58 |
ConversationMap _conversations; |
| 59 |
|
| 60 |
public: |
| 61 |
/** |
| 62 |
* Construct an ConversationEntity wrapper around the given Node. |
| 63 |
*/ |
| 64 |
ConversationEntity(const scene::INodePtr& node); |
| 65 |
|
| 66 |
/** |
| 67 |
* Return an Conversation reference by numeric index. |
| 68 |
* |
| 69 |
* @param iIndex |
| 70 |
* The numberic index of the conversation to retrieve. |
| 71 |
* |
| 72 |
* @return |
| 73 |
* A non-const reference to an Conversation object, corresponding to the |
| 74 |
* given index. If the provided index did not previously exist, a new |
| 75 |
* Conversation object will be created and returned. |
| 76 |
*/ |
| 77 |
Conversation& getConversation(int iIndex) { |
| 78 |
return _conversations[iIndex]; |
| 79 |
} |
| 80 |
|
| 81 |
// Returns the highest used conversation index (will return -1 if no conversations are present) |
| 82 |
int getHighestIndex(); |
| 83 |
|
| 84 |
/** |
| 85 |
* Add a new conversation, starting from the first unused conversation ID. |
| 86 |
* Will return the ID of the newly inserted conv |
| 87 |
*/ |
| 88 |
int addConversation(); |
| 89 |
|
| 90 |
/** |
| 91 |
* Delete a numbered conversation. This re-orders all conversations so that the |
| 92 |
* numbering is consistent again (deleting conv 2 will re-number 3 => 2, 4 => 3, etc.) |
| 93 |
*/ |
| 94 |
void deleteConversation(int index); |
| 95 |
|
| 96 |
/** |
| 97 |
* Move the conversation with the given index either up or down. |
| 98 |
* Will return the conversation's index after the move |
| 99 |
*/ |
| 100 |
int moveConversation(int index, bool moveUp); |
| 101 |
|
| 102 |
/** |
| 103 |
* Clear all conversations. |
| 104 |
*/ |
| 105 |
void clearConversations() { |
| 106 |
_conversations.clear(); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Test whether this entity contains conversations or not. |
| 111 |
*/ |
| 112 |
bool isEmpty() const { |
| 113 |
return _conversations.empty(); |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* Delete the actual entity node from the map. This will render any further |
| 118 |
* operations on this ConversationEntity undefined, and it should immediately |
| 119 |
* be deleted. |
| 120 |
*/ |
| 121 |
void deleteWorldNode(); |
| 122 |
|
| 123 |
/** |
| 124 |
* Populate the given list store with the conversations from this entity. |
| 125 |
* |
| 126 |
* @param store |
| 127 |
* The list store to populate. This must have 2 columns -- an integer |
| 128 |
* column for the conversation number, and a text column for the name. |
| 129 |
*/ |
| 130 |
void populateListStore(wxutil::TreeModel& store, const ConversationColumns& columns) const; |
| 131 |
|
| 132 |
/** |
| 133 |
* Write all conversation data to keyvals on the underlying entity. |
| 134 |
*/ |
| 135 |
void writeToEntity(); |
| 136 |
|
| 137 |
private: |
| 138 |
|
| 139 |
// Removes all conversation-related spawnargs from the given entity |
| 140 |
void clearEntity(Entity* entity); |
| 141 |
}; |
| 142 |
|
| 143 |
/** |
| 144 |
* Conversation entity pointer type. |
| 145 |
*/ |
| 146 |
typedef std::shared_ptr<ConversationEntity> ConversationEntityPtr; |
| 147 |
|
| 148 |
/** |
| 149 |
* Conversation entity named map type. |
| 150 |
*/ |
| 151 |
typedef std::map<std::string, ConversationEntityPtr> ConversationEntityMap; |
| 152 |
|
| 153 |
} // namespace conversation |