/// <summary>
        /// 
        /// </summary>
        /// <param name="prefab"></param>
        public PropertySlider(WingProperty propRef, Color foreColour, Action<float> onChange)
        {
            propertyInstance = UnityEngine.Object.Instantiate(StaticWingGlobals.UI_PropertyPrefab);

            inputSlider = propertyInstance.GetChild("InputSlider").GetComponent<Slider>();
            inputSlider.fillRect.GetComponent<Image>().color = foreColour;

            propertyLabel = inputSlider.gameObject.GetChild("PropertyLabel").GetComponent<Text>();
            propertyLabel.text = propRef.name;
            input = inputSlider.gameObject.GetChild("UserInput").GetComponent<InputField>();

            Refresh(propRef);

            input.onValueChange.AddListener(TextValueChanged);
            inputSlider.onValueChanged.AddListener(SliderValueChanged);
            onValueChanged += onChange;
        }
        /// <summary>
        /// Constructor
        /// </summary>
        public EditorWindow()
        {
            // get references to all useful components
            canvas = UnityEngine.Object.Instantiate(StaticWingGlobals.UI_WindowPrefab.GetComponent<Canvas>());
            canvas.enabled = false;

            mainPanel = canvas.gameObject.GetChild("MainPanel");
            windowPosition = mainPanel.GetComponent<RectTransform>();
            GameObject headerPanel = mainPanel.GetChild("HeaderPanel");
            wingType = headerPanel.GetChild("WingType").GetComponent<Text>();
            lastModifiedProperty = headerPanel.GetChild("LastModifiedProperty").GetComponent<Text>();
            lastModifiedPropertyTooltip = headerPanel.GetChild("LastModifiedPropertyToolTip").GetComponent<Text>();
            closeButton = headerPanel.GetChild("CloseButton").GetComponent<Button>();

            // window position drag event
            EventTrigger.Entry entry = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.Drag;
            entry.callback = new EventTrigger.TriggerEvent();
            entry.callback.AddListener((x) => windowDrag(x));
            mainPanel.GetComponent<EventTrigger>().triggers.Add(entry);

            // close button click hides the window
            closeButton.onClick.AddListener(closeWindow);
        }
        public void Start()
        {
            LoggingUtil.LogVerbose(this, "Start");

            // Don't run if not in career
            if (HighLogic.CurrentGame.Mode != Game.Modes.CAREER)
            {
                LoggingUtil.LogDebug(this, "Destroying TrackingStationUI - not in career mode.");
                Destroy(this);
                return;
            }

            // Get the last button in the list to use as a copy
            MapViewFiltering.FilterButton lastButton = MapViewFiltering.Instance.FilterButtons.Last();

            // Create our copies
            activeWaypointButton = UnityEngine.Object.Instantiate(lastButton.button.gameObject);
            activeWaypointButton.name = "Button Active Waypoints";
            offeredWaypointButton = UnityEngine.Object.Instantiate(lastButton.button.gameObject);
            offeredWaypointButton.name = "Button Offered Waypoints";
            activeOrbitButton = UnityEngine.Object.Instantiate(lastButton.button.gameObject);
            activeOrbitButton.name = "Button Active Orbits";
            offeredOrbitButton = UnityEngine.Object.Instantiate(lastButton.button.gameObject);
            offeredOrbitButton.name = "Button Offered Orbits";

            // Fix z coordinates
            activeWaypointButton.GetComponent<RectTransform>().SetLocalPositionZ(750);
            offeredWaypointButton.GetComponent<RectTransform>().SetLocalPositionZ(750);
            activeOrbitButton.GetComponent<RectTransform>().SetLocalPositionZ(750);
            offeredOrbitButton.GetComponent<RectTransform>().SetLocalPositionZ(750);

            // Set up the tool-tips
            activeWaypointButton.GetComponent<TooltipController_Text>().textString = "Toggle Active Waypoints";
            offeredWaypointButton.GetComponent<TooltipController_Text>().textString = "Toggle Offered Waypoints";
            activeOrbitButton.GetComponent<TooltipController_Text>().textString = "Toggle Active Orbits";
            offeredOrbitButton.GetComponent<TooltipController_Text>().textString = "Toggle Offered Orbits";

            // Setup the button
            TrackingStationObjectButton activeWaypointTSButton = activeWaypointButton.GetComponent<TrackingStationObjectButton>();
            TrackingStationObjectButton offeredWaypointTSButton = offeredWaypointButton.GetComponent<TrackingStationObjectButton>();
            TrackingStationObjectButton activeOrbitTSButton = activeOrbitButton.GetComponent<TrackingStationObjectButton>();
            TrackingStationObjectButton offeredOrbitTSButton = offeredOrbitButton.GetComponent<TrackingStationObjectButton>();

            // Setup handlers
            activeWaypointTSButton.OnClickLeft.AddListener(new UnityAction(ActiveWaypointButtonClick));
            activeWaypointTSButton.OnClickRight.AddListener(new UnityAction(ActiveWaypointButtonClick));
            offeredWaypointTSButton.OnClickLeft.AddListener(new UnityAction(OfferedWaypointButtonClick));
            offeredWaypointTSButton.OnClickRight.AddListener(new UnityAction(OfferedWaypointButtonClick));
            activeOrbitTSButton.OnClickLeft.AddListener(new UnityAction(ActiveOrbitButtonClick));
            activeOrbitTSButton.OnClickRight.AddListener(new UnityAction(ActiveOrbitButtonClick));
            offeredOrbitTSButton.OnClickLeft.AddListener(new UnityAction(OfferedOrbitButtonClick));
            offeredOrbitTSButton.OnClickRight.AddListener(new UnityAction(OfferedOrbitButtonClick));

            // Setup sprites
            activeWaypointTSButton.spriteTrue = activeWaypointEnabledSprite;
            activeWaypointTSButton.spriteFalse = activeWaypointDisabledSprite;
            offeredWaypointTSButton.spriteTrue = offeredWaypointEnabledSprite;
            offeredWaypointTSButton.spriteFalse = offeredWaypointDisabledSprite;
            activeOrbitTSButton.spriteTrue = activeOrbitEnabledSprite;
            activeOrbitTSButton.spriteFalse = activeOrbitDisabledSprite;
            offeredOrbitTSButton.spriteTrue = offeredOrbitEnabledSprite;
            offeredOrbitTSButton.spriteFalse = offeredOrbitDisabledSprite;

            // Set defaults
            ContractConfiguratorParameters parms = HighLogic.CurrentGame.Parameters.CustomParams<ContractConfiguratorParameters>();
            activeWaypointButton.GetComponent<TrackingStationObjectButton>().SetState(parms.DisplayActiveWaypoints);
            offeredWaypointButton.GetComponent<TrackingStationObjectButton>().SetState(parms.DisplayOfferedWaypoints);
            activeOrbitButton.GetComponent<TrackingStationObjectButton>().SetState(parms.DisplayActiveOrbits);
            offeredOrbitButton.GetComponent<TrackingStationObjectButton>().SetState(parms.DisplayOfferedOrbits);

            // Disable counts
            activeWaypointButton.GetChild("Count").SetActive(false);
            offeredWaypointButton.GetChild("Count").SetActive(false);
            activeOrbitButton.GetChild("Count").SetActive(false);
            offeredOrbitButton.GetChild("Count").SetActive(false);

            // Re-parent
            GameObject trackingFilters = lastButton.button.transform.parent.gameObject;
            RectTransform trackingFiltersRect = trackingFilters.GetComponent<RectTransform>();
            trackingFiltersRect.sizeDelta = new Vector2(trackingFiltersRect.sizeDelta.x + 44 * 2, trackingFiltersRect.sizeDelta.y);
            activeWaypointButton.transform.SetParent(trackingFilters.transform);
            offeredWaypointButton.transform.SetParent(trackingFilters.transform);
            activeOrbitButton.transform.SetParent(trackingFilters.transform);
            offeredOrbitButton.transform.SetParent(trackingFilters.transform);
            activeWaypointButton.SetActive(true);
            offeredWaypointButton.SetActive(true);
            activeOrbitButton.SetActive(true);
            offeredOrbitButton.SetActive(true);

            // Move the commNet button
            GameObject commNet = trackingFilters.transform.parent.gameObject.GetChild("CommNetVisualisation");
            if (commNet != null)
            {
                RectTransform r = commNet.GetComponent<RectTransform>();
                r.localPosition = new Vector3(r.localPosition.x + 132, r.localPosition.y);
            }

            LoggingUtil.LogVerbose(this, "Finished setup");
        }
Example #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        public EditorWindow(string title)
        {
            // get references to all useful components
            go = Object.Instantiate(StaticWingGlobals.UI_WindowPrefab);
            go.transform.SetParent(KSP.UI.UIMasterController.Instance.appCanvas.transform, false);
            canvas = go.GetComponent<Canvas>();

            mainPanel = canvas.gameObject.GetChild("MainPanel");
            windowPosition = mainPanel.GetComponent<RectTransform>();
            GameObject headerPanel = mainPanel.GetChild("HeaderPanel");
            wingType = headerPanel.GetChild("WingType").GetComponent<Text>();
            lastModifiedProperty = headerPanel.GetChild("LastModifiedProperty").GetComponent<Text>();
            lastModifiedPropertyTooltip = headerPanel.GetChild("LastModifiedPropertyToolTip").GetComponent<Text>();
            closeButton = headerPanel.GetChild("CloseButton").GetComponent<Button>();

            // window position drag event
            EventTrigger.Entry dragEntry = new EventTrigger.Entry();
            dragEntry.eventID = EventTriggerType.Drag;
            dragEntry.callback = new EventTrigger.TriggerEvent();
            dragEntry.callback.AddListener((x) => windowDrag(x));
            mainPanel.GetComponent<EventTrigger>().triggers.Add(dragEntry);

            // close button click hides the window
            closeButton.onClick.AddListener(closeWindow);
            Visible = false;

            WindowTitle = title;
        }