Browse Source

Improve PropsEditor (#63)

Pavel Alexandrov 5 years ago
parent
commit
e543c754a0
3 changed files with 42 additions and 0 deletions
  1. 37 0
      hide/comp/PropsEditor.hx
  2. 4 0
      hide/tools/TypesCache.hx
  3. 1 0
      hrt/prefab/Props.hx

+ 37 - 0
hide/comp/PropsEditor.hx

@@ -75,8 +75,37 @@ class PropsEditor extends Component {
 			var e = new Element('<select field="${p.name}"></select>').appendTo(parent);
 		case PFile(exts):
 			new Element('<input type="texturepath" extensions="${exts.join(" ")}" field="${p.name}">').appendTo(parent);
+		case PString(len):
+			var e = new Element('<input type="text" field="${p.name}">').appendTo(parent);
+			if ( len != null ) e.attr("maxlength", "" + len);
+			if ( p.def != null ) e.attr("value", "" + p.def);
 		}
 	}
+	
+	public static function makeGroupEl(name: String, content: Element) {
+		var el = new Element('<div class="group" name="${name}"></div>');
+		content.appendTo(el);
+		return el;
+	}
+	
+	public static function makeSectionEl(name: String, content: Element, ?headerContent: Element) {
+		var el = new Element('<div class="section"><h1><span>${name}</span></h1><div class="content"></div></div>');
+		if (headerContent != null) headerContent.appendTo(el.find("h1"));
+		content.appendTo(el.find(".content"));
+		return el;
+	}
+	
+	public static function makeLabelEl(name: String, content: Element) {
+		var el = new Element('<dt>${name}</dt><dd></dd>');
+		content.appendTo(el.find("dd"));
+		return el;
+	}
+	
+	public static function makeListEl(content:Array<Element>) {
+		var el = new Element("<dl>");
+		for ( e in content ) e.appendTo(el);
+		return el;
+	}
 
 	static function upperCase(prop: String) {
 		return prop.charAt(0).toUpperCase() + prop.substr(1);
@@ -125,6 +154,10 @@ class PropsEditor extends Component {
 			section.children(".content").slideToggle(100);
 			saveDisplayState("section:" + StringTools.trim(e.getThis().text()), section.hasClass("open"));
 		}).find("input").mousedown(function(e) e.stopPropagation());
+		
+		e.find("input[type=section_name]").change(function(e) {
+			e.getThis().closest(".section").find(">h1 span").text(e.getThis().val());
+		});
 
 		// init groups
 		var gindex = 0;
@@ -157,6 +190,10 @@ class PropsEditor extends Component {
 			saveDisplayState("group:" + key, group.hasClass("open"));
 
 		}).find("input").mousedown(function(e) e.stopPropagation());
+		
+		e.find("input[type=group_name]").change(function(e) {
+			e.getThis().closest(".group").find(">.title").val(e.getThis().val());
+		});
 
 		// init input reflection
 		for( f in e.find("[field]").elements() ) {

+ 4 - 0
hide/tools/TypesCache.hx

@@ -238,6 +238,8 @@ class TypesCache {
 			return e.getConstructors()[0];
 		case PFile(_):
 			return null;
+		case PString(_):
+			return null;
 		}
 	}
 
@@ -249,6 +251,8 @@ class TypesCache {
 			PFloat();
 		case CTPath(["Bool"]):
 			PBool;
+		case CTPath(["String"]):
+			PString();
 		default:
 			PUnsupported(new hscript.Printer().typeToString(t));
 		}

+ 1 - 0
hrt/prefab/Props.hx

@@ -9,6 +9,7 @@ enum PropType {
 	PChoice( choices : Array<String> );
 	PFile( exts : Array<String> );
 	PEnum( e : Enum<Dynamic>);
+	PString( ?maxLen : Int );
 	PUnsupported( debug : String );
 }