Skylanders: Improve figure data view and generation

Co-authored-by: deReeperJosh <joshua@dereeper.co.nz>
This commit is contained in:
Mandar1jn 2023-08-24 17:24:30 +02:00 committed by Admiral H. Curtiss
parent 220988d064
commit afdf6de041
No known key found for this signature in database
GPG key ID: F051B4C4044F33FB
20 changed files with 1369 additions and 146 deletions

View file

@ -339,6 +339,8 @@ add_executable(dolphin-emu
Settings/USBDeviceAddToWhitelistDialog.h
Settings/WiiPane.cpp
Settings/WiiPane.h
SkylanderPortal/SkylanderModifyDialog.cpp
SkylanderPortal/SkylanderModifyDialog.h
SkylanderPortal/SkylanderPortalWindow.cpp
SkylanderPortal/SkylanderPortalWindow.h
TAS/GCTASInputWindow.cpp

View file

@ -210,6 +210,7 @@
<ClCompile Include="Settings\PathPane.cpp" />
<ClCompile Include="Settings\USBDeviceAddToWhitelistDialog.cpp" />
<ClCompile Include="Settings\WiiPane.cpp" />
<ClCompile Include="SkylanderPortal\SkylanderModifyDialog.cpp" />
<ClCompile Include="SkylanderPortal\SkylanderPortalWindow.cpp" />
<ClCompile Include="TAS\GCTASInputWindow.cpp" />
<ClCompile Include="TAS\GBATASInputWindow.cpp" />
@ -253,6 +254,7 @@
<ClInclude Include="QtUtils\WrapInScrollArea.h" />
<ClInclude Include="ResourcePackManager.h" />
<ClInclude Include="Resources.h" />
<ClInclude Include="SkylanderPortal\SkylanderModifyDialog.h" />
<ClInclude Include="TAS\TASControlState.h" />
<ClInclude Include="TAS\TASSlider.h" />
<ClInclude Include="Translation.h" />

View file

@ -0,0 +1,344 @@
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "SkylanderModifyDialog.h"
#include <QBoxLayout>
#include <QCheckBox>
#include <QDateTimeEdit>
#include <QDialog>
#include <QDialogButtonBox>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QStringConverter>
#include <QValidator>
#include "Core/IOS/USB/Emulated/Skylanders/Skylander.h"
#include "Core/System.h"
#include "DolphinQt/QtUtils/SetWindowDecorations.h"
SkylanderModifyDialog::SkylanderModifyDialog(QWidget* parent, u8 slot)
: QDialog(parent), m_slot(slot)
{
bool should_show = true;
QVBoxLayout* layout = new QVBoxLayout;
IOS::HLE::USB::Skylander* skylander =
Core::System::GetInstance().GetSkylanderPortal().GetSkylander(slot);
m_figure = skylander->figure.get();
m_figure_data = m_figure->GetData();
auto* hbox_name = new QHBoxLayout;
QString name = QString();
if ((m_figure_data.skylander_data.nickname[0] != 0x00 &&
m_figure_data.normalized_type == IOS::HLE::USB::Type::Skylander))
{
name = QStringLiteral("\"%1\"").arg(QString::fromUtf16(
reinterpret_cast<char16_t*>(m_figure_data.skylander_data.nickname.data())));
}
else
{
auto found = IOS::HLE::USB::list_skylanders.find(
std::make_pair(m_figure_data.figure_id, m_figure_data.variant_id));
if (found != IOS::HLE::USB::list_skylanders.end())
{
name = QString::fromStdString(found->second.name);
}
else
{
// Should never be able to happen. Still good to have
name =
tr("Unknown (Id:%1 Var:%2)").arg(m_figure_data.figure_id).arg(m_figure_data.variant_id);
}
}
auto* label_name = new QLabel(QString::fromStdString("Modifying Skylander %1").arg(name));
hbox_name->addWidget(label_name);
layout->addLayout(hbox_name);
m_buttons = new QDialogButtonBox(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
if (m_figure_data.normalized_type == IOS::HLE::USB::Type::Skylander)
{
PopulateSkylanderOptions(layout);
}
else if (m_figure_data.normalized_type == IOS::HLE::USB::Type::Trophy)
{
should_show &= PopulateTrophyOptions(layout);
}
else if (m_figure_data.normalized_type == IOS::HLE::USB::Type::Item)
{
should_show = false;
QMessageBox::warning(
this, tr("No data to modify!"),
tr("The type of this Skylander does not have any data that can be modified!"),
QMessageBox::Ok);
}
else if (m_figure_data.normalized_type == IOS::HLE::USB::Type::Unknown)
{
should_show = false;
QMessageBox::warning(this, tr("Unknow Skylander type!"),
tr("The type of this Skylander is unknown!"), QMessageBox::Ok);
}
else
{
should_show = false;
QMessageBox::warning(
this, tr("Unable to modify Skylander!"),
tr("The type of this Skylander is unknown, or can't be modified at this time!"),
QMessageBox::Ok);
QMessageBox::warning(this, tr("Can't be modified yet!"),
tr("This Skylander type can't be modified yet!"), QMessageBox::Ok);
}
layout->addWidget(m_buttons);
this->setLayout(layout);
SetQWidgetWindowDecorations(this);
if (should_show)
{
this->show();
this->raise();
}
}
void SkylanderModifyDialog::PopulateSkylanderOptions(QVBoxLayout* layout)
{
auto* hbox_toy_code = new QHBoxLayout();
auto* label_toy_code = new QLabel(tr("Toy code:"));
auto* edit_toy_code = new QLineEdit(QString::fromUtf8(m_figure_data.skylander_data.toy_code));
edit_toy_code->setDisabled(true);
auto* hbox_money = new QHBoxLayout();
auto* label_money = new QLabel(tr("Money:"));
auto* edit_money = new QLineEdit(QStringLiteral("%1").arg(m_figure_data.skylander_data.money));
auto* hbox_hero = new QHBoxLayout();
auto* label_hero = new QLabel(tr("Hero level:"));
auto* edit_hero =
new QLineEdit(QStringLiteral("%1").arg(m_figure_data.skylander_data.hero_level));
auto toUtf16 = QStringDecoder(QStringDecoder::Utf16);
auto* hbox_nick = new QHBoxLayout();
auto* label_nick = new QLabel(tr("Nickname:"));
auto* edit_nick = new QLineEdit(QString::fromUtf16(
reinterpret_cast<char16_t*>(m_figure_data.skylander_data.nickname.data())));
auto* hbox_playtime = new QHBoxLayout();
auto* label_playtime = new QLabel(tr("Playtime:"));
auto* edit_playtime =
new QLineEdit(QStringLiteral("%1").arg(m_figure_data.skylander_data.playtime));
auto* hbox_last_reset = new QHBoxLayout();
auto* label_last_reset = new QLabel(tr("Last reset:"));
auto* edit_last_reset =
new QDateTimeEdit(QDateTime(QDate(m_figure_data.skylander_data.last_reset.year,
m_figure_data.skylander_data.last_reset.month,
m_figure_data.skylander_data.last_reset.day),
QTime(m_figure_data.skylander_data.last_reset.hour,
m_figure_data.skylander_data.last_reset.minute)));
auto* hbox_last_placed = new QHBoxLayout();
auto* label_last_placed = new QLabel(tr("Last placed:"));
auto* edit_last_placed =
new QDateTimeEdit(QDateTime(QDate(m_figure_data.skylander_data.last_placed.year,
m_figure_data.skylander_data.last_placed.month,
m_figure_data.skylander_data.last_placed.day),
QTime(m_figure_data.skylander_data.last_placed.hour,
m_figure_data.skylander_data.last_placed.minute)));
edit_money->setValidator(new QIntValidator(0, 65000, this));
edit_hero->setValidator(new QIntValidator(0, 100, this));
edit_nick->setValidator(new QRegularExpressionValidator(
QRegularExpression(QString::fromStdString("^\\p{L}{0,15}$")), this));
edit_playtime->setValidator(new QIntValidator(0, INT_MAX, this));
edit_last_reset->setDisplayFormat(QString::fromStdString("dd/MM/yyyy hh:mm"));
edit_last_placed->setDisplayFormat(QString::fromStdString("dd/MM/yyyy hh:mm"));
edit_toy_code->setToolTip(tr("The toy code for this figure. Only available for real figures."));
edit_money->setToolTip(tr("The amount of money this skylander should have. Between 0 and 65000"));
edit_hero->setToolTip(tr("The hero level of this skylander. Only seen in Skylanders: Spyro's "
"Adventures. Between 0 and 100"));
edit_nick->setToolTip(tr("The nickname for this skylander. Limited to 15 characters"));
edit_playtime->setToolTip(
tr("The total time this figure has been used inside a game in seconds"));
edit_last_reset->setToolTip(tr("The last time the figure has been reset. If the figure has never "
"been reset, the first time the figure was placed on a portal"));
edit_last_placed->setToolTip(tr("The last time the figure has been placed on a portal"));
hbox_toy_code->addWidget(label_toy_code);
hbox_toy_code->addWidget(edit_toy_code);
hbox_money->addWidget(label_money);
hbox_money->addWidget(edit_money);
hbox_hero->addWidget(label_hero);
hbox_hero->addWidget(edit_hero);
hbox_nick->addWidget(label_nick);
hbox_nick->addWidget(edit_nick);
hbox_playtime->addWidget(label_playtime);
hbox_playtime->addWidget(edit_playtime);
hbox_last_reset->addWidget(label_last_reset);
hbox_last_reset->addWidget(edit_last_reset);
hbox_last_placed->addWidget(label_last_placed);
hbox_last_placed->addWidget(edit_last_placed);
layout->addLayout(hbox_toy_code);
layout->addLayout(hbox_money);
layout->addLayout(hbox_hero);
layout->addLayout(hbox_nick);
layout->addLayout(hbox_playtime);
layout->addLayout(hbox_last_reset);
layout->addLayout(hbox_last_placed);
connect(m_buttons, &QDialogButtonBox::accepted, this, [=, this]() {
if (!edit_money->hasAcceptableInput())
{
QMessageBox::warning(this, tr("Incorrect money value!"),
tr("Make sure that the money value is between 0 and 65000!"),
QMessageBox::Ok);
}
else if (!edit_hero->hasAcceptableInput())
{
QMessageBox::warning(this, tr("Incorrect hero level value!"),
tr("Make sure that the hero level value is between 0 and 100!"),
QMessageBox::Ok);
}
else if (!edit_nick->hasAcceptableInput())
{
QMessageBox::warning(this, tr("Incorrect nickname!"),
tr("Make sure that the nickname is between 0 and 15 characters long!"),
QMessageBox::Ok);
}
else if (!edit_playtime->hasAcceptableInput())
{
QMessageBox::warning(this, tr("Incorrect playtime value!"),
tr("Make sure that the playtime value is valid!"), QMessageBox::Ok);
}
else if (!edit_last_reset->hasAcceptableInput())
{
QMessageBox::warning(this, tr("Incorrect last reset time!"),
tr("Make sure that the last reset datetime value is valid!"),
QMessageBox::Ok);
}
else if (!edit_last_placed->hasAcceptableInput())
{
QMessageBox::warning(this, tr("Incorrect last placed time!"),
tr("Make sure that the last placed datetime value is valid!"),
QMessageBox::Ok);
}
else
{
m_allow_close = true;
m_figure_data.skylander_data = {
.money = edit_money->text().toUShort(),
.hero_level = edit_hero->text().toUShort(),
.playtime = edit_playtime->text().toUInt(),
.last_reset = {.minute = static_cast<u8>(edit_last_reset->time().minute()),
.hour = static_cast<u8>(edit_last_reset->time().hour()),
.day = static_cast<u8>(edit_last_reset->date().day()),
.month = static_cast<u8>(edit_last_reset->date().month()),
.year = static_cast<u16>(edit_last_reset->date().year())},
.last_placed = {.minute = static_cast<u8>(edit_last_placed->time().minute()),
.hour = static_cast<u8>(edit_last_placed->time().hour()),
.day = static_cast<u8>(edit_last_placed->date().day()),
.month = static_cast<u8>(edit_last_placed->date().month()),
.year = static_cast<u16>(edit_last_placed->date().year())}};
std::u16string nickname = edit_nick->text().toStdU16String();
nickname.copy(reinterpret_cast<char16_t*>(m_figure_data.skylander_data.nickname.data()),
nickname.length());
if (m_figure->FileIsOpen())
{
m_figure->SetData(&m_figure_data);
}
else
{
QMessageBox::warning(this, tr("Could not save your changes!"),
tr("The file associated to this file was closed! Did you clear the "
"slot before saving?"),
QMessageBox::Ok);
}
this->accept();
}
});
}
bool SkylanderModifyDialog::PopulateTrophyOptions(QVBoxLayout* layout)
{
static constexpr u16 KAOS_TROPHY_ID = 3503;
static constexpr u16 SEA_TROPHY_ID = 3502;
if (m_figure_data.figure_id == KAOS_TROPHY_ID)
{
QMessageBox::warning(this, tr("Can't edit villains for this trophy!"),
tr("Kaos is the only villain for this trophy and is always unlocked. No "
"need to edit anything!"),
QMessageBox::Ok);
return false;
}
constexpr size_t MAX_VILLAINS = 4;
std::array<int, MAX_VILLAINS> shift_distances;
if (m_figure_data.figure_id == SEA_TROPHY_ID)
shift_distances = {0, 1, 2, 4};
else
shift_distances = {0, 2, 3, 4};
std::array<QCheckBox*, MAX_VILLAINS> edit_villains;
for (size_t i = 0; i < MAX_VILLAINS; ++i)
{
edit_villains[i] = new QCheckBox();
edit_villains[i]->setChecked(static_cast<bool>(m_figure_data.trophy_data.unlocked_villains &
(0b1 << shift_distances[i])));
auto* const label = new QLabel(tr("Captured villain %1:").arg(i + 1));
auto* const hbox = new QHBoxLayout();
hbox->addWidget(label);
hbox->addWidget(edit_villains[i]);
layout->addLayout(hbox);
}
connect(m_buttons, &QDialogButtonBox::accepted, this, [=, this]() {
m_figure_data.trophy_data.unlocked_villains = 0x0;
for (size_t i = 0; i < MAX_VILLAINS; ++i)
m_figure_data.trophy_data.unlocked_villains |=
edit_villains[i]->isChecked() ? (0b1 << shift_distances[i]) : 0b0;
m_figure->SetData(&m_figure_data);
m_allow_close = true;
this->accept();
});
return true;
}
void SkylanderModifyDialog::accept()
{
if (m_allow_close)
{
auto* skylander = Core::System::GetInstance().GetSkylanderPortal().GetSkylander(m_slot);
skylander->queued_status.push(IOS::HLE::USB::Skylander::REMOVED);
skylander->queued_status.push(IOS::HLE::USB::Skylander::ADDED);
skylander->queued_status.push(IOS::HLE::USB::Skylander::READY);
QDialog::accept();
}
}

View file

@ -0,0 +1,29 @@
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QDialog>
#include "Common/CommonTypes.h"
#include "Core/IOS/USB/Emulated/Skylanders/SkylanderFigure.h"
class QVBoxLayout;
class QDialogButtonBox;
class SkylanderModifyDialog : public QDialog
{
public:
explicit SkylanderModifyDialog(QWidget* parent = nullptr, u8 slot = 0);
private:
void PopulateSkylanderOptions(QVBoxLayout* layout);
bool PopulateTrophyOptions(QVBoxLayout* layout);
void accept() override;
bool m_allow_close = false;
u8 m_slot;
IOS::HLE::USB::FigureData m_figure_data;
IOS::HLE::USB::SkylanderFigure* m_figure;
QDialogButtonBox* m_buttons;
};

View file

@ -22,6 +22,7 @@
#include <QScrollArea>
#include <QStackedWidget>
#include <QString>
#include <QStringConverter>
#include <QStringList>
#include <QThread>
#include <QVBoxLayout>
@ -30,13 +31,14 @@
#include "Common/FileUtil.h"
#include "Core/Config/MainSettings.h"
#include "Core/IOS/USB/Emulated/Skylander.h"
#include "Core/IOS/USB/Emulated/Skylanders/Skylander.h"
#include "Core/System.h"
#include "DolphinQt/QtUtils/DolphinFileDialog.h"
#include "DolphinQt/QtUtils/SetWindowDecorations.h"
#include "DolphinQt/Resources.h"
#include "DolphinQt/Settings.h"
#include "SkylanderModifyDialog.h"
SkylanderPortalWindow::SkylanderPortalWindow(QWidget* parent) : QWidget(parent)
{
@ -124,15 +126,18 @@ void SkylanderPortalWindow::CreateMainWindow()
auto* load_file_btn = new QPushButton(tr("Load File"));
auto* clear_btn = new QPushButton(tr("Clear Slot"));
auto* load_btn = new QPushButton(tr("Load Slot"));
auto* modify_btn = new QPushButton(tr("Modify Slot"));
connect(create_btn, &QAbstractButton::clicked, this,
&SkylanderPortalWindow::CreateSkylanderAdvanced);
connect(clear_btn, &QAbstractButton::clicked, this, [this]() { ClearSlot(GetCurrentSlot()); });
connect(load_btn, &QAbstractButton::clicked, this, &SkylanderPortalWindow::LoadSelected);
connect(load_file_btn, &QAbstractButton::clicked, this, &SkylanderPortalWindow::LoadFromFile);
connect(modify_btn, &QAbstractButton::clicked, this, &SkylanderPortalWindow::ModifySkylander);
command_layout->addWidget(create_btn);
command_layout->addWidget(load_file_btn);
command_layout->addWidget(clear_btn);
command_layout->addWidget(load_btn);
command_layout->addWidget(modify_btn);
m_command_buttons->setLayout(command_layout);
main_layout->addWidget(m_command_buttons);
@ -647,6 +652,20 @@ void SkylanderPortalWindow::CreateSkylanderAdvanced()
create_window->raise();
}
void SkylanderPortalWindow::ModifySkylander()
{
if (auto sky_slot = m_sky_slots[GetCurrentSlot()])
{
new SkylanderModifyDialog(this, sky_slot.value().portal_slot);
}
else
{
QMessageBox::warning(this, tr("Failed to modify Skylander!"),
tr("Make sure there is a Skylander in slot %1!").arg(GetCurrentSlot()),
QMessageBox::Ok);
}
}
void SkylanderPortalWindow::ClearSlot(u8 slot)
{
auto& system = Core::System::GetInstance();
@ -771,16 +790,18 @@ void SkylanderPortalWindow::RefreshList()
void SkylanderPortalWindow::CreateSkyfile(const QString& path, bool load_after)
{
auto& system = Core::System::GetInstance();
if (!system.GetSkylanderPortal().CreateSkylander(path.toStdString(), m_sky_id, m_sky_var))
{
QMessageBox::warning(
this, tr("Failed to create Skylander file!"),
tr("Failed to create Skylander file:\n%1\n(Skylander may already be on the portal)")
.arg(path),
QMessageBox::Ok);
return;
IOS::HLE::USB::SkylanderFigure figure(path.toStdString());
if (!figure.Create(m_sky_id, m_sky_var))
{
QMessageBox::warning(
this, tr("Failed to create Skylander file!"),
tr("Failed to create Skylander file:\n%1\n(Skylander may already be on the portal)")
.arg(path),
QMessageBox::Ok);
return;
}
figure.Close();
}
m_last_skylander_path = QFileInfo(path).absolutePath() + QString::fromStdString("/");
@ -814,8 +835,8 @@ void SkylanderPortalWindow::LoadSkyfilePath(u8 slot, const QString& path)
auto& system = Core::System::GetInstance();
const std::pair<u16, u16> id_var = system.GetSkylanderPortal().CalculateIDs(file_data);
const u8 portal_slot =
system.GetSkylanderPortal().LoadSkylander(file_data.data(), std::move(sky_file));
const u8 portal_slot = system.GetSkylanderPortal().LoadSkylander(
std::make_unique<IOS::HLE::USB::SkylanderFigure>(std::move(sky_file)));
if (portal_slot == 0xFF)
{
QMessageBox::warning(this, tr("Failed to load the Skylander file!"),

View file

@ -14,7 +14,8 @@
#include <QWidget>
#include "Core/Core.h"
#include "Core/IOS/USB/Emulated/Skylander.h"
#include "Core/IOS/USB/Emulated/Skylanders/Skylander.h"
#include "Core/IOS/USB/Emulated/Skylanders/SkylanderFigure.h"
class QCheckBox;
class QGroupBox;
@ -64,6 +65,7 @@ private:
void LoadFromFile();
void ClearSlot(u8 slot);
void CreateSkylanderAdvanced();
void ModifySkylander();
// Behind the scenes
void OnEmulationStateChanged(Core::State state);