2019-03-04 04:24:19 +00:00
// 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.
2018-11-06 10:23:03 +00:00
using osu.Framework.Allocation ;
2019-11-23 11:52:41 +00:00
using osu.Framework.Bindables ;
2018-11-06 10:23:03 +00:00
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
2020-06-28 11:14:46 +00:00
using osu.Framework.Graphics.Primitives ;
2018-11-06 10:23:03 +00:00
using osu.Framework.Graphics.Shapes ;
2018-11-22 08:25:46 +00:00
using osu.Framework.Graphics.Sprites ;
2018-11-06 10:23:03 +00:00
using osu.Game.Beatmaps ;
using osu.Game.Beatmaps.Legacy ;
2021-07-31 07:46:02 +00:00
using osu.Game.Extensions ;
2018-11-06 10:23:03 +00:00
using osu.Game.Graphics ;
2024-01-17 06:38:51 +00:00
using osu.Game.Models ;
2019-11-23 11:52:41 +00:00
using osu.Game.Rulesets ;
2018-11-06 10:23:03 +00:00
using osu.Game.Screens.Menu ;
2018-11-22 01:25:30 +00:00
using osuTK ;
using osuTK.Graphics ;
2018-11-06 10:23:03 +00:00
namespace osu.Game.Tournament.Components
{
2022-11-24 05:32:20 +00:00
public partial class SongBar : CompositeDrawable
2018-11-06 10:23:03 +00:00
{
2023-08-01 05:56:48 +00:00
private IBeatmapInfo ? beatmap ;
2018-11-06 10:23:03 +00:00
2020-04-26 21:59:24 +00:00
public const float HEIGHT = 145 / 2f ;
2020-03-08 05:46:09 +00:00
2019-11-23 11:52:41 +00:00
[Resolved]
2023-07-25 11:50:55 +00:00
private IBindable < RulesetInfo > ruleset { get ; set ; } = null ! ;
2019-11-23 11:52:41 +00:00
2023-08-01 05:56:48 +00:00
public IBeatmapInfo ? Beatmap
2018-11-06 10:23:03 +00:00
{
set
{
2021-10-27 09:25:23 +00:00
if ( beatmap = = value )
2018-11-06 10:23:03 +00:00
return ;
2021-10-27 09:25:23 +00:00
beatmap = value ;
2023-08-01 05:56:48 +00:00
refreshContent ( ) ;
2018-11-06 10:23:03 +00:00
}
}
private LegacyMods mods ;
public LegacyMods Mods
{
get = > mods ;
set
{
mods = value ;
2023-08-01 05:56:48 +00:00
refreshContent ( ) ;
2018-11-06 10:23:03 +00:00
}
}
2023-07-25 11:50:55 +00:00
private FillFlowContainer flow = null ! ;
2018-11-10 16:29:42 +00:00
2018-11-16 09:14:42 +00:00
private bool expanded ;
2018-11-10 16:29:42 +00:00
public bool Expanded
{
2018-11-16 09:14:42 +00:00
get = > expanded ;
2018-11-10 16:29:42 +00:00
set
{
2018-11-16 09:14:42 +00:00
expanded = value ;
2020-03-08 05:46:09 +00:00
flow . Direction = expanded ? FillDirection . Full : FillDirection . Vertical ;
2018-11-10 16:29:42 +00:00
}
}
2020-06-28 11:14:46 +00:00
// Todo: This is a hack for https://github.com/ppy/osu-framework/issues/3617 since this container is at the very edge of the screen and potentially initially masked away.
protected override bool ComputeIsMaskedAway ( RectangleF maskingBounds ) = > false ;
2018-11-06 10:23:03 +00:00
[BackgroundDependencyLoader]
2023-08-01 05:56:48 +00:00
private void load ( OsuColour colours )
2018-11-06 10:23:03 +00:00
{
2020-03-08 05:46:09 +00:00
RelativeSizeAxes = Axes . X ;
AutoSizeAxes = Axes . Y ;
2018-11-06 10:23:03 +00:00
2023-08-01 05:56:48 +00:00
Masking = true ;
CornerRadius = 5 ;
2018-11-06 10:23:03 +00:00
InternalChildren = new Drawable [ ]
{
2023-08-01 05:56:48 +00:00
new Box
{
Colour = colours . Gray3 ,
RelativeSizeAxes = Axes . Both ,
2023-10-10 09:47:20 +00:00
Alpha = 0.4f ,
2023-08-01 05:56:48 +00:00
} ,
2020-03-08 05:46:09 +00:00
flow = new FillFlowContainer
2018-11-06 10:23:03 +00:00
{
RelativeSizeAxes = Axes . X ,
2020-03-08 05:46:09 +00:00
AutoSizeAxes = Axes . Y ,
Direction = FillDirection . Full ,
2018-11-10 16:29:42 +00:00
Anchor = Anchor . BottomRight ,
Origin = Anchor . BottomRight ,
2018-11-06 10:23:03 +00:00
}
} ;
2018-11-22 04:17:51 +00:00
Expanded = true ;
2018-11-06 10:23:03 +00:00
}
2023-08-01 05:56:48 +00:00
private void refreshContent ( )
2018-11-06 10:23:03 +00:00
{
2024-01-17 06:38:51 +00:00
beatmap ? ? = new BeatmapInfo
2018-11-06 10:23:03 +00:00
{
2024-01-17 06:38:51 +00:00
Metadata = new BeatmapMetadata
{
Artist = "unknown" ,
Title = "no beatmap selected" ,
Author = new RealmUser { Username = "unknown" } ,
} ,
DifficultyName = "unknown" ,
BeatmapSet = new BeatmapSetInfo ( ) ,
StarRating = 0 ,
Difficulty = new BeatmapDifficulty
{
CircleSize = 0 ,
DrainRate = 0 ,
OverallDifficulty = 0 ,
ApproachRate = 0 ,
} ,
} ;
2018-11-06 10:23:03 +00:00
2021-10-28 05:48:36 +00:00
double bpm = beatmap . BPM ;
2021-10-27 09:25:23 +00:00
double length = beatmap . Length ;
2018-11-22 05:10:33 +00:00
string hardRockExtra = "" ;
string srExtra = "" ;
2018-11-06 10:23:03 +00:00
2021-10-27 09:25:23 +00:00
float ar = beatmap . Difficulty . ApproachRate ;
2019-11-23 11:52:41 +00:00
2018-11-22 05:10:33 +00:00
if ( ( mods & LegacyMods . HardRock ) > 0 )
{
hardRockExtra = "*" ;
srExtra = "*" ;
}
2018-11-06 10:23:03 +00:00
if ( ( mods & LegacyMods . DoubleTime ) > 0 )
{
2019-11-23 15:21:34 +00:00
// temporary local calculation (taken from OsuDifficultyCalculator)
2021-10-01 08:03:08 +00:00
double preempt = ( int ) IBeatmapDifficultyInfo . DifficultyRange ( ar , 1800 , 1200 , 450 ) / 1.5 ;
2019-11-23 15:21:34 +00:00
ar = ( float ) ( preempt > 1200 ? ( 1800 - preempt ) / 120 : ( 1200 - preempt ) / 150 + 5 ) ;
2018-11-06 10:23:03 +00:00
bpm * = 1.5f ;
length / = 1.5f ;
2018-11-22 05:10:33 +00:00
srExtra = "*" ;
2018-11-06 10:23:03 +00:00
}
2019-11-23 11:52:41 +00:00
( string heading , string content ) [ ] stats ;
2021-11-24 06:25:49 +00:00
switch ( ruleset . Value . OnlineID )
2019-11-23 11:52:41 +00:00
{
default :
stats = new ( string heading , string content ) [ ]
{
2021-10-27 09:25:23 +00:00
( "CS" , $"{beatmap.Difficulty.CircleSize:0.#}{hardRockExtra}" ) ,
2019-11-23 16:45:21 +00:00
( "AR" , $"{ar:0.#}{hardRockExtra}" ) ,
2021-10-27 09:25:23 +00:00
( "OD" , $"{beatmap.Difficulty.OverallDifficulty:0.#}{hardRockExtra}" ) ,
2019-11-23 11:52:41 +00:00
} ;
break ;
case 1 :
case 3 :
stats = new ( string heading , string content ) [ ]
{
2021-10-27 09:25:23 +00:00
( "OD" , $"{beatmap.Difficulty.OverallDifficulty:0.#}{hardRockExtra}" ) ,
( "HP" , $"{beatmap.Difficulty.DrainRate:0.#}{hardRockExtra}" )
2019-11-23 11:52:41 +00:00
} ;
break ;
case 2 :
stats = new ( string heading , string content ) [ ]
{
2021-10-27 09:25:23 +00:00
( "CS" , $"{beatmap.Difficulty.CircleSize:0.#}{hardRockExtra}" ) ,
2019-11-23 16:45:21 +00:00
( "AR" , $"{ar:0.#}" ) ,
2019-11-23 11:52:41 +00:00
} ;
break ;
}
2020-03-08 05:46:09 +00:00
flow . Children = new Drawable [ ]
2018-11-06 10:23:03 +00:00
{
2020-03-08 05:46:09 +00:00
new Container
2018-11-06 10:23:03 +00:00
{
2020-03-08 05:46:09 +00:00
RelativeSizeAxes = Axes . X ,
2020-04-26 21:59:24 +00:00
Height = HEIGHT ,
2020-03-08 05:46:09 +00:00
Width = 0.5f ,
Anchor = Anchor . BottomRight ,
Origin = Anchor . BottomRight ,
Children = new Drawable [ ]
{
new GridContainer
{
RelativeSizeAxes = Axes . Both ,
Content = new [ ]
{
new Drawable [ ]
{
new FillFlowContainer
{
RelativeSizeAxes = Axes . X ,
AutoSizeAxes = Axes . Y ,
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Direction = FillDirection . Vertical ,
Children = new Drawable [ ]
{
new DiffPiece ( stats ) ,
2023-06-29 04:55:03 +00:00
new DiffPiece ( ( "Star Rating" , $"{beatmap.StarRating:0.00}{srExtra}" ) )
2020-03-08 05:46:09 +00:00
}
} ,
new FillFlowContainer
{
RelativeSizeAxes = Axes . X ,
AutoSizeAxes = Axes . Y ,
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Direction = FillDirection . Vertical ,
Children = new Drawable [ ]
{
2021-07-31 07:46:02 +00:00
new DiffPiece ( ( "Length" , length . ToFormattedDuration ( ) . ToString ( ) ) ) ,
new DiffPiece ( ( "BPM" , $"{bpm:0.#}" ) ) ,
2020-03-08 05:46:09 +00:00
}
} ,
new Container
{
RelativeSizeAxes = Axes . Both ,
Children = new Drawable [ ]
{
new Box
{
Colour = Color4 . Black ,
RelativeSizeAxes = Axes . Both ,
Alpha = 0.1f ,
} ,
new OsuLogo
{
Triangles = false ,
Scale = new Vector2 ( 0.08f ) ,
Margin = new MarginPadding ( 50 ) ,
X = - 10 ,
Anchor = Anchor . CentreRight ,
Origin = Anchor . CentreRight ,
} ,
}
} ,
} ,
}
}
}
2018-11-06 10:23:03 +00:00
} ,
2023-08-21 06:33:58 +00:00
new TournamentBeatmapPanel ( beatmap )
2018-11-06 10:23:03 +00:00
{
2020-03-08 05:46:09 +00:00
RelativeSizeAxes = Axes . X ,
Width = 0.5f ,
2020-04-26 21:59:24 +00:00
Height = HEIGHT ,
2020-03-08 05:46:09 +00:00
Anchor = Anchor . BottomRight ,
Origin = Anchor . BottomRight ,
2018-11-06 10:23:03 +00:00
}
} ;
}
2018-11-22 08:25:46 +00:00
2022-11-24 05:32:20 +00:00
public partial class DiffPiece : TextFlowContainer
2018-11-22 08:25:46 +00:00
{
public DiffPiece ( params ( string heading , string content ) [ ] tuples )
{
Margin = new MarginPadding { Horizontal = 15 , Vertical = 1 } ;
AutoSizeAxes = Axes . Both ;
2020-03-08 05:46:09 +00:00
static void cp ( SpriteText s , bool bold )
2018-11-22 08:25:46 +00:00
{
2020-03-08 05:46:09 +00:00
s . Font = OsuFont . Torus . With ( weight : bold ? FontWeight . Bold : FontWeight . Regular , size : 15 ) ;
2018-11-22 08:25:46 +00:00
}
2021-10-27 04:04:41 +00:00
for ( int i = 0 ; i < tuples . Length ; i + + )
2018-11-22 08:25:46 +00:00
{
2021-10-27 04:04:41 +00:00
( string heading , string content ) = tuples [ i ] ;
2019-06-13 08:04:57 +00:00
if ( i > 0 )
{
2018-11-22 08:25:46 +00:00
AddText ( " / " , s = >
{
2020-03-08 05:46:09 +00:00
cp ( s , false ) ;
2018-11-22 08:25:46 +00:00
s . Spacing = new Vector2 ( - 2 , 0 ) ;
} ) ;
2019-06-13 08:04:57 +00:00
}
2018-11-22 08:25:46 +00:00
2020-03-08 05:46:09 +00:00
AddText ( new TournamentSpriteText { Text = heading } , s = > cp ( s , false ) ) ;
AddText ( " " , s = > cp ( s , false ) ) ;
AddText ( new TournamentSpriteText { Text = content } , s = > cp ( s , true ) ) ;
2018-11-22 08:25:46 +00:00
}
}
}
2018-11-06 10:23:03 +00:00
}
}