Skip to content

Commit

Permalink
Qt: Disable shared memcard settings outside of shared mode
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jan 8, 2025
1 parent 08a3c31 commit 7f974ea
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/core/gpu_sw_rasterizer.inl
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ ALWAYS_INLINE_RELEASE static void ShadePixel(const PixelVectors<texture_enable>&
color = RG_BAToRGB5A1(rg, ba);
}

if (!transparency_enable && preserve_mask.allfalse()) { StoreVector(start_x, y, color); return; }

GSVectorNi bg_color = LoadVector(start_x, y);

if constexpr (transparency_enable)
Expand Down
46 changes: 37 additions & 9 deletions src/duckstation-qt/memorycardsettingswidget.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]>
// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <[email protected]>
// SPDX-License-Identifier: CC-BY-NC-ND-4.0

#include "memorycardsettingswidget.h"
Expand All @@ -18,8 +18,14 @@
#include "fmt/format.h"

#include <QtCore/QUrl>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QVBoxLayout>

#include <functional>

static constexpr char MEMORY_CARD_IMAGE_FILTER[] =
QT_TRANSLATE_NOOP("MemoryCardSettingsWidget", "All Memory Card Types (*.mcd *.mcr *.mc)");
Expand All @@ -41,10 +47,11 @@ void MemoryCardSettingsWidget::createUi(SettingsWindow* dialog)
{
createPortSettingsUi(dialog, i, &m_port_ui[i]);
layout->addWidget(m_port_ui[i].container);
onMemoryCardTypeChanged(i);
}

{
QGroupBox* box = new QGroupBox(tr("Shared Settings"), this);
QGroupBox* box = new QGroupBox(tr("Game-Specific Card Settings"), this);
QVBoxLayout* box_layout = new QVBoxLayout(box);
QPushButton* browse = new QPushButton(tr("Browse..."), box);
QPushButton* open_memcards = new QPushButton(tr("Open..."), box);
Expand Down Expand Up @@ -118,6 +125,8 @@ void MemoryCardSettingsWidget::createPortSettingsUi(SettingsWindow* dialog, int
SettingWidgetBinder::BindWidgetToEnumSetting(m_dialog->getSettingsInterface(), ui->memory_card_type, "MemoryCards",
fmt::format("Card{}Type", index + 1), &Settings::ParseMemoryCardTypeName,
&Settings::GetMemoryCardTypeName, default_value);
connect(ui->memory_card_type, &QComboBox::currentIndexChanged, this,
std::bind(&MemoryCardSettingsWidget::onMemoryCardTypeChanged, this, index));
ui->layout->addWidget(new QLabel(tr("Memory Card Type:"), ui->container));
ui->layout->addWidget(ui->memory_card_type);

Expand All @@ -132,22 +141,41 @@ void MemoryCardSettingsWidget::createPortSettingsUi(SettingsWindow* dialog, int
}
memory_card_layout->addWidget(ui->memory_card_path);

QPushButton* memory_card_path_browse = new QPushButton(tr("Browse..."), ui->container);
connect(memory_card_path_browse, &QPushButton::clicked, this,
ui->memory_card_path_browse = new QPushButton(tr("Browse..."), ui->container);
connect(ui->memory_card_path_browse, &QPushButton::clicked, this,
[this, index]() { onBrowseMemoryCardPathClicked(index); });
memory_card_layout->addWidget(memory_card_path_browse);
memory_card_layout->addWidget(ui->memory_card_path_browse);

QPushButton* memory_card_path_reset = new QPushButton(tr("Reset"), ui->container);
connect(memory_card_path_reset, &QPushButton::clicked, this,
ui->memory_card_path_reset = new QPushButton(tr("Reset"), ui->container);
connect(ui->memory_card_path_reset, &QPushButton::clicked, this,
[this, index]() { onResetMemoryCardPathClicked(index); });
memory_card_layout->addWidget(memory_card_path_reset);
memory_card_layout->addWidget(ui->memory_card_path_reset);

ui->layout->addWidget(new QLabel(tr("Shared Memory Card Path:"), ui->container));
ui->memory_card_path_label = new QLabel(tr("Shared Memory Card Path:"), ui->container);
ui->layout->addWidget(ui->memory_card_path_label);
ui->layout->addLayout(memory_card_layout);

ui->layout->addStretch(1);
}

void MemoryCardSettingsWidget::onMemoryCardTypeChanged(int index)
{
const MemoryCardType default_type =
(index == 0) ? Settings::DEFAULT_MEMORY_CARD_1_TYPE : Settings::DEFAULT_MEMORY_CARD_2_TYPE;
const MemoryCardType type =
Settings::ParseMemoryCardTypeName(m_dialog
->getEffectiveStringValue("MemoryCards",
TinyString::from_format("Card{}Type", index + 1),
Settings::GetMemoryCardTypeName(default_type))
.c_str())
.value_or(default_type);
const bool shared_enabled = (type == MemoryCardType::Shared);
m_port_ui[index].memory_card_path_label->setEnabled(shared_enabled);
m_port_ui[index].memory_card_path->setEnabled(shared_enabled);
m_port_ui[index].memory_card_path_browse->setEnabled(shared_enabled);
m_port_ui[index].memory_card_path_reset->setEnabled(shared_enabled);
}

void MemoryCardSettingsWidget::onBrowseMemoryCardPathClicked(int index)
{
QString path = QDir::toNativeSeparators(QFileDialog::getOpenFileName(this, tr("Select path to memory card image"),
Expand Down
18 changes: 13 additions & 5 deletions src/duckstation-qt/memorycardsettingswidget.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]>
// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <[email protected]>
// SPDX-License-Identifier: CC-BY-NC-ND-4.0

#pragma once

#include "core/types.h"

#include <QtWidgets/QComboBox>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>

#include <array>
#include <vector>

class QLabel;
class QGroupBox;
class QVBoxLayout;
class QComboBox;
class QLineEdit;
class QPushButton;

class SettingsWindow;

class MemoryCardSettingsWidget : public QWidget
Expand All @@ -31,11 +35,15 @@ class MemoryCardSettingsWidget : public QWidget
QGroupBox* container;
QVBoxLayout* layout;
QComboBox* memory_card_type;
QLabel* memory_card_path_label;
QLineEdit* memory_card_path;
QPushButton* memory_card_path_browse;
QPushButton* memory_card_path_reset;
};

void createUi(SettingsWindow* dialog);
void createPortSettingsUi(SettingsWindow* dialog, int index, PortSettingsUI* ui);
void onMemoryCardTypeChanged(int index);
void onBrowseMemoryCardPathClicked(int index);
void onResetMemoryCardPathClicked(int index);
void onMemoryCardPathChanged(int index);
Expand Down

0 comments on commit 7f974ea

Please sign in to comment.