mirror of
https://github.com/PCSX2/pcsx2.git
synced 2025-12-16 04:08:48 +00:00
Qt: Show when a patch is applied on the Patches game properties page
This commit is contained in:
parent
1fb469373a
commit
1b06346e9e
@ -15,19 +15,23 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
GamePatchDetailsWidget::GamePatchDetailsWidget(std::string name, const std::string& author,
|
||||
const std::string& description, bool tristate, Qt::CheckState checkState, SettingsWindow* dialog, QWidget* parent)
|
||||
GamePatchDetailsWidget::GamePatchDetailsWidget(const Patch::PatchInfo& info, bool tristate, Qt::CheckState checkState, SettingsWindow* dialog, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_dialog(dialog)
|
||||
, m_name(name)
|
||||
, m_name(info.name)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
|
||||
m_ui.name->setText(QString::fromStdString(name));
|
||||
const QString name = QString::fromStdString(info.name);
|
||||
const QString author = !info.author.empty() ? QString::fromStdString(info.author) : tr("Unknown");
|
||||
const QString place = QString::fromUtf8(PlaceToString(info.place));
|
||||
const QString description = !info.description.empty() ? QString::fromStdString(info.description) : tr("No description provided.");
|
||||
m_ui.name->setText(name);
|
||||
m_ui.description->setText(
|
||||
tr("<strong>Author: </strong>%1<br>%2")
|
||||
.arg(author.empty() ? tr("Unknown") : QString::fromStdString(author))
|
||||
.arg(description.empty() ? tr("No description provided.") : QString::fromStdString(description)));
|
||||
tr("<strong>Author:</strong> %1<br><strong>Applied:</strong> %2<br>%3")
|
||||
.arg(author)
|
||||
.arg(place)
|
||||
.arg(description));
|
||||
|
||||
pxAssert(dialog->getSettingsInterface());
|
||||
m_ui.enabled->setTristate(tristate);
|
||||
@ -178,7 +182,7 @@ void GamePatchSettingsWidget::reloadList()
|
||||
}
|
||||
|
||||
GamePatchDetailsWidget* it =
|
||||
new GamePatchDetailsWidget(std::move(pi.name), pi.author, pi.description, globally_toggleable_option, check_state, dialog(), container);
|
||||
new GamePatchDetailsWidget(pi, globally_toggleable_option, check_state, dialog(), container);
|
||||
layout->addWidget(it);
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ class GamePatchDetailsWidget : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GamePatchDetailsWidget(std::string name, const std::string& author, const std::string& description, bool tristate, Qt::CheckState checkState,
|
||||
GamePatchDetailsWidget(const Patch::PatchInfo& info, bool tristate, Qt::CheckState checkState,
|
||||
SettingsWindow* dialog, QWidget* parent);
|
||||
~GamePatchDetailsWidget();
|
||||
|
||||
|
||||
@ -492,6 +492,10 @@ void Patch::ExtractPatchInfo(std::vector<PatchInfo>* dst, const std::string& pna
|
||||
std::istringstream ss(pnach_data);
|
||||
std::string line;
|
||||
PatchInfo current_patch;
|
||||
|
||||
std::optional<patch_place_type> last_place;
|
||||
bool unknown_place = false;
|
||||
|
||||
while (std::getline(ss, line))
|
||||
{
|
||||
TrimPatchLine(line);
|
||||
@ -518,6 +522,8 @@ void Patch::ExtractPatchInfo(std::vector<PatchInfo>* dst, const std::string& pna
|
||||
}
|
||||
}
|
||||
current_patch = {};
|
||||
last_place = std::nullopt;
|
||||
unknown_place = false;
|
||||
}
|
||||
|
||||
current_patch.name = line.substr(1, line.length() - 2);
|
||||
@ -530,13 +536,51 @@ void Patch::ExtractPatchInfo(std::vector<PatchInfo>* dst, const std::string& pna
|
||||
// Just ignore other directives, who knows what rubbish people have in here.
|
||||
// Use comment for description if it hasn't been otherwise specified.
|
||||
if (key == "author")
|
||||
{
|
||||
current_patch.author = value;
|
||||
}
|
||||
else if (key == "description")
|
||||
{
|
||||
current_patch.description = value;
|
||||
}
|
||||
else if (key == "comment" && current_patch.description.empty())
|
||||
{
|
||||
current_patch.description = value;
|
||||
else if (key == "patch" && !has_patch && num_unlabelled_patches)
|
||||
(*num_unlabelled_patches)++;
|
||||
}
|
||||
else if (key == "patch")
|
||||
{
|
||||
if (!has_patch && num_unlabelled_patches)
|
||||
(*num_unlabelled_patches)++;
|
||||
|
||||
// Try to extract the place value of the patch lines so we can
|
||||
// display them in the GUI if they all match. TODO: Don't duplicate
|
||||
// all this parsing logic twice.
|
||||
if (unknown_place)
|
||||
continue;
|
||||
|
||||
std::string::size_type comma_pos = value.find(",");
|
||||
if (comma_pos == std::string::npos)
|
||||
comma_pos = 0;
|
||||
const std::string_view padded_place = value.substr(0, comma_pos);
|
||||
const std::string_view place_string = StringUtil::StripWhitespace(padded_place);
|
||||
const std::optional<patch_place_type> place = LookupEnumName<patch_place_type>(
|
||||
place_string, s_place_to_string);
|
||||
if (!place.has_value() || (last_place.has_value() && place != last_place))
|
||||
{
|
||||
// This group contains patch lines with different or invalid
|
||||
// place values.
|
||||
current_patch.place = std::nullopt;
|
||||
unknown_place = true;
|
||||
}
|
||||
|
||||
current_patch.place = place;
|
||||
last_place = place;
|
||||
}
|
||||
else if (key == "dpatch")
|
||||
{
|
||||
current_patch.place = std::nullopt;
|
||||
unknown_place = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Last one.
|
||||
@ -1755,3 +1799,31 @@ void Patch::ApplyDynaPatch(const DynamicPatch& patch, u32 address)
|
||||
memWrite32(address + replacement.offset, replacement.value);
|
||||
}
|
||||
}
|
||||
|
||||
const char* Patch::PlaceToString(std::optional<patch_place_type> place)
|
||||
{
|
||||
if (!place.has_value())
|
||||
//: Time when a patch is applied.
|
||||
return TRANSLATE("Patch", "Unknown");
|
||||
|
||||
switch (*place)
|
||||
{
|
||||
case Patch::PPT_ONCE_ON_LOAD:
|
||||
//: Time when a patch is applied.
|
||||
return TRANSLATE("Patch", "Only On Startup");
|
||||
case Patch::PPT_CONTINUOUSLY:
|
||||
//: Time when a patch is applied.
|
||||
return TRANSLATE("Patch", "Every Frame");
|
||||
case Patch::PPT_COMBINED_0_1:
|
||||
//: Time when a patch is applied.
|
||||
return TRANSLATE("Patch", "On Startup & Every Frame");
|
||||
case Patch::PPT_ON_LOAD_OR_WHEN_ENABLED:
|
||||
//: Time when a patch is applied.
|
||||
return TRANSLATE("Patch", "On Startup & When Enabled");
|
||||
default:
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -55,6 +55,10 @@ namespace Patch
|
||||
std::string description;
|
||||
std::string author;
|
||||
|
||||
// This is only populated if all the patch lines in a given group have
|
||||
// the same place value.
|
||||
std::optional<patch_place_type> place;
|
||||
|
||||
std::string_view GetNamePart() const;
|
||||
std::string_view GetNameParentPart() const;
|
||||
};
|
||||
@ -116,4 +120,6 @@ namespace Patch
|
||||
extern u32 GetAllActivePatchesCount();
|
||||
|
||||
extern bool IsGloballyToggleablePatch(const PatchInfo& patch_info);
|
||||
|
||||
extern const char* PlaceToString(std::optional<patch_place_type> place);
|
||||
} // namespace Patch
|
||||
|
||||
Loading…
Reference in New Issue
Block a user