public static void Target(Property property) { var target = (Target)property.value; string targetString = target.ToString(); Color baseColor = GUI.color; if (target.entityRef.entity != null) { EntityReferencePropertyManager.Next(target.entityRef.entity); GUI.color = baseColor * EntityReferencePropertyManager.GetColor(); targetString = EntityReferencePropertyManager.GetName(); } GUILayout.BeginHorizontal(); AlignedLabel(property); if (GUILayout.Button(targetString, GUI.skin.textField)) { TargetGUI targetGUI = GUIManager.guiGameObject.AddComponent <TargetGUI>(); targetGUI.title = property.name; targetGUI.voxelArray = VoxelArrayEditor.instance; targetGUI.handler = (Target newTarget) => { property.value = newTarget; }; } GUILayout.EndHorizontal(); GUI.color = baseColor; }
public override ICollection <Property> Properties() { return(Property.JoinProperties(base.Properties(), new Property[] { new Property("loc", "To", () => target, v => target = (EntityReference)v, PropertyGUIs.EntityReference), new Property("rel", "Relative to", () => origin, v => origin = (EntityReference)v, (Property property) => { var reference = (EntityReference)property.value; if (reference.entity == null) { if (targetEntity.entity != null) { property.value = targetEntity; } else if (!targetEntityIsActivator) { // TODO: this is not a good solution property.value = new EntityReference( EntityReferencePropertyManager.CurrentEntity()); } } PropertyGUIs._EntityReferenceCustom(property, targetEntityIsActivator, targetEntityIsActivator ? "Activator" : "None"); }) })); }
public static void Filter(Property property) { var filter = (ActivatedSensor.Filter)property.value; string filterString = filter.ToString(); Color baseColor = GUI.color; ActivatedSensor.EntityFilter entityFilter = filter as ActivatedSensor.EntityFilter; if (entityFilter != null) { Entity e = entityFilter.entityRef.entity; if (e != null) { EntityReferencePropertyManager.Next(e); GUI.color = baseColor * EntityReferencePropertyManager.GetColor(); filterString = EntityReferencePropertyManager.GetName(); } } GUILayout.BeginHorizontal(); AlignedLabel(property); if (GUILayout.Button(filterString, GUI.skin.textField)) { FilterGUI filterGUI = GUIManager.guiGameObject.AddComponent <FilterGUI>(); filterGUI.title = property.name + " by..."; filterGUI.voxelArray = VoxelArrayEditor.instance; filterGUI.handler = (ActivatedSensor.Filter newFilter) => { property.value = newFilter; }; } GUILayout.EndHorizontal(); GUI.color = baseColor; }
public override void WindowGUI() { // clear substance highlight while properties panel is disabled EntityReferencePropertyManager.Reset(null); GUILayout.BeginHorizontal(); SelectionGUI(); GUILayout.FlexibleSpace(); Vector3 selectionSize = voxelArray.selectionBounds.size; if (selectionSize == Vector3.zero) { ActionBarLabel("Select edges to bevel..."); } else { ActionBarLabel(SelectionString(selectionSize)); } GUILayout.FlexibleSpace(); TutorialGUI.TutorialHighlight("bevel done"); if (HighlightedActionBarButton(GUIIconSet.instance.done)) { Destroy(this); } TutorialGUI.ClearHighlight(); GUILayout.EndHorizontal(); }
public static void BehaviorTarget(Property property) { var value = (EntityBehavior.BehaviorTargetProperty)(property.value); Entity behaviorTarget = value.targetEntity.entity; string text; if (value.targetEntityIsActivator) { text = "Activators"; } else if (behaviorTarget != null) { // only temporarily, so the name won't be "Target": EntityReferencePropertyManager.SetBehaviorTarget(null); EntityReferencePropertyManager.Next(behaviorTarget); text = EntityReferencePropertyManager.GetName(); EntityReferencePropertyManager.SetBehaviorTarget(behaviorTarget); // put it back } else { return; } GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label(GUIIconSet.instance.target, alignedLabelStyle.Value, GUILayout.ExpandWidth(false)); if (GUILayout.Button("<i>" + text + "</i>", GUILayout.ExpandWidth(false))) { BehaviorTargetPicker(GUIPanel.guiGameObject, VoxelArrayEditor.instance, EntityReferencePropertyManager.CurrentEntity(), newValue => { property.value = newValue; }); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); }
public override IEnumerable <Property> Properties() { return(Property.JoinProperties(base.Properties(), new Property[] { new Property("loc", "To", () => dest, v => dest = (EntityReference)v, PropertyGUIs.EntityReference), new Property("rel", "Relative to", () => origin, v => origin = (EntityReference)v, (Property property) => { var reference = (EntityReference)property.value; // TODO: this is not a good solution Entity targetEntity = target.GetEntity( EntityReferencePropertyManager.CurrentEntity()); if (reference.entity == null && targetEntity != null) { property.value = new EntityReference(targetEntity); } PropertyGUIs._EntityReferenceCustom(property, targetEntity == null, targetEntity == null ? "Activator" : "None"); }) })); }
public virtual ICollection <Property> Properties() { return(new Property[] { new Property("tar", "Target", () => new BehaviorTargetProperty(targetEntity, targetEntityIsActivator), v => { var prop = (BehaviorTargetProperty)v; // selfEntity will be null if multiple entities are selected Entity selfEntity = EntityReferencePropertyManager.CurrentEntity(); var oldTargetEntity = targetEntity.entity; var newTargetEntity = prop.targetEntity.entity; if (oldTargetEntity == null && !targetEntityIsActivator) { oldTargetEntity = selfEntity; } if (newTargetEntity == null && !prop.targetEntityIsActivator) { newTargetEntity = selfEntity; } if (oldTargetEntity != null) { // replace all property values referencing the old target with the new target // the new target could be null foreach (Property _selfProp in this.Properties()) { var selfProp = _selfProp; selfProp.value = PropertiesObjectType.PropertyValueReplaceEntity( selfProp.value, oldTargetEntity, newTargetEntity); } } targetEntity = prop.targetEntity; targetEntityIsActivator = prop.targetEntityIsActivator; }, PropertyGUIs.BehaviorTarget), new Property("con", "Condition", () => condition, v => condition = (Condition)v, (Property property) => { if (targetEntityIsActivator) { PropertyGUIs.ActivatorBehaviorCondition(property); } else { PropertyGUIs.BehaviorCondition(property); } }) }); }
public override IEnumerable <Property> Properties() { return(new Property[] { new Property("tar", "Target", () => target, v => { var prop = (BehaviorTargetProperty)v; // selfEntity will be null if multiple entities are selected Entity selfEntity = EntityReferencePropertyManager.CurrentEntity(); var oldTargetEntity = target.GetEntity(selfEntity); var newTargetEntity = prop.GetEntity(selfEntity); if (oldTargetEntity != null) { // replace all property values referencing the old target with the new target // the new target could be null foreach (Property _selfProp in this.Properties()) { var selfProp = _selfProp; selfProp.value = PropertiesObject.PropertyValueReplaceEntity( selfProp.value, oldTargetEntity, newTargetEntity); } } target = prop; }, PropertyGUIs.BehaviorTarget), new Property("con", "Condition", () => condition, v => condition = (Condition)v, (Property property) => { if (target.targetEntityIsActivator) { PropertyGUIs.ActivatorBehaviorCondition(property); } else { PropertyGUIs.BehaviorCondition(property); } }) }); }
public static void _EntityReferenceCustom(Property property, bool allowNull, string nullName) { var reference = (EntityReference)property.value; string valueString = nullName; Color baseColor = GUI.color; if (reference.entity != null) { EntityReferencePropertyManager.Next(reference.entity); GUI.color = baseColor * EntityReferencePropertyManager.GetColor(); valueString = EntityReferencePropertyManager.GetName(); } GUILayout.BeginHorizontal(); AlignedLabel(property); if (GUILayout.Button(valueString, GUI.skin.textField)) { EntityPickerGUI picker = GUIManager.guiGameObject.AddComponent <EntityPickerGUI>(); picker.voxelArray = VoxelArrayEditor.instance; picker.allowNone = false; picker.allowMultiple = false; picker.allowNull = allowNull; picker.nullName = nullName; picker.handler = (ICollection <Entity> entities) => { foreach (Entity entity in entities) { property.value = new EntityReference(entity); return; } property.value = null; }; } GUILayout.EndHorizontal(); GUI.color = baseColor; }
private void EntityPropertiesGUI() { Entity singleSelectedEntity = null; if (selectedEntities.Count == 1) { singleSelectedEntity = selectedEntities[0]; } EntityReferencePropertyManager.Reset(singleSelectedEntity); // could be null and that's fine (?) GUILayout.BeginVertical(GUI.skin.box); PropertiesObjectGUI(editEntity); GUILayout.EndVertical(); if (singleSelectedEntity != null && !(singleSelectedEntity is PlayerObject)) { GUILayout.BeginHorizontal(); if (GUIUtils.HighlightedButton("Clone")) { if (singleSelectedEntity is ObjectEntity) { ObjectEntity clone = (ObjectEntity)(singleSelectedEntity.Clone()); var pickerGUI = gameObject.AddComponent <FacePickerGUI>(); pickerGUI.voxelArray = voxelArray; pickerGUI.message = "Tap to place clone"; pickerGUI.pickAction = () => { if (!voxelArray.PlaceObject(clone)) { DialogGUI.ShowMessageDialog(gameObject, ActionBarGUI.OBJECT_NO_ROOM_ERROR); } }; } else if (singleSelectedEntity is Substance) { Substance clone = (Substance)(singleSelectedEntity.Clone()); clone.defaultPaint = voxelArray.GetSelectedPaint(); clone.defaultPaint.addSelected = false; clone.defaultPaint.storedSelected = false; voxelArray.substanceToCreate = clone; var createGUI = gameObject.AddComponent <CreateSubstanceGUI>(); createGUI.voxelArray = voxelArray; } } if (GUIUtils.HighlightedButton("Delete")) { DeleteButton(); } GUILayout.EndHorizontal(); } if (selectedEntities.Count > 1) { if (GUIUtils.HighlightedButton("Delete")) { DeleteButton(); } } TutorialGUI.TutorialHighlight("change sensor"); if (GUILayout.Button("Change Sensor")) { TypePickerGUI sensorMenu = gameObject.AddComponent <TypePickerGUI>(); sensorMenu.title = "Change Sensor"; sensorMenu.categories = new PropertiesObjectType[][] { GameScripts.sensors }; sensorMenu.handler = (PropertiesObjectType type) => { foreach (Entity entity in selectedEntities) { entity.sensor = (Sensor)type.Create(); } voxelArray.unsavedChanges = true; UpdateEditEntity(); }; } TutorialGUI.ClearHighlight(); GUILayout.BeginVertical(GUI.skin.box); PropertiesObjectGUI(editSensor, " Sensor"); GUILayout.EndVertical(); TutorialGUI.TutorialHighlight("add behavior"); if (GUILayout.Button("Add Behavior")) { NewBehaviorGUI behaviorMenu = gameObject.AddComponent <NewBehaviorGUI>(); behaviorMenu.title = "Add Behavior"; behaviorMenu.self = singleSelectedEntity; behaviorMenu.voxelArray = voxelArray; behaviorMenu.handler = (PropertiesObjectType behaviorType) => { foreach (Entity entity in selectedEntities) { EntityBehavior newBehavior = (EntityBehavior)behaviorType.Create(); // with multiple selected entities, NewBehaviorGUI doesn't check if behaviors // are valid for the selected entities if (newBehavior.targetEntity.entity == null && !newBehavior.targetEntityIsActivator && !newBehavior.BehaviorObjectType().rule(entity)) { continue; } entity.behaviors.Add(newBehavior); EntityPreviewManager.BehaviorUpdated(singleSelectedEntity, newBehavior); } voxelArray.unsavedChanges = true; UpdateEditEntity(); scrollVelocity = new Vector2(0, 2000 * editBehaviors.Count); // scroll to bottom }; } TutorialGUI.ClearHighlight(); Color guiBaseColor = GUI.backgroundColor; StoredEntityBehavior behaviorToRemove = null; foreach (StoredEntityBehavior storedBehavior in editBehaviors) { TutorialGUI.TutorialHighlight("behaviors"); Entity behaviorTarget = null; if (storedBehavior.sharedTarget) { behaviorTarget = storedBehavior.allBehaviors[0].targetEntity.entity; } if (behaviorTarget != null) { EntityReferencePropertyManager.Next(behaviorTarget); GUI.backgroundColor = guiBaseColor * EntityReferencePropertyManager.GetColor(); } EntityReferencePropertyManager.SetBehaviorTarget(behaviorTarget); GUILayout.BeginVertical(GUI.skin.box); GUI.backgroundColor = guiBaseColor; PropertiesObjectGUI(storedBehavior, " Behavior", () => EntityPreviewManager.BehaviorUpdated(singleSelectedEntity, storedBehavior.allBehaviors[0])); if (GUILayout.Button("Remove")) { behaviorToRemove = storedBehavior; } GUILayout.EndVertical(); // clear this every time, in case the next target is the same EntityReferencePropertyManager.SetBehaviorTarget(null); } if (behaviorToRemove != null) { foreach (Entity entity in selectedEntities) { foreach (EntityBehavior remove in behaviorToRemove.allBehaviors) { if (entity.behaviors.Remove(remove)) { break; } } } voxelArray.unsavedChanges = true; UpdateEditEntity(); EntityPreviewManager.BehaviorUpdated(singleSelectedEntity, behaviorToRemove.allBehaviors[0]); } if (mismatchedSelectedBehaviorCounts) { GUILayout.BeginVertical(GUI.skin.box); GUILayout.Label("(other behaviors...)", GUIStyleSet.instance.labelTitle); GUILayout.EndVertical(); } }
public override void WindowGUI() { if (slidingPanel && GUI.enabled) { GUI.enabled = false; GUI.color = new Color(1, 1, 1, 2); // reverse disabled tinting } scroll = GUILayout.BeginScrollView(scroll); if (voxelArray.selectionChanged && !freezeUpdates) { worldSelected = false; voxelArray.selectionChanged = false; scroll = Vector2.zero; scrollVelocity = Vector2.zero; selectedEntities = new List <Entity>(voxelArray.GetSelectedEntities()); UpdateEditEntity(); } bool propertiesDisplayed = false; if (worldSelected) { GUILayout.BeginVertical(GUI.skin.box); PropertiesObjectGUI(voxelArray.world); GUILayout.EndVertical(); propertiesDisplayed = true; EntityReferencePropertyManager.Reset(null); } else if (editEntity != null) { EntityPropertiesGUI(); propertiesDisplayed = true; } else { EntityReferencePropertyManager.Reset(null); } if (Input.touchCount == 1) { if (horizontalSlide && (!adjustingSlider) && PanelContainsPoint(touchStartPos)) { slidingPanel = true; } } else { adjustingSlider = false; slidingPanel = false; } if (slidingPanel) { Touch touch = Input.GetTouch(0); if (Event.current.type == EventType.Repaint) // scroll at correct rate { slide += touch.deltaPosition.x / scaleFactor; } normallyOpen = slide > SLIDE_HIDDEN / 2; } else { if (Event.current.type == EventType.Repaint) { bool shouldOpen = normallyOpen && propertiesDisplayed; slide += 2000 * Time.deltaTime * (shouldOpen ? 1 : -1); } } if (slide > 0) { slide = 0; } if (slide < SLIDE_HIDDEN) { slide = SLIDE_HIDDEN; } GUILayout.Space(bottomGap); GUILayout.EndScrollView(); }
private void InputsGUI(Property property) { Input[] inputs = (Input[])property.value; GUILayout.Label("Inputs:"); if (GUILayout.Button("Add Input")) { EntityPickerGUI picker = GUIPanel.guiGameObject.AddComponent <EntityPickerGUI>(); picker.voxelArray = VoxelArrayEditor.instance; picker.handler = (ICollection <Entity> entities) => { Input[] newInputs = new Input[inputs.Length + entities.Count]; Array.Copy(inputs, newInputs, inputs.Length); int i = 0; foreach (Entity entity in entities) { newInputs[inputs.Length + i] = new Input(entity); i++; } property.value = newInputs; }; } bool copyArray = false; int inputToDelete = -1; Color baseColor = GUI.color; for (int i = 0; i < inputs.Length; i++) { Entity e = inputs[i].entityRef.entity; if (e == null) { inputToDelete = i; } EntityReferencePropertyManager.Next(e); GUI.color = baseColor * EntityReferencePropertyManager.GetColor(); GUILayout.BeginVertical(GUI.skin.box); GUILayout.BeginHorizontal(); GUILayout.Label(EntityReferencePropertyManager.GetName() + " "); GUILayout.FlexibleSpace(); if (GUILayout.Button("X")) { inputToDelete = i; } GUILayout.EndHorizontal(); int negativeNum = inputs[i].negative ? 1 : 0; int newNegativeNum = GUILayout.SelectionGrid(negativeNum, new string[] { "Positive", "Negative" }, 2, GUI.skin.GetStyle("button_tab")); if (negativeNum != newNegativeNum) { inputs[i].negative = newNegativeNum == 1; copyArray = true; } GUILayout.EndVertical(); } GUI.color = baseColor; if (inputToDelete != -1) { Input[] newInputs = new Input[inputs.Length - 1]; Array.Copy(inputs, newInputs, inputToDelete); Array.Copy(inputs, inputToDelete + 1, newInputs, inputToDelete, newInputs.Length - inputToDelete); property.value = newInputs; } else if (copyArray) { Input[] newInputs = new Input[inputs.Length]; Array.Copy(inputs, newInputs, inputs.Length); property.value = newInputs; // mark unsaved changes flag } }