Split off SidebarButton

This commit is contained in:
Drew DeVault 2016-11-12 01:53:20 -05:00
parent d346e49c4f
commit 00cc4278da
4 changed files with 115 additions and 103 deletions

View File

@ -71,106 +71,5 @@ public SidebarScrollContainer()
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);
}
}
}
}

View File

@ -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);
}
}
}

View File

@ -33,7 +33,7 @@ public class OptionsOverlay : OverlayContainer
private ScrollContainer scrollContainer;
private OptionsSidebar sidebar;
private OptionsSidebar.SidebarButton[] sidebarButtons;
private SidebarButton[] sidebarButtons;
private OptionsSection[] sections;
private float lastKnownScroll;
@ -108,7 +108,7 @@ public OptionsOverlay()
{
Width = sidebar_width,
Children = sidebarButtons = sections.Select(section =>
new OptionsSidebar.SidebarButton
new SidebarButton
{
Selected = sections[0] == section,
Section = section,

View File

@ -234,6 +234,7 @@
<Compile Include="Overlays\Options\Online\PrivacyOptions.cs" />
<Compile Include="Overlays\Options\Online\NotificationsOptions.cs" />
<Compile Include="Overlays\Options\CheckBoxOption.cs" />
<Compile Include="Overlays\Options\SidebarButton.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">