Skip to content

Commit

Permalink
Terrible code is terrible
Browse files Browse the repository at this point in the history
  • Loading branch information
dd01da0465b4542f8f8af4ecedc149ed committed Jan 11, 2021
1 parent 2a4084c commit 6fd5b1e
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 36 deletions.
2 changes: 1 addition & 1 deletion osu!stream/Audio/IBackgroundAudioPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public virtual bool Load(byte[] audio, bool looping, string identifier = null)
/// </summary>
public bool Load(string filename, bool looping)
{
return Load(File.ReadAllBytes(filename), looping, filename);
return Load(File.ReadAllBytes("/sdcard/" + filename), looping, filename);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion osu!stream/GameModes/SongSelect/SongSelect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class SongSelectMode
public static string BeatmapPath { get { return Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/../Library/Caches"; } }
#endif
#else
public static string BeatmapPath => @"Beatmaps/";
public static string BeatmapPath => @"/sdcard/Beatmaps/";
#endif

private readonly pList<Beatmap> maps = new pList<Beatmap>(new BeatmapPackComparer(), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void showDifficultySelection(BeatmapPanel panel, bool instant = false)
cancelLockedHoverPreview();

SelectedPanel = panel;
Player.Beatmap = panel.Beatmap;
Player.Beatmap = panel?.Beatmap;

panel.s_BackingPlate2.Alpha = 1;
panel.s_BackingPlate2.AdditiveFlash(400, 1, true);
Expand Down
62 changes: 62 additions & 0 deletions osu!stream/Input/Sources/InputSourceAndroid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Android.Views;
using osum.Helpers;
using System.Collections.Generic;
using System.Drawing;

namespace osum.Input.Sources
{
internal class InputSourceAndroid : InputSource
{
public InputSourceAndroid() : base()
{
}

public void HandleTouches(MotionEvent e)
{
Clock.Update(true);

for (int i = 0; i < e.PointerCount; i++)
{
handleMotionEvent(i, e);
}
}

Dictionary<int, TrackingPoint> touchDictionary = new Dictionary<int, TrackingPoint>();

private void handleMotionEvent(int i, MotionEvent e)
{
TrackingPoint point = null;
PointF location = new PointF(e.GetX(i)/* / 2.25f*/, e.GetY(i)/* / 2.25f*/);

switch (e.Action)
{
case MotionEventActions.Down:
point = new TrackingPointAndroid(location, e);
touchDictionary[e.GetPointerId(i)] = point;
TriggerOnDown(point);
break;
case MotionEventActions.Cancel:
case MotionEventActions.Up:
if (!touchDictionary.TryGetValue(e.GetPointerId(i), out point))
return;
touchDictionary.Remove(e.GetPointerId(i));
TriggerOnUp(point);
break;
case MotionEventActions.Move:
if (!touchDictionary.TryGetValue(e.GetPointerId(i), out point))
return;
point.Location = location;
TriggerOnMove(point);
break;
}
}

public void ReleaseAllTouches()
{
foreach (TrackingPoint t in trackingPoints.ToArray())
TriggerOnUp(t);
trackingPoints.Clear();
touchDictionary.Clear();
}
}
}
31 changes: 31 additions & 0 deletions osu!stream/Input/TrackingPointAndroid.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Drawing;
using OpenTK;

namespace osum.Input
{
class TrackingPointAndroid : TrackingPoint
{
public TrackingPointAndroid(PointF location, object tag) : base(location, tag)
{
}

public override void UpdatePositions()
{
bool ios8 = true;

float x = (ios8 ? Location.X : Location.Y) * GameBase.ScaleFactor;
float y = (ios8 ? Location.Y : Location.X) * GameBase.ScaleFactor;

if (GameBase.Instance.FlipView || ios8)
y = GameBase.NativeSize.Height - y;
if (GameBase.Instance.FlipView && !ios8)
x = GameBase.NativeSize.Width - x;

Vector2 oldBase = BasePosition;
BasePosition = new Vector2(
(x / GameBase.NativeSize.Width) * GameBase.BaseSizeFixedWidth.X,
GameBase.BaseSizeFixedWidth.Y - ((y / GameBase.NativeSize.Height) * GameBase.BaseSizeFixedWidth.Y));
WindowDelta = BasePosition - oldBase;
}
}
}
2 changes: 1 addition & 1 deletion osu!stream/Libraries/NetLib/NetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static bool AddRequest(NetRequest request)
activeRequests.Add(request);
}

#if iOS || ANDROID
#if iOS
if (request.AbortRequested) return false;
request.Perform();
#else
Expand Down
12 changes: 11 additions & 1 deletion osu!stream/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Android.Views;
using Android.Content.PM;
using Xamarin.Essentials;
using osum.Input;
using osum.Input.Sources;
#endif
#if !iOS && !ANDROID
using osum.Support.Desktop;
Expand All @@ -15,7 +17,7 @@
namespace osum
{
#if ANDROID
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true, ScreenOrientation = ScreenOrientation.UserLandscape)]
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", ScreenOrientation = ScreenOrientation.UserLandscape, MainLauncher = true)]
public class Application : AppCompatActivity
#else
public class Application
Expand Down Expand Up @@ -69,6 +71,14 @@ public override void OnRequestPermissionsResult(int requestCode, string[] permis

base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}

public override bool OnTouchEvent(MotionEvent e)
{
InputSourceAndroid source = InputManager.RegisteredSources[0] as InputSourceAndroid;
source.HandleTouches(e);

return base.OnTouchEvent(e);
}
#endif
}
}
59 changes: 31 additions & 28 deletions osu!stream/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion osu!stream/Support/Android/GameBaseAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected override SoundEffectPlayer InitializeSoundEffects()

protected override void InitializeInput()
{
InputSource source = new InputSource();
InputSource source = new InputSourceAndroid();
InputManager.AddSource(source);
}

Expand All @@ -50,5 +50,7 @@ public override void SetupScreen()

base.SetupScreen();
}

public override string PathConfig => "/sdcard/";
}
}
4 changes: 2 additions & 2 deletions osu!stream/Support/Android/GameWindowAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(e);

//if (GameBase.Instance != null) GameBase.Instance.Update();
if (GameBase.Instance != null) GameBase.Instance.Update();
}

protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(e);

//if (GameBase.Instance != null) GameBase.Instance.Draw();
if (GameBase.Instance != null) GameBase.Instance.Draw();

SwapBuffers();
}
Expand Down
2 changes: 2 additions & 0 deletions osu!stream/osu!stream_android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
<Compile Include="Audio\BackgroundAudioPlayerAndroid.cs" />
<Compile Include="Audio\SoundEffectPlayerBass.cs" />
<Compile Include="Audio\SoundEffectPlayerOpenAL.cs" />
<Compile Include="Input\Sources\InputSourceAndroid.cs" />
<Compile Include="Input\TrackingPointAndroid.cs" />
<Compile Include="Main.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down

0 comments on commit 6fd5b1e

Please sign in to comment.