particleEditorUndo.ed.tscript 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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. //=============================================================================================
  23. // ParticleEditor.
  24. //=============================================================================================
  25. //---------------------------------------------------------------------------------------------
  26. function ParticleEditor::createUndo( %this, %class, %desc )
  27. {
  28. pushInstantGroup();
  29. %action = new UndoScriptAction()
  30. {
  31. class = %class;
  32. superClass = BaseParticleEdAction;
  33. actionName = %desc;
  34. };
  35. popInstantGroup();
  36. return %action;
  37. }
  38. //---------------------------------------------------------------------------------------------
  39. function ParticleEditor::submitUndo( %this, %action )
  40. {
  41. %action.addToManager( Editor.getUndoManager() );
  42. }
  43. //=============================================================================================
  44. // BaseParticleEdAction.
  45. //=============================================================================================
  46. //---------------------------------------------------------------------------------------------
  47. function BaseParticleEdAction::sync( %this )
  48. {
  49. // Sync particle state.
  50. if( isObject( %this.particle ) )
  51. {
  52. %this.particle.reload();
  53. PE_ParticleEditor.guiSync();
  54. if( %this.particle.getId() == PE_ParticleEditor.currParticle.getId() )
  55. PE_ParticleEditor.setParticleDirty();
  56. }
  57. // Sync emitter state.
  58. if( isObject( %this.emitter ) )
  59. {
  60. %this.emitter.reload();
  61. PE_EmitterEditor.guiSync();
  62. if( %this.emitter.getId() == PE_EmitterEditor.currEmitter.getId() )
  63. PE_EmitterEditor.setEmitterDirty();
  64. }
  65. }
  66. //---------------------------------------------------------------------------------------------
  67. function BaseParticleEdAction::redo( %this )
  68. {
  69. %this.sync();
  70. }
  71. //---------------------------------------------------------------------------------------------
  72. function BaseParticleEdAction::undo( %this )
  73. {
  74. %this.sync();
  75. }
  76. //=============================================================================================
  77. // ActionRenameEmitter.
  78. //=============================================================================================
  79. //---------------------------------------------------------------------------------------------
  80. //TODO
  81. //=============================================================================================
  82. // ActionCreateNewEmitter.
  83. //=============================================================================================
  84. //---------------------------------------------------------------------------------------------
  85. function ActionCreateNewEmitter::redo( %this )
  86. {
  87. %emitter = %this.emitter;
  88. // Assign name.
  89. %emitter.name = %this.emitterName;
  90. // Remove from unlisted.
  91. PE_UnlistedEmitters.remove( %emitter );
  92. // Drop it in the dropdown and select it.
  93. %popup = PEE_EmitterSelector;
  94. %popup.add( %emitter.getName(), %emitter.getId() );
  95. %popup.sort();
  96. %popup.setSelected( %emitter.getId() );
  97. // Sync up.
  98. Parent::redo( %this );
  99. }
  100. //---------------------------------------------------------------------------------------------
  101. function ActionCreateNewEmitter::undo( %this )
  102. {
  103. %emitter = %this.emitter;
  104. // Prevent a save dialog coming up on the emitter.
  105. if( %emitter == PE_EmitterEditor.currEmitter )
  106. PE_EmitterEditor.setEmitterNotDirty();
  107. // Add to unlisted.
  108. PE_UnlistedEmitters.add( %emitter );
  109. // Remove it from in the dropdown and select prev emitter.
  110. %popup = PEE_EmitterSelector;
  111. if( isObject( %this.prevEmitter ) )
  112. %popup.setSelected( %this.prevEmitter.getId() );
  113. else
  114. %popup.setFirstSelected();
  115. %popup.clearEntry( %emitter.getId() );
  116. // Unassign name.
  117. %this.emitterName = %emitter.name;
  118. %emitter.name = "";
  119. // Sync up.
  120. Parent::undo( %this );
  121. }
  122. //=============================================================================================
  123. // ActionDeleteEmitter.
  124. //=============================================================================================
  125. //---------------------------------------------------------------------------------------------
  126. function ActionDeleteEmitter::redo( %this )
  127. {
  128. %emitter = %this.emitter;
  129. // Unassign name.
  130. %this.emitterName = %emitter.name;
  131. %emitter.name = "";
  132. // Add to unlisted.
  133. PE_UnlistedEmitters.add( %emitter );
  134. // Remove from file.
  135. if( %emitter.getFileName() !$= ""
  136. && %emitter.getFilename() !$= "tools/particleEditor/particleEmitterEditor.ed." @ $TorqueScriptFileExtension )
  137. PE_EmitterSaver.removeObjectFromFile( %emitter );
  138. // Select DefaultEmitter or first in list.
  139. %popup = PEE_EmitterSelector_Control-->PopUpMenu;
  140. %popup.setFirstSelected();
  141. // Remove from dropdown.
  142. %popup.clearEntry( %emitter );
  143. // Sync up.
  144. Parent::redo( %this );
  145. }
  146. //---------------------------------------------------------------------------------------------
  147. function ActionDeleteEmitter::undo( %this )
  148. {
  149. %emitter = %this.emitter;
  150. // Re-assign name.
  151. %emitter.name = %this.emitterName;
  152. // Remove from unlisted.
  153. PE_UnlistedEmitters.remove( %emitter );
  154. // Resave to file.
  155. if( %this.emitterFname !$= ""
  156. && %this.emitterFname !$= "tools/particleEditor/particleEmitterEditor.ed.gui" )
  157. {
  158. PE_EmitterSaver.setDirty( %emitter, %this.emitterFname );
  159. PE_EmitterSaver.saveDirty();
  160. }
  161. // Add it to the dropdown and selet it.
  162. %popup = PEE_EmitterSelector_Control-->PopUpMenu;
  163. %popup.add( %emitter.getName(), %emitter.getId() );
  164. %popup.sort();
  165. %popup.setSelected( %emitter.getId() );
  166. // Sync up.
  167. Parent::undo( %this );
  168. }
  169. //=============================================================================================
  170. // ActionUpdateActiveEmitter.
  171. //=============================================================================================
  172. //---------------------------------------------------------------------------------------------
  173. function ActionUpdateActiveEmitter::redo( %this )
  174. {
  175. %emitter = %this.emitter;
  176. %emitter.setFieldValue( %this.field, %this.newValue );
  177. Parent::redo( %this );
  178. }
  179. //---------------------------------------------------------------------------------------------
  180. function ActionUpdateActiveEmitter::undo( %this )
  181. {
  182. %emitter = %this.emitter;
  183. %emitter.setFieldValue( %this.field, %this.oldValue );
  184. Parent::undo( %this );
  185. }
  186. //=============================================================================================
  187. // ActionUpdateActiveEmitterLifeFields.
  188. //=============================================================================================
  189. //---------------------------------------------------------------------------------------------
  190. function ActionUpdateActiveEmitterLifeFields::redo( %this )
  191. {
  192. %emitter = %this.emitter;
  193. %emitter.lifetimeMS = %this.newValueLifetimeMS;
  194. %emitter.lifetimeVarianceMS = %this.newValueLifetimeVarianceMS;
  195. Parent::redo( %this );
  196. }
  197. //---------------------------------------------------------------------------------------------
  198. function ActionUpdateActiveEmitterLifeFields::undo( %this )
  199. {
  200. %emitter = %this.emitter;
  201. %emitter.lifetimeMS = %this.oldValueLifetimeMS;
  202. %emitter.lifetimeVarianceMS = %this.oldValueLifetimeVarianceMS;
  203. Parent::undo( %this );
  204. }
  205. //=============================================================================================
  206. // ActionUpdateActiveEmitterAmountFields.
  207. //=============================================================================================
  208. //---------------------------------------------------------------------------------------------
  209. function ActionUpdateActiveEmitterAmountFields::redo( %this )
  210. {
  211. %emitter = %this.emitter;
  212. %emitter.ejectionPeriodMS = %this.newValueEjectionPeriodMS;
  213. %emitter.periodVarianceMS = %this.newValuePeriodVarianceMS;
  214. Parent::redo( %this );
  215. }
  216. //---------------------------------------------------------------------------------------------
  217. function ActionUpdateActiveEmitterAmountFields::undo( %this )
  218. {
  219. %emitter = %this.emitter;
  220. %emitter.ejectionPeriodMS = %this.oldValueEjectionPeriodMS;
  221. %emitter.periodVarianceMS = %this.oldValuePeriodVarianceMS;
  222. Parent::undo( %this );
  223. }
  224. //=============================================================================================
  225. // ActionUpdateActiveEmitterSpeedFields.
  226. //=============================================================================================
  227. //---------------------------------------------------------------------------------------------
  228. function ActionUpdateActiveEmitterSpeedFields::redo( %this )
  229. {
  230. %emitter = %this.emitter;
  231. %emitter.ejectionVelocity = %this.newValueEjectionVelocity;
  232. %emitter.velocityVariance = %this.newValueVelocityVariance;
  233. Parent::redo( %this );
  234. }
  235. //---------------------------------------------------------------------------------------------
  236. function ActionUpdateActiveEmitterSpeedFields::undo( %this )
  237. {
  238. %emitter = %this.emitter;
  239. %emitter.ejectionVelocity = %this.oldValueEjectionVelocity;
  240. %emitter.velocityVariance = %this.oldValueVelocityVariance;
  241. Parent::undo( %this );
  242. }
  243. //=============================================================================================
  244. // ActionCreateNewParticle.
  245. //=============================================================================================
  246. //---------------------------------------------------------------------------------------------
  247. function ActionCreateNewParticle::redo( %this )
  248. {
  249. %particle = %this.particle.getName();
  250. %particleId = %this.particle.getId();
  251. %particleIndex = %this.particleIndex;
  252. %emitter = %this.emitter;
  253. // Remove from unlisted.
  254. PE_UnlistedParticles.remove( %particleId );
  255. // Add it to the dropdown.
  256. PEP_ParticleSelector.add( %particle, %particleId );
  257. PEP_ParticleSelector.sort();
  258. PEP_ParticleSelector.setSelected( %particleId, false );
  259. // Add particle to dropdowns in the emitter editor.
  260. for( %i = 1; %i < 5; %i ++ )
  261. {
  262. %emitterParticle = "PEE_EmitterParticle" @ %i;
  263. %popup = %emitterParticle-->PopupMenu;
  264. %popup.add( %particle, %particleId );
  265. %popup.sort();
  266. if( %i == %particleIndex + 1 )
  267. %popup.setSelected( %particleId );
  268. }
  269. // Sync up.
  270. PE_ParticleEditor.loadNewParticle();
  271. Parent::redo( %this );
  272. }
  273. //---------------------------------------------------------------------------------------------
  274. function ActionCreateNewParticle::undo( %this )
  275. {
  276. %particle = %this.particle.getName();
  277. %particleId = %this.particle.getId();
  278. %emitter = %this.emitter;
  279. // Add to unlisted.
  280. PE_UnlistedParticles.add( %particleId );
  281. // Remove from dropdown.
  282. PEP_ParticleSelector.clearEntry( %particleId );
  283. PEP_ParticleSelector.setFirstSelected( false );
  284. // Remove from particle dropdowns in emitter editor.
  285. for( %i = 1; %i < 5; %i ++ )
  286. {
  287. %emitterParticle = "PEE_EmitterParticle" @ %i;
  288. %popup = %emitterParticle-->PopUpMenu;
  289. if( %popup.getSelected() == %particleId )
  290. %popup.setSelected( %this.prevParticle );
  291. %popup.clearEntry( %particleId );
  292. }
  293. // Sync up.
  294. PE_ParticleEditor.loadNewParticle();
  295. Parent::undo( %this );
  296. }
  297. //=============================================================================================
  298. // ActionDeleteParticle.
  299. //=============================================================================================
  300. //---------------------------------------------------------------------------------------------
  301. function ActionDeleteParticle::redo( %this )
  302. {
  303. %particle = %this.particle.getName();
  304. %particleId = %this.particle.getId();
  305. %emitter = %this.emitter;
  306. // Add to unlisted.
  307. PE_UnlistedParticles.add( %particleId );
  308. // Remove from file.
  309. if( %particle.getFileName() !$= ""
  310. && %particle.getFilename() !$= "tools/particleEditor/particleParticleEditor.ed." @ $TorqueScriptFileExtension )
  311. PE_ParticleSaver.removeObjectFromFile( %particleId );
  312. // Remove from dropdown.
  313. PEP_ParticleSelector.clearEntry( %particleId );
  314. PEP_ParticleSelector.setFirstSelected();
  315. // Remove from particle selectors in emitter.
  316. for( %i = 1; %i < 5; %i ++ )
  317. {
  318. %emitterParticle = "PEE_EmitterParticle" @ %i;
  319. %popup = %emitterParticle-->PopUpMenu;
  320. if( %popup.getSelected() == %particleId )
  321. {
  322. %this.particleIndex = %i - 1;
  323. %popup.setSelected( 0 ); // Select "None".
  324. }
  325. %popup.clearEntry( %particleId );
  326. }
  327. // Sync up.
  328. PE_ParticleEditor.loadNewParticle();
  329. Parent::redo( %this );
  330. }
  331. //---------------------------------------------------------------------------------------------
  332. function ActionDeleteParticle::undo( %this )
  333. {
  334. %particle = %this.particle.getName();
  335. %particleId = %this.particle.getId();
  336. %particleIndex = %this.particleIndex;
  337. %emitter = %this.emitter;
  338. // Remove from unlisted.
  339. PE_UnlistedParticles.remove( %particleId );
  340. // Resave to file.
  341. if( %particle.getFilename() !$= ""
  342. && %particle.getFilename() !$= "tools/particleEditor/particleParticleEditor.ed.gui" )
  343. {
  344. PE_ParticleSaver.setDirty( %particle );
  345. PE_ParticleSaver.saveDirty();
  346. }
  347. // Add to dropdown.
  348. PEP_ParticleSelector.add( %particle, %particleId );
  349. PEP_ParticleSelector.sort();
  350. PEP_ParticleSelector.setSelected( %particleId );
  351. // Add particle to dropdowns in the emitter editor.
  352. for( %i = 1; %i < 5; %i ++ )
  353. {
  354. %emitterParticle = "PEE_EmitterParticle" @ %i;
  355. %popup = %emitterParticle-->PopUpMenu;
  356. %popup.add( %particle, %particleId );
  357. %popup.sort();
  358. if( %i == %particleIndex + 1 )
  359. %popup.setSelected( %particleId );
  360. }
  361. // Sync up.
  362. PE_ParticleEditor.loadNewParticle();
  363. Parent::undo( %This );
  364. }
  365. //=============================================================================================
  366. // ActionUpdateActiveParticle.
  367. //=============================================================================================
  368. //---------------------------------------------------------------------------------------------
  369. function ActionUpdateActiveParticle::redo( %this )
  370. {
  371. %particle = %this.particle;
  372. %particle.setFieldValue( %this.field, %this.newValue );
  373. Parent::redo( %this );
  374. }
  375. function ActionUpdateActiveParticle::undo( %this )
  376. {
  377. %particle = %this.particle;
  378. %particle.setFieldValue( %this.field, %this.oldValue );
  379. Parent::undo( %this );
  380. }
  381. //=============================================================================================
  382. // ActionUpdateActiveParticleLifeFields.
  383. //=============================================================================================
  384. //---------------------------------------------------------------------------------------------
  385. function ActionUpdateActiveParticleLifeFields::redo( %this )
  386. {
  387. %particle = %this.particle;
  388. %particle.lifetimeMS = %this.newValueLifetimeMS;
  389. %particle.lifetimeVarianceMS = %this.newValueLifetimeVarianceMS;
  390. Parent::redo( %this );
  391. }
  392. //---------------------------------------------------------------------------------------------
  393. function ActionUpdateActiveParticleLifeFields::undo( %this )
  394. {
  395. %particle = %this.particle;
  396. %particle.lifetimeMS = %this.oldValueLifetimeMS;
  397. %particle.lifetimeVarianceMS = %this.oldValueLifetimeVarianceMS;
  398. Parent::undo( %this );
  399. }
  400. //=============================================================================================
  401. // ActionUpdateActiveParticleSpinFields.
  402. //=============================================================================================
  403. //---------------------------------------------------------------------------------------------
  404. function ActionUpdateActiveParticleSpinFields::redo( %this )
  405. {
  406. %particle = %this.particle;
  407. %particle.spinRandomMax = %this.newValueSpinRandomMax;
  408. %particle.spinRandomMin = %this.newValueSpinRandomMin;
  409. Parent::redo( %this );
  410. }
  411. //---------------------------------------------------------------------------------------------
  412. function ActionUpdateActiveParticleSpinFields::undo( %this )
  413. {
  414. %particle = %this.particle;
  415. %particle.spinRandomMax = %this.oldValueSpinRandomMax;
  416. %particle.spinRandomMin = %this.oldValueSpinRandomMin;
  417. Parent::undo( %this );
  418. }