Implement texture atlas chopper

This commit is contained in:
don-tnowe 2022-09-22 21:00:21 +03:00
parent 83d23e60c6
commit 544bfb8fd1
34 changed files with 274 additions and 25 deletions

View File

@ -7,7 +7,10 @@ A plugin for Godot 3 that adds a tab for editing folders of Resources as data ta
- Select multiple cells in one column (Shift/Ctrl+Click) to edit them in the Inspector simultaneously.
- Multi-cell text editing (visible cursor not included, unfortunately)
- Copy-paste Text into Cells (one line, one cell)
- Special mass operations for some datatypes (rotate color hues/adjust sat/val/RGB, multiply/add numbers...)
- Special mass operations for some datatypes
- Multiply/add numbers
- Rotate color hues/adjust sat/val/RGB
- Chop texture into atlas, assign results to each selected resource
- Sort entries by column
- Search by evaluating GDScript expression
- Row stylization (color-type cells change look of the row until next color-type)

View File

@ -73,6 +73,9 @@ func _on_filesystem_changed():
else:
for k in remembered_paths:
if remembered_paths[k].resource_path != k:
var res = remembered_paths[k]
remembered_paths.erase(k)
remembered_paths[res.resource_path] = res
display_folder(current_path, sorting_by, sorting_reverse, true)
break
@ -292,15 +295,7 @@ func select_cell(cell : Control):
column_editors[column_index].set_selected(cell, true)
edited_cells.append(cell)
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.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]
_try_open_docks(cell)
inspector_resource = rows[_get_cell_row(cell)].duplicate()
editor_plugin.get_editor_interface().edit_resource(inspector_resource)
return
@ -326,6 +321,17 @@ func select_cell(cell : Control):
edit_cursor_positions.append(column_editors[column_index].get_text_length(cur_cell))
func _try_open_docks(cell : Control):
var column_index = _get_cell_column(cell)
for x in get_node(path_property_editors).get_children():
x.visible = x.try_edit_value(
column_editors[column_index].get_value(cell),
column_types[column_index],
column_hints[column_index]
)
x.get_node(x.path_property_name).text = columns[column_index]
func set_edited_cells_values(new_cell_values : Array, update_whole_row : bool = false):
var column = _get_cell_column(edited_cells[0])
var edited_cells_resources = _get_edited_cells_resources()
@ -610,3 +616,6 @@ func _on_inspector_property_edited(property : String):
for x in edited_cells:
rows[_get_cell_row(x)].set(property, value)
_update_row(_get_cell_row(x))
# Resources could stop being null, sooooo...
_try_open_docks(edited_cells[0])

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=2]
[gd_scene load_steps=13 format=2]
[ext_resource path="res://addons/resources_speadsheet_view/editor_view.gd" type="Script" id=1]
[ext_resource path="res://addons/resources_speadsheet_view/typed_cells/cell_editor_string.gd" type="Script" id=2]
@ -9,6 +9,7 @@
[ext_resource path="res://addons/resources_speadsheet_view/typed_editors/dock_color.tscn" type="PackedScene" id=7]
[ext_resource path="res://addons/resources_speadsheet_view/typed_editors/dock_number.tscn" type="PackedScene" id=8]
[ext_resource path="res://addons/resources_speadsheet_view/typed_cells/cell_editor_resource.gd" type="Script" id=9]
[ext_resource path="res://addons/resources_speadsheet_view/typed_editors/dock_texture.tscn" type="PackedScene" id=10]
[sub_resource type="Image" id=3]
data = {
@ -249,6 +250,12 @@ anchor_right = 0.0
margin_right = 1020.0
margin_bottom = 84.0
[node name="EditTexture" parent="HeaderContentSplit/MarginContainer/FooterContentSplit/Footer/PropertyEditors" instance=ExtResource( 10 )]
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

View File

@ -0,0 +1,40 @@
tool
extends SheetsDockEditor
var _stored_value : Texture
func try_edit_value(value, type, property_hint) -> bool:
if type != TYPE_OBJECT or !value is Texture:
return false
_stored_value = value
$"CenterContainer/HBoxContainer/TextureRect".texture = value
return true
func _on_Button_pressed():
var h_count = int($"CenterContainer/HBoxContainer/VBoxContainer/HBoxContainer/LineEdit".text)
var v_count = int($"CenterContainer/HBoxContainer/VBoxContainer/HBoxContainer/LineEdit2".text)
# No, Scene Unique Names can not be used in-editor (last time i checked)
var folder_name := _stored_value.resource_path.get_basename()
var dir := Directory.new()
dir.make_dir(folder_name)
var tex_size := _stored_value.get_size()
var tile_size := Vector2(tex_size.x / h_count, tex_size.y / v_count)
var tile_array := []
for j in v_count:
for i in h_count:
var tile := AtlasTexture.new()
tile.region = Rect2(tile_size * Vector2(i, j), tile_size)
tile.atlas = _stored_value
tile_array.append(tile)
tile.take_over_path(folder_name + "/" + folder_name.get_file() + "_" + str(j * v_count + i + 1) + ".tres")
ResourceSaver.save(tile.resource_path, tile)
tile_array.resize(sheet.edited_cells.size())
sheet.set_edited_cells_values(tile_array)
sheet.editor_plugin.get_editor_interface().get_resource_filesystem().scan()

View File

@ -0,0 +1,108 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://addons/resources_speadsheet_view/typed_editors/dock_texture.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture" id=2]
[node name="EditTexture" type="VBoxContainer"]
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="."]
margin_right = 1024.0
margin_bottom = 14.0
[node name="HBoxContainer" type="HBoxContainer" parent="Header"]
margin_right = 455.0
margin_bottom = 14.0
size_flags_horizontal = 3
[node name="Label" type="Label" parent="Header/HBoxContainer"]
margin_right = 85.0
margin_bottom = 14.0
text = "EDIT: Texture"
[node name="HSeparator" type="HSeparator" parent="Header/HBoxContainer"]
margin_left = 89.0
margin_right = 455.0
margin_bottom = 14.0
size_flags_horizontal = 3
[node name="Label" type="Label" parent="Header"]
margin_left = 459.0
margin_right = 565.0
margin_bottom = 14.0
text = "PROPERTY NAME"
[node name="HSeparator2" type="HSeparator" parent="Header"]
margin_left = 569.0
margin_right = 1024.0
margin_bottom = 14.0
size_flags_horizontal = 3
[node name="CenterContainer" type="CenterContainer" parent="."]
margin_top = 18.0
margin_right = 1024.0
margin_bottom = 84.0
[node name="HBoxContainer" type="HBoxContainer" parent="CenterContainer"]
margin_left = 384.0
margin_right = 640.0
margin_bottom = 66.0
alignment = 1
[node name="TextureRect" type="TextureRect" parent="CenterContainer/HBoxContainer"]
margin_right = 48.0
margin_bottom = 66.0
rect_min_size = Vector2( 48, 48 )
size_flags_horizontal = 3
size_flags_vertical = 3
texture = ExtResource( 2 )
expand = true
stretch_mode = 6
[node name="VSeparator" type="VSeparator" parent="CenterContainer/HBoxContainer"]
margin_left = 52.0
margin_right = 56.0
margin_bottom = 66.0
[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer/HBoxContainer"]
margin_left = 60.0
margin_right = 256.0
margin_bottom = 66.0
[node name="Label" type="Label" parent="CenterContainer/HBoxContainer/VBoxContainer"]
margin_right = 196.0
margin_bottom = 14.0
text = "Atlas Chopper"
align = 1
[node name="HBoxContainer" type="HBoxContainer" parent="CenterContainer/HBoxContainer/VBoxContainer"]
margin_top = 18.0
margin_right = 196.0
margin_bottom = 42.0
[node name="LineEdit" type="LineEdit" parent="CenterContainer/HBoxContainer/VBoxContainer/HBoxContainer"]
margin_right = 96.0
margin_bottom = 24.0
rect_min_size = Vector2( 96, 0 )
size_flags_horizontal = 3
placeholder_text = "H Count"
[node name="LineEdit2" type="LineEdit" parent="CenterContainer/HBoxContainer/VBoxContainer/HBoxContainer"]
margin_left = 100.0
margin_right = 196.0
margin_bottom = 24.0
rect_min_size = Vector2( 96, 0 )
size_flags_horizontal = 3
placeholder_text = "V Count"
[node name="Button" type="Button" parent="CenterContainer/HBoxContainer/VBoxContainer"]
margin_top = 46.0
margin_right = 196.0
margin_bottom = 66.0
text = "Chop chop chop!!!"
[connection signal="pressed" from="CenterContainer/HBoxContainer/VBoxContainer/Button" to="." method="_on_Button_pressed"]

View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 64, 128, 64, 64 )

View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 128, 128, 64, 64 )

View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 192, 128, 64, 64 )

View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 0, 192, 64, 64 )

View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 64, 192, 64, 64 )

View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 128, 192, 64, 64 )

View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 192, 192, 64, 64 )

View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 128, 64, 64, 64 )

View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 192, 64, 64, 64 )

View File

@ -0,0 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[ext_resource path="res://example/icons/all_icons.png" type="Texture" id=1]
[resource]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 0, 128, 64, 64 )

View File

@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/6.tres" type="Texture" id=2]
[ext_resource path="res://example/icons/all_icons/all_icons_6.tres" type="Texture" id=2]
[resource]
resource_name = "Upgrade: Elemental Damage"

View File

@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/2.tres" type="Texture" id=2]
[ext_resource path="res://example/icons/all_icons/all_icons_1.tres" type="Texture" id=2]
[resource]
resource_name = "Upgrade: Health"

View File

@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/6.tres" type="Texture" id=2]
[ext_resource path="res://example/icons/all_icons/all_icons_6.tres" type="Texture" id=2]
[resource]
resource_name = "Upgrade: Area of Effect"

View File

@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/5.tres" type="Texture" id=2]
[ext_resource path="res://example/icons/all_icons/all_icons_5.tres" type="Texture" id=2]
[resource]
resource_name = "Upgrade: Magic"
@ -10,7 +10,7 @@ color1 = Color( 1, 1, 1, 1 )
max_duplicates = 9
tags = "magic"
icon = ExtResource( 2 )
color2 = Color( 0.189457, 0.452246, 0.902344, 1 )
color2 = Color( 0.188235, 0.45098, 0.901961, 1 )
tag_delimeter = " "
base_weight = 10.0
is_notable = false

View File

@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/1.tres" type="Texture" id=2]
[ext_resource path="res://example/icons/all_icons/all_icons_2.tres" type="Texture" id=2]
[resource]
resource_name = "Upgrade: Strength"

View File

@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/3.tres" type="Texture" id=2]
[ext_resource path="res://example/icons/all_icons/all_icons_3.tres" type="Texture" id=2]
[resource]
resource_name = "Weapon: Axe"

View File

@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/4.tres" type="Texture" id=2]
[ext_resource path="res://example/icons/all_icons/all_icons_4.tres" type="Texture" id=2]
[resource]
resource_name = "Weapon: Blizzard"

View File

@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=4 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/4.tres" type="Texture" id=2]
[ext_resource path="res://example/icons/all_icons/all_icons_4.tres" type="Texture" id=2]
[ext_resource path="res://example/new scene.tscn" type="PackedScene" id=3]
[resource]

View File

@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/3.tres" type="Texture" id=2]
[ext_resource path="res://example/icons/all_icons/all_icons_3.tres" type="Texture" id=2]
[resource]
resource_name = "Weapon: Daggers"

View File

@ -1,6 +1,7 @@
[gd_resource type="Resource" load_steps=2 format=2]
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/all_icons/all_icons_4.tres" type="Texture" id=2]
[resource]
resource_name = "Weapon: Fireball"
@ -8,6 +9,7 @@ script = ExtResource( 1 )
color1 = Color( 1, 1, 0.2, 1 )
max_duplicates = 1
tags = "weapon magic fireball projectile elemental"
icon = ExtResource( 2 )
color2 = Color( 0.189457, 0.452246, 0.902344, 1 )
tag_delimeter = " "
base_weight = 10.0

View File

@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=4 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/3.tres" type="Texture" id=2]
[ext_resource path="res://example/icons/all_icons/all_icons_3.tres" type="Texture" id=2]
[ext_resource path="res://example/new scene.tscn" type="PackedScene" id=3]
[resource]

View File

@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/4.tres" type="Texture" id=2]
[ext_resource path="res://example/icons/all_icons/all_icons_4.tres" type="Texture" id=2]
[resource]
resource_name = "Weapon: Lightning"

View File

@ -1,7 +1,7 @@
[gd_resource type="Resource" load_steps=3 format=2]
[ext_resource path="res://example/my_custom_resource.gd" type="Script" id=1]
[ext_resource path="res://example/icons/3.tres" type="Texture" id=2]
[ext_resource path="res://example/icons/all_icons/all_icons_3.tres" type="Texture" id=2]
[resource]
resource_name = "Weapon: Spear"