Skip to content

Commit

Permalink
Merge branch 'master-ru' into arumoon-server
Browse files Browse the repository at this point in the history
  • Loading branch information
MilenVolf committed Aug 18, 2023
2 parents 561badf + febc7ba commit 7913e22
Show file tree
Hide file tree
Showing 41 changed files with 157,966 additions and 26,866 deletions.
21 changes: 21 additions & 0 deletions Content.Client/Lathe/UI/LatheBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public sealed class LatheBoundUserInterface : BoundUserInterface
[ViewVariables]
private LatheQueueMenu? _queueMenu;

[ViewVariables]
private LatheMaterialsEjectionMenu? _materialsEjectionMenu;

public LatheBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
Expand All @@ -24,6 +27,7 @@ protected override void Open()

_menu = new LatheMenu(this);
_queueMenu = new LatheQueueMenu();
_materialsEjectionMenu = new LatheMaterialsEjectionMenu();

_menu.OnClose += Close;

Expand All @@ -34,15 +38,30 @@ protected override void Open()
else
_queueMenu.OpenCenteredLeft();
};

_menu.OnMaterialsEjectionButtonPressed += _ =>
{
if (_materialsEjectionMenu.IsOpen)
_materialsEjectionMenu.Close();
else
_materialsEjectionMenu.OpenCenteredRight();
};

_menu.OnServerListButtonPressed += _ =>
{
SendMessage(new ConsoleServerSelectionMessage());
};

_menu.RecipeQueueAction += (recipe, amount) =>
{
SendMessage(new LatheQueueRecipeMessage(recipe, amount));
};

_materialsEjectionMenu.OnEjectPressed += (material, sheetsToExtract) =>
{
SendMessage(new LatheEjectMaterialMessage(material, sheetsToExtract));
};

_menu.OpenCentered();
}

Expand All @@ -59,6 +78,7 @@ protected override void UpdateState(BoundUserInterfaceState state)
_menu?.PopulateMaterials(Owner);
_queueMenu?.PopulateList(msg.Queue);
_queueMenu?.SetInfo(msg.CurrentlyProducing);
_materialsEjectionMenu?.PopulateMaterials(Owner);
break;
}
}
Expand All @@ -70,6 +90,7 @@ protected override void Dispose(bool disposing)
return;
_menu?.Dispose();
_queueMenu?.Dispose();
_materialsEjectionMenu?.Dispose();
}
}
}
21 changes: 21 additions & 0 deletions Content.Client/Lathe/UI/LatheMaterialEjector.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<PanelContainer xmlns="https://spacestation14.io"
HorizontalExpand="True">
<BoxContainer Name="Content"
Orientation="Horizontal"
HorizontalExpand="True">
<TextureRect Name="Icon"
Access="Public"
MinSize="32 32"
RectClipContent="True" />
<BoxContainer Orientation="Vertical"
HorizontalExpand="True"
VerticalExpand="False">
<Label Name="ProductName"
Access="Public"
HorizontalExpand="True"
ClipText="True"
Margin="0 4 0 0"/>
</BoxContainer>
<!--Here go buttons which added in c#-->
</BoxContainer>
</PanelContainer>
64 changes: 64 additions & 0 deletions Content.Client/Lathe/UI/LatheMaterialEjector.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Content.Shared.Materials;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;

namespace Content.Client.Lathe.UI;

/// <summary>
/// This widget is one row in the lathe eject menu.
/// </summary>

[GenerateTypedNameReferences]
public sealed partial class LatheMaterialEjector : PanelContainer
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

public string Material;
public Action<string, int>? OnEjectPressed;
public int VolumePerSheet;

public LatheMaterialEjector(string material, Action<string, int>? onEjectPressed, int volumePerSheet, int maxEjectableSheets)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

Material = material;
OnEjectPressed = onEjectPressed;
VolumePerSheet = volumePerSheet;

PopulateButtons(maxEjectableSheets);
}

public void PopulateButtons(int maxEjectableSheets)
{
int[] sheetsToEjectArray = { 1, 5, 10, 30 };

foreach (int sheetsToEject in sheetsToEjectArray)
{
var button = new Button()
{
Name = $"{sheetsToEject}",
Access = AccessLevel.Public,
Text = Loc.GetString($"{sheetsToEject}"),
MinWidth = 45,
};

button.OnPressed += (_) =>
{
OnEjectPressed?.Invoke(Material, sheetsToEject);
};

button.Disabled = maxEjectableSheets < sheetsToEject;

if (_prototypeManager.TryIndex<MaterialPrototype>(Material, out var proto))
{
button.ToolTip = Loc.GetString("lathe-menu-tooltip-display", ("amount", sheetsToEject * VolumePerSheet), ("material", Loc.GetString(proto.Name)));
}

Content.AddChild(button);
}
}
}
16 changes: 16 additions & 0 deletions Content.Client/Lathe/UI/LatheMaterialsEjectionMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<DefaultWindow
xmlns="https://spacestation14.io"
Title="{Loc 'lathe-menu-materials-ejection-title'}"
MinSize="300 100"
SetSize="350 475">
<ScrollContainer MinHeight="80">
<BoxContainer
Name="MaterialsList"
Orientation="Vertical"
SizeFlagsStretchRatio="8"
HorizontalExpand="True"
VerticalExpand="True">
<!-- Materials populated in C# file -->
</BoxContainer>
</ScrollContainer>
</DefaultWindow>
74 changes: 74 additions & 0 deletions Content.Client/Lathe/UI/LatheMaterialsEjectionMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Content.Shared.Materials;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using System.Linq;

namespace Content.Client.Lathe.UI;

[GenerateTypedNameReferences]
public sealed partial class LatheMaterialsEjectionMenu : DefaultWindow
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

private readonly SpriteSystem _spriteSystem;

public event Action<string, int>? OnEjectPressed;

public LatheMaterialsEjectionMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_spriteSystem = _entityManager.EntitySysManager.GetEntitySystem<SpriteSystem>();
}

public void PopulateMaterials(EntityUid lathe)
{
if (!_entityManager.TryGetComponent<MaterialStorageComponent>(lathe, out var materials))
return;

MaterialsList.DisposeAllChildren();

foreach (var (materialId, volume) in materials.Storage)
{
if (volume <= 0)
continue;

if (!_prototypeManager.TryIndex(materialId, out MaterialPrototype? material))
continue;

var name = Loc.GetString(material.Name);
int volumePerSheet = 0;
int maxEjectableSheets = 0;

if (material.StackEntity != null)
{
var proto = _prototypeManager.Index<EntityPrototype>(material.StackEntity);
name = proto.Name;

if (proto.TryGetComponent<PhysicalCompositionComponent>(out var composition))
{
volumePerSheet = composition.MaterialComposition.FirstOrDefault(kvp => kvp.Key == materialId).Value;
maxEjectableSheets = (int) MathF.Floor(volume / volumePerSheet);
}
}

var row = new LatheMaterialEjector(materialId, OnEjectPressed, volumePerSheet, maxEjectableSheets)
{
Icon = { Texture = _spriteSystem.Frame0(material.Icon) },
ProductName = { Text = name }
};

MaterialsList.AddChild(row);
}

if (MaterialsList.ChildCount == 0)
{
Close();
}
}
}

11 changes: 9 additions & 2 deletions Content.Client/Lathe/UI/LatheMenu.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<DefaultWindow
<DefaultWindow
xmlns="https://spacestation14.io"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
Title="{Loc 'lathe-menu-title'}"
MinSize="300 450"
SetSize="300 450">
SetSize="350 475">
<BoxContainer
Orientation="Vertical"
VerticalExpand="True"
Expand Down Expand Up @@ -79,6 +79,13 @@
VerticalExpand="True">
</ItemList>
</BoxContainer>
<Button
Name="MaterialsEjectionButton"
Text="{Loc 'lathe-menu-materials-ejection'}"
TextAlign="Center"
Mode="Press"
StyleClasses="OpenRight">
</Button>
</BoxContainer>
</DefaultWindow>

Expand Down
23 changes: 19 additions & 4 deletions Content.Client/Lathe/UI/LatheMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using System.Text;
using Content.Client.Stylesheets;
using Content.Shared.Lathe;
Expand All @@ -22,6 +22,7 @@ public sealed partial class LatheMenu : DefaultWindow
private readonly LatheSystem _lathe;

public event Action<BaseButton.ButtonEventArgs>? OnQueueButtonPressed;
public event Action<BaseButton.ButtonEventArgs>? OnMaterialsEjectionButtonPressed;
public event Action<BaseButton.ButtonEventArgs>? OnServerListButtonPressed;
public event Action<string, int>? RecipeQueueAction;

Expand All @@ -47,6 +48,7 @@ public LatheMenu(LatheBoundUserInterface owner)
};

QueueButton.OnPressed += a => OnQueueButtonPressed?.Invoke(a);
MaterialsEjectionButton.OnPressed += a => OnMaterialsEjectionButtonPressed?.Invoke(a);
ServerListButton.OnPressed += a => OnServerListButtonPressed?.Invoke(a);

if (_entityManager.TryGetComponent<LatheComponent>(owner.Owner, out var latheComponent))
Expand All @@ -57,6 +59,11 @@ public LatheMenu(LatheBoundUserInterface owner)
QueueButton.RemoveStyleClass(StyleBase.ButtonOpenRight);
//QueueButton.AddStyleClass(StyleBase.ButtonSquare);
}

if (MaterialsEjectionButton != null && !latheComponent.CanEjectStoredMaterials)
{
MaterialsEjectionButton.Dispose();
}
}
}

Expand All @@ -69,14 +76,24 @@ public void PopulateMaterials(EntityUid lathe)

foreach (var (id, amount) in materials.Storage)
{
if (amount <= 0)
continue;

if (!_prototypeManager.TryIndex(id, out MaterialPrototype? material))
continue;

var name = Loc.GetString(material.Name);
var mat = Loc.GetString("lathe-menu-material-display",
("material", name), ("amount", amount));

Materials.AddItem(mat, _spriteSystem.Frame0(material.Icon), false);
}

if (MaterialsEjectionButton != null)
{
MaterialsEjectionButton.Disabled = Materials.Count == 0;
}

if (Materials.Count == 0)
{
var noMaterialsMsg = Loc.GetString("lathe-menu-no-materials-message");
Expand Down Expand Up @@ -132,9 +149,7 @@ public void PopulateRecipes(EntityUid lathe)

var adjustedAmount = SharedLatheSystem.AdjustMaterial(amount, prototype.ApplyMaterialDiscount, component.MaterialUseMultiplier);

sb.Append(adjustedAmount);
sb.Append(' ');
sb.Append(Loc.GetString(proto.Name));
sb.Append(Loc.GetString("lathe-menu-tooltip-display", ("amount", adjustedAmount), ("material", Loc.GetString(proto.Name))));
}

var icon = prototype.Icon == null
Expand Down
7 changes: 4 additions & 3 deletions Content.Client/Lathe/UI/LatheQueueMenu.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<DefaultWindow
<DefaultWindow
xmlns="https://spacestation14.io"
Title="{Loc 'lathe-queue-menu-title'}"
MinSize="300 450"
SetSize="300 450">
SetSize="350 475">
<BoxContainer Orientation="Vertical">
<BoxContainer
Orientation="Horizontal"
Expand All @@ -19,7 +19,8 @@
SizeFlagsStretchRatio="3">
<Label
Name="NameLabel"
RectClipContent="True">
RectClipContent="True"
Margin="36 0 0 0">
</Label>
<Label
Name="Description"
Expand Down
12 changes: 6 additions & 6 deletions Content.Client/Message/RichTextLabelExt.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Utility;

namespace Content.Client.Message
namespace Content.Client.Message;

public static class RichTextLabelExt
{
public static class RichTextLabelExt
public static RichTextLabel SetMarkup(this RichTextLabel label, string markup)
{
public static void SetMarkup(this RichTextLabel label, string markup)
{
label.SetMessage(FormattedMessage.FromMarkup(markup));
}
label.SetMessage(FormattedMessage.FromMarkup(markup));
return label;
}
}
Loading

0 comments on commit 7913e22

Please sign in to comment.