27
27
#include " supertux/debug.hpp"
28
28
#include " supertux/gameconfig.hpp"
29
29
#include " supertux/globals.hpp"
30
+ #include " supertux/level.hpp"
30
31
#include " supertux/resources.hpp"
31
32
#include " supertux/sector.hpp"
32
33
#include " supertux/tile.hpp"
@@ -53,7 +54,7 @@ TileMap::TileMap(const TileSet *new_tileset) :
53
54
m_width(0 ),
54
55
m_height(0 ),
55
56
m_z_pos(0 ),
56
- m_offset(Vector(0 , 32 )),
57
+ m_offset(Vector(0 , 0 )),
57
58
m_movement(0 , 0 ),
58
59
m_objects_hit_bottom(),
59
60
m_ground_movement_manager(nullptr ),
@@ -87,7 +88,7 @@ TileMap::TileMap(const TileSet *tileset_, const ReaderMapping& reader) :
87
88
m_width(-1 ),
88
89
m_height(-1 ),
89
90
m_z_pos(0 ),
90
- m_offset(Vector(0 , 32 )),
91
+ m_offset(Vector(0 , 0 )),
91
92
m_movement(Vector(0 , 0 )),
92
93
m_objects_hit_bottom(),
93
94
m_ground_movement_manager(nullptr ),
@@ -393,7 +394,7 @@ TileMap::after_editor_set()
393
394
}
394
395
} else {
395
396
if (m_add_path) {
396
- init_path_pos (m_offset );
397
+ init_path_pos (get_offset () );
397
398
}
398
399
}
399
400
@@ -677,15 +678,27 @@ TileMap::resize(int new_width, int new_height, int fill_id,
677
678
apply_offset_y (fill_id, yoffset);
678
679
}
679
680
680
- void TileMap::resize (const Size& newsize, const Size& resize_offset) {
681
+ void
682
+ TileMap::resize (const Size& newsize, const Size& resize_offset) {
681
683
resize (newsize.width , newsize.height , 0 , resize_offset.width , resize_offset.height );
682
684
}
683
685
686
+ Vector
687
+ TileMap::get_offset () const
688
+ {
689
+ // Apply custom offset for tilemap to fit buttons at the top of the editor.
690
+ // This extra offset isn't saved.
691
+ if (Editor::is_active () && !Level::current ()->is_saving_in_progress ())
692
+ return m_offset + Vector (0 , 32 );
693
+
694
+ return m_offset;
695
+ }
696
+
684
697
Rect
685
698
TileMap::get_tiles_overlapping (const Rectf &rect) const
686
699
{
687
700
Rectf rect2 = rect;
688
- rect2.move (-m_offset );
701
+ rect2.move (-get_offset () );
689
702
690
703
int t_left = std::max (0 , int (floorf (rect2.get_left () / 32 )));
691
704
int t_right = std::min (m_width , int (ceilf (rect2.get_right () / 32 )));
@@ -738,7 +751,7 @@ TileMap::get_tile_id(const Vector& pos) const
738
751
bool
739
752
TileMap::is_outside_bounds (const Vector& pos) const
740
753
{
741
- auto pos_ = (pos - m_offset ) / 32 .0f ;
754
+ auto pos_ = (pos - get_offset () ) / 32 .0f ;
742
755
float width = static_cast <float >(m_width);
743
756
float height = static_cast <float >(m_height);
744
757
return pos_.x < 0 || pos_.x >= width || pos_.y < 0 || pos_.y >= height;
@@ -754,7 +767,7 @@ TileMap::get_tile(int x, int y) const
754
767
uint32_t
755
768
TileMap::get_tile_id_at (const Vector& pos) const
756
769
{
757
- Vector xy = (pos - m_offset ) / 32 .0f ;
770
+ Vector xy = (pos - get_offset () ) / 32 .0f ;
758
771
return get_tile_id (static_cast <int >(xy.x ), static_cast <int >(xy.y ));
759
772
}
760
773
@@ -789,7 +802,7 @@ TileMap::change(int idx, uint32_t newtile)
789
802
void
790
803
TileMap::change_at (const Vector& pos, uint32_t newtile)
791
804
{
792
- Vector xy = (pos - m_offset ) / 32 .0f ;
805
+ Vector xy = (pos - get_offset () ) / 32 .0f ;
793
806
change (int (xy.x ), int (xy.y ), newtile);
794
807
}
795
808
@@ -1021,11 +1034,11 @@ void
1021
1034
TileMap::move_by (const Vector& shift)
1022
1035
{
1023
1036
if (!get_path ()) {
1024
- init_path_pos (m_offset );
1037
+ init_path_pos (get_offset () );
1025
1038
m_add_path = true ;
1026
1039
}
1027
1040
get_path ()->move_by (shift);
1028
- m_offset += shift;
1041
+ set_offset ( get_offset () + shift) ;
1029
1042
}
1030
1043
1031
1044
void
0 commit comments