示例#1
0
    public void LoadKeybinds()
    {
        Logger.Log("Loading user keybinds", Category.Keybindings);
        // Get the user's saved keybinds from PlayerPrefs
        string jsonKeybinds = PlayerPrefs.GetString("userKeybinds");

        if (jsonKeybinds != "")
        {
            // Check if user has any saved keybinds and deserialize it from JSON
            // If there are any problems then just reset controls to default
            try
            {
                userKeybinds = JsonConvert.DeserializeObject <KeybindDict>(jsonKeybinds);
            }
            catch (Exception e)
            {
                Logger.LogWarning("Couldn't deserialize userKeybind JSON: " + e, Category.Keybindings);
                ResetKeybinds();
                ModalPanelManager.Instance.Inform("Unable to read saved keybinds.\nThey were either corrupt or outdated, so they have been reset.");
            }
        }
        else
        {
            // Make a new copy of defaultKeybinds and make userKeybinds reference it
            Logger.Log("No saved keybinds found. Using default.", Category.Keybindings);
            ResetKeybinds();
        }
    }
示例#2
0
        public KeybindDict Clone()
        {
            KeybindDict newCopy = new KeybindDict();

            foreach (KeyValuePair <KeyAction, DualKeyCombo> entry in this)
            {
                newCopy.Add(entry.Key, entry.Value.Clone());
            }
            return(newCopy);
        }
示例#3
0
    public void SaveKeybinds(KeybindDict newKeybinds)
    {
        Logger.Log("Saving user keybinds", Category.Keybindings);
        // Make userKeybinds reference the new keybinds (since KeybindDict is reference type)
        userKeybinds = newKeybinds;
        // Turn the user's keybinds into JSON
        string jsonKeybinds = JsonConvert.SerializeObject(userKeybinds);

        // Save the user's keybinds to PlayerPrefs as a JSON string
        PlayerPrefs.SetString("userKeybinds", jsonKeybinds);
        PlayerPrefs.Save();
    }
示例#4
0
 public void ResetToDefaultButton()
 {
     modalPanelManager.Confirm(
         "Are you sure?",
         () =>
     {
         keybindManager.ResetKeybinds();
         tempKeybinds = keybindManager.userKeybinds.Clone();
         PopulateKeybindScrollView();
     },
         "Reset"
         );
 }
示例#5
0
    public void SaveKeybinds(KeybindDict newKeybinds, bool closeKeyBindWindow = false)
    {
        Logger.Log("Saving user keybinds", Category.Keybindings);
        // Make userKeybinds reference the new keybinds (since KeybinbdDict is reference type)
        userKeybinds = newKeybinds;
        // Turn the user's keybinds into JSON
        string jsonKeybinds = JsonConvert.SerializeObject(userKeybinds);

        // Save the user's keybinds to PlayerPrefs as a JSON string
        PlayerPrefs.SetString("userKeybinds", jsonKeybinds);
        // PlayerPrefs.Save();
        if (closeKeyBindWindow)
        {
            GUI_IngameMenu.Instance.CloseMenuPanel(FindObjectOfType <ControlSettingsMenu>().gameObject);
        }
    }
示例#6
0
    public void LoadKeybinds()
    {
        Logger.Log("Loading user keybinds", Category.Keybindings);
        // Get the user's saved keybinds from PlayerPrefs
        string jsonKeybinds = PlayerPrefs.GetString("userKeybinds");

        if (jsonKeybinds != "")
        {
            // Check if user has any saved keybinds and deserialize it from JSON
            // If there are any problems then just reset controls to default
            try
            {
                userKeybinds = JsonConvert.DeserializeObject <KeybindDict>(jsonKeybinds);
                // Set keybind texts when loading keybinds
                foreach (var keyValuePair in userKeybinds)
                {
                    UIManager.UpdateKeybindText(keyValuePair.Key, keyValuePair.Value.PrimaryCombo);
                }
            }
            catch (Exception e)
            {
                Logger.LogWarning("Couldn't deserialize userKeybind JSON: " + e, Category.Keybindings);
                ResetKeybinds();
                ModalPanelManager.Instance.Inform("Unable to read saved keybinds.\nThey were either corrupt or outdated, so they have been reset.");
            }

            // Properly updating user keybinds when we add or remove one
            var newHotkeys        = defaultKeybinds.Keys.Except(userKeybinds.Keys);
            var deprecatedHotKeys = userKeybinds.Keys.Except(defaultKeybinds.Keys);

            foreach (KeyAction entry in newHotkeys)
            {
                userKeybinds.Add(entry, defaultKeybinds[entry]);
            }
            foreach (KeyAction entry in deprecatedHotKeys)
            {
                userKeybinds.Remove(entry);
            }
        }
        else
        {
            // Make a new copy of defaultKeybinds and make userKeybinds reference it
            Logger.Log("No saved keybinds found. Using default.", Category.Keybindings);
            ResetKeybinds();
        }
    }
示例#7
0
    public void LoadKeybinds()
    {
        Logger.Log("Loading user keybinds", Category.Keybindings);
        // Get the user's saved keybinds from PlayerPrefs
        string jsonKeybinds = PlayerPrefs.GetString("userKeybinds");

        if (jsonKeybinds != "")
        {
            // Check if user has any saved keybinds and deserialise it from JSON
            userKeybinds = JsonConvert.DeserializeObject <KeybindDict>(jsonKeybinds);
        }
        else
        {
            // Make a new copy of defaultKeybinds and make userKeybinds reference it
            userKeybinds = defaultKeybinds.Clone();
        }
    }
示例#8
0
 public KeybindDict(KeybindDict initialDict) : base(initialDict)
 {
     // Constructor with a parameter which can use the base class constructor
 }
示例#9
0
 void OnEnable()
 {
     tempKeybinds = keybindManager.userKeybinds.Clone();
     PopulateKeybindScrollView();
 }