コード例 #1
0
        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);
            int buttonIndex = 0;

            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 subtypeIndex   = i;
                int theButtonIndex = buttonIndex;

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

                subtypeButtons.Add(subtypeButton);

                if (subtype == switcherModule.CurrentSubtype)
                {
                    currentButtonIndex = buttonIndex;
                }

                buttonIndex++;
            }

            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(currentButtonIndex);

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

            subtypeTitleText.text = switcherModule.CurrentSubtype.title;

            subtypeButtons[currentButtonIndex].Activate();
        }