EditModuleDialog.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. function EditModuleDialog::init(%this, %width, %height)
  2. {
  3. //Get the dialog contents
  4. %window = %this.getObject(0);
  5. %content = %window.getObject(0);
  6. %form = new GuiGridCtrl()
  7. {
  8. class = "EditorForm";
  9. extent = %width SPC %height;
  10. cellSizeX = %width;
  11. cellSizeY = 50;
  12. };
  13. %form.addListener(%this);
  14. %item = %form.addFormItem("Module Name", %width SPC 30);
  15. %this.moduleNameBox = %form.createTextEditItem(%item);
  16. %this.moduleNameBox.text = %this.module.moduleID;
  17. %item = %form.addFormItem("Description", %width SPC 30);
  18. %this.descriptionBox = %form.createTextEditItem(%item);
  19. %this.descriptionBox.text = %this.module.description;
  20. %item = %form.addFormItem("Version", %width SPC 30);
  21. %this.versionBox = %form.createTextEditItem(%item);
  22. %this.versionBox.inputMode = "number";
  23. %this.versionBox.text = %this.module.versionID;
  24. %item = %form.addFormItem("Build", %width SPC 30);
  25. %this.buildBox = %form.createTextEditItem(%item);
  26. %this.buildBox.inputMode = "number";
  27. %this.buildBox.text = %this.module.buildID;
  28. %item = %form.addFormItem("Type", %width SPC 30);
  29. %this.typeBox = %form.createTextEditItem(%item);
  30. %this.typeBox.text = %this.module.type;
  31. %item = %form.addFormItem("Author", %width SPC 30);
  32. %this.authorBox = %form.createTextEditItem(%item);
  33. %this.authorBox.text = %this.module.author;
  34. %content.add(%form);
  35. %this.feedback = new GuiControl()
  36. {
  37. HorizSizing = "right";
  38. VertSizing = "bottom";
  39. Position = "12 320";
  40. Extent = (%width - 24) SPC 80;
  41. text = "Saving changes to a module will require the module to be unloaded and will likely require the game to be restarted. Also, changing the name or version of a module may break dependencies. You will need to find and fix these.";
  42. textWrap = true;
  43. textExtend = true;
  44. };
  45. ThemeManager.setProfile(%this.feedback, "infoProfile");
  46. %this.cancelButton = new GuiButtonCtrl()
  47. {
  48. HorizSizing = "right";
  49. VertSizing = "bottom";
  50. Position = "278 450";
  51. Extent = "100 30";
  52. Text = "Cancel";
  53. Command = %this.getID() @ ".onClose();";
  54. };
  55. ThemeManager.setProfile(%this.cancelButton, "buttonProfile");
  56. %this.saveButton = new GuiButtonCtrl()
  57. {
  58. HorizSizing = "right";
  59. VertSizing = "bottom";
  60. Position = "388 448";
  61. Extent = "100 34";
  62. Text = "Save";
  63. Command = %this.getID() @ ".onSave();";
  64. };
  65. ThemeManager.setProfile(%this.saveButton, "primaryButtonProfile");
  66. %content.add(%this.feedback);
  67. %content.add(%this.cancelButton);
  68. %content.add(%this.saveButton);
  69. %this.validate();
  70. }
  71. function EditModuleDialog::onKeyPressed(%this, %textBox)
  72. {
  73. %this.validate();
  74. }
  75. function EditModuleDialog::onReturnPressed(%this, %textBox)
  76. {
  77. %this.onSave();
  78. }
  79. function EditModuleDialog::Validate(%this)
  80. {
  81. %this.createButton.active = false;
  82. %name = %this.moduleNameBox.getText();
  83. %desc = %this.descriptionBox.getText();
  84. %version = %this.versionBox.getText();
  85. %build = %this.buildBox.getText();
  86. %type = %this.typeBox.getText();
  87. %author = %this.authorBox.getText();
  88. if(%name $= "" || %version $= "" || %build $= "")
  89. {
  90. return false;
  91. }
  92. %this.moduleNameBox.text = stripChars(%name, " ");
  93. %this.saveButton.active = true;
  94. return true;
  95. }
  96. function EditModuleDialog::onSave(%this)
  97. {
  98. if(%this.validate())
  99. {
  100. %name = %this.moduleNameBox.getText();
  101. %desc = %this.descriptionBox.getText();
  102. %version = %this.versionBox.getText();
  103. %build = %this.buildBox.getText();
  104. %type = %this.typeBox.getText();
  105. %author = %this.authorBox.getText();
  106. %data = new ScriptObject()
  107. {
  108. moduleID = %name;
  109. description = %desc;
  110. versionID = %version;
  111. buildID = %build;
  112. type = %type;
  113. author = %author;
  114. };
  115. %this.postEvent("ModuleEdited", %data);
  116. %data.delete();
  117. %this.onClose();
  118. }
  119. }