Exemplo n.º 1
0
 private bool AddOneIfMassAllows(Transferable transferable)
 {
     if (transferable.CanAdjustBy(1).Accepted&& MassUsage + transferable.ThingDef.BaseMass < MassCapacity)
     {
         transferable.AdjustBy(1);
         massUsageDirty = true;
         return(true);
     }
     return(false);
 }
        private static void DoCountAdjustInterfaceInternal(Rect rect, Transferable trad, int index, int min, int max, bool flash, bool readOnly)
        {
            rect = rect.Rounded();
            Rect rect2 = new Rect(rect.center.x - 45f, rect.center.y - 12.5f, 90f, 25f).Rounded();

            if (flash)
            {
                GUI.DrawTexture(rect2, TransferableUIUtility.FlashTex);
            }
            TransferableOneWay transferableOneWay = trad as TransferableOneWay;
            bool flag = transferableOneWay != null && transferableOneWay.HasAnyThing && transferableOneWay.AnyThing is Pawn && transferableOneWay.MaxCount == 1;

            if (!trad.Interactive || readOnly)
            {
                if (flag)
                {
                    bool flag2 = trad.CountToTransfer != 0;
                    Widgets.Checkbox(rect2.position, ref flag2, 24f, true, false, null, null);
                }
                else
                {
                    GUI.color   = ((trad.CountToTransfer != 0) ? Color.white : TransferableUIUtility.ZeroCountColor);
                    Text.Anchor = TextAnchor.MiddleCenter;
                    Widgets.Label(rect2, trad.CountToTransfer.ToStringCached());
                }
            }
            else if (flag)
            {
                bool flag3 = trad.CountToTransfer != 0;
                bool flag4 = flag3;
                Widgets.Checkbox(rect2.position, ref flag4, 24f, false, true, null, null);
                if (flag4 != flag3)
                {
                    if (flag4)
                    {
                        trad.AdjustTo(trad.GetMaximumToTransfer());
                    }
                    else
                    {
                        trad.AdjustTo(trad.GetMinimumToTransfer());
                    }
                }
            }
            else
            {
                Rect rect3 = rect2.ContractedBy(2f);
                rect3.xMax -= 15f;
                rect3.xMin += 16f;
                int    countToTransfer = trad.CountToTransfer;
                string editBuffer      = trad.EditBuffer;
                Widgets.TextFieldNumeric <int>(rect3, ref countToTransfer, ref editBuffer, (float)min, (float)max);
                trad.AdjustTo(countToTransfer);
                trad.EditBuffer = editBuffer;
            }
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.color   = Color.white;
            if (trad.Interactive && !flag)
            {
                TransferablePositiveCountDirection positiveCountDirection = trad.PositiveCountDirection;
                int  num   = (positiveCountDirection != TransferablePositiveCountDirection.Source) ? -1 : 1;
                int  num2  = GenUI.CurrentAdjustmentMultiplier();
                bool flag5 = trad.GetRange() == 1;
                if (trad.CanAdjustBy(num * num2).Accepted)
                {
                    Rect rect4 = new Rect(rect2.x - 30f, rect.y, 30f, rect.height);
                    if (flag5)
                    {
                        rect4.x     -= rect4.width;
                        rect4.width += rect4.width;
                    }
                    if (Widgets.ButtonText(rect4, "<", true, false, true))
                    {
                        trad.AdjustBy(num * num2);
                        SoundDefOf.Tick_High.PlayOneShotOnCamera(null);
                    }
                    if (!flag5)
                    {
                        string label = "<<";
                        int?   num3  = null;
                        int    num4  = 0;
                        for (int i = 0; i < TransferableUIUtility.stoppingPoints.Count; i++)
                        {
                            TransferableCountToTransferStoppingPoint transferableCountToTransferStoppingPoint = TransferableUIUtility.stoppingPoints[i];
                            if (positiveCountDirection == TransferablePositiveCountDirection.Source)
                            {
                                if (trad.CountToTransfer < transferableCountToTransferStoppingPoint.threshold && (transferableCountToTransferStoppingPoint.threshold < num4 || !num3.HasValue))
                                {
                                    label = transferableCountToTransferStoppingPoint.leftLabel;
                                    num3  = new int?(transferableCountToTransferStoppingPoint.threshold);
                                }
                            }
                            else if (trad.CountToTransfer > transferableCountToTransferStoppingPoint.threshold && (transferableCountToTransferStoppingPoint.threshold > num4 || !num3.HasValue))
                            {
                                label = transferableCountToTransferStoppingPoint.leftLabel;
                                num3  = new int?(transferableCountToTransferStoppingPoint.threshold);
                            }
                        }
                        rect4.x -= rect4.width;
                        if (Widgets.ButtonText(rect4, label, true, false, true))
                        {
                            if (num3.HasValue)
                            {
                                trad.AdjustTo(num3.Value);
                            }
                            else if (num == 1)
                            {
                                trad.AdjustTo(trad.GetMaximumToTransfer());
                            }
                            else
                            {
                                trad.AdjustTo(trad.GetMinimumToTransfer());
                            }
                            SoundDefOf.Tick_High.PlayOneShotOnCamera(null);
                        }
                    }
                }
                if (trad.CanAdjustBy(-num * num2).Accepted)
                {
                    Rect rect5 = new Rect(rect2.xMax, rect.y, 30f, rect.height);
                    if (flag5)
                    {
                        rect5.width += rect5.width;
                    }
                    if (Widgets.ButtonText(rect5, ">", true, false, true))
                    {
                        trad.AdjustBy(-num * num2);
                        SoundDefOf.Tick_Low.PlayOneShotOnCamera(null);
                    }
                    if (!flag5)
                    {
                        string label2 = ">>";
                        int?   num5   = null;
                        int    num6   = 0;
                        for (int j = 0; j < TransferableUIUtility.stoppingPoints.Count; j++)
                        {
                            TransferableCountToTransferStoppingPoint transferableCountToTransferStoppingPoint2 = TransferableUIUtility.stoppingPoints[j];
                            if (positiveCountDirection == TransferablePositiveCountDirection.Destination)
                            {
                                if (trad.CountToTransfer < transferableCountToTransferStoppingPoint2.threshold && (transferableCountToTransferStoppingPoint2.threshold < num6 || !num5.HasValue))
                                {
                                    label2 = transferableCountToTransferStoppingPoint2.rightLabel;
                                    num5   = new int?(transferableCountToTransferStoppingPoint2.threshold);
                                }
                            }
                            else if (trad.CountToTransfer > transferableCountToTransferStoppingPoint2.threshold && (transferableCountToTransferStoppingPoint2.threshold > num6 || !num5.HasValue))
                            {
                                label2 = transferableCountToTransferStoppingPoint2.rightLabel;
                                num5   = new int?(transferableCountToTransferStoppingPoint2.threshold);
                            }
                        }
                        rect5.x += rect5.width;
                        if (Widgets.ButtonText(rect5, label2, true, false, true))
                        {
                            if (num5.HasValue)
                            {
                                trad.AdjustTo(num5.Value);
                            }
                            else if (num == 1)
                            {
                                trad.AdjustTo(trad.GetMinimumToTransfer());
                            }
                            else
                            {
                                trad.AdjustTo(trad.GetMaximumToTransfer());
                            }
                            SoundDefOf.Tick_Low.PlayOneShotOnCamera(null);
                        }
                    }
                }
            }
            if (trad.CountToTransfer != 0)
            {
                Rect position = new Rect(rect2.x + rect2.width / 2f - (float)(TransferableUIUtility.TradeArrow.width / 2), rect2.y + rect2.height / 2f - (float)(TransferableUIUtility.TradeArrow.height / 2), (float)TransferableUIUtility.TradeArrow.width, (float)TransferableUIUtility.TradeArrow.height);
                TransferablePositiveCountDirection positiveCountDirection2 = trad.PositiveCountDirection;
                if ((positiveCountDirection2 == TransferablePositiveCountDirection.Source && trad.CountToTransfer > 0) || (positiveCountDirection2 == TransferablePositiveCountDirection.Destination && trad.CountToTransfer < 0))
                {
                    position.x     += position.width;
                    position.width *= -1f;
                }
                GUI.DrawTexture(position, TransferableUIUtility.TradeArrow);
            }
        }