Skip to content

Commit c43c26a

Browse files
TechnikTilKade-github
authored andcommitted
Add Mobile Controls
Signed-off-by: TechnikTil <techniktil@tilnotdrip.org>
1 parent 6767f73 commit c43c26a

File tree

1 file changed

+72
-30
lines changed

1 file changed

+72
-30
lines changed

scripts/states/MenuSwitch.hxc

Lines changed: 72 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ package kade.menucore.states;
77

88
import funkin.ui.title.TitleState;
99
import funkin.ui.mainmenu.MainMenuState;
10+
import funkin.ui.FullScreenScaleMode;
11+
import funkin.util.TouchUtil;
12+
import funkin.util.SwipeUtil;
1013
import funkin.ui.MusicBeatState;
1114
import funkin.audio.FunkinSound;
1215
import flixel.FlxG;
@@ -27,6 +30,7 @@ class MenuSwitch extends MusicBeatState {
2730
var mcHandle = null;
2831

2932
var bg:FlxSprite;
33+
var chooseBlackBar:FlxText;
3034
var choose:FlxText;
3135

3236
var topRightText:FlxText;
@@ -47,6 +51,8 @@ class MenuSwitch extends MusicBeatState {
4751
public var versions:Array<String> = new Array();
4852
public var states:Array<FlxState> = new Array();
4953

54+
var backMobile:Bool = false;
55+
5056
public function new():Void {
5157
super();
5258

@@ -63,35 +69,52 @@ class MenuSwitch extends MusicBeatState {
6369
atlasTexts = mcHandle.atlasTexts;
6470
versionDescriptions = mcHandle.versionDescriptions;
6571

66-
bg = new FlxSprite(-320, -115);
72+
bg = new FlxSprite();
6773
bg.loadGraphic(Paths.image("mc_bg","shared"));
68-
bg.setGraphicSize(FlxG.width, FlxG.height);
74+
bg.setGraphicSize(Std.int(FlxG.width * 1.2));
75+
bg.updateHitbox();
76+
bg.screenCenter();
77+
bg.zIndex = 0;
6978
add(bg);
7079

71-
choose = new FlxText(6, 2, FlxG.width, "CHOOSE THE VERSION");
80+
chooseBlackBar = new FlxSprite(0, 0);
81+
chooseBlackBar.makeGraphic(FlxG.width, 60, 0xFF000000);
82+
chooseBlackBar.zIndex = 10;
83+
add(chooseBlackBar);
84+
85+
choose = new FlxText(Math.max(FullScreenScaleMode.gameNotchSize.x, 6), 2, FlxG.width, "CHOOSE THE VERSION");
7286
choose.setFormat(Paths.font("vcr.ttf"), 55, 0xFFFFFFFF);
87+
choose.zIndex = 20;
7388
add(choose);
7489

7590
topRightText = new FlxText(0, 15, FlxG.width / 2, "");
7691
topRightText.setFormat(Paths.font("vcr.ttf"), 35, 0xFFFFFFFF, "right");
77-
topRightText.x = FlxG.width - topRightText.width - 10;
92+
topRightText.x = (FlxG.width - topRightText.width - Math.max(FullScreenScaleMode.gameNotchSize.x, 10));
93+
topRightText.zIndex = 30;
7894
add(topRightText);
7995

8096
// Middle black bar of bg
8197
blackBar = new FlxSprite(0, 0);
8298
blackBar.makeGraphic(FlxG.width, 185, 0xFF000000);
8399
blackBar.y = FlxG.height / 2 - blackBar.height / 2;
100+
blackBar.zIndex = 40;
84101
add(blackBar);
85102

86103
leftSelect = FunkinSprite.createSparrow(0,0,"freeplay/freeplaySelector/freeplaySelector");
104+
leftSelect.animation.addByPrefix('shine', 'arrow pointer loop', 24);
105+
leftSelect.animation.play("shine", true);
87106
leftSelect.x = FlxG.width / 8 - leftSelect.width / 2;
88107
leftSelect.y = FlxG.height / 2 - leftSelect.height / 2;
108+
leftSelect.zIndex = 70;
89109
add(leftSelect);
90110

91111
rightSelect = FunkinSprite.createSparrow(0,0,"freeplay/freeplaySelector/freeplaySelector");
112+
rightSelect.animation.addByPrefix('shine', 'arrow pointer loop', 24);
113+
rightSelect.animation.play("shine", true);
92114
rightSelect.x = FlxG.width - FlxG.width / 8 - rightSelect.width / 2;
93115
rightSelect.y = FlxG.height / 2 - rightSelect.height / 2;
94116
rightSelect.flipX = true;
117+
rightSelect.zIndex = 80;
95118
add(rightSelect);
96119
}
97120

@@ -120,6 +143,9 @@ class MenuSwitch extends MusicBeatState {
120143
versionImage.x = (FlxG.width / 2 - versionImage.width / 2) + (i - visualSelect) * versionImage.width * 1.2;
121144
versionText.x = versionImage.x + (versionImage.width / 2 - versionText.width / 2);
122145

146+
versionImage.zIndex = 50;
147+
versionText.zIndex = 60;
148+
123149
add(versionImage);
124150
add(versionText);
125151

@@ -128,7 +154,7 @@ class MenuSwitch extends MusicBeatState {
128154
}
129155

130156
topRightText.text = versionDescriptions[selected];
131-
topRightText.x = FlxG.width - topRightText.width - 10;
157+
topRightText.x = (FlxG.width - topRightText.width - Math.max(FullScreenScaleMode.gameNotchSize.x, 10));
132158
}
133159

134160
public override function create():Void {
@@ -145,6 +171,14 @@ class MenuSwitch extends MusicBeatState {
145171

146172
populateVersions();
147173

174+
if (FlxG.onMobile) {
175+
addBackButton(FlxG.width - 230, FlxG.height - 200, 0xFFFFFFFF, () -> {
176+
backMobile = true;
177+
}, 0.3);
178+
}
179+
180+
refresh();
181+
148182
FunkinSound.playMusic("menu-switch",
149183
{
150184
startingVolume: 0,
@@ -162,42 +196,50 @@ class MenuSwitch extends MusicBeatState {
162196
public override function update(elapsed:Float):Void {
163197
super.update(elapsed);
164198

165-
// TODO: Eventually do mobile hitboxes... (sorry mobile fam)
199+
var back:Bool = controls.BACK || backMobile;
200+
var accept:Bool = controls.ACCEPT;
201+
var left:Bool = controls.UI_LEFT_P;
202+
var right:Bool = controls.UI_RIGHT_P;
166203

167-
// Escape key, goes back to TitleState
168-
if (FlxG.keys.justPressed.ESCAPE) {
169-
trace("MenuSwitch: ESCAPE pressed, going back to TitleState");
170-
var titleState = new TitleState();
171-
FlxG.switchState(titleState);
172-
}
204+
if (FlxG.onMobile) {
205+
if (TouchUtil.pressAction(versionImages[selected]))
206+
accept = true;
173207

174-
if (FlxG.keys.justPressed.ENTER) {
175-
// TODO: Make this an animation or something
176-
//FunkinSound.playOnce(Paths.sound("confirmMenu"), 0.5);
177-
var toState = states[selected];
178-
trace("MenuSwitch: ENTER pressed, switching to " + toState);
179-
FlxG.switchState(toState);
208+
if (TouchUtil.pressAction(leftSelect) || SwipeUtil.justSwipedLeft)
209+
left = true;
210+
211+
if (TouchUtil.pressAction(rightSelect) || SwipeUtil.justSwipedRight)
212+
right = true;
180213
}
181214

182-
if (FlxG.keys.justPressed.LEFT) {
183-
selected--;
215+
if (left || right) {
216+
if (left)
217+
selected--;
218+
else
219+
selected++;
220+
184221
if (selected < 0)
185222
selected = versions.length - 1;
186-
FunkinSound.playOnce(Paths.sound("scrollMenu"), 0.5);
187-
188-
topRightText.text = versionDescriptions[selected];
189-
}
190-
191-
if (FlxG.keys.justPressed.RIGHT) {
192-
selected++;
193-
if (selected >= versions.length)
223+
else if (selected >= versions.length)
194224
selected = 0;
225+
195226
FunkinSound.playOnce(Paths.sound("scrollMenu"), 0.5);
196227

197228
topRightText.text = versionDescriptions[selected];
198-
topRightText.x = FlxG.width - topRightText.width - 10;
229+
topRightText.x = (FlxG.width - topRightText.width - Math.max(FullScreenScaleMode.gameNotchSize.x, 10));
230+
}
231+
else if (back) {
232+
trace("MenuSwitch: ESCAPE pressed, going back to TitleState");
233+
var titleState = new TitleState();
234+
FlxG.switchState(titleState);
235+
}
236+
else if (accept) {
237+
// TODO: Make this an animation or something
238+
//FunkinSound.playOnce(Paths.sound("confirmMenu"), 0.5);
239+
var toState = states[selected];
240+
trace("MenuSwitch: ENTER pressed, switching to " + toState);
241+
FlxG.switchState(toState);
199242
}
200-
201243

202244
visualSelect += (selected - visualSelect) * 0.2;
203245

0 commit comments

Comments
 (0)