Skip to content

Commit

Permalink
blob
Browse files Browse the repository at this point in the history
  • Loading branch information
KayzelW authored and Darkiich committed May 14, 2024
1 parent 857105d commit c41a4a1
Show file tree
Hide file tree
Showing 175 changed files with 6,534 additions and 30 deletions.
51 changes: 51 additions & 0 deletions Content.Client/Blob/BlobChemSwapBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Content.Shared.Blob;
using JetBrains.Annotations;
using Robust.Client.GameObjects;

namespace Content.Client.Blob;

[UsedImplicitly]
public sealed class BlobChemSwapBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private BlobChemSwapMenu? _menu;

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

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

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

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

_menu?.UpdateState(st.ChemList, st.SelectedChem);
}

private void OnIdSelected(BlobChemType selectedId)
{
SendMessage(new BlobChemSwapPrototypeSelectedMessage(selectedId));
}

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

if (disposing)
{
_menu?.Close();
_menu = null;
}
}
}
11 changes: 11 additions & 0 deletions Content.Client/Blob/BlobChemSwapMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc 'blob-chem-swap-ui-window-name'}"
MinSize="250 300"
SetSize="250 300">
<BoxContainer Orientation="Vertical">
<ScrollContainer VerticalExpand="True">
<GridContainer Name="Grid" Columns="3" Margin="0 5" >
</GridContainer>
</ScrollContainer>
</BoxContainer>
</DefaultWindow>
77 changes: 77 additions & 0 deletions Content.Client/Blob/BlobChemSwapMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System.Numerics;
using Content.Client.Stylesheets;
using Content.Shared.Blob;
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.Blob;

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

private Dictionary<BlobChemType, Color> _possibleChems = new();
private BlobChemType _selectedId;

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

public void UpdateState(Dictionary<BlobChemType, Color> chemList, BlobChemType selectedChem)
{
_possibleChems = chemList;
_selectedId = selectedChem;
UpdateGrid();
}

private void UpdateGrid()
{
ClearGrid();

var group = new ButtonGroup();

foreach (var blobChem in _possibleChems)
{
if (!_prototypeManager.TryIndex("NormalBlobTile", out EntityPrototype? proto))
continue;

var button = new Button
{
MinSize = new Vector2(64, 64),
HorizontalExpand = true,
Group = group,
StyleClasses = {StyleBase.ButtonSquare},
ToggleMode = true,
Pressed = _selectedId == blobChem.Key,
ToolTip = Loc.GetString($"blob-chem-{blobChem.Key.ToString().ToLower()}-info"),
TooltipDelay = 0.01f,
};
button.OnPressed += _ => OnIdSelected?.Invoke(blobChem.Key);
Grid.AddChild(button);

var texture = _sprite.GetPrototypeIcon(proto);
button.AddChild(new TextureRect
{
Stretch = TextureRect.StretchMode.KeepAspectCentered,
Modulate = blobChem.Value,
Texture = texture.Default,
});
}
}

private void ClearGrid()
{
Grid.RemoveAllChildren();
}
}
44 changes: 44 additions & 0 deletions Content.Client/Blob/BlobObserverSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Content.Shared.Blob;
using Content.Shared.GameTicking;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.GameStates;

namespace Content.Client.Blob;

public sealed class BlobObserverSystem : SharedBlobObserverSystem
{
[Dependency] private readonly ILightManager _lightManager = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<BlobObserverComponent, ComponentHandleState>(HandleState);
SubscribeLocalEvent<BlobObserverComponent, PlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<BlobObserverComponent, PlayerDetachedEvent>(OnPlayerDetached);
SubscribeNetworkEvent<RoundRestartCleanupEvent>(RoundRestartCleanup);
}

private void HandleState(EntityUid uid, BlobObserverComponent component, ref ComponentHandleState args)
{
if (args.Current is not BlobChemSwapComponentState state)
return;
component.SelectedChemId = state.SelectedChem;
}

private void OnPlayerAttached(EntityUid uid, BlobObserverComponent component, PlayerAttachedEvent args)
{
_lightManager.DrawLighting = false;
}

private void OnPlayerDetached(EntityUid uid, BlobObserverComponent component, PlayerDetachedEvent args)
{
_lightManager.DrawLighting = true;
}

private void RoundRestartCleanup(RoundRestartCleanupEvent ev)
{
_lightManager.DrawLighting = true;
}
}
9 changes: 9 additions & 0 deletions Content.Client/Blob/BlobTileComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Content.Shared.Blob;

namespace Content.Client.Blob;

[RegisterComponent]
public sealed class BlobTileComponent : SharedBlobTileComponent
{

}
38 changes: 38 additions & 0 deletions Content.Client/Blob/BlobTileSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Content.Client.DamageState;
using Content.Shared.Blob;
using Robust.Client.GameObjects;
using Robust.Shared.GameStates;

namespace Content.Client.Blob;

public sealed class BlobTileSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BlobTileComponent, ComponentHandleState>(OnBlobTileHandleState);
}

private void OnBlobTileHandleState(EntityUid uid, BlobTileComponent component, ref ComponentHandleState args)
{
if (args.Current is not BlobTileComponentState state)
return;

if (component.Color == state.Color)
return;

component.Color = state.Color;
TryComp<SpriteComponent>(uid, out var sprite);

if (sprite == null)
return;

foreach (var key in new []{ DamageStateVisualLayers.Base, DamageStateVisualLayers.BaseUnshaded })
{
if (!sprite.LayerMapTryGet(key, out _))
continue;

sprite.LayerSetColor(key, component.Color);
}
}
}
9 changes: 9 additions & 0 deletions Content.Client/Blob/BlobbernautComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Content.Shared.Blob;

namespace Content.Client.Blob;

[RegisterComponent]
public sealed class BlobbernautComponent : SharedBlobbernautComponent
{

}
39 changes: 39 additions & 0 deletions Content.Client/Blob/BlobbernautSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Linq;
using Content.Client.DamageState;
using Content.Shared.Blob;
using Robust.Client.GameObjects;
using Robust.Shared.GameStates;

namespace Content.Client.Blob;

public sealed class BlobbernautSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BlobbernautComponent, ComponentHandleState>(OnBlobTileHandleState);
}

private void OnBlobTileHandleState(EntityUid uid, BlobbernautComponent component, ref ComponentHandleState args)
{
if (args.Current is not BlobbernautComponentState state)
return;

if (component.Color == state.Color)
return;

component.Color = state.Color;
TryComp<SpriteComponent>(uid, out var sprite);

if (sprite == null)
return;

foreach (var key in new []{ DamageStateVisualLayers.Base })
{
if (!sprite.LayerMapTryGet(key, out _))
continue;

sprite.LayerSetColor(key, component.Color);
}
}
}
9 changes: 9 additions & 0 deletions Content.Client/Chemistry/Components/SmokeComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Content.Shared.Chemistry.Components;

namespace Content.Client.Chemistry.Components;

[RegisterComponent]
public sealed class SmokeComponent : SharedSmokeComponent
{

}
35 changes: 35 additions & 0 deletions Content.Client/Chemistry/Components/SmokeSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Linq;
using Content.Shared.Chemistry.Components;
using Robust.Client.GameObjects;
using Robust.Shared.GameStates;

namespace Content.Client.Chemistry.Components;

public sealed class SmokeSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SmokeComponent, ComponentHandleState>(OnBlobTileHandleState);
}

private void OnBlobTileHandleState(EntityUid uid, SmokeComponent component, ref ComponentHandleState args)
{
if (args.Current is not SmokeComponentState state)
return;

if (component.Color == state.Color)
return;

component.Color = state.Color;
TryComp<SpriteComponent>(uid, out var sprite);

if (sprite == null)
return;

for (var i = 0; i < sprite.AllLayers.Count(); i++)
{
sprite.LayerSetColor(i, component.Color);
}
}
}
8 changes: 8 additions & 0 deletions Content.Server/Blob/BlobBorderComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Content.Server.Blob
{
[RegisterComponent]
public sealed class BlobBorderComponent : Component
{

}
}
Loading

0 comments on commit c41a4a1

Please sign in to comment.