Skip to content

Commit 4819a74

Browse files
LasercarEliteMasterEric
authored andcommitted
Charselect remember character
1 parent f952583 commit 4819a74

File tree

5 files changed

+86
-26
lines changed

5 files changed

+86
-26
lines changed

source/funkin/ui/charSelect/CharSelectSubState.hx

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ class CharSelectSubState extends MusicBeatSubState
6969
var chooseDipshit:FlxSprite;
7070
var dipshitBlur:FlxSprite;
7171
var transitionGradient:FlxSprite;
72-
var curChar(default, set):String = "pico";
72+
var curChar(default, set):String = Constants.DEFAULT_CHARACTER;
73+
var rememberedChar:String;
7374
var nametag:Nametag;
7475
var camFollow:FlxObject;
7576
var autoFollow:Bool = false;
@@ -98,9 +99,10 @@ class CharSelectSubState extends MusicBeatSubState
9899

99100
var cutoutSize:Float = 0;
100101

101-
public function new()
102+
public function new(?params:CharSelectSubStateParams)
102103
{
103104
super();
105+
rememberedChar = params?.character;
104106
loadAvailableCharacters();
105107
}
106108

@@ -182,19 +184,40 @@ class CharSelectSubState extends MusicBeatSubState
182184
charLightGF.loadGraphic(Paths.image('charSelect/charLight'));
183185
add(charLightGF);
184186

185-
gfChill = new CharSelectGF();
186-
gfChill.switchGF("bf");
187-
gfChill.x += cutoutSize;
188-
add(gfChill);
189-
190-
playerChillOut = new CharSelectPlayer(cutoutSize, 0);
191-
playerChillOut.switchChar("bf");
192-
playerChillOut.visible = false;
193-
add(playerChillOut);
187+
function setupPlayerChill(character:String)
188+
{
189+
gfChill = new CharSelectGF();
190+
gfChill.switchGF(character);
191+
gfChill.x += cutoutSize;
192+
add(gfChill);
193+
194+
playerChillOut = new CharSelectPlayer(cutoutSize, 0);
195+
playerChillOut.switchChar(character);
196+
playerChillOut.visible = false;
197+
add(playerChillOut);
198+
199+
playerChill = new CharSelectPlayer(cutoutSize, 0);
200+
playerChill.switchChar(character);
201+
add(playerChill);
202+
}
194203

195-
playerChill = new CharSelectPlayer(cutoutSize, 0);
196-
playerChill.switchChar("bf");
197-
add(playerChill);
204+
// I think I can do the character preselect thing here? This better work
205+
// Edit: [UH-OH!] yes! It does!
206+
if (rememberedChar != null && rememberedChar != Constants.DEFAULT_CHARACTER)
207+
{
208+
setupPlayerChill(rememberedChar);
209+
for (pos => charId in availableChars)
210+
{
211+
if (charId == rememberedChar)
212+
{
213+
setCursorPosition(pos);
214+
break;
215+
}
216+
}
217+
@:bypassAccessor curChar = rememberedChar;
218+
}
219+
else
220+
setupPlayerChill(Constants.DEFAULT_CHARACTER);
198221

199222
var speakers:FlxAtlasSprite = new FlxAtlasSprite(cutoutSize - 10, 0, Paths.animateAtlas("charSelect/charSelectSpeakers"));
200223
speakers.anim.play("");
@@ -241,7 +264,7 @@ class CharSelectSubState extends MusicBeatSubState
241264
dipshitBacking.scrollFactor.set();
242265
dipshitBlur.scrollFactor.set();
243266

244-
nametag = new Nametag();
267+
nametag = new Nametag(curChar);
245268
nametag.midpointX += cutoutSize;
246269
add(nametag);
247270

@@ -1153,6 +1176,25 @@ class CharSelectSubState extends MusicBeatSubState
11531176
return gridPosition;
11541177
}
11551178

1179+
// Moved this code into a function because is now used twice
1180+
function setCursorPosition(index:Int)
1181+
{
1182+
var copy = 3;
1183+
var yThing = -1;
1184+
1185+
while ((index + 1) > copy)
1186+
{
1187+
yThing++;
1188+
copy += 3;
1189+
}
1190+
1191+
var xThing = (copy - index - 2) * -1;
1192+
1193+
// Look, I'd write better code but I had better aneurysms, my bad - Cheems
1194+
cursorY = yThing;
1195+
cursorX = xThing;
1196+
}
1197+
11561198
function set_curChar(value:String):String
11571199
{
11581200
if (curChar == value) return value;
@@ -1203,3 +1245,11 @@ class CharSelectSubState extends MusicBeatSubState
12031245
return value;
12041246
}
12051247
}
1248+
1249+
/**
1250+
* Parameters used to initialize the CharSelectSubState.
1251+
*/
1252+
typedef CharSelectSubStateParams =
1253+
{
1254+
?character:String, // ?fromFreeplaySelect:Bool,
1255+
};

source/funkin/ui/charSelect/Nametag.hx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ class Nametag extends FlxSprite
1212
var midpointY(default, set):Float = 100;
1313
var mosaicShader:MosaicEffect;
1414

15-
public function new(?x:Float = 0, ?y:Float = 0)
15+
public function new(?x:Float = 0, ?y:Float = 0, character:String)
1616
{
1717
super(x, y);
1818

1919
mosaicShader = new MosaicEffect();
2020
shader = mosaicShader;
2121

22-
switchChar("bf");
22+
// So that's why there was that cursed sight (originally defaulted to bf)
23+
if (character != null) switchChar(character);
24+
else
25+
switchChar(Constants.DEFAULT_CHARACTER);
2326
}
2427

2528
public function updatePosition():Void

source/funkin/ui/freeplay/FreeplayState.hx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,26 @@ class FreeplayState extends MusicBeatSubState
227227

228228
public function new(?params:FreeplayStateParams, ?stickers:StickerSubState)
229229
{
230-
currentCharacterId = params?.character ?? rememberedCharacterId;
231-
styleData = FreeplayStyleRegistry.instance.fetchEntry(currentCharacterId);
232-
233230
var fetchPlayableCharacter = function():PlayableCharacter {
234231
var targetCharId = params?.character ?? rememberedCharacterId;
235232
var result = PlayerRegistry.instance.fetchEntry(targetCharId);
236-
if (result == null) throw 'No valid playable character with id ${targetCharId}';
233+
if (result == null)
234+
{
235+
trace('No valid playable character with id ${targetCharId}');
236+
result = PlayerRegistry.instance.fetchEntry(Constants.DEFAULT_CHARACTER);
237+
if (result == null) throw 'WTH your default character is null?????';
238+
}
237239
return result;
238240
};
239241

240242
currentCharacter = fetchPlayableCharacter();
243+
currentCharacterId = currentCharacter.getFreeplayStyleID();
244+
241245
currentVariation = rememberedVariation;
242246
currentDifficulty = rememberedDifficulty;
243-
styleData = FreeplayStyleRegistry.instance.fetchEntry(currentCharacter.getFreeplayStyleID());
247+
styleData = FreeplayStyleRegistry.instance.fetchEntry(currentCharacterId);
244248
rememberedCharacterId = currentCharacter?.id ?? Constants.DEFAULT_CHARACTER;
249+
245250
fromCharSelect = params?.fromCharSelect ?? false;
246251
fromResultsParams = params?.fromResults;
247252
prepForNewRank = fromResultsParams?.playRankAnim ?? false;
@@ -1296,7 +1301,8 @@ class FreeplayState extends MusicBeatSubState
12961301
fadeShader.fade(1.0, 0.0, 0.8, {ease: FlxEase.quadIn});
12971302
FlxG.sound.music?.fadeOut(0.9, 0);
12981303
new FlxTimer().start(0.9, _ -> {
1299-
FlxG.switchState(() -> new funkin.ui.charSelect.CharSelectSubState());
1304+
FlxG.switchState(new funkin.ui.charSelect.CharSelectSubState({character: currentCharacterId} // Passing the currrent Freeplay character to the CharSelect so we can start it with that character selected
1305+
));
13001306
});
13011307
for (grpSpr in exitMoversCharSel.keys())
13021308
{

source/funkin/ui/mainmenu/MainMenuState.hx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ class MainMenuState extends MusicBeatState
134134
// Since CUTOUT_WIDTH is static it might retain some old inccrect values so we update it before loading freeplay
135135
FreeplayState.CUTOUT_WIDTH = funkin.ui.FullScreenScaleMode.gameCutoutSize.x / 1.5;
136136

137+
var rememberedFreeplayCharacter = FreeplayState.rememberedCharacterId;
137138
#if FEATURE_DEBUG_FUNCTIONS
138139
// Debug function: Hold SHIFT when selecting Freeplay to swap character without the char select menu
139-
var targetCharacter:Null<String> = (FlxG.keys.pressed.SHIFT) ? (FreeplayState.rememberedCharacterId == "pico" ? "bf" : "pico") : null;
140+
var targetCharacter:Null<String> = (FlxG.keys.pressed.SHIFT) ? (FreeplayState.rememberedCharacterId == "pico" ? "bf" : "pico") : rememberedFreeplayCharacter;
140141
#else
141-
var targetCharacter:Null<String> = null;
142+
var targetCharacter:Null<String> = rememberedFreeplayCharacter;
142143
#end
143144

144145
if (!hasUpgraded)

source/funkin/ui/options/PreferencesMenu.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class PreferencesMenu extends Page<OptionsState.OptionsMenuPageName>
148148
createPrefItemCheckbox('Pause on Unfocus', 'If enabled, game automatically pauses when it loses focus.', function(value:Bool):Void {
149149
Preferences.autoPause = value;
150150
}, Preferences.autoPause);
151-
createPrefItemCheckbox('Launch in Fullscreen', 'Automatically launch the game in fullscreen on startup', function(value:Bool):Void {
151+
createPrefItemCheckbox('Launch in Fullscreen', 'Automatically launch the game in fullscreen on startup.', function(value:Bool):Void {
152152
Preferences.autoFullscreen = value;
153153
}, Preferences.autoFullscreen);
154154
#end

0 commit comments

Comments
 (0)