Skip to content

Commit

Permalink
Merge pull request #461 from DebugOk/Wizmerge-19/11
Browse files Browse the repository at this point in the history
Merge wizden up to 19/11
  • Loading branch information
DebugOk authored Nov 21, 2023
2 parents faef0c3 + 80857f3 commit 3d1827c
Show file tree
Hide file tree
Showing 307 changed files with 5,300 additions and 2,554 deletions.
3 changes: 2 additions & 1 deletion Content.Client/Gateway/UI/GatewayBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ protected override void Open()
{
base.Open();

_window = new GatewayWindow();
_window = new GatewayWindow(EntMan.GetNetEntity(Owner));

_window.OpenPortal += destination =>
{
SendMessage(new GatewayOpenPortalMessage(destination));
Expand Down
25 changes: 20 additions & 5 deletions Content.Client/Gateway/UI/GatewayWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@
Title="{Loc 'gateway-window-title'}"
MinSize="800 360">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<Label Name="NextCloseLabel"
Text="{Loc 'gateway-window-portal-closing'}"
Margin="5"></Label>
<ProgressBar Name="NextCloseBar"
<BoxContainer Orientation="Horizontal">
<!-- This is wide as shit but makes it consistent with the cooldown label +
handles localisations a bit better -->
<Label Name="NextUnlockLabel"
Text="{Loc 'gateway-window-portal-unlock'}"
Margin="5"
SetWidth="128"/>
<ProgressBar Name="NextUnlockBar"
HorizontalExpand="True"
MinValue="0"
MaxValue="1"
SetHeight="25"/>
<Label Name="NextUnlockText" Text="0" Margin="5"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Name="NextReadyLabel"
Text="{Loc 'gateway-window-portal-cooldown'}"
Margin="5"
SetWidth="128"/>
<ProgressBar Name="NextReadyBar"
HorizontalExpand="True"
MinValue="0"
MaxValue="1"
Expand Down
184 changes: 127 additions & 57 deletions Content.Client/Gateway/UI/GatewayWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Numerics;
using Content.Client.Computer;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Controls;
Expand All @@ -19,30 +20,55 @@ public sealed partial class GatewayWindow : FancyWindow,
private readonly IGameTiming _timing;

public event Action<NetEntity>? OpenPortal;
private List<(NetEntity, string, TimeSpan, bool)> _destinations = default!;
private List<GatewayDestinationData> _destinations = new();

public readonly NetEntity Owner;

private NetEntity? _current;
private TimeSpan _nextClose;
private TimeSpan _lastOpen;
private List<Label> _readyLabels = default!;
private List<Button> _openButtons = default!;
private TimeSpan _nextReady;
private TimeSpan _cooldown;

private TimeSpan _unlockTime;
private TimeSpan _nextUnlock;

/// <summary>
/// Re-apply the state if the timer has elapsed.
/// </summary>
private GatewayBoundUserInterfaceState? _lastState;

public GatewayWindow()
/// <summary>
/// Are we currently waiting on an unlock timer.
/// </summary>
private bool _isUnlockPending = true;

/// <summary>
/// Are we currently waiting on a cooldown timer.
/// </summary>
private bool _isCooldownPending = true;

public GatewayWindow(NetEntity netEntity)
{
RobustXamlLoader.Load(this);
var dependencies = IoCManager.Instance!;
_timing = dependencies.Resolve<IGameTiming>();
Owner = netEntity;

NextUnlockBar.ForegroundStyleBoxOverride = new StyleBoxFlat(Color.FromHex("#C74EBD"));
}

public void UpdateState(GatewayBoundUserInterfaceState state)
{
_destinations = state.Destinations;
_current = state.Current;
_nextClose = state.NextClose;
_lastOpen = state.LastOpen;
_nextReady = state.NextReady;
_cooldown = state.Cooldown;
_unlockTime = state.UnlockTime;
_nextUnlock = state.NextUnlock;

_isUnlockPending = _nextUnlock >= _timing.CurTime;
_isCooldownPending = _nextReady >= _timing.CurTime;

Container.DisposeAllChildren();
_readyLabels = new List<Label>(_destinations.Count);
_openButtons = new List<Button>(_destinations.Count);

if (_destinations.Count == 0)
{
Expand All @@ -63,60 +89,86 @@ public void UpdateState(GatewayBoundUserInterfaceState state)
}

var now = _timing.CurTime;

foreach (var dest in _destinations)
{
var ent = dest.Item1;
var name = dest.Item2;
var nextReady = dest.Item3;
var busy = dest.Item4;
var ent = dest.Entity;
var name = dest.Name;
var locked = dest.Locked && _nextUnlock > _timing.CurTime;

var box = new BoxContainer()
{
Orientation = BoxContainer.LayoutOrientation.Horizontal,
Margin = new Thickness(5f, 5f)
Margin = new Thickness(5f, 5f),
};

// HOW DO I ALIGN THESE GOODER
var nameLabel = new RichTextLabel()
{
VerticalAlignment = VAlignment.Center,
SetWidth = 156f,
};

box.AddChild(new Label()
nameLabel.SetMessage(name);
box.AddChild(nameLabel);
// Buffer
box.AddChild(new Control()
{
Text = name
HorizontalExpand = true,
});

var readyLabel = new Label
bool Pressable() => ent == _current || ent == Owner;

var buttonStripe = new StripeBack()
{
Text = ReadyText(now, nextReady, busy),
Margin = new Thickness(10f, 0f, 0f, 0f)
Visible = locked,
HorizontalExpand = true,
VerticalExpand = true,
Margin = new Thickness(10f, 0f, 0f, 0f),
Children =
{
new Label()
{
Text = Loc.GetString("gateway-window-locked"),
HorizontalAlignment = HAlignment.Center,
VerticalAlignment = VAlignment.Center,
}
}
};
_readyLabels.Add(readyLabel);
box.AddChild(readyLabel);

var openButton = new Button()
{
Text = Loc.GetString("gateway-window-open-portal"),
Pressed = ent == _current,
Pressed = Pressable(),
ToggleMode = true,
Disabled = _current != null || busy || now < nextReady
Disabled = now < _nextReady || Pressable(),
HorizontalAlignment = HAlignment.Right,
Margin = new Thickness(10f, 0f, 0f, 0f),
Visible = !locked,
SetHeight = 32f,
};

openButton.OnPressed += args =>
{
OpenPortal?.Invoke(ent);
};

if (ent == _current)
if (Pressable())
{
openButton.AddStyleClass(StyleBase.ButtonCaution);
}

_openButtons.Add(openButton);
box.AddChild(new BoxContainer()
var buttonContainer = new BoxContainer()
{
HorizontalExpand = true,
Align = BoxContainer.AlignMode.End,
Children =
{
openButton
}
});
buttonStripe,
openButton,
},
SetSize = new Vector2(128f, 40f),
};

box.AddChild(buttonContainer);

Container.AddChild(new PanelContainer()
{
Expand All @@ -128,57 +180,75 @@ public void UpdateState(GatewayBoundUserInterfaceState state)
}
});
}

_lastState = state;
}

protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);

var now = _timing.CurTime;
var dirtyState = false;

// if its not going to close then show it as empty
if (_current == null)
if (_nextUnlock == TimeSpan.Zero)
{
NextCloseBar.Value = 0f;
NextCloseText.Text = "00:00";
NextUnlockBar.Value = 1f;
NextUnlockText.Text = "00:00";
}
else
{
var remaining = _nextClose - _timing.CurTime;
var remaining = _nextUnlock - now;
if (remaining < TimeSpan.Zero)
{
NextCloseBar.Value = 1f;
NextCloseText.Text = "00:00";
if (_isUnlockPending)
{
dirtyState = true;
_isUnlockPending = false;
}

NextUnlockBar.Value = 1f;
NextUnlockText.Text = "00:00";
}
else
{
var openTime = _nextClose - _lastOpen;
NextCloseBar.Value = 1f - (float) (remaining / openTime);
NextCloseText.Text = $"{remaining.Minutes:00}:{remaining.Seconds:00}";
NextUnlockBar.Value = 1f - (float) (remaining.TotalSeconds / _unlockTime.TotalSeconds);
NextUnlockText.Text = $"{remaining.Minutes:00}:{remaining.Seconds:00}";
}
}

for (var i = 0; i < _destinations.Count; i++)
// if its not going to close then show it as empty
if (_current == null || _cooldown == TimeSpan.Zero)
{
var dest = _destinations[i];
var nextReady = dest.Item3;
var busy = dest.Item4;
_readyLabels[i].Text = ReadyText(now, nextReady, busy);
_openButtons[i].Disabled = _current != null || busy || now < nextReady;
NextReadyBar.Value = 1f;
NextCloseText.Text = "00:00";
}
}
else
{
var remaining = _nextReady - now;
if (remaining < TimeSpan.Zero)
{
if (_isCooldownPending)
{
dirtyState = true;
_isCooldownPending = false;
}

private string ReadyText(TimeSpan now, TimeSpan nextReady, bool busy)
{
if (busy)
return Loc.GetString("gateway-window-already-active");
NextReadyBar.Value = 1f;
NextCloseText.Text = "00:00";
}
else
{
NextReadyBar.Value = 1f - (float) (remaining.TotalSeconds / _cooldown.TotalSeconds);
NextCloseText.Text = $"{remaining.Minutes:00}:{remaining.Seconds:00}";
}
}

if (now < nextReady)
if (dirtyState && _lastState != null)
{
var time = nextReady - now;
return Loc.GetString("gateway-window-ready-in", ("time", $"{time.Minutes:00}:{time.Seconds:00}"));
// Refresh UI buttons.
UpdateState(_lastState);
}

return Loc.GetString("gateway-window-ready");
}
}
5 changes: 0 additions & 5 deletions Content.Client/Input/ContentContexts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ public static void SetupContexts(IInputContextContainer contexts)
common.AddFunction(boundKey);
}

foreach (var boundKey in ContentKeyFunctions.GetLoadoutBoundKeys())
{
common.AddFunction(boundKey);
}

var aghost = contexts.New("aghost", "common");
aghost.AddFunction(EngineKeyFunctions.MoveUp);
aghost.AddFunction(EngineKeyFunctions.MoveDown);
Expand Down
4 changes: 0 additions & 4 deletions Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,6 @@ void AddCheckBox(string checkBoxName, bool currentState, Action<BaseButton.Butto
{
AddButton(boundKey);
}
foreach (var boundKey in ContentKeyFunctions.GetLoadoutBoundKeys())
{
AddButton(boundKey);
}

AddHeader("ui-options-header-shuttle");
AddButton(ContentKeyFunctions.ShuttleStrafeUp);
Expand Down
Loading

0 comments on commit 3d1827c

Please sign in to comment.