UIResourceOps.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include <TurboBadger/tb_window.h>
  6. #include <TurboBadger/tb_editfield.h>
  7. #include <Atomic/Core/Context.h>
  8. #include <Atomic/UI/UI.h>
  9. #include "Resources/AEResourceOps.h"
  10. #include "UIResourceOps.h"
  11. namespace AtomicEditor
  12. {
  13. // UINewFolder------------------------------------------------
  14. UINewFolder::UINewFolder(Context* context):
  15. UIModalOpWindow(context)
  16. {
  17. UI* tbui = GetSubsystem<UI>();
  18. window_->SetText("New Folder");
  19. tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/resourcenewfolder.tb.txt");
  20. nameField_ = window_->GetContentRoot()->GetWidgetByIDAndType<TBEditField>(TBIDC("folder_name"));
  21. assert(nameField_);
  22. window_->ResizeToFitContent();
  23. Center();
  24. }
  25. UINewFolder::~UINewFolder()
  26. {
  27. }
  28. bool UINewFolder::OnEvent(const TBWidgetEvent &ev)
  29. {
  30. UIModalOps* ops = GetSubsystem<UIModalOps>();
  31. if (ev.type == EVENT_TYPE_CLICK)
  32. {
  33. if (ev.target->GetID() == TBIDC("create"))
  34. {
  35. TBStr text;
  36. nameField_->GetText(text);
  37. ResourceOps* rops = GetSubsystem<ResourceOps>();
  38. rops->HandleNewFolder(ops->GetResourcePath() + text.CStr(), true);
  39. ops->Hide();
  40. return true;
  41. }
  42. if (ev.target->GetID() == TBIDC("cancel"))
  43. {
  44. ops->Hide();
  45. return true;
  46. }
  47. }
  48. return false;
  49. }
  50. // UIResourceDelete------------------------------------------------
  51. UIResourceDelete::UIResourceDelete(Context* context):
  52. UIModalOpWindow(context)
  53. {
  54. UIModalOps* ops = GetSubsystem<UIModalOps>();
  55. UI* tbui = GetSubsystem<UI>();
  56. window_->SetText("Delete Resource");
  57. tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/resourcedelete.tb.txt");
  58. TBEditField* message = window_->GetContentRoot()->GetWidgetByIDAndType<TBEditField>(TBIDC("message"));
  59. String msg;
  60. message->SetText(msg.AppendWithFormat("Are you sure you want to delete resource:\n\n%s\n\nThis operation cannot be undone"
  61. ,ops->GetResourcePath().CString()).CString());
  62. window_->ResizeToFitContent();
  63. Center();
  64. }
  65. UIResourceDelete::~UIResourceDelete()
  66. {
  67. }
  68. bool UIResourceDelete::OnEvent(const TBWidgetEvent &ev)
  69. {
  70. UIModalOps* ops = GetSubsystem<UIModalOps>();
  71. if (ev.type == EVENT_TYPE_CLICK)
  72. {
  73. if (ev.target->GetID() == TBIDC("delete"))
  74. {
  75. ResourceOps* rops = GetSubsystem<ResourceOps>();
  76. rops->HandleResourceDelete(ops->GetResourcePath());
  77. ops->Hide();
  78. return true;
  79. }
  80. if (ev.target->GetID() == TBIDC("cancel"))
  81. {
  82. ops->Hide();
  83. return true;
  84. }
  85. }
  86. return false;
  87. }
  88. // UICreateComponent------------------------------------------------
  89. UICreateComponent::UICreateComponent(Context* context):
  90. UIModalOpWindow(context)
  91. {
  92. UI* tbui = GetSubsystem<UI>();
  93. window_->SetText("Create Javascript Component");
  94. tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
  95. nameField_ = window_->GetContentRoot()->GetWidgetByIDAndType<TBEditField>(TBIDC("component_name"));
  96. assert(nameField_);
  97. window_->ResizeToFitContent();
  98. Center();
  99. }
  100. UICreateComponent::~UICreateComponent()
  101. {
  102. }
  103. bool UICreateComponent::OnEvent(const TBWidgetEvent &ev)
  104. {
  105. UIModalOps* ops = GetSubsystem<UIModalOps>();
  106. if (ev.type == EVENT_TYPE_POINTER_MOVE)
  107. return false;
  108. if (ev.type == EVENT_TYPE_CLICK)
  109. {
  110. if (ev.target->GetID() == TBIDC("create"))
  111. {
  112. TBStr text;
  113. nameField_->GetText(text);
  114. ResourceOps* rops = GetSubsystem<ResourceOps>();
  115. rops->HandleCreateComponent(ops->GetResourcePath(), text.CStr(), true, true);
  116. ops->Hide();
  117. return true;
  118. }
  119. if (ev.target->GetID() == TBIDC("cancel"))
  120. {
  121. ops->Hide();
  122. return true;
  123. }
  124. }
  125. return false;
  126. }
  127. // UICreateScript------------------------------------------------
  128. UICreateScript::UICreateScript(Context* context):
  129. UIModalOpWindow(context)
  130. {
  131. UI* tbui = GetSubsystem<UI>();
  132. window_->SetText("Create Script");
  133. tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/resourcecreatescript.tb.txt");
  134. nameField_ = window_->GetContentRoot()->GetWidgetByIDAndType<TBEditField>(TBIDC("script_name"));
  135. assert(nameField_);
  136. window_->ResizeToFitContent();
  137. Center();
  138. }
  139. UICreateScript::~UICreateScript()
  140. {
  141. }
  142. bool UICreateScript::OnEvent(const TBWidgetEvent &ev)
  143. {
  144. UIModalOps* ops = GetSubsystem<UIModalOps>();
  145. if (ev.type == EVENT_TYPE_POINTER_MOVE)
  146. return false;
  147. if (ev.type == EVENT_TYPE_CLICK)
  148. {
  149. if (ev.target->GetID() == TBIDC("create"))
  150. {
  151. TBStr text;
  152. nameField_->GetText(text);
  153. ResourceOps* rops = GetSubsystem<ResourceOps>();
  154. rops->HandleCreateScript(ops->GetResourcePath(), text.CStr(), true, true);
  155. ops->Hide();
  156. return true;
  157. }
  158. if (ev.target->GetID() == TBIDC("cancel"))
  159. {
  160. ops->Hide();
  161. return true;
  162. }
  163. }
  164. return false;
  165. }
  166. // UICreateModule------------------------------------------------
  167. UICreateModule::UICreateModule(Context* context):
  168. UIModalOpWindow(context)
  169. {
  170. UI* tbui = GetSubsystem<UI>();
  171. window_->SetText("Create Module");
  172. tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/resourcecreatemodule.tb.txt");
  173. nameField_ = window_->GetContentRoot()->GetWidgetByIDAndType<TBEditField>(TBIDC("module_name"));
  174. assert(nameField_);
  175. window_->ResizeToFitContent();
  176. Center();
  177. }
  178. UICreateModule::~UICreateModule()
  179. {
  180. }
  181. bool UICreateModule::OnEvent(const TBWidgetEvent &ev)
  182. {
  183. UIModalOps* ops = GetSubsystem<UIModalOps>();
  184. if (ev.type == EVENT_TYPE_POINTER_MOVE)
  185. return false;
  186. if (ev.type == EVENT_TYPE_CLICK)
  187. {
  188. if (ev.target->GetID() == TBIDC("create"))
  189. {
  190. TBStr text;
  191. nameField_->GetText(text);
  192. ResourceOps* rops = GetSubsystem<ResourceOps>();
  193. rops->HandleCreateModule(ops->GetResourcePath(), text.CStr(), true, true);
  194. ops->Hide();
  195. return true;
  196. }
  197. if (ev.target->GetID() == TBIDC("cancel"))
  198. {
  199. ops->Hide();
  200. return true;
  201. }
  202. }
  203. return false;
  204. }
  205. // UICreateModule------------------------------------------------
  206. UICreate2DLevel::UICreate2DLevel(Context* context):
  207. UIModalOpWindow(context)
  208. {
  209. UI* tbui = GetSubsystem<UI>();
  210. window_->SetText("Create 2D Level");
  211. tbui->LoadResourceFile(window_->GetContentRoot(), "AtomicEditor/editor/ui/resourcecreate2dlevel.tb.txt");
  212. nameField_ = window_->GetContentRoot()->GetWidgetByIDAndType<TBEditField>(TBIDC("level_name"));
  213. assert(nameField_);
  214. window_->ResizeToFitContent();
  215. Center();
  216. }
  217. UICreate2DLevel::~UICreate2DLevel()
  218. {
  219. }
  220. bool UICreate2DLevel::OnEvent(const TBWidgetEvent &ev)
  221. {
  222. UIModalOps* ops = GetSubsystem<UIModalOps>();
  223. if (ev.type == EVENT_TYPE_POINTER_MOVE)
  224. return false;
  225. if (ev.type == EVENT_TYPE_CLICK)
  226. {
  227. if (ev.target->GetID() == TBIDC("create"))
  228. {
  229. TBStr text;
  230. nameField_->GetText(text);
  231. ResourceOps* rops = GetSubsystem<ResourceOps>();
  232. rops->HandleCreate2DLevel(ops->GetResourcePath(), text.CStr(), true, true);
  233. ops->Hide();
  234. return true;
  235. }
  236. if (ev.target->GetID() == TBIDC("cancel"))
  237. {
  238. ops->Hide();
  239. return true;
  240. }
  241. }
  242. return false;
  243. }
  244. }