Forráskód Böngészése

Allow fixing references manually, show error if not found

trethaller 7 éve
szülő
commit
0f1e08dc6f
3 módosított fájl, 35 hozzáadás és 1 törlés
  1. 3 0
      bin/style.css
  2. 4 0
      bin/style.less
  3. 28 1
      hide/prefab/Reference.hx

+ 3 - 0
bin/style.css

@@ -552,6 +552,9 @@ input[type=checkbox]:checked:after {
 .hide-properties .group > .content {
   margin-bottom: 5px;
 }
+.hide-properties .error {
+  color: red;
+}
 /* Curve editor */
 .hide-curve-editor:focus {
   background-color: rgba(0, 0, 0, 0.219);

+ 4 - 0
bin/style.less

@@ -600,6 +600,10 @@ input[type=checkbox] {
 		margin-bottom : 5px;
 	}
 
+	.error {
+		color: red;
+	}
+
 }
 
 /* Curve editor */

+ 28 - 1
hide/prefab/Reference.hx

@@ -29,7 +29,8 @@ class Reference extends Prefab {
 		var lib = getParent(hxd.prefab.Library);
 		if(lib == null)
 			return null;
-		return lib.getOpt(Prefab, refpath);
+		ref = lib.getOpt(Prefab, refpath);
+		return ref;
 	}
 
 	override function makeInstance(ctx: Context) : Context {
@@ -43,6 +44,32 @@ class Reference extends Prefab {
 	}
 
 	#if editor
+
+	
+	override function edit( ctx : EditContext ) {
+		var element = new hide.Element('
+			<dl>
+				<dt>Reference</dt><dd><input type="text" field="refpath"/></dd>
+			</dl>');
+
+		function updateProps() {
+			var input = element.find("input");
+			var found = resolveRef() != null;
+			input.toggleClass("error", !found);
+		}
+		updateProps();
+
+		var props = ctx.properties.add(element, this, function(pname) {
+			ctx.onChange(this, pname);
+			if(pname == "refpath") {
+				ref = null;
+				updateProps();
+				if(!ctx.properties.isTempChange)
+					ctx.refresh(this);
+			}	
+		});
+	}
+
 	override function getHideProps() : HideProps {
 		return { icon : "share", name : "Reference" };
 	}