private void label2_Click_1(object sender, EventArgs e) { configure = true; AprNes_ConfigureUI.GetInstance().StartPosition = FormStartPosition.CenterParent; AprNes_ConfigureUI.GetInstance().init(); AprNes_ConfigureUI.GetInstance().ShowDialog(this); configure = false; }
public static AprNes_ConfigureUI GetInstance() { if (instance == null || instance.IsDisposed) { instance = new AprNes_ConfigureUI(); } return(instance); }
void polling_listener() { while (app_running) { Thread.Sleep(_joystick.PeriodMin); List <joystickEvent> event_list = _joystick.joy_event_captur(); foreach (joystickEvent joy_event in event_list) { //for configure if (configure) { AprNesUI.GetInstance().Invoke(new MethodInvoker(() => { if (joy_event.event_type == 0) //方向鍵觸發 { if (joy_event.way_type == 0) { AprNes_ConfigureUI.GetInstance().Setup_JoyPad_define(joy_event.joystick_id.ToString(), "X", 0, joy_event.way_value); } else { AprNes_ConfigureUI.GetInstance().Setup_JoyPad_define(joy_event.joystick_id.ToString(), "Y", 0, joy_event.way_value); } } else //一般按鈕觸發 { AprNes_ConfigureUI.GetInstance().Setup_JoyPad_define(joy_event.joystick_id.ToString(), "Button " + joy_event.button_id.ToString(), joy_event.button_id, 128); } })); break; } //for gaming.. if (running) { KeyMap joy = KeyMap.NES_btn_A; if (joy_event.event_type == 1) { string key = joy_event.joystick_id.ToString() + "," + "Button " + joy_event.button_id.ToString() + "," + joy_event.button_id.ToString(); if (AprNesUI.GetInstance().NES_KeyMAP_joypad.ContainsKey(key)) { joy = AprNesUI.GetInstance().NES_KeyMAP_joypad[key]; } else { continue; } } else { string XY = (joy_event.way_type == 0) ? "X" : "Y"; string key = joy_event.joystick_id.ToString() + "," + JoyPadWayName(XY, joy_event.way_value) + "," + "0" + "," + joy_event.way_value; if (AprNesUI.GetInstance().NES_KeyMAP_joypad.ContainsKey(key)) { joy = AprNesUI.GetInstance().NES_KeyMAP_joypad[key]; } else { string key_a = joy_event.joystick_id.ToString() + "," + JoyPadWayName(XY, 0) + "," + "0" + "," + "0"; string key_b = joy_event.joystick_id.ToString() + "," + JoyPadWayName(XY, 65535) + "," + "0" + "," + "65535"; if (NES_KeyMAP_joypad.ContainsKey(key_a) || (AprNesUI.GetInstance().NES_KeyMAP_joypad.ContainsKey(key_b))) { if (XY == "X") { NesCore.P1_ButtonUnPress((byte)KeyMap.NES_btn_LEFT); NesCore.P1_ButtonUnPress((byte)KeyMap.NES_btn_RIGHT); } if (XY == "Y") { NesCore.P1_ButtonUnPress((byte)KeyMap.NES_btn_UP); NesCore.P1_ButtonUnPress((byte)KeyMap.NES_btn_DOWN); } } continue; } } switch (joy) { case KeyMap.NES_btn_A: { if (joy_event.button_event == 1) { NesCore.P1_ButtonPress((byte)KeyMap.NES_btn_A); } else { NesCore.P1_ButtonUnPress((byte)KeyMap.NES_btn_A); } } break; case KeyMap.NES_btn_B: { if (joy_event.button_event == 1) { NesCore.P1_ButtonPress((byte)KeyMap.NES_btn_B); } else { NesCore.P1_ButtonUnPress((byte)KeyMap.NES_btn_B); } } break; case KeyMap.NES_btn_SELECT: { if (joy_event.button_event == 1) { NesCore.P1_ButtonPress((byte)KeyMap.NES_btn_SELECT); } else { NesCore.P1_ButtonUnPress((byte)KeyMap.NES_btn_SELECT); } } break; case KeyMap.NES_btn_START: { if (joy_event.button_event == 1) { NesCore.P1_ButtonPress((byte)KeyMap.NES_btn_START); } else { NesCore.P1_ButtonUnPress((byte)KeyMap.NES_btn_START); } } break; case KeyMap.NES_btn_UP: NesCore.P1_ButtonPress((byte)KeyMap.NES_btn_UP); break; case KeyMap.NES_btn_DOWN: NesCore.P1_ButtonPress((byte)KeyMap.NES_btn_DOWN); break; case KeyMap.NES_btn_LEFT: NesCore.P1_ButtonPress((byte)KeyMap.NES_btn_LEFT); break; case KeyMap.NES_btn_RIGHT: NesCore.P1_ButtonPress((byte)KeyMap.NES_btn_RIGHT); break; } } } } }