2023-01-24 21:51:02 +00:00
|
|
|
// Copyright 2023 Dolphin Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#include "DolphinQt/InfinityBase/InfinityBaseWindow.h"
|
|
|
|
|
2023-06-08 15:05:24 +00:00
|
|
|
#include <string>
|
|
|
|
|
2023-01-24 21:51:02 +00:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QCompleter>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QScrollArea>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include "Common/IOFile.h"
|
|
|
|
|
|
|
|
#include "Core/Config/MainSettings.h"
|
2023-06-08 15:05:24 +00:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/IOS/USB/Emulated/Infinity.h"
|
2023-01-24 21:51:02 +00:00
|
|
|
#include "Core/System.h"
|
|
|
|
|
|
|
|
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
|
2023-07-30 22:42:15 +00:00
|
|
|
#include "DolphinQt/QtUtils/SetWindowDecorations.h"
|
2023-01-24 21:51:02 +00:00
|
|
|
#include "DolphinQt/Settings.h"
|
|
|
|
|
|
|
|
// Qt is not guaranteed to keep track of file paths using native file pickers, so we use this
|
|
|
|
// static variable to ensure we open at the most recent figure file location
|
|
|
|
static QString s_last_figure_path;
|
|
|
|
|
2024-06-26 22:04:27 +00:00
|
|
|
using FigureUIPosition = IOS::HLE::USB::FigureUIPosition;
|
|
|
|
|
2023-01-24 21:51:02 +00:00
|
|
|
InfinityBaseWindow::InfinityBaseWindow(QWidget* parent) : QWidget(parent)
|
|
|
|
{
|
2024-04-20 14:26:53 +00:00
|
|
|
// i18n: Window for managing Disney Infinity figures
|
2023-01-24 21:51:02 +00:00
|
|
|
setWindowTitle(tr("Infinity Manager"));
|
2023-04-17 00:40:26 +00:00
|
|
|
setObjectName(QStringLiteral("infinity_manager"));
|
2023-01-24 21:51:02 +00:00
|
|
|
setMinimumSize(QSize(700, 200));
|
|
|
|
|
|
|
|
CreateMainWindow();
|
|
|
|
|
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
|
|
|
|
&InfinityBaseWindow::OnEmulationStateChanged);
|
|
|
|
|
|
|
|
installEventFilter(this);
|
|
|
|
|
2024-03-28 18:35:13 +00:00
|
|
|
OnEmulationStateChanged(Core::GetState(Core::System::GetInstance()));
|
2024-08-18 13:08:44 +00:00
|
|
|
}
|
2023-01-24 21:51:02 +00:00
|
|
|
|
|
|
|
InfinityBaseWindow::~InfinityBaseWindow() = default;
|
|
|
|
|
|
|
|
void InfinityBaseWindow::CreateMainWindow()
|
|
|
|
{
|
|
|
|
auto* main_layout = new QVBoxLayout();
|
|
|
|
|
|
|
|
auto* checkbox_group = new QGroupBox();
|
|
|
|
auto* checkbox_layout = new QHBoxLayout();
|
|
|
|
checkbox_layout->setAlignment(Qt::AlignHCenter);
|
|
|
|
m_checkbox = new QCheckBox(tr("Emulate Infinity Base"), this);
|
|
|
|
m_checkbox->setChecked(Config::Get(Config::MAIN_EMULATE_INFINITY_BASE));
|
2023-06-08 14:55:27 +00:00
|
|
|
connect(m_checkbox, &QCheckBox::toggled, this, &InfinityBaseWindow::EmulateBase);
|
2023-01-24 21:51:02 +00:00
|
|
|
checkbox_layout->addWidget(m_checkbox);
|
|
|
|
checkbox_group->setLayout(checkbox_layout);
|
|
|
|
main_layout->addWidget(checkbox_group);
|
|
|
|
|
|
|
|
auto add_line = [](QVBoxLayout* vbox) {
|
|
|
|
auto* line = new QFrame();
|
|
|
|
line->setFrameShape(QFrame::HLine);
|
|
|
|
line->setFrameShadow(QFrame::Sunken);
|
|
|
|
vbox->addWidget(line);
|
|
|
|
};
|
|
|
|
|
|
|
|
m_group_figures = new QGroupBox(tr("Active Infinity Figures:"));
|
|
|
|
auto* vbox_group = new QVBoxLayout();
|
|
|
|
auto* scroll_area = new QScrollArea();
|
|
|
|
|
2024-06-26 22:04:27 +00:00
|
|
|
AddFigureSlot(vbox_group, tr("Play Set/Power Disc"), FigureUIPosition::HexagonDiscOne);
|
2023-01-24 21:51:02 +00:00
|
|
|
add_line(vbox_group);
|
2024-06-26 22:04:27 +00:00
|
|
|
AddFigureSlot(vbox_group, tr("Power Disc Two"), FigureUIPosition::HexagonDiscTwo);
|
2023-01-24 21:51:02 +00:00
|
|
|
add_line(vbox_group);
|
2024-06-26 22:04:27 +00:00
|
|
|
AddFigureSlot(vbox_group, tr("Power Disc Three"), FigureUIPosition::HexagonDiscThree);
|
2024-05-11 16:10:15 +00:00
|
|
|
add_line(vbox_group);
|
2024-06-26 22:04:27 +00:00
|
|
|
AddFigureSlot(vbox_group, tr("Player One"), FigureUIPosition::PlayerOne);
|
2024-05-11 16:10:15 +00:00
|
|
|
add_line(vbox_group);
|
2024-06-26 22:04:27 +00:00
|
|
|
AddFigureSlot(vbox_group, tr("Player One Ability One"), FigureUIPosition::P1AbilityOne);
|
2023-01-24 21:51:02 +00:00
|
|
|
add_line(vbox_group);
|
2024-06-26 22:04:27 +00:00
|
|
|
AddFigureSlot(vbox_group, tr("Player One Ability Two"), FigureUIPosition::P1AbilityTwo);
|
2023-01-24 21:51:02 +00:00
|
|
|
add_line(vbox_group);
|
2024-06-26 22:04:27 +00:00
|
|
|
AddFigureSlot(vbox_group, tr("Player Two"), FigureUIPosition::PlayerTwo);
|
2023-01-24 21:51:02 +00:00
|
|
|
add_line(vbox_group);
|
2024-06-26 22:04:27 +00:00
|
|
|
AddFigureSlot(vbox_group, tr("Player Two Ability One"), FigureUIPosition::P2AbilityOne);
|
2023-01-24 21:51:02 +00:00
|
|
|
add_line(vbox_group);
|
2024-06-26 22:04:27 +00:00
|
|
|
AddFigureSlot(vbox_group, tr("Player Two Ability Two"), FigureUIPosition::P2AbilityTwo);
|
2023-01-24 21:51:02 +00:00
|
|
|
|
|
|
|
m_group_figures->setLayout(vbox_group);
|
|
|
|
scroll_area->setWidget(m_group_figures);
|
|
|
|
scroll_area->setWidgetResizable(true);
|
|
|
|
m_group_figures->setVisible(Config::Get(Config::MAIN_EMULATE_INFINITY_BASE));
|
|
|
|
main_layout->addWidget(scroll_area);
|
|
|
|
setLayout(main_layout);
|
|
|
|
}
|
|
|
|
|
2024-06-26 22:04:27 +00:00
|
|
|
void InfinityBaseWindow::AddFigureSlot(QVBoxLayout* vbox_group, QString name, FigureUIPosition slot)
|
2023-01-24 21:51:02 +00:00
|
|
|
{
|
|
|
|
auto* hbox_infinity = new QHBoxLayout();
|
|
|
|
|
|
|
|
auto* label_skyname = new QLabel(name);
|
|
|
|
|
|
|
|
auto* clear_btn = new QPushButton(tr("Clear"));
|
|
|
|
auto* create_btn = new QPushButton(tr("Create"));
|
|
|
|
auto* load_btn = new QPushButton(tr("Load"));
|
2024-06-26 22:04:27 +00:00
|
|
|
m_edit_figures[static_cast<u8>(slot)] = new QLineEdit();
|
|
|
|
m_edit_figures[static_cast<u8>(slot)]->setEnabled(false);
|
|
|
|
m_edit_figures[static_cast<u8>(slot)]->setText(tr("None"));
|
2023-01-24 21:51:02 +00:00
|
|
|
|
|
|
|
connect(clear_btn, &QAbstractButton::clicked, this, [this, slot] { ClearFigure(slot); });
|
|
|
|
connect(create_btn, &QAbstractButton::clicked, this, [this, slot] { CreateFigure(slot); });
|
|
|
|
connect(load_btn, &QAbstractButton::clicked, this, [this, slot] { LoadFigure(slot); });
|
|
|
|
|
|
|
|
hbox_infinity->addWidget(label_skyname);
|
2024-06-26 22:04:27 +00:00
|
|
|
hbox_infinity->addWidget(m_edit_figures[static_cast<u8>(slot)]);
|
2023-01-24 21:51:02 +00:00
|
|
|
hbox_infinity->addWidget(clear_btn);
|
|
|
|
hbox_infinity->addWidget(create_btn);
|
|
|
|
hbox_infinity->addWidget(load_btn);
|
|
|
|
|
|
|
|
vbox_group->addLayout(hbox_infinity);
|
|
|
|
}
|
|
|
|
|
2024-06-26 22:04:27 +00:00
|
|
|
void InfinityBaseWindow::ClearFigure(FigureUIPosition slot)
|
2023-01-24 21:51:02 +00:00
|
|
|
{
|
|
|
|
auto& system = Core::System::GetInstance();
|
2024-06-26 22:04:27 +00:00
|
|
|
m_edit_figures[static_cast<u8>(slot)]->setText(tr("None"));
|
2023-01-24 21:51:02 +00:00
|
|
|
|
|
|
|
system.GetInfinityBase().RemoveFigure(slot);
|
|
|
|
}
|
|
|
|
|
2024-06-26 22:04:27 +00:00
|
|
|
void InfinityBaseWindow::LoadFigure(FigureUIPosition slot)
|
2023-01-24 21:51:02 +00:00
|
|
|
{
|
|
|
|
const QString file_path =
|
|
|
|
DolphinFileDialog::getOpenFileName(this, tr("Select Figure File"), s_last_figure_path,
|
|
|
|
QStringLiteral("Infinity Figure (*.bin);;"));
|
|
|
|
if (file_path.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_last_figure_path = QFileInfo(file_path).absolutePath() + QLatin1Char('/');
|
|
|
|
|
|
|
|
LoadFigurePath(slot, file_path);
|
|
|
|
}
|
|
|
|
|
2024-06-26 22:04:27 +00:00
|
|
|
void InfinityBaseWindow::CreateFigure(FigureUIPosition slot)
|
2023-01-24 21:51:02 +00:00
|
|
|
{
|
|
|
|
CreateFigureDialog create_dlg(this, slot);
|
2023-07-30 22:42:15 +00:00
|
|
|
SetQWidgetWindowDecorations(&create_dlg);
|
2023-01-24 21:51:02 +00:00
|
|
|
if (create_dlg.exec() == CreateFigureDialog::Accepted)
|
|
|
|
{
|
|
|
|
LoadFigurePath(slot, create_dlg.GetFilePath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-26 22:04:27 +00:00
|
|
|
void InfinityBaseWindow::LoadFigurePath(FigureUIPosition slot, const QString& path)
|
2023-01-24 21:51:02 +00:00
|
|
|
{
|
|
|
|
File::IOFile inf_file(path.toStdString(), "r+b");
|
|
|
|
if (!inf_file)
|
|
|
|
{
|
|
|
|
QMessageBox::warning(
|
|
|
|
this, tr("Failed to open the Infinity file!"),
|
2024-04-20 14:26:53 +00:00
|
|
|
tr("Failed to open the Infinity file:\n%1\n\nThe file may already be in use on the base.")
|
2023-01-24 21:51:02 +00:00
|
|
|
.arg(path),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::array<u8, IOS::HLE::USB::INFINITY_NUM_BLOCKS * IOS::HLE::USB::INFINITY_BLOCK_SIZE> file_data;
|
|
|
|
if (!inf_file.ReadBytes(file_data.data(), file_data.size()))
|
|
|
|
{
|
2024-04-20 14:26:53 +00:00
|
|
|
QMessageBox::warning(
|
|
|
|
this, tr("Failed to read the Infinity file!"),
|
2024-05-19 19:52:49 +00:00
|
|
|
tr("Failed to read the Infinity file:\n%1\n\nThe file was too small.").arg(path),
|
2024-04-20 14:26:53 +00:00
|
|
|
QMessageBox::Ok);
|
2023-01-24 21:51:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& system = Core::System::GetInstance();
|
|
|
|
|
|
|
|
system.GetInfinityBase().RemoveFigure(slot);
|
2024-06-26 22:04:27 +00:00
|
|
|
m_edit_figures[static_cast<u8>(slot)]->setText(QString::fromStdString(
|
2023-04-17 00:40:26 +00:00
|
|
|
system.GetInfinityBase().LoadFigure(file_data, std::move(inf_file), slot)));
|
2023-01-24 21:51:02 +00:00
|
|
|
}
|
|
|
|
|
2024-06-26 22:04:27 +00:00
|
|
|
CreateFigureDialog::CreateFigureDialog(QWidget* parent, FigureUIPosition slot) : QDialog(parent)
|
2023-01-24 21:51:02 +00:00
|
|
|
{
|
|
|
|
setWindowTitle(tr("Infinity Figure Creator"));
|
|
|
|
setObjectName(QStringLiteral("infinity_creator"));
|
|
|
|
setMinimumSize(QSize(500, 150));
|
|
|
|
auto* layout = new QVBoxLayout;
|
|
|
|
|
|
|
|
auto* combo_figlist = new QComboBox();
|
|
|
|
QStringList filterlist;
|
2023-04-17 00:40:26 +00:00
|
|
|
u32 first_entry = 0;
|
2023-06-12 13:02:18 +00:00
|
|
|
for (const auto& entry : IOS::HLE::USB::InfinityBase::GetFigureList())
|
2023-01-24 21:51:02 +00:00
|
|
|
{
|
|
|
|
const auto figure = entry.second;
|
|
|
|
// Only display entry if it is a piece appropriate for the slot
|
2024-06-26 22:04:27 +00:00
|
|
|
if ((slot == FigureUIPosition::HexagonDiscOne &&
|
2023-04-17 00:40:26 +00:00
|
|
|
((figure > 0x1E8480 && figure < 0x2DC6BF) || (figure > 0x3D0900 && figure < 0x4C4B3F))) ||
|
2024-06-26 22:04:27 +00:00
|
|
|
((slot == FigureUIPosition::HexagonDiscTwo || slot == FigureUIPosition::HexagonDiscThree) &&
|
|
|
|
(figure > 0x3D0900 && figure < 0x4C4B3F)) ||
|
|
|
|
((slot == FigureUIPosition::PlayerOne || slot == FigureUIPosition::PlayerTwo) &&
|
|
|
|
figure < 0x1E847F) ||
|
|
|
|
((slot == FigureUIPosition::P1AbilityOne || slot == FigureUIPosition::P1AbilityTwo ||
|
|
|
|
slot == FigureUIPosition::P2AbilityOne || slot == FigureUIPosition::P2AbilityTwo) &&
|
2023-04-17 00:40:26 +00:00
|
|
|
(figure > 0x2DC6C0 && figure < 0x3D08FF)))
|
2023-01-24 21:51:02 +00:00
|
|
|
{
|
2023-06-08 14:52:34 +00:00
|
|
|
const auto figure_name = QString::fromStdString(entry.first);
|
|
|
|
combo_figlist->addItem(figure_name, QVariant(figure));
|
|
|
|
filterlist << figure_name;
|
2023-01-24 21:51:02 +00:00
|
|
|
if (first_entry == 0)
|
|
|
|
{
|
2023-04-17 00:40:26 +00:00
|
|
|
first_entry = figure;
|
2023-01-24 21:51:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
combo_figlist->addItem(tr("--Unknown--"), QVariant(0xFFFF));
|
|
|
|
combo_figlist->setEditable(true);
|
|
|
|
combo_figlist->setInsertPolicy(QComboBox::NoInsert);
|
|
|
|
|
|
|
|
auto* co_compl = new QCompleter(filterlist, this);
|
|
|
|
co_compl->setCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
co_compl->setCompletionMode(QCompleter::PopupCompletion);
|
|
|
|
co_compl->setFilterMode(Qt::MatchContains);
|
|
|
|
combo_figlist->setCompleter(co_compl);
|
|
|
|
|
|
|
|
layout->addWidget(combo_figlist);
|
|
|
|
|
|
|
|
auto* line = new QFrame();
|
|
|
|
line->setFrameShape(QFrame::HLine);
|
|
|
|
line->setFrameShadow(QFrame::Sunken);
|
|
|
|
layout->addWidget(line);
|
|
|
|
|
|
|
|
auto* hbox_idvar = new QHBoxLayout();
|
|
|
|
auto* label_id = new QLabel(tr("Figure Number:"));
|
2023-06-08 14:52:34 +00:00
|
|
|
auto* edit_num = new QLineEdit(QString::number(first_entry));
|
2023-01-24 21:51:02 +00:00
|
|
|
auto* rxv = new QRegularExpressionValidator(QRegularExpression(QStringLiteral("\\d*")), this);
|
|
|
|
edit_num->setValidator(rxv);
|
|
|
|
hbox_idvar->addWidget(label_id);
|
|
|
|
hbox_idvar->addWidget(edit_num);
|
|
|
|
layout->addLayout(hbox_idvar);
|
|
|
|
|
|
|
|
auto* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
|
|
|
buttons->button(QDialogButtonBox::Ok)->setText(tr("Create"));
|
|
|
|
layout->addWidget(buttons);
|
|
|
|
|
|
|
|
setLayout(layout);
|
|
|
|
|
2023-11-04 21:01:39 +00:00
|
|
|
connect(combo_figlist, &QComboBox::currentIndexChanged, [=](int index) {
|
2023-01-24 21:51:02 +00:00
|
|
|
const u32 char_info = combo_figlist->itemData(index).toUInt();
|
|
|
|
if (char_info != 0xFFFFFFFF)
|
|
|
|
{
|
|
|
|
edit_num->setText(QString::number(char_info));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(buttons, &QDialogButtonBox::accepted, this, [=, this]() {
|
|
|
|
bool ok_char = false;
|
2023-04-17 00:40:26 +00:00
|
|
|
const u32 char_number = edit_num->text().toULong(&ok_char);
|
2023-01-24 21:51:02 +00:00
|
|
|
if (!ok_char)
|
|
|
|
{
|
|
|
|
QMessageBox::warning(this, tr("Error converting value"), tr("Character entered is invalid!"),
|
|
|
|
QMessageBox::Ok);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString predef_name = s_last_figure_path;
|
|
|
|
|
|
|
|
auto& system = Core::System::GetInstance();
|
|
|
|
const auto found_fig = system.GetInfinityBase().FindFigure(char_number);
|
2023-04-17 00:40:26 +00:00
|
|
|
if (!found_fig.empty())
|
2023-01-24 21:51:02 +00:00
|
|
|
{
|
2023-06-08 14:52:34 +00:00
|
|
|
predef_name += QString::fromStdString(found_fig + ".bin");
|
2023-01-24 21:51:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-04-20 14:26:53 +00:00
|
|
|
// i18n: This is used to create a file name. The string must end in ".bin".
|
2023-01-24 21:51:02 +00:00
|
|
|
QString str = tr("Unknown(%1).bin");
|
|
|
|
predef_name += str.arg(char_number);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_file_path = DolphinFileDialog::getSaveFileName(this, tr("Create Infinity File"), predef_name,
|
|
|
|
tr("Infinity Object (*.bin);;"));
|
|
|
|
if (m_file_path.isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!system.GetInfinityBase().CreateFigure(m_file_path.toStdString(), char_number))
|
|
|
|
{
|
2023-04-17 00:40:26 +00:00
|
|
|
QMessageBox::warning(
|
|
|
|
this, tr("Failed to create Infinity file"),
|
2024-04-20 14:26:53 +00:00
|
|
|
tr("Blank figure creation failed at:\n%1\n\nTry again with a different character.")
|
2023-04-17 00:40:26 +00:00
|
|
|
.arg(m_file_path),
|
|
|
|
QMessageBox::Ok);
|
2023-01-24 21:51:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
s_last_figure_path = QFileInfo(m_file_path).absolutePath() + QLatin1Char('/');
|
|
|
|
accept();
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
|
|
|
|
|
|
connect(co_compl, QOverload<const QString&>::of(&QCompleter::activated),
|
|
|
|
[=](const QString& text) {
|
|
|
|
combo_figlist->setCurrentText(text);
|
|
|
|
combo_figlist->setCurrentIndex(combo_figlist->findText(text));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CreateFigureDialog::GetFilePath() const
|
|
|
|
{
|
|
|
|
return m_file_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InfinityBaseWindow::EmulateBase(bool emulate)
|
|
|
|
{
|
|
|
|
Config::SetBaseOrCurrent(Config::MAIN_EMULATE_INFINITY_BASE, emulate);
|
|
|
|
m_group_figures->setVisible(emulate);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InfinityBaseWindow::OnEmulationStateChanged(Core::State state)
|
|
|
|
{
|
|
|
|
const bool running = state != Core::State::Uninitialized;
|
|
|
|
|
|
|
|
m_checkbox->setEnabled(!running);
|
|
|
|
}
|