mirror of
https://github.com/Qsgs-Fans/FreeKill.git
synced 2024-11-16 03:32:34 +08:00
parent
cee3ec279d
commit
f24ea5dead
139
Fk/ModMaker/ModDetail.qml
Normal file
139
Fk/ModMaker/ModDetail.qml
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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")
|
||||
|
|
|
@ -7,6 +7,7 @@ Item {
|
|||
StackView {
|
||||
id: modStack
|
||||
anchors.fill: parent
|
||||
/*
|
||||
pushEnter: Transition {
|
||||
PropertyAnimation {
|
||||
property: "opacity"
|
||||
|
@ -39,6 +40,7 @@ Item {
|
|||
duration: 200
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
ModConfig {
|
||||
|
|
|
@ -432,6 +432,14 @@
|
|||
<source>create_mod_hint</source>
|
||||
<translation>请输入mod的名称。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>create_package</source>
|
||||
<translation>新建拓展包</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>create_package_hint</source>
|
||||
<translation>请输入拓展包的内部名称。</translation>
|
||||
</message>
|
||||
</context>
|
||||
|
||||
</TS>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user