No Description

mainwindow.cpp 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include "project.h"
  4. #include "editor.h"
  5. #include "objectpropertiesframe.h"
  6. #include "ui_objectpropertiesframe.h"
  7. #include <QDebug>
  8. #include <QFileDialog>
  9. #include <QStandardItemModel>
  10. #include <QShortcut>
  11. #include <QSettings>
  12. #include <QSpinBox>
  13. #include <QTextEdit>
  14. #include <QSpacerItem>
  15. #include <QFont>
  16. #include <QScrollBar>
  17. MainWindow::MainWindow(QWidget *parent) :
  18. QMainWindow(parent),
  19. ui(new Ui::MainWindow)
  20. {
  21. QCoreApplication::setOrganizationName("pret");
  22. QCoreApplication::setApplicationName("pretmap");
  23. ui->setupUi(this);
  24. new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
  25. editor = new Editor;
  26. connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects()));
  27. connect(editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
  28. on_toolButton_Paint_clicked();
  29. QSettings settings;
  30. QString key = "recent_projects";
  31. if (settings.contains(key)) {
  32. QString default_dir = settings.value(key).toStringList().last();
  33. if (!default_dir.isNull()) {
  34. qDebug() << QString("default_dir: '%1'").arg(default_dir);
  35. openProject(default_dir);
  36. }
  37. }
  38. }
  39. MainWindow::~MainWindow()
  40. {
  41. delete ui;
  42. }
  43. void MainWindow::openProject(QString dir) {
  44. if (dir.isNull()) {
  45. return;
  46. }
  47. bool already_open = (
  48. (editor != NULL && editor != nullptr)
  49. && (editor->project != NULL && editor->project != nullptr)
  50. && (editor->project->root == dir)
  51. );
  52. if (!already_open) {
  53. editor->project = new Project;
  54. editor->project->root = dir;
  55. setWindowTitle(editor->project->getProjectTitle() + " - pretmap");
  56. populateMapList();
  57. setMap(getDefaultMap());
  58. } else {
  59. setWindowTitle(editor->project->getProjectTitle() + " - pretmap");
  60. populateMapList();
  61. }
  62. }
  63. QString MainWindow::getDefaultMap() {
  64. if (editor && editor->project) {
  65. QList<QStringList*> *names = editor->project->groupedMapNames;
  66. if (names) {
  67. QSettings settings;
  68. QString key = "project:" + editor->project->root;
  69. if (settings.contains(key)) {
  70. QMap<QString, QVariant> qmap = settings.value(key).toMap();
  71. if (qmap.contains("recent_map")) {
  72. QString map_name = qmap.value("recent_map").toString();
  73. for (int i = 0; i < names->length(); i++) {
  74. if (names->value(i)->contains(map_name)) {
  75. return map_name;
  76. }
  77. }
  78. }
  79. }
  80. // Failing that, just get the first map in the list.
  81. for (int i = 0; i < names->length(); i++) {
  82. QStringList *list = names->value(i);
  83. if (list->length()) {
  84. return list->value(0);
  85. }
  86. }
  87. }
  88. }
  89. return QString();
  90. }
  91. QString MainWindow::getExistingDirectory(QString dir) {
  92. return QFileDialog::getExistingDirectory(this, "Open Directory", dir, QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
  93. }
  94. void MainWindow::on_action_Open_Project_triggered()
  95. {
  96. QSettings settings;
  97. QString key = "recent_projects";
  98. QString recent = ".";
  99. if (settings.contains(key)) {
  100. recent = settings.value(key).toStringList().last();
  101. }
  102. QString dir = getExistingDirectory(recent);
  103. if (!dir.isEmpty()) {
  104. QStringList recents;
  105. if (settings.contains(key)) {
  106. recents = settings.value(key).toStringList();
  107. }
  108. recents.removeAll(dir);
  109. recents.append(dir);
  110. settings.setValue(key, recents);
  111. openProject(dir);
  112. }
  113. }
  114. void MainWindow::setMap(QString map_name) {
  115. qDebug() << QString("setMap(%1)").arg(map_name);
  116. if (map_name.isNull()) {
  117. return;
  118. }
  119. editor->setMap(map_name);
  120. if (ui->tabWidget->currentIndex() == 1) {
  121. editor->setEditingObjects();
  122. } else {
  123. if (ui->tabWidget_2->currentIndex() == 1) {
  124. editor->setEditingCollision();
  125. } else {
  126. editor->setEditingMap();
  127. }
  128. }
  129. ui->graphicsView_Map->setScene(editor->scene);
  130. ui->graphicsView_Map->setSceneRect(editor->scene->sceneRect());
  131. ui->graphicsView_Map->setFixedSize(editor->scene->width() + 2, editor->scene->height() + 2);
  132. ui->graphicsView_Objects_Map->setScene(editor->scene);
  133. ui->graphicsView_Objects_Map->setSceneRect(editor->scene->sceneRect());
  134. ui->graphicsView_Objects_Map->setFixedSize(editor->scene->width() + 2, editor->scene->height() + 2);
  135. ui->graphicsView_Objects_Map->editor = editor;
  136. ui->graphicsView_Metatiles->setScene(editor->scene_metatiles);
  137. //ui->graphicsView_Metatiles->setSceneRect(editor->scene_metatiles->sceneRect());
  138. ui->graphicsView_Metatiles->setFixedSize(editor->metatiles_item->pixmap().width() + 2, editor->metatiles_item->pixmap().height() + 2);
  139. ui->graphicsView_Collision->setScene(editor->scene_collision_metatiles);
  140. //ui->graphicsView_Collision->setSceneRect(editor->scene_collision_metatiles->sceneRect());
  141. ui->graphicsView_Collision->setFixedSize(editor->collision_metatiles_item->pixmap().width() + 2, editor->collision_metatiles_item->pixmap().height() + 2);
  142. ui->graphicsView_Elevation->setScene(editor->scene_elevation_metatiles);
  143. //ui->graphicsView_Elevation->setSceneRect(editor->scene_elevation_metatiles->sceneRect());
  144. ui->graphicsView_Elevation->setFixedSize(editor->elevation_metatiles_item->pixmap().width() + 2, editor->elevation_metatiles_item->pixmap().height() + 2);
  145. displayMapProperties();
  146. setWindowTitle(map_name + " - " + editor->project->getProjectTitle() + " - pretmap");
  147. connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
  148. setRecentMap(map_name);
  149. updateMapList();
  150. }
  151. void MainWindow::setRecentMap(QString map_name) {
  152. QSettings settings;
  153. QString key = "project:" + editor->project->root;
  154. QMap<QString, QVariant> qmap;
  155. if (settings.contains(key)) {
  156. qmap = settings.value(key).toMap();
  157. }
  158. qmap.insert("recent_map", map_name);
  159. settings.setValue(key, qmap);
  160. }
  161. void MainWindow::displayMapProperties() {
  162. ui->comboBox_Song->clear();
  163. ui->comboBox_Location->clear();
  164. ui->comboBox_Visibility->clear();
  165. ui->comboBox_Weather->clear();
  166. ui->comboBox_Type->clear();
  167. ui->comboBox_BattleScene->clear();
  168. ui->checkBox_ShowLocation->setChecked(false);
  169. if (!editor || !editor->map || !editor->project) {
  170. ui->frame_3->setEnabled(false);
  171. return;
  172. }
  173. ui->frame_3->setEnabled(true);
  174. Map *map = editor->map;
  175. Project *project = editor->project;
  176. QStringList songs = project->getSongNames();
  177. ui->comboBox_Song->addItems(songs);
  178. QString song = map->song;
  179. if (!songs.contains(song)) {
  180. song = project->getSongName(song.toInt());
  181. }
  182. ui->comboBox_Song->setCurrentText(song);
  183. ui->comboBox_Location->addItems(project->getLocations());
  184. ui->comboBox_Location->setCurrentText(map->location);
  185. ui->comboBox_Visibility->addItems(project->getVisibilities());
  186. ui->comboBox_Visibility->setCurrentText(map->visibility);
  187. ui->comboBox_Weather->addItems(project->getWeathers());
  188. ui->comboBox_Weather->setCurrentText(map->weather);
  189. ui->comboBox_Type->addItems(project->getMapTypes());
  190. ui->comboBox_Type->setCurrentText(map->type);
  191. ui->comboBox_BattleScene->addItems(project->getBattleScenes());
  192. ui->comboBox_BattleScene->setCurrentText(map->battle_scene);
  193. ui->checkBox_ShowLocation->setChecked(map->show_location.toInt() > 0 || map->show_location == "TRUE");
  194. }
  195. void MainWindow::on_comboBox_Song_activated(const QString &song)
  196. {
  197. if (editor && editor->map) {
  198. editor->map->song = song;
  199. }
  200. }
  201. void MainWindow::on_comboBox_Location_activated(const QString &location)
  202. {
  203. if (editor && editor->map) {
  204. editor->map->location = location;
  205. }
  206. }
  207. void MainWindow::on_comboBox_Visibility_activated(const QString &visibility)
  208. {
  209. if (editor && editor->map) {
  210. editor->map->visibility = visibility;
  211. }
  212. }
  213. void MainWindow::on_comboBox_Weather_activated(const QString &weather)
  214. {
  215. if (editor && editor->map) {
  216. editor->map->weather = weather;
  217. }
  218. }
  219. void MainWindow::on_comboBox_Type_activated(const QString &type)
  220. {
  221. if (editor && editor->map) {
  222. editor->map->type = type;
  223. }
  224. }
  225. void MainWindow::on_comboBox_BattleScene_activated(const QString &battle_scene)
  226. {
  227. if (editor && editor->map) {
  228. editor->map->battle_scene = battle_scene;
  229. }
  230. }
  231. void MainWindow::on_checkBox_ShowLocation_clicked(bool checked)
  232. {
  233. if (editor && editor->map) {
  234. if (checked) {
  235. editor->map->show_location = "TRUE";
  236. } else {
  237. editor->map->show_location = "FALSE";
  238. }
  239. }
  240. }
  241. void MainWindow::populateMapList() {
  242. Project *project = editor->project;
  243. QIcon mapFolderIcon;
  244. mapFolderIcon.addFile(QStringLiteral(":/icons/folder_closed_map.ico"), QSize(), QIcon::Normal, QIcon::Off);
  245. mapFolderIcon.addFile(QStringLiteral(":/icons/folder_map.ico"), QSize(), QIcon::Normal, QIcon::On);
  246. QIcon folderIcon;
  247. folderIcon.addFile(QStringLiteral(":/icons/folder_closed.ico"), QSize(), QIcon::Normal, QIcon::Off);
  248. QIcon mapIcon;
  249. mapIcon.addFile(QStringLiteral(":/icons/map.ico"), QSize(), QIcon::Normal, QIcon::Off);
  250. mapIcon.addFile(QStringLiteral(":/icons/image.ico"), QSize(), QIcon::Normal, QIcon::On);
  251. mapListModel = new QStandardItemModel;
  252. QStandardItem *entry = new QStandardItem;
  253. entry->setText(project->getProjectTitle());
  254. entry->setIcon(folderIcon);
  255. entry->setEditable(false);
  256. mapListModel->appendRow(entry);
  257. QStandardItem *maps = new QStandardItem;
  258. maps->setText("maps");
  259. maps->setIcon(folderIcon);
  260. maps->setEditable(false);
  261. entry->appendRow(maps);
  262. project->readMapGroups();
  263. for (int i = 0; i < project->groupNames->length(); i++) {
  264. QString group_name = project->groupNames->value(i);
  265. QStandardItem *group = new QStandardItem;
  266. group->setText(group_name);
  267. group->setIcon(mapFolderIcon);
  268. group->setEditable(false);
  269. group->setData(group_name, Qt::UserRole);
  270. group->setData("map_group", MapListUserRoles::TypeRole);
  271. maps->appendRow(group);
  272. QStringList *names = project->groupedMapNames->value(i);
  273. for (int j = 0; j < names->length(); j++) {
  274. QString map_name = names->value(j);
  275. QStandardItem *map = new QStandardItem;
  276. map->setText(QString("[%1.%2] ").arg(i).arg(j, 2, 10, QLatin1Char('0')) + map_name);
  277. map->setIcon(mapIcon);
  278. map->setEditable(false);
  279. map->setData(map_name, Qt::UserRole);
  280. map->setData("map_name", MapListUserRoles::TypeRole);
  281. group->appendRow(map);
  282. }
  283. }
  284. // Right-clicking on items in the map list tree view brings up a context menu.
  285. ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu);
  286. connect(ui->mapList, SIGNAL(customContextMenuRequested(const QPoint &)),
  287. this, SLOT(onOpenMapListContextMenu(const QPoint &)));
  288. ui->mapList->setModel(mapListModel);
  289. ui->mapList->setUpdatesEnabled(true);
  290. ui->mapList->expandToDepth(2);
  291. ui->mapList->repaint();
  292. }
  293. void MainWindow::onOpenMapListContextMenu(const QPoint &point)
  294. {
  295. QModelIndex index = ui->mapList->indexAt(point);
  296. if (!index.isValid()) {
  297. return;
  298. }
  299. QStandardItem *selectedItem = mapListModel->itemFromIndex(index);
  300. QVariant itemType = selectedItem->data(MapListUserRoles::TypeRole);
  301. if (!itemType.isValid()) {
  302. return;
  303. }
  304. // Build custom context menu depending on which type of item was selected (map group, map name, etc.)
  305. if (itemType == "map_group") {
  306. QString groupName = selectedItem->data(Qt::UserRole).toString();
  307. QMenu* menu = new QMenu();
  308. QActionGroup* actions = new QActionGroup(menu);
  309. actions->addAction(menu->addAction("Add New Map to Group"))->setData(groupName);
  310. connect(actions, SIGNAL(triggered(QAction*)), this, SLOT(addNewMapToGroup(QAction*)));
  311. menu->exec(QCursor::pos());
  312. }
  313. }
  314. void MainWindow::addNewMapToGroup(QAction* triggeredAction)
  315. {
  316. QString groupName = triggeredAction->data().toString();
  317. qDebug() << "Adding new map " << groupName;
  318. }
  319. void MainWindow::on_mapList_activated(const QModelIndex &index)
  320. {
  321. QVariant data = index.data(Qt::UserRole);
  322. if (!data.isNull()) {
  323. setMap(data.toString());
  324. }
  325. //updateMapList();
  326. }
  327. void MainWindow::markAllEdited(QAbstractItemModel *model) {
  328. QList<QModelIndex> list;
  329. list.append(QModelIndex());
  330. while (list.length()) {
  331. QModelIndex parent = list.takeFirst();
  332. for (int i = 0; i < model->rowCount(parent); i++) {
  333. QModelIndex index = model->index(i, 0, parent);
  334. if (model->hasChildren(index)) {
  335. list.append(index);
  336. }
  337. markEdited(index);
  338. }
  339. }
  340. }
  341. void MainWindow::markEdited(QModelIndex index) {
  342. QVariant data = index.data(Qt::UserRole);
  343. if (!data.isNull()) {
  344. QString map_name = data.toString();
  345. if (editor->project) {
  346. if (editor->project->map_cache->contains(map_name)) {
  347. // Just mark anything that's been opened for now.
  348. // TODO if (project->getMap()->saved)
  349. //ui->mapList->setExpanded(index, true);
  350. ui->mapList->setExpanded(index, editor->project->map_cache->value(map_name)->hasUnsavedChanges());
  351. }
  352. }
  353. }
  354. }
  355. void MainWindow::updateMapList() {
  356. QAbstractItemModel *model = ui->mapList->model();
  357. markAllEdited(model);
  358. }
  359. void MainWindow::on_action_Save_Project_triggered()
  360. {
  361. editor->saveProject();
  362. updateMapList();
  363. }
  364. void MainWindow::undo() {
  365. editor->undo();
  366. }
  367. void MainWindow::redo() {
  368. editor->redo();
  369. }
  370. void MainWindow::on_action_Save_triggered() {
  371. editor->save();
  372. updateMapList();
  373. }
  374. void MainWindow::on_tabWidget_2_currentChanged(int index)
  375. {
  376. if (index == 0) {
  377. editor->setEditingMap();
  378. } else if (index == 1) {
  379. editor->setEditingCollision();
  380. }
  381. }
  382. void MainWindow::on_action_Exit_triggered()
  383. {
  384. QApplication::quit();
  385. }
  386. void MainWindow::on_tabWidget_currentChanged(int index)
  387. {
  388. if (index == 0) {
  389. on_tabWidget_2_currentChanged(ui->tabWidget_2->currentIndex());
  390. } else if (index == 1) {
  391. editor->setEditingObjects();
  392. }
  393. }
  394. void MainWindow::on_actionUndo_triggered()
  395. {
  396. undo();
  397. }
  398. void MainWindow::on_actionRedo_triggered()
  399. {
  400. redo();
  401. }
  402. void MainWindow::on_toolButton_newObject_clicked()
  403. {
  404. if (editor) {
  405. DraggablePixmapItem *object = editor->addNewEvent();
  406. if (object) {
  407. //if (editor->selected_events->length()) {
  408. editor->selectMapObject(object, true);
  409. //}
  410. }
  411. updateSelectedObjects();
  412. }
  413. }
  414. // Should probably just pass layout and let the editor work it out
  415. void MainWindow::updateSelectedObjects() {
  416. QList<DraggablePixmapItem *> *all_events = editor->getObjects();
  417. QList<DraggablePixmapItem *> *events = all_events;
  418. if (editor->selected_events && editor->selected_events->length()) {
  419. events = editor->selected_events;
  420. }
  421. QMap<QString, int> map_obj_gfx_constants = editor->project->getMapObjGfxConstants();
  422. QList<ObjectPropertiesFrame *> frames;
  423. for (DraggablePixmapItem *item : *events) {
  424. ObjectPropertiesFrame *frame = new ObjectPropertiesFrame;
  425. // frame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  426. QSpinBox *x = frame->ui->spinBox_x;
  427. QSpinBox *y = frame->ui->spinBox_y;
  428. QSpinBox *z = frame->ui->spinBox_z;
  429. x->setValue(item->event->x());
  430. connect(x, SIGNAL(valueChanged(QString)), item, SLOT(set_x(QString)));
  431. connect(item, SIGNAL(xChanged(int)), x, SLOT(setValue(int)));
  432. y->setValue(item->event->y());
  433. connect(y, SIGNAL(valueChanged(QString)), item, SLOT(set_y(QString)));
  434. connect(item, SIGNAL(yChanged(int)), y, SLOT(setValue(int)));
  435. z->setValue(item->event->elevation());
  436. connect(z, SIGNAL(valueChanged(QString)), item, SLOT(set_elevation(QString)));
  437. connect(item, SIGNAL(elevationChanged(int)), z, SLOT(setValue(int)));
  438. QFont font;
  439. font.setCapitalization(QFont::Capitalize);
  440. frame->ui->label_name->setFont(font);
  441. QString event_type = item->event->get("event_type");
  442. QString map_name = item->event->get("map_name");
  443. frame->ui->label_name->setText(
  444. QString("%1 %2 %3")
  445. .arg(map_name)
  446. .arg(event_type)
  447. .arg(editor->project->getMap(map_name)->events.value(event_type).indexOf(item->event) + 1)
  448. );
  449. frame->ui->label_spritePixmap->setPixmap(item->event->pixmap);
  450. connect(item, SIGNAL(spriteChanged(QPixmap)), frame->ui->label_spritePixmap, SLOT(setPixmap(QPixmap)));
  451. frame->ui->sprite->setVisible(false);
  452. QMap<QString, QString> field_labels;
  453. field_labels["script_label"] = "Script";
  454. field_labels["event_flag"] = "Event Flag";
  455. field_labels["replacement"] = "Replacement";
  456. field_labels["behavior"] = "Behavior";
  457. field_labels["radius_x"] = "Movement Radius X";
  458. field_labels["radius_y"] = "Movement Radius Y";
  459. field_labels["property"] = "Property";
  460. field_labels["sight_radius"] = "Sight Radius";
  461. field_labels["destination_warp"] = "Destination Warp";
  462. field_labels["destination_map_name"] = "Destination Map";
  463. field_labels["coord_unknown1"] = "Unknown 1";
  464. field_labels["coord_unknown2"] = "Unknown 2";
  465. field_labels["type"] = "Type";
  466. field_labels["item"] = "Item";
  467. field_labels["item_unknown5"] = "Unknown 5";
  468. field_labels["item_unknown6"] = "Unknown 6";
  469. field_labels["weather"] = "Weather";
  470. field_labels["flag"] = "Flag";
  471. field_labels["secret_base_map"] = "Secret Base Map";
  472. QStringList fields;
  473. if (event_type == "object") {
  474. frame->ui->sprite->setVisible(true);
  475. frame->ui->comboBox_sprite->addItems(map_obj_gfx_constants.keys());
  476. frame->ui->comboBox_sprite->setCurrentText(item->event->get("sprite"));
  477. connect(frame->ui->comboBox_sprite, SIGNAL(activated(QString)), item, SLOT(set_sprite(QString)));
  478. /*
  479. frame->ui->script->setVisible(true);
  480. frame->ui->comboBox_script->addItem(item->event->get("script_label"));
  481. frame->ui->comboBox_script->setCurrentText(item->event->get("script_label"));
  482. //item->bind(frame->ui->comboBox_script, "script_label");
  483. connect(frame->ui->comboBox_script, SIGNAL(activated(QString)), item, SLOT(set_script(QString)));
  484. //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); });
  485. //connect(item, SIGNAL(scriptChanged(QString)), frame->ui->comboBox_script, SLOT(setValue(QString)));
  486. */
  487. fields << "behavior";
  488. fields << "radius_x";
  489. fields << "radius_y";
  490. fields << "script_label";
  491. fields << "event_flag";
  492. fields << "replacement";
  493. fields << "property";
  494. fields << "sight_radius";
  495. }
  496. else if (event_type == "warp") {
  497. fields << "destination_warp";
  498. fields << "destination_map_name";
  499. }
  500. else if (event_type == "trap") {
  501. fields << "script_label";
  502. fields << "coord_unknown1";
  503. fields << "coord_unknown2";
  504. }
  505. else if (event_type == "trap_weather") {
  506. fields << "weather";
  507. }
  508. else if (event_type == "sign") {
  509. fields << "type";
  510. fields << "script_label";
  511. }
  512. else if (event_type == "event_hidden_item") {
  513. fields << "item";
  514. fields << "flag";
  515. }
  516. else if (event_type == "event_secret_base") {
  517. fields << "secret_base_map";
  518. }
  519. for (QString key : fields) {
  520. QWidget *widget = new QWidget(frame);
  521. QFormLayout *fl = new QFormLayout(widget);
  522. fl->setContentsMargins(9, 0, 9, 0);
  523. QComboBox *combo = new QComboBox(widget);
  524. combo->setEditable(true);
  525. QString value = item->event->get(key);
  526. if (key == "destination_map_name") {
  527. if (!editor->project->mapNames->contains(value)) {
  528. combo->addItem(value);
  529. }
  530. combo->addItems(*editor->project->mapNames);
  531. } else {
  532. combo->addItem(value);
  533. }
  534. combo->setCurrentText(value);
  535. fl->addRow(new QLabel(field_labels[key], widget), combo);
  536. widget->setLayout(fl);
  537. frame->layout()->addWidget(widget);
  538. item->bind(combo, key);
  539. }
  540. frames.append(frame);
  541. }
  542. //int scroll = ui->scrollArea_4->verticalScrollBar()->value();
  543. QWidget *target = ui->scrollAreaWidgetContents;
  544. if (target->children().length()) {
  545. qDeleteAll(target->children());
  546. }
  547. QVBoxLayout *layout = new QVBoxLayout(target);
  548. target->setLayout(layout);
  549. ui->scrollArea_4->setWidgetResizable(true);
  550. ui->scrollArea_4->setWidget(target);
  551. for (ObjectPropertiesFrame *frame : frames) {
  552. layout->addWidget(frame);
  553. }
  554. layout->addStretch(1);
  555. // doesn't work
  556. //QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  557. //ui->scrollArea_4->ensureVisible(0, scroll);
  558. }
  559. void MainWindow::on_toolButton_deleteObject_clicked()
  560. {
  561. if (editor && editor->selected_events) {
  562. if (editor->selected_events->length()) {
  563. for (DraggablePixmapItem *item : *editor->selected_events) {
  564. editor->deleteEvent(item->event);
  565. if (editor->scene->items().contains(item)) {
  566. editor->scene->removeItem(item);
  567. }
  568. editor->selected_events->removeOne(item);
  569. }
  570. updateSelectedObjects();
  571. }
  572. }
  573. }
  574. void MainWindow::on_toolButton_Paint_clicked()
  575. {
  576. editor->map_edit_mode = "paint";
  577. checkToolButtons();
  578. }
  579. void MainWindow::on_toolButton_Select_clicked()
  580. {
  581. editor->map_edit_mode = "select";
  582. checkToolButtons();
  583. }
  584. void MainWindow::on_toolButton_Fill_clicked()
  585. {
  586. editor->map_edit_mode = "fill";
  587. checkToolButtons();
  588. }
  589. void MainWindow::on_toolButton_Dropper_clicked()
  590. {
  591. editor->map_edit_mode = "pick";
  592. checkToolButtons();
  593. }
  594. void MainWindow::checkToolButtons() {
  595. ui->toolButton_Paint->setChecked(editor->map_edit_mode == "paint");
  596. ui->toolButton_Select->setChecked(editor->map_edit_mode == "select");
  597. ui->toolButton_Fill->setChecked(editor->map_edit_mode == "fill");
  598. ui->toolButton_Dropper->setChecked(editor->map_edit_mode == "pick");
  599. }
  600. void MainWindow::onMapChanged(Map *map) {
  601. updateMapList();
  602. }