osu/osu.Game/Overlays/Chat/ChannelSelectionOverlay.cs

259 lines
9.0 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
2017-05-20 21:06:25 +00:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
2017-05-20 21:06:25 +00:00
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
2017-05-20 21:06:25 +00:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input;
2017-05-20 21:06:25 +00:00
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
2017-05-20 21:06:25 +00:00
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Chat;
2017-05-20 21:06:25 +00:00
namespace osu.Game.Overlays.Chat
{
public class ChannelSelectionOverlay : OverlayContainer
2017-05-20 21:06:25 +00:00
{
public static readonly float WIDTH_PADDING = 170;
private readonly Box bg;
private readonly Triangles triangles;
2017-05-20 21:06:25 +00:00
private readonly Box headerBg;
private readonly SearchTextBox search;
2017-05-20 23:22:55 +00:00
private readonly SearchContainer<ChannelSection> sectionsFlow;
public Action<Channel> OnRequestJoin;
public IEnumerable<ChannelSection> Sections
{
set
{
sectionsFlow.Children = value;
foreach (ChannelSection s in sectionsFlow.Children)
{
foreach (ChannelListItem c in s.ChannelFlow.Children)
{
c.OnRequestJoin = channel => { OnRequestJoin?.Invoke(channel); };
}
}
}
}
2017-05-20 21:06:25 +00:00
public ChannelSelectionOverlay()
{
RelativeSizeAxes = Axes.X;
2017-05-20 23:05:28 +00:00
2017-05-20 21:06:25 +00:00
Children = new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Children = new Drawable[]
2017-05-20 21:06:25 +00:00
{
bg = new Box
{
RelativeSizeAxes = Axes.Both,
},
triangles = new Triangles
{
RelativeSizeAxes = Axes.Both,
TriangleScale = 5,
},
},
},
new ScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollDraggerVisible = false,
Padding = new MarginPadding { Top = 85 },
Children = new[]
{
2017-05-20 23:22:55 +00:00
sectionsFlow = new SearchContainer<ChannelSection>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
2017-05-20 23:22:55 +00:00
LayoutDuration = 200,
LayoutEasing = EasingTypes.OutQuint,
Spacing = new Vector2(0f, 20f),
Padding = new MarginPadding { Top = 20, Bottom = 20, Left = WIDTH_PADDING, Right = WIDTH_PADDING },
},
2017-05-20 21:06:25 +00:00
},
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
headerBg = new Box
{
RelativeSizeAxes = Axes.Both,
},
new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0f, 10f),
Padding = new MarginPadding { Top = 10f, Bottom = 10f, Left = WIDTH_PADDING, Right = WIDTH_PADDING },
Children = new Drawable[]
{
new OsuSpriteText
{
Text = @"Chat Channels",
TextSize = 20,
Shadow = false,
2017-05-20 21:06:25 +00:00
},
search = new HeaderSearchTextBox
{
RelativeSizeAxes = Axes.X,
PlaceholderText = @"Search",
Exit = Hide,
2017-05-20 21:06:25 +00:00
},
},
},
},
},
new SettingsButton
2017-05-20 21:06:25 +00:00
{
Margin = new MarginPadding { Top = 160 },
2017-05-20 21:06:25 +00:00
},
};
2017-05-20 23:22:55 +00:00
search.Current.ValueChanged += newValue => sectionsFlow.SearchTerm = newValue;
2017-05-20 21:06:25 +00:00
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
bg.Colour = colours.Gray3;
triangles.ColourDark = colours.Gray3;
triangles.ColourLight = OsuColour.FromHex(@"353535");
2017-05-20 21:06:25 +00:00
headerBg.Colour = colours.Gray2.Opacity(0.75f);
}
protected override void PopIn()
{
search.HoldFocus = true;
Schedule(() => search.TriggerFocus());
2017-05-20 23:05:28 +00:00
FadeIn(100, EasingTypes.OutQuint);
MoveToY(0, 800, EasingTypes.OutQuint);
2017-05-20 21:06:25 +00:00
}
protected override void PopOut()
{
search.HoldFocus = false;
2017-05-20 23:05:28 +00:00
FadeOut(500, EasingTypes.InQuint);
MoveToY(DrawHeight, 500, EasingTypes.In);
2017-05-20 21:06:25 +00:00
}
private class HeaderSearchTextBox : SearchTextBox
{
protected override Color4 BackgroundFocused => Color4.Black.Opacity(0.2f);
protected override Color4 BackgroundUnfocused => Color4.Black.Opacity(0.2f);
}
private class SettingsButton : ClickableContainer
{
private const float width = 60f;
private readonly Box bg;
private readonly Container bgContainer;
private SampleChannel clickSample;
public SettingsButton()
{
Size = new Vector2(width, 50f);
Children = new Drawable[]
{
bgContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Shear = new Vector2(0.2f, 0f),
Masking = true,
MaskingSmoothness = 2,
EdgeEffect = new EdgeEffect
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.2f),
Offset = new Vector2(2, 0),
Radius = 2,
},
Children = new[]
{
bg = new Box
{
RelativeSizeAxes = Axes.Both,
EdgeSmoothness = new Vector2(2f, 0f),
},
},
},
new TextAwesome
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.fa_osu_gear,
TextSize = 20,
Shadow = true,
UseFullGlyphHeight = false,
},
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours, AudioManager audio)
{
bg.Colour = colours.Pink;
clickSample = audio.Sample.Get(@"Menu/menuclick");
}
protected override bool OnHover(InputState state)
{
ResizeWidthTo(width + 20f, 500, EasingTypes.OutElastic);
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
ResizeWidthTo(width, 500, EasingTypes.OutElastic);
}
protected override bool OnClick(InputState state)
{
var flash = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.White.Opacity(0.5f),
};
bgContainer.Add(flash);
flash.Alpha = 1;
flash.FadeOut(500, EasingTypes.OutQuint);
flash.Expire();
clickSample.Play();
return base.OnClick(state);
}
}
2017-05-20 21:06:25 +00:00
}
}