فهرست منبع

more simple edition for props

Nicolas Cannasse 8 سال پیش
والد
کامیت
3bc472a0b4
2فایلهای تغییر یافته به همراه65 افزوده شده و 100 حذف شده
  1. 21 4
      hide/comp/PropsEditor.hx
  2. 44 96
      hide/view/Particles3D.hx

+ 21 - 4
hide/comp/PropsEditor.hx

@@ -20,7 +20,7 @@ class PropsEditor extends Component {
 	public function addMaterial( m : h3d.mat.Material, ?parent : Element ) {
 	public function addMaterial( m : h3d.mat.Material, ?parent : Element ) {
 		var props = m.props;
 		var props = m.props;
 		var def = h3d.mat.MaterialSetup.current.editMaterial(props);
 		var def = h3d.mat.MaterialSetup.current.editMaterial(props);
-		def = add(def, props, function(undo) {
+		def = add(def, props, function(_, undo) {
 			if( m.model != null )
 			if( m.model != null )
 				h3d.mat.MaterialSetup.current.saveModelMaterial(m);
 				h3d.mat.MaterialSetup.current.saveModelMaterial(m);
 			m.refreshProps();
 			m.refreshProps();
@@ -31,7 +31,7 @@ class PropsEditor extends Component {
 			def.appendTo(parent);
 			def.appendTo(parent);
 	}
 	}
 
 
-	public function add( e : Element, ?context : Dynamic, ?onChange ) {
+	public function add( e : Element, ?context : Dynamic, ?onChange : String -> Bool -> Void ) {
 
 
 		e.appendTo(root);
 		e.appendTo(root);
 		e = e.wrap("<div></div>").parent(); // necessary to have find working on top level element
 		e = e.wrap("<div></div>").parent(); // necessary to have find working on top level element
@@ -83,7 +83,7 @@ class PropsEditor extends Component {
 		// init input reflection
 		// init input reflection
 		for( f in e.find("[field]").elements() ) {
 		for( f in e.find("[field]").elements() ) {
 			var f = new PropsField(this, f, context);
 			var f = new PropsField(this, f, context);
-			if( onChange != null ) f.onChange = onChange;
+			if( onChange != null ) f.onChange = function(undo) onChange(@:privateAccess f.fname,undo);
 			fields.push(f);
 			fields.push(f);
 		}
 		}
 
 
@@ -95,14 +95,15 @@ class PropsEditor extends Component {
 
 
 class PropsField extends Component {
 class PropsField extends Component {
 
 
+	public var fname : String;
 	var props : PropsEditor;
 	var props : PropsEditor;
-	var fname : String;
 	var context : Dynamic;
 	var context : Dynamic;
 	var current : Dynamic;
 	var current : Dynamic;
 	var enumValue : Enum<Dynamic>;
 	var enumValue : Enum<Dynamic>;
 	var tempChange : Bool;
 	var tempChange : Bool;
 	var beforeTempChange : { value : Dynamic };
 	var beforeTempChange : { value : Dynamic };
 	var tselect : hide.comp.TextureSelect;
 	var tselect : hide.comp.TextureSelect;
+	var fselect : hide.comp.FileSelect;
 	var viewRoot : Element;
 	var viewRoot : Element;
 
 
 	public function new(props, f, context) {
 	public function new(props, f, context) {
@@ -144,6 +145,22 @@ class PropsField extends Component {
 				onChange(false);
 				onChange(false);
 			}
 			}
 			return;
 			return;
+		case "model":
+			f.addClass("file");
+			fselect = new hide.comp.FileSelect(f, ["hmd", "fbx"]);
+			fselect.path = current;
+			fselect.onChange = function() {
+				props.undo.change(Field(context, fname, current), function() {
+					var f = resolveField();
+					f.current = Reflect.field(f.context, fname);
+					f.fselect.path = f.current;
+					f.onChange(true);
+				});
+				current = fselect.path;
+				Reflect.setProperty(context, fname, current);
+				onChange(false);
+			};
+			return;
 		case "range":
 		case "range":
 
 
 			f.wrap('<div class="range-group"/>');
 			f.wrap('<div class="range-group"/>');

+ 44 - 96
hide/view/Particles3D.hx

@@ -191,14 +191,20 @@ class Particles3D extends FileView {
 		for( g in parts.getGroups() )
 		for( g in parts.getGroups() )
 			addGroup(g);
 			addGroup(g);
 
 
+		var props : { ?model : String, ?attach : String, ?anim : String } = @:privateAccess parts.hideProps;
+		if( props == null ) {
+			props = {};
+			@:privateAccess parts.hideProps = props;
+		}
+
 		var extra = new Element('
 		var extra = new Element('
 			<div class="section">
 			<div class="section">
 				<h1>Manage</h1>
 				<h1>Manage</h1>
 				<div class="content">
 				<div class="content">
 					<dl>
 					<dl>
-					<dt>Model</dt><dd><input class="file model"/></dd>
-					<dt class="attach">Attach</dt><dd class="attach"><select/></dd>
-					<dt class="anim">Anim</dt><dd class="anim"><select/></dd>
+					<dt>Model</dt><dd><input type="model" field="model"/></dd>
+					<dt class="attach">Attach</dt><dd class="attach"><select field="attach"/></dd>
+					<dt class="anim">Anim</dt><dd class="anim"><select field="anim"/></dd>
 					<dt>Show Bounds</dt><dd><input type="checkbox" class="bounds"/></dd>
 					<dt>Show Bounds</dt><dd><input type="checkbox" class="bounds"/></dd>
 					<dt>Enable Lights</dt><dd><input type="checkbox" class="lights" checked="checked"/></dd>
 					<dt>Enable Lights</dt><dd><input type="checkbox" class="lights" checked="checked"/></dd>
 					<dt></dt><dd><input type="button" class="new" value="New Group"/></dd>
 					<dt></dt><dd><input type="button" class="new" value="New Group"/></dd>
@@ -206,98 +212,21 @@ class Particles3D extends FileView {
 				</div>
 				</div>
 			</div>
 			</div>
 		');
 		');
-		extra = properties.add(extra);
-		extra.find(".bounds").change(function(e) bounds.visible = e.getThis().prop("checked"));
-		var defAmbient = scene.s3d.lightSystem.ambientLight.clone();
-		extra.find(".lights").change(function(e) {
-			var ls = scene.s3d.lightSystem;
-			var enable = e.getThis().prop("checked");
-			ls.maxLightsPerObject = enable ? 6 : 0;
-			if( enable ) ls.ambientLight.load(defAmbient) else ls.ambientLight.set(1, 1, 1);
-		});
-		extra.find(".new").click(function(_) {
-			var g = parts.addGroup();
-			g.name = "Group#" + Lambda.count({ iterator : parts.getGroups });
-			addGroup(g);
-			extra.appendTo(properties.root);
-			undo.change(Custom(function(undo) {
-				if( undo )
-					parts.removeGroup(g);
-				else
-					parts.addGroup(g);
-				initProperties();
-			}));
-		}, null);
-
-		var pmodel = new hide.comp.FileSelect(extra.find(".model"), ["hmd", "fbx"]);
-		var props : { ?model : String, ?attach : String, ?anim : String } = @:privateAccess parts.hideProps;
-		if( props == null ) {
-			props = {};
-			@:privateAccess parts.hideProps = props;
-		}
-		pmodel.path = props.model;
 
 
+		var anim = extra.find(".anim select");
 		var attach = extra.find(".attach select");
 		var attach = extra.find(".attach select");
-		attach.change(function(_) {
-			var prev = props.attach;
-			var next = attach.val();
-			if( prev == next ) return;
-			props.attach = next;
-			undo.change(Custom(function(undo) {
-				props.attach = undo ? prev : next;
-				attach.val(props.attach == null ? '' : props.attach);
-				pmodel.onChange();
-			}));
-			pmodel.onChange();
-			attach.blur();
-		});
 
 
-		var anim = extra.find(".anim select");
-		anim.change(function(_) {
-			var prev = props.anim;
-			var next = anim.val();
-			if( next == "" ) next = null;
-			if( prev == next ) return;
-			props.anim = next;
-			undo.change(Custom(function(undo) {
-				props.anim = undo ? prev : next;
-				anim.val(props.anim == null ? '' : props.anim);
-				pmodel.onChange();
-			}));
-			pmodel.onChange();
-			anim.blur();
-		});
-		anim.contextmenu(function(e) {
-			e.preventDefault();
-			new hide.comp.ContextMenu([
-				{ label : "Clear", enabled : props.anim != null, click : function() {
-					var prev = props.anim;
-					props.anim = null;
-					anim.val('');
-					undo.change(Custom(function(undo) {
-						props.anim = undo ? prev : null;
-						anim.val(props.anim == null ? '' : props.anim);
-						pmodel.onChange();
-					}));
-					pmodel.onChange();
-				}},
-			]);
-		});
+		function syncProps() {
 
 
-		pmodel.onChange = function() {
+			extra.find(".attach").toggle(props.model != null);
+			extra.find(".anim").toggle(props.model != null);
 
 
-			extra.find(".attach").toggle(pmodel.path != null);
-			extra.find(".anim").toggle(pmodel.path != null);
+			parts.rebuild();
 
 
-			if( props.model != pmodel.path ) {
-				var prev = props.model;
-				var next = pmodel.path;
-				props.model = next;
-				undo.change(Custom(function(undo) {
-					props.model = pmodel.path = undo ? prev : next;
-					pmodel.onChange();
-				}));
-			}
+			if( props.anim == '' )
+				props.anim = null;
+			if( props.attach == '' )
+				props.attach = '';
 
 
 			if( model != null ) {
 			if( model != null ) {
 				model.remove();
 				model.remove();
@@ -346,7 +275,7 @@ class Particles3D extends FileView {
 					var prev = anim.val();
 					var prev = anim.val();
 					anim.html('');
 					anim.html('');
 					var anims = scene.listAnims(props.model);
 					var anims = scene.listAnims(props.model);
-					new Element('<option value="">-- select --</option>').appendTo(anim);
+					new Element('<option value="">-- none --</option>').appendTo(anim);
 					for( a in anims ) {
 					for( a in anims ) {
 						var name = scene.animationName(a);
 						var name = scene.animationName(a);
 						new Element('<option value="$a" ${a == prev ? "selected='selected'" : ""}>$name</option>').appendTo(anim);
 						new Element('<option value="$a" ${a == prev ? "selected='selected'" : ""}>$name</option>').appendTo(anim);
@@ -364,12 +293,31 @@ class Particles3D extends FileView {
 			}
 			}
 			parts.follow = parent;
 			parts.follow = parent;
 			ide.cleanObject(props);
 			ide.cleanObject(props);
-		};
-		pmodel.onChange();
-		if( props.attach != null )
-			attach.val(props.attach);
-		if( props.anim != null )
-			anim.val(props.anim);
+		}
+		syncProps();
+		extra = properties.add(extra, props, function(_, _) syncProps());
+
+		extra.find(".bounds").change(function(e) bounds.visible = e.getThis().prop("checked"));
+		var defAmbient = scene.s3d.lightSystem.ambientLight.clone();
+		extra.find(".lights").change(function(e) {
+			var ls = scene.s3d.lightSystem;
+			var enable = e.getThis().prop("checked");
+			ls.maxLightsPerObject = enable ? 6 : 0;
+			if( enable ) ls.ambientLight.load(defAmbient) else ls.ambientLight.set(1, 1, 1);
+		});
+		extra.find(".new").click(function(_) {
+			var g = parts.addGroup();
+			g.name = "Group#" + Lambda.count({ iterator : parts.getGroups });
+			addGroup(g);
+			extra.appendTo(properties.root);
+			undo.change(Custom(function(undo) {
+				if( undo )
+					parts.removeGroup(g);
+				else
+					parts.addGroup(g);
+				initProperties();
+			}));
+		}, null);
 	}
 	}
 
 
 	static var _ = FileTree.registerExtension(Particles3D, ["json.particles3D"], { icon : "snowflake-o", createNew: "Particle 3D" });
 	static var _ = FileTree.registerExtension(Particles3D, ["json.particles3D"], { icon : "snowflake-o", createNew: "Particle 3D" });