diff --git a/assets/data/editors/layouts/stage/characterEditScreen.xml b/assets/data/editors/layouts/stage/characterEditScreen.xml index b6674370..22b64ac5 100644 --- a/assets/data/editors/layouts/stage/characterEditScreen.xml +++ b/assets/data/editors/layouts/stage/characterEditScreen.xml @@ -52,6 +52,10 @@ + +
+ +
diff --git a/source/funkin/editors/stage/StageEditor.hx b/source/funkin/editors/stage/StageEditor.hx index e0e4fc33..2e73cc54 100644 --- a/source/funkin/editors/stage/StageEditor.hx +++ b/source/funkin/editors/stage/StageEditor.hx @@ -305,27 +305,32 @@ class StageEditor extends UIState { members.insert(newID, sprite); } stageSpritesWindow.addButton.callback = () -> { - var node:Access = new Access(Xml.createElement("sprite")); - stage.stageXML.x.addChild(node.x); - node.att.name = "sprite_" + stageSpritesWindow.buttons.length; - - var sprite:FunkinSprite = new FunkinSprite(); - add(sprite); - sprite.extra.set(exID("node"), node); - sprite.extra.set(exID("type"), node.name); - sprite.extra.set(exID("imageFile"), ''); - sprite.extra.set(exID("parentNode"), new Access(node.x.parent)); - sprite.extra.set(exID("highMemory"), false); - sprite.extra.set(exID("lowMemory"), false); - xmlMap.set(sprite, node); - - var button:StageSpriteButton = new StageSpriteButton(0, 0, sprite, node); - sprite.extra.set(exID("button"), button); - stageSpritesWindow.add(button); - - var substate = new StageSpriteEditScreen(button); - substate.newSprite = true; - openSubState(substate); + var lastDrawCam = stageSpritesWindow.addButton.__lastDrawCameras[0]; + var screenPos = stageSpritesWindow.addButton.getScreenPosition(null, lastDrawCam == null ? FlxG.camera : lastDrawCam); + openContextMenu([ + { + label: "Sprite", + onSelect: _sprite_new, + color: 0xFF00FF00, + icon: 2 + }, + { + label: "Box", + onSelect: function(_) { + UIState.state.displayNotification(new UIBaseNotification("Creating a box isnt implemented yet!", 2, BOTTOM_LEFT)); + CoolUtil.playMenuSFX(WARNING, 0.45); + }, + color: 0xFF00FF00, + icon: 2 + }, + { + label: "Character", + onSelect: _character_new, + color: 0xFF00FF00, + icon: 2 + } + ], null, lastDrawCam.x + screenPos.x, lastDrawCam.y + screenPos.y + stageSpritesWindow.addButton.bHeight, stageSpritesWindow.addButton.bWidth); + screenPos.put(); } for (i=>sprite in order) { var xml = (sprite != null) ? xmlMap.get(sprite) : orderNodes[i]; @@ -478,6 +483,78 @@ class StageEditor extends UIState { undos.save(); } + function _sprite_new(_) { + var node:Access = new Access(Xml.createElement("sprite")); + stage.stageXML.x.addChild(node.x); + node.att.name = "sprite_" + stageSpritesWindow.buttons.length; + + var sprite:FunkinSprite = new FunkinSprite(); + insert(members.indexOf(stage), sprite); + sprite.extra.set(exID("node"), node); + sprite.extra.set(exID("type"), node.name); + sprite.extra.set(exID("imageFile"), ''); + sprite.extra.set(exID("parentNode"), stage.stageXML.x); + sprite.extra.set(exID("highMemory"), false); + sprite.extra.set(exID("lowMemory"), false); + xmlMap.set(sprite, node); + + var button:StageSpriteButton = new StageSpriteButton(0, 0, sprite, node); + sprite.extra.set(exID("button"), button); + stageSpritesWindow.add(button); + + var substate = new StageSpriteEditScreen(button); + substate.newSprite = true; + openSubState(substate); + } + + function _character_new(_) { + var node:Access = new Access(Xml.createElement("char")); + stage.stageXML.x.addChild(node.x); + node.att.name = "character_" + stageSpritesWindow.buttons.length; + + var charPos = new StageCharPos(); + charPos.visible = charPos.active = false; + charPos.name = "character_" + stageSpritesWindow.buttons.length; + charPos.extra.set(exID("extraChar"), true); + stage.characterPoses[charPos.name] = charPos; + + var char = new Character(0,0, "bf", stage.isCharFlipped(charPos.name, true), true); + char.name = "bf"; + char.debugMode = true; + // Play first anim, and make it the last frame + var animToPlay = char.getAnimOrder()[0]; + char.playAnim(animToPlay, true, NONE); + var lastIndx = (char.animateAtlas != null) ? + char.animateAtlas.anim.length - 1 : + char.animation.curAnim.numFrames - 1; + char.playAnim(animToPlay, true, NONE, false, lastIndx); + char.stopAnimation(); + + // Add it to the stage + char.visible = true; + char.alpha = 0.5; + function setEx(name:String, value:Dynamic) { + char.extra.set(exID(name), value); + charPos.extra.set(exID(name), value); + } + setEx("node", node); + setEx("pos", charPos); + setEx("char", char); + + setEx("parentNode", stage.stageXML); + setEx("highMemory", false); + setEx("lowMemory", false); + chars.push(char); + + stage.applyCharStuff(char, charPos.name, 0); + charMap[charPos.name] = char; + + var button = new StageCharacterButton(0,0, charPos, node); + char.extra.set(exID("button"), button); + charPos.extra.set(exID("button"), button); + stageSpritesWindow.add(button); + } + function saveToXml(xml:Xml, name:String, value:Dynamic, ?defaultValue:Dynamic) { if(value == null || value == defaultValue) return xml; xml.set(name, Std.string(value)); diff --git a/source/funkin/editors/ui/UIContextMenu.hx b/source/funkin/editors/ui/UIContextMenu.hx index 8cc5bcb0..36db45ab 100644 --- a/source/funkin/editors/ui/UIContextMenu.hx +++ b/source/funkin/editors/ui/UIContextMenu.hx @@ -7,6 +7,7 @@ class UIContextMenu extends MusicBeatSubstate { public var options:Array; var x:Float; var y:Float; + var w:Int = 100; var contextCam:FlxCamera; var bg:UISliceSprite; @@ -21,11 +22,12 @@ class UIContextMenu extends MusicBeatSubstate { __oobDeletion = false; } - public function new(options:Array, callback:UIContextMenuCallback, x:Float, y:Float) { + public function new(options:Array, callback:UIContextMenuCallback, x:Float, y:Float, ?w:Int = 100) { super(); this.options = options.getDefault([]); this.x = x; this.y = y; + this.w = w; this.callback = callback; } @@ -37,7 +39,7 @@ class UIContextMenu extends MusicBeatSubstate { contextCam.scroll.set(0, 7.5); FlxG.cameras.add(contextCam, false); - bg = new UISliceSprite(x, y, 100, 100, 'editors/ui/context-bg'); + bg = new UISliceSprite(x, y, w, 100, 'editors/ui/context-bg'); bg.cameras = [contextCam]; add(bg); diff --git a/source/funkin/editors/ui/UIState.hx b/source/funkin/editors/ui/UIState.hx index c1716104..e2e580af 100644 --- a/source/funkin/editors/ui/UIState.hx +++ b/source/funkin/editors/ui/UIState.hx @@ -136,7 +136,7 @@ class UIState extends MusicBeatState { } } - public function openContextMenu(options:Array, ?callback:UIContextMenuCallback, ?x:Float, ?y:Float) { + public function openContextMenu(options:Array, ?callback:UIContextMenuCallback, ?x:Float, ?y:Float, ?w:Int) { var state = FlxG.state; while(state.subState != null && !(state._requestSubStateReset && state._requestedSubState == null)) state = state.subState; @@ -144,7 +144,7 @@ class UIState extends MusicBeatState { state.persistentDraw = true; state.persistentUpdate = true; - state.openSubState(curContextMenu = new UIContextMenu(options, callback, x.getDefault(__mousePos.x), y.getDefault(__mousePos.y))); + state.openSubState(curContextMenu = new UIContextMenu(options, callback, x.getDefault(__mousePos.x), y.getDefault(__mousePos.y), w)); return curContextMenu; }