Esempio n. 1
0
 private static void removeResource(PartResource resource, Part p)
 {
     //remove partinfo
     for (int i = 0; i < p.partInfo.resourceInfos.Count; i++)
     {
         AvailablePart.ResourceInfo info = p.partInfo.resourceInfos[i];
         try
         {
             if (info.resourceName.Equals(addSpaces(resource.resourceName)))
             {
                 //Debug.log("[MUR] remove!!! info.resourceName = '" + info.resourceName + "'");
                 p.partInfo.resourceInfos.Remove(info);
                 break;
             }
         }
         catch (Exception e)
         {
             Debug.LogError("Error: " + e);
         }
     }
     //remove resource
     p.Resources.list.Remove(resource);
     Destroy(resource);
     //// don't know what it does, perhaps nothing
     //p.Resources.UpdateList();
 }
Esempio n. 2
0
        static string PartInfo(AvailablePart part, string search)
        {
            string _partinfo = " ";

            if (!string.IsNullOrEmpty(part.tags) && searchExtension(partInfos.TAG, search))
            {
                _partinfo += part.tags + " ";
            }
            if (part.title != null && searchExtension(partInfos.TITLE, search))
            {
                _partinfo += part.title + " ";
            }
            if (part.author != null && searchExtension(partInfos.AUTHOR, search))
            {
                _partinfo += part.author + " ";
            }
            if (part.manufacturer != null && searchExtension(partInfos.MANUFACTURER, search))
            {
                _partinfo += part.manufacturer + " ";
            }
            if (part.name != null && searchExtension(partInfos.NAME, search))
            {
                _partinfo += part.name + " ";
            }
            if (!float.IsNaN(part.partSize) && searchExtension(partInfos.PARTSIZE, search))
            {
                _partinfo += part.partSize + " ";
            }

            if (part.resourceInfos.Count > 0 && searchExtension(partInfos.RESOURCEINFOS, search))
            {
                _partinfo += part.resourceInfo + " ";
                List <AvailablePart.ResourceInfo> _resourceInfos = part.resourceInfos;
                for (int _i = _resourceInfos.Count - 1; _i >= 0; --_i)
                {
                    AvailablePart.ResourceInfo _resourceInfo = _resourceInfos[_i];
                    _partinfo += _resourceInfo.resourceName + " ";
                }
            }
            if (part.TechRequired != null && searchExtension(partInfos.TECHREQUIRED, search))
            {
                _partinfo += part.TechRequired + " ";
            }
            if (part.moduleInfos.Count > 0 && searchExtension(partInfos.MODULE, search))
            {
                List <AvailablePart.ModuleInfo> _moduleInfos = part.moduleInfos;
                for (int _i = _moduleInfos.Count - 1; _i >= 0; --_i)
                {
                    AvailablePart.ModuleInfo _moduleInfo = _moduleInfos[_i];
                    _partinfo += _moduleInfo.moduleName + " ";
                }
            }
            if (part.description != null && searchExtension(partInfos.DESCRIPTION, search))
            {
                _partinfo += part.description;
            }
            return(_partinfo);
        }
Esempio n. 3
0
 public static void updateInfo(Part p, PartResource resource)
 {
     for (int i = 0; i < p.partInfo.resourceInfos.Count; i++)
     {
         AvailablePart.ResourceInfo info = p.partInfo.resourceInfos[i];
         //Debug.Log("[MUR] info.resourceName = '" + info.resourceName + "'");
         if (info.resourceName.Equals(addSpaces(resource.resourceName)))
         {
             info.primaryInfo = createPrimaryInfo(resource);
             info.info        = createInfo(resource);
         }
     }
 }
Esempio n. 4
0
        // See CompilePartInfo
        public static AvailablePart.ResourceInfo GetResourceInfo(PartResource pr)
        {
            AvailablePart.ResourceInfo resourceInfo = new AvailablePart.ResourceInfo();
            resourceInfo.resourceName = pr.resourceName;
            resourceInfo.displayName  = pr.info.displayName.LocalizeRemoveGender();
            StringBuilder infoString = new StringBuilder();

            infoString.Append(Localizer.Format("#autoLOC_166269", pr.amount.ToString("F1")));
            infoString.Append((pr.amount == pr.maxAmount) ? string.Empty : (" " + Localizer.Format("#autoLOC_6004042", pr.maxAmount.ToString("F1"))));
            infoString.Append(Localizer.Format("#autoLOC_166270", (pr.amount * pr.info.density).ToString("F2")));
            infoString.Append((pr.info.unitCost <= 0f) ? string.Empty : Localizer.Format("#autoLOC_166271", (pr.amount * (double)pr.info.unitCost).ToString("F2")));
            resourceInfo.info = infoString.ToStringAndRelease();
            if (pr.maxAmount > 0.0)
            {
                resourceInfo.primaryInfo = "<b>" + resourceInfo.displayName + ": </b>" + KSPUtil.LocalizeNumber(pr.maxAmount, "F1");
            }
            return(resourceInfo);
        }
Esempio n. 5
0
        public override void upgradeValue(Part p, float value)
        {
            //Debug.log("[MUR] upgradeValue " + p.name + " rn=" + resourceName);
            if (resourceName == null || resourceName.Length == 0)
            {
                return;
            }
            foreach (PartResource pr in p.Resources)
            {
                //Debug.log("[MUR] has resource " + pr.resourceName + ", " + pr.maxAmount);
            }
            PartResource resource = p.Resources[resourceName];

            if (resource == null)
            {
                //create the resource
                resource = addResource(p, resourceName, value, value);
                //Debug.log("[MUR] addresource");
                if (resource == null)
                {
                    //Debug.logError("Error: cannot add resource " + resourceName + " to " + p.name + " because this resource don't exist.");
                    return;
                }
                AvailablePart.ResourceInfo newInfo = new AvailablePart.ResourceInfo();
                newInfo.resourceName = addSpaces(resource.resourceName);
                p.partInfo.resourceInfos.Add(newInfo);
                //Debug.log("[MUR] addresource info : " + newInfo.resourceName);
            }
            else
            {
                resource.maxAmount = (float)(/*resource.maxAmount + */ value);
                resource.amount    = (float)(/*resource.amount + */ value);
                //Debug.log("[MUR] better amount ");
            }
            foreach (PartResource pr in p.Resources)
            {
                //Debug.log("[MUR] has resource (before) " + pr.resourceName + ", " + pr.maxAmount);
            }
            //reload partinfo
            updateInfo(p, resource);
        }
Esempio n. 6
0
        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);
        }