mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-30 11:56:37 -05:00
add entries editing tab to rme
This commit is contained in:
@@ -165,7 +165,7 @@ void RegionMap::saveLayout() {
|
||||
|
||||
for (auto sec : project->mapSectionNameToValue.keys()) {
|
||||
if (!mapSecToMapEntry.contains(sec)) continue;
|
||||
struct RegionMapEntry entry = mapSecToMapEntry.value(sec);
|
||||
RegionMapEntry entry = mapSecToMapEntry.value(sec);
|
||||
entries_text += " [" + sec + "] = {" + QString::number(entry.x) + ", " + QString::number(entry.y) + ", "
|
||||
+ QString::number(entry.width) + ", " + QString::number(entry.height) + ", sMapName_" + entry.name + "},\n";
|
||||
}
|
||||
@@ -205,7 +205,7 @@ void RegionMap::saveOptions(int id, QString sec, QString name, int x, int y) {
|
||||
sMapNamesMap.insert(sName, name);
|
||||
if (!mapSecToMapEntry.keys().contains(sec)) {
|
||||
sMapNames.append(sName);
|
||||
struct RegionMapEntry entry = {x, y, 1, 1, sName};
|
||||
RegionMapEntry entry = {x, y, 1, 1, sName};
|
||||
mapSecToMapEntry.insert(sec, entry);
|
||||
}
|
||||
}
|
||||
@@ -359,3 +359,19 @@ QString RegionMap::fix_case(QString caps) {
|
||||
}
|
||||
return camel;
|
||||
}
|
||||
|
||||
void RegionMapEntry::setX(const int val) {
|
||||
this->x = val;
|
||||
}
|
||||
|
||||
void RegionMapEntry::setY(int val) {
|
||||
this->y = val;
|
||||
}
|
||||
|
||||
void RegionMapEntry::setWidth(int val) {
|
||||
this->width = val;
|
||||
}
|
||||
|
||||
void RegionMapEntry::setHeight(int val) {
|
||||
this->height = val;
|
||||
}
|
||||
|
||||
@@ -46,9 +46,6 @@ void RegionMapEditor::on_action_RegionMap_Save_triggered() {
|
||||
if (project && region_map) {
|
||||
this->region_map->save();
|
||||
this->city_map_item->save();
|
||||
this->currIndex = this->region_map_layout_item->highlightedTile;
|
||||
this->region_map_layout_item->highlightedTile = -1;
|
||||
displayRegionMap();
|
||||
}
|
||||
this->hasUnsavedChanges = false;
|
||||
}
|
||||
@@ -87,6 +84,8 @@ void RegionMapEditor::displayRegionMap() {
|
||||
displayRegionMapImage();
|
||||
displayRegionMapLayout();
|
||||
displayRegionMapLayoutOptions();
|
||||
displayRegionMapEntriesImage();
|
||||
displayRegionMapEntryOptions();
|
||||
}
|
||||
|
||||
void RegionMapEditor::displayRegionMapImage() {
|
||||
@@ -171,6 +170,60 @@ void RegionMapEditor::updateRegionMapLayoutOptions(int index) {
|
||||
this->ui->comboBox_RM_ConnectedMap->blockSignals(false);
|
||||
}
|
||||
|
||||
void RegionMapEditor::displayRegionMapEntriesImage() {
|
||||
if (!scene_region_map_entries) {
|
||||
this->scene_region_map_entries = new QGraphicsScene;
|
||||
}
|
||||
if (region_map_entries_item && scene_region_map_entries) {
|
||||
this->scene_region_map_entries->removeItem(region_map_entries_item);
|
||||
delete region_map_entries_item;
|
||||
}
|
||||
|
||||
this->region_map_entries_item = new RegionMapEntriesPixmapItem(this->region_map, this->mapsquare_selector_item);
|
||||
|
||||
if (entriesFirstDraw) {
|
||||
QString first = this->project->mapSectionValueToName.first();
|
||||
this->region_map_entries_item->currentSection = first;
|
||||
this->activeEntry = first;
|
||||
updateRegionMapEntryOptions(first);
|
||||
entriesFirstDraw = false;
|
||||
}
|
||||
|
||||
this->region_map_entries_item->draw();
|
||||
|
||||
int idx = this->region_map->getMapSquareIndex(this->region_map->mapSecToMapEntry.value(activeEntry).x + this->region_map->padLeft,
|
||||
this->region_map->mapSecToMapEntry.value(activeEntry).y + this->region_map->padTop);
|
||||
this->region_map_entries_item->select(idx);
|
||||
|
||||
this->scene_region_map_entries->addItem(region_map_entries_item);
|
||||
this->scene_region_map_entries->setSceneRect(this->scene_region_map_entries->itemsBoundingRect());
|
||||
|
||||
this->ui->graphicsView_Region_Map_Entries->setScene(this->scene_region_map_entries);
|
||||
}
|
||||
|
||||
void RegionMapEditor::displayRegionMapEntryOptions() {
|
||||
this->ui->comboBox_RM_Entry_MapSection->addItems(this->project->mapSectionValueToName.values());
|
||||
int width = this->region_map->width() - this->region_map->padLeft - this->region_map->padRight;
|
||||
int height = this->region_map->height() - this->region_map->padTop - this->region_map->padBottom;
|
||||
this->ui->spinBox_RM_Entry_x->setMaximum(width - 1);
|
||||
this->ui->spinBox_RM_Entry_y->setMaximum(height - 1);
|
||||
this->ui->spinBox_RM_Entry_width->setMinimum(1);
|
||||
this->ui->spinBox_RM_Entry_height->setMinimum(1);
|
||||
this->ui->spinBox_RM_Entry_width->setMaximum(width);
|
||||
this->ui->spinBox_RM_Entry_height->setMaximum(height);
|
||||
}
|
||||
|
||||
void RegionMapEditor::updateRegionMapEntryOptions(QString section) {
|
||||
this->ui->comboBox_RM_Entry_MapSection->setCurrentText(section);
|
||||
this->activeEntry = section;
|
||||
this->region_map_entries_item->currentSection = section;
|
||||
RegionMapEntry entry = this->region_map->mapSecToMapEntry.value(section);
|
||||
this->ui->spinBox_RM_Entry_x->setValue(entry.x);
|
||||
this->ui->spinBox_RM_Entry_y->setValue(entry.y);
|
||||
this->ui->spinBox_RM_Entry_width->setValue(entry.width);
|
||||
this->ui->spinBox_RM_Entry_height->setValue(entry.height);
|
||||
}
|
||||
|
||||
void RegionMapEditor::displayRegionMapTileSelector() {
|
||||
if (!scene_region_map_tiles) {
|
||||
this->scene_region_map_tiles = new QGraphicsScene;
|
||||
@@ -402,9 +455,15 @@ void RegionMapEditor::on_tabWidget_Region_Map_currentChanged(int index) {
|
||||
{
|
||||
case 0:
|
||||
this->ui->verticalSlider_Zoom_Image_Tiles->setVisible(true);
|
||||
this->region_map_item->draw();
|
||||
break;
|
||||
case 1:
|
||||
this->ui->verticalSlider_Zoom_Image_Tiles->setVisible(false);
|
||||
this->region_map_layout_item->draw();
|
||||
break;
|
||||
case 2:
|
||||
this->ui->verticalSlider_Zoom_Image_Tiles->setVisible(false);
|
||||
this->region_map_entries_item->draw();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -414,6 +473,47 @@ void RegionMapEditor::on_comboBox_RM_ConnectedMap_activated(const QString &mapse
|
||||
this->hasUnsavedChanges = true;// sometimes this is called for unknown reasons
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_comboBox_RM_Entry_MapSection_activated(const QString &text) {
|
||||
this->activeEntry = text;
|
||||
this->region_map_entries_item->currentSection = activeEntry;
|
||||
updateRegionMapEntryOptions(activeEntry);
|
||||
|
||||
int idx = this->region_map->getMapSquareIndex(this->region_map->mapSecToMapEntry.value(activeEntry).x + this->region_map->padLeft,
|
||||
this->region_map->mapSecToMapEntry.value(activeEntry).y + this->region_map->padTop);
|
||||
this->region_map_entries_item->select(idx);
|
||||
this->region_map_entries_item->draw();
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_spinBox_RM_Entry_x_valueChanged(int x) {
|
||||
this->region_map->mapSecToMapEntry[activeEntry].setX(x);
|
||||
int idx = this->region_map->getMapSquareIndex(this->region_map->mapSecToMapEntry.value(activeEntry).x + this->region_map->padLeft,
|
||||
this->region_map->mapSecToMapEntry.value(activeEntry).y + this->region_map->padTop);
|
||||
this->region_map_entries_item->select(idx);
|
||||
this->region_map_entries_item->draw();
|
||||
this->hasUnsavedChanges = true;
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_spinBox_RM_Entry_y_valueChanged(int y) {
|
||||
this->region_map->mapSecToMapEntry[activeEntry].setY(y);
|
||||
int idx = this->region_map->getMapSquareIndex(this->region_map->mapSecToMapEntry.value(activeEntry).x + this->region_map->padLeft,
|
||||
this->region_map->mapSecToMapEntry.value(activeEntry).y + this->region_map->padTop);
|
||||
this->region_map_entries_item->select(idx);
|
||||
this->region_map_entries_item->draw();
|
||||
this->hasUnsavedChanges = true;
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_spinBox_RM_Entry_width_valueChanged(int width) {
|
||||
this->region_map->mapSecToMapEntry[activeEntry].setWidth(width);
|
||||
this->region_map_entries_item->draw();
|
||||
this->hasUnsavedChanges = true;
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_spinBox_RM_Entry_height_valueChanged(int height) {
|
||||
this->region_map->mapSecToMapEntry[activeEntry].setHeight(height);
|
||||
this->region_map_entries_item->draw();
|
||||
this->hasUnsavedChanges = true;
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_lineEdit_RM_MapName_textEdited(const QString &text) {
|
||||
this->hasUnsavedChanges = true;
|
||||
}
|
||||
@@ -507,6 +607,7 @@ void RegionMapEditor::undo() {
|
||||
this->region_map->setTiles(commit->tiles);
|
||||
this->region_map_item->draw();
|
||||
this->region_map_layout_item->draw();
|
||||
this->region_map_entries_item->draw();
|
||||
break;
|
||||
case RegionMapEditorBox::CityMapImage:
|
||||
if (commit->cityMap == this->city_map_item->file)
|
||||
@@ -533,6 +634,7 @@ void RegionMapEditor::redo() {
|
||||
this->region_map->setTiles(commit->tiles);
|
||||
this->region_map_item->draw();
|
||||
this->region_map_layout_item->draw();
|
||||
this->region_map_entries_item->draw();
|
||||
break;
|
||||
case RegionMapEditorBox::CityMapImage:
|
||||
this->city_map_item->setTiles(commit->tiles);
|
||||
@@ -766,6 +868,9 @@ void RegionMapEditor::on_verticalSlider_Zoom_Map_Image_valueChanged(int val) {
|
||||
ui->graphicsView_Region_Map_Layout->setResizeAnchor(QGraphicsView::NoAnchor);
|
||||
ui->graphicsView_Region_Map_Layout->setMatrix(matrix);
|
||||
ui->graphicsView_Region_Map_Layout->setFixedSize(width + 2, height + 2);
|
||||
ui->graphicsView_Region_Map_Entries->setResizeAnchor(QGraphicsView::NoAnchor);
|
||||
ui->graphicsView_Region_Map_Entries->setMatrix(matrix);
|
||||
ui->graphicsView_Region_Map_Entries->setFixedSize(width + 2, height + 2);
|
||||
}
|
||||
|
||||
void RegionMapEditor::on_verticalSlider_Zoom_Image_Tiles_valueChanged(int val) {
|
||||
|
||||
110
src/ui/regionmapentriespixmapitem.cpp
Normal file
110
src/ui/regionmapentriespixmapitem.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
#include "regionmapentriespixmapitem.h"
|
||||
|
||||
void RegionMapEntriesPixmapItem::draw() {
|
||||
if (!region_map) return;
|
||||
|
||||
RegionMapEntry entry = region_map->mapSecToMapEntry.value(currentSection);
|
||||
bool selectingEntry = false;
|
||||
|
||||
int entry_x, entry_y, entry_w, entry_h;
|
||||
|
||||
if (entry.name.isEmpty() || entry.name == "MAPSEC_NONE") {
|
||||
entry_x = entry_y = 0;
|
||||
entry_w = entry_h = 1;
|
||||
} else {
|
||||
selectingEntry = true;
|
||||
entry_x = entry.x, entry_y = entry.y;
|
||||
entry_w = entry.width, entry_h = entry.height;
|
||||
}
|
||||
|
||||
QImage image(region_map->width() * 8, region_map->height() * 8, QImage::Format_RGBA8888);
|
||||
|
||||
QPainter painter(&image);
|
||||
for (int i = 0; i < region_map->map_squares.size(); i++) {
|
||||
QImage bottom_img = this->tile_selector->tileImg(region_map->map_squares[i].tile_img_id);
|
||||
QImage top_img(8, 8, QImage::Format_RGBA8888);
|
||||
int x = i % region_map->width();
|
||||
int y = i / region_map->width();
|
||||
bool insideEntry = false;
|
||||
if (selectingEntry) {
|
||||
if (x == entry_x + this->region_map->padLeft && y == entry_y + this->region_map->padTop)
|
||||
insideEntry = true;
|
||||
else if (x - this->region_map->padLeft - entry_x < entry_w && x >= entry_x + this->region_map->padLeft
|
||||
&& y - this->region_map->padTop - entry_y < entry_h && y >= entry_y + this->region_map->padTop)
|
||||
insideEntry = true;
|
||||
}
|
||||
if (insideEntry) {
|
||||
top_img.fill(QColor(255, 68, 68));
|
||||
} else if (region_map->map_squares[i].has_map) {
|
||||
top_img.fill(Qt::gray);
|
||||
} else {
|
||||
top_img.fill(Qt::black);
|
||||
}
|
||||
QPoint pos = QPoint(x * 8, y * 8);
|
||||
painter.setOpacity(1);
|
||||
painter.drawImage(pos, bottom_img);
|
||||
painter.save();
|
||||
painter.setOpacity(0.55);
|
||||
painter.drawImage(pos, top_img);
|
||||
painter.restore();
|
||||
}
|
||||
painter.end();
|
||||
|
||||
this->selectionOffsetX = entry_w - 1;
|
||||
this->selectionOffsetY = entry_h - 1;
|
||||
|
||||
this->setPixmap(QPixmap::fromImage(image));
|
||||
this->drawSelection();
|
||||
}
|
||||
|
||||
void RegionMapEntriesPixmapItem::select(int x, int y) {
|
||||
int index = this->region_map->getMapSquareIndex(x, y);
|
||||
SelectablePixmapItem::select(x, y, 0, 0);
|
||||
this->selectedTile = index;
|
||||
this->updateSelectedTile();
|
||||
|
||||
emit selectedTileChanged(this->region_map->map_squares[index].mapsec);
|
||||
}
|
||||
|
||||
void RegionMapEntriesPixmapItem::select(int index) {
|
||||
int x = index % this->region_map->width();
|
||||
int y = index / this->region_map->width();
|
||||
SelectablePixmapItem::select(x, y, 0, 0);
|
||||
this->selectedTile = index;
|
||||
this->updateSelectedTile();
|
||||
|
||||
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) {
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void RegionMapEntriesPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void RegionMapEntriesPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void RegionMapEntriesPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void RegionMapEntriesPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event) {
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void RegionMapEntriesPixmapItem::updateSelectedTile() {
|
||||
QPoint origin = this->getSelectionStart();
|
||||
this->selectedTile = this->region_map->getMapSquareIndex(origin.x(), origin.y());
|
||||
this->highlightedTile = -1;
|
||||
draw();
|
||||
}
|
||||
Reference in New Issue
Block a user