numeric mods
This commit is contained in:
parent
eaa487f16a
commit
5246d8481d
11 changed files with 185 additions and 0 deletions
57
addons/numeric-modifiers/float_mods_property.tscn
Normal file
57
addons/numeric-modifiers/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 = "*"
|
21
addons/numeric-modifiers/numeric_modifiers.gd
Normal file
21
addons/numeric-modifiers/numeric_modifiers.gd
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
extends Resource
|
||||||
|
|
||||||
|
class_name NumericModifiers
|
||||||
|
|
||||||
|
@export var flat_value : float
|
||||||
|
@export var percentage_value : float
|
||||||
|
@export var mult_value : float
|
||||||
|
|
||||||
|
var value:
|
||||||
|
get():
|
||||||
|
return get_value()
|
||||||
|
|
||||||
|
func _init(flat : float = 0, per : float = 0, mult : float = 1) -> void:
|
||||||
|
flat_value = flat
|
||||||
|
percentage_value = per
|
||||||
|
mult_value = mult
|
||||||
|
|
||||||
|
resource_local_to_scene = true
|
||||||
|
|
||||||
|
func get_value() -> float:
|
||||||
|
return flat_value * mult_value * (1.0 + percentage_value)
|
1
addons/numeric-modifiers/numeric_modifiers.gd.uid
Normal file
1
addons/numeric-modifiers/numeric_modifiers.gd.uid
Normal file
|
@ -0,0 +1 @@
|
||||||
|
uid://bupbncytu4jo6
|
13
addons/numeric-modifiers/numeric_mods_inspector.gd
Normal file
13
addons/numeric-modifiers/numeric_mods_inspector.gd
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
@tool
|
||||||
|
extends EditorInspectorPlugin
|
||||||
|
|
||||||
|
class_name NumericModsInspector
|
||||||
|
|
||||||
|
func _can_handle(object: Object) -> bool:
|
||||||
|
return true
|
||||||
|
|
||||||
|
func _parse_property(object: Object, type: Variant.Type, name: String, hint_type: PropertyHint, hint_string: String, usage_flags: int, wide: bool) -> bool:
|
||||||
|
if hint_string == "NumericModifiers":
|
||||||
|
add_property_editor(name,NumericModsProperty.new())
|
||||||
|
return true
|
||||||
|
return false
|
1
addons/numeric-modifiers/numeric_mods_inspector.gd.uid
Normal file
1
addons/numeric-modifiers/numeric_mods_inspector.gd.uid
Normal file
|
@ -0,0 +1 @@
|
||||||
|
uid://bxfxecofojsqk
|
66
addons/numeric-modifiers/numeric_mods_property.gd
Normal file
66
addons/numeric-modifiers/numeric_mods_property.gd
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
@tool
|
||||||
|
extends EditorProperty
|
||||||
|
|
||||||
|
class_name NumericModsProperty
|
||||||
|
|
||||||
|
var control : VBoxContainer
|
||||||
|
var mod : NumericModifiers
|
||||||
|
var updating : bool
|
||||||
|
|
||||||
|
func _init() -> void:
|
||||||
|
control = preload("uid://d2ne6ml10xgcl").instantiate()
|
||||||
|
add_child(control)
|
||||||
|
add_focusable(control)
|
||||||
|
|
||||||
|
refresh_control()
|
||||||
|
|
||||||
|
control.get_node("%Flat").value_changed.connect(update_flat)
|
||||||
|
control.get_node("%Percentage").value_changed.connect(update_percentage)
|
||||||
|
control.get_node("%Mult").value_changed.connect(update_mult)
|
||||||
|
|
||||||
|
func refresh_control():
|
||||||
|
if mod == null: return
|
||||||
|
|
||||||
|
control.get_node("%Flat").set_value_no_signal(mod.flat_value)
|
||||||
|
control.get_node("%Percentage").set_value_no_signal(mod.percentage_value)
|
||||||
|
control.get_node("%Mult").set_value_no_signal(mod.mult_value)
|
||||||
|
|
||||||
|
func update_flat(value : float):
|
||||||
|
if updating: return
|
||||||
|
|
||||||
|
mod.flat_value = value
|
||||||
|
|
||||||
|
refresh_control()
|
||||||
|
emit_changed(get_edited_property(),mod)
|
||||||
|
|
||||||
|
func update_percentage(value : float):
|
||||||
|
if updating: return
|
||||||
|
|
||||||
|
mod.percentage_value = value
|
||||||
|
|
||||||
|
refresh_control()
|
||||||
|
emit_changed(get_edited_property(),mod)
|
||||||
|
|
||||||
|
func update_mult(value : float):
|
||||||
|
if updating: return
|
||||||
|
|
||||||
|
mod.mult_value = value
|
||||||
|
|
||||||
|
refresh_control()
|
||||||
|
emit_changed(get_edited_property(),mod)
|
||||||
|
|
||||||
|
func _update_property() -> void:
|
||||||
|
var new_value = get_edited_object().get(get_edited_property()) as NumericModifiers
|
||||||
|
if new_value == null:
|
||||||
|
new_value = NumericModifiers.new()
|
||||||
|
new_value.resource_local_to_scene = true
|
||||||
|
emit_changed(get_edited_property(),new_value)
|
||||||
|
if new_value.resource_local_to_scene == false:
|
||||||
|
new_value.resource_local_to_scene = true
|
||||||
|
if new_value == mod:
|
||||||
|
return
|
||||||
|
|
||||||
|
updating = true
|
||||||
|
mod = new_value
|
||||||
|
refresh_control()
|
||||||
|
updating = false
|
1
addons/numeric-modifiers/numeric_mods_property.gd.uid
Normal file
1
addons/numeric-modifiers/numeric_mods_property.gd.uid
Normal file
|
@ -0,0 +1 @@
|
||||||
|
uid://d0cs3kbl7cvwc
|
7
addons/numeric-modifiers/plugin.cfg
Normal file
7
addons/numeric-modifiers/plugin.cfg
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
[plugin]
|
||||||
|
|
||||||
|
name="Numeric Modifiers"
|
||||||
|
description="Adds a way to export numeric modifiers resource"
|
||||||
|
author="R34nd0"
|
||||||
|
version="1.0"
|
||||||
|
script="plugin.gd"
|
13
addons/numeric-modifiers/plugin.gd
Normal file
13
addons/numeric-modifiers/plugin.gd
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
@tool
|
||||||
|
extends EditorPlugin
|
||||||
|
|
||||||
|
class_name NumericModifiersPlugin
|
||||||
|
|
||||||
|
var inspector : NumericModsInspector
|
||||||
|
|
||||||
|
func _enter_tree() -> void:
|
||||||
|
inspector = NumericModsInspector.new()
|
||||||
|
add_inspector_plugin(inspector)
|
||||||
|
|
||||||
|
func _exit_tree() -> void:
|
||||||
|
remove_inspector_plugin(inspector)
|
1
addons/numeric-modifiers/plugin.gd.uid
Normal file
1
addons/numeric-modifiers/plugin.gd.uid
Normal file
|
@ -0,0 +1 @@
|
||||||
|
uid://50hsyqdhr2pe
|
|
@ -19,6 +19,10 @@ config/icon="uid://3tgkfxqayrbo"
|
||||||
|
|
||||||
project/assembly_name="Revenge of the Red Dragon Pon of the Red Dragon Pon of the Red Dragon Pon"
|
project/assembly_name="Revenge of the Red Dragon Pon of the Red Dragon Pon of the Red Dragon Pon"
|
||||||
|
|
||||||
|
[editor_plugins]
|
||||||
|
|
||||||
|
enabled=PackedStringArray("res://addons/numeric-modifiers/plugin.cfg")
|
||||||
|
|
||||||
[global_group]
|
[global_group]
|
||||||
|
|
||||||
enemy="Group for all enemy objects. This group should contain Entity node as child."
|
enemy="Group for all enemy objects. This group should contain Entity node as child."
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue