ApplicationOptions.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. namespace Urho
  5. {
  6. /// <summary>
  7. /// Application options, see full description at:
  8. /// http://urho3d.github.io/documentation/1.5/_running.html
  9. /// </summary>
  10. public class ApplicationOptions
  11. {
  12. /// <param name="assetsFolder">usually it's "Data". Can be null if built-in assets are enough for you</param>
  13. public ApplicationOptions(string assetsFolder)
  14. {
  15. if (assetsFolder != null)
  16. {
  17. ResourcePaths = new[] { assetsFolder };
  18. }
  19. }
  20. public ApplicationOptions(string[] assetsFolders)
  21. {
  22. ResourcePaths = assetsFolders;
  23. }
  24. /// <summary>
  25. /// Desktop only
  26. /// </summary>
  27. public int Width { get; set; } = 0;
  28. /// <summary>
  29. /// Desktop only
  30. /// </summary>
  31. public int Height { get; set; } = 0;
  32. /// <summary>
  33. /// Desktop only
  34. /// </summary>
  35. public bool WindowedMode { get; set; } = true;
  36. /// <summary>
  37. /// Desktop only
  38. /// </summary>
  39. public bool ResizableWindow { get; set; } = false;
  40. /// <summary>
  41. /// With limit enabled: 200 fps for Desktop (and always 60 fps for mobile despite of the flag)
  42. /// </summary>
  43. public bool LimitFps { get; set; } = true;
  44. #if XFORMS
  45. /// <summary>
  46. /// iOS only
  47. /// </summary>
  48. public OrientationType Orientation { get; set; } = OrientationType.Portrait;
  49. #else
  50. /// <summary>
  51. /// iOS only
  52. /// </summary>
  53. public OrientationType Orientation { get; set; } = OrientationType.Landscape;
  54. #endif
  55. /// <summary>
  56. /// Resource path(s) to use (default: Data, CoreData)
  57. /// </summary>
  58. public string[] ResourcePaths { get; set; } = null;
  59. /// <summary>
  60. /// Resource package files to use (default: empty)
  61. /// </summary>
  62. public string[] ResourcePackagesPaths { get; set; } = null;
  63. #if WINDOWS_UWP
  64. public bool TouchEmulation { get { return true; } set {} }
  65. #else
  66. /// <summary>
  67. /// Touch emulation on desktop platform
  68. /// </summary>
  69. public bool TouchEmulation { get; set; } = false;
  70. #endif
  71. /// <summary>
  72. /// Add any flag listed here: http://urho3d.github.io/documentation/1.5/_running.html
  73. /// </summary>
  74. public string AdditionalFlags { get; set; } = string.Empty;
  75. /// <summary>
  76. /// Windows: external window handle (WinForms Panel.Handle) to use in order to display Urho game
  77. /// You can use it in WPF via WindowsFormsHost (and a WF panel inside it)
  78. /// </summary>
  79. public IntPtr ExternalWindow { get; set; }
  80. public enum OrientationType
  81. {
  82. Landscape,
  83. Portrait,
  84. LandscapeAndPortrait
  85. }
  86. public override string ToString()
  87. {
  88. StringBuilder builder = new StringBuilder();
  89. builder.Append("args");//it will be skipped by Urho;
  90. #if !IOS //always use -w on iOS
  91. if (WindowedMode)
  92. #endif
  93. builder.Append(" -w");
  94. if (!LimitFps)
  95. builder.Append(" -nolimit");
  96. if (Width > 0)
  97. builder.AppendFormat(" -x {0}", Width);
  98. if (Height > 0)
  99. builder.AppendFormat(" -y {0}", Height);
  100. #if !IOS //always use -s on iOS and UWP
  101. if (ResizableWindow)
  102. #endif
  103. builder.Append(" -s");
  104. var resourcePathes = new[] {"CoreData"}.Concat(ResourcePaths ?? new string[0]);
  105. builder.AppendFormat(" -p \"{0}\"", string.Join(";", resourcePathes.Distinct()));
  106. if (ResourcePackagesPaths?.Length > 0)
  107. builder.AppendFormat(" -pf \"{0}\"", string.Join(";", ResourcePackagesPaths));
  108. #if !WINDOWS_UWP
  109. if (TouchEmulation)
  110. #endif
  111. builder.Append(" -touch");
  112. switch (Orientation)
  113. {
  114. case OrientationType.Landscape:
  115. builder.Append(" -landscape");
  116. break;
  117. case OrientationType.Portrait:
  118. builder.Append(" -portrait");
  119. break;
  120. case OrientationType.LandscapeAndPortrait:
  121. builder.Append(" -landscape -portrait");
  122. break;
  123. }
  124. return builder + " " + AdditionalFlags;
  125. }
  126. }
  127. }