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-08-26 00:14:18 +08:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
2019-03-02 12:40:43 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-03-11 09:18:41 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2018-08-26 00:14:18 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-09-10 03:51:38 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2018-08-26 00:14:18 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-09-10 03:51:38 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-12 17:49:47 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2018-08-26 00:14:18 +08:00
|
|
|
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;
|
2018-11-22 09:25:30 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
using osuTK.Input;
|
2018-08-26 00:14:18 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tournament.Screens.Ladder.Components
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class DrawableMatchTeam : DrawableTournamentTeam, IHasContextMenu
|
2018-08-26 00:14:18 +08:00
|
|
|
{
|
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!;
|
2018-08-26 00:14:18 +08:00
|
|
|
|
|
|
|
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!;
|
2018-08-26 00:14:18 +08:00
|
|
|
|
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()
|
|
|
|
{
|
2020-03-08 18:41:22 +08:00
|
|
|
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)
|
2018-08-26 00:14:18 +08:00
|
|
|
: base(team)
|
|
|
|
{
|
2019-06-18 13:57:05 +08:00
|
|
|
this.match = match;
|
2018-09-25 02:55:24 +08:00
|
|
|
this.losers = losers;
|
2018-08-26 00:14:18 +08:00
|
|
|
Size = new Vector2(150, 40);
|
|
|
|
|
2020-10-26 13:27:55 +08:00
|
|
|
Flag.Scale = new Vector2(0.54f);
|
2018-08-26 00:14:18 +08:00
|
|
|
Flag.Anchor = Flag.Origin = Anchor.CentreLeft;
|
|
|
|
|
|
|
|
AcronymText.Anchor = AcronymText.Origin = Anchor.CentreLeft;
|
|
|
|
AcronymText.Padding = new MarginPadding { Left = 50 };
|
2020-03-07 00:37:15 +08:00
|
|
|
AcronymText.Font = OsuFont.Torus.With(size: 22, weight: FontWeight.Bold);
|
2018-08-26 00:14:18 +08:00
|
|
|
|
2023-07-25 19:50:55 +08:00
|
|
|
isWinner = () => match.Winner == Team;
|
2018-08-26 00:14:18 +08:00
|
|
|
|
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);
|
2018-08-26 00:14:18 +08:00
|
|
|
}
|
|
|
|
|
2018-09-10 03:51:38 +08:00
|
|
|
[BackgroundDependencyLoader(true)]
|
2022-01-15 08:06:39 +08:00
|
|
|
private void load(LadderEditorScreen ladderEditor)
|
2018-08-26 00:14:18 +08:00
|
|
|
{
|
2018-11-16 19:14:34 +08:00
|
|
|
this.ladderEditor = ladderEditor;
|
2018-09-10 03:51:38 +08:00
|
|
|
|
2020-03-07 00:37:15 +08:00
|
|
|
colourWinner = losers
|
2020-03-11 09:18:41 +08:00
|
|
|
? Color4Extensions.FromHex("#8E7F48")
|
|
|
|
: Color4Extensions.FromHex("#1462AA");
|
2018-08-26 00:14:18 +08:00
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
background = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Padding = new MarginPadding(5),
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
AcronymText,
|
|
|
|
Flag,
|
2020-03-07 00:37:15 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Masking = true,
|
|
|
|
Width = 0.3f,
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
backgroundRight = new Box
|
2018-08-26 00:14:18 +08:00
|
|
|
{
|
2020-03-07 00:37:15 +08:00
|
|
|
Colour = OsuColour.Gray(0.1f),
|
|
|
|
Alpha = 0.8f,
|
2018-08-26 00:14:18 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-03-07 00:37:15 +08:00
|
|
|
},
|
|
|
|
scoreText = new TournamentSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.Torus.With(size: 22),
|
2018-08-26 00:14:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
completed.BindValueChanged(_ => updateWinStyle());
|
|
|
|
|
|
|
|
score.BindValueChanged(val =>
|
|
|
|
{
|
2019-03-02 12:40:43 +08:00
|
|
|
scoreText.Text = val.NewValue?.ToString() ?? string.Empty;
|
2018-08-26 00:14:18 +08:00
|
|
|
updateWinStyle();
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
2018-11-07 00:20:32 +08:00
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-08-26 18:11:46 +08:00
|
|
|
{
|
2018-11-16 19:14:34 +08:00
|
|
|
if (Team == null || editorInfo != null) return false;
|
2018-08-26 18:11:46 +08:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-10-12 17:49:47 +08:00
|
|
|
if (e.Button == MouseButton.Left)
|
2018-08-26 18:11:46 +08:00
|
|
|
{
|
|
|
|
if (score.Value == null)
|
|
|
|
{
|
2019-06-18 13:57:05 +08:00
|
|
|
match.StartMatch();
|
2018-08-26 18:11:46 +08:00
|
|
|
}
|
2019-06-18 13:57:05 +08:00
|
|
|
else if (!match.Completed.Value)
|
2018-08-26 18:11:46 +08:00
|
|
|
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;
|
|
|
|
|
2018-08-26 18:11:46 +08:00
|
|
|
if (score.Value > 0)
|
|
|
|
score.Value--;
|
|
|
|
else
|
2019-06-18 13:57:05 +08:00
|
|
|
match.CancelMatchStart();
|
2018-08-26 18:11:46 +08:00
|
|
|
}
|
|
|
|
|
2018-09-10 03:51:38 +08:00
|
|
|
return false;
|
2018-08-26 18:11:46 +08:00
|
|
|
}
|
|
|
|
|
2018-08-26 00:14:18 +08:00
|
|
|
private void updateWinStyle()
|
|
|
|
{
|
2019-03-02 12:40:43 +08:00
|
|
|
bool winner = completed.Value && isWinner?.Invoke() == true;
|
2018-08-26 00:14:18 +08:00
|
|
|
|
2020-03-11 09:18:41 +08:00
|
|
|
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);
|
2020-03-07 00:37:15 +08:00
|
|
|
|
|
|
|
AcronymText.Colour = winner ? Color4.Black : Color4.White;
|
2018-08-26 00:14:18 +08:00
|
|
|
|
2020-03-07 00:37:15 +08:00
|
|
|
scoreText.Font = scoreText.Font.With(weight: winner ? FontWeight.Bold : FontWeight.Regular);
|
2018-08-26 00:14:18 +08:00
|
|
|
}
|
2018-09-10 03:51:38 +08:00
|
|
|
|
2018-09-22 04:52:25 +08:00
|
|
|
public MenuItem[] ContextMenuItems
|
2018-09-10 03:51:38 +08:00
|
|
|
{
|
2018-09-22 04:52:25 +08:00
|
|
|
get
|
|
|
|
{
|
2018-11-16 19:14:34 +08:00
|
|
|
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
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2018-09-10 03:51:38 +08:00
|
|
|
}
|
2018-08-26 00:14:18 +08:00
|
|
|
}
|