From d736506eb4c56ab52545b2c966d625b93f96b3b4 Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 7 Jan 2026 20:20:41 +0100 Subject: [PATCH] feat: new primitives get selected immediately --- .../terrain_editor/terrain_mesh_editor.cpp | 1 + modules/terrain_editor/terrain_mesh_editor.h | 2 +- .../terrain_editor/terrain_mesh_generator.cpp | 7 +++ .../terrain_editor/terrain_mesh_generator.h | 2 + project/scenes/editor.tscn | 3 -- .../base_primitive_inspector.tscn | 52 +++++++++---------- 6 files changed, 37 insertions(+), 30 deletions(-) diff --git a/modules/terrain_editor/terrain_mesh_editor.cpp b/modules/terrain_editor/terrain_mesh_editor.cpp index 67679ade..3d37d1cc 100644 --- a/modules/terrain_editor/terrain_mesh_editor.cpp +++ b/modules/terrain_editor/terrain_mesh_editor.cpp @@ -48,6 +48,7 @@ void TerrainMeshEditor::_bind_methods() { void TerrainMeshEditor::ready() { connect(sig_primitive_list_changed, callable_mp(this, &self_type::on_primitive_list_changed)); + connect(sig_primitive_added, callable_mp(this, &self_type::set_current_selected)); load_new(); if (FileDialog * dialog{ memnew(FileDialog) }) { this->file_dialog = dialog; diff --git a/modules/terrain_editor/terrain_mesh_editor.h b/modules/terrain_editor/terrain_mesh_editor.h index ab5ae5b1..8d9eb3b1 100644 --- a/modules/terrain_editor/terrain_mesh_editor.h +++ b/modules/terrain_editor/terrain_mesh_editor.h @@ -39,7 +39,7 @@ public: void save_data_as(); void set_new_file_data(Ref data); Ref get_new_file_data() const; - void set_current_selected(Ref); + void set_current_selected(Ref primitive); Ref get_current_selected() const; void set_point_primitive_object(Ref scene); Ref get_point_primitive_object() const; diff --git a/modules/terrain_editor/terrain_mesh_generator.cpp b/modules/terrain_editor/terrain_mesh_generator.cpp index 9053e0a5..4271ec93 100644 --- a/modules/terrain_editor/terrain_mesh_generator.cpp +++ b/modules/terrain_editor/terrain_mesh_generator.cpp @@ -13,6 +13,8 @@ String const TerrainMeshGenerator::sig_primitives_changed{ "primitives_changed" }; String const TerrainMeshGenerator::sig_primitive_list_changed{ "primitive_list_changed" }; +String const TerrainMeshGenerator::sig_primitive_added{ "primitive_added" }; +String const TerrainMeshGenerator::sig_primitive_removed{ "primitive_removed" }; void TerrainMeshGenerator::_bind_methods() { BIND_HPROPERTY(Variant::ARRAY, primitives, PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:TerrainPrimitive", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE)); @@ -23,6 +25,8 @@ void TerrainMeshGenerator::_bind_methods() { BIND_HPROPERTY(Variant::OBJECT, chunk_scene, PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"); ADD_SIGNAL(MethodInfo(sig_primitives_changed)); ADD_SIGNAL(MethodInfo(sig_primitive_list_changed, PropertyInfo(Variant::ARRAY, "array", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:TerrainPrimitive", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE)))); + ADD_SIGNAL(MethodInfo(sig_primitive_added, PropertyInfo(Variant::OBJECT, "primitive", PROPERTY_HINT_RESOURCE_TYPE, "TerrainPrimitive"))); + ADD_SIGNAL(MethodInfo(sig_primitive_removed, PropertyInfo(Variant::OBJECT, "primitive", PROPERTY_HINT_RESOURCE_TYPE, "TerrainPrimitive"))); ClassDB::bind_method(D_METHOD("push_task", "area", "out_mesh", "side_points"), &self_type::push_task); ClassDB::bind_method(D_METHOD("add_primitive", "primitive"), &self_type::add_primitive); ClassDB::bind_method(D_METHOD("insert_primitive", "primitive", "idx"), &self_type::insert_primitive); @@ -264,12 +268,14 @@ void TerrainMeshGenerator::add_primitive(Ref primitive) { Array list = get_primitives(); list.push_front(primitive); set_primitives(list); + emit_signal(sig_primitive_added, primitive); } void TerrainMeshGenerator::insert_primitive(Ref primitive, int idx) { Array list = get_primitives(); list.insert(idx, primitive); set_primitives(list); + emit_signal(sig_primitive_added, primitive); } void TerrainMeshGenerator::remove_primitive(Ref primitive) { @@ -279,6 +285,7 @@ void TerrainMeshGenerator::remove_primitive(Ref primitive) { list.remove_at(idx); } set_primitives(list); + emit_signal(sig_primitive_removed, primitive); } void TerrainMeshGenerator::set_primitives(Array primitives) { diff --git a/modules/terrain_editor/terrain_mesh_generator.h b/modules/terrain_editor/terrain_mesh_generator.h index 80b5e3bf..02ff7793 100644 --- a/modules/terrain_editor/terrain_mesh_generator.h +++ b/modules/terrain_editor/terrain_mesh_generator.h @@ -82,4 +82,6 @@ private: public: static String const sig_primitives_changed; static String const sig_primitive_list_changed; + static String const sig_primitive_added; + static String const sig_primitive_removed; }; diff --git a/project/scenes/editor.tscn b/project/scenes/editor.tscn index 9fac213f..9e7dc0fd 100644 --- a/project/scenes/editor.tscn +++ b/project/scenes/editor.tscn @@ -101,10 +101,8 @@ func _unhandled_input(event: InputEvent) -> void: load_path = "res://.godot/imported/point.svg-e68fd7c1e788d2c48d769cc58eba6e98.ctex" [sub_resource type="PointPrimitive" id="PointPrimitive_5lcyj"] -expression = "sloped_height" [sub_resource type="PlanePrimitive" id="PlanePrimitive_5lcyj"] -expression = "baseline" [sub_resource type="FastNoiseLite" id="FastNoiseLite_3vi5u"] frequency = 0.0336 @@ -115,7 +113,6 @@ domain_warp_fractal_lacunarity = 5.512 domain_warp_fractal_gain = 0.662 [sub_resource type="NoisePrimitive" id="NoisePrimitive_5lcyj"] -expression = "previous_height + noise_sample" noise = SubResource("FastNoiseLite_3vi5u") [sub_resource type="GDScript" id="GDScript_74j0u"] diff --git a/project/ui/primitive_inspectors/base_primitive_inspector.tscn b/project/ui/primitive_inspectors/base_primitive_inspector.tscn index 04cc8718..6cb4246f 100644 --- a/project/ui/primitive_inspectors/base_primitive_inspector.tscn +++ b/project/ui/primitive_inspectors/base_primitive_inspector.tscn @@ -22,19 +22,6 @@ func _on_item_selected(index: int) -> void: EditHistory.push_action(primitive.set_blend_mode.bind(index), primitive.set_blend_mode.bind(before)) " -[sub_resource type="GDScript" id="GDScript_ivj30"] -resource_name = "DeletePrimitive" -script/source = "extends Button - -@onready var terrain : TerrainMeshEditor = ($\"../../../..\" as LayerEditor).terrain -@onready var primitive : TerrainPrimitive = terrain.current_selected - -func _pressed() -> void: - var idx : int = terrain.primitives.find(primitive) - EditHistory.push_action(terrain.remove_primitive.bind(primitive), terrain.insert_primitive.bind(primitive, idx)) - terrain.current_selected = null -" - [sub_resource type="GDScript" id="GDScript_2i6ni"] resource_name = "ExpressionEditor" script/source = "extends TextEdit @@ -65,6 +52,19 @@ func _timeout(): primitive.expression = text " +[sub_resource type="GDScript" id="GDScript_ivj30"] +resource_name = "DeletePrimitive" +script/source = "extends Button + +@onready var terrain : TerrainMeshEditor = ($\"../../../..\" as LayerEditor).terrain +@onready var primitive : TerrainPrimitive = terrain.current_selected + +func _pressed() -> void: + var idx : int = terrain.primitives.find(primitive) + EditHistory.push_action(terrain.remove_primitive.bind(primitive), terrain.insert_primitive.bind(primitive, idx)) + terrain.current_selected = null +" + [node name="Primitive" type="MarginContainer" unique_id=905749607] offset_right = 302.0 offset_bottom = 230.0 @@ -109,22 +109,10 @@ popup/item_2/text = "Both" popup/item_2/id = 2 script = SubResource("GDScript_h3glg") -[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer" unique_id=274380821] -layout_mode = 2 -alignment = 2 - -[node name="Button" type="Button" parent="VBoxContainer/HBoxContainer" unique_id=1514690251] -custom_minimum_size = Vector2(32, 32) -layout_mode = 2 -icon = ExtResource("1_h3glg") -icon_alignment = 1 -expand_icon = true -script = SubResource("GDScript_ivj30") - [node name="Expression" type="TextEdit" parent="VBoxContainer" unique_id=1154146381] layout_mode = 2 size_flags_vertical = 3 -placeholder_text = "expression" +placeholder_text = "previous_height * previous_height" backspace_deletes_composite_character_enabled = true caret_blink = true caret_move_on_right_click = false @@ -139,6 +127,18 @@ wait_time = 2.0 layout_mode = 2 text = "Error Text" +[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer" unique_id=274380821] +layout_mode = 2 +alignment = 2 + +[node name="Button" type="Button" parent="VBoxContainer/HBoxContainer" unique_id=1514690251] +custom_minimum_size = Vector2(32, 32) +layout_mode = 2 +icon = ExtResource("1_h3glg") +icon_alignment = 1 +expand_icon = true +script = SubResource("GDScript_ivj30") + [connection signal="item_selected" from="VBoxContainer/BlendModeSelector" to="VBoxContainer/BlendModeSelector" method="_on_item_selected"] [editable path="VBoxContainer/FloatEditor3"]