Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some more context menus; remove global ContextMenuContainer #1265

Merged
merged 6 commits into from Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion osu-framework
3 changes: 1 addition & 2 deletions osu.Game/OsuGameBase.cs
Expand Up @@ -200,10 +200,9 @@ protected override void LoadComplete()
globalBinding = new GlobalKeyBindingInputManager(this)
{
RelativeSizeAxes = Axes.Both,
Child = new OsuTooltipContainer(Cursor)
Child = content = new OsuTooltipContainer(Cursor)
{
RelativeSizeAxes = Axes.Both,
Child = content = new OsuContextMenuContainer { RelativeSizeAxes = Axes.Both },
}
}
}
Expand Down
33 changes: 26 additions & 7 deletions osu.Game/Overlays/Chat/ChatLine.cs
@@ -1,7 +1,6 @@
// 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;
Expand All @@ -13,6 +12,9 @@
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
using osu.Game.Users;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;

namespace osu.Game.Overlays.Chat
{
Expand Down Expand Up @@ -63,8 +65,6 @@ public class ChatLine : Container
private const float message_padding = 200;
private const float text_size = 20;

private Action<User> loadProfile;

private Color4 customUsernameColour;

private OsuSpriteText timestamp;
Expand Down Expand Up @@ -100,10 +100,9 @@ public Message Message
}

[BackgroundDependencyLoader(true)]
private void load(OsuColour colours, UserProfileOverlay profile)
private void load(OsuColour colours)
{
customUsernameColour = colours.ChatBlue;
loadProfile = u => profile?.ShowUser(u);
}

private bool senderHasBackground => !string.IsNullOrEmpty(message.Sender.Colour);
Expand Down Expand Up @@ -171,13 +170,12 @@ protected override void LoadComplete()
FixedWidth = true,
TextSize = text_size * 0.75f,
},
new ClickableContainer
new MessageSender(message.Sender)
{
AutoSizeAxes = Axes.Both,
Origin = Anchor.TopRight,
Anchor = Anchor.TopRight,
Child = effectedUsername,
Action = () => loadProfile(message.Sender),
},
}
},
Expand Down Expand Up @@ -210,5 +208,26 @@ private void updateMessageContent()
username.Text = $@"{message.Sender.Username}" + (senderHasBackground ? "" : ":");
contentFlow.Text = message.Content;
}

private class MessageSender : ClickableContainer, IHasContextMenu
{
private readonly User sender;

public MessageSender(User sender)
{
this.sender = sender;
}

[BackgroundDependencyLoader(true)]
private void load(UserProfileOverlay profile)
{
Action = () => profile?.ShowUser(sender);
}

public MenuItem[] ContextMenuItems => new MenuItem[]
{
new OsuMenuItem("View Profile", MenuItemType.Highlighted, Action),
};
}
}
}
34 changes: 20 additions & 14 deletions osu.Game/Overlays/Chat/DrawableChannel.cs
Expand Up @@ -10,23 +10,13 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
using osu.Game.Online.Chat;

namespace osu.Game.Overlays.Chat
{
public class DrawableChannel : Container
{
private class ChatLineContainer : FillFlowContainer<ChatLine>
{
protected override int Compare(Drawable x, Drawable y)
{
var xC = (ChatLine)x;
var yC = (ChatLine)y;

return xC.Message.CompareTo(yC.Message);
}
}

public readonly Channel Channel;
private readonly ChatLineContainer flow;
private readonly ScrollContainer scroll;
Expand All @@ -45,12 +35,17 @@ public DrawableChannel(Channel channel)
// Some chat lines have effects that slightly protrude to the bottom,
// which we do not want to mask away, hence the padding.
Padding = new MarginPadding { Bottom = 5 },
Child = flow = new ChatLineContainer
Child = new OsuContextMenuContainer
{
Padding = new MarginPadding { Left = 20, Right = 20 },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Child = flow = new ChatLineContainer
{
Padding = new MarginPadding { Left = 20, Right = 20 },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
}
},
}
};
Expand Down Expand Up @@ -124,5 +119,16 @@ private void messageRemoved(Message removed)
}

private void scrollToEnd() => ScheduleAfterChildren(() => scroll.ScrollToEnd());

private class ChatLineContainer : FillFlowContainer<ChatLine>
{
protected override int Compare(Drawable x, Drawable y)
{
var xC = (ChatLine)x;
var yC = (ChatLine)y;

return xC.Message.CompareTo(yC.Message);
}
}
}
}
4 changes: 2 additions & 2 deletions osu.Game/Overlays/LoginOverlay.cs
Expand Up @@ -3,12 +3,12 @@

using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Overlays.Settings.Sections.General;
using OpenTK.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;

namespace osu.Game.Overlays
{
Expand All @@ -34,7 +34,7 @@ private void load(OsuColour colours)
Colour = Color4.Black,
Alpha = 0.6f,
},
new Container
new OsuContextMenuContainer
{
Width = 360,
AutoSizeAxes = Axes.Y,
Expand Down
4 changes: 0 additions & 4 deletions osu.Game/Overlays/Settings/Sections/General/LoginSettings.cs
Expand Up @@ -366,10 +366,6 @@ private void load(OsuColour colours)
BackgroundColour = colours.Gray3;
}
}




}

private enum UserAction
Expand Down
12 changes: 9 additions & 3 deletions osu.Game/Overlays/SocialOverlay.cs
Expand Up @@ -9,6 +9,7 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
Expand Down Expand Up @@ -63,12 +64,17 @@ public SocialOverlay()

ScrollFlow.Children = new[]
{
panelFlow = new FillFlowContainer<UserPanel>
new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Top = 20 },
Spacing = new Vector2(10f),
Child = panelFlow = new FillFlowContainer<UserPanel>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Margin = new MarginPadding { Top = 20 },
Spacing = new Vector2(10f),
}
},
};

Expand Down
8 changes: 7 additions & 1 deletion osu.Game/Screens/Select/BeatmapCarousel.cs
Expand Up @@ -19,6 +19,7 @@
using osu.Framework.Configuration;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;

namespace osu.Game.Screens.Select
{
Expand Down Expand Up @@ -86,9 +87,14 @@ public IEnumerable<BeatmapSetInfo> Beatmaps

public BeatmapCarousel()
{
Add(scrollableContent = new Container<Panel>
Add(new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = scrollableContent = new Container<Panel>
{
RelativeSizeAxes = Axes.X,
}
});
}

Expand Down
14 changes: 12 additions & 2 deletions osu.Game/Users/UserPanel.cs
Expand Up @@ -13,10 +13,13 @@
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics.UserInterface;
using osu.Framework.Graphics.Cursor;

namespace osu.Game.Users
{
public class UserPanel : ClickableContainer
public class UserPanel : ClickableContainer, IHasContextMenu
{
private readonly User user;
private const float height = 100;
Expand All @@ -31,6 +34,8 @@ public class UserPanel : ClickableContainer

public new Action Action;

protected Action ViewProfile;

public UserPanel(User user)
{
this.user = user;
Expand Down Expand Up @@ -171,7 +176,7 @@ private void load(OsuColour colours, UserProfileOverlay profile)
Status.ValueChanged += displayStatus;
Status.ValueChanged += status => statusBg.FadeColour(status?.GetAppropriateColour(colours) ?? colours.Gray5, 500, Easing.OutQuint);

base.Action = () =>
base.Action = ViewProfile = () =>
{
Action?.Invoke();
profile?.ShowUser(user);
Expand Down Expand Up @@ -203,5 +208,10 @@ private void displayStatus(UserStatus status)
statusMessage.Text = status.Message;
}
}

public MenuItem[] ContextMenuItems => new MenuItem[]
{
new OsuMenuItem("View Profile", MenuItemType.Highlighted, ViewProfile),
};
}
}