UIWindow collapsing fix
Co-Authored-By: Ne_Eo <NeeEoo@users.noreply.github.com>
This commit is contained in:
@@ -45,6 +45,11 @@ class UISliceSprite extends UISprite {
|
||||
var bottom:FlxFrame = null;
|
||||
var bottomright:FlxFrame = null;
|
||||
|
||||
public var topHeight:Int = 0;
|
||||
public var bottomHeight:Int = 0;
|
||||
public var leftWidth:Int = 0;
|
||||
public var rightWidth:Int = 0;
|
||||
|
||||
override function set_frames(val) {
|
||||
super.set_frames(val);
|
||||
calculateFrames();
|
||||
@@ -70,6 +75,11 @@ class UISliceSprite extends UISprite {
|
||||
bottomleft = frames.frames[framesOffset + 6];
|
||||
bottom = frames.frames[framesOffset + 7];
|
||||
bottomright = frames.frames[framesOffset + 8];
|
||||
|
||||
leftWidth = Std.int(Math.max(topleft.frame.width, Math.max(middleleft.frame.width, bottomleft.frame.width)));
|
||||
rightWidth = Std.int(Math.max(topright.frame.width, Math.max(middleright.frame.width, bottomright.frame.width)));
|
||||
topHeight = Std.int(Math.max(topleft.frame.height, Math.max(top.frame.height, topright.frame.height)));
|
||||
bottomHeight = Std.int(Math.max(topleft.frame.height, Math.max(top.frame.height, topright.frame.height)));
|
||||
}
|
||||
|
||||
public override function draw() @:privateAccess {
|
||||
|
||||
@@ -55,7 +55,8 @@ class UISprite extends FlxSprite {
|
||||
FlxCamera._defaultCameras = cameras;
|
||||
|
||||
for(m in members)
|
||||
m.update(elapsed);
|
||||
if(m.exists && m.active)
|
||||
m.update(elapsed);
|
||||
|
||||
FlxCamera._defaultCameras = __oldDefCams;
|
||||
}
|
||||
@@ -114,4 +115,11 @@ class UISprite extends FlxSprite {
|
||||
if (hoverCallback != null)
|
||||
hoverCallback();
|
||||
}
|
||||
|
||||
public function updateSpriteRect() {
|
||||
__rect.x = x;
|
||||
__rect.y = y;
|
||||
__rect.width = width;
|
||||
__rect.height = height;
|
||||
}
|
||||
}
|
||||
@@ -59,28 +59,15 @@ class UIState extends MusicBeatState {
|
||||
currentFocus.onTextEdit(str, start, end);
|
||||
}
|
||||
|
||||
public inline function updateSpriteRect(spr:UISprite) {
|
||||
spr.__rect.x = spr.x;
|
||||
spr.__rect.y = spr.y;
|
||||
spr.__rect.width = spr.width;
|
||||
spr.__rect.height = spr.height;
|
||||
}
|
||||
|
||||
public function updateButtonHandler(spr:UISprite, buttonHandler:Void->Void) {
|
||||
spr.__rect.x = spr.x;
|
||||
spr.__rect.y = spr.y;
|
||||
spr.__rect.width = spr.width;
|
||||
spr.__rect.height = spr.height;
|
||||
spr.updateSpriteRect();
|
||||
updateRectButtonHandler(spr, spr.__rect, buttonHandler);
|
||||
}
|
||||
|
||||
public function isOverlapping(spr:UISprite, rect:FlxRect) {
|
||||
for(camera in spr.__lastDrawCameras) {
|
||||
var pos = FlxG.mouse.getScreenPosition(camera, FlxPoint.get());
|
||||
__rect.x = rect.x;
|
||||
__rect.y = rect.y;
|
||||
__rect.width = rect.width;
|
||||
__rect.height = rect.height;
|
||||
__rect.copyFrom(rect);
|
||||
|
||||
__rect.x -= camera.scroll.x * spr.scrollFactor.x;
|
||||
__rect.y -= camera.scroll.y * spr.scrollFactor.y;
|
||||
|
||||
@@ -18,19 +18,28 @@ class UIWindow extends UISliceSprite {
|
||||
public override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
|
||||
if(collapsable && FlxG.mouse.justPressed) {
|
||||
// TOOLBAR
|
||||
cursor = ARROW;
|
||||
|
||||
if(collapsable) {
|
||||
__rect.x = x; __rect.y = y;
|
||||
__rect.width = bWidth; __rect.height = 23;
|
||||
__rect.width = bWidth; __rect.height = topHeight;
|
||||
|
||||
if(UIState.state.isOverlapping(this, __rect)) {
|
||||
content.exists = !content.exists;
|
||||
drawMiddle = !drawMiddle;
|
||||
drawBottom = !drawBottom;
|
||||
cursor = BUTTON;
|
||||
if(FlxG.mouse.justPressed) {
|
||||
content.exists = !content.exists;
|
||||
drawMiddle = !drawMiddle;
|
||||
drawBottom = !drawBottom;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__rect.x = x; __rect.y = y+23;
|
||||
__rect.width = bWidth; __rect.height = bHeight-23;
|
||||
__rect.x = x;
|
||||
__rect.width = bWidth;
|
||||
if(content.exists) {
|
||||
__rect.y = y+topHeight;
|
||||
__rect.height = bHeight-topHeight;
|
||||
}
|
||||
hovered = UIState.state.isOverlapping(this, __rect);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user