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
17#include "trigger/sequence_trigger.hpp"
18
19#include "editor/editor.hpp"
20#include "object/player.hpp"
21#include "supertux/debug.hpp"
22#include "util/reader_mapping.hpp"
23#include "util/writer.hpp"
24#include "video/drawing_context.hpp"
25
26SequenceTrigger::SequenceTrigger(const ReaderMapping& reader) :
27 triggerevent(EVENT_TOUCH),
28 sequence(SEQ_ENDSEQUENCE),
29 new_size(),
30 new_spawnpoint(),
31 fade_tilemap(),
32 fade()
33{
34 reader.get("x", m_col.m_bbox.get_left(), 0.0f);
35 reader.get("y", m_col.m_bbox.get_top(), 0.0f);
36 float w, h;
37 reader.get("width", w, 32.0f);
38 reader.get("height", h, 32.0f);
39 m_col.m_bbox.set_size(w, h);
40 new_size.x = w;
41 new_size.y = h;
42 std::string sequence_name;
43 if (reader.get("sequence", sequence_name)) {
44 sequence = string_to_sequence(sequence_name);
45 }
46
47 reader.get("new_spawnpoint", new_spawnpoint);
48 reader.get("fade_tilemap", fade_tilemap);
49 reader.get("fade", reinterpret_cast<int&>(fade));
50}
51
52SequenceTrigger::SequenceTrigger(const Vector& pos, const std::string& sequence_name) :
53 triggerevent(EVENT_TOUCH),
54 sequence(string_to_sequence(sequence_name)),
55 new_size(),
56 new_spawnpoint(),
57 fade_tilemap(),
58 fade()
59{
60 m_col.m_bbox.set_pos(pos);
61 m_col.m_bbox.set_size(32, 32);
62}
63
64ObjectSettings
65SequenceTrigger::get_settings()
66{
67 new_size.x = m_col.m_bbox.get_width();
68 new_size.y = m_col.m_bbox.get_height();
69
70 ObjectSettings result = TriggerBase::get_settings();
71
72 //result.add_float(_("Width"), &new_size.x, "width");
73 //result.add_float(_("Height"), &new_size.y, "height");
74
75 result.add_enum(_("Sequence"), reinterpret_cast<int*>(&sequence),
76 {_("end sequence"), _("stop Tux"), _("fireworks")},
77 {"endsequence", "stoptux", "fireworks"},
78 boost::none, "sequence");
79
80 result.add_text(_("New worldmap spawnpoint"), &new_spawnpoint, "new_spawnpoint");
81 result.add_text(_("Worldmap fade tilemap"), &fade_tilemap, "fade_tilemap");
82 result.add_string_select(_("Fade"), reinterpret_cast<int*>(&fade),
83 {_("Fade in"), _("Fade out")},
84 0, "fade");
85
86 result.reorder({"sequence", "region", "width", "height", "x", "y", "fade"});
87
88 return result;
89}
90
91void
92SequenceTrigger::after_editor_set()
93{
94 m_col.m_bbox.set_size(new_size.x, new_size.y);
95}
96
97void
98SequenceTrigger::event(Player& player, EventType type)
99{
100 if (type == triggerevent) {
101 auto data = SequenceData(new_spawnpoint, fade_tilemap, fade);
102 player.trigger_sequence(sequence, &data);
103 }
104}
105
106std::string
107SequenceTrigger::get_sequence_name() const
108{
109 return sequence_to_string(sequence);
110}
111
112void
113SequenceTrigger::draw(DrawingContext& context)
114{
115 if (Editor::is_active() || g_debug.show_collision_rects) {
116 context.color().draw_filled_rect(m_col.m_bbox, Color(1.0f, 0.0f, 0.0f, 0.6f),
117 0.0f, LAYER_OBJECTS);
118 }
119}
120
121/* EOF */
122