run_instances_dialog.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /**************************************************************************/
  2. /* run_instances_dialog.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/gui/dialogs.h"
  32. class CheckBox;
  33. class LineEdit;
  34. class SpinBox;
  35. class Timer;
  36. class Tree;
  37. class TreeItem;
  38. class PopupMenu;
  39. class RunInstancesDialog : public AcceptDialog {
  40. GDCLASS(RunInstancesDialog, AcceptDialog);
  41. enum Columns {
  42. COLUMN_OVERRIDE_ARGS,
  43. COLUMN_LAUNCH_ARGUMENTS,
  44. COLUMN_OVERRIDE_FEATURES,
  45. COLUMN_FEATURE_TAGS,
  46. };
  47. struct InstanceData {
  48. TreeItem *item = nullptr;
  49. bool overrides_run_args() const;
  50. String get_launch_arguments() const;
  51. bool overrides_features() const;
  52. String get_feature_tags() const;
  53. };
  54. // Right-click popup menu.
  55. enum {
  56. CLEAR_ITEM,
  57. CLEAR_ALL,
  58. };
  59. inline static RunInstancesDialog *singleton = nullptr;
  60. TypedArray<Dictionary> stored_data;
  61. Vector<InstanceData> instances_data;
  62. Timer *main_apply_timer = nullptr;
  63. Timer *instance_apply_timer = nullptr;
  64. LineEdit *main_args_edit = nullptr;
  65. LineEdit *main_features_edit = nullptr;
  66. SpinBox *instance_count = nullptr;
  67. CheckBox *enable_multiple_instances_checkbox = nullptr;
  68. Tree *instance_tree = nullptr;
  69. PopupMenu *popup_menu = nullptr;
  70. void _fetch_main_args();
  71. // These 2 methods are necessary due to callable_mp() not supporting default arguments.
  72. void _start_main_timer();
  73. void _start_instance_timer();
  74. void _refresh_argument_count();
  75. void _create_instance(InstanceData &p_instance, const Dictionary &p_data, int p_idx);
  76. void _save_main_args();
  77. void _save_arguments();
  78. // Separates command line arguments without splitting up quoted strings.
  79. Vector<String> _split_cmdline_args(const String &p_arg_string) const;
  80. void _instance_menu_id_pressed(int p_option);
  81. void _instance_tree_rmb(const Vector2 &p_pos, MouseButton p_button);
  82. public:
  83. void popup_dialog();
  84. int get_instance_count() const;
  85. void get_argument_list_for_instance(int p_idx, List<String> &r_list) const;
  86. void apply_custom_features(int p_instance_idx);
  87. static RunInstancesDialog *get_singleton() { return singleton; }
  88. RunInstancesDialog();
  89. };