示例#1
0
        private void SpawnPrefab(string name)
        {
            Entity entity = TagIOUtils.InstantiatePrefab(name);

            if (entity != null)
            {
                Owner.Entities.Add(entity);
                Owner.Entities.Flush();
                if (entity.Components.Get <Transform>() is Transform sp)
                {
                    sp.Position = Owner.CurrentViewport.Location;
                }
                SelectedIndex = Owner.Entities.Count - 1;
            }
        }
示例#2
0
 private void CreateEntity(string instruction)
 {
     if (instruction == BLANK_ENTITY)
     {
         Owner.Entities.Add(new Entity());
         Owner.Entities.Flush();
         SelectedIndex = Owner.Entities.Count - 1;
     }
     else if (instruction == FROM_PREFABS)
     {
         TagIOUtils.Refresh();
         Owner.Events.InvokeEvent(new StartEnumSelectEvent("Select Prefab", TagIOUtils.GetPrefabNames(), SpawnPrefab, null));
         Owner.Events.InvokeEvent(new ForceModalChangeEvent("enum_select", null));
         ModalActive  = false;
         ModalVisible = false;
     }
 }
示例#3
0
        public override void Input()
        {
            if (!ModalActive)
            {
                return;
            }
            if (!Owner.Entities.ContainsId(Selected))
            {
                return;
            }
            Entity entity = Owner.Entities[Selected];

            if (entity == null)
            {
                Owner.Events.InvokeEvent(new RequestModalChangeEvent(null));
                return;
            }

            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            Vector2D movement = inputMap.Movement;

            if (movement.Magnitude > 1e-5 && Editor.MoveTimeframe.Execute())
            {
                if (movement.Y > 0)
                {
                    if (ComponentLocked)
                    {
                        if (SelectedPropertyIndex - 1 >= 0)
                        {
                            SelectedPropertyIndex--;
                        }
                    }
                    else
                    {
                        if (SelectedComponentIndex - 1 >= -2)
                        {
                            SelectedComponentIndex--;
                        }
                    }
                }
                else if (movement.Y < 0)
                {
                    if (ComponentLocked)
                    {
                        if (SelectedPropertyIndex + 1 < SelectedComponent.Members.Count)
                        {
                            SelectedPropertyIndex++;
                        }
                    }
                    else
                    {
                        if (SelectedComponentIndex + 1 <= entity.Components.Count + 1)
                        {
                            SelectedComponentIndex++;
                        }
                    }
                }

                if (movement.Y != 0)
                {
                    RemoveTimer = 0;
                }

                /*if (SelectedComponentIndex < StartOffset)
                 * {
                 *  StartOffset = SelectedComponentIndex;
                 * }
                 * if (SelectedComponentIndex > StartOffset + AmountVisible)
                 * {
                 *  StartOffset = SelectedComponentIndex - AmountVisible;
                 * }*/
            }

            if (inputMap.Jump.Consume())
            {
                if (SelectedComponentIndex == -2)
                {
                    new PropertySummary(Owner, typeof(Entity).GetProperty("Name"), entity).TriggerEdit(inputMap.Interact.Pressed);
                    ModalActive = false;
                }
                else if (SelectedComponentIndex == -1)
                {
                    entity.Active = !entity.Active;
                }
                else if (SelectedComponentIndex == Helper.Components.Count)
                {
                    Owner.Events.InvokeEvent(new StartEnumSelectEvent("Available components", Component.GetAllIdentifiers().Where(s => !Helper.Components.ContainsKey(s)).ToList(), AddComponent, null));
                    Owner.Events.InvokeEvent(new ForceModalChangeEvent("enum_select", null));
                    ModalActive  = false;
                    ModalVisible = false;
                }
                else if (SelectedComponentIndex == Helper.Components.Count + 1)
                {
                    Owner.Events.InvokeEvent(new StartTextInputEvent(entity.Name, n => TagIOUtils.SavePrefab(entity, n), null)
                    {
                        Label = "Prefab Name"
                    });
                    Owner.Events.InvokeEvent(new ForceModalChangeEvent("text_input", null));
                    ModalActive = false;
                }
                else if (!ComponentLocked)
                {
                    SelectedComponent     = Helper.Components.Values.ElementAt(SelectedComponentIndex);
                    SelectedPropertyIndex = 0;
                    ComponentLocked       = true;
                }
                else
                {
                    if (SelectedPropertyIndex >= Helper.Components.Values.ElementAt(SelectedComponentIndex).Members.Count)
                    {
                        return;
                    }
                    IMemberSummary member = Helper.Components.Values.ElementAt(SelectedComponentIndex).Members.Values.ElementAt(SelectedPropertyIndex);
                    if (member.CanSet)
                    {
                        bool modalNeedsChange = member.TriggerEdit(inputMap.Interact.Pressed);
                        if (modalNeedsChange)
                        {
                            ModalActive = false;
                        }
                    }
                }
            }

            if (RemoveTimer > 0)
            {
                RemoveTimer--;
            }
            if (inputMap.Pulse.Pressed && SelectedComponentIndex >= 0 && !ComponentLocked)
            {
                RemoveTimer += 2;
                if (RemoveTimer / 25 > 3)
                {
                    Owner.Entities[Selected].Components.Remove(Helper.Components.Values.ElementAt(SelectedComponentIndex).ComponentName);
                    RemoveTimer = 0;
                    Helper.Update(Selected);
                    if (SelectedComponentIndex >= Helper.Components.Count)
                    {
                        SelectedComponentIndex = Helper.Components.Count - 1;
                    }
                }
            }
            else
            {
                RemoveTimer = 0;
            }

            if (SelectedComponentIndex >= 0 && SelectedComponentIndex < ComponentRenderOffsets.Count)
            {
                int y = ComponentRenderOffsets[SelectedComponentIndex];
                if (y < 0)
                {
                    ListFromIndex--;
                }
                else if (y > 720)
                {
                    ListFromIndex = Math.Max(0, SelectedComponentIndex - 2);
                }
            }
        }