fix button
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 848 B |
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextureAtlas imagePath="button.png">
|
||||
<!-- Created without animate lol i wrote this-->
|
||||
<SubTexture name="normal-topleft" x="0" y="0" width="4" height="4"/>
|
||||
<SubTexture name="normal-top" x="4" y="0" width="12" height="4"/>
|
||||
<SubTexture name="normal-topright" x="16" y="0" width="4" height="4"/>
|
||||
<SubTexture name="normal-middleleft" x="0" y="8" width="4" height="15"/>
|
||||
<SubTexture name="normal-middle" x="4" y="8" width="12" height="15"/>
|
||||
<SubTexture name="normal-middleright" x="16" y="8" width="4" height="15"/>
|
||||
<SubTexture name="normal-bottomleft" x="0" y="24" width="4" height="4"/>
|
||||
<SubTexture name="normal-bottom" x="4" y="24" width="12" height="4"/>
|
||||
<SubTexture name="normal-bottomright" x="16" y="24" width="4" height="4"/>
|
||||
|
||||
<SubTexture name="hover-topleft" x="20" y="0" width="4" height="4"/>
|
||||
<SubTexture name="hover-top" x="24" y="0" width="12" height="4"/>
|
||||
<SubTexture name="hover-topright" x="36" y="0" width="4" height="4"/>
|
||||
<SubTexture name="hover-middleleft" x="20" y="8" width="4" height="15"/>
|
||||
<SubTexture name="hover-middle" x="24" y="8" width="12" height="15"/>
|
||||
<SubTexture name="hover-middleright" x="36" y="8" width="4" height="15"/>
|
||||
<SubTexture name="hover-bottomleft" x="20" y="24" width="4" height="4"/>
|
||||
<SubTexture name="hover-bottom" x="24" y="24" width="12" height="4"/>
|
||||
<SubTexture name="hover-bottomright" x="36" y="24" width="4" height="4"/>
|
||||
|
||||
<SubTexture name="pressed-topleft" x="40" y="0" width="4" height="4"/>
|
||||
<SubTexture name="pressed-top" x="44" y="0" width="12" height="4"/>
|
||||
<SubTexture name="pressed-topright" x="56" y="0" width="4" height="4"/>
|
||||
<SubTexture name="pressed-middleleft" x="40" y="8" width="4" height="15"/>
|
||||
<SubTexture name="pressed-middle" x="44" y="8" width="12" height="15"/>
|
||||
<SubTexture name="pressed-middleright" x="56" y="8" width="4" height="15"/>
|
||||
<SubTexture name="pressed-bottomleft" x="40" y="24" width="4" height="4"/>
|
||||
<SubTexture name="pressed-bottom" x="44" y="24" width="12" height="4"/>
|
||||
<SubTexture name="pressed-bottomright" x="56" y="24" width="4" height="4"/>
|
||||
</TextureAtlas>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.6 KiB |
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextureAtlas imagePath="button.png">
|
||||
<!-- Created without animate lol i wrote this-->
|
||||
<SubTexture name="normal-topleft" x="0" y="0" width="8" height="8"/>
|
||||
<SubTexture name="normal-top" x="8" y="0" width="16" height="8"/>
|
||||
<SubTexture name="normal-topright" x="24" y="0" width="8" height="8"/>
|
||||
<SubTexture name="normal-middleleft" x="0" y="8" width="8" height="16"/>
|
||||
<SubTexture name="normal-middle" x="8" y="8" width="16" height="16"/>
|
||||
<SubTexture name="normal-middleright" x="24" y="8" width="8" height="16"/>
|
||||
<SubTexture name="normal-bottomleft" x="0" y="24" width="8" height="8"/>
|
||||
<SubTexture name="normal-bottom" x="8" y="24" width="16" height="8"/>
|
||||
<SubTexture name="normal-bottomright" x="24" y="24" width="8" height="8"/>
|
||||
|
||||
<SubTexture name="hover-topleft" x="32" y="0" width="8" height="8"/>
|
||||
<SubTexture name="hover-top" x="40" y="0" width="16" height="8"/>
|
||||
<SubTexture name="hover-topright" x="56" y="0" width="8" height="8"/>
|
||||
<SubTexture name="hover-middleleft" x="32" y="8" width="8" height="16"/>
|
||||
<SubTexture name="hover-middle" x="40" y="8" width="16" height="16"/>
|
||||
<SubTexture name="hover-middleright" x="56" y="8" width="8" height="16"/>
|
||||
<SubTexture name="hover-bottomleft" x="32" y="24" width="8" height="8"/>
|
||||
<SubTexture name="hover-bottom" x="40" y="24" width="16" height="8"/>
|
||||
<SubTexture name="hover-bottomright" x="56" y="24" width="8" height="8"/>
|
||||
|
||||
<SubTexture name="pressed-topleft" x="64" y="0" width="8" height="8"/>
|
||||
<SubTexture name="pressed-top" x="72" y="0" width="16" height="8"/>
|
||||
<SubTexture name="pressed-topright" x="88" y="0" width="8" height="8"/>
|
||||
<SubTexture name="pressed-middleleft" x="64" y="8" width="8" height="16"/>
|
||||
<SubTexture name="pressed-middle" x="72" y="8" width="16" height="16"/>
|
||||
<SubTexture name="pressed-middleright" x="80" y="8" width="8" height="16"/>
|
||||
<SubTexture name="pressed-bottomleft" x="64" y="24" width="8" height="8"/>
|
||||
<SubTexture name="pressed-bottom" x="72" y="24" width="16" height="8"/>
|
||||
<SubTexture name="pressed-bottomright" x="80" y="24" width="8" height="8"/>
|
||||
</TextureAtlas>
|
||||
+1
-1
@@ -1 +1 @@
|
||||
2508
|
||||
2514
|
||||
@@ -13,5 +13,8 @@ class UIDebugState extends UIState {
|
||||
|
||||
add(new UICheckbox(10, 10, "Test unchecked", false));
|
||||
add(new UICheckbox(10, 40, "Test checked", true));
|
||||
add(new UIButton(10, 70, "Test button", function() {
|
||||
trace("Hello, World!");
|
||||
}, 120, 20));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package funkin.editors.ui;
|
||||
|
||||
import flixel.graphics.frames.FlxFrame;
|
||||
|
||||
class UIButton extends UISprite {
|
||||
public var bWidth:Int = 120;
|
||||
public var bHeight:Int = 20;
|
||||
public var callback:Void->Void = null;
|
||||
|
||||
public function resize(w:Int, h:Int) {
|
||||
bWidth = w;
|
||||
bHeight = h;
|
||||
}
|
||||
|
||||
public override function new(x:Float, y:Float, t:String, callback:Void->Void, w:Float = 120, h:Float = 20) {
|
||||
super(x, y);
|
||||
frames = CoolUtil.loadFrames(Paths.image('editors/ui/button'));
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public override function updateButton() {
|
||||
__rect.x = x;
|
||||
__rect.y = y;
|
||||
__rect.width = bWidth;
|
||||
__rect.height = bHeight;
|
||||
UIState.state.updateRectButtonHandler(this, __rect, onHovered);
|
||||
}
|
||||
|
||||
public override function onHovered() {
|
||||
super.onHovered();
|
||||
if (FlxG.mouse.justReleased && callback != null)
|
||||
callback();
|
||||
}
|
||||
|
||||
public override function draw() {
|
||||
var x:Float = this.x;
|
||||
var y:Float = this.y;
|
||||
var offset:Int = hovered ? (pressed ? 18 : 9) : 0;
|
||||
|
||||
var topleft:FlxFrame = frames.frames[offset];
|
||||
var top:FlxFrame = frames.frames[offset + 1];
|
||||
var topright:FlxFrame = frames.frames[offset + 2];
|
||||
var middleleft:FlxFrame = frames.frames[offset + 3];
|
||||
var middle:FlxFrame = frames.frames[offset + 4];
|
||||
var middleright:FlxFrame = frames.frames[offset + 5];
|
||||
var bottomleft:FlxFrame = frames.frames[offset + 6];
|
||||
var bottom:FlxFrame = frames.frames[offset + 7];
|
||||
var bottomright:FlxFrame = frames.frames[offset + 8];
|
||||
|
||||
@:privateAccess {
|
||||
// TOP LEFT
|
||||
frame = topleft;
|
||||
setPosition(x, y);
|
||||
__setSize(topleft.frame.width, topleft.frame.height);
|
||||
super.draw();
|
||||
|
||||
// TOP
|
||||
frame = top;
|
||||
setPosition(x + topleft.frame.width, y);
|
||||
__setSize(bWidth - topleft.frame.width - topright.frame.width, top.frame.height);
|
||||
super.draw();
|
||||
|
||||
// TOP RIGHT
|
||||
frame = topright;
|
||||
setPosition(x + bWidth - topright.frame.width, y);
|
||||
__setSize(topright.frame.width, topright.frame.height);
|
||||
super.draw();
|
||||
|
||||
// MIDDLE LEFT
|
||||
frame = middleleft;
|
||||
setPosition(x, y + top.frame.height);
|
||||
__setSize(middleleft.frame.width, bHeight - topleft.frame.height - bottomleft.frame.height);
|
||||
super.draw();
|
||||
|
||||
// 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);
|
||||
super.draw();
|
||||
|
||||
// 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);
|
||||
super.draw();
|
||||
|
||||
// BOTTOM LEFT
|
||||
frame = bottomleft;
|
||||
setPosition(x, y + bHeight - bottom.frame.height);
|
||||
__setSize(bottomleft.frame.width, bottomleft.frame.height);
|
||||
super.draw();
|
||||
|
||||
// BOTTOM
|
||||
frame = bottom;
|
||||
setPosition(x + bottomleft.frame.width, y + bHeight - bottom.frame.height);
|
||||
__setSize(bWidth - bottomleft.frame.width - bottomright.frame.width, bottom.frame.height);
|
||||
super.draw();
|
||||
|
||||
// BOTTOM RIGHT
|
||||
frame = bottomright;
|
||||
setPosition(x + bWidth - bottomright.frame.width, y + bHeight - bottom.frame.height);
|
||||
__setSize(bottomright.frame.width, bottomright.frame.height);
|
||||
super.draw();
|
||||
}
|
||||
|
||||
|
||||
setPosition(x, y);
|
||||
}
|
||||
|
||||
private function __setSize(Width:Float, Height:Float) {
|
||||
var newScaleX:Float = Width / frameWidth;
|
||||
var newScaleY:Float = Height / frameHeight;
|
||||
scale.set(newScaleX, newScaleY);
|
||||
|
||||
if (Width <= 0)
|
||||
scale.x = newScaleY;
|
||||
else if (Height <= 0)
|
||||
scale.y = newScaleX;
|
||||
|
||||
updateHitbox();
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,12 @@ package funkin.editors.ui;
|
||||
import funkin.ui.FunkinText;
|
||||
|
||||
class UICheckbox extends UISprite {
|
||||
public var checked:Bool = false;
|
||||
public var onChecked:Bool->Void = null;
|
||||
|
||||
public var field:FunkinText;
|
||||
public var check:FlxSprite;
|
||||
|
||||
public var checked:Bool = false;
|
||||
|
||||
var hovered:Bool = false;
|
||||
var pressed:Bool = false;
|
||||
public function new(x:Float, y:Float, text:String, checked:Bool = false, w:Int = 0) {
|
||||
super(x, y);
|
||||
loadGraphic(Paths.image('editors/ui/checkbox'), true, 20, 20);
|
||||
@@ -29,8 +28,6 @@ class UICheckbox extends UISprite {
|
||||
public override function update(elapsed:Float) {
|
||||
// ANIMATION HANDLING
|
||||
animation.play(hovered ? (pressed ? "pressed" : "hover") : "normal");
|
||||
hovered = false;
|
||||
pressed = false;
|
||||
|
||||
// CHECKMARK HANDLING
|
||||
check.alpha = checked ? 1 : 0;
|
||||
@@ -56,9 +53,7 @@ class UICheckbox extends UISprite {
|
||||
}
|
||||
|
||||
public override function onHovered() {
|
||||
hovered = true;
|
||||
if (FlxG.mouse.pressed)
|
||||
pressed = true;
|
||||
super.onHovered();
|
||||
if (FlxG.mouse.justReleased) {
|
||||
// clicked
|
||||
checked = !checked;
|
||||
@@ -66,6 +61,8 @@ class UICheckbox extends UISprite {
|
||||
|
||||
if (Options.editorSFX)
|
||||
CoolUtil.playMenuSFX(checked ? CHECKED : UNCHECKED, 0.5);
|
||||
if (onChecked != null)
|
||||
onChecked(checked);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@ class UISprite extends FlxSprite {
|
||||
|
||||
private var __oldDefCams:Array<FlxCamera>;
|
||||
|
||||
var hovered:Bool = false;
|
||||
var pressed:Bool = false;
|
||||
|
||||
public override function update(elapsed:Float) {
|
||||
super.update(elapsed);
|
||||
updateButton();
|
||||
@@ -25,6 +28,9 @@ class UISprite extends FlxSprite {
|
||||
|
||||
FlxCamera._defaultCameras = __oldDefCams;
|
||||
}
|
||||
|
||||
hovered = false;
|
||||
pressed = false;
|
||||
}
|
||||
|
||||
public override function draw() {
|
||||
@@ -56,6 +62,8 @@ class UISprite extends FlxSprite {
|
||||
* Called whenever the sprite is being hovered by the mouse.
|
||||
*/
|
||||
public function onHovered() {
|
||||
|
||||
hovered = true;
|
||||
if (FlxG.mouse.pressed)
|
||||
pressed = true;
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ class UIState extends MusicBeatState {
|
||||
updateRectButtonHandler(spr, spr.__rect, buttonHandler);
|
||||
}
|
||||
|
||||
|
||||
public function updateRectButtonHandler(spr:UISprite, rect:FlxRect, buttonHandler:Void->Void) {
|
||||
var pos = FlxG.mouse.getScreenPosition(camera);
|
||||
for(camera in spr.__lastDrawCameras) {
|
||||
|
||||
Reference in New Issue
Block a user