File indexing completed on 2024-07-21 03:47:50

0001 /*
0002     SPDX-FileCopyrightText: 2007 Paolo Capriotti <p.capriotti@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef SEA_H
0008 #define SEA_H
0009 
0010 #include <QWidget>
0011 
0012 #include "sea.h"
0013 #include "animator.h"
0014 
0015 class BattleFieldView;
0016 class KBSRenderer;
0017 class Delegate;
0018 class WelcomeScreen;
0019 class PlayerLabel;
0020 class StatsWidget;
0021 class Stats;
0022 
0023 class SeaView : public QWidget 
0024 {
0025 Q_OBJECT
0026     static const unsigned int GRID_SIZE = 10;
0027     static const unsigned int LABEL_SPACING = 4;
0028     static const unsigned int MARGIN = 5;
0029     static const unsigned int GAP = 2;
0030     
0031     WelcomeScreen* m_screen;
0032     BattleFieldView* m_fields[2];
0033     PlayerLabel* m_labels[2];
0034     StatsWidget* m_stats[2];
0035     
0036     KBSRenderer* m_renderer;
0037     Delegate* m_delegate;
0038     BattleFieldView* otherField(BattleFieldView* field);
0039     QPoint m_last_preview;
0040     int m_last_f;
0041     
0042     bool setPreview(Sea::Player player, const QPoint& pos);
0043     bool updatePreview(const QPoint& pos);
0044     int fieldAt(const QPoint& p);
0045 public:
0046     explicit SeaView(QWidget* parent);
0047     ~SeaView() override;
0048     
0049     void setDelegate(Delegate* c);
0050     void cancelPreview();
0051     void add(Sea::Player p, Ship* ship);
0052     void hit(Sea::Player p, const Coord& c);
0053     void miss(Sea::Player p, const Coord& c);
0054     void sink(Sea::Player p, Ship* ship);
0055     void clear();
0056     void setStatus(Sea::Status status);
0057     
0058     void setStats(Sea::Player p, const QString& icon, 
0059                   const QString& text, Stats* stats);
0060     void setNick(Sea::Player p, const QString& nick);
0061 
0062     WelcomeScreen* globalScreen() const;
0063     WelcomeScreen* screen(Sea::Player player) const;
0064 
0065     void toggleLeftGrid(bool show);
0066     void toggleRightGrid(bool show);
0067 protected:
0068     void resizeEvent(QResizeEvent*) override;
0069     
0070     QSize tileSize() const;
0071 public Q_SLOTS:
0072     void refresh();
0073 };
0074 
0075 #endif // SEA_H
0076