Replicated the weapon flying tick setup using resources
This commit is contained in:
@@ -6,7 +6,7 @@ using Godot;
|
||||
namespace Gamesmiths.Forge.Godot.Editor.Attributes;
|
||||
|
||||
[Tool]
|
||||
public partial class AttributeEditorProperty : EditorProperty
|
||||
public partial class AttributeEditorProperty : EditorProperty, ISerializationListener
|
||||
{
|
||||
private const int ButtonSize = 26;
|
||||
private const int PopupSize = 300;
|
||||
@@ -15,17 +15,15 @@ public partial class AttributeEditorProperty : EditorProperty
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Texture2D dropdownIcon = EditorInterface.Singleton
|
||||
.GetEditorTheme()
|
||||
.GetIcon("GuiDropdown", "EditorIcons");
|
||||
Texture2D dropdownIcon = EditorInterface.Singleton.GetEditorTheme().GetIcon("GuiDropdown", "EditorIcons");
|
||||
|
||||
var hbox = new HBoxContainer();
|
||||
var hBox = new HBoxContainer();
|
||||
_label = new Label { Text = "None", SizeFlagsHorizontal = SizeFlags.ExpandFill };
|
||||
var button = new Button { Icon = dropdownIcon, CustomMinimumSize = new Vector2(ButtonSize, 0) };
|
||||
|
||||
hbox.AddChild(_label);
|
||||
hbox.AddChild(button);
|
||||
AddChild(hbox);
|
||||
hBox.AddChild(_label);
|
||||
hBox.AddChild(button);
|
||||
AddChild(hBox);
|
||||
|
||||
var popup = new Popup { Size = new Vector2I(PopupSize, PopupSize) };
|
||||
var tree = new Tree
|
||||
@@ -78,6 +76,20 @@ public partial class AttributeEditorProperty : EditorProperty
|
||||
_label.Text = string.IsNullOrEmpty(value) ? "None" : value;
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
for (var i = GetChildCount() - 1; i >= 0; i--)
|
||||
{
|
||||
Node child = GetChild(i);
|
||||
RemoveChild(child);
|
||||
child.Free();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
}
|
||||
|
||||
private static void BuildAttributeTree(Tree tree)
|
||||
{
|
||||
TreeItem root = tree.CreateItem();
|
||||
|
||||
@@ -12,7 +12,7 @@ using Godot.Collections;
|
||||
namespace Gamesmiths.Forge.Godot.Editor.Attributes;
|
||||
|
||||
[Tool]
|
||||
public partial class AttributeSetClassEditorProperty : EditorProperty
|
||||
public partial class AttributeSetClassEditorProperty : EditorProperty, ISerializationListener
|
||||
{
|
||||
private OptionButton _optionButton = null!;
|
||||
|
||||
@@ -32,26 +32,40 @@ public partial class AttributeSetClassEditorProperty : EditorProperty
|
||||
var className = _optionButton.GetItemText((int)x);
|
||||
EmitChanged(GetEditedProperty(), className);
|
||||
|
||||
GodotObject obj = GetEditedObject();
|
||||
if (obj is not null)
|
||||
GodotObject @object = GetEditedObject();
|
||||
if (@object is not null)
|
||||
{
|
||||
var dict = new Dictionary<string, AttributeValues>();
|
||||
var dictionary = new Dictionary<string, AttributeValues>();
|
||||
|
||||
var assembly = Assembly.GetAssembly(typeof(ForgeAttributeSet));
|
||||
Type? targetType = System.Array.Find(assembly?.GetTypes() ?? [], x => x.Name == className);
|
||||
if (targetType is not null)
|
||||
{
|
||||
System.Collections.Generic.IEnumerable<PropertyInfo> attrProps = targetType
|
||||
System.Collections.Generic.IEnumerable<PropertyInfo> attributeProperties = targetType
|
||||
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||
.Where(x => x.PropertyType == typeof(EntityAttribute));
|
||||
|
||||
foreach (PropertyInfo? pi in attrProps)
|
||||
foreach (var propertyName in attributeProperties.Select(x => x.Name))
|
||||
{
|
||||
dict[pi.Name] = new AttributeValues(0, 0, int.MaxValue);
|
||||
if (@object is not ForgeAttributeSet forgeAttributeSet)
|
||||
{
|
||||
dictionary[propertyName] = new AttributeValues(0, 0, int.MaxValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
AttributeSet? attributeSet = forgeAttributeSet.GetAttributeSet();
|
||||
if (attributeSet is null)
|
||||
{
|
||||
dictionary[propertyName] = new AttributeValues(0, 0, int.MaxValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
EntityAttribute key = attributeSet.AttributesMap[className + "." + propertyName];
|
||||
dictionary[propertyName] = new AttributeValues(key.CurrentValue, key.Min, key.Max);
|
||||
}
|
||||
}
|
||||
|
||||
EmitChanged("InitialAttributeValues", dict);
|
||||
EmitChanged("InitialAttributeValues", dictionary);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -70,5 +84,19 @@ public partial class AttributeSetClassEditorProperty : EditorProperty
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
for (var i = GetChildCount() - 1; i >= 0; i--)
|
||||
{
|
||||
Node child = GetChild(i);
|
||||
RemoveChild(child);
|
||||
child.Free();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -13,7 +13,7 @@ using Godot.Collections;
|
||||
namespace Gamesmiths.Forge.Godot.Editor.Attributes;
|
||||
|
||||
[Tool]
|
||||
public partial class AttributeSetValuesEditorProperty : EditorProperty
|
||||
public partial class AttributeSetValuesEditorProperty : EditorProperty, ISerializationListener
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -94,6 +94,24 @@ public partial class AttributeSetValuesEditorProperty : EditorProperty
|
||||
}
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
VBoxContainer? attributesRoot = GetNodeOrNull<VBoxContainer>("AttributesRoot");
|
||||
if (attributesRoot is not null)
|
||||
{
|
||||
for (var i = attributesRoot.GetChildCount() - 1; i >= 0; i--)
|
||||
{
|
||||
Node child = attributesRoot.GetChild(i);
|
||||
attributesRoot.RemoveChild(child);
|
||||
child.Free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
}
|
||||
|
||||
private static PanelContainer AttributeHeader(string text)
|
||||
{
|
||||
var headerPanel = new PanelContainer
|
||||
@@ -124,17 +142,17 @@ public partial class AttributeSetValuesEditorProperty : EditorProperty
|
||||
|
||||
private static HBoxContainer AttributeFieldRow(string label, SpinBox spinBox)
|
||||
{
|
||||
var hbox = new HBoxContainer();
|
||||
var hBox = new HBoxContainer();
|
||||
|
||||
hbox.AddChild(new Label
|
||||
hBox.AddChild(new Label
|
||||
{
|
||||
Text = label,
|
||||
CustomMinimumSize = new Vector2(80, 0),
|
||||
SizeFlagsHorizontal = SizeFlags.ExpandFill,
|
||||
});
|
||||
|
||||
hbox.AddChild(spinBox);
|
||||
return hbox;
|
||||
hBox.AddChild(spinBox);
|
||||
return hBox;
|
||||
}
|
||||
|
||||
private static SpinBox CreateSpinBox(int min, int max, int value)
|
||||
@@ -143,8 +161,9 @@ public partial class AttributeSetValuesEditorProperty : EditorProperty
|
||||
{
|
||||
MinValue = min,
|
||||
MaxValue = max,
|
||||
Value = value,
|
||||
SizeFlagsHorizontal = SizeFlags.ExpandFill,
|
||||
SelectAllOnFocus = true,
|
||||
Value = value,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ using Godot;
|
||||
namespace Gamesmiths.Forge.Godot.Editor.Attributes;
|
||||
|
||||
[Tool]
|
||||
public partial class AttributeValues : Resource
|
||||
public partial class AttributeValues : RefCounted
|
||||
{
|
||||
[Export]
|
||||
public int Default { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user