navigation_link_2d.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**************************************************************************/
  2. /* navigation_link_2d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "scene/2d/node_2d.h"
  32. class NavigationLink2D : public Node2D {
  33. GDCLASS(NavigationLink2D, Node2D);
  34. bool enabled = true;
  35. RID link;
  36. RID map_override;
  37. bool bidirectional = true;
  38. uint32_t navigation_layers = 1;
  39. Vector2 end_position;
  40. Vector2 start_position;
  41. real_t enter_cost = 0.0;
  42. real_t travel_cost = 1.0;
  43. Transform2D current_global_transform;
  44. #ifdef DEBUG_ENABLED
  45. void _update_debug_mesh();
  46. #endif // DEBUG_ENABLED
  47. protected:
  48. static void _bind_methods();
  49. void _notification(int p_what);
  50. #ifndef DISABLE_DEPRECATED
  51. bool _set(const StringName &p_name, const Variant &p_value);
  52. bool _get(const StringName &p_name, Variant &r_ret) const;
  53. #endif // DISABLE_DEPRECATED
  54. public:
  55. #ifdef DEBUG_ENABLED
  56. virtual Rect2 _edit_get_rect() const override;
  57. virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;
  58. #endif // DEBUG_ENABLED
  59. RID get_rid() const;
  60. void set_enabled(bool p_enabled);
  61. bool is_enabled() const { return enabled; }
  62. void set_navigation_map(RID p_navigation_map);
  63. RID get_navigation_map() const;
  64. void set_bidirectional(bool p_bidirectional);
  65. bool is_bidirectional() const { return bidirectional; }
  66. void set_navigation_layers(uint32_t p_navigation_layers);
  67. uint32_t get_navigation_layers() const { return navigation_layers; }
  68. void set_navigation_layer_value(int p_layer_number, bool p_value);
  69. bool get_navigation_layer_value(int p_layer_number) const;
  70. void set_start_position(Vector2 p_position);
  71. Vector2 get_start_position() const { return start_position; }
  72. void set_end_position(Vector2 p_position);
  73. Vector2 get_end_position() const { return end_position; }
  74. void set_global_start_position(Vector2 p_position);
  75. Vector2 get_global_start_position() const;
  76. void set_global_end_position(Vector2 p_position);
  77. Vector2 get_global_end_position() const;
  78. void set_enter_cost(real_t p_enter_cost);
  79. real_t get_enter_cost() const { return enter_cost; }
  80. void set_travel_cost(real_t p_travel_cost);
  81. real_t get_travel_cost() const { return travel_cost; }
  82. PackedStringArray get_configuration_warnings() const override;
  83. NavigationLink2D();
  84. ~NavigationLink2D();
  85. private:
  86. void _link_enter_navigation_map();
  87. void _link_exit_navigation_map();
  88. void _link_update_transform();
  89. };