From feaf8b230dc9effa914e06cf253b9577dd2e44f8 Mon Sep 17 00:00:00 2001 From: lemz1 Date: Sat, 9 Nov 2024 20:30:23 +0100 Subject: [PATCH] icon selection stuff --- .../debug/char/pages/CharCreatorSelectPage.hx | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx b/source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx index 6477afc26e..89fb1f00b5 100644 --- a/source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx +++ b/source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx @@ -12,9 +12,16 @@ import flixel.tweens.FlxTween; import flixel.FlxSprite; import openfl.display.BlendMode; import openfl.filters.ShaderFilter; +import funkin.ui.charSelect.Lock; +import funkin.util.MathUtil; +import flixel.math.FlxPoint; +import flixel.math.FlxMath; +import flixel.FlxG; class CharCreatorSelectPage extends CharCreatorDefaultPage { + static final ICON_SIZE:Float = 128; + var data:WizardGenerateParams; var nametag:FlxSprite; @@ -23,6 +30,8 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage var availableChars:Map = new Map(); var fadeShader:funkin.graphics.shaders.BlueFade = new funkin.graphics.shaders.BlueFade(); + var selectedIndex:Int = 0; + override public function new(state:CharCreatorState, data:WizardGenerateParams) { super(state); @@ -32,6 +41,8 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage // copied sum code LOL initBackground(); + initForeground(); + // gf and player code doodoo nametag = new FlxSprite(); @@ -212,11 +223,17 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage var path:String = availableChars.get(i); var temp:PixelatedIcon = new PixelatedIcon(0, 0); temp.setCharacter(path); - temp.setGraphicSize(128, 128); + temp.setGraphicSize(ICON_SIZE, ICON_SIZE); temp.updateHitbox(); temp.ID = 0; grpIcons.add(temp); } + else + { + var temp:Lock = new Lock(0, 0, i); + temp.ID = 1; + grpIcons.add(temp); + } } updateIconPositions(); @@ -266,4 +283,42 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage availableChars.set(targetPosition, playerId); } } + + override function update(elapsed:Float):Void + { + super.update(elapsed); + + handleCursor(elapsed); + } + + function handleCursor(elapsed:Float):Void + { + var mouseX:Float = FlxG.mouse.viewX - grpIcons.x; + var mouseY:Float = FlxG.mouse.viewY - grpIcons.y; + + var cursorX:Int = Math.floor(mouseX / ICON_SIZE); + var cursorY:Int = Math.floor(mouseY / ICON_SIZE); + + if (cursorX < 0 || cursorX >= 3 || cursorY < 0 || cursorY >= 3) + { + return; + } + + selectedIndex = cursorY * 3 + cursorX; + + var selectedIcon = grpIcons.members[selectedIndex]; + + var cursorLocIntended:FlxPoint = FlxPoint.get(selectedIcon.x + ICON_SIZE / 2 - cursor.width / 2, selectedIcon.y + ICON_SIZE / 2 - cursor.height / 2); + + cursor.x = MathUtil.smoothLerp(cursor.x, cursorLocIntended.x, elapsed, 0.1); + cursor.y = MathUtil.smoothLerp(cursor.y, cursorLocIntended.y, elapsed, 0.1); + + cursorBlue.x = MathUtil.coolLerp(cursorBlue.x, cursor.x, 0.95 * 0.4); + cursorBlue.y = MathUtil.coolLerp(cursorBlue.y, cursor.y, 0.95 * 0.4); + + cursorDarkBlue.x = MathUtil.coolLerp(cursorDarkBlue.x, cursorLocIntended.x, 0.95 * 0.2); + cursorDarkBlue.y = MathUtil.coolLerp(cursorDarkBlue.y, cursorLocIntended.y, 0.95 * 0.2); + + cursorLocIntended.put(); + } }