Merge pull request #31974 from YeldhamDev/tilegrid_map_fixes

Small fixes for the Tile/GridMap editors
This commit is contained in:
Rémi Verschelde 2019-09-24 11:06:34 +02:00 committed by GitHub
commit cf540f853d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 29 deletions

View file

@ -989,7 +989,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (mb->is_pressed()) { if (mb->is_pressed()) {
if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) if (Input::get_singleton()->is_key_pressed(KEY_SPACE))
return false; //drag return false; // Drag.
if (tool == TOOL_NONE) { if (tool == TOOL_NONE) {
@ -1593,7 +1593,7 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
} }
} }
int max_lines = 10000; //avoid crash if size too smal int max_lines = 10000; //avoid crash if size too small
if (node->get_half_offset() != TileMap::HALF_OFFSET_Y && node->get_half_offset() != TileMap::HALF_OFFSET_NEGATIVE_Y) { if (node->get_half_offset() != TileMap::HALF_OFFSET_Y && node->get_half_offset() != TileMap::HALF_OFFSET_NEGATIVE_Y) {
@ -1645,7 +1645,7 @@ void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) {
p_overlay->draw_colored_polygon(points, Color(0.2, 0.8, 1, 0.4)); p_overlay->draw_colored_polygon(points, Color(0.2, 0.8, 1, 0.4));
} }
if (mouse_over) { if (mouse_over && node->get_tileset().is_valid()) {
Vector2 endpoints[4] = { Vector2 endpoints[4] = {
node->map_to_world(over_tile, true), node->map_to_world(over_tile, true),

View file

@ -385,8 +385,8 @@ bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, boo
if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters)) if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters))
return false; return false;
//make sure the intersection is inside the frustum planes, to avoid // Make sure the intersection is inside the frustum planes, to avoid
//painting on invisible regions // Painting on invisible regions.
for (int i = 0; i < planes.size(); i++) { for (int i = 0; i < planes.size(); i++) {
Plane fp = local_xform.xform(planes[i]); Plane fp = local_xform.xform(planes[i]);
@ -397,8 +397,6 @@ bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, boo
int cell[3]; int cell[3];
float cell_size[3] = { node->get_cell_size().x, node->get_cell_size().y, node->get_cell_size().z }; float cell_size[3] = { node->get_cell_size().x, node->get_cell_size().y, node->get_cell_size().z };
last_mouseover = Vector3(-1, -1, -1);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (i == edit_axis) if (i == edit_axis)
@ -407,19 +405,11 @@ bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, boo
cell[i] = inters[i] / node->get_cell_size()[i]; cell[i] = inters[i] / node->get_cell_size()[i];
if (inters[i] < 0) if (inters[i] < 0)
cell[i] -= 1; //compensate negative cell[i] -= 1; // Compensate negative.
grid_ofs[i] = cell[i] * cell_size[i]; grid_ofs[i] = cell[i] * cell_size[i];
} }
/*if (cell[i]<0 || cell[i]>=grid_size[i]) {
cursor_visible=false;
_update_cursor_transform();
return false;
}*/
} }
last_mouseover = Vector3(cell[0], cell[1], cell[2]);
VS::get_singleton()->instance_set_transform(grid_instance[edit_axis], node->get_global_transform() * edit_grid_xform); VS::get_singleton()->instance_set_transform(grid_instance[edit_axis], node->get_global_transform() * edit_grid_xform);
if (cursor_instance.is_valid()) { if (cursor_instance.is_valid()) {
@ -656,7 +646,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
if (mb->is_pressed()) if (mb->is_pressed())
floor->set_value(floor->get_value() + mb->get_factor()); floor->set_value(floor->get_value() + mb->get_factor());
return true; //eaten return true; // Eaten.
} else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) { } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) {
if (mb->is_pressed()) if (mb->is_pressed())
floor->set_value(floor->get_value() - mb->get_factor()); floor->set_value(floor->get_value() - mb->get_factor());
@ -702,9 +692,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true);
} else { } else {
if ( if ((mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) || (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) {
(mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) ||
(mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) {
if (set_items.size()) { if (set_items.size()) {
undo_redo->create_action(TTR("GridMap Paint")); undo_redo->create_action(TTR("GridMap Paint"));
@ -933,7 +921,7 @@ void GridMapEditor::update_palette() {
item++; item++;
} }
if (selected != -1) { if (selected != -1 && mesh_library_palette->get_item_count() > 0) {
mesh_library_palette->select(selected); mesh_library_palette->select(selected);
} }
@ -945,7 +933,6 @@ void GridMapEditor::edit(GridMap *p_gridmap) {
node = p_gridmap; node = p_gridmap;
VS *vs = VS::get_singleton(); VS *vs = VS::get_singleton();
last_mouseover = Vector3(-1, -1, -1);
input_action = INPUT_NONE; input_action = INPUT_NONE;
selection.active = false; selection.active = false;
_update_selection_transform(); _update_selection_transform();
@ -981,7 +968,7 @@ void GridMapEditor::edit(GridMap *p_gridmap) {
{ {
//update grids // Update grids.
indicator_mat.instance(); indicator_mat.instance();
indicator_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); indicator_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
indicator_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); indicator_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
@ -1052,9 +1039,7 @@ void GridMapEditor::_update_clip() {
void GridMapEditor::update_grid() { void GridMapEditor::update_grid() {
grid_xform.origin.x -= 1; //force update in hackish way.. what do i care grid_xform.origin.x -= 1; // Force update in hackish way.
//VS *vs = VS::get_singleton();
grid_ofs[edit_axis] = edit_floor[edit_axis] * node->get_cell_size()[edit_axis]; grid_ofs[edit_axis] = edit_floor[edit_axis] * node->get_cell_size()[edit_axis];
@ -1140,7 +1125,6 @@ void GridMapEditor::_notification(int p_what) {
SpatialEditorPlugin *sep = Object::cast_to<SpatialEditorPlugin>(editor->get_editor_plugin_screen()); SpatialEditorPlugin *sep = Object::cast_to<SpatialEditorPlugin>(editor->get_editor_plugin_screen());
if (sep) if (sep)
sep->snap_cursor_to_plane(p); sep->snap_cursor_to_plane(p);
//editor->get_editor_plugin_screen()->call("snap_cursor_to_plane",p);
} }
} break; } break;
@ -1358,7 +1342,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
selected_palette = -1; selected_palette = -1;
lock_view = false; lock_view = false;
cursor_rot = 0; cursor_rot = 0;
last_mouseover = Vector3(-1, -1, -1);
selection_mesh = VisualServer::get_singleton()->mesh_create(); selection_mesh = VisualServer::get_singleton()->mesh_create();
paste_mesh = VisualServer::get_singleton()->mesh_create(); paste_mesh = VisualServer::get_singleton()->mesh_create();

View file

@ -156,7 +156,6 @@ class GridMapEditor : public VBoxContainer {
Transform cursor_transform; Transform cursor_transform;
Vector3 cursor_origin; Vector3 cursor_origin;
Vector3 last_mouseover;
int display_mode; int display_mode;
int selected_palette; int selected_palette;