2019-03-04 12:24:19 +08: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 18:23:03 +08:00
2018-11-22 16:25:46 +08:00
using System ;
2018-11-06 18:23:03 +08:00
using osu.Framework.Allocation ;
2019-11-23 19:52:41 +08:00
using osu.Framework.Bindables ;
2018-11-06 18:23:03 +08:00
using osu.Framework.Graphics ;
using osu.Framework.Graphics.Containers ;
2020-06-28 19:14:46 +08:00
using osu.Framework.Graphics.Primitives ;
2018-11-06 18:23:03 +08:00
using osu.Framework.Graphics.Shapes ;
2018-11-22 16:25:46 +08:00
using osu.Framework.Graphics.Sprites ;
2018-11-06 18:23:03 +08:00
using osu.Game.Beatmaps ;
using osu.Game.Beatmaps.Legacy ;
using osu.Game.Graphics ;
2019-11-23 19:52:41 +08:00
using osu.Game.Rulesets ;
2018-11-06 18:23:03 +08:00
using osu.Game.Screens.Menu ;
2018-11-22 09:25:30 +08:00
using osuTK ;
using osuTK.Graphics ;
2018-11-06 18:23:03 +08:00
namespace osu.Game.Tournament.Components
{
public class SongBar : CompositeDrawable
{
private BeatmapInfo beatmap ;
2020-04-27 05:59:24 +08:00
public const float HEIGHT = 145 / 2f ;
2020-03-08 13:46:09 +08:00
2019-11-23 19:52:41 +08:00
[Resolved]
private IBindable < RulesetInfo > ruleset { get ; set ; }
2018-11-06 18:23:03 +08:00
public BeatmapInfo Beatmap
{
get = > beatmap ;
set
{
if ( beatmap = = value )
return ;
beatmap = value ;
update ( ) ;
}
}
private LegacyMods mods ;
public LegacyMods Mods
{
get = > mods ;
set
{
mods = value ;
update ( ) ;
}
}
2020-03-08 13:46:09 +08:00
private FillFlowContainer flow ;
2018-11-11 00:29:42 +08:00
2018-11-16 17:14:42 +08:00
private bool expanded ;
2018-11-11 00:29:42 +08:00
public bool Expanded
{
2018-11-16 17:14:42 +08:00
get = > expanded ;
2018-11-11 00:29:42 +08:00
set
{
2018-11-16 17:14:42 +08:00
expanded = value ;
2020-03-08 13:46:09 +08:00
flow . Direction = expanded ? FillDirection . Full : FillDirection . Vertical ;
2018-11-11 00:29:42 +08:00
}
}
2020-06-28 19:14:46 +08: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 18:23:03 +08:00
[BackgroundDependencyLoader]
private void load ( )
{
2020-03-08 13:46:09 +08:00
RelativeSizeAxes = Axes . X ;
AutoSizeAxes = Axes . Y ;
2018-11-06 18:23:03 +08:00
InternalChildren = new Drawable [ ]
{
2020-03-08 13:46:09 +08:00
flow = new FillFlowContainer
2018-11-06 18:23:03 +08:00
{
RelativeSizeAxes = Axes . X ,
2020-03-08 13:46:09 +08:00
AutoSizeAxes = Axes . Y ,
LayoutDuration = 500 ,
LayoutEasing = Easing . OutQuint ,
Direction = FillDirection . Full ,
2018-11-11 00:29:42 +08:00
Anchor = Anchor . BottomRight ,
Origin = Anchor . BottomRight ,
2018-11-06 18:23:03 +08:00
}
} ;
2018-11-22 12:17:51 +08:00
Expanded = true ;
2018-11-06 18:23:03 +08:00
}
private void update ( )
{
if ( beatmap = = null )
{
2020-03-08 13:46:09 +08:00
flow . Clear ( ) ;
2018-11-06 18:23:03 +08:00
return ;
}
2019-07-08 15:43:35 +08:00
var bpm = beatmap . BeatmapSet . OnlineInfo . BPM ;
2019-07-08 01:25:36 +08:00
var length = beatmap . Length ;
2018-11-22 13:10:33 +08:00
string hardRockExtra = "" ;
string srExtra = "" ;
2018-11-06 18:23:03 +08:00
2019-11-23 19:52:41 +08:00
var ar = beatmap . BaseDifficulty . ApproachRate ;
2018-11-22 13:10:33 +08:00
if ( ( mods & LegacyMods . HardRock ) > 0 )
{
hardRockExtra = "*" ;
srExtra = "*" ;
}
2018-11-06 18:23:03 +08:00
if ( ( mods & LegacyMods . DoubleTime ) > 0 )
{
2019-11-23 23:21:34 +08:00
// temporary local calculation (taken from OsuDifficultyCalculator)
double preempt = ( int ) BeatmapDifficulty . DifficultyRange ( ar , 1800 , 1200 , 450 ) / 1.5 ;
ar = ( float ) ( preempt > 1200 ? ( 1800 - preempt ) / 120 : ( 1200 - preempt ) / 150 + 5 ) ;
2018-11-06 18:23:03 +08:00
bpm * = 1.5f ;
length / = 1.5f ;
2018-11-22 13:10:33 +08:00
srExtra = "*" ;
2018-11-06 18:23:03 +08:00
}
2019-11-23 19:52:41 +08:00
( string heading , string content ) [ ] stats ;
switch ( ruleset . Value . ID )
{
default :
stats = new ( string heading , string content ) [ ]
{
( "CS" , $"{beatmap.BaseDifficulty.CircleSize:0.#}{hardRockExtra}" ) ,
2019-11-24 00:45:21 +08:00
( "AR" , $"{ar:0.#}{hardRockExtra}" ) ,
2019-11-23 19:52:41 +08:00
( "OD" , $"{beatmap.BaseDifficulty.OverallDifficulty:0.#}{hardRockExtra}" ) ,
} ;
break ;
case 1 :
case 3 :
stats = new ( string heading , string content ) [ ]
{
( "OD" , $"{beatmap.BaseDifficulty.OverallDifficulty:0.#}{hardRockExtra}" ) ,
( "HP" , $"{beatmap.BaseDifficulty.DrainRate:0.#}{hardRockExtra}" )
} ;
break ;
case 2 :
stats = new ( string heading , string content ) [ ]
{
( "CS" , $"{beatmap.BaseDifficulty.CircleSize:0.#}{hardRockExtra}" ) ,
2019-11-24 00:45:21 +08:00
( "AR" , $"{ar:0.#}" ) ,
2019-11-23 19:52:41 +08:00
} ;
break ;
}
2020-03-08 13:46:09 +08:00
flow . Children = new Drawable [ ]
2018-11-06 18:23:03 +08:00
{
2020-03-08 13:46:09 +08:00
new Container
2018-11-06 18:23:03 +08:00
{
2020-03-08 13:46:09 +08:00
RelativeSizeAxes = Axes . X ,
2020-04-27 05:59:24 +08:00
Height = HEIGHT ,
2020-03-08 13:46:09 +08: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 ) ,
new DiffPiece ( ( "Star Rating" , $"{beatmap.StarDifficulty:0.#}{srExtra}" ) )
}
} ,
new FillFlowContainer
{
RelativeSizeAxes = Axes . X ,
AutoSizeAxes = Axes . Y ,
Anchor = Anchor . Centre ,
Origin = Anchor . Centre ,
Direction = FillDirection . Vertical ,
Children = new Drawable [ ]
{
new DiffPiece ( ( "Length" , TimeSpan . FromMilliseconds ( length ) . ToString ( @"mm\:ss" ) ) ) ,
new DiffPiece ( ( "BPM" , $"{bpm:0.#}" ) )
}
} ,
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 18:23:03 +08:00
} ,
2020-03-08 13:46:09 +08:00
new TournamentBeatmapPanel ( beatmap )
2018-11-06 18:23:03 +08:00
{
2020-03-08 13:46:09 +08:00
RelativeSizeAxes = Axes . X ,
Width = 0.5f ,
2020-04-27 05:59:24 +08:00
Height = HEIGHT ,
2020-03-08 13:46:09 +08:00
Anchor = Anchor . BottomRight ,
Origin = Anchor . BottomRight ,
2018-11-06 18:23:03 +08:00
}
} ;
}
2018-11-22 16:25:46 +08:00
public class DiffPiece : TextFlowContainer
{
public DiffPiece ( params ( string heading , string content ) [ ] tuples )
{
Margin = new MarginPadding { Horizontal = 15 , Vertical = 1 } ;
AutoSizeAxes = Axes . Both ;
2020-03-08 13:46:09 +08:00
static void cp ( SpriteText s , bool bold )
2018-11-22 16:25:46 +08:00
{
2020-03-08 13:46:09 +08:00
s . Font = OsuFont . Torus . With ( weight : bold ? FontWeight . Bold : FontWeight . Regular , size : 15 ) ;
2018-11-22 16:25:46 +08:00
}
2019-06-13 16:04:57 +08:00
for ( var i = 0 ; i < tuples . Length ; i + + )
2018-11-22 16:25:46 +08:00
{
2019-11-12 18:19:48 +08:00
var ( heading , content ) = tuples [ i ] ;
2019-06-13 16:04:57 +08:00
if ( i > 0 )
{
2018-11-22 16:25:46 +08:00
AddText ( " / " , s = >
{
2020-03-08 13:46:09 +08:00
cp ( s , false ) ;
2018-11-22 16:25:46 +08:00
s . Spacing = new Vector2 ( - 2 , 0 ) ;
} ) ;
2019-06-13 16:04:57 +08:00
}
2018-11-22 16:25:46 +08:00
2020-03-08 13:46:09 +08: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 16:25:46 +08:00
}
}
}
2018-11-06 18:23:03 +08:00
}
}