Exemplo n.º 1
0
    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;
    }
Exemplo n.º 2
0
    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;
    }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
    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;
    }
Exemplo n.º 5
0
    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();
        }
    }
Exemplo n.º 6
0
    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
        }
    }