path_gameobject.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SuperTux
  2. // Copyright (C) 2018 Ingo Ruhnke <grumbel@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. #ifndef HEADER_SUPERTUX_OBJECT_PATH_GAMEOBJECT_HPP
  17. #define HEADER_SUPERTUX_OBJECT_PATH_GAMEOBJECT_HPP
  18. #include "sprite/sprite_ptr.hpp"
  19. #include "supertux/game_object.hpp"
  20. #include "math/fwd.hpp"
  21. class Path;
  22. enum class PathStyle
  23. {
  24. NONE,
  25. SOLID
  26. };
  27. class PathGameObject : public GameObject
  28. {
  29. public:
  30. PathGameObject();
  31. PathGameObject(const Vector& pos);
  32. PathGameObject(const ReaderMapping& mapping, bool backward_compatibility_hack=false);
  33. ~PathGameObject() override;
  34. virtual void update(float dt_sec) override;
  35. virtual void draw(DrawingContext& context) override;
  36. static std::string class_name() { return "path"; }
  37. virtual std::string get_class_name() const override { return class_name(); }
  38. static std::string display_name() { return _("Path"); }
  39. virtual std::string get_display_name() const override { return display_name(); }
  40. virtual GameObjectClasses get_class_types() const override { return GameObject::get_class_types().add(typeid(PathGameObject)); }
  41. virtual void editor_select() override;
  42. virtual void editor_deselect() override;
  43. virtual void remove_me() override;
  44. virtual void on_flip(float height) override;
  45. virtual ObjectSettings get_settings() override;
  46. void regenerate_name();
  47. inline Path& get_path() { return *m_path; }
  48. void copy_into(PathGameObject& other);
  49. /** Allows saving the object only if the path is referenced somewhere. */
  50. bool is_saveable() const override;
  51. private:
  52. std::unique_ptr<Path> m_path;
  53. PathStyle m_style;
  54. SpritePtr m_edge_sprite;
  55. SpritePtr m_node_sprite;
  56. private:
  57. PathGameObject(const PathGameObject&) = delete;
  58. PathGameObject& operator=(const PathGameObject&) = delete;
  59. };
  60. #endif
  61. /* EOF */