Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ internal class elmHud_Window : HudElementBase
private bool _matchEnded;
private readonly MatchTimer _timer;

private readonly LabelBox _timerLabel;
internal readonly LabelBox _timerLabel;
internal LabelBox _winnerLabel;
public EliminationHud_TeamBanner[] Banners;

public elmHud_Window(HudParentBase parent, EliminationGamemode gamemode) : base(parent)
Expand Down Expand Up @@ -136,7 +137,7 @@ public void MatchEnded(IMyFaction winner)
if (_timerLabel == null)
return;

var winnerLabel = new LabelBox(_timerLabel)
_winnerLabel = new LabelBox(_timerLabel)
{
Text = winner != null
? $"A WINNER IS {winner.Name}. {winnerPoints} tickets remaining."
Expand All @@ -147,7 +148,7 @@ public void MatchEnded(IMyFaction winner)
Color = HudConstants.HudBackgroundColor
};

winnerLabel.TextBoard.SetFormatting(GlyphFormat.White.WithColor(Color.Red).WithSize(3)
_winnerLabel.TextBoard.SetFormatting(GlyphFormat.White.WithColor(Color.Red).WithSize(3)
.WithAlignment(TextAlignment.Center));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using Sandbox.ModAPI;
using SC.SUGMA.GameModes.Elimination;
using SC.SUGMA.GameState;
using SC.SUGMA.Utilities;
using VRage.Game.ModAPI;
using VRageMath;

namespace SC.SUGMA.GameModes.KOTH
{
internal partial class KOTHGamemode : EliminationGamemode
{
public KOTHSphereZone ControlPoint;

private Vector3D _controlPointPosition = new Vector3D(0, 0, 0);
private float _controlPointRadius = 2500f;

private int ActivationTime = 300;
public int ActivationTimeCounter = 0;

private int WinTime = 120;

public override string ReadableName { get; internal set; } = "King Of The Hill";

public override string Description { get; internal set; } =
"Factions fight over a Central Capture Point. Either spend 2 minutes uncontested in the center zone, or eliminate the enemy team to win.";

public KOTHGamemode()
{
ArgumentParser += new ArgumentParser(
new ArgumentParser.ArgumentDefinition(
text => ActivationTime = int.Parse(text),
"at", "activation-time",
$"Delay before Center Zone is Capturable, in Seconds"
),
new ArgumentParser.ArgumentDefinition(
text => WinTime = int.Parse(text),
"wt", "win-time",
"How long a team has to hold the zone uncontested to win, in Seconds"
)
);
}

public override void StartRound(string[] arguments = null)
{
base.StartRound(arguments);

if (TrackedFactions.Count <= 1)
return;

ActivationTimeCounter = ActivationTime;
ControlPoint = null;

if (!MyAPIGateway.Utilities.IsDedicated)
SUGMA_SessionComponent.I.RegisterComponent("KOTHHud", new KOTHHud(this));
}

public override void StopRound()
{
base.StopRound();

SUGMA_SessionComponent.I.GetComponent<KOTHHud>("KOTHHud")?.MatchEnded(ControlPoint._zoneOwner);
SUGMA_SessionComponent.I.UnregisterComponent("KOTHHud");

ControlPoint = null;
SUGMA_SessionComponent.I.UnregisterComponent("KOTHZone");
}

internal override void DisplayWinMessage()
{
if (ControlPoint._zoneOwner == null)
{
MyAPIGateway.Utilities.ShowNotification("YOU ARE ALL LOSERS.", 10000, "Red");
return;
}

MyAPIGateway.Utilities.ShowNotification($"A WINNER IS [{ControlPoint._zoneOwner?.Name}]!", 10000);
}

public override void UpdateActive()
{
if (ActivationTimeCounter > 0)
{
if (_matchTimer.Ticks % 60 == 0)
{
ActivationTimeCounter--;

if (ActivationTimeCounter <= 0)
{
ControlPoint = new KOTHSphereZone(_controlPointPosition, _controlPointRadius, WinTime);
SUGMA_SessionComponent.I.RegisterComponent("KOTHZone", ControlPoint);
}
}
}

if (ControlPoint == null)
return;

if (ControlPoint.IsCaptured)
{
StopRound();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using RichHudFramework;
using RichHudFramework.Client;
using RichHudFramework.UI;
using RichHudFramework.UI.Client;
using RichHudFramework.UI.Rendering;
using SC.SUGMA.GameModes.Elimination;
using SC.SUGMA.GameState;
using SC.SUGMA.Utilities;
using VRage.Game.ModAPI;
using VRage.Utils;
using VRageMath;

namespace SC.SUGMA.GameModes.KOTH
{
internal class KOTHHud : ComponentBase
{
private readonly KOTHGamemode _gamemode;
private KOTHHud_Window _window;

public KOTHHud(KOTHGamemode gamemode)
{
_gamemode = gamemode;
}

public override void Init(string id)
{
base.Init(id);

if (!RichHudClient.Registered)
throw new Exception("RichHudAPI was not initialized in time!");

_window = new KOTHHud_Window(HudMain.HighDpiRoot, _gamemode);
}

public override void Close()
{
HudMain.HighDpiRoot.RemoveChild(_window);
}

public override void UpdateTick()
{
if (SUGMA_SessionComponent.I.CurrentGamemode != null)
_window.Update();
}

public void MatchEnded(IMyFaction winner)
{
_window.MatchEnded(winner);
}
}

internal class KOTHHud_Window : WindowBase
{
private static readonly Material _circleMaterial =
new Material(MyStringId.GetOrCompute("SugmaCircle"), new Vector2(32, 32));

private readonly KOTHGamemode _gamemode;
private readonly elmHud_Window _windowBase;

private TexturedBox _captureIndicator;

private Label _captureLabel;

public KOTHHud_Window(HudParentBase parent, KOTHGamemode gamemode) : base(parent)
{
_gamemode = gamemode;
_windowBase = SUGMA_SessionComponent.I.GetComponent<EliminationHud>("elmHud").Window;

_captureIndicator = new TexturedBox(_windowBase)
{
Material = _circleMaterial,
ParentAlignment = ParentAlignments.Bottom | ParentAlignments.Center,
Size = Vector2.One * 64,
Offset = new Vector2(0, -15),
ZOffset = sbyte.MaxValue
};

_captureLabel = new Label(_captureIndicator)
{
ParentAlignment = ParentAlignments.Center,
Offset = new Vector2(0, -55),
Text = "Initializing KOTH..."
};

foreach (var banner in _windowBase.Banners)
{
banner.Visible = false;
}
}

public void Update()
{
if (_gamemode.ControlPoint == null)
{
int timeLeft = Math.Max(0, _gamemode.ActivationTimeCounter);
if (timeLeft > 0)
{
_captureIndicator.Color = Color.White;
_captureLabel.Text = $"Zone Locked: {timeLeft}s";
}
else
{
_captureIndicator.Color = Color.White;
_captureLabel.Text = "Waiting for zone creation...";
}
return;
}

var zone = _gamemode.ControlPoint;

bool isActivelyCapturing = zone.ActiveCapturingFaction != null && zone.CaptureTimeCurrent > 0f;
Color capturingColor = isActivelyCapturing
? zone.ActiveCapturingFaction.CustomColor.ColorMaskToRgb()
: Color.White;

_captureIndicator.Color = capturingColor.SetAlphaPct(0.5f);

float current = zone.CaptureTimeCurrent;
float total = zone.CaptureTime;

if (!isActivelyCapturing && current > 0f)
{
_captureIndicator.Color = Color.White.SetAlphaPct(0.5f);
}

_captureLabel.Text = $"Capturing: {current:0.0}s / {total:0.0}s";
}

public void MatchEnded(IMyFaction winner)
{
_captureIndicator.Visible = false;
_captureLabel.Visible = false;

_windowBase._winnerLabel.Visible = false;
_windowBase._winnerLabel = new LabelBox(_windowBase._timerLabel)
{
Text = winner != null
? $"A WINNER IS {winner.Name}"
: "YOU ARE ALL LOSERS",
ParentAlignment = ParentAlignments.Bottom,
Height = EliminationHud_TeamBanner.BaseHeight,
TextPadding = new Vector2(2.5f, 0),
Color = HudConstants.HudBackgroundColor
};
_windowBase._winnerLabel.Visible = true;

_windowBase._winnerLabel.TextBoard.SetFormatting(GlyphFormat.White.WithColor(Color.Red).WithSize(3)
.WithAlignment(TextAlignment.Center));
}
}
}
Loading