Add color and number editing docks

This commit is contained in:
don-tnowe 2022-09-22 15:53:03 +03:00
parent 7f30ee06fd
commit af6f49b7e4
8 changed files with 628 additions and 217 deletions

View File

@ -146,6 +146,7 @@ func _set_sorting(sort_by):
func _create_table(root_node : Control, columns_changed : bool):
deselect_all_cells()
edited_cells = []
edit_cursor_positions = []
var new_node : Control
@ -275,11 +276,13 @@ func select_cell(cell : Control):
edit_cursor_positions.append(column_editors[column_index].get_text_length(cell))
for x in get_node(path_property_editors).get_children():
x.visible = x.can_edit_value(
x.visible = x.try_edit_value(
column_editors[column_index].get_value(cell),
column_types[_get_cell_column(cell)],
column_hints[_get_cell_column(cell)]
)
x.get_node(x.path_property_name).text = columns[column_index]
return
if column_index != _get_cell_column(edited_cells[edited_cells.size() - 1]):
@ -287,9 +290,12 @@ func select_cell(cell : Control):
var row_start = _get_cell_row(edited_cells[edited_cells.size() - 1])
var row_end := _get_cell_row(cell)
var edge_shift = -1 if row_start > row_end else 1
row_start += edge_shift
row_end += edge_shift
var table_root := get_node(path_table_root)
for i in range(row_end, row_start, 1 if row_start > row_end else -1):
for i in range(row_start, row_end, edge_shift):
var cur_cell := table_root.get_child(i * columns.size() + column_index)
if !cur_cell.visible:
# When search is active, some cells will be hidden.
@ -300,6 +306,44 @@ func select_cell(cell : Control):
edit_cursor_positions.append(column_editors[column_index].get_text_length(cur_cell))
func set_edited_cells_values(new_cell_values : Array):
var column = _get_cell_column(edited_cells[0])
var edited_cells_resources = _get_edited_cells_resources()
editor_plugin.undo_redo.create_action("Set Cell Value Externally")
editor_plugin.undo_redo.add_undo_method(
self,
"_update_resources",
edited_cells_resources.duplicate(),
edited_cells.duplicate(),
column,
get_edited_cells_values()
)
for i in new_cell_values.size():
column_editors[column].set_value(edited_cells[i], new_cell_values[i])
editor_plugin.undo_redo.add_do_method(
self,
"_update_resources",
edited_cells_resources.duplicate(),
edited_cells.duplicate(),
column,
get_edited_cells_values()
)
editor_plugin.undo_redo.commit_action()
editor_interface.get_resource_filesystem().scan()
undo_redo_version = editor_plugin.undo_redo.get_version()
func get_edited_cells_values() -> Array:
var arr := edited_cells.duplicate()
var cell_editor = column_editors[_get_cell_column(edited_cells[0])]
for i in arr.size():
arr[i] = cell_editor.get_value(arr[i])
return arr
func _can_select_cell(cell : Control) -> bool:
if edited_cells.size() == 0:
return true
@ -352,16 +396,19 @@ func _on_cell_gui_input(event : InputEvent, cell : Control):
func _gui_input(event : InputEvent):
if event is InputEventMouseButton:
if event.button_index != BUTTON_LEFT:
return
grab_focus()
if !event.pressed:
deselect_all_cells()
func _input(event : InputEvent):
if !event is InputEventKey or !event.pressed:
if !has_focus() or edited_cells.size() == 0:
return
if !visible or edited_cells.size() == 0:
if !event is InputEventKey or !event.pressed:
return
if column_types[_get_cell_column(edited_cells[0])] == TYPE_OBJECT:
@ -387,7 +434,7 @@ func _input(event : InputEvent):
if Input.is_key_pressed(KEY_CONTROL) and event.scancode == KEY_Y:
editor_plugin.undo_redo.redo()
return
editor_plugin.undo_redo.create_action("Set Cell Value")
editor_plugin.undo_redo.add_undo_method(
self,
@ -395,7 +442,7 @@ func _input(event : InputEvent):
edited_cells_resources.duplicate(),
edited_cells.duplicate(),
_get_cell_column(edited_cells[0]),
_get_edited_cells_values()
get_edited_cells_values()
)
_key_specific_action(event)
@ -407,7 +454,7 @@ func _input(event : InputEvent):
edited_cells_resources.duplicate(),
edited_cells.duplicate(),
_get_cell_column(edited_cells[0]),
_get_edited_cells_values()
get_edited_cells_values()
)
editor_plugin.undo_redo.commit_action()
editor_interface.get_resource_filesystem().scan()
@ -510,15 +557,6 @@ func _get_edited_cells_resources() -> Array:
return arr
func _get_edited_cells_values() -> Array:
var arr := edited_cells.duplicate()
var cell_editor = column_editors[_get_cell_column(edited_cells[0])]
for i in arr.size():
arr[i] = cell_editor.get_value(edited_cells[i])
return arr
func _on_SearchCond_text_entered(new_text : String):
var new_script := GDScript.new()
new_script.source_code = "static func can_show(res, index):\n\treturn " + new_text
@ -531,7 +569,3 @@ func _on_SearchCond_text_entered(new_text : String):
var row_visible = new_script_instance.can_show(rows[i], i)
for j in columns.size():
table_elements[(i + 1) * columns.size() + j].visible = row_visible
func _on_focus_exited():
deselect_all_cells()

View File

@ -237,6 +237,17 @@ __meta__ = {
unique_name_in_owner = true
margin_right = 1020.0
[node name="EditColor" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Footer/PropertyEditors" instance=ExtResource( 7 )]
visible = false
anchor_right = 0.0
margin_right = 1020.0
[node name="EditNumber" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Footer/PropertyEditors" instance=ExtResource( 8 )]
visible = false
anchor_right = 0.0
margin_right = 1020.0
margin_bottom = 84.0
[node name="HBoxContainer" type="HBoxContainer" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Footer"]
margin_top = 4.0
margin_right = 1020.0
@ -380,7 +391,6 @@ https://twitter.com/don_tnowe
Issues and contribution:
https://github.com/don-tnowe/godot-resources-as-sheets-plugin"
[connection signal="focus_exited" from="." to="." method="_on_focus_exited"]
[connection signal="text_entered" from="HeaderContentSplit/VBoxContainer/HBoxContainer/HBoxContainer/Path" to="." method="_on_Path_text_entered"]
[connection signal="pressed" from="HeaderContentSplit/VBoxContainer/HBoxContainer/HBoxContainer/SelectDir" to="Control/FileDialog" method="popup_centered"]
[connection signal="item_selected" from="HeaderContentSplit/VBoxContainer/HBoxContainer/RecentPaths" to="." method="_on_RecentPaths_item_selected"]

View File

@ -2,6 +2,20 @@ tool
class_name SheetsDockEditor
extends Control
# Override to define when to show the dock.
func can_edit_value(value, type, property_hint) -> bool:
return true
export var path_property_name := NodePath("Header/Label")
var sheet : Control
var selection : Array
func _ready():
var parent := get_parent()
while parent != null and !parent.has_method("select_cell"):
parent = parent.get_parent()
sheet = parent
get_node(path_property_name).add_font_override("bold", get_font("bold", "EditorFonts"))
# Override to define when to show the dock and, if it can edit the value, how to handle it.
func try_edit_value(value, type, property_hint) -> bool:
return true

View File

@ -1,6 +1,122 @@
tool
extends SheetsDockEditor
onready var _value_rect := $"EditColor/ColorProper/ColorRect"
onready var _color_picker_panel := $"EditColor/VSeparator6/Panel"
onready var _color_picker := $"EditColor/VSeparator6/Panel/MarginContainer/ColorPicker"
onready var _custom_value_edit := $"EditColor/CustomX/LineEdit"
func can_edit_value(value, type, property_hint) -> bool:
return type == TYPE_COLOR
var _stored_value := Color.white
func _ready():
_connect_buttons($"EditColor/RGBGrid", 0, 0)
_connect_buttons($"EditColor/RGBGrid", 5, 1)
_connect_buttons($"EditColor/RGBGrid", 10, 2)
_connect_buttons($"EditColor/HSVGrid", 0, 3)
_connect_buttons($"EditColor/HSVGrid", 5, 4)
_connect_buttons($"EditColor/HSVGrid", 10, 5)
func _connect_buttons(grid, start_index, property_bind):
grid.get_child(start_index + 0).connect("pressed", self, "_increment_values_custom", [-1.0, property_bind])
grid.get_child(start_index + 1).connect("pressed", self, "_increment_values", [-10.0, property_bind])
grid.get_child(start_index + 3).connect("pressed", self, "_increment_values", [10.0, property_bind])
grid.get_child(start_index + 4).connect("pressed", self, "_increment_values_custom", [1.0, property_bind])
func try_edit_value(value, type, property_hint) -> bool:
_color_picker_panel.set_as_toplevel(false)
if type != TYPE_COLOR:
return false
_set_stored_value(value)
_color_picker_panel.visible = false
return true
func _set_stored_value(v):
_stored_value = v
_color_picker.color = v
_value_rect.color = v
func _increment_values(by : float, property : int):
var cell_values = sheet.get_edited_cells_values()
match property:
0:
_stored_value.r += by / 255.0
for i in cell_values.size():
cell_values[i].r += by / 255.0
1:
_stored_value.g += by / 255.0
for i in cell_values.size():
cell_values[i].g += by / 255.0
2:
_stored_value.b += by / 255.0
for i in cell_values.size():
cell_values[i].b += by / 255.0
3:
# Hue has 360 degrees and loops
_stored_value.h += by / 360.0
for i in cell_values.size():
cell_values[i].h = fposmod(cell_values[i].h + by / 180.0, 1.0)
4:
_stored_value.s += by * 0.005
for i in cell_values.size():
cell_values[i].s += by * 0.01
5:
_stored_value.v += by * 0.005
for i in cell_values.size():
cell_values[i].v += by * 0.01
_set_stored_value(_stored_value)
sheet.set_edited_cells_values(cell_values)
func _increment_values_custom(multiplier : float, property : int):
if property == 4 || property == 5:
# Numbered buttons increment by 5 for Sat and Value, so hue is x0.5 effect. Negate it here
multiplier *= 2.0
_increment_values(float(_custom_value_edit.text) * multiplier, property)
func _on_Button_pressed():
_color_picker_panel.visible = !_color_picker_panel.visible
if _color_picker_panel.visible:
_color_picker_panel.set_as_toplevel(true)
_color_picker_panel.rect_global_position = (
sheet.rect_global_position
+ Vector2(0, sheet.rect_size.y - _color_picker_panel.rect_size.y)
+ Vector2(16, -16)
)
_color_picker_panel.rect_global_position.y = clamp(
_color_picker_panel.rect_global_position.y,
0,
sheet._editor_plugin.get_editor_interface().get_base_control().rect_size.y
)
_color_picker.color = _stored_value
elif _color_picker.color != _stored_value:
_set_stored_value(_color_picker.color)
update_cell_values()
func _on_ColorPicker_gui_input(event : InputEvent):
if event is InputEventMouseButton && !event.pressed:
_set_stored_value(_color_picker.color)
update_cell_values()
func update_cell_values():
var values = sheet.get_edited_cells_values()
for i in values.size():
values[i] = _stored_value
sheet.set_edited_cells_values(values)

View File

@ -6,6 +6,7 @@
anchor_right = 1.0
margin_bottom = 86.0
rect_pivot_offset = Vector2( -460, -28 )
mouse_filter = 0
script = ExtResource( 1 )
[node name="Header" type="HBoxContainer" parent="."]
@ -28,7 +29,7 @@ margin_right = 455.0
margin_bottom = 14.0
size_flags_horizontal = 3
[node name="Label2" type="Label" parent="Header"]
[node name="Label" type="Label" parent="Header"]
margin_left = 459.0
margin_right = 565.0
margin_bottom = 14.0
@ -47,7 +48,7 @@ margin_bottom = 86.0
alignment = 1
[node name="VSeparator7" type="Control" parent="EditColor"]
margin_right = 188.0
margin_right = 172.0
margin_bottom = 68.0
rect_min_size = Vector2( 16, 0 )
size_flags_horizontal = 3
@ -96,7 +97,7 @@ margin_bottom = 20.0
text = "+X"
[node name="RGBGrid" type="GridContainer" parent="EditColor"]
margin_left = 192.0
margin_left = 176.0
margin_right = 353.0
margin_bottom = 68.0
columns = 5
@ -110,29 +111,29 @@ text = "-X"
[node name="Button2" type="Button" parent="EditColor/RGBGrid"]
modulate = Color( 1, 0.780392, 0.780392, 1 )
margin_left = 29.0
margin_right = 54.0
margin_right = 62.0
margin_bottom = 20.0
text = "-5"
text = "-10"
[node name="Label" type="Label" parent="EditColor/RGBGrid"]
margin_left = 58.0
margin_left = 66.0
margin_top = 3.0
margin_right = 97.0
margin_right = 105.0
margin_bottom = 17.0
text = "Red"
align = 1
[node name="Button5" type="Button" parent="EditColor/RGBGrid"]
modulate = Color( 1, 0.780392, 0.780392, 1 )
margin_left = 101.0
margin_right = 129.0
margin_left = 109.0
margin_right = 145.0
margin_bottom = 20.0
text = "+5"
text = "+10"
[node name="Button6" type="Button" parent="EditColor/RGBGrid"]
modulate = Color( 1, 0.780392, 0.780392, 1 )
margin_left = 133.0
margin_right = 161.0
margin_left = 149.0
margin_right = 177.0
margin_bottom = 20.0
text = "+X"
@ -147,31 +148,31 @@ text = "-X"
modulate = Color( 0.666667, 1, 0.745098, 1 )
margin_left = 29.0
margin_top = 24.0
margin_right = 54.0
margin_right = 62.0
margin_bottom = 44.0
text = "-5"
text = "-10"
[node name="Label2" type="Label" parent="EditColor/RGBGrid"]
margin_left = 58.0
margin_left = 66.0
margin_top = 27.0
margin_right = 97.0
margin_right = 105.0
margin_bottom = 41.0
text = "Green"
align = 1
[node name="Button11" type="Button" parent="EditColor/RGBGrid"]
modulate = Color( 0.666667, 1, 0.745098, 1 )
margin_left = 101.0
margin_left = 109.0
margin_top = 24.0
margin_right = 129.0
margin_right = 145.0
margin_bottom = 44.0
text = "+5"
text = "+10"
[node name="Button12" type="Button" parent="EditColor/RGBGrid"]
modulate = Color( 0.666667, 1, 0.745098, 1 )
margin_left = 133.0
margin_left = 149.0
margin_top = 24.0
margin_right = 161.0
margin_right = 177.0
margin_bottom = 44.0
text = "+X"
@ -186,31 +187,31 @@ text = "-X"
modulate = Color( 0.772549, 0.792157, 1, 1 )
margin_left = 29.0
margin_top = 48.0
margin_right = 54.0
margin_right = 62.0
margin_bottom = 68.0
text = "-5"
text = "-10"
[node name="Label3" type="Label" parent="EditColor/RGBGrid"]
margin_left = 58.0
margin_left = 66.0
margin_top = 51.0
margin_right = 97.0
margin_right = 105.0
margin_bottom = 65.0
text = "Blue"
align = 1
[node name="Button17" type="Button" parent="EditColor/RGBGrid"]
modulate = Color( 0.772549, 0.792157, 1, 1 )
margin_left = 101.0
margin_left = 109.0
margin_top = 48.0
margin_right = 129.0
margin_right = 145.0
margin_bottom = 68.0
text = "+5"
text = "+10"
[node name="Button18" type="Button" parent="EditColor/RGBGrid"]
modulate = Color( 0.772549, 0.792157, 1, 1 )
margin_left = 133.0
margin_left = 149.0
margin_top = 48.0
margin_right = 161.0
margin_right = 177.0
margin_bottom = 68.0
text = "+X"
@ -235,38 +236,6 @@ margin_right = 96.0
margin_bottom = 68.0
text = "Choose Color"
[node name="Panel" type="PanelContainer" parent="EditColor/ColorProper/Button"]
visible = false
anchor_left = 0.5
anchor_right = 0.5
margin_left = -157.5
margin_top = -529.0
margin_right = 157.5
margin_bottom = -53.0
[node name="Panel2" type="Panel" parent="EditColor/ColorProper/Button/Panel"]
self_modulate = Color( 1.5, 1.5, 1.5, 1 )
margin_left = 7.0
margin_top = 7.0
margin_right = 316.0
margin_bottom = 477.0
[node name="MarginContainer" type="MarginContainer" parent="EditColor/ColorProper/Button/Panel"]
margin_left = 7.0
margin_top = 7.0
margin_right = 316.0
margin_bottom = 477.0
custom_constants/margin_right = 4
custom_constants/margin_top = 4
custom_constants/margin_left = 4
custom_constants/margin_bottom = 4
[node name="ColorPicker" type="ColorPicker" parent="EditColor/ColorProper/Button/Panel/MarginContainer"]
margin_left = 4.0
margin_top = 4.0
margin_right = 305.0
margin_bottom = 466.0
[node name="VSeparator2" type="VSeparator" parent="EditColor"]
margin_left = 465.0
margin_right = 469.0
@ -274,7 +243,7 @@ margin_bottom = 68.0
[node name="HSVGrid" type="GridContainer" parent="EditColor"]
margin_left = 473.0
margin_right = 630.0
margin_right = 646.0
margin_bottom = 68.0
columns = 5
@ -287,29 +256,29 @@ text = "-X"
[node name="Button2" type="Button" parent="EditColor/HSVGrid"]
modulate = Color( 0.898039, 1, 0.698039, 1 )
margin_left = 29.0
margin_right = 54.0
margin_right = 62.0
margin_bottom = 20.0
text = "-5"
text = "-10"
[node name="Label" type="Label" parent="EditColor/HSVGrid"]
margin_left = 58.0
margin_left = 66.0
margin_top = 3.0
margin_right = 93.0
margin_right = 101.0
margin_bottom = 17.0
text = "Hue"
align = 1
[node name="Button5" type="Button" parent="EditColor/HSVGrid"]
modulate = Color( 0.717647, 1, 0.980392, 1 )
margin_left = 97.0
margin_right = 125.0
margin_left = 105.0
margin_right = 141.0
margin_bottom = 20.0
text = "+5"
text = "+10"
[node name="Button6" type="Button" parent="EditColor/HSVGrid"]
modulate = Color( 0.74902, 0.729412, 1, 1 )
margin_left = 129.0
margin_right = 157.0
margin_left = 145.0
margin_right = 173.0
margin_bottom = 20.0
text = "+X"
@ -322,29 +291,29 @@ text = "-X"
[node name="Button8" type="Button" parent="EditColor/HSVGrid"]
margin_left = 29.0
margin_top = 24.0
margin_right = 54.0
margin_right = 62.0
margin_bottom = 44.0
text = "-5"
[node name="Label2" type="Label" parent="EditColor/HSVGrid"]
margin_left = 58.0
margin_left = 66.0
margin_top = 27.0
margin_right = 93.0
margin_right = 101.0
margin_bottom = 41.0
text = "Sat"
align = 1
[node name="Button11" type="Button" parent="EditColor/HSVGrid"]
margin_left = 97.0
margin_left = 105.0
margin_top = 24.0
margin_right = 125.0
margin_right = 141.0
margin_bottom = 44.0
text = "+5"
[node name="Button12" type="Button" parent="EditColor/HSVGrid"]
margin_left = 129.0
margin_left = 145.0
margin_top = 24.0
margin_right = 157.0
margin_right = 173.0
margin_bottom = 44.0
text = "+X"
@ -357,40 +326,40 @@ text = "-X"
[node name="Button14" type="Button" parent="EditColor/HSVGrid"]
margin_left = 29.0
margin_top = 48.0
margin_right = 54.0
margin_right = 62.0
margin_bottom = 68.0
text = "-5"
[node name="Label3" type="Label" parent="EditColor/HSVGrid"]
margin_left = 58.0
margin_left = 66.0
margin_top = 51.0
margin_right = 93.0
margin_right = 101.0
margin_bottom = 65.0
text = "Value"
align = 1
[node name="Button17" type="Button" parent="EditColor/HSVGrid"]
margin_left = 97.0
margin_left = 105.0
margin_top = 48.0
margin_right = 125.0
margin_right = 141.0
margin_bottom = 68.0
text = "+5"
[node name="Button18" type="Button" parent="EditColor/HSVGrid"]
margin_left = 129.0
margin_left = 145.0
margin_top = 48.0
margin_right = 157.0
margin_right = 173.0
margin_bottom = 68.0
text = "+X"
[node name="VSeparator4" type="VSeparator" parent="EditColor"]
margin_left = 634.0
margin_right = 638.0
margin_left = 650.0
margin_right = 654.0
margin_bottom = 68.0
[node name="CustomX" type="VBoxContainer" parent="EditColor"]
margin_left = 642.0
margin_right = 832.0
margin_left = 658.0
margin_right = 848.0
margin_bottom = 68.0
[node name="Label" type="Label" parent="EditColor/CustomX"]
@ -407,8 +376,49 @@ margin_bottom = 68.0
text = "20"
[node name="VSeparator6" type="Control" parent="EditColor"]
margin_left = 836.0
margin_left = 852.0
margin_right = 1024.0
margin_bottom = 68.0
rect_min_size = Vector2( 16, 0 )
size_flags_horizontal = 3
[node name="Panel" type="PanelContainer" parent="EditColor/VSeparator6"]
visible = false
anchor_top = 1.0
anchor_bottom = 1.0
margin_left = -601.0
margin_top = -504.0
margin_right = -278.0
[node name="Panel2" type="Panel" parent="EditColor/VSeparator6/Panel"]
self_modulate = Color( 1.5, 1.5, 1.5, 1 )
margin_left = 7.0
margin_top = 7.0
margin_right = 316.0
margin_bottom = 497.0
[node name="MarginContainer" type="MarginContainer" parent="EditColor/VSeparator6/Panel"]
margin_left = 7.0
margin_top = 7.0
margin_right = 316.0
margin_bottom = 497.0
custom_constants/margin_right = 4
custom_constants/margin_top = 4
custom_constants/margin_left = 4
custom_constants/margin_bottom = 4
[node name="ColorPicker" type="ColorPicker" parent="EditColor/VSeparator6/Panel/MarginContainer"]
margin_left = 4.0
margin_top = 4.0
margin_right = 305.0
margin_bottom = 486.0
[node name="Button" type="Button" parent="EditColor/VSeparator6/Panel/MarginContainer/ColorPicker"]
margin_top = 462.0
margin_right = 301.0
margin_bottom = 482.0
text = "OK"
[connection signal="pressed" from="EditColor/ColorProper/Button" to="." method="_on_Button_pressed"]
[connection signal="gui_input" from="EditColor/VSeparator6/Panel/MarginContainer/ColorPicker" to="." method="_on_ColorPicker_gui_input"]
[connection signal="pressed" from="EditColor/VSeparator6/Panel/MarginContainer/ColorPicker/Button" to="." method="_on_Button_pressed"]

View File

@ -1,27 +1,157 @@
tool
extends SheetsDockEditor
onready var number_panel = $"HBoxContainer/CustomX/HBoxContainer/NumberPanel"
onready var _value_label := $"HBoxContainer/HBoxContainer/NumberPanel/Label"
onready var _button_grid := $"HBoxContainer/HBoxContainer/GridContainer"
onready var _sequence_gen_inputs := $"HBoxContainer/CustomX2/HBoxContainer"
onready var _custom_value_edit := $"HBoxContainer/CustomX/LineEdit"
var mouse_down := false
var _stored_value = 0
var _stored_value_is_int := false
var _mouse_drag_increment := 0.0
var _mouse_down := false
func can_edit_value(value, type, property_hint) -> bool:
return type == TYPE_REAL or type == TYPE_INT
func _ready():
_button_grid.get_child(0).connect("pressed", self, "_increment_values", [0.1])
_button_grid.get_child(1).connect("pressed", self, "_increment_values", [1])
_button_grid.get_child(2).connect("pressed", self, "_increment_values", [10])
_button_grid.get_child(3).connect("pressed", self, "_increment_values", [100])
_button_grid.get_child(4).connect("pressed", self, "_increment_values_custom", [true, false])
_button_grid.get_child(5).connect("pressed", self, "_increment_values_custom", [true, true])
_button_grid.get_child(6).connect("pressed", self, "_increment_values", [-0.1])
_button_grid.get_child(7).connect("pressed", self, "_increment_values", [-1])
_button_grid.get_child(8).connect("pressed", self, "_increment_values", [-10])
_button_grid.get_child(9).connect("pressed", self, "_increment_values", [-100])
_button_grid.get_child(10).connect("pressed", self, "_increment_values_custom",[false, false])
_button_grid.get_child(11).connect("pressed", self, "_increment_values_custom",[false, true])
func try_edit_value(value, type, property_hint) -> bool:
if type != TYPE_REAL and type != TYPE_INT:
return false
_stored_value = value
_value_label.text = str(value)
_stored_value_is_int = type != TYPE_REAL
_button_grid.columns = 5 if _stored_value_is_int else 6
_button_grid.get_child(0).visible = !_stored_value_is_int
_button_grid.get_child(6).visible = !_stored_value_is_int
return true
func _increment_values(by : float):
var cell_values = sheet.get_edited_cells_values()
if _stored_value_is_int:
_stored_value += int(by)
for i in cell_values.size():
cell_values[i] += int(by)
else:
_stored_value += by
for i in cell_values.size():
cell_values[i] += by
sheet.set_edited_cells_values(cell_values)
_value_label.text = str(_stored_value)
func _increment_values_custom(positive : bool, multiplier : bool):
var value := float(_custom_value_edit.text)
if !multiplier:
_increment_values(value if positive else -value)
else:
if !positive: value = 1 / value
var cell_values = sheet.get_edited_cells_values()
_stored_value *= value
for i in cell_values.size():
cell_values[i] *= value
if _stored_value_is_int:
cell_values[i] = int(cell_values[i])
sheet.set_edited_cells_values(cell_values)
_value_label.text = str(_stored_value)
func _on_NumberPanel_gui_input(event):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
if event.pressed:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
mouse_down = true
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
if event.pressed:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
_mouse_drag_increment = 0.0
_mouse_down = true
else:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
if mouse_down:
Input.warp_mouse_position(number_panel.rect_global_position + number_panel.rect_size * 0.5)
mouse_down = false
else:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
if _mouse_down:
Input.warp_mouse_position(_value_label.rect_global_position + _value_label.rect_size * 0.5)
_increment_values(_mouse_drag_increment)
_mouse_down = false
if mouse_down and event is InputEventMouseMotion:
number_panel.get_child(0).text = str(float(number_panel.get_child(0).text) + event.relative.x * 0.01)
if _mouse_down and event is InputEventMouseMotion:
if _stored_value_is_int:
_mouse_drag_increment += event.relative.x * 0.25
_value_label.text = str(_stored_value + int(_mouse_drag_increment))
else:
_mouse_drag_increment += event.relative.x * 0.01
_value_label.text = str(_stored_value + _mouse_drag_increment)
func _on_SequenceFill_pressed(add : bool = false):
sheet.set_edited_cells_values(_fill_sequence(sheet.get_edited_cells_values(), add))
func _fill_sequence(arr : Array, add : bool = false) -> Array:
if !_sequence_gen_inputs.get_child(0).text.is_valid_float():
return arr
var start := float(_sequence_gen_inputs.get_child(0).text)
var end = null
var step = null
if _sequence_gen_inputs.get_child(2).text.is_valid_float():
step = float(_sequence_gen_inputs.get_child(2).text)
if _sequence_gen_inputs.get_child(1).text.is_valid_float():
end = float(_sequence_gen_inputs.get_child(1).text)
if end == null:
end = INF if step == null or step >= 0 else -INF
var end_is_higher = end > start
if step == null:
if end == null or end == INF or end == -INF:
step = 0.0
else:
step = (end - start) / arr.size()
if _stored_value_is_int:
if start != null:
start = int(start)
if step != null:
step = int(step)
if end != INF and end != -INF:
end = int(end)
var cur = start
if !add:
for i in arr.size():
arr[i] = 0
# The range() global function can also be used, but does not work with floats.
for i in arr.size():
arr[i] = arr[i] + cur
cur += step
if (end_is_higher and cur >= end) or (!end_is_higher and cur <= end):
cur += (start - end)
return arr

View File

@ -6,6 +6,7 @@
anchor_right = 1.0
margin_bottom = 86.0
rect_pivot_offset = Vector2( -460, -28 )
mouse_filter = 0
script = ExtResource( 1 )
[node name="Header" type="HBoxContainer" parent="."]
@ -28,7 +29,7 @@ margin_right = 455.0
margin_bottom = 14.0
size_flags_horizontal = 3
[node name="Label2" type="Label" parent="Header"]
[node name="Label" type="Label" parent="Header"]
margin_left = 459.0
margin_right = 565.0
margin_bottom = 14.0
@ -46,111 +47,221 @@ margin_right = 1024.0
margin_bottom = 84.0
alignment = 1
[node name="CustomX" type="VBoxContainer" parent="HBoxContainer"]
margin_left = 275.0
margin_right = 748.0
[node name="CustomX2" type="VBoxContainer" parent="HBoxContainer"]
margin_left = 202.0
margin_right = 384.0
margin_bottom = 66.0
[node name="HBoxContainer" type="HBoxContainer" parent="HBoxContainer/CustomX"]
margin_right = 473.0
margin_bottom = 20.0
[node name="HBoxContainer3" type="HBoxContainer" parent="HBoxContainer/CustomX2"]
margin_right = 182.0
margin_bottom = 14.0
[node name="Button4" type="Button" parent="HBoxContainer/CustomX/HBoxContainer"]
margin_right = 25.0
margin_bottom = 20.0
text = "-X"
[node name="Label" type="Label" parent="HBoxContainer/CustomX2/HBoxContainer3"]
margin_right = 116.0
margin_bottom = 14.0
size_flags_vertical = 6
text = "Fill with Sequence"
[node name="Button10" type="Button" parent="HBoxContainer/CustomX/HBoxContainer"]
margin_left = 29.0
margin_right = 70.0
margin_bottom = 20.0
text = "-100"
[node name="Label2" type="Label" parent="HBoxContainer/CustomX2/HBoxContainer3"]
margin_left = 120.0
margin_right = 134.0
margin_bottom = 14.0
hint_tooltip = "Fill selected cells with a number sequence. Order is the same as the cells were selected.
- You must specify Start.
- If all values specified, selected cells will have a repeating sequence
of numbers from Start to End, with increment of Step, not including End.
- If both End AND Step are empty, cells are filled with Start.
- If End is omitted, selected cells will have values from Start to (Step x CellCount).
- If Step is omitted, selected cells will have values from Start to End inclusive,
step based on cell count."
mouse_filter = 0
mouse_default_cursor_shape = 16
size_flags_vertical = 6
text = "(?)"
[node name="Button7" type="Button" parent="HBoxContainer/CustomX/HBoxContainer"]
margin_left = 74.0
margin_right = 107.0
margin_bottom = 20.0
text = "-10"
[node name="HBoxContainer" type="HBoxContainer" parent="HBoxContainer/CustomX2"]
margin_top = 18.0
margin_right = 182.0
margin_bottom = 42.0
[node name="Button11" type="Button" parent="HBoxContainer/CustomX/HBoxContainer"]
margin_left = 111.0
margin_right = 136.0
margin_bottom = 20.0
text = "-1"
[node name="LineEdit" type="LineEdit" parent="HBoxContainer/CustomX2/HBoxContainer"]
margin_right = 58.0
margin_bottom = 24.0
hint_tooltip = "Start (must not be blank)"
placeholder_text = "Start *"
[node name="Button14" type="Button" parent="HBoxContainer/CustomX/HBoxContainer"]
margin_left = 140.0
margin_right = 177.0
margin_bottom = 20.0
text = "-0.1"
[node name="LineEdit2" type="LineEdit" parent="HBoxContainer/CustomX2/HBoxContainer"]
margin_left = 62.0
margin_right = 120.0
margin_bottom = 24.0
hint_tooltip = "End"
placeholder_text = "End"
[node name="NumberPanel" type="Panel" parent="HBoxContainer/CustomX/HBoxContainer"]
margin_left = 181.0
margin_right = 277.0
[node name="LineEdit3" type="LineEdit" parent="HBoxContainer/CustomX2/HBoxContainer"]
margin_left = 124.0
margin_right = 182.0
margin_bottom = 24.0
hint_tooltip = "End"
placeholder_text = "Step"
[node name="HBoxContainer2" type="HBoxContainer" parent="HBoxContainer/CustomX2"]
margin_top = 46.0
margin_right = 182.0
margin_bottom = 66.0
[node name="SequenceFill" type="Button" parent="HBoxContainer/CustomX2/HBoxContainer2"]
margin_right = 89.0
margin_bottom = 20.0
size_flags_horizontal = 3
text = "Replace"
[node name="SequenceFill2" type="Button" parent="HBoxContainer/CustomX2/HBoxContainer2"]
margin_left = 93.0
margin_right = 182.0
margin_bottom = 20.0
size_flags_horizontal = 3
text = "Add"
[node name="VSeparator2" type="VSeparator" parent="HBoxContainer"]
margin_left = 388.0
margin_right = 392.0
margin_bottom = 66.0
[node name="HBoxContainer" type="VBoxContainer" parent="HBoxContainer"]
margin_left = 396.0
margin_right = 620.0
margin_bottom = 66.0
alignment = 1
[node name="NumberPanel" type="MarginContainer" parent="HBoxContainer/HBoxContainer"]
margin_right = 224.0
margin_bottom = 18.0
rect_min_size = Vector2( 96, 0 )
mouse_default_cursor_shape = 10
size_flags_vertical = 3
custom_constants/margin_right = 0
custom_constants/margin_top = 0
custom_constants/margin_left = 0
custom_constants/margin_bottom = 0
[node name="Label" type="Label" parent="HBoxContainer/CustomX/HBoxContainer/NumberPanel"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 4.0
margin_right = -4.0
[node name="Panel" type="Panel" parent="HBoxContainer/HBoxContainer/NumberPanel"]
margin_right = 224.0
margin_bottom = 18.0
mouse_filter = 2
[node name="Label" type="Label" parent="HBoxContainer/HBoxContainer/NumberPanel"]
margin_top = 2.0
margin_right = 224.0
margin_bottom = 16.0
text = "1"
valign = 1
clip_text = true
[node name="Button15" type="Button" parent="HBoxContainer/CustomX/HBoxContainer"]
margin_left = 281.0
margin_right = 321.0
[node name="GridContainer" type="GridContainer" parent="HBoxContainer/HBoxContainer"]
margin_top = 22.0
margin_right = 224.0
margin_bottom = 66.0
columns = 6
[node name="Button15" type="Button" parent="HBoxContainer/HBoxContainer/GridContainer"]
margin_right = 40.0
margin_bottom = 20.0
text = "+0.1"
[node name="Button12" type="Button" parent="HBoxContainer/CustomX/HBoxContainer"]
margin_left = 325.0
margin_right = 353.0
[node name="Button12" type="Button" parent="HBoxContainer/HBoxContainer/GridContainer"]
margin_left = 44.0
margin_right = 72.0
margin_bottom = 20.0
text = "+1"
[node name="Button8" type="Button" parent="HBoxContainer/CustomX/HBoxContainer"]
margin_left = 357.0
margin_right = 393.0
[node name="Button8" type="Button" parent="HBoxContainer/HBoxContainer/GridContainer"]
margin_left = 76.0
margin_right = 112.0
margin_bottom = 20.0
text = "+10"
[node name="Button13" type="Button" parent="HBoxContainer/CustomX/HBoxContainer"]
margin_left = 397.0
margin_right = 441.0
[node name="Button13" type="Button" parent="HBoxContainer/HBoxContainer/GridContainer"]
margin_left = 116.0
margin_right = 160.0
margin_bottom = 20.0
text = "+100"
[node name="Button9" type="Button" parent="HBoxContainer/CustomX/HBoxContainer"]
margin_left = 445.0
margin_right = 473.0
[node name="Button9" type="Button" parent="HBoxContainer/HBoxContainer/GridContainer"]
margin_left = 164.0
margin_right = 192.0
margin_bottom = 20.0
text = "+X"
[node name="HBoxContainer2" type="HBoxContainer" parent="HBoxContainer/CustomX"]
margin_top = 24.0
margin_right = 473.0
margin_bottom = 38.0
[node name="Button16" type="Button" parent="HBoxContainer/HBoxContainer/GridContainer"]
margin_left = 196.0
margin_right = 224.0
margin_bottom = 20.0
text = "*X"
[node name="Label" type="Label" parent="HBoxContainer/CustomX/HBoxContainer2"]
[node name="Button14" type="Button" parent="HBoxContainer/HBoxContainer/GridContainer"]
margin_top = 24.0
margin_right = 40.0
margin_bottom = 44.0
text = "-0.1"
[node name="Button11" type="Button" parent="HBoxContainer/HBoxContainer/GridContainer"]
margin_left = 44.0
margin_top = 24.0
margin_right = 72.0
margin_bottom = 44.0
text = "-1"
[node name="Button7" type="Button" parent="HBoxContainer/HBoxContainer/GridContainer"]
margin_left = 76.0
margin_top = 24.0
margin_right = 112.0
margin_bottom = 44.0
text = "-10"
[node name="Button10" type="Button" parent="HBoxContainer/HBoxContainer/GridContainer"]
margin_left = 116.0
margin_top = 24.0
margin_right = 160.0
margin_bottom = 44.0
text = "-100"
[node name="Button4" type="Button" parent="HBoxContainer/HBoxContainer/GridContainer"]
margin_left = 164.0
margin_top = 24.0
margin_right = 192.0
margin_bottom = 44.0
text = "-X"
[node name="Button5" type="Button" parent="HBoxContainer/HBoxContainer/GridContainer"]
margin_left = 196.0
margin_top = 24.0
margin_right = 224.0
margin_bottom = 44.0
text = "/X"
[node name="VSeparator" type="VSeparator" parent="HBoxContainer"]
margin_left = 624.0
margin_right = 628.0
margin_bottom = 66.0
[node name="CustomX" type="VBoxContainer" parent="HBoxContainer"]
margin_left = 632.0
margin_right = 822.0
margin_bottom = 66.0
[node name="Label" type="Label" parent="HBoxContainer/CustomX"]
margin_top = 12.0
margin_right = 190.0
margin_bottom = 14.0
margin_bottom = 26.0
size_flags_vertical = 6
text = "Custom Value (for +X buttons)"
[node name="HSeparator" type="HSeparator" parent="HBoxContainer/CustomX/HBoxContainer2"]
margin_left = 194.0
margin_right = 473.0
margin_bottom = 14.0
size_flags_horizontal = 3
[node name="LineEdit" type="LineEdit" parent="HBoxContainer/CustomX"]
margin_top = 42.0
margin_right = 473.0
margin_right = 190.0
margin_bottom = 66.0
text = "20"
text = "1000"
[connection signal="gui_input" from="HBoxContainer/CustomX/HBoxContainer/NumberPanel" to="." method="_on_NumberPanel_gui_input"]
[connection signal="pressed" from="HBoxContainer/CustomX2/HBoxContainer2/SequenceFill" to="." method="_on_SequenceFill_pressed"]
[connection signal="pressed" from="HBoxContainer/CustomX2/HBoxContainer2/SequenceFill2" to="." method="_on_SequenceFill_pressed" binds= [ true ]]
[connection signal="gui_input" from="HBoxContainer/HBoxContainer/NumberPanel" to="." method="_on_NumberPanel_gui_input"]

View File

@ -48,24 +48,10 @@ _global_script_class_icons={
"ThemeStylebox": ""
}
[application]
config/name="Edit Resources as Spreadsheets"
run/main_scene="res://addons/resources_speadsheet_view/editor_view.tscn"
config/icon="res://icon.png"
[editor_plugins]
enabled=PoolStringArray( "res://addons/resources_speadsheet_view/plugin.cfg" )
[gui]
common/drop_mouse_on_gui_input_disabled=true
[physics]
common/enable_pause_aware_picking=true
[rendering]
quality/driver/driver_name="GLES2"