Files
RobustToolbox/Robust.Client/UserInterface/Controls/ContainerButton.cs
Acruid dadd7b4cc3 Remove Static Component NetIds (#1842)
* ComponentNames are not sent over the network when components are created.

* Removed ComponentStates array from EntityState, now the state is stored directly inside the CompChange struct.

* Remove the unnecessary NetID property from ComponentState.

* Remove Component.NetworkSynchronizeExistence.

* Change GetNetComponents to return both the component and the component NetId.

* Remove public usages of the Component.NetID property.

* Adds the NetIDAttribute that can be applied to components.

* Removed Component.NetID.

* Revert changes to GetComponentState and how prediction works.

* Adds component netID automatic generation.

* Modifies ClientConsoleHost so that commands can be called before Initialize().

* Completely remove static NetIds.

* Renamed NetIDAttribute to NetworkedComponentAttribute.

* Fixing unit tests.
2021-07-12 10:23:13 +02:00

91 lines
2.8 KiB
C#

using System;
using Robust.Client.Graphics;
using Robust.Shared.Maths;
namespace Robust.Client.UserInterface.Controls
{
public class ContainerButton : BaseButton
{
public const string StylePropertyStyleBox = "stylebox";
public const string StyleClassButton = "button";
public const string StylePseudoClassNormal = "normal";
public const string StylePseudoClassPressed = "pressed";
public const string StylePseudoClassHover = "hover";
public const string StylePseudoClassDisabled = "disabled";
public ContainerButton()
{
DrawModeChanged();
}
private StyleBox ActualStyleBox
{
get
{
if (TryGetStyleProperty<StyleBox>(StylePropertyStyleBox, out var box))
{
return box;
}
return UserInterfaceManager.ThemeDefaults.ButtonStyle;
}
}
protected override Vector2 MeasureOverride(Vector2 availableSize)
{
var boxSize = ActualStyleBox.MinimumSize / UIScale;
var childBox = Vector2.ComponentMax(availableSize - boxSize, Vector2.Zero);
var min = Vector2.Zero;
foreach (var child in Children)
{
child.Measure(childBox);
min = Vector2.ComponentMax(min, child.DesiredSize);
}
return min + boxSize;
}
protected override Vector2 ArrangeOverride(Vector2 finalSize)
{
var contentBox = ActualStyleBox.GetContentBox(UIBox2.FromDimensions(Vector2.Zero, finalSize * UIScale));
foreach (var child in Children)
{
child.ArrangePixel((UIBox2i) contentBox);
}
return finalSize;
}
protected internal override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
var style = ActualStyleBox;
var drawBox = PixelSizeBox;
style.Draw(handle, drawBox);
}
protected override void DrawModeChanged()
{
switch (DrawMode)
{
case DrawModeEnum.Normal:
SetOnlyStylePseudoClass(StylePseudoClassNormal);
break;
case DrawModeEnum.Pressed:
SetOnlyStylePseudoClass(StylePseudoClassPressed);
break;
case DrawModeEnum.Hover:
SetOnlyStylePseudoClass(StylePseudoClassHover);
break;
case DrawModeEnum.Disabled:
SetOnlyStylePseudoClass(StylePseudoClassDisabled);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}