From 7385e42db52395dff75304b24c8f0bf6e29c3fc8 Mon Sep 17 00:00:00 2001 From: lunarcleint <88809950+lunarcleint@users.noreply.github.com> Date: Mon, 22 Jul 2024 00:50:42 -0700 Subject: [PATCH] ghost anims and stuffers --- .../editors/character/CharacterAnimButton.hx | 14 ++++++- .../editors/character/CharacterAnimsWindow.hx | 16 +++++++- .../editors/character/CharacterEditor.hx | 14 +++---- .../editors/character/CharacterGhost.hx | 39 +++++++++++++++++++ source/funkin/game/Character.hx | 17 +++++--- 5 files changed, 83 insertions(+), 17 deletions(-) create mode 100644 source/funkin/editors/character/CharacterGhost.hx diff --git a/source/funkin/editors/character/CharacterAnimButton.hx b/source/funkin/editors/character/CharacterAnimButton.hx index 5a574e5c..49d44bab 100644 --- a/source/funkin/editors/character/CharacterAnimButton.hx +++ b/source/funkin/editors/character/CharacterAnimButton.hx @@ -147,7 +147,7 @@ class CharacterAnimButton extends UIButton { deleteIcon.antialiasing = false; members.push(deleteIcon); - editButton = new UIButton(0, 0, "", () -> {this.closed = !this.closed; this.update(0);}, 28,24); + editButton = new UIButton(0, 0, "", () -> {this.closed = !this.closed;}, 28,24); editButton.frames = Paths.getFrames("editors/ui/grayscale-button"); editButton.color = 0xFFAFAA12; members.push(editButton); @@ -157,7 +157,7 @@ class CharacterAnimButton extends UIButton { editIcon.antialiasing = false; members.push(editIcon); - ghostButton = new UIButton(0, 0, "", null, 28, 24); + ghostButton = new UIButton(0, 0, "", toggleGhost, 28, 24); ghostButton.frames = Paths.getFrames("editors/ui/grayscale-button"); ghostButton.color = 0xFFADADAD; ghostButton.alpha = 0.5; @@ -363,6 +363,16 @@ class CharacterAnimButton extends UIButton { } } + public function toggleGhost() { + if (parent.ghosts.indexOf(anim) == -1) { + parent.ghosts.push(anim); + ghostIcon.animation.play("alive", true); + } else { + parent.ghosts.remove(anim); + ghostIcon.animation.play("dead", true); + } + } + public override function draw() { updateButtonsPos(); super.draw(); diff --git a/source/funkin/editors/character/CharacterAnimsWindow.hx b/source/funkin/editors/character/CharacterAnimsWindow.hx index 0fea6514..caf959f1 100644 --- a/source/funkin/editors/character/CharacterAnimsWindow.hx +++ b/source/funkin/editors/character/CharacterAnimsWindow.hx @@ -9,7 +9,7 @@ import funkin.game.Character; using funkin.backend.utils.BitmapUtil; class CharacterAnimsWindow extends UIButtonList { - public var character:Character; + public var character:CharacterGhost; public var displayWindowSprite:FlxSprite; public var displayWindowGraphic:FlxGraphic; @@ -17,7 +17,7 @@ class CharacterAnimsWindow extends UIButtonList { public var animButtons:Map = []; - public function new(x:Float, y:Float, character:Character) { + public function new(x:Float, y:Float, character:CharacterGhost) { super(x, y, Std.int(500-16), 419, "", FlxPoint.get(Std.int(500-16-32), 208)); cameraSpacing = 0; @@ -46,6 +46,18 @@ class CharacterAnimsWindow extends UIButtonList { this.character = character; } + public var ghosts:Array = []; + public override function update(elapsed:Float) { + super.update(elapsed); + + // if (CharacterEditor.instance.draggingCharacter && ghosts[0] != character.getAnimName()) { + // if (ghosts.indexOf(character.getAnimName()) != -1) + // ghosts.remove(character.getAnimName()); + // ghosts.insert(0, character.getAnimName()); + // } + character.ghosts = ghosts; + } + public function buildAnimDisplay(name:String, anim:FlxAnimation) { var frameIndex:Int = anim.frames.getDefault([0])[0]; var frame:FlxFrame = displayWindowSprite.frames.frames[frameIndex]; diff --git a/source/funkin/editors/character/CharacterEditor.hx b/source/funkin/editors/character/CharacterEditor.hx index 7a8267ca..0ec7c473 100644 --- a/source/funkin/editors/character/CharacterEditor.hx +++ b/source/funkin/editors/character/CharacterEditor.hx @@ -17,7 +17,7 @@ import funkin.editors.extra.DrawAxis; class CharacterEditor extends UIState { static var __character:String; - public var character:Character; + public var character:CharacterGhost; public static var instance(get, null):CharacterEditor; @@ -246,7 +246,7 @@ class CharacterEditor extends UIState { FlxG.cameras.add(uiCamera); - character = new Character(0,0, __character, false, false); + character = new CharacterGhost(0,0, __character, false, false); character.debugMode = true; character.cameras = [charCamera]; @@ -313,8 +313,8 @@ class CharacterEditor extends UIState { var _nextScroll:FlxPoint = FlxPoint.get(0,0); var _cameraZoomMulti:Float = 1; - var draggingCharacter:Bool = false; - var draggingOffset:FlxPoint = new FlxPoint(); + public var draggingCharacter:Bool = false; + public var draggingOffset:FlxPoint = new FlxPoint(); public override function update(elapsed:Float) { if(FlxG.keys.justPressed.ANY) UIUtil.processShortcuts(topMenu); @@ -383,9 +383,6 @@ class CharacterEditor extends UIState { if (draggingCharacter) { cameraHoverDummy.cursor = #if (mac) DRAG; #elseif (linux) DRAG; #elseif MOVE; #end - draggingOffset.x += FlxG.mouse.deltaScreenX; draggingOffset.y += FlxG.mouse.deltaScreenY; - character.extraOffset = draggingOffset; - if (FlxG.mouse.justReleased) { draggingOffset.x /= character.scale.x; draggingOffset.y /= character.scale.y; @@ -394,6 +391,9 @@ class CharacterEditor extends UIState { draggingOffset.set(0, 0); draggingCharacter = false; character.extraOffset = draggingOffset; + } else { + draggingOffset.x += FlxG.mouse.deltaScreenX; draggingOffset.y += FlxG.mouse.deltaScreenY; + character.extraOffset = draggingOffset; } } } diff --git a/source/funkin/editors/character/CharacterGhost.hx b/source/funkin/editors/character/CharacterGhost.hx new file mode 100644 index 00000000..1fb8efaa --- /dev/null +++ b/source/funkin/editors/character/CharacterGhost.hx @@ -0,0 +1,39 @@ +package funkin.editors.character; + +import flixel.animation.FlxAnimation; +import funkin.game.Character; + +class CharacterGhost extends Character { + public var ghosts:Array = []; + public override function draw() { + ghostDraw = true; + + if (animateAtlas != null) {} + else { + for (anim in ghosts) @:privateAccess { + alpha = 0.4; color = 0xFFAEAEAE; + + var flxanim:FlxAnimation = animation._animations.get(anim); + var frameIndex:Int = flxanim.frames.getDefault([0])[0]; + frame = frames.frames[frameIndex]; + + setAnimOffset(anim); + super.draw(); + } + + frame = frames.frames[animation.frameIndex]; + } + + setAnimOffset(animation.name); + alpha = 1; color = 0xFFFFFFFF; + ghostDraw = false; super.draw(); + } + + public function setAnimOffset(anim:String) { + var daOffset:FlxPoint = animOffsets.get(anim); + frameOffset.set(daOffset.x, daOffset.y); + daOffset.putWeak(); + + offset.set(globalOffset.x * (isPlayer != playerOffsets ? 1 : -1), -globalOffset.y); + } +} \ No newline at end of file diff --git a/source/funkin/game/Character.hx b/source/funkin/game/Character.hx index eb2e8ca7..38fbee96 100644 --- a/source/funkin/game/Character.hx +++ b/source/funkin/game/Character.hx @@ -195,9 +195,12 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset public function isFlippedOffsets() return (isPlayer != playerOffsets) != (flipX != __baseFlipped); + public var ghostDraw:Bool = false; public override function draw() { - x += extraOffset.x; - y += extraOffset.y; + if (!ghostDraw) { + x += extraOffset.x; + y += extraOffset.y; + } if (isFlippedOffsets()) { __reverseDrawProcedure = true; @@ -211,11 +214,13 @@ class Character extends FunkinSprite implements IBeatReceiver implements IOffset __reverseDrawProcedure = false; } else super.draw(); - x -= extraOffset.x; - y -= extraOffset.y; + if (!ghostDraw) { + x -= extraOffset.x; + y -= extraOffset.y; - if (debugHitbox) drawHitbox(); - if (debugCamera) drawCamera(); + if (debugHitbox) drawHitbox(); + if (debugCamera) drawCamera(); + } } public var debugHitbox:Bool = false;