File indexing completed on 2024-05-12 05:39:51
0001 /*************************************************************************** 0002 * Copyright (C) 2021 by Renaud Guezennec * 0003 * http://www.rolisteam.org/contact * 0004 * * 0005 * This software is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 #ifndef NONPLAYABLECHARACTERMODEL_H 0021 #define NONPLAYABLECHARACTERMODEL_H 0022 0023 #include "data/character.h" 0024 #include "model/characterstatemodel.h" 0025 0026 #include <QAbstractListModel> 0027 #include <QPointer> 0028 #include <core_global.h> 0029 0030 namespace campaign 0031 { 0032 class CORE_EXPORT NonPlayableCharacter : public Character 0033 { 0034 Q_OBJECT 0035 Q_PROPERTY(QString avatarPath READ avatarPath WRITE setAvatarPath NOTIFY avatarPathChanged) 0036 Q_PROPERTY(QStringList tags READ tags WRITE setTags NOTIFY tagsChanged) 0037 Q_PROPERTY(int size READ size WRITE setSize NOTIFY sizeChanged) 0038 Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged) 0039 Q_PROPERTY(QString gameMasterDesc READ gameMasterDesc WRITE setGameMasterDesc NOTIFY gameMasterDescChanged) 0040 public: 0041 NonPlayableCharacter(QObject* parent= nullptr); 0042 0043 QStringList tags() const; 0044 QString avatarPath() const; 0045 int size() const; 0046 QString description() const; 0047 0048 const QString& gameMasterDesc() const; 0049 void setGameMasterDesc(const QString& newGameMasterDesc); 0050 0051 public slots: 0052 void setTags(const QStringList& list); 0053 void setAvatarPath(const QString& path); 0054 void setSize(int size); 0055 void setDescription(const QString& desc); 0056 0057 signals: 0058 void tagsChanged(); 0059 void avatarPathChanged(); 0060 void sizeChanged(); 0061 void descriptionChanged(); 0062 0063 void gameMasterDescChanged(); 0064 0065 private: 0066 QString m_avatarPath; 0067 QStringList m_tags; 0068 int m_size; 0069 QString m_description; 0070 QString m_gameMasterDesc; 0071 }; 0072 0073 class CORE_EXPORT NonPlayableCharacterModel : public QAbstractListModel 0074 { 0075 Q_OBJECT 0076 Q_PROPERTY(QString npcRoot READ npcRoot WRITE setNpcRoot NOTIFY npcRootChanged) 0077 public: 0078 enum CustomRole 0079 { 0080 RoleAvatar= Qt::UserRole + 1, 0081 RoleName, 0082 RoleDescription, 0083 RoleGmDetails, 0084 RoleTags, 0085 RoleColor, 0086 RoleMinHp, 0087 RoleCurrentHp, 0088 RoleMaxHp, 0089 RoleInitiative, 0090 RoleDistancePerTurn, 0091 RoleState, 0092 RoleLifeColor, 0093 RoleInitCommand, 0094 RoleUuid, 0095 RoleAvatarPath, 0096 RoleHasInitiative, 0097 RoleActionCount, 0098 RoleShapeCount, 0099 RolePropertiesCount, 0100 RoleUnknown 0101 }; 0102 Q_ENUM(CustomRole) 0103 enum Columns 0104 { 0105 ColAvatar, 0106 ColName, 0107 ColDescription, 0108 ColGmDetails, 0109 ColTags, 0110 ColColor, 0111 ColMinHp, 0112 ColCurrentHp, 0113 ColMaxHp, 0114 ColInitiative, 0115 ColDistancePerTurn, 0116 ColState, 0117 ColLifeColor, 0118 ColInitCommand, 0119 ColUnknown 0120 }; 0121 Q_ENUM(Columns) 0122 explicit NonPlayableCharacterModel(CharacterStateModel* states, QObject* parent= nullptr); 0123 0124 // Header: 0125 QVariant headerData(int section, Qt::Orientation orientation, int role= Qt::DisplayRole) const override; 0126 0127 // Basic functionality: 0128 int rowCount(const QModelIndex& parent= QModelIndex()) const override; 0129 int columnCount(const QModelIndex&) const override; 0130 0131 QVariant data(const QModelIndex& index, int role= Qt::DisplayRole) const override; 0132 0133 // Editable: 0134 bool setData(const QModelIndex& index, const QVariant& value, int role= Qt::EditRole) override; 0135 Qt::DropActions supportedDropActions() const override; 0136 bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override; 0137 Qt::ItemFlags flags(const QModelIndex& index) const override; 0138 0139 void append(); 0140 void addCharacter(NonPlayableCharacter* character); 0141 void setModelData(const std::vector<NonPlayableCharacter*>& data); 0142 void removeNpc(const QString& index); 0143 void refresh(const QString& index); 0144 void clear(); 0145 0146 const std::vector<std::unique_ptr<NonPlayableCharacter>>& npcList() const; 0147 QStringList headers(); 0148 0149 QModelIndex indexFromUuid(const QString& id); 0150 NonPlayableCharacter* characterFromUuid(const QString& id); 0151 0152 const QString& npcRoot() const; 0153 void setNpcRoot(const QString& newNpcRoot); 0154 0155 private: 0156 QString stateName(const QString& id) const; 0157 0158 signals: 0159 void characterAdded(); 0160 void characterRemoved(QString id); 0161 void npcRootChanged(); 0162 0163 private: 0164 std::vector<std::unique_ptr<NonPlayableCharacter>> m_data; 0165 QPointer<CharacterStateModel> m_states; 0166 QStringList m_header; 0167 QString m_npcRoot; 0168 }; 0169 } // namespace campaign 0170 #endif // NONPLAYABLECHARACTERMODEL_H