Small tweaks and reorganization in TerrainWorldEditor.

This commit is contained in:
Relintai 2025-02-04 09:02:19 +01:00
parent 781c91ba34
commit f25c008f6d
2 changed files with 45 additions and 37 deletions

View File

@ -110,7 +110,7 @@ EditorPlugin::AfterGUIInput TerrainWorldEditor::do_input_action(Camera *p_camera
if (channel == -1) if (channel == -1)
return EditorPlugin::AFTER_GUI_INPUT_PASS; return EditorPlugin::AFTER_GUI_INPUT_PASS;
int isolevel = _current_isolevel; int isolevel = _add_remove_current_isolevel;
bool mode_add = false; bool mode_add = false;
if (_tool_mode == TOOL_MODE_ADD) { if (_tool_mode == TOOL_MODE_ADD) {
@ -140,9 +140,9 @@ void TerrainWorldEditor::edit(TerrainWorld *p_world) {
_channel_isolevel = _world->get_channel_index_info(TerrainWorld::CHANNEL_TYPE_INFO_ISOLEVEL); _channel_isolevel = _world->get_channel_index_info(TerrainWorld::CHANNEL_TYPE_INFO_ISOLEVEL);
if (_channel_isolevel == -1) { if (_channel_isolevel == -1) {
_isolevel_slider->hide(); _add_remove_isolevel_slider->hide();
} else { } else {
_isolevel_slider->show(); _add_remove_isolevel_slider->show();
} }
spatial_editor = Object::cast_to<SpatialEditorPlugin>(_editor->get_editor_plugin_screen()); spatial_editor = Object::cast_to<SpatialEditorPlugin>(_editor->get_editor_plugin_screen());
@ -198,7 +198,7 @@ TerrainWorldEditor::TerrainWorldEditor() {
_world = NULL; _world = NULL;
_selected_type = 0; _selected_type = 0;
_channel_type = -1; _channel_type = -1;
_current_isolevel = 255; _add_remove_current_isolevel = 255;
_channel_isolevel = -1; _channel_isolevel = -1;
_editor = NULL; _editor = NULL;
_tool_mode = TOOL_MODE_ADD; _tool_mode = TOOL_MODE_ADD;
@ -214,7 +214,7 @@ TerrainWorldEditor::TerrainWorldEditor(EditorNode *p_editor) {
_world = NULL; _world = NULL;
_selected_type = 0; _selected_type = 0;
_channel_type = -1; _channel_type = -1;
_current_isolevel = 255; _add_remove_current_isolevel = 255;
_channel_isolevel = -1; _channel_isolevel = -1;
_isolevel_picker_mode = false; _isolevel_picker_mode = false;
@ -300,16 +300,16 @@ TerrainWorldEditor::TerrainWorldEditor(EditorNode *p_editor) {
isolevel_slider_label->set_text(TTR("Isolevel")); isolevel_slider_label->set_text(TTR("Isolevel"));
_add_remove_tool_container->add_child(isolevel_slider_label); _add_remove_tool_container->add_child(isolevel_slider_label);
_isolevel_slider = memnew(HSlider); _add_remove_isolevel_slider = memnew(HSlider);
_isolevel_slider->set_min(1); _add_remove_isolevel_slider->set_min(1);
_isolevel_slider->set_value(_current_isolevel); _add_remove_isolevel_slider->set_value(_add_remove_current_isolevel);
_isolevel_slider->set_custom_minimum_size(Size2(50 * EDSCALE, 0)); _add_remove_isolevel_slider->set_custom_minimum_size(Size2(50 * EDSCALE, 0));
_isolevel_slider->set_v_size_flags(SIZE_EXPAND_FILL); _add_remove_isolevel_slider->set_v_size_flags(SIZE_EXPAND_FILL);
_isolevel_slider->set_h_size_flags(SIZE_EXPAND_FILL); _add_remove_isolevel_slider->set_h_size_flags(SIZE_EXPAND_FILL);
_isolevel_slider->set_tooltip(TTR("Isolevel")); _add_remove_isolevel_slider->set_tooltip(TTR("Isolevel"));
_add_remove_tool_container->add_child(_isolevel_slider); _add_remove_tool_container->add_child(_add_remove_isolevel_slider);
_isolevel_slider->connect("value_changed", this, "_on_isolevel_slider_value_changed"); _add_remove_isolevel_slider->connect("value_changed", this, "_on_add_remove_isolevel_slider_value_changed");
_isolevel_slider->hide(); _add_remove_isolevel_slider->hide();
ScrollContainer *scs = memnew(ScrollContainer); ScrollContainer *scs = memnew(ScrollContainer);
scs->set_h_size_flags(SIZE_EXPAND_FILL); scs->set_h_size_flags(SIZE_EXPAND_FILL);
@ -344,8 +344,9 @@ void TerrainWorldEditor::_notification(int p_what) {
} }
void TerrainWorldEditor::_node_removed(Node *p_node) { void TerrainWorldEditor::_node_removed(Node *p_node) {
if (p_node == _world) if (p_node == _world) {
_world = NULL; _world = NULL;
}
} }
void TerrainWorldEditor::_on_surface_button_pressed() { void TerrainWorldEditor::_on_surface_button_pressed() {
@ -409,12 +410,12 @@ void TerrainWorldEditor::_on_insert_block_at_camera_button_pressed() {
_world->set_voxel_at_world_position(pos, selected_terrain, channel); _world->set_voxel_at_world_position(pos, selected_terrain, channel);
} else { } else {
_world->set_voxel_at_world_position(pos, selected_terrain, channel, false); _world->set_voxel_at_world_position(pos, selected_terrain, channel, false);
_world->set_voxel_at_world_position(pos, _current_isolevel, _channel_isolevel); _world->set_voxel_at_world_position(pos, _add_remove_current_isolevel, _channel_isolevel);
} }
} }
void TerrainWorldEditor::_on_isolevel_slider_value_changed(float value) { void TerrainWorldEditor::_on_add_remove_isolevel_slider_value_changed(float value) {
_current_isolevel = value; _add_remove_current_isolevel = value;
} }
void TerrainWorldEditor::_bind_methods() { void TerrainWorldEditor::_bind_methods() {
@ -422,7 +423,7 @@ void TerrainWorldEditor::_bind_methods() {
ClassDB::bind_method("_on_surface_button_pressed", &TerrainWorldEditor::_on_surface_button_pressed); ClassDB::bind_method("_on_surface_button_pressed", &TerrainWorldEditor::_on_surface_button_pressed);
ClassDB::bind_method("_on_tool_button_pressed", &TerrainWorldEditor::_on_tool_button_pressed); ClassDB::bind_method("_on_tool_button_pressed", &TerrainWorldEditor::_on_tool_button_pressed);
ClassDB::bind_method("_on_insert_block_at_camera_button_pressed", &TerrainWorldEditor::_on_insert_block_at_camera_button_pressed); ClassDB::bind_method("_on_insert_block_at_camera_button_pressed", &TerrainWorldEditor::_on_insert_block_at_camera_button_pressed);
ClassDB::bind_method("_on_isolevel_slider_value_changed", &TerrainWorldEditor::_on_isolevel_slider_value_changed); ClassDB::bind_method("_on_add_remove_isolevel_slider_value_changed", &TerrainWorldEditor::_on_add_remove_isolevel_slider_value_changed);
} }
void TerrainWorldEditorPlugin::_notification(int p_what) { void TerrainWorldEditorPlugin::_notification(int p_what) {
@ -443,8 +444,9 @@ void TerrainWorldEditorPlugin::edit(Object *p_object) {
} }
bool TerrainWorldEditorPlugin::handles(Object *p_object) const { bool TerrainWorldEditorPlugin::handles(Object *p_object) const {
if (!p_object->is_class("TerrainWorld")) if (!p_object->is_class("TerrainWorld")) {
return false; return false;
}
TerrainWorld *w = Object::cast_to<TerrainWorld>(p_object); TerrainWorld *w = Object::cast_to<TerrainWorld>(p_object);

View File

@ -76,7 +76,7 @@ protected:
void _on_surface_button_pressed(); void _on_surface_button_pressed();
void _on_tool_button_pressed(); void _on_tool_button_pressed();
void _on_insert_block_at_camera_button_pressed(); void _on_insert_block_at_camera_button_pressed();
void _on_isolevel_slider_value_changed(float value); void _on_add_remove_isolevel_slider_value_changed(float value);
private: private:
//enum BrushType { //enum BrushType {
@ -87,7 +87,7 @@ private:
enum IsolevelBrushType { enum IsolevelBrushType {
ISOLEVEL_BRUSH_TYPE_ADD = 0, ISOLEVEL_BRUSH_TYPE_ADD = 0,
ISOLEVEL_BRUSH_TYPE_SUBSTRACT, ISOLEVEL_BRUSH_TYPE_SUBSTRACT,
ISOLEVEL_BRUSH_TYPE_SET, ISOLEVEL_BRUSH_TYPE_SET, // Icon CanvasLayer
ISOLEVEL_BRUSH_TYPE_SMOOTH, // Icon: Blend ISOLEVEL_BRUSH_TYPE_SMOOTH, // Icon: Blend
}; };
@ -99,22 +99,9 @@ private:
IsolevelBrushType _isolevel_brush_type; IsolevelBrushType _isolevel_brush_type;
private: private:
HFlowContainer *_tool_button_container;
VBoxContainer *_add_remove_tool_container;
VBoxContainer *_surfaces_vbox_container;
Ref<ButtonGroup> _surfaces_button_group;
Ref<ButtonGroup> _tool_button_group;
TerrainWorldEditorToolMode _tool_mode;
TerrainWorldEditorToolMode _previous_tool_mode;
TerrainWorld *_world; TerrainWorld *_world;
HSlider *_isolevel_slider;
int _selected_type; int _selected_type;
int _current_isolevel;
SpatialEditorPlugin *spatial_editor; SpatialEditorPlugin *spatial_editor;
EditorNode *_editor; EditorNode *_editor;
@ -122,12 +109,31 @@ private:
int _channel_type; int _channel_type;
int _channel_isolevel; int _channel_isolevel;
TerrainWorldEditorToolMode _tool_mode;
TerrainWorldEditorToolMode _previous_tool_mode;
ToolButton *_add_button; ToolButton *_add_button;
ToolButton *_remove_button; ToolButton *_remove_button;
ToolButton *_insert_button;
ToolButton *_isolevel_brush_button; ToolButton *_isolevel_brush_button;
ToolButton *_paint_brush_button; ToolButton *_paint_brush_button;
ToolButton *_paint_picker_button; ToolButton *_paint_picker_button;
HFlowContainer *_tool_button_container;
Ref<ButtonGroup> _tool_button_group;
VBoxContainer *_add_remove_tool_container;
HSlider *_add_remove_isolevel_slider;
int _add_remove_current_isolevel;
ToolButton *_insert_button;
VBoxContainer *_isolevel_brush_tool_container;
VBoxContainer *_paint_brush_tool_container;
VBoxContainer *_paint_picker_tool_container;
VBoxContainer *_surfaces_vbox_container;
Ref<ButtonGroup> _surfaces_button_group;
}; };
class TerrainWorldEditorPlugin : public EditorPlugin { class TerrainWorldEditorPlugin : public EditorPlugin {