1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 05:53:21 +08:00
osu-lazer/osu.Game.Tournament/Screens/Ladder/Components/DrawableMatchTeam.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

207 lines
7.0 KiB
C#
Raw Normal View History

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.
using System;
using osu.Framework.Allocation;
2019-03-02 12:40:43 +08:00
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
2018-09-21 18:58:47 +08:00
using osu.Game.Graphics.UserInterface;
2018-08-26 00:24:19 +08:00
using osu.Game.Tournament.Components;
2019-06-18 13:51:48 +08:00
using osu.Game.Tournament.Models;
using osu.Game.Tournament.Screens.Editors;
using osuTK;
using osuTK.Graphics;
using osuTK.Input;
namespace osu.Game.Tournament.Screens.Ladder.Components
{
public partial class DrawableMatchTeam : DrawableTournamentTeam, IHasContextMenu
{
2019-06-18 13:57:05 +08:00
private readonly TournamentMatch match;
2018-09-25 02:55:24 +08:00
private readonly bool losers;
2023-07-25 19:50:55 +08:00
private TournamentSpriteText scoreText = null!;
private Box background = null!;
private Box backgroundRight = null!;
private readonly Bindable<int?> score = new Bindable<int?>();
private readonly BindableBool completed = new BindableBool();
private Color4 colourWinner;
2023-07-25 19:50:55 +08:00
private readonly Func<bool>? isWinner;
private LadderEditorScreen ladderEditor = null!;
2023-07-30 00:57:44 +08:00
[Resolved]
2023-07-25 19:50:55 +08:00
private LadderInfo? ladderInfo { get; set; }
2018-11-11 09:13:17 +08:00
private void setCurrent()
{
if (ladderInfo == null) return;
2018-11-11 09:13:17 +08:00
//todo: tournamentgamebase?
if (ladderInfo.CurrentMatch.Value != null)
ladderInfo.CurrentMatch.Value.Current.Value = false;
2019-06-18 13:57:05 +08:00
ladderInfo.CurrentMatch.Value = match;
2018-11-11 09:13:17 +08:00
ladderInfo.CurrentMatch.Value.Current.Value = true;
}
2023-07-30 00:57:44 +08:00
[Resolved]
2023-07-25 19:50:55 +08:00
private LadderEditorInfo? editorInfo { get; set; }
2018-09-22 04:52:25 +08:00
2023-07-25 19:50:55 +08:00
public DrawableMatchTeam(TournamentTeam? team, TournamentMatch match, bool losers)
: base(team)
{
2019-06-18 13:57:05 +08:00
this.match = match;
2018-09-25 02:55:24 +08:00
this.losers = losers;
Size = new Vector2(150, 40);
Flag.Scale = new Vector2(0.54f);
Flag.Anchor = Flag.Origin = Anchor.CentreLeft;
AcronymText.Anchor = AcronymText.Origin = Anchor.CentreLeft;
AcronymText.Padding = new MarginPadding { Left = 50 };
AcronymText.Font = OsuFont.Torus.With(size: 22, weight: FontWeight.Bold);
2023-07-25 19:50:55 +08:00
isWinner = () => match.Winner == Team;
2023-07-25 19:50:55 +08:00
completed.BindTo(match.Completed);
if (team != null)
score.BindTo(team == match.Team1.Value ? match.Team1Score : match.Team2Score);
}
[BackgroundDependencyLoader(true)]
2022-01-15 08:06:39 +08:00
private void load(LadderEditorScreen ladderEditor)
{
this.ladderEditor = ladderEditor;
colourWinner = losers
? Color4Extensions.FromHex("#8E7F48")
: Color4Extensions.FromHex("#1462AA");
InternalChildren = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
new Container
{
Padding = new MarginPadding(5),
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
AcronymText,
Flag,
}
},
new Container
{
Masking = true,
Width = 0.3f,
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
backgroundRight = new Box
{
Colour = OsuColour.Gray(0.1f),
Alpha = 0.8f,
RelativeSizeAxes = Axes.Both,
},
scoreText = new TournamentSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.Torus.With(size: 22),
}
}
}
};
completed.BindValueChanged(_ => updateWinStyle());
score.BindValueChanged(val =>
{
2019-03-02 12:40:43 +08:00
scoreText.Text = val.NewValue?.ToString() ?? string.Empty;
updateWinStyle();
}, true);
}
2018-11-07 00:20:32 +08:00
protected override bool OnClick(ClickEvent e)
{
if (Team == null || editorInfo != null) return false;
2019-06-18 13:57:05 +08:00
if (!match.Current.Value)
2018-11-07 00:20:32 +08:00
{
2018-11-11 09:13:17 +08:00
setCurrent();
2018-11-07 00:20:32 +08:00
return true;
}
if (e.Button == MouseButton.Left)
{
if (score.Value == null)
{
2019-06-18 13:57:05 +08:00
match.StartMatch();
}
2019-06-18 13:57:05 +08:00
else if (!match.Completed.Value)
score.Value++;
}
else
{
2019-06-18 13:57:05 +08:00
if (match.Progression.Value?.Completed.Value == true)
2018-09-25 01:31:48 +08:00
// don't allow changing scores if the match has a progression. can cause large data loss
return false;
2019-06-18 13:57:05 +08:00
if (match.Completed.Value && match.Winner != Team)
2018-09-25 02:14:30 +08:00
// don't allow changing scores from the non-winner
return false;
if (score.Value > 0)
score.Value--;
else
2019-06-18 13:57:05 +08:00
match.CancelMatchStart();
}
return false;
}
private void updateWinStyle()
{
2019-03-02 12:40:43 +08:00
bool winner = completed.Value && isWinner?.Invoke() == true;
background.FadeColour(winner ? Color4.White : Color4Extensions.FromHex("#444"), winner ? 500 : 0, Easing.OutQuint);
backgroundRight.FadeColour(winner ? colourWinner : Color4Extensions.FromHex("#333"), winner ? 500 : 0, Easing.OutQuint);
AcronymText.Colour = winner ? Color4.Black : Color4.White;
scoreText.Font = scoreText.Font.With(weight: winner ? FontWeight.Bold : FontWeight.Regular);
}
2018-09-22 04:52:25 +08:00
public MenuItem[] ContextMenuItems
{
2018-09-22 04:52:25 +08:00
get
{
if (editorInfo == null)
2019-11-28 21:41:29 +08:00
return Array.Empty<MenuItem>();
2018-09-22 04:52:25 +08:00
return new MenuItem[]
{
2018-11-11 09:13:17 +08:00
new OsuMenuItem("Set as current", MenuItemType.Standard, setCurrent),
2019-06-18 13:57:05 +08:00
new OsuMenuItem("Join with", MenuItemType.Standard, () => ladderEditor.BeginJoin(match, false)),
new OsuMenuItem("Join with (loser)", MenuItemType.Standard, () => ladderEditor.BeginJoin(match, true)),
new OsuMenuItem("Remove", MenuItemType.Destructive, () => ladderEditor.Remove(match)),
2018-09-22 04:52:25 +08:00
};
}
}
}
}