Skip to content

Commit

Permalink
prototype menu for char index
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Nov 9, 2024
1 parent cc02f3c commit bd3d3cd
Show file tree
Hide file tree
Showing 2 changed files with 300 additions and 212 deletions.
231 changes: 19 additions & 212 deletions source/funkin/ui/debug/char/pages/CharCreatorSelectPage.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import funkin.data.freeplay.player.PlayerData;
import funkin.data.freeplay.player.PlayerRegistry;
import funkin.graphics.adobeanimate.FlxAtlasSprite;
import funkin.graphics.FunkinSprite;
import funkin.ui.debug.char.pages.subpages.CharSelectIndexSubPage;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
import flixel.group.FlxSpriteGroup;
import flixel.tweens.FlxEase;
Expand All @@ -18,10 +19,9 @@ import flixel.math.FlxPoint;
import flixel.math.FlxMath;
import flixel.FlxG;

@:allow(funkin.ui.debug.char.pages.subpages.CharSelectIndexSubPage)
class CharCreatorSelectPage extends CharCreatorDefaultPage
{
static final ICON_SIZE:Float = 128;

var data:WizardGenerateParams;

var nametag:FlxSprite;
Expand All @@ -30,14 +30,17 @@ 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 cursorIndex:Int = 0;

// used for `PlayableCharacter` generation
var selectedIndexData:Int = 0;

var subPages:Map<CharCreatorSelectSubPage, FlxSpriteGroup>;

var handleInput:Bool = true;

override public function new(state:CharCreatorState, data:WizardGenerateParams)
{
super(state);

loadAvailableCharacters();
this.data = data;

Expand All @@ -51,12 +54,10 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage
nametag = new FlxSprite();
add(nametag);

initCursors();
initSounds();
subPages = new Map<CharCreatorSelectSubPage, FlxSpriteGroup>();
subPages.set(IndexSubPage, new CharSelectIndexSubPage(this));

initLocks();

FlxTween.color(cursor, 0.2, 0xFFFFFF00, 0xFFFFCC00, {type: PINGPONG});
add(subPages[IndexSubPage]);
}

function initBackground():Void
Expand Down Expand Up @@ -132,144 +133,6 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage
add(chooseDipshit);
}

var cursor:FlxSprite;
var cursorBlue:FlxSprite;
var cursorDarkBlue:FlxSprite;
var grpCursors:FlxTypedSpriteGroup<FlxSprite>; // using flxtypedgroup raises an error
var cursorConfirmed:FlxSprite;
var cursorDenied:FlxSprite;

function initCursors():Void
{
grpCursors = new FlxTypedSpriteGroup<FlxSprite>();
add(grpCursors);

cursor = new FlxSprite(0, 0);
cursor.loadGraphic(Paths.image('charSelect/charSelector'));
cursor.color = 0xFFFFFF00;

// FFCC00

cursorBlue = new FlxSprite(0, 0);
cursorBlue.loadGraphic(Paths.image('charSelect/charSelector'));
cursorBlue.color = 0xFF3EBBFF;

cursorDarkBlue = new FlxSprite(0, 0);
cursorDarkBlue.loadGraphic(Paths.image('charSelect/charSelector'));
cursorDarkBlue.color = 0xFF3C74F7;

cursorBlue.blend = BlendMode.SCREEN;
cursorDarkBlue.blend = BlendMode.SCREEN;

cursorConfirmed = new FlxSprite(0, 0);
cursorConfirmed.frames = Paths.getSparrowAtlas("charSelect/charSelectorConfirm");
cursorConfirmed.animation.addByPrefix("idle", "cursor ACCEPTED instance 1", 24, true);
cursorConfirmed.visible = false;
add(cursorConfirmed);

cursorDenied = new FlxSprite(0, 0);
cursorDenied.frames = Paths.getSparrowAtlas("charSelect/charSelectorDenied");
cursorDenied.animation.addByPrefix("idle", "cursor DENIED instance 1", 24, false);
cursorDenied.visible = false;
add(cursorDenied);

grpCursors.add(cursorDarkBlue);
grpCursors.add(cursorBlue);
grpCursors.add(cursor);
}

var selectSound:FunkinSound;
var lockedSound:FunkinSound;
var staticSound:FunkinSound;

function initSounds():Void
{
selectSound = new FunkinSound();
selectSound.loadEmbedded(Paths.sound('CS_select'));
selectSound.pitch = 1;
selectSound.volume = 0.7;

FlxG.sound.defaultSoundGroup.add(selectSound);
FlxG.sound.list.add(selectSound);

lockedSound = new FunkinSound();
lockedSound.loadEmbedded(Paths.sound('CS_locked'));
lockedSound.pitch = 1;
lockedSound.volume = 1.;

FlxG.sound.defaultSoundGroup.add(lockedSound);
FlxG.sound.list.add(lockedSound);

staticSound = new FunkinSound();
staticSound.loadEmbedded(Paths.sound('static loop'));
staticSound.pitch = 1;
staticSound.looped = true;
staticSound.volume = 0.6;

FlxG.sound.defaultSoundGroup.add(staticSound);
FlxG.sound.list.add(staticSound);
}

var grpIcons:FlxSpriteGroup;
final grpXSpread:Float = 107;
final grpYSpread:Float = 127;

function initLocks():Void
{
grpIcons = new FlxSpriteGroup();
add(grpIcons);

// only the unused slots should be selectable
// i dont know if i like using the lock sprite
// maybe there is a different placeholder we could use
// also, we should probably make the used slots
// less visible or something like that
for (i in 0...9)
{
if (availableChars.exists(i))
{
var path:String = availableChars.get(i);
var temp:PixelatedIcon = new PixelatedIcon(0, 0);
temp.setCharacter(path);
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();

for (index => member in grpIcons.members)
{
member.y += 300;
FlxTween.tween(member, {y: member.y - 300}, 1, {ease: FlxEase.expoOut});
}
}

function updateIconPositions():Void
{
grpIcons.x = 450;
grpIcons.y = 120;
for (index => member in grpIcons.members)
{
var posX:Float = (index % 3);
var posY:Float = Math.floor(index / 3);

member.x = posX * grpXSpread;
member.y = posY * grpYSpread;

member.x += grpIcons.x;
member.y += grpIcons.y;
}
}

function loadAvailableCharacters():Void
{
var playerIds:Array<String> = PlayerRegistry.instance.listEntryIds();
Expand All @@ -296,73 +159,17 @@ class CharCreatorSelectPage extends CharCreatorDefaultPage
{
super.update(elapsed);

changeSelectedIcon();

handleMousePress();

handleCursorPosition(elapsed);
}

function changeSelectedIcon():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;
}

var newIndex:Int = cursorY * 3 + cursorX;

if (newIndex == cursorIndex)
{
return;
}

selectSound.play(true);

cursorIndex = newIndex;
}

function handleMousePress():Void
{
if (!FlxG.mouse.justPressed)
{
return;
}

var selectedIcon = grpIcons.members[cursorIndex];

// skip if the selected icon is already used
if (selectedIcon.ID == 0)
if (handleInput)
{
lockedSound.play(true);
return;
if (FlxG.keys.justPressed.B)
{
cast(subPages[IndexSubPage], CharSelectIndexSubPage).open();
}
}

selectedIndexData = cursorIndex;
selectSound.play(true);
}
}

function handleCursorPosition(elapsed:Float):Void
{
var selectedIcon = grpIcons.members[cursorIndex];

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();
}
enum CharCreatorSelectSubPage
{
IndexSubPage;
}
Loading

1 comment on commit bd3d3cd

@lemz1
Copy link
Collaborator Author

@lemz1 lemz1 commented on bd3d3cd Nov 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can access this menu by pressing "B", and leave it by pressing "X"
i was too lazy to implement the haxe ui functionality to access and close the sub menu

Please sign in to comment.