Inheritance: UnityEngine.MonoBehaviour
Exemplo n.º 1
0
 private static PopupWindow GetInstance()
 {
     if (go == null)
     {
         go = new GameObject("TacPopupWindow");
         instance = go.AddComponent<PopupWindow>();
     }
     return instance;
 }
Exemplo n.º 2
0
        public static void Draw(string buttonText, Rect windowPos, Func <int, object, bool> popupDrawCallback, GUIStyle buttonStyle, object parameter, params GUILayoutOption[] options)
        {
            PopupWindow pw = PopupWindow.GetInstance();

            var content = new GUIContent(buttonText);
            var rect    = GUILayoutUtility.GetRect(content, buttonStyle, options);

            if (GUI.Button(rect, content, buttonStyle))
            {
                pw.showPopup = true;

                // pw.popupPos = new Rect(windowPos.x + rect.xMin, windowPos.y + rect.yMax + 1, 10, 10);
                var mouse = Input.mousePosition;
                pw.popupPos = new Rect(mouse.x - 10, Screen.height - mouse.y - 10, 10, 10);

                pw.callback  = popupDrawCallback;
                pw.parameter = parameter;
            }

            if (Event.current.rawType == EventType.MouseUp)
            {
                pw.showPopup = false;
            }
        }
Exemplo n.º 3
0
        private bool DrawPopupContents(int windowId, object parameter)
        {
            ResourcePartMap clickedPart = (ResourcePartMap)parameter;

            List <ResourcePartMap> parts = clickedPart.isSelected ?
                                           EnumerateSelectedParts().ToList() : new List <ResourcePartMap>(1)
            {
                clickedPart
            };
            bool canPump = true, allHighlighted = true, guiChanged = false;

            foreach (ResourcePartMap part in parts)
            {
                canPump        &= part.resource.TransferMode == ResourceTransferMode.PUMP;
                allHighlighted &= part.isHighlighted;
            }

            bool highlight = GUILayout.Toggle(allHighlighted, "Highlight", popupButtonStyle);

            if (highlight != allHighlighted)
            {
                foreach (ResourcePartMap part in parts)
                {
                    if (!highlight && part.isHighlighted && !part.isSelected)
                    {
                        part.part.SetHighlightDefault();
                    }
                    part.isHighlighted = highlight;
                }
                guiChanged = true;
            }

            if (controller.IsPrelaunch() && parts.Count == 1) // only allow editing when a single part is selected
            {
                newAmount = clickedPart.resource.Amount;
                PopupWindow.Draw("Edit", windowPos, DrawEditPopupContents, popupButtonStyle, clickedPart);
            }

            if (canPump && isControllable)
            {
                TransferDirection direction = clickedPart.direction;
                bool?toggleChange           = null; // how a toggle was changed, if at all
                foreach (ResourcePartMap part in parts)
                {
                    if (part.direction != direction)
                    {
                        direction = TransferDirection.VARIOUS;
                        break;
                    }
                }

                DrawPopupToggle(TransferDirection.NONE, "Stop", ref direction, ref toggleChange);
                DrawPopupToggle(TransferDirection.IN, "Transfer In", ref direction, ref toggleChange);
                DrawPopupToggle(TransferDirection.OUT, "Transfer Out", ref direction, ref toggleChange);
                DrawPopupToggle(TransferDirection.BALANCE, "Balance", ref direction, ref toggleChange);
                if (settings.ShowDump)
                {
                    DrawPopupToggle(TransferDirection.DUMP, "Dump", ref direction, ref toggleChange);
                }
                DrawPopupToggle(TransferDirection.LOCKED, "Lock", ref direction, ref toggleChange);

                if (toggleChange.HasValue)
                {
                    foreach (ResourcePartMap part in parts)
                    {
                        if (!toggleChange.Value) // if the user turned a direction off...
                        {
                            if (part.direction == direction)
                            {
                                if (direction == TransferDirection.LOCKED)
                                {
                                    part.resource.Locked = false;
                                }
                                part.direction = TransferDirection.NONE;
                            }
                        }
                        else if (part.direction != direction)
                        {
                            if (direction == TransferDirection.LOCKED)
                            {
                                part.resource.Locked = true;
                            }
                            part.direction = direction;
                        }
                    }

                    guiChanged = true;
                }
            }

            return(guiChanged);
        }
Exemplo n.º 4
0
        protected override void DrawWindowContents(int windowID)
        {
            headerScrollPosition = GUILayout.BeginScrollView(headerScrollPosition, GUILayout.ExpandHeight(false));
            GUILayout.BeginHorizontal();
            List <ResourceInfo> sortedResources = controller.GetResourceInfo().Values.ToList();

            sortedResources.Sort((a, b) => a.title.CompareTo(b.title));
            foreach (ResourceInfo resource in sortedResources)
            {
                bool toggled = GUILayout.Toggle(resource.isShowing, resource.title, buttonStyle) != resource.isShowing;
                if (toggled)
                {
                    SetResourceVisibility(resource, !resource.isShowing);
                    if (resource.isShowing && settings.OneTabOnly)
                    {
                        foreach (ResourceInfo otherResource in sortedResources)
                        {
                            if (otherResource != resource)
                            {
                                SetResourceVisibility(otherResource, false);
                            }
                        }
                    }
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.EndScrollView();

            scrollPosition = GUILayout.BeginScrollView(scrollPosition);
            GUILayout.BeginVertical();

            // cache the value so we only do it once per call
            isControllable = controller.IsControllable();

            // avoid allocating new options and arrays for every cell
            GUILayoutOption[] width20 = new[] { GUILayout.Width(20) }, width46 = new[] { GUILayout.Width(46) }, width60 = new[] { GUILayout.Width(60) };
            foreach (ResourceInfo resource in sortedResources)
            {
                if (resource.isShowing)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    GUILayout.Label(resource.title, sectionStyle, GUILayout.Width(100));
                    if (resource.parts[0].resource.TransferMode == ResourceTransferMode.PUMP && isControllable)
                    {
                        resource.balance = GUILayout.Toggle(resource.balance, "Balance All", buttonStyle);
                    }
                    if (GUILayout.Button("Select All", buttonStyle))
                    {
                        bool ctrl = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
                        SelectParts(resource, resource.parts, resource.parts.Any(p => !p.isSelected), ctrl);
                        ResetRangeSelection();
                    }
                    PopupWindow.Draw("Sort", windowPos, DrawSortMenu, buttonStyle, null);
                    GUILayout.EndHorizontal();

                    foreach (ResourcePartMap partInfo in resource.parts)
                    {
                        PartResourceInfo partResource = partInfo.resource;
                        double           percentFull  = partResource.PercentFull * 100.0;

                        if (percentFull < settings.FuelCriticalLevel)
                        {
                            labelStyle.normal.textColor = new Color(0.88f, 0.20f, 0.20f, 1.0f);
                        }
                        else if (percentFull < settings.FuelWarningLevel)
                        {
                            labelStyle.normal.textColor = Color.yellow;
                        }
                        else
                        {
                            labelStyle.normal.textColor = Color.white;
                        }

                        labelStyle.fontStyle = partInfo.isSelected ? FontStyle.Bold : FontStyle.Normal;

                        GUILayout.BeginHorizontal();
                        string partTitle = partInfo.part.partInfo.title;

                        if (GUILayout.Button(partTitle.Substring(0, Math.Min(30, partTitle.Length)), labelStyle)) // if the user clicked an item name...
                        {
                            bool shift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
                            bool ctrl  = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
                            bool alt   = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt);
                            if (alt) // alt-click selects either all parts on the same ship or all parts of the same type
                            {
                                List <ResourcePartMap> parts;
                                if (shift)
                                {
                                    parts = resource.parts.FindAll(p => p.part.partInfo.title == partTitle);
                                }
                                else
                                {
                                    parts = resource.parts.FindAll(p => p.shipId == partInfo.shipId);
                                }
                                SelectParts(resource, parts, parts.Any(p => !p.isSelected), ctrl); // select all those parts if any is unselected
                                ResetRangeSelection();
                            }
                            else // otherwise, select and deselect items normally
                            {
                                ICollection <ResourcePartMap> parts;
                                // shift-click selects a range of items in the view
                                if (shift && resource == lastResourceClicked && partInfo != lastPartClicked && lastPartClicked != null)
                                {
                                    int partIndex = resource.parts.IndexOf(partInfo), lastIndex = resource.parts.IndexOf(lastPartClicked);
                                    if (lastIndex < 0)
                                    {
                                        lastIndex = partIndex;
                                    }
                                    parts = resource.parts.GetRange(Math.Min(partIndex, lastIndex), Math.Abs(partIndex - lastIndex) + 1);
                                }
                                else
                                {
                                    parts = new ResourcePartMap[] { partInfo };
                                }
                                SelectParts(resource, parts, !partInfo.isSelected || !ctrl && resource.parts.Count(p => p.isSelected) > parts.Count, ctrl);
                                lastResourceClicked = resource;
                                lastPartClicked     = partInfo;
                            }
                        }

                        GUILayout.FlexibleSpace();
                        if (settings.ShowShipNumber)
                        {
                            GUILayout.Label(partInfo.shipId.ToString(), labelStyle, width20);
                        }
                        if (settings.ShowStageNumber)
                        {
                            GUILayout.Label(partInfo.part.inverseStage.ToString(), labelStyle, width20);
                        }
                        if (settings.ShowMaxAmount)
                        {
                            GUILayout.Label(partResource.MaxAmount.ToString("N1"), labelStyle, width60);
                        }
                        if (settings.ShowCurrentAmount)
                        {
                            GUILayout.Label(partResource.Amount.ToString("N1"), labelStyle, width60);
                        }
                        if (settings.ShowPercentFull)
                        {
                            GUILayout.Label(percentFull.ToString("N1") + "%", labelStyle, width46);
                        }
                        PopupWindow.Draw(GetControlText(partInfo), windowPos, DrawPopupContents, buttonStyle, partInfo, width20);

                        GUILayout.EndHorizontal();
                    }
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            GUILayout.BeginHorizontal();
            if (GUILayout.Toggle((settings.RateMultiplier == 100.0), "x100", buttonStyle))
            {
                settings.RateMultiplier = 100.0;
            }
            if (GUILayout.Toggle((settings.RateMultiplier == 10.0), "x10", buttonStyle))
            {
                settings.RateMultiplier = 10.0;
            }
            if (GUILayout.Toggle((settings.RateMultiplier == 1.0), "x1", buttonStyle))
            {
                settings.RateMultiplier = 1.0;
            }
            if (GUILayout.Toggle((settings.RateMultiplier == 0.1), "x0.1", buttonStyle))
            {
                settings.RateMultiplier = 0.1;
            }
            GUILayout.EndHorizontal();



            // Extra title bar buttons
            if (GUI.Button(new Rect(windowPos.width - 72, 4, 20, 20), resetContent, closeButtonStyle))
            {
                controller.RebuildActiveVesselLists( );
            }
            if (GUI.Button(new Rect(windowPos.width - 48, 4, 20, 20), settingsContent, closeButtonStyle))
            {
                settingsWindow.ToggleVisible( );
            }
            if (GUI.Button(new Rect(windowPos.width - 24, 4, 20, 20), helpContent, closeButtonStyle))
            {
                helpWindow.ToggleVisible( );
            }
        }
Exemplo n.º 5
0
        private bool DrawPopupContents(int windowId, object parameter)
        {
            ResourcePartMap partInfo = (ResourcePartMap)parameter;

            partInfo.isSelected = GUILayout.Toggle(partInfo.isSelected, "Highlight", popupButtonStyle);
            if (!partInfo.isSelected)
            {
                partInfo.part.SetHighlightDefault();
            }

            if (controller.IsPrelaunch())
            {
                newAmount = partInfo.resource.amount;
                PopupWindow.Draw("Edit", windowPos, DrawEditPopupContents, popupButtonStyle, partInfo);
            }

            if (partInfo.resource.info.resourceTransferMode == ResourceTransferMode.PUMP && isControllable)
            {
                if (GUILayout.Toggle((partInfo.direction == TransferDirection.NONE), "Stop", popupButtonStyle))
                {
                    partInfo.direction = TransferDirection.NONE;
                }

                if (GUILayout.Toggle((partInfo.direction == TransferDirection.IN), "Transfer In", popupButtonStyle))
                {
                    partInfo.direction = TransferDirection.IN;
                }
                else if (partInfo.direction == TransferDirection.IN)
                {
                    partInfo.direction = TransferDirection.NONE;
                }

                if (GUILayout.Toggle((partInfo.direction == TransferDirection.OUT), "Transfer Out", popupButtonStyle))
                {
                    partInfo.direction = TransferDirection.OUT;
                }
                else if (partInfo.direction == TransferDirection.OUT)
                {
                    partInfo.direction = TransferDirection.NONE;
                }

                if (GUILayout.Toggle((partInfo.direction == TransferDirection.BALANCE), "Balance", popupButtonStyle))
                {
                    partInfo.direction = TransferDirection.BALANCE;
                }
                else if (partInfo.direction == TransferDirection.BALANCE)
                {
                    partInfo.direction = TransferDirection.NONE;
                }

                if (settings.ShowDump)
                {
                    if (GUILayout.Toggle((partInfo.direction == TransferDirection.DUMP), "Dump", popupButtonStyle))
                    {
                        partInfo.direction = TransferDirection.DUMP;
                    }
                    else if (partInfo.direction == TransferDirection.DUMP)
                    {
                        partInfo.direction = TransferDirection.NONE;
                    }
                }

                if (GUILayout.Toggle((partInfo.direction == TransferDirection.LOCKED), "Lock", popupButtonStyle))
                {
                    partInfo.direction          = TransferDirection.LOCKED;
                    partInfo.resource.flowState = false;
                }
                else if (partInfo.direction == TransferDirection.LOCKED)
                {
                    partInfo.direction          = TransferDirection.NONE;
                    partInfo.resource.flowState = true;
                }
            }

            if (GUI.changed)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        protected override void DrawWindowContents(int windowID)
        {
            headerScrollPosition = GUILayout.BeginScrollView(headerScrollPosition, GUILayout.ExpandHeight(false));
            GUILayout.BeginHorizontal();
            foreach (KeyValuePair <string, ResourceInfo> pair in controller.GetResourceInfo())
            {
                ResourceInfo value = pair.Value;
                value.isShowing = GUILayout.Toggle(value.isShowing, pair.Key, buttonStyle);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndScrollView();

            scrollPosition = GUILayout.BeginScrollView(scrollPosition);
            GUILayout.BeginVertical();

            // cache the value so we only do it once per call
            isControllable = controller.IsControllable();

            foreach (KeyValuePair <string, ResourceInfo> pair in controller.GetResourceInfo())
            {
                ResourceInfo resourceInfo = pair.Value;
                if (resourceInfo.isShowing)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    GUILayout.Label(pair.Key, sectionStyle, GUILayout.Width(100));
                    if (resourceInfo.parts[0].resource.info.resourceTransferMode == ResourceTransferMode.PUMP && isControllable)
                    {
                        resourceInfo.balance = GUILayout.Toggle(resourceInfo.balance, "Balance All", buttonStyle);
                    }
                    GUILayout.EndHorizontal();

                    foreach (ResourcePartMap partInfo in resourceInfo.parts)
                    {
                        PartResource resource    = partInfo.resource;
                        Part         part        = partInfo.part;
                        double       percentFull = resource.amount / resource.maxAmount * 100.0;

                        if (percentFull < settings.FuelCriticalLevel)
                        {
                            labelStyle.normal.textColor = new Color(0.88f, 0.20f, 0.20f, 1.0f);
                        }
                        else if (percentFull < settings.FuelWarningLevel)
                        {
                            labelStyle.normal.textColor = Color.yellow;
                        }
                        else
                        {
                            labelStyle.normal.textColor = Color.white;
                        }

                        GUILayout.BeginHorizontal();
                        string partTitle = part.partInfo.title;
                        GUILayout.Label(partTitle.Substring(0, Math.Min(30, partTitle.Length)), labelStyle);
                        GUILayout.FlexibleSpace();
                        if (settings.ShowStageNumber)
                        {
                            GUILayout.Label(part.inverseStage.ToString("#0"), labelStyle, GUILayout.Width(20));
                        }
                        if (settings.ShowMaxAmount)
                        {
                            GUILayout.Label(resource.maxAmount.ToString("#,##0.0"), labelStyle, GUILayout.Width(60));
                        }
                        if (settings.ShowCurrentAmount)
                        {
                            GUILayout.Label(resource.amount.ToString("#,##0.0"), labelStyle, GUILayout.Width(60));
                        }
                        if (settings.ShowPercentFull)
                        {
                            GUILayout.Label(percentFull.ToString("##0.0") + "%", labelStyle, GUILayout.Width(46));
                        }
                        PopupWindow.Draw(GetControlText(partInfo.direction), windowPos, DrawPopupContents, buttonStyle, partInfo, GUILayout.Width(20));

                        GUILayout.EndHorizontal();
                    }
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            GUILayout.BeginHorizontal();
            if (GUILayout.Toggle((settings.RateMultiplier == 100.0), "x100", buttonStyle))
            {
                settings.RateMultiplier = 100.0;
            }
            if (GUILayout.Toggle((settings.RateMultiplier == 10.0), "x10", buttonStyle))
            {
                settings.RateMultiplier = 10.0;
            }
            if (GUILayout.Toggle((settings.RateMultiplier == 1.0), "x1", buttonStyle))
            {
                settings.RateMultiplier = 1.0;
            }
            if (GUILayout.Toggle((settings.RateMultiplier == 0.1), "x0.1", buttonStyle))
            {
                settings.RateMultiplier = 0.1;
            }
            GUILayout.EndHorizontal();

            if (GUI.Button(new Rect(windowPos.width - 68, 4, 20, 20), "S", closeButtonStyle))
            {
                settingsWindow.SetVisible(true);
            }
            if (GUI.Button(new Rect(windowPos.width - 46, 4, 20, 20), "?", closeButtonStyle))
            {
                helpWindow.SetVisible(true);
            }
        }
Exemplo n.º 7
0
 void Awake()
 {
     instance  = this;
     windowId  = "Tac.PopupWindow".GetHashCode();
     showPopup = false;
 }
Exemplo n.º 8
0
        protected override void DrawWindowContents(int windowID)
        {
            headerScrollPosition = GUILayout.BeginScrollView(headerScrollPosition, GUILayout.ExpandHeight(false));
            GUILayout.BeginHorizontal();
            List <ResourceInfo> sortedResources = controller.GetResourceInfo().Values.ToList();

            sortedResources.Sort((a, b) => a.title.CompareTo(b.title));
            foreach (ResourceInfo resource in sortedResources)
            {
                if (HighLogic.CurrentGame.Parameters.CustomParams <TacSettings_1>().hideNontransferableResources&&
                    (resource.parts[0].resource.TransferMode != ResourceTransferMode.PUMP || !isControllable)
                    )
                {
                    continue;
                }

                bool toggled = (GUILayout.Toggle(resource.isShowing, resource.title, buttonStyle) != resource.isShowing);
                if (toggled)
                {
                    SetResourceVisibility(resource, !resource.isShowing);
                    if (resource.isShowing && settings.OneTabOnly)
                    {
                        foreach (ResourceInfo otherResource in sortedResources)
                        {
                            if (otherResource != resource)
                            {
                                SetResourceVisibility(otherResource, false);
                            }
                        }
                    }
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.EndScrollView();

            scrollPosition = GUILayout.BeginScrollView(scrollPosition);
            GUILayout.BeginVertical();

            // cache the value so we only do it once per call
            isControllable = controller.IsControllable();

            // avoid allocating new options and arrays for every cell
            //GUILayoutOption[] width20 = new[] { GUILayout.Width(20) }, width46 = new[] { GUILayout.Width(46) }, width60 = new[] { GUILayout.Width(60) };
            foreach (ResourceInfo resource in sortedResources)
            {
                if (resource.isShowing)
                {
                    if (HighLogic.CurrentGame.Parameters.CustomParams <TacSettings_1>().hideNontransferableResources&&
                        (resource.parts[0].resource.TransferMode != ResourceTransferMode.PUMP || !isControllable)
                        )
                    {
                        continue;
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    GUILayout.Label(resource.title, sectionStyle, GUILayout.Width(100));
                    if (resource.parts[0].resource.TransferMode == ResourceTransferMode.PUMP && isControllable)
                    {
                        resource.balance = GUILayout.Toggle(resource.balance, "Balance All", buttonStyle);
                    }
                    if (GUILayout.Button("Select All", buttonStyle))
                    {
                        bool ctrl = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
                        SelectParts(resource, resource.parts, resource.parts.Any(p => !p.isSelected), ctrl);
                        ResetRangeSelection();
                    }
                    PopupWindow.Draw("Sort", windowPos, DrawSortMenu, buttonStyle, null);


                    GUILayout.EndHorizontal();

                    foreach (ResourcePartMap partInfo in resource.parts)
                    {
                        PartResourceInfo partResource = partInfo.resource;
                        double           percentFull  = partResource.PercentFull * 100.0;

                        if (percentFull < settings.FuelCriticalLevel)
                        {
                            labelStyle.normal.textColor = new Color(0.88f, 0.20f, 0.20f, 1.0f);
                        }
                        else if (percentFull < settings.FuelWarningLevel)
                        {
                            labelStyle.normal.textColor = Color.yellow;
                        }
                        else
                        {
                            labelStyle.normal.textColor = Color.white;
                        }

                        labelStyle.fontStyle = partInfo.isSelected ? FontStyle.Bold : FontStyle.Normal;

                        GUILayout.BeginHorizontal();
                        string partTitle = partInfo.part.partInfo.title;

                        if (GUILayout.Button(partTitle.Substring(0, Math.Min(30, partTitle.Length)), labelStyle)) // if the user clicked an item name...
                        {
                            bool shift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
                            bool ctrl  = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
                            bool alt   = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt);
                            if (alt) // alt-click selects either all parts on the same ship or all parts of the same type
                            {
                                List <ResourcePartMap> parts;
                                if (shift)
                                {
                                    parts = resource.parts.FindAll(p => p.part.partInfo.title == partTitle);
                                }
                                else
                                {
                                    parts = resource.parts.FindAll(p => p.shipId == partInfo.shipId);
                                }
                                SelectParts(resource, parts, parts.Any(p => !p.isSelected), ctrl); // select all those parts if any is unselected
                                ResetRangeSelection();
                            }
                            else // otherwise, select and deselect items normally
                            {
                                ICollection <ResourcePartMap> parts;
                                // shift-click selects a range of items in the view
                                if (shift && resource == lastResourceClicked && partInfo != lastPartClicked && lastPartClicked != null)
                                {
                                    int partIndex = resource.parts.IndexOf(partInfo), lastIndex = resource.parts.IndexOf(lastPartClicked);
                                    if (lastIndex < 0)
                                    {
                                        lastIndex = partIndex;
                                    }
                                    parts = resource.parts.GetRange(Math.Min(partIndex, lastIndex), Math.Abs(partIndex - lastIndex) + 1);
                                }
                                else
                                {
                                    parts = new ResourcePartMap[] { partInfo };
                                }
                                SelectParts(resource, parts, !partInfo.isSelected || !ctrl && resource.parts.Count(p => p.isSelected) > parts.Count, ctrl);
                                lastResourceClicked = resource;
                                lastPartClicked     = partInfo;
                            }
                        }

                        GUILayout.FlexibleSpace();
                        if (settings.ShowShipNumber)
                        {
                            GUILayout.Label(partInfo.shipId.ToString(), labelStyle, width20);
                        }
                        if (settings.ShowStageNumber)
                        {
                            GUILayout.Label(partInfo.part.inverseStage.ToString(), labelStyle, width20);
                        }
                        if (settings.ShowMaxAmount)
                        {
                            GUILayout.Label(partResource.MaxAmount.ToString("N1"), labelStyle, width60);
                        }
                        if (settings.ShowCurrentAmount)
                        {
                            GUILayout.Label(partResource.Amount.ToString("N1"), labelStyle, width60);
                        }
                        if (settings.ShowPercentFull)
                        {
                            GUILayout.Label(percentFull.ToString("N1") + "%", labelStyle, width46);
                        }

                        GUILayout.Space(10);
                        //  Lock, Transfer In, Transfer Out, Balance, Dump, Highlight, then maybe Edit...??

                        if (settings.ShowToggles)
                        {
                            List <ResourcePartMap> selectedParts = partInfo.isSelected ? EnumerateSelectedParts().ToList() : new List <ResourcePartMap>(1)
                            {
                                partInfo
                            };
                            bool canPump = true, allHighlighted = true;
                            foreach (ResourcePartMap part in selectedParts)
                            {
                                canPump        &= part.resource.TransferMode == ResourceTransferMode.PUMP;
                                allHighlighted &= part.isHighlighted;
                            }
                            for (int toggleNum = 1; toggleNum < 6; toggleNum++)
                            {
                                if (canPump && isControllable)
                                {
                                    if (HighLogic.CurrentGame.Parameters.CustomParams <TacSettings_3>().lockedPos == toggleNum)
                                    {
                                        DrawToggleButton(partInfo, TransferDirection.LOCKED, "L", "Lock");
                                    }
                                    if (HighLogic.CurrentGame.Parameters.CustomParams <TacSettings_3>().transferInPos == toggleNum)
                                    {
                                        DrawToggleButton(partInfo, TransferDirection.IN, "I", "Transfer In");
                                    }
                                    if (HighLogic.CurrentGame.Parameters.CustomParams <TacSettings_3>().transferOutPos == toggleNum)
                                    {
                                        DrawToggleButton(partInfo, TransferDirection.OUT, "O", "Transfer Out");
                                    }
                                    if (HighLogic.CurrentGame.Parameters.CustomParams <TacSettings_3>().balancePos == toggleNum)
                                    {
                                        DrawToggleButton(partInfo, TransferDirection.BALANCE, "B", "Balance");
                                    }
                                    if (HighLogic.CurrentGame.Parameters.CustomParams <TacSettings_3>().dumpPos == toggleNum)
                                    {
                                        DrawToggleButton(partInfo, TransferDirection.DUMP, "D", "Dump");
                                    }
                                }
                                if (HighLogic.CurrentGame.Parameters.CustomParams <TacSettings_3>().lockedPos == toggleNum)
                                {
                                    bool highlight = GUILayout.Toggle(allHighlighted, new GUIContent("H", "Highlight"), buttonStyle, width20);
                                    if (highlight != allHighlighted)
                                    {
                                        foreach (ResourcePartMap part in selectedParts)
                                        {
                                            if (!highlight && part.isHighlighted && !part.isSelected)
                                            {
                                                part.part.SetHighlightDefault();
                                            }
                                            part.isHighlighted = highlight;
                                        }
                                        //guiChanged = true;
                                    }
                                }
                            }
                        }
                        if (HighLogic.CurrentGame.Parameters.CustomParams <TacSettings_1>().popupMenu)
                        {
                            PopupWindow.Draw(GetControlText(partInfo), windowPos, DrawPopupContents, coloredButtonStyle, partInfo, width20);
                        }

                        GUILayout.EndHorizontal();
                    }
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            GUILayout.BeginHorizontal();
            if (GUILayout.Toggle((settings.RateMultiplier == 100.0), "x100", buttonStyle))
            {
                settings.RateMultiplier = 100.0;
            }
            if (GUILayout.Toggle((settings.RateMultiplier == 10.0), "x10", buttonStyle))
            {
                settings.RateMultiplier = 10.0;
            }
            if (GUILayout.Toggle((settings.RateMultiplier == 1.0), "x1", buttonStyle))
            {
                settings.RateMultiplier = 1.0;
            }
            if (GUILayout.Toggle((settings.RateMultiplier == 0.1), "x0.1", buttonStyle))
            {
                settings.RateMultiplier = 0.1;
            }
            GUILayout.EndHorizontal();



            // Extra title bar buttons
#if false
            if (GUI.Button(new Rect(windowPos.width - 72, 4, 20, 20), resetContent, closeButtonStyle))
#else
            if (GUI.Button(new Rect(windowPos.width - 48, 4, 20, 20), resetContent, closeButtonStyle))
#endif
            {
                controller.RebuildActiveVesselLists();
            }
#if false
            if (!HighLogic.CurrentGame.Parameters.CustomParams <TacSettings_3>().disableOldSettings)
            {
                if (GUI.Button(new Rect(windowPos.width - 48, 4, 20, 20), settingsContent, closeButtonStyle))
                {
                    settingsWindow.ToggleVisible();
                }
            }
#endif
            if (GUI.Button(new Rect(windowPos.width - 24, 4, 20, 20), helpContent, closeButtonStyle))
            {
                helpWindow.ToggleVisible();
            }
        }
Exemplo n.º 9
0
 void Awake()
 {
     instance = this;
     windowId = "Tac.PopupWindow".GetHashCode();
     showPopup = false;
 }