| 1 | // SuperTux |
| 2 | // Copyright (C) 2016 Hume2 <teratux.mail@gmail.com> |
| 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 "editor/node_marker.hpp" |
| 18 | |
| 19 | #include "editor/editor.hpp" |
| 20 | |
| 21 | NodeMarker::NodeMarker (Path* path_, std::vector<Path::Node>::iterator node_iterator, size_t id_) : |
| 22 | m_path(path_), |
| 23 | m_node(node_iterator), |
| 24 | m_id(id_) |
| 25 | { |
| 26 | set_pos(m_node->position - Vector(8, 8)); |
| 27 | } |
| 28 | |
| 29 | void |
| 30 | NodeMarker::update_iterator() |
| 31 | { |
| 32 | if (m_id >= m_path->m_nodes.size()) { |
| 33 | remove_me(); |
| 34 | } else { |
| 35 | m_node = m_path->m_nodes.begin() + m_id; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | Vector |
| 40 | NodeMarker::get_point_vector() const |
| 41 | { |
| 42 | std::vector<Path::Node>::iterator next_node = m_node + 1; |
| 43 | if (next_node == m_path->m_nodes.end()) { |
| 44 | if (m_path->m_mode == WalkMode::CIRCULAR) { |
| 45 | //loop to the first node |
| 46 | return m_path->m_nodes.begin()->position - m_node->position; |
| 47 | } else { |
| 48 | return Vector(0,0); |
| 49 | } |
| 50 | } else { |
| 51 | //point to the next node |
| 52 | return next_node->position - m_node->position; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | Vector |
| 57 | NodeMarker::get_offset() const |
| 58 | { |
| 59 | return Vector(8, 8); |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | NodeMarker::move_to(const Vector& pos) |
| 64 | { |
| 65 | MovingObject::move_to(pos); |
| 66 | m_node->position = m_col.m_bbox.get_middle(); |
| 67 | } |
| 68 | |
| 69 | void |
| 70 | NodeMarker::editor_delete() |
| 71 | { |
| 72 | m_path->m_nodes.erase(m_node); |
| 73 | Editor::current()->update_node_iterators(); |
| 74 | } |
| 75 | |
| 76 | ObjectSettings |
| 77 | NodeMarker::get_settings() |
| 78 | { |
| 79 | ObjectSettings result(_("Path Node" )); |
| 80 | result.add_float(_("Time" ), &(m_node->time)); |
| 81 | return result; |
| 82 | } |
| 83 | |
| 84 | void |
| 85 | NodeMarker::editor_update() |
| 86 | { |
| 87 | set_pos(m_node->position - Vector(8, 8)); |
| 88 | } |
| 89 | |
| 90 | /* EOF */ |
| 91 | |