Esempio n. 1
0
        public static void SetConfirmedForCurrentServer(bool isAllowed)
        {
            if (!Storage.TryLoad(
                    out Dictionary <ServerAddress, bool> dictionary))
            {
                dictionary = new Dictionary <ServerAddress, bool>();
            }

            var serverAddress = Api.Client.CurrentGame.ServerInfo.ServerAddress;

            dictionary[serverAddress] = isAllowed;
            Storage.Save(dictionary);

            Refresh();
        }
Esempio n. 2
0
        /// <summary>
        /// Try to load settings from client storage or init deafult one.
        /// </summary>
        public static void InitSettings()
        {
            settingsStorage = Api.Client.Storage.GetStorage("Mods/CNEI.Settings");
            settingsStorage.RegisterType(typeof(ViewType));
            settingsStorage.RegisterType(typeof(Settings));

            if (!settingsStorage.TryLoad(out settingsInstance))
            {
                // Default settings.
                settingsInstance.View = ViewType.Default;

                settingsInstance.DefaultViewPreset = new List <string>()
                {
                    "ProtoCharacterMob",
                    "ProtoItem",
                    "ProtoObjectLoot",
                    "ProtoObjectLootContainer",
                    "ProtoObjectMineral",
                    "ProtoObjectStructure",
                    "ProtoObjectVegetation"
                };

                settingsInstance.IsTypeVisibile = false;

                isSettingsChanged = true;
            }

            // Temp settings values to check if they changed.
            tempView      = settingsInstance.View;
            IsTypeVisible = settingsInstance.IsTypeVisibile;

            ChangeCurrentView();
            LoadDefaultViewFromSettings();
        }
        static ClientComponentPhysicsSpaceVisualizer()
        {
            SessionStorage = Api.Client.Storage.GetSessionStorage(
                nameof(ClientComponentPhysicsSpaceVisualizer) + ".Settings");
            SessionStorage.RegisterType(typeof(Settings));
            SessionStorage.RegisterType(typeof(CollisionGroupId));

            if (SessionStorage.TryLoad(out settingsInstance))
            {
                EnabledLayers       = settingsInstance.EnabledLayers;
                IsVisualizerEnabled = settingsInstance.IsVisualizerEnabled;
            }
            else
            {
                // set defaults
                settingsInstance.EnabledLayers = EnabledLayers = new HashSet <CollisionGroupId>()
                {
                    CollisionGroupId.Default,
                    CollisionGroupId.HitboxMelee,
                    CollisionGroupId.HitboxRanged,
                    CollisionGroupId.InteractionArea,
                    CollisionGroupId.ClickArea
                };
            }

            ServerOperatorSystem.ClientIsOperatorChanged += IsServerOperatorChangedHandler;
        }
Esempio n. 4
0
        public static void LoadGlobalSettingsFromClientStorage()
        {
            settingsStorage = Api.Client.Storage.GetStorage("Mods/" + ModId + "/GlobalSettings");
            settingsStorage.RegisterType(typeof(ViewType));
            settingsStorage.RegisterType(typeof(Settings));

            if (!settingsStorage.TryLoad(out settingsInstance))
            {
                // Default settings.
                settingsInstance.View = ViewType.Default;

                settingsInstance.IsTypeVisible = false;

                settingsInstance.HideUnreachableObjects = true;

                isSettingsChanged = true;
            }

            // Temp settings values to check if they changed.
            tempView               = settingsInstance.View;
            IsTypeVisible          = settingsInstance.IsTypeVisible;
            HideUnreachableObjects = settingsInstance.HideUnreachableObjects;

            ChangeCurrentView();
        }
Esempio n. 5
0
        public static void LoadDefaultViewPresetFromClientStorage()
        {
            defaultViewStorage = Api.Client.Storage.GetStorage("Mods/" + ModId + "/DefaultView");
            bool settingExist = true;

            // Force reload preset if saved version is too old.
            if (VersionFromClientStorage.CompareTo(new Version("0.4.7")) < 0 ||
                !defaultViewStorage.TryLoad(out defaultViewPresetFromSettings))
            {
                // Default settings.
                defaultViewPresetFromSettings = new List <string>()
                {
                    "ProtoCharacterMob",
                    "ProtoItem",
                    "ProtoObjectHackableContainer",
                    "ProtoObjectLoot",
                    "ProtoObjectLootContainer",
                    "ProtoObjectMineral",
                    "ProtoObjectStructure",
                    "ProtoObjectVegetation",
                    "ProtoStatusEffect",
                    "ProtoVehicle"
                };
                settingExist = false;
            }

            LoadDefaultViewFromSettings();

            if (!settingExist)
            {
                defaultViewStorage.Save(defaultViewPresetFromSettings);
            }
        }
Esempio n. 6
0
 static ClientCurrentCharacterLagPredictionManager()
 {
     SessionStorage = Api.Client.Storage.GetSessionStorage(nameof(ClientCurrentCharacterLagPredictionManager));
     if (!SessionStorage.TryLoad(out isLagPredictionEnabled))
     {
         // enabled by default
         isLagPredictionEnabled = true;
     }
 }
Esempio n. 7
0
 static ClientTileDecalHelper()
 {
     SessionStorage = Api.Client.Storage.GetSessionStorage(
         $"{nameof(ClientTileDecalHelper)}.{nameof(IsDecalsEnabled)}");
     if (!SessionStorage.TryLoad(out isDecalsEnabled))
     {
         isDecalsEnabled = true;
     }
 }
Esempio n. 8
0
 static ClientComponentPerformanceIndicatorsManager()
 {
     SessionStorage = Api.Client.Storage.GetSessionStorage(
         $"{nameof(HUDPerformanceIndicatorsPanel)}.{nameof(IsDisplayed)}");
     if (!SessionStorage.TryLoad(out isDisplayed))
     {
         // overlay is visible by default
         isDisplayed = true;
     }
 }
Esempio n. 9
0
 static ClientPostEffectsManager()
 {
     SessionStorage = Api.Client.Storage.GetSessionStorage(
         $"{nameof(ClientPostEffectsManager)}.{nameof(IsPostEffectsEnabled)}");
     if (!SessionStorage.TryLoad(out isPostEffectsEnabled) &&
         !Api.IsEditor)
     {
         // post-effects are enabled by default in non-Editor
         isPostEffectsEnabled = true;
     }
 }
        public void Setup(ICharacter character)
        {
            this.character = character;

            // ReSharper disable once CanExtractXamlLocalizableStringCSharp
            this.inputContext = ClientInputContext
                                .Start("Player character Movement")
                                .HandleAll(this.UpdateInput);

            StorageRunMode.TryLoad(out this.runToggle);
        }
Esempio n. 11
0
        /// <summary>
        /// Try to load mod version from client storage.
        /// </summary>
        private static void LoadVersionFromClientStorage()
        {
            // Load settings.
            versionStorage = Api.Client.Storage.GetStorage("Mods/Automaton/Version");
            versionStorage.RegisterType(typeof(Version));
            versionStorage.TryLoad(out VersionFromClientStorage);

            // Version changes handeling.
            // if (VersionFromClientStorage.CompareTo(CurrentVersion) > 0)

            versionStorage.Save(CurrentVersion);
        }
        static ClientPostEffectsManager()
        {
            SessionStorage = Api.Client.Storage.GetSessionStorage(
                $"{nameof(ClientPostEffectsManager)}.{nameof(IsPostEffectsEnabled)}");
            if (!SessionStorage.TryLoad(out isPostEffectsEnabled) &&
                !Api.IsEditor)
            {
                // post-effects are enabled by default in non-Editor
                isPostEffectsEnabled = true;
            }

            ServerOperatorSystem.ClientIsOperatorChanged += IsServerOperatorChangedHandler;
        }
Esempio n. 13
0
 static VehicleCustomNamingDataManager()
 {
     ClientStorage = Api.Client.Storage.GetStorage("Mods/VehicleCustomNaming/VehicleCustomNamingDataManager");
     ClientStorage.RegisterType(typeof(Settings));
     if (ClientStorage.TryLoad(out settingsInstance))
     {
         RenamedVehicles = settingsInstance.SavedRenamedVehicles;
     }
     else
     {
         settingsInstance.SavedRenamedVehicles = RenamedVehicles = new Dictionary <uint, string>();
     }
 }
Esempio n. 14
0
        static ComponentLagPredictionVisualizer()
        {
            SessionStorage = Api.Client.Storage.GetSessionStorage(
                $"{nameof(ComponentLagPredictionVisualizer)}.{nameof(IsVisualizerEnabled)}");
            SessionStorage.TryLoad(out isVisualizerEnabled);

            ClientCurrentCharacterLagPredictionManager.IsLagPredictionEnabledChanged
                += () =>
                {
                if (!ClientCurrentCharacterLagPredictionManager.IsLagPredictionEnabled)
                {
                    DestroyInstance();
                }
                };
        }
Esempio n. 15
0
        /// <summary>
        /// Try to load mod version from client storage.
        /// </summary>
        private static void LoadVersionFromClientStorage()
        {
            // Load settings.
            versionStorage = Api.Client.Storage.GetStorage("Mods/" + ModId + "/Version");
            versionStorage.RegisterType(typeof(Version));
            if (!versionStorage.TryLoad(out VersionFromClientStorage))
            {
                VersionFromClientStorage = new Version("0.0.1");
            }

            // Version changes handling.
            // if (VersionFromClientStorage.CompareTo(CurrentVersion) > 0)

            // Or should I wait until all migration work is done?
            versionStorage.Save(CurrentVersion);
        }
        private static async void RefreshWelcomeMessage()
        {
            if (Api.IsEditor)
            {
                return;
            }

            var gameServerInfo = Client.CurrentGame.ServerInfo;

            var serverAddress = gameServerInfo.ServerAddress;

            lastGetWelcomeMessageTask = Instance.CallServer(_ => _.ServerRemote_GetWelcomeMessage());

            var welcomeMessage = await lastGetWelcomeMessageTask;

            if (string.IsNullOrWhiteSpace(welcomeMessage))
            {
                if (!Client.CurrentGame.IsConnectedToOfficialServer)
                {
                    return;
                }

                welcomeMessage = OfficialServerWelcomeMessage.Trim();
            }

            // load the last messages from storage
            if (!ClientStorageLastServerMessage.TryLoad(out Dictionary <ServerAddress, string> dictLastMessages))
            {
                dictLastMessages = new Dictionary <ServerAddress, string>();
            }

            if (dictLastMessages.TryGetValue(serverAddress, out var lastMessage) &&
                lastMessage == welcomeMessage)
            {
                // the player already saw this welcome message
                return;
            }

            dictLastMessages[serverAddress] = welcomeMessage;
            ClientStorageLastServerMessage.Save(dictLastMessages);
            ClientShowWelcomeMessageInternal(welcomeMessage);
        }
Esempio n. 17
0
        /// <summary>
        /// Try to load settings from client storage or init deafult one.
        /// </summary>
        private static void LoadSettings()
        {
            settingsStorage = Api.Client.Storage.GetStorage("Mods/Automaton.Settings");
            settingsStorage.RegisterType(typeof(Settings));
            if (!settingsStorage.TryLoad(out settingsInstance))
            {
                // Init default settings. (All disabled by default)
                settingsInstance.IsEnabled = false;
                settingsInstance.Features
                    = FeaturesDictionary.ToDictionary(p => p.Key, p => new List <string>());
                // TODO: May be add default options in ProtoFeature
            }

            foreach (KeyValuePair <string, ProtoFeature> pair in FeaturesDictionary)
            {
                if (!settingsInstance.Features.ContainsKey(pair.Key))
                {
                    settingsInstance.Features.Add(pair.Key, new List <string>());
                }
                pair.Value.LoadSettings(settingsInstance.Features[pair.Key]);
            }
        }
Esempio n. 18
0
 private List <string> TryLoad()
 {
     Storage.TryLoad(out List <string> result);
     return(result ?? new List <string>());
 }