2
0

EditorSettings.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Runtime.InteropServices;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using BansheeEngine;
  10. namespace BansheeEditor
  11. {
  12. /// <summary>
  13. /// Contains various settings that are applied globally to the editor. Settings will persist through editor sessions.
  14. /// </summary>
  15. internal static class EditorSettings
  16. {
  17. /// <summary>
  18. /// Determines if snapping for move handle is active. When active the move handle can only be moved in increments
  19. /// specified by <see cref="MoveHandleSnapAmount"/>.
  20. /// </summary>
  21. public static bool MoveHandleSnapActive
  22. {
  23. get { return Internal_GetMoveHandleSnapActive(); }
  24. set { Internal_SetMoveHandleSnapActive(value); }
  25. }
  26. /// <summary>
  27. /// Determines if snapping for rotate handle is active. When active the rotate handle can only be rotated in
  28. /// increments specified by <see cref="RotateHandleSnapAmount"/>.
  29. /// </summary>
  30. public static bool RotateHandleSnapActive
  31. {
  32. get { return Internal_GetRotateHandleSnapActive(); }
  33. set { Internal_SetRotateHandleSnapActive(value); }
  34. }
  35. /// <summary>
  36. /// Determines size of the increments the move handle can be moved when <see cref="MoveHandleSnapActive"/> is
  37. /// active.
  38. /// </summary>
  39. public static float MoveHandleSnapAmount
  40. {
  41. get { return Internal_GetMoveHandleSnapAmount(); }
  42. set { Internal_SetMoveHandleSnapAmount(value); }
  43. }
  44. /// <summary>
  45. /// Determines size of the increments the rotate handle can be moved when <see cref="RotateHandleSnapActive"/> is
  46. /// active.
  47. /// </summary>
  48. public static Degree RotateHandleSnapAmount
  49. {
  50. get { return Internal_GetRotateHandleSnapAmount(); }
  51. set { Internal_SetRotateHandleSnapAmount(value.Degrees); }
  52. }
  53. /// <summary>
  54. /// Determines the default size for all handles.
  55. /// </summary>
  56. public static float DefaultHandleSize
  57. {
  58. get { return Internal_GetDefaultHandleSize(); }
  59. set { Internal_SetDefaultHandleSize(value); }
  60. }
  61. /// <summary>
  62. /// Determines the active tool shown in the scene view.
  63. /// </summary>
  64. public static SceneViewTool ActiveSceneTool
  65. {
  66. get { return (SceneViewTool)Internal_GetActiveSceneTool(); }
  67. set { Internal_SetActiveSceneTool((int)value); }
  68. }
  69. /// <summary>
  70. /// Determines the coordinate mode used by the tools in the scene view.
  71. /// </summary>
  72. public static HandleCoordinateMode ActiveCoordinateMode
  73. {
  74. get { return (HandleCoordinateMode)Internal_GetActiveCoordinateMode(); }
  75. set { Internal_SetActiveCoordinateMode((int)value); }
  76. }
  77. /// <summary>
  78. /// Determines the pivot mode used by the tools in the scene view.
  79. /// </summary>
  80. public static HandlePivotMode ActivePivotMode
  81. {
  82. get { return (HandlePivotMode)Internal_GetActivePivotMode(); }
  83. set { Internal_SetActivePivotMode((int)value); }
  84. }
  85. /// <summary>
  86. /// Contains the absolute path to the last open project, if any.
  87. /// </summary>
  88. public static string LastOpenProject
  89. {
  90. get { return Internal_GetLastOpenProject(); }
  91. set { Internal_SetLastOpenProject(value); }
  92. }
  93. /// <summary>
  94. /// Determines should the last open project be automatically loaded on editor startup.
  95. /// </summary>
  96. public static bool AutoLoadLastProject
  97. {
  98. get { return Internal_GetAutoLoadLastProject(); }
  99. set { Internal_SetAutoLoadLastProject(value); }
  100. }
  101. /// <summary>
  102. /// Contains a list of most recently loaded projects.
  103. /// </summary>
  104. public static RecentProject[] RecentProjects
  105. {
  106. get
  107. {
  108. string[] paths;
  109. UInt64[] timeStamps;
  110. Internal_GetRecentProjects(out paths, out timeStamps);
  111. RecentProject[] output = new RecentProject[paths.Length];
  112. for (int i = 0; i < paths.Length; i++)
  113. output[i] = new RecentProject(paths[i], timeStamps[i]);
  114. return output;
  115. }
  116. set
  117. {
  118. int numEntries = 0;
  119. if (value != null)
  120. numEntries = value.Length;
  121. string[] paths = new string[numEntries];
  122. UInt64[] timeStamps = new UInt64[numEntries];
  123. for (int i = 0; i < numEntries; i++)
  124. {
  125. paths[i] = value[i].path;
  126. timeStamps[i] = value[i].accessTimestamp;
  127. }
  128. Internal_SetRecentProjects(paths, timeStamps);
  129. }
  130. }
  131. /// <summary>
  132. /// Contains a hash value that is updated whenever one of the properties in this object is updated. This allows
  133. /// external systems to track when they might need to reload the settings.
  134. /// </summary>
  135. public static int Hash
  136. {
  137. get { return Internal_GetHash(); }
  138. }
  139. /// <summary>
  140. /// Sets a generic floating point property.
  141. /// </summary>
  142. /// <param name="name">Name to record the property under.</param>
  143. /// <param name="value">Value of the property.</param>
  144. public static void SetFloat(string name, float value)
  145. {
  146. Internal_SetFloat(name, value);
  147. }
  148. /// <summary>
  149. /// Sets a generic integer property.
  150. /// </summary>
  151. /// <param name="name">Name to record the property under.</param>
  152. /// <param name="value">Value of the property.</param>
  153. public static void SetInt(string name, int value)
  154. {
  155. Internal_SetInt(name, value);
  156. }
  157. /// <summary>
  158. /// Sets a generic boolean property.
  159. /// </summary>
  160. /// <param name="name">Name to record the property under.</param>
  161. /// <param name="value">Value of the property.</param>
  162. public static void SetBool(string name, bool value)
  163. {
  164. Internal_SetBool(name, value);
  165. }
  166. /// <summary>
  167. /// Sets a generic string property.
  168. /// </summary>
  169. /// <param name="name">Name to record the property under.</param>
  170. /// <param name="value">Value of the property.</param>
  171. public static void SetString(string name, String value)
  172. {
  173. Internal_SetString(name, value);
  174. }
  175. /// <summary>
  176. /// Retrieves a generic floating point property.
  177. /// </summary>
  178. /// <param name="name">Name of the property to retrieve.</param>
  179. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  180. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  181. public static float GetFloat(string name, float defaultValue = 0.0f)
  182. {
  183. return Internal_GetFloat(name, defaultValue);
  184. }
  185. /// <summary>
  186. /// Retrieves a generic integer property.
  187. /// </summary>
  188. /// <param name="name">Name of the property to retrieve.</param>
  189. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  190. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  191. public static int GetInt(string name, int defaultValue = 0)
  192. {
  193. return Internal_GetInt(name, defaultValue);
  194. }
  195. /// <summary>
  196. /// Retrieves a generic boolean property.
  197. /// </summary>
  198. /// <param name="name">Name of the property to retrieve.</param>
  199. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  200. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  201. public static bool GetBool(string name, bool defaultValue = false)
  202. {
  203. return Internal_GetBool(name, defaultValue);
  204. }
  205. /// <summary>
  206. /// Retrieves a generic string property.
  207. /// </summary>
  208. /// <param name="name">Name of the property to retrieve.</param>
  209. /// <param name="defaultValue">Default value to return if property cannot be found.</param>
  210. /// <returns>Value of the property if it exists, otherwise the default value.</returns>
  211. public static String GetString(string name, string defaultValue = "")
  212. {
  213. return Internal_GetString(name, defaultValue);
  214. }
  215. /// <summary>
  216. /// Checks does a generic property with the specified name exists.
  217. /// </summary>
  218. /// <param name="name">Name of the property to check.</param>
  219. /// <returns>True if the property exists, false otherwise.</returns>
  220. public static bool HasKey(string name)
  221. {
  222. return Internal_HasKey(name);
  223. }
  224. /// <summary>
  225. /// Deletes a generic property with the specified name.
  226. /// </summary>
  227. /// <param name="name">Name of the property to delete.</param>
  228. public static void DeleteKey(string name)
  229. {
  230. Internal_DeleteKey(name);
  231. }
  232. /// <summary>
  233. /// Deletes all generic properties.
  234. /// </summary>
  235. public static void DeleteAllKeys()
  236. {
  237. Internal_DeleteAllKeys();
  238. }
  239. /// <summary>
  240. /// Saves editor settings to the disk.
  241. /// </summary>
  242. public static void Save()
  243. {
  244. Internal_Save();
  245. }
  246. [MethodImpl(MethodImplOptions.InternalCall)]
  247. private static extern bool Internal_GetMoveHandleSnapActive();
  248. [MethodImpl(MethodImplOptions.InternalCall)]
  249. private static extern void Internal_SetMoveHandleSnapActive(bool value);
  250. [MethodImpl(MethodImplOptions.InternalCall)]
  251. private static extern bool Internal_GetRotateHandleSnapActive();
  252. [MethodImpl(MethodImplOptions.InternalCall)]
  253. private static extern void Internal_SetRotateHandleSnapActive(bool value);
  254. [MethodImpl(MethodImplOptions.InternalCall)]
  255. private static extern float Internal_GetMoveHandleSnapAmount();
  256. [MethodImpl(MethodImplOptions.InternalCall)]
  257. private static extern void Internal_SetMoveHandleSnapAmount(float value);
  258. [MethodImpl(MethodImplOptions.InternalCall)]
  259. private static extern float Internal_GetRotateHandleSnapAmount();
  260. [MethodImpl(MethodImplOptions.InternalCall)]
  261. private static extern void Internal_SetRotateHandleSnapAmount(float value);
  262. [MethodImpl(MethodImplOptions.InternalCall)]
  263. private static extern float Internal_GetDefaultHandleSize();
  264. [MethodImpl(MethodImplOptions.InternalCall)]
  265. private static extern void Internal_SetDefaultHandleSize(float value);
  266. [MethodImpl(MethodImplOptions.InternalCall)]
  267. private static extern int Internal_GetActiveSceneTool();
  268. [MethodImpl(MethodImplOptions.InternalCall)]
  269. private static extern void Internal_SetActiveSceneTool(int value);
  270. [MethodImpl(MethodImplOptions.InternalCall)]
  271. private static extern int Internal_GetActiveCoordinateMode();
  272. [MethodImpl(MethodImplOptions.InternalCall)]
  273. private static extern void Internal_SetActiveCoordinateMode(int value);
  274. [MethodImpl(MethodImplOptions.InternalCall)]
  275. private static extern int Internal_GetActivePivotMode();
  276. [MethodImpl(MethodImplOptions.InternalCall)]
  277. private static extern void Internal_SetActivePivotMode(int value);
  278. [MethodImpl(MethodImplOptions.InternalCall)]
  279. private static extern string Internal_GetLastOpenProject();
  280. [MethodImpl(MethodImplOptions.InternalCall)]
  281. private static extern void Internal_SetLastOpenProject(string value);
  282. [MethodImpl(MethodImplOptions.InternalCall)]
  283. private static extern bool Internal_GetAutoLoadLastProject();
  284. [MethodImpl(MethodImplOptions.InternalCall)]
  285. private static extern void Internal_SetAutoLoadLastProject(bool value);
  286. [MethodImpl(MethodImplOptions.InternalCall)]
  287. private static extern void Internal_GetRecentProjects(out string[] paths, out UInt64[] timestamps);
  288. [MethodImpl(MethodImplOptions.InternalCall)]
  289. private static extern void Internal_SetRecentProjects(string[] paths, UInt64[] timestamps);
  290. [MethodImpl(MethodImplOptions.InternalCall)]
  291. private static extern void Internal_SetFloat(string name, float value);
  292. [MethodImpl(MethodImplOptions.InternalCall)]
  293. private static extern void Internal_SetInt(string name, int value);
  294. [MethodImpl(MethodImplOptions.InternalCall)]
  295. private static extern void Internal_SetBool(string name, bool value);
  296. [MethodImpl(MethodImplOptions.InternalCall)]
  297. private static extern void Internal_SetString(string name, String value);
  298. [MethodImpl(MethodImplOptions.InternalCall)]
  299. private static extern float Internal_GetFloat(string name, float defaultValue);
  300. [MethodImpl(MethodImplOptions.InternalCall)]
  301. private static extern int Internal_GetInt(string name, int defaultValue);
  302. [MethodImpl(MethodImplOptions.InternalCall)]
  303. private static extern bool Internal_GetBool(string name, bool defaultValue);
  304. [MethodImpl(MethodImplOptions.InternalCall)]
  305. private static extern string Internal_GetString(string name, string defaultValue);
  306. [MethodImpl(MethodImplOptions.InternalCall)]
  307. private static extern bool Internal_HasKey(string name);
  308. [MethodImpl(MethodImplOptions.InternalCall)]
  309. private static extern void Internal_DeleteKey(string name);
  310. [MethodImpl(MethodImplOptions.InternalCall)]
  311. private static extern void Internal_DeleteAllKeys();
  312. [MethodImpl(MethodImplOptions.InternalCall)]
  313. private static extern int Internal_GetHash();
  314. [MethodImpl(MethodImplOptions.InternalCall)]
  315. private static extern void Internal_Save();
  316. }
  317. /// <summary>
  318. /// Contains data about a recently opened project.
  319. /// </summary>
  320. [StructLayout(LayoutKind.Sequential)]
  321. public struct RecentProject // Note: Must match C++ struct RecentProject
  322. {
  323. /// <summary>
  324. /// Constructs a new recently opened project object.
  325. /// </summary>
  326. /// <param name="path">Absolute path to the project.</param>
  327. /// <param name="timestamp">Timestamp when the project was last opened.</param>
  328. public RecentProject(string path, UInt64 timestamp)
  329. {
  330. this.path = path;
  331. this.accessTimestamp = timestamp;
  332. }
  333. public string path;
  334. public UInt64 accessTimestamp;
  335. }
  336. }