mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
Added a resource property.
This commit is contained in:
parent
1dd6aa25f4
commit
f9662ed967
@ -1,6 +1,8 @@
|
||||
tool
|
||||
extends ScrollContainer
|
||||
|
||||
var EditorResourceWidget : PackedScene = preload("res://addons/world_generator/widgets/EditorResourceWidget.tscn")
|
||||
|
||||
var _edited_resource : WorldGenBaseResource = null
|
||||
var properties : Array = Array()
|
||||
|
||||
@ -22,6 +24,27 @@ func add_slot_label(getter : String, setter : String, slot_name : String) -> int
|
||||
|
||||
return add_slot(getter, setter, l)
|
||||
|
||||
func add_slot_resource(getter : String, setter : String, slot_name : String, resource_type : String = "Resource") -> int:
|
||||
var bc : HBoxContainer = HBoxContainer.new()
|
||||
bc.set_h_size_flags(SIZE_EXPAND_FILL)
|
||||
|
||||
var l : Label = Label.new()
|
||||
l.text = slot_name
|
||||
bc.add_child(l)
|
||||
|
||||
var r : Control = EditorResourceWidget.instance()
|
||||
r.set_resource_type(resource_type)
|
||||
r.set_resource(_edited_resource.call(getter))
|
||||
r.set_h_size_flags(SIZE_EXPAND_FILL)
|
||||
|
||||
bc.add_child(r)
|
||||
|
||||
var slot_idx : int = add_slot(getter, setter, bc)
|
||||
|
||||
r.connect("on_resource_changed", self, "on_widget_resource_changed", [ slot_idx ])
|
||||
|
||||
return slot_idx
|
||||
|
||||
func add_slot_line_edit(getter : String, setter : String, slot_name : String, placeholder : String = "") -> int:
|
||||
var bc : HBoxContainer = HBoxContainer.new()
|
||||
bc.set_h_size_flags(SIZE_EXPAND_FILL)
|
||||
@ -35,7 +58,7 @@ func add_slot_line_edit(getter : String, setter : String, slot_name : String, pl
|
||||
le.set_h_size_flags(SIZE_EXPAND_FILL)
|
||||
bc.add_child(le)
|
||||
|
||||
var slot_idx : int = add_slot(getter, setter, bc)
|
||||
var slot_idx : int = add_slot(getter, setter, bc)
|
||||
|
||||
le.text = _edited_resource.call(getter)
|
||||
|
||||
@ -307,6 +330,9 @@ func on_slot_enum_item_selected(val : int, slot_idx : int) -> void:
|
||||
func on_slot_line_edit_text_entered(text : String, slot_idx : int) -> void:
|
||||
_edited_resource.call(properties[slot_idx][2], text)
|
||||
|
||||
func on_widget_resource_changed(res : Resource, slot_idx : int) -> void:
|
||||
_edited_resource.call(properties[slot_idx][2], res)
|
||||
|
||||
func clear() -> void:
|
||||
properties.clear()
|
||||
|
||||
|
77
game/addons/world_generator/widgets/EditorResourceWidget.gd
Normal file
77
game/addons/world_generator/widgets/EditorResourceWidget.gd
Normal file
@ -0,0 +1,77 @@
|
||||
tool
|
||||
extends HBoxContainer
|
||||
|
||||
var _resource_type : String = "Resource"
|
||||
var _resource : Resource = null
|
||||
|
||||
signal on_resource_changed(new_res)
|
||||
|
||||
func _enter_tree():
|
||||
$ResourceButton.set_drag_forwarding(self)
|
||||
|
||||
func set_resource_type(type : String) -> void:
|
||||
_resource_type = type
|
||||
|
||||
func set_resource(res : Resource) -> void:
|
||||
if res && !res.is_class(_resource_type):
|
||||
return
|
||||
|
||||
var emit : bool = res != _resource
|
||||
|
||||
_resource = res
|
||||
|
||||
refresh_ui()
|
||||
|
||||
if emit:
|
||||
emit_signal("on_resource_changed", _resource)
|
||||
|
||||
func refresh_ui() -> void:
|
||||
if _resource:
|
||||
var text : String = _resource.resource_name
|
||||
|
||||
if text == "":
|
||||
text = _resource.get_class()
|
||||
|
||||
$ResourceButton.text = text
|
||||
else:
|
||||
$ResourceButton.text = "[null]"
|
||||
|
||||
func on_clear_button_pressed() -> void:
|
||||
if _resource:
|
||||
set_resource(null)
|
||||
|
||||
func on_resource_button_pressed() -> void:
|
||||
if _resource:
|
||||
#todo
|
||||
pass
|
||||
|
||||
#examples
|
||||
#{files:[res://modules/planets/test_planet/test_world.tres], from:@@4176:[Tree:9070], type:files}
|
||||
#{from:Button:[Button:917001], resource:[Resource:26180], type:resource}
|
||||
|
||||
func can_drop_data_fw(position, data, from_control):
|
||||
return true
|
||||
|
||||
func drop_data_fw(position, data, from_control):
|
||||
if data["type"] == "resource":
|
||||
var res : Resource = data["resource"]
|
||||
set_resource(res)
|
||||
elif data["type"] == "files":
|
||||
var files : Array = data["files"]
|
||||
|
||||
for f in files:
|
||||
var res : Resource = load(f)
|
||||
set_resource(res)
|
||||
return
|
||||
|
||||
func get_drag_data_fw(position, from_control):
|
||||
if !_resource:
|
||||
return
|
||||
|
||||
var d : Dictionary = Dictionary()
|
||||
|
||||
d["from"] = self
|
||||
d["resource"] = _resource
|
||||
d["type"] = "resource"
|
||||
|
||||
return d
|
@ -0,0 +1,26 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://addons/world_generator/widgets/EditorResourceWidget.gd" type="Script" id=1]
|
||||
|
||||
[node name="EditorResourceWidget" type="HBoxContainer"]
|
||||
margin_right = 376.0
|
||||
margin_bottom = 40.0
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="ResourceButton" type="Button" parent="."]
|
||||
margin_right = 342.0
|
||||
margin_bottom = 40.0
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Clear" type="Button" parent="."]
|
||||
margin_left = 346.0
|
||||
margin_right = 376.0
|
||||
margin_bottom = 40.0
|
||||
rect_min_size = Vector2( 30, 0 )
|
||||
text = "X"
|
||||
|
||||
[connection signal="pressed" from="ResourceButton" to="." method="on_resource_button_pressed"]
|
||||
[connection signal="pressed" from="Clear" to="." method="on_clear_button_pressed"]
|
Loading…
Reference in New Issue
Block a user