コード例 #1
0
        private void TransferOut(double maxFlow, ResourceInfo resourceInfo, ResourcePartMap srcPart)
        {
            double available = srcPart.resource.Amount;

            if (available < AmountEpsilon)
            {
                return;
            }
            available = Math.Min(available, maxFlow);

            var destParts = resourceInfo.parts.FindAll(
                rpm => (rpm.resource.MaxAmount - rpm.resource.Amount) >= AmountEpsilon &&
                (rpm.direction == TransferDirection.NONE || rpm.direction == TransferDirection.IN || rpm.direction == TransferDirection.BALANCE));

            if (destParts.Count == 0)
            {
                return;
            }
            double giveToEach = available / destParts.Count;

            foreach (ResourcePartMap destPart in destParts)
            {
                if (srcPart.part != destPart.part)
                {
                    srcPart.resource.TransferTo(destPart.resource, giveToEach);
                }
            }
        }
コード例 #2
0
        // Actually this most often does a refresh of an already added tank
        private void AddResource(string resourceName, Part part, Dictionary <object, int> shipIds, Func <Part, string, PartResourceInfo> infoCreator)
        {
            ResourceInfo resourceInfo;

            if (!vesselInfo.resources.TryGetValue(resourceName, out resourceInfo))
            {
                vesselInfo.resources[resourceName] = resourceInfo = new ResourceInfo(GetResourceTitle(resourceName));
            }
            List <ResourcePartMap> resourceParts = resourceInfo.parts;
            ResourcePartMap        partInfo      = resourceParts.Find(info => info.part.Equals(part));

            if (partInfo == null)
            {
                resourceParts.Add(new ResourcePartMap(infoCreator(part, resourceName), part, shipIds[part]));

//				string ToLog = "ADD " + part.name + " - " + resourceName;
//				if( part.Resources.Contains( resourceName ) ) // _RocketFuel does't exist
//					ToLog += ":" + part.Resources[ resourceName ].amount.ToString( );
//				this.Log( ToLog );
            }
            else
            {
                // Make sure we are still pointing at the right resource instance. This is a fix for compatibility with StretchyTanks.
                partInfo.resource.Refresh(part);
//				string ToLog = "REFRESH " + part.name + " - " + resourceName;
//				if( part.Resources.Contains( resourceName ) ) // _RocketFuel does't exist
//					ToLog += ":" + part.Resources[ resourceName ].amount.ToString( );
//				this.Log( ToLog );
            }
        }
コード例 #3
0
        private void TransferIn(double maxFlow, ResourceInfo resourceInfo, ResourcePartMap destPart)
        {
            double required = destPart.resource.MaxAmount - destPart.resource.Amount;

            if (required < AmountEpsilon)
            {
                return;
            }
            required = Math.Min(required, maxFlow);

            var srcParts = resourceInfo.parts.FindAll(
                rpm => (rpm.resource.Amount >= AmountEpsilon) &&
                (rpm.direction == TransferDirection.NONE || rpm.direction == TransferDirection.OUT || rpm.direction == TransferDirection.DUMP ||
                 rpm.direction == TransferDirection.BALANCE));

            if (srcParts.Count == 0)
            {
                return;
            }
            double takeFromEach = required / srcParts.Count;

            foreach (ResourcePartMap srcPart in srcParts)
            {
                if (destPart.part != srcPart.part)
                {
                    srcPart.resource.TransferTo(destPart.resource, takeFromEach);
                }
            }
        }
コード例 #4
0
 private void SelectPart(ResourceInfo resource, ResourcePartMap part, bool selected)
 {
     part.isSelected = selected;
     if ((!selected || !resource.isShowing) && !part.isHighlighted)
     {
         part.part.SetHighlightDefault();
     }
 }
コード例 #5
0
        private void DumpOut(double maxFlow, ResourceInfo resourceInfo, ResourcePartMap partInfo)
        {
            double available = partInfo.resource.Amount;

            if (available < AmountEpsilon)
            {
                return;
            }
            partInfo.resource.SetAmount(Math.Max(0, available - maxFlow));
        }
コード例 #6
0
        private void RebuildLists(Vessel vessel)
        {
            this.Log("Rebuilding resource lists.");

            List <string> toDelete = new List <string>();

            foreach (KeyValuePair <string, ResourceInfo> resourceEntry in resources)
            {
                resourceEntry.Value.parts.RemoveAll(partInfo => !vessel.parts.Contains(partInfo.part));

                if (resourceEntry.Value.parts.Count == 0)
                {
                    toDelete.Add(resourceEntry.Key);
                }
            }

            foreach (string resource in toDelete)
            {
                resources.Remove(resource);
            }

            foreach (Part part in vessel.parts)
            {
                foreach (PartResource resource in part.Resources)
                {
                    if (resources.ContainsKey(resource.resourceName))
                    {
                        List <ResourcePartMap> resourceParts = resources[resource.resourceName].parts;
                        ResourcePartMap        partInfo      = resourceParts.Find(info => info.part.Equals(part));

                        if (partInfo == null)
                        {
                            resourceParts.Add(new ResourcePartMap(resource, part));
                        }
                        else
                        {
                            // Make sure we are still pointing at the right resource instance. This is a fix for compatibility with StretchyTanks.
                            partInfo.resource = resource;
                        }
                    }
                    else
                    {
                        ResourceInfo resourceInfo = new ResourceInfo();
                        resourceInfo.parts.Add(new ResourcePartMap(resource, part));

                        resources[resource.resourceName] = resourceInfo;
                    }
                }
            }

            numberOfParts   = vessel.parts.Count;
            currentVessel   = vessel;
            vesselSituation = vessel.situation;
        }
コード例 #7
0
 /*
  * Checks the PartResource's flow state (controlled from the part's right click menu), and makes our state match its state.
  */
 private static void SynchronizeFlowState(ResourcePartMap partInfo)
 {
     if (partInfo.resource.flowState == true && partInfo.direction == TransferDirection.LOCKED)
     {
         partInfo.direction = TransferDirection.NONE;
     }
     else if (partInfo.resource.flowState == false && partInfo.direction != TransferDirection.LOCKED)
     {
         partInfo.direction = TransferDirection.LOCKED;
     }
 }
コード例 #8
0
        private bool DrawEditPopupContents(int windowId, object parameter)
        {
            ResourcePartMap partInfo    = (ResourcePartMap)parameter;
            bool            shouldClose = false;

            if (newAmount > partInfo.resource.MaxAmount || newAmount < 0)
            {
                editStyle.normal.textColor  = Color.red;
                editStyle.focused.textColor = Color.red;
                labelStyle.normal.textColor = Color.red;
            }
            else
            {
                editStyle.normal.textColor  = Color.white;
                editStyle.focused.textColor = Color.white;
                labelStyle.normal.textColor = Color.white;
            }

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Empty", buttonStyle))
            {
                newAmount = 0;
            }
            if (GUILayout.Button("Fill", buttonStyle))
            {
                newAmount = partInfo.resource.MaxAmount;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Enter new amount:", labelStyle);
            newAmount = Utilities.ShowTextField(newAmount, 10, editStyle, GUILayout.MinWidth(60));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("OK", buttonStyle) && newAmount <= partInfo.resource.MaxAmount && newAmount >= 0)
            {
                partInfo.resource.SetAmount(newAmount);
                shouldClose = true;
            }
            if (GUILayout.Button("Cancel", buttonStyle))
            {
                shouldClose = true;
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            return(shouldClose);
        }
コード例 #9
0
        private void DrawToggleButton(ResourcePartMap partInfo, TransferDirection toggleDirection, string text, string toolTip)
        {
            bool b    = (partInfo.direction == toggleDirection);
            bool bout = GUILayout.Toggle(b, new GUIContent(text, toolTip), buttonStyle, width20);

            if (b && !bout)
            {
                partInfo.direction = TransferDirection.NONE;
            }
            else
            {
                if (bout)
                {
                    partInfo.direction = toggleDirection;
                }
            }
            if (b != bout)
            {
                List <ResourcePartMap> parts = partInfo.isSelected ?  EnumerateSelectedParts().ToList() : new List <ResourcePartMap>(1)
                {
                    partInfo
                };
                foreach (ResourcePartMap rmp in parts)
                {
                    if (partInfo.direction == TransferDirection.NONE) // if the user turned a direction off...
                    {
                        //if (rmp.direction != toggleDirection)
                        {
                            if (toggleDirection == TransferDirection.LOCKED)
                            {
                                rmp.resource.Locked = false;

                                rmp.direction = TransferDirection.NONE;
                            }
                        }
                    }
                    else
                    {
                        //if (rmp.direction != toggleDirection)
                        {
                            if (toggleDirection == TransferDirection.LOCKED)
                            {
                                rmp.resource.Locked = true;

                                rmp.direction = toggleDirection;
                            }
                        }
                    }
                }
            }
        }
コード例 #10
0
 public void SortParts(Comparison <ResourcePartMap> comparer)
 {
     foreach (ResourceInfo resource in vesselInfo.resources.Values)
     {
         // we need a stable sort, but the built-in .NET sorting methods are unstable, so we'll use insertion sort
         List <ResourcePartMap> parts = resource.parts;
         for (int i = 1; i < parts.Count; i++)
         {
             ResourcePartMap part = parts[i];
             int             j;
             for (j = i; j > 0 && comparer(parts[j - 1], part) > 0; j--)
             {
                 parts[j] = parts[j - 1];
             }
             parts[j] = part;
         }
     }
 }
コード例 #11
0
        private void TransferOut(double deltaTime, ResourceInfo resourceInfo, ResourcePartMap partInfo)
        {
            var otherParts = resourceInfo.parts.FindAll(rpm => ((rpm.resource.maxAmount - rpm.resource.amount) > 0) &&
                                                        (rpm.direction == TransferDirection.NONE || rpm.direction == TransferDirection.IN || rpm.direction == TransferDirection.BALANCE));
            double available  = Math.Min(settings.MaxFuelFlow * settings.RateMultiplier * deltaTime, partInfo.resource.amount);
            double giveToEach = available / otherParts.Count;
            double totalGiven = 0.0;

            foreach (ResourcePartMap otherPartInfo in otherParts)
            {
                if (partInfo.part != otherPartInfo.part)
                {
                    double amountGiven = Math.Min(giveToEach, otherPartInfo.resource.maxAmount - otherPartInfo.resource.amount);
                    otherPartInfo.resource.amount += amountGiven;

                    totalGiven += amountGiven;
                }
            }

            partInfo.resource.amount -= totalGiven;
        }
コード例 #12
0
        private void TransferIn(double deltaTime, ResourceInfo resourceInfo, ResourcePartMap partInfo)
        {
            var otherParts = resourceInfo.parts.FindAll(rpm => (rpm.resource.amount > 0) &&
                                                        (rpm.direction == TransferDirection.NONE || rpm.direction == TransferDirection.OUT || rpm.direction == TransferDirection.DUMP || rpm.direction == TransferDirection.BALANCE));
            double available    = Math.Min(settings.MaxFuelFlow * settings.RateMultiplier * deltaTime, partInfo.resource.maxAmount - partInfo.resource.amount);
            double takeFromEach = available / otherParts.Count;
            double totalTaken   = 0.0;

            foreach (ResourcePartMap otherPartInfo in otherParts)
            {
                if (partInfo.part != otherPartInfo.part)
                {
                    double amountTaken = Math.Min(takeFromEach, otherPartInfo.resource.amount);
                    otherPartInfo.resource.amount -= amountTaken;

                    totalTaken += amountTaken;
                }
            }

            partInfo.resource.amount += totalTaken;
        }
コード例 #13
0
        private string GetControlText(ResourcePartMap partInfo)
        {
            switch (partInfo.direction)
            {
            case TransferDirection.IN:
                return("I");

            case TransferDirection.OUT:
                return("O");

            case TransferDirection.BALANCE:
                return("B");

            case TransferDirection.DUMP:
                return("D");

            case TransferDirection.LOCKED:
                return("L");

            default:
                return(partInfo.isHighlighted ? "H" : "-");
            }
        }
コード例 #14
0
        private void TransferIn(double deltaTime, ResourceInfo resourceInfo, ResourcePartMap partInfo)
        {
            var otherParts = resourceInfo.parts.FindAll(rpm => (rpm.resource.amount > 0)
                && (rpm.direction == TransferDirection.NONE || rpm.direction == TransferDirection.OUT || rpm.direction == TransferDirection.DUMP || rpm.direction == TransferDirection.BALANCE));
            double available = Math.Min(settings.MaxFuelFlow * settings.RateMultiplier * deltaTime, partInfo.resource.maxAmount - partInfo.resource.amount);
            double takeFromEach = available / otherParts.Count;
            double totalTaken = 0.0;

            foreach (ResourcePartMap otherPartInfo in otherParts)
            {
                if (partInfo.part != otherPartInfo.part)
                {
                    double amountTaken = Math.Min(takeFromEach, otherPartInfo.resource.amount);
                    otherPartInfo.resource.amount -= amountTaken;

                    totalTaken += amountTaken;
                }
            }

            partInfo.resource.amount += totalTaken;
        }
コード例 #15
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();
            }
        }
コード例 #16
0
 private void ResetRangeSelection()
 {
     lastResourceClicked = null;
     lastPartClicked     = null;
 }
コード例 #17
0
 private void DumpOut(double deltaTime, ResourceInfo resourceInfo, ResourcePartMap partInfo)
 {
     double available = Math.Min(settings.MaxFuelFlow * settings.RateMultiplier * deltaTime, partInfo.resource.amount);
     partInfo.resource.amount -= available;
 }
コード例 #18
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);
        }
コード例 #19
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( );
            }
        }
コード例 #20
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);
            }
        }
コード例 #21
0
 public PartPercentFull(ResourcePartMap partInfo, double percentFull)
 {
     this.partInfo = partInfo;
     this.percentFull = percentFull;
 }
コード例 #22
0
        private void TransferOut(double deltaTime, ResourceInfo resourceInfo, ResourcePartMap partInfo)
        {
            var otherParts = resourceInfo.parts.FindAll(rpm => ((rpm.resource.maxAmount - rpm.resource.amount) > 0)
                && (rpm.direction == TransferDirection.NONE || rpm.direction == TransferDirection.IN || rpm.direction == TransferDirection.BALANCE));
            double available = Math.Min(settings.MaxFuelFlow * settings.RateMultiplier * deltaTime, partInfo.resource.amount);
            double giveToEach = available / otherParts.Count;
            double totalGiven = 0.0;

            foreach (ResourcePartMap otherPartInfo in otherParts)
            {
                if (partInfo.part != otherPartInfo.part)
                {
                    double amountGiven = Math.Min(giveToEach, otherPartInfo.resource.maxAmount - otherPartInfo.resource.amount);
                    otherPartInfo.resource.amount += amountGiven;

                    totalGiven += amountGiven;
                }
            }

            partInfo.resource.amount -= totalGiven;
        }
コード例 #23
0
 /*
  * Checks the PartResource's flow state (controlled from the part's right click menu), and makes our state match its state.
  */
 private static void SynchronizeFlowState(ResourcePartMap partInfo)
 {
     if (partInfo.resource.flowState == true && partInfo.direction == TransferDirection.LOCKED)
     {
         partInfo.direction = TransferDirection.NONE;
     }
     else if (partInfo.resource.flowState == false && partInfo.direction != TransferDirection.LOCKED)
     {
         partInfo.direction = TransferDirection.LOCKED;
     }
 }
コード例 #24
0
        private void DumpOut(double deltaTime, ResourceInfo resourceInfo, ResourcePartMap partInfo)
        {
            double available = Math.Min(settings.MaxFuelFlow * settings.RateMultiplier * deltaTime, partInfo.resource.amount);

            partInfo.resource.amount -= available;
        }
コード例 #25
0
 public PartPercentFull(ResourcePartMap partInfo, double percentFull)
 {
     this.partInfo    = partInfo;
     this.percentFull = percentFull;
 }