Skip to content

Commit b015ed1

Browse files
Mobile shit...
1 parent 780408d commit b015ed1

File tree

7 files changed

+180
-17
lines changed

7 files changed

+180
-17
lines changed

source/core/Main.hx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ class Main extends Sprite
171171
}
172172
}
173173

174+
public static var debugCounter:DebugCounter;
175+
176+
public static var debugPrintPlugin:DebugPrintPlugin;
177+
178+
public static var mobileControlsPlugin:MobileControlsPlugin;
179+
174180
@:unreflective public static function preResetConfig()
175181
{
176182
#if WINDOWS_API
@@ -197,19 +203,17 @@ class Main extends Sprite
197203

198204
ALEPluginsHandler.destroy();
199205

206+
debugPrintPlugin = null;
207+
208+
mobileControlsPlugin = null;
209+
200210
CoolVars.reset();
201211

202212
debugCounter?.destroy();
203213

204214
FlxG.game.removeChild(debugCounter);
205215
}
206216

207-
public static var debugCounter:DebugCounter;
208-
209-
public static var debugPrintPlugin:DebugPrintPlugin;
210-
211-
public static var mobileControlsPlugin:MobileControlsPlugin;
212-
213217
@:unreflective static var allowMobileConfig:Bool = true;
214218

215219
@:unreflective public static function postResetConfig()

source/core/backend/ALEState.hx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import cpp.vm.Gc;
88
import hl.Gc;
99
#end
1010

11+
import api.MobileAPI;
12+
1113
class ALEState extends FlxState
1214
{
1315
public var camGame:ALECamera;
@@ -46,8 +48,6 @@ class ALEState extends FlxState
4648

4749
override function tryUpdate(elapsed:Float):Void
4850
{
49-
final allowSubStateUpdate:Bool = subState != null;
50-
5151
if (persistentUpdate || (subState == null || FlxState.transitioning))
5252
update(elapsed);
5353

@@ -58,7 +58,9 @@ class ALEState extends FlxState
5858
resetSubState();
5959
}
6060

61-
if (subState != null && allowSubStateUpdate)
61+
MobileAPI.controls?.update(FlxG.elapsed);
62+
63+
if (subState != null)
6264
subState.tryUpdate(elapsed);
6365
}
6466

source/core/config/MainState.hx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
package core.config;
22

3-
import funkin.states.PlayState;
3+
import funkin.substates.ModsMenuSubState;
44

55
import flixel.FlxState;
66

77
import core.Main;
88

99
class MainState extends FlxState
1010
{
11+
@:unreflective static var showedModMenu:Bool = #if mobile false #else true #end;
12+
1113
override public function create()
1214
{
1315
super.create();
1416

1517
Main.postResetConfig();
1618

17-
FlxTimer.wait(0.0001, () -> CoolUtil.switchState(new CustomState(CoolVars.data.initialState), true, true));
19+
FlxTimer.wait(0.0001, () -> {
20+
if (showedModMenu)
21+
{
22+
CoolUtil.switchState(new CustomState(CoolVars.data.initialState), true, true);
23+
} else {
24+
showedModMenu = true;
25+
26+
CoolUtil.openSubState(new ModsMenuSubState());
27+
}
28+
});
1829
}
1930
}

source/core/plugins/ALEPluginsHandler.hx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,7 @@ class ALEPluginsHandler
117117
plugin.cameras = [FlxG.camera];
118118

119119
plugins.remove(plugin);
120+
121+
plugin.destroy();
120122
}
121123
}

source/funkin/states/PlayState.hx

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import core.structures.ALEStageObjectsConfig;
2020
import core.structures.ALESong;
2121
import core.structures.ALEHud;
2222
import core.structures.Point;
23+
import core.plugins.ALEPluginsHandler;
2324
import core.enums.SongType;
2425
import core.enums.Rating;
2526

@@ -33,6 +34,8 @@ import funkin.visuals.game.*;
3334
import funkin.visuals.objects.Bar;
3435
import funkin.visuals.FXCamera;
3536

37+
import api.MobileAPI;
38+
3639
class PlayState extends ScriptState
3740
{
3841
public static var instance:PlayState;
@@ -122,6 +125,8 @@ class PlayState extends ScriptState
122125
var totalNoteTypes:Array<String> = [];
123126
var totalEvents:Array<String> = [];
124127

128+
@:unreflective var hitboxes:FlxTypedGroup<Hitbox>;
129+
125130
override function create()
126131
{
127132
instance = this;
@@ -179,6 +184,44 @@ class PlayState extends ScriptState
179184
}
180185

181186
scriptCallbackCall(POST, 'Create');
187+
188+
if (CoolVars.mobile)
189+
{
190+
MobileAPI.createButtons(100, 100, [{label: 'P', keys: ClientPrefs.controls.ui.pause}]);
191+
192+
add(hitboxes = new FlxTypedGroup<Hitbox>());
193+
194+
createMobileHitboxes(playersStrumLines.members[0] ?? extrasStrumLines.members[0] ?? opponentsStrumLines.members[0]);
195+
}
196+
}
197+
198+
public function createMobileHitboxes(strumLine:StrumLine)
199+
{
200+
if (!CoolVars.mobile)
201+
return;
202+
203+
hitboxes.clear();
204+
205+
for (index => strum in strumLine.data.strums)
206+
{
207+
final keysArray:Array<Null<FlxKey>> = CoolUtil.getControl(strum.keybind[0], strum.keybind[1]);
208+
209+
final hitbox:Hitbox = new Hitbox(strumLine.data.strums.length, index,
210+
() -> {
211+
for (key in keysArray)
212+
if (key != null)
213+
justPressedKey(new KeyboardEvent('keyDown', false, true, 0, key));
214+
},
215+
() -> {
216+
for (key in keysArray)
217+
if (key != null)
218+
justReleasedKey(new KeyboardEvent('keyUp', false, true, 0, key));
219+
}
220+
);
221+
hitbox.cameras = [ALEPluginsHandler.pluginsCamera];
222+
223+
hitboxes.add(hitbox);
224+
}
182225
}
183226

184227
override function update(elapsed:Float)
@@ -658,6 +701,10 @@ class PlayState extends ScriptState
658701

659702
var strumLines:FlxTypedGroup<StrumLine>;
660703

704+
var opponentsStrumLines:FlxTypedGroup<StrumLine>;
705+
var playersStrumLines:FlxTypedGroup<StrumLine>;
706+
var extrasStrumLines:FlxTypedGroup<StrumLine>;
707+
661708
var strums:FlxTypedGroup<Strum>;
662709

663710
var characters:FlxTypedGroup<Character>;
@@ -711,6 +758,10 @@ class PlayState extends ScriptState
711758
players = new FlxTypedGroup<Character>();
712759
extras = new FlxTypedGroup<Character>();
713760

761+
opponentsStrumLines = new FlxTypedGroup<StrumLine>();
762+
playersStrumLines = new FlxTypedGroup<StrumLine>();
763+
extrasStrumLines = new FlxTypedGroup<StrumLine>();
764+
714765
strumLines.cameras = [camHUD];
715766

716767
strums = new FlxTypedGroup<Strum>();
@@ -738,7 +789,7 @@ class PlayState extends ScriptState
738789

739790
strumLine.onMissNote = missNote;
740791

741-
strumLines.add(strumLine);
792+
addStrumLine(strumLine);
742793

743794
for (strum in strumLine.strums)
744795
strums.add(strum);
@@ -1035,6 +1086,30 @@ class PlayState extends ScriptState
10351086
function addBehindGroup(group:FlxTypedGroup<Dynamic>, obj:FlxBasic)
10361087
insert(members.indexOf(group.members[0]), obj);
10371088

1089+
function addStrumLine(strumLine:StrumLine)
1090+
{
1091+
if (scriptCallbackCall(ON, 'StrumLineAdd', null, [strumLine], []))
1092+
{
1093+
switch (strumLine.type)
1094+
{
1095+
case 'opponent':
1096+
opponentsStrumLines.add(strumLine);
1097+
1098+
case 'player':
1099+
playersStrumLines.add(strumLine);
1100+
1101+
case 'extra':
1102+
extrasStrumLines.add(strumLine);
1103+
1104+
default:
1105+
}
1106+
1107+
strumLines.add(strumLine);
1108+
}
1109+
1110+
scriptCallbackCall(POST, 'StrumLineAdd', null, [strumLine], []);
1111+
}
1112+
10381113
function addCharacter(character:Character)
10391114
{
10401115
if (scriptCallbackCall(ON, 'CharacterAdd', null, [character], []))
@@ -1204,10 +1279,7 @@ class PlayState extends ScriptState
12041279
function justPressedKey(event:KeyboardEvent)
12051280
{
12061281
if (scriptCallbackCall(ON, 'JustPressedKey', null, [event], [event.keyCode]))
1207-
{
1208-
if (FlxG.keys.firstJustPressed() > -1)
1209-
strumLines.forEachAlive(strl -> strl.justPressedKey(event.keyCode));
1210-
}
1282+
strumLines.forEachAlive(strl -> strl.justPressedKey(event.keyCode));
12111283

12121284
scriptCallbackCall(POST, 'JustPressedKey', null, [event], [event.keyCode]);
12131285
}

source/funkin/substates/ModsMenuSubState.hx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import flixel.util.FlxSave;
88

99
import sys.FileSystem;
1010

11-
class ModsMenuSubState extends MusicBeatSubState
11+
import api.MobileAPI;
12+
13+
@:unreflective class ModsMenuSubState extends MusicBeatSubState
1214
{
1315
var sprites:FlxTypedGroup<Alphabet> = new FlxTypedGroup<Alphabet>();
1416

@@ -69,6 +71,15 @@ class ModsMenuSubState extends MusicBeatSubState
6971
}
7072

7173
changeShit();
74+
75+
MobileAPI.toggleButtons(false, false);
76+
77+
MobileAPI.createButtons(FlxG.width - 100, FlxG.height - 100, [{label: 'A', keys: ClientPrefs.controls.ui.accept}], null, true);
78+
79+
MobileAPI.createButtons(100, FlxG.height - 200, [
80+
{label: 'D', keys: ClientPrefs.controls.ui.down},
81+
{label: 'U', keys: ClientPrefs.controls.ui.up},
82+
], null, true);
7283
}
7384

7485
override function update(elapsed:Float)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package funkin.visuals.game;
2+
3+
class Hitbox extends FlxSprite
4+
{
5+
public var onPress:Void -> Void;
6+
public var onRelease:Void -> Void;
7+
8+
public function new(strums:Int, index:Int, onPress:Void -> Void, onRelease:Void -> Void)
9+
{
10+
super();
11+
12+
final hitboxWidth:Float = FlxG.width / strums;
13+
14+
makeGraphic(Math.floor(hitboxWidth), FlxG.height);
15+
16+
x = index * hitboxWidth;
17+
18+
alpha = 0;
19+
20+
this.onPress = onPress;
21+
this.onRelease = onRelease;
22+
}
23+
24+
var pressed:Bool = false;
25+
26+
override function update(elapsed:Float)
27+
{
28+
super.update(elapsed);
29+
30+
var isOverlaped:Bool = false;
31+
32+
#if mobile
33+
for (touch in FlxG.touches.list)
34+
{
35+
if (touch.overlaps(this, cameras[0]) && touch.pressed)
36+
{
37+
isOverlaped = true;
38+
39+
break;
40+
}
41+
}
42+
#else
43+
isOverlaped = Controls.MOUSE && FlxG.mouse.overlaps(this, cameras[0]);
44+
#end
45+
46+
if (!pressed && isOverlaped)
47+
{
48+
pressed = true;
49+
50+
alpha = 0.025;
51+
52+
onPress();
53+
} else if (pressed && !isOverlaped) {
54+
pressed = false;
55+
56+
alpha = 0;
57+
58+
onRelease();
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)