Skip to content

Commit

Permalink
实现内容超过时自动滚动
Browse files Browse the repository at this point in the history
  • Loading branch information
cdwcgt committed Dec 17, 2024
1 parent d3a45aa commit 8a449c8
Showing 1 changed file with 122 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Models;
using osuTK;
using osuTK.Graphics;
Expand All @@ -27,6 +29,8 @@ public partial class RoundInformationPreview : CompositeDrawable
private readonly TournamentSpriteText mapCountText;
private static readonly Color4 boarder_color = new Color4(56, 56, 56, 255);

private const float cover_width = 50f;

public RoundInformationPreview()
{
AutoSizeAxes = Axes.X;
Expand Down Expand Up @@ -86,7 +90,7 @@ public RoundInformationPreview()
new Container
{
Name = "右侧主要内容",
AutoSizeAxes = Axes.X,
Width = 1000f,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Y,
Expand All @@ -96,12 +100,62 @@ public RoundInformationPreview()
},
Children = new Drawable[]
{
mapContentContainer = new FillFlowContainer
new BufferedContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
mapContentContainer = new FillFlowContainer
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal
},
new Container
{
Name = "cover",
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Blending = new BlendingParameters
{
// Don't change the destination colour.
RGBEquation = BlendingEquation.Add,
Source = BlendingType.Zero,
Destination = BlendingType.One,
// Subtract the cover's alpha from the destination (points with alpha 1 should make the destination completely transparent).
AlphaEquation = BlendingEquation.Add,
SourceAlpha = BlendingType.Zero,
DestinationAlpha = BlendingType.OneMinusSrcAlpha
},
Children = new Drawable[]
{
new Box
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Y,
Width = cover_width,
Colour = ColourInfo.GradientHorizontal(
Color4.White.Opacity(1f),
Color4.White.Opacity(0f)
)
},
new Box
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Y,
Width = cover_width,
Colour = ColourInfo.GradientHorizontal(
Color4.White.Opacity(0f),
Color4.White.Opacity(1f)
)
},
}
}
}
},
mapCountText = new TournamentSpriteText
{
Expand All @@ -122,6 +176,38 @@ protected override void LoadComplete()
ladderInfo.CurrentMatch.BindValueChanged(matchChanged, true);
}

private bool mapContentReturnPosition;
private bool mapContentNeedRoll;
private double pauseTime;

protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();

if (!mapContentNeedRoll)
return;

if (pauseTime > 0)
{
pauseTime -= Clock.ElapsedFrameTime;
return;
}

if (!mapContentReturnPosition && mapContentContainer.DrawWidth + mapContentContainer.X < 1000 - cover_width)
{
mapContentReturnPosition = true;
pauseTime = 3000;
}

if (mapContentReturnPosition && mapContentContainer.X >= cover_width)
{
mapContentReturnPosition = false;
pauseTime = 3000;
}

mapContentContainer.X = mapContentReturnPosition ? mapContentContainer.X + (float)(50 * Time.Elapsed / 1000) : mapContentContainer.X + (float)(-50 * Time.Elapsed / 1000);
}

private void matchChanged(ValueChangedEvent<TournamentMatch?> match)
{
if (match.OldValue != null)
Expand Down Expand Up @@ -153,8 +239,8 @@ private void updateState()
int pickMapCount = ladderInfo.CurrentMatch.Value.Round.Value.BestOf.Value - 1;

var pickChoice = remainChoices.Take(pickMapCount)
// 往后面填充null
.Concat(Enumerable.Repeat((BeatmapChoice?)null, pickMapCount - remainChoices.Take(pickMapCount).Count()));
// 往后面填充null
.Concat(Enumerable.Repeat((BeatmapChoice?)null, pickMapCount - remainChoices.Take(pickMapCount).Count()));

mapContentContainer.Add(banMapDetail);
mapContentContainer.Add(createDivideLine());
Expand All @@ -178,6 +264,23 @@ private void updateState()
{
banMapDetail.UpdateBeatmap(banChoices);
pickDetail.UpdateBeatmap(pickChoice);

Scheduler.Add(() =>
{
if (mapContentContainer.DrawWidth < 1000)
{
mapContentNeedRoll = false;
mapContentContainer.Anchor = Anchor.TopCentre;
mapContentContainer.Origin = Anchor.TopCentre;
mapContentContainer.X = 0;
return;
}

mapContentNeedRoll = true;

mapContentContainer.Anchor = Anchor.TopLeft;
mapContentContainer.Origin = Anchor.TopLeft;
});
});
}

Expand Down Expand Up @@ -215,7 +318,13 @@ private MapBox createTBMapBox(bool isSelected)
if (TBMap == null)
return mapbox;

mapbox.BottomMapContainer.Add(createMapBoxContent("TB", TBMap.BackgroundColor, TBMap.TextColor));
mapbox.BottomMapContainer.Add(new TournamentModIcon("TB")
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill
});

return mapbox;
}
Expand Down Expand Up @@ -417,11 +526,11 @@ public MapBox()
};
}

public Container TopMapContainer { get; set; }
public Container TopMapContainer { get; }

public Container BottomMapContainer { get; set; }
public Container BottomMapContainer { get; }

public Box CenterLine { get; set; }
public Box CenterLine { get; }
}
}
}

0 comments on commit 8a449c8

Please sign in to comment.