ModMaker(鸽) (#216)

忘记进度如何了,总之合了吧
This commit is contained in:
notify 2023-07-01 23:18:07 +08:00 committed by GitHub
parent cee3ec279d
commit f24ea5dead
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 168 additions and 0 deletions

139
Fk/ModMaker/ModDetail.qml Normal file
View 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();
}
}

View File

@ -50,6 +50,15 @@ Item {
width: root.width width: root.width
text: modelData 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 { swipe.right: Label {
id: deleteLabel id: deleteLabel
text: qsTr("Delete") text: qsTr("Delete")

View File

@ -7,6 +7,7 @@ Item {
StackView { StackView {
id: modStack id: modStack
anchors.fill: parent anchors.fill: parent
/*
pushEnter: Transition { pushEnter: Transition {
PropertyAnimation { PropertyAnimation {
property: "opacity" property: "opacity"
@ -39,6 +40,7 @@ Item {
duration: 200 duration: 200
} }
} }
*/
} }
ModConfig { ModConfig {

View File

@ -432,6 +432,14 @@
<source>create_mod_hint</source> <source>create_mod_hint</source>
<translation>mod的名称</translation> <translation>mod的名称</translation>
</message> </message>
<message>
<source>create_package</source>
<translation></translation>
</message>
<message>
<source>create_package_hint</source>
<translation></translation>
</message>
</context> </context>
</TS> </TS>

View File

@ -121,6 +121,14 @@ void ModMaker::saveToFile(const QString &fName, const QString &content) {
c.close(); 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) { void ModMaker::createMod(const QString &name) {
init(name); init(name);
} }

View File

@ -14,6 +14,8 @@ public:
Q_INVOKABLE QString readFile(const QString &fileName); Q_INVOKABLE QString readFile(const QString &fileName);
Q_INVOKABLE void saveToFile(const QString &fileName, const QString &content); 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 createMod(const QString &name);
Q_INVOKABLE void removeMod(const QString &name); Q_INVOKABLE void removeMod(const QString &name);