fix new map popup window to allow layout selection

This commit is contained in:
garak 2023-02-08 17:08:42 -05:00
parent f8c7ada585
commit a4fdb0de64
5 changed files with 234 additions and 86 deletions

View file

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>410</width>
<height>621</height>
<height>687</height>
</rect>
</property>
<property name="windowTitle">
@ -73,14 +73,14 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_NewMap_Width">
<property name="text">
<string>Map Width</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="1">
<widget class="QSpinBox" name="spinBox_NewMap_Width">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Width (in blocks) of the new map.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -90,14 +90,14 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_NewMap_Height">
<property name="text">
<string>Map Height</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="5" column="1">
<widget class="QSpinBox" name="spinBox_NewMap_Height">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Height (in blocks) of the new map.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -107,14 +107,14 @@
</property>
</widget>
</item>
<item row="4" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_NewMap_BorderWidth">
<property name="text">
<string>Border Width</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="6" column="1">
<widget class="QSpinBox" name="spinBox_NewMap_BorderWidth">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Width (in blocks) of the new map's border.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -124,14 +124,14 @@
</property>
</widget>
</item>
<item row="5" column="0">
<item row="7" column="0">
<widget class="QLabel" name="label_NewMap_BorderHeight">
<property name="text">
<string>Border Height</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="7" column="1">
<widget class="QSpinBox" name="spinBox_NewMap_BorderHeight">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Height (in blocks) of the new map's border.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -141,14 +141,14 @@
</property>
</widget>
</item>
<item row="6" column="0">
<item row="8" column="0">
<widget class="QLabel" name="label_NewMap_Primary_Tileset">
<property name="text">
<string>Primary Tileset</string>
</property>
</widget>
</item>
<item row="6" column="1">
<item row="8" column="1">
<widget class="NoScrollComboBox" name="comboBox_NewMap_Primary_Tileset">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The primary tileset for the new map.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -158,14 +158,14 @@
</property>
</widget>
</item>
<item row="7" column="0">
<item row="9" column="0">
<widget class="QLabel" name="label_NewMap_Secondary_Tileset">
<property name="text">
<string>Secondary Tileset</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="9" column="1">
<widget class="NoScrollComboBox" name="comboBox_NewMap_Secondary_Tileset">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The secondary tileset for the new map.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -175,14 +175,14 @@
</property>
</widget>
</item>
<item row="8" column="0">
<item row="10" column="0">
<widget class="QLabel" name="label_NewMap_Type">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="8" column="1">
<item row="10" column="1">
<widget class="NoScrollComboBox" name="comboBox_NewMap_Type">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The map type is a general attribute, which is used for many different things. For example. it determines whether biking or running is allowed.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -192,14 +192,14 @@
</property>
</widget>
</item>
<item row="9" column="0">
<item row="11" column="0">
<widget class="QLabel" name="label_NewMap_Location">
<property name="text">
<string>Location</string>
</property>
</widget>
</item>
<item row="9" column="1">
<item row="11" column="1">
<widget class="NoScrollComboBox" name="comboBox_NewMap_Location">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The section of the region map which the map is grouped under. This also determines the name of the map that is displayed when the player enters it.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -209,14 +209,14 @@
</property>
</widget>
</item>
<item row="10" column="0">
<item row="12" column="0">
<widget class="QLabel" name="label_Song">
<property name="text">
<string>Song</string>
</property>
</widget>
</item>
<item row="10" column="1">
<item row="12" column="1">
<widget class="NoScrollComboBox" name="comboBox_NewMap_Song">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The default background music for this map.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -226,14 +226,14 @@
</property>
</widget>
</item>
<item row="11" column="0">
<item row="13" column="0">
<widget class="QLabel" name="label_NewMap_Flyable">
<property name="text">
<string>Can Fly To</string>
</property>
</widget>
</item>
<item row="11" column="1">
<item row="13" column="1">
<widget class="QCheckBox" name="checkBox_NewMap_Flyable">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Whether to add a heal location to the new map.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -243,14 +243,14 @@
</property>
</widget>
</item>
<item row="12" column="0">
<item row="14" column="0">
<widget class="QLabel" name="label_NewMap_Show_Location">
<property name="text">
<string>Show Location Name</string>
</property>
</widget>
</item>
<item row="12" column="1">
<item row="14" column="1">
<widget class="QCheckBox" name="checkBox_NewMap_Show_Location">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Whether or not to display the location name when the player enters the map.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -260,14 +260,14 @@
</property>
</widget>
</item>
<item row="13" column="0">
<item row="15" column="0">
<widget class="QLabel" name="label_NewMap_Allow_Running">
<property name="text">
<string>Allow Running</string>
</property>
</widget>
</item>
<item row="13" column="1">
<item row="15" column="1">
<widget class="QCheckBox" name="checkBox_NewMap_Allow_Running">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Allows the player to use Running Shoes&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -277,14 +277,14 @@
</property>
</widget>
</item>
<item row="14" column="0">
<item row="16" column="0">
<widget class="QLabel" name="label_NewMap_Allow_Biking">
<property name="text">
<string>Allow Biking</string>
</property>
</widget>
</item>
<item row="14" column="1">
<item row="16" column="1">
<widget class="QCheckBox" name="checkBox_NewMap_Allow_Biking">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Allows the player to use a Bike&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -294,14 +294,14 @@
</property>
</widget>
</item>
<item row="15" column="0">
<item row="17" column="0">
<widget class="QLabel" name="label_NewMap_Allow_Escape_Rope">
<property name="text">
<string>Allow Dig &amp; Escape Rope</string>
</property>
</widget>
</item>
<item row="15" column="1">
<item row="17" column="1">
<widget class="QCheckBox" name="checkBox_NewMap_Allow_Escape_Rope">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Allows the player to use Dig or Escape Rope&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -311,14 +311,14 @@
</property>
</widget>
</item>
<item row="16" column="0">
<item row="18" column="0">
<widget class="QLabel" name="label_NewMap_Floor_Number">
<property name="text">
<string>Floor Number</string>
</property>
</widget>
</item>
<item row="16" column="1">
<item row="18" column="1">
<widget class="QSpinBox" name="spinBox_NewMap_Floor_Number">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Floor number to be used for maps with elevators.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
@ -328,6 +328,96 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="NoScrollComboBox" name="comboBox_Layout">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Layout</string>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Use Existing Layout</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_UseExistingLayout">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
@ -396,7 +486,7 @@
<x>0</x>
<y>0</y>
<width>410</width>
<height>21</height>
<height>22</height>
</rect>
</property>
</widget>

View file

@ -23,6 +23,7 @@ public:
bool importedMap;
QString layoutId;
void init();
void initUi();
void init(MapSortOrder type, QVariant data);
void init(Layout *);
static void setDefaultSettings(Project *project);
@ -60,6 +61,8 @@ private:
static struct Settings settings;
private slots:
void on_checkBox_UseExistingLayout_stateChanged(int state);
void on_comboBox_Layout_currentTextChanged(const QString &text);
void on_pushButton_NewMap_Accept_clicked();
void on_lineEdit_NewMap_Name_textChanged(const QString &);
};

View file

@ -1153,68 +1153,79 @@ void MainWindow::sortMapList() {
}
void MainWindow::onOpenMapListContextMenu(const QPoint &point) {
/// !TODO
// QModelIndex index = mapListProxyModel->mapToSource(ui->mapList->indexAt(point));
// if (!index.isValid()) {
// return;
// }
QStandardItemModel *model;
int dataRole;
FilterChildrenProxyModel *proxy;
QTreeView *list;
void (MainWindow::*addFunction)(QAction *);
QString actionText;
switch (ui->mapListContainer->currentIndex()) {
//
case MapListTab::Groups:
switch (this->mapSortOrder) {
case MapSortOrder::SortByGroup:
model = this->mapGroupModel;
dataRole = MapListRoles::GroupRole;
proxy = this->groupListProxyModel;
list = this->ui->mapList;
addFunction = &MainWindow::onAddNewMapToGroupClick;
actionText = "Add New Map to Group";
break;
case MapListTab::Areas:
case MapSortOrder::SortByArea:
model = this->mapAreaModel;
dataRole = Qt::UserRole;
proxy = this->areaListProxyModel;
list = this->ui->areaList;
addFunction = &MainWindow::onAddNewMapToAreaClick;
actionText = "Add New Map to Area";
break;
case MapListTab::Layouts:
case MapSortOrder::SortByLayout:
model = this->layoutTreeModel;
dataRole = Qt::UserRole;
proxy = this->layoutListProxyModel;
list = this->ui->layoutList;
addFunction = &MainWindow::onAddNewMapToLayoutClick;
actionText = "Add New Map with Layout";
break;
}
// QStandardItem *selectedItem = mapListModel->itemFromIndex(index);
// QVariant itemType = selectedItem->data(MapListUserRoles::TypeRole);
// if (!itemType.isValid()) {
// return;
// }
QModelIndex index = proxy->mapToSource(list->indexAt(point));
if (!index.isValid()) {
return;
}
// // Build custom context menu depending on which type of item was selected (map group, map name, etc.)
// if (itemType == "map_group") {
// QString groupName = selectedItem->data(Qt::UserRole).toString();
// int groupNum = selectedItem->data(MapListUserRoles::GroupRole).toInt();
// QMenu* menu = new QMenu(this);
// QActionGroup* actions = new QActionGroup(menu);
// actions->addAction(menu->addAction("Add New Map to Group"))->setData(groupNum);
// connect(actions, &QActionGroup::triggered, this, &MainWindow::onAddNewMapToGroupClick);
// menu->exec(QCursor::pos());
// } else if (itemType == "map_sec") {
// QString secName = selectedItem->data(Qt::UserRole).toString();
// QMenu* menu = new QMenu(this);
// QActionGroup* actions = new QActionGroup(menu);
// actions->addAction(menu->addAction("Add New Map to Area"))->setData(secName);
// connect(actions, &QActionGroup::triggered, this, &MainWindow::onAddNewMapToAreaClick);
// menu->exec(QCursor::pos());
// } else if (itemType == "map_layout") {
// QString layoutId = selectedItem->data(MapListUserRoles::TypeRole2).toString();
// QMenu* menu = new QMenu(this);
// QActionGroup* actions = new QActionGroup(menu);
// actions->addAction(menu->addAction("Add New Map with Layout"))->setData(layoutId);
// connect(actions, &QActionGroup::triggered, this, &MainWindow::onAddNewMapToLayoutClick);
// menu->exec(QCursor::pos());
// }
QStandardItem *selectedItem = model->itemFromIndex(index);
if (selectedItem->parent()) {
return;
}
QVariant itemData = selectedItem->data(dataRole);
if (!itemData.isValid()) {
return;
}
QMenu menu(this);
QActionGroup actions(&menu);
actions.addAction(menu.addAction(actionText))->setData(itemData);
(this->*addFunction)(menu.exec(QCursor::pos()));
}
void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction)
{
void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction) {
if (!triggeredAction) return;
openNewMapPopupWindow();
this->newMapPrompt->init(MapSortOrder::SortByGroup, triggeredAction->data());
}
void MainWindow::onAddNewMapToAreaClick(QAction* triggeredAction)
{
void MainWindow::onAddNewMapToAreaClick(QAction* triggeredAction) {
if (!triggeredAction) return;
openNewMapPopupWindow();
this->newMapPrompt->init(MapSortOrder::SortByArea, triggeredAction->data());
}
void MainWindow::onAddNewMapToLayoutClick(QAction* triggeredAction)
{
void MainWindow::onAddNewMapToLayoutClick(QAction* triggeredAction) {
if (!triggeredAction) return;
openNewMapPopupWindow();
this->newMapPrompt->init(MapSortOrder::SortByLayout, triggeredAction->data());
}

View file

@ -29,6 +29,7 @@ QStandardItem *MapGroupModel::createMapItem(QString mapName, int groupIndex, int
map->setEditable(false);
map->setData(mapName, Qt::UserRole);
map->setData("map_name", MapListRoles::TypeRole);
map->setData(groupIndex, MapListRoles::GroupRole);
// map->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
this->mapItems.insert(mapName, map);
return map;

View file

@ -26,7 +26,7 @@ NewMapPopup::~NewMapPopup()
delete ui;
}
void NewMapPopup::init() {
void NewMapPopup::initUi() {
// Populate combo boxes
ui->comboBox_NewMap_Primary_Tileset->addItems(project->primaryTilesetLabels);
ui->comboBox_NewMap_Secondary_Tileset->addItems(project->secondaryTilesetLabels);
@ -35,6 +35,10 @@ void NewMapPopup::init() {
ui->comboBox_NewMap_Type->addItems(project->mapTypes);
ui->comboBox_NewMap_Location->addItems(project->mapSectionValueToName.values());
const QSignalBlocker b(ui->comboBox_Layout);
ui->comboBox_Layout->addItems(project->mapLayoutsTable);
this->layoutId = project->mapLayoutsTable.first();
// Set spin box limits
ui->spinBox_NewMap_Width->setMinimum(1);
ui->spinBox_NewMap_Height->setMinimum(1);
@ -66,6 +70,10 @@ void NewMapPopup::init() {
ui->spinBox_NewMap_Floor_Number->setVisible(hasFloorNumber);
ui->label_NewMap_Floor_Number->setVisible(hasFloorNumber);
this->updateGeometry();
}
void NewMapPopup::init() {
// Restore previous settings
ui->lineEdit_NewMap_Name->setText(project->getNewMapName());
ui->comboBox_NewMap_Group->setTextItem(settings.group);
@ -86,6 +94,7 @@ void NewMapPopup::init() {
ui->spinBox_NewMap_Floor_Number->setValue(settings.floorNumber);
// Connect signals
// !TODO: make sure this doesnt reconnect a million times
connect(ui->spinBox_NewMap_Width, QOverload<int>::of(&QSpinBox::valueChanged), [=](int){checkNewMapDimensions();});
connect(ui->spinBox_NewMap_Height, QOverload<int>::of(&QSpinBox::valueChanged), [=](int){checkNewMapDimensions();});
@ -94,6 +103,7 @@ void NewMapPopup::init() {
// Creating new map by right-clicking in the map list
void NewMapPopup::init(MapSortOrder type, QVariant data) {
initUi();
switch (type)
{
case MapSortOrder::SortByGroup:
@ -103,6 +113,7 @@ void NewMapPopup::init(MapSortOrder type, QVariant data) {
settings.location = data.toString();
break;
case MapSortOrder::SortByLayout:
this->ui->checkBox_UseExistingLayout->setCheckState(Qt::Checked);
useLayout(data.toString());
break;
}
@ -205,26 +216,58 @@ void NewMapPopup::saveSettings() {
void NewMapPopup::useLayoutSettings(Layout *layout) {
if (!layout) return;
settings.width = layout->width;
ui->spinBox_NewMap_Width->setValue(layout->width);
settings.height = layout->height;
ui->spinBox_NewMap_Height->setValue(layout->height);
settings.borderWidth = layout->border_width;
ui->spinBox_NewMap_BorderWidth->setValue(layout->border_width);
settings.borderHeight = layout->border_height;
ui->spinBox_NewMap_BorderWidth->setValue(layout->border_height);
settings.primaryTilesetLabel = layout->tileset_primary_label;
ui->comboBox_NewMap_Primary_Tileset->setCurrentIndex(ui->comboBox_NewMap_Primary_Tileset->findText(layout->tileset_primary_label));
settings.secondaryTilesetLabel = layout->tileset_secondary_label;
ui->comboBox_NewMap_Secondary_Tileset->setCurrentIndex(ui->comboBox_NewMap_Secondary_Tileset->findText(layout->tileset_secondary_label));
}
void NewMapPopup::useLayout(QString layoutId) {
this->existingLayout = true;
this->layoutId = layoutId;
useLayoutSettings(project->mapLayouts.value(this->layoutId));
// Dimensions and tilesets can't be changed for new maps using an existing layout
ui->spinBox_NewMap_Width->setDisabled(true);
ui->spinBox_NewMap_Height->setDisabled(true);
ui->spinBox_NewMap_BorderWidth->setDisabled(true);
ui->spinBox_NewMap_BorderHeight->setDisabled(true);
ui->comboBox_NewMap_Primary_Tileset->setDisabled(true);
ui->comboBox_NewMap_Secondary_Tileset->setDisabled(true);
this->ui->comboBox_Layout->setCurrentIndex(this->ui->comboBox_Layout->findText(layoutId));
useLayoutSettings(project->mapLayouts.value(this->layoutId));
}
void NewMapPopup::on_checkBox_UseExistingLayout_stateChanged(int state) {
bool layoutEditsEnabled = (state == Qt::Unchecked);
this->ui->comboBox_Layout->setEnabled(!layoutEditsEnabled);
this->ui->spinBox_NewMap_Width->setEnabled(layoutEditsEnabled);
this->ui->spinBox_NewMap_Height->setEnabled(layoutEditsEnabled);
this->ui->spinBox_NewMap_BorderWidth->setEnabled(layoutEditsEnabled);
this->ui->spinBox_NewMap_BorderWidth->setEnabled(layoutEditsEnabled);
this->ui->comboBox_NewMap_Primary_Tileset->setEnabled(layoutEditsEnabled);
this->ui->comboBox_NewMap_Secondary_Tileset->setEnabled(layoutEditsEnabled);
if (!layoutEditsEnabled) {
useLayout(this->layoutId);//this->ui->comboBox_Layout->currentText());
} else {
this->existingLayout = false;
}
}
void NewMapPopup::on_comboBox_Layout_currentTextChanged(const QString &text) {
if (this->project->mapLayoutsTable.contains(text)) {
useLayout(text);
}
}
void NewMapPopup::on_lineEdit_NewMap_Name_textChanged(const QString &text) {