Files
CodenameEngine/source/funkin/editors/ui/UIButton.hx
T
TheZoroForce240andGitHub 4fe3ba76e3 Charter/Editor additions and fixes (#793)
* camera highlights again

* option to mute all hitsounds

* context menus inside context menus and wip sliders in context menu

* wip volume slider stuff

* strumline preview fix with resizable editors

* more slider stuff

* editor sfx option should now actually work for everything

* fixed strumline vocals volume, fixed note type option keybinds and moved bookmarks and note types into submenus

* fix for saving difficulty specific meta json

* some extra misc changes

fixed camera highlights not updating when zooming in/out, optimized some of the highlight draw code so it doesn't do a full loop, and added the note scale flag into the strumline preview

* fix compiling after merge
2026-03-01 21:13:33 +07:00

59 lines
1.5 KiB
Haxe

package funkin.editors.ui;
class UIButton extends UISliceSprite {
public var callback:Void->Void = null;
public var field:UIText;
public var shouldPress = true;
public var hasBeenPressed = false;
public var autoFrames:Bool = true;
public var autoFollow: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;
if(text != null) {
members.push(field = new UIText(x, y, w, text));
field.alignment = CENTER;
field.fieldWidth = w;
}
cursor = CLICK;
}
public override function resize(w:Int, h:Int) {
super.resize(w, h);
if (field != null && autoFollow) field.fieldWidth = w;
}
public override function onHovered() {
super.onHovered();
if (FlxG.mouse.justPressed) {
hasBeenPressed = true;
UIState.playEditorSound(Flags.DEFAULT_EDITOR_BUTTONCLICK_SOUND);
}
if (FlxG.mouse.justReleased && callback != null && shouldPress && hasBeenPressed) {
callback();
hasBeenPressed = false;
}
}
public override function update(elapsed:Float) {
if (autoFollow && field != null) field.follow(this, 0, (bHeight - field.height) / 2);
if (!hovered && hasBeenPressed && FlxG.mouse.justReleased) hasBeenPressed = false;
if (autoAlpha) {
alpha = selectable ? 1 : 0.4;
if(field != null) field.alpha = alpha;
}
super.update(elapsed);
}
public override function draw() {
setFrameOffset();
super.draw();
}
public function setFrameOffset() {
framesOffset = hovered ? (pressed ? 18 : 9) : 0;
}
}