File indexing completed on 2024-05-12 05:39:48

0001 /***************************************************************************
0002  *  Copyright (C) 2019 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 PLAYERCONTROLLER_H
0021 #define PLAYERCONTROLLER_H
0022 
0023 #include <QObject>
0024 #include <QPointer>
0025 #include <QUndoStack>
0026 #include <memory>
0027 
0028 #include "controllerinterface.h"
0029 #include "data/player.h"
0030 #include "model/charactermodel.h"
0031 
0032 #include <core_global.h>
0033 class Player;
0034 
0035 class Character;
0036 class QAbstractItemModel;
0037 class PlayerModel;
0038 class LocalModel;
0039 class PlayerOnMapModel;
0040 class CharacterStateModel;
0041 class CharacterModel;
0042 class PlayerUpdater;
0043 class NetworkController;
0044 class CORE_EXPORT PlayerController : public AbstractControllerInterface
0045 {
0046     Q_OBJECT
0047     Q_PROPERTY(PlayerModel* model READ model CONSTANT)
0048     Q_PROPERTY(QAbstractItemModel* characterStateModel READ characterStateModel NOTIFY characterStateModelChanged)
0049     Q_PROPERTY(CharacterModel* characterModel READ characterModel CONSTANT)
0050     Q_PROPERTY(bool localIsGm READ localIsGm CONSTANT)
0051     Q_PROPERTY(Player* localPlayer READ localPlayer CONSTANT)
0052     Q_PROPERTY(QString gameMasterId READ gameMasterId NOTIFY gameMasterIdChanged)
0053     Q_PROPERTY(QString localPlayerId READ localPlayerId NOTIFY localPlayerIdChanged)
0054 
0055 public:
0056     explicit PlayerController(NetworkController* network, QObject* parent= nullptr);
0057     ~PlayerController() override;
0058 
0059     Player* localPlayer() const;
0060 
0061     PlayerModel* model() const;
0062     bool localIsGm() const;
0063     QAbstractItemModel* characterStateModel() const;
0064     CharacterModel* characterModel() const;
0065 
0066     QString gameMasterId() const;
0067     QString localPlayerId() const;
0068     QColor localColor() const;
0069 
0070     void setGameController(GameController*) override;
0071     void clear();
0072 
0073 signals:
0074     void localPlayerChanged();
0075     void characterStateModelChanged();
0076     void gameMasterIdChanged(const QString& gameMasterId);
0077     void localPlayerIdChanged(const QString& id);
0078 
0079 public slots:
0080     void addPlayer(Player* player);
0081     void removePlayer(Player* player);
0082     void addLocalCharacter();
0083     void removeLocalCharacter(const QModelIndex& index);
0084 
0085 private:
0086     void removePlayerById(const QString& id);
0087 
0088 private:
0089     std::unique_ptr<PlayerModel> m_model;
0090     std::unique_ptr<CharacterModel> m_characterModel;
0091     std::unique_ptr<PlayerUpdater> m_updater;
0092     QPointer<QAbstractItemModel> m_characterStateModel;
0093     QPointer<Player> m_localPlayer;
0094     QPointer<QUndoStack> m_stack;
0095 };
0096 
0097 #endif // PLAYERCONTROLLER_H