diff --git a/osu-framework b/osu-framework index 0b60779e35..6dcee1dcf5 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 0b60779e350bb5c316a5fb0454989ea831001087 +Subproject commit 6dcee1dcf50f33f87722104f12b990d7cd6d8eef diff --git a/osu.Game/GameModes/FieldTest.cs b/osu.Game/GameModes/FieldTest.cs index 58df93eee3..df7a7cb734 100644 --- a/osu.Game/GameModes/FieldTest.cs +++ b/osu.Game/GameModes/FieldTest.cs @@ -24,92 +24,84 @@ namespace osu.Game.GameModes { private AutoSizeContainer container; - public override void Load() - { - base.Load(); + public override void Load() + { + base.Load(); + OsuGame game = Game as OsuGame; - OsuGame game = Game as OsuGame; + ClickableBox button; + Add(new Drawable[] + { + new Box() + { + SizeMode = InheritMode.XY, + Size = new Vector2(1, 1), + Colour = Color4.DarkRed + }, + button = new ClickableBox(Color4.Pink) + { + Size = new Vector2(50, 50) + }, + container = new AutoSizeContainer() + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Children = new Drawable[] + { + new ClickableBox(Color4.SkyBlue) + { + SizeMode = InheritMode.XY, + Size = Vector2.One + }, + new ClickableBox(Color4.Orange) + { + Size = new Vector2(50, 50), + Anchor = Anchor.TopLeft, + Origin = Anchor.TopLeft + }, + new ClickableBox(Color4.Orange) + { + Size = new Vector2(50, 50), + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight + }, + new ClickableBox(Color4.Orange) + { + Size = new Vector2(50, 50), + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft + }, + new ClickableBox(Color4.Blue) + { + Size = new Vector2(10, 10), + Anchor = Anchor.Centre, + Origin = Anchor.Centre + }, + new ClickableBox(Color4.Orange) + { + Size = new Vector2(50, 50), + Anchor = Anchor.BottomRight, + Origin = Anchor.BottomRight + }, + new SpriteCircular(game.Textures.Get("coin")) + { + Position = new Vector2(100), + Anchor = Anchor.Centre, + Origin = Anchor.Centre + }, + new SpriteText(game.Textures) + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + Text = "12345" + } + } + } + }); - Add(new Box() - { - SizeMode = InheritMode.XY, + button.Activated += () => ExitMode(); - Size = new Vector2(1, 1), - Colour = Color4.DarkRed - }); - - ClickableBox button; - Add(button = new ClickableBox(Color4.Pink) - { - Size = new Vector2(50, 50) - }); - - button.Activated += () => ExitMode(); - - Add(container = new AutoSizeContainer() - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre - }); - - container.Add(new ClickableBox(Color4.SkyBlue) - { - SizeMode = InheritMode.XY, - - Size = Vector2.One - }); - - container.Add(new ClickableBox(Color4.Orange) - { - Size = new Vector2(50, 50), - Anchor = Anchor.TopLeft, - Origin = Anchor.TopLeft - }); - - container.Add(new ClickableBox(Color4.Orange) - { - Size = new Vector2(50, 50), - Anchor = Anchor.TopRight, - Origin = Anchor.TopRight - }); - - container.Add(new ClickableBox(Color4.Orange) - { - Size = new Vector2(50, 50), - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft - }); - - - container.Add(new ClickableBox(Color4.Blue) - { - Size = new Vector2(10, 10), - Anchor = Anchor.Centre, - Origin = Anchor.Centre - }); - - container.Add(new ClickableBox(Color4.Orange) - { - Size = new Vector2(50, 50), - Anchor = Anchor.BottomRight, - Origin = Anchor.BottomRight - }); - - container.Add(new SpriteCircular(game.Textures.Get("coin")) - { - Position = new Vector2(100), - Origin = Anchor.Centre, - Anchor = Anchor.Centre - }); - - Add(new SpriteText(game.Textures) - { - Origin = Anchor.CentreLeft, - Anchor = Anchor.CentreLeft, - - Text = "12345" - }); - } + } class ClickableBox : Box { diff --git a/osu.Game/GameModes/FontTest.cs b/osu.Game/GameModes/FontTest.cs index a24acd73c8..a74a8792db 100644 --- a/osu.Game/GameModes/FontTest.cs +++ b/osu.Game/GameModes/FontTest.cs @@ -21,28 +21,30 @@ namespace osu.Game.GameModes { private FlowContainer flow; - public override void Load() - { - base.Load(); + public override void Load() + { + base.Load(); - flow = new FlowContainer() - { - Anchor = Anchor.TopLeft, - Direction = FlowDirection.VerticalOnly - }; - Add(flow); + 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) + }; + } - for (int i = 1; i < 50; i++) - { - SpriteText text = new SpriteText() - { - Text = $@"Font testy at size {i}", - Scale = new Vector2(i) - }; + Add(flow = new FlowContainer() + { + Anchor = Anchor.TopLeft, + Direction = FlowDirection.VerticalOnly, + Children = flowChildren, + }); - flow.Add(text); - } - } + + } protected override void Update() { diff --git a/osu.Game/GameModes/Menu/ButtonSystem.cs b/osu.Game/GameModes/Menu/ButtonSystem.cs index acee3e35b8..eff4d9eb4b 100644 --- a/osu.Game/GameModes/Menu/ButtonSystem.cs +++ b/osu.Game/GameModes/Menu/ButtonSystem.cs @@ -50,42 +50,47 @@ namespace osu.Game.GameModes.Menu { base.Load(); - osuLogo = new OsuLogo(onOsuLogo) + Add(new Drawable[] { - Origin = Anchor.Centre, - Anchor = Anchor.Centre, - }; - - Add(buttonArea = new Container() - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - SizeMode = InheritMode.X, - Size = new Vector2(1, button_area_height), - Alpha = 0 + osuLogo = new OsuLogo(onOsuLogo) + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre + }, + buttonArea = new Container() + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + SizeMode = InheritMode.X, + Size = new Vector2(1, button_area_height), + Alpha = 0, + Children = new Drawable[] + { + new Box() + { + SizeMode = InheritMode.XY, + Colour = new Color4(50, 50, 50, 255) + }, + buttonFlow = new FlowContainerWithOrigin() + { + Anchor = Anchor.Centre, + Position = new Vector2(wedge_width * 2 - (button_width + osuLogo.SizeForFlow / 4), 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 + } + } + } }); - Add(osuLogo); - - buttonArea.Add(new Box() - { - SizeMode = InheritMode.XY, - Colour = new Color4(50, 50, 50, 255) - }); - - buttonArea.Add(buttonFlow = new FlowContainerWithOrigin() - { - Anchor = Anchor.Centre, - Position = new Vector2(wedge_width * 2 - (button_width + osuLogo.SizeForFlow / 4), 0), - Padding = new Vector2(-wedge_width, 0) - }); - - 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(@"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))); @@ -285,37 +290,35 @@ namespace osu.Game.GameModes.Menu { 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")) { Anchor = Anchor.Centre, Origin = Anchor.Centre, Alpha = 0.4f }; - - logoBounceContainer.Add(ripple); - ripple.ScaleTo(1.1f, 500); ripple.FadeOut(500); ripple.Loop(300); - logoBounceContainer.Add(vis = new MenuVisualisation() + Add(logoBounceContainer = new AutoSizeContainer() { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = logo.Size, - Additive = true, - //Radius = logo.Size.X / 2 * 0.96f, - Alpha = 0.2f, + Children = new Drawable[] + { + logo = new Sprite(Game.Textures.Get(@"menu-osu")) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre + }, + ripple, + vis = new MenuVisualisation() + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = logo.Size, + Additive = true, + Alpha = 0.2f, + } + } }); } @@ -414,46 +417,40 @@ namespace osu.Game.GameModes.Menu this.text = text; } - public override void Load() - { - base.Load(); - Alpha = 0; + public override void Load() + { + base.Load(); + Alpha = 0; - Add(box = new WedgedBox(new Vector2(button_width + Math.Abs(extraWidth), button_area_height), wedge_width) - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Colour = colour, - Scale = new Vector2(0, 1) - }); - - iconText = new AutoSizeContainer - { - Position = new Vector2(extraWidth / 2, 0), - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - }; - - Add(iconText); - - icon = new TextAwesome(symbol, 40, Vector2.Zero) - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Scale = new Vector2(0.7f), - }; - iconText.Add(icon); - - SpriteText ft = new SpriteText() - { - Direction = FlowDirection.HorizontalOnly, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Position = new Vector2(0, 25), - Text = text - }; - iconText.Add(ft); - } + Add(new Drawable[] + { + box = new WedgedBox(new Vector2(button_width + Math.Abs(extraWidth), button_area_height), wedge_width) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Colour = colour, + Scale = new Vector2(0, 2) + }, + iconText = new AutoSizeContainer() + { + Position = new Vector2(extraWidth / 2, 0), + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Children = new Drawable[] + { + icon = new TextAwesome(symbol, 40, Vector2.Zero), + new SpriteText() + { + Direction = FlowDirection.HorizontalOnly, + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Position = new Vector2(0, 25), + Text = text + } + } + } + }); + } protected override bool OnHover(InputState state) { diff --git a/osu.Game/GameModes/Menu/MainMenu.cs b/osu.Game/GameModes/Menu/MainMenu.cs index e9bb8c5c5c..dbe4db8bff 100644 --- a/osu.Game/GameModes/Menu/MainMenu.cs +++ b/osu.Game/GameModes/Menu/MainMenu.cs @@ -5,6 +5,7 @@ using OpenTK; using osu.Framework.Audio.Sample; using osu.Framework.Audio.Track; using osu.Framework.GameModes; +using osu.Framework.Graphics; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics.UserInterface; @@ -16,28 +17,28 @@ namespace osu.Game.GameModes.Menu private AudioTrackBass bgm; - public override void Load() - { - base.Load(); + public override void Load() + { + base.Load(); - AudioSample welcome = Game.Audio.Sample.Get(@"welcome"); - //welcome.Play(); + AudioSample welcome = Game.Audio.Sample.Get(@"welcome"); - Add(new ButtonSystem()); - - Add(new TextBox() - { - Text = @"The quick brown fox jumped over the lazy dog.", - Position = new Vector2(50,50), - Size = new Vector2(300,20) - }); - - Add(new SpriteText() - { - Text = @"The quick brown fox jumped over the lazy dog.", - Position = new Vector2(50, 80), - Size = new Vector2(300, 20) - }); - } + Add(new Drawable[] + { + new ButtonSystem(), + new TextBox() + { + Text = @"The quick brown fox jumped over the lazy dog.", + Position = new Vector2(50, 50), + Size = new Vector2(300, 20) + }, + new SpriteText() + { + Text = @"The quick brown fox jumped over the lazy dog.", + Position = new Vector2(50, 80), + Size = new Vector2(300, 20) + } + }); + } } } diff --git a/osu.Game/Graphics/UserInterface/TextBox.cs b/osu.Game/Graphics/UserInterface/TextBox.cs index 367cc44e2f..a167741c42 100644 --- a/osu.Game/Graphics/UserInterface/TextBox.cs +++ b/osu.Game/Graphics/UserInterface/TextBox.cs @@ -14,6 +14,8 @@ using osu.Framework.Input; using osu.Framework.Graphics.Sprites; using osu.Framework.MathUtils; using osu.Framework.Threading; +using System.Linq; +using osu.Framework.Extensions.IEnumerableExtensions; namespace osu.Game.Graphics.UserInterface { @@ -46,36 +48,38 @@ namespace osu.Game.Graphics.UserInterface private Scheduler textUpdateScheduler = new Scheduler(); - public override void Load() - { - base.Load(); + public override void Load() + { + base.Load(); + Add(new Drawable[] + { + new MaskingContainer(), + background = new Box() + { + Colour = BackgroundUnfocused, + SizeMode = InheritMode.XY + }, + TextContainer = new Container() + { + SizeMode = InheritMode.XY, + Children = new Drawable[] + { + cursor = new Box() + { + Size = Vector2.One, + Colour = Color4.Transparent, + SizeMode = InheritMode.Y, + Alpha = 0 + }, + textFlow = new FlowContainer() + { + Direction = FlowDirection.HorizontalOnly + } + } + }, - AddProcessing(new MaskingContainer()); - - Add(background = new Box() - { - Colour = BackgroundUnfocused, - SizeMode = InheritMode.XY, - }); - - Add(TextContainer = new Container() { SizeMode = InheritMode.XY }); - - textFlow = new FlowContainer() - { - Direction = FlowDirection.HorizontalOnly, - }; - - cursor = new Box() - { - Size = Vector2.One, - Colour = Color4.Transparent, - SizeMode = InheritMode.Y, - Alpha = 0 - }; - - TextContainer.Add(cursor); - TextContainer.Add(textFlow); - } + }); + } private void resetSelection() { @@ -168,10 +172,13 @@ namespace osu.Game.Graphics.UserInterface { if (index > 0) { - if (index < text.Length) - return textFlow.Children[index].Position.X + textFlow.Position.X; - else - return textFlow.Children[index - 1].Position.X + textFlow.Children[index - 1].Size.X + textFlow.Padding.X + textFlow.Position.X; + if (index < text.Length) + return textFlow.Children.ElementAt(index).Position.X + textFlow.Position.X; + else + { + var d = textFlow.Children.ElementAt(index - 1); + return d.Position.X + d.Size.X + textFlow.Padding.X + textFlow.Position.X; + } } else return 0; @@ -247,16 +254,16 @@ namespace osu.Game.Graphics.UserInterface if (sound) Game.Audio.Sample.Get(@"Keyboard/key-delete")?.Play(); - for (int i = 0; i < count; i++) - { - Drawable d = textFlow.Children[start]; - textFlow.Remove(d); + textFlow.Children.Skip(start).Take(count).ToList().ForEach(d => + { + textFlow.Remove(d); + + TextContainer.Add(d); + d.FadeOut(200); + d.MoveToY(d.Size.Y, 200, EasingTypes.InExpo); + d.Expire(); + }); - TextContainer.Add(d); - d.FadeOut(200); - d.MoveToY(d.Size.Y, 200, EasingTypes.InExpo); - d.Expire(); - } text = text.Remove(start, count); if (selectionLength > 0) @@ -270,8 +277,9 @@ namespace osu.Game.Graphics.UserInterface protected virtual Drawable AddCharacterToFlow(char c) { - for (int i = selectionLeft; i < text.Length; i++) - textFlow.Children[i].Depth = i + 1; + int i = selectionLeft; + foreach (Drawable dd in textFlow.Children.Skip(selectionLeft).Take(text.Length - selectionLeft)) + dd.Depth = i + 1; Drawable ch;