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

Merge pull request #1 from ppy/master

Actualize fork
This commit is contained in:
UselessToucan 2016-10-03 18:41:10 +03:00 committed by GitHub
commit 2f588a2d2c
81 changed files with 2412 additions and 148 deletions

@ -1 +1 @@
Subproject commit 05c40c281741f81ea09f05fce9a1b22c7589dc8e
Subproject commit 4d78fdfbe01e3ecb213c19a3f3243c80a71bb668

@ -1 +1 @@
Subproject commit 5cc6e0a311145a9871fb90d0d91226f3858bdce4
Subproject commit cc107f9bcfc8efeeff88f19c2df8cec9755eda39

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,
RelativeSizeAxes = Axes.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,97 @@
//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();
//ensure we are at offset 0
if (localClock == null)
localClock = new FramedOffsetClock(base.Clock);
localClock.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

@ -0,0 +1,35 @@
//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 OpenTK.Input;
using osu.Framework.GameModes.Testing;
using osu.Framework.Graphics;
using osu.Game.Graphics.UserInterface;
namespace osu.Desktop.Tests
{
class TestCaseKeyCounter : TestCase
{
public override string Name => @"KeyCounter";
public override string Description => @"Tests key counter";
public override void Reset()
{
base.Reset();
KeyCounterCollection kc = new KeyCounterCollection
{
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
IsCounting = true
};
Add(kc);
kc.AddKey(new KeyCounterKeyboard(@"Z", Key.Z));
kc.AddKey(new KeyCounterKeyboard(@"X", Key.X));
kc.AddKey(new KeyCounterMouse(@"M1", MouseButton.Left));
kc.AddKey(new KeyCounterMouse(@"M2", MouseButton.Right));
}
}
}

View File

@ -0,0 +1,21 @@
//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.GameModes.Testing;
using osu.Game.GameModes.Menu;
namespace osu.Desktop.Tests
{
class TestCaseMenuButtonSystem : TestCase
{
public override string Name => @"ButtonSystem";
public override string Description => @"Main menu button system";
public override void Reset()
{
base.Reset();
Add(new ButtonSystem());
}
}
}

View File

@ -1,4 +1,7 @@
using OpenTK;
//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 OpenTK.Graphics;
using osu.Framework.GameModes.Testing;
using osu.Framework.Graphics;
@ -27,7 +30,7 @@ namespace osu.Desktop.Tests
Add(flow = new FlowContainer()
{
SizeMode = InheritMode.XY,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.5f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre

View File

@ -150,6 +150,10 @@
</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" />
<Compile Include="VisualTestGame.cs" />
</ItemGroup>

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

@ -6,12 +6,11 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework.GameModes;
namespace osu.Game.Graphics.Containers
namespace osu.Game.Beatmaps.Timing
{
class OsuGameMode : GameMode
public class ControlPoint
{
public new OsuGame Game => base.Game as OsuGame;
public double Time;
}
}

View File

@ -6,12 +6,12 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps.Samples;
namespace osu.Game.Graphics.Containers
namespace osu.Game.Beatmaps.Timing
{
class OsuLargeComponent : LargeContainer
class SampleChange : ControlPoint
{
public new OsuGame Game => base.Game as OsuGame;
public SampleInfo Sample;
}
}

View File

@ -3,17 +3,16 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Graphics.Containers
namespace osu.Game.Beatmaps.Timing
{
class OsuComponent : AutoSizeContainer
class TimingChange : ControlPoint
{
public new OsuGame Game => base.Game as OsuGame;
public double BeatLength;
public double BPM => 60000 / BeatLength;
}
}

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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.GameModes.Charts
{
class ChartInfo : GameModeWhiteBox
{
}
}

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;
using System.Collections.Generic;
namespace osu.Game.GameModes.Charts
{
class ChartListing : GameModeWhiteBox
{
protected override IEnumerable<Type> PossibleChildren => new[] {
typeof(ChartInfo)
};
}
}

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.GameModes.Direct
{
class OnlineListing : GameModeWhiteBox
{
}
}

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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.GameModes.Edit
{
class Editor : GameModeWhiteBox
{
}
}

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;
using System.Collections.Generic;
namespace osu.Game.GameModes.Edit
{
class SongSelectEdit : GameModeWhiteBox
{
protected override IEnumerable<Type> PossibleChildren => new[] {
typeof(Editor)
};
}
}

View File

@ -0,0 +1,156 @@
//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.GameModes;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Graphics.UserInterface;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.GameModes
{
public class GameModeWhiteBox : GameMode
{
private Button popButton;
const int transition_time = 1000;
protected virtual IEnumerable<Type> PossibleChildren => null;
private FlowContainer childModeButtons;
private Container textContainer;
protected override double OnEntering(GameMode last)
{
//only show the pop button if we are entered form another gamemode.
if (last != null)
popButton.Alpha = 1;
Content.Alpha = 0;
textContainer.Position = new Vector2(Size.X / 16, 0);
Content.Delay(300);
textContainer.MoveTo(Vector2.Zero, transition_time, EasingTypes.OutExpo);
Content.FadeIn(transition_time, EasingTypes.OutExpo);
return 0;// transition_time * 1000;
}
protected override double OnExiting(GameMode next)
{
textContainer.MoveTo(new Vector2((Size.X / 16), 0), transition_time, EasingTypes.OutExpo);
Content.FadeOut(transition_time, EasingTypes.OutExpo);
return transition_time;
}
protected override double OnSuspending(GameMode next)
{
textContainer.MoveTo(new Vector2(-(Size.X / 16), 0), transition_time, EasingTypes.OutExpo);
Content.FadeOut(transition_time, EasingTypes.OutExpo);
return transition_time;
}
protected override double OnResuming(GameMode last)
{
textContainer.MoveTo(Vector2.Zero, transition_time, EasingTypes.OutExpo);
Content.FadeIn(transition_time, EasingTypes.OutExpo);
return transition_time;
}
public override void Load()
{
base.Load();
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.7f),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = getColourFor(GetType()),
Alpha = 0.6f,
Additive = true
},
textContainer = new AutoSizeContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new[]
{
new SpriteText
{
Text = GetType().Name,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
TextSize = 50,
},
new SpriteText
{
Text = GetType().Namespace,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Position = new Vector2(0, 30)
},
}
},
popButton = new Button
{
Text = @"Back",
RelativeSizeAxes = Axes.X,
Size = new Vector2(0.1f, 40),
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Colour = new Color4(235, 51, 153, 255),
Alpha = 0,
Action = delegate {
Exit();
}
},
childModeButtons = new FlowContainer
{
Direction = FlowDirection.VerticalOnly,
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.1f, 1)
}
};
if (PossibleChildren != null)
{
foreach (Type t in PossibleChildren)
{
childModeButtons.Add(new Button
{
Text = $@"{t.Name}",
RelativeSizeAxes = Axes.X,
Size = new Vector2(1, 40),
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Colour = getColourFor(t),
Action = delegate
{
Push(Activator.CreateInstance(t) as GameMode);
}
});
}
}
}
private Color4 getColourFor(Type type)
{
int hash = type.Name.GetHashCode();
byte r = (byte)MathHelper.Clamp(((hash & 0xFF0000) >> 16) * 0.8f, 20, 255);
byte g = (byte)MathHelper.Clamp(((hash & 0x00FF00) >> 8) * 0.8f, 20, 255);
byte b = (byte)MathHelper.Clamp((hash & 0x0000FF) * 0.8f, 20, 255);
return new Color4(r, g, b, 255);
}
}
}

View File

@ -11,7 +11,6 @@ using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
using osu.Framework.Threading;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using OpenTK;
@ -20,17 +19,29 @@ using OpenTK.Input;
namespace osu.Game.GameModes.Menu
{
internal class ButtonSystem : OsuLargeComponent
public class ButtonSystem : Container
{
public Action OnEdit;
public Action OnExit;
public Action OnDirect;
public Action OnSolo;
public Action OnSettings;
public Action OnMulti;
public Action OnChart;
public Action OnTest;
private FlowContainerWithOrigin buttonFlow;
const float button_area_height = 128;
const float button_width = 180f;
const float wedge_width = 25.6f;
const float button_area_height = 100;
const float button_width = 140f;
const float wedge_width = 20;
public const int EXIT_DELAY = 3000;
private OsuLogo osuLogo;
private Drawable iconFacade;
private Container buttonArea;
private Box buttonAreaBackground;
private Button backButton;
private Button settingsButton;
@ -41,9 +52,15 @@ namespace osu.Game.GameModes.Menu
public enum MenuState
{
Initial,
Exit,
TopLevel,
Play,
EnteringMode,
Exit,
}
public ButtonSystem()
{
RelativeSizeAxes = Axes.Both;
}
public override void Load()
@ -56,15 +73,18 @@ namespace osu.Game.GameModes.Menu
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
SizeMode = InheritMode.X,
RelativeSizeAxes = Axes.X,
Size = new Vector2(1, button_area_height),
Alpha = 0,
Children = new Drawable[]
{
new Box
buttonAreaBackground = new Box
{
SizeMode = InheritMode.XY,
Colour = new Color4(50, 50, 50, 255)
RelativeSizeAxes = Axes.Both,
Size = new Vector2(2, 1),
Colour = new Color4(50, 50, 50, 255),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
buttonFlow = new FlowContainerWithOrigin
{
@ -72,7 +92,7 @@ namespace osu.Game.GameModes.Menu
Padding = new Vector2(-wedge_width, 0),
Children = new Drawable[]
{
settingsButton = new Button(@"settings", @"options", FontAwesome.gear, new Color4(85, 85, 85, 255), onSettings, -wedge_width, Key.O),
settingsButton = new Button(@"settings", @"options", FontAwesome.gear, new Color4(85, 85, 85, 255), OnSettings, -wedge_width, Key.O),
backButton = new Button(@"back", @"back", FontAwesome.fa_osu_left_o, new Color4(51, 58, 94, 255), onBack, -wedge_width, Key.Escape),
iconFacade = new Container //need a container to make the osu! icon flow properly.
{
@ -92,14 +112,14 @@ namespace osu.Game.GameModes.Menu
buttonFlow.Position = new Vector2(wedge_width * 2 - (button_width + osuLogo.SizeForFlow / 4), 0);
buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"solo", @"freeplay", FontAwesome.user, new Color4(102, 68, 204, 255), onSolo, wedge_width, Key.P)));
buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"multi", @"multiplayer", FontAwesome.users, new Color4(94, 63, 186, 255), onMulti, 0, Key.M)));
buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"chart", @"charts", FontAwesome.fa_osu_charts, new Color4(80, 53, 160, 255), onChart)));
buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"tests", @"tests", FontAwesome.terminal, new Color4(80, 53, 160, 255), onTest, 0, Key.T)));
buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"solo", @"freeplay", FontAwesome.user, new Color4(102, 68, 204, 255), OnSolo, wedge_width, Key.P)));
buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"multi", @"multiplayer", FontAwesome.users, new Color4(94, 63, 186, 255), OnMulti, 0, Key.M)));
buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"chart", @"charts", FontAwesome.fa_osu_charts, new Color4(80, 53, 160, 255), OnChart)));
buttonsPlay.Add((Button)buttonFlow.Add(new Button(@"tests", @"tests", FontAwesome.terminal, new Color4(80, 53, 160, 255), OnTest, 0, Key.T)));
buttonsTopLevel.Add((Button)buttonFlow.Add(new Button(@"play", @"play", FontAwesome.fa_osu_logo, new Color4(102, 68, 204, 255), onPlay, wedge_width, Key.P)));
buttonsTopLevel.Add((Button)buttonFlow.Add(new Button(@"osu!editor", @"edit", FontAwesome.fa_osu_edit_o, new Color4(238, 170, 0, 255), onEdit, 0, Key.E)));
buttonsTopLevel.Add((Button)buttonFlow.Add(new Button(@"osu!direct", @"direct", FontAwesome.fa_osu_chevron_down_o, new Color4(165, 204, 0, 255), onDirect, 0, Key.D)));
buttonsTopLevel.Add((Button)buttonFlow.Add(new Button(@"osu!editor", @"edit", FontAwesome.fa_osu_edit_o, new Color4(238, 170, 0, 255), OnEdit, 0, Key.E)));
buttonsTopLevel.Add((Button)buttonFlow.Add(new Button(@"osu!direct", @"direct", FontAwesome.fa_osu_chevron_down_o, new Color4(165, 204, 0, 255), OnDirect, 0, Key.D)));
buttonsTopLevel.Add((Button)buttonFlow.Add(new Button(@"exit", @"exit", FontAwesome.fa_osu_cross_o, new Color4(238, 51, 153, 255), onExit, 0, Key.Q)));
}
@ -109,31 +129,15 @@ namespace osu.Game.GameModes.Menu
return true;
}
private void onSettings()
{
//OsuGame.Options.LoginOnly = false;
//OsuGame.Options.Expanded = true;
}
private void onPlay()
{
State = MenuState.Play;
}
private void onEdit()
{
//OsuGame.ChangeMode(OsuModes.SelectEdit);
}
private void onDirect()
{
//OsuGame.ChangeMode(OsuModes.OnlineSelection);
}
private void onExit()
{
//OsuGame.ChangeMode(OsuModes.Exit);
State = MenuState.Exit;
OnExit?.Invoke();
}
private void onBack()
@ -141,27 +145,6 @@ namespace osu.Game.GameModes.Menu
State = MenuState.TopLevel;
}
private void onSolo()
{
//OsuGame.ChangeMode(OsuModes.SelectPlay);
}
private void onMulti()
{
//OsuGame.ChangeMode(OsuModes.Lobby);
}
private void onChart()
{
//OsuGame.ChangeMode(OsuModes.Charts);
}
private void onTest()
{
//OsuGame.ChangeMode(OsuModes.FieldTest);
}
private void onOsuLogo()
{
switch (state)
@ -196,11 +179,16 @@ namespace osu.Game.GameModes.Menu
MenuState lastState = state;
state = value;
//todo: figure a more elegant way of doing this.
buttonsTopLevel.ForEach(b => b.ContractStyle = 0);
buttonsPlay.ForEach(b => b.ContractStyle = 0);
backButton.ContractStyle = 0;
settingsButton.ContractStyle = 0;
switch (state)
{
case MenuState.Initial:
backButton.State = Button.ButtonState.Contracted;
buttonAreaBackground.ScaleTo(Vector2.One, 500, EasingTypes.Out);
buttonArea.FadeOut(500);
osuLogo.Delay(150);
@ -214,7 +202,7 @@ namespace osu.Game.GameModes.Menu
b.State = Button.ButtonState.Contracted;
break;
case MenuState.TopLevel:
backButton.State = Button.ButtonState.Contracted;
buttonAreaBackground.ScaleTo(Vector2.One, 200, EasingTypes.Out);
osuLogo.MoveTo(buttonFlow.Position, 200, EasingTypes.In);
osuLogo.ScaleTo(0.5f, 200, EasingTypes.In);
@ -232,14 +220,26 @@ namespace osu.Game.GameModes.Menu
b.State = Button.ButtonState.Contracted;
break;
case MenuState.Play:
backButton.State = Button.ButtonState.Expanded;
foreach (Button b in buttonsTopLevel)
b.State = Button.ButtonState.Exploded;
foreach (Button b in buttonsPlay)
b.State = Button.ButtonState.Expanded;
break;
case MenuState.EnteringMode:
buttonAreaBackground.ScaleTo(new Vector2(2, 0), 300, EasingTypes.InSine);
buttonsTopLevel.ForEach(b => b.ContractStyle = 1);
buttonsPlay.ForEach(b => b.ContractStyle = 1);
backButton.ContractStyle = 1;
settingsButton.ContractStyle = 1;
foreach (Button b in buttonsTopLevel)
b.State = Button.ButtonState.Contracted;
foreach (Button b in buttonsPlay)
b.State = Button.ButtonState.Contracted;
break;
case MenuState.Exit:
buttonArea.FadeOut(200);
@ -250,13 +250,14 @@ namespace osu.Game.GameModes.Menu
b.State = Button.ButtonState.Contracted;
osuLogo.Delay(150);
osuLogo.ScaleTo(1f, 4000);
osuLogo.RotateTo(20, 4000);
osuLogo.FadeOut(4000);
osuLogo.ScaleTo(1f, EXIT_DELAY * 1.5f);
osuLogo.RotateTo(20, EXIT_DELAY * 1.5f);
osuLogo.FadeOut(EXIT_DELAY);
break;
}
backButton.State = state >= MenuState.Play ? Button.ButtonState.Expanded : Button.ButtonState.Contracted;
backButton.State = state == MenuState.Play ? Button.ButtonState.Expanded : Button.ButtonState.Contracted;
settingsButton.State = state == MenuState.TopLevel ? Button.ButtonState.Expanded : Button.ButtonState.Contracted;
if (lastState == MenuState.Initial)
@ -276,14 +277,14 @@ namespace osu.Game.GameModes.Menu
/// <summary>
/// osu! logo and its attachments (pulsing, visualiser etc.)
/// </summary>
class OsuLogo : OsuComponent
class OsuLogo : AutoSizeContainer
{
private Sprite logo;
private Container logoBounceContainer;
private MenuVisualisation vis;
private Action clickAction;
public float SizeForFlow => logo == null ? 0 : logo.ActualSize.X * logo.Scale.X * logoBounceContainer.Scale.X * 0.8f;
public float SizeForFlow => logo == null ? 0 : logo.Size.X * logo.Scale.X * logoBounceContainer.Scale.X * 0.8f;
public override void Load()
{
@ -291,7 +292,6 @@ namespace osu.Game.GameModes.Menu
Sprite ripple;
Children = new Drawable[]
{
logoBounceContainer = new AutoSizeContainer
@ -300,13 +300,13 @@ namespace osu.Game.GameModes.Menu
{
logo = new Sprite()
{
Texture = Game.Textures.Get(@"menu-osu"),
Texture = Game.Textures.Get(@"Menu/logo"),
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
ripple = new Sprite()
{
Texture = Game.Textures.Get(@"menu-osu"),
Texture = Game.Textures.Get(@"Menu/logo"),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0.4f
@ -397,7 +397,7 @@ namespace osu.Game.GameModes.Menu
/// Button designed specifically for the osu!next main menu.
/// In order to correctly flow, we have to use a negative margin on the parent container (due to the parallelogram shape).
/// </summary>
private class Button : OsuComponent
private class Button : AutoSizeContainer
{
private Container iconText;
private WedgedBox box;
@ -447,7 +447,7 @@ namespace osu.Game.GameModes.Menu
icon = new TextAwesome
{
Anchor = Anchor.Centre,
TextSize = 40,
TextSize = 30,
Position = new Vector2(0, 0),
Icon = symbol
},
@ -456,6 +456,7 @@ namespace osu.Game.GameModes.Menu
Direction = FlowDirection.HorizontalOnly,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
TextSize = 16,
Position = new Vector2(0, 35),
Text = text
}
@ -603,8 +604,9 @@ namespace osu.Game.GameModes.Menu
base.Update();
}
ButtonState state;
public int ContractStyle;
ButtonState state;
public ButtonState State
{
get { return state; }
@ -614,15 +616,25 @@ namespace osu.Game.GameModes.Menu
if (state == value)
return;
ButtonState lastState = state;
state = value;
switch (state)
{
case ButtonState.Contracted:
const int contract_duration = 500;
box.ScaleTo(new Vector2(0, 1), contract_duration, EasingTypes.OutExpo);
FadeOut(contract_duration);
switch (ContractStyle)
{
default:
box.ScaleTo(new Vector2(0, 1), 500, EasingTypes.OutExpo);
FadeOut(500);
break;
case 1:
box.ScaleTo(new Vector2(0, 1), 400, EasingTypes.InSine);
FadeOut(800);
break;
}
break;
case ButtonState.Contracted2:
break;
case ButtonState.Expanded:
const int expand_duration = 500;
@ -643,6 +655,7 @@ namespace osu.Game.GameModes.Menu
public enum ButtonState
{
Contracted,
Contracted2,
Expanded,
Exploded
}

View File

@ -4,26 +4,87 @@
using osu.Framework.Audio.Sample;
using osu.Framework.Audio.Track;
using osu.Framework.GameModes;
using osu.Framework.GameModes.Testing;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Transformations;
using osu.Game.GameModes.Charts;
using osu.Game.GameModes.Direct;
using osu.Game.GameModes.Edit;
using osu.Game.GameModes.Multiplayer;
using osu.Game.GameModes.Play;
using osu.Game.Graphics.Containers;
using OpenTK;
namespace osu.Game.GameModes.Menu
{
internal class MainMenu : GameMode
{
private ButtonSystem buttons;
public override string Name => @"Main Menu";
private AudioTrackBass bgm;
//private AudioTrack bgm;
public override void Load()
{
base.Load();
public override void Load()
{
base.Load();
AudioSample welcome = Game.Audio.Sample.Get(@"welcome");
OsuGame osu = (OsuGame)Game;
Children = new Drawable[]
{
new ButtonSystem(),
};
}
AudioSample welcome = Game.Audio.Sample.Get(@"welcome");
welcome.Play();
//bgm = Game.Audio.Track.Get(@"circles");
//bgm.Start();
Children = new Drawable[]
{
new ParallaxContainer
{
ParallaxAmount = 0.01f,
Children = new Drawable[]
{
buttons = new ButtonSystem()
{
OnChart = delegate { Push(new ChartListing()); },
OnDirect = delegate { Push(new OnlineListing()); },
OnEdit = delegate { Push(new SongSelectEdit()); },
OnSolo = delegate { Push(new SongSelectPlay()); },
OnMulti = delegate { Push(new Lobby()); },
OnTest = delegate { Push(new TestBrowser()); },
OnExit = delegate {
Game.Scheduler.AddDelayed(delegate {
Game.Host.Exit();
}, ButtonSystem.EXIT_DELAY);
},
OnSettings = delegate {
osu.Options.PoppedOut = !osu.Options.PoppedOut;
},
}
}
}
};
}
protected override double OnSuspending(GameMode next)
{
const float length = 400;
buttons.State = ButtonSystem.MenuState.EnteringMode;
Content.FadeOut(length, EasingTypes.InSine);
Content.MoveTo(new Vector2(-800, 0), length, EasingTypes.InSine);
return base.OnSuspending(next);
}
protected override double OnResuming(GameMode last)
{
const float length = 300;
buttons.State = ButtonSystem.MenuState.TopLevel;
Content.FadeIn(length, EasingTypes.OutQuint);
Content.MoveTo(new Vector2(0, 0), length, EasingTypes.OutQuint);
return base.OnResuming(last);
}
}
}

View File

@ -0,0 +1,19 @@
//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.GameModes.Multiplayer
{
class Lobby : GameModeWhiteBox
{
protected override IEnumerable<Type> PossibleChildren => new[] {
typeof(MatchCreate),
typeof(Match)
};
}
}

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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Game.GameModes.Play;
namespace osu.Game.GameModes.Multiplayer
{
class Match : GameModeWhiteBox
{
protected override IEnumerable<Type> PossibleChildren => new[] {
typeof(MatchSongSelect),
typeof(Player),
};
}
}

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.GameModes.Multiplayer
{
class MatchCreate : GameModeWhiteBox
{
protected override IEnumerable<Type> PossibleChildren => new[] {
typeof(Match)
};
}
}

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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.GameModes.Multiplayer
{
class MatchSongSelect : GameModeWhiteBox
{
}
}

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/logo"),
Origin = Anchor.Centre,
Scale = new Vector2(0.1f),
RelativePositionAxes = Axes.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()
{
RelativeSizeAxes = Axes.Y;
Size = new Vector2(512, 0.9f);
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
}
public override void Load()
{
base.Load();
Add(new Box { RelativeSizeAxes = Axes.Both, Alpha = 0.5f });
}
}
}

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 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 : Container
{
public abstract List<HitObject> Objects { set; }
public HitRenderer()
{
RelativeSizeAxes = Axes.Both;
}
public override void Load()
{
base.Load();
Add(new Box() { RelativeSizeAxes = Axes.Both, 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/logo"),
Origin = Anchor.Centre,
Scale = new Vector2(0.1f),
RelativePositionAxes = Axes.Both,
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;
RelativeSizeAxes = Axes.Both;
Size = new Vector2(columns / 20f, 1f);
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
}
public override void Load()
{
base.Load();
Add(new Box() { RelativeSizeAxes = Axes.Both, Alpha = 0.5f });
for (int i = 0; i < columns; i++)
Add(new Box()
{
RelativeSizeAxes = Axes.Y,
Size = new Vector2(2, 1),
RelativePositionAxes = Axes.Both,
Position = new Vector2((float)i / columns, 0),
Alpha = 0.5f,
Colour = Color4.Black
});
}
}
}

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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.GameModes.Play
{
class ModSelect : GameModeWhiteBox
{
}
}

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/logo"),
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()
{
RelativeSizeAxes = Axes.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,
RelativeSizeAxes = Axes.Both,
Alpha = 0.5f
});
}
}
}

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.GameModes.Play
{
class Player : GameModeWhiteBox
{
protected override IEnumerable<Type> PossibleChildren => new[] {
typeof(Results)
};
}
}

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,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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace osu.Game.GameModes.Play
{
class Results : GameModeWhiteBox
{
}
}

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;
namespace osu.Game.GameModes.Play
{
class SongSelectPlay : GameModeWhiteBox
{
protected override IEnumerable<Type> PossibleChildren => new[] {
typeof(ModSelect),
typeof(Player)
};
}
}

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/logo"),
Origin = Anchor.Centre,
Scale = new Vector2(0.2f),
RelativePositionAxes = Axes.Both,
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()
{
RelativeSizeAxes = Axes.X;
Size = new Vector2(1, 100);
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}
public override void Load()
{
base.Load();
Add(new Box { RelativeSizeAxes = Axes.Both, Alpha = 0.5f });
Add(new Sprite
{
Texture = Game.Textures.Get(@"Menu/logo"),
Origin = Anchor.Centre,
Scale = new Vector2(0.2f),
RelativePositionAxes = Axes.Both,
Position = new Vector2(0.1f, 0.5f),
Colour = Color4.Gray
});
}
}
}

View File

@ -0,0 +1,42 @@
//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 osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.Containers;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Graphics.Background
{
class Background : Container
{
protected Sprite BackgroundSprite;
public Background()
{
RelativeSizeAxes = Axes.Both;
}
public override void Load()
{
base.Load();
Add(BackgroundSprite = new Sprite
{
Texture = Game.Textures.Get(@"Menu/background"),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = Color4.DarkGray
});
}
protected override void Update()
{
base.Update();
BackgroundSprite.Scale = new Vector2(Math.Max(Size.X / BackgroundSprite.Size.X, Size.Y / BackgroundSprite.Size.Y));
}
}
}

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

@ -0,0 +1,46 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Framework.Input;
using OpenTK;
namespace osu.Game.Graphics.Containers
{
class ParallaxContainer : Container
{
public float ParallaxAmount = 0.02f;
public override bool Contains(Vector2 screenSpacePos) => true;
public ParallaxContainer()
{
RelativeSizeAxes = Axes.Both;
}
private Container content = new Container()
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
protected override Container AddTarget => content;
public override void Load()
{
base.Load();
Add(content);
}
protected override bool OnMouseMove(InputState state)
{
content.Position = (state.Mouse.Position - Size / 2) * ParallaxAmount;
return base.OnMouseMove(state);
}
protected override void Update()
{
base.Update();
content.Scale = new Vector2(1 + ParallaxAmount);
}
}
}

View File

@ -0,0 +1,53 @@
//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.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
namespace osu.Game.Graphics.Cursor
{
class OsuCursorContainer : CursorContainer
{
protected override Drawable CreateCursor() => new OsuCursor();
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
ActiveCursor.Scale = new OpenTK.Vector2(1);
ActiveCursor.ScaleTo(1.2f, 100, EasingTypes.OutQuad);
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
if (!state.Mouse.HasMainButtonPressed)
ActiveCursor.ScaleTo(1, 200, EasingTypes.OutQuad);
return base.OnMouseUp(state, args);
}
class OsuCursor : AutoSizeContainer
{
public OsuCursor()
{
Origin = Anchor.Centre;
}
public override void Load()
{
base.Load();
Children = new Drawable[]
{
new Sprite
{
Texture = Game.Textures.Get(@"Cursor/cursor")
}
};
}
}
}
}

View File

@ -1,18 +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;
using System;
using osu.Framework.Graphics.Containers;
using OpenTK;
using osu.Framework.Graphics;
namespace osu.Game.Graphics.Processing
{
class RatioAdjust : LargeContainer
class RatioAdjust : Container
{
public override bool Contains(Vector2 screenSpacePos) => true;
public RatioAdjust()
{
RelativeSizeAxes = Axes.Both;
}
protected override void Update()
{
base.Update();
Scale = new Vector2(Parent.ActualSize.Y / 768f);
Vector2 parent = Parent.Size;
Scale = new Vector2(Math.Min(parent.Y / 768f, parent.X / 1024f));
Size = new Vector2(1 / Scale.X);
}
}

View File

@ -0,0 +1,129 @@
//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 OpenTK.Graphics;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
namespace osu.Game.Graphics.UserInterface
{
public abstract class KeyCounter : Container
{
private Sprite buttonSprite;
private Sprite glowSprite;
private Container textLayer;
private SpriteText countSpriteText;
public override string Name { get; }
public bool IsCounting { get; set; }
private int count;
public int Count
{
get { return count; }
private set
{
if (count != value)
{
count = value;
countSpriteText.Text = value.ToString(@"#,0");
}
}
}
private bool isLit;
public bool IsLit
{
get { return isLit; }
protected set
{
if (isLit != value)
{
isLit = value;
updateGlowSprite(value);
if (value && IsCounting)
Count++;
}
}
}
//further: change default values here and in KeyCounterCollection if needed, instead of passing them in every constructor
public Color4 KeyDownTextColor { get; set; } = Color4.DarkGray;
public Color4 KeyUpTextColor { get; set; } = Color4.White;
public int FadeTime { get; set; } = 0;
protected KeyCounter(string name)
{
Name = name;
}
public override void Load()
{
base.Load();
Children = new Drawable[]
{
buttonSprite = new Sprite
{
Texture = Game.Textures.Get(@"KeyCounter/key-up"),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
glowSprite = new Sprite
{
Texture = Game.Textures.Get(@"KeyCounter/key-glow"),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0
},
textLayer = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
new SpriteText
{
Text = Name,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativePositionAxes = Axes.Both,
Position = new Vector2(0, -0.25f),
Colour = KeyUpTextColor
},
countSpriteText = new SpriteText
{
Text = Count.ToString(@"#,0"),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativePositionAxes = Axes.Both,
Position = new Vector2(0, 0.25f),
Colour = KeyUpTextColor
}
}
}
};
//Set this manually because an element with Alpha=0 won't take it size to AutoSizeContainer,
//so the size can be changing between buttonSprite and glowSprite.
Height = buttonSprite.Height;
Width = buttonSprite.Width;
}
private void updateGlowSprite(bool show)
{
if (show)
{
glowSprite.FadeIn(FadeTime);
textLayer.FadeColour(KeyDownTextColor, FadeTime);
}
else
{
glowSprite.FadeOut(FadeTime);
textLayer.FadeColour(KeyUpTextColor, FadeTime);
}
}
public void ResetCount() => Count = 0;
}
}

View File

@ -0,0 +1,100 @@
//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;
using OpenTK.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Graphics.UserInterface
{
public class KeyCounterCollection : FlowContainer
{
public KeyCounterCollection()
{
Direction = FlowDirection.HorizontalOnly;
}
private List<KeyCounter> counters = new List<KeyCounter>();
public IReadOnlyList<KeyCounter> Counters => counters;
public void AddKey(KeyCounter key)
{
counters.Add(key);
key.IsCounting = this.IsCounting;
key.FadeTime = this.FadeTime;
key.KeyDownTextColor = this.KeyDownTextColor;
key.KeyUpTextColor = this.KeyUpTextColor;
base.Add(key);
}
public void ResetCount()
{
foreach (var counter in counters)
counter.ResetCount();
}
public override bool Contains(Vector2 screenSpacePos) => true;
//further: change default values here and in KeyCounter if needed, instead of passing them in every constructor
private bool isCounting;
public bool IsCounting
{
get { return isCounting; }
set
{
if (value != isCounting)
{
isCounting = value;
foreach (var child in counters)
child.IsCounting = value;
}
}
}
private int fadeTime = 0;
public int FadeTime
{
get { return fadeTime; }
set
{
if (value != fadeTime)
{
fadeTime = value;
foreach (var child in counters)
child.FadeTime = value;
}
}
}
private Color4 keyDownTextColor = Color4.DarkGray;
public Color4 KeyDownTextColor
{
get { return keyDownTextColor; }
set
{
if (value != keyDownTextColor)
{
keyDownTextColor = value;
foreach (var child in counters)
child.KeyDownTextColor = value;
}
}
}
private Color4 keyUpTextColor = Color4.White;
public Color4 KeyUpTextColor
{
get { return keyUpTextColor; }
set
{
if (value != keyUpTextColor)
{
keyUpTextColor = value;
foreach (var child in counters)
child.KeyUpTextColor = value;
}
}
}
}
}

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 OpenTK.Input;
using osu.Framework.Graphics;
using osu.Framework.Input;
namespace osu.Game.Graphics.UserInterface
{
public class KeyCounterKeyboard : KeyCounter
{
public Key Key { get; }
public KeyCounterKeyboard(string name, Key key) : base(name)
{
Key = key;
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
if (args.Key == this.Key) IsLit = true;
return base.OnKeyDown(state, args);
}
protected override bool OnKeyUp(InputState state, KeyUpEventArgs args)
{
if (args.Key == this.Key) IsLit = false;
return base.OnKeyUp(state, args);
}
}
}

View File

@ -0,0 +1,33 @@
//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 OpenTK.Input;
using osu.Framework.Graphics;
using osu.Framework.Input;
namespace osu.Game.Graphics.UserInterface
{
public class KeyCounterMouse : KeyCounter
{
public MouseButton Button { get; }
public KeyCounterMouse(string name, MouseButton button) : base(name)
{
Button = button;
}
public override bool Contains(Vector2 screenSpacePos) => true;
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
if (args.Button == this.Button) IsLit = true;
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
if (args.Button == this.Button) IsLit = false;
return base.OnMouseUp(state, args);
}
}
}

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

@ -2,6 +2,7 @@
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Diagnostics;
using System.Security;
using osu.Framework.Extensions;
@ -35,6 +36,8 @@ namespace osu.Game.Online.API
internal string Get(Representation request = Representation.Raw)
{
Debug.Assert(representation == request);
switch (request)
{
default:

View File

@ -22,7 +22,7 @@ namespace osu.Game.Online.Chat
public List<Message> Messages = new List<Message>();
internal bool Joined;
//internal bool Joined;
[JsonConstructor]
public Channel()

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();
RelativeSizeAxes = Axes.X;
Add(new Box
{
RelativeSizeAxes = Axes.Both,
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,
RelativePositionAxes = Axes.X,
Position = new Vector2(0.14f,0),
});
Add(new SpriteText
{
Text = msg.Content,
RelativePositionAxes = Axes.X,
Position = new Vector2(0.15f, 0),
RelativeSizeAxes = Axes.X,
Size = new Vector2(0.85f, 1),
});
}
}
}
}

View File

@ -21,10 +21,10 @@ namespace osu.Game.Online.Chat
public DateTime Timestamp;
[JsonProperty(@"content")]
internal string Content;
public string Content;
[JsonProperty(@"sender")]
internal 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

@ -5,12 +5,19 @@ using osu.Game.Configuration;
using osu.Game.GameModes.Menu;
using OpenTK;
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;
using osu.Game.Overlays;
namespace osu.Game
{
public class OsuGame : OsuGameBase
{
public Toolbar Toolbar;
public override void SetHost(BasicGameHost host)
{
base.SetHost(host);
@ -22,15 +29,18 @@ namespace osu.Game
{
base.Load();
Add(new MainMenu());
}
ShowPerformanceOverlay = true;
protected override void Dispose(bool isDisposing)
{
//refresh token may have changed.
Config.Set(OsuConfig.Token, API.Token);
base.Dispose(isDisposing);
Add(new Drawable[] {
new ParallaxContainer
{
Children = new [] {
new Background()
}
},
new MainMenu(),
Toolbar = new Toolbar(),
});
}
public override bool Invalidate(Invalidation invalidation = Invalidation.All, Drawable source = null, bool shallPropagate = true)
@ -39,8 +49,8 @@ namespace osu.Game
if (Parent != null)
{
Config.Set(OsuConfig.Width, ActualSize.X);
Config.Set(OsuConfig.Height, ActualSize.Y);
Config.Set(OsuConfig.Width, Size.X);
Config.Set(OsuConfig.Height, Size.Y);
}
return true;
}

View File

@ -1,11 +1,14 @@
using osu.Framework.Graphics;
using osu.Framework.GameModes;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Textures;
using osu.Framework.IO.Stores;
using osu.Game.Configuration;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.Processing;
using osu.Game.Online.API;
using osu.Game.Overlays;
namespace osu.Game
{
@ -15,7 +18,8 @@ namespace osu.Game
protected override string MainResourceFile => @"osu.Game.Resources.dll";
internal APIAccess API;
public Options Options;
public APIAccess API;
protected override Container AddTarget => ratioContainer?.IsLoaded == true ? ratioContainer : base.AddTarget;
@ -44,10 +48,26 @@ namespace osu.Game
{
Children = new Drawable[]
{
new CursorContainer()
Options = new Options(),
new OsuCursorContainer()
}
}
});
}
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);
}
}
}

View File

@ -0,0 +1,75 @@
//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.Transformations;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Input;
using OpenTK.Input;
namespace osu.Game.Overlays
{
public class Options : Container
{
const float width = 300;
public override void Load()
{
base.Load();
Depth = float.MaxValue;
RelativeSizeAxes = Axes.Y;
Size = new Vector2(width, 1);
Position = new Vector2(-width, 0);
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = new Color4(0.1f, 0.1f, 0.1f, 0.9f)
}
};
}
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
switch (args.Key)
{
case Key.Escape:
if (!poppedOut) return false;
PoppedOut = false;
return true;
}
return base.OnKeyDown(state, args);
}
private bool poppedOut;
public bool PoppedOut
{
get { return poppedOut; }
set
{
if (value == poppedOut) return;
poppedOut = value;
if (poppedOut)
{
MoveTo(new Vector2(0, 0), 300, EasingTypes.Out);
}
else
{
MoveTo(new Vector2(-width, 0), 300, EasingTypes.Out);
}
}
}
}
}

View File

@ -0,0 +1,38 @@
//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.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Drawables;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Overlays
{
public class Toolbar : Container
{
const float height = 50;
public override void Load()
{
base.Load();
RelativeSizeAxes = Axes.X;
Size = new Vector2(1, height);
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = new Color4(0.1f, 0.1f, 0.1f, 0.9f)
}
};
}
}
}

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,14 +45,65 @@
<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" />
<Compile Include="GameModes\GameModeWhiteBox.cs" />
<Compile Include="GameModes\Menu\ButtonSystem.cs" />
<Compile Include="GameModes\Menu\MainMenu.cs" />
<Compile Include="Graphics\Containers\OsuComponent.cs" />
<Compile Include="Graphics\Containers\OsuGameMode.cs" />
<Compile Include="Graphics\Containers\OsuLargeComponent.cs" />
<Compile Include="GameModes\Multiplayer\Lobby.cs" />
<Compile Include="GameModes\Multiplayer\Match.cs" />
<Compile Include="GameModes\Multiplayer\MatchCreate.cs" />
<Compile Include="GameModes\Multiplayer\MatchSongSelect.cs" />
<Compile Include="GameModes\Play\ModSelect.cs" />
<Compile Include="GameModes\Play\Player.cs" />
<Compile Include="GameModes\Charts\ChartListing.cs" />
<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" />
<Compile Include="Graphics\Cursor\OsuCursorContainer.cs" />
<Compile Include="Graphics\Processing\RatioAdjust.cs" />
<Compile Include="Graphics\TextAwesome.cs" />
<Compile Include="Graphics\UserInterface\KeyCounter.cs" />
<Compile Include="Graphics\UserInterface\KeyCounterKeyboard.cs" />
<Compile Include="Graphics\UserInterface\KeyCounterCollection.cs" />
<Compile Include="Graphics\UserInterface\KeyCounterMouse.cs" />
<Compile Include="Online\API\APIAccess.cs" />
<Compile Include="Online\API\APIRequest.cs" />
<Compile Include="Online\API\OAuth.cs" />
@ -61,10 +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">