EditContext.hx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package hide.prefab;
  2. import hrt.prefab.Prefab;
  3. import hrt.prefab.Context;
  4. class EditContext {
  5. public var rootContext : Context;
  6. #if editor
  7. var updates : Array<Float->Void> = [];
  8. public var ide(get,never) : hide.Ide;
  9. public var scene : hide.comp.Scene;
  10. public var properties : hide.comp.PropsEditor;
  11. public var cleanups : Array<Void->Void>;
  12. function get_ide() return hide.Ide.inst;
  13. public function onChange(p : Prefab, propName : String) {
  14. var ctx = getContext(p);
  15. scene.setCurrent();
  16. if(ctx != null) {
  17. p.updateInstance(ctx, propName);
  18. var parent = p.parent;
  19. while( parent != null ) {
  20. var pr = parent.getHideProps();
  21. if( pr.onChildUpdate != null ) pr.onChildUpdate(p);
  22. parent = parent.parent;
  23. }
  24. }
  25. for( ctx2 in rootContext.shared.getContexts(p) )
  26. if( ctx2 != ctx )
  27. p.updateInstance(ctx2, propName);
  28. }
  29. public function getCurrentProps( p : Prefab ) : Element {
  30. throw "Not implemented";
  31. return null;
  32. }
  33. public function addUpdate( f : (dt:Float) -> Void ) {
  34. updates.push(f);
  35. }
  36. public function removeUpdate( f : (dt:Float) -> Void ) {
  37. for( f2 in updates )
  38. if( Reflect.compareMethods(f,f2) ) {
  39. updates.remove(f2);
  40. break;
  41. }
  42. }
  43. public function makeChanges( p : Prefab, f : Void -> Void ) @:privateAccess {
  44. var current = p.save();
  45. properties.undo.change(Custom(function(b) {
  46. var old = p.save();
  47. p.load(current);
  48. current = old;
  49. rebuildProperties();
  50. onChange(p, null);
  51. }));
  52. f();
  53. rebuildProperties();
  54. onChange(p, null);
  55. }
  56. #end
  57. public function new(ctx) {
  58. this.rootContext = ctx;
  59. }
  60. public function getContext( p : Prefab ) {
  61. return rootContext.shared.contexts.get(p);
  62. }
  63. /**
  64. Converts screen mouse coordinates into projection into ground.
  65. If "forPrefab" is used, only this prefab is taken into account for ground consideration (self painting)
  66. **/
  67. public function screenToGround( x : Float, y : Float, ?forPrefab : Prefab ) : h3d.col.Point {
  68. throw "Not implemented";
  69. return null;
  70. }
  71. /**
  72. Similar to screenToGround but based on 3D coordinates instead of screen ones
  73. **/
  74. public function positionToGroundZ( x : Float, y : Float, ?forPrefab : Prefab ) : Float {
  75. throw "Not implemented";
  76. return null;
  77. }
  78. /**
  79. Rebuild the edit window
  80. **/
  81. public function rebuildProperties() {
  82. }
  83. /**
  84. Force rebuilding makeInstance for the given hierarchy
  85. **/
  86. public function rebuildPrefab( p : Prefab ) {
  87. }
  88. public function getNamedObjects( ?exclude : h3d.scene.Object ) {
  89. var out = [];
  90. function getJoint(path:Array<String>,j:h3d.anim.Skin.Joint) {
  91. path.push(j.name);
  92. out.push(path.join("."));
  93. for( j in j.subs )
  94. getJoint(path, j);
  95. path.pop();
  96. }
  97. function getRec(path:Array<String>, o:h3d.scene.Object) {
  98. if( o == exclude || o.name == null ) return;
  99. path.push(o.name);
  100. out.push(path.join("."));
  101. for( c in o )
  102. getRec(path, c);
  103. var sk = Std.downcast(o, h3d.scene.Skin);
  104. if( sk != null ) {
  105. var j = sk.getSkinData();
  106. for( j in j.rootJoints )
  107. getJoint(path, j);
  108. }
  109. path.pop();
  110. }
  111. for( o in rootContext.shared.root3d )
  112. getRec([], o);
  113. return out;
  114. }
  115. }