177 lines
5.2 KiB
C++
177 lines
5.2 KiB
C++
#ifndef QSCENERENDERER_H
|
|
#define QSCENERENDERER_H
|
|
|
|
#include <cmath>
|
|
#include <qopenglwidget.h>
|
|
#include <QOpenGLFunctions_4_0_Core>
|
|
#include "terrain.h"
|
|
#include "tile.h"
|
|
#include <QMouseEvent>
|
|
#include <QElapsedTimer>
|
|
#include <QTimer>
|
|
#include <vector>
|
|
#include <QMap>
|
|
#include "matrix2d.h"
|
|
#include "unitrenderer.h"
|
|
#include "gamemanager.h"
|
|
|
|
class QSceneRenderer : public QOpenGLWidget
|
|
{
|
|
public:
|
|
QSceneRenderer(QWidget* parent = Q_NULLPTR);
|
|
inline Matrix2D<TerrainPoint> * getMapPoints() { return m_point; }
|
|
inline int getNumPointsWidth() const { return m_numPointsWidth; }
|
|
inline int getNumPointsHeight() const { return m_numPointsHeight; }
|
|
inline int getNumPoints05() const { return m_numPoints05; }
|
|
|
|
Tile * getTile(int x, int y);
|
|
void loadRiverMap(const QImage &riverImg);
|
|
|
|
protected:
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
|
void keyPressEvent(QKeyEvent * e) override;
|
|
void wheelEvent(QWheelEvent * e) override;
|
|
void initializeGL() override;
|
|
void resizeGL(int w, int h) override;
|
|
void paintGL() override;
|
|
|
|
// Minimap helpers
|
|
QRect getMinimapRect() const;
|
|
QRect getMinimapCardRect() const;
|
|
QRect getZoomOutButtonRect() const;
|
|
QRect getZoomResetButtonRect() const;
|
|
QRect getZoomInButtonRect() const;
|
|
QRect getMinimapSourceRect() const;
|
|
QPointF worldToMinimap(float wx, float wy, const QRect &rect) const;
|
|
QVector2D minimapToWorld(const QPoint &pos, const QRect &rect) const;
|
|
void drawMinimap(QPainter &painter);
|
|
|
|
// Units HUD and 2D overlays
|
|
void drawUnitsOverlay(QPainter &painter, const QMatrix4x4 &vMatrix);
|
|
void drawUnitCard(QPainter &painter, Unit *unit);
|
|
void drawTickBar(QPainter &painter);
|
|
void drawPathAndRange(QPainter &painter, Unit *unit, const QMatrix4x4 &vMatrix);
|
|
void drawFloatingTexts(QPainter &painter, const QMatrix4x4 &vMatrix);
|
|
// City & Territory Overlays
|
|
void drawCityBorders(QPainter &painter, const QMatrix4x4 &vMatrix);
|
|
void drawImprovementsOverlay(QPainter &painter, const QMatrix4x4 &vMatrix);
|
|
void drawCityViewOverlay(QPainter &painter, const QMatrix4x4 &vMatrix);
|
|
bool screenToHex(const QPoint &screenPos, const QMatrix4x4 &vMatrix, int &outX, int &outY);
|
|
QImage getTintedIcon(const QString &path, const QColor &color);
|
|
|
|
float getCameraPitchDeg() const;
|
|
float getCameraForwardDist() const;
|
|
QVector3D getCameraLookAt() const;
|
|
void loadCameraConfig();
|
|
|
|
float m_cameraMinZoom = 2.0f;
|
|
float m_cameraMaxZoom = 16.0f;
|
|
float m_cameraPitchMinDeg = 45.0f;
|
|
float m_cameraPitchMaxDeg = 75.0f;
|
|
|
|
float m_camera_x = 10.0f;
|
|
float m_camera_y = 0.0f;
|
|
QMatrix4x4 Projection;
|
|
QMatrix4x4 cameraTransformation;
|
|
QVector3D cameraPosition;
|
|
QVector3D cameraUpDirection;
|
|
|
|
Matrix2D<TerrainPoint> * m_point;
|
|
Matrix2D<Tile> * tiles;
|
|
QPoint lastPos;
|
|
float zRot = 0.0f;
|
|
float m_numPointsWidth;
|
|
float m_numPointsHeight;
|
|
int m_numPoints05;
|
|
float m_zoom;
|
|
QElapsedTimer m_elapsedTimer;
|
|
float m_lastFrameTime;
|
|
QImage m_image_minimap;
|
|
bool m_draggingMinimap;
|
|
float m_minimapZoom;
|
|
|
|
// Saved camera state for restoring after City View
|
|
QVector3D m_savedCamPos;
|
|
float m_savedZoom = 8.0f;
|
|
float m_savedZRot = 90.0f;
|
|
|
|
// Units & UI state
|
|
UnitRenderer m_unitRenderer;
|
|
QMap<QString, QImage> m_iconCache;
|
|
QMap<QString, QImage> m_tintedIconCache;
|
|
QPoint m_mouseCurrentPos;
|
|
|
|
struct ActionBubble {
|
|
QRect rect;
|
|
QString actionId;
|
|
QString tooltip;
|
|
};
|
|
std::vector<ActionBubble> m_activeActionBubbles;
|
|
|
|
QRect m_speed1xRect;
|
|
QRect m_speed2xRect;
|
|
QRect m_speed5xRect;
|
|
QRect m_unitCardRect;
|
|
QRect m_closeCityViewBtnRect;
|
|
|
|
struct CitySlotHit {
|
|
QRect rect;
|
|
int tx, ty;
|
|
QString defaultRes;
|
|
};
|
|
std::vector<CitySlotHit> m_citySlotHits;
|
|
|
|
struct CityBuyTileHit {
|
|
QRect rect;
|
|
int tx, ty;
|
|
};
|
|
std::vector<CityBuyTileHit> m_cityBuyTileHits;
|
|
|
|
struct CityBannerHit {
|
|
QRect rect;
|
|
int cityId;
|
|
};
|
|
std::vector<CityBannerHit> m_cityBannerHits;
|
|
|
|
struct CityProjectHit {
|
|
QRect rect;
|
|
CityProjectType type;
|
|
QString id;
|
|
};
|
|
std::vector<CityProjectHit> m_cityProjectHits;
|
|
|
|
QRect m_cancelProjectBtnRect;
|
|
int m_cityProjectTab = 0; // 0 = Buildings, 1 = Units
|
|
QRect m_tabBuildingsRect;
|
|
QRect m_tabUnitsRect;
|
|
|
|
void drawCityResourceMenu(QPainter &painter, const QMatrix4x4 &vMatrix);
|
|
void onSlotLongPressTimeout();
|
|
|
|
// Slot Long Press & Resource Selection Menu State
|
|
bool m_slotPressPending = false;
|
|
bool m_slotLongPressTriggered = false;
|
|
int m_pressedSlotTx = -1;
|
|
int m_pressedSlotTy = -1;
|
|
QPoint m_slotPressPos;
|
|
QElapsedTimer m_slotPressElapsed;
|
|
QTimer *m_slotLongPressTimer = nullptr;
|
|
|
|
bool m_resourceMenuOpen = false;
|
|
int m_resourceMenuTx = -1;
|
|
int m_resourceMenuTy = -1;
|
|
QRect m_resourceMenuRect;
|
|
QRect m_resourceMenuCloseBtnRect;
|
|
|
|
struct CityResourceChoiceHit {
|
|
QRect rect;
|
|
QString res;
|
|
int amount;
|
|
};
|
|
std::vector<CityResourceChoiceHit> m_cityResourceChoiceHits;
|
|
};
|
|
|
|
#endif // QSCENERENDERER_H
|