summaryrefslogtreecommitdiff
path: root/scene/2d/tile_map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d/tile_map.cpp')
-rw-r--r--scene/2d/tile_map.cpp63
1 files changed, 47 insertions, 16 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 68b026b1b3..b1cc8c226a 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -50,12 +50,12 @@ void TileMap::_notification(int p_what) {
Node2D *c = this;
while (c) {
- navigation = c->cast_to<Navigation2D>();
+ navigation = Object::cast_to<Navigation2D>(c);
if (navigation) {
break;
}
- c = c->get_parent()->cast_to<Node2D>();
+ c = Object::cast_to<Node2D>(c->get_parent());
}
pending_update = true;
@@ -336,6 +336,7 @@ void TileMap::_update_dirty_quadrants() {
if (mat.is_valid())
vs->canvas_item_set_material(canvas_item, mat->get_rid());
vs->canvas_item_set_parent(canvas_item, get_canvas_item());
+ _update_item_material_state(canvas_item);
Transform2D xform;
xform.set_origin(q.pos);
vs->canvas_item_set_transform(canvas_item, xform);
@@ -370,15 +371,13 @@ void TileMap::_update_dirty_quadrants() {
s = tex->get_size();
else {
s = r.size;
- r.position.x += fp_adjust;
- r.position.y += fp_adjust;
- r.size.x -= fp_adjust * 2.0;
- r.size.y -= fp_adjust * 2.0;
}
Rect2 rect;
rect.position = offset.floor();
rect.size = s;
+ rect.size.x += fp_adjust;
+ rect.size.y += fp_adjust;
if (rect.size.y > rect.size.x) {
if ((c.flip_h && (c.flip_v || c.transpose)) || (c.flip_v && !c.transpose))
@@ -782,6 +781,35 @@ void TileMap::_clear_quadrants() {
}
}
+void TileMap::set_material(const Ref<Material> &p_material) {
+
+ CanvasItem::set_material(p_material);
+ _update_all_items_material_state();
+}
+
+void TileMap::set_use_parent_material(bool p_use_parent_material) {
+
+ CanvasItem::set_use_parent_material(p_use_parent_material);
+ _update_all_items_material_state();
+}
+
+void TileMap::_update_all_items_material_state() {
+
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
+
+ Quadrant &q = E->get();
+ for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) {
+
+ _update_item_material_state(E->get());
+ }
+ }
+}
+
+void TileMap::_update_item_material_state(const RID &p_canvas_item) {
+
+ VS::get_singleton()->canvas_item_set_use_parent_material(p_canvas_item, get_use_parent_material() || get_material().is_valid());
+}
+
void TileMap::clear() {
_clear_quadrants();
@@ -1315,15 +1343,18 @@ void TileMap::_bind_methods() {
ADD_SIGNAL(MethodInfo("settings_changed"));
BIND_CONSTANT(INVALID_CELL);
- BIND_CONSTANT(MODE_SQUARE);
- BIND_CONSTANT(MODE_ISOMETRIC);
- BIND_CONSTANT(MODE_CUSTOM);
- BIND_CONSTANT(HALF_OFFSET_X);
- BIND_CONSTANT(HALF_OFFSET_Y);
- BIND_CONSTANT(HALF_OFFSET_DISABLED);
- BIND_CONSTANT(TILE_ORIGIN_TOP_LEFT);
- BIND_CONSTANT(TILE_ORIGIN_CENTER);
- BIND_CONSTANT(TILE_ORIGIN_BOTTOM_LEFT);
+
+ BIND_ENUM_CONSTANT(MODE_SQUARE);
+ BIND_ENUM_CONSTANT(MODE_ISOMETRIC);
+ BIND_ENUM_CONSTANT(MODE_CUSTOM);
+
+ BIND_ENUM_CONSTANT(HALF_OFFSET_X);
+ BIND_ENUM_CONSTANT(HALF_OFFSET_Y);
+ BIND_ENUM_CONSTANT(HALF_OFFSET_DISABLED);
+
+ BIND_ENUM_CONSTANT(TILE_ORIGIN_TOP_LEFT);
+ BIND_ENUM_CONSTANT(TILE_ORIGIN_CENTER);
+ BIND_ENUM_CONSTANT(TILE_ORIGIN_BOTTOM_LEFT);
}
TileMap::TileMap() {