Przeglądaj źródła

moved cdb props from Level3D to SceneEditor

Nicolas Cannasse 5 lat temu
rodzic
commit
1e38f8b656
2 zmienionych plików z 68 dodań i 57 usunięć
  1. 67 0
      hide/comp/SceneEditor.hx
  2. 1 57
      hide/view/l3d/Level3D.hx

+ 67 - 0
hide/comp/SceneEditor.hx

@@ -16,6 +16,8 @@ import hrt.prefab.Object2D;
 import hrt.prefab.Object3D;
 import hrt.prefab.Object3D;
 import h3d.scene.Object;
 import h3d.scene.Object;
 
 
+import hide.comp.cdb.DataFiles;
+
 enum SelectMode {
 enum SelectMode {
 	/**
 	/**
 		Update tree, add undo command
 		Update tree, add undo command
@@ -1304,8 +1306,73 @@ class SceneEditor {
 		}));
 		}));
 	}
 	}
 
 
+	function makeCdbProps( e : PrefabElement, type : cdb.Sheet ) {
+		var props = type.getDefaults();
+		Reflect.setField(props, "$cdbtype", DataFiles.getTypeName(type));
+		if( type.idCol != null && !type.idCol.opt ) {
+			var id = new haxe.io.Path(view.state.path).file;
+			id = id.charAt(0).toUpperCase() + id.substr(1);
+			id += "_"+e.name;
+			Reflect.setField(props, type.idCol.name, id);
+		}
+		return props;
+	}
+
 	function fillProps( edit, e : PrefabElement ) {
 	function fillProps( edit, e : PrefabElement ) {
 		e.edit(edit);
 		e.edit(edit);
+
+		var typeName = e.getCdbType();
+		if( typeName == null && e.props != null )
+			return; // don't allow CDB data with props already used !
+
+		var types = DataFiles.getAvailableTypes();
+		if( types.length == 0 )
+			return;
+
+		var group = new hide.Element('
+			<div class="group" name="CDB">
+				<dl><dt>Type</dt><dd><select><option value="">- No props -</option></select></dd>
+			</div>
+		');
+
+		var select = group.find("select");
+		for(t in types) {
+			var id = DataFiles.getTypeName(t);
+			new hide.Element("<option>").attr("value", id).text(id).appendTo(select);
+		}
+
+		var curType = DataFiles.resolveType(typeName);
+		if(curType != null) select.val(DataFiles.getTypeName(curType));
+
+		function changeProps(props: Dynamic) {
+			properties.undo.change(Field(e, "props", e.props), ()->edit.rebuildProperties());
+			e.props = props;
+			edit.onChange(e, "props");
+			edit.rebuildProperties();
+		}
+
+		select.change(function(v) {
+			var typeId = select.val();
+			if(typeId == null || typeId == "") {
+				changeProps(null);
+				return;
+			}
+			var props = makeCdbProps(e, DataFiles.resolveType(typeId));
+			changeProps(props);
+		});
+
+		edit.properties.add(group);
+
+		if(curType != null) {
+			var props = new hide.Element('<div></div>').appendTo(group.find(".content"));
+			var editor = new hide.comp.cdb.ObjEditor(curType, view.config, e.props, props);
+			editor.undo = properties.undo;
+			editor.onChange = function(pname) {
+				edit.onChange(e, 'props.$pname');
+				var e = Std.instance(e, hrt.prefab.l3d.Instance);
+				if( e != null ) e.addRanges(context.shared.contexts.get(e));
+			}
+		}
 	}
 	}
 
 
 	public function showProps(e: PrefabElement) {
 	public function showProps(e: PrefabElement) {

+ 1 - 57
hide/view/l3d/Level3D.hx

@@ -192,9 +192,8 @@ private class Level3DSceneEditor extends hide.comp.SceneEditor {
 
 
 				function make(name) {
 				function make(name) {
 					var p = new hrt.prefab.l3d.Instance(current == null ? sceneData : current);
 					var p = new hrt.prefab.l3d.Instance(current == null ? sceneData : current);
-					p.props = type.getDefaults();
-					Reflect.setField(p.props, "$cdbtype", typeId);
 					p.name = name;
 					p.name = name;
+					p.props = makeCdbProps(p, type);
 					setup(p);
 					setup(p);
 					if(onMake != null)
 					if(onMake != null)
 						onMake(p);
 						onMake(p);
@@ -234,61 +233,6 @@ private class Level3DSceneEditor extends hide.comp.SceneEditor {
 		return newItems;
 		return newItems;
 	}
 	}
 
 
-	override function fillProps(edit:hide.prefab.EditContext, e:PrefabElement) {
-		super.fillProps(edit, e);
-
-		var typeName = e.getCdbType();
-		if( typeName == null && e.props != null )
-			return; // don't allow CDB data with props already used !
-
-		var group = new hide.Element('
-			<div class="group" name="CDB">
-				<dl><dt>Type</dt><dd><select><option value="">- No props -</option></select></dd>
-			</div>
-		');
-
-		var select = group.find("select");
-		for(t in DataFiles.getAvailableTypes()) {
-			var id = DataFiles.getTypeName(t);
-			new hide.Element("<option>").attr("value", id).text(id).appendTo(select);
-		}
-
-		var curType = DataFiles.resolveType(typeName);
-		if(curType != null) select.val(DataFiles.getTypeName(curType));
-
-		function changeProps(props: Dynamic) {
-			properties.undo.change(Field(e, "props", e.props), ()->edit.rebuildProperties());
-			e.props = props;
-			edit.onChange(e, "props");
-			edit.rebuildProperties();
-		}
-
-		select.change(function(v) {
-			var typeId = select.val();
-			if(typeId == null || typeId == "") {
-				changeProps(null);
-				return;
-			}
-			var cdbSheet = DataFiles.resolveType(typeId);
-			var props = cdbSheet.getDefaults();
-			Reflect.setField(props, "$cdbtype", typeId);
-			changeProps(props);
-		});
-
-		edit.properties.add(group);
-
-		if(curType != null) {
-			var props = new hide.Element('<div></div>').appendTo(group.find(".content"));
-			var editor = new hide.comp.cdb.ObjEditor(curType, parent.config, e.props, props);
-			editor.undo = properties.undo;
-			editor.onChange = function(pname) {
-				edit.onChange(e, 'props.$pname');
-				var e = Std.instance(e, hrt.prefab.l3d.Instance);
-				if( e != null ) e.addRanges(context.shared.contexts.get(e));
-			}
-		}
-	}
-
 	override function getAvailableTags(p:PrefabElement) {
 	override function getAvailableTags(p:PrefabElement) {
 		return cast ide.currentConfig.get("l3d.tags");
 		return cast ide.currentConfig.get("l3d.tags");
 	}
 	}