Skip to content
Open
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
55 changes: 49 additions & 6 deletions Content.Client/Lathe/UI/LatheMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public sealed partial class LatheMenu : FancyWindow

public EntityUid Entity;

// LuaM-start
private readonly List<(string Id, RecipeControl Control)> _recipeControls = new();
private readonly List<(int Index, Label Label)> _queueRows = new();
// LuaM-end

public LatheMenu()
{
RobustXamlLoader.Load(this);
Expand Down Expand Up @@ -132,10 +137,25 @@ public void PopulateRecipes()
if (!int.TryParse(AmountLineEdit.Text, out var quantity) || quantity <= 0)
quantity = 1;

var sortedRecipesToShow = recipesToShow.OrderBy(_lathe.GetRecipeName);
RecipeList.Children.Clear();
var sortedRecipesToShow = recipesToShow.OrderBy(_lathe.GetRecipeName).ToList(); // LuaM: added ToList
_entityManager.TryGetComponent(Entity, out LatheComponent? lathe);

// LuaM-start
if (sortedRecipesToShow.Count == _recipeControls.Count &&
sortedRecipesToShow.Select(p => p.ID).SequenceEqual(_recipeControls.Select(c => c.Id)))
{
for (var i = 0; i < sortedRecipesToShow.Count; i++)
{
_recipeControls[i].Control.SetCanProduce(_lathe.CanProduce(Entity, sortedRecipesToShow[i], quantity, component: lathe));
}

return;
}

_recipeControls.Clear();
// LuaM-end
RecipeList.Children.Clear();

foreach (var prototype in sortedRecipesToShow)
{
var canProduce = _lathe.CanProduce(Entity, prototype, quantity, component: lathe);
Expand All @@ -148,6 +168,7 @@ public void PopulateRecipes()
RecipeQueueAction?.Invoke(s, amount);
};
RecipeList.AddChild(control);
_recipeControls.Add((prototype.ID, control)); // LuaM
}
}

Expand Down Expand Up @@ -243,6 +264,20 @@ public void UpdateCategories()
/// <param name="queue"></param>
public void PopulateQueueList(List<LatheRecipeBatch> queue) // Frontier: LatheRecipePrototype<LatheRecipeBatch
{
// LuaM-start
if (queue.Count == _queueRows.Count &&
queue.Select(b => b.Index).SequenceEqual(_queueRows.Select(r => r.Index)))
{
for (var i = 0; i < queue.Count; i++)
{
_queueRows[i].Label.Text = GetQueueLabelText(i + 1, queue[i]);
}

return;
}

_queueRows.Clear();
// LuaM-end
QueueList.DisposeAllChildren();

var idx = 1;
Expand All @@ -255,10 +290,8 @@ public void PopulateQueueList(List<LatheRecipeBatch> queue) // Frontier: LatheRe
queuedRecipeBox.AddChild(GetRecipeDisplayControl(batch.Recipe));

var queuedRecipeLabel = new Label();
if (batch.ItemsRequested > 1)
queuedRecipeLabel.Text = $"{idx}. {_lathe.GetRecipeName(batch.Recipe)} ({batch.ItemsPrinted}/{batch.ItemsRequested})";
else
queuedRecipeLabel.Text = $"{idx}. {_lathe.GetRecipeName(batch.Recipe)}";
queuedRecipeLabel.Text = GetQueueLabelText(idx, batch); // LuaM: inline text > GetQueueLabelText
_queueRows.Add((batch.Index, queuedRecipeLabel)); // LuaM
// End Frontier
queuedRecipeBox.AddChild(queuedRecipeLabel);
// <Mono>
Expand All @@ -273,6 +306,16 @@ public void PopulateQueueList(List<LatheRecipeBatch> queue) // Frontier: LatheRe
}
}

// LuaM-start
private string GetQueueLabelText(int idx, LatheRecipeBatch batch)
{
if (batch.ItemsRequested > 1)
return $"{idx}. {_lathe.GetRecipeName(batch.Recipe)} ({batch.ItemsPrinted}/{batch.ItemsRequested})";

return $"{idx}. {_lathe.GetRecipeName(batch.Recipe)}";
}
// LuaM-end

public void SetQueueInfo(LatheRecipePrototype? recipe)
{
FabricatingContainer.Visible = recipe != null;
Expand Down
5 changes: 5 additions & 0 deletions Content.Client/Lathe/UI/RecipeControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public RecipeControl(LatheSystem latheSystem, LatheRecipePrototype recipe, Func<
};
}

public void SetCanProduce(bool canProduce) // LuaM
{
Button.Disabled = !canProduce;
}

private Control? SupplyTooltip(Control sender)
{
return new RecipeTooltip(TooltipTextSupplier());
Expand Down
122 changes: 112 additions & 10 deletions Content.Client/_Mono/Movement/Systems/FocusToggleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,125 @@
using Content.Client.Movement.Components;
using Content.Shared._Mono.Movement.Systems;
using System.Numerics;
using Content.Client.UserInterface.Controls;
using Content.Shared.Camera;
using Content.Shared.Input;
using Content.Shared.Movement.Components;
using Content.Shared.Shuttles.Components;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Shared.Input.Binding;
using Robust.Shared.Map;
using Robust.Shared.Player;

namespace Content.Client._Mono.Movement.Systems;

public sealed class FocusToggleSystem : SharedFocusToggleSystem
public sealed class FocusToggleSystem : EntitySystem
{
protected override bool HasCompEyeCursorOffset(EntityUid uid)
[Dependency] private IEyeManager _eyeManager = default!;
[Dependency] private IInputManager _inputManager = default!;
[Dependency] private IUserInterfaceManager _uiManager = default!;
[Dependency] private IPlayerManager _player = default!;

private const float MaxOffset = 3f;
private const float EdgeOffset = 0.9f;
private const float Sharpness = 8f;

private EntityUid? _owner;
private bool _active;
private Vector2 _target;
private Vector2 _current;

public override void Initialize()
{
return HasComp<EyeCursorOffsetComponent>(uid);
base.Initialize();

SubscribeLocalEvent<ContentEyeComponent, GetEyeOffsetEvent>(OnGetEyeOffset);

CommandBinds.Builder
.Bind(ContentKeyFunctions.ToggleFocus, InputCmdHandler.FromDelegate(OnToggleFocus))
.Register<FocusToggleSystem>();
}

protected override void AddCompEyeCursorOffset(EntityUid uid)
public override void Shutdown()
{
EnsureComp<EyeCursorOffsetComponent>(uid);
base.Shutdown();

CommandBinds.Unregister<FocusToggleSystem>();
}

protected override void RemCompEyeCursorOffset(EntityUid uid)
private void OnToggleFocus(ICommonSession? session)
{
RemComp<EyeCursorOffsetComponent>(uid);
if (session?.AttachedEntity is not { } uid || uid != _player.LocalEntity)
return;

if (TryComp<PilotComponent>(uid, out var pilot) && pilot.Console != null)
return;

_active = !_active;
}
}

private void OnGetEyeOffset(Entity<ContentEyeComponent> ent, ref GetEyeOffsetEvent args)
{
if (ent.Owner != _owner)
return;

args.Offset += _current;
}

public override void FrameUpdate(float frameTime)
{
base.FrameUpdate(frameTime);

var player = _player.LocalEntity;
if (player != _owner)
{
_owner = player;
_active = false;
_target = Vector2.Zero;
_current = Vector2.Zero;
}

if (player == null)
return;

if (_active && TryComp<PilotComponent>(player.Value, out var pilot) && pilot.Console != null)
_active = false;

if (!_active)
_target = Vector2.Zero;
else if (TryGetMouseOffset(out var offset))
_target = offset;

_current = Vector2.Lerp(_current, _target, 1f - MathF.Exp(-Sharpness * frameTime));
if (!_active && _current.LengthSquared() < 0.0001f)
_current = Vector2.Zero;
}

private bool TryGetMouseOffset(out Vector2 offset)
{
offset = Vector2.Zero;

var mousePos = _inputManager.MouseScreenPosition;
if (mousePos.Window == WindowId.Invalid)
return false;

if (_uiManager.ActiveScreen == null || !_uiManager.ActiveScreen.TryGetWidget<MainViewport>(out var mainViewport))
return false;

var screenSize = mainViewport.Size;
var minValue = MathF.Min(screenSize.X / 2, screenSize.Y / 2) * EdgeOffset;
if (minValue <= 0f)
return false;

var normalized = new Vector2(-(mousePos.X - screenSize.X / 2) / minValue, (mousePos.Y - screenSize.Y / 2) / minValue);
var eyeRotation = _eyeManager.CurrentEye.Rotation;
offset = Vector2.Transform(normalized, Quaternion.CreateFromAxisAngle(-Vector3.UnitZ, (float) eyeRotation.Opposite().Theta));

offset *= MaxOffset;
if (offset.Length() > MaxOffset)
offset = offset.Normalized() * MaxOffset;

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public PersonalShieldOverlay()
_inventory = _entManager.System<InventorySystem>();
var protoMan = IoCManager.Resolve<IPrototypeManager>();
_shader = protoMan.Index(ShaderId).InstanceUnique();
ZIndex = -2; // LuaM
}

protected override void Draw(in OverlayDrawArgs args)
Expand Down
30 changes: 16 additions & 14 deletions Content.Server/Research/Systems/ResearchSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,11 @@ public string[] GetNFServerNames(EntityUid gridUid)
{
var allServers = EntityQueryEnumerator<ResearchServerComponent>();
var list = new List<string>();
var station = _station.GetOwningStation(gridUid);

if (station is { } stationUid)
while (allServers.MoveNext(out var uid, out var comp)) // LuaM: station-only > IsSameResearchNetwork
{
while (allServers.MoveNext(out var uid, out var comp))
{
if (_station.GetOwningStation(uid) == stationUid)
list.Add(comp.ServerName);
}
if (IsSameResearchNetwork(gridUid, uid))
list.Add(comp.ServerName);
}

var serverList = list.ToArray();
Expand All @@ -122,21 +118,27 @@ public int[] GetNFServerIds(EntityUid gridUid)
{
var allServers = EntityQueryEnumerator<ResearchServerComponent>();
var list = new List<int>();
var station = _station.GetOwningStation(gridUid);

if (station is { } stationUid)
while (allServers.MoveNext(out var uid, out var comp)) // LuaM: station-only > IsSameResearchNetwork
{
while (allServers.MoveNext(out var uid, out var comp))
{
if (_station.GetOwningStation(uid) == stationUid)
list.Add(comp.Id);
}
if (IsSameResearchNetwork(gridUid, uid))
list.Add(comp.Id);
}

var serverList = list.ToArray();
return serverList;
}

// LuaM-start
private bool IsSameResearchNetwork(EntityUid client, EntityUid server)
{
if (_station.GetOwningStation(client) is { } station)
return _station.GetOwningStation(server) == station;

return Transform(client).GridUid is { } grid && Transform(server).GridUid == grid;
}
// LuaM-end

public override void Update(float frameTime)
{
var query = EntityQueryEnumerator<ResearchServerComponent>();
Expand Down
47 changes: 24 additions & 23 deletions Content.Server/_Mono/Movement/Systems/FocusToggleSystem.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
using Content.Server.Movement.Components;
using Content.Shared._Mono.Movement.Systems;

namespace Content.Server._Mono.Movement.Systems;

public sealed class FocusToggleSystem : SharedFocusToggleSystem
{
protected override bool HasCompEyeCursorOffset(EntityUid uid)
{
return HasComp<EyeCursorOffsetComponent>(uid);
}

protected override void AddCompEyeCursorOffset(EntityUid uid)
{
EnsureComp<EyeCursorOffsetComponent>(uid);
}

protected override void RemCompEyeCursorOffset(EntityUid uid)
{
RemComp<EyeCursorOffsetComponent>(uid);
}
}

// LuaM-start: Закомменчено из-за ненадобности
// using Content.Server.Movement.Components;
// using Content.Shared._Mono.Movement.Systems;
//
// namespace Content.Server._Mono.Movement.Systems;
//
// public sealed class FocusToggleSystem : SharedFocusToggleSystem
// {
// protected override bool HasCompEyeCursorOffset(EntityUid uid)
// {
// return HasComp<EyeCursorOffsetComponent>(uid);
// }
//
// protected override void AddCompEyeCursorOffset(EntityUid uid)
// {
// EnsureComp<EyeCursorOffsetComponent>(uid);
// }
//
// protected override void RemCompEyeCursorOffset(EntityUid uid)
// {
// RemComp<EyeCursorOffsetComponent>(uid);
// }
// }
// LuaM-end
3 changes: 1 addition & 2 deletions Content.Shared/NightVision/SharedNightVisionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ private void OnCompUnequip(Entity<NightVisionComponent> ent, ref GotUnequippedEv
if (!ent.Comp.RelayOverlay)
return;

ent.Comp.Enabled = false; // mono
RefreshOverlay(ent);
SetEnabled((ent, ent.Comp), false, args.Equipee); // LuaM: Enabled = false, RefreshOverlay(ent) > SetEnabled
}
protected virtual void OnRefreshEquipmentHud(Entity<NightVisionComponent> ent, ref InventoryRelayedEvent<RefreshNightVisionEvent> args)
{
Expand Down
14 changes: 11 additions & 3 deletions Content.Shared/Preferences/HumanoidCharacterProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,18 @@ public List<ProtoId<TraitPrototype>> GetValidTraits(IEnumerable<ProtoId<TraitPro
var groups = new Dictionary<string, int>();
var result = new List<ProtoId<TraitPrototype>>();

foreach (var trait in traits)
var ordered = new List<TraitPrototype>(); // LuaM
foreach (var trait in traits) // LuaM
{
if (!protoManager.TryIndex(trait, out var traitProto))
continue;
if (protoManager.TryIndex(trait, out var indexed)) // LuaM
ordered.Add(indexed); // LuaM
}

ordered.Sort((a, b) => a.Cost != b.Cost ? a.Cost.CompareTo(b.Cost) : string.CompareOrdinal(a.ID, b.ID)); // LuaM

foreach (var traitProto in ordered) // LuaM: traits > ordered
{
ProtoId<TraitPrototype> trait = traitProto.ID; // LuaM

// Always valid.
if (traitProto.Category == null)
Expand Down
Loading
Loading