ソースを参照

FileTree is FileView, opened memory in IconTree, toggled memory in Toolbar

Nicolas Cannasse 8 年 前
コミット
96986a298d
7 ファイル変更88 行追加36 行削除
  1. 6 1
      bin/app.html
  2. 12 3
      hide/comp/IconTree.hx
  3. 10 2
      hide/comp/Toolbar.hx
  4. 3 2
      hide/ui/Ide.hx
  5. 16 24
      hide/view/FileTree.hx
  6. 8 2
      hide/view/FileView.hx
  7. 33 2
      hide/view/Model.hx

+ 6 - 1
bin/app.html

@@ -12,6 +12,11 @@
 <script src="libs/goldenlayout.js"></script>
 <script src="libs/jstree/jstree.js"></script>
 
+<script>
+	// fix for Sys.programPath
+	__filename = process.argv[0];
+</script>
+
 <script>
 	var nodeRequire = require;
 	monaco = {};
@@ -44,7 +49,7 @@
 		<menu label="Exit" class="exit"></menu>
 	</menu>
 	<menu label="View" class="view">
-		<menu label="Resources" component="hide.view.FileTree" state='{"root":""}'></menu>
+		<menu label="Resources" component="hide.view.FileTree" state='{"path":""}'></menu>
 		<menu label="Directory" component="hide.view.FileTree"></menu>
 		<separator></separator>
 		<menu label="About" component="hide.view.About"></menu>

+ 12 - 3
hide/comp/IconTree.hx

@@ -37,8 +37,15 @@ class IconTree extends Component {
 					dots: true,
 					icons: true
             	},
-				data : function(obj,callb) {
-					callb.call(this,get(obj.parent == null ? null : obj.id));
+				data : function(obj, callb) {
+					var parent = obj.parent == null ? null : obj.id;
+					var content : Array<IconTreeItem> = get(parent);
+					for( c in content )
+						if( c.state == null ) {
+							var s = getDisplayState((parent == null ? "" : parent + "/") + c.id);
+							if( s ) c.state = { opened : true };
+						}
+					callb.call(this,content);
 				}
 			},
 			plugins : [ "wholerow" ],
@@ -53,10 +60,12 @@ class IconTree extends Component {
    			var data = node[0].id;
 			onDblClick(data);
 		});
-		root.on("open_node.jstree", function(event,e) {
+		root.on("open_node.jstree", function(event, e) {
+			saveDisplayState(e.node.id, true);
 			onToggle(e.node.id, true);
 		});
 		root.on("close_node.jstree", function(event,e) {
+			saveDisplayState(e.node.id, false);
 			onToggle(e.node.id, false);
 		});
 		root.on("refresh.jstree", function(_) {

+ 10 - 2
hide/comp/Toolbar.hx

@@ -25,10 +25,18 @@ class Toolbar extends Component {
 		return e;
 	}
 
-	public function addToggle( icon : String, ?label : String, ?onToggle : Bool -> Void ) : ToolToggle {
+	public function addToggle( icon : String, ?label : String, ?onToggle : Bool -> Void, ?defValue = false ) : ToolToggle {
 		var e = new Element('<div class="toggle" title="${label==null ? "" : label}"><div class="icon fa fa-$icon"/></div>');
-		e.click(function(_) { e.toggleClass("toggled"); if( onToggle != null ) onToggle(e.hasClass("toggled")); });
+		e.click(function(_) {
+			e.toggleClass("toggled");
+			this.saveDisplayState("toggle:" + icon, e.hasClass("toggled"));
+			if( onToggle != null ) onToggle(e.hasClass("toggled"));
+		});
 		e.appendTo(root);
+		if( defValue ) e.addClass("toggled");
+		var def = getDisplayState("toggle:" + icon);
+		if( def == null ) def = false;
+		if( def != defValue ) e.click();
 		return { element : e, toggle : function(b) e.toggleClass("toggled",b) };
 	}
 

+ 3 - 2
hide/ui/Ide.hx

@@ -205,6 +205,7 @@ class Ide {
 		}
 		window.title = "HIDE - " + dir;
 		props = Props.loadForProject(projectDir, resourceDir);
+		hxd.res.Loader.currentInstance = new hxd.res.Loader(new hxd.fs.LocalFileSystem(resourceDir));
 		renderers = [
 			new h3d.mat.MaterialSetup("Default"),
 		];
@@ -240,7 +241,7 @@ class Ide {
 	}
 
 	public function chooseFile( exts : Array<String>, onSelect : String -> Void ) {
-		var e = new Element('<input type="file" value="" accept="${[for( e in exts ) "."+e].join(",")}"/>');
+		var e = new Element('<input type="file" style="visibility:hidden" value="" accept="${[for( e in exts ) "."+e].join(",")}"/>');
 		e.change(function(_) {
 			var file = makeRelative(e.val());
 			e.remove();
@@ -249,7 +250,7 @@ class Ide {
 	}
 
 	public function chooseDirectory( onSelect : String -> Void ) {
-		var e = new Element('<input type="file" value="" nwdirectory/>');
+		var e = new Element('<input type="file" style="visibility:hidden" value="" nwdirectory/>');
 		e.change(function(ev) {
 			var dir = makeRelative(ev.getThis().val());
 			onSelect(dir == "" ? null : dir);

+ 16 - 24
hide/view/FileTree.hx

@@ -11,20 +11,20 @@ typedef ExtensionDesc = {
 	var options : ExtensionOptions;
 }
 
-class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
+class FileTree extends FileView {
 
 	var tree : hide.comp.IconTree;
 	var lastOpen : hide.ui.View<Dynamic>;
 
 	public function new(state) {
 		super(state);
-		if( state.root == null ) {
+		if( state.path == null ) {
 			ide.chooseDirectory(function(dir) {
 				if( dir == null ) {
 					close();
 					return;
 				}
-				state.root = dir.split("\\").join("/")+"/";
+				state.path = dir.split("\\").join("/")+"/";
 				saveState();
 				rebuild();
 			});
@@ -49,24 +49,23 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 	}
 
 	override function getTitle() {
-		if( state.root == "" )
+		if( state.path == "" )
 			return "Resources";
-		if( state.root == null )
+		if( state.path == null )
 			return "";
-		return state.root;
+		return super.getTitle();
 	}
 
 	override function onDisplay() {
 
-		if( state.root == null ) return;
-
-		if( state.opened == null ) state.opened = [];
+		if( state.path == null ) return;
 
 		var panel = new Element("<div class='hide-scroll'>").appendTo(root);
 		tree = new hide.comp.IconTree(panel);
+		tree.saveDisplayKey = "FileTree:" + getPath().split("\\").join("/").substr(0,-1);
 		tree.get = function(path) {
 			if( path == null ) path = "";
-			var basePath = ide.getPath(state.root) + path;
+			var basePath = getFilePath(path);
 			var content = new Array<hide.comp.IconTree.IconTreeItem>();
 			for( c in sys.FileSystem.readDirectory(basePath) ) {
 				if( isIgnored(basePath, c) ) continue;
@@ -79,19 +78,11 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 					text : c,
 					icon : "fa fa-" + (isDir ? "folder" : (ext != null && ext.options.icon != null ? ext.options.icon : "file-text")),
 					children : isDir,
-					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); });
 			return content;
 		};
-		tree.onToggle = function(path, isOpen) {
-			state.opened.remove(path);
-			if( isOpen )
-				state.opened.push(path);
-			saveState();
-		};
-
 
 		// prevent dummy mouseLeft from breaking our quickOpen feature
 		var mouseLeft = false;
@@ -124,7 +115,7 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 	}
 
 	function onDeleteFile( path : String ) {
-		var fullPath = getPath(path);
+		var fullPath = getFilePath(path);
 		if( sys.FileSystem.isDirectory(fullPath) ) {
 			for( f in sys.FileSystem.readDirectory(fullPath) )
 				onDeleteFile(path + "/" + f);
@@ -133,12 +124,12 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 			sys.FileSystem.deleteFile(fullPath);
 	}
 
-	function getPath(path:String) {
-		return ide.getPath(state.root) + path;
+	function getFilePath(path:String) {
+		return ide.getPath(state.path) + path;
 	}
 
 	function onOpenFile( path : String ) {
-		var fullPath = getPath(path);
+		var fullPath = getFilePath(path);
 		if( sys.FileSystem.isDirectory(fullPath) )
 			return;
 		var ext = getExtension(fullPath);
@@ -153,10 +144,10 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 	}
 
 	function createNew( basePath : String, ext : ExtensionDesc ) {
-		var fullPath = getPath(basePath);
+		var fullPath = getFilePath(basePath);
 		if( !sys.FileSystem.isDirectory(fullPath) ) {
 			basePath = new haxe.io.Path(basePath).dir;
-			fullPath = getPath(basePath);
+			fullPath = getFilePath(basePath);
 		}
 		var file = js.Browser.window.prompt(ext.options.createNew + " name:");
 		if( file == null ) return;
@@ -169,6 +160,7 @@ class FileTree extends hide.ui.View<{ root : String, opened : Array<String> }> {
 		}
 
 		var view : hide.view.FileView = Type.createEmptyInstance(Type.resolveClass(ext.component));
+		view.ide = ide;
 		sys.io.File.saveBytes(fullPath + "/" + file, view.getDefaultContent());
 		tree.refresh(function() tree.setSelection([basePath + "/" + file]));
 		onOpenFile(basePath+"/"+file);

+ 8 - 2
hide/view/FileView.hx

@@ -6,6 +6,8 @@ class FileView extends hide.ui.View<{ path : String }> {
 	var modified(default,set) : Bool;
 
 	function get_extension() {
+		if( state.path == null )
+			return "";
 		var file = state.path.split("/").pop();
 		return file.indexOf(".") < 0 ? "" : file.split(".").pop().toLowerCase();
 	}
@@ -39,8 +41,10 @@ class FileView extends hide.ui.View<{ path : String }> {
 	}
 
 	override function get_props() {
-		if( props == null )
+		if( props == null ) {
+			if( state.path == null ) return super.get_props();
 			props = hide.ui.Props.loadForFile(ide, state.path);
+		}
 		return props;
 	}
 
@@ -58,13 +62,15 @@ class FileView extends hide.ui.View<{ path : String }> {
 
 	override function getTitle() {
 		var parts = state.path.split("/");
+		if( parts[parts.length - 1] == "" ) parts.pop(); // directory
 		while( parts.length > 2 ) parts.shift();
 		return parts.join(" / ")+(modified?" *":"");
 	}
 
 	override function syncTitle() {
 		super.syncTitle();
-		haxe.Timer.delay(function() container.tab.element.attr("title",getPath()), 100);
+		if( state.path != null )
+			haxe.Timer.delay(function() container.tab.element.attr("title",getPath()), 100);
 	}
 
 }

+ 33 - 2
hide/view/Model.hx

@@ -9,6 +9,8 @@ class Model extends FileView {
 	var tree : hide.comp.SceneTree;
 	var overlay : Element;
 	var properties : hide.comp.PropsEditor;
+	var light : h3d.scene.DirLight;
+	var lightDirection = new h3d.Vector( 1, 2, -4 );
 
 	override function onDisplay() {
 		root.html('
@@ -35,8 +37,14 @@ class Model extends FileView {
 
 	function init() {
 		obj = scene.loadModel(state.path);
-
 		new h3d.scene.Object(scene.s3d).addChild(obj);
+
+		light = obj.find(function(o) return Std.instance(o, h3d.scene.DirLight));
+		if( light == null ) {
+			light = new h3d.scene.DirLight(new h3d.Vector(), scene.s3d);
+			light.enableSpecular = true;
+		}
+
 		control = new h3d.scene.CameraController(scene.s3d);
 		tree = new hide.comp.SceneTree(obj, overlay, obj.name != null);
 		tree.onSelectMaterial = function(m) {
@@ -76,17 +84,40 @@ class Model extends FileView {
 
 		scene.init(props);
 		scene.onUpdate = update;
+
+		tools.saveDisplayKey = "ModelTools";
+
 		tools.addButton("video-camera", "Reset Camera", function() {
 			scene.resetCamera(obj,1.5);
 			control.loadFromCamera();
 		});
+
+		tools.addToggle("sun-o", "Enable Lights/Shadows", function(v) {
+			if( !v ) {
+				for( m in obj.getMaterials() ) {
+					m.mainPass.enableLights = false;
+					m.shadows = false;
+				}
+			} else {
+				for( m in obj.getMaterials() )
+					h3d.mat.MaterialSetup.current.initModelMaterial(m);
+			}
+		},true);
+
 		//tools.addButton("cube","Test");
-		//tools.addToggle("bank","Test toggle");
 	}
 
 	function update(dt:Float) {
 		var cam = scene.s3d.camera;
 		saveDisplayState("Camera", { x : cam.pos.x, y : cam.pos.y, z : cam.pos.z, tx : cam.target.x, ty : cam.target.y, tz : cam.target.z });
+		if( light != null ) {
+			var angle = Math.atan2(cam.target.y - cam.pos.y, cam.target.x - cam.pos.x);
+			light.direction.set(
+				Math.cos(angle) * lightDirection.x - Math.sin(angle) * lightDirection.y,
+				Math.sin(angle) * lightDirection.x + Math.cos(angle) * lightDirection.y,
+				lightDirection.z
+			);
+		}
 	}
 
 	function listAnims() {