Skip to content

Commit

Permalink
wip mobile button layout shit
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed May 9, 2024
1 parent bbcf9e2 commit 625d9f3
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 32 deletions.
93 changes: 71 additions & 22 deletions source/funkin/MobileTouch.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,71 @@ import openfl.display.BitmapData;
import openfl.display.Sprite;
import flixel.input.FlxInput;

typedef MobileLayout = Map<MobileButtonID, FlxPoint>;

enum abstract MobileLayoutID(Int) from Int to Int {
var NONE = 0;
var NOTES = 1;
var STORY_MODE = 2;
var FREEPLAY = 3;
var BASIC_MENU = 4;
}

class MobileTouch extends Sprite
{
public static var touch:MobileTouch;

public var mode(default, set):TouchMode = NONE;
function set_mode(value:TouchMode):TouchMode
static final layouts:Map<MobileLayoutID, MobileLayout> =
[
STORY_MODE => [
UP => FlxPoint.get(20, 100),
DOWN => FlxPoint.get(20, 400),
],

FREEPLAY => [

],

BASIC_MENU => [

]
];

public var layout(default, set):MobileLayoutID;
function set_layout(value:MobileLayoutID)
{
noteButtons.fastForEach((button, i) -> button.visible = value == NOTES);
uiButtons.fastForEach((button, i) -> button.visible = value == MENU);
switch (value)
{
case NOTES:
noteButtons.fastForEach((button, i) -> button.visible = true);
uiButtons.fastForEach((button, i) -> button.visible = false);
return this.layout = value;

default:
noteButtons.fastForEach((button, i) -> button.visible = false);
uiButtons.fastForEach((button, i) -> button.visible = false);
}

if (value == NONE)
return this.layout = value;

var layout = layouts.get(value);

for (i in 0...7) {
var point:Null<FlxPoint> = layout.get(i);
if (point != null) {
var button:MobileButton = uiButtons[i];
button.visible = true;
button.x = point.x;
button.y = point.y;
}
}

return mode = value;
return this.layout = value;
}

public static function setMode(mode:TouchMode) {
touch.mode = mode;
public static function setLayout(id:MobileLayoutID) {
touch.layout = id;
}

final noteButtons:Array<MobileButton> = [];
Expand Down Expand Up @@ -78,31 +128,37 @@ class MobileTouch extends Sprite
button.input = FlxG.keys.getKey(inputs[i]);

button.scaleX = button.scaleY = (Math.min(w, h) / Math.min(bitmap.width, bitmap.height)) * 0.23;
button.x = button.scaleX * bitmap.width * i;
//button.x = button.scaleX * bitmap.width * i;

uiButtons.push(button);
addChild(button);
}

mode = NONE;
layout = NONE;
});
}

public function update(elapsed:Float)
public function update(elapsed:Float):Void
{
switch(mode) {
switch (layout)
{
case NONE:
return;

case NOTES:
noteButtons.fastForEach((button, i) -> {
button.update(elapsed);
if (button.pressed) button.alpha = 0.6;
else button.alpha -= elapsed * 2;
});
case MENU:

default:
uiButtons.fastForEach((button, i) -> {
button.update(elapsed);
if (button.pressed) button.alpha = 0.4;
else button.alpha = FlxMath.lerp(button.alpha, 0.2, elapsed);
if (button.visible) {
button.update(elapsed);
if (button.pressed) button.alpha = 0.4;
else button.alpha = FlxMath.lerp(button.alpha, 0.2, elapsed);
}
});
}
}
Expand Down Expand Up @@ -164,13 +220,6 @@ class MobileButton extends Sprite
}
}

enum abstract TouchMode(Int) from Int to Int
{
var NONE:Int = 0;
var NOTES:Int = 1;
var MENU:Int = 2;
}

enum abstract MobileButtonID(Int) from Int to Int
{
var LEFT:Int = 0;
Expand Down
4 changes: 2 additions & 2 deletions source/funkin/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class PlayState extends MusicBeatState
override public function create():Void {
instance = this;

#if mobile MobileTouch.setMode(NOTES); #end
#if mobile MobileTouch.setLayout(NOTES); #end

if (clearCache) CoolUtil.clearCache(clearCacheData)
else {
Expand Down Expand Up @@ -850,7 +850,7 @@ class PlayState extends MusicBeatState
}

public function showUI(bool:Bool):Void {
#if mobile MobileTouch.setMode(bool ? NOTES : NONE); #end
#if mobile MobileTouch.setLayout(bool ? NOTES : NONE); #end

final displayObjects:Array<FlxBasic> = [iconGroup, scoreTxt, healthBar, notesGroup, watermark];
displayObjects.fastForEach((object, i) -> {
Expand Down
7 changes: 7 additions & 0 deletions source/funkin/states/editors/chart/ChartGridBase.hx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ class ChartNoteGrid extends ChartGridBase
public function new() {
super(true);

if (Conductor.inst.stream) {
var song = Conductor.loadedSong;
@:privateAccess
Conductor.loadedSong = "";
Conductor.loadSong(song);
}

// Waveforms
instWaveform = new AudioWaveform(grid.x, grid.y, grid.width, grid.height, Conductor.inst.sound);
voicesWaveform = new AudioWaveform(grid.x, grid.y, grid.width, grid.height, Conductor.vocals.sound);
Expand Down
6 changes: 3 additions & 3 deletions source/funkin/states/menus/FreeplayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class FreeplayState extends MusicBeatState
CoolUtil.playMusic('freakyMenu');

FlxG.mouse.visible = #if mobile false; #else true; #end
#if mobile MobileTouch.setMode(MENU); #end
#if mobile MobileTouch.setLayout(FREEPLAY); #end

#if discord_rpc // Updating Discord Rich Presence
DiscordClient.changePresence("In the Menus", null);
Expand Down Expand Up @@ -177,7 +177,7 @@ class FreeplayState extends MusicBeatState

#if desktop
if(FlxG.keys.justPressed.ONE) {
final curSong = cast songs[curSelected];
final curSong = songs[curSelected];
if (curSong.song != loadedSong)
{
if (FlxG.sound.music != null)
Expand Down Expand Up @@ -235,7 +235,7 @@ class FreeplayState extends MusicBeatState
function loadSong(toChart:Bool):Void {
var songData = songs[curSelected];
var diff = curWeekDiffs[curDifficulty];
#if mobile MobileTouch.setMode(NONE); #end
#if mobile MobileTouch.setLayout(NONE); #end
WeekSetup.loadSong(songData.week, songData.song, diff, false, false, #if DEV_TOOLS toChart ? ChartingState : #end null);
}

Expand Down
2 changes: 1 addition & 1 deletion source/funkin/states/menus/MainMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MainMenuState extends MusicBeatState {
{
// Updating Discord Rich Presence
#if discord_rpc DiscordClient.changePresence("In the Menus", null); #end
#if mobile MobileTouch.setMode(NONE); #end
#if mobile MobileTouch.setLayout(NONE); #end

if (FlxG.sound.music == null || !FlxG.sound.music.playing)
CoolUtil.playMusic('freakyMenu');
Expand Down
4 changes: 2 additions & 2 deletions source/funkin/states/menus/StoryMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class StoryMenuState extends MusicBeatState {

// Updating Discord Rich Presence
#if discord_rpc DiscordClient.changePresence("In the Menus", null); #end
#if mobile MobileTouch.setMode(MENU); #end
#if mobile MobileTouch.setLayout(STORY_MODE); #end

WeekSetup.getWeekList().fastForEach((week, i) -> {
if (!week.data.hideStory) {
Expand Down Expand Up @@ -259,7 +259,7 @@ class StoryMenuState extends MusicBeatState {
CoolUtil.playSound('confirmMenu');
grpWeekText.members[curWeek].startFlashing();
grpWeekCharacters.members[1].playAnim('confirm', true);
#if mobile MobileTouch.setMode(NONE); #end
#if mobile MobileTouch.setLayout(NONE); #end

var playlist = getCurData().songList.songs;
var diff = curWeekDiffs[curDifficulty];
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/states/options/OptionsState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class OptionsState extends MusicBeatState {

optionItems.push('Exit');

#if mobile MobileTouch.setMode(MENU); #end
#if mobile MobileTouch.setLayout(BASIC_MENU); #end

var bg:FunkinSprite = new FunkinSprite('menuBGMagenta');
bg.setScale(1.1);
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/substates/GameOverSubstate.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class GameOverSubstate extends MusicBeatSubstate {
if (PlayState.instance.startTimer != null)
PlayState.instance.startTimer.cancel();

#if mobile MobileTouch.setMode(NONE); #end
#if mobile MobileTouch.setLayout(NONE); #end

final charName = PlayState?.instance?.boyfriend?.gameOverChar ?? "bf-dead";
skinFolder = PlayState.instance.boyfriend.gameOverSuffix;
Expand Down

0 comments on commit 625d9f3

Please sign in to comment.