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

𝔖𝔲𝔯𝔀𝔒𝔯𝔢 update #2412

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
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
51 changes: 51 additions & 0 deletions Content.Client/SS220/Surgery/Ui/SurgeryDrapeBUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Β© SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using System.Linq;
using Content.Shared.SS220.Surgery.Graph;
using Content.Shared.SS220.Surgery.Ui;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;

namespace Content.Client.SS220.Surgery.Ui;

public sealed class SurgeryDrapeBUI : BoundUserInterface
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

[ViewVariables]
private SurgeryDrapeMenu? _menu;

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

protected override void Open()
{
base.Open();
_menu = this.CreateWindow<SurgeryDrapeMenu>();
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

switch (state)
{
case SurgeryDrapeUpdate update:
_menu?.AddOperations(GetAvailableOperations(EntMan.GetEntity(update.User),
EntMan.GetEntity(update.Target)));
break;
}
}

private List<SurgeryGraphPrototype> GetAvailableOperations(EntityUid user, EntityUid target)
{
// Performer shouldnt see surgery if he is not allowed
var result = _prototypeManager.EnumeratePrototypes<SurgeryGraphPrototype>()
.Where((graph) =>
{
return SharedSurgeryAvaibilityChecks.IsSurgeryGraphAvailablePerformer(user, graph, EntMan);
})
.ToList();

return result;
}
}
50 changes: 50 additions & 0 deletions Content.Client/SS220/Surgery/Ui/SurgeryDrapeMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!-- Β© SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt -->
<controls:FancyWindow
xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:surgery="clr-namespace:Content.Client.SS220.Surgery.Ui"
Title="{Loc 'surgery-observer-title'}"
Resizable="True"
MinSize="256 106"
RectClipContent="False">
<Control>
<PanelContainer>
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#1B1B1E"/>
</PanelContainer.PanelOverride>
</PanelContainer>
<BoxContainer Name="ContentBox" Orientation="Horizontal" MouseFilter="Pass" VerticalAlignment="Center"
VerticalExpand="False" HorizontalExpand="False">
<BoxContainer Name="PuppetBox" MouseFilter="Pass" Margin="1 1" VerticalAlignment="Bottom">
<surgery:SurgeryPuppetBox Name="Puppet" Scale="3 3" MouseFilter="Pass" />
</BoxContainer>
<BoxContainer Name="DetailedInfoBox" Orientation="Horizontal" VerticalExpand="True" HorizontalExpand="False">
<BoxContainer Name="OperationsBox" Orientation="Vertical" HorizontalExpand="False">
<RichTextLabel Name="OperationsLabel" Text="{Loc 'surgery-list-name'}" HorizontalExpand="True" HorizontalAlignment="Center"/>
<ScrollContainer Name="OperationScroll" HScrollEnabled="False"
HorizontalExpand="True" VerticalExpand="True" MouseFilter="Pass">
<BoxContainer
Name="OperationContainer"
Orientation="Vertical"
SizeFlagsStretchRatio="2"
HorizontalExpand="True"
VerticalExpand="True">
<!-- operations are added here by code -->
</BoxContainer>
</ScrollContainer>
</BoxContainer>
<BoxContainer Name="DescriptionBox" Orientation="Vertical" HorizontalExpand="False"
VerticalAlignment="Center" VerticalExpand="True" MinSize="300 120" MaxSize="300 120">
<RichTextLabel Name="OperationName" Text="{Loc 'surgery-operation-name'}" VerticalExpand="True" Margin="4 2"
HorizontalExpand="True" VerticalAlignment="Stretch" HorizontalAlignment="Left" LineHeightScale="0.65"/>
<RichTextLabel Name="OperationDescription" Text="{Loc 'surgery-operation-desc'}" VerticalExpand="True" Margin="4 2"
VerticalAlignment="Top" HorizontalAlignment="Stretch" HorizontalExpand="True" LineHeightScale="0.65"/>
<RichTextLabel Name="OperationPostscript" Text="{Loc 'surgery-operation-postscript'}" VerticalExpand="True" Margin="4 2"
HorizontalExpand="True" VerticalAlignment="Bottom" HorizontalAlignment="Left" LineHeightScale="0.65"/>
</BoxContainer>
</BoxContainer>
</BoxContainer>
</Control>
</controls:FancyWindow>
193 changes: 193 additions & 0 deletions Content.Client/SS220/Surgery/Ui/SurgeryDrapeMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
// Β© SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Content.Client.UserInterface.Controls;
using Content.Shared.SS220.Surgery;
using Content.Shared.SS220.Surgery.Graph;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

namespace Content.Client.SS220.Surgery.Ui;

[GenerateTypedNameReferences]
public sealed partial class SurgeryDrapeMenu : FancyWindow
{
[Dependency] private readonly IEntityManager _entityManager = default!;

public event Action<ProtoId<SurgeryGraphPrototype>>? OnSurgeryCLicked;

private Dictionary<PuppetParts, HashSet<Control>> _operations = new();

// maybe I shouldn't keep it here....
public EntityUid Target;
public EntityUid Performer;

public SurgeryDrapeMenu()
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);

Puppet.Initialize();

Puppet.SelectedPartChanged += (part, prevPart) =>
{
OperationsLabel.Text = LocPuppetPartPath(part);
UpdateOperations(part, prevPart);
};

_operations.Clear(); // never knows what coming after all
foreach (var part in Enum.GetValues<PuppetParts>())
{
_operations.Add(part, new(8));
}
}

public void UpdateOperations(PuppetParts? currentPart, PuppetParts? previousPart)
{
if (currentPart != null)
{
foreach (var control in _operations[currentPart.Value])
{
control.Visible = true;
}
}
if (previousPart != null)
{
foreach (var control in _operations[previousPart.Value])
{
control.Visible = false;
}
}
}

public void AddOperations(List<SurgeryGraphPrototype> graphPrototypes)
{
foreach (var val in _operations.Values)
{
val.Clear();
}

foreach (var graph in graphPrototypes)
{
var button = MakeOperationButton(graph);
OperationContainer.AddChild(button);
SetFormattedText(button.RichTextLabel, graph.NameLocPath);
button.Visible = graph.TargetPuppetPart == Puppet.SelectedPart;
_operations[graph.TargetPuppetPart].Add(button);
}
}

private SurgeryPerformButton MakeOperationButton(SurgeryGraphPrototype surgeryGraph)
{
var button = new SurgeryPerformButton(surgeryGraph.ID)
{
VerticalAlignment = VAlignment.Top,
StyleClasses = { "OpenBoth" }
};
button.HorizontalExpandAll = false;
button.VerticalExpandAll = true;

button.OnPressed += (_) =>
{
OnSurgeryCLicked?.Invoke(button.GraphId);
};

button.OnMouseEntered += (_) =>
{
if (surgeryGraph.PostscriptLocPath != null)
SetFormattedText(OperationPostscript, surgeryGraph.PostscriptLocPath);

SetFormattedText(OperationName, surgeryGraph.NameLocPath);
SetFormattedText(OperationDescription, surgeryGraph.DescriptionLocPath);
};

if (SharedSurgeryAvaibilityChecks.IsSurgeryGraphAvailableTarget(Target, surgeryGraph, _entityManager, out var reason))
{
var tooltip = new Tooltip();
SetFormattedText(tooltip, reason!);
button.TooltipSupplier = (_) => tooltip;
}

return button;
}

private string LocPuppetPartPath(PuppetParts? part)
{
if (part == null)
return "surgery-puppet-part-none";
return $"surgery-puppet-part-{Enum.GetName(typeof(PuppetParts), part)!}";
}

/// <summary>
/// Some helper function to easily set formatted message from locPath
/// </summary>
private void SetFormattedText(Action<FormattedMessage> setterFormatted, Action<string> setterString, string locPath)
{
var loc = Loc.GetString(locPath);
if (FormattedMessage.TryFromMarkup(loc, out var msg))
setterFormatted(msg);
else
setterString(loc);
}

private void SetFormattedText(RichTextLabel richTextLabel, string locPath)
{
SetFormattedText((x) => richTextLabel.SetMessage(x), (x) => richTextLabel.Text = x, locPath);
}

private void SetFormattedText(Tooltip tooltip, string locPath)
{
SetFormattedText(tooltip.SetMessage, (x) => tooltip.Text = x, locPath);
}
}

public sealed class SurgeryPerformButton : ContainerButton
{
[ViewVariables]
public ProtoId<SurgeryGraphPrototype> GraphId;
public RichTextLabel RichTextLabel { get; }

public SurgeryPerformButton(ProtoId<SurgeryGraphPrototype> graphId)
{
GraphId = graphId;

AddStyleClass(StyleClassButton);
RichTextLabel = new RichTextLabel
{
StyleClasses = { StyleClassButton }
};
AddChild(RichTextLabel);
}

public void SetMessage(FormattedMessage msg)
{
RichTextLabel.SetMessage(msg);
}

[ViewVariables]
public string? Text { get => RichTextLabel.Text; set => RichTextLabel.Text = value; }

[ViewVariables]
public bool HorizontalExpandAll
{
set
{
HorizontalExpand = value;
RichTextLabel.HorizontalExpand = value;
}
}

[ViewVariables]
public bool VerticalExpandAll
{
set
{
VerticalExpand = value;
RichTextLabel.VerticalExpand = value;
}
}
}
9 changes: 9 additions & 0 deletions Content.Client/SS220/Surgery/Ui/SurgeryPuppetBox.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Β© SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt -->
<surgery:SurgeryPuppetBox
xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:surgery="clr-namespace:Content.Client.SS220.Surgery.Ui"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client">
<TextureRect Name="Background" Stretch="Keep" MouseFilter="Pass"
TexturePath="/Textures/SS220/Interface/Surgery/puppet/box.png"/>
</surgery:SurgeryPuppetBox>
Loading
Loading