feat: selection tracking
This commit is contained in:
parent
4aa1075fb6
commit
cb43179770
15 changed files with 217 additions and 20 deletions
51
modules/terrain_editor/layer_editor.cpp
Normal file
51
modules/terrain_editor/layer_editor.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#include "layer_editor.h"
|
||||
#include "scene/resources/packed_scene.h"
|
||||
|
||||
void LayerEditor::_bind_methods() {
|
||||
String hint_string{ vformat("StringName;%s/%s:PackedScene", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE) };
|
||||
BIND_HPROPERTY(Variant::DICTIONARY, inspectors, PROPERTY_HINT_DICTIONARY_TYPE, hint_string);
|
||||
BIND_HPROPERTY(Variant::OBJECT, terrain, PROPERTY_HINT_NODE_TYPE, "TerrainMeshEditor");
|
||||
}
|
||||
|
||||
void LayerEditor::deselect_current() {
|
||||
if (this->current_inspector) {
|
||||
this->current_inspector->queue_free();
|
||||
}
|
||||
this->current_inspector = nullptr;
|
||||
}
|
||||
|
||||
void LayerEditor::select(Ref<TerrainPrimitive> primitive) {
|
||||
deselect_current();
|
||||
if (primitive.is_valid() && this->inspectors.has(primitive->get_class())) {
|
||||
this->current_inspector = this->inspectors.get(primitive->get_class())->instantiate();
|
||||
add_child(this->current_inspector);
|
||||
}
|
||||
}
|
||||
|
||||
void LayerEditor::set_inspectors(Dictionary dict) {
|
||||
this->inspectors.clear();
|
||||
for (KeyValue<Variant, Variant> kvp : dict) {
|
||||
StringName name{ kvp.key };
|
||||
Ref<PackedScene> value{ kvp.value };
|
||||
this->inspectors.insert(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary LayerEditor::get_inspectors() const {
|
||||
Dictionary r;
|
||||
for (KeyValue<StringName, Ref<PackedScene>> const &kvp : this->inspectors) {
|
||||
r[kvp.key] = kvp.value;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
void LayerEditor::set_terrain(TerrainMeshEditor *editor) {
|
||||
this->terrain = editor;
|
||||
if (editor && !Engine::get_singleton()->is_editor_hint()) {
|
||||
editor->connect(TerrainMeshEditor::sig_selection_changed, callable_mp(this, &self_type::select));
|
||||
}
|
||||
}
|
||||
|
||||
TerrainMeshEditor *LayerEditor::get_terrain() const {
|
||||
return this->terrain;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue