ActivationWindow.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. import EditorEvents = require("editor/EditorEvents");
  23. import EditorUI = require("ui/EditorUI");
  24. import ModalWindow = require("../ModalWindow");
  25. import ProgressModal = require("../ProgressModal");
  26. class ActivationWindow extends ModalWindow {
  27. constructor() {
  28. super(true);
  29. this.init("Product Activation", "AtomicEditor/editor/ui/activation.tb.txt");
  30. this.licenseKeyEdit = <Atomic.UIEditField>this.getWidget("license_key");
  31. this.subscribeToEvent("LicenseActivationError", (eventData) => this.handleLicenseActivationError(eventData));
  32. this.subscribeToEvent("LicenseActivationSuccess", (eventData) => this.handleLicenseActivationSuccess(eventData));
  33. this.progressModal = new ProgressModal("Activation", "Activating, please wait...");
  34. if (ToolCore.licenseSystem.sourceBuild) {
  35. var message = "\nThis is a <color #76D6FF>development snapshot</color> of the Atomic Editor intended for testing new features.\n\n";
  36. message += "Please report issues to the Atomic Forums or GitHub issue tracker.";
  37. new Atomic.UIMessageWindow(this, "modal_error").show("Atomic Editor - Development Snapshot", message, Atomic.UI_MESSAGEWINDOW_SETTINGS_OK, true, 640, 260);
  38. }
  39. }
  40. handleLicenseActivationError(ev) {
  41. this.progressModal.hide();
  42. EditorUI.showModalError("Activation Error",
  43. ev.message);
  44. }
  45. handleLicenseActivationSuccess(ev) {
  46. this.progressModal.hide();
  47. this.hide();
  48. EditorUI.getModelOps().showActivationSuccessWindow();
  49. }
  50. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  51. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  52. var id = ev.target.id;
  53. if (id == "quit") {
  54. this.sendEvent("ExitRequested");
  55. return true;
  56. } else if (id == "get_key") {
  57. var fileSystem = Atomic.getFileSystem();
  58. fileSystem.systemOpen("https://store.atomicgameengine.com/site");
  59. } else if (id == "activate") {
  60. var key = this.licenseKeyEdit.text.trim().toUpperCase();
  61. var licenseSystem = ToolCore.getLicenseSystem();
  62. if (!licenseSystem.validateKey(key)) {
  63. EditorUI.showModalError("Invalid Product Key",
  64. "The key entered is invalid\n\nProduct keys are in the form of ATOMIC-XXXX-XXXX-XXXX-XXXX");
  65. return true;
  66. }
  67. this.progressModal.show();
  68. licenseSystem.requestServerActivation(key);
  69. }
  70. }
  71. }
  72. progressModal: ProgressModal;
  73. licenseKeyEdit: Atomic.UIEditField;
  74. }
  75. export = ActivationWindow;