Merge pull request #10190 from AdmiralCurtiss/cheats-manager-qol

Cheats Manager quality of life improvements.
This commit is contained in:
Léo Lam 2021-10-29 19:32:11 +02:00 committed by GitHub
commit 663b937728
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 84 additions and 32 deletions

View File

@ -340,22 +340,31 @@ void Cheats::CheatSearchSession<T>::SetFilterType(FilterType filter_type)
} }
template <typename T> template <typename T>
static std::optional<T> ParseValue(const std::string& str) static std::optional<T> ParseValue(const std::string& str, bool force_parse_as_hex)
{ {
if (str.empty()) if (str.empty())
return std::nullopt; return std::nullopt;
T tmp; T tmp;
if (TryParse(str, &tmp)) if constexpr (std::is_integral_v<T>)
return tmp; {
if (TryParse(str, &tmp, force_parse_as_hex ? 16 : 0))
return tmp;
}
else
{
if (TryParse(str, &tmp))
return tmp;
}
return std::nullopt; return std::nullopt;
} }
template <typename T> template <typename T>
bool Cheats::CheatSearchSession<T>::SetValueFromString(const std::string& value_as_string) bool Cheats::CheatSearchSession<T>::SetValueFromString(const std::string& value_as_string,
bool force_parse_as_hex)
{ {
m_value = ParseValue<T>(value_as_string); m_value = ParseValue<T>(value_as_string, force_parse_as_hex);
return m_value.has_value(); return m_value.has_value();
} }
@ -469,35 +478,47 @@ Cheats::SearchErrorCode Cheats::CheatSearchSession<T>::RunSearch()
} }
template <typename T> template <typename T>
size_t Cheats::CheatSearchSession<T>::GetMemoryRangeCount() size_t Cheats::CheatSearchSession<T>::GetMemoryRangeCount() const
{ {
return m_memory_ranges.size(); return m_memory_ranges.size();
} }
template <typename T> template <typename T>
Cheats::MemoryRange Cheats::CheatSearchSession<T>::GetMemoryRange(size_t index) Cheats::MemoryRange Cheats::CheatSearchSession<T>::GetMemoryRange(size_t index) const
{ {
return m_memory_ranges[index]; return m_memory_ranges[index];
} }
template <typename T> template <typename T>
PowerPC::RequestedAddressSpace Cheats::CheatSearchSession<T>::GetAddressSpace() PowerPC::RequestedAddressSpace Cheats::CheatSearchSession<T>::GetAddressSpace() const
{ {
return m_address_space; return m_address_space;
} }
template <typename T> template <typename T>
Cheats::DataType Cheats::CheatSearchSession<T>::GetDataType() Cheats::DataType Cheats::CheatSearchSession<T>::GetDataType() const
{ {
return Cheats::GetDataType(Cheats::SearchValue{T(0)}); return Cheats::GetDataType(Cheats::SearchValue{T(0)});
} }
template <typename T> template <typename T>
bool Cheats::CheatSearchSession<T>::GetAligned() bool Cheats::CheatSearchSession<T>::GetAligned() const
{ {
return m_aligned; return m_aligned;
} }
template <typename T>
bool Cheats::CheatSearchSession<T>::IsIntegerType() const
{
return std::is_integral_v<T>;
}
template <typename T>
bool Cheats::CheatSearchSession<T>::IsFloatingType() const
{
return std::is_floating_point_v<T>;
}
template <typename T> template <typename T>
size_t Cheats::CheatSearchSession<T>::GetResultCount() const size_t Cheats::CheatSearchSession<T>::GetResultCount() const
{ {

View File

@ -132,7 +132,7 @@ public:
virtual void SetFilterType(FilterType filter_type) = 0; virtual void SetFilterType(FilterType filter_type) = 0;
// Set the value of the CompareAgainstSpecificValue filter used by subsequent searches. // Set the value of the CompareAgainstSpecificValue filter used by subsequent searches.
virtual bool SetValueFromString(const std::string& value_as_string) = 0; virtual bool SetValueFromString(const std::string& value_as_string, bool force_parse_as_hex) = 0;
// Resets the search results, causing the next search to act as a new search. // Resets the search results, causing the next search to act as a new search.
virtual void ResetResults() = 0; virtual void ResetResults() = 0;
@ -140,11 +140,14 @@ public:
// Run either a new search or a next search based on the current state of this session. // Run either a new search or a next search based on the current state of this session.
virtual SearchErrorCode RunSearch() = 0; virtual SearchErrorCode RunSearch() = 0;
virtual size_t GetMemoryRangeCount() = 0; virtual size_t GetMemoryRangeCount() const = 0;
virtual MemoryRange GetMemoryRange(size_t index) = 0; virtual MemoryRange GetMemoryRange(size_t index) const = 0;
virtual PowerPC::RequestedAddressSpace GetAddressSpace() = 0; virtual PowerPC::RequestedAddressSpace GetAddressSpace() const = 0;
virtual DataType GetDataType() = 0; virtual DataType GetDataType() const = 0;
virtual bool GetAligned() = 0; virtual bool GetAligned() const = 0;
virtual bool IsIntegerType() const = 0;
virtual bool IsFloatingType() const = 0;
virtual size_t GetResultCount() const = 0; virtual size_t GetResultCount() const = 0;
virtual size_t GetValidValueCount() const = 0; virtual size_t GetValidValueCount() const = 0;
@ -165,7 +168,7 @@ public:
}; };
template <typename T> template <typename T>
class CheatSearchSession : public CheatSearchSessionBase class CheatSearchSession final : public CheatSearchSessionBase
{ {
public: public:
CheatSearchSession(std::vector<MemoryRange> memory_ranges, CheatSearchSession(std::vector<MemoryRange> memory_ranges,
@ -178,16 +181,19 @@ public:
void SetCompareType(CompareType compare_type) override; void SetCompareType(CompareType compare_type) override;
void SetFilterType(FilterType filter_type) override; void SetFilterType(FilterType filter_type) override;
bool SetValueFromString(const std::string& value_as_string) override; bool SetValueFromString(const std::string& value_as_string, bool force_parse_as_hex) override;
void ResetResults() override; void ResetResults() override;
SearchErrorCode RunSearch() override; SearchErrorCode RunSearch() override;
size_t GetMemoryRangeCount() override; size_t GetMemoryRangeCount() const override;
MemoryRange GetMemoryRange(size_t index) override; MemoryRange GetMemoryRange(size_t index) const override;
PowerPC::RequestedAddressSpace GetAddressSpace() override; PowerPC::RequestedAddressSpace GetAddressSpace() const override;
DataType GetDataType() override; DataType GetDataType() const override;
bool GetAligned() override; bool GetAligned() const override;
bool IsIntegerType() const override;
bool IsFloatingType() const override;
size_t GetResultCount() const override; size_t GetResultCount() const override;
size_t GetValidValueCount() const override; size_t GetValidValueCount() const override;

View File

@ -20,8 +20,10 @@
#include "Core/CheatSearch.h" #include "Core/CheatSearch.h"
#include "Core/Config/MainSettings.h" #include "Core/Config/MainSettings.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/Memmap.h" #include "Core/HW/Memmap.h"
#include "Core/PowerPC/MMU.h" #include "Core/PowerPC/MMU.h"
#include "DolphinQt/QtUtils/ModalMessageBox.h"
CheatSearchFactoryWidget::CheatSearchFactoryWidget() CheatSearchFactoryWidget::CheatSearchFactoryWidget()
{ {
@ -152,6 +154,15 @@ void CheatSearchFactoryWidget::OnNewSearchClicked()
PowerPC::RequestedAddressSpace address_space; PowerPC::RequestedAddressSpace address_space;
if (m_standard_address_space->isChecked()) if (m_standard_address_space->isChecked())
{ {
const Core::State core_state = Core::GetState();
if (core_state != Core::State::Running && core_state != Core::State::Paused)
{
ModalMessageBox::warning(
this, tr("No game running."),
tr("Please start a game before starting a search with standard memory regions."));
return;
}
memory_ranges.emplace_back(0x80000000, Memory::GetRamSizeReal()); memory_ranges.emplace_back(0x80000000, Memory::GetRamSizeReal());
if (SConfig::GetInstance().bWii) if (SConfig::GetInstance().bWii)
memory_ranges.emplace_back(0x90000000, Memory::GetExRamSizeReal()); memory_ranges.emplace_back(0x90000000, Memory::GetExRamSizeReal());

View File

@ -57,6 +57,7 @@ CheatSearchWidget::CheatSearchWidget(std::unique_ptr<Cheats::CheatSearchSessionB
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
CreateWidgets(); CreateWidgets();
ConnectWidgets(); ConnectWidgets();
OnValueSourceChanged();
UpdateGuiTable(); UpdateGuiTable();
} }
@ -157,16 +158,14 @@ void CheatSearchWidget::CreateWidgets()
session_info_label->setText(tr("%1, %2, %3, %4").arg(ranges).arg(space).arg(type).arg(aligned)); session_info_label->setText(tr("%1, %2, %3, %4").arg(ranges).arg(space).arg(type).arg(aligned));
} }
auto* value_layout = new QHBoxLayout();
// i18n: This label is followed by a dropdown where the user can select things like "is equal to" // i18n: This label is followed by a dropdown where the user can select things like "is equal to"
// or "is less than or equal to", followed by another dropdown where the user can select "any // or "is less than or equal to", followed by another dropdown where the user can select "any
// value", "last value", or "this value:". These three UI elements are intended to form a sentence // value", "last value", or "this value:". These three UI elements are intended to form a sentence
// together. Because the UI elements can't be reordered by a translation, you may have to give // together. Because the UI elements can't be reordered by a translation, you may have to give
// up on the idea of having them form a sentence depending on the grammar of your target language. // up on the idea of having them form a sentence depending on the grammar of your target language.
auto* instructions_label = new QLabel(tr("Keep addresses where value in memory")); auto* instructions_label = new QLabel(tr("Keep addresses where value in memory"));
value_layout->addWidget(instructions_label);
auto* value_layout = new QHBoxLayout();
m_compare_type_dropdown = new QComboBox(); m_compare_type_dropdown = new QComboBox();
m_compare_type_dropdown->addItem(tr("is equal to"), m_compare_type_dropdown->addItem(tr("is equal to"),
QVariant::fromValue(Cheats::CompareType::Equal)); QVariant::fromValue(Cheats::CompareType::Equal));
@ -194,6 +193,9 @@ void CheatSearchWidget::CreateWidgets()
m_given_value_text = new QLineEdit(); m_given_value_text = new QLineEdit();
value_layout->addWidget(m_given_value_text); value_layout->addWidget(m_given_value_text);
m_parse_values_as_hex_checkbox = new QCheckBox(tr("Parse as Hex"));
value_layout->addWidget(m_parse_values_as_hex_checkbox);
auto* button_layout = new QHBoxLayout(); auto* button_layout = new QHBoxLayout();
m_next_scan_button = new QPushButton(tr("Search and Filter")); m_next_scan_button = new QPushButton(tr("Search and Filter"));
button_layout->addWidget(m_next_scan_button); button_layout->addWidget(m_next_scan_button);
@ -212,6 +214,7 @@ void CheatSearchWidget::CreateWidgets()
QVBoxLayout* layout = new QVBoxLayout(); QVBoxLayout* layout = new QVBoxLayout();
layout->addWidget(session_info_label); layout->addWidget(session_info_label);
layout->addWidget(instructions_label);
layout->addLayout(value_layout); layout->addLayout(value_layout);
layout->addLayout(button_layout); layout->addLayout(button_layout);
layout->addWidget(m_display_values_in_hex_checkbox); layout->addWidget(m_display_values_in_hex_checkbox);
@ -234,7 +237,7 @@ void CheatSearchWidget::ConnectWidgets()
connect(m_value_source_dropdown, &QComboBox::currentTextChanged, this, connect(m_value_source_dropdown, &QComboBox::currentTextChanged, this,
&CheatSearchWidget::OnValueSourceChanged); &CheatSearchWidget::OnValueSourceChanged);
connect(m_display_values_in_hex_checkbox, &QCheckBox::toggled, this, connect(m_display_values_in_hex_checkbox, &QCheckBox::toggled, this,
&CheatSearchWidget::OnHexCheckboxStateChanged); &CheatSearchWidget::OnDisplayHexCheckboxStateChanged);
} }
void CheatSearchWidget::OnNextScanClicked() void CheatSearchWidget::OnNextScanClicked()
@ -253,7 +256,8 @@ void CheatSearchWidget::OnNextScanClicked()
m_session->SetCompareType(m_compare_type_dropdown->currentData().value<Cheats::CompareType>()); m_session->SetCompareType(m_compare_type_dropdown->currentData().value<Cheats::CompareType>());
if (filter_type == Cheats::FilterType::CompareAgainstSpecificValue) if (filter_type == Cheats::FilterType::CompareAgainstSpecificValue)
{ {
if (!m_session->SetValueFromString(m_given_value_text->text().toStdString())) if (!m_session->SetValueFromString(m_given_value_text->text().toStdString(),
m_parse_values_as_hex_checkbox->isChecked()))
{ {
m_info_label_1->setText(tr("Failed to parse given value into target data type.")); m_info_label_1->setText(tr("Failed to parse given value into target data type."));
return; return;
@ -431,10 +435,12 @@ void CheatSearchWidget::OnAddressTableContextMenu()
void CheatSearchWidget::OnValueSourceChanged() void CheatSearchWidget::OnValueSourceChanged()
{ {
const auto filter_type = m_value_source_dropdown->currentData().value<Cheats::FilterType>(); const auto filter_type = m_value_source_dropdown->currentData().value<Cheats::FilterType>();
m_given_value_text->setEnabled(filter_type == Cheats::FilterType::CompareAgainstSpecificValue); const bool is_value_search = filter_type == Cheats::FilterType::CompareAgainstSpecificValue;
m_given_value_text->setEnabled(is_value_search);
m_parse_values_as_hex_checkbox->setEnabled(is_value_search && m_session->IsIntegerType());
} }
void CheatSearchWidget::OnHexCheckboxStateChanged() void CheatSearchWidget::OnDisplayHexCheckboxStateChanged()
{ {
if (!m_session->WasFirstSearchDone()) if (!m_session->WasFirstSearchDone())
return; return;

View File

@ -52,7 +52,7 @@ private:
void OnAddressTableItemChanged(QTableWidgetItem* item); void OnAddressTableItemChanged(QTableWidgetItem* item);
void OnAddressTableContextMenu(); void OnAddressTableContextMenu();
void OnValueSourceChanged(); void OnValueSourceChanged();
void OnHexCheckboxStateChanged(); void OnDisplayHexCheckboxStateChanged();
bool RefreshValues(); bool RefreshValues();
void UpdateGuiTable(); void UpdateGuiTable();
@ -75,6 +75,7 @@ private:
QPushButton* m_next_scan_button; QPushButton* m_next_scan_button;
QPushButton* m_refresh_values_button; QPushButton* m_refresh_values_button;
QPushButton* m_reset_button; QPushButton* m_reset_button;
QCheckBox* m_parse_values_as_hex_checkbox;
QCheckBox* m_display_values_in_hex_checkbox; QCheckBox* m_display_values_in_hex_checkbox;
QTableWidget* m_address_table; QTableWidget* m_address_table;
}; };

View File

@ -34,9 +34,16 @@ CheatsManager::CheatsManager(QWidget* parent) : QDialog(parent)
ConnectWidgets(); ConnectWidgets();
RefreshCodeTabs(Core::GetState(), true); RefreshCodeTabs(Core::GetState(), true);
auto& settings = Settings::GetQSettings();
restoreGeometry(settings.value(QStringLiteral("cheatsmanager/geometry")).toByteArray());
} }
CheatsManager::~CheatsManager() = default; CheatsManager::~CheatsManager()
{
auto& settings = Settings::GetQSettings();
settings.setValue(QStringLiteral("cheatsmanager/geometry"), saveGeometry());
}
void CheatsManager::OnStateChanged(Core::State state) void CheatsManager::OnStateChanged(Core::State state)
{ {