2016-10-04 18:41:18 +08:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-12-05 20:09:41 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2016-12-01 13:22:29 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2016-12-01 17:53:13 +08:00
|
|
|
|
using osu.Framework.Graphics.Transformations;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Game.Graphics;
|
2016-12-01 17:53:13 +08:00
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
2016-12-01 13:22:29 +08:00
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
|
|
|
|
public class ToolbarButton : Container
|
|
|
|
|
{
|
|
|
|
|
public FontAwesome Icon
|
|
|
|
|
{
|
|
|
|
|
get { return DrawableIcon.Icon; }
|
|
|
|
|
set { DrawableIcon.Icon = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
|
|
|
|
get { return DrawableText.Text; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
DrawableText.Text = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string TooltipMain
|
|
|
|
|
{
|
|
|
|
|
get { return tooltip1.Text; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
tooltip1.Text = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string TooltipSub
|
|
|
|
|
{
|
|
|
|
|
get { return tooltip2.Text; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
tooltip2.Text = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Action Action;
|
|
|
|
|
protected TextAwesome DrawableIcon;
|
|
|
|
|
protected SpriteText DrawableText;
|
|
|
|
|
protected Box HoverBackground;
|
|
|
|
|
private FlowContainer tooltipContainer;
|
|
|
|
|
private SpriteText tooltip1;
|
|
|
|
|
private SpriteText tooltip2;
|
2016-12-01 15:05:54 +08:00
|
|
|
|
protected FlowContainer Flow;
|
2016-12-05 20:09:41 +08:00
|
|
|
|
private AudioSample sampleClick;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
|
|
|
|
|
public ToolbarButton()
|
|
|
|
|
{
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2016-10-12 11:22:19 +08:00
|
|
|
|
HoverBackground = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2016-12-01 17:53:13 +08:00
|
|
|
|
Colour = new Color4(80, 80, 80, 180),
|
2016-12-01 17:54:32 +08:00
|
|
|
|
BlendingMode = BlendingMode.Additive,
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
2016-12-01 15:05:54 +08:00
|
|
|
|
Flow = new FlowContainer
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Direction = FlowDirection.HorizontalOnly,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2016-12-07 18:13:45 +08:00
|
|
|
|
Padding = new MarginPadding { Left = 20, Right = 20 },
|
2016-12-01 15:05:54 +08:00
|
|
|
|
Spacing = new Vector2(5),
|
2016-10-12 11:22:19 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2016-10-22 17:05:46 +08:00
|
|
|
|
AutoSizeAxes = Axes.X,
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2016-10-12 11:22:19 +08:00
|
|
|
|
DrawableIcon = new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
},
|
|
|
|
|
DrawableText = new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
},
|
2016-10-04 18:41:18 +08:00
|
|
|
|
},
|
2016-10-12 11:22:19 +08:00
|
|
|
|
},
|
|
|
|
|
tooltipContainer = new FlowContainer
|
|
|
|
|
{
|
|
|
|
|
Direction = FlowDirection.VerticalOnly,
|
2016-10-22 17:05:46 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2016-11-15 00:22:20 +08:00
|
|
|
|
Position = new Vector2(5, 5),
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
Children = new[]
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2016-11-05 07:27:41 +08:00
|
|
|
|
tooltip1 = new SpriteText
|
2016-10-12 11:22:19 +08:00
|
|
|
|
{
|
2016-11-23 10:35:31 +08:00
|
|
|
|
Shadow = true,
|
2016-10-12 11:22:19 +08:00
|
|
|
|
TextSize = 22,
|
2016-11-09 14:16:34 +08:00
|
|
|
|
Font = @"Exo2.0-Bold",
|
2016-10-12 11:22:19 +08:00
|
|
|
|
},
|
|
|
|
|
tooltip2 = new SpriteText
|
|
|
|
|
{
|
2016-11-23 10:35:31 +08:00
|
|
|
|
Shadow = true,
|
2016-11-09 14:16:34 +08:00
|
|
|
|
TextSize = 16
|
2016-10-12 11:22:19 +08:00
|
|
|
|
}
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-05 20:09:41 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
|
|
|
|
sampleClick = audio.Sample.Get(@"Menu/menuclick");
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 17:16:16 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
//todo: find a way to avoid using this (autosize needs to be able to ignore certain drawables.. in this case the tooltip)
|
2016-12-01 15:05:54 +08:00
|
|
|
|
Size = new Vector2(Flow.DrawSize.X, 1);
|
2016-10-05 17:16:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 19:35:17 +08:00
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;
|
|
|
|
|
|
2016-11-15 14:31:48 +08:00
|
|
|
|
protected override bool OnClick(InputState state)
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
|
|
|
|
Action?.Invoke();
|
2016-12-05 20:09:41 +08:00
|
|
|
|
sampleClick.Play();
|
2016-12-02 17:43:01 +08:00
|
|
|
|
HoverBackground.FlashColour(new Color4(255, 255, 255, 100), 500, EasingTypes.OutQuint);
|
2016-10-04 19:00:55 +08:00
|
|
|
|
return true;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
2016-12-01 17:53:13 +08:00
|
|
|
|
HoverBackground.FadeIn(200);
|
2016-10-04 18:41:18 +08:00
|
|
|
|
tooltipContainer.FadeIn(100);
|
2016-11-15 15:25:41 +08:00
|
|
|
|
return false;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
2016-12-01 17:53:13 +08:00
|
|
|
|
HoverBackground.FadeOut(200);
|
2016-10-04 18:41:18 +08:00
|
|
|
|
tooltipContainer.FadeOut(100);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-01 17:53:13 +08:00
|
|
|
|
|
|
|
|
|
public class OpaqueBackground : Container
|
|
|
|
|
{
|
|
|
|
|
public OpaqueBackground()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2016-12-01 20:12:37 +08:00
|
|
|
|
Masking = true;
|
2016-12-01 17:53:13 +08:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = new Color4(30, 30, 30, 255)
|
|
|
|
|
},
|
|
|
|
|
new Triangles
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0.05f,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|