Unstable 1.2.1.0
This commit is contained in:
+66
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using Barotrauma.Items.Components;
|
||||
|
||||
namespace Barotrauma;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
sealed class ConditionallyEditable : Editable
|
||||
{
|
||||
public ConditionallyEditable(ConditionType conditionType, bool onlyInEditors = true)
|
||||
{
|
||||
this.conditionType = conditionType;
|
||||
this.onlyInEditors = onlyInEditors;
|
||||
}
|
||||
private readonly ConditionType conditionType;
|
||||
|
||||
private readonly bool onlyInEditors;
|
||||
|
||||
public enum ConditionType
|
||||
{
|
||||
//These need to exist at compile time, so it is a little awkward
|
||||
//I would love to see a better way to do this
|
||||
AllowLinkingWifiToChat,
|
||||
IsSwappableItem,
|
||||
AllowRotating,
|
||||
Attachable,
|
||||
HasBody,
|
||||
Pickable,
|
||||
OnlyByStatusEffectsAndNetwork,
|
||||
HasIntegratedButtons,
|
||||
IsToggleableController,
|
||||
HasConnectionPanel
|
||||
}
|
||||
|
||||
public bool IsEditable(ISerializableEntity entity)
|
||||
{
|
||||
if (onlyInEditors && Screen.Selected is { IsEditor: false }) { return false; }
|
||||
|
||||
return conditionType switch
|
||||
{
|
||||
ConditionType.AllowLinkingWifiToChat
|
||||
=> GameMain.NetworkMember is not { ServerSettings.AllowLinkingWifiToChat: false },
|
||||
ConditionType.IsSwappableItem
|
||||
=> entity is Item item && item.Prefab.SwappableItem != null,
|
||||
ConditionType.AllowRotating
|
||||
=> (entity is Item { body: null } item && item.Prefab.AllowRotatingInEditor)
|
||||
|| (entity is Structure structure && structure.Prefab.AllowRotatingInEditor),
|
||||
ConditionType.Attachable
|
||||
=> entity is Holdable { Attachable: true },
|
||||
ConditionType.HasBody
|
||||
=> entity is Structure { HasBody: true } or Item { body: not null },
|
||||
ConditionType.Pickable
|
||||
=> entity is Item item && item.GetComponent<Pickable>() != null,
|
||||
ConditionType.OnlyByStatusEffectsAndNetwork
|
||||
=> GameMain.NetworkMember is { IsServer: true },
|
||||
ConditionType.HasIntegratedButtons
|
||||
=> entity is Door { HasIntegratedButtons: true },
|
||||
ConditionType.IsToggleableController
|
||||
=> entity is Controller { IsToggle: true } controller && controller.Item.GetComponent<ConnectionPanel>() != null,
|
||||
ConditionType.HasConnectionPanel
|
||||
=> (entity is Item item && item.GetComponent<ConnectionPanel>() != null)
|
||||
|| (entity is ItemComponent ic && ic.Item.GetComponent<ConnectionPanel>() != null),
|
||||
_
|
||||
=> false
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using Barotrauma.Items.Components;
|
||||
|
||||
namespace Barotrauma;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
class Editable : Attribute
|
||||
{
|
||||
public int MaxLength;
|
||||
public int DecimalCount = 1;
|
||||
|
||||
public int MinValueInt = int.MinValue, MaxValueInt = int.MaxValue;
|
||||
public float MinValueFloat = float.MinValue, MaxValueFloat = float.MaxValue;
|
||||
public bool ForceShowPlusMinusButtons = false;
|
||||
public float ValueStep;
|
||||
|
||||
/// <summary>
|
||||
/// Labels of the components of a vector property (defaults to x,y,z,w)
|
||||
/// </summary>
|
||||
public string[] VectorComponentLabels;
|
||||
|
||||
/// <summary>
|
||||
/// If a translation can't be found for the property name, this tag is used instead
|
||||
/// </summary>
|
||||
public string FallBackTextTag;
|
||||
|
||||
/// <summary>
|
||||
/// Currently implemented only for int and bool fields. TODO: implement the remaining types (SerializableEntityEditor)
|
||||
/// </summary>
|
||||
public bool ReadOnly;
|
||||
|
||||
public Editable(int maxLength = 20)
|
||||
{
|
||||
MaxLength = maxLength;
|
||||
}
|
||||
|
||||
public Editable(int minValue, int maxValue)
|
||||
{
|
||||
MinValueInt = minValue;
|
||||
MaxValueInt = maxValue;
|
||||
}
|
||||
|
||||
public Editable(float minValue, float maxValue, int decimals = 1)
|
||||
{
|
||||
MinValueFloat = minValue;
|
||||
MaxValueFloat = maxValue;
|
||||
DecimalCount = decimals;
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
sealed class InGameEditable : Editable
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user