Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Android support since Jordan wanted that #18

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
<define name="TITLE_SCREEN_EASTER_EGG" if="officialBuild"/> <!-- DELETE THE if="officialBuild" for enabling this on an unofficial build -->
<define name="CRASH_HANDLER" if="desktop release || android" />

<assets path="assets/android" if="android"/> <!-- to not have the android assets in another builds -saw -->

<assets path="assets/preload" rename="assets" exclude="*.ogg" if="web"/>
<assets path="assets/preload" rename="assets" exclude="*.mp3" unless="web"/>
<section if="TITLE_SCREEN_EASTER_EGG">
Expand Down
Binary file added assets/android/hitbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions assets/android/hitbox.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<TextureAtlas imagePath="hitbox.png">
<SubTexture name="left" x="0" y="0" width="320" height="720" frameX="0" frameY="0" frameWidth="320" frameHeight="720"/>
<SubTexture name="down" x="320" y="0" width="320" height="720" frameX="0" frameY="0" frameWidth="320" frameHeight="720"/>
<SubTexture name="up" x="640" y="0" width="320" height="720" frameX="0" frameY="0" frameWidth="320" frameHeight="720"/>
<SubTexture name="right" x="960" y="0" width="320" height="720" frameX="0" frameY="0" frameWidth="320" frameHeight="720"/>
</TextureAtlas>
Binary file added assets/android/menu/arrows.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions assets/android/menu/arrows.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<TextureAtlas imagePath="arrows.png">
<!-- Created with Adobe Animate version 21.0.5.40714 -->
<!-- http://www.adobe.com/products/animate.html -->
<SubTexture name="arrow left0000" x="0" y="0" width="48" height="85"/>
<SubTexture name="arrow push left0000" x="58" y="0" width="42" height="75"/>
<SubTexture name="arrow push right0000" x="110" y="0" width="41" height="74"/>
<SubTexture name="arrow right0000" x="161" y="0" width="47" height="85"/>
</TextureAtlas>
Binary file added assets/android/virtualpad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions assets/android/virtualpad.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<TextureAtlas imagePath="virtualpad.png">
<SubTexture name="left" x="0" y="0" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="down" x="396" y="0" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="up" x="792" y="0" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="right" x="1188" y="0" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="a" x="0" y="127" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="b" x="396" y="127" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="c" x="792" y="127" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="d" x="1188" y="127" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="e" x="0" y="254" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="f" x="396" y="254" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="g" x="792" y="254" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="s" x="1188" y="254" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="v" x="0" y="381" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="x" x="396" y="381" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="y" x="792" y="381" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
<SubTexture name="z" x="1188" y="381" width="396" height="127" frameX="0" frameY="0" frameWidth="396" frameHeight="127"/>
</TextureAtlas>
4 changes: 4 additions & 0 deletions source/AchievementsMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class AchievementsMenuState extends MusicBeatState
add(descText);
changeSelection();

#if android
addVirtualPad(UP_DOWN, B);
#end

super.create();
}

Expand Down
158 changes: 148 additions & 10 deletions source/Controls.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package;

#if android
import android.flixel.FlxButton;
import android.flixel.FlxHitbox;
import android.flixel.FlxVirtualPad;
#end
import flixel.FlxG;
import flixel.input.FlxInput;
import flixel.input.actions.FlxAction;
Expand Down Expand Up @@ -379,6 +384,125 @@ class Controls extends FlxActionSet
}
#end

#if android
public var trackedinputsUI:Array<FlxActionInput> = [];
public var trackedinputsNOTES:Array<FlxActionInput> = [];

public function addbuttonNOTES(action:FlxActionDigital, button:FlxButton, state:FlxInputState) {
var input:FlxActionInputDigitalIFlxInput = new FlxActionInputDigitalIFlxInput(button, state);
trackedinputsNOTES.push(input);
action.add(input);
}

public function addbuttonUI(action:FlxActionDigital, button:FlxButton, state:FlxInputState) {
var input:FlxActionInputDigitalIFlxInput = new FlxActionInputDigitalIFlxInput(button, state);
trackedinputsUI.push(input);
action.add(input);
}

public function setHitBox(Hitbox:FlxHitbox) {
inline forEachBound(Control.NOTE_UP, (action, state) -> addbuttonNOTES(action, Hitbox.buttonUp, state));
inline forEachBound(Control.NOTE_DOWN, (action, state) -> addbuttonNOTES(action, Hitbox.buttonDown, state));
inline forEachBound(Control.NOTE_LEFT, (action, state) -> addbuttonNOTES(action, Hitbox.buttonLeft, state));
inline forEachBound(Control.NOTE_RIGHT, (action, state) -> addbuttonNOTES(action, Hitbox.buttonRight, state));
}

public function setVirtualPadUI(VirtualPad:FlxVirtualPad, DPad:FlxDPadMode, Action:FlxActionMode) {
switch (DPad) {
case UP_DOWN:
inline forEachBound(Control.UI_UP, (action, state) -> addbuttonUI(action, VirtualPad.buttonUp, state));
inline forEachBound(Control.UI_DOWN, (action, state) -> addbuttonUI(action, VirtualPad.buttonDown, state));
case LEFT_RIGHT:
inline forEachBound(Control.UI_LEFT, (action, state) -> addbuttonUI(action, VirtualPad.buttonLeft, state));
inline forEachBound(Control.UI_RIGHT, (action, state) -> addbuttonUI(action, VirtualPad.buttonRight, state));
case UP_LEFT_RIGHT:
inline forEachBound(Control.UI_UP, (action, state) -> addbuttonUI(action, VirtualPad.buttonUp, state));
inline forEachBound(Control.UI_LEFT, (action, state) -> addbuttonUI(action, VirtualPad.buttonLeft, state));
inline forEachBound(Control.UI_RIGHT, (action, state) -> addbuttonUI(action, VirtualPad.buttonRight, state));
case LEFT_FULL | RIGHT_FULL:
inline forEachBound(Control.UI_UP, (action, state) -> addbuttonUI(action, VirtualPad.buttonUp, state));
inline forEachBound(Control.UI_DOWN, (action, state) -> addbuttonUI(action, VirtualPad.buttonDown, state));
inline forEachBound(Control.UI_LEFT, (action, state) -> addbuttonUI(action, VirtualPad.buttonLeft, state));
inline forEachBound(Control.UI_RIGHT, (action, state) -> addbuttonUI(action, VirtualPad.buttonRight, state));
case BOTH_FULL:
inline forEachBound(Control.UI_UP, (action, state) -> addbuttonUI(action, VirtualPad.buttonUp, state));
inline forEachBound(Control.UI_DOWN, (action, state) -> addbuttonUI(action, VirtualPad.buttonDown, state));
inline forEachBound(Control.UI_LEFT, (action, state) -> addbuttonUI(action, VirtualPad.buttonLeft, state));
inline forEachBound(Control.UI_RIGHT, (action, state) -> addbuttonUI(action, VirtualPad.buttonRight, state));
inline forEachBound(Control.UI_UP, (action, state) -> addbuttonUI(action, VirtualPad.buttonUp2, state));
inline forEachBound(Control.UI_DOWN, (action, state) -> addbuttonUI(action, VirtualPad.buttonDown2, state));
inline forEachBound(Control.UI_LEFT, (action, state) -> addbuttonUI(action, VirtualPad.buttonLeft2, state));
inline forEachBound(Control.UI_RIGHT, (action, state) -> addbuttonUI(action, VirtualPad.buttonRight2, state));
case NONE: // do nothing
}

switch (Action) {
case A:
inline forEachBound(Control.ACCEPT, (action, state) -> addbuttonUI(action, VirtualPad.buttonA, state));
case B:
inline forEachBound(Control.BACK, (action, state) -> addbuttonUI(action, VirtualPad.buttonB, state));
case A_B | A_B_C | A_B_E | A_B_X_Y | A_B_C_X_Y | A_B_C_X_Y_Z | A_B_C_D_V_X_Y_Z:
inline forEachBound(Control.ACCEPT, (action, state) -> addbuttonUI(action, VirtualPad.buttonA, state));
inline forEachBound(Control.BACK, (action, state) -> addbuttonUI(action, VirtualPad.buttonB, state));
case NONE: // do nothing
}
}

public function setVirtualPadNOTES(VirtualPad:FlxVirtualPad, DPad:FlxDPadMode, Action:FlxActionMode) {
switch (DPad) {
case UP_DOWN:
inline forEachBound(Control.NOTE_UP, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonUp, state));
inline forEachBound(Control.NOTE_DOWN, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonDown, state));
case LEFT_RIGHT:
inline forEachBound(Control.NOTE_LEFT, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonLeft, state));
inline forEachBound(Control.NOTE_RIGHT, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonRight, state));
case UP_LEFT_RIGHT:
inline forEachBound(Control.NOTE_UP, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonUp, state));
inline forEachBound(Control.NOTE_LEFT, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonLeft, state));
inline forEachBound(Control.NOTE_RIGHT, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonRight, state));
case LEFT_FULL | RIGHT_FULL:
inline forEachBound(Control.NOTE_UP, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonUp, state));
inline forEachBound(Control.NOTE_DOWN, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonDown, state));
inline forEachBound(Control.NOTE_LEFT, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonLeft, state));
inline forEachBound(Control.NOTE_RIGHT, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonRight, state));
case BOTH_FULL:
inline forEachBound(Control.NOTE_UP, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonUp, state));
inline forEachBound(Control.NOTE_DOWN, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonDown, state));
inline forEachBound(Control.NOTE_LEFT, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonLeft, state));
inline forEachBound(Control.NOTE_RIGHT, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonRight, state));
inline forEachBound(Control.NOTE_UP, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonUp2, state));
inline forEachBound(Control.NOTE_DOWN, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonDown2, state));
inline forEachBound(Control.NOTE_LEFT, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonLeft2, state));
inline forEachBound(Control.NOTE_RIGHT, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonRight2, state));
case NONE: // do nothing
}

switch (Action) {
case A:
inline forEachBound(Control.ACCEPT, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonA, state));
case B:
inline forEachBound(Control.BACK, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonB, state));
case A_B | A_B_C | A_B_E | A_B_X_Y | A_B_C_X_Y | A_B_C_X_Y_Z | A_B_C_D_V_X_Y_Z:
inline forEachBound(Control.ACCEPT, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonA, state));
inline forEachBound(Control.BACK, (action, state) -> addbuttonNOTES(action, VirtualPad.buttonB, state));
case NONE: // do nothing
}
}

public function removeFlxInput(Tinputs:Array<FlxActionInput>) {
for (action in this.digitalActions) {
var i = action.inputs.length;
while (i-- > 0) {
var x = Tinputs.length;
while (x-- > 0) {
if (Tinputs[x] == action.inputs[i])
action.remove(action.inputs[i]);
}
}
}
}
#end

override function update()
{
super.update();
Expand Down Expand Up @@ -578,11 +702,12 @@ class Controls extends FlxActionSet
* Sets all actions that pertain to the binder to trigger when the supplied keys are used.
* If binder is a literal you can inline this
*/
public function bindKeys(control:Control, keys:Array<FlxKey>)
{
#if !android
public function bindKeys(control:Control, keys:Array<FlxKey>) {
var copyKeys:Array<FlxKey> = keys.copy();
for (i in 0...copyKeys.length) {
if(i == NONE) copyKeys.remove(i);
if (i == NONE)
copyKeys.remove(i);
}

#if (haxe >= "4.0.0")
Expand All @@ -592,15 +717,11 @@ class Controls extends FlxActionSet
#end
}

/**
* Sets all actions that pertain to the binder to trigger when the supplied keys are used.
* If binder is a literal you can inline this
*/
public function unbindKeys(control:Control, keys:Array<FlxKey>)
{
public function unbindKeys(control:Control, keys:Array<FlxKey>) {
var copyKeys:Array<FlxKey> = keys.copy();
for (i in 0...copyKeys.length) {
if(i == NONE) copyKeys.remove(i);
if (i == NONE)
copyKeys.remove(i);
}

#if (haxe >= "4.0.0")
Expand All @@ -609,6 +730,23 @@ class Controls extends FlxActionSet
forEachBound(control, function(action, _) removeKeys(action, copyKeys));
#end
}
#else
public function bindKeys(control:Control, keys:Array<FlxKey>) {
#if (haxe >= "4.0.0")
inline forEachBound(control, (action, state) -> addKeys(action, keys, state));
#else
forEachBound(control, function(action, state) addKeys(action, keys, state));
#end
}

public function unbindKeys(control:Control, keys:Array<FlxKey>) {
#if (haxe >= "4.0.0")
inline forEachBound(control, (action, _) -> removeKeys(action, keys));
#else
forEachBound(control, function(action, _) removeKeys(action, keys));
#end
}
#end

inline static function addKeys(action:FlxActionDigital, keys:Array<FlxKey>, state:FlxInputState)
{
Expand Down
5 changes: 5 additions & 0 deletions source/CreditsState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ class CreditsState extends MusicBeatState
bg.color = getCurrentBGColor();
intendedColor = bg.color;
changeSelection();

#if android
addVirtualPad(UP_DOWN, A_B);
#end

super.create();
}

Expand Down
10 changes: 10 additions & 0 deletions source/FlashingState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class FlashingState extends MusicBeatState
warnText.setFormat("VCR OSD Mono", 32, FlxColor.WHITE, CENTER);
warnText.screenCenter(Y);
add(warnText);

#if android
addVirtualPad(NONE, A_B);
#end
}

override function update(elapsed:Float)
Expand All @@ -48,12 +52,18 @@ class FlashingState extends MusicBeatState
ClientPrefs.saveSettings();
FlxG.sound.play(Paths.sound('confirmMenu'));
FlxFlicker.flicker(warnText, 1, 0.1, false, true, function(flk:FlxFlicker) {
#if android
virtualPad.alpha = 0.1;
#end
new FlxTimer().start(0.5, function (tmr:FlxTimer) {
MusicBeatState.switchState(new TitleState());
});
});
} else {
FlxG.sound.play(Paths.sound('cancelMenu'));
#if android
FlxTween.tween(virtualPad, {alpha: 0}, 1);
#end
FlxTween.tween(warnText, {alpha: 0}, 1, {
onComplete: function (twn:FlxTween) {
MusicBeatState.switchState(new TitleState());
Expand Down
29 changes: 22 additions & 7 deletions source/FreeplayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,26 @@ class FreeplayState extends MusicBeatState
add(textBG);

#if PRELOAD_ALL
#if android
var leText:String = "Press X to listen to the Song / Press C to open the Gameplay Changers Menu / Press Y to Reset your Score and Accuracy.";
var size:Int = 16;
#else
var leText:String = "Press SPACE to listen to the Song / Press CTRL to open the Gameplay Changers Menu / Press RESET to Reset your Score and Accuracy.";
var size:Int = 16;
#end
#else
var leText:String = "Press CTRL to open the Gameplay Changers Menu / Press RESET to Reset your Score and Accuracy.";
var leText:String = "Press C to open the Gameplay Changers Menu / Press Y to Reset your Score and Accuracy.";
var size:Int = 18;
#end
var text:FlxText = new FlxText(textBG.x, textBG.y + 4, FlxG.width, leText, size);
text.setFormat(Paths.font("vcr.ttf"), size, FlxColor.WHITE, RIGHT);
text.scrollFactor.set();
add(text);

#if android
addVirtualPad(LEFT_FULL, A_B_C_X_Y_Z);
#end

super.create();
}

Expand Down Expand Up @@ -302,11 +312,11 @@ class FreeplayState extends MusicBeatState
var upP = controls.UI_UP_P;
var downP = controls.UI_DOWN_P;
var accepted = controls.ACCEPT;
var space = FlxG.keys.justPressed.SPACE;
var ctrl = FlxG.keys.justPressed.CONTROL;
var space = FlxG.keys.justPressed.SPACE #if android || virtualPad.buttonX.justPressed #end;
var ctrl = FlxG.keys.justPressed.CONTROL #if android || virtualPad.buttonC.justPressed #end;

var shiftMult:Int = 1;
if(FlxG.keys.pressed.SHIFT) shiftMult = 3;
if (FlxG.keys.pressed.SHIFT #if android || virtualPad.buttonZ.pressed #end) shiftMult = 3;

if(songs.length > 1)
{
Expand Down Expand Up @@ -359,6 +369,9 @@ class FreeplayState extends MusicBeatState

if(ctrl)
{
#if android
removeVirtualPad();
#end
persistentUpdate = false;
openSubState(new GameplayChangersSubstate());
}
Expand Down Expand Up @@ -458,7 +471,7 @@ class FreeplayState extends MusicBeatState

curPlaying = false;

if (FlxG.keys.pressed.SHIFT){
if (FlxG.keys.pressed.SHIFT #if android || virtualPad.buttonZ.pressed #end) {
LoadingState.loadAndSwitchState(new ChartingState());
}else{
LoadingState.loadAndSwitchState(new PlayState());
Expand All @@ -478,8 +491,10 @@ class FreeplayState extends MusicBeatState
}
}
}
else if(controls.RESET)
{
else if (controls.RESET #if android || virtualPad.buttonY.justPressed #end) {
#if android
removeVirtualPad();
#end
persistentUpdate = false;
openSubState(new ResetScoreSubState(songs[curSelected].songName, curDifficulty, songs[curSelected].songCharacter));
FlxG.sound.play(Paths.sound('scrollMenu'));
Expand Down
Loading
Loading