implement ship modules

This commit is contained in:
2026-05-18 08:49:51 +02:00
parent b59e392461
commit d08bf5d37b
33 changed files with 1911 additions and 56 deletions

70
src/ui/ShipLayoutDialog.h Normal file
View File

@@ -0,0 +1,70 @@
#pragma once
#include <optional>
#include <string>
#include <vector>
#include <QDialog>
#include <QPoint>
#include "GameConfig.h"
#include "Rotation.h"
#include "ShipLayout.h"
class QPushButton;
class ShipLayoutDialog : public QDialog
{
Q_OBJECT
public:
ShipLayoutDialog(const GameConfig* config,
const std::string& shipId,
const ShipLayoutConfig& currentLayout,
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();
bool canPlaceModule(const ModuleDef& def, QPoint position, Rotation rotation) const;
std::vector<std::string> rotatedMask(const ModuleDef& def, Rotation rotation) const;
const GameConfig* m_config;
std::string m_shipId;
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;
std::optional<ShipLayoutConfig> m_result;
};