private void CreateUpgradeWidgets(UpgradePrefab prefab, GameObject container) { foreach (PartUpgrade pu in prefab.upgrades) { // Don't create widgets for untracked upgrades if (pu.isUntracked) { continue; } // Create new widget PartListTooltipWidget newWidget = Instantiate(tooltip.extInfoModuleWidgetPrefab); newWidget.gameObject.name = "Upgrade tooltip widget"; // Add widget to list newWidget.transform.SetParent(container.transform, false); // Add "toggle" component if ((pu.upgradeState == PartUpgrade.UpgradeState.Enabled || pu.upgradeState == PartUpgrade.UpgradeState.Disabled)) { Toggle toggle = newWidget.gameObject.AddComponent <Toggle>(); toggle.isOn = (pu.upgradeState == PartUpgrade.UpgradeState.Enabled) ? true : false; toggle.enabled = true; toggle.onValueChanged.AddListener(onUpgradeToggle); } // Add the upgrade handler UpgradeWidgetComponent handler = newWidget.gameObject.AddComponent <UpgradeWidgetComponent>(); handler.partName = prefab.part.partInfo.name; handler.upgrade = pu.upgradeName; handler.upgradeState = pu.upgradeState; handler.isUpdated = false; // Create text newWidget.Setup(pu.GetTitle(), pu.GetInfo(prefab)); ToggleColors(handler, newWidget.GetComponent <Image>()); // Everything is good newWidget.gameObject.SetActive(true); } }
private void SetupSwitcherWidget(PartModule pm, AvailablePart.ModuleInfo pmInfo, Transform parent, PartListTooltipWidget extInfoVariantsWidgePrefab) { string title = ""; string info = ""; if (pm is ModuleB9PartSwitch) { GetB9Info((ModuleB9PartSwitch)pm, out title, out info); } else if (pm is ModulePartVariants) { GetVariantsInfo((ModulePartVariants)pm, out title, out info); } PartListTooltipWidget widget = Instantiate(extInfoVariantsWidgePrefab); widget.Setup(title, info); widget.transform.SetParent(parent, false); // Create a button Button button = widget.gameObject.AddComponent <Button>(); button.enabled = true; ColorBlock colors = button.colors; colors.highlightedColor = new Color32(242, 213, 50, 100); button.colors = colors; button.onClick.AddListener(OnSwitcherWidgetClick); ButtonWidget handler = widget.gameObject.AddComponent <ButtonWidget>(); handler.switcherModule = pm; handler.widget = widget; }
private PartListTooltipWidget CreateListToggleWidget(GameObject container, UpgradePrefab prefab) { // Create new widget PartListTooltipWidget newWidget = Instantiate(tooltip.extInfoRscWidgePrefab); newWidget.gameObject.name = "Widget list toggle"; // Add widget to container and set it as the first one newWidget.transform.SetParent(container.transform, false); newWidget.transform.SetAsFirstSibling(); // Create a toggle Toggle toggle = newWidget.gameObject.AddComponent <Toggle>(); toggle.isOn = true; toggle.enabled = true; toggle.onValueChanged.AddListener(onListToggle); // Initialize widget text then destroy info text object (we only need the title) newWidget.Setup("null", "null"); Destroy(newWidget.gameObject.GetChild("ModuleInfoText")); newWidget.gameObject.SetActive(true); return(newWidget); }
private void UpdateInfoToolTip(bool getHoveredpart = true) { // Get the part if requested if (getHoveredpart) { selectedPart = hoveredPart; } if (selectedPart == null) { ShowInfoToolTip(false); return; } // Create the UI if (!objectsCreated) { //UIPartActionWindow customPAW = Instantiate(UIPartActionController.Instance.windowPrefab); //customPAW.transform.SetParent(UIMasterController.Instance.actionCanvas.transform, false); //customPAW.gameObject.SetActive(true); //customPAW.gameObject.name = "FloatingPartTooltip"; //customPAW.Setup(selectedPart, UIPartActionWindow.DisplayType.Selected, UI_Scene.Editor); //customPAW.gameObject.GetChild("VerticalLayout").DestroyGameObject(); //infoToolTipInstance = Instantiate(FindObjectOfType<PartListTooltipController>().tooltipPrefab, customPAW.gameObject.transform); //infoToolTip = infoToolTipInstance.gameObject; //infoToolTip.transform.SetSiblingIndex(2); // Create tooltip object infoToolTipInstance = Instantiate(FindObjectOfType <PartListTooltipController>().tooltipPrefab, DialogCanvasUtil.DialogCanvasRect); infoToolTip = infoToolTipInstance.gameObject; // Get various UI GameObjects descriptionText = infoToolTip.GetChild("DescriptionText"); descriptionTopObject = infoToolTip.GetChild("Scroll View"); descriptionContent = descriptionText.transform.parent.gameObject; manufacturerPanel = infoToolTip.GetChild("ManufacturerPanel"); primaryInfoTopObject = infoToolTip.GetChild("ThumbAndPrimaryInfo").GetChild("Scroll View"); footerTopObject = infoToolTip.GetChild("Footer"); extWidgetsContent = infoToolTipInstance.panelExtended.GetChild("Content"); // Make it draggable DragPanelOffsettable dragpanel = infoToolTip.AddComponent <DragPanelOffsettable>(); dragpanel.edgeOffset = 20; // Remove part thumbnail infoToolTip.GetChild("ThumbContainer").DestroyGameObject(); // Remove RMBHint infoToolTip.GetChild("RMBHint").DestroyGameObject(); // Remove module widget list variant spacer infoToolTipInstance.extInfoListSpacerVariants.gameObject.DestroyGameObject(); // Adjust size LayoutElement leftPanel = infoToolTip.GetChild("StandardInfo").GetComponent <LayoutElement>(); leftPanel.preferredWidth = 240; leftPanel.minWidth = 240; LayoutElement costPanel = infoToolTip.GetChild("CostPanel").GetComponent <LayoutElement>(); costPanel.preferredWidth = 150; // Add switcher toggle infoButton = CreateButton(footerTopObject.transform, OnSwitcherToggle); infoButton.GetComponent <LayoutElement>().minWidth = 106; infoButton.GetComponent <LayoutElement>().preferredHeight = 24; infoButton.GetComponentInChildren <TextMeshProUGUI>().SetText("Show part info"); objectsCreated = true; } // Destroy module/ressource widgets PartListTooltipWidget[] extWidgets = extWidgetsContent.GetComponentsInChildren <PartListTooltipWidget>(true); for (int i = 0; i < extWidgets.Count(); i++) { extWidgets[i].gameObject.DestroyGameObject(); } // Destroy switcher widgets PartListTooltipWidget[] switchWidgets = descriptionContent.GetComponentsInChildren <PartListTooltipWidget>(true); for (int i = 0; i < switchWidgets.Count(); i++) { switchWidgets[i].gameObject.DestroyGameObject(); } // TODO: revert scrollbars to top bool hasSwitcher = false; // Create partmodule and switcher widgets foreach (PartModule pm in selectedPart.Modules) { if (!pm.enabled || !pm.isEnabled) { continue; } AvailablePart.ModuleInfo pmInfo = GetModuleInfo(pm); if (pm is ModuleB9PartSwitch || pm is ModulePartVariants) { SetupSwitcherWidget(pm, pmInfo, descriptionContent.transform, infoToolTipInstance.extInfoVariantsWidgePrefab); hasSwitcher = true; continue; } if (string.IsNullOrEmpty(pmInfo.info)) { continue; } PartListTooltipWidget widget = Instantiate(infoToolTipInstance.extInfoModuleWidgetPrefab); widget.Setup(pmInfo.moduleDisplayName, pmInfo.info); widget.transform.SetParent(infoToolTipInstance.extInfoListContainer, false); } // Move or hide module spacer if (infoToolTipInstance.extInfoListContainer.childCount > 2 && selectedPart.Resources.Count > 0) { infoToolTipInstance.extInfoListSpacer.gameObject.SetActive(true); infoToolTipInstance.extInfoListSpacer.SetSiblingIndex(infoToolTipInstance.extInfoListContainer.childCount - 1); } else { infoToolTipInstance.extInfoListSpacer.gameObject.SetActive(false); } // Add ressource widgets foreach (PartResource pr in selectedPart.Resources) { AvailablePart.ResourceInfo prInfo = GetResourceInfo(pr); if (string.IsNullOrEmpty(prInfo.info)) { continue; } //if (RemoveControlCharacters(pm.GetInfo()).Equals("")) continue; PartListTooltipWidget widget = Instantiate(infoToolTipInstance.extInfoRscWidgePrefab); widget.Setup(prInfo.displayName, prInfo.info); widget.transform.SetParent(infoToolTipInstance.extInfoListContainer, false); } // Setup info infoToolTipInstance.textName.text = selectedPart.partInfo.title; infoToolTipInstance.textManufacturer.text = selectedPart.partInfo.manufacturer; infoToolTipInstance.textDescription.text = selectedPart.partInfo.description; infoToolTipInstance.textInfoBasic.text = GetPartInfo(selectedPart); infoToolTipInstance.textCost.text = Localizer.Format("#autoLOC_456128", new string[] { "<sprite=\"CurrencySpriteAsset\" name=\"Funds\" tint=1>", ( selectedPart.partInfo.cost + selectedPart.GetModuleCosts(0.0f, ModifierStagingSituation.CURRENT) //TODO: this is wrong if ressource amount != maxamount ).ToString("N2") }); infoToolTipInstance.panelExtended.SetActive(infoToolTipInstance.extInfoListContainer.GetComponentsInChildren <PartListTooltipWidget>(true).Count() > 0); // Reposition tooltip if new part selected if (getHoveredpart) { UIMasterController.RepositionTooltip((RectTransform)infoToolTip.transform, Vector2.one, 8f); } // Update switcher button visibility infoButton.SetActive(hasSwitcher); ShowSwitcherWidgets(hasSwitcher); }