Esempio n. 1
0
        /// <summary>
        /// Called when we change the flag of a mission or in general.
        /// This will upload the flag to the server.
        /// </summary>
        private static void HandleFlagChangeEvent(string flagUrl)
        {
            SettingsSystem.CurrentSettings.SelectedFlag = flagUrl;
            SettingsSystem.SaveSettings();

            System.SendFlag(flagUrl);
        }
Esempio n. 2
0
        /// <summary>
        /// Called when we change the flag of a mission or in general.
        /// This will upload the flag to the server.
        /// </summary>
        private static void HandleFlagChangeEvent(string flagUrl)
        {
            SettingsSystem.CurrentSettings.SelectedFlag = flagUrl;
            SettingsSystem.SaveSettings();

            //If it's not a LMP flag don't sync it.
            if (!flagUrl.ToLower().StartsWith("lunamultiplayer/flags/"))
            {
                return;
            }

            var flagName     = flagUrl.Substring("LunaMultiPlayer/Flags/".Length) + ".png";
            var fullFlagPath = CommonUtil.CombinePaths(FlagSystem.FlagPath, flagName);

            //If the flag is owned by someone else don't sync it
            if (System.ServerFlags.TryGetValue(flagName, out var existingFlag) && existingFlag.Owner != SettingsSystem.CurrentSettings.PlayerName)
            {
                return;
            }

            if (File.Exists(fullFlagPath))
            {
                //Don't send the flag when the SHA sum already matches as that would mean that the server already has it
                if (existingFlag != null && existingFlag.ShaSum == Common.CalculateSha256FileHash(fullFlagPath))
                {
                    return;
                }

                LunaLog.Log($"[LMP]: Uploading {Path.GetFileName(fullFlagPath)}");

                System.MessageSender.SendMessage(System.MessageSender.GetFlagMessageData(flagName, fullFlagPath));
            }
        }
Esempio n. 3
0
        private void DrawDebugSwitches()
        {
#if DEBUG
            var d1 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug1, "D1", ButtonStyle);
            if (d1 != SettingsSystem.CurrentSettings.Debug1)
            {
                SettingsSystem.CurrentSettings.Debug1 = d1;
                SettingsSystem.SaveSettings();
            }
            var d2 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug2, "D2", ButtonStyle);
            if (d2 != SettingsSystem.CurrentSettings.Debug2)
            {
                SettingsSystem.CurrentSettings.Debug2 = d2;
                SettingsSystem.SaveSettings();
            }
            var d3 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug3, "D3", ButtonStyle);
            if (d3 != SettingsSystem.CurrentSettings.Debug3)
            {
                SettingsSystem.CurrentSettings.Debug3 = d3;
                SettingsSystem.SaveSettings();
            }
            var d4 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug4, "D4", ButtonStyle);
            if (d4 != SettingsSystem.CurrentSettings.Debug4)
            {
                SettingsSystem.CurrentSettings.Debug4 = d4;
                SettingsSystem.SaveSettings();
            }
            var d5 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug5, "D5", ButtonStyle);
            if (d5 != SettingsSystem.CurrentSettings.Debug5)
            {
                SettingsSystem.CurrentSettings.Debug5 = d5;
                SettingsSystem.SaveSettings();
            }
            var d6 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug6, "D6", ButtonStyle);
            if (d6 != SettingsSystem.CurrentSettings.Debug6)
            {
                SettingsSystem.CurrentSettings.Debug6 = d6;
                SettingsSystem.SaveSettings();
            }
            var d7 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug7, "D7", ButtonStyle);
            if (d7 != SettingsSystem.CurrentSettings.Debug7)
            {
                SettingsSystem.CurrentSettings.Debug7 = d7;
                SettingsSystem.SaveSettings();
            }
            var d8 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug8, "D8", ButtonStyle);
            if (d8 != SettingsSystem.CurrentSettings.Debug8)
            {
                SettingsSystem.CurrentSettings.Debug8 = d8;
                SettingsSystem.SaveSettings();
            }
            var d9 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug9, "D9", ButtonStyle);
            if (d9 != SettingsSystem.CurrentSettings.Debug9)
            {
                SettingsSystem.CurrentSettings.Debug9 = d9;
                SettingsSystem.SaveSettings();
            }
#endif
        }
Esempio n. 4
0
        private void DrawDebugSwitches()
        {
#if DEBUG
            var d1 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug1, StatusTexts.Debug1BtnTxt, ButtonStyle);
            if (d1 != SettingsSystem.CurrentSettings.Debug1)
            {
                SettingsSystem.CurrentSettings.Debug1 = d1;
                SettingsSystem.SaveSettings();
            }
            var d2 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug2, StatusTexts.Debug2BtnTxt, ButtonStyle);
            if (d2 != SettingsSystem.CurrentSettings.Debug2)
            {
                SettingsSystem.CurrentSettings.Debug2 = d2;
                SettingsSystem.SaveSettings();
            }
            var d3 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug3, StatusTexts.Debug3BtnTxt, ButtonStyle);
            if (d3 != SettingsSystem.CurrentSettings.Debug3)
            {
                SettingsSystem.CurrentSettings.Debug3 = d3;
                SettingsSystem.SaveSettings();
            }
            var d4 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug4, StatusTexts.Debug4BtnTxt, ButtonStyle);
            if (d4 != SettingsSystem.CurrentSettings.Debug4)
            {
                SettingsSystem.CurrentSettings.Debug4 = d4;
                SettingsSystem.SaveSettings();
            }
            var d5 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug5, StatusTexts.Debug5BtnTxt, ButtonStyle);
            if (d5 != SettingsSystem.CurrentSettings.Debug5)
            {
                SettingsSystem.CurrentSettings.Debug5 = d5;
                SettingsSystem.SaveSettings();
            }
            var d6 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug6, StatusTexts.Debug6BtnTxt, ButtonStyle);
            if (d6 != SettingsSystem.CurrentSettings.Debug6)
            {
                SettingsSystem.CurrentSettings.Debug6 = d6;
                SettingsSystem.SaveSettings();
            }
            var d7 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug7, StatusTexts.Debug7BtnTxt, ButtonStyle);
            if (d7 != SettingsSystem.CurrentSettings.Debug7)
            {
                SettingsSystem.CurrentSettings.Debug7 = d7;
                SettingsSystem.SaveSettings();
            }
            var d8 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug8, StatusTexts.Debug8BtnTxt, ButtonStyle);
            if (d8 != SettingsSystem.CurrentSettings.Debug8)
            {
                SettingsSystem.CurrentSettings.Debug8 = d8;
                SettingsSystem.SaveSettings();
            }
            var d9 = GUILayout.Toggle(SettingsSystem.CurrentSettings.Debug9, StatusTexts.Debug9BtnTxt, ButtonStyle);
            if (d9 != SettingsSystem.CurrentSettings.Debug9)
            {
                SettingsSystem.CurrentSettings.Debug9 = d9;
                SettingsSystem.SaveSettings();
            }
#endif
        }
Esempio n. 5
0
 private void Awake()
 {
     _settingsSystem = FindObjectOfType <SettingsSystem>();
     videoSettingsButton.onClick.AddListener(ToggleVideoSettingsUI);
     controlSettingsButton.onClick.AddListener(ToggleControlSettingsUI);
     saveSettingsButton.onClick.AddListener(SaveSettings);
     resetSettingsButton.onClick.AddListener(ResetSettings);
     returnFromSettingsButton.onClick.AddListener(Return);
 }
Esempio n. 6
0
 private void DrawGeneralSettings()
 {
     _showGeneralSettings = GUILayout.Toggle(_showGeneralSettings, LocalizationContainer.OptionsWindowText.GeneralSettings, ButtonStyle);
     if (_showGeneralSettings)
     {
         var settingSyncCheck = GUILayout.Toggle(SettingsSystem.CurrentSettings.IgnoreSyncChecks, LocalizationContainer.OptionsWindowText.IgnoreSyncChecks, "toggle");
         if (settingSyncCheck != SettingsSystem.CurrentSettings.IgnoreSyncChecks)
         {
             SettingsSystem.CurrentSettings.IgnoreSyncChecks = settingSyncCheck;
             SettingsSystem.SaveSettings();
         }
     }
 }
        private void DrawServerEntry(int serverPos)
        {
            SelectedIndex = serverPos;
            GUILayout.BeginVertical(BoxStyle);
            GUILayout.BeginHorizontal();
            GUILayout.Label(LocalizationContainer.ConnectionWindowText.Name, LabelOptions);
            var newServerName = GUILayout.TextArea(SettingsSystem.CurrentSettings.Servers[serverPos].Name, TextAreaStyle);

            if (newServerName != SettingsSystem.CurrentSettings.Servers[serverPos].Name)
            {
                SettingsSystem.CurrentSettings.Servers[serverPos].Name = newServerName;
                SettingsSystem.SaveSettings();
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label(LocalizationContainer.ConnectionWindowText.Address, LabelOptions);
            var newAddress = GUILayout.TextArea(SettingsSystem.CurrentSettings.Servers[serverPos].Address, TextAreaStyle);

            if (newAddress != SettingsSystem.CurrentSettings.Servers[serverPos].Address)
            {
                SettingsSystem.CurrentSettings.Servers[serverPos].Address = newAddress;
                SettingsSystem.SaveSettings();
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label(LocalizationContainer.ConnectionWindowText.Port, LabelOptions);
            var port = GUILayout.TextArea(SettingsSystem.CurrentSettings.Servers[serverPos].Port.ToString(), TextAreaStyle);

            if (int.TryParse(port, out var parsedPort))
            {
                if (parsedPort != SettingsSystem.CurrentSettings.Servers[serverPos].Port)
                {
                    SettingsSystem.CurrentSettings.Servers[serverPos].Port = parsedPort;
                    SettingsSystem.SaveSettings();
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label(LocalizationContainer.ConnectionWindowText.Password, LabelOptions);
            var newPassword = GUILayout.PasswordField(SettingsSystem.CurrentSettings.Servers[serverPos].Password, '*', 30, TextAreaStyle);

            if (newPassword != SettingsSystem.CurrentSettings.Servers[serverPos].Password)
            {
                SettingsSystem.CurrentSettings.Servers[serverPos].Password = newPassword;
                SettingsSystem.SaveSettings();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
Esempio n. 8
0
        public static void SpawnDialog()
        {
            var disclaimerText = "Luna Multi Player (LMP) shares the following personally identifiable information with the master server and any server you connect to.\n";

            disclaimerText += "a) Your player name you connect with.\n";
            disclaimerText += "b) Your player token (A randomly generated string to authenticate you).\n";
            disclaimerText += "c) Your IP address is logged on the server console.\n";
            disclaimerText += "\n";
            disclaimerText += "LMP does not contact any other computer than the server you are connecting to and the master server.\n";
            disclaimerText += "In order to use LMP, you must allow it to use this info\n";
            disclaimerText += "\n";
            disclaimerText += "For more information - see the KSP addon rules\n";

            PopupDialog.SpawnPopupDialog(
                new MultiOptionDialog("DisclaimerWindow", disclaimerText, "LunaMultiPlayer - Disclaimer",
                                      HighLogic.UISkin,
                                      new Rect(.5f, .5f, 425f, 150f),
                                      new DialogGUIFlexibleSpace(),
                                      new DialogGUIVerticalLayout(
                                          new DialogGUIHorizontalLayout(
                                              new DialogGUIButton("Accept",
                                                                  delegate
            {
                SettingsSystem.CurrentSettings.DisclaimerAccepted = true;
                SystemsContainer.Get <MainSystem>().Enabled       = true;
                SettingsSystem.SaveSettings();
            }
                                                                  ),
                                              new DialogGUIFlexibleSpace(),
                                              new DialogGUIButton("Open the KSP Addon rules in browser",
                                                                  delegate
            {
                Application.OpenURL("http://forum.kerbalspaceprogram.com/index.php?/topic/154851-add-on-posting-rules-march-8-2017/");
            }
                                                                  , false),
                                              new DialogGUIFlexibleSpace(),
                                              new DialogGUIButton("Decline",
                                                                  delegate
            {
                LunaLog.LogError("[LMP]: User did not accept disclaimer");
            }
                                                                  )
                                              )
                                          )
                                      ),
                true,
                HighLogic.UISkin
                );
        }
Esempio n. 9
0
        /// <summary>
        /// Play cutscene and tutorial (if needed)
        /// </summary>
        void ShowCutscene(Action onCutsceneEnd)
        {
            State = GameState.Cutscene;

            // disable player object
            CurrentPlayer.gameObject.SetActive(false);

            // don't play cutscene next time
            if (Settings.GameShowCutscene)
            {
                SettingsSystem.ChangeSetting(SettingsList.Setting_Key_Game_ShowCutscene);
            }

            cutsceneManager.Play(onCutsceneEnd);
        }
Esempio n. 10
0
        private void DrawPlayerNameSection()
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(LocalizationContainer.ConnectionWindowText.PlayerName, LabelOptions);
            GUI.enabled = MainSystem.NetworkState <= ClientState.Disconnected;
            var newPlayerName = GUILayout.TextArea(SettingsSystem.CurrentSettings.PlayerName, 32, TextAreaStyle); // Max 32 characters

            if (newPlayerName != SettingsSystem.CurrentSettings.PlayerName)
            {
                SettingsSystem.CurrentSettings.PlayerName = newPlayerName.Trim().Replace("\n", "");
                SettingsSystem.SaveSettings();
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();
        }
Esempio n. 11
0
        public LevelEntities ToScene(DreamSystem dreamSystem = null, SettingsSystem settingsSystem = null)
        {
            _levelObject = new GameObject("Level");
            LevelEntities levelEntities = _levelObject.AddComponent <LevelEntities>();

            levelEntities.DreamSystem    = dreamSystem;
            levelEntities.SettingsSystem = settingsSystem;
            foreach (var entity in Entities)
            {
                GameObject entityObj = entity.CreateGameObject(levelEntities);
                entityObj.transform.SetParent(_levelObject.transform);
            }

            return(levelEntities);
        }
Esempio n. 12
0
 public static void SpawnDialog()
 {
     PopupDialog.SpawnPopupDialog(
         new MultiOptionDialog("DisclaimerWindow", LocalizationContainer.DisclaimerDialogText.Text, LocalizationContainer.DisclaimerDialogText.Title,
                               HighLogic.UISkin,
                               new Rect(.5f, .5f, 425f, 150f),
                               new DialogGUIFlexibleSpace(),
                               new DialogGUIVerticalLayout(
                                   new DialogGUIHorizontalLayout(
                                       new DialogGUIButton(LocalizationContainer.DisclaimerDialogText.Accept,
                                                           delegate
     {
         SettingsSystem.CurrentSettings.DisclaimerAccepted = true;
         MainSystem.Singleton.Enabled = true;
         SettingsSystem.SaveSettings();
     }
                                                           ),
                                       new DialogGUIFlexibleSpace(),
                                       new DialogGUIButton(LocalizationContainer.DisclaimerDialogText.OpenUrl,
                                                           delegate
     {
         Application.OpenURL("http://forum.kerbalspaceprogram.com/index.php?/topic/154851-add-on-posting-rules-march-8-2017/");
     }
                                                           , false),
                                       new DialogGUIFlexibleSpace(),
                                       new DialogGUIButton(LocalizationContainer.DisclaimerDialogText.Decline,
                                                           delegate
     {
         LunaLog.LogError("[LMP]: User did not accept disclaimer");
     }
                                                           ),
                                       new DialogGUIFlexibleSpace(),
                                       new DialogGUIButton(LocalizationContainer.GetCurrentLanguageAsText(),
                                                           delegate
     {
         LocalizationContainer.LoadLanguage(LocalizationContainer.GetNextLanguage());
         SettingsSystem.CurrentSettings.Language = LocalizationContainer.CurrentLanguage;
         SettingsSystem.SaveSettings();
         SpawnDialog();
     }
                                                           )
                                       )
                                   )
                               ),
         true,
         HighLogic.UISkin
         );
 }
Esempio n. 13
0
        void ShowTutorial()
        {
            State = GameState.Tutorial;

            // don't show tutorial next time
            if (Settings.GameShowTutorial)
            {
                SettingsSystem.ChangeSetting(SettingsList.Setting_Key_Game_ShowTutorial);
            }

            // at start of tutorial: player has zero speed and default position
            ActivateGameplay(false, true, false);

            // on the end of tutorial: enable spawners
            tutorialManager.StartTutorial(CurrentPlayer, spawnersController.RestartSpawn);
        }
    // Use this for initialization
    private void Start()
    {
        SettingsSystem.SetAnisotropicToggler(aniosotropicToggler);
        SettingsSystem.SetFullScreenToggler(fullScreenToggler);
        SettingsSystem.SetVSyncToggler(vsyncToggler);

        SettingsSystem.SetMusicToggler(musicToggler, mixer, musicFloat);
        SettingsSystem.SetSoundFXToggler(sfxToggler, mixer, sfxFloat);
        SettingsSystem.SetMusicVolumeSlider(musicSlider, mixer, musicFloat);
        SettingsSystem.SetSoundFXVolumeSlider(sfxSlider, mixer, sfxFloat);

        SettingsSystem.SetAntialiasingDropdown(antialiasing);
        SettingsSystem.SetResolutionDropdown(resolution);
        SettingsSystem.SetShadowQualityDropdown(shadowQuality);
        SettingsSystem.SetShadowResolutionDropdown(shadowResolution);
        SettingsSystem.SetTextureDropdown(texture);
        SettingsSystem.SetQualityDropdown(quality, QualitySettings.GetQualityLevel());
        SettingsSystem.Refresh();
    }
Esempio n. 15
0
 public static void SpawnDialog()
 {
     PopupDialog.SpawnPopupDialog(
         new MultiOptionDialog("DisclaimerWindow", LocalizationContainer.DisclaimerDialogText.Text, LocalizationContainer.DisclaimerDialogText.Title,
                               HighLogic.UISkin,
                               new Rect(.5f, .5f, 425f, 150f),
                               new DialogGUIFlexibleSpace(),
                               new DialogGUIVerticalLayout(
                                   new DialogGUIHorizontalLayout(
                                       new DialogGUIButton(LocalizationContainer.DisclaimerDialogText.Accept,
                                                           delegate
     {
         SettingsSystem.CurrentSettings.DisclaimerAccepted = true;
         MainSystem.Singleton.Enabled = true;
         SettingsSystem.SaveSettings();
         MainSystem.Singleton.StartCoroutine(UpdateHandler.CheckForUpdates());
     }
                                                           ),
                                       new DialogGUIFlexibleSpace(),
                                       new DialogGUIButton(LocalizationContainer.DisclaimerDialogText.Decline,
                                                           delegate
     {
         LunaLog.LogError("[LMP]: User did not accept disclaimer");
     }
                                                           ),
                                       new DialogGUIFlexibleSpace(),
                                       new DialogGUIButton(LocalizationContainer.GetCurrentLanguageAsText(),
                                                           delegate
     {
         LocalizationContainer.LoadLanguage(LocalizationContainer.GetNextLanguage());
         SettingsSystem.CurrentSettings.Language = LocalizationContainer.CurrentLanguage;
         SettingsSystem.SaveSettings();
         SpawnDialog();
     }
                                                           )
                                       )
                                   )
                               ),
         true,
         HighLogic.UISkin
         );
 }
Esempio n. 16
0
        public static void DrawFilters()
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            var hideFullServers = GUILayout.Toggle(SettingsSystem.CurrentSettings.ServerFilters.HideFullServers, LocalizationContainer.ServerListFiltersText.HideFullServers);

            if (hideFullServers != SettingsSystem.CurrentSettings.ServerFilters.HideFullServers)
            {
                SettingsSystem.CurrentSettings.ServerFilters.HideFullServers = hideFullServers;
                SettingsSystem.SaveSettings();
            }
            GUILayout.FlexibleSpace();
            var hideEmptyServers = GUILayout.Toggle(SettingsSystem.CurrentSettings.ServerFilters.HideEmptyServers, LocalizationContainer.ServerListFiltersText.HideEmptyServers);

            if (hideEmptyServers != SettingsSystem.CurrentSettings.ServerFilters.HideEmptyServers)
            {
                SettingsSystem.CurrentSettings.ServerFilters.HideEmptyServers = hideEmptyServers;
                SettingsSystem.SaveSettings();
            }
            GUILayout.FlexibleSpace();
            var hidePrivateServers = GUILayout.Toggle(SettingsSystem.CurrentSettings.ServerFilters.HidePrivateServers, LocalizationContainer.ServerListFiltersText.HidePrivateServers);

            if (hidePrivateServers != SettingsSystem.CurrentSettings.ServerFilters.HidePrivateServers)
            {
                SettingsSystem.CurrentSettings.ServerFilters.HidePrivateServers = hidePrivateServers;
                SettingsSystem.SaveSettings();
            }
            GUILayout.FlexibleSpace();
            var dedicatedServersOnly = GUILayout.Toggle(SettingsSystem.CurrentSettings.ServerFilters.DedicatedServersOnly, LocalizationContainer.ServerListFiltersText.DedicatedServersOnly);

            if (dedicatedServersOnly != SettingsSystem.CurrentSettings.ServerFilters.DedicatedServersOnly)
            {
                SettingsSystem.CurrentSettings.ServerFilters.DedicatedServersOnly = dedicatedServersOnly;
                SettingsSystem.SaveSettings();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
Esempio n. 17
0
        /// <summary>
        /// Create or find systems
        /// </summary>
        void CreateSystems()
        {
            // find objects
            Background      = FindObjectOfType <BackgroundController>();
            cutsceneManager = FindObjectOfType <CutsceneManager>();
            tutorialManager = FindObjectOfType <TutorialManager>();
            audioManager    = FindObjectOfType <AudioManager>();

            WeaponsStats = new AllWeaponsStats(weaponsList.Data);
            AmmoStats    = new AllAmmoStats(ammoList.Data);

            spawnersController = new SpawnersController();
            SettingsSystem     = new SettingsSystem(Settings);
            Shop = new ShopSystem();
            audioSettingsHandler = new AudioSettingsHandler();
            timeController       = new TimeController(Time.fixedDeltaTime);

            ObjectPool    = new ObjectPool(objectPoolPrefabs, transform);
            ParticlesPool = new ParticlesPool(particlesPoolPrefabs, transform);

#if UNITY_ANDROID && !UNITY_EDITOR
            OnlineService = new PlayGamesService();
#endif
        }
Esempio n. 18
0
        private static void DrawGeneralSettings()
        {
            _showGeneralSettings = GUILayout.Toggle(_showGeneralSettings, LocalizationContainer.OptionsWindowText.GeneralSettings, ToggleButtonStyle);
            if (_showGeneralSettings)
            {
                GUILayout.Label($"{LocalizationContainer.OptionsWindowText.ChatBuffer} {SettingsSystem.CurrentSettings.ChatBuffer}");

                GUI.enabled = MainSystem.NetworkState <= ClientState.Disconnected;
                var chatBuffer = (int)Math.Round(GUILayout.HorizontalScrollbar(SettingsSystem.CurrentSettings.ChatBuffer, 10, 1, 500));
                if (chatBuffer != SettingsSystem.CurrentSettings.ChatBuffer)
                {
                    SettingsSystem.CurrentSettings.ChatBuffer = chatBuffer;
                    SettingsSystem.SaveSettings();
                }
                GUI.enabled = true;

                var settingSyncCheck = GUILayout.Toggle(SettingsSystem.CurrentSettings.IgnoreSyncChecks, LocalizationContainer.OptionsWindowText.IgnoreSyncChecks);
                if (settingSyncCheck != SettingsSystem.CurrentSettings.IgnoreSyncChecks)
                {
                    SettingsSystem.CurrentSettings.IgnoreSyncChecks = settingSyncCheck;
                    SettingsSystem.SaveSettings();
                }
            }
        }
Esempio n. 19
0
        private void DrawCustomServers()
        {
            GUILayout.Label(LocalizationContainer.ConnectionWindowText.CustomServers);
            GUILayout.BeginVertical(BoxStyle);

            if (GUILayout.Button(PlusIcon, ButtonStyle))
            {
                SettingsSystem.CurrentSettings.Servers.Insert(0, new ServerEntry());
                SettingsSystem.SaveSettings();
            }
            GUILayout.Space(15);

            ScrollPos = GUILayout.BeginScrollView(ScrollPos, GUILayout.Width(WindowWidth - 5),
                                                  GUILayout.Height(WindowHeight - 100));
            for (var serverPos = 0; serverPos < SettingsSystem.CurrentSettings.Servers.Count; serverPos++)
            {
                GUILayout.BeginHorizontal();
                var selected = GUILayout.Toggle(SelectedIndex == serverPos,
                                                SettingsSystem.CurrentSettings.Servers[serverPos].Name, ButtonStyle);
                if (GUILayout.Button(DeleteIcon, ButtonStyle, GUILayout.Width(35)))
                {
                    SettingsSystem.CurrentSettings.Servers.RemoveAt(SelectedIndex);
                    SettingsSystem.SaveSettings();
                }
                else
                {
                    GUILayout.EndHorizontal();
                    if (selected)
                    {
                        DrawServerEntry(serverPos);
                    }
                }
            }
            GUILayout.EndScrollView();
            GUILayout.EndVertical();
        }
Esempio n. 20
0
        private void DrawNetworkSettings()
        {
            _showAdvancedNetworkSettings = GUILayout.Toggle(_showAdvancedNetworkSettings, LocalizationContainer.OptionsWindowText.NetworkSettings, ButtonStyle);
            if (_showAdvancedNetworkSettings)
            {
                if (MainSystem.NetworkState > ClientState.Disconnected)
                {
                    GUILayout.Label(LocalizationContainer.OptionsWindowText.CannotChangeWhileConnected);
                }

                GUILayout.Label($"{LocalizationContainer.OptionsWindowText.Mtu} {NetworkMain.Config.MaximumTransmissionUnit}");
                if (MainSystem.NetworkState <= ClientState.Disconnected)
                {
                    if (NetworkMain.ClientConnection.Status != NetPeerStatus.NotRunning)
                    {
                        if (GUILayout.Button(LocalizationContainer.OptionsWindowText.ResetNetwork))
                        {
                            NetworkMain.ResetNetworkSystem();
                        }
                    }
                    else
                    {
                        var mtuValue = (int)Math.Round(GUILayout.HorizontalScrollbar(SettingsSystem.CurrentSettings.Mtu, 0, 1, NetworkMain.MaxMtuSize));
                        if (mtuValue != SettingsSystem.CurrentSettings.Mtu)
                        {
                            NetworkMain.Config.MaximumTransmissionUnit = SettingsSystem.CurrentSettings.Mtu = mtuValue;
                            SettingsSystem.SaveSettings();
                        }

                        var autoExpandValue = GUILayout.Toggle(SettingsSystem.CurrentSettings.AutoExpandMtu, LocalizationContainer.OptionsWindowText.AutoExpandMtu);
                        if (autoExpandValue != SettingsSystem.CurrentSettings.AutoExpandMtu)
                        {
                            NetworkMain.Config.AutoExpandMTU = SettingsSystem.CurrentSettings.AutoExpandMtu = autoExpandValue;
                            SettingsSystem.SaveSettings();
                        }
                    }
                }

                if (SettingsSystem.CurrentSettings.TimeoutSeconds == float.MaxValue)
                {
                    GUILayout.Label($"{LocalizationContainer.OptionsWindowText.ConnectionTimeout} ∞");
                }
                else
                {
                    GUILayout.Label($"{LocalizationContainer.OptionsWindowText.ConnectionTimeout} {NetworkMain.Config.ConnectionTimeout} sec");
                }
                if (MainSystem.NetworkState <= ClientState.Disconnected)
                {
                    _infiniteTimeout = SettingsSystem.CurrentSettings.TimeoutSeconds == float.MaxValue;

                    GUI.enabled = !_infiniteTimeout;
                    var newTimeoutVal = (int)Math.Round(GUILayout.HorizontalScrollbar(SettingsSystem.CurrentSettings.TimeoutSeconds, 0, NetworkMain.Config.PingInterval, 120));
                    if (newTimeoutVal != SettingsSystem.CurrentSettings.TimeoutSeconds)
                    {
                        NetworkMain.Config.ConnectionTimeout = SettingsSystem.CurrentSettings.TimeoutSeconds = newTimeoutVal;
                        SettingsSystem.SaveSettings();
                    }
                    GUI.enabled = true;

                    _infiniteTimeout = GUILayout.Toggle(_infiniteTimeout, "∞", "toggle");
                    if (_infiniteTimeout)
                    {
                        NetworkMain.Config.ConnectionTimeout = SettingsSystem.CurrentSettings.TimeoutSeconds = float.MaxValue;
                        SettingsSystem.SaveSettings();
                    }
                }
            }
        }
Esempio n. 21
0
 public void Construct(GameInputSystem inputSystem, SettingsSystem settingsSystem, WeaponSystem weaponSystem)
 {
     _inputSystem  = inputSystem;
     _weaponSystem = weaponSystem;
     _settings     = settingsSystem;
 }
Esempio n. 22
0
        private void NetworkUpdate()
        {
            switch (MainSystem.NetworkState)
            {
            case ClientState.DisconnectRequested:
            case ClientState.Disconnected:
                break;

            case ClientState.Connecting:
                ChangeRoutineExecutionInterval(RoutineExecution.Update, nameof(NetworkUpdate), 0);
                return;

            case ClientState.Connected:
                HandshakeSystem.Singleton.Enabled = true;
                MainSystem.Singleton.Status       = "Connected";
                MainSystem.NetworkState           = ClientState.Handshaking;
                HandshakeSystem.Singleton.MessageSender.SendHandshakeRequest();
                _lastStateTime = LunaComputerTime.UtcNow;
                break;

            case ClientState.Handshaking:
                MainSystem.Singleton.Status = "Waiting for handshake response";
                if (ConnectionIsStuck(60000))
                {
                    LunaLog.Log("[LMP]: Failed to get a handshake response after 60 seconds. Sending the handshake again...");
                    MainSystem.NetworkState = ClientState.Connected;
                }
                break;

            case ClientState.Handshaked:
                MainSystem.Singleton.Status      = "Handshaking successful";
                SettingsSystem.Singleton.Enabled = true;
                MainSystem.NetworkState          = ClientState.SyncingSettings;
                SettingsSystem.Singleton.MessageSender.SendSettingsRequest();

                _lastStateTime = LunaComputerTime.UtcNow;
                break;

            case ClientState.SyncingSettings:
                MainSystem.Singleton.Status = "Syncing settings";
                if (ConnectionIsStuck())
                {
                    MainSystem.NetworkState = ClientState.Handshaked;
                }
                break;

            case ClientState.SettingsSynced:
                MainSystem.Singleton.Status = "Settings synced";
                if (SettingsSystem.ValidateSettings())
                {
                    KerbalSystem.Singleton.Enabled      = true;
                    VesselProtoSystem.Singleton.Enabled = true;
                    VesselSyncSystem.Singleton.Enabled  = true;
                    VesselSyncSystem.Singleton.MessageSender.SendVesselsSyncMsg();
                    MainSystem.NetworkState = ClientState.SyncingKerbals;
                    KerbalSystem.Singleton.MessageSender.SendKerbalsRequest();
                    _lastStateTime = LunaComputerTime.UtcNow;
                }
                break;

            case ClientState.SyncingKerbals:
                MainSystem.Singleton.Status = "Syncing kerbals";
                if (ConnectionIsStuck(10000))
                {
                    MainSystem.NetworkState = ClientState.SettingsSynced;
                }
                break;

            case ClientState.KerbalsSynced:
                MainSystem.Singleton.Status  = "Kerbals synced";
                WarpSystem.Singleton.Enabled = true;
                MainSystem.NetworkState      = ClientState.SyncingWarpsubspaces;
                WarpSystem.Singleton.MessageSender.SendWarpSubspacesRequest();
                _lastStateTime = LunaComputerTime.UtcNow;
                break;

            case ClientState.SyncingWarpsubspaces:
                MainSystem.Singleton.Status = "Syncing warp subspaces";
                if (ConnectionIsStuck())
                {
                    MainSystem.NetworkState = ClientState.KerbalsSynced;
                }
                break;

            case ClientState.WarpsubspacesSynced:
                MainSystem.Singleton.Status         = "Warp subspaces synced";
                PlayerColorSystem.Singleton.Enabled = true;
                MainSystem.NetworkState             = ClientState.SyncingColors;
                PlayerColorSystem.Singleton.MessageSender.SendColorsRequest();
                _lastStateTime = LunaComputerTime.UtcNow;
                break;

            case ClientState.SyncingColors:
                MainSystem.Singleton.Status = "Syncing player colors";
                if (ConnectionIsStuck())
                {
                    MainSystem.NetworkState = ClientState.WarpsubspacesSynced;
                }
                break;

            case ClientState.ColorsSynced:
                MainSystem.Singleton.Status  = "Player colors synced";
                FlagSystem.Singleton.Enabled = true;
                MainSystem.NetworkState      = ClientState.SyncingFlags;
                FlagSystem.Singleton.MessageSender.SendFlagsRequest();
                _lastStateTime = LunaComputerTime.UtcNow;
                break;

            case ClientState.SyncingFlags:
                MainSystem.Singleton.Status = "Syncing flags";
                if (ConnectionIsStuck(10000))
                {
                    MainSystem.NetworkState = ClientState.ColorsSynced;
                }
                break;

            case ClientState.FlagsSynced:
                MainSystem.Singleton.Status              = "Flags synced";
                StatusSystem.Singleton.Enabled           = true;
                PlayerConnectionSystem.Singleton.Enabled = true;
                MainSystem.NetworkState = ClientState.SyncingPlayers;
                StatusSystem.Singleton.MessageSender.SendPlayersRequest();
                _lastStateTime = LunaComputerTime.UtcNow;
                break;

            case ClientState.SyncingPlayers:
                MainSystem.Singleton.Status = "Syncing players";
                if (ConnectionIsStuck())
                {
                    MainSystem.NetworkState = ClientState.FlagsSynced;
                }
                break;

            case ClientState.PlayersSynced:
                MainSystem.Singleton.Status      = "Players synced";
                ScenarioSystem.Singleton.Enabled = true;
                MainSystem.NetworkState          = ClientState.SyncingScenarios;
                ScenarioSystem.Singleton.MessageSender.SendScenariosRequest();
                _lastStateTime = LunaComputerTime.UtcNow;
                break;

            case ClientState.SyncingScenarios:
                MainSystem.Singleton.Status = "Syncing scenarios";
                if (ConnectionIsStuck(10000))
                {
                    MainSystem.NetworkState = ClientState.PlayersSynced;
                }
                break;

            case ClientState.ScenariosSynced:
                MainSystem.Singleton.Status  = "Scenarios synced";
                MainSystem.NetworkState      = ClientState.SyncingLocks;
                LockSystem.Singleton.Enabled = true;
                LockSystem.Singleton.MessageSender.SendLocksRequest();
                _lastStateTime = LunaComputerTime.UtcNow;
                break;

            case ClientState.SyncingLocks:
                MainSystem.Singleton.Status = "Syncing locks";
                if (ConnectionIsStuck())
                {
                    MainSystem.NetworkState = ClientState.ScenariosSynced;
                }
                break;

            case ClientState.LocksSynced:
                MainSystem.Singleton.Status    = "Starting";
                MainSystem.Singleton.StartGame = true;
                MainSystem.NetworkState        = ClientState.Starting;
                break;

            case ClientState.Starting:
                //Once we start the game we don't need to run this routine on every frame
                ChangeRoutineExecutionInterval(RoutineExecution.Update, nameof(NetworkUpdate), 1500);
                MainSystem.Singleton.Status = "Running";
                CommonUtil.Reserve20Mb();
                LunaLog.Log("[LMP]: All systems up and running. Поехали!");
                if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
                {
                    MainSystem.NetworkState = ClientState.Running;
                    NetworkMain.DeleteAllTheControlLocksSoTheSpaceCentreBugGoesAway();
                }
                break;

            case ClientState.Running:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 23
0
 void Awake()
 {
     Instance = this;
     DontDestroyOnLoad(gameObject);
 }
Esempio n. 24
0
        public void MainSystemUpdate()
        {
            LunaLog.ProcessLogMessages();

            var startClock = ProfilerData.LmpReferenceTime.ElapsedTicks;

            if (!Enabled)
            {
                return;
            }

            try
            {
                if (HighLogic.LoadedScene == GameScenes.MAINMENU)
                {
                    if (!SystemsContainer.Get <ModSystem>().DllListBuilt)
                    {
                        SystemsContainer.Get <ModSystem>().DllListBuilt = true;
                        SystemsContainer.Get <ModSystem>().BuildDllFileList();
                    }
                    if (!LmpSaveChecked)
                    {
                        LmpSaveChecked = true;
                        SetupBlankGameIfNeeded();
                    }
                }

                HandleWindowEvents();
                SystemsHandler.Update();
                WindowsHandler.Update();

                //Force quit
                if (ForceQuit)
                {
                    ForceQuit   = false;
                    GameRunning = false;
                    FireReset   = true;
                    StopGame();
                }

                if (DisplayDisconnectMessage)
                {
                    ShowDisconnectMessage();
                }

                //Normal quit
                if (GameRunning)
                {
                    if (HighLogic.LoadedScene == GameScenes.MAINMENU)
                    {
                        GameRunning = false;
                        FireReset   = true;
                        SystemsContainer.Get <ToolbarSystem>().Enabled = false; //Always disable toolbar in main menu
                        NetworkConnection.Disconnect("Quit to main menu");
                    }

                    if (HighLogic.CurrentGame.flagURL != SettingsSystem.CurrentSettings.SelectedFlag)
                    {
                        LunaLog.Log("[LMP]: Saving Selected flag");
                        SettingsSystem.CurrentSettings.SelectedFlag = HighLogic.CurrentGame.flagURL;
                        SettingsSystem.SaveSettings();
                        SystemsContainer.Get <FlagSystem>().FlagChangeEvent = true;
                    }

                    // save every GeeASL from each body in FlightGlobals
                    if (HighLogic.LoadedScene == GameScenes.FLIGHT && BodiesGees.Count == 0)
                    {
                        foreach (var body in FlightGlobals.Bodies)
                        {
                            BodiesGees.Add(body, body.GeeASL);
                        }
                    }

                    //handle use of cheats
                    if (!SettingsSystem.ServerSettings.AllowCheats)
                    {
                        CheatOptions.InfinitePropellant = false;
                        CheatOptions.NoCrashDamage      = false;

                        foreach (var gravityEntry in BodiesGees)
                        {
                            gravityEntry.Key.GeeASL = gravityEntry.Value;
                        }
                    }

                    if (HighLogic.LoadedScene == GameScenes.FLIGHT && FlightGlobals.ready)
                    {
                        HighLogic.CurrentGame.Parameters.Flight.CanLeaveToSpaceCenter = PauseMenu.canSaveAndExit == ClearToSaveStatus.CLEAR;
                    }
                    else
                    {
                        HighLogic.CurrentGame.Parameters.Flight.CanLeaveToSpaceCenter = true;
                    }
                }

                if (FireReset)
                {
                    FireReset = false;
                    SystemsHandler.KillAllSystems();
                }

                if (StartGame)
                {
                    StartGame = false;
                    StartGameNow();
                }
            }
            catch (Exception e)
            {
                HandleException(e, "Main system- update");
            }
            LunaProfiler.UpdateData.ReportTime(startClock);
        }
Esempio n. 25
0
        private void HandleWindowEvents()
        {
            if (!WindowsContainer.Get <StatusWindow>().DisconnectEventHandled)
            {
                WindowsContainer.Get <StatusWindow>().DisconnectEventHandled = true;
                ForceQuit = true;
                NetworkConnection.Disconnect("Quit");
                SystemsContainer.Get <ScenarioSystem>().SendScenarioModules(); // Send scenario modules before disconnecting
            }
            if (!ConnectionWindow.RenameEventHandled)
            {
                SystemsContainer.Get <StatusSystem>().MyPlayerStatus.PlayerName = SettingsSystem.CurrentSettings.PlayerName;
                ConnectionWindow.RenameEventHandled = true;
                SettingsSystem.SaveSettings();
            }
            if (!ConnectionWindow.AddEventHandled)
            {
                SettingsSystem.CurrentSettings.Servers.Add(ConnectionWindow.AddEntry);
                ConnectionWindow.AddEntry        = null;
                ConnectionWindow.AddingServer    = false;
                ConnectionWindow.AddEventHandled = true;
                SettingsSystem.SaveSettings();
            }
            if (!ConnectionWindow.EditEventHandled)
            {
                SettingsSystem.CurrentSettings.Servers[ConnectionWindow.Selected].Name    = ConnectionWindow.EditEntry.Name;
                SettingsSystem.CurrentSettings.Servers[ConnectionWindow.Selected].Address = ConnectionWindow.EditEntry.Address;
                SettingsSystem.CurrentSettings.Servers[ConnectionWindow.Selected].Port    = ConnectionWindow.EditEntry.Port;
                ConnectionWindow.EditEntry        = null;
                ConnectionWindow.AddingServer     = false;
                ConnectionWindow.EditEventHandled = true;
                SettingsSystem.SaveSettings();
            }
            if (!ConnectionWindow.RemoveEventHandled)
            {
                SettingsSystem.CurrentSettings.Servers.RemoveAt(ConnectionWindow.Selected);
                ConnectionWindow.Selected           = -1;
                ConnectionWindow.RemoveEventHandled = true;
                SettingsSystem.SaveSettings();
            }
            if (!ConnectionWindow.ConnectEventHandled)
            {
                ConnectionWindow.ConnectEventHandled = true;
                NetworkConnection.ConnectToServer(
                    SettingsSystem.CurrentSettings.Servers[ConnectionWindow.Selected].Address,
                    SettingsSystem.CurrentSettings.Servers[ConnectionWindow.Selected].Port);
            }
            if (CommandLineServer != null && HighLogic.LoadedScene == GameScenes.MAINMENU &&
                Time.timeSinceLevelLoad > 1f)
            {
                NetworkConnection.ConnectToServer(CommandLineServer.Address, CommandLineServer.Port);
                CommandLineServer = null;
            }

            if (!ConnectionWindow.DisconnectEventHandled)
            {
                ConnectionWindow.DisconnectEventHandled = true;
                GameRunning = false;
                FireReset   = true;
                NetworkConnection.Disconnect(NetworkState <= ClientState.Starting
                    ? "Cancelled connection to server"
                    : "Quit");
            }
        }
Esempio n. 26
0
        public void DrawContent(int windowId)
        {
            if (!LoadEventHandled)
            {
                LoadEventHandled = true;
                TempColor        = SettingsSystem.CurrentSettings.PlayerColor;
                NewCacheSize     = SettingsSystem.CurrentSettings.CacheSize.ToString();
            }
            //Player color
            GUILayout.BeginVertical();
            GUI.DragWindow(MoveRect);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Player Name color: ");
            GUILayout.Label(SettingsSystem.CurrentSettings.PlayerName, TempColorLabelStyle);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("R: ");
            TempColor.r = GUILayout.HorizontalScrollbar(TempColor.r, 0, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("G: ");
            TempColor.g = GUILayout.HorizontalScrollbar(TempColor.g, 0, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("B: ");
            TempColor.b = GUILayout.HorizontalScrollbar(TempColor.b, 0, 0, 1);
            GUILayout.EndHorizontal();
            TempColorLabelStyle.active.textColor = TempColor;
            TempColorLabelStyle.normal.textColor = TempColor;
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Random", ButtonStyle))
            {
                TempColor = PlayerColorSystem.GenerateRandomColor();
            }
            if (GUILayout.Button("Set", ButtonStyle))
            {
                WindowsContainer.Get <StatusWindow>().ColorEventHandled = false;
                SettingsSystem.CurrentSettings.PlayerColor = TempColor;
                SettingsSystem.SaveSettings();
                if (MainSystem.NetworkState == ClientState.Running)
                {
                    SystemsContainer.Get <PlayerColorSystem>().MessageSender.SendPlayerColorToServer();
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
            //Cache
            var enableCache = GUILayout.Toggle(SettingsSystem.CurrentSettings.EnableCache, "Enable cache", ButtonStyle);

            if (enableCache != SettingsSystem.CurrentSettings.EnableCache)
            {
                if (!enableCache)
                {
                    UniverseSyncCache.DeleteCache();               //Remove all cache when deactivating it
                }
                SettingsSystem.CurrentSettings.EnableCache = enableCache;
                SettingsSystem.SaveSettings();
            }
            if (SettingsSystem.CurrentSettings.EnableCache)
            {
                GUILayout.Label("Cache size");
                GUILayout.Label($"Current size: {Math.Round(UniverseSyncCache.CurrentCacheSize / (float)(1024 * 1024), 3)} MB.");
                GUILayout.Label($"Max size: {SettingsSystem.CurrentSettings.CacheSize} MB.");
                NewCacheSize = GUILayout.TextArea(NewCacheSize);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Set", ButtonStyle))
                {
                    if (int.TryParse(NewCacheSize, out var tempCacheSize))
                    {
                        if (tempCacheSize < 1)
                        {
                            tempCacheSize = 1;
                            NewCacheSize  = tempCacheSize.ToString();
                        }
                        if (tempCacheSize > 1000)
                        {
                            tempCacheSize = 1000;
                            NewCacheSize  = tempCacheSize.ToString();
                        }
                        SettingsSystem.CurrentSettings.CacheSize = tempCacheSize;
                        SettingsSystem.SaveSettings();
                    }
                    else
                    {
                        NewCacheSize = SettingsSystem.CurrentSettings.CacheSize.ToString();
                    }
                }
                if (GUILayout.Button("Expire cache"))
                {
                    UniverseSyncCache.ExpireCache();
                }
                if (GUILayout.Button("Delete cache"))
                {
                    UniverseSyncCache.DeleteCache();
                }
                GUILayout.EndHorizontal();
            }

            //Key bindings
            GUILayout.Space(10);
            var chatDescription = $"Set chat key (current: {SettingsSystem.CurrentSettings.ChatKey})";

            if (SettingChat)
            {
                chatDescription = "Setting chat key (click to cancel)...";
                if (Event.current.isKey)
                {
                    if (Event.current.keyCode != KeyCode.Escape)
                    {
                        SettingsSystem.CurrentSettings.ChatKey = Event.current.keyCode;
                        SettingsSystem.SaveSettings();
                        SettingChat = false;
                    }
                    else
                    {
                        SettingChat = false;
                    }
                }
            }
            if (GUILayout.Button(chatDescription))
            {
                SettingChat = !SettingChat;
            }
            GUILayout.Space(10);
            GUILayout.Label("Generate a server LMPModControl:");
            if (GUILayout.Button("Generate blacklist LMPModControl.txt"))
            {
                SystemsContainer.Get <ModSystem>().GenerateModControlFile(false);
            }
            if (GUILayout.Button("Generate whitelist LMPModControl.txt"))
            {
                SystemsContainer.Get <ModSystem>().GenerateModControlFile(true);
            }
            WindowsContainer.Get <UniverseConverterWindow>().Display = GUILayout.Toggle(WindowsContainer.Get <UniverseConverterWindow>().Display, "Generate Universe from saved game", ButtonStyle);
            if (GUILayout.Button("Reset disclaimer"))
            {
                SettingsSystem.CurrentSettings.DisclaimerAccepted = false;
                SettingsSystem.SaveSettings();
            }
            var settingCompression = GUILayout.Toggle(SettingsSystem.CurrentSettings.CompressionEnabled, "Enable compression", ButtonStyle);

            if (settingCompression != SettingsSystem.CurrentSettings.CompressionEnabled)
            {
                SettingsSystem.CurrentSettings.CompressionEnabled = settingCompression;
                SettingsSystem.SaveSettings();
            }
            var settingInterpolation = GUILayout.Toggle(SettingsSystem.CurrentSettings.InterpolationEnabled, "Enable interpolation", ButtonStyle);

            if (settingInterpolation != SettingsSystem.CurrentSettings.InterpolationEnabled)
            {
                SettingsSystem.CurrentSettings.InterpolationEnabled = settingInterpolation;
                SettingsSystem.SaveSettings();
            }
            var positionFudge = GUILayout.Toggle(SettingsSystem.CurrentSettings.PositionFudgeEnable, "Enable position fudge", ButtonStyle);

            if (positionFudge != SettingsSystem.CurrentSettings.PositionFudgeEnable)
            {
                SettingsSystem.CurrentSettings.PositionFudgeEnable = positionFudge;
                SettingsSystem.SaveSettings();
            }
            var altPositionSystem = GUILayout.Toggle(SettingsSystem.CurrentSettings.UseAlternativePositionSystem, "Use alterative position system", ButtonStyle);

            if (altPositionSystem != SettingsSystem.CurrentSettings.UseAlternativePositionSystem)
            {
                SettingsSystem.CurrentSettings.UseAlternativePositionSystem = altPositionSystem;
                SettingsSystem.SaveSettings();
            }
            var packOtherVessels = GUILayout.Toggle(SettingsSystem.CurrentSettings.PackOtherControlledVessels, "Pack other vessels", ButtonStyle);

            if (packOtherVessels != SettingsSystem.CurrentSettings.PackOtherControlledVessels)
            {
                SettingsSystem.CurrentSettings.PackOtherControlledVessels = packOtherVessels;
                SettingsSystem.SaveSettings();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Label("Toolbar:", SmallOption);
            if (GUILayout.Button(ToolbarMode, ButtonStyle))
            {
                var newSetting = (int)SettingsSystem.CurrentSettings.ToolbarType + 1;
                //Overflow to 0
                if (!Enum.IsDefined(typeof(LmpToolbarType), newSetting))
                {
                    newSetting = 0;
                }
                SettingsSystem.CurrentSettings.ToolbarType = (LmpToolbarType)newSetting;
                SettingsSystem.SaveSettings();
                UpdateToolbarString();
                SystemsContainer.Get <ToolbarSystem>().ToolbarChanged();
            }
            GUILayout.EndHorizontal();
#if DEBUG
            if (GUILayout.Button("Check Common.dll stock parts"))
            {
                SystemsContainer.Get <ModSystem>().CheckCommonStockParts();
            }
#endif
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Close", ButtonStyle))
            {
                Display = false;
            }
            GUILayout.EndVertical();
        }
Esempio n. 27
0
        public void DrawContent(int windowId)
        {
            if (!LoadEventHandled)
            {
                LoadEventHandled = true;
                TempColor        = SettingsSystem.CurrentSettings.PlayerColor;
            }
            //Player color
            GUILayout.BeginVertical();
            GUI.DragWindow(MoveRect);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Player Name color: ");
            GUILayout.Label(SettingsSystem.CurrentSettings.PlayerName, TempColorLabelStyle);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("R: ", SmallOption);
            TempColor.r = GUILayout.HorizontalScrollbar(TempColor.r, 0, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("G: ", SmallOption);
            TempColor.g = GUILayout.HorizontalScrollbar(TempColor.g, 0, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("B: ", SmallOption);
            TempColor.b = GUILayout.HorizontalScrollbar(TempColor.b, 0, 0, 1);
            GUILayout.EndHorizontal();
            TempColorLabelStyle.active.textColor = TempColor;
            TempColorLabelStyle.normal.textColor = TempColor;
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Random", ButtonStyle))
            {
                TempColor = PlayerColorSystem.GenerateRandomColor();
            }
            if (GUILayout.Button("Set", ButtonStyle))
            {
                WindowsContainer.Get <StatusWindow>().ColorEventHandled = false;
                SettingsSystem.CurrentSettings.PlayerColor = TempColor;
                SettingsSystem.SaveSettings();
                if (MainSystem.NetworkState == ClientState.Running)
                {
                    SystemsContainer.Get <PlayerColorSystem>().MessageSender.SendPlayerColorToServer();
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(10);
            //Key bindings
            var chatDescription = $"Set chat key (current: {SettingsSystem.CurrentSettings.ChatKey})";

            if (SettingChat)
            {
                chatDescription = "Setting chat key (click to cancel)...";
                if (Event.current.isKey)
                {
                    if (Event.current.keyCode != KeyCode.Escape)
                    {
                        SettingsSystem.CurrentSettings.ChatKey = Event.current.keyCode;
                        SettingsSystem.SaveSettings();
                        SettingChat = false;
                    }
                    else
                    {
                        SettingChat = false;
                    }
                }
            }
            if (GUILayout.Button(chatDescription))
            {
                SettingChat = !SettingChat;
            }
            if (GUILayout.Button("Reset disclaimer"))
            {
                SettingsSystem.CurrentSettings.DisclaimerAccepted = false;
                SettingsSystem.SaveSettings();
            }
            var settingInterpolation = GUILayout.Toggle(SettingsSystem.CurrentSettings.InterpolationEnabled, "Enable interpolation", ButtonStyle);

            if (settingInterpolation != SettingsSystem.CurrentSettings.InterpolationEnabled)
            {
                SettingsSystem.CurrentSettings.InterpolationEnabled = settingInterpolation;
                SettingsSystem.SaveSettings();
            }
            var closeBtnInConnectionWindow = GUILayout.Toggle(SettingsSystem.CurrentSettings.CloseBtnInConnectionWindow, "Show \"Close\" button in connection window", ButtonStyle);

            if (closeBtnInConnectionWindow != SettingsSystem.CurrentSettings.CloseBtnInConnectionWindow)
            {
                SettingsSystem.CurrentSettings.CloseBtnInConnectionWindow = closeBtnInConnectionWindow;
                SettingsSystem.SaveSettings();
            }
            GUILayout.Space(10);
            GUILayout.BeginVertical();
            GUILayout.Label("Positioning system:");
            var positionSetting = GUILayout.SelectionGrid(SettingsSystem.CurrentSettings.PositionSystem, new[] { "Dark", "Dagger", "Mixed" }, 3, "toggle");

            if (positionSetting != SettingsSystem.CurrentSettings.PositionSystem)
            {
                SettingsSystem.CurrentSettings.PositionSystem = positionSetting;
                SettingsSystem.SaveSettings();
            }
            GUILayout.EndVertical();
            GUILayout.Space(10);
            GUILayout.Label("Generate a server LMPModControl:");
            if (GUILayout.Button("Generate blacklist LMPModControl.txt"))
            {
                SystemsContainer.Get <ModSystem>().GenerateModControlFile(false);
            }
            if (GUILayout.Button("Generate whitelist LMPModControl.txt"))
            {
                SystemsContainer.Get <ModSystem>().GenerateModControlFile(true);
            }
            WindowsContainer.Get <UniverseConverterWindow>().Display = GUILayout.Toggle(WindowsContainer.Get <UniverseConverterWindow>().Display, "Generate Universe from saved game", ButtonStyle);
            GUILayout.Space(10);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Toolbar:", SmallOption);
            if (GUILayout.Button(ToolbarMode, ButtonStyle))
            {
                var newSetting = (int)SettingsSystem.CurrentSettings.ToolbarType + 1;
                //Overflow to 0
                if (!Enum.IsDefined(typeof(LmpToolbarType), newSetting))
                {
                    newSetting = 0;
                }
                SettingsSystem.CurrentSettings.ToolbarType = (LmpToolbarType)newSetting;
                SettingsSystem.SaveSettings();
                UpdateToolbarString();
                SystemsContainer.Get <ToolbarSystem>().ToolbarChanged();
            }
            GUILayout.EndHorizontal();
#if DEBUG
            DrawAdvancedDebugOptions();
#endif
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Close", ButtonStyle))
            {
                Display = false;
            }
            GUILayout.EndVertical();
        }
Esempio n. 28
0
 private void Awake()
 {
     _settingsSystem = FindObjectOfType <SettingsSystem>();
     _settingsUI     = FindObjectOfType <SettingsUI>();
 }
Esempio n. 29
0
        public override void DrawWindowContent(int windowId)
        {
            //Player color
            GUILayout.BeginVertical(BoxStyle);
            GUI.DragWindow(MoveRect);
            GUILayout.BeginHorizontal();
            GUILayout.Label(LocalizationContainer.OptionsWindowText.Language);
            if (GUILayout.Button(LocalizationContainer.GetCurrentLanguageAsText(), ButtonStyle))
            {
                LocalizationContainer.LoadLanguage(LocalizationContainer.GetNextLanguage());
                SettingsSystem.CurrentSettings.Language = LocalizationContainer.CurrentLanguage;
                SettingsSystem.SaveSettings();
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label(LocalizationContainer.OptionsWindowText.Color);
            GUILayout.Label(SettingsSystem.CurrentSettings.PlayerName, _tempColorLabelStyle);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label(LocalizationContainer.OptionsWindowText.Red, _smallOption);
            _tempColor.r = GUILayout.HorizontalScrollbar(_tempColor.r, 0, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label(LocalizationContainer.OptionsWindowText.Green, _smallOption);
            _tempColor.g = GUILayout.HorizontalScrollbar(_tempColor.g, 0, 0, 1);
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label(LocalizationContainer.OptionsWindowText.Blue, _smallOption);
            _tempColor.b = GUILayout.HorizontalScrollbar(_tempColor.b, 0, 0, 1);
            GUILayout.EndHorizontal();
            _tempColorLabelStyle.active.textColor = _tempColor;
            _tempColorLabelStyle.normal.textColor = _tempColor;
            GUILayout.BeginHorizontal();
            if (GUILayout.Button(LocalizationContainer.OptionsWindowText.Random, ButtonStyle))
            {
                _tempColor = PlayerColorSystem.GenerateRandomColor();
            }
            if (GUILayout.Button(LocalizationContainer.OptionsWindowText.Set, ButtonStyle))
            {
                StatusWindow.Singleton.ColorEventHandled   = false;
                SettingsSystem.CurrentSettings.PlayerColor = _tempColor;
                SettingsSystem.SaveSettings();
                if (MainSystem.NetworkState == ClientState.Running)
                {
                    PlayerColorSystem.Singleton.MessageSender.SendPlayerColorToServer();
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(10);
            var settingInterpolator = GUILayout.Toggle(SettingsSystem.CurrentSettings.PositionInterpolation, "Use interpolation", ButtonStyle);

            if (settingInterpolator != SettingsSystem.CurrentSettings.PositionInterpolation)
            {
                SettingsSystem.CurrentSettings.PositionInterpolation = settingInterpolator;
                SettingsSystem.SaveSettings();
            }
            GUILayout.Space(10);

            if (GUILayout.Button(LocalizationContainer.OptionsWindowText.GenerateLmpModControl))
            {
                ModSystem.Singleton.GenerateModControlFile(false);
            }
            if (GUILayout.Button(LocalizationContainer.OptionsWindowText.GenerateLmpModControl + " + SHA"))
            {
                ModSystem.Singleton.GenerateModControlFile(true);
            }
            _displayUniverseConverterDialog = GUILayout.Toggle(_displayUniverseConverterDialog, LocalizationContainer.OptionsWindowText.GenerateUniverse, ButtonStyle);
            GUILayout.Space(10);
#if DEBUG
            DrawAdvancedDebugOptions();
#endif
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
        }
Esempio n. 30
0
        private void DrawAdvancedDebugOptions()
        {
            var settingIntegrator = GUILayout.Toggle(SettingsSystem.CurrentSettings.OverrideIntegrator, "Override flight integrator", ButtonStyle);

            if (settingIntegrator != SettingsSystem.CurrentSettings.OverrideIntegrator)
            {
                SettingsSystem.CurrentSettings.OverrideIntegrator = settingIntegrator;
                SettingsSystem.SaveSettings();
            }
            if (GUILayout.Button("Check Common.dll stock parts"))
            {
                ModSystem.Singleton.CheckCommonStockParts();
            }
            GUILayout.Space(10);

            _showAdvancedNetworkFields = GUILayout.Toggle(_showAdvancedNetworkFields, "Advanced network fields", ButtonStyle);
            if (_showAdvancedNetworkFields)
            {
                if (MainSystem.NetworkState > ClientState.Disconnected)
                {
                    GUILayout.Label("Cannot change values while connected");
                }

                GUILayout.Label($"MTU: {NetworkMain.Config.MaximumTransmissionUnit}");
                GUILayout.Label(_infiniteTimeout
                    ? "Timeout: Infinite"
                    : $"Timeout: {NetworkMain.Config.ConnectionTimeout}s. Minimum: {NetworkMain.Config.PingInterval}s");

                GUILayout.BeginHorizontal();
                if (MainSystem.NetworkState <= ClientState.Disconnected)
                {
                    _infiniteTimeout = GUILayout.Toggle(_infiniteTimeout, "Infinite", "toggle");
                    if (!_infiniteTimeout)
                    {
                        if (NetworkMain.Config.ConnectionTimeout >= float.MaxValue - 1)
                        {
                            NetworkMain.Config.ConnectionTimeout = 15;
                        }

                        var value = GUILayout.TextArea(NetworkMain.Config.ConnectionTimeout.ToString(CultureInfo.InvariantCulture), 32, TextAreaStyle);
                        if (float.TryParse(value, out var parsedResult))
                        {
                            if (parsedResult >= NetworkMain.Config.PingInterval)
                            {
                                NetworkMain.Config.ConnectionTimeout = parsedResult;
                            }
                        }
                    }
                    else
                    {
                        NetworkMain.Config.ConnectionTimeout = float.MaxValue;
                    }
                }
                GUILayout.EndHorizontal();
            }

            _showBadNetworkSimulationFields = GUILayout.Toggle(_showBadNetworkSimulationFields, "Bad network simulation", ButtonStyle);
            if (_showBadNetworkSimulationFields)
            {
                if (MainSystem.NetworkState <= ClientState.Disconnected)
                {
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Random", ButtonStyle))
                    {
                        NetworkMain.RandomizeBadConnectionValues();
                    }
                    if (GUILayout.Button("Reset", ButtonStyle))
                    {
                        NetworkMain.ResetBadConnectionValues();
                    }
                    GUILayout.EndHorizontal();
                }

                GUILayout.Label($"NTP time offset: {LunaTime.SimulatedMsTimeOffset:F1}ms");
                LunaTime.SimulatedMsTimeOffset = (float)Math.Round(GUILayout.HorizontalScrollbar(LunaTime.SimulatedMsTimeOffset, 0, -2500, 2500), 3);
                if (MainSystem.NetworkState > ClientState.Disconnected)
                {
                    GUILayout.Label("Cannot change values while connected");
                }

                GUILayout.Label($"Packet loss: {NetworkMain.Config.SimulatedLoss * 100:F1}%");
                if (MainSystem.NetworkState <= ClientState.Disconnected)
                {
                    NetworkMain.Config.SimulatedLoss = (float)Math.Round(GUILayout.HorizontalScrollbar(NetworkMain.Config.SimulatedLoss, 0, 0, 1), 3);
                }
                GUILayout.Label($"Packet duplication: {NetworkMain.Config.SimulatedDuplicatesChance * 100:F1}%");
                if (MainSystem.NetworkState <= ClientState.Disconnected)
                {
                    NetworkMain.Config.SimulatedDuplicatesChance = (float)Math.Round(GUILayout.HorizontalScrollbar(NetworkMain.Config.SimulatedDuplicatesChance, 0, 0, 1), 3);
                }
                GUILayout.Label($"Max random latency: {NetworkMain.Config.SimulatedRandomLatency * 1000:F1} ms");
                if (MainSystem.NetworkState <= ClientState.Disconnected)
                {
                    NetworkMain.Config.SimulatedRandomLatency = (float)Math.Round(GUILayout.HorizontalScrollbar(NetworkMain.Config.SimulatedRandomLatency, 0, 0, 3), 4);
                }
                GUILayout.Label($"Min latency: {NetworkMain.Config.SimulatedMinimumLatency * 1000:F1} ms");
                if (MainSystem.NetworkState <= ClientState.Disconnected)
                {
                    NetworkMain.Config.SimulatedMinimumLatency = (float)Math.Round(GUILayout.HorizontalScrollbar(NetworkMain.Config.SimulatedMinimumLatency, 0, 0, 3), 4);
                }
            }
        }