From ca443411beaee40e16871fbf27b2d5130713a0ef Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Fri, 3 Feb 2023 18:10:06 -0500 Subject: [PATCH] stage edit funny moments --- source/funkin/play/character/BaseCharacter.hx | 1 + source/funkin/play/stage/Bopper.hx | 6 +-- source/funkin/play/stage/Stage.hx | 22 +++++---- source/funkin/play/stage/StageProp.hx | 13 ++++++ source/funkin/ui/haxeui/HaxeUISubState.hx | 45 +++++++++++++++++++ .../ui/stageBuildShit/StageOffsetSubstate.hx | 31 ++++++++++--- 6 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 source/funkin/play/stage/StageProp.hx diff --git a/source/funkin/play/character/BaseCharacter.hx b/source/funkin/play/character/BaseCharacter.hx index 20d1280c2..bd12b5f2e 100644 --- a/source/funkin/play/character/BaseCharacter.hx +++ b/source/funkin/play/character/BaseCharacter.hx @@ -144,6 +144,7 @@ class BaseCharacter extends Bopper else { this.characterName = _data.name; + this.name = _data.name; this.singTimeCrochet = _data.singTime; this.globalOffsets = _data.offsets; this.flipX = _data.flipX; diff --git a/source/funkin/play/stage/Bopper.hx b/source/funkin/play/stage/Bopper.hx index cb33469b3..757893d7f 100644 --- a/source/funkin/play/stage/Bopper.hx +++ b/source/funkin/play/stage/Bopper.hx @@ -5,6 +5,7 @@ import flixel.math.FlxPoint; import flixel.util.FlxTimer; import funkin.modding.IScriptedClass.IPlayStateScriptedClass; import funkin.modding.events.ScriptEvent; +import funkin.play.stage.StageProp; typedef AnimationFrameCallback = String->Int->Int->Void; typedef AnimationFinishedCallback = String->Void; @@ -13,7 +14,7 @@ typedef AnimationFinishedCallback = String->Void; * A Bopper is a stage prop which plays a dance animation. * Y'know, a thingie that bops. A bopper. */ -class Bopper extends FlxSprite implements IPlayStateScriptedClass +class Bopper extends StageProp implements IPlayStateScriptedClass { /** * The bopper plays the dance animation once every `danceEvery` beats. @@ -281,8 +282,7 @@ class Bopper extends FlxSprite implements IPlayStateScriptedClass applyAnimationOffsets(correctName); canPlayOtherAnims = false; - forceAnimationTimer.start(duration, (timer) -> - { + forceAnimationTimer.start(duration, (timer) -> { canPlayOtherAnims = true; }, 1); } diff --git a/source/funkin/play/stage/Stage.hx b/source/funkin/play/stage/Stage.hx index 66227c6a5..3dd167fd6 100644 --- a/source/funkin/play/stage/Stage.hx +++ b/source/funkin/play/stage/Stage.hx @@ -11,9 +11,12 @@ import funkin.modding.events.ScriptEventDispatcher; import funkin.play.character.BaseCharacter; import funkin.play.stage.StageData.StageDataCharacter; import funkin.play.stage.StageData.StageDataParser; +import funkin.play.stage.StageProp; import funkin.util.SortUtil; import funkin.util.assets.FlxAnimationUtil; +typedef StagePropGroup = FlxTypedSpriteGroup; + /** * A Stage is a group of objects rendered in the PlayState. * @@ -28,7 +31,7 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass public var camZoom:Float = 1.0; - var namedProps:Map = new Map(); + var namedProps:Map = new Map(); var characters:Map = new Map(); var boppers:Array = new Array(); @@ -66,7 +69,7 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass debugIconGroup = new FlxSpriteGroup(); debugIconGroup.visible = false; debugIconGroup.zIndex = 1000000; - add(debugIconGroup); + // add(debugIconGroup); } public function resetStage():Void @@ -93,7 +96,7 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass for (dataProp in _data.props) { // Fetch the prop. - var prop:FlxSprite = getNamedProp(dataProp.name); + var prop:StageProp = getNamedProp(dataProp.name); if (prop != null) { @@ -125,14 +128,14 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass var isAnimated = dataProp.animations.length > 0; - var propSprite:FlxSprite; + var propSprite:StageProp; if (dataProp.danceEvery != 0) { propSprite = new Bopper(dataProp.danceEvery); } else { - propSprite = new FlxSprite(); + propSprite = new StageProp(); } if (isAnimated) @@ -239,11 +242,12 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass * @param name (Optional) A unique name for the sprite. * You can call `getNamedProp(name)` to retrieve it later. */ - public function addProp(prop:FlxSprite, ?name:String = null) + public function addProp(prop:StageProp, ?name:String = null) { if (name != null) { namedProps.set(name, prop); + prop.name = name; } this.add(prop); } @@ -255,6 +259,7 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass { boppers.push(bopper); this.addProp(bopper, name); + bopper.name = name; } /** @@ -268,8 +273,7 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass public function setShader(shader:FlxShader) { - forEachAlive(function(prop:FlxSprite) - { + forEachAlive(function(prop:FlxSprite) { prop.shader = shader; }); } @@ -439,7 +443,7 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass * @param name The name of the prop to retrieve. * @return The corresponding FlxSprite. */ - public function getNamedProp(name:String):FlxSprite + public function getNamedProp(name:String):StageProp { return this.namedProps.get(name); } diff --git a/source/funkin/play/stage/StageProp.hx b/source/funkin/play/stage/StageProp.hx new file mode 100644 index 000000000..0cce506d1 --- /dev/null +++ b/source/funkin/play/stage/StageProp.hx @@ -0,0 +1,13 @@ +package funkin.play.stage; + +import flixel.FlxSprite; + +class StageProp extends FlxSprite +{ + public var name:String = ""; + + public function new() + { + super(); + } +} diff --git a/source/funkin/ui/haxeui/HaxeUISubState.hx b/source/funkin/ui/haxeui/HaxeUISubState.hx index aba738eef..326287426 100644 --- a/source/funkin/ui/haxeui/HaxeUISubState.hx +++ b/source/funkin/ui/haxeui/HaxeUISubState.hx @@ -1,6 +1,8 @@ package funkin.ui.haxeui; import haxe.ui.RuntimeComponentBuilder; +import haxe.ui.components.CheckBox; +import haxe.ui.containers.menus.MenuCheckBox; import haxe.ui.core.Component; import haxe.ui.events.MouseEvent; @@ -101,6 +103,49 @@ class HaxeUISubState extends MusicBeatSubstate } } + /** + * Set the value of a HaxeUI component. + * Usually modifies the text of a label or value of a text field. + */ + function setUIValue(key:String, value:T):T + { + var target:Component = findComponent(key); + if (target == null) + { + // Gracefully handle the case where the item can't be located. + trace('WARN: Could not locate menu item: $key'); + return value; + } + else + { + return target.value = value; + } + } + + /** + * Set the value of a HaxeUI checkbox, + * since that's on 'selected' instead of 'value'. + */ + public function setUICheckboxSelected(key:String, value:Bool):Bool + { + var targetA:CheckBox = findComponent(key, CheckBox); + + if (targetA != null) + { + return targetA.selected = value; + } + + var targetB:MenuCheckBox = findComponent(key, MenuCheckBox); + if (targetB != null) + { + return targetB.selected = value; + } + + // Gracefully handle the case where the item can't be located. + trace('WARN: Could not locate check box: $key'); + return value; + } + public function findComponent(criteria:String = null, type:Class = null, recursive:Null = null, searchType:String = "id"):Null { if (component == null) return null; diff --git a/source/funkin/ui/stageBuildShit/StageOffsetSubstate.hx b/source/funkin/ui/stageBuildShit/StageOffsetSubstate.hx index 8390f0dcd..54e2a6539 100644 --- a/source/funkin/ui/stageBuildShit/StageOffsetSubstate.hx +++ b/source/funkin/ui/stageBuildShit/StageOffsetSubstate.hx @@ -4,9 +4,12 @@ import flixel.FlxSprite; import flixel.input.mouse.FlxMouseEvent; import flixel.math.FlxPoint; import funkin.play.PlayState; +import funkin.play.character.BaseCharacter; import funkin.play.stage.StageData; +import funkin.play.stage.StageProp; import funkin.ui.haxeui.HaxeUISubState; import haxe.ui.RuntimeComponentBuilder; +import haxe.ui.containers.ListView; import haxe.ui.core.Component; import openfl.events.Event; import openfl.events.IOErrorEvent; @@ -46,10 +49,33 @@ class StageOffsetSubstate extends HaxeUISubState // uiStuff.cameras = [PlayState.instance.camHUD]; // btn.cameras = [PlayState.instance.camHUD]; + var layerList:ListView = findComponent("prop-layers"); + for (thing in PlayState.instance.currentStage) { + var prop:StageProp = cast thing; + if (prop != null && prop.name != null) + { + layerList.dataSource.add( + { + item: prop.name, + complete: true + }); + } + // + // + // + // + // + FlxMouseEvent.add(thing, spr -> { + var dyn:StageProp = cast spr; + if (dyn != null && dyn.name != null) trace(dyn.name); + char = cast thing; + + // trace(thing); + // trace(spr); trace("JUST PRESSED!"); sprOld.x = thing.x; sprOld.y = thing.y; @@ -115,11 +141,6 @@ class StageOffsetSubstate extends HaxeUISubState if (FlxG.keys.pressed.CONTROL) CoolUtil.mouseWheelZoom(); - if (FlxG.mouse.wheel != 0) - { - FlxG.camera.zoom += FlxG.mouse.wheel * 0.1; - } - if (FlxG.keys.justPressed.Y) { for (thing in PlayState.instance.currentStage)