From 960ab248ec53ce221573c264ba2108c78548e936 Mon Sep 17 00:00:00 2001 From: lunarcleint <88809950+lunarcleint@users.noreply.github.com> Date: Mon, 15 Apr 2024 14:21:00 -0700 Subject: [PATCH] cleaner code --- .../editors/character/CharacterAnimButton.hx | 11 +++-- .../editors/character/CharacterAnimsWindow.hx | 2 +- .../editors/character/CharacterEditor.hx | 48 ++++++++++--------- source/funkin/editors/charter/Charter.hx | 6 +-- .../editors/charter/CharterBackdropGroup.hx | 20 -------- .../funkin/editors/extra/CameraHoverDummy.hx | 21 ++++++++ source/funkin/editors/ui/UIButton.hx | 4 +- 7 files changed, 61 insertions(+), 51 deletions(-) create mode 100644 source/funkin/editors/extra/CameraHoverDummy.hx diff --git a/source/funkin/editors/character/CharacterAnimButton.hx b/source/funkin/editors/character/CharacterAnimButton.hx index 1a78f49b..b84201b8 100644 --- a/source/funkin/editors/character/CharacterAnimButton.hx +++ b/source/funkin/editors/character/CharacterAnimButton.hx @@ -8,10 +8,15 @@ class CharacterAnimButton extends UIButton { public function new(x:Float,y:Float,anim:String, offset:FlxPoint) { this.anim = anim; - super(x,y, '$anim (${offset.x}, ${offset.y})', function () { + super(x,y, ""/*'$anim (${offset.x}, ${offset.y})'*/, function () { CharacterEditor.instance.playAnimation(this.anim); - }, Std.int(500-16)); - autoAlpha = false; + }, Std.int(500-16), 100); + + + autoAlpha = autoFrames = false; + + frames = Paths.getFrames('editors/ui/inputbox'); + framesOffset = 9; } public function updateInfo(anim:String, offset:FlxPoint, ghost:Bool) { diff --git a/source/funkin/editors/character/CharacterAnimsWindow.hx b/source/funkin/editors/character/CharacterAnimsWindow.hx index cf0f70b3..a3d42536 100644 --- a/source/funkin/editors/character/CharacterAnimsWindow.hx +++ b/source/funkin/editors/character/CharacterAnimsWindow.hx @@ -2,7 +2,7 @@ package funkin.editors.character; class CharacterAnimsWindow extends UIButtonList { public function new(x:Float, y:Float, animations:Array) { - super(x, y, Std.int(500-16), 419, "", FlxPoint.get(500-16, 32)); + super(x, y, Std.int(500-16), 419, "", FlxPoint.get(500-16, 100)); cameraSpacing = 0; frames = Paths.getFrames('editors/ui/inputbox'); diff --git a/source/funkin/editors/character/CharacterEditor.hx b/source/funkin/editors/character/CharacterEditor.hx index 6da1a2bf..a2a8f713 100644 --- a/source/funkin/editors/character/CharacterEditor.hx +++ b/source/funkin/editors/character/CharacterEditor.hx @@ -1,5 +1,6 @@ package funkin.editors.character; +import funkin.editors.extra.CameraHoverDummy; import openfl.display.BitmapData; import flixel.math.FlxPoint; import funkin.backend.system.framerate.Framerate; @@ -29,6 +30,8 @@ class CharacterEditor extends UIState { public var uiGroup:FlxTypedGroup = new FlxTypedGroup(); + public var cameraHoverDummy:CameraHoverDummy; + public var characterPropertiresWindow:CharacterPropertiesWindow; public var characterAnimsWindow:CharacterAnimsWindow; @@ -229,36 +232,27 @@ class CharacterEditor extends UIState { add(ghosts); add(character); + uiGroup.cameras = [uiCamera]; + add(cameraHoverDummy = new CameraHoverDummy(uiGroup, FlxPoint.weak(0, 0))); + characterPropertiresWindow = new CharacterPropertiesWindow((FlxG.width-500), 23+12+10, character); uiGroup.add(characterPropertiresWindow); topMenuSpr = new UITopMenu(topMenu); - topMenuSpr.cameras = uiGroup.cameras = [uiCamera]; + topMenuSpr.cameras = [uiCamera]; var animationsLoaded:Array = character.getAnimOrder(); characterAnimsWindow = new CharacterAnimsWindow(characterPropertiresWindow.x, characterPropertiresWindow.y+224+16, animationsLoaded); uiGroup.add(characterAnimsWindow); - playAnimation(animationsLoaded[0]); - - var characterMidpoint:FlxPoint = character.getMidpoint(); - characterMidpoint.x += ((characterAnimsWindow.bWidth+23)/2); - characterMidpoint.x -= (FlxG.width/2)-character.globalOffset.x; - characterMidpoint.y -= (FlxG.height/2)-character.globalOffset.y+(23/4); - charCamera.scroll = _nextScroll.set(characterMidpoint.x, characterMidpoint.y); - characterMidpoint.put(); - - _cameraZoomMulti = 1/(1+(0-character.getScreenPosition().y/FlxG.height)); - if (!(_cameraZoomMulti < 1)) _cameraZoomMulti *= .9; - FlxG.camera.zoom = __camZoom = _cameraZoomMulti; - - _nextScroll.x -= ((FlxG.width/2)*FlxG.camera.zoom)-FlxG.width/2; - _nextScroll.y += (((FlxG.height/2)*FlxG.camera.zoom)-FlxG.height/2)/2; - add(uiGroup); add(topMenuSpr); + playAnimation(animationsLoaded[0]); + _view_focus_character(null); + + if(Framerate.isLoaded) { Framerate.fpsCounter.alpha = 0.4; Framerate.memoryCounter.alpha = 0.4; @@ -280,15 +274,10 @@ class CharacterEditor extends UIState { var _nextScroll:FlxPoint = FlxPoint.get(0,0); var _cameraZoomMulti:Float = 1; public override function update(elapsed:Float) { - super.update(elapsed); - if(FlxG.keys.justPressed.ANY) UIUtil.processShortcuts(topMenu); - // if (character != null) - // characterPropertiresWindow.characterInfo.text = '${character.getNameList().length} Animations\nFlipped: ${character.flipX}\nSprite: ${character.sprite}\nAnim: ${character.getAnimName()}\nOffset: (${character.frameOffset.x}, ${character.frameOffset.y})'; - - if (/*!(characterPropertiresWindow.hovered || characterAnimsWindow.hovered) && !characterAnimsWindow.dragging*/true) { + if (cameraHoverDummy.hovered) { if (FlxG.mouse.wheel != 0) { zoom += 0.25 * FlxG.mouse.wheel; __camZoom = Math.pow(2, zoom); @@ -298,6 +287,7 @@ class CharacterEditor extends UIState { closeCurrentContextMenu(); openContextMenu(topMenu[2].childs); } + if (FlxG.mouse.pressed) { _nextScroll.set(_nextScroll.x - FlxG.mouse.deltaScreenX, _nextScroll.y - FlxG.mouse.deltaScreenY); currentCursor = HAND; @@ -316,6 +306,8 @@ class CharacterEditor extends UIState { characterBG.scale.set(FlxG.width/characterBG.width, FlxG.height/characterBG.height); characterBG.scale.set(characterBG.scale.x / charCamera.zoom, characterBG.scale.y / charCamera.zoom); + super.update(elapsed); + WindowUtils.prefix = undos.unsaved ? "* " : ""; SaveWarning.showWarning = undos.unsaved; } @@ -635,6 +627,16 @@ class CharacterEditor extends UIState { zoom = 0; __camZoom = Math.pow(2, zoom); } + + function _view_focus_character(_) { + if (character == null) return; + + var characterMidpoint:FlxPoint = character.getMidpoint(); + characterMidpoint.x -= (FlxG.width/2)-character.globalOffset.x; + characterMidpoint.y -= (FlxG.height/2)-character.globalOffset.y+(23/4); + _nextScroll.set(characterMidpoint.x, characterMidpoint.y); + characterMidpoint.put(); + } #end } diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index ddb6db51..1ad5b6a1 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -1,6 +1,7 @@ package funkin.editors.charter; // ! FUCK YOU CHUF (your biggest fan -lunar) <3 +import funkin.editors.extra.CameraHoverDummy; import flixel.input.keyboard.FlxKey; import flixel.math.FlxPoint; import flixel.sound.FlxSound; @@ -8,7 +9,6 @@ import funkin.backend.chart.*; import funkin.backend.chart.ChartData; import funkin.backend.system.Conductor; import funkin.backend.system.framerate.Framerate; -import funkin.editors.charter.CharterBackdropGroup.CharterBackdropDummy; import funkin.editors.charter.CharterBackdropGroup.EventBackdrop; import funkin.editors.charter.CharterStrumline; import funkin.editors.ui.UIContextMenu.UIContextMenuOption; @@ -50,7 +50,7 @@ class Charter extends UIState { public var eventsBackdrop:EventBackdrop; public var addEventSpr:CharterEventAdd; - public var gridBackdropDummy:CharterBackdropDummy; + public var gridBackdropDummy:CameraHoverDummy; public var noteHoverer:CharterNoteHoverer; public var noteDeleteAnims:CharterDeleteAnim; @@ -391,7 +391,7 @@ class Charter extends UIState { eventsBackdrop.cameras = [charterCamera]; eventsGroup.eventsBackdrop = eventsBackdrop; - add(gridBackdropDummy = new CharterBackdropDummy(gridBackdrops)); + add(gridBackdropDummy = new CameraHoverDummy(gridBackdrops, FlxPoint.weak(1, 0))); selectionBox = new UISliceSprite(0, 0, 2, 2, 'editors/ui/selection'); selectionBox.visible = false; selectionBox.scrollFactor.set(1, 1); diff --git a/source/funkin/editors/charter/CharterBackdropGroup.hx b/source/funkin/editors/charter/CharterBackdropGroup.hx index 481bd76b..bc49ab93 100644 --- a/source/funkin/editors/charter/CharterBackdropGroup.hx +++ b/source/funkin/editors/charter/CharterBackdropGroup.hx @@ -237,26 +237,6 @@ class CharterBackdrop extends FlxTypedGroup { } } -class CharterBackdropDummy extends UISprite { - var parent:CharterBackdropGroup; - public function new(parent:CharterBackdropGroup) { - super(); - this.parent = parent; - cameras = parent.cameras; - scrollFactor.set(1, 0); - } - - public override function updateButton() { - camera.getViewRect(__rect); - UIState.state.updateRectButtonHandler(this, __rect, onHovered); - } - - public override function draw() { - @:privateAccess - __lastDrawCameras = cameras.copy(); - } -} - class EventBackdrop extends FlxBackdrop { public var eventBeatSeparator:FlxBackdrop; public var eventSecSeparator:FlxBackdrop; diff --git a/source/funkin/editors/extra/CameraHoverDummy.hx b/source/funkin/editors/extra/CameraHoverDummy.hx new file mode 100644 index 00000000..5ad69391 --- /dev/null +++ b/source/funkin/editors/extra/CameraHoverDummy.hx @@ -0,0 +1,21 @@ +package funkin.editors.extra; + +class CameraHoverDummy extends UISprite { + var parent:FlxBasic; + public function new(?parent:FlxBasic, scroll:FlxPoint) { + super(); + this.parent = parent; + cameras = parent == null ? [FlxG.camera] : parent.cameras; + scrollFactor.copyFrom(scroll); + } + + public override function updateButton() { + camera.getViewRect(__rect); + UIState.state.updateRectButtonHandler(this, __rect, onHovered); + } + + public override function draw() { + @:privateAccess + __lastDrawCameras = cameras.copy(); + } +} \ No newline at end of file diff --git a/source/funkin/editors/ui/UIButton.hx b/source/funkin/editors/ui/UIButton.hx index c5522c5c..9a16b795 100644 --- a/source/funkin/editors/ui/UIButton.hx +++ b/source/funkin/editors/ui/UIButton.hx @@ -6,6 +6,8 @@ class UIButton extends UISliceSprite { public var shouldPress = true; public var hasBeenPressed = false; + public var autoFrames:Bool = true; + public override function new(x:Float, y:Float, text:String, callback:Void->Void, w:Int = 120, h:Int = 32) { super(x, y, w, h, 'editors/ui/button'); this.callback = callback; @@ -38,7 +40,7 @@ class UIButton extends UISliceSprite { } public override function draw() { - framesOffset = hovered ? (pressed ? 18 : 9) : 0; + if (autoFrames) framesOffset = hovered ? (pressed ? 18 : 9) : 0; super.draw(); } } \ No newline at end of file