コード例 #1
0
ファイル: Input.cs プロジェクト: kaikue/Oceania-MG
        private void SetUpControlMappings()
        {
            controlMappings = new Dictionary <Controls, HashSet <ControlType> >();

            foreach (Controls control in Enum.GetValues(typeof(Controls)))
            {
                controlMappings[control] = new HashSet <ControlType>();
            }

            string[] lines = File.ReadAllLines("Content/Config/controls.txt");
            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                if (line.Length == 0 || line.StartsWith("//"))
                {
                    continue;
                }

                //split by : first, then potentially &, then .

                string[] split = line.Split(':');
                if (split.Length != 2)
                {
                    throw new FormatException("controls.txt line " + (i + 1) + " must be of format Action:Controller.Button[&Controller.Button]");
                }

                string actionStr = split[0].Trim(' ');
                bool   success   = Enum.TryParse(actionStr, out Controls control);
                if (!success)
                {
                    throw new FormatException("controls.txt line " + (i + 1) + ": Invalid action " + actionStr);
                }

                string[] controls = split[1].Split('&');

                ControlType controlType = ParseControl(controls[0], i + 1);
                //in case of more than one control, create a multi-control
                for (int j = 1; j < controls.Length; j++)
                {
                    ControlType nextControl = ParseControl(controls[j], i + 1);
                    controlType = new MultiControl(controlType, nextControl);
                }

                AddControl(control, controlType);
            }
        }
コード例 #2
0
 private void CreateCustomControls(AssaultWing game)
 {
     var escapeControl = new MultiControl
     {
         new KeyboardKey(Keys.Escape),
         new GamePadButton(0, GamePadButtonType.Start),
         new GamePadButton(0, GamePadButtonType.Back),
     };
     var screenShotControl = new KeyboardKey(Keys.PrintScreen);
     game.CustomControls.Add(Tuple.Create<Control, Action>(escapeControl, Click_EscapeControl));
     game.CustomControls.Add(Tuple.Create<Control, Action>(screenShotControl, Game.TakeScreenShot));
     game.CustomControls.Add(Tuple.Create<Control, Action>(MenuEngine.Controls.Back, Click_MenuBackControl));
 }
コード例 #3
0
ファイル: MenuControls.cs プロジェクト: vvnurmi/assaultwing
 public MenuControls()
 {
     PlayerDirs = new[]
     {
         new Directions(
             up: new MultiControl
             {
                 new KeyboardKey(Keys.Up),
                 new GamePadStickDirection(0, GamePadStickType.DPad, GamePadStickDirectionType.Up),
                 new GamePadStickDirection(0, GamePadStickType.LThumb, GamePadStickDirectionType.Up),
                 new GamePadStickDirection(0, GamePadStickType.RThumb, GamePadStickDirectionType.Up),
             },
             down: new MultiControl
             {
                 new KeyboardKey(Keys.Down),
                 new GamePadStickDirection(0, GamePadStickType.DPad, GamePadStickDirectionType.Down),
                 new GamePadStickDirection(0, GamePadStickType.LThumb, GamePadStickDirectionType.Down),
                 new GamePadStickDirection(0, GamePadStickType.RThumb, GamePadStickDirectionType.Down),
             },
             left: new MultiControl
             {
                 new KeyboardKey(Keys.Left),
                 new GamePadStickDirection(0, GamePadStickType.DPad, GamePadStickDirectionType.Left),
                 new GamePadStickDirection(0, GamePadStickType.LThumb, GamePadStickDirectionType.Left),
                 new GamePadStickDirection(0, GamePadStickType.RThumb, GamePadStickDirectionType.Left),
             },
             right: new MultiControl
             {
                 new KeyboardKey(Keys.Right),
                 new GamePadStickDirection(0, GamePadStickType.DPad, GamePadStickDirectionType.Right),
                 new GamePadStickDirection(0, GamePadStickType.LThumb, GamePadStickDirectionType.Right),
                 new GamePadStickDirection(0, GamePadStickType.RThumb, GamePadStickDirectionType.Right),
             }),
         new Directions(
             up: new MultiControl
             {
                 new KeyboardKey(Keys.W),
                 new GamePadStickDirection(1, GamePadStickType.DPad, GamePadStickDirectionType.Up),
                 new GamePadStickDirection(1, GamePadStickType.LThumb, GamePadStickDirectionType.Up),
                 new GamePadStickDirection(1, GamePadStickType.RThumb, GamePadStickDirectionType.Up),
             },
             down: new MultiControl
             {
                 new KeyboardKey(Keys.S),
                 new GamePadStickDirection(1, GamePadStickType.DPad, GamePadStickDirectionType.Down),
                 new GamePadStickDirection(1, GamePadStickType.LThumb, GamePadStickDirectionType.Down),
                 new GamePadStickDirection(1, GamePadStickType.RThumb, GamePadStickDirectionType.Down),
             },
             left: new MultiControl
             {
                 new KeyboardKey(Keys.A),
                 new GamePadStickDirection(1, GamePadStickType.DPad, GamePadStickDirectionType.Left),
                 new GamePadStickDirection(1, GamePadStickType.LThumb, GamePadStickDirectionType.Left),
                 new GamePadStickDirection(1, GamePadStickType.RThumb, GamePadStickDirectionType.Left),
             },
             right: new MultiControl
             {
                 new KeyboardKey(Keys.D),
                 new GamePadStickDirection(1, GamePadStickType.DPad, GamePadStickDirectionType.Right),
                 new GamePadStickDirection(1, GamePadStickType.LThumb, GamePadStickDirectionType.Right),
                 new GamePadStickDirection(1, GamePadStickType.RThumb, GamePadStickDirectionType.Right),
             }),
     };
     Activate = new MultiControl
     {
         new KeyboardKey(Keys.Enter),
         new GamePadButton(0, GamePadButtonType.Start),
         new GamePadButton(0, GamePadButtonType.A),
     };
     Back = new MultiControl
     {
         new KeyboardKey(Keys.Escape),
         new GamePadButton(0, GamePadButtonType.Back),
         new GamePadButton(0, GamePadButtonType.B),
     };
     Tab = new MultiControl
     {
         new KeyboardKey(Keys.Tab),
         new GamePadButton(0, GamePadButtonType.RShoulder),
     };
     TabBack = new MultiControl
     {
         new GamePadButton(0, GamePadButtonType.LShoulder),
     };
     StartGame = new MultiControl
     {
         new KeyboardKey(Keys.F10),
         new GamePadButton(0, GamePadButtonType.Start),
     };
 }
コード例 #4
0
 /// <summary>
 /// 对多条指令的添加设置
 /// </summary>
 private void multiCommands()
 {
     //界面的控件的更改和添加(atCommand);
     tboxMCLCount.ReadOnly = true;
     multiControl          = new MultiControl(int.Parse(tboxMCLCount.Text), panel1, portControl);
 }