Skip to content

Commit

Permalink
Извлекаемые чертежи (#47)
Browse files Browse the repository at this point in the history
* ejectable blueprints

* // Corvax-Next-BlueprintEject

* // Corvax-Next-Something

Co-authored-by: FN <[email protected]>

* Apply suggestions from code review

---------

Co-authored-by: FN <[email protected]>
Co-authored-by: AwareFoxy <[email protected]>
  • Loading branch information
3 people authored Nov 18, 2024
1 parent cdba530 commit 74c8d77
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Content.Client/Lathe/UI/LatheBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ protected override void Open()
SendMessage(new ConsoleServerSelectionMessage());
};

// Corvax-Next-BlueprintEject-Start
_menu.OnBlueprintEjectButtonPressed += _ =>
{
SendMessage(new LatheBlueprintEjectMessage());
};
// Corvax-Next-BlueprintEject-End

_menu.RecipeQueueAction += (recipe, amount) =>
{
SendMessage(new LatheQueueRecipeMessage(recipe, amount));
Expand All @@ -42,6 +49,7 @@ protected override void UpdateState(BoundUserInterfaceState state)
case LatheUpdateState msg:
if (_menu != null)
_menu.Recipes = msg.Recipes;
_menu?.UpdateBlueprintEjectButton(msg.HasAnyBlueprints); // Corvax-Next-BlueprintEject
_menu?.PopulateRecipes();
_menu?.UpdateCategories();
_menu?.PopulateQueueList(msg.Queue);
Expand Down
8 changes: 8 additions & 0 deletions Content.Client/Lathe/UI/LatheMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@
Orientation="Horizontal"
Align="End"
HorizontalExpand="True">
<!-- Corvax-Next-BlueprintEject-Start -->
<Button
Name="BlueprintEjectButton"
Text="{Loc 'lathe-menu-blueprint-eject'}"
TextAlign="Center"
Mode="Press">
</Button>
<!-- Corvax-Next-BlueprintEject-End -->
<Button
Name="ServerListButton"
Text="{Loc 'lathe-menu-server-list'}"
Expand Down
17 changes: 17 additions & 0 deletions Content.Client/Lathe/UI/LatheMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Shared.Lathe;
using Content.Shared.Lathe.Prototypes;
using Content.Shared.Research.Prototypes;
using Content.Shared.Research.Components; // Corvax-Next-BlueprintEject
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
Expand All @@ -25,6 +26,7 @@ public sealed partial class LatheMenu : DefaultWindow
private readonly MaterialStorageSystem _materialStorage;

public event Action<BaseButton.ButtonEventArgs>? OnServerListButtonPressed;
public event Action<BaseButton.ButtonEventArgs>? OnBlueprintEjectButtonPressed; // Corvax-Next-BlueprintEject
public event Action<string, int>? RecipeQueueAction;

public List<ProtoId<LatheRecipePrototype>> Recipes = new();
Expand Down Expand Up @@ -56,6 +58,7 @@ public LatheMenu()
FilterOption.OnItemSelected += OnItemSelected;

ServerListButton.OnPressed += a => OnServerListButtonPressed?.Invoke(a);
BlueprintEjectButton.OnPressed += a => OnBlueprintEjectButtonPressed?.Invoke(a); // Corvax-Next-BlueprintEject
}

public void SetEntity(EntityUid uid)
Expand All @@ -70,6 +73,13 @@ public void SetEntity(EntityUid uid)
}
}

// Corvax-Next-BlueprintEject-Start
if (!_entityManager.HasComponent<BlueprintReceiverComponent>(Entity))
{
BlueprintEjectButton.Visible = false;
}
// Corvax-Next-BlueprintEject-End

MaterialsList.SetOwner(Entity);
}

Expand Down Expand Up @@ -280,4 +290,11 @@ private void OnItemSelected(OptionButton.ItemSelectedEventArgs obj)
}
PopulateRecipes();
}

// Corvax-Next-BlueprintEject-Start
public void UpdateBlueprintEjectButton(bool hasAnyBlueprints)
{
BlueprintEjectButton.Disabled = !hasAnyBlueprints;
}
// Corvax-Next-BlueprintEject-End
}
29 changes: 28 additions & 1 deletion Content.Server/Lathe/LatheSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Content.Shared.Emag.Components;
using Content.Shared.Examine;
using Content.Shared.Lathe;
using Content.Shared.Research.Systems; // Corvax-Next-BlueprintEject
using Content.Shared.Materials;
using Content.Shared.Power;
using Content.Shared.ReagentSpeed;
Expand Down Expand Up @@ -50,6 +51,7 @@ public sealed class LatheSystem : SharedLatheSystem
[Dependency] private readonly SharedSolutionContainerSystem _solution = default!;
[Dependency] private readonly StackSystem _stack = default!;
[Dependency] private readonly TransformSystem _transform = default!;
[Dependency] private readonly BlueprintSystem _blueprints = default!; // Corvax-Next-BlueprintEject

/// <summary>
/// Per-tick cache
Expand All @@ -73,6 +75,7 @@ public override void Initialize()
SubscribeLocalEvent<TechnologyDatabaseComponent, LatheGetRecipesEvent>(OnGetRecipes);
SubscribeLocalEvent<EmagLatheRecipesComponent, LatheGetRecipesEvent>(GetEmagLatheRecipes);
SubscribeLocalEvent<LatheHeatProducingComponent, LatheStartPrintingEvent>(OnHeatStartPrinting);
SubscribeLocalEvent<LatheComponent, LatheBlueprintEjectMessage>(OnBlueprintEjectMessage); // Corvax-Next-BlueprintEject
}
public override void Update(float frameTime)
{
Expand Down Expand Up @@ -271,7 +274,9 @@ public void UpdateUserInterfaceState(EntityUid uid, LatheComponent? component =

var producing = component.CurrentRecipe ?? component.Queue.FirstOrDefault();

var state = new LatheUpdateState(GetAvailableRecipes(uid, component), component.Queue, producing);
var hasAnyBlueprints = TryComp<BlueprintReceiverComponent>(uid, out var blueprintReceiver) && _blueprints.HasAnyBlueprints(uid, blueprintReceiver); //Corvax-Next-BlueprintEject

var state = new LatheUpdateState(GetAvailableRecipes(uid, component), component.Queue, producing, hasAnyBlueprints); //Corvax-Next-BlueprintEject
_uiSys.SetUiState(uid, LatheUiKey.Key, state);
}

Expand Down Expand Up @@ -395,6 +400,28 @@ private void OnLatheSyncRequestMessage(EntityUid uid, LatheComponent component,
{
UpdateUserInterfaceState(uid, component);
}

// Corvax-Next-BlueprintEject-Start
private void OnBlueprintEjectMessage(EntityUid uid, LatheComponent component, LatheBlueprintEjectMessage args)
{
if (!TryComp<BlueprintReceiverComponent>(uid, out var blueprintReceiver))
return;

var toRemove = new HashSet<EntityUid>();
var container = _container.GetContainer(uid, blueprintReceiver.ContainerId);
foreach (var entity in container.ContainedEntities)
{
toRemove.Add(entity);
}

foreach (var entity in toRemove)
{
_container.Remove(entity, container);
}

UpdateUserInterfaceState(uid, component);
}
// Corvax-Next-BlueprintEject-End
#endregion
}
}
14 changes: 13 additions & 1 deletion Content.Shared/Lathe/LatheMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,27 @@ public sealed class LatheUpdateState : BoundUserInterfaceState
public List<LatheRecipePrototype> Queue;

public LatheRecipePrototype? CurrentlyProducing;
public bool HasAnyBlueprints; // Corvax-Next-BlueprintEject

public LatheUpdateState(List<ProtoId<LatheRecipePrototype>> recipes, List<LatheRecipePrototype> queue, LatheRecipePrototype? currentlyProducing = null)
public LatheUpdateState(List<ProtoId<LatheRecipePrototype>> recipes, List<LatheRecipePrototype> queue, LatheRecipePrototype? currentlyProducing = null, bool hasAnyBlueprints = false) // Corvax-Next-BlueprintEject
{
Recipes = recipes;
Queue = queue;
CurrentlyProducing = currentlyProducing;
HasAnyBlueprints = hasAnyBlueprints; // Corvax-Next-BlueprintEject
}
}

// Corvax-Next-BlueprintEject-start

/// <summary>
/// Sent to the server to eject blueprints from the lathe.
/// </summary>
[Serializable, NetSerializable]
public sealed class LatheBlueprintEjectMessage : BoundUserInterfaceMessage;

// Corvax-Next-BlueprintEject-end

/// <summary>
/// Sent to the server to sync material storage and the recipe queue.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions Content.Shared/Research/Systems/BlueprintSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,11 @@ public HashSet<ProtoId<LatheRecipePrototype>> GetBlueprintRecipes(Entity<Bluepri

return recipes;
}

// Corvax-Next-BlueprintEject-Start
public bool HasAnyBlueprints(EntityUid ent, BlueprintReceiverComponent comp)
{
return _container.GetContainer(ent, comp.ContainerId).ContainedEntities.Count > 0;
}
// Corvax-Next-BlueprintEject-End
}
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/_corvaxnext/lathe/ui/lathe-menu.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lathe-menu-blueprint-eject = Извлечь чертежи

0 comments on commit 74c8d77

Please sign in to comment.