Skip to content

Commit

Permalink
Merge pull request #1764 from space-syndicate/upstream-sync
Browse files Browse the repository at this point in the history
Upstream sync
  • Loading branch information
Morb0 authored Jan 15, 2024
2 parents 1e47ef2 + b7aef96 commit 2d8ff19
Show file tree
Hide file tree
Showing 785 changed files with 451,402 additions and 410,160 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ dotnet_naming_symbols.type_parameters_symbols.applicable_kinds = type_parameter
resharper_braces_for_ifelse = required_for_multiline
resharper_keep_existing_attribute_arrangement = true

[*.{csproj,xml,yml,yaml,dll.config,msbuildproj,targets}]
[*.{csproj,xml,yml,yaml,dll.config,msbuildproj,targets,props}]
indent_size = 2

[nuget.config]
indent_size = 2

[{*.yaml,*.yml}]
Expand Down
2 changes: 1 addition & 1 deletion Content.Benchmarks/Content.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<LangVersion>12</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
<PackageReference Include="BenchmarkDotNet" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Content.Client\Content.Client.csproj" />
Expand Down
47 changes: 31 additions & 16 deletions Content.Client/Administration/QuickDialogSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Content.Client.Administration;

// mfw they ported input() from BYOND

/// <summary>
/// This handles the client portion of quick dialogs.
/// </summary>
Expand All @@ -32,39 +34,48 @@ private void OpenDialog(QuickDialogOpenEvent ev)

var promptsDict = new Dictionary<string, LineEdit>();

foreach (var entry in ev.Prompts)
for (var index = 0; index < ev.Prompts.Count; index++)
{
var entry = ev.Prompts[index];
var entryBox = new BoxContainer()
{
Orientation = BoxContainer.LayoutOrientation.Horizontal
};

entryBox.AddChild(new Label { Text = entry.Prompt, HorizontalExpand = true, SizeFlagsStretchRatio = 0.5f });
var edit = new LineEdit() { HorizontalExpand = true};
var edit = new LineEdit() { HorizontalExpand = true };
entryBox.AddChild(edit);
switch (entry.Type)
{
case QuickDialogEntryType.Integer:
edit.IsValid += VerifyInt;
edit.PlaceHolder = "Integer..";
edit.PlaceHolder = Loc.GetString("quick-dialog-ui-integer");
break;
case QuickDialogEntryType.Float:
edit.IsValid += VerifyFloat;
edit.PlaceHolder = "Float..";
edit.PlaceHolder = Loc.GetString("quick-dialog-ui-float");
break;
case QuickDialogEntryType.ShortText:
edit.IsValid += VerifyShortText;
edit.PlaceHolder = "Short text..";
edit.PlaceHolder = Loc.GetString("quick-dialog-ui-short-text");
break;
case QuickDialogEntryType.LongText:
edit.IsValid += VerifyLongText;
edit.PlaceHolder = "Long text..";
edit.PlaceHolder = Loc.GetString("quick-dialog-ui-long-text");
break;
default:
throw new ArgumentOutOfRangeException();
}

promptsDict.Add(entry.FieldId, edit);
entryContainer.AddChild(entryBox);

if (index == ev.Prompts.Count - 1)
{
// Last text box gets enter confirmation.
// Only the last so you don't accidentally confirm early.
edit.OnTextEntered += _ => Confirm();
}
}

var buttonsBox = new BoxContainer()
Expand All @@ -79,17 +90,10 @@ private void OpenDialog(QuickDialogOpenEvent ev)
{
var okButton = new Button()
{
Text = "Ok",
Text = Loc.GetString("quick-dialog-ui-ok"),
};

okButton.OnPressed += _ =>
{
RaiseNetworkEvent(new QuickDialogResponseEvent(ev.DialogId,
promptsDict.Select(x => (x.Key, x.Value.Text)).ToDictionary(x => x.Key, x => x.Text),
QuickDialogButtonFlag.OkButton));
alreadyReplied = true;
window.Close();
};
okButton.OnPressed += _ => Confirm();

buttonsBox.AddChild(okButton);
}
Expand All @@ -98,7 +102,7 @@ private void OpenDialog(QuickDialogOpenEvent ev)
{
var cancelButton = new Button()
{
Text = "Cancel",
Text = Loc.GetString("quick-dialog-ui-cancel"),
};

cancelButton.OnPressed += _ =>
Expand Down Expand Up @@ -130,6 +134,17 @@ private void OpenDialog(QuickDialogOpenEvent ev)
window.MinWidth *= 2; // Just double it.

window.OpenCentered();

return;

void Confirm()
{
RaiseNetworkEvent(new QuickDialogResponseEvent(ev.DialogId,
promptsDict.Select(x => (x.Key, x.Value.Text)).ToDictionary(x => x.Key, x => x.Text),
QuickDialogButtonFlag.OkButton));
alreadyReplied = true;
window.Close();
}
}

private bool VerifyInt(string input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public override void Closed()
public override void HandleState(EuiStateBase baseState)
{
var state = (EditSolutionsEuiState) baseState;
_window.SetTargetEntity(state.Target);
_window.UpdateSolutions(state.Solutions);
_window.UpdateReagents();
_window.SetState(state);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using Content.Shared.Administration;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Robust.Client.AutoGenerated;
using Robust.Client.Console;
using Robust.Client.Timing;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Timing;

namespace Content.Client.Administration.UI.ManageSolutions
{
Expand All @@ -16,11 +19,13 @@ public sealed partial class EditSolutionsWindow : DefaultWindow
{
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IClientGameTiming _timing = default!;

private NetEntity _target = NetEntity.Invalid;
private string? _selectedSolution;
private AddReagentWindow? _addReagentWindow;
private Dictionary<string, EntityUid>? _solutions;
private EditSolutionsEuiState? _nextState;

public EditSolutionsWindow()
{
Expand Down Expand Up @@ -327,5 +332,27 @@ public void UpdateSolutions(List<(string, NetEntity)>? solutions)
SolutionOption.Select(selectedIndex);
_selectedSolution = (string?) SolutionOption.SelectedMetadata;
}

protected override void FrameUpdate(FrameEventArgs args)
{
// TODO: THIS IS FUCKING TERRIBLE.
// Ok so the problem is that this shouldn't be via an EUI at all. Why?
// The EUI update notification comes in *before* the game state it updates from.
// So the UI doesn't update properly. Heck.
// I didn't wanna completely rewrite this thing to work properly so instead you get terrible hacks.

if (_nextState != null && _timing.LastRealTick >= _nextState.Tick)
{
SetTargetEntity(_nextState.Target);
UpdateSolutions(_nextState.Solutions);
UpdateReagents();
_nextState = null;
}
}

public void SetState(EditSolutionsEuiState state)
{
_nextState = state;
}
}
}
47 changes: 36 additions & 11 deletions Content.Client/Administration/UI/Tabs/ObjectsTab/ObjectsTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Map.Components;
using Robust.Shared.Timing;

namespace Content.Client.Administration.UI.Tabs.ObjectsTab;

[GenerateTypedNameReferences]
public sealed partial class ObjectsTab : Control
{
[Dependency] private readonly EntityManager _entityManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;

private readonly List<ObjectsTabEntry> _objects = new();
private List<ObjectsTabSelection> _selections = new();

public event Action<ObjectsTabEntry, GUIBoundKeyEventArgs>? OnEntryKeyBindDown;

// Listen I could either have like 4 different event subscribers (for map / grid / station changes) and manage their lifetimes in AdminUIController
// OR
// I can do this.
private TimeSpan _updateFrequency = TimeSpan.FromSeconds(2);

private TimeSpan _nextUpdate = TimeSpan.FromSeconds(2);

public ObjectsTab()
{
RobustXamlLoader.Load(this);
Expand All @@ -33,33 +42,38 @@ public ObjectsTab()
ObjectTypeOptions.AddItem(Enum.GetName((ObjectsTabSelection)type)!);
}

RefreshObjectList();
}

private void RefreshObjectList()
{
RefreshObjectList(_selections[ObjectTypeOptions.SelectedId]);
}

private void RefreshObjectList(ObjectsTabSelection selection)
{
var entities = new List<EntityUid>();
var entities = new List<(string Name, NetEntity Entity)>();
switch (selection)
{
case ObjectsTabSelection.Stations:
entities.AddRange(_entityManager.EntitySysManager.GetEntitySystem<StationSystem>().Stations);
break;
case ObjectsTabSelection.Grids:
{
var query = _entityManager.AllEntityQueryEnumerator<MapGridComponent>();
while (query.MoveNext(out var uid, out _))
var query = _entityManager.AllEntityQueryEnumerator<MapGridComponent, MetaDataComponent>();
while (query.MoveNext(out var uid, out _, out var metadata))
{
entities.Add(uid);
entities.Add((metadata.EntityName, _entityManager.GetNetEntity(uid)));
}

break;
}
case ObjectsTabSelection.Maps:
{
var query = _entityManager.AllEntityQueryEnumerator<MapComponent>();
while (query.MoveNext(out var uid, out _))
var query = _entityManager.AllEntityQueryEnumerator<MapComponent, MetaDataComponent>();
while (query.MoveNext(out var uid, out _, out var metadata))
{
entities.Add(uid);
entities.Add((metadata.EntityName, _entityManager.GetNetEntity(uid)));
}
break;
}
Expand All @@ -74,17 +88,28 @@ private void RefreshObjectList(ObjectsTabSelection selection)

_objects.Clear();

foreach (var entity in entities)
foreach (var (name, nent) in entities)
{
// TODO the server eitehr needs to send the entity's name, or it needs to ensure the client knows about the entity.
var name = _entityManager.GetComponentOrNull<MetaDataComponent>(entity)?.EntityName ?? "Unknown Entity"; // this should be fixed, so I CBF localizing.
var ctrl = new ObjectsTabEntry(name, entity);
var ctrl = new ObjectsTabEntry(name, nent);
_objects.Add(ctrl);
ObjectList.AddChild(ctrl);
ctrl.OnKeyBindDown += args => OnEntryKeyBindDown?.Invoke(ctrl, args);
}
}

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

if (_timing.CurTime < _nextUpdate)
return;

// I do not care for precision.
_nextUpdate = _timing.CurTime + _updateFrequency;

RefreshObjectList();
}

private enum ObjectsTabSelection
{
Grids,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ namespace Content.Client.Administration.UI.Tabs.ObjectsTab;
[GenerateTypedNameReferences]
public sealed partial class ObjectsTabEntry : ContainerButton
{
public EntityUid AssocEntity;
public NetEntity AssocEntity;

public ObjectsTabEntry(string name, EntityUid euid)
public ObjectsTabEntry(string name, NetEntity nent)
{
RobustXamlLoader.Load(this);
AssocEntity = euid;
EIDLabel.Text = euid.ToString();
AssocEntity = nent;
EIDLabel.Text = nent.ToString();
NameLabel.Text = name;
}
}
14 changes: 2 additions & 12 deletions Content.Client/Chemistry/EntitySystems/InjectorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<InjectorComponent, ComponentHandleState>(OnHandleInjectorState);
SubscribeLocalEvent<InjectorComponent, ItemStatusCollectMessage>(OnItemInjectorStatus);
Subs.ItemStatus<InjectorComponent>(ent => new InjectorStatusControl(ent));
SubscribeLocalEvent<HyposprayComponent, ComponentHandleState>(OnHandleHyposprayState);
SubscribeLocalEvent<HyposprayComponent, ItemStatusCollectMessage>(OnItemHyposprayStatus);
Subs.ItemStatus<HyposprayComponent>(ent => new HyposprayStatusControl(ent));
}

private void OnHandleInjectorState(EntityUid uid, InjectorComponent component, ref ComponentHandleState args)
Expand All @@ -30,11 +30,6 @@ private void OnHandleInjectorState(EntityUid uid, InjectorComponent component, r
component.UiUpdateNeeded = true;
}

private void OnItemInjectorStatus(EntityUid uid, InjectorComponent component, ItemStatusCollectMessage args)
{
args.Controls.Add(new InjectorStatusControl(component));
}

private void OnHandleHyposprayState(EntityUid uid, HyposprayComponent component, ref ComponentHandleState args)
{
if (args.Current is not HyposprayComponentState cState)
Expand All @@ -44,9 +39,4 @@ private void OnHandleHyposprayState(EntityUid uid, HyposprayComponent component,
component.TotalVolume = cState.MaxVolume;
component.UiUpdateNeeded = true;
}

private void OnItemHyposprayStatus(EntityUid uid, HyposprayComponent component, ItemStatusCollectMessage args)
{
args.Controls.Add(new HyposprayStatusControl(component));
}
}
4 changes: 2 additions & 2 deletions Content.Client/Content.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nett" Version="0.15.0" />
<PackageReference Include="JetBrains.Annotations" Version="2022.1.0" PrivateAssets="All" />
<PackageReference Include="Nett" />
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RobustToolbox\Lidgren.Network\Lidgren.Network.csproj" />
Expand Down
7 changes: 1 addition & 6 deletions Content.Client/Crayon/CrayonSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CrayonComponent, ComponentHandleState>(OnCrayonHandleState);
SubscribeLocalEvent<CrayonComponent, ItemStatusCollectMessage>(OnCrayonItemStatus);
Subs.ItemStatus<CrayonComponent>(ent => new StatusControl(ent));
}

private static void OnCrayonHandleState(EntityUid uid, CrayonComponent component, ref ComponentHandleState args)
Expand All @@ -33,11 +33,6 @@ private static void OnCrayonHandleState(EntityUid uid, CrayonComponent component
component.UIUpdateNeeded = true;
}

private static void OnCrayonItemStatus(EntityUid uid, CrayonComponent component, ItemStatusCollectMessage args)
{
args.Controls.Add(new StatusControl(component));
}

private sealed class StatusControl : Control
{
private readonly CrayonComponent _parent;
Expand Down
Loading

0 comments on commit 2d8ff19

Please sign in to comment.