allow entries to be moved by dragging them around map
This commit is contained in:
parent
92ea089876
commit
e30ec429ab
4 changed files with 48 additions and 12 deletions
|
@ -42,6 +42,7 @@ public:
|
||||||
void onRegionMapLayoutHoveredTileCleared();
|
void onRegionMapLayoutHoveredTileCleared();
|
||||||
|
|
||||||
void onRegionMapEntriesSelectedTileChanged(QString) {};
|
void onRegionMapEntriesSelectedTileChanged(QString) {};
|
||||||
|
void onRegionMapEntryDragged(int, int);
|
||||||
|
|
||||||
void undo();
|
void undo();
|
||||||
void redo();
|
void redo();
|
||||||
|
|
|
@ -16,10 +16,12 @@ public:
|
||||||
QString currentSection = QString();
|
QString currentSection = QString();
|
||||||
int selectedTile;
|
int selectedTile;
|
||||||
int highlightedTile;
|
int highlightedTile;
|
||||||
|
int pressedX;
|
||||||
|
int pressedY;
|
||||||
void draw();
|
void draw();
|
||||||
void select(int, int);
|
void select(int, int);
|
||||||
void select(int);
|
void select(int);
|
||||||
void highlight(int, int, int);
|
bool draggingEntry = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateSelectedTile();
|
void updateSelectedTile();
|
||||||
|
@ -29,6 +31,7 @@ signals:
|
||||||
void hoveredTileChanged(int);
|
void hoveredTileChanged(int);
|
||||||
void hoveredTileCleared();
|
void hoveredTileCleared();
|
||||||
void selectedTileChanged(QString);
|
void selectedTileChanged(QString);
|
||||||
|
void entryPositionChanged(int, int);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
|
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
|
||||||
|
|
|
@ -181,6 +181,9 @@ void RegionMapEditor::displayRegionMapEntriesImage() {
|
||||||
|
|
||||||
this->region_map_entries_item = new RegionMapEntriesPixmapItem(this->region_map, this->mapsquare_selector_item);
|
this->region_map_entries_item = new RegionMapEntriesPixmapItem(this->region_map, this->mapsquare_selector_item);
|
||||||
|
|
||||||
|
connect(this->region_map_entries_item, &RegionMapEntriesPixmapItem::entryPositionChanged,
|
||||||
|
this, &RegionMapEditor::onRegionMapEntryDragged);
|
||||||
|
|
||||||
if (entriesFirstDraw) {
|
if (entriesFirstDraw) {
|
||||||
QString first = this->project->mapSectionValueToName.first();
|
QString first = this->project->mapSectionValueToName.first();
|
||||||
this->region_map_entries_item->currentSection = first;
|
this->region_map_entries_item->currentSection = first;
|
||||||
|
@ -221,8 +224,6 @@ void RegionMapEditor::updateRegionMapEntryOptions(QString section) {
|
||||||
this->ui->spinBox_RM_Entry_width->setEnabled(enabled);
|
this->ui->spinBox_RM_Entry_width->setEnabled(enabled);
|
||||||
this->ui->spinBox_RM_Entry_height->setEnabled(enabled);
|
this->ui->spinBox_RM_Entry_height->setEnabled(enabled);
|
||||||
|
|
||||||
// if the key is not in the entries map, add it
|
|
||||||
|
|
||||||
this->ui->comboBox_RM_Entry_MapSection->setCurrentText(section);
|
this->ui->comboBox_RM_Entry_MapSection->setCurrentText(section);
|
||||||
this->activeEntry = section;
|
this->activeEntry = section;
|
||||||
this->region_map_entries_item->currentSection = section;
|
this->region_map_entries_item->currentSection = section;
|
||||||
|
@ -365,6 +366,12 @@ void RegionMapEditor::onRegionMapTileSelectorHoveredTileCleared() {
|
||||||
this->ui->statusbar->clearMessage();
|
this->ui->statusbar->clearMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RegionMapEditor::onRegionMapEntryDragged(int new_x, int new_y) {
|
||||||
|
on_spinBox_RM_Entry_x_valueChanged(new_x);
|
||||||
|
on_spinBox_RM_Entry_y_valueChanged(new_y);
|
||||||
|
updateRegionMapEntryOptions(activeEntry);
|
||||||
|
}
|
||||||
|
|
||||||
void RegionMapEditor::onRegionMapLayoutSelectedTileChanged(int index) {
|
void RegionMapEditor::onRegionMapLayoutSelectedTileChanged(int index) {
|
||||||
setCurrentSquareOptions();
|
setCurrentSquareOptions();
|
||||||
QString message = QString();
|
QString message = QString();
|
||||||
|
|
|
@ -76,22 +76,47 @@ void RegionMapEntriesPixmapItem::select(int index) {
|
||||||
emit selectedTileChanged(this->region_map->map_squares[index].mapsec);
|
emit selectedTileChanged(this->region_map->map_squares[index].mapsec);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMapEntriesPixmapItem::highlight(int x, int y, int red) {
|
|
||||||
this->highlightedTile = red;
|
|
||||||
SelectablePixmapItem::select(x + this->region_map->padLeft, y + this->region_map->padTop, 0, 0);
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegionMapEntriesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
void RegionMapEntriesPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
event->ignore();
|
QPoint pos = this->getCellPos(event->pos());
|
||||||
|
int x = pos.x() - this->region_map->padLeft;
|
||||||
|
int y = pos.y() - this->region_map->padTop;
|
||||||
|
|
||||||
|
RegionMapEntry entry = this->region_map->mapSecToMapEntry.value(currentSection);
|
||||||
|
pressedX = x - entry.x;
|
||||||
|
pressedY = y - entry.y;
|
||||||
|
if (entry.x == x && entry.y == y) {
|
||||||
|
this->draggingEntry = true;
|
||||||
|
}
|
||||||
|
else if (pressedX < entry.width && x >= entry.x && pressedY < entry.height && y >= entry.y) {
|
||||||
|
this->draggingEntry = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMapEntriesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
void RegionMapEntriesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
event->ignore();
|
if (!draggingEntry) {
|
||||||
|
event->ignore();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint pos = this->getCellPos(event->pos());
|
||||||
|
int new_x = pos.x() - this->region_map->padLeft - pressedX;
|
||||||
|
int new_y = pos.y() - this->region_map->padTop - pressedY;
|
||||||
|
|
||||||
|
RegionMapEntry entry = this->region_map->mapSecToMapEntry.value(currentSection);
|
||||||
|
|
||||||
|
// check to make sure not moving out of bounds
|
||||||
|
if (new_x + entry.width > this->region_map->width() - this->region_map->padLeft - this->region_map->padRight
|
||||||
|
|| new_y + entry.height > this->region_map->height() - this->region_map->padTop - this->region_map->padBottom
|
||||||
|
|| new_x < 0 || new_y < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (new_x != entry.x || new_y != entry.y) {
|
||||||
|
emit entryPositionChanged(new_x, new_y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMapEntriesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
void RegionMapEntriesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||||
event->ignore();
|
this->draggingEntry = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionMapEntriesPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
void RegionMapEntriesPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
||||||
|
|
Loading…
Reference in a new issue