Updates to latest osu-framework, Updates existing Load() methods to use Children = new Drawable[]{} syntax

This commit is contained in:
Remie Richards
2016-09-17 21:33:46 +01:00
parent b52c3074ef
commit 1a5c2b5221
6 changed files with 260 additions and 260 deletions

View File

@ -27,88 +27,80 @@ namespace osu.Game.GameModes
public override void Load() public override void Load()
{ {
base.Load(); base.Load();
OsuGame game = Game as OsuGame; OsuGame game = Game as OsuGame;
Add(new Box() ClickableBox button;
Add(new Drawable[]
{
new Box()
{ {
SizeMode = InheritMode.XY, SizeMode = InheritMode.XY,
Size = new Vector2(1, 1), Size = new Vector2(1, 1),
Colour = Color4.DarkRed Colour = Color4.DarkRed
}); },
button = new ClickableBox(Color4.Pink)
ClickableBox button;
Add(button = new ClickableBox(Color4.Pink)
{ {
Size = new Vector2(50, 50) Size = new Vector2(50, 50)
}); },
container = new AutoSizeContainer()
button.Activated += () => ExitMode();
Add(container = new AutoSizeContainer()
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre Origin = Anchor.Centre,
}); Children = new Drawable[]
{
container.Add(new ClickableBox(Color4.SkyBlue) new ClickableBox(Color4.SkyBlue)
{ {
SizeMode = InheritMode.XY, SizeMode = InheritMode.XY,
Size = Vector2.One Size = Vector2.One
}); },
new ClickableBox(Color4.Orange)
container.Add(new ClickableBox(Color4.Orange)
{ {
Size = new Vector2(50, 50), Size = new Vector2(50, 50),
Anchor = Anchor.TopLeft, Anchor = Anchor.TopLeft,
Origin = Anchor.TopLeft Origin = Anchor.TopLeft
}); },
new ClickableBox(Color4.Orange)
container.Add(new ClickableBox(Color4.Orange)
{ {
Size = new Vector2(50, 50), Size = new Vector2(50, 50),
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,
Origin = Anchor.TopRight Origin = Anchor.TopRight
}); },
new ClickableBox(Color4.Orange)
container.Add(new ClickableBox(Color4.Orange)
{ {
Size = new Vector2(50, 50), Size = new Vector2(50, 50),
Anchor = Anchor.BottomLeft, Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft Origin = Anchor.BottomLeft
}); },
new ClickableBox(Color4.Blue)
container.Add(new ClickableBox(Color4.Blue)
{ {
Size = new Vector2(10, 10), Size = new Vector2(10, 10),
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre Origin = Anchor.Centre
}); },
new ClickableBox(Color4.Orange)
container.Add(new ClickableBox(Color4.Orange)
{ {
Size = new Vector2(50, 50), Size = new Vector2(50, 50),
Anchor = Anchor.BottomRight, Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight Origin = Anchor.BottomRight
}); },
new SpriteCircular(game.Textures.Get("coin"))
container.Add(new SpriteCircular(game.Textures.Get("coin"))
{ {
Position = new Vector2(100), Position = new Vector2(100),
Origin = Anchor.Centre, Anchor = Anchor.Centre,
Anchor = Anchor.Centre Origin = Anchor.Centre
}); },
new SpriteText(game.Textures)
Add(new SpriteText(game.Textures)
{ {
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "12345" Text = "12345"
}
}
}
}); });
button.Activated += () => ExitMode();
} }
class ClickableBox : Box class ClickableBox : Box

View File

@ -25,23 +25,25 @@ namespace osu.Game.GameModes
{ {
base.Load(); base.Load();
flow = new FlowContainer() Drawable[] flowChildren = new Drawable[50];
for (int i = 0; i < 50; i++)
{
int j = i + 1;
flowChildren[i] = new SpriteText()
{
Text = $@"Font testy at size {j}",
Scale = new Vector2(j)
};
}
Add(flow = new FlowContainer()
{ {
Anchor = Anchor.TopLeft, Anchor = Anchor.TopLeft,
Direction = FlowDirection.VerticalOnly Direction = FlowDirection.VerticalOnly,
}; Children = flowChildren,
Add(flow); });
for (int i = 1; i < 50; i++)
{
SpriteText text = new SpriteText()
{
Text = $@"Font testy at size {i}",
Scale = new Vector2(i)
};
flow.Add(text);
}
} }
protected override void Update() protected override void Update()

View File

@ -50,42 +50,47 @@ namespace osu.Game.GameModes.Menu
{ {
base.Load(); base.Load();
Add(new Drawable[]
{
osuLogo = new OsuLogo(onOsuLogo) osuLogo = new OsuLogo(onOsuLogo)
{ {
Origin = Anchor.Centre, Origin = Anchor.Centre,
Anchor = Anchor.Centre, Anchor = Anchor.Centre
}; },
buttonArea = new Container()
Add(buttonArea = new Container()
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
SizeMode = InheritMode.X, SizeMode = InheritMode.X,
Size = new Vector2(1, button_area_height), Size = new Vector2(1, button_area_height),
Alpha = 0 Alpha = 0,
}); Children = new Drawable[]
{
Add(osuLogo); new Box()
buttonArea.Add(new Box()
{ {
SizeMode = InheritMode.XY, SizeMode = InheritMode.XY,
Colour = new Color4(50, 50, 50, 255) Colour = new Color4(50, 50, 50, 255)
}); },
buttonFlow = new FlowContainerWithOrigin()
buttonArea.Add(buttonFlow = new FlowContainerWithOrigin()
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Position = new Vector2(wedge_width * 2 - (button_width + osuLogo.SizeForFlow / 4), 0), Position = new Vector2(wedge_width * 2 - (button_width + osuLogo.SizeForFlow / 4), 0),
Padding = new Vector2(-wedge_width, 0) 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),
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.
{
Size = new Vector2(0, button_area_height)
}
},
CentreTarget = iconFacade
}
}
}
}); });
buttonFlow.Add(settingsButton = new Button(@"settings", @"options", FontAwesome.gear, new Color4(85, 85, 85, 255), onSettings, -wedge_width, Key.O));
buttonFlow.Add(backButton = new Button(@"back", @"back", FontAwesome.fa_osu_left_o, new Color4(51, 58, 94, 255), onBack, -wedge_width, Key.Escape));
//need a container to make the osu! icon flow properly.
buttonFlow.Add(iconFacade = new Container() { Size = new Vector2(0, button_area_height) });
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(@"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(@"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(@"chart", @"charts", FontAwesome.fa_osu_charts, new Color4(80, 53, 160, 255), onChart)));
@ -285,37 +290,35 @@ namespace osu.Game.GameModes.Menu
{ {
base.Load(); base.Load();
Add(logoBounceContainer = new AutoSizeContainer());
logo = new Sprite(Game.Textures.Get(@"menu-osu"))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
};
logoBounceContainer.Add(logo);
Sprite ripple = new Sprite(Game.Textures.Get(@"menu-osu")) Sprite ripple = new Sprite(Game.Textures.Get(@"menu-osu"))
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Alpha = 0.4f Alpha = 0.4f
}; };
logoBounceContainer.Add(ripple);
ripple.ScaleTo(1.1f, 500); ripple.ScaleTo(1.1f, 500);
ripple.FadeOut(500); ripple.FadeOut(500);
ripple.Loop(300); ripple.Loop(300);
logoBounceContainer.Add(vis = new MenuVisualisation() Add(logoBounceContainer = new AutoSizeContainer()
{
Children = new Drawable[]
{
logo = new Sprite(Game.Textures.Get(@"menu-osu"))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
},
ripple,
vis = new MenuVisualisation()
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = logo.Size, Size = logo.Size,
Additive = true, Additive = true,
//Radius = logo.Size.X / 2 * 0.96f,
Alpha = 0.2f, Alpha = 0.2f,
}
}
}); });
} }
@ -419,40 +422,34 @@ namespace osu.Game.GameModes.Menu
base.Load(); base.Load();
Alpha = 0; Alpha = 0;
Add(box = new WedgedBox(new Vector2(button_width + Math.Abs(extraWidth), button_area_height), wedge_width) Add(new Drawable[]
{
box = new WedgedBox(new Vector2(button_width + Math.Abs(extraWidth), button_area_height), wedge_width)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Colour = colour, Colour = colour,
Scale = new Vector2(0, 1) Scale = new Vector2(0, 2)
}); },
iconText = new AutoSizeContainer()
iconText = new AutoSizeContainer
{ {
Position = new Vector2(extraWidth / 2, 0), Position = new Vector2(extraWidth / 2, 0),
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
}; Children = new Drawable[]
Add(iconText);
icon = new TextAwesome(symbol, 40, Vector2.Zero)
{ {
Anchor = Anchor.Centre, icon = new TextAwesome(symbol, 40, Vector2.Zero),
Origin = Anchor.Centre, new SpriteText()
Scale = new Vector2(0.7f),
};
iconText.Add(icon);
SpriteText ft = new SpriteText()
{ {
Direction = FlowDirection.HorizontalOnly, Direction = FlowDirection.HorizontalOnly,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Position = new Vector2(0, 25), Position = new Vector2(0, 25),
Text = text Text = text
}; }
iconText.Add(ft); }
}
});
} }
protected override bool OnHover(InputState state) protected override bool OnHover(InputState state)

View File

@ -5,6 +5,7 @@ using OpenTK;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.GameModes; using osu.Framework.GameModes;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -21,22 +22,22 @@ namespace osu.Game.GameModes.Menu
base.Load(); base.Load();
AudioSample welcome = Game.Audio.Sample.Get(@"welcome"); AudioSample welcome = Game.Audio.Sample.Get(@"welcome");
//welcome.Play();
Add(new ButtonSystem()); Add(new Drawable[]
{
Add(new TextBox() new ButtonSystem(),
new TextBox()
{ {
Text = @"The quick brown fox jumped over the lazy dog.", Text = @"The quick brown fox jumped over the lazy dog.",
Position = new Vector2(50, 50), Position = new Vector2(50, 50),
Size = new Vector2(300, 20) Size = new Vector2(300, 20)
}); },
new SpriteText()
Add(new SpriteText()
{ {
Text = @"The quick brown fox jumped over the lazy dog.", Text = @"The quick brown fox jumped over the lazy dog.",
Position = new Vector2(50, 80), Position = new Vector2(50, 80),
Size = new Vector2(300, 20) Size = new Vector2(300, 20)
}
}); });
} }
} }

View File

@ -14,6 +14,8 @@ using osu.Framework.Input;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.MathUtils; using osu.Framework.MathUtils;
using osu.Framework.Threading; using osu.Framework.Threading;
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;
namespace osu.Game.Graphics.UserInterface namespace osu.Game.Graphics.UserInterface
{ {
@ -49,32 +51,34 @@ namespace osu.Game.Graphics.UserInterface
public override void Load() public override void Load()
{ {
base.Load(); base.Load();
Add(new Drawable[]
AddProcessing(new MaskingContainer()); {
new MaskingContainer(),
Add(background = new Box() background = new Box()
{ {
Colour = BackgroundUnfocused, Colour = BackgroundUnfocused,
SizeMode = InheritMode.XY, SizeMode = InheritMode.XY
}); },
TextContainer = new Container()
Add(TextContainer = new Container() { SizeMode = InheritMode.XY }); {
SizeMode = InheritMode.XY,
textFlow = new FlowContainer() Children = new Drawable[]
{ {
Direction = FlowDirection.HorizontalOnly,
};
cursor = new Box() cursor = new Box()
{ {
Size = Vector2.One, Size = Vector2.One,
Colour = Color4.Transparent, Colour = Color4.Transparent,
SizeMode = InheritMode.Y, SizeMode = InheritMode.Y,
Alpha = 0 Alpha = 0
}; },
textFlow = new FlowContainer()
{
Direction = FlowDirection.HorizontalOnly
}
}
},
TextContainer.Add(cursor); });
TextContainer.Add(textFlow);
} }
private void resetSelection() private void resetSelection()
@ -169,9 +173,12 @@ namespace osu.Game.Graphics.UserInterface
if (index > 0) if (index > 0)
{ {
if (index < text.Length) if (index < text.Length)
return textFlow.Children[index].Position.X + textFlow.Position.X; return textFlow.Children.ElementAt(index).Position.X + textFlow.Position.X;
else else
return textFlow.Children[index - 1].Position.X + textFlow.Children[index - 1].Size.X + textFlow.Padding.X + textFlow.Position.X; {
var d = textFlow.Children.ElementAt(index - 1);
return d.Position.X + d.Size.X + textFlow.Padding.X + textFlow.Position.X;
}
} }
else else
return 0; return 0;
@ -247,16 +254,16 @@ namespace osu.Game.Graphics.UserInterface
if (sound) if (sound)
Game.Audio.Sample.Get(@"Keyboard/key-delete")?.Play(); Game.Audio.Sample.Get(@"Keyboard/key-delete")?.Play();
for (int i = 0; i < count; i++) textFlow.Children.Skip(start).Take(count).ToList().ForEach(d =>
{ {
Drawable d = textFlow.Children[start];
textFlow.Remove(d); textFlow.Remove(d);
TextContainer.Add(d); TextContainer.Add(d);
d.FadeOut(200); d.FadeOut(200);
d.MoveToY(d.Size.Y, 200, EasingTypes.InExpo); d.MoveToY(d.Size.Y, 200, EasingTypes.InExpo);
d.Expire(); d.Expire();
} });
text = text.Remove(start, count); text = text.Remove(start, count);
if (selectionLength > 0) if (selectionLength > 0)
@ -270,8 +277,9 @@ namespace osu.Game.Graphics.UserInterface
protected virtual Drawable AddCharacterToFlow(char c) protected virtual Drawable AddCharacterToFlow(char c)
{ {
for (int i = selectionLeft; i < text.Length; i++) int i = selectionLeft;
textFlow.Children[i].Depth = i + 1; foreach (Drawable dd in textFlow.Children.Skip(selectionLeft).Take(text.Length - selectionLeft))
dd.Depth = i + 1;
Drawable ch; Drawable ch;