ActivationWindow.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import EditorEvents = require("../../editor/EditorEvents");
  2. import EditorUI = require("../EditorUI");
  3. import ModalWindow = require("../modal/ModalWindow");
  4. import ProgressModal = require("../modal/ProgressModal");
  5. class ActivationWidow extends ModalWindow {
  6. constructor() {
  7. super();
  8. this.init("Product Activation", "AtomicEditor/editor/ui/activation.tb.txt");
  9. this.licenseKeyEdit = <Atomic.UIEditField> this.getWidget("license_key");
  10. this.subscribeToEvent("LicenseActivationError", (eventData) => this.handleLicenseActivationError(eventData));
  11. this.subscribeToEvent("LicenseActivationSuccess", (eventData) => this.handleLicenseActivationSuccess(eventData));
  12. this.progressModal = new ProgressModal("Activation", "Activating, please wait...");
  13. }
  14. handleLicenseActivationError(ev) {
  15. this.progressModal.hide();
  16. EditorUI.showModalError("Activation Error",
  17. ev.message);
  18. }
  19. handleLicenseActivationSuccess(ev) {
  20. this.progressModal.hide();
  21. this.hide();
  22. EditorUI.getModelOps().showActivationSuccessWindow();
  23. }
  24. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  25. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  26. var id = ev.target.id;
  27. if (id == "quit") {
  28. this.sendEvent(EditorEvents.Quit);
  29. return true;
  30. } else if (id == "get_key") {
  31. var fileSystem = Atomic.getFileSystem();
  32. fileSystem.systemOpen("https://store.atomicgameengine.com/site");
  33. } else if (id == "activate") {
  34. var key = this.licenseKeyEdit.text.trim().toUpperCase();
  35. var licenseSystem = ToolCore.getLicenseSystem();
  36. if (!licenseSystem.validateKey(key)) {
  37. EditorUI.showModalError("Invalid Product Key",
  38. "The key entered is invalid\n\nProduct keys are in the form of ATOMIC-XXXX-XXXX-XXXX-XXXX");
  39. return true;
  40. }
  41. this.progressModal.show();
  42. licenseSystem.requestServerActivation(key);
  43. }
  44. }
  45. }
  46. progressModal:ProgressModal;
  47. licenseKeyEdit: Atomic.UIEditField;
  48. }
  49. export = ActivationWidow;