File indexing completed on 2024-04-21 15:08:02

0001 // Copyright (c) 2002-2003 Rob Kaper <cap@capsi.com>
0002 //
0003 // This library is free software; you can redistribute it and/or
0004 // modify it under the terms of the GNU Lesser General Public
0005 // License version 2.1 as published by the Free Software Foundation.
0006 //
0007 // This library is distributed in the hope that it will be useful,
0008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
0009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0010 // Lesser General Public License for more details.
0011 //
0012 // You should have received a copy of the GNU Lesser General Public License
0013 // along with this library; see the file COPYING.LIB.  If not, write to
0014 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0015 // Boston, MA 02110-1301, USA.
0016 
0017 #ifndef ATLANTIK_BOARD_H
0018 #define ATLANTIK_BOARD_H
0019 
0020 #include <QWidget>
0021 #include <QTimer>
0022 #include <QList>
0023 #include <QHash>
0024 
0025 #include "libatlantikui_export.h"
0026 #include "tokentheme.h"
0027 
0028 class QGridLayout;
0029 class QPoint;
0030 
0031 class AtlanticCore;
0032 class Auction;
0033 class Estate;
0034 class Player;
0035 class Token;
0036 
0037 class EstateView;
0038 
0039 class LIBATLANTIKUI_EXPORT AtlantikBoard : public QWidget
0040 {
0041 Q_OBJECT
0042 
0043 public:
0044     enum DisplayMode { Play, Edit };
0045 
0046     AtlantikBoard(AtlanticCore *atlanticCore, int maxEstates, DisplayMode mode, QWidget *parent);
0047     ~AtlantikBoard();
0048     void reset();
0049 
0050     void setViewProperties(bool indicateUnowned, bool highlightUnowned, bool darkenMortgaged, bool quartzEffects, bool animateTokens);
0051     int heightForWidth(int) const override;
0052     void addEstateView(Estate *estate, bool indicateUnowned = false, bool highlightUnowned = false, bool darkenMortgaged = false, bool quartzEffects = false);
0053     void addAuctionWidget(Auction *auction);
0054 
0055     void addToken(Player *player);
0056     void removeToken(Player *player);
0057 
0058     EstateView *findEstateView(Estate *estate) const;
0059     QWidget *centerWidget();
0060 
0061     void setTokenTheme(const TokenTheme &theme);
0062 
0063 public Q_SLOTS:
0064     void slotMoveToken();
0065     void slotResizeAftermath();
0066     void displayDefault();
0067 
0068 private Q_SLOTS:
0069     void playerChanged(Player *player);
0070     void displayButton(const QString &command, const QString &caption, bool enabled);
0071     void prependEstateDetails(Estate *);
0072     void insertDetails(const QString &text, bool clearText, bool clearButtons, Estate *estate = nullptr);
0073     void insertText(const QString &text, bool clearText, bool clearButtons);
0074     void addCloseButton();
0075 
0076 Q_SIGNALS:
0077     void tokenConfirmation(Estate *estate);
0078     void buttonCommand(const QString &command);
0079 
0080 protected:
0081     void resizeEvent(QResizeEvent *) override;
0082 
0083 private:
0084     Token *findToken(Player *player) const;
0085     void jumpToken(Token *token);
0086     void moveToken(Token *token);
0087     QPoint calculateTokenDestination(Token *token, Estate *estate = nullptr);
0088 
0089     void updateCenter();
0090 
0091     AtlanticCore *m_atlanticCore;
0092     DisplayMode m_mode;
0093 
0094     QWidget *spacer, *m_lastServerDisplay, *m_lastServerDisplayBeforeAuction;
0095     QGridLayout *m_gridLayout;
0096     Token *m_movingToken;
0097     QTimer *m_timer;
0098     bool m_resumeTimer;
0099 
0100     bool m_animateTokens;
0101     int m_maxEstates;
0102 
0103     QHash<Estate *, EstateView *> m_estateViews;
0104     QHash<Player *, Token *> m_tokens;
0105     QList<QWidget *> m_displayQueue;
0106 
0107     TokenTheme m_tokenTheme;
0108 };
0109 
0110 #endif