Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin-Tel committed Oct 9, 2023
2 parents d1d7c28 + 367c251 commit 158e16e
Show file tree
Hide file tree
Showing 65 changed files with 557 additions and 281 deletions.
1 change: 0 additions & 1 deletion Content.Client/Actions/ActionsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public sealed class ActionsSystem : SharedActionsSystem

public event Action<EntityUid>? OnActionAdded;
public event Action<EntityUid>? OnActionRemoved;
public event OnActionReplaced? ActionReplaced;
public event Action? ActionsUpdated;
public event Action<ActionsComponent>? LinkActions;
public event Action? UnlinkActions;
Expand Down
14 changes: 11 additions & 3 deletions Content.Client/PDA/Ringer/RingerBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Content.Shared.PDA;
using Content.Shared.PDA.Ringer;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.Timing;

namespace Content.Client.PDA.Ringer
{
Expand Down Expand Up @@ -29,9 +29,17 @@ protected override void Open()

_menu.SetRingerButton.OnPressed += _ =>
{
if (!TryGetRingtone(out var ringtone)) return;
if (!TryGetRingtone(out var ringtone))
return;
SendMessage(new RingerSetRingtoneMessage(ringtone));
_menu.SetRingerButton.Disabled = true;
Timer.Spawn(333, () =>
{
if (_menu is { Disposed: false, SetRingerButton: { Disposed: false } ringer})
ringer.Disabled = false;
});
};
}

Expand Down Expand Up @@ -74,7 +82,7 @@ protected override void UpdateState(BoundUserInterfaceState state)

}

_menu.TestRingerButton.Visible = !msg.IsPlaying;
_menu.TestRingerButton.Disabled = msg.IsPlaying;
}


Expand Down
6 changes: 4 additions & 2 deletions Content.Client/PDA/Ringer/RingtoneMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@
Access="Public"
Text="{Loc 'comp-ringer-ui-test-ringtone-button'}"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
VerticalAlignment="Center"
StyleClasses="OpenRight" />
<Button Name = "SetRingerButton"
Access="Public"
Text="{Loc 'comp-ringer-ui-set-ringtone-button'}"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
VerticalAlignment="Center"
StyleClasses="OpenLeft" />
</BoxContainer>
</PanelContainer>
</BoxContainer>
Expand Down
24 changes: 0 additions & 24 deletions Content.Client/UserInterface/Controls/RecordedSplitContainer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Numerics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input;

namespace Content.Client.UserInterface.Controls;

Expand All @@ -10,8 +8,6 @@ namespace Content.Client.UserInterface.Controls;
/// </summary>
public sealed class RecordedSplitContainer : SplitContainer
{
public Action<Vector2, Vector2>? OnSplitResizeFinish;

public double? DesiredSplitCenter;

protected override Vector2 ArrangeOverride(Vector2 finalSize)
Expand All @@ -30,24 +26,4 @@ protected override Vector2 ArrangeOverride(Vector2 finalSize)

return base.ArrangeOverride(finalSize);
}

protected override void KeyBindUp(GUIBoundKeyEventArgs args)
{
base.KeyBindUp(args);

if (args.Function != EngineKeyFunctions.UIClick)
{
return;
}

if (ChildCount != 2)
{
return;
}

var first = GetChild(0);
var second = GetChild(1);

OnSplitResizeFinish?.Invoke(first.Size, second.Size);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public SeparatedChatGameScreen()
SetAnchorAndMarginPreset(Hotbar, LayoutPreset.BottomWide, margin: 5);
SetAnchorAndMarginPreset(Alerts, LayoutPreset.CenterRight, margin: 10);

ScreenContainer.OnSplitResizeFinish += (first, second) =>
ScreenContainer.OnSplitResizeFinished += () =>
OnChatResized?.Invoke(new Vector2(ScreenContainer.SplitFraction, 0));
}

Expand Down
96 changes: 63 additions & 33 deletions Content.Client/UserInterface/Systems/Actions/ActionUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public sealed class ActionUIController : UIController, IOnStateChanged<GameplayS
[Dependency] private readonly IOverlayManager _overlays = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IEntityManager _entMan = default!;

[UISystemDependency] private readonly ActionsSystem? _actionsSystem = default;
[UISystemDependency] private readonly InteractionOutlineSystem? _interactionOutline = default;
Expand Down Expand Up @@ -113,12 +114,11 @@ public void OnStateEntered(GameplayState state)
{
_actionsSystem.OnActionAdded += OnActionAdded;
_actionsSystem.OnActionRemoved += OnActionRemoved;
_actionsSystem.ActionReplaced += OnActionReplaced;
_actionsSystem.ActionsUpdated += OnActionsUpdated;
}

UpdateFilterLabel();
SearchAndDisplay();
QueueWindowUpdate();

_dragShadow.Orphan();
UIManager.PopupRoot.AddChild(_dragShadow);
Expand Down Expand Up @@ -307,6 +307,8 @@ private void OnWindowOpened()
{
if (ActionButton != null)
ActionButton.Pressed = true;

SearchAndDisplay();
}

private void OnWindowClosed()
Expand All @@ -321,7 +323,6 @@ public void OnStateExited(GameplayState state)
{
_actionsSystem.OnActionAdded -= OnActionAdded;
_actionsSystem.OnActionRemoved -= OnActionRemoved;
_actionsSystem.ActionReplaced -= OnActionReplaced;
_actionsSystem.ActionsUpdated -= OnActionsUpdated;
}

Expand All @@ -345,6 +346,9 @@ CurrentPage[index] is not { } actionId ||

private void ChangePage(int index)
{
if (_actionsSystem == null)
return;

var lastPage = _pages.Count - 1;
if (index < 0)
{
Expand All @@ -357,7 +361,7 @@ private void ChangePage(int index)

_currentPageIndex = index;
var page = _pages[_currentPageIndex];
_container?.SetActionData(page);
_container?.SetActionData(_actionsSystem, page);

ActionsBar!.PageButtons.Label.Text = $"{_currentPageIndex + 1}";
}
Expand Down Expand Up @@ -424,7 +428,6 @@ private void OnActionAdded(EntityUid actionId)
}

AppendAction(actionId);
SearchAndDisplay();
}

private void OnActionRemoved(EntityUid actionId)
Expand Down Expand Up @@ -454,24 +457,11 @@ private void OnActionRemoved(EntityUid actionId)
}
}
}

SearchAndDisplay();
}

private void OnActionReplaced(EntityUid actionId)
{
if (_container == null)
return;

foreach (var button in _container.GetButtons())
{
if (button.ActionId == actionId)
button.UpdateData(actionId);
}
}

private void OnActionsUpdated()
{
QueueWindowUpdate();
if (_container == null)
return;

Expand Down Expand Up @@ -538,27 +528,56 @@ private void ClearList()

private void PopulateActions(IEnumerable<(EntityUid Id, BaseActionComponent Comp)> actions)
{
if (_window == null)
if (_window is not { Disposed: false, IsOpen: true })
return;

ClearList();
if (_actionsSystem == null)
return;

_window.UpdateNeeded = false;

List<ActionButton> existing = new(_window.ResultsGrid.ChildCount);
foreach (var child in _window.ResultsGrid.Children)
{
if (child is ActionButton button)
existing.Add(button);
}

int i = 0;
foreach (var action in actions)
{
var button = new ActionButton {Locked = true};
if (i < existing.Count)
{
existing[i++].UpdateData(action.Id, _actionsSystem);
continue;
}

button.UpdateData(action.Id);
var button = new ActionButton(_entMan, _spriteSystem, this) {Locked = true};
button.ActionPressed += OnWindowActionPressed;
button.ActionUnpressed += OnWindowActionUnPressed;
button.ActionFocusExited += OnWindowActionFocusExisted;

button.UpdateData(action.Id, _actionsSystem);
_window.ResultsGrid.AddChild(button);
}

for (; i < existing.Count; i++)
{
existing[i].Dispose();
}
}

public void QueueWindowUpdate()
{
if (_window != null)
_window.UpdateNeeded = true;
}

private void SearchAndDisplay()
{
if (_window is not { Disposed: false } || _actionsSystem == null)
if (_window is not { Disposed: false, IsOpen: true })
return;

if (_actionsSystem == null)
return;

if (_playerManager.LocalPlayer?.ControlledEntity is not { } player)
Expand Down Expand Up @@ -598,6 +617,9 @@ private void SearchAndDisplay()

private void SetAction(ActionButton button, EntityUid? actionId)
{
if (_actionsSystem == null)
return;

int position;

if (actionId == null)
Expand All @@ -611,7 +633,7 @@ private void SetAction(ActionButton button, EntityUid? actionId)
return;
}

if (button.TryReplaceWith(actionId.Value) &&
if (button.TryReplaceWith(actionId.Value, _actionsSystem) &&
_container != null &&
_container.TryGetButtonIndex(button, out position))
{
Expand Down Expand Up @@ -648,18 +670,18 @@ private void OnClearPressed(ButtonEventArgs args)
_window.SearchBar.Clear();
_window.FilterButton.DeselectAll();
UpdateFilterLabel();
SearchAndDisplay();
QueueWindowUpdate();
}

private void OnSearchChanged(LineEditEventArgs args)
{
SearchAndDisplay();
QueueWindowUpdate();
}

private void OnFilterSelected(ItemPressedEventArgs args)
{
UpdateFilterLabel();
SearchAndDisplay();
QueueWindowUpdate();
}

private void OnWindowActionPressed(GUIBoundKeyEventArgs args, ActionButton action)
Expand Down Expand Up @@ -849,12 +871,15 @@ private void ClearActions()

private void AssignSlots(List<SlotAssignment> assignments)
{
if (_actionsSystem == null)
return;

foreach (ref var assignment in CollectionsMarshal.AsSpan(assignments))
{
_pages[assignment.Hotbar][assignment.Slot] = assignment.ActionId;
}

_container?.SetActionData(_pages[_currentPageIndex]);
_container?.SetActionData(_actionsSystem, _pages[_currentPageIndex]);
}

public void RemoveActionContainer()
Expand All @@ -881,19 +906,24 @@ public void OnSystemUnloaded(ActionsSystem system)
public override void FrameUpdate(FrameEventArgs args)
{
_menuDragHelper.Update(args.DeltaSeconds);
if (_window is {UpdateNeeded: true})
SearchAndDisplay();
}

private void OnComponentLinked(ActionsComponent component)
{
if (_actionsSystem == null)
return;

LoadDefaultActions(component);
_container?.SetActionData(_pages[DefaultPageIndex]);
SearchAndDisplay();
_container?.SetActionData(_actionsSystem, _pages[DefaultPageIndex]);
QueueWindowUpdate();
}

private void OnComponentUnlinked()
{
_container?.ClearActionData();
SearchAndDisplay();
QueueWindowUpdate();
StopTargeting();
}

Expand Down
Loading

0 comments on commit 158e16e

Please sign in to comment.