Esempio n. 1
0
        public void Launcher_Load(object sender, EventArgs e)
        {
            prevState  = new WiimoteState();
            m_vkcodes  = new VKCodes();
            m_profiles = new List <Profile>();

            // Behavior
            m_bMgr = new BehaviorManager();
            m_bMgr.Add(new StandardBehavior());
            m_bMgr.Add(new MinecraftBehavior());

            // Profileフォルダの読み込み
            if (!Directory.Exists("./Profile/"))
            {
                // Defaultプロファイルの作成
                Directory.CreateDirectory("./Profile/");
                var defaultProfile = new Profile();
                defaultProfile.Name              = "Default";
                defaultProfile.Behavior          = (new StandardBehavior()).GetName();
                defaultProfile.ActionAssignments = new Dictionary <WiimoteModel, List <ActionAttribute> >();
                defaultProfile.Save("./Profile/default.json");
            }

            LoadProfiles();

            // フォルダ内JSON変更の検知
            m_fileSystemWatcher.Path   = "./Profile";
            m_fileSystemWatcher.Filter = "*.json";
            m_fileSystemWatcher.SynchronizingObject = this;
            m_fileSystemWatcher.NotifyFilter        = NotifyFilters.LastAccess;
            m_fileSystemWatcher.Changed            += m_fileSystemWatcher_Changed;
            // m_fileSystemWatcher.EnableRaisingEvents = true; //監視を開始

            m_wm = new Wiimote();

            try
            {
                // 接続
                m_wm.WiimoteChanged          += (s, args) => UpdateState(args);
                m_wm.WiimoteExtensionChanged += (s, args) => UpdateExtension(args);
                m_wm.Connect();
                m_wm.SetReportType(InputReport.IRExtensionAccel, true);

                // LED
                m_wm.SetLEDs(true, false, false, false);

                // 振動
                Task.Run(() =>
                {
                    m_wm.SetRumble(true);
                    Thread.Sleep(200);
                    m_wm.SetRumble(false);
                });

                // デバッグ情報
                m_debugInfo         = new DebugInfo();
                m_debugInfo.OnHiden = () =>
                {
                    MenuItem_debugInfo.Checked = false;
                };
#if DEBUG
                m_debugInfo.Show();
                MenuItem_debugInfo.Checked = true;
#endif
            }
            catch (Exception ex)
            {
                string msg;

                switch (ex)
                {
                case WiimoteNotFoundException _:
                    msg = "Wiiリモコンを認識できませんでした.\n\n1. Bluetoothが有効になっているか,\n2. Wiiリモコンに電池が入っているか,\n3. LEDが点滅して接続待機状態になっているかどうか\n等を確認してください.";
                    break;

                case WiimoteException _:
                    msg = "Wiiリモコンに何らかのエラーが発生しました.";
                    break;

                default:
                    msg = "予期せぬエラーが発生しました.";
                    break;
                }

                MessageBox.Show(
                    msg,
                    "エラー",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
#if !DEBUG
                Environment.Exit(1);
#endif
            }
        }
Esempio n. 2
0
        public void Profiler_Load(object sender, EventArgs e)
        {
            m_vkcodes  = new VKCodes();
            m_profiles = new List <Profile>();

            // ModelRect
            m_dic_buttonRect = new Dictionary <WiimoteModel, Rectangle>();
            ReadRectsFromCsv(csv: Properties.Resources.modelRect);

            // Behavior
            m_bMgr = new BehaviorManager();
            m_bMgr.Add(new StandardBehavior());
            m_bMgr.Add(new MinecraftBehavior());

            m_dic_mouseAction = new Dictionary <string, MouseAction>
            {
                { "マウスのXを相対移動", MouseAction.MoveDx },
                { "マウスのYを相対移動", MouseAction.MoveDy },
                { "マウスのXを指定", MouseAction.MoveX },
                { "マウスのYを指定", MouseAction.MoveY },
                { "マウスのホイールを回転", MouseAction.ScrollWheel },
                { "マウスの左クリック", MouseAction.LeftClick },
                { "マウスの右クリック", MouseAction.RightClick },
                { "マウスの中クリック", MouseAction.MiddleClick }
            };

            // 装飾キーを追加
            m_dic_modKeys = new Dictionary <string, byte>
            {
                { "Shift", m_vkcodes["Shift"] },
                { "Ctrl", m_vkcodes["Ctrl"] },
                { "Alt", m_vkcodes["Alt"] },
                { "Win", m_vkcodes["LWin"] }
            };

            #region UIの初期化
            // RadioButton
            radioBtn_none.Checked    = true;
            radioBtn_JoyNone.Checked = true;

            // 設定Panel
            panel_setKeyMouse.Visible = true;
            panel_setJoystick.Visible = false;

            // Behavior
            combo_behavior.Items.AddRange(m_bMgr.GetBehaviorNames().ToArray());
            combo_behavior.SelectedIndex = 0;

            // キーボード
            combo_key.Items.AddRange(m_vkcodes.GetKeys().ToArray());

            // マウス
            combo_mouse.Items.AddRange(m_dic_mouseAction.Keys.ToArray());

            // 装飾キー
            combo_modKey.Items.AddRange(m_dic_modKeys.Keys.ToArray());

            #endregion

            LoadProfiles();

            // 詳細タブ
            listBox_models.Items.AddRange(Enum.GetNames(typeof(WiimoteModel)).Where(x => x != "_N_STICK").ToArray());
            listBox_models.SelectedIndex = 0;
        }