Skip to content

Commit

Permalink
icon selection stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Nov 9, 2024
1 parent 332c09d commit feaf8b2
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +30,8 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage
var availableChars:Map<Int, String> = new Map<Int, String>();
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);
Expand All @@ -32,6 +41,8 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage
// copied sum code LOL
initBackground();

initForeground();

// gf and player code doodoo

nametag = new FlxSprite();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}

0 comments on commit feaf8b2

Please sign in to comment.