moving_object.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // SuperTux
  2. // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include "supertux/moving_object.hpp"
  17. #include "editor/resize_marker.hpp"
  18. #include "supertux/sector.hpp"
  19. #include "util/reader_mapping.hpp"
  20. #include "util/writer.hpp"
  21. MovingObject::MovingObject() :
  22. m_col(COLGROUP_MOVING, *this),
  23. m_parent_dispenser()
  24. {
  25. }
  26. MovingObject::MovingObject(const ReaderMapping& reader) :
  27. GameObject(reader),
  28. m_col(COLGROUP_MOVING, *this),
  29. m_parent_dispenser()
  30. {
  31. float height, width;
  32. if (reader.get("width", width))
  33. m_col.m_bbox.set_width(width);
  34. if (reader.get("height", height))
  35. m_col.m_bbox.set_height(height);
  36. reader.get("x", m_col.m_bbox.get_left());
  37. reader.get("y", m_col.m_bbox.get_top());
  38. }
  39. MovingObject::~MovingObject()
  40. {
  41. }
  42. ObjectSettings
  43. MovingObject::get_settings()
  44. {
  45. ObjectSettings result = GameObject::get_settings();
  46. if (m_parent_dispenser)
  47. {
  48. result.remove("name");
  49. return result;
  50. }
  51. if (has_variable_size())
  52. result.add_rectf(_("Region"), &m_col.m_bbox, "region", OPTION_HIDDEN);
  53. result.add_float(_("X"), &m_col.m_bbox.get_left(), "x", {}, OPTION_HIDDEN);
  54. result.add_float(_("Y"), &m_col.m_bbox.get_top(), "y", {}, OPTION_HIDDEN);
  55. return result;
  56. }
  57. void
  58. MovingObject::set_parent_dispenser(Dispenser* dispenser)
  59. {
  60. m_parent_dispenser = dispenser;
  61. if (dispenser)
  62. {
  63. m_name.clear();
  64. }
  65. }
  66. void
  67. MovingObject::editor_select()
  68. {
  69. Sector::get().add<ResizeMarker>(this, ResizeMarker::Side::LEFT_UP, ResizeMarker::Side::LEFT_UP);
  70. Sector::get().add<ResizeMarker>(this, ResizeMarker::Side::LEFT_UP, ResizeMarker::Side::NONE);
  71. Sector::get().add<ResizeMarker>(this, ResizeMarker::Side::LEFT_UP, ResizeMarker::Side::RIGHT_DOWN);
  72. Sector::get().add<ResizeMarker>(this, ResizeMarker::Side::NONE, ResizeMarker::Side::LEFT_UP);
  73. Sector::get().add<ResizeMarker>(this, ResizeMarker::Side::NONE, ResizeMarker::Side::RIGHT_DOWN);
  74. Sector::get().add<ResizeMarker>(this, ResizeMarker::Side::RIGHT_DOWN, ResizeMarker::Side::LEFT_UP);
  75. Sector::get().add<ResizeMarker>(this, ResizeMarker::Side::RIGHT_DOWN, ResizeMarker::Side::NONE);
  76. Sector::get().add<ResizeMarker>(this, ResizeMarker::Side::RIGHT_DOWN, ResizeMarker::Side::RIGHT_DOWN);
  77. }
  78. void
  79. MovingObject::on_flip(float height)
  80. {
  81. Vector pos = get_pos();
  82. pos.y = height - pos.y - get_bbox().get_height();
  83. set_pos(pos);
  84. }
  85. /* EOF */