diff --git a/source/funkin/editors/stager/StageCreationScreen.hx b/source/funkin/editors/stager/StageCreationScreen.hx new file mode 100644 index 00000000..f600de11 --- /dev/null +++ b/source/funkin/editors/stager/StageCreationScreen.hx @@ -0,0 +1,62 @@ +package funkin.editors.stager; + +typedef StageCreationData = { + var name:String; + var path:String; +} + +class StageCreationScreen extends UISubstateWindow { + private var onSave:Null -> Void = null; + + public var stageNameTextBox:UITextBox; + public var stagePathTextBox:UITextBox; + public var voicesExplorer:UIFileExplorer; + + public var saveButton:UIButton; + public var closeButton:UIButton; + + public function new(?onSave:StageCreationData->Void) { + super(); + if (onSave != null) this.onSave = onSave; + } + + public override function create() { + winTitle = "Creating New Stage"; + + winWidth = 748 - 32 + 40; + winHeight = 200; + + super.create(); + + function addLabelOn(ui:UISprite, text:String):UIText { + var text:UIText = new UIText(ui.x, ui.y - 24, 0, text); + ui.members.push(text); + return text; + } + + var stageInfo:UIText; + add(stageInfo = new UIText(windowSpr.x + 20, windowSpr.y + 30 + 16, 0, "Stage Info", 28)); + + add(stageNameTextBox = new UITextBox(stageInfo.x, stageInfo.y + stageInfo.height + 36, "Stage Name")); + addLabelOn(stageNameTextBox, "Stage Name"); + + add(stagePathTextBox = new UITextBox(stageNameTextBox.x + 320 + 26, stageNameTextBox.y, "Stage Path")); + addLabelOn(stagePathTextBox, "Stage Path"); + + add(saveButton = new UIButton(windowSpr.x + windowSpr.bWidth - 20 - 125, windowSpr.y + windowSpr.bHeight - 16 - 32, "Save & Close", function() { + saveStageInfo(); + close(); + }, 125)); + + add(closeButton = new UIButton(saveButton.x - 20 - saveButton.bWidth, saveButton.y, "Cancel", close, 125)); + closeButton.color = 0xFFFF0000; + } + + function saveStageInfo() { + if (onSave != null) onSave({ + name: stageNameTextBox.label.text, + path: stagePathTextBox.label.text + }); + } + +} \ No newline at end of file diff --git a/source/funkin/editors/stager/StageEditor.hx b/source/funkin/editors/stager/StageEditor.hx index beeb6c23..7a2557c8 100644 --- a/source/funkin/editors/stager/StageEditor.hx +++ b/source/funkin/editors/stager/StageEditor.hx @@ -298,7 +298,6 @@ class StageEditor extends UIState { // TODO: implement this } for (i=>sprite in order) { - trace(sprite, Type.getClassName(Type.getClass(sprite))); var xml = xmlMap.get(sprite); if(xml != null) { if(sprite is FunkinSprite) { diff --git a/source/funkin/editors/stager/StageSelection.hx b/source/funkin/editors/stager/StageSelection.hx index d53e5d12..726849bf 100644 --- a/source/funkin/editors/stager/StageSelection.hx +++ b/source/funkin/editors/stager/StageSelection.hx @@ -6,9 +6,12 @@ import funkin.options.type.IconOption; import funkin.options.type.NewOption; import funkin.options.type.OptionType; import funkin.options.type.TextOption; +import funkin.editors.stager.StageCreationScreen.StageCreationData; class StageSelection extends EditorTreeMenu { + public var stages:Array = []; + public override function create() { bgType = "charter"; @@ -17,17 +20,17 @@ class StageSelection extends EditorTreeMenu var modsList:Array = Stage.getList(true, true); var list:Array = [ - for (char in (modsList.length == 0 ? Stage.getList(false, true) : modsList)) - new TextOption(char, "Press ACCEPT to edit this stage.", + for (stage in (modsList.length == 0 ? Stage.getList(false, true) : modsList)) { + stages.push(stage); + new TextOption(stage, "Press ACCEPT to edit this stage.", function() { - FlxG.switchState(new StageEditor(char)); - }) + FlxG.switchState(new StageEditor(stage)); + }); + } ]; list.insert(0, new NewOption("New Stage", "New Stage", function() { - openSubState(new UIWarningSubstate("New Stage: Feature Not Implemented!", "This feature isnt implemented yet. Please wait for more cne updates to have this functional.\n\n\n- Codename Devs", [ - {label: "Ok", color: 0xFFFF0000, onClick: function(t) {}} - ])); + FlxG.state.openSubState(new StageCreationScreen(saveStage)); })); main = new OptionsScreen("Stage Editor", "Select a stage to edit. HSCRIPT only stages are not supported.", list); @@ -35,6 +38,26 @@ class StageSelection extends EditorTreeMenu DiscordUtil.call("onEditorTreeLoaded", ["Stage Editor"]); } + public function saveStage(creation:StageCreationData) { + if ([for (s in stages) s.toLowerCase()].contains(creation.name.toLowerCase())) { + openSubState(new UIWarningSubstate("Creating Stage: Error!", "The stage you are trying to create alreadly exists, if you would like to override it delete the stage first!", [ + {label: "Ok", color: 0xFFFF0000, onClick: function(t) {}} + ])); + return; + } + + #if sys + // Save File + CoolUtil.safeSaveFile('${Paths.getAssetsRoot()}/data/stages/${creation.name}.xml', '\n\n'); + #end + + // Add to List + var option = new TextOption(creation.name, "Press ACCEPT to edit this stage.", function() { + FlxG.switchState(new StageEditor(creation.name)); + }); + optionsTree.members[optionsTree.members.length-1].insert(1, option); + } + override function createPost() { super.createPost(); diff --git a/source/funkin/editors/ui/UISliceSprite.hx b/source/funkin/editors/ui/UISliceSprite.hx index 2de6aeb0..e1f91b8d 100644 --- a/source/funkin/editors/ui/UISliceSprite.hx +++ b/source/funkin/editors/ui/UISliceSprite.hx @@ -45,6 +45,12 @@ class UISliceSprite extends UISprite { var bottom:FlxFrame = null; var bottomright:FlxFrame = null; + override function set_frames(val) { + super.set_frames(val); + calculateFrames(); + return val; + } + function set_framesOffset(value:Int) { if(value != framesOffset) { framesOffset = value; @@ -54,6 +60,7 @@ class UISliceSprite extends UISprite { } function calculateFrames() { + if(frames == null) return; topleft = frames.frames[framesOffset]; top = frames.frames[framesOffset + 1]; topright = frames.frames[framesOffset + 2];