mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Implement resource packs
This commit is contained in:
@ -107,6 +107,7 @@ add_executable(dolphin-emu
|
||||
QtUtils/WinIconHelper.cpp
|
||||
QtUtils/WrapInScrollArea.cpp
|
||||
QtUtils/AspectRatioWidget.cpp
|
||||
ResourcePackManager.cpp
|
||||
Settings/AdvancedPane.cpp
|
||||
Settings/AudioPane.cpp
|
||||
Settings/GameCubePane.cpp
|
||||
|
@ -329,6 +329,7 @@
|
||||
<ClCompile Include="FIFO\FIFOAnalyzer.cpp" />
|
||||
<ClCompile Include="FIFO\FIFOPlayerWindow.cpp" />
|
||||
<ClCompile Include="QtUtils\WinIconHelper.cpp" />
|
||||
<ClCompile Include="ResourcePackManager.cpp" />
|
||||
<ClCompile Include="TAS\GCTASInputWindow.cpp" />
|
||||
<ClCompile Include="TAS\WiiTASInputWindow.cpp" />
|
||||
<ClCompile Include="TAS\TASInputWindow.cpp" />
|
||||
@ -390,6 +391,7 @@
|
||||
<ClInclude Include="QtUtils\QueueOnObject.h" />
|
||||
<ClInclude Include="QtUtils\RunOnObject.h" />
|
||||
<ClInclude Include="QtUtils\WinIconHelper.h" />
|
||||
<ClInclude Include="ResourcePackManager.h" />
|
||||
<ClInclude Include="Resources.h" />
|
||||
<ClInclude Include="Translation.h" />
|
||||
<ClInclude Include="WiiUpdate.h" />
|
||||
@ -477,4 +479,4 @@
|
||||
<Message Text="Copy: @(BinaryFiles) -> $(BinaryOutputDir)" Importance="High" />
|
||||
<Copy SourceFiles="@(BinaryFiles)" DestinationFolder="$(BinaryOutputDir)" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
@ -87,6 +87,7 @@
|
||||
#include "DolphinQt/QtUtils/RunOnObject.h"
|
||||
#include "DolphinQt/QtUtils/WindowActivationEventFilter.h"
|
||||
#include "DolphinQt/RenderWidget.h"
|
||||
#include "DolphinQt/ResourcePackManager.h"
|
||||
#include "DolphinQt/Resources.h"
|
||||
#include "DolphinQt/SearchBar.h"
|
||||
#include "DolphinQt/Settings.h"
|
||||
@ -99,6 +100,10 @@
|
||||
|
||||
#include "UICommon/DiscordPresence.h"
|
||||
#include "UICommon/GameFile.h"
|
||||
#include "UICommon/ResourcePack/Manager.h"
|
||||
#include "UICommon/ResourcePack/Manifest.h"
|
||||
#include "UICommon/ResourcePack/ResourcePack.h"
|
||||
|
||||
#include "UICommon/UICommon.h"
|
||||
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
@ -208,6 +213,21 @@ MainWindow::MainWindow(std::unique_ptr<BootParameters> boot_parameters) : QMainW
|
||||
// Restoring of window states can sometimes go wrong, resulting in widgets being visible when they
|
||||
// shouldn't be so we have to reapply all our rules afterwards.
|
||||
Settings::Instance().RefreshWidgetVisibility();
|
||||
|
||||
if (!ResourcePack::Init())
|
||||
QMessageBox::critical(this, tr("Error"), tr("Error occured while loading some texture packs"));
|
||||
|
||||
for (auto& pack : ResourcePack::GetPacks())
|
||||
{
|
||||
if (!pack.IsValid())
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error"),
|
||||
tr("Invalid Pack %1 provided: %2")
|
||||
.arg(QString::fromStdString(pack.GetPath()))
|
||||
.arg(QString::fromStdString(pack.GetError())));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -391,6 +411,8 @@ void MainWindow::ConnectMenuBar()
|
||||
|
||||
// Tools
|
||||
connect(m_menu_bar, &MenuBar::ShowMemcardManager, this, &MainWindow::ShowMemcardManager);
|
||||
connect(m_menu_bar, &MenuBar::ShowResourcePackManager, this,
|
||||
&MainWindow::ShowResourcePackManager);
|
||||
connect(m_menu_bar, &MenuBar::ShowCheatsManager, this, &MainWindow::ShowCheatsManager);
|
||||
connect(m_menu_bar, &MenuBar::BootGameCubeIPL, this, &MainWindow::OnBootGameCubeIPL);
|
||||
connect(m_menu_bar, &MenuBar::ImportNANDBackup, this, &MainWindow::OnImportNANDBackup);
|
||||
@ -1553,6 +1575,13 @@ void MainWindow::ShowMemcardManager()
|
||||
manager.exec();
|
||||
}
|
||||
|
||||
void MainWindow::ShowResourcePackManager()
|
||||
{
|
||||
ResourcePackManager manager(this);
|
||||
|
||||
manager.exec();
|
||||
}
|
||||
|
||||
void MainWindow::ShowCheatsManager()
|
||||
{
|
||||
m_cheats_manager->show();
|
||||
|
@ -131,6 +131,7 @@ private:
|
||||
void ShowNetPlaySetupDialog();
|
||||
void ShowFIFOPlayer();
|
||||
void ShowMemcardManager();
|
||||
void ShowResourcePackManager();
|
||||
void ShowCheatsManager();
|
||||
|
||||
void NetPlayInit();
|
||||
|
@ -204,6 +204,9 @@ void MenuBar::AddToolsMenu()
|
||||
m_show_cheat_manager =
|
||||
tools_menu->addAction(tr("&Cheats Manager"), this, [this] { emit ShowCheatsManager(); });
|
||||
|
||||
tools_menu->addAction(tr("&Resource Pack Manager"), this,
|
||||
[this] { emit ShowResourcePackManager(); });
|
||||
|
||||
connect(&Settings::Instance(), &Settings::EnableCheatsChanged, [this](bool enabled) {
|
||||
m_show_cheat_manager->setEnabled(Core::GetState() != Core::State::Uninitialized && enabled);
|
||||
});
|
||||
|
@ -78,6 +78,7 @@ signals:
|
||||
void ShowFIFOPlayer();
|
||||
void ShowAboutDialog();
|
||||
void ShowCheatsManager();
|
||||
void ShowResourcePackManager();
|
||||
void ConnectWiiRemote(int id);
|
||||
|
||||
// Options
|
||||
|
325
Source/Core/DolphinQt/ResourcePackManager.cpp
Normal file
325
Source/Core/DolphinQt/ResourcePackManager.cpp
Normal file
@ -0,0 +1,325 @@
|
||||
// Copyright 2018 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include "DolphinQt/ResourcePackManager.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QGridLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QTableWidget>
|
||||
#include <QUrl>
|
||||
|
||||
#include "Common/FileUtil.h"
|
||||
#include "UICommon/ResourcePack/Manager.h"
|
||||
|
||||
ResourcePackManager::ResourcePackManager(QWidget* widget) : QDialog(widget)
|
||||
{
|
||||
CreateWidgets();
|
||||
ConnectWidgets();
|
||||
RepopulateTable();
|
||||
|
||||
setWindowTitle(tr("Resource Pack Manager"));
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
resize(QSize(900, 600));
|
||||
}
|
||||
|
||||
void ResourcePackManager::CreateWidgets()
|
||||
{
|
||||
auto* layout = new QGridLayout;
|
||||
|
||||
m_table_widget = new QTableWidget;
|
||||
|
||||
m_open_directory_button = new QPushButton(tr("Open Directory..."));
|
||||
m_change_button = new QPushButton(tr("Install"));
|
||||
m_remove_button = new QPushButton(tr("Remove"));
|
||||
m_refresh_button = new QPushButton(tr("Refresh"));
|
||||
m_priority_up_button = new QPushButton(tr("Up"));
|
||||
m_priority_down_button = new QPushButton(tr("Down"));
|
||||
|
||||
auto* buttons = new QDialogButtonBox(QDialogButtonBox::Ok);
|
||||
|
||||
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
|
||||
layout->addWidget(m_table_widget, 0, 0, 7, 1);
|
||||
layout->addWidget(m_open_directory_button, 0, 1);
|
||||
layout->addWidget(m_change_button, 1, 1);
|
||||
layout->addWidget(m_remove_button, 2, 1);
|
||||
layout->addWidget(m_refresh_button, 3, 1);
|
||||
layout->addWidget(m_priority_up_button, 4, 1);
|
||||
layout->addWidget(m_priority_down_button, 5, 1);
|
||||
|
||||
layout->addWidget(buttons, 7, 1, Qt::AlignRight);
|
||||
setLayout(layout);
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
void ResourcePackManager::ConnectWidgets()
|
||||
{
|
||||
connect(m_open_directory_button, &QPushButton::pressed, this,
|
||||
&ResourcePackManager::OpenResourcePackDir);
|
||||
connect(m_refresh_button, &QPushButton::pressed, this, &ResourcePackManager::Refresh);
|
||||
connect(m_change_button, &QPushButton::pressed, this, &ResourcePackManager::Change);
|
||||
connect(m_remove_button, &QPushButton::pressed, this, &ResourcePackManager::Remove);
|
||||
connect(m_priority_up_button, &QPushButton::pressed, this, &ResourcePackManager::PriorityUp);
|
||||
connect(m_priority_down_button, &QPushButton::pressed, this, &ResourcePackManager::PriorityDown);
|
||||
|
||||
connect(m_table_widget, &QTableWidget::itemSelectionChanged, this,
|
||||
&ResourcePackManager::SelectionChanged);
|
||||
|
||||
connect(m_table_widget, &QTableWidget::itemDoubleClicked, this,
|
||||
&ResourcePackManager::ItemDoubleClicked);
|
||||
}
|
||||
|
||||
void ResourcePackManager::OpenResourcePackDir()
|
||||
{
|
||||
QDesktopServices::openUrl(
|
||||
QUrl::fromLocalFile(QString::fromStdString(File::GetUserPath(D_RESOURCEPACK_IDX))));
|
||||
}
|
||||
|
||||
void ResourcePackManager::RepopulateTable()
|
||||
{
|
||||
m_table_widget->clear();
|
||||
m_table_widget->setColumnCount(6);
|
||||
|
||||
m_table_widget->setHorizontalHeaderLabels({QStringLiteral(""), tr("Name"), tr("Version"),
|
||||
tr("Description"), tr("Author"), tr("Website")});
|
||||
|
||||
auto* header = m_table_widget->horizontalHeader();
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
header->setSectionResizeMode(i, QHeaderView::ResizeToContents);
|
||||
|
||||
header->setStretchLastSection(true);
|
||||
|
||||
int size = static_cast<int>(ResourcePack::GetPacks().size());
|
||||
|
||||
m_table_widget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_table_widget->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
|
||||
m_table_widget->setRowCount(size);
|
||||
m_table_widget->setIconSize(QSize(32, 32));
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
const auto& pack = ResourcePack::GetPacks()[size - 1 - i];
|
||||
auto* manifest = pack.GetManifest();
|
||||
|
||||
auto* logo_item = new QTableWidgetItem;
|
||||
auto* name_item = new QTableWidgetItem(QString::fromStdString(manifest->GetName()));
|
||||
auto* version_item = new QTableWidgetItem(QString::fromStdString(manifest->GetVersion()));
|
||||
auto* author_item = new QTableWidgetItem(
|
||||
QString::fromStdString(manifest->GetAuthors().value_or("Unknown author")));
|
||||
auto* description_item =
|
||||
new QTableWidgetItem(QString::fromStdString(manifest->GetDescription().value_or("")));
|
||||
auto* website_item =
|
||||
new QTableWidgetItem(QString::fromStdString(manifest->GetWebsite().value_or("")));
|
||||
|
||||
QPixmap logo;
|
||||
|
||||
logo.loadFromData(reinterpret_cast<const uchar*>(pack.GetLogo().data()),
|
||||
(int)pack.GetLogo().size());
|
||||
|
||||
logo_item->setIcon(QIcon(logo));
|
||||
|
||||
QFont link_font = website_item->font();
|
||||
|
||||
link_font.setUnderline(true);
|
||||
|
||||
website_item->setFont(link_font);
|
||||
website_item->setForeground(QBrush(Qt::blue));
|
||||
website_item->setData(Qt::UserRole, website_item->text());
|
||||
|
||||
for (auto* item :
|
||||
{logo_item, name_item, version_item, author_item, description_item, website_item})
|
||||
{
|
||||
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
||||
|
||||
if (ResourcePack::IsInstalled(pack))
|
||||
{
|
||||
item->setBackgroundColor(QColor(Qt::green));
|
||||
|
||||
auto font = item->font();
|
||||
font.setBold(true);
|
||||
item->setFont(font);
|
||||
}
|
||||
}
|
||||
|
||||
m_table_widget->setItem(i, 0, logo_item);
|
||||
m_table_widget->setItem(i, 1, name_item);
|
||||
m_table_widget->setItem(i, 2, version_item);
|
||||
m_table_widget->setItem(i, 3, description_item);
|
||||
m_table_widget->setItem(i, 4, author_item);
|
||||
m_table_widget->setItem(i, 5, website_item);
|
||||
}
|
||||
|
||||
SelectionChanged();
|
||||
}
|
||||
|
||||
void ResourcePackManager::Change()
|
||||
{
|
||||
auto items = m_table_widget->selectedItems();
|
||||
|
||||
if (items.empty())
|
||||
return;
|
||||
|
||||
if (ResourcePack::IsInstalled(ResourcePack::GetPacks()[items[0]->row()]))
|
||||
Uninstall();
|
||||
else
|
||||
Install();
|
||||
}
|
||||
|
||||
void ResourcePackManager::Install()
|
||||
{
|
||||
auto items = m_table_widget->selectedItems();
|
||||
|
||||
if (items.empty())
|
||||
return;
|
||||
|
||||
auto& item = ResourcePack::GetPacks()[m_table_widget->rowCount() - 1 - items[0]->row()];
|
||||
|
||||
bool success = item.Install(File::GetUserPath(D_USER_IDX));
|
||||
|
||||
if (!success)
|
||||
{
|
||||
QMessageBox::critical(
|
||||
this, tr("Error"),
|
||||
tr("Failed to install pack: %1").arg(QString::fromStdString(item.GetError())));
|
||||
}
|
||||
|
||||
RepopulateTable();
|
||||
}
|
||||
|
||||
void ResourcePackManager::Uninstall()
|
||||
{
|
||||
auto items = m_table_widget->selectedItems();
|
||||
|
||||
if (items.empty())
|
||||
return;
|
||||
|
||||
auto& item = ResourcePack::GetPacks()[m_table_widget->rowCount() - 1 - items[0]->row()];
|
||||
|
||||
bool success = item.Uninstall(File::GetUserPath(D_USER_IDX));
|
||||
|
||||
if (!success)
|
||||
{
|
||||
QMessageBox::critical(
|
||||
this, tr("Error"),
|
||||
tr("Failed to uninstall pack: %1").arg(QString::fromStdString(item.GetError())));
|
||||
}
|
||||
|
||||
RepopulateTable();
|
||||
}
|
||||
|
||||
void ResourcePackManager::Remove()
|
||||
{
|
||||
auto items = m_table_widget->selectedItems();
|
||||
|
||||
if (items.empty())
|
||||
return;
|
||||
|
||||
QMessageBox box(this);
|
||||
box.setWindowTitle(tr("Confirmation"));
|
||||
box.setText(tr("Are you sure you want to delete this pack?"));
|
||||
box.setIcon(QMessageBox::Warning);
|
||||
box.setStandardButtons(QMessageBox::Yes | QMessageBox::Abort);
|
||||
|
||||
if (box.exec() != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
Uninstall();
|
||||
File::Delete(
|
||||
ResourcePack::GetPacks()[m_table_widget->rowCount() - 1 - items[0]->row()].GetPath());
|
||||
RepopulateTable();
|
||||
}
|
||||
|
||||
void ResourcePackManager::PriorityDown()
|
||||
{
|
||||
auto items = m_table_widget->selectedItems();
|
||||
|
||||
if (items.empty())
|
||||
return;
|
||||
|
||||
int row = m_table_widget->rowCount() - 1 - items[0]->row();
|
||||
|
||||
if (items[0]->row() >= m_table_widget->rowCount())
|
||||
return;
|
||||
|
||||
auto& pack = ResourcePack::GetPacks()[row];
|
||||
std::string path = pack.GetPath();
|
||||
|
||||
row--;
|
||||
|
||||
ResourcePack::Remove(pack);
|
||||
ResourcePack::Add(path, row);
|
||||
|
||||
RepopulateTable();
|
||||
|
||||
m_table_widget->selectRow(row == 0 ? m_table_widget->rowCount() - 1 : row);
|
||||
}
|
||||
|
||||
void ResourcePackManager::PriorityUp()
|
||||
{
|
||||
auto items = m_table_widget->selectedItems();
|
||||
|
||||
if (items.empty())
|
||||
return;
|
||||
|
||||
int row = m_table_widget->rowCount() - 1 - items[0]->row();
|
||||
|
||||
if (items[0]->row() == 0)
|
||||
return;
|
||||
|
||||
auto& pack = ResourcePack::GetPacks()[row];
|
||||
std::string path = pack.GetPath();
|
||||
|
||||
row++;
|
||||
|
||||
ResourcePack::Remove(pack);
|
||||
ResourcePack::Add(path, items[0]->row() == m_table_widget->rowCount() ? -1 : row);
|
||||
|
||||
RepopulateTable();
|
||||
|
||||
m_table_widget->selectRow(row == m_table_widget->rowCount() - 1 ? 0 : row);
|
||||
}
|
||||
|
||||
void ResourcePackManager::Refresh()
|
||||
{
|
||||
ResourcePack::Init();
|
||||
RepopulateTable();
|
||||
}
|
||||
|
||||
void ResourcePackManager::SelectionChanged()
|
||||
{
|
||||
auto items = m_table_widget->selectedItems();
|
||||
|
||||
const bool has_selection = !items.empty();
|
||||
|
||||
if (has_selection)
|
||||
{
|
||||
m_change_button->setText(ResourcePack::IsInstalled(ResourcePack::GetPacks()[items[0]->row()]) ?
|
||||
tr("Uninstall") :
|
||||
tr("Install"));
|
||||
}
|
||||
|
||||
for (auto* item : {m_change_button, m_remove_button})
|
||||
item->setEnabled(has_selection);
|
||||
|
||||
m_priority_down_button->setEnabled(has_selection &&
|
||||
items[0]->row() < m_table_widget->rowCount() - 1);
|
||||
m_priority_up_button->setEnabled(has_selection && items[0]->row() != 0);
|
||||
}
|
||||
|
||||
void ResourcePackManager::ItemDoubleClicked(QTableWidgetItem* item)
|
||||
{
|
||||
auto item_data = item->data(Qt::UserRole);
|
||||
|
||||
if (item_data.isNull())
|
||||
return;
|
||||
|
||||
QDesktopServices::openUrl(QUrl(item_data.toString()));
|
||||
}
|
42
Source/Core/DolphinQt/ResourcePackManager.h
Normal file
42
Source/Core/DolphinQt/ResourcePackManager.h
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright 2018 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
class QPushButton;
|
||||
class QTableWidget;
|
||||
class QTableWidgetItem;
|
||||
|
||||
class ResourcePackManager : public QDialog
|
||||
{
|
||||
public:
|
||||
explicit ResourcePackManager(QWidget* parent = nullptr);
|
||||
|
||||
private:
|
||||
void CreateWidgets();
|
||||
void ConnectWidgets();
|
||||
void OpenResourcePackDir();
|
||||
void RepopulateTable();
|
||||
void Change();
|
||||
void Install();
|
||||
void Uninstall();
|
||||
void Remove();
|
||||
void PriorityUp();
|
||||
void PriorityDown();
|
||||
void Refresh();
|
||||
|
||||
void SelectionChanged();
|
||||
void ItemDoubleClicked(QTableWidgetItem* item);
|
||||
|
||||
QPushButton* m_open_directory_button;
|
||||
QPushButton* m_change_button;
|
||||
QPushButton* m_remove_button;
|
||||
QPushButton* m_refresh_button;
|
||||
QPushButton* m_priority_up_button;
|
||||
QPushButton* m_priority_down_button;
|
||||
|
||||
QTableWidget* m_table_widget;
|
||||
};
|
Reference in New Issue
Block a user