Beispiel #1
0
        static UIElements()
        {
            OptionEntryPrefab = GameObject.Instantiate(CheckboxOption_PauseOnFocusLost);
            var EntryText = OptionEntryPrefab.transform.Find("Text").gameObject;

            EntryText.GetComponent <Text>().text = "Option Entry";
            GameObject.DestroyImmediate(EntryText.GetComponent <UILocalisedText>());
            for (var i = 0; i < OptionEntryPrefab.transform.childCount; i++)
            {
                var child = OptionEntryPrefab.transform.GetChild(i).gameObject;
                if (child != EntryText)
                {
                    GameObject.DestroyImmediate(child);
                }
            }

            InputFieldOption_Prefab = UIElements.CreateOptionEntry("", "InputFieldOption_Prefab");

            var InputFieldOption_PrefabRect = InputFieldOption_Prefab.GetComponent <RectTransform>();
            var InputFieldOption_PrefabBehaviourInputField = InputFieldOption_Prefab.AddComponent <UIOptionsBehaviourInputField>();

            var InputFieldOption_Prefab_InputField = DefaultControls.CreateInputField(new DefaultControls.Resources()
            {
                inputField = UIElements.Options_Unticked
            });
            var InputFieldOption_Prefab_InputFieldInputField = InputFieldOption_Prefab_InputField.GetComponent <InputField>();

            typeof(UIOptionsBehaviourInputField).GetField("m_Target", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(InputFieldOption_PrefabBehaviourInputField, InputFieldOption_Prefab_InputFieldInputField);
            InputFieldOption_Prefab_InputFieldInputField.transition = Selectable.Transition.None;
            InputFieldOption_Prefab_InputFieldInputField.navigation = new Navigation()
            {
                mode = Navigation.Mode.None
            };
            var InputFieldOption_Prefab_InputFieldRect = InputFieldOption_Prefab_InputField.GetComponent <RectTransform>();

            InputFieldOption_Prefab_InputFieldRect.anchoredPosition3D = new Vector3(174f, 0, 0);
            InputFieldOption_Prefab_InputFieldRect.sizeDelta          = new Vector2(202f, 30f);

            var InputFieldOption_Prefab_InputField_Placeholder     = InputFieldOption_Prefab_InputField.transform.Find("Placeholder").gameObject;
            var InputFieldOption_Prefab_InputField_PlaceholderRect = InputFieldOption_Prefab_InputField_Placeholder.GetComponent <RectTransform>();
            var InputFieldOption_Prefab_InputField_PlaceholderText = InputFieldOption_Prefab_InputField_Placeholder.GetComponent <Text>();

            InputFieldOption_Prefab_InputField_PlaceholderText.text        = "";
            InputFieldOption_Prefab_InputField_PlaceholderText.alignment   = TextAnchor.MiddleLeft;
            InputFieldOption_Prefab_InputField_PlaceholderText.font        = UIElements.ExoRegular;
            InputFieldOption_Prefab_InputField_PlaceholderText.fontSize    = 14;
            InputFieldOption_Prefab_InputField_PlaceholderText.fontStyle   = FontStyle.Normal;
            InputFieldOption_Prefab_InputField_PlaceholderText.color       = Color.white;
            InputFieldOption_Prefab_InputField_PlaceholderText.lineSpacing = 1;

            var InputFieldOption_Prefab_InputField_Text     = InputFieldOption_Prefab_InputField.transform.Find("Text").gameObject;
            var InputFieldOption_Prefab_InputField_TextRect = InputFieldOption_Prefab_InputField_Text.GetComponent <RectTransform>();
            var InputFieldOption_Prefab_InputField_TextText = InputFieldOption_Prefab_InputField_Text.GetComponent <Text>();

            InputFieldOption_Prefab_InputField_TextText.text        = "";
            InputFieldOption_Prefab_InputField_TextText.alignment   = TextAnchor.MiddleLeft;
            InputFieldOption_Prefab_InputField_TextText.font        = UIElements.ExoRegular;
            InputFieldOption_Prefab_InputField_TextText.fontSize    = 14;
            InputFieldOption_Prefab_InputField_TextText.fontStyle   = FontStyle.Normal;
            InputFieldOption_Prefab_InputField_TextText.color       = Color.white;
            InputFieldOption_Prefab_InputField_TextText.lineSpacing = 1;
            InputFieldOption_Prefab_InputField.transform.SetParent(InputFieldOption_Prefab.transform, false);

            if (Pre1481)
            {
                KeyOption_Prefab = GameObject.Instantiate(KeybindingPrefab_TurnCamera);
                KeyOption_Prefab.SetActive(true);
                var KeybindEntryText = KeyOption_Prefab.transform.Find("Text").gameObject;
                GameObject.DestroyImmediate(KeybindEntryText.GetComponent <UILocalisedText>());
                KeybindEntryText.GetComponent <Text>().text = "";
                var KeybindButton1 = KeyOption_Prefab.transform.Find("Buttons Panel/Button").gameObject;
                KeybindButton1.GetComponent <Button>().interactable = true;

                /*var KeybindButton2 = KeybindingPrefab_TurnCamera.transform.Find("Buttons Panel/Button (2)").gameObject;
                 *              KeybindButton2.SetActive(true);
                 *              KeybindButton2.GetComponent<Button>().interactable = true;*/

                CategoryPrefab = GameObjects.First(f => f.name.StartsWith("_EmptySpace_ (1)"));
            }
            else
            {
                Controls_KeybindingOption_FireWeapons = GameObjects.First(f => f.name == "Controls_KeybindingOption FireWeapons");
                UIElements.KeyOption_Prefab           = GameObject.Instantiate(Controls_KeybindingOption_FireWeapons.transform.Find("FirstRow (1)").gameObject);

                var rect = KeyOption_Prefab.GetComponent <RectTransform>();
                rect.pivot = Vector2.up;
                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 590f);
                rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 50f);
                GameObject.DestroyImmediate(KeyOption_Prefab.transform.Find("AxisName").GetComponent <UILocalisedText>());
                GameObject.DestroyImmediate(KeyOption_Prefab.transform.Find("Name").gameObject);
                GameObject.DestroyImmediate(KeyOption_Prefab.transform.Find("AxisDescription").gameObject);

                var btn1     = KeyOption_Prefab.transform.Find("ButtonPos1").gameObject;
                var btn1Rect = btn1.GetComponent <RectTransform>();
                btn1Rect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, btn1Rect.sizeDelta.x, btn1Rect.sizeDelta.x);
                GameObject.DestroyImmediate(btn1.GetComponent <UIKeyBindButton>());
                btn1.GetComponent <Button>().onClick.RemoveAllListeners();
                btn1.SetActive(false);

                var btn2     = KeyOption_Prefab.transform.Find("ButtonPos2");
                var btn2Rect = btn2.GetComponent <RectTransform>();
                btn2Rect.pivot = btn2Rect.anchorMin = btn2Rect.anchorMax = new Vector2(1, 0.5f);
                btn2Rect.anchoredPosition3D = Vector3.zero;
                btn2Rect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Right, 0, btn2Rect.sizeDelta.x);
                btn2.GetComponent <Button>().onClick.RemoveAllListeners();
                GameObject.DestroyImmediate(btn2.GetComponent <UIKeyBindButton>());

                CategoryPrefab = GameObject.Instantiate(GameObjects.First(f => f.name == "Heading_Movement"));
                var catRect = CategoryPrefab.GetComponent <RectTransform>();
                catRect.sizeDelta = new Vector2(590f, 50f);
                GameObject.DestroyImmediate(CategoryPrefab.GetComponentInChildren <UILocalisedText>());
            }

            SliderOption_Prefab = GameObject.Instantiate(SliderOption_HorizontalSensivity);
            var SliderOption_Prefab_Text = SliderOption_Prefab.transform.Find("Text");

            GameObject.DestroyImmediate(SliderOption_Prefab_Text.GetComponent <UILocalisedText>());
            var SliderOption_Prefab_TextText = SliderOption_Prefab_Text.GetComponent <Text>();

            SliderOption_Prefab_TextText.fontSize          = 15;
            SliderOption_Prefab_TextText.font              = UIElements.ExoSemiBold;
            SliderOption_Prefab_TextText.enabled           = true;
            SliderOption_Prefab_TextText.resizeTextMaxSize = 15;
            SliderOption_Prefab_TextText.resizeTextMinSize = 1;

            DropdownOption_Prefab = GameObject.Instantiate(DropdownOption_Language);
            var DropdownOption_Prefab_Text = DropdownOption_Prefab.transform.Find("Text");

            GameObject.DestroyImmediate(DropdownOption_Prefab_Text.GetComponent <UILocalisedText>());
            DropdownOption_Prefab.GetComponentInChildren <Dropdown>().ClearOptions();

            CheckboxOption_Prefab = GameObject.Instantiate(CheckboxOption_PauseOnFocusLost);
            var CheckboxOption_Prefab_Text = CheckboxOption_Prefab.transform.Find("Text");

            GameObject.DestroyImmediate(CheckboxOption_Prefab_Text.GetComponent <UILocalisedText>());
        }
        void SetPage(int index)
        {
            if (index < 0 || index >= pages.Count)
            {
                return;
            }

            while (Content1.transform.childCount > 0)
            {
                Content1.transform.GetChild(0).SetParent(null, false);
            }
            while (Content2.transform.childCount > 0)
            {
                Content2.transform.GetChild(0).SetParent(null, false);
            }

            page_index = index;

            try
            {
                MidPanel.transform.parent.Find("Top Panel/Category 1/Title").GetComponent <Text>().text = pages[page_index].columns[0].entries[0].title.ToUpper();
                foreach (var entry in pages[page_index].columns[0].entries)
                {
                    if (entry.title != "" && entry.title != pages[page_index].columns[0].entries[0].title)
                    {
                        UIElements.CreateCategoryEntry(entry.title.ToUpper()).transform.SetParent(Content1.transform, false);
                    }
                    else if (entry.option != null)
                    {
                        entry.option.UIElement.transform.SetParent(Content1.transform, false);
                    }
                }

                if (pages[page_index].columns.Count > 1)
                {
                    MidPanel.transform.parent.Find("Top Panel/Category 2/Title").GetComponent <Text>().text = pages[page_index].columns[1].entries[0].title.ToUpper();
                    foreach (var entry in pages[page_index].columns[1].entries)
                    {
                        if (entry.title != "" && entry.title != pages[page_index].columns[1].entries[0].title)
                        {
                            UIElements.CreateCategoryEntry(entry.title.ToUpper()).transform.SetParent(Content2.transform, false);
                        }
                        else if (entry.option != null)
                        {
                            entry.option.UIElement.transform.SetParent(Content2.transform, false);
                        }
                    }
                }
                else
                {
                    MidPanel.transform.parent.Find("Top Panel/Category 2/Title").GetComponent <Text>().text = "";
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("UI");
                Console.WriteLine(e.ToString());
            }

            var midGroup = MidPanel.GetComponent <HorizontalLayoutGroup>();

            midGroup.CalculateLayoutInputHorizontal();
            midGroup.CalculateLayoutInputVertical();
            midGroup.SetLayoutHorizontal();
            midGroup.SetLayoutVertical();

            var content2Group = Content2.GetComponent <VerticalLayoutGroup>();

            content2Group.CalculateLayoutInputHorizontal();
            content2Group.CalculateLayoutInputVertical();
            content2Group.SetLayoutHorizontal();
            content2Group.SetLayoutVertical();

            var content1Group = Content1.GetComponent <VerticalLayoutGroup>();

            content1Group.CalculateLayoutInputHorizontal();
            content1Group.CalculateLayoutInputVertical();
            content1Group.SetLayoutHorizontal();
            content1Group.SetLayoutVertical();

            var prev = PrevPage.GetComponent <Button>();

            prev.interactable = page_index - 1 >= 0;

            var next = NextPage.GetComponent <Button>();

            next.interactable = page_index + 1 < pages.Count;

            var text = PageInfo.GetComponent <Text>();

            text.text = $"Page {page_index + 1}/{pages.Count}";
        }