diff --git a/CMakeLists.txt b/CMakeLists.txt index e08c252f..974d7b56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,12 +297,16 @@ set(EDITOR_SOURCES src/ui/picker/picker_audio_widget.cpp src/ui/picker/picker_audio_widget.h src/ui/picker/picker_audio_widget.ui + src/ui/picker/picker_backdrop_widget.cpp + src/ui/picker/picker_backdrop_widget.h src/ui/picker/picker_child_widget.cpp src/ui/picker/picker_child_widget.h src/ui/picker/picker_charset_widget.cpp src/ui/picker/picker_charset_widget.h src/ui/picker/picker_faceset_widget.cpp src/ui/picker/picker_faceset_widget.h + src/ui/picker/picker_panorama_widget.cpp + src/ui/picker/picker_panorama_widget.h src/ui/picker/picker_dialog.cpp src/ui/picker/picker_dialog.h src/ui/picker/picker_dialog.ui diff --git a/src/ui/main_window.cpp b/src/ui/main_window.cpp index 74b7f49f..1397c861 100644 --- a/src/ui/main_window.cpp +++ b/src/ui/main_window.cpp @@ -1057,9 +1057,6 @@ void MainWindow::on_treeMap_currentItemChanged(QTreeWidgetItem* current, QTreeWi ui->actionMapDelete->setEnabled(false); return; } - ui->actionMapCopy->setEnabled(current->data(1,Qt::DisplayRole).toInt() != 0); - ui->actionMapDelete->setEnabled(current->data(1,Qt::DisplayRole).toInt() != 0); - core().project()->treeMap().active_node = current->data(1,Qt::DisplayRole).toInt() != 0; } void MainWindow::on_actionMapCopy_triggered() @@ -1306,7 +1303,7 @@ void MainWindow::on_actionMapProperties_triggered() if (!currentScene()) return; - currentScene()->editMapProperties(); + currentScene()->editMapProperties(ui->treeMap->currentItem()); } void MainWindow::on_actionSearch_triggered() diff --git a/src/ui/map/map_scene.cpp b/src/ui/map/map_scene.cpp index a1d0bacc..0c5753e3 100644 --- a/src/ui/map/map_scene.cpp +++ b/src/ui/map/map_scene.cpp @@ -235,10 +235,29 @@ QMap *MapScene::mapEvents() return events; } -void MapScene::editMapProperties() +void MapScene::editMapProperties(QTreeWidgetItem *item) { + int old_width = m_map->width; + int old_height = m_map->height; + lcf::DBString old_name = n_mapInfo.name; + MapPropertiesDialog dlg(m_project, n_mapInfo, *m_map, m_view); - dlg.exec(); + if (dlg.exec() == QDialog::Accepted) { + if (m_map->width != old_width || m_map->height != old_height) { + setLayerData(Core::LOWER, m_map->lower_layer); + setLayerData(Core::UPPER, m_map->upper_layer); + redrawGrid(); + } + + Save(true); + redrawPanorama(); + redrawMap(); + setScale(m_scale); + + if (n_mapInfo.name != old_name) { + item->setData(0, Qt::DisplayRole, ToQString(n_mapInfo.name)); + } + } } void MapScene::redrawMap() @@ -333,9 +352,9 @@ void MapScene::onToolChanged() } } -void MapScene::Save() +void MapScene::Save(bool properties_changed) { - if (!isModified()) + if (!isModified() && !properties_changed) return; auto& treeMap = m_project.treeMap(); @@ -345,6 +364,8 @@ void MapScene::Save() treeMap.maps[i] = n_mapInfo; //Apply info changes break; } + // Remember last active map + treeMap.active_node = n_mapInfo.ID; // FIXME: ProjectData.Project is Const core().project()->saveTreeMap(); QString file = QString("Map%1.emu") @@ -370,26 +391,11 @@ void MapScene::Load(bool revert) m_map = m_project.project().loadMap(n_mapInfo.ID); m_lower = m_map->lower_layer; m_upper = m_map->upper_layer; - if(m_map->parallax_flag) - core().LoadBackground(m_map->parallax_name.c_str()); - else - core().LoadBackground(QString()); + + redrawPanorama(); if (!revert) { - QList lines; - for (int x = 0; x <= m_map->width; x++) - lines.append(new QGraphicsLineItem(x*core().tileSize(), - 0, - x*core().tileSize(), - m_map->height*core().tileSize())); - - for (int y = 0; y <= m_map->height; y++) - lines.append(new QGraphicsLineItem(0, - y*core().tileSize(), - m_map->width*core().tileSize(), - y*core().tileSize())); - - m_lines = createItemGroup(lines); + redrawGrid(); } redrawMap(); @@ -1040,3 +1046,39 @@ int MapScene::getFirstFreeId() { return id; } + +void MapScene::redrawPanorama() { + if (m_map->parallax_flag) { + core().LoadBackground(m_map->parallax_name.c_str()); + } else { + core().LoadBackground(QString()); + } +} + +void MapScene::redrawGrid() { + if (!grid_lines.empty()) { + while (!grid_lines.empty()) { + QGraphicsItem* line = grid_lines.takeLast(); + delete line; + } + destroyItemGroup(m_lines); + } + + for (int x = 0; x <= m_map->width; x++) { + grid_lines.append(new QGraphicsLineItem(x*core().tileSize(), + 0, + x*core().tileSize(), + m_map->height*core().tileSize())); + } + + for (int y = 0; y <= m_map->height; y++) { + grid_lines.append(new QGraphicsLineItem(0, + y*core().tileSize(), + m_map->width*core().tileSize(), + y*core().tileSize())); + } + + m_lines = createItemGroup(grid_lines); + + m_lines->setVisible(core().layer() == Core::EVENT); +} diff --git a/src/ui/map/map_scene.h b/src/ui/map/map_scene.h index ad68b33b..b55b267b 100644 --- a/src/ui/map/map_scene.h +++ b/src/ui/map/map_scene.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -51,7 +52,7 @@ class MapScene : public QGraphicsScene void setLayerData(Core::Layer layer, std::vector data); void setEventData(int id, const lcf::rpg::Event &data); QMap *mapEvents(); - void editMapProperties(); + void editMapProperties(QTreeWidgetItem *item); signals: @@ -68,7 +69,7 @@ public slots: void onToolChanged(); - void Save(); + void Save(bool properties_changed = false); void Load(bool revert = false); @@ -121,6 +122,8 @@ private slots: short bind(int x, int y); lcf::rpg::Event* getEventAt(int x, int y); int getFirstFreeId(); + void redrawPanorama(); + void redrawGrid(); QMenu *m_eventMenu; @@ -150,5 +153,6 @@ private slots: ProjectData& m_project; lcf::rpg::Event event_clipboard; bool event_clipboard_set = false; + QList grid_lines; }; diff --git a/src/ui/maptree/map_properties_dialog.cpp b/src/ui/maptree/map_properties_dialog.cpp index e64e5eac..0acccd1c 100644 --- a/src/ui/maptree/map_properties_dialog.cpp +++ b/src/ui/maptree/map_properties_dialog.cpp @@ -19,6 +19,12 @@ #include "ui_map_properties_dialog.h" #include "core.h" #include "common/dbstring.h" +#include "ui/picker/picker_audio_widget.h" +#include "ui/picker/picker_backdrop_widget.h" +#include "ui/picker/picker_panorama_widget.h" +#include "ui/picker/picker_dialog.h" +#include +#include "common/lcf_widget_binding.h" MapPropertiesDialog::MapPropertiesDialog(ProjectData& project, lcf::rpg::MapInfo &info, lcf::rpg::Map &map, QWidget *parent) : QDialog(parent), @@ -28,9 +34,61 @@ MapPropertiesDialog::MapPropertiesDialog(ProjectData& project, lcf::rpg::MapInfo m_project(project) { ui->setupUi(this); - + + m_info_copy = m_info; + m_map_copy = m_map; + auto& database = project.database(); + for (int i = 0; i < static_cast(database.chipsets.size()); i++) { + ui->comboTileset->addItem(ToQString(database.chipsets[static_cast(i)].name), i + 1); + } + + ui->comboWrapping->addItem("None", lcf::rpg::Map::ScrollType_none); + ui->comboWrapping->addItem("Vertical", lcf::rpg::Map::ScrollType_vertical); + ui->comboWrapping->addItem("Horizontal", lcf::rpg::Map::ScrollType_horizontal); + ui->comboWrapping->addItem("Both", lcf::rpg::Map::ScrollType_both); + + m_buttonGroupBGM = new QButtonGroup(this); + m_buttonGroupBGM->addButton(ui->radioBGMparent); + m_buttonGroupBGM->setId(ui->radioBGMparent, lcf::rpg::MapInfo::MusicType_parent); + m_buttonGroupBGM->addButton(ui->radioBGMevent); + m_buttonGroupBGM->setId(ui->radioBGMevent, lcf::rpg::MapInfo::MusicType_event); + m_buttonGroupBGM->addButton(ui->radioBGMspecify); + m_buttonGroupBGM->setId(ui->radioBGMspecify, lcf::rpg::MapInfo::MusicType_specific); + + m_buttonGroupBackdrop = new QButtonGroup(this); + m_buttonGroupBackdrop->addButton(ui->radioBackdropParent); + m_buttonGroupBackdrop->setId(ui->radioBackdropParent, lcf::rpg::MapInfo::BGMType_parent); + m_buttonGroupBackdrop->addButton(ui->radioBackdropTerrain); + m_buttonGroupBackdrop->setId(ui->radioBackdropTerrain, lcf::rpg::MapInfo::BGMType_terrain); + m_buttonGroupBackdrop->addButton(ui->radioBackdropSpecify); + m_buttonGroupBackdrop->setId(ui->radioBackdropSpecify, lcf::rpg::MapInfo::BGMType_specific); + + m_buttonGroupTeleport = new QButtonGroup(this); + m_buttonGroupTeleport->addButton(ui->radioTeleportParent); + m_buttonGroupTeleport->setId(ui->radioTeleportParent, lcf::rpg::MapInfo::TriState_parent); + m_buttonGroupTeleport->addButton(ui->radioTeleportAllow); + m_buttonGroupTeleport->setId(ui->radioTeleportAllow, lcf::rpg::MapInfo::TriState_allow); + m_buttonGroupTeleport->addButton(ui->radioTeleportForbid); + m_buttonGroupTeleport->setId(ui->radioTeleportForbid, lcf::rpg::MapInfo::TriState_forbid); + + m_buttonGroupEscape = new QButtonGroup(this); + m_buttonGroupEscape->addButton(ui->radioEscapeParent); + m_buttonGroupEscape->setId(ui->radioEscapeParent, lcf::rpg::MapInfo::TriState_parent); + m_buttonGroupEscape->addButton(ui->radioEscapeAllow); + m_buttonGroupEscape->setId(ui->radioEscapeAllow, lcf::rpg::MapInfo::TriState_allow); + m_buttonGroupEscape->addButton(ui->radioEscapeForbid); + m_buttonGroupEscape->setId(ui->radioEscapeForbid, lcf::rpg::MapInfo::TriState_forbid); + + m_buttonGroupSave = new QButtonGroup(this); + m_buttonGroupSave->addButton(ui->radioSaveParent); + m_buttonGroupSave->setId(ui->radioSaveParent, lcf::rpg::MapInfo::TriState_parent); + m_buttonGroupSave->addButton(ui->radioSaveAllow); + m_buttonGroupSave->setId(ui->radioSaveAllow, lcf::rpg::MapInfo::TriState_allow); + m_buttonGroupSave->addButton(ui->radioSaveForbid); + m_buttonGroupSave->setId(ui->radioSaveForbid, lcf::rpg::MapInfo::TriState_forbid); + for (int terrain = 0; terrain < 162; terrain++) m_generatorLowerLayer.push_back(core().translate(terrain, UP+DOWN+LEFT+RIGHT)); for (short tile_id = 10000; tile_id < 10144; tile_id++) @@ -47,55 +105,23 @@ MapPropertiesDialog::MapPropertiesDialog(ProjectData& project, lcf::rpg::MapInfo m_ObstacleBItem = new QGraphicsPixmapItem(); m_ObstacleCItem = new QGraphicsPixmapItem(); - ui->lineName->setText(ToQString(info.name)); - ui->lineBGMname->setText(ToQString(info.music.name)); - ui->lineBackdropName->setText(ToQString(info.background_name)); - for (int i = 0; i < static_cast(database.chipsets.size()); i++) - ui->comboTileset->addItem(ToQString(database.chipsets[static_cast(i)].name), i+1); - ui->comboTileset->setCurrentIndex(map.chipset_id-1); - ui->comboWrapping->setCurrentIndex(map.scroll_type); - ui->spinDungeonRoomHeight->setValue(map.generator_height); - ui->spinDungeonRoomWidth->setValue(map.generator_width); - ui->spinEncounterRate->setValue(info.encounter_steps); - ui->spinHeight->setValue(map.height); - ui->spinWidth->setValue(map.width); - ui->spinHorizontalScrollSpeed->setValue(map.parallax_sx); - ui->spinVerticalScrollSpeed->setValue(map.parallax_sy); - ui->checkHorizontalAutoscroll->setChecked(map.parallax_auto_loop_x); - ui->checkVerticalAutoscroll->setChecked(map.parallax_auto_loop_y); - ui->checkDungeonSurroundWithWalls->setChecked(map.generator_surround); - ui->groupHorizontalScroll->setChecked(map.parallax_loop_x); - ui->groupVerticalScroll->setChecked(map.parallax_loop_y); - ui->groupPanorama->setChecked(map.parallax_flag); - ui->groupUseGenerator->setChecked(map.generator_flag); - ui->radioBackdropParent->setChecked(info.background_type == 0); - ui->radioBackdropTerrain->setChecked(info.background_type == 1); - ui->radioBackdropSpecify->setChecked(info.background_type == 2); - ui->radioBGMparent->setChecked(info.music_type == 0); - ui->radioBGMevent->setChecked(info.music_type == 1); - ui->radioBGMspecify->setChecked(info.music_type == 2); - ui->radioTeleportParent->setChecked(info.teleport == 0); - ui->radioTeleportAllow->setChecked(info.teleport == 1); - ui->radioTeleportForbid->setChecked(info.teleport == 2); - ui->radioEscapeParent->setChecked(info.escape == 0); - ui->radioEscapeAllow->setChecked(info.escape == 1); - ui->radioEscapeForbid->setChecked(info.escape == 2); - ui->radioSaveParent->setChecked(info.save == 0); - ui->radioSaveAllow->setChecked(info.save == 1); - ui->radioSaveForbid->setChecked(info.save == 2); - ui->radioDungeonSinglePassage->setChecked(map.generator_mode == 0); - ui->radioDungeonLinkedRooms->setChecked(map.generator_mode == 1); - ui->radioDungeonMaze->setChecked(map.generator_mode == 2); - ui->radioDungeonOpenRoom->setChecked(map.generator_mode == 3); - ui->radioDungeonPassage1_1->setChecked(map.generator_tiles == 0); - ui->radioDungeonPassage2_2->setChecked(map.generator_tiles == 1); - for (int i = static_cast(info.encounters.size()) - 1; i >= 0; i--) - { - QTableWidgetItem * item = new QTableWidgetItem(); - item->setData(Qt::DisplayRole, ToQString(database.troops[static_cast(info.encounters[static_cast(i)].troop_id)-1].name)); - item->setData(Qt::UserRole, info.encounters[static_cast(i)].troop_id); - ui->tableEncounters->insertRow(0); - ui->tableEncounters->setItem(0,0,item); + ui->spinDungeonRoomHeight->setValue(m_map_copy.generator_height); + ui->spinDungeonRoomWidth->setValue(m_map_copy.generator_width); + ui->spinEncounterRate->setValue(m_info_copy.encounter_steps); + ui->checkDungeonSurroundWithWalls->setChecked(m_map_copy.generator_surround); + ui->groupUseGenerator->setChecked(m_map_copy.generator_flag); + ui->radioDungeonSinglePassage->setChecked(m_map_copy.generator_mode == 0); + ui->radioDungeonLinkedRooms->setChecked(m_map_copy.generator_mode == 1); + ui->radioDungeonMaze->setChecked(m_map_copy.generator_mode == 2); + ui->radioDungeonOpenRoom->setChecked(m_map_copy.generator_mode == 3); + ui->radioDungeonPassage1_1->setChecked(m_map_copy.generator_tiles == 0); + ui->radioDungeonPassage2_2->setChecked(m_map_copy.generator_tiles == 1); + for (int i = 0; i < static_cast(m_info_copy.encounters.size()); i++) { + QTableWidgetItem *item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole, ToQString(database.troops[static_cast(m_info_copy.encounters[static_cast(i)].troop_id)-1].name)); + item->setData(Qt::UserRole, m_info_copy.encounters[static_cast(i)].troop_id); + ui->tableEncounters->insertRow(i); + ui->tableEncounters->setItem(i, 0, item); } m_encounterDelegate = new QEncounterDelegate(this); ui->tableEncounters->setItemDelegate(m_encounterDelegate); @@ -122,83 +148,83 @@ MapPropertiesDialog::MapPropertiesDialog(ProjectData& project, lcf::rpg::MapInfo ui->graphicsObstacleC->scene()->addItem(m_ObstacleCItem); ui->graphicsUpperWall->scene()->addItem(m_upperWallItem); QPixmap pix(32, 32); - if(map.generator_tile_ids.size()>0) + if(m_map_copy.generator_tile_ids.size()>0) { pix.fill(); core().beginPainting(pix); - core().renderTile(map.generator_tile_ids[0], QRect(0,0,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[0], QRect(0,0,32,32)); core().endPainting(); m_ceilingItem->setPixmap(pix); pix.fill(); core().beginPainting(pix); - core().renderTile(map.generator_tile_ids[1], QRect(0,0,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[1], QRect(0,0,32,32)); core().endPainting(); m_lowerWallItem->setPixmap(pix); pix.fill(); core().beginPainting(pix); - core().renderTile(map.generator_tile_ids[2], QRect(0,0,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[2], QRect(0,0,32,32)); core().endPainting(); m_upperWallItem->setPixmap(pix); pix.fill(); core().beginPainting(pix); - core().renderTile(map.generator_tile_ids[3], QRect(0,0,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[3], QRect(0,0,32,32)); core().endPainting(); m_floorAItem->setPixmap(pix); pix.fill(); core().beginPainting(pix); - core().renderTile(map.generator_tile_ids[4], QRect(0,0,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[4], QRect(0,0,32,32)); core().endPainting(); m_floorBItem->setPixmap(pix); pix.fill(); core().beginPainting(pix); - core().renderTile(map.generator_tile_ids[5], QRect(0,0,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[5], QRect(0,0,32,32)); core().endPainting(); m_floorCItem->setPixmap(pix); pix = QPixmap(64, 64); pix.fill(); core().beginPainting(pix); - core().renderTile(map.generator_tile_ids[6], QRect(0,0,32,32)); - core().renderTile(map.generator_tile_ids[7], QRect(32,0,32,32)); - core().renderTile(map.generator_tile_ids[8], QRect(0,32,32,32)); - core().renderTile(map.generator_tile_ids[9], QRect(32,32,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[6], QRect(0,0,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[7], QRect(32,0,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[8], QRect(0,32,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[9], QRect(32,32,32,32)); core().endPainting(); m_ObstacleAItem->setPixmap(pix); pix.fill(); core().beginPainting(pix); - core().renderTile(map.generator_tile_ids[10], QRect(0,0,32,32)); - core().renderTile(map.generator_tile_ids[11], QRect(32,0,32,32)); - core().renderTile(map.generator_tile_ids[12], QRect(0,32,32,32)); - core().renderTile(map.generator_tile_ids[13], QRect(32,32,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[10], QRect(0,0,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[11], QRect(32,0,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[12], QRect(0,32,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[13], QRect(32,32,32,32)); core().endPainting(); m_ObstacleBItem->setPixmap(pix); pix.fill(); core().beginPainting(pix); - core().renderTile(map.generator_tile_ids[14], QRect(0,0,32,32)); - core().renderTile(map.generator_tile_ids[15], QRect(32,0,32,32)); - core().renderTile(map.generator_tile_ids[16], QRect(0,32,32,32)); - core().renderTile(map.generator_tile_ids[17], QRect(32,32,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[14], QRect(0,0,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[15], QRect(32,0,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[16], QRect(0,32,32,32)); + core().renderTile(m_map_copy.generator_tile_ids[17], QRect(32,32,32,32)); core().endPainting(); m_ObstacleCItem->setPixmap(pix); } - if (map.parallax_flag) + if (m_map_copy.parallax_flag) { - pix = QPixmap(m_project.project().findFile(PANORAMA, ToQString(map.parallax_name), FileFinder::FileType::Image)); + pix = QPixmap(m_project.project().findFile(PANORAMA, ToQString(m_map_copy.parallax_name), FileFinder::FileType::Image)); if (!pix) - pix = QPixmap(core().rtpPath(PANORAMA,ToQString(map.parallax_name))); + pix = QPixmap(core().rtpPath(PANORAMA,ToQString(m_map_copy.parallax_name))); m_panoramaItem->setPixmap(pix); } //TODO: Show generator tiles. - if (info.parent_map == 0) + if (m_info_copy.parent_map == 0) { ui->radioBackdropParent->setEnabled(false); ui->radioBGMparent->setEnabled(false); @@ -206,6 +232,55 @@ MapPropertiesDialog::MapPropertiesDialog(ProjectData& project, lcf::rpg::MapInfo ui->radioSaveParent->setEnabled(false); ui->radioEscapeParent->setEnabled(false); } + + new_panorama = m_map_copy.parallax_name; + new_music = m_info_copy.music; + + old_width = m_map_copy.width; + old_height = m_map_copy.height; + + ui->lineBGMname->setText(ToQString(m_info_copy.music.name)); + + LcfWidgetBinding::connect(this, ui->lineName); + LcfWidgetBinding::connect(this, ui->lineBackdropName); + LcfWidgetBinding::connect(this, ui->comboTileset); + LcfWidgetBinding::connect(this, ui->comboWrapping); + LcfWidgetBinding::connect(this, ui->spinWidth); + LcfWidgetBinding::connect(this, ui->spinHeight); + LcfWidgetBinding::connect(this, ui->groupPanorama); + LcfWidgetBinding::connect(this, ui->groupHorizontalScroll); + LcfWidgetBinding::connect(this, ui->groupVerticalScroll); + LcfWidgetBinding::connect(this, ui->checkHorizontalAutoscroll); + LcfWidgetBinding::connect(this, ui->checkVerticalAutoscroll); + LcfWidgetBinding::connect(this, ui->spinHorizontalScrollSpeed); + LcfWidgetBinding::connect(this, ui->spinVerticalScrollSpeed); + LcfWidgetBinding::connect(this, m_buttonGroupBGM); + LcfWidgetBinding::connect(this, m_buttonGroupBackdrop); + LcfWidgetBinding::connect(this, m_buttonGroupTeleport); + LcfWidgetBinding::connect(this, m_buttonGroupEscape); + LcfWidgetBinding::connect(this, m_buttonGroupSave); + + LcfWidgetBinding::bind(ui->lineName, m_info_copy.name); + LcfWidgetBinding::bind(ui->lineBackdropName, m_info_copy.background_name); + LcfWidgetBinding::bind(ui->comboTileset, m_map_copy.chipset_id); + LcfWidgetBinding::bind(ui->comboWrapping, m_map_copy.scroll_type); + LcfWidgetBinding::bind(ui->spinWidth, m_map_copy.width); + LcfWidgetBinding::bind(ui->spinHeight, m_map_copy.height); + LcfWidgetBinding::bind(ui->groupPanorama, m_map_copy.parallax_flag); + LcfWidgetBinding::bind(ui->groupHorizontalScroll, m_map_copy.parallax_loop_x); + LcfWidgetBinding::bind(ui->groupVerticalScroll, m_map_copy.parallax_loop_y); + LcfWidgetBinding::bind(ui->checkHorizontalAutoscroll, m_map_copy.parallax_auto_loop_x); + LcfWidgetBinding::bind(ui->checkVerticalAutoscroll, m_map_copy.parallax_auto_loop_y); + LcfWidgetBinding::bind(ui->spinHorizontalScrollSpeed, m_map_copy.parallax_sx); + LcfWidgetBinding::bind(ui->spinVerticalScrollSpeed, m_map_copy.parallax_sy); + LcfWidgetBinding::bind(m_buttonGroupBGM, m_info_copy.music_type); + LcfWidgetBinding::bind(m_buttonGroupBackdrop, m_info_copy.background_type); + LcfWidgetBinding::bind(m_buttonGroupTeleport, m_info_copy.teleport); + LcfWidgetBinding::bind(m_buttonGroupEscape, m_info_copy.escape); + LcfWidgetBinding::bind(m_buttonGroupSave, m_info_copy.save); + + ui->spinHorizontalScrollSpeed->setEnabled(m_map_copy.parallax_auto_loop_x); + ui->spinVerticalScrollSpeed->setEnabled(m_map_copy.parallax_auto_loop_y); } MapPropertiesDialog::~MapPropertiesDialog() @@ -224,6 +299,95 @@ MapPropertiesDialog::~MapPropertiesDialog() delete ui; } +void MapPropertiesDialog::accept() { + int width = m_map_copy.width; + int height = m_map_copy.height; + if (width < old_width || height < old_height) { + int result = QMessageBox::question(this, + "Shrink map", + QString("You are about to shrink the current map. All out of bounds map data and events will be deleted. This cannot be undone. Do you want to continue?"), + QMessageBox::Yes | QMessageBox::No); + + if (result != QMessageBox::Yes) { + return; + } + } + + if (ui->groupPanorama->isChecked()) { + m_map_copy.parallax_name = new_panorama; + } else { + m_map_copy.parallax_flag = false; + m_map_copy.parallax_name = ToDBString(""); + m_map_copy.parallax_loop_x = false; + m_map_copy.parallax_loop_y = false; + m_map_copy.parallax_auto_loop_x = false; + m_map_copy.parallax_auto_loop_y = false; + m_map_copy.parallax_sx = 0; + m_map_copy.parallax_sy = 0; + } + + new_music.name = ui->lineBGMname->text().toStdString(); + m_info_copy.music = new_music; + + m_info_copy.encounters.clear(); + for (int i = 0; i < ui->tableEncounters->rowCount(); i++) { + QTableWidgetItem *item = ui->tableEncounters->item(i, 0); + lcf::rpg::Encounter enc; + enc.troop_id = item->data(Qt::UserRole).toInt(); + m_info_copy.encounters.push_back(enc); + } + m_info_copy.encounter_steps = ui->spinEncounterRate->value(); + + // Resize map if map bounds have been changed + if (width != old_width || height != old_height) { + auto old_lower_layer = m_map_copy.lower_layer; + auto old_upper_layer = m_map_copy.upper_layer; + int old_tile_counter = 0; + + m_map_copy.lower_layer.clear(); + m_map_copy.upper_layer.clear(); + for (int y = 0; y < height; y++) { + if (y < old_height) { + for (int x = 0; x < width; x++) { + if (x < old_width) { + m_map_copy.lower_layer.push_back(old_lower_layer[old_tile_counter]); + m_map_copy.upper_layer.push_back(old_upper_layer[old_tile_counter]); + old_tile_counter++; + } else { + m_map_copy.lower_layer.push_back(0); + m_map_copy.upper_layer.push_back(10000); + } + } + if (width < old_width) { + old_tile_counter += (old_width - width); + } + } else { + for (int x = 0; x < width; x++) { + m_map_copy.lower_layer.push_back(0); + m_map_copy.upper_layer.push_back(10000); + } + } + } + + // Delete out of bounds events + if (width < old_width || height < old_height) { + std::vector::iterator ev = m_map_copy.events.begin(); + while (ev != m_map_copy.events.end()) { + if (ev->x >= width || ev->y >= height) { + ev = m_map_copy.events.erase(ev); + } else { + ++ev; + } + } + } + } + + m_info = m_info_copy; + m_map = m_map_copy; + + QDialog::accept(); +} + void MapPropertiesDialog::on_groupPanorama_toggled(bool arg1) { m_panoramaItem->setVisible(arg1); @@ -278,15 +442,60 @@ void MapPropertiesDialog::on_groupObstacleC_toggled(bool arg1) m_ObstacleCItem->setVisible(arg1); } -void MapPropertiesDialog::on_tableEncounters_itemChanged(QTableWidgetItem *item) -{ - if (item->row() == ui->tableEncounters->rowCount()-1) - { - QTableWidgetItem *n_item = new QTableWidgetItem(); - n_item->setData(Qt::DisplayRole, item->data(Qt::DisplayRole)); - n_item->setData(Qt::UserRole, item->data(Qt::UserRole)); - ui->tableEncounters->insertRow(ui->tableEncounters->rowCount()-1); - ui->tableEncounters->setItem(ui->tableEncounters->rowCount()-2, 0, n_item); - item->setData(Qt::DisplayRole, ""); +void MapPropertiesDialog::on_pushAddEncounter_clicked() { + QTableWidgetItem* item = new QTableWidgetItem(); + item->setData(Qt::DisplayRole, ToQString(m_project.database().troops[0].name)); + item->setData(Qt::UserRole, 1); + ui->tableEncounters->insertRow(ui->tableEncounters->rowCount()); + ui->tableEncounters->setItem(ui->tableEncounters->rowCount() - 1, 0, item); +} + +void MapPropertiesDialog::on_pushRemoveEncounter_clicked() { + QTableWidgetItem *item = ui->tableEncounters->currentItem(); + if (item) { + ui->tableEncounters->removeRow(item->row()); } } + +void MapPropertiesDialog::on_pushSetPanorama_clicked() { + auto* widget = new PickerPanoramaWidget(this); + PickerDialog dialog(m_project, FileFinder::FileType::Image, widget, this); + QObject::connect(&dialog, &PickerDialog::fileSelected, [&](const QString& baseName) { + new_panorama = ToDBString(baseName); + }); + dialog.setDirectoryAndFile(PANORAMA, ToQString(new_panorama)); + dialog.exec(); + + if (!new_panorama.empty()) { + QPixmap pix = QPixmap(m_project.project().findFile(PANORAMA, ToQString(new_panorama), FileFinder::FileType::Image)); + if (!pix) { + pix = QPixmap(core().rtpPath(PANORAMA, ToQString(new_panorama))); + } + m_panoramaItem->setPixmap(pix); + } +} + +void MapPropertiesDialog::on_toolSetBGM_clicked() { + auto* widget = new PickerAudioWidget(new_music, this); + PickerDialog dialog(m_project, FileFinder::FileType::Music, widget, this); + QObject::connect(&dialog, &PickerDialog::fileSelected, [&](const QString& baseName) { + ui->lineBGMname->setText(baseName); + new_music.name = baseName.toStdString(); + new_music.fadein = widget->fadeInTime(); + new_music.volume = widget->volume(); + new_music.tempo = widget->tempo(); + new_music.balance = widget->balance(); + }); + dialog.setDirectoryAndFile(MUSIC, ui->lineBGMname->text()); + dialog.exec(); +} + +void MapPropertiesDialog::on_toolSetBackdrop_clicked() { + auto* widget = new PickerBackdropWidget(this); + PickerDialog dialog(m_project, FileFinder::FileType::Image, widget, this); + QObject::connect(&dialog, &PickerDialog::fileSelected, [&](const QString& baseName) { + ui->lineBackdropName->setText(baseName); + }); + dialog.setDirectoryAndFile(BACKDROP, ui->lineBackdropName->text()); + dialog.exec(); +} diff --git a/src/ui/maptree/map_properties_dialog.h b/src/ui/maptree/map_properties_dialog.h index ba59180c..c53c281c 100644 --- a/src/ui/maptree/map_properties_dialog.h +++ b/src/ui/maptree/map_properties_dialog.h @@ -23,6 +23,7 @@ #include #include #include "ui/common/encounter_delegate.h" +#include class ProjectData; @@ -39,6 +40,8 @@ class MapPropertiesDialog : public QDialog ~MapPropertiesDialog(); private slots: + void accept(); + void on_groupPanorama_toggled(bool arg1); void on_groupUseGenerator_toggled(bool arg1); @@ -53,7 +56,15 @@ private slots: void on_groupObstacleC_toggled(bool arg1); - void on_tableEncounters_itemChanged(QTableWidgetItem *item); + void on_pushAddEncounter_clicked(); + + void on_pushRemoveEncounter_clicked(); + + void on_pushSetPanorama_clicked(); + + void on_toolSetBGM_clicked(); + + void on_toolSetBackdrop_clicked(); private: Ui::MapPropertiesDialog *ui; @@ -73,10 +84,24 @@ private slots: lcf::rpg::MapInfo &m_info; lcf::rpg::Map &m_map; + lcf::rpg::MapInfo m_info_copy; + lcf::rpg::Map m_map_copy; std::vector m_generatorLowerLayer; std::vector m_generatorUpperLayer; ProjectData& m_project; + + lcf::DBString new_panorama; + lcf::rpg::Music new_music; + + int old_width; + int old_height; + + QButtonGroup* m_buttonGroupBGM = nullptr; + QButtonGroup* m_buttonGroupBackdrop = nullptr; + QButtonGroup* m_buttonGroupTeleport = nullptr; + QButtonGroup* m_buttonGroupEscape = nullptr; + QButtonGroup* m_buttonGroupSave = nullptr; }; diff --git a/src/ui/maptree/map_properties_dialog.ui b/src/ui/maptree/map_properties_dialog.ui index 7c298b0d..316428f4 100644 --- a/src/ui/maptree/map_properties_dialog.ui +++ b/src/ui/maptree/map_properties_dialog.ui @@ -56,10 +56,18 @@ - + + + 20 + + - + + + 15 + + @@ -71,28 +79,7 @@ - - - - None - - - - - Vertical - - - - - Horizontal - - - - - Both - - - + @@ -117,37 +104,30 @@ 21 - - - - - Name + + + + - - <Add Encounter> - - - - 75 - true - - - - - - 85 - 170 - 0 - - - + + + Add + + - + + + + Remove + + + + @@ -186,7 +166,20 @@ - + + + + 324 + 244 + + + + + 324 + 244 + + + diff --git a/src/ui/picker/picker_backdrop_widget.cpp b/src/ui/picker/picker_backdrop_widget.cpp new file mode 100644 index 00000000..97832727 --- /dev/null +++ b/src/ui/picker/picker_backdrop_widget.cpp @@ -0,0 +1,31 @@ +/* + * This file is part of EasyRPG Editor. + * + * EasyRPG Editor is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EasyRPG Editor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EasyRPG Editor. If not, see . + */ + +#include "picker_backdrop_widget.h" +#include "ui/viewer/rpg_graphics_view.h" +#include + +void PickerBackdropWidget::imageChanged(QPixmap image) { + if (!m_pixmap) { + m_view->setMinimumSize(324, 244); + m_view->setMaximumSize(324, 244); + m_pixmap = new QGraphicsPixmapItem(image); + } + + m_pixmap->setPixmap(image); + m_view->setItem(m_pixmap); +} diff --git a/src/ui/picker/picker_backdrop_widget.h b/src/ui/picker/picker_backdrop_widget.h new file mode 100644 index 00000000..2dab24fa --- /dev/null +++ b/src/ui/picker/picker_backdrop_widget.h @@ -0,0 +1,35 @@ +/* + * This file is part of EasyRPG Editor. + * + * EasyRPG Editor is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EasyRPG Editor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EasyRPG Editor. If not, see . + */ + +#pragma once + +#include +#include "picker_child_widget.h" + +class QGraphicsScene; +class QGraphicsPixmapItem; + +class PickerBackdropWidget : public PickerChildWidget { + Q_OBJECT +public: + PickerBackdropWidget(QWidget* parent = nullptr) : PickerChildWidget(parent) {} + + void imageChanged(QPixmap image) override; + +private: + QGraphicsPixmapItem* m_pixmap = nullptr; +}; diff --git a/src/ui/picker/picker_panorama_widget.cpp b/src/ui/picker/picker_panorama_widget.cpp new file mode 100644 index 00000000..1698fa11 --- /dev/null +++ b/src/ui/picker/picker_panorama_widget.cpp @@ -0,0 +1,31 @@ +/* + * This file is part of EasyRPG Editor. + * + * EasyRPG Editor is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EasyRPG Editor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EasyRPG Editor. If not, see . + */ + +#include "picker_panorama_widget.h" +#include "ui/viewer/rpg_graphics_view.h" +#include + +void PickerPanoramaWidget::imageChanged(QPixmap image) { + if (!m_pixmap) { + m_view->setMinimumSize(324, 244); + m_view->setMaximumSize(324, 244); + m_pixmap = new QGraphicsPixmapItem(image); + } + + m_pixmap->setPixmap(image); + m_view->setItem(m_pixmap); +} diff --git a/src/ui/picker/picker_panorama_widget.h b/src/ui/picker/picker_panorama_widget.h new file mode 100644 index 00000000..f716a2cb --- /dev/null +++ b/src/ui/picker/picker_panorama_widget.h @@ -0,0 +1,35 @@ +/* + * This file is part of EasyRPG Editor. + * + * EasyRPG Editor is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EasyRPG Editor is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with EasyRPG Editor. If not, see . + */ + +#pragma once + +#include +#include "picker_child_widget.h" + +class QGraphicsScene; +class QGraphicsPixmapItem; + +class PickerPanoramaWidget : public PickerChildWidget { + Q_OBJECT +public: + PickerPanoramaWidget(QWidget* parent = nullptr) : PickerChildWidget(parent) {} + + void imageChanged(QPixmap image) override; + +private: + QGraphicsPixmapItem* m_pixmap = nullptr; +};