Now the world editor will use the channel reported by world's get_channel_index_info. Also it now has support for liquid channels (based on the currently selected tab).

This commit is contained in:
Relintai 2020-04-17 02:09:24 +02:00
parent f43e4a2cc4
commit 35863196d7
2 changed files with 32 additions and 1 deletions

View File

@ -104,6 +104,16 @@ bool VoxelWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point,
if (ss->intersect_ray(from, to, res)) {
Vector3 pos;
int selected_voxel = 0;
int channel = 0;
if (_current_tab == 0) {
channel = _channel_type;
} else {
channel = _channel_liquid_type;
}
if (channel == -1)
return false;
if (_tool_mode == TOOL_MODE_ADD) {
pos = (res.position + (Vector3(0.1, 0.1, 0.1) * res.normal));
@ -113,7 +123,7 @@ bool VoxelWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point,
selected_voxel = 0;
}
_world->set_voxel_at_world_position(pos, selected_voxel, 0);
_world->set_voxel_at_world_position(pos, selected_voxel, channel);
return true;
}
@ -127,6 +137,9 @@ void VoxelWorldEditor::edit(VoxelWorld *p_world) {
if (!_world)
return;
_channel_type = _world->get_channel_index_info(VoxelWorld::CHANNEL_TYPE_INFO_TYPE);
_channel_liquid_type = _world->get_channel_index_info(VoxelWorld::CHANNEL_TYPE_INFO_LIQUID);
spatial_editor = Object::cast_to<SpatialEditorPlugin>(_editor->get_editor_plugin_screen());
for (int i = 0; i < _surfaces_vbox_container->get_child_count(); ++i) {
@ -203,15 +216,21 @@ VoxelWorldEditor::VoxelWorldEditor() {
_world = NULL;
_selected_type = 0;
_selected_liquid_type = 0;
_channel_type = -1;
_channel_liquid_type = -1;
_editor = NULL;
_tool_mode = TOOL_MODE_ADD;
_current_tab = 0;
}
VoxelWorldEditor::VoxelWorldEditor(EditorNode *p_editor) {
_world = NULL;
_selected_type = 0;
_selected_liquid_type = 0;
_channel_type = -1;
_channel_liquid_type = -1;
_editor = p_editor;
_tool_mode = TOOL_MODE_ADD;
_current_tab = 0;
spatial_editor_hb = memnew(HBoxContainer);
spatial_editor_hb->set_h_size_flags(SIZE_EXPAND_FILL);
@ -245,6 +264,7 @@ VoxelWorldEditor::VoxelWorldEditor(EditorNode *p_editor) {
tab_container->set_h_size_flags(SIZE_EXPAND_FILL);
tab_container->set_v_size_flags(SIZE_EXPAND_FILL);
tab_container->set_name("Surfaces");
tab_container->connect("tab_selected", this, "_tab_selected");
add_child(tab_container);
_surfaces_vbox_container = memnew(VBoxContainer);
@ -298,10 +318,15 @@ void VoxelWorldEditor::_on_tool_button_pressed() {
}
}
void VoxelWorldEditor::_tab_selected(int tab) {
_current_tab = tab;
}
void VoxelWorldEditor::_bind_methods() {
ClassDB::bind_method("_node_removed", &VoxelWorldEditor::_node_removed);
ClassDB::bind_method("_on_surface_button_pressed", &VoxelWorldEditor::_on_surface_button_pressed);
ClassDB::bind_method("_on_tool_button_pressed", &VoxelWorldEditor::_on_tool_button_pressed);
ClassDB::bind_method("_tab_selected", &VoxelWorldEditor::_tab_selected);
}
void VoxelWorldEditorPlugin::_notification(int p_what) {

View File

@ -64,6 +64,7 @@ protected:
void _node_removed(Node *p_node);
void _on_surface_button_pressed();
void _on_tool_button_pressed();
void _tab_selected(int tab);
private:
VBoxContainer *_surfaces_vbox_container;
@ -81,6 +82,11 @@ private:
SpatialEditorPlugin *spatial_editor;
EditorNode *_editor;
int _channel_type;
int _channel_liquid_type;
int _current_tab;
};
class VoxelWorldEditorPlugin : public EditorPlugin {