mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-19 23:25:09 -05:00
lots of changes
This commit is contained in:
365
mainwindow.cpp
365
mainwindow.cpp
@@ -1,12 +1,20 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "project.h"
|
||||
#include "editor.h"
|
||||
#include "objectpropertiesframe.h"
|
||||
#include "ui_objectpropertiesframe.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
#include <QStandardItemModel>
|
||||
#include <QShortcut>
|
||||
#include <QSettings>
|
||||
#include <QSpinBox>
|
||||
#include <QTextEdit>
|
||||
#include <QSpacerItem>
|
||||
#include <QFont>
|
||||
#include <QScrollBar>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
@@ -15,16 +23,23 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
QCoreApplication::setOrganizationName("pret");
|
||||
QCoreApplication::setApplicationName("pretmap");
|
||||
|
||||
editor = new Editor;
|
||||
|
||||
new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
|
||||
ui->setupUi(this);
|
||||
new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
|
||||
|
||||
editor = new Editor;
|
||||
connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects()));
|
||||
connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
|
||||
|
||||
on_toolButton_Paint_clicked();
|
||||
|
||||
QSettings settings;
|
||||
QString key = "recent_projects";
|
||||
if (settings.contains(key)) {
|
||||
QString default_dir = settings.value(key).toStringList().last();
|
||||
openProject(default_dir);
|
||||
if (!default_dir.isNull()) {
|
||||
qDebug() << QString("default_dir: '%1'").arg(default_dir);
|
||||
openProject(default_dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,35 +49,53 @@ MainWindow::~MainWindow()
|
||||
}
|
||||
|
||||
void MainWindow::openProject(QString dir) {
|
||||
bool already_open = (editor->project != NULL) && (editor->project->root == dir);
|
||||
if (dir.isNull()) {
|
||||
return;
|
||||
}
|
||||
bool already_open = (
|
||||
(editor != NULL && editor != nullptr)
|
||||
&& (editor->project != NULL && editor->project != nullptr)
|
||||
&& (editor->project->root == dir)
|
||||
);
|
||||
if (!already_open) {
|
||||
editor->project = new Project;
|
||||
editor->project->root = dir;
|
||||
setWindowTitle(editor->project->getProjectTitle() + " - pretmap");
|
||||
populateMapList();
|
||||
setMap(getDefaultMap());
|
||||
} else {
|
||||
setWindowTitle(editor->project->getProjectTitle() + " - pretmap");
|
||||
populateMapList();
|
||||
}
|
||||
}
|
||||
|
||||
QString MainWindow::getDefaultMap() {
|
||||
QSettings settings;
|
||||
QString key = "project:" + editor->project->root;
|
||||
if (settings.contains(key)) {
|
||||
QMap<QString, QVariant> qmap = settings.value(key).toMap();
|
||||
if (qmap.contains("recent_map")) {
|
||||
QString map_name = qmap.value("recent_map").toString();
|
||||
return map_name;
|
||||
if (editor && editor->project) {
|
||||
QList<QStringList*> *names = editor->project->groupedMapNames;
|
||||
if (names) {
|
||||
QSettings settings;
|
||||
QString key = "project:" + editor->project->root;
|
||||
if (settings.contains(key)) {
|
||||
QMap<QString, QVariant> qmap = settings.value(key).toMap();
|
||||
if (qmap.contains("recent_map")) {
|
||||
QString map_name = qmap.value("recent_map").toString();
|
||||
for (int i = 0; i < names->length(); i++) {
|
||||
if (names->value(i)->contains(map_name)) {
|
||||
return map_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Failing that, just get the first map in the list.
|
||||
for (int i = 0; i < names->length(); i++) {
|
||||
QStringList *list = names->value(i);
|
||||
if (list->length()) {
|
||||
return list->value(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Failing that, just get the first map in the list.
|
||||
for (int i = 0; i < editor->project->groupedMapNames->length(); i++) {
|
||||
QStringList *list = editor->project->groupedMapNames->value(i);
|
||||
if (list->length()) {
|
||||
return list->value(0);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString MainWindow::getExistingDirectory(QString dir) {
|
||||
@@ -92,6 +125,7 @@ void MainWindow::on_action_Open_Project_triggered()
|
||||
}
|
||||
|
||||
void MainWindow::setMap(QString map_name) {
|
||||
qDebug() << QString("setMap(%1)").arg(map_name);
|
||||
if (map_name.isNull()) {
|
||||
return;
|
||||
}
|
||||
@@ -114,6 +148,7 @@ void MainWindow::setMap(QString map_name) {
|
||||
ui->graphicsView_Objects_Map->setScene(editor->scene);
|
||||
ui->graphicsView_Objects_Map->setSceneRect(editor->scene->sceneRect());
|
||||
ui->graphicsView_Objects_Map->setFixedSize(editor->scene->width() + 2, editor->scene->height() + 2);
|
||||
ui->graphicsView_Objects_Map->editor = editor;
|
||||
|
||||
ui->graphicsView_Metatiles->setScene(editor->scene_metatiles);
|
||||
//ui->graphicsView_Metatiles->setSceneRect(editor->scene_metatiles->sceneRect());
|
||||
@@ -129,6 +164,10 @@ void MainWindow::setMap(QString map_name) {
|
||||
|
||||
displayMapProperties();
|
||||
|
||||
setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - pretmap");
|
||||
|
||||
connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
|
||||
|
||||
setRecentMap(map_name);
|
||||
updateMapList();
|
||||
}
|
||||
@@ -145,11 +184,22 @@ void MainWindow::setRecentMap(QString map_name) {
|
||||
}
|
||||
|
||||
void MainWindow::displayMapProperties() {
|
||||
ui->comboBox_Song->clear();
|
||||
ui->comboBox_Location->clear();
|
||||
ui->comboBox_Visibility->clear();
|
||||
ui->comboBox_Weather->clear();
|
||||
ui->comboBox_Type->clear();
|
||||
ui->comboBox_BattleScene->clear();
|
||||
ui->checkBox_ShowLocation->setChecked(false);
|
||||
if (!editor || !editor->map || !editor->project) {
|
||||
ui->frame_3->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
ui->frame_3->setEnabled(true);
|
||||
Map *map = editor->map;
|
||||
Project *project = editor->project;
|
||||
|
||||
QStringList songs = project->getSongNames();
|
||||
ui->comboBox_Song->clear();
|
||||
ui->comboBox_Song->addItems(songs);
|
||||
QString song = map->song;
|
||||
if (!songs.contains(song)) {
|
||||
@@ -157,23 +207,18 @@ void MainWindow::displayMapProperties() {
|
||||
}
|
||||
ui->comboBox_Song->setCurrentText(song);
|
||||
|
||||
ui->comboBox_Location->clear();
|
||||
ui->comboBox_Location->addItems(project->getLocations());
|
||||
ui->comboBox_Location->setCurrentText(map->location);
|
||||
|
||||
ui->comboBox_Visibility->clear();
|
||||
ui->comboBox_Visibility->addItems(project->getVisibilities());
|
||||
ui->comboBox_Visibility->setCurrentText(map->visibility);
|
||||
|
||||
ui->comboBox_Weather->clear();
|
||||
ui->comboBox_Weather->addItems(project->getWeathers());
|
||||
ui->comboBox_Weather->setCurrentText(map->weather);
|
||||
|
||||
ui->comboBox_Type->clear();
|
||||
ui->comboBox_Type->addItems(project->getMapTypes());
|
||||
ui->comboBox_Type->setCurrentText(map->type);
|
||||
|
||||
ui->comboBox_BattleScene->clear();
|
||||
ui->comboBox_BattleScene->addItems(project->getBattleScenes());
|
||||
ui->comboBox_BattleScene->setCurrentText(map->battle_scene);
|
||||
|
||||
@@ -182,40 +227,54 @@ void MainWindow::displayMapProperties() {
|
||||
|
||||
void MainWindow::on_comboBox_Song_activated(const QString &song)
|
||||
{
|
||||
editor->map->song = song;
|
||||
if (editor && editor->map) {
|
||||
editor->map->song = song;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_comboBox_Location_activated(const QString &location)
|
||||
{
|
||||
editor->map->location = location;
|
||||
if (editor && editor->map) {
|
||||
editor->map->location = location;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_comboBox_Visibility_activated(const QString &visibility)
|
||||
{
|
||||
editor->map->visibility = visibility;
|
||||
if (editor && editor->map) {
|
||||
editor->map->visibility = visibility;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_comboBox_Weather_activated(const QString &weather)
|
||||
{
|
||||
editor->map->weather = weather;
|
||||
if (editor && editor->map) {
|
||||
editor->map->weather = weather;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_comboBox_Type_activated(const QString &type)
|
||||
{
|
||||
editor->map->type = type;
|
||||
if (editor && editor->map) {
|
||||
editor->map->type = type;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_comboBox_BattleScene_activated(const QString &battle_scene)
|
||||
{
|
||||
editor->map->battle_scene = battle_scene;
|
||||
if (editor && editor->map) {
|
||||
editor->map->battle_scene = battle_scene;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_checkBox_ShowLocation_clicked(bool checked)
|
||||
{
|
||||
if (checked) {
|
||||
editor->map->show_location = "TRUE";
|
||||
} else {
|
||||
editor->map->show_location = "FALSE";
|
||||
if (editor && editor->map) {
|
||||
if (checked) {
|
||||
editor->map->show_location = "TRUE";
|
||||
} else {
|
||||
editor->map->show_location = "FALSE";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +340,7 @@ void MainWindow::on_mapList_activated(const QModelIndex &index)
|
||||
if (!data.isNull()) {
|
||||
setMap(data.toString());
|
||||
}
|
||||
updateMapList();
|
||||
//updateMapList();
|
||||
}
|
||||
|
||||
void MainWindow::markAllEdited(QAbstractItemModel *model) {
|
||||
@@ -307,7 +366,8 @@ void MainWindow::markEdited(QModelIndex index) {
|
||||
if (editor->project->map_cache->contains(map_name)) {
|
||||
// Just mark anything that's been opened for now.
|
||||
// TODO if (project->getMap()->saved)
|
||||
ui->mapList->setExpanded(index, true);
|
||||
//ui->mapList->setExpanded(index, true);
|
||||
ui->mapList->setExpanded(index, editor->project->map_cache->value(map_name)->hasUnsavedChanges());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,6 +394,7 @@ void MainWindow::redo() {
|
||||
|
||||
void MainWindow::on_action_Save_triggered() {
|
||||
editor->save();
|
||||
updateMapList();
|
||||
}
|
||||
|
||||
void MainWindow::on_tabWidget_2_currentChanged(int index)
|
||||
@@ -368,3 +429,231 @@ void MainWindow::on_actionRedo_triggered()
|
||||
{
|
||||
redo();
|
||||
}
|
||||
|
||||
void MainWindow::on_toolButton_newObject_clicked()
|
||||
{
|
||||
if (editor) {
|
||||
DraggablePixmapItem *object = editor->addNewEvent();
|
||||
if (object) {
|
||||
//if (editor->selected_events->length()) {
|
||||
editor->selectMapObject(object, true);
|
||||
//}
|
||||
}
|
||||
updateSelectedObjects();
|
||||
}
|
||||
}
|
||||
|
||||
// Should probably just pass layout and let the editor work it out
|
||||
void MainWindow::updateSelectedObjects() {
|
||||
|
||||
QList<DraggablePixmapItem *> *all_events = editor->getObjects();
|
||||
QList<DraggablePixmapItem *> *events = all_events;
|
||||
|
||||
if (editor->selected_events && editor->selected_events->length()) {
|
||||
events = editor->selected_events;
|
||||
}
|
||||
|
||||
QMap<QString, int> map_obj_gfx_constants = editor->project->getMapObjGfxConstants();
|
||||
|
||||
QList<ObjectPropertiesFrame *> frames;
|
||||
|
||||
for (DraggablePixmapItem *item : *events) {
|
||||
ObjectPropertiesFrame *frame = new ObjectPropertiesFrame;
|
||||
// frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
|
||||
QSpinBox *x = frame->ui->spinBox_x;
|
||||
QSpinBox *y = frame->ui->spinBox_y;
|
||||
QSpinBox *z = frame->ui->spinBox_z;
|
||||
|
||||
x->setValue(item->event->x());
|
||||
connect(x, SIGNAL(valueChanged(QString)), item, SLOT(set_x(QString)));
|
||||
connect(item, SIGNAL(xChanged(int)), x, SLOT(setValue(int)));
|
||||
|
||||
y->setValue(item->event->y());
|
||||
connect(y, SIGNAL(valueChanged(QString)), item, SLOT(set_y(QString)));
|
||||
connect(item, SIGNAL(yChanged(int)), y, SLOT(setValue(int)));
|
||||
|
||||
z->setValue(item->event->elevation());
|
||||
connect(z, SIGNAL(valueChanged(QString)), item, SLOT(set_elevation(QString)));
|
||||
connect(item, SIGNAL(elevationChanged(int)), z, SLOT(setValue(int)));
|
||||
|
||||
QFont font;
|
||||
font.setCapitalization(QFont::Capitalize);
|
||||
frame->ui->label_name->setFont(font);
|
||||
QString event_type = item->event->get("event_type");
|
||||
QString map_name = item->event->get("map_name");
|
||||
frame->ui->label_name->setText(
|
||||
QString("%1 %2 %3")
|
||||
.arg(map_name)
|
||||
.arg(event_type)
|
||||
.arg(editor->project->getMap(map_name)->events.value(event_type).indexOf(item->event) + 1)
|
||||
);
|
||||
|
||||
frame->ui->label_spritePixmap->setPixmap(item->event->pixmap);
|
||||
connect(item, SIGNAL(spriteChanged(QPixmap)), frame->ui->label_spritePixmap, SLOT(setPixmap(QPixmap)));
|
||||
|
||||
frame->ui->sprite->setVisible(false);
|
||||
|
||||
QMap<QString, QString> field_labels;
|
||||
field_labels["script_label"] = "Script";
|
||||
field_labels["event_flag"] = "Event Flag";
|
||||
field_labels["replacement"] = "Replacement";
|
||||
field_labels["property"] = "Property";
|
||||
field_labels["sight_radius"] = "Sight Radius";
|
||||
field_labels["destination_warp"] = "Destination Warp";
|
||||
field_labels["destination_map"] = "Destination Map";
|
||||
field_labels["coord_unknown1"] = "Unknown 1";
|
||||
field_labels["coord_unknown2"] = "Unknown 2";
|
||||
field_labels["type"] = "Type";
|
||||
field_labels["item"] = "Item";
|
||||
field_labels["item_unknown5"] = "Unknown 5";
|
||||
field_labels["item_unknown6"] = "Unknown 6";
|
||||
|
||||
QStringList fields;
|
||||
|
||||
if (event_type == "object") {
|
||||
|
||||
frame->ui->sprite->setVisible(true);
|
||||
frame->ui->comboBox_sprite->addItems(map_obj_gfx_constants.keys());
|
||||
frame->ui->comboBox_sprite->setCurrentText(item->event->get("sprite"));
|
||||
connect(frame->ui->comboBox_sprite, SIGNAL(activated(QString)), item, SLOT(set_sprite(QString)));
|
||||
|
||||
/*
|
||||
frame->ui->script->setVisible(true);
|
||||
frame->ui->comboBox_script->addItem(item->event->get("script_label"));
|
||||
frame->ui->comboBox_script->setCurrentText(item->event->get("script_label"));
|
||||
//item->bind(frame->ui->comboBox_script, "script_label");
|
||||
connect(frame->ui->comboBox_script, SIGNAL(activated(QString)), item, SLOT(set_script(QString)));
|
||||
//connect(frame->ui->comboBox_script, static_cast<void (QComboBox::*)(const QString&)>(&QComboBox::activated), item, [item](QString script_label){ item->event->put("script_label", script_label); });
|
||||
//connect(item, SIGNAL(scriptChanged(QString)), frame->ui->comboBox_script, SLOT(setValue(QString)));
|
||||
*/
|
||||
|
||||
fields << "script_label";
|
||||
fields << "event_flag";
|
||||
fields << "replacement";
|
||||
fields << "property";
|
||||
fields << "sight_radius";
|
||||
}
|
||||
else if (event_type == "warp") {
|
||||
fields << "destination_warp";
|
||||
fields << "destination_map";
|
||||
}
|
||||
else if (event_type == "trap") {
|
||||
fields << "script_label";
|
||||
fields << "coord_unknown1";
|
||||
fields << "coord_unknown2";
|
||||
}
|
||||
else if (event_type == "sign") {
|
||||
fields << "type";
|
||||
fields << "script_label";
|
||||
}
|
||||
else if (event_type == "hidden item") {
|
||||
fields << "type";
|
||||
fields << "item";
|
||||
fields << "item_unknown5";
|
||||
fields << "item_unknown6";
|
||||
}
|
||||
|
||||
for (QString key : fields) {
|
||||
QWidget *widget = new QWidget(frame);
|
||||
QFormLayout *fl = new QFormLayout(widget);
|
||||
fl->setContentsMargins(9, 0, 9, 0);
|
||||
QComboBox *combo = new QComboBox(widget);
|
||||
combo->setEditable(true);
|
||||
|
||||
QString value = item->event->get(key);
|
||||
if (key == "destination_map") {
|
||||
if (!editor->project->mapNames->contains(value)) {
|
||||
combo->addItem(value);
|
||||
}
|
||||
combo->addItems(*editor->project->mapNames);
|
||||
} else {
|
||||
combo->addItem(value);
|
||||
}
|
||||
combo->setCurrentText(value);
|
||||
|
||||
fl->addRow(new QLabel(field_labels[key], widget), combo);
|
||||
widget->setLayout(fl);
|
||||
frame->layout()->addWidget(widget);
|
||||
|
||||
item->bind(combo, key);
|
||||
}
|
||||
|
||||
frames.append(frame);
|
||||
|
||||
}
|
||||
|
||||
//int scroll = ui->scrollArea_4->verticalScrollBar()->value();
|
||||
|
||||
QWidget *target = ui->scrollAreaWidgetContents;
|
||||
|
||||
if (target->children().length()) {
|
||||
qDeleteAll(target->children());
|
||||
}
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(target);
|
||||
target->setLayout(layout);
|
||||
ui->scrollArea_4->setWidgetResizable(true);
|
||||
ui->scrollArea_4->setWidget(target);
|
||||
|
||||
for (ObjectPropertiesFrame *frame : frames) {
|
||||
layout->addWidget(frame);
|
||||
}
|
||||
|
||||
layout->addStretch(1);
|
||||
|
||||
// doesn't work
|
||||
//QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
//ui->scrollArea_4->ensureVisible(0, scroll);
|
||||
}
|
||||
|
||||
void MainWindow::on_toolButton_deleteObject_clicked()
|
||||
{
|
||||
if (editor && editor->selected_events) {
|
||||
if (editor->selected_events->length()) {
|
||||
for (DraggablePixmapItem *item : *editor->selected_events) {
|
||||
editor->deleteEvent(item->event);
|
||||
if (editor->scene->items().contains(item)) {
|
||||
editor->scene->removeItem(item);
|
||||
}
|
||||
editor->selected_events->removeOne(item);
|
||||
}
|
||||
updateSelectedObjects();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_toolButton_Paint_clicked()
|
||||
{
|
||||
editor->map_edit_mode = "paint";
|
||||
checkToolButtons();
|
||||
}
|
||||
|
||||
void MainWindow::on_toolButton_Select_clicked()
|
||||
{
|
||||
editor->map_edit_mode = "select";
|
||||
checkToolButtons();
|
||||
}
|
||||
|
||||
void MainWindow::on_toolButton_Fill_clicked()
|
||||
{
|
||||
editor->map_edit_mode = "fill";
|
||||
checkToolButtons();
|
||||
}
|
||||
|
||||
void MainWindow::on_toolButton_Dropper_clicked()
|
||||
{
|
||||
editor->map_edit_mode = "pick";
|
||||
checkToolButtons();
|
||||
}
|
||||
|
||||
void MainWindow::checkToolButtons() {
|
||||
ui->toolButton_Paint->setChecked(editor->map_edit_mode == "paint");
|
||||
ui->toolButton_Select->setChecked(editor->map_edit_mode == "select");
|
||||
ui->toolButton_Fill->setChecked(editor->map_edit_mode == "fill");
|
||||
ui->toolButton_Dropper->setChecked(editor->map_edit_mode == "pick");
|
||||
}
|
||||
|
||||
void MainWindow::onMapChanged(Map *map) {
|
||||
updateMapList();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user