sequence_trigger.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "trigger/sequence_trigger.hpp"
  17. #include "editor/editor.hpp"
  18. #include "object/player.hpp"
  19. #include "supertux/debug.hpp"
  20. #include "util/reader_mapping.hpp"
  21. #include "util/writer.hpp"
  22. #include "video/drawing_context.hpp"
  23. SequenceTrigger::SequenceTrigger(const ReaderMapping& reader) :
  24. Trigger(reader),
  25. triggerevent(EVENT_TOUCH),
  26. sequence(SEQ_ENDSEQUENCE),
  27. new_spawnpoint(),
  28. fade_tilemap(),
  29. fade()
  30. {
  31. std::string sequence_name;
  32. if (reader.get("sequence", sequence_name))
  33. sequence = string_to_sequence(sequence_name);
  34. reader.get("new_spawnpoint", new_spawnpoint);
  35. reader.get("fade_tilemap", fade_tilemap);
  36. reader.get("fade", reinterpret_cast<int&>(fade));
  37. }
  38. ObjectSettings
  39. SequenceTrigger::get_settings()
  40. {
  41. ObjectSettings result = Trigger::get_settings();
  42. result.add_enum(_("Sequence"), reinterpret_cast<int*>(&sequence),
  43. {_("end sequence"), _("stop Tux"), _("fireworks")},
  44. {"endsequence", "stoptux", "fireworks"},
  45. std::nullopt, "sequence");
  46. result.add_text(_("New worldmap spawnpoint"), &new_spawnpoint, "new_spawnpoint");
  47. result.add_text(_("Worldmap fade tilemap"), &fade_tilemap, "fade_tilemap");
  48. result.add_string_select(_("Fade"), reinterpret_cast<int*>(&fade),
  49. {_("Fade in"), _("Fade out")},
  50. 0, "fade");
  51. result.reorder({"sequence", "region", "width", "height", "x", "y", "fade"});
  52. return result;
  53. }
  54. void
  55. SequenceTrigger::event(Player& player, EventType type)
  56. {
  57. if (type != triggerevent)
  58. return;
  59. auto data = SequenceData(new_spawnpoint, fade_tilemap, fade);
  60. player.trigger_sequence(sequence, &data);
  61. }
  62. std::string
  63. SequenceTrigger::get_sequence_name() const
  64. {
  65. return sequence_to_string(sequence);
  66. }
  67. void
  68. SequenceTrigger::draw(DrawingContext& context)
  69. {
  70. if (Editor::is_active() || g_debug.show_collision_rects)
  71. context.color().draw_filled_rect(m_col.m_bbox, Color(1.0f, 0.0f, 0.0f, 0.6f),
  72. 0.0f, LAYER_OBJECTS);
  73. }
  74. /* EOF */