| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  tile_map_editor_plugin.cpp                                           */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							|  |  |  | /*                    http://www.godotengine.org                         */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2017-01-01 22:01:57 +01:00
										 |  |  | /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							| 
									
										
										
										
											2017-04-08 00:11:42 +02:00
										 |  |  | /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md)    */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | #include "tile_map_editor_plugin.h"
 | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "canvas_item_editor_plugin.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 14:21:25 +01:00
										 |  |  | #include "editor/editor_scale.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "editor/editor_settings.h"
 | 
					
						
							|  |  |  | #include "os/input.h"
 | 
					
						
							|  |  |  | #include "os/keyboard.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void TileMapEditor::_notification(int p_what) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	switch (p_what) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 		case NOTIFICATION_ENTER_TREE: { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			transp->set_icon(get_icon("Transpose", "EditorIcons")); | 
					
						
							|  |  |  | 			mirror_x->set_icon(get_icon("MirrorX", "EditorIcons")); | 
					
						
							|  |  |  | 			mirror_y->set_icon(get_icon("MirrorY", "EditorIcons")); | 
					
						
							|  |  |  | 			rotate_0->set_icon(get_icon("Rotate0", "EditorIcons")); | 
					
						
							|  |  |  | 			rotate_90->set_icon(get_icon("Rotate90", "EditorIcons")); | 
					
						
							|  |  |  | 			rotate_180->set_icon(get_icon("Rotate180", "EditorIcons")); | 
					
						
							|  |  |  | 			rotate_270->set_icon(get_icon("Rotate270", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2016-08-15 16:48:04 -03:00
										 |  |  | 		case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 			if (is_visible_in_tree()) { | 
					
						
							| 
									
										
										
										
											2016-08-15 16:48:04 -03:00
										 |  |  | 				_update_palette(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TileMapEditor::_menu_option(int p_option) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	switch (p_option) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-12 17:21:01 -03:00
										 |  |  | 		case OPTION_BUCKET: { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			tool = TOOL_BUCKET; | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			canvas_item_editor->update(); | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		case OPTION_PICK_TILE: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			tool = TOOL_PICKING; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			canvas_item_editor->update(); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case OPTION_SELECT: { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			tool = TOOL_SELECTING; | 
					
						
							|  |  |  | 			selection_active = false; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			canvas_item_editor->update(); | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 		case OPTION_DUPLICATE: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			_update_copydata(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (selection_active) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				tool = TOOL_DUPLICATING; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				canvas_item_editor->update(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		case OPTION_ERASE_SELECTION: { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!selection_active) | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			undo_redo->create_action("Erase Selection"); | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { | 
					
						
							|  |  |  | 				for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					_set_cell(Point2i(j, i), TileMap::INVALID_CELL, false, false, false, true); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			undo_redo->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			selection_active = false; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			copydata.clear(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			canvas_item_editor->update(); | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TileMapEditor::_canvas_mouse_enter() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	mouse_over = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	canvas_item_editor->update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TileMapEditor::_canvas_mouse_exit() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	mouse_over = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	canvas_item_editor->update(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int TileMapEditor::get_selected_tile() const { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-22 10:05:03 -03:00
										 |  |  | 	int item = palette->get_current(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (item == -1) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return TileMap::INVALID_CELL; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-22 10:05:03 -03:00
										 |  |  | 	return palette->get_item_metadata(item); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-17 16:48:21 +10:00
										 |  |  | void TileMapEditor::set_selected_tile(int p_tile) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	int idx = palette->find_metadata(p_tile); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (idx >= 0) { | 
					
						
							|  |  |  | 		palette->select(idx, true); | 
					
						
							|  |  |  | 		palette->ensure_current_is_visible(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-02-11 21:40:50 +10:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-06-22 10:05:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TileMapEditor::_set_cell(const Point2i &p_pos, int p_value, bool p_flip_h, bool p_flip_v, bool p_transpose, bool p_with_undo) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ERR_FAIL_COND(!node); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int prev_val = node->get_cell(p_pos.x, p_pos.y); | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	bool prev_flip_h = node->is_cell_x_flipped(p_pos.x, p_pos.y); | 
					
						
							|  |  |  | 	bool prev_flip_v = node->is_cell_y_flipped(p_pos.x, p_pos.y); | 
					
						
							|  |  |  | 	bool prev_transpose = node->is_cell_transposed(p_pos.x, p_pos.y); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (p_value == prev_val && p_flip_h == prev_flip_h && p_flip_v == prev_flip_v && p_transpose == prev_transpose) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; //check that it's actually different
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-19 16:46:52 -03:00
										 |  |  | 	if (p_with_undo) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		undo_redo->add_do_method(node, "set_cellv", Point2(p_pos), p_value, p_flip_h, p_flip_v, p_transpose); | 
					
						
							|  |  |  | 		undo_redo->add_undo_method(node, "set_cellv", Point2(p_pos), prev_val, prev_flip_h, prev_flip_v, prev_transpose); | 
					
						
							| 
									
										
										
										
											2014-04-19 16:46:52 -03:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		node->set_cell(p_pos.x, p_pos.y, p_value, p_flip_h, p_flip_v, p_transpose); | 
					
						
							| 
									
										
										
										
											2014-04-19 16:46:52 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TileMapEditor::_text_entered(const String &p_text) { | 
					
						
							| 
									
										
										
										
											2015-06-22 10:05:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	canvas_item_editor->grab_focus(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-06-22 10:05:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TileMapEditor::_text_changed(const String &p_text) { | 
					
						
							| 
									
										
										
										
											2015-06-22 10:05:03 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_update_palette(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | void TileMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	Ref<InputEventKey> k = p_ie; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	if (k.is_valid() && (k->get_scancode() == KEY_UP || | 
					
						
							|  |  |  | 								k->get_scancode() == KEY_DOWN || | 
					
						
							|  |  |  | 								k->get_scancode() == KEY_PAGEUP || | 
					
						
							|  |  |  | 								k->get_scancode() == KEY_PAGEDOWN)) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		palette->call("_gui_input", k); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		search_box->accept_event(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-27 02:50:51 +02:00
										 |  |  | // Implementation detail of TileMapEditor::_update_palette();
 | 
					
						
							|  |  |  | // in modern C++ this could have been inside its body
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | struct _PaletteEntry { | 
					
						
							|  |  |  | 	int id; | 
					
						
							|  |  |  | 	String name; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool operator<(const _PaletteEntry &p_rhs) const { | 
					
						
							|  |  |  | 		return name < p_rhs.name; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void TileMapEditor::_update_palette() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!node) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	int selected = get_selected_tile(); | 
					
						
							| 
									
										
										
										
											2015-06-22 10:05:03 -03:00
										 |  |  | 	palette->clear(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Ref<TileSet> tileset = node->get_tileset(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	if (tileset.is_null()) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	List<int> tiles; | 
					
						
							|  |  |  | 	tileset->get_tile_list(&tiles); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	if (tiles.empty()) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 19:41:36 -03:00
										 |  |  | 	float min_size = EDITOR_DEF("editors/tile_map/preview_size", 64); | 
					
						
							| 
									
										
										
										
											2016-08-15 16:48:04 -03:00
										 |  |  | 	min_size *= EDSCALE; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	int hseparation = EDITOR_DEF("editors/tile_map/palette_item_hseparation", 8); | 
					
						
							| 
									
										
										
										
											2017-01-05 19:41:36 -03:00
										 |  |  | 	bool show_tile_names = bool(EDITOR_DEF("editors/tile_map/show_tile_names", true)); | 
					
						
							| 
									
										
										
										
											2017-03-27 02:50:51 +02:00
										 |  |  | 	bool show_tile_ids = bool(EDITOR_DEF("editors/tile_map/show_tile_ids", false)); | 
					
						
							|  |  |  | 	bool sort_by_name = bool(EDITOR_DEF("editors/tile_map/sort_tiles_by_name", true)); | 
					
						
							| 
									
										
										
										
											2016-05-27 22:42:51 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	palette->add_constant_override("hseparation", hseparation * EDSCALE); | 
					
						
							|  |  |  | 	palette->add_constant_override("vseparation", 8 * EDSCALE); | 
					
						
							| 
									
										
										
										
											2016-06-12 17:10:34 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	palette->set_fixed_icon_size(Size2(min_size, min_size)); | 
					
						
							| 
									
										
										
										
											2017-01-04 01:16:14 -03:00
										 |  |  | 	palette->set_fixed_column_width(min_size * MAX(size_slider->get_value(), 1)); | 
					
						
							| 
									
										
										
										
											2016-06-12 17:10:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	String filter = search_box->get_text().strip_edges(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-27 02:50:51 +02:00
										 |  |  | 	Vector<_PaletteEntry> entries; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (List<int>::Element *E = tiles.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-27 02:50:51 +02:00
										 |  |  | 		String name = tileset->tile_get_name(E->get()); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-27 02:50:51 +02:00
										 |  |  | 		if (name != "") { | 
					
						
							|  |  |  | 			if (show_tile_ids) { | 
					
						
							|  |  |  | 				if (sort_by_name) { | 
					
						
							|  |  |  | 					name = name + " - " + itos(E->get()); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					name = itos(E->get()) + " - " + name; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			name = "#" + itos(E->get()); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 16:48:04 -03:00
										 |  |  | 		if (filter != "" && !filter.is_subsequence_ofi(name)) | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-27 02:50:51 +02:00
										 |  |  | 		const _PaletteEntry entry = { E->get(), name }; | 
					
						
							|  |  |  | 		entries.push_back(entry); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (sort_by_name) { | 
					
						
							|  |  |  | 		entries.sort(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < entries.size(); i++) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-15 16:48:04 -03:00
										 |  |  | 		if (show_tile_names) { | 
					
						
							| 
									
										
										
										
											2017-03-27 02:50:51 +02:00
										 |  |  | 			palette->add_item(entries[i].name); | 
					
						
							| 
									
										
										
										
											2016-08-15 16:48:04 -03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			palette->add_item(String()); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-27 02:50:51 +02:00
										 |  |  | 		Ref<Texture> tex = tileset->tile_get_texture(entries[i].id); | 
					
						
							| 
									
										
										
										
											2015-06-22 10:05:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		if (tex.is_valid()) { | 
					
						
							| 
									
										
										
										
											2017-03-27 02:50:51 +02:00
										 |  |  | 			Rect2 region = tileset->tile_get_region(entries[i].id); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-14 16:24:17 -03:00
										 |  |  | 			if (!region.has_no_area()) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				palette->set_item_icon_region(palette->get_item_count() - 1, region); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			palette->set_item_icon(palette->get_item_count() - 1, tex); | 
					
						
							| 
									
										
										
										
											2015-06-22 10:05:03 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-27 02:50:51 +02:00
										 |  |  | 		palette->set_item_metadata(palette->get_item_count() - 1, entries[i].id); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-27 22:42:51 +03:00
										 |  |  | 	palette->set_same_column_width(true); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (selected != -1) | 
					
						
							|  |  |  | 		set_selected_tile(selected); | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-08-15 16:48:04 -03:00
										 |  |  | 		palette->select(0); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TileMapEditor::_pick_tile(const Point2 &p_pos) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	int id = node->get_cell(p_pos.x, p_pos.y); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (id == TileMap::INVALID_CELL) | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (search_box->get_text().strip_edges() != "") { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		search_box->set_text(""); | 
					
						
							|  |  |  | 		_update_palette(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	set_selected_tile(id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mirror_x->set_pressed(node->is_cell_x_flipped(p_pos.x, p_pos.y)); | 
					
						
							|  |  |  | 	mirror_y->set_pressed(node->is_cell_y_flipped(p_pos.x, p_pos.y)); | 
					
						
							|  |  |  | 	transp->set_pressed(node->is_cell_transposed(p_pos.x, p_pos.y)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_update_transform_buttons(); | 
					
						
							|  |  |  | 	canvas_item_editor->update(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool erase, bool preview) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-02 11:17:50 +00:00
										 |  |  | 	int prev_id = node->get_cell(p_start.x, p_start.y); | 
					
						
							|  |  |  | 	int id = TileMap::INVALID_CELL; | 
					
						
							|  |  |  | 	if (!erase) { | 
					
						
							|  |  |  | 		id = get_selected_tile(); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-02 11:17:50 +00:00
										 |  |  | 		if (id == TileMap::INVALID_CELL) | 
					
						
							| 
									
										
										
										
											2017-01-07 18:25:37 -03:00
										 |  |  | 			return PoolVector<Vector2>(); | 
					
						
							| 
									
										
										
										
											2017-08-03 20:44:15 +02:00
										 |  |  | 	} else if (prev_id == TileMap::INVALID_CELL) { | 
					
						
							|  |  |  | 		return PoolVector<Vector2>(); | 
					
						
							| 
									
										
										
										
											2016-09-02 11:17:50 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 	Rect2i r = node->get_item_rect(); | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 	r.position = r.position / node->get_cell_size(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	r.size = r.size / node->get_cell_size(); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 	int area = r.get_area(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (preview) { | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 		// Test if we can re-use the result from preview bucket fill
 | 
					
						
							|  |  |  | 		bool invalidate_cache = false; | 
					
						
							|  |  |  | 		// Area changed
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (r != bucket_cache_rect) | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 			_clear_bucket_cache(); | 
					
						
							|  |  |  | 		// Cache grid is not initialized
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (bucket_cache_visited == 0) { | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 			bucket_cache_visited = new bool[area]; | 
					
						
							|  |  |  | 			invalidate_cache = true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// Tile ID changed or position wasn't visited by the previous fill
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 		int loc = (p_start.x - r.position.x) + (p_start.y - r.position.y) * r.get_size().x; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (prev_id != bucket_cache_tile || !bucket_cache_visited[loc]) { | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 			invalidate_cache = true; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (invalidate_cache) { | 
					
						
							|  |  |  | 			for (int i = 0; i < area; ++i) | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 				bucket_cache_visited[i] = false; | 
					
						
							| 
									
										
										
										
											2017-01-07 18:25:37 -03:00
										 |  |  | 			bucket_cache = PoolVector<Vector2>(); | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 			bucket_cache_tile = prev_id; | 
					
						
							|  |  |  | 			bucket_cache_rect = r; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 			return bucket_cache; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-07 18:25:37 -03:00
										 |  |  | 	PoolVector<Vector2> points; | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	List<Point2i> queue; | 
					
						
							|  |  |  | 	queue.push_back(p_start); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (queue.size()) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Point2i n = queue.front()->get(); | 
					
						
							|  |  |  | 		queue.pop_front(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-12 17:21:01 -03:00
										 |  |  | 		if (!r.has_point(n)) | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-02 11:17:50 +00:00
										 |  |  | 		if (node->get_cell(n.x, n.y) == prev_id) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (preview) { | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 				int loc = (n.x - r.position.x) + (n.y - r.position.y) * r.get_size().x; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (bucket_cache_visited[loc]) | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 					continue; | 
					
						
							|  |  |  | 				bucket_cache_visited[loc] = true; | 
					
						
							|  |  |  | 				bucket_cache.push_back(n); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 				node->set_cellv(n, id, flip_h, flip_v, transpose); | 
					
						
							|  |  |  | 				points.push_back(n); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			queue.push_back(n + Point2i(0, 1)); | 
					
						
							|  |  |  | 			queue.push_back(n + Point2i(0, -1)); | 
					
						
							|  |  |  | 			queue.push_back(n + Point2i(1, 0)); | 
					
						
							|  |  |  | 			queue.push_back(n + Point2i(-1, 0)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 	return preview ? bucket_cache : points; | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TileMapEditor::_fill_points(const PoolVector<Vector2> p_points, const Dictionary &p_op) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int len = p_points.size(); | 
					
						
							| 
									
										
										
										
											2017-01-07 18:25:37 -03:00
										 |  |  | 	PoolVector<Vector2>::Read pr = p_points.read(); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int id = p_op["id"]; | 
					
						
							|  |  |  | 	bool xf = p_op["flip_h"]; | 
					
						
							|  |  |  | 	bool yf = p_op["flip_v"]; | 
					
						
							|  |  |  | 	bool tr = p_op["transpose"]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < len; i++) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		_set_cell(pr[i], id, xf, yf, tr); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-07 18:25:37 -03:00
										 |  |  | void TileMapEditor::_erase_points(const PoolVector<Vector2> p_points) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int len = p_points.size(); | 
					
						
							| 
									
										
										
										
											2017-01-07 18:25:37 -03:00
										 |  |  | 	PoolVector<Vector2>::Read pr = p_points.read(); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < len; i++) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		_set_cell(pr[i], TileMap::INVALID_CELL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TileMapEditor::_select(const Point2i &p_from, const Point2i &p_to) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Point2i begin = p_from; | 
					
						
							|  |  |  | 	Point2i end = p_to; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	if (begin.x > end.x) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		SWAP(begin.x, end.x); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (begin.y > end.y) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		SWAP(begin.y, end.y); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 	rectangle.position = begin; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	rectangle.size = end - begin; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	canvas_item_editor->update(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TileMapEditor::_draw_cell(int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D &p_xform) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	Ref<Texture> t = node->get_tileset()->tile_get_texture(p_cell); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (t.is_null()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector2 tile_ofs = node->get_tileset()->tile_get_texture_offset(p_cell); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Rect2 r = node->get_tileset()->tile_get_region(p_cell); | 
					
						
							|  |  |  | 	Size2 sc = p_xform.get_scale(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 	Rect2 rect = Rect2(); | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 	rect.position = node->map_to_world(p_point) + node->get_cell_draw_offset(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 	if (r.has_no_area()) { | 
					
						
							|  |  |  | 		rect.size = t->get_size(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 		rect.size = r.size; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (rect.size.y > rect.size.x) { | 
					
						
							|  |  |  | 		if ((p_flip_h && (p_flip_v || p_transpose)) || (p_flip_v && !p_transpose)) | 
					
						
							|  |  |  | 			tile_ofs.y += rect.size.y - rect.size.x; | 
					
						
							|  |  |  | 	} else if (rect.size.y < rect.size.x) { | 
					
						
							|  |  |  | 		if ((p_flip_v && (p_flip_h || p_transpose)) || (p_flip_h && !p_transpose)) | 
					
						
							|  |  |  | 			tile_ofs.x += rect.size.x - rect.size.y; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p_transpose) { | 
					
						
							|  |  |  | 		SWAP(tile_ofs.x, tile_ofs.y); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (p_flip_h) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		sc.x *= -1.0; | 
					
						
							|  |  |  | 		tile_ofs.x *= -1.0; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (p_flip_v) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		sc.y *= -1.0; | 
					
						
							|  |  |  | 		tile_ofs.y *= -1.0; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (node->get_tile_origin() == TileMap::TILE_ORIGIN_TOP_LEFT) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 		rect.position += tile_ofs; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	} else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_BOTTOM_LEFT) { | 
					
						
							| 
									
										
										
										
											2016-06-18 00:01:00 +02:00
										 |  |  | 		Size2 cell_size = node->get_cell_size(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 		rect.position += tile_ofs; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (p_transpose) { | 
					
						
							|  |  |  | 			if (p_flip_h) | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 				rect.position.x -= cell_size.x; | 
					
						
							| 
									
										
										
										
											2016-06-18 00:01:00 +02:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 				rect.position.x += cell_size.x; | 
					
						
							| 
									
										
										
										
											2016-06-18 00:01:00 +02:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (p_flip_v) | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 				rect.position.y -= cell_size.y; | 
					
						
							| 
									
										
										
										
											2016-06-18 00:01:00 +02:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 				rect.position.y += cell_size.y; | 
					
						
							| 
									
										
										
										
											2016-06-18 00:01:00 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	} else if (node->get_tile_origin() == TileMap::TILE_ORIGIN_CENTER) { | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 		rect.position += node->get_cell_size() / 2; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		Vector2 s = r.size; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Vector2 center = (s / 2) - tile_ofs; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (p_flip_h) | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			rect.position.x -= s.x - center.x; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			rect.position.x -= center.x; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (p_flip_v) | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			rect.position.y -= s.y - center.y; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			rect.position.y -= center.y; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 	rect.position = p_xform.xform(rect.position); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	rect.size *= sc; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 	if (r.has_no_area()) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		canvas_item_editor->draw_texture_rect(t, rect, false, Color(1, 1, 1, 0.5), p_transpose); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		canvas_item_editor->draw_texture_rect_region(t, rect, r, Color(1, 1, 1, 0.5), p_transpose); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void TileMapEditor::_draw_fill_preview(int p_cell, const Point2i &p_point, bool p_flip_h, bool p_flip_v, bool p_transpose, const Transform2D &p_xform) { | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-07 18:25:37 -03:00
										 |  |  | 	PoolVector<Vector2> points = _bucket_fill(p_point, false, true); | 
					
						
							|  |  |  | 	PoolVector<Vector2>::Read pr = points.read(); | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 	int len = points.size(); | 
					
						
							|  |  |  | 	int time_after = OS::get_singleton()->get_ticks_msec(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < len; ++i) { | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 		_draw_cell(p_cell, pr[i], p_flip_h, p_flip_v, p_transpose, p_xform); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TileMapEditor::_clear_bucket_cache() { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (bucket_cache_visited) { | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 		delete[] bucket_cache_visited; | 
					
						
							|  |  |  | 		bucket_cache_visited = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | void TileMapEditor::_update_copydata() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	copydata.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!selection_active) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 	for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 		for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			TileData tcd; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			tcd.cell = node->get_cell(j, i); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (tcd.cell != TileMap::INVALID_CELL) { | 
					
						
							|  |  |  | 				tcd.pos = Point2i(j, i); | 
					
						
							|  |  |  | 				tcd.flip_h = node->is_cell_x_flipped(j, i); | 
					
						
							|  |  |  | 				tcd.flip_v = node->is_cell_y_flipped(j, i); | 
					
						
							|  |  |  | 				tcd.transpose = node->is_cell_transposed(j, i); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			copydata.push_back(tcd); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | static inline Vector<Point2i> line(int x0, int x1, int y0, int y1) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector<Point2i> points; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float dx = ABS(x1 - x0); | 
					
						
							|  |  |  | 	float dy = ABS(y1 - y0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int x = x0; | 
					
						
							|  |  |  | 	int y = y0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int sx = x0 > x1 ? -1 : 1; | 
					
						
							|  |  |  | 	int sy = y0 > y1 ? -1 : 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (dx > dy) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		float err = dx / 2; | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 		for (; x != x1; x += sx) { | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 			points.push_back(Vector2(x, y)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			err -= dy; | 
					
						
							|  |  |  | 			if (err < 0) { | 
					
						
							|  |  |  | 				y += sy; | 
					
						
							|  |  |  | 				err += dx; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		float err = dy / 2; | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 		for (; y != y1; y += sy) { | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 			points.push_back(Vector2(x, y)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			err -= dx; | 
					
						
							|  |  |  | 			if (err < 0) { | 
					
						
							|  |  |  | 				x += sx; | 
					
						
							|  |  |  | 				err += dy; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	points.push_back(Vector2(x, y)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return points; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { | 
					
						
							| 
									
										
										
										
											2015-12-28 21:23:32 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-13 10:45:50 -03:00
										 |  |  | 	if (!node || !node->get_tileset().is_valid() || !node->is_visible_in_tree()) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 00:52:51 -03:00
										 |  |  | 	Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform(); | 
					
						
							|  |  |  | 	Transform2D xform_inv = xform.affine_inverse(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	Ref<InputEventMouseButton> mb = p_event; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	if (mb.is_valid()) { | 
					
						
							|  |  |  | 		if (mb->get_button_index() == BUTTON_LEFT) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			if (mb->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				if (Input::get_singleton()->is_key_pressed(KEY_SPACE)) | 
					
						
							|  |  |  | 					return false; //drag
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				if (tool == TOOL_NONE) { | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					if (mb->get_shift()) { | 
					
						
							| 
									
										
										
										
											2016-03-12 17:21:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						if (mb->get_control()) | 
					
						
							|  |  |  | 							tool = TOOL_RECTANGLE_PAINT; | 
					
						
							|  |  |  | 						else | 
					
						
							|  |  |  | 							tool = TOOL_LINE_PAINT; | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						selection_active = false; | 
					
						
							|  |  |  | 						rectangle_begin = over_tile; | 
					
						
							| 
									
										
										
										
											2016-03-12 17:21:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						return true; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					if (mb->get_control()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						tool = TOOL_PICKING; | 
					
						
							|  |  |  | 						_pick_tile(over_tile); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						return true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					tool = TOOL_PAINTING; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				if (tool == TOOL_PAINTING) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					int id = get_selected_tile(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					if (id != TileMap::INVALID_CELL) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						tool = TOOL_PAINTING; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						paint_undo.clear(); | 
					
						
							|  |  |  | 						paint_undo[over_tile] = _get_op_from_cell(over_tile); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						_set_cell(over_tile, id, flip_h, flip_v, transpose); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				} else if (tool == TOOL_PICKING) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					_pick_tile(over_tile); | 
					
						
							|  |  |  | 				} else if (tool == TOOL_SELECTING) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					selection_active = true; | 
					
						
							|  |  |  | 					rectangle_begin = over_tile; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				return true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				if (tool != TOOL_NONE) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					if (tool == TOOL_PAINTING) { | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						int id = get_selected_tile(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						if (id != TileMap::INVALID_CELL && paint_undo.size()) { | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 							undo_redo->create_action(TTR("Paint TileMap")); | 
					
						
							|  |  |  | 							for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 								Point2 p = E->key(); | 
					
						
							|  |  |  | 								undo_redo->add_do_method(node, "set_cellv", p, id, flip_h, flip_v, transpose); | 
					
						
							|  |  |  | 								undo_redo->add_undo_method(node, "set_cellv", p, E->get().idx, E->get().xf, E->get().yf, E->get().tr); | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							undo_redo->commit_action(); | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 							paint_undo.clear(); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} else if (tool == TOOL_LINE_PAINT) { | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						int id = get_selected_tile(); | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						if (id != TileMap::INVALID_CELL) { | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 							undo_redo->create_action("Line Draw"); | 
					
						
							|  |  |  | 							for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2016-03-12 17:21:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 								_set_cell(E->key(), id, flip_h, flip_v, transpose, true); | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 							undo_redo->commit_action(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 							paint_undo.clear(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 							canvas_item_editor->update(); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} else if (tool == TOOL_RECTANGLE_PAINT) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						int id = get_selected_tile(); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						if (id != TileMap::INVALID_CELL) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 							undo_redo->create_action("Rectangle Paint"); | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 							for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { | 
					
						
							|  |  |  | 								for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 									_set_cell(Point2i(j, i), id, flip_h, flip_v, transpose, true); | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 							} | 
					
						
							|  |  |  | 							undo_redo->commit_action(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							canvas_item_editor->update(); | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} else if (tool == TOOL_DUPLICATING) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 						Point2 ofs = over_tile - rectangle.position; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						undo_redo->create_action(TTR("Duplicate")); | 
					
						
							|  |  |  | 						for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							_set_cell(E->get().pos + ofs, E->get().cell, E->get().flip_h, E->get().flip_v, E->get().transpose, true); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						undo_redo->commit_action(); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						copydata.clear(); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						canvas_item_editor->update(); | 
					
						
							| 
									
										
										
										
											2016-09-02 11:17:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					} else if (tool == TOOL_SELECTING) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						canvas_item_editor->update(); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					} else if (tool == TOOL_BUCKET) { | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						Dictionary pop; | 
					
						
							|  |  |  | 						pop["id"] = node->get_cell(over_tile.x, over_tile.y); | 
					
						
							|  |  |  | 						pop["flip_h"] = node->is_cell_x_flipped(over_tile.x, over_tile.y); | 
					
						
							|  |  |  | 						pop["flip_v"] = node->is_cell_y_flipped(over_tile.x, over_tile.y); | 
					
						
							|  |  |  | 						pop["transpose"] = node->is_cell_transposed(over_tile.x, over_tile.y); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						PoolVector<Vector2> points = _bucket_fill(over_tile); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						if (points.size() == 0) | 
					
						
							|  |  |  | 							return false; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						Dictionary op; | 
					
						
							|  |  |  | 						op["id"] = get_selected_tile(); | 
					
						
							|  |  |  | 						op["flip_h"] = flip_h; | 
					
						
							|  |  |  | 						op["flip_v"] = flip_v; | 
					
						
							|  |  |  | 						op["transpose"] = transpose; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						undo_redo->create_action("Bucket Fill"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						undo_redo->add_do_method(this, "_fill_points", points, op); | 
					
						
							|  |  |  | 						undo_redo->add_undo_method(this, "_fill_points", points, pop); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						undo_redo->commit_action(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					tool = TOOL_NONE; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					return true; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else if (mb->get_button_index() == BUTTON_RIGHT) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			if (mb->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				if (tool == TOOL_SELECTING || selection_active) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					tool = TOOL_NONE; | 
					
						
							|  |  |  | 					selection_active = false; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					canvas_item_editor->update(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					return true; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				if (tool == TOOL_DUPLICATING) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					tool = TOOL_NONE; | 
					
						
							|  |  |  | 					copydata.clear(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					canvas_item_editor->update(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					return true; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				if (tool == TOOL_NONE) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					paint_undo.clear(); | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-03 10:54:24 +02:00
										 |  |  | 					Point2 local = node->world_to_map(xform_inv.xform(mb->get_position())); | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					if (mb->get_shift()) { | 
					
						
							| 
									
										
										
										
											2016-03-12 17:21:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						if (mb->get_control()) | 
					
						
							|  |  |  | 							tool = TOOL_RECTANGLE_ERASE; | 
					
						
							|  |  |  | 						else | 
					
						
							|  |  |  | 							tool = TOOL_LINE_ERASE; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						selection_active = false; | 
					
						
							|  |  |  | 						rectangle_begin = local; | 
					
						
							|  |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						tool = TOOL_ERASING; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						paint_undo[local] = _get_op_from_cell(local); | 
					
						
							|  |  |  | 						_set_cell(local, TileMap::INVALID_CELL); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					return true; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				if (tool == TOOL_ERASING || tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) { | 
					
						
							| 
									
										
										
										
											2014-04-19 16:46:52 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					if (paint_undo.size()) { | 
					
						
							|  |  |  | 						undo_redo->create_action(TTR("Erase TileMap")); | 
					
						
							|  |  |  | 						for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2014-04-19 16:46:52 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 							Point2 p = E->key(); | 
					
						
							|  |  |  | 							undo_redo->add_do_method(node, "set_cellv", p, TileMap::INVALID_CELL, false, false, false); | 
					
						
							|  |  |  | 							undo_redo->add_undo_method(node, "set_cellv", p, E->get().idx, E->get().xf, E->get().yf, E->get().tr); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2014-04-19 16:46:52 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						undo_redo->commit_action(); | 
					
						
							|  |  |  | 						paint_undo.clear(); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					if (tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) { | 
					
						
							|  |  |  | 						canvas_item_editor->update(); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					tool = TOOL_NONE; | 
					
						
							| 
									
										
										
										
											2016-09-02 11:17:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					return true; | 
					
						
							| 
									
										
										
										
											2016-09-02 11:17:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				} else if (tool == TOOL_BUCKET) { | 
					
						
							| 
									
										
										
										
											2016-09-02 11:17:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					Dictionary pop; | 
					
						
							|  |  |  | 					pop["id"] = node->get_cell(over_tile.x, over_tile.y); | 
					
						
							|  |  |  | 					pop["flip_h"] = node->is_cell_x_flipped(over_tile.x, over_tile.y); | 
					
						
							|  |  |  | 					pop["flip_v"] = node->is_cell_y_flipped(over_tile.x, over_tile.y); | 
					
						
							|  |  |  | 					pop["transpose"] = node->is_cell_transposed(over_tile.x, over_tile.y); | 
					
						
							| 
									
										
										
										
											2016-09-02 11:17:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					PoolVector<Vector2> points = _bucket_fill(over_tile, true); | 
					
						
							| 
									
										
										
										
											2016-09-02 11:17:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					if (points.size() == 0) | 
					
						
							|  |  |  | 						return false; | 
					
						
							| 
									
										
										
										
											2016-09-02 11:17:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					undo_redo->create_action("Bucket Fill"); | 
					
						
							| 
									
										
										
										
											2016-09-02 11:17:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					undo_redo->add_do_method(this, "_erase_points", points); | 
					
						
							|  |  |  | 					undo_redo->add_undo_method(this, "_fill_points", points, pop); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					undo_redo->commit_action(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	Ref<InputEventMouseMotion> mm = p_event; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	if (mm.is_valid()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-03 10:54:24 +02:00
										 |  |  | 		Point2i new_over_tile = node->world_to_map(xform_inv.xform(mm->get_position())); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		if (new_over_tile != over_tile) { | 
					
						
							| 
									
										
										
										
											2016-06-16 21:10:44 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			over_tile = new_over_tile; | 
					
						
							|  |  |  | 			canvas_item_editor->update(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-06-16 21:10:44 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		int tile_under = node->get_cell(over_tile.x, over_tile.y); | 
					
						
							|  |  |  | 		String tile_name = "none"; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		if (node->get_tileset()->has_tile(tile_under)) | 
					
						
							|  |  |  | 			tile_name = node->get_tileset()->tile_get_name(tile_under); | 
					
						
							|  |  |  | 		tile_info->set_text(String::num(over_tile.x) + ", " + String::num(over_tile.y) + " [" + tile_name + "]"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		if (tool == TOOL_PAINTING) { | 
					
						
							| 
									
										
										
										
											2016-03-12 17:21:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			int id = get_selected_tile(); | 
					
						
							|  |  |  | 			if (id != TileMap::INVALID_CELL) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				if (!paint_undo.has(over_tile)) { | 
					
						
							|  |  |  | 					paint_undo[over_tile] = _get_op_from_cell(over_tile); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				_set_cell(over_tile, id, flip_h, flip_v, transpose); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 				return true; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-12 17:21:01 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		if (tool == TOOL_SELECTING) { | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			_select(rectangle_begin, over_tile); | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		if (tool == TOOL_LINE_PAINT || tool == TOOL_LINE_ERASE) { | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			int id = get_selected_tile(); | 
					
						
							|  |  |  | 			bool erasing = (tool == TOOL_LINE_ERASE); | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			if (erasing && paint_undo.size()) { | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					_set_cell(E->key(), E->get().idx, E->get().xf, E->get().yf, E->get().tr); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			paint_undo.clear(); | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			if (id != TileMap::INVALID_CELL) { | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				Vector<Point2i> points = line(rectangle_begin.x, over_tile.x, rectangle_begin.y, over_tile.y); | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				for (int i = 0; i < points.size(); i++) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					paint_undo[points[i]] = _get_op_from_cell(points[i]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					if (erasing) | 
					
						
							|  |  |  | 						_set_cell(points[i], TileMap::INVALID_CELL); | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				canvas_item_editor->update(); | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (tool == TOOL_RECTANGLE_PAINT || tool == TOOL_RECTANGLE_ERASE) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			_select(rectangle_begin, over_tile); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			if (tool == TOOL_RECTANGLE_ERASE) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				if (paint_undo.size()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 					for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						_set_cell(E->key(), E->get().idx, E->get().xf, E->get().yf, E->get().tr); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 				paint_undo.clear(); | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 				for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { | 
					
						
							|  |  |  | 					for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						Point2i tile = Point2i(j, i); | 
					
						
							|  |  |  | 						paint_undo[tile] = _get_op_from_cell(tile); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 						_set_cell(tile, TileMap::INVALID_CELL); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (tool == TOOL_ERASING) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			if (!paint_undo.has(over_tile)) { | 
					
						
							|  |  |  | 				paint_undo[over_tile] = _get_op_from_cell(over_tile); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			_set_cell(over_tile, TileMap::INVALID_CELL); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (tool == TOOL_PICKING && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			_pick_tile(over_tile); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	Ref<InputEventKey> k = p_event; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	if (k.is_valid() && k->is_pressed()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		if (k->get_scancode() == KEY_ESCAPE) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			if (tool == TOOL_DUPLICATING) | 
					
						
							|  |  |  | 				copydata.clear(); | 
					
						
							|  |  |  | 			else if (tool == TOOL_SELECTING || selection_active) | 
					
						
							|  |  |  | 				selection_active = false; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			tool = TOOL_NONE; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			canvas_item_editor->update(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		if (tool != TOOL_NONE || !mouse_over) | 
					
						
							|  |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		if (ED_IS_SHORTCUT("tile_map_editor/erase_selection", p_event)) { | 
					
						
							|  |  |  | 			_menu_option(OPTION_ERASE_SELECTION); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (ED_IS_SHORTCUT("tile_map_editor/select", p_event)) { | 
					
						
							|  |  |  | 			tool = TOOL_SELECTING; | 
					
						
							|  |  |  | 			selection_active = false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			canvas_item_editor->update(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (ED_IS_SHORTCUT("tile_map_editor/duplicate_selection", p_event)) { | 
					
						
							|  |  |  | 			_update_copydata(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 			if (selection_active) { | 
					
						
							|  |  |  | 				tool = TOOL_DUPLICATING; | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-12 17:19:18 -05:00
										 |  |  | 				canvas_item_editor->update(); | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-12 17:19:18 -05:00
										 |  |  | 				return true; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (ED_IS_SHORTCUT("tile_map_editor/find_tile", p_event)) { | 
					
						
							|  |  |  | 			search_box->select_all(); | 
					
						
							|  |  |  | 			search_box->grab_focus(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (ED_IS_SHORTCUT("tile_map_editor/mirror_x", p_event)) { | 
					
						
							|  |  |  | 			flip_h = !flip_h; | 
					
						
							|  |  |  | 			mirror_x->set_pressed(flip_h); | 
					
						
							|  |  |  | 			canvas_item_editor->update(); | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (ED_IS_SHORTCUT("tile_map_editor/mirror_y", p_event)) { | 
					
						
							|  |  |  | 			flip_v = !flip_v; | 
					
						
							|  |  |  | 			mirror_y->set_pressed(flip_v); | 
					
						
							|  |  |  | 			canvas_item_editor->update(); | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (ED_IS_SHORTCUT("tile_map_editor/transpose", p_event)) { | 
					
						
							|  |  |  | 			transpose = !transpose; | 
					
						
							|  |  |  | 			transp->set_pressed(transpose); | 
					
						
							|  |  |  | 			canvas_item_editor->update(); | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void TileMapEditor::_canvas_draw() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!node) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 00:52:51 -03:00
										 |  |  | 	Transform2D cell_xf = node->get_cell_transform(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 00:52:51 -03:00
										 |  |  | 	Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform(); | 
					
						
							|  |  |  | 	Transform2D xform_inv = xform.affine_inverse(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Size2 screen_size = canvas_item_editor->get_size(); | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		Rect2 aabb; | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 		aabb.position = node->world_to_map(xform_inv.xform(Vector2())); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(0, screen_size.height)))); | 
					
						
							|  |  |  | 		aabb.expand_to(node->world_to_map(xform_inv.xform(Vector2(screen_size.width, 0)))); | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 		aabb.expand_to(node->world_to_map(xform_inv.xform(screen_size))); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Rect2i si = aabb.grow(1.0); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (node->get_half_offset() != TileMap::HALF_OFFSET_X) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			int max_lines = 2000; //avoid crash if size too smal
 | 
					
						
							| 
									
										
										
										
											2016-01-24 17:22:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			for (int i = (si.position.x) - 1; i <= (si.position.x + si.size.x); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 				Vector2 from = xform.xform(node->map_to_world(Vector2(i, si.position.y))); | 
					
						
							|  |  |  | 				Vector2 to = xform.xform(node->map_to_world(Vector2(i, si.position.y + si.size.y + 1))); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); | 
					
						
							|  |  |  | 				canvas_item_editor->draw_line(from, to, col, 1); | 
					
						
							|  |  |  | 				if (max_lines-- == 0) | 
					
						
							| 
									
										
										
										
											2016-01-24 17:22:17 -03:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			int max_lines = 10000; //avoid crash if size too smal
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			for (int i = (si.position.x) - 1; i <= (si.position.x + si.size.x); i++) { | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 				for (int j = (si.position.y) - 1; j <= (si.position.y + si.size.y); j++) { | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					Vector2 ofs; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					if (ABS(j) & 1) { | 
					
						
							|  |  |  | 						ofs = cell_xf[0] * 0.5; | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					Vector2 from = xform.xform(node->map_to_world(Vector2(i, j), true) + ofs); | 
					
						
							|  |  |  | 					Vector2 to = xform.xform(node->map_to_world(Vector2(i, j + 1), true) + ofs); | 
					
						
							|  |  |  | 					Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); | 
					
						
							|  |  |  | 					canvas_item_editor->draw_line(from, to, col, 1); | 
					
						
							| 
									
										
										
										
											2016-01-24 17:22:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					if (max_lines-- == 0) | 
					
						
							| 
									
										
										
										
											2016-01-24 17:22:17 -03:00
										 |  |  | 						break; | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		int max_lines = 10000; //avoid crash if size too smal
 | 
					
						
							| 
									
										
										
										
											2016-01-24 17:22:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (node->get_half_offset() != TileMap::HALF_OFFSET_Y) { | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			for (int i = (si.position.y) - 1; i <= (si.position.y + si.size.y); i++) { | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 				Vector2 from = xform.xform(node->map_to_world(Vector2(si.position.x, i))); | 
					
						
							|  |  |  | 				Vector2 to = xform.xform(node->map_to_world(Vector2(si.position.x + si.size.x + 1, i))); | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); | 
					
						
							|  |  |  | 				canvas_item_editor->draw_line(from, to, col, 1); | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				if (max_lines-- == 0) | 
					
						
							| 
									
										
										
										
											2016-01-24 17:22:17 -03:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			for (int i = (si.position.y) - 1; i <= (si.position.y + si.size.y); i++) { | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 				for (int j = (si.position.x) - 1; j <= (si.position.x + si.size.x); j++) { | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					Vector2 ofs; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					if (ABS(j) & 1) { | 
					
						
							|  |  |  | 						ofs = cell_xf[1] * 0.5; | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					Vector2 from = xform.xform(node->map_to_world(Vector2(j, i), true) + ofs); | 
					
						
							|  |  |  | 					Vector2 to = xform.xform(node->map_to_world(Vector2(j + 1, i), true) + ofs); | 
					
						
							|  |  |  | 					Color col = i == 0 ? Color(1, 0.8, 0.2, 0.5) : Color(1, 0.3, 0.1, 0.2); | 
					
						
							|  |  |  | 					canvas_item_editor->draw_line(from, to, col, 1); | 
					
						
							| 
									
										
										
										
											2016-01-24 17:22:17 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 					if (max_lines-- == 0) | 
					
						
							| 
									
										
										
										
											2016-01-24 17:22:17 -03:00
										 |  |  | 						break; | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (selection_active) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Vector<Vector2> points; | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 		points.push_back(xform.xform(node->map_to_world((rectangle.position)))); | 
					
						
							|  |  |  | 		points.push_back(xform.xform(node->map_to_world((rectangle.position + Point2(rectangle.size.x + 1, 0))))); | 
					
						
							|  |  |  | 		points.push_back(xform.xform(node->map_to_world((rectangle.position + Point2(rectangle.size.x + 1, rectangle.size.y + 1))))); | 
					
						
							|  |  |  | 		points.push_back(xform.xform(node->map_to_world((rectangle.position + Point2(0, rectangle.size.y + 1))))); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		canvas_item_editor->draw_colored_polygon(points, Color(0.2, 0.8, 1, 0.4)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (mouse_over) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		Vector2 endpoints[4] = { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			node->map_to_world(over_tile, true), | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			node->map_to_world((over_tile + Point2(1, 0)), true), | 
					
						
							|  |  |  | 			node->map_to_world((over_tile + Point2(1, 1)), true), | 
					
						
							|  |  |  | 			node->map_to_world((over_tile + Point2(0, 1)), true) | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int i = 0; i < 4; i++) { | 
					
						
							|  |  |  | 			if (node->get_half_offset() == TileMap::HALF_OFFSET_X && ABS(over_tile.y) & 1) | 
					
						
							|  |  |  | 				endpoints[i] += cell_xf[0] * 0.5; | 
					
						
							|  |  |  | 			if (node->get_half_offset() == TileMap::HALF_OFFSET_Y && ABS(over_tile.x) & 1) | 
					
						
							|  |  |  | 				endpoints[i] += cell_xf[1] * 0.5; | 
					
						
							|  |  |  | 			endpoints[i] = xform.xform(endpoints[i]); | 
					
						
							| 
									
										
										
										
											2014-10-03 00:10:51 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		Color col; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (node->get_cell(over_tile.x, over_tile.y) != TileMap::INVALID_CELL) | 
					
						
							|  |  |  | 			col = Color(0.2, 0.8, 1.0, 0.8); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			col = Color(1.0, 0.4, 0.2, 0.8); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int i = 0; i < 4; i++) | 
					
						
							|  |  |  | 			canvas_item_editor->draw_line(endpoints[i], endpoints[(i + 1) % 4], col, 2); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 19:41:36 -03:00
										 |  |  | 		bool bucket_preview = EditorSettings::get_singleton()->get("editors/tile_map/bucket_fill_preview"); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (tool == TOOL_SELECTING || tool == TOOL_PICKING || !bucket_preview) { | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (tool == TOOL_LINE_PAINT) { | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (paint_undo.empty()) | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			int id = get_selected_tile(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (id == TileMap::INVALID_CELL) | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 				return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2016-03-11 14:06:54 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				_draw_cell(id, E->key(), flip_h, flip_v, transpose, xform); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		} else if (tool == TOOL_RECTANGLE_PAINT) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			int id = get_selected_tile(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (id == TileMap::INVALID_CELL) | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) { | 
					
						
							|  |  |  | 				for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 					_draw_cell(id, Point2i(j, i), flip_h, flip_v, transpose, xform); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		} else if (tool == TOOL_DUPLICATING) { | 
					
						
							| 
									
										
										
										
											2016-01-04 15:28:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			if (copydata.empty()) | 
					
						
							|  |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2016-01-04 15:28:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			Ref<TileSet> ts = node->get_tileset(); | 
					
						
							| 
									
										
										
										
											2016-01-04 15:28:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			if (ts.is_null()) | 
					
						
							|  |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2016-01-02 18:17:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			Point2 ofs = over_tile - rectangle.position; | 
					
						
							| 
									
										
										
										
											2015-03-09 02:34:56 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) { | 
					
						
							| 
									
										
										
										
											2015-03-09 02:34:56 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 				if (!ts->has_tile(E->get().cell)) | 
					
						
							|  |  |  | 					continue; | 
					
						
							| 
									
										
										
										
											2015-03-09 02:34:56 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 				TileData tcd = E->get(); | 
					
						
							| 
									
										
										
										
											2015-03-09 02:34:56 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 				_draw_cell(tcd.cell, tcd.pos + ofs, tcd.flip_h, tcd.flip_v, tcd.transpose, xform); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-03-09 02:34:56 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			Rect2i duplicate = rectangle; | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			duplicate.position = over_tile; | 
					
						
							| 
									
										
										
										
											2015-03-09 02:34:56 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			Vector<Vector2> points; | 
					
						
							| 
									
										
										
										
											2017-06-04 00:25:13 +02:00
										 |  |  | 			points.push_back(xform.xform(node->map_to_world(duplicate.position))); | 
					
						
							|  |  |  | 			points.push_back(xform.xform(node->map_to_world((duplicate.position + Point2(duplicate.size.x + 1, 0))))); | 
					
						
							|  |  |  | 			points.push_back(xform.xform(node->map_to_world((duplicate.position + Point2(duplicate.size.x + 1, duplicate.size.y + 1))))); | 
					
						
							|  |  |  | 			points.push_back(xform.xform(node->map_to_world((duplicate.position + Point2(0, duplicate.size.y + 1))))); | 
					
						
							| 
									
										
										
										
											2015-03-09 02:34:56 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			canvas_item_editor->draw_colored_polygon(points, Color(0.2, 1.0, 0.8, 0.2)); | 
					
						
							| 
									
										
										
										
											2015-03-09 02:34:56 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		} else if (tool == TOOL_BUCKET) { | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			int tile = get_selected_tile(); | 
					
						
							|  |  |  | 			_draw_fill_preview(tile, over_tile, flip_h, flip_v, transpose, xform); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			int st = get_selected_tile(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			if (st == TileMap::INVALID_CELL) | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 			_draw_cell(st, over_tile, flip_h, flip_v, transpose, xform); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TileMapEditor::edit(Node *p_tile_map) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	search_box->set_text(""); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (!canvas_item_editor) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		canvas_item_editor = CanvasItemEditor::get_singleton()->get_viewport_control(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-19 16:46:52 -03:00
										 |  |  | 	if (node) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		node->disconnect("settings_changed", this, "_tileset_settings_changed"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (p_tile_map) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		node = p_tile_map->cast_to<TileMap>(); | 
					
						
							|  |  |  | 		if (!canvas_item_editor->is_connected("draw", this, "_canvas_draw")) | 
					
						
							|  |  |  | 			canvas_item_editor->connect("draw", this, "_canvas_draw"); | 
					
						
							|  |  |  | 		if (!canvas_item_editor->is_connected("mouse_entered", this, "_canvas_mouse_enter")) | 
					
						
							|  |  |  | 			canvas_item_editor->connect("mouse_entered", this, "_canvas_mouse_enter"); | 
					
						
							|  |  |  | 		if (!canvas_item_editor->is_connected("mouse_exited", this, "_canvas_mouse_exit")) | 
					
						
							|  |  |  | 			canvas_item_editor->connect("mouse_exited", this, "_canvas_mouse_exit"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		_update_palette(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		node = NULL; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		if (canvas_item_editor->is_connected("draw", this, "_canvas_draw")) | 
					
						
							|  |  |  | 			canvas_item_editor->disconnect("draw", this, "_canvas_draw"); | 
					
						
							|  |  |  | 		if (canvas_item_editor->is_connected("mouse_entered", this, "_canvas_mouse_enter")) | 
					
						
							|  |  |  | 			canvas_item_editor->disconnect("mouse_entered", this, "_canvas_mouse_enter"); | 
					
						
							|  |  |  | 		if (canvas_item_editor->is_connected("mouse_exited", this, "_canvas_mouse_exit")) | 
					
						
							|  |  |  | 			canvas_item_editor->disconnect("mouse_exited", this, "_canvas_mouse_exit"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		_update_palette(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-19 16:46:52 -03:00
										 |  |  | 	if (node) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		node->connect("settings_changed", this, "_tileset_settings_changed"); | 
					
						
							| 
									
										
										
										
											2014-04-19 16:46:52 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 	_clear_bucket_cache(); | 
					
						
							| 
									
										
										
										
											2014-04-19 16:46:52 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TileMapEditor::_tileset_settings_changed() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-19 16:46:52 -03:00
										 |  |  | 	_update_palette(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-19 16:46:52 -03:00
										 |  |  | 	if (canvas_item_editor) | 
					
						
							|  |  |  | 		canvas_item_editor->update(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-24 19:18:56 +02:00
										 |  |  | void TileMapEditor::_icon_size_changed(float p_value) { | 
					
						
							|  |  |  | 	if (node) { | 
					
						
							| 
									
										
										
										
											2016-05-27 18:54:46 +02:00
										 |  |  | 		palette->set_icon_scale(p_value); | 
					
						
							| 
									
										
										
										
											2016-05-24 19:18:56 +02:00
										 |  |  | 		_update_palette(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void TileMapEditor::_bind_methods() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_text_entered"), &TileMapEditor::_text_entered); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_text_changed"), &TileMapEditor::_text_changed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_sbox_input"), &TileMapEditor::_sbox_input); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_menu_option"), &TileMapEditor::_menu_option); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_canvas_draw"), &TileMapEditor::_canvas_draw); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_canvas_mouse_enter"), &TileMapEditor::_canvas_mouse_enter); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_canvas_mouse_exit"), &TileMapEditor::_canvas_mouse_exit); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_tileset_settings_changed"), &TileMapEditor::_tileset_settings_changed); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_update_transform_buttons"), &TileMapEditor::_update_transform_buttons); | 
					
						
							| 
									
										
										
										
											2017-02-13 12:47:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_fill_points"), &TileMapEditor::_fill_points); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_erase_points"), &TileMapEditor::_erase_points); | 
					
						
							| 
									
										
										
										
											2017-02-13 12:47:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_icon_size_changed"), &TileMapEditor::_icon_size_changed); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i &p_pos) { | 
					
						
							| 
									
										
										
										
											2015-01-17 16:48:21 +10:00
										 |  |  | 	CellOp op; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	op.idx = node->get_cell(p_pos.x, p_pos.y); | 
					
						
							|  |  |  | 	if (op.idx != TileMap::INVALID_CELL) { | 
					
						
							|  |  |  | 		if (node->is_cell_x_flipped(p_pos.x, p_pos.y)) | 
					
						
							|  |  |  | 			op.xf = true; | 
					
						
							|  |  |  | 		if (node->is_cell_y_flipped(p_pos.x, p_pos.y)) | 
					
						
							|  |  |  | 			op.yf = true; | 
					
						
							|  |  |  | 		if (node->is_cell_transposed(p_pos.x, p_pos.y)) | 
					
						
							|  |  |  | 			op.tr = true; | 
					
						
							| 
									
										
										
										
											2015-01-17 16:48:21 +10:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return op; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-02 21:27:48 +10:00
										 |  |  | void TileMapEditor::_update_transform_buttons(Object *p_button) { | 
					
						
							| 
									
										
										
										
											2015-02-03 19:51:21 +10:00
										 |  |  | 	//ERR_FAIL_NULL(p_button);
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ToolButton *b = p_button->cast_to<ToolButton>(); | 
					
						
							| 
									
										
										
										
											2015-02-03 19:51:21 +10:00
										 |  |  | 	//ERR_FAIL_COND(!b);
 | 
					
						
							| 
									
										
										
										
											2015-06-22 10:05:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-02 22:28:10 +10:00
										 |  |  | 	if (b == rotate_0) { | 
					
						
							|  |  |  | 		mirror_x->set_pressed(false); | 
					
						
							|  |  |  | 		mirror_y->set_pressed(false); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		transp->set_pressed(false); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	} else if (b == rotate_90) { | 
					
						
							| 
									
										
										
										
											2015-02-13 10:56:53 +10:00
										 |  |  | 		mirror_x->set_pressed(true); | 
					
						
							|  |  |  | 		mirror_y->set_pressed(false); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		transp->set_pressed(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	} else if (b == rotate_180) { | 
					
						
							| 
									
										
										
										
											2015-02-02 22:28:10 +10:00
										 |  |  | 		mirror_x->set_pressed(true); | 
					
						
							|  |  |  | 		mirror_y->set_pressed(true); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		transp->set_pressed(false); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	} else if (b == rotate_270) { | 
					
						
							| 
									
										
										
										
											2015-02-13 10:56:53 +10:00
										 |  |  | 		mirror_x->set_pressed(false); | 
					
						
							|  |  |  | 		mirror_y->set_pressed(true); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		transp->set_pressed(true); | 
					
						
							| 
									
										
										
										
											2015-02-02 22:28:10 +10:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-06-22 10:05:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	flip_h = mirror_x->is_pressed(); | 
					
						
							|  |  |  | 	flip_v = mirror_y->is_pressed(); | 
					
						
							|  |  |  | 	transpose = transp->is_pressed(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	rotate_0->set_pressed(!flip_h && !flip_v && !transpose); | 
					
						
							|  |  |  | 	rotate_90->set_pressed(flip_h && !flip_v && transpose); | 
					
						
							|  |  |  | 	rotate_180->set_pressed(flip_h && flip_v && !transpose); | 
					
						
							|  |  |  | 	rotate_270->set_pressed(!flip_h && flip_v && transpose); | 
					
						
							| 
									
										
										
										
											2015-02-02 21:27:48 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | TileMapEditor::TileMapEditor(EditorNode *p_editor) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	node = NULL; | 
					
						
							|  |  |  | 	canvas_item_editor = NULL; | 
					
						
							|  |  |  | 	editor = p_editor; | 
					
						
							|  |  |  | 	undo_redo = editor->get_undo_redo(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	tool = TOOL_NONE; | 
					
						
							|  |  |  | 	selection_active = false; | 
					
						
							|  |  |  | 	mouse_over = false; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	flip_h = false; | 
					
						
							|  |  |  | 	flip_v = false; | 
					
						
							|  |  |  | 	transpose = false; | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | 	bucket_cache_tile = -1; | 
					
						
							|  |  |  | 	bucket_cache_visited = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-11 18:40:11 -05:00
										 |  |  | 	ED_SHORTCUT("tile_map_editor/erase_selection", TTR("Erase selection"), KEY_DELETE); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ED_SHORTCUT("tile_map_editor/find_tile", TTR("Find tile"), KEY_MASK_CMD + KEY_F); | 
					
						
							| 
									
										
										
										
											2016-06-12 17:19:18 -05:00
										 |  |  | 	ED_SHORTCUT("tile_map_editor/transpose", TTR("Transpose")); | 
					
						
							|  |  |  | 	ED_SHORTCUT("tile_map_editor/mirror_x", TTR("Mirror X"), KEY_A); | 
					
						
							|  |  |  | 	ED_SHORTCUT("tile_map_editor/mirror_y", TTR("Mirror Y"), KEY_S); | 
					
						
							| 
									
										
										
										
											2016-06-11 18:40:11 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-08 22:46:26 -03:00
										 |  |  | 	HBoxContainer *tool_hb1 = memnew(HBoxContainer); | 
					
						
							|  |  |  | 	add_child(tool_hb1); | 
					
						
							|  |  |  | 	HBoxContainer *tool_hb2 = memnew(HBoxContainer); | 
					
						
							|  |  |  | 	add_child(tool_hb2); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	search_box = memnew(LineEdit); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	search_box->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	search_box->connect("text_entered", this, "_text_entered"); | 
					
						
							|  |  |  | 	search_box->connect("text_changed", this, "_text_changed"); | 
					
						
							| 
									
										
										
										
											2017-01-08 16:28:12 -03:00
										 |  |  | 	search_box->connect("gui_input", this, "_sbox_input"); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	add_child(search_box); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	size_slider = memnew(HSlider); | 
					
						
							| 
									
										
										
										
											2016-05-24 19:18:56 +02:00
										 |  |  | 	size_slider->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	size_slider->set_min(0.1f); | 
					
						
							|  |  |  | 	size_slider->set_max(4.0f); | 
					
						
							|  |  |  | 	size_slider->set_step(0.1f); | 
					
						
							| 
									
										
										
										
											2017-01-04 01:16:14 -03:00
										 |  |  | 	size_slider->set_value(1.0f); | 
					
						
							| 
									
										
										
										
											2016-05-24 19:18:56 +02:00
										 |  |  | 	size_slider->connect("value_changed", this, "_icon_size_changed"); | 
					
						
							|  |  |  | 	add_child(size_slider); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 19:41:36 -03:00
										 |  |  | 	int mw = EDITOR_DEF("editors/tile_map/palette_min_width", 80); | 
					
						
							| 
									
										
										
										
											2015-06-22 10:05:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-29 08:37:25 +10:00
										 |  |  | 	// Add tile palette
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	palette = memnew(ItemList); | 
					
						
							| 
									
										
										
										
											2014-12-29 08:37:25 +10:00
										 |  |  | 	palette->set_v_size_flags(SIZE_EXPAND_FILL); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	palette->set_custom_minimum_size(Size2(mw, 0)); | 
					
						
							| 
									
										
										
										
											2016-08-15 16:48:04 -03:00
										 |  |  | 	palette->set_max_columns(0); | 
					
						
							|  |  |  | 	palette->set_icon_mode(ItemList::ICON_MODE_TOP); | 
					
						
							|  |  |  | 	palette->set_max_text_lines(2); | 
					
						
							| 
									
										
										
										
											2014-12-29 08:37:25 +10:00
										 |  |  | 	add_child(palette); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-29 08:37:25 +10:00
										 |  |  | 	// Add menu items
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	toolbar = memnew(HBoxContainer); | 
					
						
							| 
									
										
										
										
											2016-03-15 14:32:28 -03:00
										 |  |  | 	toolbar->set_h_size_flags(SIZE_EXPAND_FILL); | 
					
						
							|  |  |  | 	toolbar->set_alignment(BoxContainer::ALIGN_END); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	CanvasItemEditor::get_singleton()->add_control_to_menu_panel(toolbar); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-16 21:10:44 -03:00
										 |  |  | 	// Tile position
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	tile_info = memnew(Label); | 
					
						
							| 
									
										
										
										
											2016-06-16 21:10:44 -03:00
										 |  |  | 	toolbar->add_child(tile_info); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	options = memnew(MenuButton); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	options->set_text("Tile Map"); | 
					
						
							|  |  |  | 	options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("TileMap", "EditorIcons")); | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 	options->set_process_unhandled_key_input(false); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	PopupMenu *p = options->get_popup(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-21 01:18:35 +02:00
										 |  |  | 	p->add_item(TTR("Bucket"), OPTION_BUCKET); | 
					
						
							| 
									
										
										
										
											2016-03-12 10:34:34 -03:00
										 |  |  | 	p->add_separator(); | 
					
						
							| 
									
										
										
										
											2016-05-21 01:18:35 +02:00
										 |  |  | 	p->add_item(TTR("Pick Tile"), OPTION_PICK_TILE, KEY_CONTROL); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	p->add_separator(); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	p->add_shortcut(ED_SHORTCUT("tile_map_editor/select", TTR("Select"), KEY_MASK_CMD + KEY_B), OPTION_SELECT); | 
					
						
							|  |  |  | 	p->add_shortcut(ED_SHORTCUT("tile_map_editor/duplicate_selection", TTR("Duplicate Selection"), KEY_MASK_CMD + KEY_D), OPTION_DUPLICATE); | 
					
						
							| 
									
										
										
										
											2016-06-12 17:19:18 -05:00
										 |  |  | 	p->add_shortcut(ED_GET_SHORTCUT("tile_map_editor/erase_selection"), OPTION_ERASE_SELECTION); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-08 18:18:54 -03:00
										 |  |  | 	p->connect("id_pressed", this, "_menu_option"); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	toolbar->add_child(options); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	toolbar->add_child(memnew(VSeparator)); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	transp = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	transp->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	transp->set_tooltip(TTR("Transpose") + " (" + ED_GET_SHORTCUT("tile_map_editor/transpose")->get_as_text() + ")"); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	transp->set_focus_mode(FOCUS_NONE); | 
					
						
							|  |  |  | 	transp->connect("pressed", this, "_update_transform_buttons", make_binds(transp)); | 
					
						
							| 
									
										
										
										
											2017-08-08 22:46:26 -03:00
										 |  |  | 	tool_hb1->add_child(transp); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	mirror_x = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	mirror_x->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	mirror_x->set_tooltip(TTR("Mirror X") + " (" + ED_GET_SHORTCUT("tile_map_editor/mirror_x")->get_as_text() + ")"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	mirror_x->set_focus_mode(FOCUS_NONE); | 
					
						
							| 
									
										
										
										
											2015-02-02 21:27:48 +10:00
										 |  |  | 	mirror_x->connect("pressed", this, "_update_transform_buttons", make_binds(mirror_x)); | 
					
						
							| 
									
										
										
										
											2017-08-08 22:46:26 -03:00
										 |  |  | 	tool_hb1->add_child(mirror_x); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	mirror_y = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	mirror_y->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	mirror_y->set_tooltip(TTR("Mirror Y") + " (" + ED_GET_SHORTCUT("tile_map_editor/mirror_y")->get_as_text() + ")"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	mirror_y->set_focus_mode(FOCUS_NONE); | 
					
						
							| 
									
										
										
										
											2015-02-02 21:27:48 +10:00
										 |  |  | 	mirror_y->connect("pressed", this, "_update_transform_buttons", make_binds(mirror_y)); | 
					
						
							| 
									
										
										
										
											2017-08-08 22:46:26 -03:00
										 |  |  | 	tool_hb1->add_child(mirror_y); | 
					
						
							| 
									
										
										
										
											2016-03-11 16:30:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	rotate_0 = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2015-01-19 23:07:25 +10:00
										 |  |  | 	rotate_0->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	rotate_0->set_tooltip(TTR("Rotate 0 degrees")); | 
					
						
							| 
									
										
										
										
											2015-01-19 23:07:25 +10:00
										 |  |  | 	rotate_0->set_focus_mode(FOCUS_NONE); | 
					
						
							| 
									
										
										
										
											2015-02-02 21:27:48 +10:00
										 |  |  | 	rotate_0->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_0)); | 
					
						
							| 
									
										
										
										
											2017-08-08 22:46:26 -03:00
										 |  |  | 	tool_hb2->add_child(rotate_0); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	rotate_90 = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2015-01-19 23:07:25 +10:00
										 |  |  | 	rotate_90->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	rotate_90->set_tooltip(TTR("Rotate 90 degrees")); | 
					
						
							| 
									
										
										
										
											2015-01-19 23:07:25 +10:00
										 |  |  | 	rotate_90->set_focus_mode(FOCUS_NONE); | 
					
						
							| 
									
										
										
										
											2015-02-02 21:27:48 +10:00
										 |  |  | 	rotate_90->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_90)); | 
					
						
							| 
									
										
										
										
											2017-08-08 22:46:26 -03:00
										 |  |  | 	tool_hb2->add_child(rotate_90); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	rotate_180 = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2015-01-19 23:07:25 +10:00
										 |  |  | 	rotate_180->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	rotate_180->set_tooltip(TTR("Rotate 180 degrees")); | 
					
						
							| 
									
										
										
										
											2015-01-19 23:07:25 +10:00
										 |  |  | 	rotate_180->set_focus_mode(FOCUS_NONE); | 
					
						
							| 
									
										
										
										
											2015-02-02 21:27:48 +10:00
										 |  |  | 	rotate_180->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_180)); | 
					
						
							| 
									
										
										
										
											2017-08-08 22:46:26 -03:00
										 |  |  | 	tool_hb2->add_child(rotate_180); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	rotate_270 = memnew(ToolButton); | 
					
						
							| 
									
										
										
										
											2015-01-19 23:07:25 +10:00
										 |  |  | 	rotate_270->set_toggle_mode(true); | 
					
						
							| 
									
										
										
										
											2016-05-03 22:25:37 -03:00
										 |  |  | 	rotate_270->set_tooltip(TTR("Rotate 270 degrees")); | 
					
						
							| 
									
										
										
										
											2015-01-19 23:07:25 +10:00
										 |  |  | 	rotate_270->set_focus_mode(FOCUS_NONE); | 
					
						
							| 
									
										
										
										
											2015-02-02 21:27:48 +10:00
										 |  |  | 	rotate_270->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_270)); | 
					
						
							| 
									
										
										
										
											2017-08-08 22:46:26 -03:00
										 |  |  | 	tool_hb2->add_child(rotate_270); | 
					
						
							| 
									
										
										
										
											2015-06-22 10:05:03 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-02 22:28:10 +10:00
										 |  |  | 	rotate_0->set_pressed(true); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-31 17:42:05 +01:00
										 |  |  | TileMapEditor::~TileMapEditor() { | 
					
						
							|  |  |  | 	_clear_bucket_cache(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | ///////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | void TileMapEditorPlugin::edit(Object *p_object) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tile_map_editor->edit(p_object->cast_to<Node>()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool TileMapEditorPlugin::handles(Object *p_object) const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-02 23:03:46 -03:00
										 |  |  | 	return p_object->is_class("TileMap"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TileMapEditorPlugin::make_visible(bool p_visible) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p_visible) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		tile_map_editor->show(); | 
					
						
							|  |  |  | 		tile_map_editor->get_toolbar()->show(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		tile_map_editor->hide(); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 		tile_map_editor->get_toolbar()->hide(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		tile_map_editor->edit(NULL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TileMapEditorPlugin::TileMapEditorPlugin(EditorNode *p_node) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	EDITOR_DEF("editors/tile_map/preview_size", 64); | 
					
						
							|  |  |  | 	EDITOR_DEF("editors/tile_map/palette_item_hseparation", 8); | 
					
						
							| 
									
										
										
										
											2017-01-05 19:41:36 -03:00
										 |  |  | 	EDITOR_DEF("editors/tile_map/show_tile_names", true); | 
					
						
							| 
									
										
										
										
											2017-03-27 02:50:51 +02:00
										 |  |  | 	EDITOR_DEF("editors/tile_map/show_tile_ids", false); | 
					
						
							|  |  |  | 	EDITOR_DEF("editors/tile_map/sort_tiles_by_name", true); | 
					
						
							| 
									
										
										
										
											2017-01-05 19:41:36 -03:00
										 |  |  | 	EDITOR_DEF("editors/tile_map/bucket_fill_preview", true); | 
					
						
							| 
									
										
										
										
											2016-08-15 16:48:04 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	tile_map_editor = memnew(TileMapEditor(p_node)); | 
					
						
							| 
									
										
										
										
											2016-03-10 15:10:31 -03:00
										 |  |  | 	add_control_to_container(CONTAINER_CANVAS_EDITOR_SIDE, tile_map_editor); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	tile_map_editor->hide(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | TileMapEditorPlugin::~TileMapEditorPlugin() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } |