main.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, 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
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell 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
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // Material Editor Written by Dave Calabrese and Travis Vroman of Gaslight Studios
  23. function initializeMaterialEditor()
  24. {
  25. echo(" % - Initializing Material Editor");
  26. // Load Preview Window
  27. exec("~/materialEditor/gui/guiMaterialPreviewWindow.ed.gui");
  28. // Load Properties Window
  29. exec("~/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui");
  30. // Load Client Scripts.
  31. exec("./scripts/materialEditor.ed.cs");
  32. exec("./scripts/materialEditorUndo.ed.cs");
  33. //exec("./gui/profiles.ed.cs");
  34. MaterialEditorPreviewWindow.setVisible( false );
  35. matEd_cubemapEditor.setVisible( false );
  36. matEd_addCubemapWindow.setVisible( false );
  37. MaterialEditorPropertiesWindow.setVisible( false );
  38. EditorGui.add( MaterialEditorPreviewWindow );
  39. EditorGui.add( matEd_cubemapEditor );
  40. EditorGui.add( matEd_addCubemapWindow );
  41. EditorGui.add( MaterialEditorPropertiesWindow );
  42. }
  43. function destroyMaterialEditor()
  44. {
  45. }
  46. // Material Editor
  47. function MaterialEditorPlugin::onWorldEditorStartup( %this )
  48. {
  49. // Add ourselves to the window menu.
  50. %accel = EditorGui.addToEditorsMenu( "Material Editor", "", MaterialEditorPlugin );
  51. // Add ourselves to the ToolsToolbar
  52. %tooltip = "Material Editor (" @ %accel @ ")";
  53. EditorGui.addToToolsToolbar( "MaterialEditorPlugin", "MaterialEditorPalette", expandFilename("tools/worldEditor/images/toolbar/matterial-editor"), %tooltip );
  54. //connect editor windows
  55. GuiWindowCtrl::attach( MaterialEditorPropertiesWindow, MaterialEditorPreviewWindow);
  56. %map = new ActionMap();
  57. %map.bindCmd( keyboard, "1", "EWorldEditorNoneModeBtn.performClick();", "" ); // Select
  58. %map.bindCmd( keyboard, "2", "EWorldEditorMoveModeBtn.performClick();", "" ); // Move
  59. %map.bindCmd( keyboard, "3", "EWorldEditorRotateModeBtn.performClick();", "" ); // Rotate
  60. %map.bindCmd( keyboard, "4", "EWorldEditorScaleModeBtn.performClick();", "" ); // Scale
  61. %map.bindCmd( keyboard, "f", "FitToSelectionBtn.performClick();", "" );// Fit Camera to Selection
  62. %map.bindCmd( keyboard, "z", "EditorGuiStatusBar.setCamera(\"Standard Camera\");", "" );// Free Camera
  63. %map.bindCmd( keyboard, "n", "ToggleNodeBar->renderHandleBtn.performClick();", "" );// Render Node
  64. %map.bindCmd( keyboard, "shift n", "ToggleNodeBar->renderTextBtn.performClick();", "" );// Render Node Text
  65. %map.bindCmd( keyboard, "alt s", "MaterialEditorGui.save();", "" );// Save Material
  66. //%map.bindCmd( keyboard, "delete", "ToggleNodeBar->renderTextBtn.performClick();", "" );// delete Material
  67. %map.bindCmd( keyboard, "g", "ESnapOptions-->GridSnapButton.performClick();" ); // Grid Snappping
  68. %map.bindCmd( keyboard, "t", "SnapToBar->objectSnapDownBtn.performClick();", "" );// Terrain Snapping
  69. %map.bindCmd( keyboard, "b", "SnapToBar-->objectSnapBtn.performClick();" ); // Soft Snappping
  70. %map.bindCmd( keyboard, "v", "EWorldEditorToolbar->boundingBoxColBtn.performClick();", "" );// Bounds Selection
  71. %map.bindCmd( keyboard, "o", "objectCenterDropdown->objectBoxBtn.performClick(); objectCenterDropdown.toggle();", "" );// Object Center
  72. %map.bindCmd( keyboard, "p", "objectCenterDropdown->objectBoundsBtn.performClick(); objectCenterDropdown.toggle();", "" );// Bounds Center
  73. %map.bindCmd( keyboard, "k", "objectTransformDropdown->objectTransformBtn.performClick(); objectTransformDropdown.toggle();", "" );// Object Transform
  74. %map.bindCmd( keyboard, "l", "objectTransformDropdown->worldTransformBtn.performClick(); objectTransformDropdown.toggle();", "" );// World Transform
  75. MaterialEditorPlugin.map = %map;
  76. MaterialEditorGui.fileSpec = "Torque Material Files (materials.cs)|materials.cs|All Files (*.*)|*.*|";
  77. MaterialEditorGui.textureFormats = "Image Files (*.png, *.jpg, *.dds, *.bmp, *.gif, *.jng. *.tga)|*.png;*.jpg;*.dds;*.bmp;*.gif;*.jng;*.tga|All Files (*.*)|*.*|";
  78. MaterialEditorGui.modelFormats = "DTS Files (*.dts)|*.dts";
  79. MaterialEditorGui.lastTexturePath = "";
  80. MaterialEditorGui.lastTextureFile = "";
  81. MaterialEditorGui.lastModelPath = "";
  82. MaterialEditorGui.lastModelFile = "";
  83. MaterialEditorGui.currentMaterial = "";
  84. MaterialEditorGui.lastMaterial = "";
  85. MaterialEditorGui.currentCubemap = "";
  86. MaterialEditorGui.currentObject = "";
  87. MaterialEditorGui.livePreview = "1";
  88. MaterialEditorGui.currentLayer = "0";
  89. MaterialEditorGui.currentMode = "Material";
  90. MaterialEditorGui.currentMeshMode = "EditorShape";
  91. new ArrayObject(UnlistedCubemaps);
  92. UnlistedCubemaps.add( "unlistedCubemaps", matEdCubeMapPreviewMat );
  93. UnlistedCubemaps.add( "unlistedCubemaps", WarnMatCubeMap );
  94. //MaterialEditor persistence manager
  95. new PersistenceManager(matEd_PersistMan);
  96. }
  97. function MaterialEditorPlugin::onActivated( %this )
  98. {
  99. if($gfx::wireframe){
  100. $wasInWireFrameMode = true;
  101. $gfx::wireframe = false;
  102. }else{
  103. $wasInWireFrameMode = false;
  104. }
  105. advancedTextureMapsRollout.Expanded = false;
  106. materialAnimationPropertiesRollout.Expanded = false;
  107. materialAdvancedPropertiesRollout.Expanded = false;
  108. WorldEditorPlugin.onActivated();
  109. EditorGui-->MatEdPropertiesWindow.setVisible( true );
  110. EditorGui-->MatEdPreviewWindow.setVisible( true );
  111. EditorGui-->WorldEditorToolbar.setVisible( true );
  112. MaterialEditorGui.currentObject = $Tools::materialEditorList;
  113. // Execute the back end scripts that actually do the work.
  114. MaterialEditorGui.open();
  115. %this.map.push();
  116. Parent::onActivated(%this);
  117. }
  118. function MaterialEditorPlugin::onEditMenuSelect( %this, %editMenu )
  119. {
  120. WorldEditorPlugin.onEditMenuSelect( %editMenu );
  121. }
  122. function MaterialEditorPlugin::onDeactivated( %this )
  123. {
  124. if($wasInWireFrameMode)
  125. $gfx::wireframe = true;
  126. WorldEditorPlugin.onDeactivated();
  127. MaterialEditorGui.quit();
  128. EditorGui-->MatEdPropertiesWindow.setVisible( false );
  129. EditorGui-->MatEdPreviewWindow.setVisible( false );
  130. EditorGui-->WorldEditorToolbar.setVisible( false );
  131. %this.map.pop();
  132. Parent::onDeactivated(%this);
  133. }