Przeglądaj źródła

Show/Hide visible, reflected in tree

trethaller 7 lat temu
rodzic
commit
ff5d8949a9

+ 7 - 0
bin/style.css

@@ -473,6 +473,13 @@ div.lm_close_tab:hover {
 .jstree.small .jstree-wholerow {
 .jstree.small .jstree-wholerow {
   height: 20px;
   height: 20px;
 }
 }
+.jstree-invisible a,
+.jstree-invisible i {
+  color: #555 !important;
+}
+.jstree-invisible a {
+  display: inline !important;
+}
 /* Spectrum Color picker */
 /* Spectrum Color picker */
 div.sp-replacer {
 div.sp-replacer {
   vertical-align: top;
   vertical-align: top;

+ 9 - 0
bin/style.less

@@ -519,6 +519,15 @@ div.lm_close_tab:hover { background-color : #555 !important; }
 	}
 	}
 }
 }
 
 
+.jstree-invisible {
+	a, i {
+		color: #555 !important;
+	}
+	a {
+		display: inline !important;
+	}
+}
+
 /* Spectrum Color picker */
 /* Spectrum Color picker */
 
 
 div.sp-replacer {
 div.sp-replacer {

+ 6 - 0
hide/comp/IconTree.hx

@@ -141,6 +141,12 @@ class IconTree<T:{}> extends Component {
 		return revMap.get(o);
 		return revMap.get(o);
 	}
 	}
 
 
+	public function getElement(e : T) : Element {
+		var v = getRev(e);
+		var el = (untyped root.jstree)('get_node', v.id, true);
+		return el;
+	}
+
 	public function editNode( e : T ) {
 	public function editNode( e : T ) {
 		var n = getRev(e).id;
 		var n = getRev(e).id;
 		(untyped root.jstree)('edit',n);
 		(untyped root.jstree)('edit',n);

+ 1 - 0
hide/prefab/EditContext.hx

@@ -12,6 +12,7 @@ class EditContext {
 	public var cleanups : Array<Void->Void>;
 	public var cleanups : Array<Void->Void>;
 	public var properties : hide.comp.PropsEditor;
 	public var properties : hide.comp.PropsEditor;
 	function get_ide() return hide.ui.Ide.inst;
 	function get_ide() return hide.ui.Ide.inst;
+	public function onChange(p : Prefab) { }
 	#end
 	#end
 
 
 	public function new(ctx) {
 	public function new(ctx) {

+ 4 - 1
hide/prefab/Object3D.hx

@@ -86,7 +86,10 @@ class Object3D extends Prefab {
 					<dt>Visible</dt><dd><input type="checkbox" field="visible"/></dd>
 					<dt>Visible</dt><dd><input type="checkbox" field="visible"/></dd>
 				</dl>
 				</dl>
 			</div>
 			</div>
-		'),this,function(_) applyPos(ctx.getContext(this).local3d));
+		'),this,function(_) {
+			applyPos(ctx.getContext(this).local3d);
+			ctx.onChange(this);
+		});
 		#end
 		#end
 	}
 	}
 
 

+ 43 - 5
hide/view/Level3D.hx

@@ -53,6 +53,11 @@ class LevelEditContext extends hide.prefab.EditContext {
 			c();
 			c();
 		cleanups = [];
 		cleanups = [];
 	}
 	}
+
+	override function onChange(p : PrefabElement) {
+		var level3D : Level3D = cast view;
+		level3D.onPrefabChange(p);
+	}
 }
 }
 
 
 typedef AxesOptions = {
 typedef AxesOptions = {
@@ -592,13 +597,17 @@ class Level3D extends FileView {
 
 
 		function makeItem(o:PrefabElement) : hide.comp.IconTree.IconTreeItem<PrefabElement> {
 		function makeItem(o:PrefabElement) : hide.comp.IconTree.IconTreeItem<PrefabElement> {
 			var p = o.getHideProps();
 			var p = o.getHideProps();
-			return {
+			var r : hide.comp.IconTree.IconTreeItem<PrefabElement> = {
 				data : o,
 				data : o,
 				text : o.name,
 				text : o.name,
 				icon : "fa fa-"+p.icon,
 				icon : "fa fa-"+p.icon,
 				children : o.children.length > 0,
 				children : o.children.length > 0,
 				state : { opened : true },
 				state : { opened : true },
 			};
 			};
+			if(Reflect.field(o, "visible") == false) {
+				r.li_attr = { "class": "jstree-invisible" };
+			}
+			return r;
 		}
 		}
 		tree.get = function(o:PrefabElement) {
 		tree.get = function(o:PrefabElement) {
 			var objs = o == null ? data.children : Lambda.array(o);
 			var objs = o == null ? data.children : Lambda.array(o);
@@ -645,11 +654,21 @@ class Level3D extends FileView {
 				});
 				});
 			}
 			}
 
 
-			new hide.comp.ContextMenu([
+			var menuItems : Array<hide.comp.ContextMenu.ContextMenuItem> = [
 				{ label : "New...", menu : registered },
 				{ label : "New...", menu : registered },
 				{ label : "Rename", enabled : current != null, click : function() tree.editNode(current) },
 				{ label : "Rename", enabled : current != null, click : function() tree.editNode(current) },
-				{ label : "Delete", enabled : current != null, click : function() deleteElements(curEdit.rootElements) },
-			]);
+				{ label : "Delete", enabled : current != null, click : function() deleteElements(curEdit.rootElements) }
+			];
+
+			if(current != null && curEdit != null) {
+				var obj3d = Std.instance(current, hide.prefab.Object3D);
+				if(obj3d != null) {
+					menuItems.push({label : obj3d.visible ? "Hide" : "Show", click: function() {
+						setVisible(obj3d, !obj3d.visible);
+					}});
+				}
+			}
+			new hide.comp.ContextMenu(menuItems);
 		});
 		});
 		tree.allowRename = true;
 		tree.allowRename = true;
 		tree.init();
 		tree.init();
@@ -826,7 +845,6 @@ class Level3D extends FileView {
 		mat.multiply(mat, parentMat);
 		mat.multiply(mat, parentMat);
 		var prevState = obj3d.save();
 		var prevState = obj3d.save();
 		obj3d.setTransform(mat);
 		obj3d.setTransform(mat);
-		obj3d.load(obj3d.save());
 		var newState = obj3d.save();
 		var newState = obj3d.save();
 
 
 		undo.change(Custom(function(undo) {
 		undo.change(Custom(function(undo) {
@@ -856,11 +874,31 @@ class Level3D extends FileView {
 		return context.shared.root3d;
 		return context.shared.root3d;
 	}
 	}
 
 
+	function setVisible(obj3d : hide.prefab.Object3D, visible: Bool) {
+		obj3d.visible = visible;
+		var o = curEdit.getContext(obj3d).local3d;
+		if(o != null) {
+			obj3d.applyPos(o);
+		}
+		curEdit.onChange(obj3d);
+	}
+
 	function showSearch() {
 	function showSearch() {
 		searchBox.show();
 		searchBox.show();
 		searchBox.find("input").focus().select();
 		searchBox.find("input").focus().select();
 	}
 	}
 
 
+	public function onPrefabChange(p: PrefabElement) {
+		var el = tree.getElement(p);
+		var obj3d : hide.prefab.Object3D = cast p;
+		if(obj3d.visible) {
+			el.removeClass("jstree-invisible");
+		}
+		else {
+			el.addClass("jstree-invisible");
+		}
+	}
+
 	static function worldMat(obj: Object) {
 	static function worldMat(obj: Object) {
 		if(obj.defaultTransform != null) {
 		if(obj.defaultTransform != null) {
 			var m = obj.defaultTransform.clone();
 			var m = obj.defaultTransform.clone();