sprite_change.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SuperTux
  2. // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
  3. // 2023 Vankata453
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #include "worldmap/sprite_change.hpp"
  18. #include "util/reader_mapping.hpp"
  19. #include "worldmap/worldmap_sector.hpp"
  20. namespace worldmap {
  21. SpriteChange::SpriteChange(const ReaderMapping& mapping) :
  22. WorldMapObject(mapping, "images/engine/editor/spritechange.png"),
  23. m_change_on_touch(false),
  24. m_stay_action(),
  25. m_stay_group(),
  26. m_in_stay_action(false)
  27. {
  28. mapping.get("change-on-touch", m_change_on_touch);
  29. mapping.get("stay-action", m_stay_action);
  30. mapping.get("initial-stay-action", m_in_stay_action);
  31. mapping.get("stay-group", m_stay_group);
  32. }
  33. SpriteChange::~SpriteChange()
  34. {
  35. }
  36. void
  37. SpriteChange::draw_worldmap(DrawingContext& context)
  38. {
  39. if (m_in_stay_action && !m_stay_action.empty())
  40. {
  41. m_sprite->set_action(m_stay_action);
  42. WorldMapObject::draw_worldmap(context);
  43. }
  44. }
  45. bool
  46. SpriteChange::show_stay_action() const
  47. {
  48. return m_in_stay_action;
  49. }
  50. void
  51. SpriteChange::set_stay_action()
  52. {
  53. m_in_stay_action = true;
  54. }
  55. void
  56. SpriteChange::clear_stay_action(bool propagate)
  57. {
  58. m_in_stay_action = false;
  59. // if we are in a stay_group, also clear all stay actions in this group
  60. if (!m_stay_group.empty() && propagate)
  61. {
  62. for (SpriteChange& sc : WorldMapSector::current()->get_objects_by_type<SpriteChange>())
  63. {
  64. if (sc.m_stay_group != m_stay_group) continue;
  65. sc.m_in_stay_action = false;
  66. }
  67. }
  68. }
  69. SpritePtr
  70. SpriteChange::clone_sprite() const
  71. {
  72. return m_sprite->clone();
  73. }
  74. ObjectSettings
  75. SpriteChange::get_settings()
  76. {
  77. ObjectSettings result = WorldMapObject::get_settings();
  78. result.add_text(_("Stay action"), &m_stay_action, "stay-action");
  79. result.add_bool(_("Initial stay action"), &m_in_stay_action, "initial-stay-action");
  80. result.add_text(_("Stay group"), &m_stay_group, "stay-group");
  81. result.add_bool(_("Change on touch"), &m_change_on_touch, "change-on-touch");
  82. result.reorder({"change-on-touch", "initial-stay-action", "stay-group", "sprite", "x", "y"});
  83. return result;
  84. }
  85. } // namespace worldmap
  86. /* EOF */