From 32196c57af1b0b5a368a90af0d8ff09d1e88cf76 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 9 Nov 2016 00:17:48 -0500 Subject: [PATCH 1/4] Track the visible section in options --- osu.Game/Overlays/Options/OptionsSidebar.cs | 41 +++++++++++++++++---- osu.Game/Overlays/OptionsOverlay.cs | 36 +++++++++++++++--- 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/osu.Game/Overlays/Options/OptionsSidebar.cs b/osu.Game/Overlays/Options/OptionsSidebar.cs index 6f1cb4a48c..111aad5ecd 100644 --- a/osu.Game/Overlays/Options/OptionsSidebar.cs +++ b/osu.Game/Overlays/Options/OptionsSidebar.cs @@ -77,18 +77,36 @@ namespace osu.Game.Overlays.Options private TextAwesome drawableIcon; private SpriteText headerText; private Box backgroundBox; + private Box selectionIndicator; public Action Action; - public FontAwesome Icon + private OptionsSection section; + public OptionsSection Section { - get { return drawableIcon.Icon; } - set { drawableIcon.Icon = value; } + get + { + return section; + } + set + { + section = value; + headerText.Text = value.Header; + drawableIcon.Icon = value.Icon; + } } - - public string Header + + private bool selected; + public bool Selected { - get { return headerText.Text; } - set { headerText.Text = value; } + get { return selected; } + set + { + selected = value; + if (selected) + selectionIndicator.FadeIn(50); + else + selectionIndicator.FadeOut(50); + } } public SidebarButton() @@ -122,6 +140,15 @@ namespace osu.Game.Overlays.Options Position = new Vector2(default_width + 10, 0), Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, + }, + selectionIndicator = new Box + { + Alpha = 0, + RelativeSizeAxes = Axes.Y, + Width = 5, + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + Colour = new Color4(233, 103, 161, 255) } }; } diff --git a/osu.Game/Overlays/OptionsOverlay.cs b/osu.Game/Overlays/OptionsOverlay.cs index 2e00bef970..b72c2293c9 100644 --- a/osu.Game/Overlays/OptionsOverlay.cs +++ b/osu.Game/Overlays/OptionsOverlay.cs @@ -33,10 +33,12 @@ namespace osu.Game.Overlays private ScrollContainer scrollContainer; private OptionsSidebar sidebar; + private OptionsSidebar.SidebarButton[] sidebarButtons; + private OptionsSection[] sections; public OptionsOverlay() { - var sections = new OptionsSection[] + sections = new OptionsSection[] { new GeneralSection(), new GraphicsSection(), @@ -67,6 +69,7 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.Y, Width = width, Margin = new MarginPadding { Left = sidebar_width }, + Scrolled = ScrollContainer_Scrolled, Children = new[] { new FlowContainer @@ -104,14 +107,15 @@ namespace osu.Game.Overlays sidebar = new OptionsSidebar { Width = sidebar_width, - Children = sections.Select(section => + Children = sidebarButtons = sections.Select(section => new OptionsSidebar.SidebarButton { - Icon = section.Icon, - Header = section.Header, - Action = () => scrollContainer.ScrollIntoView(section), + Selected = sections[0] == section, + Section = section, + Action = () => scrollContainer.ScrollTo( + scrollContainer.GetChildY(section) - scrollContainer.DrawSize.Y / 2), } - ) + ).ToArray() } }; } @@ -123,6 +127,26 @@ namespace osu.Game.Overlays scrollContainer.Padding = new MarginPadding { Top = (game as OsuGame)?.Toolbar.DrawHeight ?? 0 }; } + private void ScrollContainer_Scrolled(float value) + { + for (int i = sections.Length - 1; i >= 0; i--) + { + var section = sections[i]; + float y = scrollContainer.GetChildY(section) - value; + if (y <= scrollContainer.DrawSize.Y / 2) + { + var previous = sidebarButtons.SingleOrDefault(sb => sb.Selected); + var next = sidebarButtons.SingleOrDefault(sb => sb.Section == section); + if (next != null) + { + previous.Selected = false; + next.Selected = true; + } + break; + } + } + } + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true; protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) From a8bba445dba9c9c9217d02c22a78e64e20bfbbab Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 10 Nov 2016 18:04:39 -0500 Subject: [PATCH 2/4] Move scroll logic into Update --- osu.Game/Overlays/OptionsOverlay.cs | 30 ++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/osu.Game/Overlays/OptionsOverlay.cs b/osu.Game/Overlays/OptionsOverlay.cs index b72c2293c9..92ca32f7c3 100644 --- a/osu.Game/Overlays/OptionsOverlay.cs +++ b/osu.Game/Overlays/OptionsOverlay.cs @@ -35,6 +35,7 @@ namespace osu.Game.Overlays private OptionsSidebar sidebar; private OptionsSidebar.SidebarButton[] sidebarButtons; private OptionsSection[] sections; + private float lastKnownScroll; public OptionsOverlay() { @@ -69,7 +70,6 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.Y, Width = width, Margin = new MarginPadding { Left = sidebar_width }, - Scrolled = ScrollContainer_Scrolled, Children = new[] { new FlowContainer @@ -113,7 +113,7 @@ namespace osu.Game.Overlays Selected = sections[0] == section, Section = section, Action = () => scrollContainer.ScrollTo( - scrollContainer.GetChildY(section) - scrollContainer.DrawSize.Y / 2), + scrollContainer.GetChildYInContent(section) - scrollContainer.DrawSize.Y / 2), } ).ToArray() } @@ -127,22 +127,26 @@ namespace osu.Game.Overlays scrollContainer.Padding = new MarginPadding { Top = (game as OsuGame)?.Toolbar.DrawHeight ?? 0 }; } - private void ScrollContainer_Scrolled(float value) + protected override void Update() { - for (int i = sections.Length - 1; i >= 0; i--) + base.Update(); + if (scrollContainer.Current != lastKnownScroll) { - var section = sections[i]; - float y = scrollContainer.GetChildY(section) - value; - if (y <= scrollContainer.DrawSize.Y / 2) + for (int i = sections.Length - 1; i >= 0; i--) { - var previous = sidebarButtons.SingleOrDefault(sb => sb.Selected); - var next = sidebarButtons.SingleOrDefault(sb => sb.Section == section); - if (next != null) + var section = sections[i]; + float y = scrollContainer.GetChildYInContent(section) - scrollContainer.Current; + if (y <= scrollContainer.DrawSize.Y / 2 + 25) { - previous.Selected = false; - next.Selected = true; + var previous = sidebarButtons.SingleOrDefault(sb => sb.Selected); + var next = sidebarButtons.SingleOrDefault(sb => sb.Section == section); + if (next != null) + { + previous.Selected = false; + next.Selected = true; + } + break; } - break; } } } From d346e49c4f75d11dba581af3f918d7dc100c0f9a Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 12 Nov 2016 01:43:05 -0500 Subject: [PATCH 3/4] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index ef57b64639..244eaf768e 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit ef57b64639f53326104707d40536de24226dd63f +Subproject commit 244eaf768e744fbd05187b30494f3985e7305a58 From 00cc4278da4cfb1137ffcfaf433b97b608a1a585 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 12 Nov 2016 01:53:20 -0500 Subject: [PATCH 4/4] Split off SidebarButton --- osu.Game/Overlays/Options/OptionsSidebar.cs | 101 ------------------ osu.Game/Overlays/Options/SidebarButton.cs | 112 ++++++++++++++++++++ osu.Game/Overlays/OptionsOverlay.cs | 4 +- osu.Game/osu.Game.csproj | 1 + 4 files changed, 115 insertions(+), 103 deletions(-) create mode 100644 osu.Game/Overlays/Options/SidebarButton.cs diff --git a/osu.Game/Overlays/Options/OptionsSidebar.cs b/osu.Game/Overlays/Options/OptionsSidebar.cs index 111aad5ecd..d4b64a5d60 100644 --- a/osu.Game/Overlays/Options/OptionsSidebar.cs +++ b/osu.Game/Overlays/Options/OptionsSidebar.cs @@ -71,106 +71,5 @@ namespace osu.Game.Overlays.Options Content.Origin = Anchor.CentreLeft; } } - - public class SidebarButton : Container - { - private TextAwesome drawableIcon; - private SpriteText headerText; - private Box backgroundBox; - private Box selectionIndicator; - public Action Action; - - private OptionsSection section; - public OptionsSection Section - { - get - { - return section; - } - set - { - section = value; - headerText.Text = value.Header; - drawableIcon.Icon = value.Icon; - } - } - - private bool selected; - public bool Selected - { - get { return selected; } - set - { - selected = value; - if (selected) - selectionIndicator.FadeIn(50); - else - selectionIndicator.FadeOut(50); - } - } - - public SidebarButton() - { - Height = default_width; - RelativeSizeAxes = Axes.X; - Children = new Drawable[] - { - backgroundBox = new Box - { - RelativeSizeAxes = Axes.Both, - BlendingMode = BlendingMode.Additive, - Colour = new Color4(60, 60, 60, 255), - Alpha = 0, - }, - new Container - { - Width = default_width, - RelativeSizeAxes = Axes.Y, - Children = new[] - { - drawableIcon = new TextAwesome - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - }, - } - }, - headerText = new SpriteText - { - Position = new Vector2(default_width + 10, 0), - Anchor = Anchor.CentreLeft, - Origin = Anchor.CentreLeft, - }, - selectionIndicator = new Box - { - Alpha = 0, - RelativeSizeAxes = Axes.Y, - Width = 5, - Anchor = Anchor.CentreRight, - Origin = Anchor.CentreRight, - Colour = new Color4(233, 103, 161, 255) - } - }; - } - - protected override bool OnClick(InputState state) - { - Action?.Invoke(); - backgroundBox.FlashColour(Color4.White, 400); - return true; - } - - protected override bool OnHover(InputState state) - { - backgroundBox.FadeTo(0.4f, 200); - return base.OnHover(state); - } - - protected override void OnHoverLost(InputState state) - { - backgroundBox.FadeTo(0, 200); - base.OnHoverLost(state); - } - } } } \ No newline at end of file diff --git a/osu.Game/Overlays/Options/SidebarButton.cs b/osu.Game/Overlays/Options/SidebarButton.cs new file mode 100644 index 0000000000..5174ecfa27 --- /dev/null +++ b/osu.Game/Overlays/Options/SidebarButton.cs @@ -0,0 +1,112 @@ +using System; +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Input; +using osu.Game.Graphics; + +namespace osu.Game.Overlays.Options +{ + public class SidebarButton : Container + { + private TextAwesome drawableIcon; + private SpriteText headerText; + private Box backgroundBox; + private Box selectionIndicator; + public Action Action; + + private OptionsSection section; + public OptionsSection Section + { + get + { + return section; + } + set + { + section = value; + headerText.Text = value.Header; + drawableIcon.Icon = value.Icon; + } + } + + private bool selected; + public bool Selected + { + get { return selected; } + set + { + selected = value; + if (selected) + selectionIndicator.FadeIn(50); + else + selectionIndicator.FadeOut(50); + } + } + + public SidebarButton() + { + Height = OptionsSidebar.default_width; + RelativeSizeAxes = Axes.X; + Children = new Drawable[] + { + backgroundBox = new Box + { + RelativeSizeAxes = Axes.Both, + BlendingMode = BlendingMode.Additive, + Colour = new Color4(60, 60, 60, 255), + Alpha = 0, + }, + new Container + { + Width = OptionsSidebar.default_width, + RelativeSizeAxes = Axes.Y, + Children = new[] + { + drawableIcon = new TextAwesome + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }, + } + }, + headerText = new SpriteText + { + Position = new Vector2(OptionsSidebar.default_width + 10, 0), + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + }, + selectionIndicator = new Box + { + Alpha = 0, + RelativeSizeAxes = Axes.Y, + Width = 5, + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + Colour = new Color4(233, 103, 161, 255) + } + }; + } + + protected override bool OnClick(InputState state) + { + Action?.Invoke(); + backgroundBox.FlashColour(Color4.White, 400); + return true; + } + + protected override bool OnHover(InputState state) + { + backgroundBox.FadeTo(0.4f, 200); + return base.OnHover(state); + } + + protected override void OnHoverLost(InputState state) + { + backgroundBox.FadeTo(0, 200); + base.OnHoverLost(state); + } + } +} \ No newline at end of file diff --git a/osu.Game/Overlays/OptionsOverlay.cs b/osu.Game/Overlays/OptionsOverlay.cs index 92ca32f7c3..ae57ea1119 100644 --- a/osu.Game/Overlays/OptionsOverlay.cs +++ b/osu.Game/Overlays/OptionsOverlay.cs @@ -33,7 +33,7 @@ namespace osu.Game.Overlays private ScrollContainer scrollContainer; private OptionsSidebar sidebar; - private OptionsSidebar.SidebarButton[] sidebarButtons; + private SidebarButton[] sidebarButtons; private OptionsSection[] sections; private float lastKnownScroll; @@ -108,7 +108,7 @@ namespace osu.Game.Overlays { Width = sidebar_width, Children = sidebarButtons = sections.Select(section => - new OptionsSidebar.SidebarButton + new SidebarButton { Selected = sections[0] == section, Section = section, diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 4977317f0c..4ca6c84578 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -234,6 +234,7 @@ +