UIResourceOps.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. import EditorEvents = require("editor/EditorEvents");
  8. import EditorUI = require("../EditorUI");
  9. import ModalWindow = require("./ModalWindow");
  10. import ResourceOps = require("resources/ResourceOps");
  11. export class ResourceDelete extends ModalWindow {
  12. constructor(asset: ToolCore.Asset) {
  13. super();
  14. this.asset = asset;
  15. this.init("Delete Resource", "AtomicEditor/editor/ui/resourcedelete.tb.txt");
  16. var message = <Atomic.UIEditField>this.getWidget("message");
  17. var text = "Are you sure you want to delete resource:\n\n";
  18. text += asset.path;
  19. text += "\n\nThis operation cannot be undone";
  20. message.text = text;
  21. this.resizeToFitContent();
  22. this.center();
  23. }
  24. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  25. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  26. var id = ev.target.id;
  27. if (id == "delete") {
  28. this.hide();
  29. var db = ToolCore.getAssetDatabase();
  30. db.deleteAsset(this.asset);
  31. return true;
  32. }
  33. if (id == "cancel") {
  34. this.hide();
  35. return true;
  36. }
  37. }
  38. }
  39. asset: ToolCore.Asset;
  40. }
  41. export class CreateFolder extends ModalWindow {
  42. constructor(resourcePath: string) {
  43. super();
  44. this.resourcePath = resourcePath;
  45. this.init("New Folder", "AtomicEditor/editor/ui/resourcenewfolder.tb.txt");
  46. this.nameField = <Atomic.UIEditField>this.getWidget("folder_name");
  47. }
  48. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  49. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  50. var id = ev.target.id;
  51. if (id == "create") {
  52. var resourcePath = Atomic.addTrailingSlash(this.resourcePath) + this.nameField.text;
  53. if (ResourceOps.CreateNewFolder(resourcePath)) {
  54. this.hide();
  55. }
  56. return true;
  57. }
  58. if (id == "cancel") {
  59. this.hide();
  60. return true;
  61. }
  62. }
  63. }
  64. resourcePath: string;
  65. nameField: Atomic.UIEditField;
  66. }
  67. export class CreateComponent extends ModalWindow {
  68. constructor(resourcePath: string) {
  69. super();
  70. this.resourcePath = resourcePath;
  71. this.init("New Component", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
  72. this.nameField = <Atomic.UIEditField>this.getWidget("component_name");
  73. }
  74. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  75. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  76. var id = ev.target.id;
  77. if (id == "create") {
  78. var componentName = this.nameField.text;
  79. var outputFile = Atomic.addTrailingSlash(this.resourcePath) + componentName;
  80. if (outputFile.indexOf(".js") == -1) outputFile += ".js";
  81. if (ResourceOps.CreateNewComponent(outputFile, componentName)) {
  82. this.hide();
  83. this.sendEvent(EditorEvents.EditResource, { path: outputFile });
  84. }
  85. return true;
  86. }
  87. if (id == "cancel") {
  88. this.hide();
  89. return true;
  90. }
  91. }
  92. }
  93. resourcePath: string;
  94. nameField: Atomic.UIEditField;
  95. }
  96. export class CreateScript extends ModalWindow {
  97. constructor(resourcePath: string) {
  98. super();
  99. this.resourcePath = resourcePath;
  100. this.init("New Script", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
  101. this.nameField = <Atomic.UIEditField>this.getWidget("component_name");
  102. }
  103. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  104. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  105. var id = ev.target.id;
  106. if (id == "create") {
  107. var scriptName = this.nameField.text;
  108. var outputFile = Atomic.addTrailingSlash(this.resourcePath) + scriptName;
  109. if (outputFile.indexOf(".js") == -1) outputFile += ".js";
  110. if (ResourceOps.CreateNewScript(outputFile, scriptName)) {
  111. this.hide();
  112. this.sendEvent(EditorEvents.EditResource, { path: outputFile });
  113. }
  114. return true;
  115. }
  116. if (id == "cancel") {
  117. this.hide();
  118. return true;
  119. }
  120. }
  121. }
  122. resourcePath: string;
  123. nameField: Atomic.UIEditField;
  124. }
  125. export class CreateScene extends ModalWindow {
  126. constructor(resourcePath: string) {
  127. super();
  128. this.resourcePath = resourcePath;
  129. this.init("New Scene", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
  130. this.nameField = <Atomic.UIEditField>this.getWidget("component_name");
  131. }
  132. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  133. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  134. var id = ev.target.id;
  135. if (id == "create") {
  136. var sceneName = this.nameField.text;
  137. var outputFile = Atomic.addTrailingSlash(this.resourcePath) + sceneName;
  138. if (outputFile.indexOf(".scene") == -1) outputFile += ".scene";
  139. if (ResourceOps.CreateNewScene(outputFile, sceneName)) {
  140. this.hide();
  141. this.sendEvent(EditorEvents.EditResource, { path: outputFile });
  142. }
  143. return true;
  144. }
  145. if (id == "cancel") {
  146. this.hide();
  147. return true;
  148. }
  149. }
  150. }
  151. resourcePath: string;
  152. nameField: Atomic.UIEditField;
  153. }
  154. export class CreateMaterial extends ModalWindow {
  155. constructor(resourcePath: string) {
  156. super();
  157. this.resourcePath = resourcePath;
  158. this.init("New Material", "AtomicEditor/editor/ui/resourcecreatecomponent.tb.txt");
  159. this.nameField = <Atomic.UIEditField>this.getWidget("component_name");
  160. }
  161. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  162. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  163. var id = ev.target.id;
  164. if (id == "create") {
  165. var materialName = this.nameField.text;
  166. var outputFile = Atomic.addTrailingSlash(this.resourcePath) + materialName;
  167. if (outputFile.indexOf(".material") == -1) outputFile += ".material";
  168. if (ResourceOps.CreateNewMaterial(outputFile, materialName)) {
  169. this.hide();
  170. this.sendEvent(EditorEvents.EditResource, { path: outputFile });
  171. }
  172. return true;
  173. }
  174. if (id == "cancel") {
  175. this.hide();
  176. return true;
  177. }
  178. }
  179. }
  180. resourcePath: string;
  181. nameField: Atomic.UIEditField;
  182. }
  183. export class RenameAsset extends ModalWindow {
  184. constructor(asset: ToolCore.Asset) {
  185. super();
  186. this.asset = asset;
  187. this.init("Rename Resource", "AtomicEditor/editor/ui/renameasset.tb.txt");
  188. var currentName = <Atomic.UITextField>this.getWidget("current_name");
  189. this.nameEdit = <Atomic.UIEditField>this.getWidget("new_name");
  190. currentName.text = asset.name;
  191. this.nameEdit.text = asset.name;
  192. this.resizeToFitContent();
  193. this.center();
  194. }
  195. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  196. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  197. var id = ev.target.id;
  198. if (id == "rename") {
  199. this.hide();
  200. if (this.asset.name != this.nameEdit.text)
  201. this.asset.rename(this.nameEdit.text);
  202. return true;
  203. }
  204. if (id == "cancel") {
  205. this.hide();
  206. return true;
  207. }
  208. }
  209. }
  210. nameEdit: Atomic.UIEditField;
  211. asset: ToolCore.Asset;
  212. }