Ejemplo n.º 1
0
 /// <summary>Sets the currently transferring option. Erasing the previous one.</summary>
 /// <param name="newOption">The new option or <c>null</c>.</param>
 void SetPendingTransferOption(ResourceTransferOption newOption)
 {
     if (newOption != pendingOption && pendingOption != null)
     {
         pendingOption.StopAllTransfers();
     }
     pendingOption = newOption;
     if (pendingOption == null && autoScaleSpeed)
     {
         transferSpeed = 1.0f;
     }
     if (pendingOption != null)
     {
         if (pendingOption.leftToRightTransferPress || pendingOption.leftToRightTransferToggle)
         {
             currentFromPart           = part;
             currentFromPartCapacities = pendingOption.leftCapacities;
             currentFromPartAmounts    = pendingOption.leftAmounts;
             currentToPart             = linkTarget.part;
             currentToPartCapacities   = pendingOption.rightCapacities;
             currentToPartAmounts      = pendingOption.rightAmounts;
         }
         else
         {
             currentFromPart           = linkTarget.part;
             currentFromPartCapacities = pendingOption.rightCapacities;
             currentFromPartAmounts    = pendingOption.rightAmounts;
             currentToPart             = part;
             currentToPartCapacities   = pendingOption.leftCapacities;
             currentToPartAmounts      = pendingOption.leftAmounts;
         }
     }
     else
     {
         currentFromPartCapacities = null;
         currentFromPartAmounts    = null;
         currentToPartCapacities   = null;
         currentToPartAmounts      = null;
     }
     UpdateResourcesTransferGui(force: true);
 }
Ejemplo n.º 2
0
        /// <summary>Updates the resources amounts and the transfer states in GUI.</summary>
        /// <remarks>This method must be performance optimized.</remarks>
        /// <param name="resOption">The resource transfer option to update.</param>
        void UpdateOptionTransferGui(ResourceTransferOption resOption)
        {
            var leftInfoString  = "";
            var rightInfoString = "";

            resOption.canMoveRightToLeft = true;
            resOption.canMoveLeftToRight = true;
            for (var i = 0; i < resOption.resources.Length; i++)
            {
                part.GetConnectedResourceTotals(
                    resOption.resources[i], ResourceFlowMode.ALL_VESSEL_BALANCE,
                    out resOption.leftAmounts[i], out resOption.leftCapacities[i]);
                leftInfoString += (i > 0 ? "\n" : "")
                                  + CompactNumberType.Format(resOption.leftAmounts[i])
                                  + " / "
                                  + CompactNumberType.Format(resOption.leftCapacities[i]);
                linkTarget.part.GetConnectedResourceTotals(
                    resOption.resources[i], ResourceFlowMode.ALL_VESSEL_BALANCE,
                    out resOption.rightAmounts[i], out resOption.rightCapacities[i]);
                rightInfoString += (i > 0 ? "\n" : "")
                                   + CompactNumberType.Format(resOption.rightAmounts[i])
                                   + " / "
                                   + CompactNumberType.Format(resOption.rightCapacities[i]);
                if (resOption.rightAmounts[i] < double.Epsilon ||
                    resOption.leftAmounts[i] >= resOption.leftCapacities[i])
                {
                    resOption.canMoveRightToLeft = false;
                }
                if (resOption.leftAmounts[i] < double.Epsilon ||
                    resOption.rightAmounts[i] >= resOption.rightCapacities[i])
                {
                    resOption.canMoveLeftToRight = false;
                }
            }
            resOption.leftInfo.text  = leftInfoString;
            resOption.rightInfo.text = rightInfoString;
        }