add button for opening mod folder
This commit is contained in:
+2
-2
@@ -4,7 +4,7 @@ project(Minecraft_launcher VERSION 0.1 LANGUAGES CXX)
|
|||||||
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
find_package(Qt6 REQUIRED COMPONENTS Quick Core)
|
find_package(Qt6 REQUIRED COMPONENTS Quick Core Gui)
|
||||||
|
|
||||||
qt_standard_project_setup(REQUIRES 6.8)
|
qt_standard_project_setup(REQUIRES 6.8)
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ set_target_properties(appMinecraft_launcher PROPERTIES
|
|||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(appMinecraft_launcher
|
target_link_libraries(appMinecraft_launcher
|
||||||
PRIVATE Qt6::Quick Qt6::Core
|
PRIVATE Qt6::Quick Qt6::Core Qt6::Gui
|
||||||
)
|
)
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|||||||
@@ -450,6 +450,31 @@ Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Open mods folder button ────────────────────────────────────────────
|
||||||
|
Button {
|
||||||
|
id: folderButton
|
||||||
|
width: 42
|
||||||
|
height: 42
|
||||||
|
anchors.left: versionBox.right
|
||||||
|
anchors.leftMargin: 8
|
||||||
|
anchors.verticalCenter: versionBox.verticalCenter
|
||||||
|
hoverEnabled: true
|
||||||
|
|
||||||
|
background: Image {
|
||||||
|
id: folderButtonImage
|
||||||
|
anchors.fill: parent
|
||||||
|
source: folderButton.pressed ? "images/Folder/Folder_Pressed.svg"
|
||||||
|
: folderButton.hovered ? "images/Folder/Folder_Active.svg"
|
||||||
|
: "images/Folder/Folder_Idle.svg"
|
||||||
|
fillMode: Image.PreserveAspectFit
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolTip.visible: hovered
|
||||||
|
ToolTip.text: qsTr("Открыть папку с модами Minecraft")
|
||||||
|
|
||||||
|
onClicked: backend.openMinecraftFolder()
|
||||||
|
}
|
||||||
|
|
||||||
// ── Add Profile Dialog ─────────────────────────────────────────────────
|
// ── Add Profile Dialog ─────────────────────────────────────────────────
|
||||||
// Bug fix: header/footer must be Item (not Rectangle) with explicit
|
// Bug fix: header/footer must be Item (not Rectangle) with explicit
|
||||||
// implicitHeight so Dialog correctly computes its own total height.
|
// implicitHeight so Dialog correctly computes its own total height.
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
#include "launcherbackend.h"
|
#include "launcherbackend.h"
|
||||||
|
|
||||||
|
#include <QDesktopServices>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include <QUrl>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
LauncherBackend::LauncherBackend(QObject *parent)
|
LauncherBackend::LauncherBackend(QObject *parent)
|
||||||
@@ -117,6 +119,26 @@ void LauncherBackend::launchGame(int profileIndex, int versionIndex)
|
|||||||
emit launched(profile.name, version.name, version.serverUrl);
|
emit launched(profile.name, version.name, version.serverUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString LauncherBackend::minecraftDir() const
|
||||||
|
{
|
||||||
|
#if defined(Q_OS_WIN)
|
||||||
|
return QDir::homePath() + "/AppData/Roaming/.minecraft";
|
||||||
|
#elif defined(Q_OS_MACOS)
|
||||||
|
return QDir::homePath() + "/Library/Application Support/minecraft";
|
||||||
|
#else // Linux и прочие Unix-системы
|
||||||
|
return QDir::homePath() + "/.minecraft";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void LauncherBackend::openMinecraftFolder()
|
||||||
|
{
|
||||||
|
const QString modsDir = minecraftDir() + "/mods";
|
||||||
|
QDir().mkpath(modsDir);
|
||||||
|
|
||||||
|
if (!QDesktopServices::openUrl(QUrl::fromLocalFile(modsDir)))
|
||||||
|
emit launchError("Не удалось открыть папку с модами");
|
||||||
|
}
|
||||||
|
|
||||||
void LauncherBackend::loadData()
|
void LauncherBackend::loadData()
|
||||||
{
|
{
|
||||||
auto loadFile = [](const QString &path, auto handler) {
|
auto loadFile = [](const QString &path, auto handler) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public:
|
|||||||
Q_INVOKABLE void removeProfile(int index);
|
Q_INVOKABLE void removeProfile(int index);
|
||||||
Q_INVOKABLE void removeVersion(int index);
|
Q_INVOKABLE void removeVersion(int index);
|
||||||
Q_INVOKABLE void launchGame(int profileIndex, int versionIndex);
|
Q_INVOKABLE void launchGame(int profileIndex, int versionIndex);
|
||||||
|
Q_INVOKABLE void openMinecraftFolder();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void profilesChanged();
|
void profilesChanged();
|
||||||
@@ -42,6 +43,7 @@ private:
|
|||||||
void loadData();
|
void loadData();
|
||||||
void saveProfiles();
|
void saveProfiles();
|
||||||
void saveVersions();
|
void saveVersions();
|
||||||
|
QString minecraftDir() const;
|
||||||
|
|
||||||
QList<Profile> m_profiles;
|
QList<Profile> m_profiles;
|
||||||
QList<Version> m_versions;
|
QList<Version> m_versions;
|
||||||
|
|||||||
Reference in New Issue
Block a user