85 lines
2.1 KiB
C++
85 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <map>
|
|
#include <optional>
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <QDialog>
|
|
#include <QPoint>
|
|
|
|
#include "GameConfig.h"
|
|
#include "Rotation.h"
|
|
#include "ShipLayout.h"
|
|
#include "ShipLayoutBlueprint.h"
|
|
|
|
class QPushButton;
|
|
class ShipStatsPanel;
|
|
|
|
class ShipLayoutDialog : public QDialog
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
ShipLayoutDialog(const GameConfig* config,
|
|
const std::string& shipId,
|
|
const ShipLayoutConfig& currentLayout,
|
|
std::vector<ShipLayoutBlueprint>& allBlueprints,
|
|
std::set<std::string> unlockedModuleIds,
|
|
std::map<std::string, int> moduleLevels,
|
|
bool debugDraw,
|
|
QWidget* parent = nullptr);
|
|
|
|
std::optional<ShipLayoutConfig> result() const;
|
|
|
|
protected:
|
|
void keyPressEvent(QKeyEvent* event) override;
|
|
|
|
signals:
|
|
void gridCellClicked(QPoint cell);
|
|
|
|
private slots:
|
|
void onModuleButtonClicked(int index);
|
|
void onConfirm();
|
|
void onCancel();
|
|
|
|
public:
|
|
struct CellInfo
|
|
{
|
|
bool buildable;
|
|
int moduleIndex; // -1 if empty
|
|
};
|
|
|
|
private:
|
|
|
|
void rebuildOccupancy();
|
|
void updateGridWidget();
|
|
void updateStats();
|
|
bool canPlaceModule(const ModuleDef& def, QPoint position, Rotation rotation) const;
|
|
std::vector<std::string> rotatedMask(const ModuleDef& def, Rotation rotation) const;
|
|
void loadLayoutBlueprint(const std::vector<PlacedModule>& modules);
|
|
|
|
const GameConfig* m_config;
|
|
std::string m_shipId;
|
|
std::set<std::string> m_unlockedModuleIds;
|
|
std::map<std::string, int> m_moduleLevels;
|
|
std::vector<std::string> m_shipLayout;
|
|
int m_rows;
|
|
int m_cols;
|
|
|
|
std::vector<PlacedModule> m_placedModules;
|
|
std::vector<std::vector<CellInfo>> m_grid;
|
|
|
|
int m_activeModuleIndex; // -1 = remove mode, -2 = no selection
|
|
Rotation m_currentRotation;
|
|
|
|
std::vector<QPushButton*> m_moduleButtons;
|
|
QPushButton* m_removeButton;
|
|
QWidget* m_gridWidget;
|
|
ShipStatsPanel* m_statsPanel;
|
|
bool m_debugDraw;
|
|
|
|
std::optional<ShipLayoutConfig> m_result;
|
|
};
|