diff --git a/source/funkin/editors/UIDebugState.hx b/source/funkin/editors/UIDebugState.hx index 2d02c197..dd74c90e 100644 --- a/source/funkin/editors/UIDebugState.hx +++ b/source/funkin/editors/UIDebugState.hx @@ -1,6 +1,7 @@ package funkin.editors; import funkin.editors.ui.*; +import flixel.tweens.FlxTween; class UIDebugState extends UIState { public override function create() { @@ -99,6 +100,12 @@ class UIDebugState extends UIState { ])); }, 130, 48)); add(new UITextBox(10, 220, "")); + + var spliceSprite:UISliceSprite = new UISliceSprite(650, 350, 30, 30, "editors/ui/context-bg"); + add(spliceSprite); + FlxTween.num(0, 1, 2, {type: PINGPONG}, function (v:Float) { + spliceSprite.bWidth = Std.int(lerp(12, 200, v)); spliceSprite.bHeight = Std.int(lerp(12, 200, v)); + }); } public override function update(elapsed:Float) { diff --git a/source/funkin/editors/ui/UISliceSprite.hx b/source/funkin/editors/ui/UISliceSprite.hx index 4184409f..9556a521 100644 --- a/source/funkin/editors/ui/UISliceSprite.hx +++ b/source/funkin/editors/ui/UISliceSprite.hx @@ -31,12 +31,14 @@ class UISliceSprite extends UISprite { } public var drawTop:Bool = true; + public var drawMiddle:Bool = true; + public var drawBottom:Bool = true; - public override function draw() { + public override function draw() @:privateAccess { var x:Float = this.x; var y:Float = this.y; - @:privateAccess if (visible) { + if (visible && !(bWidth == 0 || bHeight == 0)) { var topleft:FlxFrame = frames.frames[framesOffset]; var top:FlxFrame = frames.frames[framesOffset + 1]; var topright:FlxFrame = frames.frames[framesOffset + 2]; @@ -47,73 +49,95 @@ class UISliceSprite extends UISprite { var bottom:FlxFrame = frames.frames[framesOffset + 7]; var bottomright:FlxFrame = frames.frames[framesOffset + 8]; + // TOP if (drawTop) { // TOP LEFT frame = topleft; setPosition(x, y); - __setSize(topleft.frame.width, topleft.frame.height); + __setSize( + topleft.frame.width * Math.min(bWidth/(topleft.frame.width*2), 1), + topleft.frame.height * Math.min(bHeight/(topleft.frame.height*2), 1) + ); super.drawSuper(); // TOP if (bWidth > topleft.frame.width + topright.frame.width) { frame = top; setPosition(x + topleft.frame.width, y); - __setSize(bWidth - topleft.frame.width - topright.frame.width, top.frame.height); + __setSize(bWidth - topleft.frame.width - topright.frame.width, top.frame.height * Math.min(bHeight/(top.frame.height*2), 1)); super.drawSuper(); } // TOP RIGHT + setPosition(x + bWidth - (topright.frame.width * Math.min(bWidth/(topright.frame.width*2), 1)), y); frame = topright; - setPosition(x + bWidth - topright.frame.width, y); - __setSize(topright.frame.width, topright.frame.height); + __setSize( + topright.frame.width * Math.min(bWidth/(topright.frame.width*2), 1), + topright.frame.height * Math.min(bHeight/(topright.frame.height*2), 1) + ); super.drawSuper(); } - // MIDDLE LEFT - if (bHeight > top.frame.height + bottom.frame.height) { + // MIDDLE + if (drawMiddle && bHeight > top.frame.height + bottom.frame.height) { + var middleHeight:Float = bHeight - (topleft.frame.height * Math.min(bHeight/(topleft.frame.height*2), 1)) - + bottomleft.frame.height * Math.min(bHeight/(bottomleft.frame.height*2), 1); + + // MIDDLE LEFT frame = middleleft; setPosition(x, y + top.frame.height); - __setSize(middleleft.frame.width, bHeight - topleft.frame.height - bottomleft.frame.height); + __setSize(middleleft.frame.width * Math.min(bWidth/(middleleft.frame.width*2), 1), middleHeight); super.drawSuper(); - if (bWidth > middleleft.frame.width + middleright.frame.width) { + if (bWidth > (middleleft.frame.width * Math.min(bWidth/(middleleft.frame.width*2), 1)) + middleright.frame.width) { // MIDDLE frame = middle; setPosition(x + topleft.frame.width, y + top.frame.height); - __setSize(bWidth - middleleft.frame.width - middleright.frame.width, bHeight - topleft.frame.height - bottomleft.frame.height); + __setSize(bWidth - middleleft.frame.width - middleright.frame.width, middleHeight); super.drawSuper(); } // MIDDLE RIGHT frame = middleright; - setPosition(x + bWidth - topright.frame.width, y + top.frame.height); - __setSize(middleright.frame.width, bHeight - topleft.frame.height - bottomleft.frame.height); + setPosition(x + bWidth - (topright.frame.width * Math.min(bWidth/(topright.frame.width*2), 1)), y + top.frame.height); + __setSize(middleright.frame.width * Math.min(bWidth/(middleright.frame.width*2), 1), middleHeight); super.drawSuper(); } - // BOTTOM LEFT - frame = bottomleft; - setPosition(x, y + bHeight - bottom.frame.height); - __setSize(bottomleft.frame.width, bottomleft.frame.height); - super.drawSuper(); + // BOTTOM + if (drawBottom) { + // BOTTOM LEFT + frame = bottomleft; + setPosition(x, y + bHeight - (bottomleft.frame.height * Math.min(bHeight/(bottomleft.frame.height*2), 1))); + __setSize( + bottomleft.frame.width * Math.min(bWidth/(bottomleft.frame.width*2), 1), + bottomleft.frame.height * Math.min(bHeight/(bottomleft.frame.height*2), 1) + ); + super.drawSuper(); - if (bWidth > bottomleft.frame.width + bottomright.frame.width) { - // BOTTOM - frame = bottom; - setPosition(x + bottomleft.frame.width, y + bHeight - bottom.frame.height); - __setSize(bWidth - bottomleft.frame.width - bottomright.frame.width, bottom.frame.height); + if (bWidth > bottomleft.frame.width + bottomright.frame.width) { + // BOTTOM + frame = bottom; + setPosition(x + bottomleft.frame.width, y + bHeight - (bottom.frame.height * Math.min(bHeight/(bottom.frame.height*2), 1))); + __setSize(bWidth - bottomleft.frame.width - bottomright.frame.width, bottom.frame.height * Math.min(bHeight/(bottom.frame.height*2), 1)); + super.drawSuper(); + } + + // BOTTOM RIGHT + frame = bottomright; + setPosition( + x + bWidth - (bottomright.frame.width * Math.min(bWidth/(bottomright.frame.width*2), 1)), + y + bHeight - (bottomright.frame.height * Math.min(bHeight/(bottomright.frame.height*2), 1)) + ); + __setSize( + bottomright.frame.width * Math.min(bWidth/(bottomright.frame.width*2), 1), + bottomright.frame.height * Math.min(bHeight/(bottomright.frame.height*2), 1) + ); super.drawSuper(); } - - // BOTTOM RIGHT - frame = bottomright; - setPosition(x + bWidth - bottomright.frame.width, y + bHeight - bottom.frame.height); - __setSize(bottomright.frame.width, bottomright.frame.height); - super.drawSuper(); } setPosition(x, y); - super.drawMembers(); }