Skip to content

Commit 86789c7

Browse files
committed
Add modulate (color) to TileSet tiles
1 parent c05ff05 commit 86789c7

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

scene/2d/tile_map.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,11 @@ void TileMap::_update_dirty_quadrants() {
457457
}
458458

459459

460+
Color modulate = tile_set->tile_get_modulate(c.id);
460461
if (r==Rect2()) {
461-
tex->draw_rect(canvas_item,rect,false,Color(1,1,1),c.transpose);
462+
tex->draw_rect(canvas_item,rect,false,modulate,c.transpose);
462463
} else {
463-
tex->draw_rect_region(canvas_item,rect,r,Color(1,1,1),c.transpose);
464+
tex->draw_rect_region(canvas_item,rect,r,modulate,c.transpose);
464465
}
465466

466467
Vector< Ref<Shape2D> > shapes = tile_set->tile_get_shapes(c.id);

scene/resources/tile_set.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ bool TileSet::_set(const StringName& p_name, const Variant& p_value) {
4848
tile_set_texture_offset(id,p_value);
4949
else if (what=="material")
5050
tile_set_material(id,p_value);
51+
else if (what=="modulate")
52+
tile_set_modulate(id,p_value);
5153
else if (what=="shape_offset")
5254
tile_set_shape_offset(id,p_value);
5355
else if (what=="region")
@@ -91,6 +93,8 @@ bool TileSet::_get(const StringName& p_name,Variant &r_ret) const{
9193
r_ret=tile_get_texture_offset(id);
9294
else if (what=="material")
9395
r_ret=tile_get_material(id);
96+
else if (what=="modulate")
97+
r_ret=tile_get_modulate(id);
9498
else if (what=="shape_offset")
9599
r_ret=tile_get_shape_offset(id);
96100
else if (what=="region")
@@ -124,6 +128,7 @@ void TileSet::_get_property_list( List<PropertyInfo> *p_list) const{
124128
p_list->push_back(PropertyInfo(Variant::OBJECT,pre+"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"));
125129
p_list->push_back(PropertyInfo(Variant::VECTOR2,pre+"tex_offset"));
126130
p_list->push_back(PropertyInfo(Variant::OBJECT,pre+"material",PROPERTY_HINT_RESOURCE_TYPE,"CanvasItemMaterial"));
131+
p_list->push_back(PropertyInfo(Variant::COLOR,pre+"modulate"));
127132
p_list->push_back(PropertyInfo(Variant::RECT2,pre+"region"));
128133
p_list->push_back(PropertyInfo(Variant::VECTOR2,pre+"occluder_offset"));
129134
p_list->push_back(PropertyInfo(Variant::OBJECT,pre+"occluder",PROPERTY_HINT_RESOURCE_TYPE,"OccluderPolygon2D"));
@@ -175,6 +180,20 @@ Ref<CanvasItemMaterial> TileSet::tile_get_material(int p_id) const{
175180
}
176181

177182

183+
void TileSet::tile_set_modulate(int p_id,const Color &p_modulate) {
184+
185+
ERR_FAIL_COND(!tile_map.has(p_id));
186+
tile_map[p_id].modulate=p_modulate;
187+
emit_changed();
188+
189+
}
190+
191+
Color TileSet::tile_get_modulate(int p_id) const{
192+
193+
ERR_FAIL_COND_V(!tile_map.has(p_id),Color(1,1,1));
194+
return tile_map[p_id].modulate;
195+
}
196+
178197
void TileSet::tile_set_texture_offset(int p_id,const Vector2 &p_offset) {
179198

180199
ERR_FAIL_COND(!tile_map.has(p_id));

scene/resources/tile_set.h

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class TileSet : public Resource {
5252
Vector2 navigation_polygon_offset;
5353
Ref<NavigationPolygon> navigation_polygon;
5454
Ref<CanvasItemMaterial> material;
55+
Color modulate;
56+
57+
// Default modulate for back-compat
58+
explicit Data() : modulate(1,1,1) {}
5559
};
5660

5761
Map<int,Data> tile_map;
@@ -94,6 +98,9 @@ class TileSet : public Resource {
9498
void tile_set_material(int p_id,const Ref<CanvasItemMaterial> &p_material);
9599
Ref<CanvasItemMaterial> tile_get_material(int p_id) const;
96100

101+
void tile_set_modulate(int p_id,const Color &p_color);
102+
Color tile_get_modulate(int p_id) const;
103+
97104
void tile_set_occluder_offset(int p_id,const Vector2& p_offset);
98105
Vector2 tile_get_occluder_offset(int p_id) const;
99106

tools/editor/plugins/tile_set_editor_plugin.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ void TileSetEditor::_import_scene(Node *scene, Ref<TileSet> p_library, bool p_me
7676
p_library->tile_set_texture(id,texture);
7777
p_library->tile_set_material(id,material);
7878

79+
p_library->tile_set_modulate(id,mi->get_modulate());
80+
7981
Vector2 phys_offset;
8082
Size2 s;
8183

0 commit comments

Comments
 (0)