fix character editor bugs +clean up code

This commit is contained in:
lunarcleint
2025-04-08 18:23:16 -07:00
parent d2fb59ecd4
commit b1f9f3fb1a
13 changed files with 383 additions and 15 deletions
@@ -147,7 +147,10 @@ class CharacterAnimButton extends UIButton {
deleteIcon.antialiasing = false;
members.push(deleteIcon);
editButton = new UIButton(0, 0, null, () -> {this.closed = !this.closed;}, 28,24);
editButton = new UIButton(0, 0, null, () -> {
if (!this.closed) UIUtil.confirmUISelections(this);
this.closed = !this.closed;
}, 28,24);
editButton.frames = Paths.getFrames("editors/ui/grayscale-button");
editButton.color = 0xFFAFAA12;
members.push(editButton);
@@ -7,6 +7,7 @@ import flixel.graphics.FlxGraphic;
import openfl.geom.Rectangle;
import flixel.graphics.frames.FlxFrame;
import funkin.game.Character;
import flixel.animation.FlxPrerotatedAnimation;
using funkin.backend.utils.BitmapUtil;
@@ -78,7 +79,7 @@ class CharacterAnimsWindow extends UIButtonList<CharacterAnimButton> {
var frameRect:Rectangle = new Rectangle(frame.offset.x, frame.offset.y, frame.sourceSize.x, frame.sourceSize.y);
var animBounds:Rectangle = displayWindowGraphic != null ? displayWindowGraphic.bitmap.bounds(frameRect) : frameRect;
displayAnimsFramesList.set(name, {frame: anim.frames.getDefault([0])[0], scale: 104/animBounds.height, animBounds: animBounds});
displayAnimsFramesList.set(name, {frame: anim.frames.getDefault([0])[0], scale: 104/Math.max(animBounds.width, animBounds.height), animBounds: animBounds});
} else {
character.storeAtlasState();
@@ -102,7 +102,7 @@ class CharacterInfoScreen extends UISubstateWindow {
}
public function saveCharacterInfo() {
@:privateAccess durationStepper.__onChange(durationStepper.label.text);
UIUtil.confirmUISelections(this);
if (onSave != null) onSave({
icon: iconColorPicker.iconTextBox.label.text,
@@ -144,8 +144,7 @@ class ChartCreationScreen extends UISubstateWindow {
var strumLines:Array<ChartStrumLine> = [];
for (strline in strumLineList.buttons.members) {
for (stepper in [strline.hudXStepper, strline.hudYStepper, strline.hudScaleStepper])
@:privateAccess stepper.__onChange(stepper.label.text);
UIUtil.confirmUISelections(strline);
strumLines.push({
characters: [for (char in strline.charactersList.buttons.members) char.textBox.label.text],
@@ -75,9 +75,8 @@ class ChartDataScreen extends UISubstateWindow {
add(previewStrumLine);
}
public function saveInfo()
{
@:privateAccess scrollSpeedStepper.__onChange(scrollSpeedStepper.label.text);
public function saveInfo() {
UIUtil.confirmUISelections(this);
var oldData:{stage:String, speed:Float} = {stage: PlayState.SONG.stage, speed: PlayState.SONG.scrollSpeed};
@@ -143,8 +143,7 @@ class CharterMetaDataScreen extends UISubstateWindow {
}
public function saveMeta() {
for (stepper in [bpmStepper, beatsPerMeasureStepper, stepsPerBeatStepper])
@:privateAccess stepper.__onChange(stepper.label.text);
UIUtil.confirmUISelections(this);
var customVals = {};
for (vals in customPropertiesButtonList.buttons.members) {
@@ -190,8 +190,7 @@ class CharterStrumlineScreen extends UISubstateWindow {
}
function saveStrumline() {
for (stepper in [hudXStepper, hudYStepper, hudScaleStepper, keyCountStepper, hudSpacingStepper])
@:privateAccess stepper.__onChange(stepper.label.text);
UIUtil.confirmUISelections(this);
var newStrumLine:ChartStrumLine = {
characters: [
@@ -228,8 +228,7 @@ class SongCreationScreen extends UISubstateWindow {
}
function saveSongInfo() {
for (stepper in [bpmStepper, beatsPerMeasureStepper, stepsPerBeatStepper])
@:privateAccess stepper.__onChange(stepper.label.text);
UIUtil.confirmUISelections(this);
var meta:ChartMetaData = {
name: songNameTextBox.label.text,
+33
View File
@@ -1,5 +1,6 @@
package funkin.editors.ui;
import flixel.util.typeLimit.OneOfTwo;
import flixel.input.FlxInput.FlxInputState;
import flixel.input.keyboard.FlxKey;
import funkin.editors.ui.UIContextMenu.UIContextMenuOption;
@@ -125,4 +126,36 @@ class UIUtil {
public static inline function prettify(str:String) {
return [for(s in str.split(" ")) [for(k=>l in s.split("")) k == 0 ? l.toUpperCase() : l.toLowerCase()].join("")].join(" ");
}
/**
* For when the user closes out before confriming all ui selections
* @param ui the thingy you wanna check
*/
public static function confirmUISelections(ui:OneOfTwo<UISprite, UIState>) {
var members:Array<FlxBasic> = [];
if (ui is UISprite)
members = cast(ui, UISprite).members;
else if (ui is UIState)
members = cast(ui, UIState).members;
for (member in members) {
if (member is UINumericStepper) @:privateAccess {
var stepper:UINumericStepper = cast member;
if (stepper.onChange != stepper.__onChange && stepper.__wasFocused) {
stepper.onChange(stepper.label.text);
stepper.__wasFocused = false;
} else stepper.__onChange(stepper.label.text);
} else if (member is UITextBox) @:privateAccess {
var textbox:UITextBox = cast member;
if (textbox.__wasFocused) {
textbox.onChange(textbox.label.text);
textbox.__wasFocused = false;
}
}
if (member is UISprite || ui is UIState)
confirmUISelections(cast member);
}
}
}