public override void EventFired(object sender, Event e)
        {
            if (e is StartEntitySelectionModeEvent start)
            {
                Source          = start.Source;
                Callback        = start.Callback;
                MultipleAllowed = start.MultipleLinks;
                Selected        = start.Selected;
                Mode            = MultipleAllowed ? Add : Single;
                ForbiddenLink   = start.ForbiddenLink;

                foreach (long id in Selected)
                {
                    ILine line = new SimpleLine(Source, EditorUtil.GetSelectionBounds(Owner.Entities[id]).Center, Color.Aqua, 4);
                    Lines.Add(id, line);
                    Owner.Events.InvokeEvent(new BeginOverlay(line));
                }
                HoverOutline = new EntityOutline(Owner, 0)
                {
                    Thickness = 4
                };
                Overlays.Add(HoverOutline);
                Owner.Events.InvokeEvent(new BeginOverlay(HoverOutline));
                HoverLine = new SimpleLine(Source, Source, Color.CadetBlue, 4);
                Overlays.Add(HoverLine);
                Owner.Events.InvokeEvent(new BeginOverlay(HoverLine));
            }
            else if (e is ModalChangeEvent changed)
            {
                ModalActive = true;
                CursorSystem.ModalActive     = true;
                CursorSystem.DraggingEnabled = true;
                if (changed.From != "collision_face_view")
                {
                    CursorSystem.SwitchToModal = changed.From;
                }
            }
            else if (e is BeginModalChangeEvent bmce)
            {
                bmce.SystemName              = CursorSystem.SwitchToModal;
                ModalActive                  = false;
                CursorSystem.ModalActive     = false;
                CursorSystem.DraggingEnabled = false;
                Callback(Selected);
                Callback = null;

                foreach (IOverlay overlay in Lines.Values)
                {
                    Owner.Events.InvokeEvent(new RemoveOverlay(overlay));
                }
                Lines.Clear();
                foreach (IOverlay overlay in Overlays)
                {
                    Owner.Events.InvokeEvent(new RemoveOverlay(overlay));
                }
                Overlays.Clear();
            }
        }
Esempio n. 2
0
        public override void Input()
        {
            if (!ModalActive)
            {
                return;
            }
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            if (Outline == null)
            {
                Outline = new EntityOutline(Owner, 0);
                Owner.Events.InvokeEvent(new BeginOverlay(Outline));
            }

            Vector2D movement = inputMap.Movement;

            if (movement.Magnitude > 1e-5 && Editor.MoveTimeframe.Execute())
            {
                if (movement.Y > 0)
                {
                    if (SelectedIndex - 1 >= -1)
                    {
                        SelectedIndex--;
                    }
                }
                else if (movement.Y < 0)
                {
                    if (SelectedIndex + 1 < Owner.Entities.Count)
                    {
                        SelectedIndex++;
                    }
                }
                if (movement.Y != 0)
                {
                    RemoveTimer = 0;
                }
            }

            if (inputMap.Jump.Consume())
            {
                if (SelectedIndex == -1)
                {
                    Owner.Events.InvokeEvent(new StartEnumSelectEvent("Add Entity", new List <string>()
                    {
                        BLANK_ENTITY, FROM_PREFABS
                    }, CreateEntity, null));
                    Owner.Events.InvokeEvent(new ForceModalChangeEvent("enum_select", null));
                    ModalActive  = false;
                    ModalVisible = false;
                }
                else
                {
                    Owner.Events.InvokeEvent(new EntitySelectEvent(Owner.Entities.ToList()[SelectedIndex], null));
                    Owner.Events.InvokeEvent(new ForceModalChangeEvent("entity_view", null));
                    ModalActive  = false;
                    ModalVisible = false;
                }
            }

            if (RemoveTimer > 0)
            {
                RemoveTimer--;
            }
            if (inputMap.Pulse.Pressed && SelectedIndex >= 0)
            {
                RemoveTimer += 2 + RemoveSpeed;
                if (RemoveTimer / 25 > 3)
                {
                    Owner.Entities.Remove(Owner.Entities.ElementAt(SelectedIndex).Id);
                    RemoveTimer = 0;
                    RemoveSpeed++;
                }
            }
            else
            {
                RemoveTimer = 0;
                RemoveSpeed = 0;
            }

            Outline.Id = 0;
            if (SelectedIndex >= 0 && SelectedIndex < Owner.Entities.Count)
            {
                Outline.Id = Owner.Entities.ToList()[SelectedIndex].Id;
            }
            if (SelectedIndex < StartOffset)
            {
                StartOffset = SelectedIndex;
            }
            if (SelectedIndex > StartOffset + AmountVisible)
            {
                StartOffset = SelectedIndex - AmountVisible;
            }
        }