26
26
#include " supertux/debug.hpp"
27
27
#include " supertux/gameconfig.hpp"
28
28
#include " supertux/globals.hpp"
29
+ #include " supertux/level.hpp"
29
30
#include " supertux/resources.hpp"
30
31
#include " supertux/sector.hpp"
31
32
#include " supertux/tile.hpp"
@@ -52,7 +53,7 @@ TileMap::TileMap(const TileSet *new_tileset) :
52
53
m_width(0 ),
53
54
m_height(0 ),
54
55
m_z_pos(0 ),
55
- m_offset(Vector(0 , 32 )),
56
+ m_offset(Vector(0 , 0 )),
56
57
m_movement(0 , 0 ),
57
58
m_objects_hit_bottom(),
58
59
m_ground_movement_manager(nullptr ),
@@ -86,7 +87,7 @@ TileMap::TileMap(const TileSet *tileset_, const ReaderMapping& reader) :
86
87
m_width(-1 ),
87
88
m_height(-1 ),
88
89
m_z_pos(0 ),
89
- m_offset(Vector(0 , 32 )),
90
+ m_offset(Vector(0 , 0 )),
90
91
m_movement(Vector(0 , 0 )),
91
92
m_objects_hit_bottom(),
92
93
m_ground_movement_manager(nullptr ),
@@ -344,7 +345,7 @@ TileMap::after_editor_set()
344
345
}
345
346
} else {
346
347
if (m_add_path) {
347
- init_path_pos (m_offset );
348
+ init_path_pos (get_offset () );
348
349
}
349
350
}
350
351
@@ -620,15 +621,27 @@ TileMap::resize(int new_width, int new_height, int fill_id,
620
621
apply_offset_y (fill_id, yoffset);
621
622
}
622
623
623
- void TileMap::resize (const Size& newsize, const Size& resize_offset) {
624
+ void
625
+ TileMap::resize (const Size& newsize, const Size& resize_offset) {
624
626
resize (newsize.width , newsize.height , 0 , resize_offset.width , resize_offset.height );
625
627
}
626
628
629
+ Vector
630
+ TileMap::get_offset () const
631
+ {
632
+ // Apply custom offset for tilemap to fit buttons at the top of the editor.
633
+ // This extra offset isn't saved.
634
+ if (Editor::is_active () && !Level::current ()->is_saving_in_progress ())
635
+ return m_offset + Vector (0 , 32 );
636
+
637
+ return m_offset;
638
+ }
639
+
627
640
Rect
628
641
TileMap::get_tiles_overlapping (const Rectf &rect) const
629
642
{
630
643
Rectf rect2 = rect;
631
- rect2.move (-m_offset );
644
+ rect2.move (-get_offset () );
632
645
633
646
int t_left = std::max (0 , int (floorf (rect2.get_left () / 32 )));
634
647
int t_right = std::min (m_width , int (ceilf (rect2.get_right () / 32 )));
@@ -681,7 +694,7 @@ TileMap::get_tile_id(const Vector& pos) const
681
694
bool
682
695
TileMap::is_outside_bounds (const Vector& pos) const
683
696
{
684
- auto pos_ = (pos - m_offset ) / 32 .0f ;
697
+ auto pos_ = (pos - get_offset () ) / 32 .0f ;
685
698
float width = static_cast <float >(m_width);
686
699
float height = static_cast <float >(m_height);
687
700
return pos_.x < 0 || pos_.x >= width || pos_.y < 0 || pos_.y >= height;
@@ -697,7 +710,7 @@ TileMap::get_tile(int x, int y) const
697
710
uint32_t
698
711
TileMap::get_tile_id_at (const Vector& pos) const
699
712
{
700
- Vector xy = (pos - m_offset ) / 32 .0f ;
713
+ Vector xy = (pos - get_offset () ) / 32 .0f ;
701
714
return get_tile_id (static_cast <int >(xy.x ), static_cast <int >(xy.y ));
702
715
}
703
716
@@ -732,7 +745,7 @@ TileMap::change(int idx, uint32_t newtile)
732
745
void
733
746
TileMap::change_at (const Vector& pos, uint32_t newtile)
734
747
{
735
- Vector xy = (pos - m_offset ) / 32 .0f ;
748
+ Vector xy = (pos - get_offset () ) / 32 .0f ;
736
749
change (int (xy.x ), int (xy.y ), newtile);
737
750
}
738
751
@@ -964,11 +977,11 @@ void
964
977
TileMap::move_by (const Vector& shift)
965
978
{
966
979
if (!get_path ()) {
967
- init_path_pos (m_offset );
980
+ init_path_pos (get_offset () );
968
981
m_add_path = true ;
969
982
}
970
983
get_path ()->move_by (shift);
971
- m_offset += shift;
984
+ set_offset ( get_offset () + shift) ;
972
985
}
973
986
974
987
void
0 commit comments