Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Вернул КПБ #259

Closed
wants to merge 2 commits into from
Closed
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
50 changes: 50 additions & 0 deletions Content.Client/_Sunrise/Synth/SynthMonitorBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using Content.Shared.Synth.Components;
using JetBrains.Annotations;

namespace Content.Client._Sunrise.Synth;

[UsedImplicitly]
public sealed class SynthMonitorBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private SynthMonitorMenu? _menu;

public SynthMonitorBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

protected override void Open()
{
base.Open();

_menu = new SynthMonitorMenu();
_menu.OnClose += Close;
_menu.OnIdSelected += OnIdSelected;
_menu.OpenCentered();
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (state is not SynthScreenBoundUserInterfaceState st)
return;

_menu?.UpdateState(st.ScreenList);
}

private void OnIdSelected(string selectedId)
{
SendMessage(new SynthScreenPrototypeSelectedMessage(selectedId));
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (disposing)
{
_menu?.Close();
_menu = null;
}
}
}
11 changes: 11 additions & 0 deletions Content.Client/_Sunrise/Synth/SynthMonitorMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc 'Change screen'}"
SetSize="380 310"
Resizable="False">
<BoxContainer Orientation="Vertical">
<ScrollContainer VerticalExpand="True">
<GridContainer Name="Grid" Columns="2" Margin="0 5" >
</GridContainer>
</ScrollContainer>
</BoxContainer>
</DefaultWindow>
84 changes: 84 additions & 0 deletions Content.Client/_Sunrise/Synth/SynthMonitorMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System.Numerics;
using Content.Client.Stylesheets;
using Content.Shared.Humanoid.Markings;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;

namespace Content.Client._Sunrise.Synth;

[GenerateTypedNameReferences]
public sealed partial class SynthMonitorMenu : DefaultWindow
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
private readonly SpriteSystem _sprite;
public event Action<string>? OnIdSelected;

private List<string> _possibleScreens = [];

public SynthMonitorMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_sprite = _entityManager.System<SpriteSystem>();
}

public void UpdateState(List<string> chemList)
{
_possibleScreens = chemList;
UpdateGrid();
}

private void UpdateGrid()
{
ClearGrid();

if (!_prototypeManager.TryIndex("MobSynth", out EntityPrototype? synthProto))
return;

foreach (var screen in _possibleScreens)
{
if (!_prototypeManager.TryIndex(screen, out MarkingPrototype? screenProto))
continue;

var button = new Button
{
MinSize = new Vector2(128, 128),
HorizontalExpand = true,
ToggleMode = false,
StyleClasses = {StyleBase.ButtonSquare},
};
button.OnPressed += _ => OnIdSelected?.Invoke(screen);
Grid.AddChild(button);

var icon = new AnimatedTextureRect
{
DisplayRect =
{
TextureScale = new Vector2(1, 1),
Stretch = TextureRect.StretchMode.KeepAspectCentered,
},
};

icon.SetFromSpriteSpecifier(screenProto.Sprites[0]);

var synth = new TextureRect()
{
Texture = _sprite.GetPrototypeIcon(synthProto).Default,
Stretch = TextureRect.StretchMode.KeepAspectCentered,
};

button.AddChild(synth);
button.AddChild(icon);
}
}

private void ClearGrid()
{
Grid.RemoveAllChildren();
}
}
Loading
Loading