//──────────────────────────────────────── /// <summary> /// コンストラクター。 /// </summary> public Usercontrol_Form1() { InitializeComponent(); this.mainloop = new Gamepadmainloop_SampleImpl(this); this.mainloop.Init(); }
//──────────────────────────────────────── /// <summary> /// ゲームコントローラーのキー入力を監視。 /// </summary> public void Perform(Gamepadmainloop mainloop) { // 接続ゲームコントローラー数。 this.Uc_Form1.UsercontrolPage1.PctxtConnectedDevices.Text = mainloop.Input.Dictionary_GameController.Count.ToString(); // 抜けたコントローラーのプレイヤー番号のリスト。 List<int> listN_Lost = new List<int>(); foreach (KeyValuePair<int, Memory_GameController> pair in mainloop.Input.Dictionary_GameController) { int nPlayer = pair.Key; Memory_GameController gc = pair.Value; Device gameController = gc.GameController; // ゲームコントローラーの、ボタンの押されている状況を取得します。 // その他に、マウス、キーボードも取得できるかも。 try { // キー読取 this.keyListener_MainImpl.Perform(gc); JoystickState state = gameController.CurrentJoystickState; StringBuilder sb = new StringBuilder(); int nX = state.X; int nY = state.Y; // 1スタートで+1、カーソルキーが4つで+4。 int nMax1 = 4+gc.KeyCnf.NCount_MaxButton+1; for (int nBtnIndex = 4+1; nBtnIndex < nMax1; nBtnIndex++) { if (gc.ButtonsFrame[nBtnIndex] == 1) { sb.Append("["); sb.Append(nBtnIndex-4-1); sb.Append("]"); } } if (5000 == nX) { // // [→] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Right] == 1) { sb.Append("[→]"); } } else if (-5000 == nX) { // // [←] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Left] == 1) { sb.Append("[←]"); } } if (5000 == nY) { // // [↓] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Down] == 1) { sb.Append("[↓]"); } } else if (-5000 == nY) { // // [↑] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Up] == 1) { sb.Append("[↑]"); } } // // 表示 // string sTxt = sb.ToString(); int nMaxItems = 23;//リストボックスに表示できるアイテム数。 if (nPlayer < this.Uc_Form1.UsercontrolPage1.Usercontrol_VwdTestArray.Length) { Usercontrol_VwdTest ucController = this.Uc_Form1.UsercontrolPage1.Usercontrol_VwdTestArray[nPlayer]; if (null != ucController) { // フォーム配置完了時 // // [↑] // { int nKeyHard = (int)EnumGamepadkeyIx.Up; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { // todo:変更されているときだけ更新したい。 pclblB.ForeColor = Color.LightGray; pclblB.Text = "↑"; } } // // [→] // { int nKeyHard = (int)EnumGamepadkeyIx.Right; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = "→"; } } // [↓] { int nKeyHard = (int)EnumGamepadkeyIx.Down; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = "↓"; } } // [←] { int nKeyHard = (int)EnumGamepadkeyIx.Left; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = "←"; } } // [0] { int nBtn = 0; int nKeyHard = (int)EnumGamepadkeyIx.B0; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [1] { int nBtn = 1; int nKeyHard = (int)EnumGamepadkeyIx.B1; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [2] { int nBtn = 2; int nKeyHard = (int)EnumGamepadkeyIx.B2; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [3] { int nBtn = 3; int nKeyHard = (int)EnumGamepadkeyIx.B3; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [4] { int nBtn = 4; int nKeyHard = (int)EnumGamepadkeyIx.B4; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [5] { int nBtn = 5; int nKeyHard = (int)EnumGamepadkeyIx.B5; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [6] { int nBtn = 6; int nKeyHard = (int)EnumGamepadkeyIx.B6; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [7] { int nBtn = 7; int nKeyHard = (int)EnumGamepadkeyIx.B7; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } if ("" != sTxt) { ucController.Pclst.Items.Add(sTxt); if (nMaxItems < ucController.Pclst.Items.Count) { ucController.Pclst.Items.RemoveAt(0); } } } } } catch (NotAcquiredException) { // ゲームコントローラーを獲得していない。 } catch (InputLostException) { // ゲームコントローラーが抜けたとき。 // 抜けたコントローラーのプレイヤー番号を記憶 listN_Lost.Add(nPlayer); } nPlayer++; } foreach (int nPlayer in listN_Lost) { // 削除 mainloop.Input.Dictionary_GameController.Remove(nPlayer); } this.Uc_Form1.UsercontrolPage1.PctxtTimer.Text = this.Uc_Form1.Mainloop.NTimer.ToString(); }
//──────────────────────────────────────── #endregion #region アクション //──────────────────────────────────────── /// <summary> /// ゲームコントローラーの接続を監視。 /// </summary> public void ListenController(Gamepadmainloop mainloopPrm) { if (!(mainloopPrm is Gamepadmainloop_SampleImpl)) { throw new Exception("未対応のクラスが引数に渡されました。"); } Gamepadmainloop_SampleImpl mainloop = (Gamepadmainloop_SampleImpl)mainloopPrm; //ゲームコントローラーの接続を監視。毎フレーム監視していては重いと思うので、たまに。 if (this.ListenFrame < 1) { goto gt_play; } if (62 <= this.ListenFrame) { this.ListenFrame = -1; } this.ListenFrame++; return; // // // // gt_play: // // 接続されている「ゲーム用コントローラー」のリストを取得します。 DeviceList dl = Manager.GetDevices( DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly ); List <DeviceInstance> deviceInstanceList = new List <DeviceInstance>(); foreach (DeviceInstance di in dl) { deviceInstanceList.Add(di); } if (this.Dictionary_GameController.Count != deviceInstanceList.Count) { // // 設定し直し。 // TODO: 抜けてないプレイヤーの接続は、そのまま保持しておきたい。 // this.Dictionary_GameController.Clear(); int playerNumber = 1; foreach (DeviceInstance di in deviceInstanceList) { Device gameControl = new Device(di.InstanceGuid); Memory_GameController gc = new Memory_GameController(); gc.GameController = gameControl; this.Dictionary_GameController.Add(playerNumber, gc); this.ReadKeyconfig(mainloop, playerNumber, gc); // 十字キーまたはレバーのX,Yの倒れ具合を、-5000,0,5000 で表現するように設定。 foreach (DeviceObjectInstance doi in gameControl.Objects) { if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0) { gameControl.Properties.SetRange( ParameterHow.ById, doi.ObjectId, new InputRange(-5000, 5000) ); } } // 倒れ方を相対的ではなく、絶対的に判定。 gameControl.Properties.AxisModeAbsolute = true; // 「協調レベル」を設定。キーボードやゲームパッドの取り合い、ウィンドウが前景のとき背景のとき等をここで設定。 gameControl.SetCooperativeLevel( mainloop.Form1, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background ); // キャプチャー(入力の補足)を獲得する。 gameControl.Acquire(); playerNumber++; } } }
//──────────────────────────────────────── private void ReadKeyconfig(Gamepadmainloop mainloop, int nPlayerPrm, Memory_GameController gc) { Log_Method pg_Method = new Log_MethodImpl(0); Log_Reports log_Reports_ThisMethod = new Log_ReportsImpl(pg_Method); pg_Method.BeginMethod(Info_Operating.Name_Library, this, "ReadKeyConfig", log_Reports_ThisMethod); // テーブルを、上から下に読んでいく。 // 列の並び順は NO ID Expl PLAYER BEFORE AFTER if (null != this.Table_Humaninput_Keyconfig)//テーブルの読取が成功していること。 { DataTable dataTable = this.Table_Humaninput_Keyconfig.DataTable; foreach (DataRow dataRow in dataTable.Rows) { int nPlayer; Int_HumaninputImpl.TryParse( dataRow.ItemArray[3], out nPlayer, EnumOperationIfErrorvalue.Spaces_To_Alt_Value, 0, log_Reports_ThisMethod ); if (nPlayerPrm == nPlayer) { string sBefore; string sAfter; String_HumaninputImpl.TryParse( dataRow.ItemArray[4], out sBefore, "", "", pg_Method, log_Reports_ThisMethod ); String_HumaninputImpl.TryParse( dataRow.ItemArray[5], out sAfter, "", "", pg_Method, log_Reports_ThisMethod ); EnumGamepadkeyIx o_Before; EnumGamepadkeyBit o_After; switch (sBefore) { case "Up": o_Before = EnumGamepadkeyIx.Up; break; case "Right": o_Before = EnumGamepadkeyIx.Right; break; case "Down": o_Before = EnumGamepadkeyIx.Down; break; case "Left": o_Before = EnumGamepadkeyIx.Left; break; case "1": o_Before = EnumGamepadkeyIx.B0; break; case "2": o_Before = EnumGamepadkeyIx.B1; break; case "3": o_Before = EnumGamepadkeyIx.B2; break; case "4": o_Before = EnumGamepadkeyIx.B3; break; case "5": o_Before = EnumGamepadkeyIx.B4; break; case "6": o_Before = EnumGamepadkeyIx.B5; break; case "7": o_Before = EnumGamepadkeyIx.B6; break; case "8": o_Before = EnumGamepadkeyIx.B7; break; default: o_Before = EnumGamepadkeyIx.Up; break; } switch (sAfter) { case "Up": o_After = EnumGamepadkeyBit.Up; break; case "Right": o_After = EnumGamepadkeyBit.Right; break; case "Down": o_After = EnumGamepadkeyBit.Down; break; case "Left": o_After = EnumGamepadkeyBit.Left; break; case "A": o_After = EnumGamepadkeyBit.A; break; case "B": o_After = EnumGamepadkeyBit.B; break; case "X": o_After = EnumGamepadkeyBit.X; break; case "Y": o_After = EnumGamepadkeyBit.Y; break; case "L": o_After = EnumGamepadkeyBit.L; break; case "R": o_After = EnumGamepadkeyBit.R; break; case "Select": o_After = EnumGamepadkeyBit.Select; break; case "Start": o_After = EnumGamepadkeyBit.Start; break; default: o_After = EnumGamepadkeyBit.Up; break; } gc.KeyCnf.KeyconfigArray[(int)o_Before] = o_After; } } } // // pg_Method.EndMethod(log_Reports_ThisMethod); log_Reports_ThisMethod.EndLogging(pg_Method); }
//──────────────────────────────────────── public void Perform(Gamepadmainloop mainloop) { // 接続ゲームコントローラー数。 this.Uc_Form1.UsercontrolPage1.PctxtConnectedDevices.Text = mainloop.Input.Dictionary_GameController.Count.ToString(); // 抜けたコントローラーのプレイヤー番号のリスト。 List<int> nList_Lost = new List<int>(); // プレイヤー毎に。 foreach (KeyValuePair<int, Memory_GameController> pair in mainloop.Input.Dictionary_GameController) { int nPlayer = pair.Key; Memory_GameController gc = pair.Value; Device gameController = gc.GameController; Usercontrol_VwdKeycnf ucCtrlCnf = this.Uc_Form1.UsercontrolPage2.Usercontrol_VwdKeycnfArray[nPlayer]; // ゲームコントローラーの、ボタンの押されている状況を取得します。 // その他に、マウス、キーボードも取得できるかも。 // ボタンが押されたかどうか。 bool bBtnPushed = false; try { // キー読取 this.keyListener_MainImpl.Perform(gc); JoystickState state = gameController.CurrentJoystickState; int nX = state.X; int nY = state.Y; // 押されたキー EnumGamepadkeyIx enumPushedKey = EnumGamepadkeyIx.None;//ダミー初期値。 // // [1] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B0] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B0; goto gt_buttonEnd;//1個だけ判定。 } // // [2] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B1] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B1; goto gt_buttonEnd;//1個だけ判定。 } // // [3] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B2] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B2; goto gt_buttonEnd;//1個だけ判定。 } // // [4] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B3] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B3; goto gt_buttonEnd;//1個だけ判定。 } // // [5] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B4] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B4; goto gt_buttonEnd;//1個だけ判定。 } // // [6] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B5] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B5; goto gt_buttonEnd;//1個だけ判定。 } // // [7] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B6] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B6; goto gt_buttonEnd;//1個だけ判定。 } // // [8] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B7] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B7; goto gt_buttonEnd;//1個だけ判定。 } if (5000 == nX) { // // [→] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Right] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.Right; goto gt_buttonEnd;//1個だけ判定。 } } else if (-5000 == nX) { // // [←] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Left] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.Left; goto gt_buttonEnd;//1個だけ判定。 } } if (5000 == nY) { // // [↓] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Down] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.Down; goto gt_buttonEnd;//1個だけ判定。 } } else if (-5000 == nY) { // // [↑] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Up] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.Up; goto gt_buttonEnd;//1個だけ判定。 } } // // // // gt_buttonEnd: // // 押されたキーの文字列化 // string sPushedKey; switch (enumPushedKey) { case EnumGamepadkeyIx.None: goto gt_playerEnd; case EnumGamepadkeyIx.Up: sPushedKey = "↑"; break; case EnumGamepadkeyIx.Right: sPushedKey = "→"; break; case EnumGamepadkeyIx.Down: sPushedKey = "↓"; break; case EnumGamepadkeyIx.Left: sPushedKey = "←"; break; case EnumGamepadkeyIx.B0: sPushedKey = "1"; break; case EnumGamepadkeyIx.B1: sPushedKey = "2"; break; case EnumGamepadkeyIx.B2: sPushedKey = "3"; break; case EnumGamepadkeyIx.B3: sPushedKey = "4"; break; case EnumGamepadkeyIx.B4: sPushedKey = "5"; break; case EnumGamepadkeyIx.B5: sPushedKey = "6"; break; case EnumGamepadkeyIx.B6: sPushedKey = "7"; break; case EnumGamepadkeyIx.B7: sPushedKey = "8"; break; default: sPushedKey = "エラー"; break; } // // 設定 // gc.KeyCnf.KeyconfigArray[(int)enumPushedKey] = gc.EnumCurKeyForCnf; // // 表示する場所。 if( bBtnPushed) { TextBox pctxtCur; TextBox pctxtNext; switch (gc.EnumCurKeyForCnf) { case EnumGamepadkeyBit.Up: // [↑] pctxtCur = ucCtrlCnf.PctxtUp; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtRight; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Right; break; case EnumGamepadkeyBit.Right: // [→] pctxtCur = ucCtrlCnf.PctxtRight; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtDown; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Down; break; case EnumGamepadkeyBit.Down: // [↓] pctxtCur = ucCtrlCnf.PctxtDown; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtLeft; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Left; break; case EnumGamepadkeyBit.Left: // [←] pctxtCur = ucCtrlCnf.PctxtLeft; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtA; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.A; break; case EnumGamepadkeyBit.A: // [A] pctxtCur = ucCtrlCnf.PctxtA; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtB; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.B; break; case EnumGamepadkeyBit.B: // [B] pctxtCur = ucCtrlCnf.PctxtB; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtX; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.X; break; case EnumGamepadkeyBit.X: // [X] pctxtCur = ucCtrlCnf.PctxtX; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtY; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Y; break; case EnumGamepadkeyBit.Y: // [Y] pctxtCur = ucCtrlCnf.PctxtY; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtL; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.L; break; case EnumGamepadkeyBit.L: // [L] pctxtCur = ucCtrlCnf.PctxtL; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtR; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.R; break; case EnumGamepadkeyBit.R: // [R] pctxtCur = ucCtrlCnf.PctxtR; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtSelect; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Select; break; case EnumGamepadkeyBit.Select: // [Select] pctxtCur = ucCtrlCnf.PctxtSelect; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtStart; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Start; break; case EnumGamepadkeyBit.Start: // [Start] pctxtCur = ucCtrlCnf.PctxtStart; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtUp; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Up; break; } } } catch (NotAcquiredException) { // ゲームコントローラーを獲得していない。 } catch (InputLostException) { // ゲームコントローラーが抜けたとき。 // 抜けたコントローラーのプレイヤー番号を記憶 nList_Lost.Add(nPlayer); } // プレイヤー1人分終了 gt_playerEnd: nPlayer++; } foreach (int playerNumber in nList_Lost) { // 削除 mainloop.Input.Dictionary_GameController.Remove(playerNumber); } this.Uc_Form1.UsercontrolPage1.PctxtTimer.Text = this.Uc_Form1.Mainloop.NTimer.ToString(); }
//──────────────────────────────────────── #endregion #region アクション //──────────────────────────────────────── /// <summary> /// ゲームコントローラーのキー入力を監視。 /// </summary> public void Perform(Gamepadmainloop mainloop) { // 接続ゲームコントローラー数。 this.Uc_Form1.UsercontrolPage1.PctxtConnectedDevices.Text = mainloop.Input.Dictionary_GameController.Count.ToString(); // 抜けたコントローラーのプレイヤー番号のリスト。 List <int> listN_Lost = new List <int>(); foreach (KeyValuePair <int, Memory_GameController> pair in mainloop.Input.Dictionary_GameController) { int nPlayer = pair.Key; Memory_GameController gc = pair.Value; Device gameController = gc.GameController; // ゲームコントローラーの、ボタンの押されている状況を取得します。 // その他に、マウス、キーボードも取得できるかも。 try { // キー読取 this.keyListener_MainImpl.Perform(gc); JoystickState state = gameController.CurrentJoystickState; StringBuilder sb = new StringBuilder(); int nX = state.X; int nY = state.Y; // 1スタートで+1、カーソルキーが4つで+4。 int nMax1 = 4 + gc.KeyCnf.NCount_MaxButton + 1; for (int nBtnIndex = 4 + 1; nBtnIndex < nMax1; nBtnIndex++) { if (gc.ButtonsFrame[nBtnIndex] == 1) { sb.Append("["); sb.Append(nBtnIndex - 4 - 1); sb.Append("]"); } } if (5000 == nX) { // // [→] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Right] == 1) { sb.Append("[→]"); } } else if (-5000 == nX) { // // [←] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Left] == 1) { sb.Append("[←]"); } } if (5000 == nY) { // // [↓] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Down] == 1) { sb.Append("[↓]"); } } else if (-5000 == nY) { // // [↑] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Up] == 1) { sb.Append("[↑]"); } } // // 表示 // string sTxt = sb.ToString(); int nMaxItems = 23;//リストボックスに表示できるアイテム数。 if (nPlayer < this.Uc_Form1.UsercontrolPage1.Usercontrol_VwdTestArray.Length) { Usercontrol_VwdTest ucController = this.Uc_Form1.UsercontrolPage1.Usercontrol_VwdTestArray[nPlayer]; if (null != ucController) { // フォーム配置完了時 // // [↑] // { int nKeyHard = (int)EnumGamepadkeyIx.Up; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { // todo:変更されているときだけ更新したい。 pclblB.ForeColor = Color.LightGray; pclblB.Text = "↑"; } } // // [→] // { int nKeyHard = (int)EnumGamepadkeyIx.Right; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = "→"; } } // [↓] { int nKeyHard = (int)EnumGamepadkeyIx.Down; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = "↓"; } } // [←] { int nKeyHard = (int)EnumGamepadkeyIx.Left; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = "←"; } } // [0] { int nBtn = 0; int nKeyHard = (int)EnumGamepadkeyIx.B0; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [1] { int nBtn = 1; int nKeyHard = (int)EnumGamepadkeyIx.B1; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [2] { int nBtn = 2; int nKeyHard = (int)EnumGamepadkeyIx.B2; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [3] { int nBtn = 3; int nKeyHard = (int)EnumGamepadkeyIx.B3; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [4] { int nBtn = 4; int nKeyHard = (int)EnumGamepadkeyIx.B4; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [5] { int nBtn = 5; int nKeyHard = (int)EnumGamepadkeyIx.B5; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [6] { int nBtn = 6; int nKeyHard = (int)EnumGamepadkeyIx.B6; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } // [7] { int nBtn = 7; int nKeyHard = (int)EnumGamepadkeyIx.B7; Label pclblB = ucController.PclblArray[nKeyHard]; if (0 < gc.ButtonsPressingFrame[nKeyHard]) { pclblB.ForeColor = Color.Blue; pclblB.Text = Utility_KeyconfigBit.GetShortString(gc.KeyCnf.KeyconfigArray[nKeyHard]); } else { pclblB.ForeColor = Color.LightGray; pclblB.Text = nBtn.ToString(); } } if ("" != sTxt) { ucController.Pclst.Items.Add(sTxt); if (nMaxItems < ucController.Pclst.Items.Count) { ucController.Pclst.Items.RemoveAt(0); } } } } } catch (NotAcquiredException) { // ゲームコントローラーを獲得していない。 } catch (InputLostException) { // ゲームコントローラーが抜けたとき。 // 抜けたコントローラーのプレイヤー番号を記憶 listN_Lost.Add(nPlayer); } nPlayer++; } foreach (int nPlayer in listN_Lost) { // 削除 mainloop.Input.Dictionary_GameController.Remove(nPlayer); } this.Uc_Form1.UsercontrolPage1.PctxtTimer.Text = this.Uc_Form1.Mainloop.NTimer.ToString(); }
//──────────────────────────────────────── private void ReadKeyconfig(Gamepadmainloop mainloop, int nPlayerPrm, Memory_GameController gc) { Log_Method pg_Method = new Log_MethodImpl(0); Log_Reports log_Reports_ThisMethod = new Log_ReportsImpl(pg_Method); pg_Method.BeginMethod(Info_Operating.Name_Library, this, "ReadKeyConfig",log_Reports_ThisMethod); // テーブルを、上から下に読んでいく。 // 列の並び順は NO ID Expl PLAYER BEFORE AFTER if (null != this.Table_Humaninput_Keyconfig)//テーブルの読取が成功していること。 { DataTable dataTable = this.Table_Humaninput_Keyconfig.DataTable; foreach (DataRow dataRow in dataTable.Rows) { int nPlayer; Int_HumaninputImpl.TryParse( dataRow.ItemArray[3], out nPlayer, EnumOperationIfErrorvalue.Spaces_To_Alt_Value, 0, log_Reports_ThisMethod ); if (nPlayerPrm == nPlayer) { string sBefore; string sAfter; String_HumaninputImpl.TryParse( dataRow.ItemArray[4], out sBefore, "", "", pg_Method, log_Reports_ThisMethod ); String_HumaninputImpl.TryParse( dataRow.ItemArray[5], out sAfter, "", "", pg_Method, log_Reports_ThisMethod ); EnumGamepadkeyIx o_Before; EnumGamepadkeyBit o_After; switch (sBefore) { case "Up": o_Before = EnumGamepadkeyIx.Up; break; case "Right": o_Before = EnumGamepadkeyIx.Right; break; case "Down": o_Before = EnumGamepadkeyIx.Down; break; case "Left": o_Before = EnumGamepadkeyIx.Left; break; case "1": o_Before = EnumGamepadkeyIx.B0; break; case "2": o_Before = EnumGamepadkeyIx.B1; break; case "3": o_Before = EnumGamepadkeyIx.B2; break; case "4": o_Before = EnumGamepadkeyIx.B3; break; case "5": o_Before = EnumGamepadkeyIx.B4; break; case "6": o_Before = EnumGamepadkeyIx.B5; break; case "7": o_Before = EnumGamepadkeyIx.B6; break; case "8": o_Before = EnumGamepadkeyIx.B7; break; default: o_Before = EnumGamepadkeyIx.Up; break; } switch (sAfter) { case "Up": o_After = EnumGamepadkeyBit.Up; break; case "Right": o_After = EnumGamepadkeyBit.Right; break; case "Down": o_After = EnumGamepadkeyBit.Down; break; case "Left": o_After = EnumGamepadkeyBit.Left; break; case "A": o_After = EnumGamepadkeyBit.A; break; case "B": o_After = EnumGamepadkeyBit.B; break; case "X": o_After = EnumGamepadkeyBit.X; break; case "Y": o_After = EnumGamepadkeyBit.Y; break; case "L": o_After = EnumGamepadkeyBit.L; break; case "R": o_After = EnumGamepadkeyBit.R; break; case "Select": o_After = EnumGamepadkeyBit.Select; break; case "Start": o_After = EnumGamepadkeyBit.Start; break; default: o_After = EnumGamepadkeyBit.Up; break; } gc.KeyCnf.KeyconfigArray[(int)o_Before] = o_After; } } } // // pg_Method.EndMethod(log_Reports_ThisMethod); log_Reports_ThisMethod.EndLogging(pg_Method); }
//──────────────────────────────────────── /// <summary> /// ゲームコントローラーの接続を監視。 /// </summary> public void ListenController(Gamepadmainloop mainloopPrm) { if (!(mainloopPrm is Gamepadmainloop_SampleImpl)) { throw new Exception("未対応のクラスが引数に渡されました。"); } Gamepadmainloop_SampleImpl mainloop = (Gamepadmainloop_SampleImpl)mainloopPrm; //ゲームコントローラーの接続を監視。毎フレーム監視していては重いと思うので、たまに。 if (this.ListenFrame < 1) { goto gt_play; } if (62 <= this.ListenFrame) { this.ListenFrame = -1; } this.ListenFrame++; return; // // // // gt_play: // // 接続されている「ゲーム用コントローラー」のリストを取得します。 DeviceList dl = Manager.GetDevices( DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly ); List<DeviceInstance> deviceInstanceList = new List<DeviceInstance>(); foreach (DeviceInstance di in dl) { deviceInstanceList.Add(di); } if (this.Dictionary_GameController.Count != deviceInstanceList.Count) { // // 設定し直し。 // TODO: 抜けてないプレイヤーの接続は、そのまま保持しておきたい。 // this.Dictionary_GameController.Clear(); int playerNumber = 1; foreach (DeviceInstance di in deviceInstanceList) { Device gameControl = new Device(di.InstanceGuid); Memory_GameController gc = new Memory_GameController(); gc.GameController = gameControl; this.Dictionary_GameController.Add(playerNumber, gc); this.ReadKeyconfig(mainloop, playerNumber, gc); // 十字キーまたはレバーのX,Yの倒れ具合を、-5000,0,5000 で表現するように設定。 foreach (DeviceObjectInstance doi in gameControl.Objects) { if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0) { gameControl.Properties.SetRange( ParameterHow.ById, doi.ObjectId, new InputRange(-5000, 5000) ); } } // 倒れ方を相対的ではなく、絶対的に判定。 gameControl.Properties.AxisModeAbsolute = true; // 「協調レベル」を設定。キーボードやゲームパッドの取り合い、ウィンドウが前景のとき背景のとき等をここで設定。 gameControl.SetCooperativeLevel( mainloop.Form1, CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background ); // キャプチャー(入力の補足)を獲得する。 gameControl.Acquire(); playerNumber++; } } }
//──────────────────────────────────────── #endregion #region アクション //──────────────────────────────────────── public void Perform(Gamepadmainloop mainloop) { // 接続ゲームコントローラー数。 this.Uc_Form1.UsercontrolPage1.PctxtConnectedDevices.Text = mainloop.Input.Dictionary_GameController.Count.ToString(); // 抜けたコントローラーのプレイヤー番号のリスト。 List <int> nList_Lost = new List <int>(); // プレイヤー毎に。 foreach (KeyValuePair <int, Memory_GameController> pair in mainloop.Input.Dictionary_GameController) { int nPlayer = pair.Key; Memory_GameController gc = pair.Value; Device gameController = gc.GameController; Usercontrol_VwdKeycnf ucCtrlCnf = this.Uc_Form1.UsercontrolPage2.Usercontrol_VwdKeycnfArray[nPlayer]; // ゲームコントローラーの、ボタンの押されている状況を取得します。 // その他に、マウス、キーボードも取得できるかも。 // ボタンが押されたかどうか。 bool bBtnPushed = false; try { // キー読取 this.keyListener_MainImpl.Perform(gc); JoystickState state = gameController.CurrentJoystickState; int nX = state.X; int nY = state.Y; // 押されたキー EnumGamepadkeyIx enumPushedKey = EnumGamepadkeyIx.None;//ダミー初期値。 // // [1] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B0] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B0; goto gt_buttonEnd;//1個だけ判定。 } // // [2] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B1] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B1; goto gt_buttonEnd;//1個だけ判定。 } // // [3] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B2] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B2; goto gt_buttonEnd;//1個だけ判定。 } // // [4] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B3] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B3; goto gt_buttonEnd;//1個だけ判定。 } // // [5] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B4] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B4; goto gt_buttonEnd;//1個だけ判定。 } // // [6] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B5] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B5; goto gt_buttonEnd;//1個だけ判定。 } // // [7] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B6] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B6; goto gt_buttonEnd;//1個だけ判定。 } // // [8] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.B7] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.B7; goto gt_buttonEnd;//1個だけ判定。 } if (5000 == nX) { // // [→] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Right] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.Right; goto gt_buttonEnd;//1個だけ判定。 } } else if (-5000 == nX) { // // [←] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Left] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.Left; goto gt_buttonEnd;//1個だけ判定。 } } if (5000 == nY) { // // [↓] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Down] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.Down; goto gt_buttonEnd;//1個だけ判定。 } } else if (-5000 == nY) { // // [↑] // if (gc.ButtonsFrame[(int)EnumGamepadkeyIx.Up] == 1) { bBtnPushed = true; enumPushedKey = EnumGamepadkeyIx.Up; goto gt_buttonEnd;//1個だけ判定。 } } // // // // gt_buttonEnd: // // 押されたキーの文字列化 // string sPushedKey; switch (enumPushedKey) { case EnumGamepadkeyIx.None: goto gt_playerEnd; case EnumGamepadkeyIx.Up: sPushedKey = "↑"; break; case EnumGamepadkeyIx.Right: sPushedKey = "→"; break; case EnumGamepadkeyIx.Down: sPushedKey = "↓"; break; case EnumGamepadkeyIx.Left: sPushedKey = "←"; break; case EnumGamepadkeyIx.B0: sPushedKey = "1"; break; case EnumGamepadkeyIx.B1: sPushedKey = "2"; break; case EnumGamepadkeyIx.B2: sPushedKey = "3"; break; case EnumGamepadkeyIx.B3: sPushedKey = "4"; break; case EnumGamepadkeyIx.B4: sPushedKey = "5"; break; case EnumGamepadkeyIx.B5: sPushedKey = "6"; break; case EnumGamepadkeyIx.B6: sPushedKey = "7"; break; case EnumGamepadkeyIx.B7: sPushedKey = "8"; break; default: sPushedKey = "エラー"; break; } // // 設定 // gc.KeyCnf.KeyconfigArray[(int)enumPushedKey] = gc.EnumCurKeyForCnf; // // 表示する場所。 if (bBtnPushed) { TextBox pctxtCur; TextBox pctxtNext; switch (gc.EnumCurKeyForCnf) { case EnumGamepadkeyBit.Up: // [↑] pctxtCur = ucCtrlCnf.PctxtUp; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtRight; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Right; break; case EnumGamepadkeyBit.Right: // [→] pctxtCur = ucCtrlCnf.PctxtRight; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtDown; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Down; break; case EnumGamepadkeyBit.Down: // [↓] pctxtCur = ucCtrlCnf.PctxtDown; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtLeft; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Left; break; case EnumGamepadkeyBit.Left: // [←] pctxtCur = ucCtrlCnf.PctxtLeft; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtA; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.A; break; case EnumGamepadkeyBit.A: // [A] pctxtCur = ucCtrlCnf.PctxtA; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtB; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.B; break; case EnumGamepadkeyBit.B: // [B] pctxtCur = ucCtrlCnf.PctxtB; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtX; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.X; break; case EnumGamepadkeyBit.X: // [X] pctxtCur = ucCtrlCnf.PctxtX; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtY; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Y; break; case EnumGamepadkeyBit.Y: // [Y] pctxtCur = ucCtrlCnf.PctxtY; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtL; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.L; break; case EnumGamepadkeyBit.L: // [L] pctxtCur = ucCtrlCnf.PctxtL; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtR; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.R; break; case EnumGamepadkeyBit.R: // [R] pctxtCur = ucCtrlCnf.PctxtR; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtSelect; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Select; break; case EnumGamepadkeyBit.Select: // [Select] pctxtCur = ucCtrlCnf.PctxtSelect; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtStart; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Start; break; case EnumGamepadkeyBit.Start: // [Start] pctxtCur = ucCtrlCnf.PctxtStart; pctxtCur.Text = sPushedKey; pctxtCur.ForeColor = Color.Black; pctxtCur.BackColor = SystemColors.Control; pctxtNext = ucCtrlCnf.PctxtUp; pctxtNext.ForeColor = Color.White; pctxtNext.BackColor = Color.Blue; gc.EnumCurKeyForCnf = EnumGamepadkeyBit.Up; break; } } } catch (NotAcquiredException) { // ゲームコントローラーを獲得していない。 } catch (InputLostException) { // ゲームコントローラーが抜けたとき。 // 抜けたコントローラーのプレイヤー番号を記憶 nList_Lost.Add(nPlayer); } // プレイヤー1人分終了 gt_playerEnd: nPlayer++; } foreach (int playerNumber in nList_Lost) { // 削除 mainloop.Input.Dictionary_GameController.Remove(playerNumber); } this.Uc_Form1.UsercontrolPage1.PctxtTimer.Text = this.Uc_Form1.Mainloop.NTimer.ToString(); }