UIResourceOps.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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/AtomicEditor
  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/TBUI.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. TBUI* tbui = GetSubsystem<TBUI>();
  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. TBUI* tbui = GetSubsystem<TBUI>();
  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. TBUI* tbui = GetSubsystem<TBUI>();
  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. TBUI* tbui = GetSubsystem<TBUI>();
  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. }