1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 06:12:55 +08:00

Merge remote-tracking branch 'refs/remotes/upstream/master' into game-modes-layout

# Conflicts:
#	osu.Game/OsuGame.cs
#	osu.Game/OsuGameBase.cs
#	osu.Game/osu.Game.csproj
This commit is contained in:
Dean Herbert 2016-10-01 17:10:27 +09:00
commit f0681f35c4
48 changed files with 1245 additions and 32 deletions

View File

@ -0,0 +1,128 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.GameModes.Testing;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Threading;
using osu.Game;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Chat;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Graphics.Sprites;
using osu.Game.Online.Chat.Display.osu.Online.Social;
namespace osu.Desktop.Tests
{
class TestCaseChatDisplay : TestCase
{
private ScheduledDelegate messageRequest;
public override string Name => @"Chat";
public override string Description => @"Testing API polling";
private List<Channel> channels = new List<Channel>();
private FlowContainer flow;
private Scheduler scheduler = new Scheduler();
private APIAccess api => ((OsuGameBase)Game).API;
private long? lastMessageId;
public override void Reset()
{
base.Reset();
lastMessageId = null;
if (api.State != APIAccess.APIState.Online)
api.OnStateChange += delegate { initializeChannels(); };
else
initializeChannels();
Add(new ScrollContainer()
{
Size = new Vector2(1, 0.5f),
Children = new Drawable[]
{
flow = new FlowContainer
{
Direction = FlowDirection.VerticalOnly,
SizeMode = InheritMode.X,
LayoutDuration = 100,
LayoutEasing = EasingTypes.Out,
Padding = new Vector2(1, 1)
}
}
});
}
protected override void Update()
{
scheduler.Update();
base.Update();
}
private void initializeChannels()
{
if (api.State != APIAccess.APIState.Online)
return;
messageRequest?.Cancel();
ListChannelsRequest req = new ListChannelsRequest();
req.Success += delegate (List<Channel> channels)
{
this.channels = channels;
messageRequest = scheduler.AddDelayed(requestNewMessages, 1000, true);
};
api.Queue(req);
}
private void requestNewMessages()
{
messageRequest.Wait();
Channel channel = channels.Find(c => c.Name == "#osu");
GetMessagesRequest gm = new GetMessagesRequest(new List<Channel> { channel }, lastMessageId);
gm.Success += delegate (List<Message> messages)
{
foreach (Message m in messages)
{
//m.LineWidth = this.Size.X; //this is kinda ugly.
//m.Drawable.Depth = m.Id;
//m.Drawable.FadeInFromZero(800);
//flow.Add(m.Drawable);
//if (osu.Messages.Count > 50)
//{
// osu.Messages[0].Drawable.Expire();
// osu.Messages.RemoveAt(0);
//}
flow.Add(new ChatLine(m));
channel.Messages.Add(m);
}
lastMessageId = messages.LastOrDefault()?.Id ?? lastMessageId;
Debug.Write("success!");
messageRequest.Continue();
};
gm.Failure += delegate
{
Debug.Write("failure!");
messageRequest.Continue();
};
api.Queue(gm);
}
}
}

View File

@ -0,0 +1,95 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.GameModes.Testing;
using osu.Framework.Graphics;
using osu.Framework.MathUtils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Objects;
using osu.Game.Beatmaps.Objects.Osu;
using osu.Game.GameModes.Play.Catch;
using osu.Game.GameModes.Play.Mania;
using osu.Game.GameModes.Play.Osu;
using osu.Game.GameModes.Play.Taiko;
using System.Collections.Generic;
using osu.Framework.Timing;
namespace osu.Desktop.Tests
{
class TestCaseGamefield : TestCase
{
public override string Name => @"Gamefield";
public override string Description => @"Showing hitobjects and what not.";
FramedOffsetClock localClock;
protected override IFrameBasedClock Clock => localClock;
public override void Reset()
{
base.Reset();
///create a new clock offset to 0.
localClock = new FramedOffsetClock(base.Clock) { Offset = -base.Clock.CurrentTime };
List<HitObject> objects = new List<HitObject>();
int time = 500;
for (int i = 0; i < 100; i++)
{
objects.Add(new Circle()
{
StartTime = time,
Position = new Vector2(RNG.Next(0, 512), RNG.Next(0, 384))
});
time += RNG.Next(50, 500);
}
Beatmap beatmap = new Beatmap
{
HitObjects = objects
};
Add(new Drawable[]
{
new OsuHitRenderer
{
Objects = beatmap.HitObjects,
Scale = new Vector2(0.5f),
Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft
},
new TaikoHitRenderer
{
Objects = beatmap.HitObjects,
Scale = new Vector2(0.5f),
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight
},
new CatchHitRenderer
{
Objects = beatmap.HitObjects,
Scale = new Vector2(0.5f),
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft
},
new ManiaHitRenderer
{
Objects = beatmap.HitObjects,
Scale = new Vector2(0.5f),
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight
}
});
}
protected override void Update()
{
base.Update();
localClock.ProcessFrame();
}
}
}

View File

@ -150,6 +150,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Tests\TestCaseChatDisplay.cs" />
<Compile Include="Tests\TestCaseGamefield.cs" />
<Compile Include="Tests\TestCaseKeyCounter.cs" />
<Compile Include="Tests\TestCaseMenuButtonSystem.cs" />
<Compile Include="Tests\TestCaseTextAwesome.cs" />

View File

@ -0,0 +1,20 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Game.Beatmaps.Objects;
using osu.Game.Beatmaps.Timing;
using osu.Game.Users;
namespace osu.Game.Beatmaps
{
public class Beatmap
{
public List<HitObject> HitObjects;
public List<ControlPoint> ControlPoints;
public string Difficulty;
public User Creator;
}
}

View File

@ -0,0 +1,20 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Game.Users;
namespace osu.Game.Beatmaps
{
/// <summary>
/// A beatmap set contains multiple beatmap (difficulties).
/// </summary>
public class BeatmapSet
{
public List<Beatmap> Beatmaps { get; protected set; }
public Metadata Metadata;
public User Creator;
}
}

View File

@ -0,0 +1,11 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps
{
public class Metadata
{
public string Artist;
public string Title;
}
}

View File

@ -0,0 +1,10 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.Objects.Catch
{
public abstract class CatchBaseHit : HitObject
{
public float Position;
}
}

View File

@ -0,0 +1,9 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.Objects.Catch
{
public class Droplet : CatchBaseHit
{
}
}

View File

@ -0,0 +1,9 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.Objects.Catch
{
public class Fruit : CatchBaseHit
{
}
}

View File

@ -0,0 +1,20 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps.Samples;
namespace osu.Game.Beatmaps.Objects
{
/// <summary>
/// A hitobject describes a point in a beatmap
/// </summary>
public abstract class HitObject
{
public double StartTime;
public double? EndTime;
public double Duration => (EndTime ?? StartTime) - StartTime;
public HitSampleInfo Sample;
}
}

View File

@ -0,0 +1,9 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.Objects.Mania
{
public class HoldNote : Note
{
}
}

View File

@ -0,0 +1,10 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.Objects.Mania
{
public abstract class ManiaBaseHit : HitObject
{
public int Column;
}
}

View File

@ -0,0 +1,9 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.Objects.Mania
{
public class Note : ManiaBaseHit
{
}
}

View File

@ -0,0 +1,9 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.Objects.Osu
{
public class Circle : OsuBaseHit
{
}
}

View File

@ -0,0 +1,12 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
namespace osu.Game.Beatmaps.Objects.Osu
{
public abstract class OsuBaseHit : HitObject
{
public Vector2 Position;
}
}

View File

@ -0,0 +1,15 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using OpenTK;
namespace osu.Game.Beatmaps.Objects.Osu
{
public class Slider : OsuBaseHit
{
public List<Vector2> Path;
public int RepeatCount;
}
}

View File

@ -0,0 +1,9 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.Objects.Osu
{
public class Spinner
{
}
}

View File

@ -0,0 +1,18 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.Objects.Taiko
{
class TaikoBaseHit : HitObject
{
public float Scale = 1;
public TaikoColour Type;
}
public enum TaikoColour
{
Red,
Blue
}
}

View File

@ -0,0 +1,10 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.Samples
{
public class HitSampleInfo : SampleInfo
{
SampleType Type;
}
}

View File

@ -0,0 +1,12 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.Samples
{
public enum SampleBank
{
Default = 0,
Custom1 = 1,
Custom2 = 2
}
}

View File

@ -0,0 +1,11 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.Samples
{
public class SampleInfo
{
public SampleBank Bank;
public SampleSet Set;
}
}

View File

@ -0,0 +1,13 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
namespace osu.Game.Beatmaps.Samples
{
public enum SampleSet
{
None = 0,
Normal = 1,
Soft = 2,
Drum = 3
}
}

View File

@ -0,0 +1,17 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
namespace osu.Game.Beatmaps.Samples
{
[Flags]
public enum SampleType
{
None = 0,
Normal = 1,
Whistle = 2,
Finish = 4,
Clap = 8
};
}

View File

@ -0,0 +1,16 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Beatmaps.Timing
{
public class ControlPoint
{
public double Time;
}
}

View File

@ -0,0 +1,17 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Game.Beatmaps.Samples;
namespace osu.Game.Beatmaps.Timing
{
class SampleChange : ControlPoint
{
public SampleInfo Sample;
}
}

View File

@ -0,0 +1,18 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Beatmaps.Timing
{
class TimingChange : ControlPoint
{
public double BeatLength;
public double BPM => 60000 / BeatLength;
}
}

View File

@ -0,0 +1,84 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transformations;
using osu.Game.Beatmaps.Objects;
using osu.Game.Beatmaps.Objects.Osu;
using osu.Game.Beatmaps.Objects.Catch;
using OpenTK;
namespace osu.Game.GameModes.Play.Catch
{
public class CatchHitRenderer : HitRenderer
{
List<CatchBaseHit> objects;
private CatchPlayfield playfield;
public override List<HitObject> Objects
{
set
{
//osu! mode requires all objects to be of CatchBaseHit type.
objects = value.ConvertAll(convertForCatch);
if (Parent != null)
Load();
}
}
private CatchBaseHit convertForCatch(HitObject input)
{
CatchBaseHit h = input as CatchBaseHit;
if (h == null)
{
OsuBaseHit o = input as OsuBaseHit;
if (o == null) throw new Exception(@"Can't convert!");
h = new Fruit()
{
StartTime = o.StartTime,
Position = o.Position.X
};
}
return h;
}
public override void Load()
{
base.Load();
if (playfield == null)
Add(playfield = new CatchPlayfield());
else
playfield.Clear();
if (objects == null) return;
foreach (CatchBaseHit h in objects)
{
//render stuff!
Sprite s = new Sprite
{
Texture = Game.Textures.Get(@"menu-osu"),
Origin = Anchor.Centre,
Scale = new Vector2(0.1f),
PositionMode = InheritMode.Y,
Position = new Vector2(h.Position, -0.1f)
};
s.Transforms.Add(new TransformPosition(Clock) { StartTime = h.StartTime - 200, EndTime = h.StartTime, StartValue = new Vector2(h.Position, -0.1f), EndValue = new Vector2(h.Position, 0.9f) });
s.Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime + h.Duration + 200, EndTime = h.StartTime + h.Duration + 400, StartValue = 1, EndValue = 0 });
s.Expire(true);
playfield.Add(s);
}
}
}
}

View File

@ -0,0 +1,30 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Framework.Graphics.Sprites;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.GameModes.Play.Catch
{
public class CatchPlayfield : Playfield
{
public CatchPlayfield()
{
SizeMode = InheritMode.Y;
Size = new Vector2(512, 0.9f);
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
}
public override void Load()
{
base.Load();
Add(new Box { SizeMode = InheritMode.XY, Alpha = 0.5f });
}
}
}

View File

@ -0,0 +1,25 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Batches;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Game.Beatmaps.Objects;
using OpenTK;
namespace osu.Game.GameModes.Play
{
public abstract class HitRenderer : LargeContainer
{
public abstract List<HitObject> Objects { set; }
public override void Load()
{
base.Load();
Add(new Box() { SizeMode = InheritMode.XY, Alpha = 0.1f, Scale = new Vector2(0.99f) });
}
}
}

View File

@ -0,0 +1,90 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transformations;
using osu.Game.Beatmaps.Objects;
using osu.Game.Beatmaps.Objects.Osu;
using osu.Game.Beatmaps.Objects.Mania;
using OpenTK;
namespace osu.Game.GameModes.Play.Mania
{
public class ManiaHitRenderer : HitRenderer
{
private readonly int columns;
List<ManiaBaseHit> objects;
private ManiaPlayfield playfield;
public ManiaHitRenderer(int columns = 5)
{
this.columns = columns;
}
public override List<HitObject> Objects
{
set
{
//osu! mode requires all objects to be of ManiaBaseHit type.
objects = value.ConvertAll(convertForMania);
if (Parent != null)
Load();
}
}
private ManiaBaseHit convertForMania(HitObject input)
{
ManiaBaseHit h = input as ManiaBaseHit;
if (h == null)
{
OsuBaseHit o = input as OsuBaseHit;
if (o == null) throw new Exception(@"Can't convert!");
h = new Note()
{
StartTime = o.StartTime,
Column = (int)Math.Round(o.Position.X / 512 * columns)
};
}
return h;
}
public override void Load()
{
base.Load();
if (playfield == null)
Add(playfield = new ManiaPlayfield(columns));
else
playfield.Clear();
if (objects == null) return;
foreach (ManiaBaseHit h in objects)
{
//render stuff!
Sprite s = new Sprite
{
Texture = Game.Textures.Get(@"menu-osu"),
Origin = Anchor.Centre,
Scale = new Vector2(0.1f),
PositionMode = InheritMode.XY,
Position = new Vector2((float)(h.Column + 0.5) / columns, -0.1f)
};
s.Transforms.Add(new TransformPositionY(Clock) { StartTime = h.StartTime - 200, EndTime = h.StartTime, StartValue = -0.1f, EndValue = 0.9f });
s.Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime + h.Duration + 200, EndTime = h.StartTime + h.Duration + 400, StartValue = 1, EndValue = 0 });
s.Expire(true);
playfield.Add(s);
}
}
}
}

View File

@ -0,0 +1,44 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Framework.Graphics.Sprites;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.GameModes.Play.Mania
{
public class ManiaPlayfield : Playfield
{
private readonly int columns;
public ManiaPlayfield(int columns)
{
this.columns = columns;
SizeMode = InheritMode.XY;
Size = new Vector2(columns / 20f, 1f);
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
}
public override void Load()
{
base.Load();
Add(new Box() { SizeMode = InheritMode.XY, Alpha = 0.5f });
for (int i = 0; i < columns; i++)
Add(new Box()
{
SizeMode = InheritMode.Y,
Size = new Vector2(2, 1),
PositionMode = InheritMode.XY,
Position = new Vector2((float)i / columns, 0),
Alpha = 0.5f,
Colour = Color4.Black
});
}
}
}

View File

@ -0,0 +1,62 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transformations;
using osu.Game.Beatmaps.Objects;
using osu.Game.Beatmaps.Objects.Osu;
using OpenTK;
namespace osu.Game.GameModes.Play.Osu
{
public class OsuHitRenderer : HitRenderer
{
List<OsuBaseHit> objects;
private OsuPlayfield playfield;
public override List<HitObject> Objects
{
set
{
//osu! mode requires all objects to be of OsuBaseHit type.
objects = value.ConvertAll(o => (OsuBaseHit)o);
if (Parent != null)
Load();
}
}
public override void Load()
{
base.Load();
if (playfield == null)
Add(playfield = new OsuPlayfield());
else
playfield.Clear();
if (objects == null) return;
foreach (OsuBaseHit h in objects)
{
//render stuff!
Sprite s = new Sprite
{
Texture = Game.Textures.Get(@"menu-osu"),
Origin = Anchor.Centre,
Scale = new Vector2(0.1f),
Alpha = 0,
Position = h.Position
};
s.Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime - 200, EndTime = h.StartTime, StartValue = 0, EndValue = 1 });
s.Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime + h.Duration + 200, EndTime = h.StartTime + h.Duration + 400, StartValue = 1, EndValue = 0 });
s.Expire(true);
playfield.Add(s);
}
}
}
}

View File

@ -0,0 +1,34 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using OpenTK;
namespace osu.Game.GameModes.Play.Osu
{
public class OsuPlayfield : Playfield
{
public OsuPlayfield()
{
SizeMode = InheritMode.None;
Size = new Vector2(512, 384);
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}
public override void Load()
{
base.Load();
Add(new Box()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
SizeMode = InheritMode.XY,
Alpha = 0.5f
});
}
}
}

View File

@ -0,0 +1,17 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics.Containers;
namespace osu.Game.GameModes.Play
{
public class Playfield : Container
{
public override void Load()
{
base.Load();
Masking = true;
}
}
}

View File

@ -0,0 +1,83 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transformations;
using osu.Game.Beatmaps.Objects;
using osu.Game.Beatmaps.Objects.Osu;
using osu.Game.Beatmaps.Objects.Taiko;
using OpenTK;
namespace osu.Game.GameModes.Play.Taiko
{
public class TaikoHitRenderer : HitRenderer
{
List<TaikoBaseHit> objects;
private TaikoPlayfield playfield;
public override List<HitObject> Objects
{
set
{
//osu! mode requires all objects to be of TaikoBaseHit type.
objects = value.ConvertAll(convertForTaiko);
if (Parent != null)
Load();
}
}
private TaikoBaseHit convertForTaiko(HitObject input)
{
TaikoBaseHit h = input as TaikoBaseHit;
if (h == null)
{
OsuBaseHit o = input as OsuBaseHit;
if (o == null) throw new Exception(@"Can't convert!");
h = new TaikoBaseHit()
{
StartTime = o.StartTime
};
}
return h;
}
public override void Load()
{
base.Load();
if (playfield == null)
Add(playfield = new TaikoPlayfield());
else
playfield.Clear();
if (objects == null) return;
foreach (TaikoBaseHit h in objects)
{
//render stuff!
Sprite s = new Sprite
{
Texture = Game.Textures.Get(@"menu-osu"),
Origin = Anchor.Centre,
Scale = new Vector2(0.2f),
PositionMode = InheritMode.XY,
Position = new Vector2(1.1f, 0.5f)
};
s.Transforms.Add(new TransformPositionX(Clock) { StartTime = h.StartTime - 200, EndTime = h.StartTime, StartValue = 1.1f, EndValue = 0.1f });
s.Transforms.Add(new TransformAlpha(Clock) { StartTime = h.StartTime + h.Duration + 200, EndTime = h.StartTime + h.Duration + 400, StartValue = 1, EndValue = 0 });
s.Expire(true);
playfield.Add(s);
}
}
}
}

View File

@ -0,0 +1,40 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Framework.Graphics.Sprites;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.GameModes.Play.Taiko
{
public class TaikoPlayfield : Playfield
{
public TaikoPlayfield()
{
SizeMode = InheritMode.X;
Size = new Vector2(1, 100);
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}
public override void Load()
{
base.Load();
Add(new Box { SizeMode = InheritMode.XY, Alpha = 0.5f });
Add(new Sprite
{
Texture = Game.Textures.Get(@"menu-osu"),
Origin = Anchor.Centre,
Scale = new Vector2(0.2f),
PositionMode = InheritMode.XY,
Position = new Vector2(0.1f, 0.5f),
Colour = Color4.Gray
});
}
}
}

View File

@ -0,0 +1,28 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.Containers;
namespace osu.Game.Graphics.Components
{
class FpsDisplay : OsuComponent
{
SpriteText fpsText;
public override void Load()
{
base.Load();
Add(fpsText = new SpriteText());
fpsText.Text = "...";
}
protected override void Update()
{
fpsText.Text = ((int)(1000 / Clock.ElapsedFrameTime)).ToString();
base.Update();
}
}
}

View File

@ -5,21 +5,25 @@ using System;
using System.Collections.Concurrent;
using System.Net;
using System.Threading;
using osu.Framework;
using osu.Framework.Logging;
using osu.Framework.Threading;
using osu.Game.Online.API.Requests;
namespace osu.Game.Online.API
{
internal class APIAccess
public class APIAccess : IUpdateable
{
private OAuth authentication;
internal string Endpoint = @"https://new.ppy.sh";
public string Endpoint = @"https://new.ppy.sh";
const string ClientId = @"daNBnfdv7SppRVc61z0XuOI13y6Hroiz";
const string ClientSecret = @"d6fgZuZeQ0eSXkEj5igdqQX6ztdtS6Ow";
ConcurrentQueue<APIRequest> queue = new ConcurrentQueue<APIRequest>();
public Scheduler Scheduler = new Scheduler();
public string Username;
private SecurePassword password;
@ -52,7 +56,7 @@ namespace osu.Game.Online.API
Logger log;
internal APIAccess()
public APIAccess()
{
authentication = new OAuth(ClientId, ClientSecret, Endpoint);
log = Logger.GetLogger(LoggingTarget.Network);
@ -61,7 +65,7 @@ namespace osu.Game.Online.API
thread.Start();
}
internal string AccessToken => authentication.RequestAccessToken();
public string AccessToken => authentication.RequestAccessToken();
/// <summary>
/// Number of consecutive requests which failed due to network issues.
@ -221,16 +225,16 @@ namespace osu.Game.Online.API
}
}
internal void Queue(APIRequest request)
public void Queue(APIRequest request)
{
queue.Enqueue(request);
}
internal event StateChangeDelegate OnStateChange;
public event StateChangeDelegate OnStateChange;
internal delegate void StateChangeDelegate(APIState oldState, APIState newState);
public delegate void StateChangeDelegate(APIState oldState, APIState newState);
internal enum APIState
public enum APIState
{
/// <summary>
/// We cannot login (not enough credentials).
@ -268,10 +272,15 @@ namespace osu.Game.Online.API
}
}
internal void Logout()
public void Logout()
{
authentication.Clear();
State = APIState.Offline;
}
public void Update()
{
Scheduler.Update();
}
}
}

View File

@ -11,7 +11,7 @@ namespace osu.Game.Online.API
/// An API request with a well-defined response type.
/// </summary>
/// <typeparam name="T">Type of the response (used for deserialisation).</typeparam>
internal class APIRequest<T> : APIRequest
public class APIRequest<T> : APIRequest
{
protected override WebRequest CreateWebRequest() => new JsonWebRequest<T>(Uri);
@ -36,7 +36,7 @@ namespace osu.Game.Online.API
/// <summary>
/// The maximum amount of time before this request will fail.
/// </summary>
internal int Timeout = WebRequest.DEFAULT_TIMEOUT;
public int Timeout = WebRequest.DEFAULT_TIMEOUT;
protected virtual string Target => string.Empty;
@ -46,11 +46,11 @@ namespace osu.Game.Online.API
private double remainingTime => Math.Max(0, Timeout - (DateTime.Now.TotalMilliseconds() - (startTime ?? 0)));
internal bool ExceededTimeout => remainingTime == 0;
public bool ExceededTimeout => remainingTime == 0;
private double? startTime;
internal double StartTime => startTime ?? -1;
public double StartTime => startTime ?? -1;
private APIAccess api;
protected WebRequest WebRequest;
@ -58,7 +58,7 @@ namespace osu.Game.Online.API
public event APISuccessHandler Success;
public event APIFailureHandler Failure;
internal void Perform(APIAccess api)
public void Perform(APIAccess api)
{
if (startTime == null)
startTime = DateTime.Now.TotalMilliseconds();
@ -74,17 +74,16 @@ namespace osu.Game.Online.API
WebRequest.BlockingPerform();
//OsuGame.Scheduler.Add(delegate {
Success?.Invoke();
//});
api.Scheduler.Add(delegate { Success?.Invoke(); });
}
internal void Fail(Exception e)
public void Fail(Exception e)
{
WebRequest?.Abort();
//OsuGame.Scheduler.Add(delegate {
api.Scheduler.Add(delegate
{
Failure?.Invoke(e);
//});
});
}
}

View File

@ -7,7 +7,7 @@ using osu.Game.Online.Chat;
namespace osu.Game.Online.API.Requests
{
internal class GetMessagesRequest : APIRequest<List<Message>>
public class GetMessagesRequest : APIRequest<List<Message>>
{
List<Channel> channels;
long? since;

View File

@ -6,7 +6,7 @@ using osu.Game.Online.Chat;
namespace osu.Game.Online.API.Requests
{
internal class ListChannelsRequest : APIRequest<List<Channel>>
public class ListChannelsRequest : APIRequest<List<Channel>>
{
protected override string Target => @"chat/channels";
}

View File

@ -0,0 +1,62 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Framework.Graphics.Sprites;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Online.Chat.Display
{
namespace osu.Online.Social
{
public class ChatLine : AutoSizeContainer
{
private readonly Message msg;
public ChatLine(Message msg)
{
this.msg = msg;
}
public override void Load()
{
base.Load();
SizeMode = InheritMode.X;
Add(new Box
{
SizeMode = InheritMode.XY,
Colour = Color4.Aqua,
Alpha = 0.2f
});
Add(new SpriteText
{
Text = msg.Timestamp.ToLocalTime().ToLongTimeString(),
Colour = new Color4(128, 128, 128, 255)
});
Add(new SpriteText
{
Text = msg.User.Name,
Origin = Anchor.TopRight,
PositionMode = InheritMode.X,
Position = new Vector2(0.14f,0),
});
Add(new SpriteText
{
Text = msg.Content,
PositionMode = InheritMode.X,
Position = new Vector2(0.15f, 0),
SizeMode = InheritMode.X,
Size = new Vector2(0.85f, 1),
});
}
}
}
}

View File

@ -24,7 +24,7 @@ namespace osu.Game.Online.Chat
public string Content;
[JsonProperty(@"sender")]
public string User;
public User User;
[JsonConstructor]
public Message()

16
osu.Game/Online/User.cs Normal file
View File

@ -0,0 +1,16 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using Newtonsoft.Json;
namespace osu.Game.Online
{
public class User
{
[JsonProperty(@"username")]
public string Name;
[JsonProperty(@"colour")]
public string Colour;
}
}

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.OS;
using osu.Game.Graphics.Background;
using osu.Game.GameModes.Play;
using osu.Game.Graphics.Containers;
namespace osu.Game
@ -36,14 +37,6 @@ namespace osu.Game
});
}
protected override void Dispose(bool isDisposing)
{
//refresh token may have changed.
Config.Set(OsuConfig.Token, API.Token);
base.Dispose(isDisposing);
}
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
{
if (!base.Invalidate(invalidation, source, shallPropagate)) return false;

View File

@ -19,9 +19,9 @@ namespace osu.Game
protected override string MainResourceFile => @"osu.Game.Resources.dll";
public Options Options;
public APIAccess API;
public Toolbar Toolbar;
internal APIAccess API;
protected override Container AddTarget => ratioContainer?.IsLoaded == true ? ratioContainer : base.AddTarget;
@ -57,5 +57,20 @@ namespace osu.Game
}
});
}
protected override void Update()
{
base.Update();
API.Update();
}
protected override void Dispose(bool isDisposing)
{
//refresh token may have changed.
Config.Set(OsuConfig.Token, API.Token);
Config.Save();
base.Dispose(isDisposing);
}
}
}

17
osu.Game/Users/User.cs Normal file
View File

@ -0,0 +1,17 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.Users
{
public class User
{
public int Id;
public string Username;
}
}

View File

@ -45,6 +45,29 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Beatmaps\Beatmap.cs" />
<Compile Include="Beatmaps\BeatmapSet.cs" />
<Compile Include="Beatmaps\Metadata.cs" />
<Compile Include="Beatmaps\Objects\HitObject.cs" />
<Compile Include="Beatmaps\Objects\Catch\CatchBaseHit.cs" />
<Compile Include="Beatmaps\Objects\Catch\Droplet.cs" />
<Compile Include="Beatmaps\Objects\Catch\Fruit.cs" />
<Compile Include="Beatmaps\Objects\Mania\HoldNote.cs" />
<Compile Include="Beatmaps\Objects\Mania\ManiaBaseHit.cs" />
<Compile Include="Beatmaps\Objects\Mania\Note.cs" />
<Compile Include="Beatmaps\Objects\Osu\Circle.cs" />
<Compile Include="Beatmaps\Objects\Osu\OsuBaseHit.cs" />
<Compile Include="Beatmaps\Objects\Osu\Slider.cs" />
<Compile Include="Beatmaps\Objects\Osu\Spinner.cs" />
<Compile Include="Beatmaps\Objects\Taiko\TaikoBaseHit.cs" />
<Compile Include="Beatmaps\Samples\HitSampleInfo.cs" />
<Compile Include="Beatmaps\Samples\SampleBank.cs" />
<Compile Include="Beatmaps\Samples\SampleInfo.cs" />
<Compile Include="Beatmaps\Samples\SampleSet.cs" />
<Compile Include="Beatmaps\Samples\SampleType.cs" />
<Compile Include="Beatmaps\Timing\ControlPoint.cs" />
<Compile Include="Beatmaps\Timing\SampleChange.cs" />
<Compile Include="Beatmaps\Timing\TimingChange.cs" />
<Compile Include="Configuration\OsuConfigManager.cs" />
<Compile Include="GameModes\Charts\ChartInfo.cs" />
<Compile Include="GameModes\Edit\Editor.cs" />
@ -61,6 +84,16 @@
<Compile Include="GameModes\Play\Results.cs" />
<Compile Include="GameModes\Direct\OnlineListing.cs" />
<Compile Include="GameModes\Play\SongSelectPlay.cs" />
<Compile Include="GameModes\Play\Catch\CatchHitRenderer.cs" />
<Compile Include="GameModes\Play\Catch\CatchPlayfield.cs" />
<Compile Include="GameModes\Play\HitRenderer.cs" />
<Compile Include="GameModes\Play\Mania\ManiaHitRenderer.cs" />
<Compile Include="GameModes\Play\Mania\ManiaPlayfield.cs" />
<Compile Include="GameModes\Play\Osu\OsuHitRenderer.cs" />
<Compile Include="GameModes\Play\Osu\OsuPlayfield.cs" />
<Compile Include="GameModes\Play\Playfield.cs" />
<Compile Include="GameModes\Play\Taiko\TaikoHitRenderer.cs" />
<Compile Include="GameModes\Play\Taiko\TaikoPlayfield.cs" />
<Compile Include="GameModes\Edit\SongSelectEdit.cs" />
<Compile Include="Graphics\Background\Background.cs" />
<Compile Include="Graphics\Containers\ParallaxContainer.cs" />
@ -79,12 +112,15 @@
<Compile Include="Online\API\SecurePassword.cs" />
<Compile Include="Online\API\Requests\ListChannels.cs" />
<Compile Include="Online\Chat\Channel.cs" />
<Compile Include="Online\Chat\Display\ChatLine.cs" />
<Compile Include="Online\Chat\Message.cs" />
<Compile Include="Online\User.cs" />
<Compile Include="OsuGame.cs" />
<Compile Include="OsuGameBase.cs" />
<Compile Include="Overlays\Options.cs" />
<Compile Include="Overlays\Toolbar.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Users\User.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\osu-framework\osu.Framework\osu.Framework.csproj">