Tabs working

This commit is contained in:
Diegoisawesome 2018-11-27 19:39:57 -06:00
parent 4550f80dc4
commit f0b74ada93
3 changed files with 287 additions and 156 deletions

View file

@ -1340,6 +1340,16 @@
<property name="bottomMargin">
<number>3</number>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label_NoEvents">
<property name="text">
<string>There are no events on the current map.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QFrame" name="frame_4">
<property name="maximumSize">
@ -1457,13 +1467,13 @@
<item row="2" column="0">
<widget class="QTabWidget" name="tabWidget_EventType">
<property name="currentIndex">
<number>4</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab_Objects">
<attribute name="title">
<string>Objects</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_21">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
@ -1476,41 +1486,20 @@
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea_10">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<item>
<widget class="QScrollArea" name="scrollArea_Objects">
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="eventsObjects_ScrollAreaContents">
<widget class="QWidget" name="scrollAreaWidgetContents_Objects">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>432</width>
<height>584</height>
<height>565</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
</item>
@ -1520,7 +1509,7 @@
<attribute name="title">
<string>Warps</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_20">
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
@ -1533,41 +1522,20 @@
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea_9">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<item>
<widget class="QScrollArea" name="scrollArea_Warps">
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="eventsWarps_ScrollAreaContents">
<widget class="QWidget" name="scrollAreaWidgetContents_Warps">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>432</width>
<height>584</height>
<height>565</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
</item>
@ -1577,7 +1545,7 @@
<attribute name="title">
<string>Triggers</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_19">
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="leftMargin">
<number>0</number>
</property>
@ -1590,41 +1558,20 @@
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea_8">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<item>
<widget class="QScrollArea" name="scrollArea_Triggers">
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="eventsTriggers_ScrollAreaContents">
<widget class="QWidget" name="scrollAreaWidgetContents_Triggers">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>432</width>
<height>584</height>
<height>565</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
</item>
@ -1634,7 +1581,7 @@
<attribute name="title">
<string>BGs</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_18">
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="leftMargin">
<number>0</number>
</property>
@ -1647,40 +1594,55 @@
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea_7">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<item>
<widget class="QScrollArea" name="scrollArea_BGs">
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="eventsBGs_ScrollAreaContents">
<widget class="QWidget" name="scrollAreaWidgetContents_BGs">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>432</width>
<height>584</height>
<height>565</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_Healspots">
<attribute name="title">
<string>Healspots</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_9">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="scrollArea_Healspots">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_Healspots">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>432</width>
<height>565</height>
</rect>
</property>
</widget>
</widget>
@ -1691,7 +1653,7 @@
<attribute name="title">
<string>Multiple</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_15">
<layout class="QVBoxLayout" name="verticalLayout_8">
<property name="leftMargin">
<number>0</number>
</property>
@ -1704,27 +1666,12 @@
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QScrollArea" name="scrollArea_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<item>
<widget class="QScrollArea" name="scrollArea_Multiple">
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="eventsMultiple_ScrollAreaContents">
<widget class="QWidget" name="scrollAreaWidgetContents_Multiple">
<property name="geometry">
<rect>
<x>0</x>
@ -1733,12 +1680,6 @@
<height>565</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
</item>
@ -1746,16 +1687,6 @@
</widget>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_NoEvents">
<property name="text">
<string>There are no events on the current map.</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
@ -2646,6 +2577,11 @@
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>NoScrollComboBox</class>
<extends>QComboBox</extends>
<header>noscrollcombobox.h</header>
</customwidget>
<customwidget>
<class>GraphicsView</class>
<extends>QGraphicsView</extends>
@ -2656,11 +2592,6 @@
<extends>QToolButton</extends>
<header>neweventtoolbutton.h</header>
</customwidget>
<customwidget>
<class>NoScrollComboBox</class>
<extends>QComboBox</extends>
<header>noscrollcombobox.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../resources/images.qrc"/>

View file

@ -78,6 +78,7 @@ private slots:
void addNewEvent(QString);
void updateSelectedObjects();
void updateObjects();
void on_toolButton_Paint_clicked();
@ -133,6 +134,8 @@ private slots:
void on_lineEdit_filterBox_textChanged(const QString &arg1);
void eventTabChanged(int index);
private:
Ui::MainWindow *ui;
TilesetEditor *tilesetEditor = nullptr;
@ -144,6 +147,21 @@ private:
QIcon* mapIcon;
QIcon* mapEditedIcon;
QWidget *eventTabObjectWidget;
QWidget *eventTabWarpWidget;
QWidget *eventTabTriggerWidget;
QWidget *eventTabBGWidget;
QWidget *eventTabHealspotWidget;
QWidget *eventTabMultipleWidget;
DraggablePixmapItem *selectedObject;
DraggablePixmapItem *selectedWarp;
DraggablePixmapItem *selectedTrigger;
DraggablePixmapItem *selectedBG;
DraggablePixmapItem *selectedHealspot;
bool isProgrammaticEventTabChange;
enum MapSortOrder {
Group = 0,
Name = 1,

View file

@ -28,7 +28,13 @@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
ui(new Ui::MainWindow),
selectedObject(nullptr),
selectedWarp(nullptr),
selectedTrigger(nullptr),
selectedBG(nullptr),
selectedHealspot(nullptr),
isProgrammaticEventTabChange(false)
{
QCoreApplication::setOrganizationName("pret");
QCoreApplication::setApplicationName("porymap");
@ -67,11 +73,12 @@ void MainWindow::initCustomUI() {
void MainWindow::initExtraSignals() {
connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString)));
connect(ui->tabWidget_EventType, &QTabWidget::currentChanged, this, &MainWindow::eventTabChanged);
}
void MainWindow::initEditor() {
this->editor = new Editor(ui);
connect(this->editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects()));
connect(this->editor, SIGNAL(objectsChanged()), this, SLOT(updateObjects()));
connect(this->editor, SIGNAL(selectedObjectsChanged()), this, SLOT(updateSelectedObjects()));
connect(this->editor, SIGNAL(loadMapRequested(QString, QString)), this, SLOT(onLoadMapRequested(QString, QString)));
connect(this->editor, SIGNAL(tilesetChanged(QString)), this, SLOT(onTilesetChanged(QString)));
@ -97,6 +104,14 @@ void MainWindow::initMiscHeapObjects() {
mapListProxyModel->setSourceModel(mapListModel);
ui->mapList->setModel(mapListProxyModel);
eventTabObjectWidget = ui->tab_Objects;
eventTabWarpWidget = ui->tab_Warps;
eventTabTriggerWidget = ui->tab_Triggers;
eventTabBGWidget = ui->tab_BGs;
eventTabHealspotWidget = ui->tab_Healspots;
eventTabMultipleWidget = ui->tab_Multiple;
ui->tabWidget_EventType->clear();
}
void MainWindow::initMapSortOrder() {
@ -874,10 +889,73 @@ void MainWindow::addNewEvent(QString event_type)
if (object) {
editor->selectMapEvent(object, false);
}
updateSelectedObjects();
updateObjects();
}
}
void MainWindow::updateObjects() {
ui->tabWidget_EventType->clear();
selectedObject = nullptr;
selectedWarp = nullptr;
selectedTrigger = nullptr;
selectedBG = nullptr;
selectedHealspot = nullptr;
bool hasObjects = false;
bool hasWarps = false;
bool hasTriggers = false;
bool hasBGs = false;
bool hasHealspots = false;
for (DraggablePixmapItem *item : *editor->getObjects())
{
QString event_type = item->event->get("event_type");
if (event_type == EventType::Object) {
hasObjects = true;
}
else if (event_type == EventType::Warp) {
hasWarps = true;
}
else if (event_type == EventType::CoordScript || event_type == EventType::CoordWeather) {
hasTriggers = true;
}
else if (event_type == EventType::Sign || event_type == EventType::HiddenItem || event_type == EventType::SecretBase) {
hasBGs = true;
}
else if (event_type == EventType::HealLocation) {
hasHealspots = true;
}
}
if (hasObjects)
{
ui->tabWidget_EventType->addTab(eventTabObjectWidget, "Objects");
}
if (hasWarps)
{
ui->tabWidget_EventType->addTab(eventTabWarpWidget, "Warps");
}
if (hasTriggers)
{
ui->tabWidget_EventType->addTab(eventTabTriggerWidget, "Triggers");
}
if (hasBGs)
{
ui->tabWidget_EventType->addTab(eventTabBGWidget, "BGs");
}
if (hasHealspots)
{
ui->tabWidget_EventType->addTab(eventTabHealspotWidget, "Healspots");
}
updateSelectedObjects();
}
// Should probably just pass layout and let the editor work it out
void MainWindow::updateSelectedObjects() {
QList<DraggablePixmapItem *> *all_events = editor->getObjects();
@ -1116,33 +1194,37 @@ void MainWindow::updateSelectedObjects() {
//int scroll = ui->scrollArea_4->verticalScrollBar()->value();
QWidget *target = ui->eventsMultiple_ScrollAreaContents;
QWidget *target = ui->scrollAreaWidgetContents_Multiple;
if (events->length() == 1)
{
QString event_type = (*events)[0]->event->get("event_type");
isProgrammaticEventTabChange = true;
if (event_type == EventType::Object) {
target = ui->eventsObjects_ScrollAreaContents;
target = ui->scrollAreaWidgetContents_Objects;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Objects);
}
else if (event_type == EventType::Warp) {
target = ui->eventsWarps_ScrollAreaContents;
target = ui->scrollAreaWidgetContents_Warps;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Warps);
}
else if (event_type == EventType::CoordScript || event_type == EventType::CoordWeather) {
target = ui->eventsTriggers_ScrollAreaContents;
target = ui->scrollAreaWidgetContents_Triggers;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Triggers);
}
else if (event_type == EventType::Sign || event_type == EventType::HiddenItem || event_type == EventType::SecretBase) {
target = ui->eventsBGs_ScrollAreaContents;
target = ui->scrollAreaWidgetContents_BGs;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_BGs);
}
else if (event_type == EventType::HealLocation) {
target = ui->scrollAreaWidgetContents_Healspots;
ui->tabWidget_EventType->setCurrentWidget(ui->tab_Healspots);
}
ui->tabWidget_EventType->removeTab(ui->tabWidget_EventType->indexOf(ui->tab_Multiple));
if (target->children().length()) {
qDeleteAll(target->children());
}
isProgrammaticEventTabChange = false;
}
else if (events->length() > 1)
{
@ -1181,6 +1263,106 @@ void MainWindow::updateSelectedObjects() {
}
}
void MainWindow::eventTabChanged(int index)
{
if (!isProgrammaticEventTabChange && editor->map != nullptr)
{
QWidget *tab = ui->tabWidget_EventType->widget(index);
DraggablePixmapItem *selectedEvent = nullptr;
if (tab == eventTabObjectWidget)
{
if (selectedObject == nullptr)
{
for (DraggablePixmapItem *item : *editor->getObjects())
{
QString event_type = item->event->get("event_type");
if (event_type == EventType::Object)
{
selectedObject = item;
break;
}
}
}
selectedEvent = selectedObject;
}
else if (tab == eventTabWarpWidget)
{
if (selectedWarp == nullptr)
{
for (DraggablePixmapItem *item : *editor->getObjects())
{
QString event_type = item->event->get("event_type");
if (event_type == EventType::Warp)
{
selectedWarp = item;
break;
}
}
}
selectedEvent = selectedWarp;
}
else if (tab == eventTabTriggerWidget)
{
if (selectedTrigger == nullptr)
{
for (DraggablePixmapItem *item : *editor->getObjects())
{
QString event_type = item->event->get("event_type");
if (event_type == EventType::CoordScript || event_type == EventType::CoordWeather)
{
selectedTrigger = item;
break;
}
}
}
selectedEvent = selectedTrigger;
}
else if (tab == eventTabBGWidget)
{
if (selectedBG == nullptr)
{
for (DraggablePixmapItem *item : *editor->getObjects())
{
QString event_type = item->event->get("event_type");
if (event_type == EventType::Sign || event_type == EventType::HiddenItem || event_type == EventType::SecretBase)
{
selectedBG = item;
break;
}
}
}
selectedEvent = selectedBG;
}
else if (tab == eventTabHealspotWidget)
{
if (selectedHealspot == nullptr)
{
for (DraggablePixmapItem *item : *editor->getObjects())
{
QString event_type = item->event->get("event_type");
if (event_type == EventType::HealLocation)
{
selectedHealspot = item;
break;
}
}
}
selectedEvent = selectedHealspot;
}
if (selectedObject != nullptr)
editor->selectMapEvent(selectedEvent);
}
isProgrammaticEventTabChange = false;
}
void MainWindow::on_toolButton_deleteObject_clicked()
{
if (editor && editor->selected_events) {
@ -1197,7 +1379,7 @@ void MainWindow::on_toolButton_deleteObject_clicked()
qDebug() << "Cannot delete event of type " << item->event->get("event_type");
}
}
updateSelectedObjects();
updateObjects();
}
}
}