Exemple #1
0
        private void setupGameObjects(GameObject r, GameObject h, ProtoCrewMember c)
        {
            if (PortraitStats.showAlways)
            {
                Transform parent = h.transform.parent;

                r.transform.SetParent(parent);
            }

            if (PortraitStats.useIcon)
            {
                r.transform.GetChild(1).gameObject.SetActive(false);

                Image back = r.GetComponent <Image>();

                if (back != null)
                {
                    back.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 51, 69);
                }

                createIcon(r.transform);
            }

            if (PortraitStats.transferButton)
            {
                transferButton = MonoBehaviour.Instantiate(portrait.evaButton, h.transform) as Button;

                transferButton.name = "Transfer Button";

                TextMeshProUGUI xferText = transferButton.GetComponentInChildren <TextMeshProUGUI>();

                if (xferText != null)
                {
                    xferText.text = "XFR";
                }

                TooltipController_Text tooltip = transferButton.GetComponent <TooltipController_Text>();

                if (tooltip != null)
                {
                    tooltip.textString = "Initiate Crew Transfer";
                }

                RectTransform rect = transferButton.GetComponent <RectTransform>();

                if (rect != null)
                {
                    rect.anchoredPosition = new Vector2(rect.anchoredPosition.x, rect.anchoredPosition.y - rect.rect.height);
                }

                transferButton.onClick.RemoveAllListeners();

                transferButton.onClick.AddListener(new UnityEngine.Events.UnityAction(initiateTransfer));

                transferButton.gameObject.SetActive(false);
            }
        }
        private void Awake()
        {
            GameObject mask = new GameObject("GuageTWR");

            mask.transform.SetParent(transform, false);
            mask.layer = 5;

            RectTransform maskRect = mask.AddComponent <RectTransform>();

            mask.AddComponent <RectMask2D>();

            _tooltip = mask.AddComponent <TooltipController_Text>();

            _tooltip.continuousUpdate    = true;
            _tooltip.prefab              = BasicDeltaV_Loader.TooltipPrefab.prefab;
            _tooltip.RequireInteractable = false;
            _tooltip.TooltipPrefabType   = BasicDeltaV_Loader.TooltipPrefab.TooltipPrefabType;

            maskRect.anchorMin        = new Vector2(0.5f, 0.5f);
            maskRect.anchorMax        = new Vector2(0.5f, 0.5f);
            maskRect.pivot            = new Vector2(0.5f, 0.5f);
            maskRect.sizeDelta        = new Vector2(31, 111.5f);
            maskRect.anchoredPosition = new Vector2(0, 0);

            var gauges = FlightUIModeController.Instance.stagingQuadrant.GetComponentsInChildren <KSP.UI.Screens.LinearGauge>();

            for (int i = gauges.Length - 1; i >= 0; i--)
            {
                if (gauges[i].gameObject.name == "GaugePitchPointer")
                {
                    //BasicDeltaV.BasicLogging("Pitch Gauge Located\nMin Position: {0:F3} - Max Position: {1:F3}", gauges[i].minValuePosition, gauges[i].maxValuePosition);
                    _gauge = Instantiate(gauges[i], mask.transform);
                    break;
                }
            }

            _gauge.gameObject.name = "GaugeTWRPointer";

            _gauge.minValue    = 0;
            _gauge.maxValue    = 3;
            _gauge.logarithmic = 10;
            _gauge.exponential = 0;

            _gauge.minValuePosition = new Vector2(-1.3f, -55.5f);
            _gauge.maxValuePosition = new Vector2(-1.3f, 52);

            _gauge.Value = 1;

            GameEvents.onTooltipSpawned.Add(TooltipSpawned);
            GameEvents.onTooltipDespawned.Add(TooltipDespawned);

            GameEvents.OnMapEntered.Add(OnMapEnter);
            GameEvents.OnMapExited.Add(OnMapExit);
            GameEvents.OnFlightUIModeChanged.Add(OnFlightModeChange);
        }
Exemple #3
0
 /// <summary>
 /// Create a tooltip object for a given GameObject, containing just one simple string.
 /// </summary>
 /// <param name="gameObj">GameObject to which we want to add a tooltip</param>
 /// <param name="tooltip">The text to show in the tooltip</param>
 /// <returns>
 /// True if we are able to create the tooltip, false otherwise
 /// </returns>
 public static bool SetTooltip(this GameObject gameObj, string tooltip)
 {
     if (gameObj != null)
     {
         TooltipController_Text tt = (gameObj.GetComponent <TooltipController_Text>() ?? gameObj.AddComponent <TooltipController_Text>());
         if (tt != null)
         {
             tt.textString = tooltip;
             tt.prefab     = textTooltipPrefab;
             return(true);
         }
     }
     return(false);
 }
Exemple #4
0
        private static GameObject SetTooltip(string tooltip, GameObject gameObj = null)
        {
            if (gameObj == null)
            {
                gameObj = new GameObject("KCT_DevPartsTooltip");
            }

            TooltipController_Text tt = gameObj.AddOrGetComponent <TooltipController_Text>();

            if (tt != null)
            {
                tt.textString = tooltip;
                tt.prefab     = TooltipPrefab;
                UIMasterController.Instance.SpawnTooltip(tt);
            }
            return(gameObj);
        }
Exemple #5
0
        public static void AddTooltipToObject(GameObject obj, string text)
        {
            if (tooltipPrefab == null)
            {
                tooltipPrefab = AssetBase.GetPrefab <Tooltip_Text>("Tooltip_Text");
            }

            TooltipController_Text tooltip = obj.GetComponent <TooltipController_Text>();

            if (tooltip == null)
            {
                tooltip = obj.AddComponent <TooltipController_Text>();
            }

            tooltip.prefab = tooltipPrefab;
            tooltip.SetText(text);
        }
        private void KillTooltips()
        {
            if (_dialog == null)
            {
                return;
            }

            var tooltips = _dialog.GetComponentsInChildren <TooltipController_Text>(true);

            for (int i = tooltips.Length - 1; i >= 0; i--)
            {
                TooltipController_Text tooltip = tooltips[i];

                if (tooltip == null)
                {
                    continue;
                }

                tooltip.SetText("");
            }
        }
Exemple #7
0
        public TelemetryUpdateData(TelemetryUpdate stockTU)
        {
            this.modeButton       = stockTU.modeButton;
            this.NOSIG            = stockTU.NOSIG;
            this.NOEP             = stockTU.NOEP;
            this.BLK              = stockTU.BLK;
            this.AUP              = stockTU.AUP;
            this.ADN              = stockTU.ADN;
            this.EP0              = stockTU.EP0;
            this.EP1              = stockTU.EP1;
            this.EP2              = stockTU.EP2;
            this.CK1              = stockTU.CK1;
            this.CK2              = stockTU.CK2;
            this.CK3              = stockTU.CK3;
            this.CP1              = stockTU.CP1;
            this.CP2              = stockTU.CP2;
            this.CP3              = stockTU.CP3;
            this.SS0              = stockTU.SS0;
            this.SS1              = stockTU.SS1;
            this.SS2              = stockTU.SS2;
            this.SS3              = stockTU.SS3;
            this.SS4              = stockTU.SS4;
            this.arrow_icon       = stockTU.arrow_icon;
            this.firstHop_icon    = stockTU.firstHop_icon;
            this.lastHop_icon     = stockTU.lastHop_icon;
            this.control_icon     = stockTU.control_icon;
            this.signal_icon      = stockTU.signal_icon;
            this.firstHop_tooltip = stockTU.firstHop_tooltip;
            this.arrow_tooltip    = stockTU.arrow_tooltip;
            this.lastHop_tooltip  = stockTU.lastHop_tooltip;
            this.control_tooltip  = stockTU.control_tooltip;
            this.signal_tooltip   = stockTU.signal_tooltip;

            //Doing Reflection to read and save attribute names and values seems too complex,
            //given most of attributes are not primitives
        }
 private void Awake()
 {
     tooltip = GetComponent <TooltipController_Text>();
     tooltip.continuousUpdate = true;
 }
        private void processPrefab()
        {
            GameObject prefab = AssetBase.GetPrefab("ScienceResultsDialog");

            if (prefab == null)
            {
                return;
            }

            ScienceRelayDialog dialogListener = prefab.gameObject.AddOrGetComponent <ScienceRelayDialog>();

            Button[] buttons = prefab.GetComponentsInChildren <Button>(true);

            for (int i = buttons.Length - 1; i >= 0; i--)
            {
                Button b = buttons[i];

                if (b.name == "ButtonPrev")
                {
                    dialogListener.buttonPrev = b;
                }
                else if (b.name == "ButtonNext")
                {
                    dialogListener.buttonNext = b;
                }
                else if (b.name == "ButtonKeep")
                {
                    transferButton = Instantiate(b, b.transform.parent) as Button;

                    transferButton.name = "ButtonTransfer";

                    transferButton.onClick.RemoveAllListeners();

                    TooltipController_Text tooltip = transferButton.GetComponent <TooltipController_Text>();

                    if (tooltip != null)
                    {
                        tooltip.textString = Localizer.Format("#autoLOC_ScienceRelay_Tooltip");
                    }

                    if (spritesLoaded)
                    {
                        Selectable select = transferButton.GetComponent <Selectable>();

                        if (select != null)
                        {
                            select.image.sprite = transferNormal;
                            select.image.type   = Image.Type.Simple;
                            select.transition   = Selectable.Transition.SpriteSwap;

                            SpriteState state = select.spriteState;
                            state.highlightedSprite = transferHighlight;
                            state.pressedSprite     = transferActive;
                            state.disabledSprite    = transferActive;
                            select.spriteState      = state;
                        }
                    }

                    dialogListener.buttonTransfer = transferButton;
                }
            }
        }
        private void processFlightStageGroup()
        {
            StageManager prefabFlight = null;

            var prefabs = Resources.FindObjectsOfTypeAll <StageManager>();

            for (int i = prefabs.Length - 1; i >= 0; i--)
            {
                var pre = prefabs[i];

                if (pre.name == "StageManager")
                {
                    prefabFlight = pre;
                }
            }

            if (prefabFlight == null)
            {
                return;
            }

            try
            {
                var fields = typeof(StageIcon).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).ToArray();

                StageIconInfoBox infoBar = fields[12].GetValue(prefabFlight.stageIconPrefab) as StageIconInfoBox;

                panelInfoBarPrefab = Instantiate(infoBar, BasicDeltaV_Settings.Instance.transform);
                panelInfoBarPrefab.gameObject.name = "BasicerDeltaV";

                RectTransform infoRect = panelInfoBarPrefab.GetComponent <RectTransform>();

                infoRect.anchorMin        = new Vector2(1, 1);
                infoRect.anchorMax        = new Vector2(1, 1);
                infoRect.anchoredPosition = new Vector2(25, 12);

                panelInfoBarPrefab.GetComponent <LayoutElement>().ignoreLayout = true;

                panelInfoBarPrefab.SetCaption(string.Format("<color=#{0}> ΔV</color>", BasicDeltaV.TextColor));
                panelInfoBarPrefab.SetProgressBarBgColor(new Color(0.51765f, 0.71765f, 0.003922f, 0.6f));
                panelInfoBarPrefab.SetProgressBarColor(new Color(1, 1, 0.078431f, 0.6f));

                Slider slider = panelInfoBarPrefab.GetComponentInChildren <Slider>();

                RectTransform sliderRect = slider.GetComponent <RectTransform>();

                sliderRect.sizeDelta        = new Vector2(sliderRect.sizeDelta.x, 16);
                sliderRect.anchoredPosition = new Vector2(sliderRect.anchoredPosition.x, -2);

                TextMeshProUGUI captionText = panelInfoBarPrefab.GetComponentsInChildren <TextMeshProUGUI>()[1];

                captionText.color = Color.white;

                RectTransform captionRect = captionText.rectTransform;

                captionRect.sizeDelta = new Vector2(captionRect.sizeDelta.x, 16);

                tooltipPrefab = panelInfoBarPrefab.GetComponent <TooltipController_Text>();

                //BasicDeltaV.BasicLogging("Toolip: Enabled: {0} tooltip prefab: {1} instance" , tool.enabled
                //    , tool.prefab == null ? "Null" : "Valid", tool.TooltipPrefabInstance == null ? "Null" : "Valid");

                tooltipPrefab.enabled          = true;
                tooltipPrefab.continuousUpdate = true;

                Destroy(panelInfoBarPrefab.GetComponentInChildren <TextMeshProUGUI>().gameObject);
                Destroy(panelInfoBarPrefab.GetComponentInChildren <Image>().gameObject);

                //BasicDeltaV.BasicLogging("DV Panel Prefab processed");
            }
            catch (Exception e)
            {
                panelInfoBarPrefab = null;

                BasicDeltaV.BasicLogging("Error in stage panel info box UI: {0}", e);
            }

            StageGroup group = prefabFlight.stageGroupPrefab;

            if (stageGroupSprite == null)
            {
                Transform layout = group.transform.Find("IconLayout");

                if (layout != null)
                {
                    stageGroupSprite = layout.GetComponent <Image>().sprite;
                }
            }

            group.gameObject.AddComponent <BasicDeltaV_StageGroupHandler>();

            stageFlightGroupProcessed = true;
        }
        private void SetOrientationButton()
        {
            if (_dialog == null)
            {
                return;
            }

            if (_stateButtons == null)
            {
                return;
            }

            UIStateButton refreshButton = _stateButtons[2];

            GameObject parent = refreshButton.transform.parent.gameObject;

            GameObject outline = MonoBehaviour.Instantiate(parent, parent.transform.parent) as GameObject;

            outline.name = "Outline_Orientation";

            FieldInfo disableField = typeof(KerbNetDialog).GetField("disableOnError", BindingFlags.NonPublic | BindingFlags.Instance);

            var disableObjects = disableField.GetValue(_dialog) as GameObject[];

            if (disableObjects != null)
            {
                List <GameObject> disableList = disableObjects.ToList();

                disableList.Add(outline);

                disableField.SetValue(_dialog, disableList.ToArray());
            }

            GameObject child = outline.GetChild("Button_Auto_Refresh");

            if (child != null)
            {
                child.transform.SetParent(null);
                MonoBehaviour.DestroyImmediate(child);
            }

            _orientButton = MonoBehaviour.Instantiate(refreshButton, outline.transform) as UIStateButton;

            _orientButton.name = "Button_Orientation";

            RectTransform rect = outline.GetComponent <RectTransform>();

            if (rect != null)
            {
                rect.anchoredPosition = new Vector2(rect.anchoredPosition.x + rect.rect.width, rect.anchoredPosition.y);
            }

            TooltipController_Text tooltip = outline.GetComponentInChildren <TooltipController_Text>();

            if (tooltip != null)
            {
                tooltip.textString = "Toggle Map Orientation";
            }

            _orientButton.states = new ButtonState[]
            {
                new ButtonState()
                {
                    name = "north_up", normal = _northSprite
                },
                new ButtonState()
                {
                    name = "orbit_up", normal = _orbitSprite
                }
            };

            _orientButton.SetState(GameSettings.KERBNET_ALIGNS_WITH_ORBIT ? "orbit_up" : "north_up", false);

            _orientButton.onValueChanged.AddListener(new UnityAction <UIStateButton>(OnOrientationChange));
        }