Kaynağa Gözat

GuiEditor

-Gui Editor as a module
-Few options still not linked up.

// features remaining:
Load gui
Auto load active gui
save dialog for naming and directory
marauder2k7 4 yıl önce
ebeveyn
işleme
12df14e0af

+ 115 - 0
toybox/GuiEditorToy/1/assets/gui/ColorSelectorTool.gui

@@ -0,0 +1,115 @@
+//--- Created With GUIEDITORTOY ---//
+%guiContent = new GuiControl() {
+   canSaveDynamicFields = "0";
+   isContainer = "1";
+   Profile = "GuiDefaultProfile";
+   HorizSizing = "width";
+   VertSizing = "height";
+   Position = "0 0";
+   Extent = "1024 748";
+   MinExtent = "8 2";
+   canSave = "1";
+   Visible = "1";
+   Active = "0";
+   tooltipWidth = "250";
+   hovertime = "1000";
+
+   new GuiWindowCtrl(CBBWindow) {
+      canSaveDynamicFields = "0";
+      isContainer = "1";
+      Profile = "GuiWindowProfile";
+      HorizSizing = "right";
+      VertSizing = "bottom";
+      Position = "384 272";
+      Extent = "200 208";
+      MinExtent = "8 2";
+      canSave = "1";
+      Visible = "1";
+      Active = "1";
+      tooltipWidth = "250";
+      hovertime = "1000";
+      Text = "Colour Picker";
+      resizeWidth = "1";
+      resizeHeight = "1";
+      canMove = "1";
+      canClose = "1";
+      canMinimize = "0";
+      canMaximize = "0";
+      minSize = "50 50";
+
+      new GuiColorPickerCtrl(CBBC) {
+         canSaveDynamicFields = "0";
+         isContainer = "0";
+         Profile = "GuiDefaultProfile";
+         HorizSizing = "right";
+         VertSizing = "bottom";
+         Position = "16 32";
+         Extent = "136 128";
+         MinExtent = "8 2";
+         canSave = "1";
+         Visible = "1";
+         Active = "1";
+         tooltipWidth = "250";
+         hovertime = "1000";
+         BaseColor = "Red";
+         PickColor = "Black";
+         SelectorGap = "1";
+         DisplayMode = "BlendColor";
+         ActionOnMove = "1";
+         ShowSelector = "1";
+      };
+      new GuiColorPickerCtrl(CBVC) {
+         canSaveDynamicFields = "0";
+         isContainer = "0";
+         Profile = "GuiDefaultProfile";
+         HorizSizing = "right";
+         VertSizing = "bottom";
+         Position = "160 32";
+         Extent = "24 128";
+         MinExtent = "8 2";
+         canSave = "1";
+         Visible = "1";
+         Active = "1";
+         tooltipWidth = "250";
+         hovertime = "1000";
+         BaseColor = "Red";
+         PickColor = "Black";
+         SelectorGap = "1";
+         DisplayMode = "VertColor";
+         ActionOnMove = "1";
+         ShowSelector = "1";
+      };
+      new GuiSliderCtrl() {
+         canSaveDynamicFields = "0";
+         isContainer = "0";
+         Profile = "GuiSliderProfile";
+         HorizSizing = "right";
+         VertSizing = "bottom";
+         Position = "16 168";
+         Extent = "168 16";
+         MinExtent = "8 2";
+         canSave = "1";
+         Visible = "1";
+         Active = "1";
+         tooltipWidth = "250";
+         hovertime = "1000";
+         range = "0.000 1.000";
+         ticks = "0";
+         Value = "1";
+      };
+   };
+};
+//--- GUIEDITORTOY END ---//
+
+function CBBC::onAction(%this)
+{
+	%col = CBBC.getFieldValue("PickColor");
+	echo(%col);
+}
+
+function CBVC::onAction(%this)
+{
+	%col = CBVC.getFieldValue("PickColor");
+	CBBC.setFieldValue("BaseColor", %col);
+	CBBC.updateColor();
+}

+ 73 - 0
toybox/GuiEditorToy/1/assets/gui/guiEditorCtrl.gui

@@ -0,0 +1,73 @@
+//--- OBJECT WRITE BEGIN ---
+%guiContent = new GuiControl(GuiEditorCtrl) {
+   parentGroup = "GuiEditorContent";
+   position = "0 0";
+   Extent = "1024 768";
+   minExtent = "8 2";
+   horizSizing = "right";
+   vertSizing = "bottom";
+   profile = "GuiDefaultProfile";
+   visible = "1";
+   active = "1";
+   tooltipProfile = "GuiToolTipProfile";
+   hovertime = "1000";
+   isContainer = "1";
+   canSave = "1";
+   canSaveDynamicFields = "1";
+   
+    new GuiBitmapCtrl() {
+		HorizSizing = "width";
+        VertSizing = "height";
+        Position = "0 0";
+        Extent = "1024 768";
+        MinExtent = "8 2";
+        canSave = "1";
+        Visible = "1";
+        hovertime = "1000";
+        bitmap = "./images/gridTiny2";
+        wrap = "1";
+	};
+   
+    new GuiControl(GuiEditorContent) {
+        canSaveDynamicFields = "0";
+        isContainer = "1";
+        Profile = "GuiDefaultProfile";
+        HorizSizing = "width";
+        VertSizing = "height";
+        Position = "0 0";
+        Extent = "1024 768";
+        MinExtent = "8 2";
+        canSave = "1";
+        Visible = "1";
+        hovertime = "1000";
+				  
+		new GuiControl(GuiBlank) {
+            canSaveDynamicFields = "0";
+            isContainer = "1";
+            Profile = "GuiDefaultProfile";
+            HorizSizing = "width";
+            VertSizing = "height";
+            Position = "0 0";
+            Extent = "1024 768";
+            MinExtent = "8 2";
+            canSave = "1";
+            Visible = "1";
+            hovertime = "1000";
+		};
+	};
+		
+	new GuiEditCtrl(GuiEditor) {
+		canSaveDynamicFields = "0";
+		isContainer = "0";
+		Profile = "GuiTextEditProfile";
+		HorizSizing = "width";
+		VertSizing = "height";
+		Position = "0 0";
+		Extent = "1024 768";
+		minExtent = "8 2";
+		canSave = "1";
+		Visible = "1";
+		hovertime = "1000";
+	};
+};
+//--- OBJECT WRITE END ---

+ 204 - 0
toybox/GuiEditorToy/1/assets/gui/guiToolbox.gui

@@ -0,0 +1,204 @@
+%guiContent = new GuiControl(GuiToolboxGui) {
+    position = "0 0";
+    extent = "1024 768";
+    minExtent = "8 2";
+    horizSizing = "right";
+    vertSizing = "bottom";
+    profile = "GuiDefaultProfile";
+    visible = "1";
+    active = "1";
+    tooltipProfile = "GuiToolTipProfile";
+    hovertime = "1000";
+    isContainer = "1";
+    canSave = "1";
+    canSaveDynamicFields = "1";
+   
+	new GuiWindowCtrl(GuiToolbox) {
+		canSaveDynamicFields = "0";
+		internalName = "toolbox";
+		isContainer = "1";
+		Profile = "GuiWindowProfile";
+		HorizSizing = "left";
+		VertSizing = "bottom";
+		position = "640 40";
+		Extent = "220 380";
+		MinExtent = "8 2";
+		canSave = "1";
+		Visible = "1";
+		hovertime = "1000";
+		text = "GUI Toolbox";
+		maxLength = "1024";
+		resizeWidth = "1";
+		resizeHeight = "1";
+		canMove = "1";
+		canClose = "0";
+		canMinimize = "1";
+		canMaximize = "0";
+		minSize = "50 50";
+		
+		new GuiScrollCtrl() {
+            canSaveDynamicFields = "0";
+            isContainer = "1";
+            Profile="GuiTransparentScrollProfile";
+			ThumbProfile = "GuiScrollThumbProfile";
+			TrackProfile = "GuiScrollTrackProfile";
+			ArrowProfile = "GuiScrollArrowProfile";
+            HorizSizing = "width";
+            VertSizing = "height";
+            position = "0 20";
+            Extent = "220 340";
+            MinExtent = "8 2";
+            canSave = "1";
+            Visible = "1";
+            hovertime = "1000";
+            willFirstRespond = "1";
+            hScrollBar = "alwaysOff";
+            vScrollBar = "dynamic";
+			constantThumbHeight="0";
+			showArrowButtons="0";
+			scrollBarThickness="14";
+		
+			new GuiListBoxCtrl() {
+				canSaveDynamicFields = "0";
+				internalName = "toolboxList";
+				superclass = "GuiEditorToolboxDrag";
+				isContainer = "0";
+				Profile = "GuiListBoxProfile";
+				HorizSizing = "width";
+				VertSizing = "height";
+				position = "2 20";
+				Extent = "218 1260";
+				MinExtent = "8 2";
+				canSave = "1";
+				Visible = "1";
+				hovertime = "1000";
+				AllowMultipleSelections = "0";
+				fitParentWidth = "1";
+			};
+		};
+	};
+	
+	new GuiWindowCtrl(GuiInspectorWindow) {
+		canSaveDynamicFields = "0";
+		isContainer = "1";
+		Profile = "GuiWindowProfile";
+		HorizSizing = "left";
+		VertSizing = "bottom";
+		position = "60 40";
+		Extent = "360 380";
+		MinExtent = "8 2";
+		canSave = "1";
+		Visible = "1";
+		hovertime = "1000";
+		text = "GUI Inspector";
+		maxLength = "1024";
+		resizeWidth = "1";
+		resizeHeight = "1";
+		canMove = "1";
+		canClose = "0";
+		canMinimize = "1";
+		canMaximize = "0";
+		minSize = "50 50";
+		
+		new GuiScrollCtrl() {
+            canSaveDynamicFields = "0";
+            isContainer = "1";
+            Profile="GuiTransparentScrollProfile";
+			ThumbProfile = "GuiScrollThumbProfile";
+			TrackProfile = "GuiScrollTrackProfile";
+			ArrowProfile = "GuiScrollArrowProfile";
+            HorizSizing = "width";
+            VertSizing = "height";
+            position = "0 20";
+            Extent = "360 340";
+            MinExtent = "8 2";
+            canSave = "1";
+            Visible = "1";
+            hovertime = "1000";
+            willFirstRespond = "1";
+            hScrollBar = "alwaysOff";
+            vScrollBar = "alwaysOn";
+			constantThumbHeight="0";
+			showArrowButtons="0";
+			scrollBarThickness="14";
+		
+			new GuiChainCtrl(GuiEditorCtrlProperties) {
+                isContainer = "1";
+                Position = "0 20";
+                Extent = "340 40";
+				HorizSizing = "width";
+				VertSizing = "height";
+            };
+		};
+	};
+	
+	new GuiWindowCtrl(GuiTreeViewWindow) {
+		canSaveDynamicFields = "0";
+		isContainer = "1";
+		Profile = "GuiWindowProfile";
+		HorizSizing = "left";
+		VertSizing = "bottom";
+		position = "360 40";
+		Extent = "220 380";
+		MinExtent = "8 2";
+		canSave = "1";
+		Visible = "1";
+		hovertime = "1000";
+		text = "Current GUI";
+		maxLength = "1024";
+		resizeWidth = "1";
+		resizeHeight = "1";
+		canMove = "1";
+		canClose = "0";
+		canMinimize = "1";
+		canMaximize = "0";
+		minSize = "50 50";
+		
+		new GuiScrollCtrl() {
+            canSaveDynamicFields = "0";
+            isContainer = "1";
+            Profile="GuiTransparentScrollProfile";
+			ThumbProfile = "GuiScrollThumbProfile";
+			TrackProfile = "GuiScrollTrackProfile";
+			ArrowProfile = "GuiScrollArrowProfile";
+            HorizSizing = "width";
+            VertSizing = "height";
+            position = "0 20";
+            Extent = "220 340";
+            MinExtent = "8 2";
+            canSave = "1";
+            Visible = "1";
+            hovertime = "1000";
+            willFirstRespond = "1";
+            hScrollBar = "alwaysOff";
+            vScrollBar = "alwaysOn";
+			constantThumbHeight="0";
+			showArrowButtons="0";
+			scrollBarThickness="14";
+		
+			new GuiTreeViewCtrl(GuiEditorTreeView) {
+               canSaveDynamicFields = "0";
+               isContainer = "1";
+               Profile = "GuiTreeViewProfile";
+               HorizSizing = "width";
+               VertSizing = "height";
+               Position = "1 1";
+               Extent = "200 20";
+               MinExtent = "8 2";
+               canSave = "1";
+               Visible = "1";
+               hovertime = "1000";
+               tabSize = "16";
+               textOffset = "2";
+               fullRowSelect = "0";
+               itemHeight = "21";
+               destroyTreeOnSleep = "1";
+               MouseDragging = "1";
+               MultipleSelections = "1";
+               DeleteObjectAllowed = "1";
+               DragToItemAllowed = "1";
+            };
+		};
+	};
+	
+};

BIN
toybox/GuiEditorToy/1/assets/gui/images/gridTiny2.PNG


+ 521 - 0
toybox/GuiEditorToy/1/assets/scripts/GuiEditorCtrlProperties.cs

@@ -0,0 +1,521 @@
+$currentTarget = "";
+// Doing this in script might end up being a waste of time
+// but because of the way the current inspector is messing about
+// it is needed.
+
+function GuiEditorCtrlProperties::update(%this, %target)
+{
+	// We can only get here from the guiEdit so its definitely a 
+	// gui control, no need to check.
+	if(%target == 0)
+	{
+		GuiEditorCtrlProperties.clear();
+		$currentTarget = "";
+	}
+	else
+	{
+		if($currentTarget != %target)
+		{
+			%this.build(%target);
+		}
+		else
+		{
+			%this.updateValues(%target);
+		}
+	}
+}
+
+function GuiEditorCtrlProperties::updateValues(%this, %target)
+{
+	%count = %target.getFieldCount();
+	for(%i = 0; %i < %count; %i++)
+	{
+		%field = %target.getField(%i);
+		%fieldType = %target.getFieldType(%field);
+		if(%fieldType $= "Point2I")
+		{
+			%fieldVal = %target.getFieldValue(%field);
+			%fieldEditX = %field @ "editX";
+			%fieldEditY = %field @ "editY";
+			%fieldEditX.setText(%fieldVal.x);
+			%fieldEditY.setText(%fieldVal.y);
+			
+		}
+		else if(%fieldType $= "bool")
+		{
+			%fieldEdit = %field @ "edit";
+			%fieldEdit.setStateOn(%target.getFieldValue(%field));
+		}
+		else
+		{
+			%fieldEdit = %field @ "edit";
+			%fieldEdit.setText(%target.getFieldValue(%field));
+		}
+	}
+}
+
+function GuiEditorCtrlProperties::build(%this, %target)
+{
+	$dynSim = new SimSet();
+	$currentTarget = %target;
+	GuiEditorCtrlProperties.clear();
+	%count = %target.getFieldCount();
+	for(%i = 0; %i < %count; %i++)
+	{
+		
+		%fieldCtrl = new GuiControl()
+		{
+			extent = "320 30";
+			horizSizing = "right";
+			vertSizing = "bottom";
+			profile = "GuiDefaultProfile";
+			visible = "1";
+		};
+		
+		%field = %target.getField(%i);
+		
+		%fieldLabel = new GuiControl()
+		{
+			text = %field @ ": ";
+			profile = "GuiTextRightProfile";
+			Position = "10 0";
+			extent = "150 30";
+			horizSizing = "right";
+			vertSizing = "bottom";
+			visible = "1";
+		};
+		
+		%fieldType = %target.getFieldType(%field);
+		%fieldVal = %target.getFieldValue(%field);
+		%fieldEdit = %this.buildEdit(%field,%fieldType,%fieldVal);
+		%fieldCtrl.add(%fieldLabel);
+		%fieldCtrl.add(%fieldEdit);
+
+		GuiEditorCtrlProperties.add(%fieldCtrl);
+	}
+	%dynCtrl = new GuiPanelCtrl()
+	{
+		position = "10 0";
+		extent = "320 20";
+		horizSizing = "right";
+		vertSizing = "bottom";
+		profile = "GuiPanelProfile";
+		visible = "1";
+		Text = "Dynamic Fields";
+	};
+	
+	GuiEditorCtrlProperties.add(%dynCtrl);
+	
+	%addDyn = new GuiControl()
+	{
+		Position = "0 20";
+		extent = "320 30";
+		horizSizing = "right";
+		vertSizing = "bottom";
+		profile = "GuiDefaultProfile";
+		visible = "1";
+	};
+	
+	%label = new GuiControl()
+	{
+		text = "Add Dynamic Field";
+		profile = "GuiTextProfile";
+		Position = "10 0";
+		extent = "150 30";
+		horizSizing = "right";
+		vertSizing = "bottom";
+		visible = "1";
+	};
+	
+	%bttn = new GuiButtonCtrl()
+	{
+		text = "+";
+		profile = "GuiButtonDynProfile";
+		Position = "280 0";
+		extent = "30 30";
+		Command = "GuiEditorCtrlProperties.addDynamic();";
+	};
+	
+	%addDyn.add(%label);
+	%addDyn.add(%bttn);
+	%dynCtrl.add(%addDyn);
+	
+	%dynChain = new GuiChainCtrl(DynamicContainer)
+	{
+		position = "0 50";
+		extent = "320 30";
+	};
+	
+	%dynCtrl.add(%dynChain);
+	
+	GuiEditorCtrlProperties.updateDynamicFields();
+}
+
+function GuiEditorCtrlProperties::addDynamic(%this)
+{
+	%name = "dynamicField" @ $currentTarget.getDynamicFieldCount();
+	$currentTarget.setFieldValue(%name,"defaultValue");
+	
+	GuiEditorCtrlProperties.updateDynamicFields();
+}
+
+function GuiEditorCtrlProperties::removeDynamic(%this, %field)
+{
+	$currentTarget.setFieldValue(%field,"");
+	GuiEditorCtrlProperties.updateDynamicFields();
+}
+
+function GuiEditorCtrlProperties::renameDynamic(%this, %field, %newName, %fieldVal)
+{
+	$currentTarget.setFieldValue(%newName, %fieldVal);
+	$currentTarget.setFieldValue(%field,"");
+	GuiEditorCtrlProperties.updateDynamicFields();
+}
+
+function GuiEditorCtrlProperties::updateDynamicFields(%this)
+{
+	%count = $currentTarget.getDynamicFieldCount();
+	DynamicContainer.clear();
+	for(%i = 0; %i < %count; %i++)
+	{
+		%field = $currentTarget.getDynamicField(%i);
+		%fieldVal = $currentTarget.getFieldValue(%field);
+		
+		
+		%dynCtrl = new GuiControl()
+		{
+			extent = "320 30";
+			horizSizing = "right";
+			vertSizing = "bottom";
+			profile = "GuiDefaultProfile";
+			visible = "1";
+		};
+		
+		%label = new GuiTextEditCtrl()
+		{
+			text = %field;
+			profile = "GuiTextEditProfile";
+			Position = "10 0";
+			extent = "130 30";
+			horizSizing = "right";
+			vertSizing = "bottom";
+			visible = "1";
+		};
+		
+		%val = new GuiTextEditCtrl()
+		{
+			text = %fieldVal;
+			profile = "GuiTextEditProfile";
+			Position = "140 0";
+			extent = "130 30";
+			horizSizing = "right";
+			vertSizing = "bottom";
+			visible = "1";
+		};
+		%label.setFieldValue("AltCommand", "GuiEditorCtrlProperties.renameDynamic(" @ %field @ "," @ %label.getId()  @ ".getText()," @ %val.getId()  @ ".getText());");
+		%label.setFieldValue("Validate", "GuiEditorCtrlProperties.renameDynamic(" @ %field @ "," @ %label.getId()  @ ".getText()," @ %val.getId()  @ ".getText());");
+		
+		%val.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %val.getId() @ ".getText());");
+		%val.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %val.getId() @ ".getText());");
+		
+		%bttn = new GuiButtonCtrl()
+		{
+			text = "X";
+			profile = "GuiButtonDynProfile";
+			Position = "280 0";
+			extent = "30 30";
+		};
+		
+		%bttn.setFieldValue("Command", "GuiEditorCtrlProperties.removeDynamic(" @ %field @ ");");
+		%dynCtrl.add(%label);
+		%dynCtrl.add(%val);
+		%dynCtrl.add(%bttn);
+		DynamicContainer.add(%dynCtrl);
+		DynamicContainer.getParent().setExpanded(0);
+		DynamicContainer.getParent().setExpanded(1);
+	}
+}
+
+function GuiEditorCtrlProperties::setData(%this,%field, %val)
+{
+	$currentTarget.setEditFieldValue(%field, %val);
+}
+
+function GuiEditorCtrlProperties::buildEdit(%this,%field,%fieldType,%fieldVal)
+{
+	// items yet to be added:
+	// filename
+	// RectI
+	// assetIdString
+	// audioAssetPtr
+	
+	%fieldEdit = %field @ "edit";
+	echo(%field TAB %fieldType TAB %fieldVal);
+	switch$(%fieldType)
+	{
+		case "float":
+			%ctrl = new GuiTextEditCtrl(%fieldEdit)
+				{
+					Text = %fieldVal;
+					Position = "160 0";
+					extent = "160 30";
+					horizSizing = "right";
+					vertSizing = "bottom";
+					visible = "1";
+					Profile = "GuiTextEditProfile";
+				};
+			%ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+			%ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+			return %ctrl;
+			
+		case "ColorF":
+			%ctrl = new GuiTextEditCtrl(%fieldEdit)
+				{
+					Text = %fieldVal;
+					Position = "160 0";
+					extent = "160 30";
+					horizSizing = "right";
+					vertSizing = "bottom";
+					visible = "1";
+					Profile = "GuiTextEditProfile";
+				};
+			%ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+			%ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+			return %ctrl;
+			
+		case "ColorI":
+			%ctrl = new GuiTextEditCtrl(%fieldEdit)
+				{
+					Text = %fieldVal;
+					Position = "160 0";
+					extent = "160 30";
+					horizSizing = "right";
+					vertSizing = "bottom";
+					visible = "1";
+					Profile = "GuiTextEditProfile";
+				};
+			%ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+			%ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+			return %ctrl;
+			
+		case "string":
+			%ctrl = new GuiTextEditCtrl(%fieldEdit)
+				{
+					Text = %fieldVal;
+					Position = "160 0";
+					extent = "160 30";
+					horizSizing = "right";
+					vertSizing = "bottom";
+					visible = "1";
+					Profile = "GuiTextEditProfile";
+				};
+			%ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+			%ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+			return %ctrl;
+			
+		case "SimObjectPtr":
+		return	%ctrl = new GuiControl(%fieldEdit)
+				{
+					Text = %fieldVal;
+					Position = "160 0";
+					extent = "160 30";
+					horizSizing = "right";
+					vertSizing = "bottom";
+					visible = "1";
+					Profile = "GuiTextProfile";
+				};
+				
+		case "caseString":
+			%ctrl = new GuiTextEditCtrl(%fieldEdit)
+			{
+				Text = %fieldVal;
+				Position = "160 0";
+				extent = "160 30";
+				horizSizing = "right";
+				vertSizing = "bottom";
+				visible = "1";
+				Profile = "GuiTextEditProfile";
+				
+			};
+			%ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+			%ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+			return %ctrl;
+			
+		case "int":
+			%ctrl = new GuiTextEditCtrl(%fieldEdit)
+				{
+					Text = %fieldVal;
+					Position = "160 0";
+					extent = "160 30";
+					horizSizing = "right";
+					vertSizing = "bottom";
+					visible = "1";
+					Profile = "GuiNumberEditProfile";
+				};
+			%ctrl.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+			%ctrl.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+			return %ctrl;
+			
+		case "bool":
+			%ctrl = new GuiCheckBoxCtrl(%fieldEdit)
+				{
+					text = "";
+					stateOn = %fieldVal;
+					Position = "160 0";
+					extent = "160 30";
+					horizSizing = "relative";
+					vertSizing = "relative";
+					visible = "1";
+					Profile = "GuiCheckBoxProfile";
+				};
+			%ctrl.setFieldValue("Command", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getStateOn());");
+			return %ctrl;
+			
+		case "Point2I":
+			return	%this.buildPoint2ICtrl(%field,%fieldVal);
+			
+		case "Point2F":
+			return	%this.buildPoint2ICtrl(%field,%fieldVal);
+			
+		case "enumval":
+			%ctrl = new GuiPopUpMenuCtrl(%fieldEdit)
+				{
+					text = %fieldVal;
+					Position = "160 6";
+					extent = "160 18";
+					Profile="GuiPopUpMenuProfile2";
+					HorizSizing="relative";
+					VertSizing="relative";
+					maxLength="1024";
+					maxPopupHeight="200";
+					bitmapBounds="16 16";
+				};
+			%cl = $currentTarget.getClassName();
+			%ctrl.setEnumContent(%cl, %field);
+			%ctrl.sort();
+			%ctrl.setFieldValue("Command", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+			return %ctrl;
+			
+		case "GuiProfile":
+			return %ctrl = %this.buildGuiProfileCtrl(%field, %fieldVal);
+			
+		default:
+			echo("Field type not handled");
+			%ctrl = 0;
+	}
+	
+}
+
+function GuiEditorCtrlProperties::buildGuiProfileCtrl(%this,%field,%fieldVal)
+{
+	%fieldEdit = %field @ "edit";
+	%ctrl = new GuiPopUpMenuCtrl(%fieldEdit)
+	{
+		text = %fieldVal;
+		Position = "160 6";
+		extent = "160 18";
+		Profile="GuiPopUpMenuProfile2";
+		HorizSizing="relative";
+		VertSizing="relative";
+		maxLength="1024";
+		maxPopupHeight="200";
+		bitmapBounds="16 16";
+	};
+	%count = GuiDataGroup.getCount();
+	for(%i = 0; %i < %count; %i++)
+	{
+		%obj = GuiDataGroup.getObject(%i);
+		if(%obj.getClassName() $= "GuiControlProfile")
+		{
+			if(%obj.getName() !$= "")
+			{
+				%ctrl.add(%obj.getName(), 0);
+			}
+		}
+	}
+	%ctrl.sort();
+	%ctrl.setFieldValue("Command", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrl.getId() @ ".getText());");
+	return %ctrl;
+	
+}
+
+function GuiEditorCtrlProperties::buildPoint2ICtrl(%this,%field, %fieldVal)
+{
+	%fieldEditX = %field @ "editX";
+	%fieldEditY = %field @ "editY";
+	
+	%cont = new GuiControl()
+	{
+		extent = "160 30";
+		Position = "160 0";
+		horizSizing = "right";
+		vertSizing = "bottom";
+		profile = "GuiDefaultProfile";
+		visible = "1";
+	};
+	
+	%xLabel = new GuiControl()
+	{
+		text = "x:";
+		extent = "30 30";
+		Position = "0 0";
+		horizSizing = "right";
+		vertSizing = "bottom";
+		profile = "GuiTextRightProfile";
+		visible = "1";
+	}; 
+	
+	
+	
+	%ctrlX = new GuiTextEditCtrl(%fieldEditX)
+	{
+		Text = %fieldVal.x;
+		Position = "30 0";
+		extent = "50 30";
+		horizSizing = "right";
+		vertSizing = "bottom";
+		visible = "1";
+		Profile = "GuiTextEditProfile";
+	};
+	
+	
+	
+	%yLabel = new GuiControl()
+	{
+		text = "y:";
+		extent = "30 30";
+		Position = "80 0";
+		horizSizing = "right";
+		vertSizing = "bottom";
+		profile = "GuiTextRightProfile";
+		visible = "1";
+	}; 
+	
+	
+	
+	%ctrlY = new GuiTextEditCtrl(%fieldEditY)
+	{
+		Text = %fieldVal.y;
+		Position = "110 0";
+		extent = "50 30";
+		horizSizing = "right";
+		vertSizing = "bottom";
+		visible = "1";
+		Profile = "GuiTextEditProfile";
+	};
+	
+	%ctrlX.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrlX.getId() @ ".getText() SPC " @ %ctrlY.getId() @ ".getText());");
+	%ctrlX.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrlX.getId() @ ".getText() SPC " @ %ctrlY.getId() @ ".getText());");
+	%ctrlY.setFieldValue("AltCommand", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrlX.getId() @ ".getText() SPC " @ %ctrlY.getId() @ ".getText());");
+	%ctrlY.setFieldValue("Validate", "GuiEditorCtrlProperties.setData(" @ %field @ "," @ %ctrlX.getId() @ ".getText() SPC " @ %ctrlY.getId() @ ".getText());");
+	
+	%cont.add(%xLabel);
+	%cont.add(%ctrlX);
+	%cont.add(%yLabel);
+	%cont.add(%ctrlY);
+	
+	return %cont;
+	
+}
+
+

+ 360 - 0
toybox/GuiEditorToy/1/main.cs

@@ -0,0 +1,360 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2013 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+function GuiEditorToy::create( %this )
+{
+	exec("./assets/gui/guiEditorCtrl.gui");
+	exec("./assets/gui/guiToolbox.gui");
+	exec("./assets/gui/ColorSelectorTool.gui");
+	exec("./assets/scripts/GuiEditorCtrlProperties.cs");
+    // Set the sandbox drag mode availability.
+    Sandbox.allowManipulation( pan );
+    Sandbox.allowManipulation( pull );
+    
+    // Set the manipulation mode.
+    Sandbox.useManipulation( pull );
+	SandboxScene.clear();
+    //SandboxWindow.delete();
+	GuiEditor.blankGui = new GuiControl();
+	
+	// Init menu
+	GuiEditorToy.initMenus();
+	
+    // Reset the toy initially.
+    GuiEditorToy.reset();
+	
+}
+
+function GuiEditorToy::initMenus( %this )
+{
+   if( isObject( %this.menuGroup ) )
+      %this.menuGroup.delete();
+      
+   %this.menuGroup = new SimGroup();
+   
+   //set up %cmdctrl variable so that it matches OS standards
+   %cmdCtrl = $platform $= "macos" ? "Cmd" : "Ctrl";
+
+   %filemenu = new PopupMenu()
+   {
+      superClass = "MenuBuilder";
+      barPosition = 0;
+      barName = "File";
+      
+      item[0] = "New Gui..." TAB %cmdCtrl SPC "N" TAB "GuiEditorStartCreate();";
+      item[1] = "Open Gui..." TAB %cmdCtrl SPC "O" TAB "GuiEditorOpenGui();";
+      item[2] = "-";
+      item[3] = "Save Gui..." TAB %cmdCtrl SPC "S" TAB "GuiEditorToy.save();";
+   };
+
+   %layoutmenu = new PopupMenu()
+   {
+      superClass = "MenuBuilder";
+      barPosition = 1;
+      barName = "Layout";
+      
+      item[0] = "Align Left" TAB %cmdCtrl SPC "L" TAB "GuiEditor.Justify(0);";
+      item[1] = "Align Right" TAB %cmdCtrl SPC "R" TAB "GuiEditor.Justify(2);";
+      item[2] = "Align Top" TAB %cmdCtrl SPC "T" TAB "GuiEditor.Justify(3);";
+      item[3] = "Align Bottom" TAB %cmdCtrl SPC "B" TAB "GuiEditor.Justify(4);";
+      item[4] = "-";
+      item[5] = "Center Horizontally" TAB "" TAB "GuiEditor.Justify(1);";
+      item[6] = "Space Vertically" TAB "" TAB "GuiEditor.Justify(5);";
+      item[7] = "Space Horizontally" TAB "" TAB "GuiEditor.Justify(6);";
+      item[8] = "-";
+      item[9] = "Bring to Front" TAB "" TAB "GuiEditor.BringToFront();";
+      item[10] = "Send to Back" TAB "" TAB "GuiEditor.PushToBack();";
+      item[11] = "Lock Selection" TAB "" TAB "GuiEditorTreeView.lockSelection(true);";
+      item[12] = "Unlock Selection" TAB "" TAB "GuiEditorTreeView.lockSelection(false);";
+   };
+   
+   %movemenu = new PopupMenu()
+   {
+      superClass = "MenuBuilder";
+      barPosition = 2;
+      barName = "Move";
+      
+      item[0] = "Nudge Up" TAB "Up" TAB "GuiEditor.moveSelection(0,-1);";
+      item[1] = "Nudge Down" TAB "Down" TAB "GuiEditor.moveSelection(0,1);";
+	  item[2] = "Nudge Right" TAB "Right" TAB "GuiEditor.moveSelection(1,0);";
+	  item[3] = "Nudge Left" TAB "Left" TAB "GuiEditor.moveSelection(-1,0);";
+   };
+   
+   // add menus to a group
+   %this.menuGroup.add(%fileMenu);
+   %this.menuGroup.add(%layoutmenu);
+   %this.menuGroup.add(%movemenu);
+   
+   for( %i = 0; %i < %this.menuGroup.getCount(); %i++ )
+     %this.menuGroup.getObject( %i ).attachToMenuBar();
+   
+}
+
+//-----------------------------------------------------------------------------
+
+function GuiEditorToy::destroy( %this )
+{   
+}
+
+//-----------------------------------------------------------------------------
+
+function GuiEditorToy::reset(%this)
+{
+    // Clear the scene.
+    
+	Canvas.setContent(GuiEditorCtrl);
+	
+	GuiEditorContent.add(GuiEditor.blankGui);
+	GuiEditorCtrl.add(GuiTreeViewWindow);
+	
+	$GuiRootElement = GuiBlank;
+	%rootSize = $GuiRootElement.extent;
+	
+	GuiEditor.setRoot(GuiBlank);
+	GuiEditorTreeView.open(GuiBlank);
+	
+	GuiEditor.setFirstResponder();
+	
+	GuiEditor.setSnapToGrid("8");
+	
+    GuiEditorCtrl.add(GuiToolbox);
+    GuiEditorCtrl.add(GuiInspectorWindow);
+    
+    //GuiEditorCtrl.add(CBBWindow);
+	
+}
+
+function GuiEditorToy::save(%this)
+{
+	%guiObj = GuiEditorContent.getObject(0);
+	if(%guiObj == -1)
+	{
+		return;
+	}
+	
+	if(%guiObj.getName() !$= "")
+	{
+		%name = %guiObj.getName() @ ".gui";
+	}
+	else
+	{
+		%name = "untitled.gui";
+	}
+	
+	%fo = new FileObject();
+	%fo.openForWrite(%name);
+	%fo.writeLine("//--- Created With GUIEDITORTOY ---//");
+	%fo.writeObject(%guiObj, "%guiContent = ");
+	%fo.writeLine("//--- GUIEDITORTOY END ---//");
+	%fo.close();
+	%fo.delete();
+	
+}
+
+//-----------------------------------------------------------------------------
+
+function GuiToolbox::onWake(%this)
+{
+	%controls = enumerateConsoleClasses("GuiControl");
+	%this-->toolboxList.clearItems();
+	for(%i = 0; %i < getFieldCount(%controls); %i++)
+	{
+		%field = getField(%controls, %i);
+		%this-->toolboxList.addItem(%field);
+	}
+}
+
+//-----------------------------------------------------------------------------
+
+function GuiEditorToolboxDrag::onTouchDragged(%this)
+{
+	%position = %this.getGlobalPosition();
+	%cursorpos = Canvas.getCursorPos();
+   
+	%class = %this.getItemText(%this.getSelectedItem());
+	%payload = eval("return new " @ %class @ "();");
+	if(!isObject(%payload))
+		return;
+      
+	%xOffset = getWord(%payload.extent, 0) / 2;
+	%yOffset = getWord(%payload.extent, 1) / 2; 
+	
+	// position where the drag will start, to prevent visible jumping.
+	%xPos = getWord(%cursorpos, 0) - %xOffset;
+	%yPos = getWord(%cursorpos, 1) - %yOffset;
+	   
+	%dragCtrl = new GuiDragAndDropControl() {
+		canSaveDynamicFields = "0";
+		Profile = "GuiDefaultProfile";
+		HorizSizing = "right";
+		VertSizing = "bottom";
+		Position = %xPos SPC %yPos;
+		extent = %payload.extent;
+		MinExtent = "32 32";
+		canSave = "1";
+		Visible = "1";
+		hovertime = "1000";
+		deleteOnMouseUp = true;
+	};
+
+	%dragCtrl.add(%payload);
+	Canvas.getContent().add(%dragCtrl);
+	   
+	%dragCtrl.startDragging(%xOffset, %yOffset);
+}
+
+//-----------------------------------------------------------------------------
+
+function GuiEditor::onControlDragged(%this, %payload, %position)
+{
+	%pos = VectorSub(%position, GuiEditorContent.getGlobalPosition());
+	%x = getWord(%pos, 0);
+	%y = getWord(%pos, 1);
+	%target = GuiEditorContent.findHitControl(%x, %y);
+	
+	while(! %target.isContainer )
+	{
+		%target = %target.getParent();
+	}
+	
+	if(%target != %this.getCurrentAddset())
+	{
+		%this.setCurrentAddSet(%target);
+	}
+	GuiEditorCtrlProperties.update(%ctrl);
+}
+
+//-----------------------------------------------------------------------------
+
+function GuiEditor::onControlDropped(%this, %payload, %position)
+{  
+   %pos = %payload.getGlobalPosition();
+   %x = getWord(%pos, 0);
+   %y = getWord(%pos, 1);
+   
+   if(%x > $GuiRootElement.extent.x || %y > $GuiRootElement.extent.y)
+   {
+      messageBox("Error", "Cannot add a control outside the root gui element!");
+      return;
+   }
+   
+   %this.addNewCtrl(%payload);
+   
+   %payload.setPositionGlobal(%x, %y);
+   %this.setFirstResponder();
+}
+
+//-----------------------------------------------------------------------------
+
+function GuiEditor::onSelect(%this, %ctrl)
+{
+	GuiEditorCtrlProperties.update(%ctrl);
+	GuiEditor.clearSelection();
+	GuiEditor.select(%ctrl);
+	GuiEditorTreeView.addSelection(%ctrl);
+}
+
+function GuiEditor::onSelectionMoved(%this, %ctrl)
+{
+	GuiEditorCtrlProperties.update(%ctrl);
+}
+
+function GuiEditor::onClearSelected(%this)
+{ 
+   GuiEditorTreeView.clearSelection();
+}
+
+function GuiEditor::onSelectionParentChange(%this)
+{
+	GuiEditorTreeView.update();
+}
+
+function GuiEditor::onDelete(%this)
+{
+	GuiEditorTreeView.update();
+	GuiEditorCtrlProperties.update(0);
+}
+
+function GuiEditor::onAddSelected(%this,%ctrl)
+{
+   GuiEditorTreeView.addSelection(%ctrl);
+   GuiEditorTreeView.scrollVisibleByObjectId(%ctrl);
+}
+
+function GuiEditor::onRemoveSelected(%this,%ctrl)
+{
+   GuiEditorTreeView.removeSelection(%ctrl); 
+}
+
+//-----------------------------------------------------------------------------
+
+function GuiEditorTreeView::update(%this)
+{
+	%obj = GuiEditorContent.getObject(0);
+	
+	if(!isObject(%obj))
+	{
+		GuiEditorTreeView.clear();
+	}
+	else
+	{
+		GuiEditorTreeView.open(GuiEditorContent.getObject(0));
+	}
+}
+
+function GuiEditorTreeView::onRightMouseDown(%this, %item, %pts, %obj)
+{
+   if(%obj)
+   {
+      GuiEditor.setCurrentAddSet(%obj);
+   }
+}
+
+function GuiEditorTreeView::onAddSelection(%this, %ctrl)
+{
+	GuiEditor.setFirstResponder();
+}
+
+function GuiEditorTreeView::onRemoveSelection(%this, %ctrl)
+{
+	GuiEditor.removeSelection(%ctrl);
+}
+
+function GuiEditorTreeView::onDeleteSelection(%this)
+{ 
+   GuiEditor.clearSelection();
+}
+
+function GuiEditorTreeView::onSelect(%this, %obj)
+{
+
+   if(isObject(%obj))
+   {
+      GuiEditorCtrlProperties.update(%obj);
+      GuiEditor.select(%obj);
+   }
+}
+
+
+
+
+

+ 10 - 0
toybox/GuiEditorToy/1/module.taml

@@ -0,0 +1,10 @@
+<ModuleDefinition
+    ModuleId="GuiEditorToy"
+    VersionId="1"
+	Enabled="1"
+    Description="Gui Editor for T2D MIT."
+    Type="toy"
+    ToyCategoryIndex="2"
+    ScriptFile="main.cs"
+    CreateFunction="create"
+    DestroyFunction="destroy"/>