public void Open(InputAction actionToRebind, IInputMap mapToRebind, IEnumerable <InputAction> allActions, IInputDevice device)
    {
        if (ChartEditor.Instance)
        {
            ChartEditor.Instance.uiServices.SetPopupBlockingEnabled(true);
        }

        this.device = device;
        rebinder    = new InputRebinder(actionToRebind, mapToRebind, allActions, device);
        gameObject.SetActive(true);
    }
Beispiel #2
0
            public float?GetAxis(IInputMap inputMap)
            {
                KeyboardMap map = inputMap as KeyboardMap;

                if (map == null)
                {
                    return(null);
                }

                return(GetInput(inputMap) ? (float?)1.0f : null);
            }
Beispiel #3
0
            public bool HasConflict(IInputMap map)
            {
                foreach (var inputMap in inputMaps)
                {
                    if (inputMap.HasConflict(map))
                    {
                        return(true);
                    }
                }

                return(false);
            }
Beispiel #4
0
        public override void Input()
        {
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            SelectInput.RegisterState(inputMap.Movement.Magnitude > 0 ? ButtonState.Pressed : ButtonState.Released);

            if (inputMap.Movement.Magnitude > 0)
            {
                if (inputMap.Movement.Y > 0 && SelectInput.Execute())
                {
                    SelectedIndex--;
                    Woofer.Controller.AudioUnit["select"].Play();
                }
                else if (inputMap.Movement.Y < 0 && SelectInput.Execute())
                {
                    SelectedIndex++;
                    Woofer.Controller.AudioUnit["select"].Play();
                }

                if (SelectedIndex > 3)
                {
                    SelectedIndex = 0;
                }
                if (SelectedIndex < 0)
                {
                    SelectedIndex = 3;
                }
            }


            if (inputMap.Jump.Consume())
            {
                switch (SelectedIndex)
                {
                case 0:
                    //Woofer.Controller.CurrentSave = new SaveGame("main");
                    //Woofer.Controller.CommandFired(new SavedSceneChangeCommand("Tutorial"));
                    Woofer.Controller.CommandFired(new InternalSceneChangeCommand(new FileSelect()));
                    break;

                case 1:
                    break;

                case 2:
                    Woofer.Controller.CommandFired(new InternalSceneChangeCommand(new LevelSelect()));
                    break;

                case 3:
                    Environment.Exit(0);
                    break;
                }
            }
        }
Beispiel #5
0
        public override void Input()
        {
            if (!ModalActive)
            {
                return;
            }

            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            if (inputMap.Pulse.Consume())
            {
                Mode++;
                if (Mode > 1)
                {
                    Mode = 0;
                }
            }

            if (Mode == Fill)
            {
                if (CursorSystem.StoppedDragging)
                {
                    Rectangle area = CursorSystem.SelectionRectangle - Pivot;
                    FillTiles(ConvertToGrid(area), true);
                }
                if (CursorSystem.Dragging)
                {
                    PreviewOutline.Bounds = ConvertFromGrid(ConvertToGrid(CursorSystem.SelectionRectangle - Pivot));
                }
                else
                {
                    PreviewOutline.Bounds = ConvertFromGrid(ConvertToGrid(new Rectangle(CursorSystem.CursorPos, new Size(0, 0)) - Pivot));
                }
            }
            else if (Mode == Clear)
            {
                if (CursorSystem.StoppedDragging)
                {
                    Rectangle area = CursorSystem.SelectionRectangle - Pivot;
                    FillTiles(ConvertToGrid(area), false);
                }
                if (CursorSystem.Dragging)
                {
                    PreviewOutline.Bounds = ConvertFromGrid(ConvertToGrid(CursorSystem.SelectionRectangle - Pivot));
                }
                else
                {
                    PreviewOutline.Bounds = ConvertFromGrid(ConvertToGrid(new Rectangle(CursorSystem.CursorPos, new Size(0, 0)) - Pivot));
                }
            }
        }
Beispiel #6
0
        public override void Input()
        {
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            Vector2D thumbstick = inputMap.Orientation;

            if (thumbstick.Magnitude >= deadzone)
            {
                foreach (PlayerOrientation po in WatchedComponents)
                {
                    po.Unit = thumbstick.Unit();
                }
            }
        }
Beispiel #7
0
        public override void Input()
        {
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            if (inputMap.Back.Consume())
            {
                Woofer.Controller.CommandFired(new InternalSceneChangeCommand(new MainMenuScene()));
            }

            SelectInput.RegisterState(inputMap.Movement.Magnitude > 0 ? ButtonState.Pressed : ButtonState.Released);

            if (inputMap.Movement.Magnitude > 0)
            {
                if (inputMap.Movement.Y > 0 && SelectInput.Execute())
                {
                    SelectedIndex--;
                    Woofer.Controller.AudioUnit["select"].Play();
                }
                else if (inputMap.Movement.Y < 0 && SelectInput.Execute())
                {
                    SelectedIndex++;
                    Woofer.Controller.AudioUnit["select"].Play();
                }

                if (SelectedIndex >= MaxFileCount)
                {
                    SelectedIndex = 0;
                }
                if (SelectedIndex < 0)
                {
                    SelectedIndex = 3;
                }
            }


            if (inputMap.Jump.Consume())
            {
                Woofer.Controller.CurrentSave = new SaveGame("save" + (SelectedIndex + 1));
                if (Slots[SelectedIndex] != null)
                {
                    Woofer.Controller.CurrentSave.Load();
                }
                else
                {
                    Woofer.Controller.CurrentSave.CreateNew();
                }
                Woofer.Controller.CommandFired(new SavedSceneChangeCommand(Woofer.Controller.CurrentSave.Data.ActiveSceneName));
            }
        }
Beispiel #8
0
        public override void Input()
        {
            if (!ModalActive)
            {
                return;
            }
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            if (inputMap.Jump.Consume())
            {
                Callback(CursorSystem.CursorPos, true);
                ModalActive = false;
                Owner.Events.InvokeEvent(new RequestModalChangeEvent(null));
            }
        }
Beispiel #9
0
            public bool SetFrom(IInputMap that)
            {
                KeyboardMap kbCast = that as KeyboardMap;

                if (kbCast == null)
                {
                    Debug.LogError("Type incompatibility when trying to call SetFrom on a keyboard input map");
                    return(false);
                }

                modifiers = kbCast.modifiers;
                keys.Clear();
                keys.AddRange(kbCast.keys);

                return(true);
            }
Beispiel #10
0
            public bool SetFrom(IInputMap that)
            {
                GamepadMap gpCast = that as GamepadMap;

                if (gpCast == null)
                {
                    Debug.LogError("Type incompatibility when trying to call SetFrom on a gamepad input map");
                    return(false);
                }

                SetEmpty();
                buttons.AddRange(gpCast.buttons);
                axes.AddRange(gpCast.axes);

                return(true);
            }
Beispiel #11
0
        public override void Input()
        {
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            foreach (PlayerMovementComponent pmc in WatchedComponents)
            {
                Physical rb = pmc.Owner.Components.Get <Physical>();

                ButtonState jumpButton = inputMap.Jump;

                if (jumpButton.IsPressed())
                {
                    pmc.Jump.RegisterPressed();
                }
                else
                {
                    pmc.Jump.RegisterUnpressed();
                }

                if (pmc.OnGround)
                {
                    if (jumpButton.IsPressed() && pmc.Jump.Execute())
                    {
                        rb.Velocity.Y = pmc.JumpSpeed;
                    }
                }

                double xMovement    = inputMap.Movement.X * pmc.CurrentSpeed;
                double xMovementCap = pmc.CurrentMaxSpeed;

                if (xMovement > 0)
                {
                    if (rb.Velocity.X <= xMovementCap)
                    {
                        rb.Velocity.X = Math.Min(rb.Velocity.X + xMovement, xMovementCap);
                    }
                }
                else if (xMovement < 0)
                {
                    if (rb.Velocity.X >= -xMovementCap)
                    {
                        rb.Velocity.X = Math.Max(rb.Velocity.X + xMovement, -xMovementCap);
                    }
                }
            }
        }
Beispiel #12
0
        public override void Input()
        {
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            foreach (PulseAbility pa in WatchedComponents.Where(c => c is PulseAbility))
            {
                ButtonState pulseButton = inputMap.Pulse;

                if (pulseButton.IsPressed())
                {
                    pa.Pulse.RegisterPressed();
                }
                else
                {
                    pa.Pulse.RegisterUnpressed();
                }

                if (pa.EnergyMeter >= pa.PulseCost)
                {
                    if (pulseButton.IsPressed() && pa.Pulse.Execute())
                    {
                        double strength = (pa.PulseStrength * Math.Sqrt(pa.EnergyMeter / pa.MaxEnergy));

                        if (pa.Owner.Components.Has <Physical>() && pa.Owner.Components.Has <PlayerOrientation>())
                        {
                            pa.Owner.Components.Get <Physical>().Velocity = pa.Owner.Components.Get <PlayerOrientation>().Unit * -strength;
                        }

                        pa.EnergyMeter -= pa.PulseCost;

                        if (pa.Owner.Components.Has <Spatial>())
                        {
                            Spatial sp = pa.Owner.Components.Get <Spatial>();
                            if (sp == null)
                            {
                                continue;
                            }
                            PlayerOrientation po = pa.Owner.Components.Get <PlayerOrientation>();

                            Owner.Events.InvokeEvent(new PulseEvent(pa, sp.Position, po != null ? po.Unit : new Vector2D(), strength, pa.MaxRange));
                        }
                    }
                }
            }
        }
Beispiel #13
0
        public bool SetFrom(IInputMap that)
        {
            JoystickMap jsCast = that as JoystickMap;

            if (jsCast == null)
            {
                Debug.LogError("Type incompatibility when trying to call SetFrom on a joystick input map");
                return(false);
            }

            SetEmpty();
            buttons.AddRange(jsCast.buttons);
            axes.AddRange(jsCast.axes);
            balls.AddRange(jsCast.balls);
            hats.AddRange(jsCast.hats);

            return(true);
        }
Beispiel #14
0
        public override void Input()
        {
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            Vector2D thumbstick = inputMap.Orientation;

            if (thumbstick.Magnitude >= deadzone)
            {
                foreach (PlayerOrientation po in WatchedComponents)
                {
                    if ((po.Owner.GetComponent <Health>()?.CurrentHealth ?? 1) <= 0)
                    {
                        continue;
                    }
                    po.Unit = thumbstick.Normalize();
                    po.Owner.Components.Get <FollowedComponent>().Offset = po.OriginOffset + po.Unit * 24;
                }
            }
        }
Beispiel #15
0
        public override void Input()
        {
            if (!ModalActive)
            {
                return;
            }
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            Vector2D movement = inputMap.Movement;

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

            if (SelectedIndex < StartOffset)
            {
                StartOffset = SelectedIndex;
            }
            if (SelectedIndex > StartOffset + AmountVisible)
            {
                StartOffset = SelectedIndex - AmountVisible;
            }

            if (inputMap.Jump.Consume())
            {
                Submit();
            }
        }
Beispiel #16
0
        public override void Input()
        {
            if (!ModalActive)
            {
                return;
            }
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            Vector2D movement = inputMap.Movement;

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

            if (inputMap.Jump.Consume())
            {
                IMemberSummary member = Members.ElementAt(SelectedPropertyIndex);
                if (member.CanSet)
                {
                    bool modalNeedsChange = member.TriggerEdit(inputMap.Interact.Pressed);
                    if (modalNeedsChange)
                    {
                        ModalActive = false;
                    }
                }
            }
        }
Beispiel #17
0
            public bool HasConflict(IInputMap other, InputAction.Properties properties)
            {
                KeyboardMap otherKbMap = other as KeyboardMap;

                if (otherKbMap == null || otherKbMap.IsEmpty)
                {
                    return(false);
                }

                KeyboardDevice.ModifierKeys manualModifierKeysPressed = KeyboardDevice.ModifierKeys.None;
                foreach (KeyCode otherKeyCode in otherKbMap.keys)
                {
                    manualModifierKeysPressed |= KeyboardDevice.ToModifierKey(otherKeyCode);
                }

                if (keys.Count <= 0 && modifiers == manualModifierKeysPressed && modifiers != KeyboardDevice.ModifierKeys.None)
                {
                    return(true);
                }

                if (modifiers != otherKbMap.modifiers)
                {
                    return(false);
                }

                foreach (KeyCode keyCode in keys)
                {
                    foreach (KeyCode otherKeyCode in otherKbMap.keys)
                    {
                        bool modifierKeyConflict = (KeyboardDevice.ToModifierKey(keyCode) & otherKbMap.modifiers) != 0;

                        if (modifierKeyConflict || keyCode == otherKeyCode)
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
            public override bool GetInputUp(IInputMap inputMap)
            {
                KeyboardMap map = inputMap as KeyboardMap;

                if (map == null)
                {
                    return(false);
                }

                if (!CheckDesiredModifierKeysActive(map.modifiers))
                {
                    return(false);
                }

                if (map.modifiers == ModifierKeys.None && map.keys.Count <= 0)
                {
                    return(false);
                }

                // Look for at least 1 key that is coming up. The rest just need to be pressed
                bool hasInputDir = false;

                foreach (KeyCode keyCode in map.keys)
                {
                    if (!CheckKey(keyCode, inputUpFn))
                    {
                        if (!CheckKey(keyCode, inputGetFn))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        hasInputDir = true;
                    }
                }

                return(hasInputDir);
            }
Beispiel #19
0
            public List <IInputMap> GetMapsForDevice(IInputDevice device)
            {
                List <IInputMap> deviceMaps = new List <IInputMap>();

                foreach (IInputMap map in inputMaps)
                {
                    if (map.IsCompatibleWithDevice(device))
                    {
                        deviceMaps.Add(map);
                    }
                }

                if (deviceMaps.Count <= 0)
                {
                    // Make some defaults
                    IInputMap newMap = device.MakeDefaultMap();
                    inputMaps.Add(newMap);
                    deviceMaps.Add(newMap);
                }

                return(deviceMaps);
            }
Beispiel #20
0
        public override void Input()
        {
            if (!ModalActive)
            {
                return;
            }
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            Vector2D movement = inputMap.Movement;

            if (movement.Magnitude > 1e-5 && Editor.MoveTimeframe.Execute())
            {
                bool shifting = inputMap.Interact.Pressed;

                if (movement.Y > 0)
                {
                    if (shifting)
                    {
                        ComponentSystem selected = Owner.Systems.ElementAtOrDefault(SelectedIndex);
                        if (selected != null)
                        {
                            if (SelectedIndex - 1 >= 0)
                            {
                                Owner.Systems.Dictionary.Insert(selected.SystemName, selected, SelectedIndex - 1);
                                Owner.Systems.QueueOnFlush(() => Owner.Systems.UpdateOrder());
                                SelectedIndex--;
                            }
                        }
                    }
                    else if (SelectedIndex - 1 >= -1)
                    {
                        SelectedIndex--;
                    }
                }
                else if (movement.Y < 0)
                {
                    if (shifting)
                    {
                        ComponentSystem selected = Owner.Systems.ElementAtOrDefault(SelectedIndex);
                        if (selected != null)
                        {
                            if (SelectedIndex + 1 < Owner.Systems.Count)
                            {
                                Owner.Systems.Dictionary.Insert(selected.SystemName, selected, SelectedIndex + 1);
                                Owner.Systems.QueueOnFlush(() => Owner.Systems.UpdateOrder());
                                SelectedIndex++;
                            }
                        }
                    }
                    else if (SelectedIndex + 1 < Owner.Systems.Count)
                    {
                        SelectedIndex++;
                    }
                }
                if (movement.Y != 0)
                {
                    RemoveTimer = 0;
                }
            }

            if (inputMap.Jump.Consume())
            {
                if (SelectedIndex == -1)
                {
                    Owner.Events.InvokeEvent(new StartEnumSelectEvent("Available systems", ComponentSystem.GetAllIdentifiers().Where(s => !Owner.Systems.Contains(s)).ToList(), AddSystem, null));
                    Owner.Events.InvokeEvent(new ForceModalChangeEvent("enum_select", null));
                    ModalActive = false;
                }
                else
                {
                    //Owner.Events.InvokeEvent(new EntitySelectEvent(Owner.Systems.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;
                if (RemoveTimer / 25 > 3)
                {
                    Owner.Systems.Remove(Owner.Systems.ElementAt(SelectedIndex).SystemName);
                    RemoveTimer = 0;
                }
            }
            else
            {
                RemoveTimer = 0;
            }

            if (SelectedIndex < StartOffset)
            {
                StartOffset = SelectedIndex;
            }
            if (SelectedIndex > StartOffset + AmountVisible)
            {
                StartOffset = SelectedIndex - AmountVisible;
            }
        }
Beispiel #21
0
        public override void Input()
        {
            if (!ModalActive)
            {
                return;
            }
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            if (inputMap.Movement.Magnitude > 0 && Editor.MoveTimeframe.Execute())
            {
                Vector2D screenMovement = inputMap.Movement;
                screenMovement.Y *= -1;
                GUIButton nextButton = Pad.Where(b => b.Enabled && b.Position != CurrentPos && GeneralUtil.SubtractAngles((b.Position - CurrentPos).Angle, screenMovement.Angle) < Math.PI / 2).OrderBy(b => (b.Position - CurrentPos).Magnitude).FirstOrDefault();
                if (nextButton != null)
                {
                    SwitchButton(nextButton);
                }
            }

            if (CurrentButton != null && ((CurrentButton.Repeating && inputMap.Jump.ConsumeRepeating()) || (!CurrentButton.Repeating && inputMap.Jump.Consume())))
            {
                GUIButton button = CurrentButton;
                if (button != null && button.Enabled)
                {
                    if (char.IsDigit(button.Display[0]))
                    {
                        Display += button.Display[0];
                    }
                    else if (button.Display[0] == '-')
                    {
                        if (Display == "0")
                        {
                            //Do nothing if zero
                        }
                        else if (Display.StartsWith("-"))
                        {
                            Display = Display.Substring(1);
                        }
                        else
                        {
                            Display = "-" + Display;
                        }
                    }
                    else if (button.Display[0] == '.')
                    {
                        if (!Display.Contains('.'))
                        {
                            Display += '.';
                        }
                    }
                    else if (button.Display[0] == '^' || button.Display[0] == 'v')
                    {
                        Normalize();
                        double value = double.Parse(Display);
                        if (button.Display[0] == '^')
                        {
                            value++;
                        }
                        else
                        {
                            value--;
                        }
                        Display = value.ToString();
                    }
                    else if (button.Display[0] == '\b')
                    {
                        if (Display.Length > 0)
                        {
                            Display = Display.Substring(0, Display.Length - 1);
                        }
                    }
                    else if (button.Display[0] == '\u0018')
                    {
                        Display = "0";
                    }
                    else if (button.Display[0] == '\u0007')
                    {
                        Submit();
                    }
                    Dirty = true;
                }
            }
        }
Beispiel #22
0
        public override void Input()
        {
            if (!ModalActive)
            {
                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 (SelectedAnimationIndex - 1 >= -2)
                        {
                            SelectedAnimationIndex--;
                        }
                    }
                }
                else if (movement.Y < 0)
                {
                    if (ComponentLocked)
                    {
                        if (SelectedPropertyIndex + 1 < SelectedAnimation.Members.Count)
                        {
                            SelectedPropertyIndex++;
                        }
                    }
                    else
                    {
                        if (SelectedAnimationIndex + 1 <= Animations.Count)
                        {
                            SelectedAnimationIndex++;
                        }
                    }
                }

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

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

            if (inputMap.Jump.Consume())
            {
                if (SelectedAnimationIndex == Animations.Count)
                {
                    Animations.Add(new AnimatedSprite());
                }
                else if (!ComponentLocked)
                {
                    SelectedAnimation     = new ObjectSummary(Owner, Animations[SelectedAnimationIndex]);
                    SelectedPropertyIndex = 0;
                    ComponentLocked       = true;
                }
                else
                {
                    if (SelectedPropertyIndex >= SelectedAnimation.Members.Count)
                    {
                        return;
                    }
                    IMemberSummary member = SelectedAnimation.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 && SelectedAnimationIndex >= 0 && !ComponentLocked)
            {
                RemoveTimer += 2;
                if (RemoveTimer / 25 > 3)
                {
                    Animations.RemoveAt(SelectedAnimationIndex);
                    RemoveTimer = 0;
                    if (SelectedAnimationIndex >= Animations.Count)
                    {
                        SelectedAnimationIndex = Animations.Count - 1;
                    }
                }
            }
            else
            {
                RemoveTimer = 0;
            }

            if (SelectedAnimationIndex >= 0 && SelectedAnimationIndex < AnimationRenderOffsets.Count)
            {
                int y = AnimationRenderOffsets[SelectedAnimationIndex];
                if (y < 0)
                {
                    ListFromIndex--;
                }
                else if (y > 720)
                {
                    ListFromIndex = Math.Max(0, SelectedAnimationIndex - 2);
                }
            }
        }
Beispiel #23
0
        public override void Input()
        {
            if (!ModalActive)
            {
                return;
            }
            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            if (inputMap.Movement.Magnitude > 0 && Editor.MoveTimeframe.Execute())
            {
                Vector2D screenMovement = inputMap.Movement;
                screenMovement.Y *= -1;

                Vector2D  movementSource = CurrentPos;
                GUIButton button         = CurrentButton;

                /*if(button != null)
                 * {
                 *  movementSource.X += screenMovement.X * button.Bounds.Width / 2;
                 *  movementSource.Y += screenMovement.Y * button.Bounds.Height / 2;
                 * }*/

                GUIButton nextButton = Pad.Where(b => b.Enabled && b.Position != CurrentPos && GeneralUtil.SubtractAngles((b.Position - CurrentPos).Angle, screenMovement.Angle) < Math.PI / 2).OrderBy(b => GeneralUtil.SubtractAngles((b.Position - CurrentPos).Angle, screenMovement.Angle)).ThenBy(b => (b.Position - movementSource).Magnitude).FirstOrDefault();
                if (nextButton != null)
                {
                    SwitchButton(nextButton);
                }
            }

            if (CurrentButton != null && ((CurrentButton.Repeating && inputMap.Jump.ConsumeRepeating()) || (!CurrentButton.Repeating && inputMap.Jump.Consume())))
            {
                GUIButton button = CurrentButton;
                if (button != null && button.Enabled)
                {
                    if (button.Display[0] == '\b')
                    {
                        if (CaretIndex > 0 && Display.Length > 0)
                        {
                            Display = Display.Substring(0, CaretIndex - 1) + Display.Substring(CaretIndex);
                            CaretIndex--;
                        }
                    }
                    else if (button.Display[0] == '\u001B')  // SHIFT
                    {
                        Shift = !Shift;
                    }
                    else if (button.Display[0] == '\u0011')  // LEFT
                    {
                        if (CaretIndex > 0)
                        {
                            CaretIndex--;
                        }
                    }
                    else if (button.Display[0] == '\u0012')  // RIGHT
                    {
                        if (CaretIndex < Display.Length)
                        {
                            CaretIndex++;
                        }
                    }
                    else if (button.Display[0] == '\u0007')
                    {
                        Submit();
                    }
                    else
                    {
                        Display = Display.Substring(0, CaretIndex) + button.Display + Display.Substring(CaretIndex);
                        CaretIndex++;
                    }
                }
            }
        }
Beispiel #24
0
 public void Add(IInputMap map)
 {
     inputMaps.Add(map);
 }
        public bool HasConflict(IInputMap other, InputAction.Properties properties)
        {
            GamepadMap otherGpMap = other as GamepadMap;

            if (otherGpMap == null || otherGpMap.IsEmpty)
            {
                return(false);
            }

            bool allowSameFrameMultiInput = properties.allowSameFrameMultiInput;

            if (allowSameFrameMultiInput)
            {
                if (buttons.Count > 0 && otherGpMap.buttons.Count > 0)
                {
                    // Check if they match exactly, or if one map is a sub-set of the other
                    var smallerButtonMap = buttons.Count < otherGpMap.buttons.Count ? buttons : otherGpMap.buttons;
                    var largerButtonMap  = buttons.Count < otherGpMap.buttons.Count ? otherGpMap.buttons : buttons;

                    int sameInputCount = 0;
                    foreach (var button in smallerButtonMap)
                    {
                        if (largerButtonMap.Contains(button))
                        {
                            ++sameInputCount;
                        }
                    }

                    if (sameInputCount == smallerButtonMap.Count)
                    {
                        return(true);
                    }
                }
            }
            else
            {
                foreach (var button in buttons)
                {
                    foreach (var otherButton in otherGpMap.buttons)
                    {
                        if (button == otherButton)
                        {
                            return(true);
                        }
                    }
                }
            }

            foreach (var axis in axes)
            {
                foreach (var otherAxis in otherGpMap.axes)
                {
                    if (axis.axis == otherAxis.axis && (axis.dir == otherAxis.dir || axis.dir == GamepadDevice.AxisDir.Any || otherAxis.dir == GamepadDevice.AxisDir.Any))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #26
0
        public override void Input()
        {
            if (!ModalActive)
            {
                return;
            }

            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            if (inputMap.Pulse.Consume())
            {
                Mode++;
                if ((MultipleAllowed && Mode > 4) || (!MultipleAllowed && Mode > 1))
                {
                    Mode = 0;
                }
                SelectionLocked = false;
            }

            if (Mode == Edit)
            {
                if (!SelectionLocked)
                {
                    UpdateSelected();
                    if (SelectedSprite != null && inputMap.Jump.Consume())
                    {
                        SelectionLocked = true;
                    }
                }
                if (SelectionLocked)
                {
                    if (!CursorSystem.Dragging)
                    {
                        DraggingSide = -1;
                    }
                    FaceOutline.Bounds = new Rectangle(FaceOutline.Bounds?.X ?? 0, FaceOutline.Bounds?.Y ?? 0, 0, 0);

                    Rectangle selectedBounds = SelectedSprite.Destination + Origin;

                    if (CursorSystem.StartedDragging)
                    {
                        PreResizeBounds = selectedBounds;
                    }

                    int highlightedSide = UpdateSelectedFace();
                    if (highlightedSide != -1 && DraggingSide == -1 && CursorSystem.Dragging)
                    {
                        DraggingSide = highlightedSide;
                    }

                    if (CursorSystem.Dragging && DraggingSide == -1 && selectedBounds.Contains(CursorSystem.CursorPos))
                    {
                        DraggingSide = 4;
                    }

                    if (CursorSystem.Dragging && DraggingSide != -1 && PreResizeBounds != null)
                    {
                        if (DraggingSide == 3) //Left
                        {
                            double prevRight = SelectedSprite.Destination.Right;
                            SelectedSprite.Destination.X     = (CursorSystem.CursorPos.X - Origin.X);
                            SelectedSprite.Destination.Width = prevRight - SelectedSprite.Destination.X;
                            if (SelectedSprite.Destination.Width < 0)
                            {
                                double min = Math.Min(SelectedSprite.Destination.Left, SelectedSprite.Destination.Right);
                                double max = Math.Max(SelectedSprite.Destination.Left, SelectedSprite.Destination.Right);
                                SelectedSprite.Destination.X     = min;
                                SelectedSprite.Destination.Width = max - min;
                                DraggingSide = 1;
                            }
                        }
                        else if (DraggingSide == 1) //Right
                        {
                            SelectedSprite.Destination.Width = (CursorSystem.CursorPos.X - SelectedSprite.Destination.X) - Origin.X;

                            if (SelectedSprite.Destination.Width < 0)
                            {
                                double min = Math.Min(SelectedSprite.Destination.Left, SelectedSprite.Destination.Right);
                                double max = Math.Max(SelectedSprite.Destination.Left, SelectedSprite.Destination.Right);
                                SelectedSprite.Destination.X     = min;
                                SelectedSprite.Destination.Width = max - min;
                                DraggingSide = 3;
                            }
                        }
                        else if (DraggingSide == 2) //Bottom
                        {
                            double prevTop = SelectedSprite.Destination.Top;
                            SelectedSprite.Destination.Y      = (CursorSystem.CursorPos.Y - Origin.Y);
                            SelectedSprite.Destination.Height = prevTop - SelectedSprite.Destination.Y;
                            if (SelectedSprite.Destination.Height < 0)
                            {
                                double min = Math.Min(SelectedSprite.Destination.Bottom, SelectedSprite.Destination.Top);
                                double max = Math.Max(SelectedSprite.Destination.Bottom, SelectedSprite.Destination.Top);
                                SelectedSprite.Destination.Y      = min;
                                SelectedSprite.Destination.Height = max - min;
                                DraggingSide = 0;
                            }
                        }
                        else if (DraggingSide == 0) //Top
                        {
                            SelectedSprite.Destination.Height = (CursorSystem.CursorPos.Y - SelectedSprite.Destination.Y) - Origin.Y;

                            if (SelectedSprite.Destination.Height < 0)
                            {
                                double min = Math.Min(SelectedSprite.Destination.Bottom, SelectedSprite.Destination.Top);
                                double max = Math.Max(SelectedSprite.Destination.Bottom, SelectedSprite.Destination.Top);
                                SelectedSprite.Destination.Y      = min;
                                SelectedSprite.Destination.Height = max - min;
                                DraggingSide = 2;
                            }
                        }
                        else if (DraggingSide == 4) //Middle
                        {
                            SelectedSprite.Destination.X = PreResizeBounds.X + (CursorSystem.CursorPos.X - CursorSystem.SelectionStart.X) - Origin.X;
                            SelectedSprite.Destination.Y = PreResizeBounds.Y + (CursorSystem.CursorPos.Y - CursorSystem.SelectionStart.Y) - Origin.Y;
                        }
                    }
                }
            }
            else if (Mode == Create)
            {
                if (CursorSystem.StartedDragging)
                {
                    Sprite newSprite = new Sprite("null", CursorSystem.SelectionRectangle - Origin, Rectangle.Empty);
                    AddSprite(newSprite);
                    Creating = true;
                }
                if (CursorSystem.Dragging && Creating)
                {
                    Sprite newSprite = Sprites.Last();
                    newSprite.Destination.X      = CursorSystem.SelectionRectangle.X - Origin.X;
                    newSprite.Destination.Y      = CursorSystem.SelectionRectangle.Y - Origin.Y;
                    newSprite.Destination.Width  = CursorSystem.SelectionRectangle.Width;
                    newSprite.Destination.Height = CursorSystem.SelectionRectangle.Height;
                }
                if (CursorSystem.StoppedDragging && Creating)
                {
                    Sprite newSprite = Sprites.Last();
                    if (newSprite.Destination.Area == 0)
                    {
                        RemoveSprite(newSprite);
                    }
                    Creating = false;
                }
            }
            else if (Mode == Delete)
            {
                UpdateSelected();
                if (SelectedSprite != null)
                {
                    IOutline associatedOutline = null;
                    foreach (IOutline outline in Outlines)
                    {
                        if (outline is SpriteOutline spriteOutline)
                        {
                            if (spriteOutline.Sprite == SelectedSprite)
                            {
                                spriteOutline.Color     = Color.Red;
                                spriteOutline.Thickness = 4;
                                associatedOutline       = outline;
                            }
                        }
                    }
                    if (inputMap.Jump.Consume())
                    {
                        RemoveSprite(SelectedSprite);
                    }
                }
            }
            else if (Mode == TweakUV)
            {
                if (!SelectionLocked)
                {
                    UpdateSelected();
                    if (SelectedSprite != null && inputMap.Jump.Consume())
                    {
                        //SelectionLocked = true;
                        Owner.Events.InvokeEvent(new StartSpriteSourceEditEvent(SelectedSprite));
                        Owner.Events.InvokeEvent(new ForceModalChangeEvent("sprite_source_view", null));
                        CursorSystem.ModalActive = false;
                        ModalActive = false;
                        Console.WriteLine("Start editing UV of sprite");
                    }
                }
            }
            else if (Mode == Clone)
            {
                UpdateSelected();
                if (SelectedSprite != null)
                {
                    IOutline associatedOutline = null;
                    foreach (IOutline outline in Outlines)
                    {
                        if (outline is SpriteOutline spriteOutline)
                        {
                            if (spriteOutline.Sprite == SelectedSprite)
                            {
                                spriteOutline.Color     = Color.MediumAquamarine;
                                spriteOutline.Thickness = 4;
                                associatedOutline       = outline;
                            }
                        }
                    }
                    if (inputMap.Jump.Consume())
                    {
                        Sprite clone = new Sprite
                        {
                            Texture     = SelectedSprite.Texture,
                            Destination = new Rectangle(SelectedSprite.Destination) + new Vector2D(4, 4),
                            Source      = SelectedSprite.Source,
                            DrawMode    = SelectedSprite.DrawMode,
                            Modifiers   = SelectedSprite.Modifiers,
                            Opacity     = SelectedSprite.Opacity
                        };
                        AddSprite(clone);
                    }
                }
            }
        }
Beispiel #27
0
        public bool HasConflict(IInputMap other, InputAction.Properties properties)
        {
            JoystickMap otherMap = other as JoystickMap;

            if (otherMap == null || otherMap.IsEmpty)
            {
                return(false);
            }

            bool allowSameFrameMultiInput = properties.allowSameFrameMultiInput;

            if (allowSameFrameMultiInput)
            {
                if (buttons.Count > 0 && otherMap.buttons.Count > 0)
                {
                    // Check if they match exactly, or if one map is a sub-set of the other
                    var smallerButtonMap = buttons.Count < otherMap.buttons.Count ? buttons : otherMap.buttons;
                    var largerButtonMap  = buttons.Count < otherMap.buttons.Count ? otherMap.buttons : buttons;

                    int sameInputCount = 0;
                    foreach (var button in smallerButtonMap)
                    {
                        bool contains = false;
                        foreach (var otherButton in largerButtonMap)
                        {
                            if (button.buttonIndex == otherButton.buttonIndex)
                            {
                                contains = true;
                                break;
                            }
                        }

                        if (contains)
                        {
                            ++sameInputCount;
                        }
                    }

                    if (sameInputCount == smallerButtonMap.Count)
                    {
                        return(true);
                    }
                }
            }
            else
            {
                foreach (var button in buttons)
                {
                    foreach (var otherButton in otherMap.buttons)
                    {
                        if (button.buttonIndex == otherButton.buttonIndex)
                        {
                            return(true);
                        }
                    }
                }
            }

            foreach (var axis in axes)
            {
                foreach (var otherAxis in otherMap.axes)
                {
                    if (axis.axisIndex == otherAxis.axisIndex && (axis.dir == otherAxis.dir || axis.dir == JoystickDevice.AxisDir.Any || otherAxis.dir == JoystickDevice.AxisDir.Any))
                    {
                        return(true);
                    }
                }
            }

            foreach (var ballIndex in balls)
            {
                foreach (var otherBallIndex in otherMap.balls)
                {
                    if (ballIndex.ballIndex == otherBallIndex.ballIndex)
                    {
                        return(true);
                    }
                }
            }

            foreach (var hat in hats)
            {
                foreach (var otherHat in otherMap.hats)
                {
                    if (hat.hatIndex == otherHat.hatIndex && hat.position == otherHat.position)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public override void Input()
        {
            if (!ModalActive)
            {
                return;
            }

            IInputMap inputMap = Woofer.Controller.InputManager.ActiveInputMap;

            if (inputMap.Pulse.Consume())
            {
                Mode++;
                if ((MultipleAllowed && Mode > 3) || (!MultipleAllowed && Mode > 1))
                {
                    Mode = 0;
                }
                SelectionLocked = false;
            }

            if (Mode == Edit)
            {
                if (!SelectionLocked)
                {
                    UpdateSelected();
                    if (SelectedBox != null && inputMap.Jump.Consume())
                    {
                        SelectionLocked = true;
                    }
                }
                if (SelectionLocked)
                {
                    if (!CursorSystem.Dragging)
                    {
                        DraggingSide = -1;
                    }
                    FaceOutline.Bounds = new Rectangle(FaceOutline.Bounds?.X ?? 0, FaceOutline.Bounds?.Y ?? 0, 0, 0);

                    Rectangle selectedBounds = SelectedBox.ToRectangle() + Pivot;

                    if (CursorSystem.StartedDragging)
                    {
                        PreResizeBounds = selectedBounds;
                    }

                    int highlightedSide = UpdateSelectedFace();
                    if (highlightedSide != -1 && DraggingSide == -1 && CursorSystem.Dragging)
                    {
                        DraggingSide = highlightedSide;
                    }

                    if (CursorSystem.Dragging && DraggingSide == -1 && selectedBounds.Contains(CursorSystem.CursorPos))
                    {
                        DraggingSide = 4;
                    }

                    if (CursorSystem.Dragging && DraggingSide != -1 && PreResizeBounds != Rectangle.Empty)
                    {
                        if (DraggingSide == 3) //Left
                        {
                            double prevRight = SelectedBox.Right;
                            SelectedBox.X     = (CursorSystem.CursorPos.X - Pivot.X);
                            SelectedBox.Width = prevRight - SelectedBox.X;
                            if (SelectedBox.Width < 0)
                            {
                                double min = Math.Min(SelectedBox.Left, SelectedBox.Right);
                                double max = Math.Max(SelectedBox.Left, SelectedBox.Right);
                                SelectedBox.X     = min;
                                SelectedBox.Width = max - min;
                                DraggingSide      = 1;
                            }
                        }
                        else if (DraggingSide == 1) //Right
                        {
                            SelectedBox.Width = (CursorSystem.CursorPos.X - SelectedBox.X) - Pivot.X;

                            if (SelectedBox.Width < 0)
                            {
                                double min = Math.Min(SelectedBox.Left, SelectedBox.Right);
                                double max = Math.Max(SelectedBox.Left, SelectedBox.Right);
                                SelectedBox.X     = min;
                                SelectedBox.Width = max - min;
                                DraggingSide      = 3;
                            }
                        }
                        else if (DraggingSide == 2)   //Bottom
                        {
                            double prevTop = SelectedBox.Top;
                            SelectedBox.Y      = (CursorSystem.CursorPos.Y - Pivot.Y);
                            SelectedBox.Height = prevTop - SelectedBox.Y;
                            if (SelectedBox.Height < 0)
                            {
                                double min = Math.Min(SelectedBox.Bottom, SelectedBox.Top);
                                double max = Math.Max(SelectedBox.Bottom, SelectedBox.Top);
                                SelectedBox.Y      = min;
                                SelectedBox.Height = max - min;
                                DraggingSide       = 0;
                            }
                        }
                        else if (DraggingSide == 0) //Top
                        {
                            SelectedBox.Height = (CursorSystem.CursorPos.Y - SelectedBox.Y) - Pivot.Y;

                            if (SelectedBox.Height < 0)
                            {
                                double min = Math.Min(SelectedBox.Bottom, SelectedBox.Top);
                                double max = Math.Max(SelectedBox.Bottom, SelectedBox.Top);
                                SelectedBox.Y      = min;
                                SelectedBox.Height = max - min;
                                DraggingSide       = 2;
                            }
                        }
                        else if (DraggingSide == 4)  //Middle
                        {
                            SelectedBox.X = PreResizeBounds.X + (CursorSystem.CursorPos.X - CursorSystem.SelectionStart.X) - Pivot.X;
                            SelectedBox.Y = PreResizeBounds.Y + (CursorSystem.CursorPos.Y - CursorSystem.SelectionStart.Y) - Pivot.Y;
                        }
                    }
                }
            }
            else if (Mode == Create)
            {
                if (CursorSystem.StartedDragging)
                {
                    CollisionBox newBox = new CollisionBox(CursorSystem.SelectionRectangle - Pivot);
                    Boxes.Add(newBox);
                    IOutline newOutline = new CollisionBoxOutline(Pivot, newBox, Color.Orange);
                    Outlines.Add(newOutline);
                    Owner.Events.InvokeEvent(new BeginOverlay(newOutline));
                    Creating = true;
                }
                if (CursorSystem.Dragging && Creating)
                {
                    CollisionBox newBox = Boxes.Last();
                    newBox.X      = CursorSystem.SelectionRectangle.X - Pivot.X;
                    newBox.Y      = CursorSystem.SelectionRectangle.Y - Pivot.Y;
                    newBox.Width  = CursorSystem.SelectionRectangle.Width;
                    newBox.Height = CursorSystem.SelectionRectangle.Height;
                }
                if (CursorSystem.StoppedDragging && Creating)
                {
                    CollisionBox newBox = Boxes.Last();
                    if (newBox.Area == 0)
                    {
                        RemoveBox(newBox);
                    }
                    Creating = false;
                }
            }
            else if (Mode == Delete)
            {
                UpdateSelected();
                if (SelectedBox != null)
                {
                    IOutline associatedOutline = null;
                    foreach (IOutline outline in Outlines)
                    {
                        if (outline is CollisionBoxOutline boxOutline)
                        {
                            if (boxOutline.Box == SelectedBox)
                            {
                                boxOutline.Color     = Color.Red;
                                boxOutline.Thickness = 4;
                                associatedOutline    = outline;
                            }
                        }
                    }
                    if (inputMap.Jump.Consume())
                    {
                        RemoveBox(SelectedBox);
                    }
                }
            }
            else if (Mode == TweakFaces)
            {
                if (!SelectionLocked)
                {
                    UpdateSelected();
                    if (SelectedBox != null && inputMap.Jump.Consume())
                    {
                        SelectionLocked = true;
                    }
                }
                if (SelectionLocked)
                {
                    FaceOutline.Bounds = new Rectangle(FaceOutline.Bounds?.X ?? 0, FaceOutline.Bounds?.Y ?? 0, 0, 0);

                    int highlightedFace = UpdateSelectedFace();

                    if (highlightedFace != -1 && inputMap.Jump.Consume())
                    {
                        Owner.Events.InvokeEvent(new CollisionFaceSelectEvent(SelectedBox, highlightedFace));
                        Owner.Events.InvokeEvent(new ForceModalChangeEvent("collision_face_view", null));
                        CursorSystem.ModalActive = false;
                        ModalActive = false;
                    }
                }
            }
        }
Beispiel #29
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;
            }
        }
 public abstract bool GetInput(IInputMap map);