FloatMods
This commit is contained in:
parent
540c6c8f2f
commit
5d8e45469d
10 changed files with 255 additions and 0 deletions
23
addons/floatmodifiers/FlatModsInspector.cs
Normal file
23
addons/floatmodifiers/FlatModsInspector.cs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#if TOOLS
|
||||
using Godot;
|
||||
|
||||
public partial class FlatModsInspector : EditorInspectorPlugin
|
||||
{
|
||||
public override bool _CanHandle(GodotObject @object)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public override bool _ParseProperty(GodotObject @object, Variant.Type type, string name, PropertyHint hintType, string hintString, PropertyUsageFlags usageFlags, bool wide)
|
||||
{
|
||||
if (hintString == "FloatModifiers")
|
||||
{
|
||||
AddPropertyEditor(name, new FloatModsProperty());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
1
addons/floatmodifiers/FlatModsInspector.cs.uid
Normal file
1
addons/floatmodifiers/FlatModsInspector.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://uc8igx80sr6u
|
||||
59
addons/floatmodifiers/FloatModifiers.cs
Normal file
59
addons/floatmodifiers/FloatModifiers.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
using Godot;
|
||||
|
||||
[GlobalClass] [Tool]
|
||||
public partial class FloatModifiers : Resource
|
||||
{
|
||||
[Export] private float flat_value;
|
||||
[Export] private float percentage_value;
|
||||
[Export] private float mult_value;
|
||||
|
||||
public static FloatModifiers Instantiate(float flat = 0.0f, float per = 0.0f, float mult = 1.0f)
|
||||
{
|
||||
FloatModifiers mod = new()
|
||||
{
|
||||
flat_value = flat,
|
||||
percentage_value = per,
|
||||
mult_value = mult
|
||||
};
|
||||
return mod;
|
||||
}
|
||||
|
||||
public float GetValue() => flat_value * mult_value * (1.0f + percentage_value);
|
||||
|
||||
public float GetFlat() => flat_value;
|
||||
|
||||
public float GetPercentage() => percentage_value;
|
||||
|
||||
public float GetMult() => mult_value;
|
||||
|
||||
public void SetFlat(float value)
|
||||
{
|
||||
flat_value = value;
|
||||
}
|
||||
|
||||
public void SetPercentage(float value)
|
||||
{
|
||||
percentage_value = value;
|
||||
}
|
||||
|
||||
public void SetMult(float value)
|
||||
{
|
||||
mult_value = value;
|
||||
}
|
||||
|
||||
public void ChangeFlat(float amount)
|
||||
{
|
||||
flat_value += amount;
|
||||
}
|
||||
|
||||
public void ChangePercentage(float amount)
|
||||
{
|
||||
percentage_value += amount;
|
||||
}
|
||||
|
||||
public void ChangeMult(float amount)
|
||||
{
|
||||
mult_value *= amount;
|
||||
}
|
||||
}
|
||||
1
addons/floatmodifiers/FloatModifiers.cs.uid
Normal file
1
addons/floatmodifiers/FloatModifiers.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c3cfnrmnnuqms
|
||||
85
addons/floatmodifiers/FloatModsProperty.cs
Normal file
85
addons/floatmodifiers/FloatModsProperty.cs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#if TOOLS
|
||||
using Godot;
|
||||
|
||||
public partial class FloatModsProperty : EditorProperty
|
||||
{
|
||||
private VBoxContainer _modsControl;
|
||||
private FloatModifiers _currentValue;
|
||||
private bool _updating;
|
||||
|
||||
public FloatModsProperty()
|
||||
{
|
||||
_modsControl = GD.Load<PackedScene>("res://addons/floatmodifiers/float_mods_property.tscn").Instantiate<VBoxContainer>();
|
||||
AddChild(_modsControl);
|
||||
AddFocusable(_modsControl);
|
||||
|
||||
RefreshControl();
|
||||
|
||||
_modsControl.GetNode<SpinBox>("%Flat").ValueChanged += UpdateFlat;
|
||||
_modsControl.GetNode<SpinBox>("%Percentage").ValueChanged += UpdatePercentage;
|
||||
_modsControl.GetNode<SpinBox>("%Mult").ValueChanged += UpdateMult;
|
||||
}
|
||||
|
||||
private void UpdateFlat(double value)
|
||||
{
|
||||
if (_updating) return;
|
||||
|
||||
_currentValue.SetFlat((float)value);
|
||||
|
||||
RefreshControl();
|
||||
EmitChanged(GetEditedProperty(), _currentValue);
|
||||
}
|
||||
private void UpdatePercentage(double value)
|
||||
{
|
||||
if (_updating) return;
|
||||
|
||||
_currentValue.SetPercentage((float)value);
|
||||
|
||||
RefreshControl();
|
||||
EmitChanged(GetEditedProperty(), _currentValue);
|
||||
}
|
||||
private void UpdateMult(double value)
|
||||
{
|
||||
if (_updating) return;
|
||||
|
||||
_currentValue.SetMult((float)value);
|
||||
|
||||
RefreshControl();
|
||||
EmitChanged(GetEditedProperty(), _currentValue);
|
||||
}
|
||||
|
||||
private void RefreshControl()
|
||||
{
|
||||
if (_currentValue == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_modsControl.GetNode<SpinBox>("%Flat").SetValueNoSignal(_currentValue.GetFlat());
|
||||
_modsControl.GetNode<SpinBox>("%Percentage").SetValueNoSignal(_currentValue.GetPercentage());
|
||||
_modsControl.GetNode<SpinBox>("%Mult").SetValueNoSignal(_currentValue.GetMult());
|
||||
}
|
||||
|
||||
|
||||
public override void _UpdateProperty()
|
||||
{
|
||||
// Read the current value from the property.
|
||||
var newValue = GetEditedObject().Get(GetEditedProperty()).As<FloatModifiers>();
|
||||
if (newValue == null)
|
||||
{
|
||||
newValue = new();
|
||||
EmitChanged(GetEditedProperty(), newValue);
|
||||
}
|
||||
if (newValue == _currentValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the control with the new value.
|
||||
_updating = true;
|
||||
_currentValue = newValue;
|
||||
RefreshControl();
|
||||
_updating = false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
1
addons/floatmodifiers/FloatModsProperty.cs.uid
Normal file
1
addons/floatmodifiers/FloatModsProperty.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dv5koj37coavh
|
||||
20
addons/floatmodifiers/Plugin.cs
Normal file
20
addons/floatmodifiers/Plugin.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#if TOOLS
|
||||
using Godot;
|
||||
|
||||
[Tool]
|
||||
public partial class Plugin : EditorPlugin
|
||||
{
|
||||
private FlatModsInspector _plugin;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
_plugin = new FlatModsInspector();
|
||||
AddInspectorPlugin(_plugin);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
RemoveInspectorPlugin(_plugin);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
1
addons/floatmodifiers/Plugin.cs.uid
Normal file
1
addons/floatmodifiers/Plugin.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://fjnw4mev4eiq
|
||||
57
addons/floatmodifiers/float_mods_property.tscn
Normal file
57
addons/floatmodifiers/float_mods_property.tscn
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
[gd_scene format=3 uid="uid://d2ne6ml10xgcl"]
|
||||
|
||||
[node name="FloatModsProperty" type="VBoxContainer"]
|
||||
offset_right = 163.0
|
||||
offset_bottom = 104.0
|
||||
|
||||
[node name="FlatContainer" type="HBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="FlatContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Flat"
|
||||
|
||||
[node name="Flat" type="SpinBox" parent="FlatContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(128, 0)
|
||||
layout_mode = 2
|
||||
step = 0.001
|
||||
allow_greater = true
|
||||
allow_lesser = true
|
||||
|
||||
[node name="PercentageContainer" type="HBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="PercentageContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "%"
|
||||
|
||||
[node name="Percentage" type="SpinBox" parent="PercentageContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(128, 0)
|
||||
layout_mode = 2
|
||||
max_value = 10.0
|
||||
step = 0.001
|
||||
allow_greater = true
|
||||
allow_lesser = true
|
||||
prefix = "+"
|
||||
|
||||
[node name="MultContainer" type="HBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="MultContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Mult"
|
||||
|
||||
[node name="Mult" type="SpinBox" parent="MultContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(128, 0)
|
||||
layout_mode = 2
|
||||
step = 0.001
|
||||
value = 1.0
|
||||
allow_greater = true
|
||||
allow_lesser = true
|
||||
prefix = "*"
|
||||
7
addons/floatmodifiers/plugin.cfg
Normal file
7
addons/floatmodifiers/plugin.cfg
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[plugin]
|
||||
|
||||
name="FloatModifiers"
|
||||
description=""
|
||||
author="R34nd0"
|
||||
version="1.0"
|
||||
script="Plugin.cs"
|
||||
Loading…
Add table
Add a link
Reference in a new issue