コード例 #1
0
        void sc_OnRecvEvent(BeatlesBlog.SimConnect.SimConnect sender, BeatlesBlog.SimConnect.SIMCONNECT_RECV_EVENT data)
        {
            switch ((Requests)data.uEventID)
            {
            case Requests.DisplayMenuMain:
                // event from main menu, see which menu item was selected
                switch ((BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT)data.dwData)
                {
                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_1:
                    // display weather selection menu
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.MENU, 0, Requests.DisplayMenuWeather, strWeatherMenu);
                    break;

                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_2:
                    // display event selection menu
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.MENU, 0, Requests.DisplayMenuEvent, strEventMenu);
                    break;

                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_3:
                    // display set data selection menu
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.MENU, 0, Requests.DisplayMenuSetData, strSetDataMenu);
                    break;

                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_4:
                    // cause mainline thread to exit
                    exitEvent.Set();
                    break;
                }
                break;

            case Requests.DisplayMenuWeather:
                // event from weather selection menu, see which menu item was selected
                switch ((BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT)data.dwData)
                {
                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_1:
                    // requests the users current location to use in weather request (actual weather request made in OnRecvSimObjectData)
                    sc.RequestDataOnUserSimObject(Requests.WeatherAtLocation, typeof(VehiclePosition));
                    break;

                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_2:
                    // request weather at SeaTac airport
                    sc.WeatherRequestObservationAtStation(Requests.WeatherObservationStation, "KSEA");
                    break;

                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_3:
                    // request the users current location to use in the weather request (actual weather request made in OnRecvSimObjectData)
                    sc.RequestDataOnUserSimObject(Requests.WeatherNearestLocation, typeof(VehiclePosition));
                    break;

                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_4:
                    // display main menu
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.MENU, 0, Requests.DisplayMenuMain, strMainMenu);
                    break;
                }
                break;

            case Requests.DisplayMenuEvent:
                // event from event selection menu, see which menu item was selected
                switch ((BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT)data.dwData)
                {
                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_1:
                    // Send the Aileron Right event and show status message
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.PRINT_RED, 3.0f, Requests.DisplayEvent, "Sent Aileron Right");
                    sc.TransmitClientEventToUser(Events.AilerRight, BeatlesBlog.SimConnect.SIMCONNECT_GROUP_PRIORITY.HIGHEST);
                    break;

                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_2:
                    // Send the Aileron Left event and show status message
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.PRINT_RED, 3.0f, Requests.DisplayEvent, "Sent Aileron Left");
                    sc.TransmitClientEventToUser(Events.AilerLeft, BeatlesBlog.SimConnect.SIMCONNECT_GROUP_PRIORITY.HIGHEST);
                    break;

                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_3:
                    // Send the Aileron Center event and show status message
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.PRINT_RED, 3.0f, Requests.DisplayEvent, "Sent Aileron Center");
                    sc.TransmitClientEventToUser(Events.AilerCenter, BeatlesBlog.SimConnect.SIMCONNECT_GROUP_PRIORITY.HIGHEST);
                    break;

                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_4:
                    // display main menu
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.MENU, 0, Requests.DisplayMenuMain, strMainMenu);
                    break;
                }
                break;

            case Requests.DisplayMenuSetData:
                // event from set data menu, see which menu item was selected
                switch ((BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT)data.dwData)
                {
                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_1:
                    // Set the user's current location to (0,0,3000) using the SIMCONNECT_DATA_INITPOSIITON structure
                    sc.SetDataOnUserSimObject(
                        new BeatlesBlog.SimConnect.SIMCONNECT_DATA_INITPOSITION(
                            38.268351,
                            -77.445360,
                            0,
                            0,
                            0,
                            225,
                            true,
                            0
                            )
                        );
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.PRINT_RED, 3.0f, Requests.DisplaySetData, "SetDataOnSimObject called with INITPOSITION structure");
                    break;

                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_2:
                    // set the user's current location to (0,0,3000) using a program defined structure
                {
                    VehicleData vehdata = new VehicleData();
                    vehdata.position.latitude   = 0;
                    vehdata.position.longitude  = 0;
                    vehdata.position.altitude   = 3000;
                    vehdata.orientation.pitch   = 0;
                    vehdata.orientation.bank    = 0;
                    vehdata.orientation.heading = 120;

                    sc.SetDataOnUserSimObject(vehdata);
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.PRINT_RED, 3.0f, Requests.DisplaySetData, "SetDataOnSimObject called with custom structure");
                }
                break;

                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_3:
                    // create an AI aircraft and place the user near it
                    sc.AICreateNonATCAircraft("Beech Baron 58 Paint1", "N09TG",
                                              new BeatlesBlog.SimConnect.SIMCONNECT_DATA_INITPOSITION(
                                                  38.268351,
                                                  -77.445360,
                                                  0,
                                                  0,
                                                  0,
                                                  225,
                                                  true,
                                                  0
                                                  ),
                                              Requests.CreateAI
                                              );
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.PRINT_RED, 3.0f, Requests.DisplaySetData, "AI Aircraft Created");
                    break;

                case BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.MENU_SELECT_4:
                    // display main menu
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.MENU, 0, Requests.DisplayMenuMain, strMainMenu);
                    break;
                }
                break;

            case Requests.DisplayWeather:
                // event from display of current weather observation, if timed out, redisplay weather selection menu
                if ((BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT)data.dwData == BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.TIMEOUT)
                {
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.MENU, 0, Requests.DisplayMenuWeather, strWeatherMenu);
                }
                break;

            case Requests.DisplayEvent:
                // event from display of event status message, if timed out, redisplay event selection menu
                if ((BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT)data.dwData == BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.TIMEOUT)
                {
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.MENU, 0, Requests.DisplayMenuEvent, strEventMenu);
                }
                break;

            case Requests.DisplaySetData:
                // event from display of set data status message, if timed out, redisplay set data selection menu
                if ((BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT)data.dwData == BeatlesBlog.SimConnect.SIMCONNECT_TEXT_RESULT.TIMEOUT)
                {
                    sc.Text(BeatlesBlog.SimConnect.SIMCONNECT_TEXT_TYPE.MENU, 0, Requests.DisplayMenuSetData, strSetDataMenu);
                }
                break;
            }

            Console.WriteLine("OnRecvEvent");
        }