plugindiagmenumodding.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * \defgroup Modding Modding DiagMenu
  3. * \warning Only available on developer and diag builds
  4. * \note This file is extensive documentation about modding DiagMenu, please read EVERYTHING before starting
  5. * @{
  6. */
  7. #ifdef DOXYGEN
  8. #ifdef MODDING_TEST
  9. #ifdef DIAG_DEVELOPER
  10. /**
  11. \brief Example of adding DiagMenu entries by modders
  12. \note PluginDiagMenu is the base of ..Client and ...Server, which is why we are registering the IDs on this level, so they exist on both Client and Server
  13. \note Keep in mind that in SinglePlayer missions, both Client and Server PluginDiagMenu are created
  14. \note Keep in mind that PluginDiagMenu... is destroyed and recreated every time the world changes
  15. */
  16. #ifdef DOXYGEN
  17. class PluginDiagMenuModded // Just to not have it show up for the regular entry... Doxygen doesn't know about modding
  18. #else
  19. modded class PluginDiagMenu
  20. #endif
  21. {
  22. /**
  23. \brief The name of the root menu where all debugs of this mod will be placed in
  24. \note Try to think of a name which will make it easy to identify as originating from your mod
  25. \note The 'maximum' length of the name of an entry is 24 characters (excess will be cut off when rendering)
  26. \note The hardcap length of the name of an entry is 64 characters
  27. */
  28. protected string m_ModdedDiagsExampleRootMenu = "BI - DiagsModdingExample";
  29. /**
  30. \brief The name of an example sub menu
  31. */
  32. protected string m_ModdedDiagsExampleSubMenu = "Example Sub Menu";
  33. /** \name Modded Diag IDs
  34. * To prevent mod conflicts, a system has been set up to create unique IDs for the modded Diags
  35. * These are then best saved to a variable so that they can be used by the other DiagMenu functions
  36. * !!! Remember to give them as unique as possible name, as something with a generic name could cause conflicts
  37. */
  38. //@{
  39. protected int m_ModdedDiagsExampleRootMenuID;
  40. protected int m_ModdedDiagsExampleBoolID;
  41. protected int m_ModdedDiagsExampleSubMenuID;
  42. protected int m_ModdedDiagsExampleRangeID;
  43. //@}
  44. //---------------------------------------------
  45. /**
  46. \brief Obtain unique IDs and store them in variables
  47. \warning Please only call GetModdedDiagID when necessary, as every time it is called it will increment and Script has a limit of 512 Diag IDs
  48. \note Don't forget to call super!
  49. */
  50. override protected void RegisterModdedDiagsIDs()
  51. {
  52. super.RegisterModdedDiagsIDs();
  53. m_ModdedDiagsExampleRootMenuID = GetModdedDiagID();
  54. m_ModdedDiagsExampleBoolID = GetModdedDiagID();
  55. m_ModdedDiagsExampleSubMenuID = GetModdedDiagID();
  56. m_ModdedDiagsExampleRangeID = GetModdedDiagID();
  57. }
  58. //---------------------------------------------
  59. /**
  60. \brief Register entries to the DiagMenu
  61. \note Please create a root menu for your mod which is then the single parent of all your diags, which is then a child of ModdedRootMenu
  62. \warning Read the in-file comments as well
  63. \warning Don't forget to call super! Mandatory at the beginning of the function so it can register the modded root menu!
  64. */
  65. override protected void RegisterModdedDiags()
  66. {
  67. super.RegisterModdedDiags();
  68. // Register the root menu of your mod under the ModdedRootMenu
  69. // Then register all following menus and items under this menu
  70. // This can not be enforced, but it will help keep things clean
  71. // Including being able to easily identify where a debug is coming from
  72. // So that reports of a broken debug can be sent to the correct developer
  73. //
  74. // If you have multiple mods, you might even want to consider to create a root menu with your developer name
  75. // And then put the mod menus as a submenu
  76. // To prevent someone running a lot of mods from having an overflooded menu
  77. // DiagMenu.MenuExists(...) could serve to help to identify if the root menu already exists when using this format
  78. // So that the multiple mods can know if they still have to register your root menu or not
  79. DiagMenu.RegisterMenu(m_ModdedDiagsExampleRootMenuID, m_ModdedDiagsExampleRootMenu, GetModdedRootMenu());
  80. {
  81. DiagMenu.RegisterBool(m_ModdedDiagsExampleBoolID, "", "Modded Example Bool", m_ModdedDiagsExampleRootMenuID);
  82. // A sub menu inside the root of the mod menu
  83. // The curly braces are simply for readability
  84. DiagMenu.RegisterMenu(m_ModdedDiagsExampleSubMenuID, m_ModdedDiagsExampleSubMenu, m_ModdedDiagsExampleRootMenuID);
  85. {
  86. DiagMenu.RegisterRange(m_ModdedDiagsExampleRangeID, "", "Modded Example Range", m_ModdedDiagsExampleSubMenuID, "3 9 6 3");
  87. }
  88. }
  89. }
  90. }
  91. #ifdef DOXYGEN
  92. class DummyDoxygenClass
  93. {
  94. int m_IgnoreThisVariable;
  95. }
  96. #endif
  97. /**
  98. \brief Example of adding DiagMenu functionality by modders
  99. \note DiagMenu is mostly designed to run on Client, which is why the decision was made to keep most of the functionality for only the Client
  100. \note This way the callbacks are only registered on Client and not on Server, to prevent mishaps
  101. */
  102. #ifdef DOXYGEN
  103. class PluginDiagMenuClientModded // Just to not have it show up for the regular entry... Doxygen doesn't know about modding
  104. #else
  105. modded class PluginDiagMenuClient
  106. #endif
  107. {
  108. /**
  109. \brief Bind callbacks to the entries to immediately perform an action when the value is changed
  110. \note Don't forget to call super!
  111. */
  112. override protected void BindCallbacks()
  113. {
  114. super.BindCallbacks();
  115. DiagMenu.BindCallback(m_ModdedDiagsExampleBoolID, CBModdedDiadIDsExampleBool);
  116. DiagMenu.BindCallback(m_ModdedDiagsExampleRangeID, CBModdedDiadIDsExampleRange);
  117. }
  118. /**
  119. \brief Example callback for RegisterBool
  120. \note Give it a unique name to prevent conflicts
  121. \note These MUST be static and return void
  122. @code
  123. // Valid RegisterBool callback signatures (Technically 'bool' can be 'int' as well, so be mindful of that)
  124. // o static void Callback();
  125. // o static void Callback(bool value);
  126. // o static void Callback(bool value, int id);
  127. @endcode
  128. */
  129. static void CBModdedDiadIDsExampleBool(bool enabled)
  130. {
  131. Print("CBModdedDiadIDsExampleBool: " + enabled);
  132. }
  133. /**
  134. \brief Example callback for RegisterRange
  135. \note Give it a unique name to prevent conflicts
  136. \note These MUST be static and return void
  137. @code
  138. // Valid RegisterRange callback signatures (Technically 'int' can be 'bool' as well, so be mindful of that)
  139. // o static void Callback();
  140. // o static void Callback(float value);
  141. // o static void Callback(float value, int id);
  142. // o static void Callback(int value);
  143. // o static void Callback(int value, int id);
  144. @endcode
  145. */
  146. static void CBModdedDiadIDsExampleRange(float value)
  147. {
  148. Print("CBModdedDiadIDsExampleRange: " + value);
  149. }
  150. }
  151. #endif
  152. #endif
  153. #endif
  154. //@}