Пример #1
0
 public List <ControllerData> loadControllers()
 {
     return(ControllerData.parse(UserSettings.GetUserSettings().getString(ControllerData.PROPERTY_CONTAINER)));
 }
Пример #2
0
        public void loadSettings(System.Windows.Forms.Form parent)
        {
            int    channelOpenButtonIndex      = UserSettings.GetUserSettings().getInt("CHANNEL_OPEN_FUNCTION_button_index");
            String channelOpenButtonDeviceGuid = UserSettings.GetUserSettings().getString("CHANNEL_OPEN_FUNCTION_device_guid");

            if (channelOpenButtonIndex != -1 && channelOpenButtonDeviceGuid.Length > 0)
            {
                loadAssignment(parent, CHANNEL_OPEN_FUNCTION, channelOpenButtonIndex, channelOpenButtonDeviceGuid);
            }

            int    toggleRaceUpdatesButtonIndex      = UserSettings.GetUserSettings().getInt("TOGGLE_RACE_UPDATES_FUNCTION_button_index");
            String toggleRaceUpdatesButtonDeviceGuid = UserSettings.GetUserSettings().getString("TOGGLE_RACE_UPDATES_FUNCTION_device_guid");

            if (toggleRaceUpdatesButtonIndex != -1 && toggleRaceUpdatesButtonDeviceGuid.Length > 0)
            {
                loadAssignment(parent, TOGGLE_RACE_UPDATES_FUNCTION, toggleRaceUpdatesButtonIndex, toggleRaceUpdatesButtonDeviceGuid);
            }

            int    toggleSpotterFunctionButtonIndex = UserSettings.GetUserSettings().getInt("TOGGLE_SPOTTER_FUNCTION_button_index");
            String toggleSpotterFunctionDeviceGuid  = UserSettings.GetUserSettings().getString("TOGGLE_SPOTTER_FUNCTION_device_guid");

            if (toggleSpotterFunctionButtonIndex != -1 && toggleSpotterFunctionDeviceGuid.Length > 0)
            {
                loadAssignment(parent, TOGGLE_SPOTTER_FUNCTION, toggleSpotterFunctionButtonIndex, toggleSpotterFunctionDeviceGuid);
            }

            int    toggleReadOpponentDeltasButtonIndex = UserSettings.GetUserSettings().getInt("TOGGLE_READ_OPPONENT_DELTAS_button_index");
            String toggleReadOpponentDeltasDeviceGuid  = UserSettings.GetUserSettings().getString("TOGGLE_READ_OPPONENT_DELTAS_device_guid");

            if (toggleReadOpponentDeltasButtonIndex != -1 && toggleReadOpponentDeltasDeviceGuid.Length > 0)
            {
                loadAssignment(parent, TOGGLE_READ_OPPONENT_DELTAS, toggleReadOpponentDeltasButtonIndex, toggleReadOpponentDeltasDeviceGuid);
            }

            int    toggleBlockMessagesInHardPartsButtonIndex = UserSettings.GetUserSettings().getInt("TOGGLE_BLOCK_MESSAGES_IN_HARD_PARTS_button_index");
            String toggleBlockMessagesInHardPartsDeviceGuid  = UserSettings.GetUserSettings().getString("TOGGLE_BLOCK_MESSAGES_IN_HARD_PARTS_device_guid");

            if (toggleBlockMessagesInHardPartsButtonIndex != -1 && toggleBlockMessagesInHardPartsDeviceGuid.Length > 0)
            {
                loadAssignment(parent, TOGGLE_BLOCK_MESSAGES_IN_HARD_PARTS, toggleBlockMessagesInHardPartsButtonIndex, toggleBlockMessagesInHardPartsDeviceGuid);
            }

            int    repeatLastMessageButtonIndex = UserSettings.GetUserSettings().getInt("REPEAT_LAST_MESSAGE_BUTTON_button_index");
            String repeatLastMessageDeviceGuid  = UserSettings.GetUserSettings().getString("REPEAT_LAST_MESSAGE_BUTTON_device_guid");

            if (repeatLastMessageButtonIndex != -1 && repeatLastMessageDeviceGuid.Length > 0)
            {
                loadAssignment(parent, REPEAT_LAST_MESSAGE_BUTTON, repeatLastMessageButtonIndex, repeatLastMessageDeviceGuid);
            }

            int    volumeUpButtonIndex = UserSettings.GetUserSettings().getInt("VOLUME_UP_button_index");
            String volumeUpDeviceGuid  = UserSettings.GetUserSettings().getString("VOLUME_UP_device_guid");

            if (volumeUpButtonIndex != -1 && volumeUpDeviceGuid.Length > 0)
            {
                loadAssignment(parent, VOLUME_UP, volumeUpButtonIndex, volumeUpDeviceGuid);
            }

            int    volumeDownButtonIndex = UserSettings.GetUserSettings().getInt("VOLUME_DOWN_button_index");
            String volumeDownDeviceGuid  = UserSettings.GetUserSettings().getString("VOLUME_DOWN_device_guid");

            if (volumeDownButtonIndex != -1 && volumeDownDeviceGuid.Length > 0)
            {
                loadAssignment(parent, VOLUME_DOWN, volumeDownButtonIndex, volumeDownDeviceGuid);
            }

            int    printTrackDataButtonIndex = UserSettings.GetUserSettings().getInt("PRINT_TRACK_DATA_button_index");
            String printTrackDataDeviceGuid  = UserSettings.GetUserSettings().getString("PRINT_TRACK_DATA_device_guid");

            if (printTrackDataButtonIndex != -1 && printTrackDataDeviceGuid.Length > 0)
            {
                loadAssignment(parent, PRINT_TRACK_DATA, printTrackDataButtonIndex, printTrackDataDeviceGuid);
            }

            int    toggleYellowFlagMessagesButtonIndex = UserSettings.GetUserSettings().getInt("TOGGLE_YELLOW_FLAG_MESSAGES_button_index");
            String toggleYellowFlagMessagesDeviceGuid  = UserSettings.GetUserSettings().getString("TOGGLE_YELLOW_FLAG_MESSAGES_device_guid");

            if (toggleYellowFlagMessagesButtonIndex != -1 && toggleYellowFlagMessagesDeviceGuid.Length > 0)
            {
                loadAssignment(parent, TOGGLE_YELLOW_FLAG_MESSAGES, toggleYellowFlagMessagesButtonIndex, toggleYellowFlagMessagesDeviceGuid);
            }

            int    getFuelStatusButtonIndex = UserSettings.GetUserSettings().getInt("GET_FUEL_STATUS_button_index");
            String getFuelStatusDeviceGuid  = UserSettings.GetUserSettings().getString("GET_FUEL_STATUS_device_guid");

            if (getFuelStatusButtonIndex != -1 && getFuelStatusDeviceGuid.Length > 0)
            {
                loadAssignment(parent, GET_FUEL_STATUS, getFuelStatusButtonIndex, getFuelStatusDeviceGuid);
            }

            int    toggleManualFormationLapButtonIndex = UserSettings.GetUserSettings().getInt("TOGGLE_MANUAL_FORMATION_LAP_button_index");
            String toggleManualFormationLapDeviceGuid  = UserSettings.GetUserSettings().getString("TOGGLE_MANUAL_FORMATION_LAP_device_guid");

            if (toggleManualFormationLapButtonIndex != -1 && toggleManualFormationLapDeviceGuid.Length > 0)
            {
                loadAssignment(parent, TOGGLE_MANUAL_FORMATION_LAP, toggleManualFormationLapButtonIndex, toggleManualFormationLapDeviceGuid);
            }

            int    readCornerNamesForLapButtonIndex = UserSettings.GetUserSettings().getInt("READ_CORNER_NAMES_FOR_LAP_button_index");
            String readCornerNamesForLapDeviceGuid  = UserSettings.GetUserSettings().getString("READ_CORNER_NAMES_FOR_LAP_device_guid");

            if (readCornerNamesForLapButtonIndex != -1 && readCornerNamesForLapDeviceGuid.Length > 0)
            {
                loadAssignment(parent, READ_CORNER_NAMES_FOR_LAP, readCornerNamesForLapButtonIndex, readCornerNamesForLapDeviceGuid);
            }

            int    getStatusButtonIndex = UserSettings.GetUserSettings().getInt("GET_STATUS_button_index");
            String getStatusDeviceGuid  = UserSettings.GetUserSettings().getString("GET_STATUS_device_guid");

            if (getStatusButtonIndex != -1 && getStatusDeviceGuid.Length > 0)
            {
                loadAssignment(parent, GET_STATUS, getStatusButtonIndex, getStatusDeviceGuid);
            }

            int    getDamageReportButtonIndex = UserSettings.GetUserSettings().getInt("GET_DAMAGE_REPORT_button_index");
            String getDamageReportDeviceGuid  = UserSettings.GetUserSettings().getString("GET_DAMAGE_REPORT_device_guid");

            if (getDamageReportButtonIndex != -1 && getDamageReportDeviceGuid.Length > 0)
            {
                loadAssignment(parent, GET_DAMAGE_REPORT, getDamageReportButtonIndex, getDamageReportDeviceGuid);
            }

            int    getCarStatusButtonIndex = UserSettings.GetUserSettings().getInt("GET_CAR_STATUS_button_index");
            String getCarStatusDeviceGuid  = UserSettings.GetUserSettings().getString("GET_CAR_STATUS_device_guid");

            if (getCarStatusButtonIndex != -1 && getCarStatusDeviceGuid.Length > 0)
            {
                loadAssignment(parent, GET_CAR_STATUS, getCarStatusButtonIndex, getCarStatusDeviceGuid);
            }

            int    getSessionStatusButtonIndex = UserSettings.GetUserSettings().getInt("GET_SESSION_STATUS_button_index");
            String getSessionStatusDeviceGuid  = UserSettings.GetUserSettings().getString("GET_SESSION_STATUS_device_guid");

            if (getSessionStatusButtonIndex != -1 && getSessionStatusDeviceGuid.Length > 0)
            {
                loadAssignment(parent, GET_SESSION_STATUS, getSessionStatusButtonIndex, getSessionStatusDeviceGuid);
            }

            int    togglePaceNotesPlaybackButtonIndex = UserSettings.GetUserSettings().getInt("TOGGLE_PACE_NOTES_PLAYBACK_button_index");
            String togglePaceNotesPlaybackDeviceGuid  = UserSettings.GetUserSettings().getString("TOGGLE_PACE_NOTES_PLAYBACK_device_guid");

            if (togglePaceNotesPlaybackButtonIndex != -1 && togglePaceNotesPlaybackDeviceGuid.Length > 0)
            {
                loadAssignment(parent, TOGGLE_PACE_NOTES_PLAYBACK, togglePaceNotesPlaybackButtonIndex, togglePaceNotesPlaybackDeviceGuid);
            }

            int    togglePaceNotesRecordingButtonIndex = UserSettings.GetUserSettings().getInt("TOGGLE_PACE_NOTES_RECORDING_button_index");
            String togglePaceNotesRecordingDeviceGuid  = UserSettings.GetUserSettings().getString("TOGGLE_PACE_NOTES_RECORDING_device_guid");

            if (togglePaceNotesRecordingButtonIndex != -1 && togglePaceNotesRecordingDeviceGuid.Length > 0)
            {
                loadAssignment(parent, TOGGLE_PACE_NOTES_RECORDING, togglePaceNotesRecordingButtonIndex, togglePaceNotesRecordingDeviceGuid);
            }
            int    toggleTrackLandmarkButtonIndex         = UserSettings.GetUserSettings().getInt("TOGGLE_TRACK_LANDMARKS_RECORDING_button_index");
            String toggleTrackLandmarkRecordingDeviceGuid = UserSettings.GetUserSettings().getString("TOGGLE_TRACK_LANDMARKS_RECORDING_device_guid");

            if (toggleTrackLandmarkButtonIndex != -1 && toggleTrackLandmarkRecordingDeviceGuid.Length > 0)
            {
                loadAssignment(parent, TOGGLE_TRACK_LANDMARKS_RECORDING, toggleTrackLandmarkButtonIndex, toggleTrackLandmarkRecordingDeviceGuid);
            }
            int    addTracklandmarkButtonIndex = UserSettings.GetUserSettings().getInt("ADD_TRACK_LANDMARK_button_index");
            String addTracklandmarkDeviceGuid  = UserSettings.GetUserSettings().getString("ADD_TRACK_LANDMARK_device_guid");

            if (addTracklandmarkButtonIndex != -1 && addTracklandmarkDeviceGuid.Length > 0)
            {
                loadAssignment(parent, ADD_TRACK_LANDMARK, addTracklandmarkButtonIndex, addTracklandmarkDeviceGuid);
            }

            int    pitPredictionButtonIndex = UserSettings.GetUserSettings().getInt("PIT_PREDICTION_button_index");
            String pitPredictionDeviceGuid  = UserSettings.GetUserSettings().getString("PIT_PREDICTION_device_guid");

            if (pitPredictionButtonIndex != -1 && pitPredictionDeviceGuid.Length > 0)
            {
                loadAssignment(parent, PIT_PREDICTION, pitPredictionButtonIndex, pitPredictionDeviceGuid);
            }
        }
Пример #3
0
 public void saveSettings()
 {
     foreach (ButtonAssignment buttonAssignment in buttonAssignments)
     {
         String actionId = "";
         if (buttonAssignment.action == CHANNEL_OPEN_FUNCTION)
         {
             actionId = "CHANNEL_OPEN_FUNCTION";
         }
         else if (buttonAssignment.action == TOGGLE_RACE_UPDATES_FUNCTION)
         {
             actionId = "TOGGLE_RACE_UPDATES_FUNCTION";
         }
         else if (buttonAssignment.action == TOGGLE_SPOTTER_FUNCTION)
         {
             actionId = "TOGGLE_SPOTTER_FUNCTION";
         }
         else if (buttonAssignment.action == TOGGLE_READ_OPPONENT_DELTAS)
         {
             actionId = "TOGGLE_READ_OPPONENT_DELTAS";
         }
         else if (buttonAssignment.action == TOGGLE_BLOCK_MESSAGES_IN_HARD_PARTS)
         {
             actionId = "TOGGLE_BLOCK_MESSAGES_IN_HARD_PARTS";
         }
         else if (buttonAssignment.action == REPEAT_LAST_MESSAGE_BUTTON)
         {
             actionId = "REPEAT_LAST_MESSAGE_BUTTON";
         }
         else if (buttonAssignment.action == VOLUME_UP)
         {
             actionId = "VOLUME_UP";
         }
         else if (buttonAssignment.action == VOLUME_DOWN)
         {
             actionId = "VOLUME_DOWN";
         }
         else if (buttonAssignment.action == PRINT_TRACK_DATA)
         {
             actionId = "PRINT_TRACK_DATA";
         }
         else if (buttonAssignment.action == TOGGLE_YELLOW_FLAG_MESSAGES)
         {
             actionId = "TOGGLE_YELLOW_FLAG_MESSAGES";
         }
         else if (buttonAssignment.action == GET_FUEL_STATUS)
         {
             actionId = "GET_FUEL_STATUS";
         }
         else if (buttonAssignment.action == TOGGLE_MANUAL_FORMATION_LAP)
         {
             actionId = "TOGGLE_MANUAL_FORMATION_LAP";
         }
         else if (buttonAssignment.action == READ_CORNER_NAMES_FOR_LAP)
         {
             actionId = "READ_CORNER_NAMES_FOR_LAP";
         }
         else if (buttonAssignment.action == GET_CAR_STATUS)
         {
             actionId = "GET_CAR_STATUS";
         }
         else if (buttonAssignment.action == GET_DAMAGE_REPORT)
         {
             actionId = "GET_DAMAGE_REPORT";
         }
         else if (buttonAssignment.action == GET_SESSION_STATUS)
         {
             actionId = "GET_SESSION_STATUS";
         }
         else if (buttonAssignment.action == GET_STATUS)
         {
             actionId = "GET_STATUS";
         }
         else if (buttonAssignment.action == TOGGLE_PACE_NOTES_PLAYBACK)
         {
             actionId = "TOGGLE_PACE_NOTES_PLAYBACK";
         }
         else if (buttonAssignment.action == TOGGLE_PACE_NOTES_RECORDING)
         {
             actionId = "TOGGLE_PACE_NOTES_RECORDING";
         }
         else if (buttonAssignment.action == TOGGLE_TRACK_LANDMARKS_RECORDING)
         {
             actionId = "TOGGLE_TRACK_LANDMARKS_RECORDING";
         }
         else if (buttonAssignment.action == ADD_TRACK_LANDMARK)
         {
             actionId = "ADD_TRACK_LANDMARK";
         }
         else if (buttonAssignment.action == PIT_PREDICTION)
         {
             actionId = "PIT_PREDICTION";
         }
         if (buttonAssignment.controller != null && (buttonAssignment.joystick != null || buttonAssignment.controller.guid == UDP_NETWORK_CONTROLLER_GUID) && buttonAssignment.buttonIndex != -1)
         {
             UserSettings.GetUserSettings().setProperty(actionId + "_button_index", buttonAssignment.buttonIndex);
             UserSettings.GetUserSettings().setProperty(actionId + "_device_guid", buttonAssignment.controller.guid.ToString());
         }
         else
         {
             UserSettings.GetUserSettings().setProperty(actionId + "_button_index", -1);
             UserSettings.GetUserSettings().setProperty(actionId + "_device_guid", "");
         }
     }
     UserSettings.GetUserSettings().saveUserSettings();
 }
Пример #4
0
        public Boolean Run(String filenameToRun, int interval, Boolean dumpToFile)
        {
            loadDataFromFile = false;
            audioPlayer.mute = false;
            if (filenameToRun != null && System.Diagnostics.Debugger.IsAttached)
            {
                loadDataFromFile = true;
                spotterEnabled   = false;
                if (interval > 0)
                {
                    _timeInterval    = TimeSpan.FromMilliseconds(interval);
                    audioPlayer.mute = false;
                }
                else
                {
                    _timeInterval    = TimeSpan.Zero;
                    audioPlayer.mute = true;
                }
                dumpToFile = false;
            }

            gameStateMapper = GameStateReaderFactory.getInstance().getGameStateMapper(gameDefinition);
            gameStateMapper.setSpeechRecogniser(speechRecogniser);
            gameDataReader = GameStateReaderFactory.getInstance().getGameStateReader(gameDefinition);
            gameDataReader.ResetGameDataFromFile();

            gameDataReader.dumpToFile = System.Diagnostics.Debugger.IsAttached && dumpToFile;
            if (gameDefinition.spotterName != null)
            {
                spotter = (Spotter)Activator.CreateInstance(Type.GetType(gameDefinition.spotterName),
                                                            audioPlayer, spotterEnabled);
            }
            else
            {
                Console.WriteLine("No spotter defined for game " + gameDefinition.friendlyName);
                spotter = null;
            }
            running = true;
            DateTime nextRunTime = DateTime.Now;

            if (!audioPlayer.initialised)
            {
                Console.WriteLine("Failed to initialise audio player");
                return(false);
            }
            audioPlayer.startMonitor();
            Boolean attemptedToRunGame = false;

            Console.WriteLine("Polling for shared data every " + _timeInterval.Milliseconds + "ms");
            Boolean sessionFinished = false;

            while (running)
            {
                DateTime now = DateTime.Now;
                if (now > nextRunTime)
                {
                    // ensure the updates don't get synchronised with the spotter / UDP receiver
                    int updateTweak = random.Next(10) - 5;
                    nextRunTime = DateTime.Now.Add(_timeInterval);
                    nextRunTime.Add(TimeSpan.FromMilliseconds(updateTweak));
                    if (!loadDataFromFile)
                    {
                        if (gameDefinition.processName == null || Utilities.IsGameRunning(gameDefinition.processName))
                        {
                            if (!mapped)
                            {
                                mapped = gameDataReader.Initialise();
                            }
                        }
                        else if (UserSettings.GetUserSettings().getBoolean(gameDefinition.gameStartEnabledProperty) && !attemptedToRunGame)
                        {
                            Utilities.runGame(UserSettings.GetUserSettings().getString(gameDefinition.gameStartCommandProperty),
                                              UserSettings.GetUserSettings().getString(gameDefinition.gameStartCommandOptionsProperty));
                            attemptedToRunGame = true;
                        }
                    }

                    if (loadDataFromFile || mapped)
                    {
                        stateCleared = false;
                        Object rawGameData;
                        if (loadDataFromFile)
                        {
                            rawGameData = gameDataReader.ReadGameDataFromFile(filenameToRun);
                            if (rawGameData == null)
                            {
                                Console.WriteLine("Reached the end of the data file, sleeping to clear queued messages");
                                Thread.Sleep(5000);
                                audioPlayer.purgeQueues();
                                running = false;
                                continue;
                            }
                        }
                        else
                        {
                            rawGameData = gameDataReader.ReadGameData(false);
                        }
                        gameStateMapper.versionCheck(rawGameData);

                        GameStateData nextGameState = null;
                        try
                        {
                            nextGameState = gameStateMapper.mapToGameStateData(rawGameData, currentGameState);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error mapping game data: " + e.StackTrace);
                        }
                        // if we're paused or viewing another car, the mapper will just return the previous game state so we don't lose all the
                        // persistent state information. If this is the case, don't process any stuff
                        if (nextGameState != null && nextGameState != currentGameState)
                        {
                            previousGameState = currentGameState;
                            currentGameState  = nextGameState;
                            if (!sessionFinished && currentGameState.SessionData.SessionPhase == SessionPhase.Finished &&
                                previousGameState != null)
                            {
                                Console.WriteLine("Session finished");
                                audioPlayer.purgeQueues();
                                if (displaySessionLapTimes)
                                {
                                    Console.WriteLine("Session lap times:");
                                    Console.WriteLine(String.Join(";", currentGameState.SessionData.formattedPlayerLapTimes));
                                }
                                sessionEndMessages.trigger(previousGameState.SessionData.SessionRunningTime, previousGameState.SessionData.SessionType, currentGameState.SessionData.SessionPhase,
                                                           previousGameState.SessionData.SessionStartPosition, previousGameState.SessionData.Position, previousGameState.SessionData.NumCarsAtStartOfSession, previousGameState.SessionData.CompletedLaps,
                                                           previousGameState.SessionData.IsDisqualified);

                                sessionFinished = true;
                                audioPlayer.disablePearlsOfWisdom = false;
                                if (loadDataFromFile)
                                {
                                    Thread.Sleep(2000);
                                }
                            }
                            float prevTime = previousGameState == null ? 0 : previousGameState.SessionData.SessionRunningTime;
                            if (currentGameState.SessionData.IsNewSession)
                            {
                                Console.WriteLine("New session");
                                audioPlayer.disablePearlsOfWisdom = false;
                                displayNewSessionInfo(currentGameState);
                                sessionFinished = false;
                                if (!stateCleared)
                                {
                                    Console.WriteLine("Clearing game state...");
                                    audioPlayer.purgeQueues();

                                    foreach (KeyValuePair <String, AbstractEvent> entry in eventsList)
                                    {
                                        entry.Value.clearState();
                                    }
                                    faultingEvents.Clear();
                                    faultingEventsCount.Clear();
                                    stateCleared = true;
                                }
                                if (enableDriverNames)
                                {
                                    List <String> rawDriverNames = currentGameState.getRawDriverNames();
                                    if (currentGameState.SessionData.DriverRawName != null && currentGameState.SessionData.DriverRawName.Length > 0 &&
                                        !rawDriverNames.Contains(currentGameState.SessionData.DriverRawName))
                                    {
                                        rawDriverNames.Add(currentGameState.SessionData.DriverRawName);
                                    }
                                    if (rawDriverNames.Count > 0)
                                    {
                                        List <String> usableDriverNames = DriverNameHelper.getUsableDriverNames(rawDriverNames);
                                        if (speechRecogniser != null && speechRecogniser.initialised)
                                        {
                                            speechRecogniser.addOpponentSpeechRecognition(usableDriverNames, enableDriverNames);
                                        }
                                    }
                                }
                            }
                            // TODO: for AC free practice sessions, the SessionRunningTime is set to 1 hour in the mapper and stays there so this block never triggers
                            else if (!sessionFinished && previousGameState != null &&
                                     (currentGameState.SessionData.SessionRunningTime > previousGameState.SessionData.SessionRunningTime ||
                                      (previousGameState.SessionData.SessionPhase != currentGameState.SessionData.SessionPhase)) ||
                                     ((gameDefinition.gameEnum == GameEnum.PCARS_32BIT || gameDefinition.gameEnum == GameEnum.PCARS_64BIT || gameDefinition.gameEnum == GameEnum.PCARS_NETWORK) &&
                                      currentGameState.SessionData.SessionHasFixedTime && currentGameState.SessionData.SessionTotalRunTime == -1))
                            {
                                if (spotter != null)
                                {
                                    if (currentGameState.FlagData.isFullCourseYellow)
                                    {
                                        spotter.pause();
                                    }
                                    else
                                    {
                                        spotter.unpause();
                                    }
                                }
                                if (currentGameState.SessionData.IsNewLap)
                                {
                                    currentGameState.display();
                                }
                                stateCleared = false;
                                foreach (KeyValuePair <String, AbstractEvent> entry in eventsList)
                                {
                                    if (entry.Value.isApplicableForCurrentSessionAndPhase(currentGameState.SessionData.SessionType, currentGameState.SessionData.SessionPhase))
                                    {
                                        triggerEvent(entry.Key, entry.Value, previousGameState, currentGameState);
                                    }
                                }
                                if (spotter != null && spotterEnabled && !spotterIsRunning && !loadDataFromFile)
                                {
                                    Console.WriteLine("********** starting spotter***********");
                                    spotter.clearState();
                                    startSpotterThread();
                                }
                                else if (spotterIsRunning && !spotterEnabled)
                                {
                                    runSpotterThread = false;
                                }
                            }
                            else if (spotter != null)
                            {
                                spotter.pause();
                            }
                        }
                    }
                }
                else
                {
                    // ensure the updates don't get synchronised with the spotter / UDP receiver
                    int threadSleepTime = 5 + random.Next(10);
                    Thread.Sleep(threadSleepTime);
                    continue;
                }
            }
            foreach (KeyValuePair <String, AbstractEvent> entry in eventsList)
            {
                entry.Value.clearState();
            }
            if (spotter != null)
            {
                spotter.clearState();
            }
            stateCleared      = true;
            currentGameState  = null;
            previousGameState = null;
            sessionFinished   = false;
            Console.WriteLine("Stopping queue monitor");
            audioPlayer.stopMonitor();
            audioPlayer.disablePearlsOfWisdom = false;
            if (gameDataReader != null && gameDataReader.dumpToFile)
            {
                gameDataReader.DumpRawGameData();
            }
            gameDataReader.stop();
            return(true);
        }
Пример #5
0
        public PropertiesForm(System.Windows.Forms.Form parent)
        {
            hasChanges  = false;
            this.parent = parent;
            InitializeComponent();
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.button1.Text = "Save (manual restart required)";
            }
            int widgetCount = 0;

            foreach (SettingsProperty strProp in UserSettings.GetUserSettings().getProperties(typeof(String), null, null))
            {
                this.flowLayoutPanel1.Controls.Add(new StringPropertyControl(strProp.Name, Configuration.getUIString(strProp.Name) + " " + Configuration.getUIString("text_prop_type"),
                                                                             UserSettings.GetUserSettings().getString(strProp.Name), (String)strProp.DefaultValue,
                                                                             Configuration.getUIString(strProp.Name + "_help")));
                widgetCount++;
            }
            pad(widgetCount);
            widgetCount = 0;
            foreach (SettingsProperty boolProp in UserSettings.GetUserSettings().getProperties(typeof(Boolean), "enable", null))
            {
                Boolean defaultValue;
                Boolean.TryParse((String)boolProp.DefaultValue, out defaultValue);
                this.flowLayoutPanel1.Controls.Add(new BooleanPropertyControl(boolProp.Name, Configuration.getUIString(boolProp.Name) + " " + Configuration.getUIString("boolean_prop_type"),
                                                                              UserSettings.GetUserSettings().getBoolean(boolProp.Name), defaultValue,
                                                                              Configuration.getUIString(boolProp.Name + "_help")));
                widgetCount++;
            }
            pad(widgetCount);
            widgetCount = 0;
            foreach (SettingsProperty intProp in UserSettings.GetUserSettings().getProperties(typeof(int), "frequency", null))
            {
                int defaultValue;
                int.TryParse((String)intProp.DefaultValue, out defaultValue);
                this.flowLayoutPanel1.Controls.Add(new IntPropertyControl(intProp.Name, Configuration.getUIString(intProp.Name) + " " + Configuration.getUIString("integer_prop_type"),
                                                                          UserSettings.GetUserSettings().getInt(intProp.Name), defaultValue,
                                                                          Configuration.getUIString(intProp.Name + "_help")));
                widgetCount++;
            }
            pad(widgetCount);
            widgetCount = 0;
            foreach (SettingsProperty boolProp in UserSettings.GetUserSettings().getProperties(typeof(Boolean), null, "enable"))
            {
                Boolean defaultValue;
                Boolean.TryParse((String)boolProp.DefaultValue, out defaultValue);
                this.flowLayoutPanel1.Controls.Add(new BooleanPropertyControl(boolProp.Name, Configuration.getUIString(boolProp.Name) + " " + Configuration.getUIString("boolean_prop_type"),
                                                                              UserSettings.GetUserSettings().getBoolean(boolProp.Name), defaultValue,
                                                                              Configuration.getUIString(boolProp.Name + "_help")));
                widgetCount++;
            }
            pad(widgetCount);
            widgetCount = 0;
            foreach (SettingsProperty intProp in UserSettings.GetUserSettings().getProperties(typeof(int), null, "frequency"))
            {
                int defaultValue;
                int.TryParse((String)intProp.DefaultValue, out defaultValue);
                this.flowLayoutPanel1.Controls.Add(new IntPropertyControl(intProp.Name, Configuration.getUIString(intProp.Name) + " " + Configuration.getUIString("integer_prop_type"),
                                                                          UserSettings.GetUserSettings().getInt(intProp.Name), defaultValue,
                                                                          Configuration.getUIString(intProp.Name + "_help")));
                widgetCount++;
            }
            pad(widgetCount);
            widgetCount = 0;
            foreach (SettingsProperty floatProp in UserSettings.GetUserSettings().getProperties(typeof(float), null, null))
            {
                float defaultValue;
                float.TryParse((String)floatProp.DefaultValue, out defaultValue);
                this.flowLayoutPanel1.Controls.Add(new FloatPropertyControl(floatProp.Name, Configuration.getUIString(floatProp.Name) + " " + Configuration.getUIString("real_number_prop_type"),
                                                                            UserSettings.GetUserSettings().getFloat(floatProp.Name), defaultValue,
                                                                            Configuration.getUIString(floatProp.Name + "_help")));
                widgetCount++;
            }
            pad(widgetCount);
            widgetCount = 0;
        }
Пример #6
0
        // Note: vast majority of startup time is in ShowDialog.  Looks like pretty much the only way to speed it up is by reducing
        // number of controls or splitting in tabs.
        public PropertiesForm(System.Windows.Forms.Form parent)
        {
            if (MainWindow.forceMinWindowSize)
            {
                this.MinimumSize = new System.Drawing.Size(995, 745);
            }

            hasChanges  = false;
            this.parent = parent;

            InitializeComponent();
            if (CrewChief.Debugging)
            {
                this.saveButton.Text = "Save (manual restart required)";
            }

            this.SuspendLayout();
            this.propertiesFlowLayoutPanel.SuspendLayout();

            int widgetCount = 0;

            foreach (SettingsProperty strProp in UserSettings.GetUserSettings().getProperties(typeof(String), null, null))
            {
                if (strProp.Name.EndsWith(PropertiesForm.listPropPostfix) && ListPropertyValues.getListBoxLabels(strProp.Name) != null)
                {
                    this.propertiesFlowLayoutPanel.Controls.Add(new ListPropertyControl(strProp.Name, Configuration.getUIString(strProp.Name) + " " + Configuration.getUIString("text_prop_type"),
                                                                                        UserSettings.GetUserSettings().getString(strProp.Name), (String)strProp.DefaultValue,
                                                                                        Configuration.getUIString(strProp.Name + "_help"), Configuration.getUIStringStrict(strProp.Name + "_filter"),
                                                                                        Configuration.getUIStringStrict(strProp.Name + "_category"), Configuration.getUIStringStrict(strProp.Name + "_type")));
                }
                else
                {
                    this.propertiesFlowLayoutPanel.Controls.Add(new StringPropertyControl(strProp.Name, Configuration.getUIString(strProp.Name) + " " + Configuration.getUIString("text_prop_type"),
                                                                                          UserSettings.GetUserSettings().getString(strProp.Name), (String)strProp.DefaultValue,
                                                                                          Configuration.getUIString(strProp.Name + "_help"), Configuration.getUIStringStrict(strProp.Name + "_filter"),
                                                                                          Configuration.getUIStringStrict(strProp.Name + "_category")));
                }
                widgetCount++;
            }
            pad(widgetCount);
            widgetCount = 0;
            foreach (SettingsProperty boolProp in UserSettings.GetUserSettings().getProperties(typeof(Boolean), "enable", null))
            {
                Boolean defaultValue;
                Boolean.TryParse((String)boolProp.DefaultValue, out defaultValue);
                this.propertiesFlowLayoutPanel.Controls.Add(new BooleanPropertyControl(boolProp.Name, Configuration.getUIString(boolProp.Name) + " " + Configuration.getUIString("boolean_prop_type"),
                                                                                       UserSettings.GetUserSettings().getBoolean(boolProp.Name), defaultValue,
                                                                                       Configuration.getUIString(boolProp.Name + "_help"), Configuration.getUIStringStrict(boolProp.Name + "_filter"),
                                                                                       Configuration.getUIStringStrict(boolProp.Name + "_category")));
                widgetCount++;
            }
            pad(widgetCount);
            widgetCount = 0;
            foreach (SettingsProperty intProp in UserSettings.GetUserSettings().getProperties(typeof(int), "frequency", null))
            {
                int defaultValue;
                int.TryParse((String)intProp.DefaultValue, out defaultValue);
                this.propertiesFlowLayoutPanel.Controls.Add(new IntPropertyControl(intProp.Name, Configuration.getUIString(intProp.Name) + " " + Configuration.getUIString("integer_prop_type"),
                                                                                   UserSettings.GetUserSettings().getInt(intProp.Name), defaultValue,
                                                                                   Configuration.getUIString(intProp.Name + "_help"), Configuration.getUIStringStrict(intProp.Name + "_filter"),
                                                                                   Configuration.getUIStringStrict(intProp.Name + "_category")));
                widgetCount++;
            }
            pad(widgetCount);
            widgetCount = 0;
            foreach (SettingsProperty boolProp in UserSettings.GetUserSettings().getProperties(typeof(Boolean), null, "enable"))
            {
                Boolean defaultValue;
                Boolean.TryParse((String)boolProp.DefaultValue, out defaultValue);
                this.propertiesFlowLayoutPanel.Controls.Add(new BooleanPropertyControl(boolProp.Name, Configuration.getUIString(boolProp.Name) + " " + Configuration.getUIString("boolean_prop_type"),
                                                                                       UserSettings.GetUserSettings().getBoolean(boolProp.Name), defaultValue,
                                                                                       Configuration.getUIString(boolProp.Name + "_help"), Configuration.getUIStringStrict(boolProp.Name + "_filter"),
                                                                                       Configuration.getUIStringStrict(boolProp.Name + "_category")));
                widgetCount++;
            }
            pad(widgetCount);
            widgetCount = 0;
            foreach (SettingsProperty intProp in UserSettings.GetUserSettings().getProperties(typeof(int), null, "frequency"))
            {
                int defaultValue;
                int.TryParse((String)intProp.DefaultValue, out defaultValue);
                this.propertiesFlowLayoutPanel.Controls.Add(new IntPropertyControl(intProp.Name, Configuration.getUIString(intProp.Name) + " " + Configuration.getUIString("integer_prop_type"),
                                                                                   UserSettings.GetUserSettings().getInt(intProp.Name), defaultValue,
                                                                                   Configuration.getUIString(intProp.Name + "_help"), Configuration.getUIStringStrict(intProp.Name + "_filter"),
                                                                                   Configuration.getUIStringStrict(intProp.Name + "_category")));
                widgetCount++;
            }
            pad(widgetCount);
            widgetCount = 0;
            foreach (SettingsProperty floatProp in UserSettings.GetUserSettings().getProperties(typeof(float), null, null))
            {
                float defaultValue;
                float.TryParse((String)floatProp.DefaultValue, out defaultValue);
                this.propertiesFlowLayoutPanel.Controls.Add(new FloatPropertyControl(floatProp.Name, Configuration.getUIString(floatProp.Name) + " " + Configuration.getUIString("real_number_prop_type"),
                                                                                     UserSettings.GetUserSettings().getFloat(floatProp.Name), defaultValue,
                                                                                     Configuration.getUIString(floatProp.Name + "_help"), Configuration.getUIStringStrict(floatProp.Name + "_filter"),
                                                                                     Configuration.getUIStringStrict(floatProp.Name + "_category")));
                widgetCount++;
            }
            pad(widgetCount);
            widgetCount = 0;

            this.searchTextPrev               = DEFAULT_SEARCH_TEXT;
            this.gameFilterPrev               = GameEnum.UNKNOWN;
            this.specialFilterPrev            = SpecialFilter.UNKNOWN;
            this.categoryFilterPrev           = PropertyCategory.ALL; // Initialize this here, so that initial game filtering works.
            this.includeCommonPreferencesPrev = true;

            this.searchTextBox.Text       = DEFAULT_SEARCH_TEXT;
            this.searchTextBox.ForeColor  = Color.Gray;
            this.searchTextBox.GotFocus  += SearchTextBox_GotFocus;
            this.searchTextBox.LostFocus += SearchTextBox_LostFocus;
            this.searchTextBox.KeyDown   += SearchTextBox_KeyDown;
            this.exitButton.Select();

            this.KeyPreview = true;
            this.KeyDown   += PropertiesForm_KeyDown;

            this.DoubleBuffered = true;

            // Filtering setup.
            this.filterBox.Items.Clear();
            this.filterBox.Items.Add(new ComboBoxItem <SpecialFilter>()
            {
                Label = Configuration.getUIString("all_preferences_label"),
                Value = SpecialFilter.ALL_PREFERENCES
            });

            this.filterBox.Items.Add(new ComboBoxItem <SpecialFilter>()
            {
                Label = Configuration.getUIString("common_preferences_label"),
                Value = SpecialFilter.COMMON_PREFERENCES
            });

            lock (MainWindow.instanceLock)
            {
                if (MainWindow.instance != null)
                {
                    var currSelectedGameFriendlyName = MainWindow.instance.gameDefinitionList.Text;
                    foreach (var game in MainWindow.instance.gameDefinitionList.Items)
                    {
                        var friendlyGameName = game.ToString();
                        this.filterBox.Items.Add(new ComboBoxItem <GameEnum>()
                        {
                            Label = friendlyGameName,
                            Value = GameDefinition.getGameDefinitionForFriendlyName(friendlyGameName).gameEnum
                        });

                        if (friendlyGameName == currSelectedGameFriendlyName)
                        {
                            this.filterBox.SelectedIndex = this.filterBox.Items.Count - 1;
                        }
                    }
                }
            }

            // Special case for no game selected.
            if (this.filterBox.SelectedIndex == -1)
            {
                this.filterBox.SelectedIndex = 0;
                // No need to filter.
                this.specialFilterPrev = SpecialFilter.ALL_PREFERENCES;
            }

            // Category filter:
            this.categoriesBox.Items.Clear();
            this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>()
            {
                Label = Configuration.getUIString("all_categories_label"),
                Value = PropertyCategory.ALL
            });

            this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>()
            {
                Label = Configuration.getUIString("ui_startup_and_paths_category_label"),
                Value = PropertyCategory.UI_STARTUP_AND_PATHS
            });

            this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>()
            {
                Label = Configuration.getUIString("audio_voice_and_controllers_category_label"),
                Value = PropertyCategory.AUDIO_VOICE_AND_CONTROLLERS
            });

            this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>()
            {
                Label = Configuration.getUIString("spotter_category_label"),
                Value = PropertyCategory.SPOTTER
            });

            this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>()
            {
                Label = Configuration.getUIString("flags_and_rules_category_label"),
                Value = PropertyCategory.FLAGS_AND_RULES
            });

            this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>()
            {
                Label = Configuration.getUIString("message_frequences_category_label"),
                Value = PropertyCategory.MESSAGE_FREQUENCES
            });

            this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>()
            {
                Label = Configuration.getUIString("fuel_temps_and_damages_category_label"),
                Value = PropertyCategory.FUEL_TEMPS_AND_DAMAGES
            });

            this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>()
            {
                Label = Configuration.getUIString("timings_category_label"),
                Value = PropertyCategory.TIMINGS
            });

            this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>()
            {
                Label = Configuration.getUIString("pit_stops_and_multiclass_category_label"),
                Value = PropertyCategory.PIT_STOPS_AND_MULTICLASS
            });

            this.categoriesBox.Items.Add(new ComboBoxItem <PropertyCategory>()
            {
                Label = Configuration.getUIString("misc_category_label"),
                Value = PropertyCategory.MISC
            });

            this.categoriesBox.SelectedIndex = 0;

            this.categoriesBox.SelectedValueChanged += this.CategoriesBox_SelectedValueChanged;

            this.propertiesFlowLayoutPanel.ResumeLayout(false);
            this.ResumeLayout(false);
        }