BsScriptPlatformInfo.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Wrappers/BsScriptPlatformInfo.h"
  4. #include "BsScriptMeta.h"
  5. #include "BsMonoField.h"
  6. #include "BsMonoClass.h"
  7. #include "BsMonoManager.h"
  8. #include "BsMonoMethod.h"
  9. #include "BsMonoUtil.h"
  10. #include "Wrappers/BsScriptPrefab.h"
  11. #include "Wrappers/BsScriptRRefBase.h"
  12. #include "BsScriptResourceManager.h"
  13. namespace bs
  14. {
  15. ScriptPlatformInfoBase::ScriptPlatformInfoBase(MonoObject* instance)
  16. :ScriptObjectBase(instance)
  17. { }
  18. ScriptPlatformInfo::ScriptPlatformInfo(MonoObject* instance)
  19. : ScriptObject(instance)
  20. {
  21. }
  22. void ScriptPlatformInfo::initRuntimeData()
  23. {
  24. metaData.scriptClass->addInternalCall("Internal_GetType", (void*)&ScriptPlatformInfo::internal_GetType);
  25. metaData.scriptClass->addInternalCall("Internal_GetDefines", (void*)&ScriptPlatformInfo::internal_GetDefines);
  26. metaData.scriptClass->addInternalCall("Internal_SetDefines", (void*)&ScriptPlatformInfo::internal_SetDefines);
  27. metaData.scriptClass->addInternalCall("Internal_GetMainScene", (void*)&ScriptPlatformInfo::internal_GetMainScene);
  28. metaData.scriptClass->addInternalCall("Internal_SetMainScene", (void*)&ScriptPlatformInfo::internal_SetMainScene);
  29. metaData.scriptClass->addInternalCall("Internal_GetFullscreen", (void*)&ScriptPlatformInfo::internal_GetFullscreen);
  30. metaData.scriptClass->addInternalCall("Internal_SetFullscreen", (void*)&ScriptPlatformInfo::internal_SetFullscreen);
  31. metaData.scriptClass->addInternalCall("Internal_GetResolution", (void*)&ScriptPlatformInfo::internal_GetResolution);
  32. metaData.scriptClass->addInternalCall("Internal_SetResolution", (void*)&ScriptPlatformInfo::internal_SetResolution);
  33. metaData.scriptClass->addInternalCall("Internal_GetDebug", (void*)&ScriptPlatformInfo::internal_GetDebug);
  34. metaData.scriptClass->addInternalCall("Internal_SetDebug", (void*)&ScriptPlatformInfo::internal_SetDebug);
  35. }
  36. MonoObject* ScriptPlatformInfo::create(const SPtr<PlatformInfo>& platformInfo)
  37. {
  38. switch (platformInfo->type)
  39. {
  40. case PlatformType::Windows:
  41. return ScriptWinPlatformInfo::create(std::static_pointer_cast<WinPlatformInfo>(platformInfo));
  42. default:
  43. break;
  44. }
  45. return nullptr;
  46. }
  47. PlatformType ScriptPlatformInfo::internal_GetType(ScriptPlatformInfoBase* thisPtr)
  48. {
  49. return thisPtr->getPlatformInfo()->type;
  50. }
  51. MonoString* ScriptPlatformInfo::internal_GetDefines(ScriptPlatformInfoBase* thisPtr)
  52. {
  53. return MonoUtil::stringToMono(thisPtr->getPlatformInfo()->defines);
  54. }
  55. void ScriptPlatformInfo::internal_SetDefines(ScriptPlatformInfoBase* thisPtr, MonoString* value)
  56. {
  57. thisPtr->getPlatformInfo()->defines = MonoUtil::monoToString(value);
  58. }
  59. MonoObject* ScriptPlatformInfo::internal_GetMainScene(ScriptPlatformInfoBase* thisPtr)
  60. {
  61. HPrefab prefab = thisPtr->getPlatformInfo()->mainScene;
  62. if (prefab != nullptr)
  63. {
  64. ScriptRRefBase* scriptRRef = ScriptResourceManager::instance().getScriptRRef(prefab);
  65. if(scriptRRef)
  66. return scriptRRef->getManagedInstance();
  67. }
  68. return nullptr;
  69. }
  70. void ScriptPlatformInfo::internal_SetMainScene(ScriptPlatformInfoBase* thisPtr, ScriptRRefBase* prefabRef)
  71. {
  72. HPrefab prefab;
  73. if (prefabRef != nullptr)
  74. prefab = static_resource_cast<Prefab>(prefabRef->getHandle());
  75. thisPtr->getPlatformInfo()->mainScene = prefab;
  76. }
  77. bool ScriptPlatformInfo::internal_GetFullscreen(ScriptPlatformInfoBase* thisPtr)
  78. {
  79. return thisPtr->getPlatformInfo()->fullscreen;
  80. }
  81. void ScriptPlatformInfo::internal_SetFullscreen(ScriptPlatformInfoBase* thisPtr, bool fullscreen)
  82. {
  83. thisPtr->getPlatformInfo()->fullscreen = fullscreen;
  84. }
  85. void ScriptPlatformInfo::internal_GetResolution(ScriptPlatformInfoBase* thisPtr, UINT32* width, UINT32* height)
  86. {
  87. *width = thisPtr->getPlatformInfo()->windowedWidth;
  88. *height = thisPtr->getPlatformInfo()->windowedHeight;
  89. }
  90. void ScriptPlatformInfo::internal_SetResolution(ScriptPlatformInfoBase* thisPtr, UINT32 width, UINT32 height)
  91. {
  92. thisPtr->getPlatformInfo()->windowedWidth = width;
  93. thisPtr->getPlatformInfo()->windowedHeight = height;
  94. }
  95. bool ScriptPlatformInfo::internal_GetDebug(ScriptPlatformInfoBase* thisPtr)
  96. {
  97. return thisPtr->getPlatformInfo()->debug;
  98. }
  99. void ScriptPlatformInfo::internal_SetDebug(ScriptPlatformInfoBase* thisPtr, bool debug)
  100. {
  101. thisPtr->getPlatformInfo()->debug = debug;
  102. }
  103. ScriptWinPlatformInfo::ScriptWinPlatformInfo(MonoObject* instance)
  104. :ScriptObject(instance)
  105. {
  106. mPlatformInfo = bs_shared_ptr_new<WinPlatformInfo>();
  107. }
  108. void ScriptWinPlatformInfo::initRuntimeData()
  109. {
  110. metaData.scriptClass->addInternalCall("Internal_GetIcon", (void*)&ScriptWinPlatformInfo::internal_GetIcon);
  111. metaData.scriptClass->addInternalCall("Internal_SetIcon", (void*)&ScriptWinPlatformInfo::internal_SetIcon);
  112. metaData.scriptClass->addInternalCall("Internal_GetTitleText", (void*)&ScriptWinPlatformInfo::internal_GetTitleText);
  113. metaData.scriptClass->addInternalCall("Internal_SetTitleText", (void*)&ScriptWinPlatformInfo::internal_SetTitleText);
  114. }
  115. SPtr<WinPlatformInfo> ScriptWinPlatformInfo::getWinPlatformInfo() const
  116. {
  117. return std::static_pointer_cast<WinPlatformInfo>(mPlatformInfo);
  118. }
  119. MonoObject* ScriptWinPlatformInfo::create(const SPtr<WinPlatformInfo>& platformInfo)
  120. {
  121. MonoObject* managedInstance = metaData.scriptClass->createInstance();
  122. ScriptWinPlatformInfo* scriptObj = new (bs_alloc<ScriptWinPlatformInfo>()) ScriptWinPlatformInfo(managedInstance);
  123. scriptObj->mPlatformInfo = platformInfo;
  124. return managedInstance;
  125. }
  126. MonoObject* ScriptWinPlatformInfo::internal_GetIcon(ScriptWinPlatformInfo* thisPtr)
  127. {
  128. HTexture icon = thisPtr->getWinPlatformInfo()->icon;
  129. if (icon != nullptr)
  130. {
  131. ScriptRRefBase* scriptRRef = ScriptResourceManager::instance().getScriptRRef(icon);
  132. if(scriptRRef)
  133. return scriptRRef->getManagedInstance();
  134. }
  135. return nullptr;
  136. }
  137. void ScriptWinPlatformInfo::internal_SetIcon(ScriptWinPlatformInfo* thisPtr, ScriptRRefBase* textureRef)
  138. {
  139. HTexture icon;
  140. if (textureRef != nullptr)
  141. icon = static_resource_cast<Texture>(textureRef->getHandle());
  142. thisPtr->getWinPlatformInfo()->icon = icon;
  143. }
  144. MonoString* ScriptWinPlatformInfo::internal_GetTitleText(ScriptWinPlatformInfo* thisPtr)
  145. {
  146. WString titleText = thisPtr->getWinPlatformInfo()->titlebarText;
  147. return MonoUtil::wstringToMono(titleText);
  148. }
  149. void ScriptWinPlatformInfo::internal_SetTitleText(ScriptWinPlatformInfo* thisPtr, MonoString* text)
  150. {
  151. WString titleText = MonoUtil::monoToWString(text);
  152. thisPtr->getWinPlatformInfo()->titlebarText = titleText;
  153. }
  154. }