Exemple #1
0
    /// <summary>
    /// Load our categories.
    /// </summary>
    private void LoadCategories()
    {
        // Clear root
        foreach (Transform child in elementRoot.transform)
        {
            Destroy(child.gameObject);
        }

        // Clear root
        foreach (Transform child in categoryRoot.transform)
        {
            Destroy(child.gameObject);
        }

        options = new Dictionary <string, Dictionary <string, BaseSettingsElement[]> >();

        Dictionary <string, Dictionary <string, SettingsOption[]> > categories = PrototypeManager.SettingsCategories.Values.ToArray().SelectMany(x => x.categories).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

        foreach (string currentName in categories.Keys)
        {
            ColorButton button = Instantiate(categoryPrefab).GetComponent <ColorButton>();
            button.transform.SetParent(categoryRoot.transform);
            button.name = currentName;
            button.SetText(LocalizationTable.GetLocalization(currentName));
            options.Add(currentName, new Dictionary <string, BaseSettingsElement[]>());

            // This is quite optimised (despite being a forloop on a dictionary), and is only done during start
            foreach (KeyValuePair <string, SettingsOption[]> keyValuePair in categories[currentName])
            {
                options[currentName].Add(keyValuePair.Key, new BaseSettingsElement[keyValuePair.Value.Length]);

                for (int i = 0; i < keyValuePair.Value.Length; i++)
                {
                    if (FunctionsManager.SettingsMenu.HasFunction("Get" + keyValuePair.Value[i].className))
                    {
                        BaseSettingsElement element = FunctionsManager.SettingsMenu.Call("Get" + keyValuePair.Value[i].className).ToObject <BaseSettingsElement>();
                        element.option        = keyValuePair.Value[i];
                        element.parameterData = keyValuePair.Value[i].options;
                        element.InitializeLUA();
                        options[currentName][keyValuePair.Key][i] = element;
                    }
                    else if (keyValuePair.Value[i].name != null)
                    {
                        Debug.LogWarning("Get" + keyValuePair.Value[i].className + "() Doesn't exist");
                    }
                }
            }
        }
    }
Exemple #2
0
    /// <summary>
    /// Load our categories.
    /// </summary>
    private void LoadCategories()
    {
        // Clear root
        foreach (Transform child in elementRoot.transform)
        {
            Destroy(child.gameObject);
        }

        // Clear root
        foreach (Transform child in categoryRoot.transform)
        {
            Destroy(child.gameObject);
        }

        options = new Dictionary <string, Dictionary <string, BaseSettingsElement[]> >();

        List <SettingsCategory> categories = PrototypeManager.SettingsCategories.Values;

        for (int i = 0; i < categories.Count; i++)
        {
            ColorButton button = Instantiate(categoryPrefab).GetComponent <ColorButton>();
            button.transform.SetParent(categoryRoot.transform);
            button.name = categories[i].Type;
            button.SetText(LocalizationTable.GetLocalization(categories[i].Type));
            options.Add(categories[i].Type, new Dictionary <string, BaseSettingsElement[]>());

            foreach (KeyValuePair <string, List <SettingsOption> > keyValuePair in categories[i].headings)
            {
                options[categories[i].Type].Add(keyValuePair.Key, new BaseSettingsElement[keyValuePair.Value.Count]);

                for (int j = 0; j < keyValuePair.Value.Count; j++)
                {
                    if (FunctionsManager.SettingsMenu.HasFunction("Get" + keyValuePair.Value[j].classData.ClassName))
                    {
                        BaseSettingsElement element = FunctionsManager.SettingsMenu.Call("Get" + keyValuePair.Value[j].classData.ClassName).ToObject <BaseSettingsElement>();
                        element.option        = keyValuePair.Value[j];
                        element.parameterData = keyValuePair.Value[j].classData.ParameterData;
                        element.InitializeLUA();
                        options[categories[i].Type][keyValuePair.Key][j] = element;
                    }
                    else if (keyValuePair.Value[j].name != null)
                    {
                        UnityDebugger.Debugger.LogError("Get" + keyValuePair.Value[j].classData.ClassName + "() Doesn't exist");
                    }
                }
            }
        }
    }
Exemple #3
0
    public static void DisplayCategory(string category)
    {
        if (instance == null)
        {
            return;
        }

        // Optimisation for saving
        if (instance.currentCategory != string.Empty && instance.currentCategory != category && instance.options.ContainsKey(instance.currentCategory))
        {
            foreach (string headingName in instance.options[instance.currentCategory].Keys)
            {
                for (int i = 0; i < instance.options[instance.currentCategory][headingName].Length; i++)
                {
                    BaseSettingsElement elementCopy = instance.options[instance.currentCategory][headingName][i];

                    if (elementCopy != null && elementCopy.valueChanged)
                    {
                        instance.changesTracker.Add(elementCopy);
                    }
                }
            }

            if (instance.changesTracker.Count > 0)
            {
                instance.Apply();
            }
        }

        instance.categoryHeading.text = LocalizationTable.GetLocalization(category);
        instance.currentCategory      = category;

        // Clear root
        foreach (Transform child in instance.elementRoot.transform)
        {
            child.BroadcastMessage("Despawn", SendMessageOptions.DontRequireReceiver);
            Destroy(child.gameObject);
        }

        foreach (ColorButton button in instance.categoryRoot.GetComponentsInChildren <ColorButton>())
        {
            if (button.gameObject.name != category)
            {
                button.RevertColor();
            }
            else
            {
                button.SelectColor();
            }
        }

        if (instance.options.ContainsKey(category) == false)
        {
            return;
        }

        if (instance.currentCategory != string.Empty && instance.options.ContainsKey(instance.currentCategory))
        {
            foreach (string headingName in instance.options[instance.currentCategory].Keys)
            {
                // Create heading prefab
                SettingsHeading heading = Instantiate(instance.headingPrefab).GetComponent <SettingsHeading>();
                heading.SetText(headingName);
                heading.transform.SetParent(instance.elementRoot.transform);

                for (int i = 0; i < instance.options[instance.currentCategory][headingName].Length; i++)
                {
                    if (instance.options[instance.currentCategory][headingName][i] != null)
                    {
                        BaseSettingsElement element = instance.options[instance.currentCategory][headingName][i];
                        heading.AddObjectToRoot(element.InitializeElement());
                        element.valueChanged = false;
                    }
                }
            }
        }

        // Update canvases, to allow the normalized position to properly exist.
        Canvas.ForceUpdateCanvases();
        instance.settingsScrollRect.normalizedPosition = new Vector2(0, 1);
    }
    public static void DisplayCategory(string category)
    {
        if (instance == null)
        {
            return;
        }

        // Optimisation for saving
        if (instance.currentCategory != string.Empty && instance.currentCategory != category && instance.options.ContainsKey(instance.currentCategory))
        {
            foreach (string headingName in instance.options[instance.currentCategory].Keys)
            {
                for (int i = 0; i < instance.options[instance.currentCategory][headingName].Length; i++)
                {
                    BaseSettingsElement elementCopy = instance.options[instance.currentCategory][headingName][i];

                    if (elementCopy != null && elementCopy.valueChanged)
                    {
                        instance.changesTracker.Add(elementCopy);
                    }
                }
            }
        }

        instance.categoryHeading.text = category;
        instance.currentCategory      = category;

        // Clear root
        foreach (Transform child in instance.elementRoot.transform)
        {
            Destroy(child.gameObject);
        }

        foreach (ColorButton button in instance.categoryRoot.GetComponentsInChildren <ColorButton>())
        {
            if (button.gameObject.name != category)
            {
                button.RevertColor();
            }
            else
            {
                button.SelectColor();
            }
        }

        if (instance.options.ContainsKey(category) == false)
        {
            return;
        }

        if (instance.currentCategory != string.Empty && instance.options.ContainsKey(instance.currentCategory))
        {
            foreach (string headingName in instance.options[instance.currentCategory].Keys)
            {
                // Create heading prefab
                SettingsHeading heading = Instantiate(instance.headingPrefab).GetComponent <SettingsHeading>();
                heading.SetText(headingName);
                heading.transform.SetParent(instance.elementRoot.transform);

                for (int i = 0; i < instance.options[instance.currentCategory][headingName].Length; i++)
                {
                    if (instance.options[instance.currentCategory][headingName][i] != null)
                    {
                        heading.AddObjectToRoot(instance.options[instance.currentCategory][headingName][i].InitializeElement());
                    }
                }
            }
        }
    }
    public static void DisplayCategory(string category, bool initial = false)
    {
        if (instance == null)
        {
            return;
        }

        RectTransform rectTransform = instance.mainRoot.GetComponent <RectTransform>();

        if (rectTransform.sizeDelta.x > Screen.width * 0.8f)
        {
            rectTransform.sizeDelta = new Vector2(Screen.width * 0.8f, rectTransform.sizeDelta.y);
        }

        if (rectTransform.sizeDelta.y > Screen.height * 0.8f)
        {
            rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, Screen.height * 0.8f);
        }

        // Optimisation for saving
        if (instance.currentCategory != string.Empty && instance.currentCategory != category && instance.options.ContainsKey(instance.currentCategory) && initial == false)
        {
            foreach (string headingName in instance.options[instance.currentCategory].Keys)
            {
                for (int i = 0; i < instance.options[instance.currentCategory][headingName].Length; i++)
                {
                    BaseSettingsElement elementCopy = instance.options[instance.currentCategory][headingName][i];

                    if (elementCopy != null && elementCopy.valueChanged)
                    {
                        instance.changesTracker.Add(elementCopy);
                    }
                }
            }

            if (instance.changesTracker.Count > 0)
            {
                instance.Apply();
            }
        }

        instance.categoryHeading.text = LocalizationTable.GetLocalization(category);
        instance.currentCategory      = category;

        // Clear root
        foreach (Transform child in instance.elementRoot.transform)
        {
            Destroy(child.gameObject);
        }

        foreach (ColorButton button in instance.categoryRoot.GetComponentsInChildren <ColorButton>())
        {
            if (button.gameObject.name != category)
            {
                button.RevertColor();
            }
            else
            {
                button.SelectColor();
            }
        }

        if (instance.options.ContainsKey(category) == false)
        {
            return;
        }

        if (instance.currentCategory != string.Empty && instance.options.ContainsKey(instance.currentCategory))
        {
            foreach (string headingName in instance.options[instance.currentCategory].Keys)
            {
                // Create heading prefab
                SettingsHeading heading = Instantiate(instance.headingPrefab).GetComponent <SettingsHeading>();
                heading.SetText(headingName);
                heading.transform.SetParent(instance.elementRoot.transform);

                for (int i = 0; i < instance.options[instance.currentCategory][headingName].Length; i++)
                {
                    if (instance.options[instance.currentCategory][headingName][i] != null)
                    {
                        BaseSettingsElement element = instance.options[instance.currentCategory][headingName][i];
                        heading.AddObjectToRoot(element.InitializeElement());
                        element.valueChanged = false;
                    }
                }
            }
        }

        instance.settingsScrollRect.verticalNormalizedPosition   = 1;
        instance.settingsScrollRect.horizontalNormalizedPosition = 0;
    }