mirror of
https://github.com/ppy/osu.git
synced 2025-03-15 12:37:45 +08:00
Allow PrivateChannelTab to derive from ChannelTab
This commit is contained in:
parent
93e2d8f309
commit
6a668ffe33
@ -20,7 +20,6 @@ namespace osu.Game.Overlays.Chat.Tabs
|
||||
{
|
||||
public class ChannelTabItem : TabItem<Channel>
|
||||
{
|
||||
|
||||
protected Color4 BackgroundInactive;
|
||||
private Color4 backgroundHover;
|
||||
protected Color4 BackgroundActive;
|
||||
@ -29,81 +28,15 @@ namespace osu.Game.Overlays.Chat.Tabs
|
||||
|
||||
protected readonly SpriteText Text;
|
||||
protected readonly SpriteText TextBold;
|
||||
private readonly ClickableContainer closeButton;
|
||||
protected readonly ClickableContainer CloseButton;
|
||||
private readonly Box box;
|
||||
private readonly Box highlightBox;
|
||||
protected readonly SpriteIcon Icon;
|
||||
|
||||
public Action<ChannelTabItem> OnRequestClose;
|
||||
private readonly Container content;
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
if (Active)
|
||||
fadeActive();
|
||||
else
|
||||
fadeInactive();
|
||||
}
|
||||
|
||||
private const float transition_length = 400;
|
||||
|
||||
private void fadeActive()
|
||||
{
|
||||
this.ResizeTo(new Vector2(Width, 1.1f), transition_length, Easing.OutQuint);
|
||||
|
||||
box.FadeColour(BackgroundActive, transition_length, Easing.OutQuint);
|
||||
highlightBox.FadeIn(transition_length, Easing.OutQuint);
|
||||
|
||||
Text.FadeOut(transition_length, Easing.OutQuint);
|
||||
TextBold.FadeIn(transition_length, Easing.OutQuint);
|
||||
}
|
||||
|
||||
private void fadeInactive()
|
||||
{
|
||||
this.ResizeTo(new Vector2(Width, 1), transition_length, Easing.OutQuint);
|
||||
|
||||
box.FadeColour(BackgroundInactive, transition_length, Easing.OutQuint);
|
||||
highlightBox.FadeOut(transition_length, Easing.OutQuint);
|
||||
|
||||
Text.FadeIn(transition_length, Easing.OutQuint);
|
||||
TextBold.FadeOut(transition_length, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected override bool OnHover(InputState state)
|
||||
{
|
||||
if (IsRemovable)
|
||||
closeButton.FadeIn(200, Easing.OutQuint);
|
||||
|
||||
if (!Active)
|
||||
box.FadeColour(backgroundHover, transition_length, Easing.OutQuint);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(InputState state)
|
||||
{
|
||||
closeButton.FadeOut(200, Easing.OutQuint);
|
||||
updateState();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
BackgroundActive = colours.ChatBlue;
|
||||
BackgroundInactive = colours.Gray4;
|
||||
backgroundHover = colours.Gray7;
|
||||
|
||||
highlightBox.Colour = colours.Yellow;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
updateState();
|
||||
}
|
||||
|
||||
protected override void OnActivated() => updateState();
|
||||
|
||||
protected override void OnDeactivated() => updateState();
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
||||
public ChannelTabItem(Channel value)
|
||||
: base(value)
|
||||
@ -118,14 +51,8 @@ namespace osu.Game.Overlays.Chat.Tabs
|
||||
Shear = new Vector2(ChannelTabControl.SHEAR_WIDTH / ChatOverlay.TAB_AREA_HEIGHT, 0);
|
||||
|
||||
Masking = true;
|
||||
EdgeEffect = new EdgeEffectParameters
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Radius = 10,
|
||||
Colour = Color4.Black.Opacity(0.2f),
|
||||
};
|
||||
|
||||
Children = new Drawable[]
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
box = new Box
|
||||
{
|
||||
@ -141,7 +68,7 @@ namespace osu.Game.Overlays.Chat.Tabs
|
||||
EdgeSmoothness = new Vector2(1, 0),
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
},
|
||||
new Container
|
||||
content = new Container
|
||||
{
|
||||
Shear = new Vector2(-ChannelTabControl.SHEAR_WIDTH / ChatOverlay.TAB_AREA_HEIGHT, 0),
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
@ -149,7 +76,7 @@ namespace osu.Game.Overlays.Chat.Tabs
|
||||
{
|
||||
Icon = new SpriteIcon
|
||||
{
|
||||
Icon = FontAwesome.fa_hashtag,
|
||||
Icon = DisplayIcon,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Colour = Color4.Black,
|
||||
@ -175,7 +102,7 @@ namespace osu.Game.Overlays.Chat.Tabs
|
||||
Font = @"Exo2.0-Bold",
|
||||
TextSize = 18,
|
||||
},
|
||||
closeButton = new TabCloseButton
|
||||
CloseButton = new TabCloseButton
|
||||
{
|
||||
Alpha = 0,
|
||||
Margin = new MarginPadding { Right = 20 },
|
||||
@ -190,5 +117,96 @@ namespace osu.Game.Overlays.Chat.Tabs
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
protected virtual FontAwesome DisplayIcon => FontAwesome.fa_hashtag;
|
||||
|
||||
protected virtual bool ShowCloseOnHover => true;
|
||||
|
||||
protected override bool OnHover(InputState state)
|
||||
{
|
||||
if (IsRemovable && ShowCloseOnHover)
|
||||
CloseButton.FadeIn(200, Easing.OutQuint);
|
||||
|
||||
if (!Active)
|
||||
box.FadeColour(backgroundHover, TRANSITION_LENGTH, Easing.OutQuint);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(InputState state)
|
||||
{
|
||||
CloseButton.FadeOut(200, Easing.OutQuint);
|
||||
updateState();
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
BackgroundActive = colours.ChatBlue;
|
||||
BackgroundInactive = colours.Gray4;
|
||||
backgroundHover = colours.Gray7;
|
||||
|
||||
highlightBox.Colour = colours.Yellow;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
updateState();
|
||||
FinishTransforms(true);
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
if (Active)
|
||||
FadeActive();
|
||||
else
|
||||
FadeInactive();
|
||||
}
|
||||
|
||||
protected const float TRANSITION_LENGTH = 400;
|
||||
|
||||
private readonly EdgeEffectParameters activateEdgeEffect = new EdgeEffectParameters
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Radius = 15,
|
||||
Colour = Color4.Black.Opacity(0.4f),
|
||||
};
|
||||
|
||||
private readonly EdgeEffectParameters deactivateEdgeEffect = new EdgeEffectParameters
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Radius = 10,
|
||||
Colour = Color4.Black.Opacity(0.2f),
|
||||
};
|
||||
|
||||
protected virtual void FadeActive()
|
||||
{
|
||||
this.ResizeHeightTo(1.1f, TRANSITION_LENGTH, Easing.OutQuint);
|
||||
|
||||
TweenEdgeEffectTo(activateEdgeEffect, TRANSITION_LENGTH);
|
||||
|
||||
box.FadeColour(BackgroundActive, TRANSITION_LENGTH, Easing.OutQuint);
|
||||
highlightBox.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
|
||||
|
||||
Text.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
|
||||
TextBold.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected virtual void FadeInactive()
|
||||
{
|
||||
this.ResizeHeightTo(1, TRANSITION_LENGTH, Easing.OutQuint);
|
||||
|
||||
TweenEdgeEffectTo(deactivateEdgeEffect, TRANSITION_LENGTH);
|
||||
|
||||
box.FadeColour(BackgroundInactive, TRANSITION_LENGTH, Easing.OutQuint);
|
||||
highlightBox.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
|
||||
|
||||
Text.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
|
||||
TextBold.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected override void OnActivated() => updateState();
|
||||
protected override void OnDeactivated() => updateState();
|
||||
}
|
||||
}
|
||||
|
@ -7,29 +7,20 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Screens.Menu;
|
||||
using osu.Game.Users;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Chat.Tabs
|
||||
{
|
||||
public class PrivateChannelTabItem : TabItem<Channel>
|
||||
public class PrivateChannelTabItem : ChannelTabItem
|
||||
{
|
||||
private static readonly Vector2 shear = new Vector2(1f / 5f, 0);
|
||||
public override bool IsRemovable => true;
|
||||
|
||||
private readonly Box highlightBox;
|
||||
private readonly Container backgroundContainer;
|
||||
private readonly Box backgroundBox;
|
||||
private readonly OsuSpriteText username;
|
||||
private readonly Avatar avatarContainer;
|
||||
private readonly TabCloseButton closeButton;
|
||||
|
||||
protected override FontAwesome DisplayIcon => FontAwesome.fa_at;
|
||||
|
||||
public PrivateChannelTabItem(Channel value)
|
||||
: base(value)
|
||||
@ -37,174 +28,61 @@ namespace osu.Game.Overlays.Chat.Tabs
|
||||
if (value.Target != TargetType.User)
|
||||
throw new ArgumentException("Argument value needs to have the targettype user!");
|
||||
|
||||
AutoSizeAxes = Axes.X;
|
||||
Height = 50;
|
||||
Origin = Anchor.BottomLeft;
|
||||
Anchor = Anchor.BottomLeft;
|
||||
EdgeEffect = activateEdgeEffect;
|
||||
Masking = true;
|
||||
Shear = shear;
|
||||
Children = new Drawable[]
|
||||
AddRange(new Drawable[]
|
||||
{
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
AutoSizeAxes = Axes.X,
|
||||
Margin = new MarginPadding
|
||||
{
|
||||
Horizontal = 3
|
||||
},
|
||||
Origin = Anchor.BottomLeft,
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
backgroundBox = new Box
|
||||
new CircularContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Anchor = Anchor.BottomLeft,
|
||||
EdgeSmoothness = new Vector2(1, 0),
|
||||
Scale = new Vector2(0.95f),
|
||||
Size = new Vector2(ChatOverlay.TAB_AREA_HEIGHT),
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Masking = true,
|
||||
Child = new DelayedLoadWrapper(new Avatar(value.JoinedUsers.First())
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
OnLoadComplete = d => d.FadeInFromZero(300, Easing.OutQuint),
|
||||
})
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
highlightBox = new Box
|
||||
{
|
||||
Width = 5,
|
||||
BypassAutoSizeAxes = Axes.X,
|
||||
Alpha = 0,
|
||||
Anchor = Anchor.BottomRight,
|
||||
Origin = Anchor.BottomRight,
|
||||
EdgeSmoothness = new Vector2(1, 0),
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Colour = new OsuColour().Yellow
|
||||
},
|
||||
new Container
|
||||
{
|
||||
Masking = true,
|
||||
AutoSizeAxes = Axes.X,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Child = new FlowContainerWithOrigin
|
||||
{
|
||||
AutoSizeAxes = Axes.X,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
X = -5,
|
||||
Direction = FillDirection.Horizontal,
|
||||
Origin = Anchor.TopLeft,
|
||||
Anchor = Anchor.TopLeft,
|
||||
Shear = -shear,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
AutoSizeAxes = Axes.X,
|
||||
Margin = new MarginPadding
|
||||
{
|
||||
Horizontal = 5
|
||||
},
|
||||
Origin = Anchor.BottomLeft,
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new SpriteIcon
|
||||
{
|
||||
Icon = FontAwesome.fa_at,
|
||||
Origin = Anchor.Centre,
|
||||
Scale = new Vector2(1.2f),
|
||||
X = -5,
|
||||
Y = 5,
|
||||
Anchor = Anchor.Centre,
|
||||
Colour = new OsuColour().BlueDarker,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
new CircularContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Scale = new Vector2(0.95f),
|
||||
AutoSizeAxes = Axes.X,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Masking = true,
|
||||
Child = new DelayedLoadWrapper(new Avatar(value.JoinedUsers.First())
|
||||
{
|
||||
Size = new Vector2(ChatOverlay.TAB_AREA_HEIGHT),
|
||||
OnLoadComplete = d => d.FadeInFromZero(300, Easing.OutQuint),
|
||||
})
|
||||
{
|
||||
Size = new Vector2(ChatOverlay.TAB_AREA_HEIGHT),
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
username = new OsuSpriteText
|
||||
{
|
||||
Origin = Anchor.CentreLeft,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Text = value.Name,
|
||||
Margin = new MarginPadding(1),
|
||||
TextSize = 18,
|
||||
Alpha = 0,
|
||||
},
|
||||
closeButton = new TabCloseButton
|
||||
{
|
||||
Height = 1,
|
||||
Origin = Anchor.BottomLeft,
|
||||
Anchor = Anchor.BottomLeft,
|
||||
Alpha = 0,
|
||||
Margin = new MarginPadding
|
||||
{
|
||||
Right = 5
|
||||
},
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Action = delegate
|
||||
{
|
||||
if (IsRemovable) OnRequestClose?.Invoke(this);
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
username.ScaleTo(new Vector2(0, 1));
|
||||
closeButton.ScaleTo(new Vector2(0, 1));
|
||||
Text.X = ChatOverlay.TAB_AREA_HEIGHT;
|
||||
TextBold.X = ChatOverlay.TAB_AREA_HEIGHT;
|
||||
}
|
||||
|
||||
public Action<PrivateChannelTabItem> OnRequestClose;
|
||||
protected override bool ShowCloseOnHover => false;
|
||||
|
||||
private readonly EdgeEffectParameters activateEdgeEffect = new EdgeEffectParameters
|
||||
protected override void FadeActive()
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Radius = 15,
|
||||
Colour = Color4.Black.Opacity(0.4f),
|
||||
};
|
||||
base.FadeActive();
|
||||
|
||||
protected override void OnActivated()
|
||||
{
|
||||
const int activate_length = 1000;
|
||||
|
||||
backgroundBox.ResizeHeightTo(1.1f, activate_length, Easing.OutQuint);
|
||||
highlightBox.ResizeHeightTo(1.1f, activate_length, Easing.OutQuint);
|
||||
highlightBox.FadeIn(activate_length, Easing.OutQuint);
|
||||
username.FadeIn(activate_length, Easing.OutQuint);
|
||||
username.ScaleTo(new Vector2(1, 1), activate_length, Easing.OutQuint);
|
||||
closeButton.ScaleTo(new Vector2(1, 1), activate_length, Easing.OutQuint);
|
||||
closeButton.FadeIn(activate_length, Easing.OutQuint);
|
||||
TweenEdgeEffectTo(activateEdgeEffect, activate_length);
|
||||
this.ResizeWidthTo(200, TRANSITION_LENGTH * 2, Easing.OutQuint);
|
||||
CloseButton.FadeIn(TRANSITION_LENGTH, Easing.OutQuint);
|
||||
}
|
||||
|
||||
private readonly EdgeEffectParameters deactivateEdgeEffect = new EdgeEffectParameters
|
||||
{
|
||||
Type = EdgeEffectType.Shadow,
|
||||
Radius = 10,
|
||||
Colour = Color4.Black.Opacity(0.2f),
|
||||
};
|
||||
|
||||
protected override void OnDeactivated()
|
||||
protected override void FadeInactive()
|
||||
{
|
||||
const int deactivate_length = 500;
|
||||
base.FadeInactive();
|
||||
|
||||
backgroundBox.ResizeHeightTo(1, deactivate_length, Easing.OutQuint);
|
||||
highlightBox.ResizeHeightTo(1, deactivate_length, Easing.OutQuint);
|
||||
highlightBox.FadeOut(deactivate_length, Easing.OutQuint);
|
||||
username.FadeOut(deactivate_length, Easing.OutQuint);
|
||||
username.ScaleTo(new Vector2(0, 1), deactivate_length, Easing.OutQuint);
|
||||
closeButton.FadeOut(deactivate_length, Easing.OutQuint);
|
||||
closeButton.ScaleTo(new Vector2(0, 1), deactivate_length, Easing.OutQuint);
|
||||
TweenEdgeEffectTo(deactivateEdgeEffect, deactivate_length);
|
||||
this.ResizeWidthTo(ChatOverlay.TAB_AREA_HEIGHT + 10, TRANSITION_LENGTH, Easing.OutQuint);
|
||||
CloseButton.FadeOut(TRANSITION_LENGTH, Easing.OutQuint);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -212,7 +90,8 @@ namespace osu.Game.Overlays.Chat.Tabs
|
||||
{
|
||||
var user = Value.JoinedUsers.First();
|
||||
|
||||
backgroundBox.Colour = user.Colour != null ? OsuColour.FromHex(user.Colour) : colours.BlueDark;
|
||||
BackgroundActive = user.Colour != null ? OsuColour.FromHex(user.Colour) : colours.BlueDark;
|
||||
BackgroundInactive = BackgroundActive.Darken(0.5f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user