1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 12:22:57 +08:00

Basic channel joining (ignore layout in ChatOverlay, temporary)

This commit is contained in:
DrabWeb 2017-05-20 21:26:39 -03:00
parent 4a166c1949
commit a60d1efc21
5 changed files with 63 additions and 13 deletions

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using osu.Framework.Configuration;
using osu.Framework.Lists;
namespace osu.Game.Online.Chat
@ -23,7 +24,7 @@ namespace osu.Game.Online.Chat
[JsonProperty(@"channel_id")]
public int Id;
public bool Joined;
public Bindable<bool> Joined = new Bindable<bool>();
public readonly SortedList<Message> Messages = new SortedList<Message>((m1, m2) => m1.Id.CompareTo(m2.Id));

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
@ -36,6 +37,8 @@ namespace osu.Game.Overlays.Chat
}
}
public Action<Channel> OnRequestJoin;
private Channel channel;
public Channel Channel
{
@ -43,11 +46,13 @@ namespace osu.Game.Overlays.Chat
set
{
if (value == channel) return;
if (channel != null) channel.Joined.ValueChanged -= updateColour;
channel = value;
name.Text = Channel.ToString();
topic.Text = Channel.Topic;
updateColour();
channel.Joined.ValueChanged += updateColour;
updateColour(Channel.Joined);
}
}
@ -56,6 +61,8 @@ namespace osu.Game.Overlays.Chat
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Action = () => { if (!Channel.Joined) OnRequestJoin?.Invoke(Channel); };
Children = new Drawable[]
{
new FillFlowContainer
@ -141,15 +148,21 @@ namespace osu.Game.Overlays.Chat
topicColour = colours.Gray9;
joinedColour = colours.Blue;
updateColour();
updateColour(Channel.Joined);
}
private void updateColour()
protected override void Dispose(bool isDisposing)
{
joinedCheckmark.FadeTo(Channel.Joined ? 1f : 0f, transition_duration);
topic.FadeTo(Channel.Joined ? 0.8f : 1f, transition_duration);
topic.FadeColour(Channel.Joined ? Color4.White : topicColour ?? Color4.White, transition_duration);
FadeColour(Channel.Joined ? joinedColour ?? Color4.White : Color4.White, transition_duration);
if(channel != null) channel.Joined.ValueChanged -= updateColour;
base.Dispose(isDisposing);
}
private void updateColour(bool joined)
{
joinedCheckmark.FadeTo(joined ? 1f : 0f, transition_duration);
topic.FadeTo(joined ? 0.8f : 1f, transition_duration);
topic.FadeColour(joined ? Color4.White : topicColour ?? Color4.White, transition_duration);
FadeColour(joined ? joinedColour ?? Color4.White : Color4.White, transition_duration);
}
}
}

View File

@ -13,14 +13,15 @@ namespace osu.Game.Overlays.Chat
{
public class ChannelSection : Container, IHasFilterableChildren
{
private readonly FillFlowContainer<ChannelListItem> items;
private readonly OsuSpriteText header;
public IEnumerable<IFilterable> FilterableChildren => items.Children.OfType<IFilterable>();
public readonly FillFlowContainer<ChannelListItem> ChannelFlow;
public IEnumerable<IFilterable> FilterableChildren => ChannelFlow.Children.OfType<ChannelListItem>();
public string[] FilterTerms => new[] { Header };
public bool MatchingCurrentFilter
{
set
set
{
FadeTo(value ? 1f : 0f, 100);
}
@ -34,9 +35,10 @@ namespace osu.Game.Overlays.Chat
public IEnumerable<Channel> Channels
{
set { items.Children = value.Select(c => new ChannelListItem { Channel = c }); }
set { ChannelFlow.Children = value.Select(c => new ChannelListItem { Channel = c }); }
}
public ChannelSection()
{
RelativeSizeAxes = Axes.X;
@ -49,7 +51,7 @@ namespace osu.Game.Overlays.Chat
TextSize = 15,
Font = @"Exo2.0-Bold",
},
items = new FillFlowContainer<ChannelListItem>
ChannelFlow = new FillFlowContainer<ChannelListItem>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using OpenTK;
using OpenTK.Graphics;
@ -16,6 +17,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Chat;
namespace osu.Game.Overlays.Chat
{
@ -29,11 +31,21 @@ namespace osu.Game.Overlays.Chat
private readonly SearchTextBox search;
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); };
}
}
}
}

View File

@ -53,6 +53,10 @@ namespace osu.Game.Overlays
private Bindable<double> chatHeight;
private readonly ChannelSelectionOverlay channelSelection;
protected override bool InternalContains(Vector2 screenSpacePos) => base.InternalContains(screenSpacePos) || channelSelection.Contains(screenSpacePos);
public ChatOverlay()
{
RelativeSizeAxes = Axes.Both;
@ -65,6 +69,12 @@ namespace osu.Game.Overlays
Children = new Drawable[]
{
channelSelection = new ChannelSelectionOverlay
{
Origin = Anchor.BottomLeft,
Height = 400,
State = Visibility.Visible,
},
new Container
{
Name = @"chat area",
@ -233,6 +243,16 @@ namespace osu.Game.Overlays
addChannel(channels.Find(c => c.Name == @"#lazer"));
addChannel(channels.Find(c => c.Name == @"#osu"));
addChannel(channels.Find(c => c.Name == @"#lobby"));
channelSelection.OnRequestJoin = channel => addChannel(channel);
channelSelection.Sections = new[]
{
new ChannelSection
{
Header = @"ALL CHANNELS",
Channels = channels,
},
};
});
messageRequest = Scheduler.AddDelayed(fetchNewMessages, 1000, true);
@ -294,6 +314,8 @@ namespace osu.Game.Overlays
if (CurrentChannel == null)
CurrentChannel = channel;
channel.Joined.Value = true;
}
private void fetchInitialMessages(Channel channel)