EditorSettings.cs 16 KB

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