Added XML Editing of anything

This commit is contained in:
NeeEoo
2024-04-17 22:20:55 +02:00
parent 75e3ab79c5
commit 7c60a4e632
8 changed files with 126 additions and 7 deletions
@@ -1,4 +1,5 @@
<window width="1056" height="520" title="Editing Sprite ${button.getName()}">
<set name="MARGIN" value="20" />
<set name="XOFFSET" value="50" />
<set name="YOFFSET" value="40" />
<set name="TO" value="64" />
@@ -24,7 +25,7 @@
<textbox name="nameTextBox" label="Name Identifier" value="button.getName()" x="col(0)" y="curY" width="200" height="32" />
<textbox name="spriteTextBox" value="getEx('imageFile')" x="last.x + last.bWidth + XOFFSET" y="curY" width="200" height="32" />
<stepper name="alphaStepper" label="Alpha" value="sprite.alpha" x="spriteTextBox.x + spriteTextBox.bWidth + XOFFSET" y="curY" precision="2" step="0.01" width="100" />
<label name="imageFile" text="Image File&#10;In (${stage.spritesParentFolder})" x="spriteTextBox.x" y="spriteTextBox.y - 14" size="15" />
<label name="imageFile" text="Image File (WIP: needs reload)&#10;In (${stage.spritesParentFolder})" x="spriteTextBox.x" y="spriteTextBox.y - 14" size="15" />
</section>
<section> <!-- ROW 2 -->
@@ -67,6 +68,44 @@
<!-- TODO: Animation list -->
</section>
<section> <!-- RIGHT SIDE -->
<set name="curY" value="title.y + TO" />
<set name="listWidth" value="250" />
<buttonlist name="animations" label="Animations (TODO)" x="col(3)" y="curY" width="listWidth" height="330" buttonSizeX="listWidth-10" buttonSizeY="35" buttonSpacing="5">
<texture path="editors/ui/inputbox" />
<camSpacing value="0" />
<code>
buttonlist.addButton.exists = false;
</code>
<!-- <code>
import funkin.editors.extra.PropertyButton;
var buttonList = buttonlist; // important for now, since it gets reset after the code is run
var width = buttonList.buttonSize.x;
var height = buttonList.buttonSize.y;
buttonList.addButton.callback = function() {
buttonList.add(new PropertyButton("newProperty", "valueHere", buttonList, width, height, 150, 220, 25));
}
//var defaultAttribs = Stage.DEFAULT_ATTRIBUTES;
//for (i in stage.stageXML.attributes()) {
// trace(i, defaultAttribs);
// if (!defaultAttribs.contains(i))
// buttonList.add(new PropertyButton(i, stage.stageXML.get(i), buttonList, width, height, 150, 220, 25));
//}
for(key =&gt; val in stage.extra)
buttonList.add(new PropertyButton(key, val, buttonList, width, height, 150, 220, 25));
</code> -->
</buttonlist>
<text text="Tip: To access custom properties,&#10;hold shift when clicking edit" x="col(2) - 60" y="self.winHeight - 50" size="15" />
</section>
<!-- Preview Transform -->
@@ -0,0 +1,51 @@
<window width="450" height="570" title="Editing XML ${type}">
<!-- BASED ON unknownEditScreen.xml -->
<set name="MARGIN" value="20" />
<set name="XOFFSET" value="30" />
<set name="YOFFSET" value="40" />
<set name="TO" value="64" />
<exec>
function col(c:Int) {
return MARGIN + (150 + XOFFSET) * c;
}
</exec>
<title name="title" x="MARGIN" y="30 + 16" text="Xml Data" />
<section>
<set name="curY" value="title.y + TO" />
<set name="listWidth" value="self.winWidth - MARGIN * 2" />
<buttonlist name="attributesList" label="Attributes" x="col(0)" y="curY" width="listWidth" height="400" buttonSizeX="listWidth-10" buttonSizeY="35" buttonSpacing="5">
<texture path="editors/ui/inputbox" />
<camSpacing value="0" />
<code>
import funkin.editors.extra.PropertyButton;
var buttonList = buttonlist; // important for now, since it gets reset after the code is run
var width = buttonList.buttonSize.x;
var height = buttonList.buttonSize.y;
buttonList.addButton.callback = function() {
buttonList.add(new PropertyButton("newProperty", "valueHere", buttonList, width, height, 160, 195, 25));
}
for (i in xml.attributes())
buttonList.add(new PropertyButton(i, xml.get(i), buttonList, width, height, 160, 195, 25));
</code>
</buttonlist>
</section>
<exec>
function onSave() {
for (i in xml.attributes())
xml.remove(i);
for (val in attributesList.buttons.members)
xml.set(val.propertyText.label.text, val.valueText.label.text);
}
</exec>
</window>
@@ -1210,4 +1210,25 @@ enum abstract StageEditorEdge(Int) {
case BOTTOM_RIGHT: "BOTTOM_RIGHT";
}
}
}
class StageXMLEditScreen extends UISoftcodedWindow {
public var xml:Access;
public var saveCallback:Void->Void;
public function new(xml:Access, saveCallback:Void->Void, type:String = "Unknown") {
this.xml = xml;
this.saveCallback = saveCallback;
super("layouts/stage/xmlEditScreen", [
"stage" => StageEditor.instance.stage,
"xml" => xml,
"exID" => StageEditor.exID,
"type" => type
]);
}
override function saveData() {
super.saveData();
if(saveCallback != null) saveCallback();
}
}
@@ -3,7 +3,6 @@ package funkin.editors.stage;
import funkin.editors.stage.StageCreationScreen.StageCreationData;
import funkin.game.Stage;
import funkin.options.OptionsScreen;
import funkin.options.type.IconOption;
import funkin.options.type.NewOption;
import funkin.options.type.OptionType;
import funkin.options.type.TextOption;
@@ -1,5 +1,6 @@
package funkin.editors.stage.elements;
import funkin.editors.stage.StageEditor.StageXMLEditScreen;
import funkin.game.Character;
import funkin.game.Stage.StageCharPos;
import haxe.xml.Access;
@@ -44,7 +45,11 @@ class StageCharacterButton extends StageElementButton {
}*/
public override function onEdit() {
FlxG.state.openSubState(new StageCharacterEditScreen(this));
if(!FlxG.keys.pressed.SHIFT) {
FlxG.state.openSubState(new StageCharacterEditScreen(this));
} else {
FlxG.state.openSubState(new StageXMLEditScreen(this.xml, updateInfo, "Character"));
}
}
//public override function onEdit() {
@@ -1,7 +1,7 @@
package funkin.editors.stage.elements;
import haxe.xml.Access;
import flixel.util.FlxColor;
import haxe.xml.Access;
using flixel.util.FlxColorTransformUtil;
@@ -1,7 +1,7 @@
package funkin.editors.stage.elements;
import haxe.xml.Access;
import flixel.util.FlxColor;
import haxe.xml.Access;
class StageSolidButton extends StageSpriteButton {
@@ -1,6 +1,6 @@
package funkin.editors.stage.elements;
import flixel.util.FlxColor;
import funkin.editors.stage.StageEditor.StageXMLEditScreen;
import funkin.editors.stage.elements.StageElementButton;
import funkin.editors.ui.UISoftcodedWindow;
import haxe.xml.Access;
@@ -40,7 +40,11 @@ class StageSpriteButton extends StageElementButton {
}
public override function onEdit() {
FlxG.state.openSubState(new StageSpriteEditScreen(this));
if(!FlxG.keys.pressed.SHIFT) {
FlxG.state.openSubState(new StageSpriteEditScreen(this));
} else {
FlxG.state.openSubState(new StageXMLEditScreen(this.xml, updateInfo, "Sprite"));
}
}
public override function onDelete() {