workbenchapi.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. typedef int[] WBModuleDef;
  2. typedef int[] ScriptEditor;
  3. typedef int[] ResourceBrowser;
  4. typedef int[] WorldEditor;
  5. class Workbench
  6. {
  7. static proto native WBModuleDef GetModule(string type);
  8. static proto native bool OpenModule(string type);
  9. static proto native bool CloseModule(string type);
  10. static proto native void Dialog(string caption, string text);
  11. static proto int ScriptDialog(string caption, string text, Class data);
  12. static proto bool SearchResources(string filter, func callback);
  13. static proto native int RunCmd(string command, bool wait = false);
  14. static proto void GetCwd(out string currentDir);
  15. static proto bool GetAbsolutePath(string relativePath, out string absPath);
  16. };
  17. class WBModuleDef
  18. {
  19. proto native external bool SetOpenedResource(string filename);
  20. proto native external int GetNumContainers();
  21. proto native external BaseContainer GetContainer(int index = 0);
  22. proto external bool GetCmdLine(string name, out string value);
  23. proto native external bool Save();
  24. proto native external bool Close();
  25. };
  26. class ScriptEditor: WBModuleDef
  27. {
  28. proto external bool GetCurrentFile(out string filename);
  29. proto native external int GetCurrentLine();
  30. };
  31. class ResourceBrowser: WBModuleDef
  32. {
  33. proto external bool GetCurrentFile(out string filename);
  34. };
  35. class WorldEditor: WBModuleDef
  36. {
  37. proto native external WorldEditorAPI GetAPI();
  38. };
  39. class WorldEditorAPI
  40. {
  41. proto native bool BeginTerrainAction(string historyPointName = "", string historyPointIcon = "");
  42. proto native void EndTerrainAction(string historyPointName = "");
  43. proto native bool BeginEntityAction(string historyPointName = "", string historyPointIcon = ""); //begin of logical edit action
  44. proto native bool EndEntityAction(string historyPointName = ""); //end of edit action
  45. proto native bool IsDoingEditAction(); //true, if code stay betwen BeginEntityAction() and EndEntityAction()
  46. proto native bool UndoOrRedoIsRestoring(); //true, if editor is restoring undo or redo state
  47. proto native bool IsModifyingData();
  48. proto native IEntity SourceToEntity(IEntitySource entSrc);
  49. proto native IEntitySource EntityToSource(IEntity ent);
  50. proto native IEntitySource FindEntityByName(string name);
  51. proto native external void SetEntitySelection(IEntity ent);
  52. proto native external void AddToEntitySelection(IEntity ent);
  53. proto native void ClearEntitySelection();
  54. proto native void RemoveFromEntitySelection(IEntity ent);
  55. proto native void SetPropertySelection(string id);
  56. proto native external bool ModifyEntityKey(IEntity ent, string key, string value);
  57. proto native external bool ModifyEntityTemplateKey(IEntitySource tmpl, string key, string value);
  58. proto native external IEntity CreateEntity(string className, string name, int layerId, vector coords, vector angles);
  59. proto native external IEntity CreateClonedEntity(IEntity ent, string name);
  60. proto native external bool DeleteEntity(IEntity ent);
  61. proto native bool DeleteEntities(out array<IEntity> ents);
  62. proto native IEntity GetEntityUnderCursor();
  63. proto native external bool TraceWorldPos(int x, int y, int traceFlags, out vector traceStart, out vector traceEnd, out vector traceDir);
  64. proto native int GetSelectedEntitiesCount();
  65. proto native IEntity GetSelectedEntity(int n = 0);
  66. private void WorldEditorAPI() {}
  67. private void ~WorldEditorAPI() {}
  68. };
  69. class WorldEditorTool
  70. {
  71. //! Filled by workbench
  72. WorldEditorAPI m_API;
  73. void OnKeyPressEvent(int key) {}
  74. void OnKeyReleaseEvent(int key) {}
  75. void OnEnterEvent() {}
  76. void OnLeaveEvent() {}
  77. void OnMouseMoveEvent(float x, float y) {}
  78. void OnMouseDoubleClickEvent(float x, float y) {}
  79. void OnMousePressEvent(float x, float y) {}
  80. void OnMouseReleaseEvent(float x, float y) {}
  81. void OnWheelEvent(int delta) {}
  82. private void WorldEditorTool() {}
  83. private void ~WorldEditorTool() {}
  84. };
  85. class WorkbenchPlugin
  86. {
  87. void Run() {}
  88. void RunCommandline() {}
  89. void Configure() {}
  90. };
  91. class ButtonAttribute
  92. {
  93. string m_Label;
  94. bool m_Focused;
  95. void ButtonAttribute(string label = "ScriptButton", bool focused = false)
  96. {
  97. m_Label = label;
  98. m_Focused = focused;
  99. }
  100. };
  101. /*!
  102. Attribute for Workbench plugin definition:
  103. name - ui name in Script Tools menu
  104. description - tooltip
  105. shortcut - shortcut in simple text form e.g. "ctrl+g"
  106. icon - relative path to icon file (32x32 png)
  107. wbModules - list of strings representing Workbench modules where this tool should be avalaible (e.g. {"ResourceManager", "ScriptEditor"}). Leave null or empty array for any module.
  108. */
  109. class WorkbenchPluginAttribute
  110. {
  111. string m_Name;
  112. string m_Icon;
  113. string m_Shortcut;
  114. string m_Description;
  115. ref array<string> m_WBModules;
  116. void WorkbenchPluginAttribute(string name, string description = "", string shortcut = "", string icon = "", array<string> wbModules = null)
  117. {
  118. m_Name = name;
  119. m_Icon = icon;
  120. m_Shortcut = shortcut;
  121. m_Description = description;
  122. m_WBModules = wbModules;
  123. }
  124. };
  125. /*!
  126. Attribute for Workbench tool definition
  127. */
  128. class WorkbenchToolAttribute: WorkbenchPluginAttribute
  129. {
  130. }