1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 03:22:55 +08:00

Refactor to make things more flexible

This commit is contained in:
EVAST9919 2019-02-09 06:23:58 +03:00
parent 105053e91b
commit 04e57d7d3d
4 changed files with 341 additions and 232 deletions

View File

@ -22,24 +22,15 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
public class DrawableScore : Container
{
private const int fade_duration = 100;
private const float text_size = 14;
private const int text_size = 14;
private readonly Box hoveredBackground;
private readonly Box background;
public DrawableScore(int index, APIScoreInfo score, int maxModsAmount)
{
SpriteText accuracy;
SpriteText scoreText;
SpriteText hitGreat;
SpriteText hitGood;
SpriteText hitMeh;
SpriteText hitMiss;
FillFlowContainer modsContainer;
RelativeSizeAxes = Axes.X;
Height = 25;
AutoSizeAxes = Axes.Y;
CornerRadius = 3;
Masking = true;
Children = new Drawable[]
@ -53,138 +44,11 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
RelativeSizeAxes = Axes.Both,
Alpha = 0,
},
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreRight,
Text = $"#{index + 1}",
TextSize = text_size,
X = ScoreTextLine.RANK_POSITION,
Font = @"Exo2.0-Bold",
},
new DrawableRank(score.Rank)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(30, 20),
FillMode = FillMode.Fit,
X = 45
},
scoreText = new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = $@"{score.TotalScore:N0}",
X = ScoreTextLine.SCORE_POSITION,
TextSize = text_size,
},
accuracy = new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = $@"{score.Accuracy:P2}",
X = ScoreTextLine.ACCURACY_POSITION,
TextSize = text_size,
},
new DrawableFlag(score.User.Country)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(20, 13),
X = 230,
},
new ClickableScoreUsername
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
User = score.User,
X = ScoreTextLine.PLAYER_POSITION,
},
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = $@"{score.MaxCombo:N0}x",
RelativePositionAxes = Axes.X,
X = ScoreTextLine.MAX_COMBO_POSITION,
TextSize = text_size,
},
hitGreat = new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = $"{score.Statistics[HitResult.Great]}",
RelativePositionAxes = Axes.X,
X = ScoreTextLine.HIT_GREAT_POSITION,
TextSize = text_size,
},
hitGood = new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = $"{score.Statistics[HitResult.Good]}",
RelativePositionAxes = Axes.X,
X = ScoreTextLine.HIT_GOOD_POSITION,
TextSize = text_size,
},
hitMeh = new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = $"{score.Statistics[HitResult.Meh]}",
RelativePositionAxes = Axes.X,
X = ScoreTextLine.HIT_MEH_POSITION,
TextSize = text_size,
},
hitMiss = new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = $"{score.Statistics[HitResult.Miss]}",
RelativePositionAxes = Axes.X,
X = ScoreTextLine.HIT_MISS_POSITION,
TextSize = text_size,
},
new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = $@"{score.PP:N0}",
RelativePositionAxes = Axes.X,
X = ScoreTextLine.PP_POSITION,
TextSize = text_size,
},
modsContainer = new FillFlowContainer
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreLeft,
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
X = -30 * maxModsAmount,
},
new DrawableScoreData(index, score, maxModsAmount),
};
if (index == 0)
scoreText.Font = @"Exo2.0-Bold";
accuracy.Colour = (score.Accuracy == 1) ? Color4.GreenYellow : Color4.White;
hitGreat.Colour = (score.Statistics[HitResult.Great] == 0) ? Color4.Gray : Color4.White;
hitGood.Colour = (score.Statistics[HitResult.Good] == 0) ? Color4.Gray : Color4.White;
hitMeh.Colour = (score.Statistics[HitResult.Meh] == 0) ? Color4.Gray : Color4.White;
hitMiss.Colour = (score.Statistics[HitResult.Miss] == 0) ? Color4.Gray : Color4.White;
if (index % 2 == 0)
if (index % 2 != 0)
background.Alpha = 0;
foreach (Mod mod in score.Mods)
modsContainer.Add(new ModIcon(mod)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Scale = new Vector2(0.3f),
});
}
[BackgroundDependencyLoader]
@ -251,5 +115,103 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
base.OnHoverLost(e);
}
}
private class DrawableScoreData : ScoreTableLine
{
public DrawableScoreData(int index, APIScoreInfo score, int maxModsAmount) : base(maxModsAmount)
{
SpriteText scoreText;
SpriteText accuracy;
SpriteText hitGreat;
SpriteText hitGood;
SpriteText hitMeh;
SpriteText hitMiss;
FillFlowContainer modsContainer;
RankContainer.Add(new SpriteText
{
Text = $"#{index + 1}",
Font = @"Exo2.0-Bold",
TextSize = text_size,
});
DrawableRankContainer.Add(new DrawableRank(score.Rank)
{
Size = new Vector2(30, 20),
FillMode = FillMode.Fit,
});
ScoreContainer.Add(scoreText = new SpriteText
{
Text = $@"{score.TotalScore:N0}",
TextSize = text_size,
});
AccuracyContainer.Add(accuracy = new SpriteText
{
Text = $@"{score.Accuracy:P2}",
TextSize = text_size,
});
FlagContainer.Add(new DrawableFlag(score.User.Country)
{
Size = new Vector2(20, 13),
});
PlayerContainer.Add(new ClickableScoreUsername
{
User = score.User,
});
MaxComboContainer.Add(new SpriteText
{
Text = $@"{score.MaxCombo:N0}x",
TextSize = text_size,
});
HitGreatContainer.Add(hitGreat = new SpriteText
{
Text = $"{score.Statistics[HitResult.Great]}",
TextSize = text_size,
});
HitGoodContainer.Add(hitGood = new SpriteText
{
Text = $"{score.Statistics[HitResult.Good]}",
TextSize = text_size,
});
HitMehContainer.Add(hitMeh = new SpriteText
{
Text = $"{score.Statistics[HitResult.Meh]}",
TextSize = text_size,
});
HitMissContainer.Add(hitMiss = new SpriteText
{
Text = $"{score.Statistics[HitResult.Miss]}",
TextSize = text_size,
});
PPContainer.Add(new SpriteText
{
Text = $@"{score.PP:N0}",
TextSize = text_size,
});
ModsContainer.Add(modsContainer = new FillFlowContainer
{
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
});
if (index == 0)
scoreText.Font = @"Exo2.0-Bold";
accuracy.Colour = (score.Accuracy == 1) ? Color4.GreenYellow : Color4.White;
hitGreat.Colour = (score.Statistics[HitResult.Great] == 0) ? Color4.Gray : Color4.White;
hitGood.Colour = (score.Statistics[HitResult.Good] == 0) ? Color4.Gray : Color4.White;
hitMeh.Colour = (score.Statistics[HitResult.Meh] == 0) ? Color4.Gray : Color4.White;
hitMiss.Colour = (score.Statistics[HitResult.Miss] == 0) ? Color4.Gray : Color4.White;
foreach (Mod mod in score.Mods)
modsContainer.Add(new ModIcon(mod)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Scale = new Vector2(0.3f),
});
}
}
}
}

View File

@ -188,7 +188,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Width = 0.7f,
Width = 0.65f,
Child = new FillFlowContainer
{
AutoSizeAxes = Axes.Y,

View File

@ -0,0 +1,183 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Overlays.BeatmapSet.Scores
{
public class ScoreTableLine : GridContainer
{
private const float rank_position = 30;
private const float drawable_rank_position = 45;
private const float score_position = 90;
private const float accuracy_position = 170;
private const float flag_position = 220;
private const float player_position = 250;
private const float max_combo_position = 0.1f;
private const float hit_great_position = 0.3f;
private const float hit_good_position = 0.45f;
private const float hit_meh_position = 0.6f;
private const float hit_miss_position = 0.75f;
private const float pp_position = 0.9f;
protected readonly Container RankContainer;
protected readonly Container DrawableRankContainer;
protected readonly Container ScoreContainer;
protected readonly Container AccuracyContainer;
protected readonly Container FlagContainer;
protected readonly Container PlayerContainer;
protected readonly Container MaxComboContainer;
protected readonly Container HitGreatContainer;
protected readonly Container HitGoodContainer;
protected readonly Container HitMehContainer;
protected readonly Container HitMissContainer;
protected readonly Container PPContainer;
protected readonly Container ModsContainer;
public ScoreTableLine(int maxModsAmount)
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
RowDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, 25),
};
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, 300),
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
};
Content = new[]
{
new Drawable[]
{
new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
RankContainer = new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreRight,
AutoSizeAxes = Axes.Both,
X = rank_position,
},
DrawableRankContainer = new Container
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
X = drawable_rank_position,
},
ScoreContainer = new Container
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
X = score_position,
},
AccuracyContainer = new Container
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
X = accuracy_position,
},
FlagContainer = new Container
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
X = flag_position,
},
PlayerContainer = new Container
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
X = player_position,
}
}
},
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new Drawable[]
{
MaxComboContainer = new Container
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
RelativePositionAxes = Axes.X,
X = max_combo_position,
},
HitGreatContainer = new Container
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
RelativePositionAxes = Axes.X,
X = hit_great_position,
},
HitGoodContainer = new Container
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
RelativePositionAxes = Axes.X,
X = hit_good_position,
},
HitMehContainer = new Container
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
RelativePositionAxes = Axes.X,
X = hit_meh_position,
},
HitMissContainer = new Container
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
RelativePositionAxes = Axes.X,
X = hit_miss_position,
},
PPContainer = new Container
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
RelativePositionAxes = Axes.X,
X = pp_position,
}
}
},
new Container
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Child = ModsContainer = new Container
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.Both,
X = -30 * maxModsAmount,
}
}
}
};
}
}
}

View File

@ -1,107 +1,71 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
namespace osu.Game.Overlays.BeatmapSet.Scores
{
public class ScoreTextLine : Container
public class ScoreTextLine : ScoreTableLine
{
private const float text_size = 12;
public const float RANK_POSITION = 30;
public const float SCORE_POSITION = 90;
public const float ACCURACY_POSITION = 170;
public const float PLAYER_POSITION = 270;
public const float MAX_COMBO_POSITION = 0.5f;
public const float HIT_GREAT_POSITION = 0.6f;
public const float HIT_GOOD_POSITION = 0.65f;
public const float HIT_MEH_POSITION = 0.7f;
public const float HIT_MISS_POSITION = 0.75f;
public const float PP_POSITION = 0.8f;
public ScoreTextLine(int maxModsAmount)
public ScoreTextLine(int maxModsAmount) : base(maxModsAmount)
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Children = new Drawable[]
RankContainer.Add(new SpriteText
{
new ScoreText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreRight,
Text = "rank".ToUpper(),
X = RANK_POSITION,
},
new ScoreText
{
Text = "score".ToUpper(),
X = SCORE_POSITION,
},
new ScoreText
{
Text = "accuracy".ToUpper(),
X = ACCURACY_POSITION,
},
new ScoreText
{
Text = "player".ToUpper(),
X = PLAYER_POSITION,
},
new ScoreText
{
Text = "max combo".ToUpper(),
X = MAX_COMBO_POSITION,
RelativePositionAxes = Axes.X,
},
new ScoreText
{
Text = "300",
RelativePositionAxes = Axes.X,
X = HIT_GREAT_POSITION,
},
new ScoreText
{
Text = "100".ToUpper(),
RelativePositionAxes = Axes.X,
X = HIT_GOOD_POSITION,
},
new ScoreText
{
Text = "50".ToUpper(),
RelativePositionAxes = Axes.X,
X = HIT_MEH_POSITION,
},
new ScoreText
{
Text = "miss".ToUpper(),
RelativePositionAxes = Axes.X,
X = HIT_MISS_POSITION,
},
new ScoreText
{
Text = "pp".ToUpper(),
RelativePositionAxes = Axes.X,
X = PP_POSITION,
},
new ScoreText
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreLeft,
Text = "mods".ToUpper(),
X = -30 * maxModsAmount,
},
};
}
private class ScoreText : SpriteText
{
public ScoreText()
Text = @"rank".ToUpper(),
TextSize = text_size,
});
ScoreContainer.Add(new SpriteText
{
TextSize = text_size;
}
Text = @"score".ToUpper(),
TextSize = text_size,
});
AccuracyContainer.Add(new SpriteText
{
Text = @"accuracy".ToUpper(),
TextSize = text_size,
});
PlayerContainer.Add(new SpriteText
{
Text = @"player".ToUpper(),
TextSize = text_size,
});
MaxComboContainer.Add(new SpriteText
{
Text = @"max combo".ToUpper(),
TextSize = text_size,
});
HitGreatContainer.Add(new SpriteText
{
Text = "300".ToUpper(),
TextSize = text_size,
});
HitGoodContainer.Add(new SpriteText
{
Text = "100".ToUpper(),
TextSize = text_size,
});
HitMehContainer.Add(new SpriteText
{
Text = "50".ToUpper(),
TextSize = text_size,
});
HitMissContainer.Add(new SpriteText
{
Text = @"miss".ToUpper(),
TextSize = text_size,
});
PPContainer.Add(new SpriteText
{
Text = @"pp".ToUpper(),
TextSize = text_size,
});
ModsContainer.Add(new SpriteText
{
Text = @"mods".ToUpper(),
TextSize = text_size,
});
}
}
}