Jelajahi Sumber

view directory ok

Nicolas Cannasse 8 tahun lalu
induk
melakukan
b3f6169472
9 mengubah file dengan 114 tambahan dan 75 penghapusan
  1. 1 0
      bin/app.html
  2. 1 1
      hide.hxml
  3. 2 2
      hide.hxproj
  4. 50 0
      hide/comp/SceneTree.hx
  5. 14 9
      hide/ui/Ide.hx
  6. 6 4
      hide/ui/Props.hx
  7. 10 2
      hide/ui/View.hx
  8. 21 10
      hide/view/FileTree.hx
  9. 9 47
      hide/view/Model.hx

+ 1 - 0
bin/app.html

@@ -40,6 +40,7 @@
 	</menu>
 	</menu>
 	<menu label="View" class="view">
 	<menu label="View" class="view">
 		<menu label="Resources" component="hide.view.FileTree" state='{"root":""}'></menu>
 		<menu label="Resources" component="hide.view.FileTree" state='{"root":""}'></menu>
+		<menu label="Directory" component="hide.view.FileTree"></menu>
 		<separator></separator>
 		<separator></separator>
 		<menu label="About" component="hide.view.About"></menu>
 		<menu label="About" component="hide.view.About"></menu>
 		<menu label="Debug" class="debug"></menu>
 		<menu label="Debug" class="debug"></menu>

+ 1 - 1
hide.hxml

@@ -4,4 +4,4 @@
 -lib hxnodejs
 -lib hxnodejs
 -lib heaps
 -lib heaps
 -dce full
 -dce full
---macro include('hide.view')
+--macro include('hide.view')

+ 2 - 2
hide.hxproj

@@ -22,9 +22,9 @@
     <option directives="" />
     <option directives="" />
     <option flashStrict="False" />
     <option flashStrict="False" />
     <option noInlineOnDebug="False" />
     <option noInlineOnDebug="False" />
-    <option mainClass="hide.ui.Main" />
+    <option mainClass="hide.ui.Ide" />
     <option enabledebug="False" />
     <option enabledebug="False" />
-    <option additional="-lib hxnodejs" />
+    <option additional="-lib hxnodejs&#xA;-lib heaps&#xA;-dce full&#xA;&#xA;--macro include('hide.view')" />
   </build>
   </build>
   <!-- haxelib libraries -->
   <!-- haxelib libraries -->
   <haxelib>
   <haxelib>

+ 50 - 0
hide/comp/SceneTree.hx

@@ -0,0 +1,50 @@
+package hide.comp;
+
+class SceneTree extends IconTree {
+
+	public var obj : h3d.scene.Object;
+
+	public function new(obj, root) {
+		super(root);
+		this.obj = obj;
+		init();
+	}
+
+	override function get( id : String ) {
+		var root = obj.parent;
+		var path = id == null ? "" : id+"/";
+		if( id != null ) {
+			var parts = [for(p in id.split("/")) Std.parseInt(p)];
+			for( p in parts )
+				root = root.getChildAt(p);
+		}
+		var elements : Array<IconTree.IconTreeItem> = [
+			for( i in 0...root.numChildren ) {
+				var c = root.getChildAt(i);
+				{
+					id : path+i,
+					text : c.name,
+					icon : "fa fa-" + (c.isMesh() ? (Std.is(c,h3d.scene.Skin) ? "male" : "cube") : "circle-o"),
+					children : c.isMesh() || c.numChildren > 0,
+				}
+			}
+		];
+		if( root.isMesh() ) {
+			function makeMaterial( m : h3d.mat.Material, index : Int ) : IconTree.IconTreeItem {
+				return {
+					id : path+"mat"+index,
+					text : m.name,
+					icon : "fa fa-photo",
+				};
+			}
+			var multi = Std.instance(root,h3d.scene.MultiMaterial);
+			if( multi != null )
+				for( m in multi.materials )
+					elements.push(makeMaterial(m,multi.materials.indexOf(m)));
+			else
+				elements.push(makeMaterial(root.toMesh().material,0));
+		}
+		return elements;
+	}
+
+}

+ 14 - 9
hide/ui/Ide.hx

@@ -12,7 +12,7 @@ class Ide {
 	var layout : golden.Layout;
 	var layout : golden.Layout;
 	var types : Map<String,hide.HType>;
 	var types : Map<String,hide.HType>;
 	var typeDef = Macros.makeTypeDef(hide.HType);
 	var typeDef = Macros.makeTypeDef(hide.HType);
-	
+
 	var menu : Element;
 	var menu : Element;
 	var currentLayout : { name : String, state : Dynamic };
 	var currentLayout : { name : String, state : Dynamic };
 	var maximized : Bool;
 	var maximized : Bool;
@@ -23,7 +23,6 @@ class Ide {
 		inst = this;
 		inst = this;
 		window = nw.Window.get();
 		window = nw.Window.get();
 		props = new Props(Sys.getCwd());
 		props = new Props(Sys.getCwd());
-		if( props.global.currentProject == null ) props.global.currentProject = Sys.getCwd();
 
 
 		var wp = props.global.windowPos;
 		var wp = props.global.windowPos;
 		if( wp != null ) {
 		if( wp != null ) {
@@ -32,7 +31,7 @@ class Ide {
 			if( wp.max ) window.maximize();
 			if( wp.max ) window.maximize();
 		}
 		}
 		window.show(true);
 		window.show(true);
-	
+
 		setProject(props.global.currentProject);
 		setProject(props.global.currentProject);
 		window.on('maximize', function() { maximized = true; onWindowChange(); });
 		window.on('maximize', function() { maximized = true; onWindowChange(); });
 		window.on('restore', function() { maximized = false; onWindowChange(); });
 		window.on('restore', function() { maximized = false; onWindowChange(); });
@@ -55,7 +54,7 @@ class Ide {
 			props.global.windowPos.w = Std.int(window.window.outerWidth);
 			props.global.windowPos.w = Std.int(window.window.outerWidth);
 			props.global.windowPos.h = Std.int(window.window.outerHeight);
 			props.global.windowPos.h = Std.int(window.window.outerHeight);
 		}
 		}
-		props.saveGlobals();	
+		props.saveGlobals();
 	}
 	}
 
 
 	function initLayout( ?state : { name : String, state : Dynamic } ) {
 	function initLayout( ?state : { name : String, state : Dynamic } ) {
@@ -161,6 +160,13 @@ class Ide {
 		initLayout();
 		initLayout();
 	}
 	}
 
 
+	public function chooseDirectory( onSelect : String -> Void ) {
+		new Element('<input type="file" nwdirectory/>').change(function(e) {
+			var dir = js.jquery.Helper.JTHIS.val();
+			onSelect(dir);
+		}).click();
+	}
+
 	function initMenu() {
 	function initMenu() {
 		if( menu == null )
 		if( menu == null )
 			menu = new Element(new Element("#mainmenu").get(0).outerHTML);
 			menu = new Element(new Element("#mainmenu").get(0).outerHTML);
@@ -179,12 +185,11 @@ class Ide {
 			});
 			});
 		}
 		}
 		menu.find(".project .open").click(function(_) {
 		menu.find(".project .open").click(function(_) {
-			new Element('<input type="file" nwdirectory/>').change(function(e) {
-				var dir = js.jquery.Helper.JTHIS.val();
+			chooseDirectory(function(dir) {
 				if( StringTools.endsWith(dir,"/res") || StringTools.endsWith(dir,"\\res") )
 				if( StringTools.endsWith(dir,"/res") || StringTools.endsWith(dir,"\\res") )
 					dir = dir.substr(0,-4);
 					dir = dir.substr(0,-4);
 				setProject(dir);
 				setProject(dir);
-			}).click();
+			});
 		});
 		});
 		menu.find(".project .clear").click(function(_) {
 		menu.find(".project .clear").click(function(_) {
 			props.global.recentProjects = [];
 			props.global.recentProjects = [];
@@ -240,7 +245,7 @@ class Ide {
 
 
 	public function open( component : String, state : Dynamic, ?onCreate : View<Dynamic> -> Void ) {
 	public function open( component : String, state : Dynamic, ?onCreate : View<Dynamic> -> Void ) {
 		var options = View.viewClasses.get(component).options;
 		var options = View.viewClasses.get(component).options;
-		
+
 		var bestTarget : golden.Container = null;
 		var bestTarget : golden.Container = null;
 		for( v in views )
 		for( v in views )
 			if( v.defaultOptions.position == options.position ) {
 			if( v.defaultOptions.position == options.position ) {
@@ -251,7 +256,7 @@ class Ide {
 		var index : Null<Int> = null;
 		var index : Null<Int> = null;
 		var width : Null<Int> = null;
 		var width : Null<Int> = null;
 		var target;
 		var target;
-		if( bestTarget != null ) 
+		if( bestTarget != null )
 			target = bestTarget.parent.parent;
 			target = bestTarget.parent.parent;
 		else {
 		else {
 			target = layout.root.contentItems[0];
 			target = layout.root.contentItems[0];

+ 6 - 4
hide/ui/Props.hx

@@ -14,7 +14,7 @@ typedef PropsDef = {
 
 
 class Props {
 class Props {
 
 
-	
+
 	var paths : {
 	var paths : {
 		global : String,
 		global : String,
 		local : String,
 		local : String,
@@ -27,7 +27,7 @@ class Props {
 	public var project : PropsDef;
 	public var project : PropsDef;
 	// per user, per project
 	// per user, per project
 	public var local : PropsDef;
 	public var local : PropsDef;
-	
+
 	// current merge
 	// current merge
 	public var current : PropsDef;
 	public var current : PropsDef;
 
 
@@ -53,6 +53,8 @@ class Props {
 		if( global == null ) global = cast {};
 		if( global == null ) global = cast {};
 		if( project == null ) project = cast {};
 		if( project == null ) project = cast {};
 		if( local == null ) local = cast {};
 		if( local == null ) local = cast {};
+		if( global.currentProject == null || !sys.FileSystem.exists(global.currentProject) )
+			global.currentProject = Sys.getCwd();
 		sync();
 		sync();
 	}
 	}
 
 
@@ -66,7 +68,7 @@ class Props {
 		};
 		};
 		merge(global);
 		merge(global);
 		merge(project);
 		merge(project);
-		merge(local);		
+		merge(local);
 	}
 	}
 
 
 	public function save() {
 	public function save() {
@@ -81,7 +83,7 @@ class Props {
 		js.Browser.window.localStorage.setItem(paths.local, str);
 		js.Browser.window.localStorage.setItem(paths.local, str);
 	}
 	}
 
 
-	public function saveGlobals() {		
+	public function saveGlobals() {
 		var str = haxe.Json.stringify(global);
 		var str = haxe.Json.stringify(global);
 		sys.io.File.saveContent(paths.global, str);
 		sys.io.File.saveContent(paths.global, str);
 	}
 	}

+ 10 - 2
hide/ui/View.hx

@@ -19,7 +19,7 @@ class View<T> {
 
 
 	var contentWidth(get,never) : Int;
 	var contentWidth(get,never) : Int;
 	var contentHeight(get,never) : Int;
 	var contentHeight(get,never) : Int;
- 
+
 	public function new(state:T) {
 	public function new(state:T) {
 		this.state = state;
 		this.state = state;
 		ide = Ide.inst;
 		ide = Ide.inst;
@@ -35,7 +35,7 @@ class View<T> {
 	}
 	}
 
 
 	function syncTitle() {
 	function syncTitle() {
-		container.setTitle(getTitle());		
+		container.setTitle(getTitle());
 	}
 	}
 
 
 	public function setContainer(cont) {
 	public function setContainer(cont) {
@@ -56,6 +56,14 @@ class View<T> {
 		untyped cont.parent.__view = this;
 		untyped cont.parent.__view = this;
 	}
 	}
 
 
+	public function rebuild() {
+		if( container == null ) return;
+		syncTitle();
+		var e = container.getElement();
+		e.html('');
+		onDisplay(container.getElement());
+	}
+
 	public function onDisplay( e : Element ) {
 	public function onDisplay( e : Element ) {
 		e.text(Type.getClassName(Type.getClass(this))+(state == null ? "" : " "+state));
 		e.text(Type.getClassName(Type.getClass(this))+(state == null ? "" : " "+state));
 	}
 	}

+ 21 - 10
hide/view/FileTree.hx

@@ -11,6 +11,13 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 
 
 	public function new(state) {
 	public function new(state) {
 		super(state);
 		super(state);
+		if( state.root == null ) {
+			ide.chooseDirectory(function(dir) {
+				state.root = dir.split("\\").join("/")+"/";
+				saveState();
+				rebuild();
+			});
+		}
 	}
 	}
 
 
 	function getExtension( file : String ) {
 	function getExtension( file : String ) {
@@ -20,11 +27,15 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 	override function getTitle() {
 	override function getTitle() {
 		if( state.root == "" )
 		if( state.root == "" )
 			return "Resources";
 			return "Resources";
-		return state.root.split("/").pop();
+		if( state.root == null )
+			return "";
+		return state.root;
 	}
 	}
 
 
 	override function onDisplay( e : Element ) {
 	override function onDisplay( e : Element ) {
 
 
+		if( state.root == null ) return;
+
 		if( state.opened == null ) state.opened = [];
 		if( state.opened == null ) state.opened = [];
 
 
 		var panel = new hide.comp.ScrollZone(e);
 		var panel = new hide.comp.ScrollZone(e);
@@ -35,28 +46,28 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 			var content = new Array<hide.comp.IconTree.IconTreeItem>();
 			var content = new Array<hide.comp.IconTree.IconTreeItem>();
 			for( c in sys.FileSystem.readDirectory(basePath) ) {
 			for( c in sys.FileSystem.readDirectory(basePath) ) {
 				if( isIgnored(basePath,c) ) continue;
 				if( isIgnored(basePath,c) ) continue;
-				var isDir = sys.FileSystem.isDirectory(basePath+"/"+c); 
+				var isDir = sys.FileSystem.isDirectory(basePath+"/"+c);
 				var ext = getExtension(c);
 				var ext = getExtension(c);
 				var id = ( path == "" ? c : path+"/"+c );
 				var id = ( path == "" ? c : path+"/"+c );
 				content.push({
 				content.push({
-					id : id, 
+					id : id,
 					text : c,
 					text : c,
 					icon : "fa fa-" + (isDir ? "folder" : (ext != null && ext.options.icon != null ? ext.options.icon : "file-text")),
 					icon : "fa fa-" + (isDir ? "folder" : (ext != null && ext.options.icon != null ? ext.options.icon : "file-text")),
 					children : isDir,
 					children : isDir,
 					state : state.opened.indexOf(id) >= 0 ? { opened : true } : null
 					state : state.opened.indexOf(id) >= 0 ? { opened : true } : null
 				});
 				});
 			}
 			}
-			content.sort(function(a,b) { if( a.children != b.children ) return a.children?-1:1; return Reflect.compare(a.text,b.text); });	
+			content.sort(function(a,b) { if( a.children != b.children ) return a.children?-1:1; return Reflect.compare(a.text,b.text); });
 			return content;
 			return content;
 		};
 		};
 		tree.onToggle = function(path, isOpen) {
 		tree.onToggle = function(path, isOpen) {
 			state.opened.remove(path);
 			state.opened.remove(path);
-			if( isOpen ) 
+			if( isOpen )
 				state.opened.push(path);
 				state.opened.push(path);
 			saveState();
 			saveState();
 		};
 		};
-		
-		
+
+
 		// prevent dummy mouseLeft from breaking our quickOpen feature
 		// prevent dummy mouseLeft from breaking our quickOpen feature
 		var mouseLeft = false;
 		var mouseLeft = false;
 		var leftCount = 0;
 		var leftCount = 0;
@@ -67,7 +78,7 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 			mouseLeft = true;
 			mouseLeft = true;
 			leftCount++;
 			leftCount++;
 			var k = leftCount;
 			var k = leftCount;
-			if( lastOpen != null ) 
+			if( lastOpen != null )
 				haxe.Timer.delay(function() {
 				haxe.Timer.delay(function() {
 					if( !mouseLeft || leftCount != k ) return;
 					if( !mouseLeft || leftCount != k ) return;
 					lastOpen = null;
 					lastOpen = null;
@@ -87,12 +98,12 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 			return;
 			return;
 		var prev = lastOpen;
 		var prev = lastOpen;
 		lastOpen = null;
 		lastOpen = null;
-		ide.open(ext.component, { path : path }, function(c) {
+		ide.open(ext.component, { path : haxe.io.Path.isAbsolute(state.root) ? fullPath : path }, function(c) {
 			if( prev != null ) prev.close();
 			if( prev != null ) prev.close();
 			lastOpen = c;
 			lastOpen = c;
 		});
 		});
 	}
 	}
- 
+
 	function isIgnored( path : String, file : String ) {
 	function isIgnored( path : String, file : String ) {
 		if( file.charCodeAt(0) == ".".code )
 		if( file.charCodeAt(0) == ".".code )
 			return true;
 			return true;

+ 9 - 47
hide/view/Model.hx

@@ -7,23 +7,22 @@ class Model extends FileView {
 	var scene : hide.comp.Scene;
 	var scene : hide.comp.Scene;
 	var control : h3d.scene.CameraController;
 	var control : h3d.scene.CameraController;
 	var tree : hide.comp.IconTree;
 	var tree : hide.comp.IconTree;
+	var scroll : hide.comp.ScrollZone;
 
 
 	override function onDisplay( e : Element ) {
 	override function onDisplay( e : Element ) {
 		tools = new hide.comp.Toolbar(e);
 		tools = new hide.comp.Toolbar(e);
 		var cont = new Element('<div class="hide-scene-layer">').appendTo(tools.content);
 		var cont = new Element('<div class="hide-scene-layer">').appendTo(tools.content);
-		var scroll = new hide.comp.ScrollZone(cont);
-		tree = new hide.comp.IconTree(scroll.content);
-		tree.get = getSceneElements;
+		scroll = new hide.comp.ScrollZone(cont);
 		scene = new hide.comp.Scene(tools.content);
 		scene = new hide.comp.Scene(tools.content);
 		scene.onReady = init;
 		scene.onReady = init;
 	}
 	}
-	
+
 	function init() {
 	function init() {
 		obj = scene.loadModel(state.path);
 		obj = scene.loadModel(state.path);
 		new h3d.scene.Object(scene.s3d).addChild(obj);
 		new h3d.scene.Object(scene.s3d).addChild(obj);
 		control = new h3d.scene.CameraController(scene.s3d);
 		control = new h3d.scene.CameraController(scene.s3d);
+		tree = new hide.comp.SceneTree(obj,scroll.content);
 		resetCamera();
 		resetCamera();
-		tree.init();
 
 
 		var anims = listAnims();
 		var anims = listAnims();
 		if( anims.length > 0 ) {
 		if( anims.length > 0 ) {
@@ -44,9 +43,9 @@ class Model extends FileView {
 				obj.playAnimation(anim);
 				obj.playAnimation(anim);
 			};
 			};
 		}
 		}
-	
-		tools.addButton("cube","Test");
-		tools.addToggle("bank","Test toggle");
+
+		//tools.addButton("cube","Test");
+		//tools.addToggle("bank","Test toggle");
 	}
 	}
 
 
 	function listAnims() {
 	function listAnims() {
@@ -65,43 +64,6 @@ class Model extends FileView {
 		return anims;
 		return anims;
 	}
 	}
 
 
-	function getSceneElements( id : String ) {
-		var root = obj.parent; 
-		var path = id == null ? "" : id+"/";
-		if( id != null ) {
-			var parts = [for(p in id.split("/")) Std.parseInt(p)];
-			for( p in parts )
-				root = root.getChildAt(p);
-		}
-		var elements : Array<hide.comp.IconTree.IconTreeItem> = [
-			for( i in 0...root.numChildren ) {
-				var c = root.getChildAt(i);
-				{
-					id : path+i,
-					text : c.name,
-					icon : "fa fa-" + (c.isMesh() ? (Std.is(c,h3d.scene.Skin) ? "male" : "cube") : "circle-o"),
-					children : c.isMesh() || c.numChildren > 0,
-				}
-			}
-		];
-		if( root.isMesh() ) {
-			function makeMaterial( m : h3d.mat.Material, index : Int ) : hide.comp.IconTree.IconTreeItem {
-				return {
-					id : path+"mat"+index,
-					text : m.name,
-					icon : "fa fa-photo",
-				};
-			}
-			var multi = Std.instance(root,h3d.scene.MultiMaterial);
-			if( multi != null )
-				for( m in multi.materials )
-					elements.push(makeMaterial(m,multi.materials.indexOf(m)));
-			else
-				elements.push(makeMaterial(root.toMesh().material,0));
-		}
-		return elements;
-	}
-
 	function resetCamera() {
 	function resetCamera() {
 		var b = obj.getBounds();
 		var b = obj.getBounds();
 		var dx = Math.max(Math.abs(b.xMax),Math.abs(b.xMin));
 		var dx = Math.max(Math.abs(b.xMax),Math.abs(b.xMin));
@@ -112,9 +74,9 @@ class Model extends FileView {
 		var zang = Math.PI * 0.4;
 		var zang = Math.PI * 0.4;
 		scene.s3d.camera.pos.set(Math.sin(zang) * Math.cos(ang) * dist, Math.sin(zang) * Math.sin(ang) * dist, Math.cos(zang) * dist);
 		scene.s3d.camera.pos.set(Math.sin(zang) * Math.cos(ang) * dist, Math.sin(zang) * Math.sin(ang) * dist, Math.cos(zang) * dist);
 		scene.s3d.camera.target.set(0, 0, (b.zMax + b.zMin) * 0.5);
 		scene.s3d.camera.target.set(0, 0, (b.zMax + b.zMin) * 0.5);
-		control.loadFromCamera();		
+		control.loadFromCamera();
 	}
 	}
 
 
-	static var _ = FileTree.registerExtension(Model,["hmd","fbx"],{ icon : "cube" });
+	static var _ = FileTree.registerExtension(Model,["hmd","fbx","scn"],{ icon : "cube" });
 
 
 }
 }