From 66953e4609af6138fe9c5d47a11d26877643904d Mon Sep 17 00:00:00 2001 From: Furo Date: Thu, 28 Nov 2024 18:03:19 +0100 Subject: [PATCH] I like the part when the bookmark said its color picker time and then started coloring all over the place --- source/funkin/backend/chart/ChartData.hx | 1 + source/funkin/backend/utils/CoolUtil.hx | 9 ++ source/funkin/editors/charter/Charter.hx | 29 +++-- .../charter/CharterBookmarkCreation.hx | 65 +++++++++++ .../editors/charter/CharterBookmarkList.hx | 2 +- .../funkin/editors/ui/UICompactColorwheel.hx | 103 ++++++++++++++++++ 6 files changed, 199 insertions(+), 10 deletions(-) create mode 100644 source/funkin/editors/charter/CharterBookmarkCreation.hx create mode 100644 source/funkin/editors/ui/UICompactColorwheel.hx diff --git a/source/funkin/backend/chart/ChartData.hx b/source/funkin/backend/chart/ChartData.hx index 565e2def..212c0065 100644 --- a/source/funkin/backend/chart/ChartData.hx +++ b/source/funkin/backend/chart/ChartData.hx @@ -61,6 +61,7 @@ typedef ChartNote = { typedef ChartBookmark = { var time:Float; var name:String; + var color:String; } typedef ChartEvent = { diff --git a/source/funkin/backend/utils/CoolUtil.hx b/source/funkin/backend/utils/CoolUtil.hx index f4214029..2017d8f9 100644 --- a/source/funkin/backend/utils/CoolUtil.hx +++ b/source/funkin/backend/utils/CoolUtil.hx @@ -1046,6 +1046,15 @@ final class CoolUtil } return result; } + + /** + * Gets the luminance of the given color + * @param color Color to use + * @return Number between 0 and 1 + */ + public static function getLuminance(color:FlxColor):Float { + return (0.2126*color.redFloat + 0.7152*color.greenFloat + 0.0722*color.blueFloat); + } } /** diff --git a/source/funkin/editors/charter/Charter.hx b/source/funkin/editors/charter/Charter.hx index 82b42646..553217c6 100644 --- a/source/funkin/editors/charter/Charter.hx +++ b/source/funkin/editors/charter/Charter.hx @@ -18,6 +18,7 @@ import funkin.editors.ui.UIContextMenu.UIContextMenuOptionSpr; import funkin.editors.ui.UIState; import funkin.editors.ui.UITopMenu.UITopMenuButton; import haxe.Json; +import flixel.util.FlxColor; class Charter extends UIState { public static var __song:String; @@ -1729,13 +1730,19 @@ class Charter extends UIState { } function _bookmarks_add(_) { - var currentBookmarks:Array = getBookmarkList(); - var newBookmarks:Array = getBookmarkList(); - newBookmarks.push({time: curStepFloat, name: "New Bookmark"}); - - PlayState.SONG.bookmarks = newBookmarks; - updateBookmarks(); - undos.addToUndo(CEditBookmarks(currentBookmarks, newBookmarks)); + FlxG.state.openSubState(new CharterBookmarkCreation(curStepFloat, function(success:Bool, name:String, color:FlxColor, daStep:Float) + { + if (success) + { + var currentBookmarks:Array = getBookmarkList(); + var newBookmarks:Array = getBookmarkList(); + newBookmarks.push({time: daStep, name: name, color: color.toWebString()}); + + PlayState.SONG.bookmarks = newBookmarks; + updateBookmarks(); + undos.addToUndo(CEditBookmarks(currentBookmarks, newBookmarks)); + } + })); } function _bookmarks_edit_list(_) FlxG.state.openSubState(new CharterBookmarkList()); //idk why its FlxG.state but it looks so off lmfao @@ -1763,7 +1770,8 @@ class Charter extends UIState { __bookmarkObjects.clear(); for (b in getBookmarkList()) { - var bookmarkcolor = 0xff911dd9;//PURPLE TO SEE IT BETTER + var bookmarkcolor:FlxColor = b.color != null ? FlxColor.fromString(b.color) : 0xff9d00ff; + var luminance = CoolUtil.getLuminance(bookmarkcolor); var sprites = []; for (str in strumLines.members) @@ -1777,11 +1785,14 @@ class Charter extends UIState { sprites.push(bookmarkspr); } - var bookmarkText = new UIText(strumLines.members[0].x + 4, 0, 400, b.name, 15, bookmarkcolor); + var bookmarkText = new UIText(strumLines.members[0].x + 4, 0, 400, b.name, 15, bookmarkcolor, true); bookmarkText.y = sprites[0].y - (bookmarkText.height + 2); bookmarkText.camera = charterCamera; add(bookmarkText); + if (luminance < 0.5) + bookmarkText.borderColor = 0x88FFFFFF; + __bookmarkObjects.push([sprites, bookmarkText]); } diff --git a/source/funkin/editors/charter/CharterBookmarkCreation.hx b/source/funkin/editors/charter/CharterBookmarkCreation.hx new file mode 100644 index 00000000..a0a7ab19 --- /dev/null +++ b/source/funkin/editors/charter/CharterBookmarkCreation.hx @@ -0,0 +1,65 @@ +package funkin.editors.charter; + +import flixel.util.FlxColor; +import flixel.math.FlxPoint; +import funkin.backend.chart.ChartData.ChartBookmark; + +class CharterBookmarkCreation extends UISubstateWindow { + public var saveButton:UIButton; + public var closeButton:UIButton; + public var textBox:UITextBox; + public var colorPicker:UICompactColorwheel; + + var callback:Bool->String->FlxColor->Float->Void; + + var bookmarkStep:Float = 0; + + override public function new(step:Float, close:Bool->String->FlxColor->Float->Void) + { + super(); + + winWidth = 320; + winHeight = 250; + winTitle = 'Creating New Bookmark'; + + callback = close; + + bookmarkStep = step; + } + + public override function create() { + FlxG.sound.music.pause(); + Charter.instance.vocals.pause(); + + function addLabelOn(ui:UISprite, text:String):UIText { + var text:UIText = new UIText(ui.x, ui.y - 24, 0, text); + ui.members.push(text); + return text; + } + + super.create(); + + textBox = new UITextBox(windowSpr.x + 20, windowSpr.y + 70, "New Bookmark", 276); + textBox.antialiasing = true; + add(textBox); + addLabelOn(textBox, "Bookmark Name:"); + + colorPicker = new UICompactColorwheel(textBox.x, textBox.y + textBox.bHeight + 34, flixel.util.FlxColor.RED); + add(colorPicker); + addLabelOn(colorPicker, "Bookmark Color:"); + + saveButton = new UIButton(windowSpr.x + windowSpr.bWidth - 20 - 125, windowSpr.y + windowSpr.bHeight - 16 - 32, "Save & Close", function() { + callback(true, textBox.label.text, colorPicker.curColor, bookmarkStep); + close(); + }, 125); + add(saveButton); + + closeButton = new UIButton(saveButton.x - 20, saveButton.y, "Close", function() { + callback(false, "", FlxColor.TRANSPARENT, -1); + close(); + }, 125); + add(closeButton); + closeButton.color = 0xFFFF0000; + closeButton.x -= closeButton.bWidth; + } +} \ No newline at end of file diff --git a/source/funkin/editors/charter/CharterBookmarkList.hx b/source/funkin/editors/charter/CharterBookmarkList.hx index 715fef3d..032177db 100644 --- a/source/funkin/editors/charter/CharterBookmarkList.hx +++ b/source/funkin/editors/charter/CharterBookmarkList.hx @@ -48,7 +48,7 @@ class CharterBookmarkList extends UISubstateWindow { public function saveList() { var oldList:Array = Charter.instance.getBookmarkList(); - var newList:Array = [for (btn in bookmarkList.buttons.members) {time: btn.bookmark.time, name: btn.textBox.label.text}]; + var newList:Array = [for (btn in bookmarkList.buttons.members) {time: btn.bookmark.time, name: btn.textBox.label.text, color: btn.bookmark.color}]; PlayState.SONG.bookmarks = newList; Charter.instance.updateBookmarks(); diff --git a/source/funkin/editors/ui/UICompactColorwheel.hx b/source/funkin/editors/ui/UICompactColorwheel.hx new file mode 100644 index 00000000..7623a1de --- /dev/null +++ b/source/funkin/editors/ui/UICompactColorwheel.hx @@ -0,0 +1,103 @@ +package funkin.editors.ui; + +import flixel.util.FlxColor; +import flixel.math.FlxPoint; +import funkin.editors.ui.UIColorwheel.UIColorWheelSelector; + +using flixel.util.FlxSpriteUtil; + +class UICompactColorwheel extends UISliceSprite { + var colorSlider:FlxSprite; + var colorSliderSelector:UIColorWheelSelector; + + var whiteColorButton:UIButton; + + public var curColor:Null; + public var curColorString:String = "#FFFFFF"; + + public var hue:Float; + + public function new (x:Float, y:Float, ?color:Int) { + super(x, y, Std.int((12.5 * 3) + 116), Std.int((12.5 * 2) + (16)), 'editors/ui/inputbox'); + + curColor = cast color; + hue = curColor.hue; + + colorSlider = new FlxSprite(x + 12.5, y + 12.5).makeGraphic(100, 16, FlxColor.TRANSPARENT); + colorSlider.drawRoundRect(0, 0, 100, 16, 10, 10, FlxColor.WHITE); + + colorSlider.pixels.lock(); + for (pixelx in 0...Std.int(colorSlider.width)) { + var color:Int = FlxColor.fromHSB(pixelx / (colorSlider.width-1) * 360, 1, 1); + for (pixely in 0...Std.int(colorSlider.height)) + if (colorSlider.pixels.getPixel32(pixelx, pixely) != FlxColor.TRANSPARENT) colorSlider.pixels.setPixel32(pixelx, pixely, color); + } + colorSlider.pixels.unlock(); + + whiteColorButton = new UIButton(colorSlider.x + colorSlider.width + 12.5, colorSlider.y, null, () -> { + setColor(FlxColor.WHITE); + }, 16, 16); + whiteColorButton.colorTransform.color = FlxColor.WHITE; + + colorSliderSelector = new UIColorWheelSelector(colorSlider.x, colorSlider.y); + + colorSlider.antialiasing = true; + + for (item in [colorSlider, colorSliderSelector, whiteColorButton]) + members.push(item); + + updateColor(false); + } + + inline function updateColorSliderPickerSelector() + colorSliderSelector.selector.setPosition(colorSlider.x + (hue / 360 * (colorSlider.width-1)) - 8, colorSlider.y); + + inline function updateColorSliderMouse(mousePos:FlxPoint) + hue = (mousePos.x / colorSlider.width) * 360; + + function setColor(newColor:FlxColor) { + this.color = curColor = colorSliderSelector.curColor = newColor; + } + + public function updateColor(checkChanged:Bool = true) { + if(checkChanged) colorChanged = true; + setColor(FlxColor.fromHSB(hue, 1, 1)); + + updateColorSliderPickerSelector(); + curColorString = curColor.toWebString(); + } + + // For Character Editor + public var colorChanged:Bool = false; + + // Make the colorwheel feel better + static inline var hitBoxExtenstion:Float = 8; + + var selectedSprite = null; + public override function update(elapsed:Float) { + var mousePos = FlxG.mouse.getScreenPosition(__lastDrawCameras[0], FlxPoint.get()); + if (hovered && FlxG.mouse.justPressed) { + for (sprite in [colorSlider]) { + var spritePos:FlxPoint = sprite.getScreenPosition(FlxPoint.get(), __lastDrawCameras[0]); + if (FlxMath.inBounds(mousePos.x, spritePos.x - (hitBoxExtenstion/2), spritePos.x - (hitBoxExtenstion/2) + (sprite.width + hitBoxExtenstion)) && FlxMath.inBounds(mousePos.y, spritePos.y - (hitBoxExtenstion/2), spritePos.y - (hitBoxExtenstion/2) + (sprite.height + hitBoxExtenstion))) { + selectedSprite = sprite; + break; + } + } + } + + if (selectedSprite != null) { + var spritePos:FlxPoint = selectedSprite.getScreenPosition(FlxPoint.get(), __lastDrawCameras[0]); + mousePos -= FlxPoint.weak(spritePos.x, spritePos.y); + mousePos.set(CoolUtil.bound(mousePos.x, 0, selectedSprite.width), CoolUtil.bound(mousePos.y, 0, selectedSprite.height)); + + if (selectedSprite == colorSlider) updateColorSliderMouse(mousePos); + updateColor(); + spritePos.put(); + + if (FlxG.mouse.justReleased) selectedSprite = null; + } + mousePos.put(); + super.update(elapsed); + } +} \ No newline at end of file