add new convenience features to rme and fix typos

This commit is contained in:
garak 2019-02-25 13:31:34 -05:00
parent 3cef77a174
commit 5b6f658e29
12 changed files with 96 additions and 47 deletions

View file

@ -1092,7 +1092,10 @@
<addaction name="action_RegionMap_Undo"/>
<addaction name="action_RegionMap_Redo"/>
<addaction name="action_RegionMap_Resize"/>
<addaction name="separator"/>
<addaction name="action_Swap"/>
<addaction name="action_RegionMap_ResetImage"/>
<addaction name="action_RegionMap_ResetLayout"/>
</widget>
<widget class="QMenu" name="menuTools">
<property name="title">
@ -1147,6 +1150,16 @@
<string>Swap...</string>
</property>
</action>
<action name="action_RegionMap_ResetImage">
<property name="text">
<string>Reset Image</string>
</property>
</action>
<action name="action_RegionMap_ResetLayout">
<property name="text">
<string>Reset Layout</string>
</property>
</action>
</widget>
<resources/>
<connections/>

View file

@ -70,6 +70,8 @@ public:
void resize(int width, int height);
void resetSquare(int index);
void resetLayout();
void resetImage();
void replaceSectionId(unsigned oldId, unsigned newId);
int width();

View file

@ -29,7 +29,9 @@ public:
QString layoutsLabel;
QMap<QString, MapLayout*> mapLayouts;
QMap<QString, MapLayout*> mapLayoutsMaster;
QStringList *regionMapSections = nullptr;
QMap<QString, QString> *mapSecToMapHoverName;
QMap<QString, int> mapSectionNameToValue;
QMap<int, QString> mapSectionValueToName;
QStringList *itemNames = nullptr;
QStringList *flagNames = nullptr;
QStringList *varNames = nullptr;
@ -47,8 +49,6 @@ public:
Map* loadMap(QString);
Map* getMap(QString);
QMap<QString, QString> *mapSecToMapHoverName;
QMap<QString, Tileset*> *tileset_cache = nullptr;
Tileset* loadTileset(QString, Tileset *tileset = nullptr);
Tileset* getTileset(QString, bool forceLoad = false);

View file

@ -92,6 +92,8 @@ private slots:
void on_action_RegionMap_Undo_triggered();
void on_action_RegionMap_Redo_triggered();
void on_action_RegionMap_Resize_triggered();
void on_action_RegionMap_ResetImage_triggered();
void on_action_RegionMap_ResetLayout_triggered();
void on_action_Swap_triggered();
void on_action_RegionMap_Generate_triggered();
void on_tabWidget_Region_Map_currentChanged(int);

View file

@ -260,7 +260,7 @@ void PorymapConfig::setShowCursorTile(bool enabled) {
}
void PorymapConfig::setRegionMapDimensions(int width, int height) {
this->regionMapDimensions = QSize(width, height);//QString("%1x%2").arg(width).arg(height);
this->regionMapDimensions = QSize(width, height);
}
QString PorymapConfig::getRecentProject() {

View file

@ -116,8 +116,9 @@ void RegionMap::readLayout() {
for (int y = 0; y < layout_height_; y++) {
for (int x = 0; x < layout_width_; x++) {
int i = img_index_(x,y);
map_squares[i].secid = static_cast<uint8_t>(mapBinData.at(layout_index_(x,y)));
QString secname = (*(project->regionMapSections))[static_cast<uint8_t>(mapBinData.at(layout_index_(x,y)))];
uint8_t id = static_cast<uint8_t>(mapBinData.at(layout_index_(x,y)));
map_squares[i].secid = id;
QString secname = project->mapSectionValueToName.value(id);
if (secname != "MAPSEC_NONE") map_squares[i].has_map = true;
map_squares[i].mapsec = secname;
map_squares[i].map_name = sMapNamesMap.value(mapSecToMapEntry.value(secname).name);
@ -140,7 +141,7 @@ void RegionMap::saveLayout() {
entries_text += "\nconst struct RegionMapLocation gRegionMapEntries[] = {\n";
for (auto sec : *(project->regionMapSections)) {
for (auto sec : project->mapSectionNameToValue.keys()) {
if (!mapSecToMapEntry.contains(sec)) continue;
struct RegionMapEntry entry = mapSecToMapEntry.value(sec);
entries_text += " [" + sec + "] = {" + QString::number(entry.x) + ", " + QString::number(entry.y) + ", "
@ -168,7 +169,7 @@ void RegionMap::saveOptions(int id, QString sec, QString name, int x, int y) {
int index = getMapSquareIndex(x + this->padLeft, y + this->padTop);
if (!sec.isEmpty()) {
this->map_squares[index].has_map = sec == "MAPSEC_NONE" ? false : true;
this->map_squares[index].secid = static_cast<uint8_t>(project->regionMapSections->indexOf(sec));
this->map_squares[index].secid = static_cast<uint8_t>(project->mapSectionNameToValue.value(sec));
this->map_squares[index].mapsec = sec;
if (!name.isEmpty()) {
this->map_squares[index].map_name = name;
@ -191,11 +192,20 @@ void RegionMap::resetSquare(int index) {
this->map_squares[index].mapsec = "MAPSEC_NONE";
this->map_squares[index].map_name = QString();
this->map_squares[index].has_map = false;
this->map_squares[index].secid = static_cast<uint8_t>(project->regionMapSections->indexOf("MAPSEC_NONE"));
this->map_squares[index].secid = static_cast<uint8_t>(project->mapSectionNameToValue.value("MAPSEC_NONE"));
this->map_squares[index].has_city_map = false;
this->map_squares[index].city_map_name = QString();
this->map_squares[index].duplicated = false;
logInfo(QString("Reset map square at (%1, %2).").arg(this->map_squares[index].x).arg(this->map_squares[index].y));
}
void RegionMap::resetLayout() {
for (int i = 0; i < map_squares.size(); i++)
resetSquare(i);
}
void RegionMap::resetImage() {
for (int i = 0; i < map_squares.size(); i++)
this->map_squares[i].tile_img_id = 0x00;
}
void RegionMap::replaceSectionId(unsigned oldId, unsigned newId) {
@ -203,7 +213,7 @@ void RegionMap::replaceSectionId(unsigned oldId, unsigned newId) {
if (square.secid == oldId) {
square.has_map = false;
square.secid = newId;
QString secname = (*(project->regionMapSections))[newId];
QString secname = project->mapSectionValueToName.value(newId);
if (secname != "MAPSEC_NONE") square.has_map = true;
square.mapsec = secname;
square.map_name = sMapNamesMap.value(mapSecToMapEntry.value(secname).name);

View file

@ -469,7 +469,7 @@ void MainWindow::displayMapProperties() {
ui->comboBox_Song->addItems(songs);
ui->comboBox_Song->setCurrentText(map->song);
ui->comboBox_Location->addItems(*project->regionMapSections);
ui->comboBox_Location->addItems(project->mapSectionValueToName.values());
ui->comboBox_Location->setCurrentText(map->location);
QMap<QString, QStringList> tilesets = project->getTilesets();
@ -661,8 +661,8 @@ void MainWindow::sortMapList() {
case MapSortOrder::Area:
{
QMap<QString, int> mapsecToGroupNum;
for (int i = 0; i < project->regionMapSections->length(); i++) {
QString mapsec_name = project->regionMapSections->value(i);
for (int i = 0; i < project->mapSectionNameToValue.size(); i++) {
QString mapsec_name = project->mapSectionValueToName.value(i);
QStandardItem *mapsec = new QStandardItem;
mapsec->setText(mapsec_name);
mapsec->setIcon(folderIcon);
@ -1979,21 +1979,6 @@ void MainWindow::on_horizontalSlider_MetatileZoom_valueChanged(int value) {
ui->graphicsView_Metatiles->setFixedSize(size.width() + 2, size.height() + 2);
}
void MainWindow::on_pushButton_RM_Options_save_clicked() {
this->editor->region_map->saveOptions(
this->editor->region_map_layout_item->selectedTile,
this->ui->comboBox_RM_ConnectedMap->currentText(),
this->ui->lineEdit_RM_MapName->text(),
this->ui->spinBox_RM_Options_x->value(),
this->ui->spinBox_RM_Options_y->value()
);
this->editor->region_map_layout_item->draw();
}
void MainWindow::on_pushButton_CityMap_save_clicked() {
this->editor->city_map_item->save();
}
void MainWindow::on_actionRegion_Map_Editor_triggered() {
if (!this->regionMapEditor) {
this->regionMapEditor = new RegionMapEditor(this, this->editor->project);

View file

@ -31,7 +31,6 @@ Project::Project()
groupNames = new QStringList;
map_groups = new QMap<QString, int>;
mapNames = new QStringList;
regionMapSections = new QStringList;
itemNames = new QStringList;
flagNames = new QStringList;
varNames = new QStringList;
@ -1510,8 +1509,18 @@ void Project::readTilesetProperties() {
void Project::readRegionMapSections() {
QString filepath = root + "/include/constants/region_map_sections.h";
this->mapSectionNameToValue.clear();
this->mapSectionValueToName.clear();
QString text = readTextFile(filepath);
if (!text.isNull()) {
QStringList prefixes = (QStringList() << "MAPSEC_");
readCDefinesSorted(filepath, prefixes, regionMapSections);
this->mapSectionNameToValue = readCDefines(text, prefixes);
for (QString defineName : this->mapSectionNameToValue.keys()) {
this->mapSectionValueToName.insert(this->mapSectionNameToValue[defineName], defineName);
}
} else {
logError(QString("Failed to read C defines file: '%1'").arg(filepath));
}
}
void Project::readItemNames() {

View file

@ -54,9 +54,6 @@ void CityMapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
}
void CityMapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
QPointF pos = event->pos();
int x = static_cast<int>(pos.x()) / 8;
int y = static_cast<int>(pos.y()) / 8;
emit mouseEvent(event, this);
}

View file

@ -70,7 +70,7 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) {
}
ui->comboBox_NewMap_Type->addItems(*project->mapTypes);
ui->comboBox_NewMap_Location->addItems(*project->regionMapSections);
ui->comboBox_NewMap_Location->addItems(project->mapSectionValueToName.values());
if (!mapSec.isEmpty()) ui->comboBox_NewMap_Location->setCurrentText(mapSec);
ui->frame_NewMap_Options->setEnabled(true);

View file

@ -10,7 +10,6 @@
#include <QLineEdit>
#include <QColor>
#include <QMessageBox>
#include <QDialogButtonBox>
#include <math.h>
RegionMapEditor::RegionMapEditor(QWidget *parent, Project *project_) :
@ -41,8 +40,6 @@ RegionMapEditor::~RegionMapEditor()
void RegionMapEditor::on_action_RegionMap_Save_triggered() {
if (project && region_map) {
region_map->save();
this->city_map_item->save();
this->region_map->saveOptions(
this->region_map_layout_item->selectedTile,
this->ui->comboBox_RM_ConnectedMap->currentText(),
@ -50,6 +47,8 @@ void RegionMapEditor::on_action_RegionMap_Save_triggered() {
this->ui->spinBox_RM_Options_x->value(),
this->ui->spinBox_RM_Options_y->value()
);
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();
@ -144,7 +143,7 @@ void RegionMapEditor::displayRegionMapLayout() {
void RegionMapEditor::displayRegionMapLayoutOptions() {
this->ui->comboBox_RM_ConnectedMap->clear();
this->ui->comboBox_RM_ConnectedMap->addItems(*(this->project->regionMapSections));
this->ui->comboBox_RM_ConnectedMap->addItems(this->project->mapSectionValueToName.values());
this->ui->frame_RM_Options->setEnabled(true);
@ -567,10 +566,10 @@ void RegionMapEditor::on_action_Swap_triggered() {
QFormLayout form(&popup);
QComboBox *oldSecBox = new QComboBox();
oldSecBox->addItems(*(this->project->regionMapSections));
oldSecBox->addItems(this->project->mapSectionValueToName.values());
form.addRow(new QLabel("Old Map Section:"), oldSecBox);
QComboBox *newSecBox = new QComboBox();
newSecBox->addItems(*(this->project->regionMapSections));
newSecBox->addItems(this->project->mapSectionValueToName.values());
form.addRow(new QLabel("New Map Section:"), newSecBox);
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &popup);
@ -584,8 +583,8 @@ void RegionMapEditor::on_action_Swap_triggered() {
beforeSection = oldSecBox->currentText();
afterSection = newSecBox->currentText();
if (!beforeSection.isEmpty() && !afterSection.isEmpty()) {
oldId = static_cast<uint8_t>(project->regionMapSections->indexOf(beforeSection));
newId = static_cast<uint8_t>(project->regionMapSections->indexOf(afterSection));
oldId = static_cast<uint8_t>(this->project->mapSectionNameToValue.value(beforeSection));
newId = static_cast<uint8_t>(this->project->mapSectionNameToValue.value(afterSection));
popup.accept();
}
});
@ -598,6 +597,41 @@ void RegionMapEditor::on_action_Swap_triggered() {
}
}
void RegionMapEditor::on_action_RegionMap_ResetImage_triggered() {
QMessageBox::StandardButton result = QMessageBox::question(
this,
"WARNING",
"This action will reset the entire map image to metatile 0x00, continue?",
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Yes
);
if (result == QMessageBox::Yes) {
this->region_map->resetImage();
displayRegionMapImage();
displayRegionMapLayout();
} else {
return;
}
}
void RegionMapEditor::on_action_RegionMap_ResetLayout_triggered() {
QMessageBox::StandardButton result = QMessageBox::question(
this,
"WARNING",
"This action will reset the entire map layout to MAPSEC_NONE, continue?",
QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Yes
);
if (result == QMessageBox::Yes) {
this->region_map->resetLayout();
displayRegionMapLayout();
} else {
return;
}
}
void RegionMapEditor::on_comboBox_CityMap_picker_currentTextChanged(const QString &file) {
this->displayCityMap(file);
this->cityMapFirstDraw = true;

View file

@ -50,9 +50,6 @@ void RegionMapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
}
void RegionMapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
QPointF pos = event->pos();
int x = static_cast<int>(pos.x()) / 8;
int y = static_cast<int>(pos.y()) / 8;
emit mouseEvent(event, this);
}