initial commit
This commit is contained in:
125
addons/cyclops_level_builder/controls/numeric_line_edit.gd
Normal file
125
addons/cyclops_level_builder/controls/numeric_line_edit.gd
Normal file
@ -0,0 +1,125 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2023 Mark McKay
|
||||
# https://github.com/blackears/cyclopsLevelBuilder
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
@tool
|
||||
extends PanelContainer
|
||||
class_name NumbericLineEdit
|
||||
|
||||
signal value_changed(value)
|
||||
|
||||
@export var value:float:
|
||||
get:
|
||||
return value
|
||||
set(v):
|
||||
if value == v:
|
||||
return
|
||||
value = v
|
||||
dirty = true
|
||||
|
||||
@export var snap_size:float = 1
|
||||
var dirty:bool = true
|
||||
|
||||
enum State{ IDLE, READY, DRAGGING, TEXT_EDIT }
|
||||
var state:State = State.IDLE
|
||||
|
||||
var mouse_down_pos:Vector2
|
||||
var drag_start_radius:float = 4
|
||||
var value_start_drag:float
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
# text = "%.4f" % value
|
||||
# $HBoxContainer/LineEdit.text = "%s" % value
|
||||
# $HBoxContainer/Label.text = "%s" % value
|
||||
$HBoxContainer/LineEdit.visible = false
|
||||
pass
|
||||
|
||||
func _process(delta):
|
||||
if dirty:
|
||||
$HBoxContainer/LineEdit.text = format_number(value)
|
||||
$HBoxContainer/Label.text = format_number(value)
|
||||
dirty = false
|
||||
|
||||
func format_number(val:float)->String:
|
||||
var text:String = "%.5f" % val
|
||||
var idx:int = text.findn(".")
|
||||
if idx != -1:
|
||||
text = text.rstrip("0")
|
||||
if text.right(1) == ".":
|
||||
text = text.left(-1)
|
||||
return text
|
||||
|
||||
|
||||
func _gui_input(event):
|
||||
if event is InputEventMouseButton:
|
||||
var e:InputEventMouseButton = event
|
||||
if e.is_pressed():
|
||||
if state == State.IDLE:
|
||||
mouse_down_pos = e.position
|
||||
state = State.READY
|
||||
else:
|
||||
if state == State.READY:
|
||||
$HBoxContainer/LineEdit.visible = true
|
||||
$HBoxContainer/Label.visible = false
|
||||
state = State.TEXT_EDIT
|
||||
elif state == State.DRAGGING:
|
||||
state = State.IDLE
|
||||
|
||||
|
||||
accept_event()
|
||||
|
||||
elif event is InputEventMouseMotion:
|
||||
var e:InputEventMouseMotion = event
|
||||
if state == State.READY:
|
||||
if e.position.distance_to(mouse_down_pos) >= drag_start_radius:
|
||||
state = State.DRAGGING
|
||||
value_start_drag = value
|
||||
|
||||
elif state == State.DRAGGING:
|
||||
var offset = e.position.x - mouse_down_pos.x
|
||||
var new_value = value_start_drag + (offset * snap_size / 20.0)
|
||||
#print("-new_value %s" % new_value)
|
||||
new_value = ceil(new_value / snap_size) * snap_size
|
||||
|
||||
#print("new_value %s" % new_value)
|
||||
|
||||
if value != new_value:
|
||||
value = new_value
|
||||
value_changed.emit(value)
|
||||
dirty = true
|
||||
|
||||
func _on_line_edit_text_submitted(new_text):
|
||||
var regex = RegEx.new()
|
||||
regex.compile("^[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)$")
|
||||
var result:RegExMatch = regex.search(new_text)
|
||||
if result:
|
||||
# print("found match")
|
||||
value = float(new_text)
|
||||
value_changed.emit(value)
|
||||
|
||||
dirty = true
|
||||
state = State.IDLE
|
||||
$HBoxContainer/LineEdit.visible = false
|
||||
$HBoxContainer/Label.visible = true
|
||||
# text = "%s" % value
|
||||
# print("text changed2 %s" % text)
|
26
addons/cyclops_level_builder/controls/numeric_line_edit.tscn
Normal file
26
addons/cyclops_level_builder/controls/numeric_line_edit.tscn
Normal file
@ -0,0 +1,26 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://diibmlqy1mpqb"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/cyclops_level_builder/controls/numeric_line_edit.gd" id="1_u8bpo"]
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer"]
|
||||
offset_right = 476.0
|
||||
offset_bottom = 40.0
|
||||
script = ExtResource("1_u8bpo")
|
||||
snap_size = 0.125
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="LineEdit" type="LineEdit" parent="HBoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "0"
|
||||
select_all_on_focus = true
|
||||
|
||||
[node name="Label" type="Label" parent="HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "0"
|
||||
|
||||
[connection signal="text_submitted" from="HBoxContainer/LineEdit" to="." method="_on_line_edit_text_submitted"]
|
@ -0,0 +1,66 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2023 Mark McKay
|
||||
# https://github.com/blackears/cyclopsLevelBuilder
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
@tool
|
||||
extends CheckBox
|
||||
class_name LineEditorBool
|
||||
|
||||
var resource:Resource:
|
||||
get:
|
||||
return resource
|
||||
set(value):
|
||||
resource = value
|
||||
dirty = true
|
||||
|
||||
var prop_name:String:
|
||||
get:
|
||||
return prop_name
|
||||
set(value):
|
||||
prop_name = value
|
||||
dirty = true
|
||||
|
||||
var dirty = true
|
||||
|
||||
func update_from_resource():
|
||||
if resource:
|
||||
var result = resource.get(prop_name)
|
||||
if result != null:
|
||||
button_pressed = result
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
if dirty:
|
||||
update_from_resource()
|
||||
dirty = false
|
||||
|
||||
|
||||
func _on_toggled(button_pressed):
|
||||
if resource:
|
||||
print("prop_name %s" % prop_name)
|
||||
print("button_pressed %s" % button_pressed)
|
||||
resource.set(prop_name, button_pressed)
|
@ -0,0 +1,10 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dpncabeqiv1xo"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/cyclops_level_builder/controls/resource_inspector/line_editor_bool.gd" id="1_sn3qq"]
|
||||
|
||||
[node name="CheckBox" type="CheckBox"]
|
||||
offset_right = 24.0
|
||||
offset_bottom = 24.0
|
||||
script = ExtResource("1_sn3qq")
|
||||
|
||||
[connection signal="toggled" from="." to="." method="_on_toggled"]
|
@ -0,0 +1,65 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2023 Mark McKay
|
||||
# https://github.com/blackears/cyclopsLevelBuilder
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
@tool
|
||||
extends SpinBox
|
||||
class_name LineEditorFloat
|
||||
|
||||
|
||||
var resource:Resource:
|
||||
get:
|
||||
return resource
|
||||
set(value):
|
||||
resource = value
|
||||
dirty = true
|
||||
|
||||
var prop_name:String:
|
||||
get:
|
||||
return prop_name
|
||||
set(value):
|
||||
prop_name = value
|
||||
dirty = true
|
||||
|
||||
var dirty = true
|
||||
|
||||
func update_from_resource():
|
||||
if resource:
|
||||
var result = resource.get(prop_name)
|
||||
if result != null:
|
||||
value = result
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
if dirty:
|
||||
update_from_resource()
|
||||
dirty = false
|
||||
|
||||
|
||||
func _on_value_changed(value):
|
||||
if resource:
|
||||
resource.set(prop_name, value)
|
@ -0,0 +1,11 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dg45e7tw7ttu3"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/cyclops_level_builder/controls/resource_inspector/line_editor_float.gd" id="1_o1hmb"]
|
||||
|
||||
[node name="SpinBox" type="SpinBox"]
|
||||
offset_right = 83.0625
|
||||
offset_bottom = 31.0
|
||||
step = 0.001
|
||||
script = ExtResource("1_o1hmb")
|
||||
|
||||
[connection signal="value_changed" from="." to="." method="_on_value_changed"]
|
@ -0,0 +1,71 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2023 Mark McKay
|
||||
# https://github.com/blackears/cyclopsLevelBuilder
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
@tool
|
||||
extends SpinBox
|
||||
class_name LineEditorInt
|
||||
|
||||
var resource:Resource:
|
||||
get:
|
||||
return resource
|
||||
set(value):
|
||||
resource = value
|
||||
dirty = true
|
||||
|
||||
var prop_name:String:
|
||||
get:
|
||||
return prop_name
|
||||
set(value):
|
||||
prop_name = value
|
||||
dirty = true
|
||||
|
||||
var dirty = true
|
||||
|
||||
func update_from_resource():
|
||||
#print("update_from_resource()")
|
||||
if resource:
|
||||
#print("resource %s" % resource)
|
||||
#print("prop_name %s" % prop_name)
|
||||
var result = resource.get(prop_name)
|
||||
#print("result %s" % result)
|
||||
if result != null:
|
||||
value = result
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
if dirty:
|
||||
update_from_resource()
|
||||
dirty = false
|
||||
|
||||
|
||||
func _on_value_changed(value):
|
||||
print("_on_value_changed(value)")
|
||||
if resource:
|
||||
print("prop_name %s" % prop_name)
|
||||
print("value %s" % value)
|
||||
resource.set(prop_name, value)
|
@ -0,0 +1,10 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dh6frljlp7oqe"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/cyclops_level_builder/controls/resource_inspector/line_editor_int.gd" id="1_ryygx"]
|
||||
|
||||
[node name="SpinBox" type="SpinBox"]
|
||||
offset_right = 83.0625
|
||||
offset_bottom = 40.0
|
||||
script = ExtResource("1_ryygx")
|
||||
|
||||
[connection signal="value_changed" from="." to="." method="_on_value_changed"]
|
@ -0,0 +1,86 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2023 Mark McKay
|
||||
# https://github.com/blackears/cyclopsLevelBuilder
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
@tool
|
||||
extends Control
|
||||
class_name ResourceInspector
|
||||
|
||||
@export var target:Resource:
|
||||
get:
|
||||
return target
|
||||
set(value):
|
||||
target = value
|
||||
build()
|
||||
|
||||
func add_label(name:String):
|
||||
var label:Label = Label.new()
|
||||
label.text = name
|
||||
$GridContainer.add_child(label)
|
||||
|
||||
func build():
|
||||
for child in $GridContainer.get_children():
|
||||
$GridContainer.remove_child(child)
|
||||
|
||||
if !target:
|
||||
return
|
||||
|
||||
for prop_dict in target.get_property_list():
|
||||
var prop_name:String = prop_dict["name"]
|
||||
# prop_dict["class_name"]
|
||||
|
||||
var type:Variant.Type = prop_dict["type"]
|
||||
match type:
|
||||
TYPE_BOOL:
|
||||
add_label(prop_name)
|
||||
|
||||
var editor:LineEditorBool = preload("res://addons/cyclops_level_builder/controls/resource_inspector/line_editor_bool.tscn").instantiate()
|
||||
editor.resource = target
|
||||
editor.prop_name = prop_name
|
||||
$GridContainer.add_child(editor)
|
||||
|
||||
TYPE_INT:
|
||||
add_label(prop_name)
|
||||
|
||||
var editor:LineEditorInt = preload("res://addons/cyclops_level_builder/controls/resource_inspector/line_editor_int.tscn").instantiate()
|
||||
editor.resource = target
|
||||
editor.prop_name = prop_name
|
||||
$GridContainer.add_child(editor)
|
||||
|
||||
TYPE_FLOAT:
|
||||
add_label(prop_name)
|
||||
|
||||
var editor:LineEditorFloat = preload("res://addons/cyclops_level_builder/controls/resource_inspector/line_editor_float.tscn").instantiate()
|
||||
editor.resource = target
|
||||
editor.prop_name = prop_name
|
||||
$GridContainer.add_child(editor)
|
||||
|
||||
pass
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
@ -0,0 +1,18 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://c2484sv0ymy2e"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/cyclops_level_builder/controls/resource_inspector/resource_inspector.gd" id="1_m3yhx"]
|
||||
|
||||
[node name="object_inspector" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_m3yhx")
|
||||
|
||||
[node name="GridContainer" type="GridContainer" parent="."]
|
||||
layout_mode = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
columns = 2
|
Reference in New Issue
Block a user