From a69244c6af2abee85cafb5a48a9cd63abd91bf91 Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Sun, 25 Dec 2022 22:17:52 +0100 Subject: [PATCH] drop down --- buildnumber.txt | 2 +- source/funkin/desktop/DesktopMain.hx | 3 +- .../funkin/desktop/editors/CharacterEditor.hx | 21 +++++++ source/funkin/desktop/sprites/DropDown.hx | 38 ++++++++++++ source/funkin/desktop/sprites/TabView.hx | 4 +- source/funkin/desktop/windows/ContextMenu.hx | 16 ++--- .../desktop/windows/WindowDragHitbox.hx | 2 +- source/funkin/game/Character.hx | 58 +++++++++++++++++-- source/funkin/system/CoolUtil.hx | 12 ++++ 9 files changed, 139 insertions(+), 17 deletions(-) create mode 100644 source/funkin/desktop/sprites/DropDown.hx diff --git a/buildnumber.txt b/buildnumber.txt index 63d53b76..a10e1ce0 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1769 \ No newline at end of file +1785 \ No newline at end of file diff --git a/source/funkin/desktop/DesktopMain.hx b/source/funkin/desktop/DesktopMain.hx index 68fc4bd6..986159f2 100644 --- a/source/funkin/desktop/DesktopMain.hx +++ b/source/funkin/desktop/DesktopMain.hx @@ -77,6 +77,7 @@ class DesktopMain extends MusicBeatState { super.update(elapsed); + if (screenSize.x != FlxG.width || screenSize.y != FlxG.height) { screenSize.set(FlxG.width, FlxG.height); updateScreenRes(); @@ -174,7 +175,7 @@ class MouseInput { public function overlapsRect(spr:FlxBasic, rect:FlxRect, ?camera:FlxCamera) { if (__cancelled) return false; if (camera == null) camera = FlxG.camera; - if (spr is FlxObject) { + if (spr is FlxObject && camera != null) { var obj = cast(spr, FlxObject); rect.x -= camera.scroll.x * obj.scrollFactor.x; rect.y -= camera.scroll.y * obj.scrollFactor.y; diff --git a/source/funkin/desktop/editors/CharacterEditor.hx b/source/funkin/desktop/editors/CharacterEditor.hx index 85adce7a..2475ae36 100644 --- a/source/funkin/desktop/editors/CharacterEditor.hx +++ b/source/funkin/desktop/editors/CharacterEditor.hx @@ -17,6 +17,13 @@ class CharacterEditor extends WindowContent { public var camFollow:FlxObject; public var tabView:TabView; + public var animList:Array = []; + + /** + * ANIMATION TAB + */ + public var animsDropDown:DropDown; + public override function create() { super.create(); @@ -58,6 +65,20 @@ class CharacterEditor extends WindowContent { tabView = new TabView(800, 20, 400, 580, ["Animation Settings", "Character Settings"]); tabView.updateAnchor(1, 0, [camHUD]); add(tabView); + + animsDropDown = new DropDown(10, 10, [], function(id) { + char.playAnim(animList[id], true); + }); + refreshAnims(); + + for(spr in [animsDropDown]) + tabView.tabs[0].add(spr); + } + + public function refreshAnims() { + @:privateAccess animList = [for(k=>e in char.animation._animations) k]; + animsDropDown.options = animList; + animsDropDown.onSelectionChange(0); } public override function update(elapsed:Float) { diff --git a/source/funkin/desktop/sprites/DropDown.hx b/source/funkin/desktop/sprites/DropDown.hx new file mode 100644 index 00000000..4721e5da --- /dev/null +++ b/source/funkin/desktop/sprites/DropDown.hx @@ -0,0 +1,38 @@ +package funkin.desktop.sprites; + +import funkin.desktop.theme.Theme.ThemeData; +import flixel.math.FlxPoint; + +class DropDown extends Button { + public var selectedIndex:Int = -1; + public var onChange:Int->Void; + public var options:Array; + + public function new(x:Float, y:Float, options:Array, onChange:Int->Void, curId:Int = 0, ?normalButton:ThemeData, ?hoverButton:ThemeData, ?pressedButton:ThemeData, ?disabledButton:ThemeData) { + super(x, y, "", onClick, normalButton, hoverButton, pressedButton, disabledButton); + this.options = options; + onSelectionChange(curId); + } + + public function onClick() { + var pos:FlxPoint = getScreenPosition(); + pos.y += height; + + var camPos = camera != null ? FlxPoint.get(camera.x - (camera.scroll.x * scrollFactor.x), camera.y - (camera.scroll.y * scrollFactor.y)) : FlxPoint.get(); + + ContextMenu.open(pos.x + camPos.x, pos.y + camPos.y, [for(o in options) { + { + name: o + } + }], onSelectionChange); + + camPos.put(); + } + + public function onSelectionChange(id:Int) { + selectedIndex = id; + label.text = options[id]; + if (onChange != null) + onChange(id); + } +} \ No newline at end of file diff --git a/source/funkin/desktop/sprites/TabView.hx b/source/funkin/desktop/sprites/TabView.hx index 44fe9ab3..f02e57e1 100644 --- a/source/funkin/desktop/sprites/TabView.hx +++ b/source/funkin/desktop/sprites/TabView.hx @@ -27,7 +27,7 @@ class TabView extends WindowGroup { add(bg); for(k=>t in tabs) { // BUTTON - var b = new Button(0, y, t, function() { + var b = new Button(0, 0, t, function() { switchTab(k); }, DesktopMain.theme.tabButtonUnselected, DesktopMain.theme.tabButtonHover, DesktopMain.theme.tabButtonPressed, DesktopMain.theme.tabButtonSelected); @@ -36,7 +36,7 @@ class TabView extends WindowGroup { // TAB var tab = new WindowGroup(); - tab.y = 20; + tab.y += b.height; this.tabs.push(tab); add(tab); } diff --git a/source/funkin/desktop/windows/ContextMenu.hx b/source/funkin/desktop/windows/ContextMenu.hx index 8838e559..b4fa85e3 100644 --- a/source/funkin/desktop/windows/ContextMenu.hx +++ b/source/funkin/desktop/windows/ContextMenu.hx @@ -19,8 +19,6 @@ class ContextMenu extends WindowGroup { super(); this.callback = callback; this.contextOptions = options; - - DesktopMain.contextMenu = FlxDestroyUtil.destroy(DesktopMain.contextMenu); var bgTheme = DesktopMain.theme.contextBackground; var optionTheme = DesktopMain.theme.contextOption; @@ -58,16 +56,18 @@ class ContextMenu extends WindowGroup { contextCamera.pixelPerfectRender = true; contextCamera.bgColor = 0; FlxG.cameras.add(contextCamera, false); + } - DesktopMain.contextMenu = this; + public static function open(x:Float, y:Float, options:Array, callback:Int->Void) { + DesktopMain.contextMenu = new ContextMenu(x, y, options, callback); } public override function update(elapsed:Float) { super.update(elapsed); - if (DesktopMain.mouseInput.overlaps(bg, camera)) { + if (DesktopMain.mouseInput.overlaps(bg, contextCamera)) { for(i=>o in selectionBGs) { var wasVisible = o.visible; - if (o.visible = DesktopMain.mouseInput.overlaps(o, camera)) { + if (o.visible = DesktopMain.mouseInput.overlaps(o, contextCamera)) { if (DesktopMain.mouseInput.justReleased) { // select option if (contextOptions[i].callback != null) @@ -75,6 +75,7 @@ class ContextMenu extends WindowGroup { if (callback != null) callback(i); destroy(); + return; } } if (o.visible != wasVisible) { @@ -85,14 +86,15 @@ class ContextMenu extends WindowGroup { } else { if (DesktopMain.mouseInput.justPressed) { destroy(); + return; } } } public override function destroy() { - super.destroy(); - DesktopMain.contextMenu = null; FlxG.cameras.remove(contextCamera, true); + DesktopMain.contextMenu = null; + super.destroy(); } } diff --git a/source/funkin/desktop/windows/WindowDragHitbox.hx b/source/funkin/desktop/windows/WindowDragHitbox.hx index c2d8a6e7..2c53008e 100644 --- a/source/funkin/desktop/windows/WindowDragHitbox.hx +++ b/source/funkin/desktop/windows/WindowDragHitbox.hx @@ -56,7 +56,7 @@ class WindowDragHitbox extends FlxObject { dragging = true; } else if (DesktopMain.mouseInput.justPressedRight) { var input = DesktopMain.mouseInput; - new ContextMenu(input.screenPos.x, input.screenPos.y, [ + ContextMenu.open(input.screenPos.x, input.screenPos.y, [ { name: "Close", callback: function() { diff --git a/source/funkin/game/Character.hx b/source/funkin/game/Character.hx index b5ebc703..a2ff00a6 100644 --- a/source/funkin/game/Character.hx +++ b/source/funkin/game/Character.hx @@ -1,5 +1,6 @@ package funkin.game; +import flixel.graphics.frames.FlxFrame; import flixel.math.FlxPoint; import funkin.interfaces.IBeatReceiver; import funkin.interfaces.IOffsetCompatible; @@ -18,6 +19,8 @@ import haxe.Exception; import haxe.io.Path; import funkin.system.Conductor; +import flash.geom.ColorTransform; + import funkin.scripting.DummyScript; import funkin.scripting.Script; import funkin.scripting.events.*; @@ -55,6 +58,9 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom public var script:Script; public var xml:Access; + public var shadowFrame:CharacterShadowFrame; + + public inline function getCameraPosition() { var midpoint = getMidpoint(); var event = new PointEvent( @@ -269,7 +275,41 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom return super.getScreenBounds(newRect, camera); } + var __drawingShadowFrame = false; + var __oldColorTransform = new ColorTransform(); public override function draw() { + if (!__drawingShadowFrame && shadowFrame != null) { + __drawingShadowFrame = true; + + var oldFrame = _frame; + var oldPos = FlxPoint.get(rotOffset.x, rotOffset.y); + + __oldColorTransform.copyColorTransform(colorTransform); + + colorTransform.alphaMultiplier = 1; + colorTransform.alphaOffset = 0; + colorTransform.blueMultiplier = 0; + colorTransform.blueOffset = 25; + colorTransform.greenMultiplier = 0; + colorTransform.greenOffset = 25; + colorTransform.redMultiplier = 0; + colorTransform.redOffset = 25; + + _frame = shadowFrame.frame; + var o = getAnimOffset(shadowFrame.anim); + rotOffset.set(o.x, o.y); + super.draw(); + + _frame = oldFrame; + rotOffset.set(oldPos.x, oldPos.y); + + colorTransform.copyColorTransform(__oldColorTransform); + + oldPos.put(); + + __drawingShadowFrame = false; + } + if ((isPlayer != playerOffsets) != (flipX != __baseFlipped)) { __reverseDrawProcedure = true; @@ -284,6 +324,12 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom super.draw(); } + public function getAnimOffset(name:String) { + if (animOffsets[name] != null) + return animOffsets[name]; + return FlxPoint.weak(0, 0); + } + public var lastAnimContext:PlayAnimContext = DANCE; public function playAnim(AnimName:String, Force:Bool = false, Context:PlayAnimContext = NONE, Reversed:Bool = false, Frame:Int = 0):Void { @@ -295,11 +341,8 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom animation.play(event.animName, event.force, event.reverse, event.startingFrame); - var daOffset = animOffsets.get(event.animName); - if (daOffset != null) - rotOffset.set(daOffset.x, daOffset.y); - else - rotOffset.set(0, 0); + var daOffset = getAnimOffset(event.animName); + rotOffset.set(daOffset.x, daOffset.y); offset.set(globalOffset.x * (isPlayer != playerOffsets ? 1 : -1), -globalOffset.y); @@ -321,4 +364,9 @@ class Character extends FlxSprite implements IBeatReceiver implements IOffsetCom { animOffsets[name] = new FlxPoint(x, y); } +} + +typedef CharacterShadowFrame = { + var anim:String; + var frame:FlxFrame; } \ No newline at end of file diff --git a/source/funkin/system/CoolUtil.hx b/source/funkin/system/CoolUtil.hx index 104c6132..bb1a48e0 100644 --- a/source/funkin/system/CoolUtil.hx +++ b/source/funkin/system/CoolUtil.hx @@ -21,6 +21,7 @@ import flixel.FlxCamera; import flixel.util.FlxAxes; import flixel.graphics.frames.FlxFrame; import flixel.graphics.frames.FlxFramesCollection; +import flash.geom.ColorTransform; using StringTools; @@ -330,4 +331,15 @@ class CoolUtil return spr; } + + public static function copyColorTransform(color1:ColorTransform, color2:ColorTransform) { + color1.alphaMultiplier = color2.alphaMultiplier; + color1.alphaOffset = color2.alphaOffset; + color1.blueMultiplier = color2.blueMultiplier; + color1.blueOffset = color2.blueOffset; + color1.greenMultiplier = color2.greenMultiplier; + color1.greenOffset = color2.greenOffset; + color1.redMultiplier = color2.redMultiplier; + color1.redOffset = color2.redOffset; + } } \ No newline at end of file