public override void Setup(UIPartActionWindow window, Part part, PartModule partModule, UI_Scene scene, UI_Control control, BaseField field)
        {
            base.Setup(window, part, partModule, scene, control, field);

            ModuleB9PartSwitch switcherModule = (ModuleB9PartSwitch)partModule;

            SwitcherSubtypeDescriptionGenerator subtypeDescriptionGenerator = new SwitcherSubtypeDescriptionGenerator(switcherModule);

            subtypeButtons = new List <UIPartActionSubtypeButton>(switcherModule.subtypes.Count);
            for (int i = 0; i < switcherModule.subtypes.Count; i++)
            {
                PartSubtype subtype = switcherModule.subtypes[i];
                if (!subtype.IsUnlocked())
                {
                    continue;
                }
                GameObject buttonGameObject             = Instantiate(prefabVariantButton, scrollMain.content);
                UIPartActionSubtypeButton subtypeButton = buttonGameObject.GetComponent <UIPartActionSubtypeButton>();

                // prevent capturing in closures
                int index = i;

                subtypeButton.Setup(
                    subtype.title,
                    subtypeDescriptionGenerator.GetFullSubtypeDescription(subtype),
                    subtype.PrimaryColor,
                    subtype.SecondaryColor,
                    () => SetSubtype(index)
                    );

                subtypeButtons.Add(subtypeButton);
            }

            subtypeButtons[0].previousItem = subtypeButtons[subtypeButtons.Count - 1];
            subtypeButtons[0].nextItem     = subtypeButtons[1];
            for (int i = 1; i < subtypeButtons.Count - 1; i++)
            {
                subtypeButtons[i].previousItem = subtypeButtons[i - 1];
                subtypeButtons[i].nextItem     = subtypeButtons[i + 1];
            }
            subtypeButtons[subtypeButtons.Count - 1].previousItem = subtypeButtons[subtypeButtons.Count - 2];
            subtypeButtons[subtypeButtons.Count - 1].nextItem     = subtypeButtons[0];

            switcherDescriptionText.text = switcherModule.switcherDescription;

            TooltipHelper.SetupSubtypeInfoTooltip(buttonPreviousTooltipController, "", "");
            TooltipHelper.SetupSubtypeInfoTooltip(buttonNextTooltipController, "", "");

            SetTooltips(switcherModule.currentSubtypeIndex);

            buttonPrevious.onClick.AddListener(PreviousSubtype);
            buttonNext.onClick.AddListener(NextSubtype);

            subtypeTitleText.text = switcherModule.CurrentSubtype.title;

            subtypeButtons[switcherModule.currentSubtypeIndex].Activate();
        }
Ejemplo n.º 2
0
        public static UIPartActionSubtypeSelector CreatePrefab()
        {
            GameObject partActionVariantSelectorPrefabGameObject = UIPartActionController.Instance.fieldPrefabs.OfType <UIPartActionVariantSelector>().FirstOrDefault()?.gameObject;

            if (partActionVariantSelectorPrefabGameObject.IsNull())
            {
                throw new Exception("Could not find FieldVariantSelector prefab");
            }

            GameObject partActionSubtypeSelectorGameObject = Instantiate(partActionVariantSelectorPrefabGameObject);

            DontDestroyOnLoad(partActionSubtypeSelectorGameObject);

            UIPartActionVariantSelector partActionVariantSelector = partActionSubtypeSelectorGameObject.GetComponent <UIPartActionVariantSelector>();
            UIPartActionSubtypeSelector partActionSubtypeSelector = partActionSubtypeSelectorGameObject.AddComponent <UIPartActionSubtypeSelector>();

            partActionSubtypeSelector.buttonPrevious   = partActionVariantSelector.buttonPrevious;
            partActionSubtypeSelector.buttonNext       = partActionVariantSelector.buttonNext;
            partActionSubtypeSelector.scrollMain       = partActionVariantSelector.scrollMain;
            partActionSubtypeSelector.subtypeTitleText = partActionVariantSelector.variantName;
            partActionSubtypeSelector.buttonPreviousTooltipController = partActionSubtypeSelector.buttonPrevious.gameObject.AddComponent <TooltipController_TitleAndText>();
            partActionSubtypeSelector.buttonNextTooltipController     = partActionSubtypeSelector.buttonNext.gameObject.AddComponent <TooltipController_TitleAndText>();

            partActionSubtypeSelector.switcherDescriptionText = partActionSubtypeSelectorGameObject.GetChild("Label_Variants").GetComponent <TMPro.TextMeshProUGUI>();

            partActionSubtypeSelector.subtypeTitleText.alignment = TMPro.TextAlignmentOptions.Right;

            RectTransform switcherDescriptionRectTransform = (RectTransform)partActionSubtypeSelector.switcherDescriptionText.gameObject.transform;

            switcherDescriptionRectTransform.anchorMin        = new Vector2(0, 1);
            switcherDescriptionRectTransform.anchorMax        = new Vector2(0, 1);
            switcherDescriptionRectTransform.pivot            = new Vector2(0, 0.5f);
            switcherDescriptionRectTransform.anchoredPosition = new Vector2(0, -5);
            switcherDescriptionRectTransform.sizeDelta       += new Vector2(45, 0);

            RectTransform subypeTitleRectTransform = (RectTransform)partActionSubtypeSelector.subtypeTitleText.gameObject.transform;

            subypeTitleRectTransform.pivot            = new Vector2(1, 0.5f);
            subypeTitleRectTransform.anchoredPosition = new Vector2(0, -5);
            subypeTitleRectTransform.sizeDelta       -= new Vector2(20, 0);

            partActionSubtypeSelector.prefabVariantButton = UIPartActionSubtypeButton.CreatePrefab(partActionVariantSelector.prefabVariantButton);

            Destroy(partActionVariantSelector);

            return(partActionSubtypeSelector);
        }
Ejemplo n.º 3
0
        public static GameObject CreatePrefab(GameObject variantButtonGameObject)
        {
            GameObject partActionVariantButtonGameObject = Instantiate(variantButtonGameObject);

            DontDestroyOnLoad(partActionVariantButtonGameObject);

            UIPartActionVariantButton partActionVariantButton = partActionVariantButtonGameObject.GetComponent <UIPartActionVariantButton>();
            UIPartActionSubtypeButton partActionSubtypeButton = partActionVariantButtonGameObject.AddComponent <UIPartActionSubtypeButton>();

            partActionSubtypeButton.imagePrimaryColor   = partActionVariantButton.imagePrimaryColor;
            partActionSubtypeButton.imageSecondaryColor = partActionVariantButton.imageSecomdaryColor;
            partActionSubtypeButton.imageSelected       = partActionVariantButton.imageSelected;
            partActionSubtypeButton.imageInvalid        = partActionVariantButton.imageInvalid;
            partActionSubtypeButton.buttonMain          = partActionVariantButton.buttonMain;
            partActionSubtypeButton.tooltipController   = partActionVariantButtonGameObject.AddComponent <TooltipController_TitleAndText>();

            Destroy(partActionVariantButton);

            return(partActionVariantButtonGameObject);
        }