diff --git a/Fk/ModMaker/ModDetail.qml b/Fk/ModMaker/ModDetail.qml new file mode 100644 index 00000000..780d392a --- /dev/null +++ b/Fk/ModMaker/ModDetail.qml @@ -0,0 +1,139 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +Item { + id: root + property var mod: ({}) + property string modName + property string modPath: "mymod/" + modName + "/" + + onModNameChanged: { + mod = JSON.parse(ModBackend.readFile(modPath + "mod.json")); + } + + ToolBar { + id: bar + width: parent.width + RowLayout { + anchors.fill: parent + ToolButton { + icon.source: AppPath + "/image/modmaker/back" + onClicked: modStack.pop(); + } + Label { + text: qsTr("ModMaker") + " - " + modName + horizontalAlignment: Qt.AlignHCenter + Layout.fillWidth: true + } + ToolButton { + icon.source: AppPath + "/image/modmaker/menu" + onClicked: { + } + } + } + } + + Rectangle { + width: parent.width + height: parent.height - bar.height + anchors.top: bar.bottom + color: "snow" + opacity: 0.75 + + ListView { + anchors.fill: parent + model: mod.packages ?? [] + delegate: SwipeDelegate { + width: root.width + text: modelData + + swipe.right: Label { + id: deleteLabel + text: qsTr("Delete") + color: "white" + verticalAlignment: Label.AlignVCenter + padding: 12 + height: parent.height + anchors.right: parent.right + opacity: swipe.complete ? 1 : 0 + Behavior on opacity { NumberAnimation { } } + + SwipeDelegate.onClicked: deletePackage(modelData); + + background: Rectangle { + color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato" + } + } + } + } + } + + RoundButton { + anchors.right: parent.right + anchors.bottom: parent.bottom + anchors.margins: 40 + scale: 2 + icon.source: AppPath + "/image/modmaker/add" + onClicked: { + dialog.source = "CreateSomething.qml"; + dialog.item.head = "create_package"; + dialog.item.hint = "create_package_hint"; + drawer.open(); + dialog.item.accepted.connect((name) => { + createNewPackage(name); + }); + } + } + + Drawer { + id: drawer + width: parent.width * 0.4 / mainWindow.scale + height: parent.height / mainWindow.scale + dim: false + clip: true + dragMargin: 0 + scale: mainWindow.scale + transformOrigin: Item.TopLeft + + Loader { + id: dialog + anchors.fill: parent + onSourceChanged: { + if (item === null) + return; + item.finished.connect(() => { + sourceComponent = undefined; + drawer.close(); + }); + } + onSourceComponentChanged: sourceChanged(); + } + } + + function createNewPackage(name) { + const new_name = modName + "_" + name; + mod.packages = mod.packages ?? []; + if (mod.packages.indexOf(new_name) !== -1) { + toast.show(qsTr("cannot use this package name")); + return; + } + const path = modPath + new_name + "/"; + ModBackend.mkdir(path); + mod.packages.push(new_name); + ModBackend.saveToFile(modPath + "mod.json", JSON.stringify(mod, undefined, 2)); + const pkgInfo = { + name: new_name, + }; + ModBackend.saveToFile(path + "pkg.json", JSON.stringify(pkgInfo, undefined, 2)); + root.modChanged(); + } + + function deletePackage(name) { + const path = modPath + name + "/"; + ModBackend.rmrf(path); + mod.packages.splice(mod.packages.indexOf(name), 1); + ModBackend.saveToFile(modPath + "mod.json", JSON.stringify(mod, undefined, 2)); + root.modChanged(); + } +} diff --git a/Fk/ModMaker/ModInit.qml b/Fk/ModMaker/ModInit.qml index df3f98bb..0b2c5be6 100644 --- a/Fk/ModMaker/ModInit.qml +++ b/Fk/ModMaker/ModInit.qml @@ -50,6 +50,15 @@ Item { width: root.width text: modelData + onClicked: { + const component = Qt.createComponent("ModDetail.qml"); + if (component.status !== Component.Ready) { + return; + } + const page = component.createObject(null, { modName: modelData }); + modStack.push(page); + } + swipe.right: Label { id: deleteLabel text: qsTr("Delete") diff --git a/Fk/ModMaker/main.qml b/Fk/ModMaker/main.qml index 44793ad7..49a8e2b6 100644 --- a/Fk/ModMaker/main.qml +++ b/Fk/ModMaker/main.qml @@ -7,6 +7,7 @@ Item { StackView { id: modStack anchors.fill: parent + /* pushEnter: Transition { PropertyAnimation { property: "opacity" @@ -39,6 +40,7 @@ Item { duration: 200 } } + */ } ModConfig { diff --git a/lang/zh_CN.ts b/lang/zh_CN.ts index 9becc946..777b88a6 100644 --- a/lang/zh_CN.ts +++ b/lang/zh_CN.ts @@ -432,6 +432,14 @@ create_mod_hint 请输入mod的名称。 + + create_package + 新建拓展包 + + + create_package_hint + 请输入拓展包的内部名称。 + diff --git a/src/ui/mod.cpp b/src/ui/mod.cpp index eb27f8fa..940c393e 100644 --- a/src/ui/mod.cpp +++ b/src/ui/mod.cpp @@ -121,6 +121,14 @@ void ModMaker::saveToFile(const QString &fName, const QString &content) { c.close(); } +void ModMaker::mkdir(const QString &path) { + QDir(".").mkdir(path); +} + +void ModMaker::rmrf(const QString &path) { + QDir(path).removeRecursively(); +} + void ModMaker::createMod(const QString &name) { init(name); } diff --git a/src/ui/mod.h b/src/ui/mod.h index 6bbe6abe..87c920b7 100644 --- a/src/ui/mod.h +++ b/src/ui/mod.h @@ -14,6 +14,8 @@ public: Q_INVOKABLE QString readFile(const QString &fileName); Q_INVOKABLE void saveToFile(const QString &fileName, const QString &content); + Q_INVOKABLE void mkdir(const QString &path); + Q_INVOKABLE void rmrf(const QString &path); Q_INVOKABLE void createMod(const QString &name); Q_INVOKABLE void removeMod(const QString &name);