Re-organize all projects (#4166)

This commit is contained in:
DrSmugleaf
2021-06-09 22:19:39 +02:00
committed by GitHub
parent 9f50e4061b
commit ff1a2d97ea
1773 changed files with 5258 additions and 5508 deletions

View File

@@ -0,0 +1,72 @@
using Content.Client.Items.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Content.Shared.Crayon;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
namespace Content.Client.Crayon
{
[RegisterComponent]
public class CrayonComponent : SharedCrayonComponent, IItemStatus
{
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
[ViewVariables(VVAccess.ReadWrite)] private string Color => _color;
[ViewVariables] private int Charges { get; set; }
[ViewVariables] private int Capacity { get; set; }
Control IItemStatus.MakeControl()
{
return new StatusControl(this);
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (curState is not CrayonComponentState state)
return;
_color = state.Color;
SelectedState = state.State;
Charges = state.Charges;
Capacity = state.Capacity;
_uiUpdateNeeded = true;
}
private sealed class StatusControl : Control
{
private readonly CrayonComponent _parent;
private readonly RichTextLabel _label;
public StatusControl(CrayonComponent parent)
{
_parent = parent;
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
AddChild(_label);
parent._uiUpdateNeeded = true;
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_parent._uiUpdateNeeded)
{
return;
}
_parent._uiUpdateNeeded = false;
_label.SetMarkup(Loc.GetString("Drawing: [color={0}]{1}[/color] ({2}/{3})",
_parent.Color,
_parent.SelectedState,
_parent.Charges,
_parent.Capacity));
}
}
}
}

View File

@@ -0,0 +1,33 @@
using Content.Shared.Crayon;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.Maths;
namespace Content.Client.Crayon
{
[UsedImplicitly]
public class CrayonDecalVisualizer : AppearanceVisualizer
{
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
var sprite = component.Owner.GetComponent<SpriteComponent>();
if (component.TryGetData(CrayonVisuals.State, out string state))
{
sprite.LayerSetState(0, state);
}
if (component.TryGetData(CrayonVisuals.Color, out Color color))
{
sprite.LayerSetColor(0, color);
}
if (component.TryGetData(CrayonVisuals.Rotation, out Angle rotation))
{
sprite.Rotation = rotation;
}
}
}
}

View File

@@ -0,0 +1,53 @@
using System.Linq;
using Content.Shared.Crayon;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Client.Crayon.UI
{
public class CrayonBoundUserInterface : BoundUserInterface
{
public CrayonBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{
}
private CrayonWindow? _menu;
protected override void Open()
{
base.Open();
_menu = new CrayonWindow(this);
_menu.OnClose += Close;
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
var crayonDecals = prototypeManager.EnumeratePrototypes<CrayonDecalPrototype>().FirstOrDefault();
if (crayonDecals != null)
_menu.Populate(crayonDecals);
_menu.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
_menu?.UpdateState((CrayonBoundUserInterfaceState) state);
}
public void Select(string state)
{
SendMessage(new CrayonSelectMessage(state));
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_menu?.Close();
}
}
}
}

View File

@@ -0,0 +1,125 @@
using System.Collections.Generic;
using Content.Client.Stylesheets;
using Content.Shared.Crayon;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.Utility;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.BaseButton;
namespace Content.Client.Crayon.UI
{
public class CrayonWindow : SS14Window
{
public CrayonBoundUserInterface Owner { get; }
private readonly LineEdit _search;
private readonly GridContainer _grid;
private Dictionary<string, Texture>? _decals;
private string? _selected;
private Color _color;
public CrayonWindow(CrayonBoundUserInterface owner)
{
MinSize = SetSize = (250, 300);
Title = Loc.GetString("Crayon");
Owner = owner;
var vbox = new VBoxContainer();
Contents.AddChild(vbox);
_search = new LineEdit();
_search.OnTextChanged += (_) => RefreshList();
vbox.AddChild(_search);
_grid = new GridContainer()
{
Columns = 6,
};
var gridScroll = new ScrollContainer()
{
VerticalExpand = true,
Children =
{
_grid
}
};
vbox.AddChild(gridScroll);
}
private void RefreshList()
{
// Clear
_grid.RemoveAllChildren();
if (_decals == null)
return;
var filter = _search.Text;
foreach (var (decal, tex) in _decals)
{
if (!decal.Contains(filter))
continue;
var button = new TextureButton()
{
TextureNormal = tex,
Name = decal,
ToolTip = decal,
Modulate = _color
};
button.OnPressed += ButtonOnPressed;
if (_selected == decal)
{
var panelContainer = new PanelContainer()
{
PanelOverride = new StyleBoxFlat()
{
BackgroundColor = StyleNano.ButtonColorDefault,
},
Children =
{
button
}
};
_grid.AddChild(panelContainer);
}
else
{
_grid.AddChild(button);
}
}
}
private void ButtonOnPressed(ButtonEventArgs obj)
{
if (obj.Button.Name != null)
{
Owner.Select(obj.Button.Name);
_selected = obj.Button.Name;
RefreshList();
}
}
public void UpdateState(CrayonBoundUserInterfaceState state)
{
_selected = state.Selected;
_color = state.Color;
RefreshList();
}
public void Populate(CrayonDecalPrototype proto)
{
var path = new ResourcePath(proto.SpritePath);
_decals = new Dictionary<string, Texture>();
foreach (var state in proto.Decals)
{
var rsi = new SpriteSpecifier.Rsi(path, state);
_decals.Add(state, rsi.Frame0());
}
RefreshList();
}
}
}