Select Git revision
CenterGrid.hpp
-
Julian Dreuth authoredJulian Dreuth authored
CenterGrid.hpp 4.59 KiB
#pragma once
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QMessageBox>
#include <QPixmap>
#include <QTimer>
#include <QVBoxLayout>
#include <QWidget>
#include "GridItem.hpp"
namespace editor
{
/**
* @brief Central widget of the Editor, contains editable grid representing a room
*/
class CenterGrid : public QWidget
{
Q_OBJECT
public:
/**
* @brief Creates a new CenterGrid
* @param parent parent widget of CenterGrid
*/
CenterGrid(QWidget *parent = nullptr);
/**
* @brief Setter function to update which sprite is currently selected and needs to be places when grid clicked
* @param message TEMPORARY message that is shown when tile is clicked replace with sprite data
*/
void setCurrentSprite(const QPixmap pixmap, const int id);
/**
* @brief Function for drawing the currently selected sprite on a tile when tile is clicked
* @param row row of the clicked tile (y coordiante)
* @param col column of the clicked tile (x coordinate)
*/
void onTileClicked(int row, int col);
/**
* @brief draws room presets on the grid
* @param index index of room preset that needs to be drawn
*/
void drawPreset(int index);
/**
* @brief gets GridItem by row and column
* @param row row (y coordinate) of the GridItem to return
* @param col column (x coordinate) of the GridItem to return
* @return GridItem* of the GridItem at row/col, or nullptr when out of bounds
*/
GridItem *getTile(int row, int col) const;
/**
* @brief getter function for Vector of TileIDs
* @return QVector<QVector<int>> of TileIDs
*/
QVector<QVector<int>> getTileIDs();
/**
* @brief getter function for Vector of MobIDs
* @return QVector<QVector<int>> of MobIDs
*/
QVector<QVector<int>> getMobIDs();
/**
* @brief getter function for Vector of ObjectsIDs
* @return QVector<QVector<int>> of ObjectIDs
*/
QVector<QVector<int>> getObjectIDs();
private:
/**
* @brief Event that gets called when the window is resized, adjusts CenterGrid to the new size
* @param event ResizeEvent that informs about the window being resized
*/
void resizeEvent(QResizeEvent *event);
/**
* @brief QT element that provides a surface for handling 2D graphics items
*/
QGraphicsScene *scene;
/**
* @brief QT widget for displaying the contents of a QGraphicsScene
*/
QGraphicsView *view;
/**
* @brief Pixmap of the currently selected sprite
*/
QPixmap m_currentSprite;
/**
* @brief ID of the currently selected sprite
*/
int m_currentSpriteID;
/**
* @brief 2D Vector holding all GridItems, making them accessible by position on grid
*/
QVector<QVector<GridItem *>> gridItems;
/**
* @brief 2D Vector holding all tileIDs, making them accessible by position on grid
*/
QVector<QVector<int>> m_tileIDs;
/**
* @brief 2D Vector holding all objectIDs, making them accessible by position on grid
*/
QVector<QVector<int>> m_objectIDs;
/**
* @brief 2D Vector holding all mobIDs, making them accessible by position on grid
*/
QVector<QVector<int>> m_mobIDs;
/**
* @brief Integer marking the type of the currently selected sprite
*/
int m_spriteType;
/**
* @brief List of all spriteIDs that are tiles
*/
std::vector<int> m_tileIDList = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
96, 97, 98, 99, 100, 101, 102, 103, 104, 128, 129, 130, 131, 132, 133,
134, 135, 136, 160, 161, 162, 163, 164, 165, 166, 167, 168, 192, 193, 194,
195, 198, 199, 201, 224, 225, 226, 227, 232, 233};
/**
* @brief List of all spriteIDs that are mobs
*/
std::vector<int> m_mobIDList = {18, 19, 20, 21, 22, 23, 24, 25, 50, 51, 52, 53, 54, 55, 56, 57,
82, 83, 84, 85, 86, 87, 88, 89, 114, 115, 116, 117, 118, 119, 120, 121,
146, 147, 148, 149, 150, 151, 152, 153, 178, 179, 180, 181, 182, 183, 184, 185,
210, 211, 212, 213, 214, 215, 216, 242, 243, 244, 245, 246, 247, 248};
/**
* @brief List of all spriteIDs that are doors
*/
std::vector<int> m_doorIDList = {102,103,104,134,135,136,166,167,168,198,199};
};
} // namespace editor