Пример #1
0
 public Controller(
     ButtonMap buttonMap       = null,
     Stick2DMap rightStickMap  = null,
     Stick3DMap rightHandMover = null,
     Stick2DMap leftStickMap   = null,
     Stick3DMap leftHandMover  = null,
     float handScale           = 0.3f,
     float handSpeed           = 0.1f
     )
 {
     this.buttonMap = buttonMap;
     this.rightHand = new VRController(
         handAnchorName: "RightHandAnchor",
         stick: OVRInput.RawAxis2D.RThumbstick,
         stickMap: rightStickMap,
         positionMover: rightHandMover,
         scale: handScale,
         speed: handSpeed,
         this.IsOnHeadset()
         );
     this.leftHand = new VRController(
         handAnchorName: "LeftHandAnchor",
         stick: OVRInput.RawAxis2D.LThumbstick,
         stickMap: leftStickMap,
         positionMover: leftHandMover,
         scale: handScale,
         speed: handSpeed,
         this.IsOnHeadset()
         );
 }
Пример #2
0
        public bool OnResponse(NetState ns, RelayInfo info)
        {
            if (_Handler == null || Desktop == null || Desktop.Viewed == null || Desktop.Viewed.NetState == null ||
                Desktop.Viewed.NetState.Gumps == null)
            {
                return(false);
            }

            var buttonID = info.ButtonID;

            if (!ButtonMap.ContainsKey(buttonID))
            {
                return(false);
            }

            buttonID = ButtonMap[buttonID];

            var switches = info.Switches.Where(SwitchMap.ContainsKey).Select(SwitchMap.GetValue).ToArray();
            var texts    = info.TextEntries.Where(tr => TextMap.ContainsKey(tr.EntryID))
                           .Select(tr => new TextRelay(TextMap[tr.EntryID], tr.Text))
                           .ToArray();

            Desktop.Viewed.NetState.Gumps.RemoveAll(g => g.TypeID == _TypeID);
            Desktop.Viewed.NetState.Send(new CloseGump(_TypeID, 0));

            _Handler(Desktop.Viewed.NetState, new RelayInfo(buttonID, switches, texts));
            return(true);
        }
Пример #3
0
        private void CreateSingleActionButtonMapList()
        {
            for (var i = ButtonMap.Count; i > 1; i--)
            {
                ButtonMap.RemoveAt(i - 1);
            }

            for (var i = ReverseButtonMap.Count; i > 1; i--)
            {
                ReverseButtonMap.RemoveAt(i - 1);
            }

            if (ButtonMap.Count == 0)
            {
                ButtonMap.Add(new HOTASButton()
                {
                    MapId = 1, MapName = $"Axis Button 1", Type = HOTASButton.ButtonType.Button
                });
            }

            if (IsDirectional)
            {
                if (ReverseButtonMap.Count == 0)
                {
                    ReverseButtonMap.Add(new HOTASButton()
                    {
                        MapId = 1, MapName = $"Reverse Axis Button 1", Type = HOTASButton.ButtonType.Button
                    });
                }
            }
        }
Пример #4
0
    public void OpenLoadMap()
    {
        ButtonMap[] bMaps = listMaps.GetComponentsInChildren <ButtonMap>();
        for (int i = 0; i < bMaps.Length; i++)
        {
            Destroy(bMaps[i].gameObject);
        }

        string pathFolder = Path.Combine(Application.persistentDataPath, "Saves");

        if (!Directory.Exists(pathFolder))
        {
            Directory.CreateDirectory(pathFolder);
        }

        string[] files = Directory.GetFiles(pathFolder, "*.json");
        for (int i = 0; i < files.Length; i++)
        {
            ButtonMap bMap = Instantiate(bMapName, listMaps);
            bMap.mapName          = Path.GetFileNameWithoutExtension(files[i]);
            bMap.filePath         = files[i];
            bMap.dataPath         = files[i].Replace("json", "png");
            bMap.textMapName.text = bMap.mapName;
        }
    }
Пример #5
0
        public override InputCollection GetDefaultControls()
        {
            InputCollection      ic     = new InputCollection();
            List <ButtonBinding> flight = new List <ButtonBinding>();

            flight.Add(new KeyBinding("right", Keys.D, ButtonEvent.Down, TurnRight));
            ButtonMap map = new ButtonMap("flight", flight);

            ic.AddMap(map);

            //Camera
            ButtonMap camControls = new ButtonMap(GenericInputGroups.Camera.ToString());

            camControls.AddBinding(new KeyBinding("Forward", Keys.NumPad8, ButtonEvent.Down, CameraMoveForward));
            camControls.AddBinding(new KeyBinding("Left", Keys.NumPad4, ButtonEvent.Down, CameraMoveLeft));
            camControls.AddBinding(new KeyBinding("Backward", Keys.NumPad5, ButtonEvent.Down, CameraMoveBackward));
            camControls.AddBinding(new KeyBinding("Right", Keys.NumPad6, ButtonEvent.Down, CameraMoveRight));
            camControls.AddBinding(new KeyBinding("Speed Increase", Keys.NumPad7, ButtonEvent.Pressed, CameraMoveSpeedIncrease));
            camControls.AddBinding(new KeyBinding("Speed Decrease", Keys.NumPad1, ButtonEvent.Pressed, CameraMoveSpeedDecrease));
            camControls.AddBinding(new KeyBinding("Height Increase", Keys.NumPad9, ButtonEvent.Down, CameraMoveHeightIncrease));
            camControls.AddBinding(new KeyBinding("Height Decrease", Keys.NumPad3, ButtonEvent.Down, CameraMoveHeightDecrease));

            camControls.AddBinding(new KeyBinding("Change Mode", Keys.Decimal, ButtonEvent.Pressed, CameraModeCycle));
            camControls.AddBinding(new KeyBinding("Home", Keys.Multiply, ButtonEvent.Pressed, CameraMoveHome));

            camControls.AddBinding(new KeyBinding("Toggle Debug Info", Keys.F1, ButtonEvent.Pressed, ToggleDebugInfo));
            camControls.AddBinding(new KeyBinding("Toggle Physics Debug", Keys.F2, ButtonEvent.Pressed, TogglePhsyicsDebug));
            ic.AddMap(camControls);

            return(ic);
        }
Пример #6
0
        public void LoadFrom(XmlNode xn)
        {
            MappedType = (ControllerType)Enum.Parse(typeof(ControllerType), xn.Attributes["type"].Value, true);
            Source     = (SourceType)Enum.Parse(typeof(SourceType), xn.Attributes["source"].Value, true);
            UUID       = xn.Attributes["uuid"] != null?Guid.Parse(xn.Attributes["uuid"].Value) : Guid.NewGuid();

            if (Source == SourceType.RawInput)
            {
                VendorID    = int.Parse(xn.Attributes["vid"].Value, NumberStyles.HexNumber);
                ProductID   = int.Parse(xn.Attributes["pid"].Value, NumberStyles.HexNumber);
                ReportHash  = uint.Parse(xn.Attributes["rpt_hash"].Value);
                DeviceIndex = int.Parse(xn.Attributes["idx"].Value);
            }
            else if (Source == SourceType.XInput)
            {
                DeviceIndex = int.Parse(xn.Attributes["idx"].Value);
            }
            else if (Source == SourceType.MUNIA)
            {
                DevicePath = xn.Attributes["devicepath"].Value;
            }
            else if (Source == SourceType.Arduino)
            {
                string port = xn.Attributes["arduino_port"].Value;
                ArduinoPort = SerialPortInfo.GetPorts().FirstOrDefault(spi => spi.Name == port) ?? new SerialPortInfo {
                    Name = port
                };
                ArduinoSource = (ControllerType)Enum.Parse(typeof(ControllerType), xn.Attributes["arduino_type"].Value, true);
            }

            foreach (XmlNode n in xn["buttons"].ChildNodes)
            {
                var btn = new ButtonMap();
                btn.LoadFrom(n);
                ButtonMaps.Add(btn);
            }

            foreach (XmlNode n in xn["axes"].ChildNodes)
            {
                var axis = new AxisMap();
                axis.LoadFrom(n);
                AxisMaps.Add(axis);
            }

            foreach (XmlNode n in xn["buttons_to_axis"].ChildNodes)
            {
                var button = new ButtonToAxisMap();
                button.LoadFrom(n);
                ButtonToAxisMaps.Add(button);
            }

            foreach (XmlNode n in xn["axis_to_buttons"].ChildNodes)
            {
                var axis = new AxisToButtonMap();
                axis.LoadFrom(n);
                AxisToButtonMaps.Add(axis);
            }
        }
Пример #7
0
 public void ClearButtonMap()
 {
     ButtonMap.Clear();
     if (App.IsDebug)
     {
         return;
     }
     LoadCapabilitiesMapping();
 }
Пример #8
0
        public override GameHelper.Input.InputCollection GetDefaultControls()
        {
            InputCollection      ic     = new InputCollection();
            List <ButtonBinding> flight = new List <ButtonBinding>();
            //flight.Add(new KeyBinding("right", Microsoft.Xna.Framework.Input.Keys.D, false, false, false, KeyEvent.Down, TurnRight));
            ButtonMap map = new ButtonMap("null", flight);

            ic.AddMap(map);

            //Camera
            ButtonMap camControls = new ButtonMap(GenericInputGroups.Camera.ToString());

            camControls.AddBinding(new KeyBinding("Forward", Keys.NumPad8, ButtonEvent.Down, CameraMoveForward));
            camControls.AddBinding(new KeyBinding("Left", Keys.NumPad4, ButtonEvent.Down, CameraMoveLeft));
            camControls.AddBinding(new KeyBinding("Backward", Keys.NumPad5, ButtonEvent.Down, CameraMoveBackward));
            camControls.AddBinding(new KeyBinding("Right", Keys.NumPad6, ButtonEvent.Down, CameraMoveRight));
            camControls.AddBinding(new KeyBinding("Speed Increase", Keys.NumPad7, ButtonEvent.Pressed, CameraMoveSpeedIncrease));
            camControls.AddBinding(new KeyBinding("Speed Decrease", Keys.NumPad1, ButtonEvent.Pressed, CameraMoveSpeedDecrease));
            camControls.AddBinding(new KeyBinding("Height Increase", Keys.NumPad9, ButtonEvent.Down, CameraMoveHeightIncrease));
            camControls.AddBinding(new KeyBinding("Height Decrease", Keys.NumPad3, ButtonEvent.Down, CameraMoveHeightDecrease));

            camControls.AddBinding(new KeyBinding("Change Mode", Keys.Decimal, ButtonEvent.Pressed, CameraModeCycle));
            camControls.AddBinding(new KeyBinding("Home", Keys.Multiply, ButtonEvent.Pressed, CameraMoveHome));

            camControls.AddBinding(new KeyBinding("Toggle Debug Info", Keys.F1, ButtonEvent.Pressed, ToggleDebugInfo));
            camControls.AddBinding(new KeyBinding("Toggle Physics Debug", Keys.F2, ButtonEvent.Pressed, TogglePhsyicsDebug));

            ic.AddMap(camControls);

            ButtonMap flightControls = new ButtonMap("flight");

            flightControls.AddBinding(new KeyBinding("Forward", Keys.W, ButtonEvent.Down, FeatherPitchDown));
            flightControls.AddBinding(new KeyBinding("Left", Keys.A, ButtonEvent.Down, FeatherRollLeft));
            flightControls.AddBinding(new KeyBinding("Backward", Keys.S, ButtonEvent.Down, FeatherPitchUp));
            flightControls.AddBinding(new KeyBinding("Right", Keys.D, ButtonEvent.Down, FeatherRollRight));
            flightControls.AddBinding(new KeyBinding("Accelerate", Keys.OemPlus, ButtonEvent.Down, FeatherAccelerate));
            flightControls.AddBinding(new KeyBinding("Decelerate", Keys.OemMinus, ButtonEvent.Down, FeatherDecelerate));
            flightControls.AddBinding(new KeyBinding("Fire", Keys.Space, ButtonEvent.Pressed, FeatherFire));

            flightControls.AddBinding(new GamePadButtonBinding("Accelerate_gp", Buttons.RightShoulder, ButtonEvent.Down, FeatherAccelerate));
            flightControls.AddBinding(new GamePadButtonBinding("Decelerate_gp", Buttons.LeftShoulder, ButtonEvent.Down, FeatherDecelerate));
            //flightControls.AddBinding(new GamePadButtonBinding("Fire_gp", Buttons.RightTrigger, ButtonEvent.Down, FeatherFire)); // Fires too easily, using the analog method


            ic.AddMap(flightControls);

            AnalogMap flightControlsGamePad = new AnalogMap("flight_gp");

            flightControlsGamePad.AddBinding(new GamePadThumbStickBinding("Fly", ThumbStick.Left, AnalogEvent.Always, AnalogData.Absolute, FeatherMove));
            flightControlsGamePad.AddBinding(new GamePadTriggerBinding("Fire", Trigger.Right, AnalogEvent.Always, AnalogData.Absolute, FeatherFireAnalog));

            ic.AddMap(flightControlsGamePad);


            return(ic);
        }
        /// <summary>
        /// Adds all of the ToolbarButtons to the Root Control
        /// </summary>
        /// <param name="map">Collection of Buttons to add</param>
        /// <param name="root">Root Control</param>
        private void AttachButtonMap(ButtonMap map, CommandBar root)
        {
            if (root == null || map == null)
            {
                return;
            }

            foreach (var item in map)
            {
                AddToolbarItem(item, root);
            }
        }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextToolbar"/> class.
        /// </summary>
        public TextToolbar()
        {
            DefaultStyleKey = typeof(TextToolbar);

            CustomButtons       = new ButtonMap();
            ButtonModifications = new DefaultButtonModificationList();

            if (!InDesignMode)
            {
                KeyEventHandler = new KeyEventHandler(Editor_KeyDown);
            }
        }
Пример #11
0
 public void Merge(ButtonMap other)
 {
     foreach (var mappedButton in other.mappedButtons)
     {
         LogicalButton          logicalButton   = mappedButton.Key;
         List <IPhysicalButton> physicalButtons = mappedButton.Value;
         if (this.mappedButtons.ContainsKey(logicalButton))
         {
             this.mappedButtons[logicalButton].AddRange(physicalButtons);
         }
         else
         {
             this.mappedButtons[logicalButton] = physicalButtons;
         }
     }
 }
Пример #12
0
        public TeamSelectData(SelectScreen selectscreen, ButtonMap buttonmap, TextSection textsection, string prefix, bool moveoverempty, bool self = true)
        {
            if (selectscreen == null)
            {
                throw new ArgumentNullException(nameof(selectscreen));
            }
            if (buttonmap == null)
            {
                throw new ArgumentNullException(nameof(buttonmap));
            }
            if (textsection == null)
            {
                throw new ArgumentNullException(nameof(textsection));
            }
            if (prefix == null)
            {
                throw new ArgumentNullException(nameof(prefix));
            }

            m_self            = self;
            P1SelectData      = new SelectData(selectscreen, buttonmap, textsection, prefix, moveoverempty);
            P2SelectData      = new SelectData(selectscreen, buttonmap, textsection, prefix, moveoverempty);
            m_selectscreen    = selectscreen;
            ButtonMap         = buttonmap;
            m_elements        = new Collection(selectscreen.SpriteManager, selectscreen.AnimationManager, selectscreen.SoundManager, selectscreen.MenuSystem.FontMap);
            m_moveWrapping    = textsection.GetAttribute("teammenu.move.wrapping", true);
            m_position        = textsection.GetAttribute <Point>(prefix + ".teammenu.pos");
            m_itemLocation    = textsection.GetAttribute <Point>(prefix + ".teammenu.item.offset");
            m_itemSpacing     = textsection.GetAttribute <Point>(prefix + ".teammenu.item.spacing");
            m_itemFont        = textsection.GetAttribute <PrintData>(prefix + ".teammenu.item.font");
            m_itemActiveFont  = textsection.GetAttribute <PrintData>(prefix + ".teammenu.item.active.font");
            m_itemActive2Font = textsection.GetAttribute <PrintData>(prefix + ".teammenu.item.active2.font");
            m_spacing         = textsection.GetAttribute <Point>(prefix + ".teammenu.value.spacing");
            m_cursorSpriteId  = textsection.GetAttribute <SpriteId>(prefix + ".teammenu.item.cursor.anim");
            m_cursorOffset    = textsection.GetAttribute <Point>(prefix + ".teammenu.item.cursor.offset");

            m_elements.Build("selfTitle", textsection, prefix + ".teammenu.selftitle");
            m_elements.Build("enemytitle", textsection, prefix + ".teammenu.enemytitle");
            m_elements.Build("move", textsection, prefix + ".teammenu.move");
            m_elements.Build("value", textsection, prefix + ".teammenu.value");
            m_elements.Build("done", textsection, prefix + ".teammenu.done");
            m_elements.Build("value.icon", textsection, prefix + ".teammenu.value.icon");
            m_elements.Build("empty.icon", textsection, prefix + ".teammenu.value.empty.icon");
        }
Пример #13
0
        public void LoadFrom(XmlNode xn)
        {
            MappedType = (ControllerType)Enum.Parse(typeof(ControllerType), xn.Attributes["type"].Value, true);
            Source     = (SourceType)Enum.Parse(typeof(SourceType), xn.Attributes["source"].Value, true);
            UUID       = xn.Attributes["uuid"] != null?Guid.Parse(xn.Attributes["uuid"].Value) : Guid.NewGuid();

            if (Source == SourceType.RawInput)
            {
                VendorID   = int.Parse(xn.Attributes["vid"].Value, NumberStyles.HexNumber);
                ProductID  = int.Parse(xn.Attributes["pid"].Value, NumberStyles.HexNumber);
                ReportHash = uint.Parse(xn.Attributes["rpt_hash"].Value);
            }
            DeviceIndex = int.Parse(xn.Attributes["idx"].Value);

            foreach (XmlNode n in xn["buttons"].ChildNodes)
            {
                var btn = new ButtonMap();
                btn.LoadFrom(n);
                ButtonMaps.Add(btn);
            }

            foreach (XmlNode n in xn["axes"].ChildNodes)
            {
                var axis = new AxisMap();
                axis.LoadFrom(n);
                AxisMaps.Add(axis);
            }

            foreach (XmlNode n in xn["buttons_to_axis"].ChildNodes)
            {
                var button = new ButtonToAxisMap();
                button.LoadFrom(n);
                ButtonToAxisMaps.Add(button);
            }

            foreach (XmlNode n in xn["axis_to_buttons"].ChildNodes)
            {
                var axis = new AxisToButtonMap();
                axis.LoadFrom(n);
                AxisToButtonMaps.Add(axis);
            }
        }
Пример #14
0
        private void CreateMultiActionButtonMapList(int segments)
        {
            //try not to lose any macros already established. if more segments, then don't lose any macros. if less segments only trim from bottom of list
            if (segments < ButtonMap.Count)
            {
                for (var i = ButtonMap.Count; i > segments; i--)
                {
                    ButtonMap.RemoveAt(i - 1);
                }
            }
            else
            {
                for (var i = ButtonMap.Count + 1; i <= segments; i++)
                {
                    ButtonMap.Add(new HOTASButton()
                    {
                        MapId = i, MapName = $"Axis Button {i}", Type = HOTASButton.ButtonType.Button
                    });
                }
            }

            if (IsDirectional)
            {
                if (segments < ReverseButtonMap.Count)
                {
                    for (var i = ReverseButtonMap.Count; i > segments; i--)
                    {
                        ReverseButtonMap.RemoveAt(i - 1);
                    }
                }
                else
                {
                    for (var i = ReverseButtonMap.Count + 1; i <= segments; i++)
                    {
                        ReverseButtonMap.Add(new HOTASButton()
                        {
                            MapId = i, MapName = $"Reverse Axis Button {i}", Type = HOTASButton.ButtonType.Button
                        });
                    }
                }
            }
        }
Пример #15
0
        private HOTASButton GetMultiActionMap(int segment)
        {
            HOTASButton map;

            if (IsDirectional)
            {
                if (Direction == AxisDirection.Forward)
                {
                    map = ButtonMap.FirstOrDefault(m => m.MapId == segment);
                }
                else
                {
                    map = ReverseButtonMap.FirstOrDefault(m => m.MapId == segment);
                }
            }
            else
            {
                map = ButtonMap.FirstOrDefault(m => m.MapId == segment);
            }
            return(map);
        }
Пример #16
0
        private HOTASButton GetSingleActionMap()
        {
            HOTASButton map;

            if (IsDirectional)
            {
                if (Direction == AxisDirection.Forward)
                {
                    map = ButtonMap.FirstOrDefault(m => m.MapId == 1);
                }
                else
                {
                    map = ReverseButtonMap.FirstOrDefault(m => m.MapId == 1);
                }
            }
            else
            {
                map = ButtonMap.FirstOrDefault(m => m.MapId == 1);
            }
            return(map);
        }
Пример #17
0
        public override void Dispose()
        {
            ButtonMap.Clear();
            ButtonMap = null;

            SwitchMap.Clear();
            SwitchMap = null;

            TextMap.Clear();
            TextMap = null;

            Desktop = null;

            _Compiled = null;
            _Buffer   = null;

            _TypeID  = -1;
            _Handler = null;

            base.Dispose();
        }
Пример #18
0
    public void OpenLoadMap()
    {
        alphaLoadMap.ResetAtBeginning();
        alphaLoadMap.PlayForward();
        alphaLoadMap.AlphaGroup.interactable   = true;
        alphaLoadMap.AlphaGroup.blocksRaycasts = true;

        ButtonMap[] bMaps = listMaps.GetComponentsInChildren <ButtonMap>();
        for (int i = 0; i < bMaps.Length; i++)
        {
            Destroy(bMaps[i].gameObject);
        }


        for (int i = 0; i < sessionData.Maps.Length; i++)
        {
            string url_Map  = sessionData.GM_Url + "Maps/" + sessionData.Maps[i];
            string fileName = sessionData.Maps[i].Split('.')[0];

            ButtonMap bMap = Instantiate(bMapName, listMaps);
            bMap.mapName          = fileName;
            bMap.filePath         = url_Map;
            bMap.filePath         = url_Map;
            bMap.textMapName.text = bMap.mapName;
        }

        /*
         * string pathFolder = Path.Combine(Application.persistentDataPath, "Saves");
         * string[] files = Directory.GetFiles(pathFolder);
         * for (int i = 0; i < files.Length; i++)
         * {
         *  ButtonMap bMap = Instantiate(bMapName, listMaps);
         *  bMap.mapName = Path.GetFileNameWithoutExtension(files[i]);
         *  bMap.mapPath = files[i];
         *  bMap.textMapName.text = bMap.mapName;
         * }
         */
    }
Пример #19
0
        public void CalculateSegmentRange(int segments)
        {
            RemoveSegmentBoundaryHandlers();

            Segments.Clear();
            if (segments == 0)
            {
                ButtonMap.Clear();
                ReverseButtonMap.Clear();
                return;
            }

            if (!IsDirectional)
            {
                ReverseButtonMap.Clear();
            }

            CreateSegments(segments);

            CreateActionMapList();

            AddSegmentBoundaryHandlers();
        }
Пример #20
0
 public static Button GetButtonFromMoreName(string buttonName)
 {
     return(ButtonMap.ContainsKey(buttonName) ? ButtonMap[buttonName] : null);
 }
Пример #21
0
    public void HandleWaitoringInput()
    {
        buttonMap = new ButtonMap();

#if UNITY_ANDROID
        foreach (var kvp in keyPresses)
        {
            string   button   = kvp.Key;
            KeyPress keyPress = kvp.Value;

            switch (keyPress)
            {
            case KeyPress.Down:
                buttonMap.downButtons.Add(button.ToUpper());
                break;

            case KeyPress.Pressed:
                buttonMap.pressedButtons.Add(button.ToUpper());
                break;

            case KeyPress.Up:
                buttonMap.upButtons.Add(button.ToUpper());
                break;
            }

            //OnKeyAction?.Invoke(button.ToUpper(), keyPress);
        }
#else
        if (Input.GetKeyDown(pickUpItemL1))
        {
            buttonMap.downButtons.Add("L1");
            //OnKeyAction?.Invoke("L1", KeyPress.Down);
        }
        else if (Input.GetKey(pickUpItemL1))
        {
            buttonMap.pressedButtons.Add("L1");
            //OnKeyAction?.Invoke("L1", KeyPress.Pressed);
        }
        else if (Input.GetKeyUp(pickUpItemL1))
        {
            buttonMap.upButtons.Add("L1");
            //OnKeyAction?.Invoke("L1", KeyPress.Up);
        }

        if (Input.GetKeyDown(pickUpItemL2))
        {
            buttonMap.downButtons.Add("L2");
            //OnKeyAction?.Invoke("L2", KeyPress.Down);
        }
        else if (Input.GetKey(pickUpItemL2))
        {
            buttonMap.pressedButtons.Add("L2");
            //OnKeyAction?.Invoke("L2", KeyPress.Pressed);
        }
        else if (Input.GetKeyUp(pickUpItemL2))
        {
            buttonMap.upButtons.Add("L2");
            //OnKeyAction?.Invoke("L2", KeyPress.Up);
        }

        if (Input.GetKeyDown(pickUpItemL3))
        {
            buttonMap.downButtons.Add("L3");
            //OnKeyAction?.Invoke("L3", KeyPress.Down);
        }
        else if (Input.GetKey(pickUpItemL3))
        {
            buttonMap.pressedButtons.Add("L3");
            //OnKeyAction?.Invoke("L3", KeyPress.Pressed);
        }
        else if (Input.GetKeyUp(pickUpItemL3))
        {
            buttonMap.upButtons.Add("L3");
            //OnKeyAction?.Invoke("L3", KeyPress.Up);
        }

        if (Input.GetKeyDown(pickUpItemL4))
        {
            buttonMap.downButtons.Add("L4");
            //OnKeyAction?.Invoke("L4", KeyPress.Down);
        }
        else if (Input.GetKey(pickUpItemL4))
        {
            buttonMap.pressedButtons.Add("L4");
            //OnKeyAction?.Invoke("L4", KeyPress.Pressed);
        }
        else if (Input.GetKeyUp(pickUpItemL4))
        {
            buttonMap.upButtons.Add("L4");
            //OnKeyAction?.Invoke("L4", KeyPress.Up);
        }

        if (Input.GetKeyDown(pickUpItemR1))
        {
            buttonMap.downButtons.Add("R1");
            //OnKeyAction?.Invoke("R1", KeyPress.Down);
        }
        else if (Input.GetKey(pickUpItemR1))
        {
            buttonMap.pressedButtons.Add("R1");
            //OnKeyAction?.Invoke("R1", KeyPress.Pressed);
        }
        else if (Input.GetKeyUp(pickUpItemR1))
        {
            buttonMap.upButtons.Add("R1");
            //OnKeyAction?.Invoke("R1", KeyPress.Up);
        }

        if (Input.GetKeyDown(pickUpItemR2))
        {
            buttonMap.downButtons.Add("R2");
            //OnKeyAction?.Invoke("R2", KeyPress.Down);
        }
        else if (Input.GetKey(pickUpItemR2))
        {
            buttonMap.pressedButtons.Add("R2");
            //OnKeyAction?.Invoke("R2", KeyPress.Pressed);
        }
        else if (Input.GetKeyUp(pickUpItemR2))
        {
            buttonMap.upButtons.Add("R2");
            //OnKeyAction?.Invoke("R2", KeyPress.Up);
        }

        if (Input.GetKeyDown(pickUpItemR3))
        {
            buttonMap.downButtons.Add("R3");
            //OnKeyAction?.Invoke("R3", KeyPress.Down);
        }
        else if (Input.GetKey(pickUpItemR3))
        {
            buttonMap.pressedButtons.Add("R3");
            //OnKeyAction?.Invoke("R3", KeyPress.Pressed);
        }
        else if (Input.GetKeyUp(pickUpItemR3))
        {
            buttonMap.upButtons.Add("R3");
            //OnKeyAction?.Invoke("R3", KeyPress.Up);
        }

        if (Input.GetKeyDown(pickUpItemR4))
        {
            buttonMap.downButtons.Add("R4");
            //OnKeyAction?.Invoke("R4", KeyPress.Down);
        }
        else if (Input.GetKey(pickUpItemR4))
        {
            buttonMap.pressedButtons.Add("R4");
            //OnKeyAction?.Invoke("R4", KeyPress.Pressed);
        }
        else if (Input.GetKeyUp(pickUpItemR4))
        {
            buttonMap.upButtons.Add("R4");
            //OnKeyAction?.Invoke("R4", KeyPress.Up);
        }

        if (Input.GetKeyDown(leftHandPickup))
        {
            buttonMap.downButtons.Add("Q");
            //OnKeyAction?.Invoke("Q", KeyPress.Down);
        }
        else if (Input.GetKey(leftHandPickup))
        {
            buttonMap.pressedButtons.Add("Q");
            //OnKeyAction?.Invoke("Q", KeyPress.Pressed);
        }
        else if (Input.GetKeyUp(leftHandPickup))
        {
            buttonMap.upButtons.Add("Q");
            //OnKeyAction?.Invoke("Q", KeyPress.Up);
        }

        if (Input.GetKeyDown(rightHandPickup))
        {
            buttonMap.downButtons.Add("E");
            //OnKeyAction?.Invoke("E", KeyPress.Down);
        }
        else if (Input.GetKey(rightHandPickup))
        {
            buttonMap.pressedButtons.Add("E");
            //OnKeyAction?.Invoke("E", KeyPress.Pressed);
        }
        else if (Input.GetKeyUp(rightHandPickup))
        {
            buttonMap.upButtons.Add("E");
            //OnKeyAction?.Invoke("E", KeyPress.Up);
        }
#endif

        OnKeyAction?.Invoke(buttonMap);

        List <string> presses = new List <string>();
        List <string> nones   = new List <string>();

        foreach (var kvp in keyPresses)
        {
            string   button   = kvp.Key;
            KeyPress keyPress = kvp.Value;

            switch (keyPress)
            {
            case KeyPress.Down:
                presses.Add(button);
                break;

            case KeyPress.Up:
                nones.Add(button);
                break;
            }
        }

        foreach (var p in presses)
        {
            keyPresses[p] = KeyPress.Pressed;
        }

        foreach (var p in nones)
        {
            keyPresses.Remove(p);
        }
    }
Пример #22
0
        public DesktopGumpEntry(DesktopGump dt, Gump gump, bool focus)
        {
            Desktop = dt;

            _TypeID  = gump.TypeID;
            _Handler = gump.OnResponse;

            if (focus)
            {
                ButtonMap = new Dictionary <int, int>();
                SwitchMap = new Dictionary <int, int>();
                TextMap   = new Dictionary <int, int>();
            }

            var entries = gump.Entries.Not(e => e is GumpModal).ToList();

            var esc = false;

            foreach (var e in entries)
            {
                bool pos;
                int  x, y;

                if (e.TryGetPosition(out x, out y))
                {
                    pos = true;
                    e.TrySetPosition(gump.X + x, gump.Y + y);
                }
                else
                {
                    pos = false;
                }

                e.Parent = Desktop;

                try
                {
                    if (e is GumpButton)
                    {
                        var b = (GumpButton)e;

                        if (focus && b.Type == GumpButtonType.Reply)
                        {
                            ButtonMap[Desktop.NewButtonID()] = b.ButtonID;

                            b.ButtonID = ButtonMap.GetKey(b.ButtonID);
                            _Compiled += b.Compile();
                            b.ButtonID = ButtonMap[b.ButtonID];
                        }
                        else
                        {
                            _Compiled += new GumpImage(b.X, b.Y, b.NormalID)
                            {
                                Parent = Desktop
                            }.Compile();
                        }
                    }
                    else if (e is GumpImageTileButton)
                    {
                        var b = (GumpImageTileButton)e;

                        if (focus && b.Type == GumpButtonType.Reply)
                        {
                            ButtonMap[Desktop.NewButtonID()] = b.ButtonID;

                            b.ButtonID = ButtonMap.GetKey(b.ButtonID);
                            _Compiled += b.Compile();
                            b.ButtonID = ButtonMap[b.ButtonID];
                        }
                        else
                        {
                            _Compiled += new GumpImage(b.X, b.Y, b.NormalID)
                            {
                                Parent = Desktop
                            }.Compile();
                        }
                    }
                    else if (e is GumpCheck)
                    {
                        var c = (GumpCheck)e;

                        if (focus)
                        {
                            SwitchMap[Desktop.NewSwitchID()] = c.SwitchID;

                            c.SwitchID = SwitchMap.GetKey(c.SwitchID);
                            _Compiled += c.Compile();
                            c.SwitchID = SwitchMap[c.SwitchID];
                        }
                        else
                        {
                            _Compiled += new GumpImage(c.X, c.Y, c.InitialState ? c.ActiveID : c.InactiveID)
                            {
                                Parent = Desktop
                            }.Compile();
                        }
                    }
                    else if (e is GumpRadio)
                    {
                        var r = (GumpRadio)e;

                        if (focus)
                        {
                            SwitchMap[Desktop.NewSwitchID()] = r.SwitchID;

                            r.SwitchID = SwitchMap.GetKey(r.SwitchID);
                            _Compiled += r.Compile();
                            r.SwitchID = SwitchMap[r.SwitchID];
                        }
                        else
                        {
                            _Compiled += new GumpImage(r.X, r.Y, r.InitialState ? r.ActiveID : r.InactiveID)
                            {
                                Parent = Desktop
                            }.Compile();
                        }
                    }
                    else if (e is GumpTextEntry)
                    {
                        var t = (GumpTextEntry)e;

                        if (focus)
                        {
                            TextMap[Desktop.NewTextEntryID()] = t.EntryID;

                            t.EntryID  = TextMap.GetKey(t.EntryID);
                            _Compiled += t.Compile();
                            t.EntryID  = TextMap[t.EntryID];
                        }
                        else
                        {
                            _Compiled += new GumpLabelCropped(t.X, t.Y, t.Width, t.Height, t.Hue, t.InitialText)
                            {
                                Parent = Desktop
                            }.Compile();
                        }
                    }
                    else if (e is GumpTextEntryLimited)
                    {
                        var t = (GumpTextEntryLimited)e;

                        if (focus)
                        {
                            TextMap[Desktop.NewTextEntryID()] = t.EntryID;

                            t.EntryID  = TextMap.GetKey(t.EntryID);
                            t.Parent   = Desktop;
                            _Compiled += t.Compile();
                            t.EntryID  = TextMap[t.EntryID];
                        }
                        else
                        {
                            _Compiled += new GumpLabelCropped(t.X, t.Y, t.Width, t.Height, t.Hue, t.InitialText)
                            {
                                Parent = Desktop
                            }.Compile();
                        }
                    }
                    else if (e is GumpPage)
                    {
                        var p = (GumpPage)e;

                        if (p.Page > 0)
                        {
                            esc = true;
                        }
                    }
                    else
                    {
                        _Compiled += e.Compile();
                    }
                }
                catch
                { }

                e.Parent = gump;

                if (pos)
                {
                    e.TrySetPosition(x, y);
                }

                if (esc)
                {
                    break;
                }
            }

            entries.Free(true);

            if (String.IsNullOrWhiteSpace(_Compiled))
            {
                _Compiled = "{{ gumptooltip -1 }}";
            }

            _Buffer = Gump.StringToBuffer(_Compiled);
        }