mirror of
https://github.com/ppy/osu.git
synced 2024-12-05 03:03:21 +08:00
Refactor everything so I can read the code
This commit is contained in:
parent
23068034b1
commit
69b4713731
@ -13,17 +13,17 @@ namespace osu.Game.Graphics.UserInterface
|
||||
/// </summary>
|
||||
public class ExpandingBar : Circle
|
||||
{
|
||||
private bool isCollapsed;
|
||||
private bool expanded = true;
|
||||
|
||||
public bool IsCollapsed
|
||||
public bool Expanded
|
||||
{
|
||||
get => isCollapsed;
|
||||
get => expanded;
|
||||
set
|
||||
{
|
||||
if (value == isCollapsed)
|
||||
if (value == expanded)
|
||||
return;
|
||||
|
||||
isCollapsed = value;
|
||||
expanded = value;
|
||||
updateState();
|
||||
}
|
||||
}
|
||||
@ -83,19 +83,21 @@ namespace osu.Game.Graphics.UserInterface
|
||||
updateState();
|
||||
}
|
||||
|
||||
public void Collapse() => IsCollapsed = true;
|
||||
public void Collapse() => Expanded = false;
|
||||
|
||||
public void Expand() => IsCollapsed = false;
|
||||
public void Expand() => Expanded = true;
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
float newSize = IsCollapsed ? CollapsedSize : ExpandedSize;
|
||||
Easing easingType = IsCollapsed ? Easing.Out : Easing.OutElastic;
|
||||
float newSize = expanded ? ExpandedSize : CollapsedSize;
|
||||
Easing easingType = expanded ? Easing.OutElastic : Easing.Out;
|
||||
|
||||
if (RelativeSizeAxes == Axes.X)
|
||||
this.ResizeHeightTo(newSize, 400, easingType);
|
||||
else
|
||||
this.ResizeWidthTo(newSize, 400, easingType);
|
||||
|
||||
this.FadeTo(expanded ? 1 : 0.5f, 100, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
Colour = stream.Colour,
|
||||
ExpandedSize = 4,
|
||||
CollapsedSize = 2,
|
||||
IsCollapsed = true
|
||||
Expanded = true
|
||||
},
|
||||
new HoverClickSounds()
|
||||
});
|
||||
@ -100,33 +100,39 @@ namespace osu.Game.Overlays.Changelog
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
if (SelectedTab.Value == null && !allStreamsDimmed)
|
||||
// highlighted regardless if we are hovered
|
||||
bool textHighlighted = IsHovered;
|
||||
bool barExpanded = IsHovered;
|
||||
|
||||
if (SelectedTab.Value == null)
|
||||
{
|
||||
expandingBar.Expand();
|
||||
expandingBar.FadeTo(1, transition_duration, Easing.OutQuint);
|
||||
text.FadeTo(1, transition_duration, Easing.OutQuint);
|
||||
return;
|
||||
// at listing, all badges are highlighted when user is not hovering any badge.
|
||||
textHighlighted |= !userHoveringArea;
|
||||
barExpanded |= !userHoveringArea;
|
||||
}
|
||||
else
|
||||
{
|
||||
// bar is always expanded when active
|
||||
barExpanded |= Active.Value;
|
||||
|
||||
// text is highlighted only when hovered or active (but not if in selection mode)
|
||||
textHighlighted |= Active.Value && !userHoveringArea;
|
||||
}
|
||||
|
||||
var shouldExpand = Active.Value || IsHovered;
|
||||
|
||||
expandingBar.IsCollapsed = !shouldExpand;
|
||||
expandingBar.FadeTo(shouldExpand ? 1 : 0.5f, transition_duration, Easing.OutQuint);
|
||||
|
||||
text.FadeTo(IsHovered || (Active.Value && !allStreamsDimmed) ? 1 : 0.5f, transition_duration, Easing.OutQuint);
|
||||
expandingBar.Expanded = barExpanded;
|
||||
text.FadeTo(textHighlighted ? 1 : 0.5f, transition_duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
private bool allStreamsDimmed;
|
||||
private bool userHoveringArea;
|
||||
|
||||
public bool AllStreamsDimmed
|
||||
public bool UserHoveringArea
|
||||
{
|
||||
get => allStreamsDimmed;
|
||||
set
|
||||
{
|
||||
if (value == allStreamsDimmed)
|
||||
if (value == userHoveringArea)
|
||||
return;
|
||||
|
||||
allStreamsDimmed = value;
|
||||
userHoveringArea = value;
|
||||
updateState();
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
foreach (var streamBadge in TabContainer.Children.OfType<UpdateStreamBadge>())
|
||||
streamBadge.AllStreamsDimmed = true;
|
||||
streamBadge.UserHoveringArea = true;
|
||||
|
||||
return base.OnHover(e);
|
||||
}
|
||||
@ -35,7 +35,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
foreach (var streamBadge in TabContainer.Children.OfType<UpdateStreamBadge>())
|
||||
streamBadge.AllStreamsDimmed = false;
|
||||
streamBadge.UserHoveringArea = false;
|
||||
|
||||
base.OnHoverLost(e);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user