From 315d5b9ecd89d2ac44806f28c9adce88a5db43f7 Mon Sep 17 00:00:00 2001 From: lunarcleint <88809950+lunarcleint@users.noreply.github.com> Date: Thu, 25 Jul 2024 18:55:12 -0700 Subject: [PATCH] edit info screen --- assets/images/editors/ui/picker.png | Bin 0 -> 137 bytes .../editors/character/CharacterEditor.hx | 10 - .../editors/character/CharacterInfoScreen.hx | 183 ++++++++++++++++++ .../character/CharacterPropertiesWindow.hx | 12 +- 4 files changed, 194 insertions(+), 11 deletions(-) create mode 100644 assets/images/editors/ui/picker.png create mode 100644 source/funkin/editors/character/CharacterInfoScreen.hx diff --git a/assets/images/editors/ui/picker.png b/assets/images/editors/ui/picker.png new file mode 100644 index 0000000000000000000000000000000000000000..12fb58a14b8fd0fdcad5f9c0a937cbed752369cd GIT binary patch literal 137 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1|-8uW1a&k#^NA%Cx&(BWL^R}&YmugAsQ2p zo;BoSP~dRB82`TByssr#c+tfd32&GVYaiI2l2%p4eu3}0$E8gM(|Q; + var holdTime:Float; + var customProperties:Map; +} + +class CharacterInfoScreen extends UISubstateWindow { + public var character:Character; + + public var iconColorPicker:UIIconColorPicker; + public var iconColorWheel:UIColorwheel; + + public var useDurationCheckbox:UICheckbox; + public var durationStepper:UINumericStepper; + + public var customPropertiesButtonList:UIButtonList; + + public var saveButton:UIButton; + public var closeButton:UIButton; + + public var onSave:(info:CharacterExtraInfo) -> Void = null; + + public function new(character:Character, onSave:(info:CharacterExtraInfo) -> Void) { + this.character = character; + this.onSave = onSave; + super(); + } + + public override function create() { + winTitle = 'Edit Character Properties...'; + winWidth = 824; winHeight = 400; + + super.create(); + + function addLabelOn(ui:UISprite, text:String) + add(new UIText(ui.x, ui.y - 24, 0, text)); + + var title:UIText; + add(title = new UIText(windowSpr.x + 20, windowSpr.y + 30 + 16, 0, "Edit Character Info", 28)); + + iconColorPicker = new UIIconColorPicker(title.x, title.y + title.height + 38, character.getIcon(), character.antialiasing, null); + add(iconColorPicker); + addLabelOn(iconColorPicker, "Icon"); + + iconColorWheel = new UIColorwheel(iconColorPicker.x+12+125+12+22, iconColorPicker.y, character.iconColor); + add(iconColorWheel); + addLabelOn(iconColorWheel, "Icon Color"); + + iconColorPicker.colorWheel = iconColorWheel; + + durationStepper = new UINumericStepper(iconColorWheel.x, iconColorWheel.y + 125 + 36, character.holdTime == -1 ? 4 : character.holdTime, 0.001, 2, 0, 9999999, 74); + add(durationStepper); + addLabelOn(durationStepper, "Sing Duration"); + + useDurationCheckbox = new UICheckbox(durationStepper.x + durationStepper.bWidth + 20, durationStepper.y+6, "Use Sing Duration?", character.holdTime != -1); + useDurationCheckbox.onChecked = (checked:Bool) -> {durationStepper.selectable = checked;}; + add(useDurationCheckbox); + + durationStepper.selectable = useDurationCheckbox.checked; + + customPropertiesButtonList = new UIButtonList(iconColorWheel.x+iconColorWheel.bWidth+22, iconColorWheel.y, 290, 200, '', FlxPoint.get(280, 35), null, 5); + customPropertiesButtonList.frames = Paths.getFrames('editors/ui/inputbox'); + customPropertiesButtonList.cameraSpacing = 0; + customPropertiesButtonList.addButton.callback = function() { + customPropertiesButtonList.add(new PropertyButton("newProperty", "valueHere", customPropertiesButtonList)); + } + + for (prop=>val in character.extra) + if (prop != StageEditor.exID("bounds")) + customPropertiesButtonList.add(new PropertyButton(prop, val, customPropertiesButtonList)); + + add(customPropertiesButtonList); + addLabelOn(customPropertiesButtonList, "Custom Values (Advanced)"); + + saveButton = new UIButton(windowSpr.x + windowSpr.bWidth - 20 - 125, windowSpr.y + windowSpr.bHeight - 16 - 32, "Save & Close", function() { + saveCharacterInfo(); + close(); + }, 125); + add(saveButton); + + closeButton = new UIButton(saveButton.x - 20 - saveButton.bWidth, saveButton.y, "Close", function() { + onSave(null); + close(); + }, 125); + add(closeButton); + closeButton.color = 0xFFFF0000; + } + + public function saveCharacterInfo() { + @:privateAccess durationStepper.__onChange(durationStepper.label.text); + + if (onSave != null) onSave({ + icon: iconColorPicker.iconTextBox.label.text, + iconColor: iconColorWheel.curColor, + holdTime: useDurationCheckbox.checked ? durationStepper.value : -1, + customProperties: [ + for (val in customPropertiesButtonList.buttons.members) + val.propertyText.label.text => val.valueText.label.text + ] + }); + } +} + +class UIIconColorPicker extends UISliceSprite { + public var colorWheel:UIColorwheel; + + public var iconSprite:FlxSprite; + public var iconTextBox:UITextBox; + + public var pickerButton:UIButton; + public var pickerIcon:FlxSprite; + + public function new(x:Float, y:Float, icon:String, antialaising:Bool, colorWheel:UIColorwheel) { + super(x, y, 12+125+12, 4+125+4+32+12, 'editors/ui/inputbox'); + + this.colorWheel = colorWheel; + + iconTextBox = new UITextBox(x+12, y+4+125+4, icon, 125); + iconTextBox.onChange = (newIcon:String) -> {updateIcon(newIcon);} + members.push(iconTextBox); + + members.push(iconSprite = new FlxSprite()); + iconSprite.antialiasing = antialaising; + + pickerButton = new UIButton(x+12+125-26, y+12, "", colorPick, 26, 26); + pickerButton.frames = Paths.getFrames('editors/ui/inputbox'); + members.push(pickerButton); + + pickerIcon = new FlxSprite(pickerButton.x+7, pickerButton.y+7).loadGraphic(Paths.image("editors/ui/picker")); + members.push(pickerIcon); + + updateIcon(icon); + } + + var __path:String = null; + public function updateIcon(icon:String) { + if (iconSprite.animation.exists(icon)) return; + @:privateAccess iconSprite.animation.clearAnimations(); + + var path:String = Paths.image('icons/$icon'); + if (!Assets.exists(path)) path = Paths.image('icons/face'); + + iconSprite.loadGraphic(__path = path, true, 150, 150); + iconSprite.animation.add(icon, [0], 0, false); + iconSprite.animation.play(icon); + + iconSprite.scale.set(125/150, 125/150); + iconSprite.updateHitbox(); + iconSprite.setPosition(x+12, y+4); + + __cachedColor = null; + } + + var __cachedColor:Null = null; + public function colorPick() { + if (__cachedColor == null) { + var imageBitmap:BitmapData = Assets.getBitmapData(__path, true, false); + __cachedColor = imageBitmap.getMostPresentColor(); + imageBitmap.dispose(); + } + + if (colorWheel != null) { + colorWheel.hue = __cachedColor.hue; + colorWheel.saturation = __cachedColor.saturation; + colorWheel.brightness = __cachedColor.brightness; + colorWheel.updateWheel(); + } + } +} \ No newline at end of file diff --git a/source/funkin/editors/character/CharacterPropertiesWindow.hx b/source/funkin/editors/character/CharacterPropertiesWindow.hx index 4349bab4..6f3c40e7 100644 --- a/source/funkin/editors/character/CharacterPropertiesWindow.hx +++ b/source/funkin/editors/character/CharacterPropertiesWindow.hx @@ -1,5 +1,6 @@ package funkin.editors.character; +import funkin.editors.character.CharacterInfoScreen.CharacterExtraInfo; import funkin.game.Character; class CharacterPropertiesWindow extends UISliceSprite { @@ -48,7 +49,7 @@ class CharacterPropertiesWindow extends UISliceSprite { members.push(scaleStepper); addLabelOn(scaleStepper, "Scale"); - editCharacterButton = new UIButton(scaleStepper.x + 90 -32 + 26, scaleStepper.y, "Edit Info", null); + editCharacterButton = new UIButton(scaleStepper.x + 90 -32 + 26, scaleStepper.y, "Edit Info", editCharacterInfoUI); members.push(editCharacterButton); flipXCheckbox = new UICheckbox(scaleStepper.x+22, scaleStepper.y+32+14, "Flipped?", character.isPlayer ? !character.__baseFlipped : character.__baseFlipped); @@ -120,6 +121,15 @@ class CharacterPropertiesWindow extends UISliceSprite { CharacterEditor.instance.playAnimation(character.getAnimName()); } + public function editCharacterInfoUI() { + CharacterEditor.instance.openSubState(new CharacterInfoScreen(character, (info:CharacterExtraInfo) -> { + character.icon = info.icon; + character.iconColor = info.iconColor; + character.holdTime = info.holdTime; + character.extra = info.customProperties.copy(); + })); + } + public function changeFlipX(newFlipX:Bool) @:privateAccess { character.flipX = character.isPlayer ? !newFlipX : newFlipX; character.__baseFlipped = character.flipX;