Browse Source

Object3D: Fix Editor UI

lviguier 1 year ago
parent
commit
2479b348ff
2 changed files with 84 additions and 78 deletions
  1. 1 1
      hide/comp/SceneEditor.hx
  2. 83 77
      hrt/prefab/Object3D.hx

+ 1 - 1
hide/comp/SceneEditor.hx

@@ -3025,7 +3025,7 @@ class SceneEditor {
 				edit.onChange(e, 'props.$pname');
 				var e = Std.downcast(e, Object3D);
 				if( e != null ) {
-					e.addEditorUI(edit);
+					e.addEditorUI();
 				}
 			}
 		}

+ 83 - 77
hrt/prefab/Object3D.hx

@@ -78,6 +78,10 @@ class Object3D extends Prefab {
 			local3d.name = name;
 			local3d.visible = visible;
 		}
+
+		#if editor
+		this.addEditorUI();
+		#end
 	}
 
 	public static var _ = Prefab.register("object", Object3D);
@@ -203,100 +207,102 @@ class Object3D extends Prefab {
 		return true;
 	}
 
-	public function addEditorUI(ctx : hide.prefab.EditContext) {
+	public function addEditorUI() {
+		//return;
 		var objs = findAll(Object3D, true);
 		for( obj in objs ) {
 			var local3d : h3d.scene.Object = obj.local3d;
 			if( local3d != null && local3d.name != null && StringTools.startsWith(local3d.name,"$UI.") )
 				local3d.remove();
 		}
-		// add ranges
 
-			var sheet = getCdbType();
-			if( sheet != null ) {
-				var ide = hide.Ide.inst;
-			var ranges = Reflect.field(ctx.scene.config.get("sceneeditor.ranges"), sheet);
-				if( ranges != null ) {
-					for( key in Reflect.fields(ranges) ) {
-						var color = Std.parseInt(Reflect.field(ranges,key));
-						var value : Dynamic = hide.comp.cdb.DataFiles.resolveCDBValue(sheet,key, props);
-						if( value != null ) {
-						var mesh = new h3d.scene.Mesh(hrt.prefab.l3d.Spray.makePrimCircle(128, 0.99), local3d);
-							mesh.name = "$UI.RANGE";
-							mesh.ignoreCollide = true;
-							mesh.ignoreBounds = true;
-							mesh.material.mainPass.culling = None;
-							mesh.material.name = "$UI.RANGE";
-							mesh.setScale(value);
-							mesh.scaleZ = 0.1;
-							mesh.material.color.setColor(color|0xFF000000);
-							mesh.material.mainPass.enableLights = false;
-							mesh.material.shadows = false;
-							mesh.material.mainPass.setPassName("overlay");
-						}
+		// add ranges
+		var sheet = getCdbType();
+		if( sheet != null ) {
+			var ide = hide.Ide.inst;
+
+			var ranges = Reflect.field(ide.currentConfig.get("sceneeditor.ranges"), sheet);
+			if( ranges != null ) {
+				for( key in Reflect.fields(ranges) ) {
+					var color = Std.parseInt(Reflect.field(ranges,key));
+					var value : Dynamic = hide.comp.cdb.DataFiles.resolveCDBValue(sheet,key, props);
+					if( value != null ) {
+					var mesh = new h3d.scene.Mesh(hrt.prefab.l3d.Spray.makePrimCircle(128, 0.99), local3d);
+						mesh.name = "$UI.RANGE";
+						mesh.ignoreCollide = true;
+						mesh.ignoreBounds = true;
+						mesh.material.mainPass.culling = None;
+						mesh.material.name = "$UI.RANGE";
+						mesh.setScale(value);
+						mesh.scaleZ = 0.1;
+						mesh.material.color.setColor(color|0xFF000000);
+						mesh.material.mainPass.enableLights = false;
+						mesh.material.shadows = false;
+						mesh.material.mainPass.setPassName("overlay");
 					}
 				}
-			var huds : Dynamic = ctx.scene.config.get("sceneeditor.huds");
-				var icon = Reflect.field(huds, sheet);
-				if( icon != null ) {
-					var t : Dynamic = hide.comp.cdb.DataFiles.resolveCDBValue(sheet,icon, props);
-					if( t != null && (t.file != null || Std.isOfType(t,String)) ) {
-					var obj = editorIcon;
-					if( obj == null || obj.follow != local3d ) {
-						editorIcon = obj = new h2d.ObjectFollower(local3d, shared.root2d);
-							obj.horizontalAlign = Middle;
-							obj.followVisibility = true;
+			}
+		var huds : Dynamic = ide.currentConfig.get("sceneeditor.huds");
+			var icon = Reflect.field(huds, sheet);
+			if( icon != null ) {
+				var t : Dynamic = hide.comp.cdb.DataFiles.resolveCDBValue(sheet,icon, props);
+				if( t != null && (t.file != null || Std.isOfType(t,String)) ) {
+				var obj = editorIcon;
+				if( obj == null || obj.follow != local3d ) {
+					editorIcon = obj = new h2d.ObjectFollower(local3d, shared.root2d);
+						obj.horizontalAlign = Middle;
+						obj.followVisibility = true;
+					}
+					if( t.file != null ) {
+						var t : cdb.Types.TilePos = t;
+						var bmp = Std.downcast(obj.getObjectByName("$huds"), h2d.Bitmap);
+						var shouldAddInt = false;
+						if( bmp == null ) {
+							shouldAddInt = true;
+							bmp = new h2d.Bitmap(null, obj);
+							bmp.name = "$huds";
 						}
-						if( t.file != null ) {
-							var t : cdb.Types.TilePos = t;
-							var bmp = Std.downcast(obj.getObjectByName("$huds"), h2d.Bitmap);
-							var shouldAddInt = false;
-							if( bmp == null ) {
-								shouldAddInt = true;
-								bmp = new h2d.Bitmap(null, obj);
-								bmp.name = "$huds";
-							}
-						bmp.tile = h2d.Tile.fromTexture(shared.loadTexture(t.file)).sub(
-								t.x * t.size,
-								t.y * t.size,
-								(t.width == null ? 1 : t.width) * t.size,
-								(t.height == null ? 1 : t.height) * t.size
-							);
-
-							if (shouldAddInt) {
-								var int = new h2d.Interactive(huds.maxWidth, huds.maxWidth, bmp);
-								int.propagateEvents = false;
-								int.x = bmp.tile.dx;
-								int.y = bmp.tile.dy;
-
-								int.onClick = function(e) {
-									var editorContext = Std.downcast(shared, hide.prefab.ContextShared);
-									if (editorContext != null)
-										editorContext.editor.selectElements([ this ]);
-								}
+					bmp.tile = h2d.Tile.fromTexture(shared.loadTexture(t.file)).sub(
+							t.x * t.size,
+							t.y * t.size,
+							(t.width == null ? 1 : t.width) * t.size,
+							(t.height == null ? 1 : t.height) * t.size
+						);
+
+						if (shouldAddInt) {
+							var int = new h2d.Interactive(huds.maxWidth, huds.maxWidth, bmp);
+							int.propagateEvents = false;
+							int.x = bmp.tile.dx;
+							int.y = bmp.tile.dy;
+
+							int.onClick = function(e) {
+								var editorContext = Std.downcast(shared, hide.prefab.ContextShared);
+								if (editorContext != null)
+									editorContext.editor.selectElements([ this ]);
 							}
+						}
 
-							var maxWidth : Dynamic = huds.maxWidth;
-							if( maxWidth != null && bmp.tile.width > maxWidth )
-								bmp.width = maxWidth;
-						} else {
-							var f = Std.downcast(obj.getObjectByName("$huds_f"), h2d.Flow);
-							if( f == null ) {
-								f = new h2d.Flow(obj);
-								f.name = "$huds_f";
-								f.padding = 3;
-								f.paddingTop = 1;
-								f.backgroundTile = h2d.Tile.fromColor(0,1,1,0.5);
-							}
-							var tf = cast(f.getChildAt(1), h2d.Text);
-							if( tf == null )
-								tf = new h2d.Text(hxd.res.DefaultFont.get(), f);
-							tf.text = t;
+						var maxWidth : Dynamic = huds.maxWidth;
+						if( maxWidth != null && bmp.tile.width > maxWidth )
+							bmp.width = maxWidth;
+					} else {
+						var f = Std.downcast(obj.getObjectByName("$huds_f"), h2d.Flow);
+						if( f == null ) {
+							f = new h2d.Flow(obj);
+							f.name = "$huds_f";
+							f.padding = 3;
+							f.paddingTop = 1;
+							f.backgroundTile = h2d.Tile.fromColor(0,1,1,0.5);
 						}
+						var tf = cast(f.getChildAt(1), h2d.Text);
+						if( tf == null )
+							tf = new h2d.Text(hxd.res.DefaultFont.get(), f);
+						tf.text = t;
 					}
 				}
 			}
 		}
+	}
 
 	override function makeInteractive() : hxd.SceneEvents.Interactive {
 		if(local3d == null)