1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:47:29 +08:00

Add GameType and DrawableGameType

This commit is contained in:
DrabWeb 2017-05-30 21:41:20 -03:00
parent d331aa3b30
commit 9e01074852
6 changed files with 193 additions and 12 deletions

View File

@ -25,6 +25,7 @@ namespace osu.Desktop.VisualTests.Tests
room.Name.Value = @"My Awesome Room";
room.Host.Value = new User { Username = @"flyte", Id = 3103765, Country = new Country { FlagName = @"JP" }};
room.Status.Value = new RoomStatusOpen();
room.Type.Value = new GameTypeTeamVersus();
room.Beatmap.Value = new BeatmapInfo
{
StarDifficulty = 3.7,
@ -59,6 +60,7 @@ namespace osu.Desktop.VisualTests.Tests
AddStep(@"change title", () => room.Name.Value = @"A Better Room Than The Above");
AddStep(@"change host", () => room.Host.Value = new User { Username = @"DrabWeb", Id = 6946022, Country = new Country { FlagName = @"CA" }});
AddStep(@"change status", () => room.Status.Value = new RoomStatusPlaying());
AddStep(@"change type", () => room.Type.Value = new GameTypeTag());
AddStep(@"change beatmap", () => room.Beatmap.Value = null);
AddStep(@"change max participants", () => room.MaxParticipants.Value = null);
AddStep(@"change participants", () => room.Participants.Value = new[]
@ -73,6 +75,7 @@ namespace osu.Desktop.VisualTests.Tests
newRoom.Name.Value = @"My New, Better Than Ever Room";
newRoom.Host.Value = new User { Username = @"Angelsim", Id = 1777162, Country = new Country { FlagName = @"KR" }};
newRoom.Status.Value = new RoomStatusOpen();
newRoom.Type.Value = new GameTypeTagTeam();
newRoom.Beatmap.Value = new BeatmapInfo
{
StarDifficulty = 7.07,

View File

@ -0,0 +1,127 @@
// Copyright (c) 2007-2017 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;
using osu.Game.Graphics;
namespace osu.Game.Online.Multiplayer
{
public abstract class GameType
{
public abstract string Name { get; }
public abstract Drawable GetIcon(OsuColour colours, float size);
}
public class GameTypeTag : GameType
{
public override string Name => "Tag";
public override Drawable GetIcon(OsuColour colours, float size)
{
return new TextAwesome
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.fa_refresh,
TextSize = size,
Colour = colours.Blue,
Shadow = false,
UseFullGlyphHeight = false,
};
}
}
public class GameTypeVersus : GameType
{
public override string Name => "Versus";
public override Drawable GetIcon(OsuColour colours, float size)
{
return new VersusRow(colours.Blue, colours.Blue, size * 0.6f)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
}
}
public class GameTypeTagTeam : GameType
{
public override string Name => "Tag Team";
public override Drawable GetIcon(OsuColour colours, float size)
{
return new VersusRow(colours.Blue, colours.Blue, size * 0.6f)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
}
}
public class GameTypeTeamVersus : GameType
{
public override string Name => "Team Versus";
public override Drawable GetIcon(OsuColour colours, float size)
{
return new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(2f),
Children = new[]
{
new VersusRow(colours.Blue, colours.Pink, size * 0.5f),
new VersusRow(colours.Blue, colours.Pink, size * 0.5f),
},
};
}
}
internal class VersusRow : FillFlowContainer
{
public VersusRow(Color4 first, Color4 second, float size)
{
var triangle_size = new Vector2(size);
AutoSizeAxes = Axes.Both;
Spacing = new Vector2(2f, 0f);
Children = new[]
{
new Container
{
Size = triangle_size,
Colour = first,
Children = new[]
{
new EquilateralTriangle
{
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Rotation = 90,
EdgeSmoothness = new Vector2(1f),
},
},
},
new Container
{
Size = triangle_size,
Colour = second,
Children = new[]
{
new EquilateralTriangle
{
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Rotation = -90,
EdgeSmoothness = new Vector2(1f),
},
},
},
};
}
}
}

View File

@ -12,6 +12,7 @@ namespace osu.Game.Online.Multiplayer
public Bindable<string> Name = new Bindable<string>();
public Bindable<User> Host = new Bindable<User>();
public Bindable<RoomStatus> Status = new Bindable<RoomStatus>();
public Bindable<GameType> Type = new Bindable<GameType>();
public Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
public Bindable<int?> MaxParticipants = new Bindable<int?>();
public Bindable<User[]> Participants = new Bindable<User[]>();

View File

@ -0,0 +1,43 @@
// Copyright (c) 2007-2017 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.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
using osu.Game.Online.Multiplayer;
namespace osu.Game.Screens.Multiplayer
{
public class DrawableGameType : CircularContainer, IHasTooltip
{
private readonly GameType type;
public string TooltipText => type.Name;
public DrawableGameType(GameType type)
{
this.type = type;
Masking = true;
Children = new[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"545454"),
},
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
Add(type.GetIcon(colours, Height / 2));
}
}
}

View File

@ -29,7 +29,7 @@ namespace osu.Game.Screens.Multiplayer
private const float ruleset_height = 30;
private readonly Box statusStrip;
private readonly Container coverContainer, rulesetContainer, flagContainer;
private readonly Container coverContainer, rulesetContainer, gameTypeContainer, flagContainer;
private readonly FillFlowContainer topFlow, levelRangeContainer, participantsFlow;
private readonly OsuSpriteText participants, participantsSlash, maxParticipants, name, status, beatmapTitle, beatmapDash, beatmapArtist, beatmapAuthor, host, levelRangeLower, levelRangeHigher;
private readonly ScrollContainer participantsScroll;
@ -37,6 +37,7 @@ namespace osu.Game.Screens.Multiplayer
private Bindable<string> nameBind = new Bindable<string>();
private Bindable<User> hostBind = new Bindable<User>();
private Bindable<RoomStatus> statusBind = new Bindable<RoomStatus>();
private Bindable<GameType> typeBind = new Bindable<GameType>();
private Bindable<BeatmapInfo> beatmapBind = new Bindable<BeatmapInfo>();
private Bindable<int?> maxParticipantsBind = new Bindable<int?>();
private Bindable<User[]> participantsBind = new Bindable<User[]>();
@ -57,6 +58,7 @@ namespace osu.Game.Screens.Multiplayer
nameBind.BindTo(Room.Name);
hostBind.BindTo(Room.Host);
statusBind.BindTo(Room.Status);
typeBind.BindTo(Room.Type);
beatmapBind.BindTo(Room.Beatmap);
maxParticipantsBind.BindTo(Room.MaxParticipants);
participantsBind.BindTo(Room.Participants);
@ -196,19 +198,9 @@ namespace osu.Game.Screens.Multiplayer
{
Size = new Vector2(ruleset_height),
},
new Container //todo: game type icon
gameTypeContainer = new Container
{
Size = new Vector2(ruleset_height),
CornerRadius = 15f,
Masking = true,
Children = new[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"545454"),
},
},
},
new Container
{
@ -384,9 +376,11 @@ namespace osu.Game.Screens.Multiplayer
//binded here instead of ctor because dependencies are needed
statusBind.ValueChanged += displayStatus;
typeBind.ValueChanged += displayGameType;
beatmapBind.ValueChanged += displayBeatmap;
statusBind.TriggerChange();
typeBind.TriggerChange();
beatmapBind.TriggerChange();
}
@ -417,6 +411,17 @@ namespace osu.Game.Screens.Multiplayer
d.FadeColour(value.GetAppropriateColour(colours), transition_duration);
}
private void displayGameType(GameType value)
{
gameTypeContainer.Children = new[]
{
new DrawableGameType(value)
{
Size = new Vector2(ruleset_height),
},
};
}
private void displayBeatmap(BeatmapInfo value)
{
if (value != null)

View File

@ -453,6 +453,8 @@
<Compile Include="Database\RankStatus.cs" />
<Compile Include="Graphics\UserInterface\BreadcrumbControl.cs" />
<Compile Include="Screens\Multiplayer\RoomInspector.cs" />
<Compile Include="Online\Multiplayer\GameType.cs" />
<Compile Include="Screens\Multiplayer\DrawableGameType.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\osu-framework\osu.Framework\osu.Framework.csproj">