SnapSettingsWindow.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 ModalWindow = require("./ModalWindow");
  23. class SnapSettingsWindow extends ModalWindow {
  24. constructor() {
  25. super();
  26. this.init("Snap Settings", "AtomicEditor/editor/ui/snapsettings.tb.txt");
  27. this.transXEditField = <Atomic.UIEditField>this.getWidget("trans_x");
  28. this.transYEditField = <Atomic.UIEditField>this.getWidget("trans_y");
  29. this.transZEditField = <Atomic.UIEditField>this.getWidget("trans_z");
  30. this.rotateEditField = <Atomic.UIEditField>this.getWidget("rotation");
  31. this.scaleEditField = <Atomic.UIEditField>this.getWidget("scale");
  32. this.refreshWidgets();
  33. }
  34. apply() {
  35. var userPrefs = ToolCore.toolSystem.project.userPrefs;
  36. userPrefs.snapTranslationX = Number(this.transXEditField.text);
  37. userPrefs.snapTranslationY = Number(this.transYEditField.text);
  38. userPrefs.snapTranslationZ = Number(this.transZEditField.text);
  39. userPrefs.snapRotation = Number(this.rotateEditField.text);
  40. userPrefs.snapScale = Number(this.scaleEditField.text);
  41. ToolCore.toolSystem.project.saveUserPrefs();
  42. }
  43. refreshWidgets() {
  44. var userPrefs = ToolCore.toolSystem.project.userPrefs;
  45. this.transXEditField.text = parseFloat(userPrefs.snapTranslationX.toFixed(5)).toString();
  46. this.transYEditField.text = parseFloat(userPrefs.snapTranslationY.toFixed(5)).toString();
  47. this.transZEditField.text = parseFloat(userPrefs.snapTranslationZ.toFixed(5)).toString();
  48. this.rotateEditField.text = parseFloat(userPrefs.snapRotation.toFixed(5)).toString();
  49. this.scaleEditField.text = parseFloat(userPrefs.snapScale.toFixed(5)).toString();
  50. }
  51. handleWidgetEvent(ev: Atomic.UIWidgetEvent) {
  52. if (ev.type == Atomic.UI_EVENT_TYPE_CLICK) {
  53. var id = ev.target.id;
  54. if (id == "apply") {
  55. this.apply();
  56. this.hide();
  57. return true;
  58. }
  59. if (id == "cancel") {
  60. this.hide();
  61. return true;
  62. }
  63. }
  64. }
  65. transXEditField: Atomic.UIEditField;
  66. transYEditField: Atomic.UIEditField;
  67. transZEditField: Atomic.UIEditField;
  68. rotateEditField: Atomic.UIEditField;
  69. scaleEditField: Atomic.UIEditField;
  70. }
  71. export = SnapSettingsWindow;