private void DrawGood(Rect rect, ref int y, AgreementGood good)
        {
            Rect thingIconRect = new Rect(0, y, 27, 27);

            Widgets.ThingIcon(thingIconRect, good.Thing.GetInnerIfMinified().def);
            Widgets.InfoCardButton(40f, y, good.Thing);

            Rect labelRect = new Rect(60f, y, rect.width - 200, 27);

            Widgets.Label(labelRect, $"TradeSchedulingAgreementWindow_DrawGood_Good".Translate(good.Thing.LabelCap, good.Value));

            Rect entryRect = new Rect(rect.width - 200, y, 270, 27);

            Widgets.IntEntry(entryRect, ref good.CountToTransfer, ref good.EditBuffer);
            good.CountToTransfer = Mathf.Clamp(good.CountToTransfer, 0, good.Thing.stackCount);
            good.EditBuffer      = good.CountToTransfer.ToStringCached();

            if (good.CountToTransfer > 0)
            {
                Widgets.DrawHighlight(new Rect(0, y, rect.width, 27));
            }

            y += 35;
        }
        public override void DoWindowContents(Rect inRect)
        {
            float y = inRect.y + 10;

            Text.Anchor = TextAnchor.MiddleCenter;
            Widgets.Label(new Rect(inRect.x, y, inRect.width, 30), "TradeSchedulingAgreementWindow_SelectFactionLabel".Translate());
            y        += 31;
            Text.Font = GameFont.Medium;
            if (GUIUtils.DrawCustomButton(new Rect(inRect.x, y, inRect.width, 30), factionInteraction?.Faction.Name, Color.white))
            {
                List <FloatMenuOption> factions = new List <FloatMenuOption>();
                foreach (var faction in alliance.Factions)
                {
                    factions.Add(new FloatMenuOption(faction.Faction.Name, delegate {
                        SelectNewFaction(faction);
                    }));
                }

                Find.WindowStack.Add(new FloatMenu(factions));
            }

            y        += 40;
            Text.Font = GameFont.Small;
            Widgets.Label(new Rect(inRect.x, y, inRect.width, 30), "TradeSchedulingAgreementWindow_SelectSettlementLabel".Translate());
            y        += 31;
            Text.Font = GameFont.Medium;
            string settlementInfo = settlement == null ? string.Empty : "TradeSchedulingAgreementWindow_SelectedSettlement".Translate(settlement.Name, factionSettlements[settlement].ToString("f2")).ToString();

            if (GUIUtils.DrawCustomButton(new Rect(inRect.x, y, inRect.width, 30), settlementInfo, Color.white))
            {
                List <FloatMenuOption> settlements = new List <FloatMenuOption>();

                foreach (var settl in factionSettlements.Where(x => x.Value > 0f).OrderBy(x2 => x2.Value))
                {
                    settlements.Add(new FloatMenuOption($"{settl.Key.Name} - {settl.Value.ToString("f2")} {DaysLabelHolder}", delegate
                    {
                        SelectNewSettlement(settl.Key);
                    }));
                }

                Find.WindowStack.Add(new FloatMenu(settlements));
            }
            y        += 35;
            Text.Font = GameFont.Small;
            Widgets.Label(new Rect(inRect.x, y, inRect.width, 50), "TradeSchedulingAgreementWindow_SelectItems".Translate());
            y += 55;
            if (settlementGoods != null)
            {
                int  tmpY               = 0;
                Rect goodReect          = new Rect(0, tmpY, inRect.width - 100, 27);
                Rect goodsMainRect      = new Rect(inRect.x, y, inRect.width, 280);
                Rect scrollVertRectFact = new Rect(0, 0, inRect.width - 20, settlementGoods.Count * 35);
                Widgets.BeginScrollView(goodsMainRect, ref goodsSlider, scrollVertRectFact, true);
                for (int i = 0; i < settlementGoods.Count; i++)
                {
                    AgreementGood good = settlementGoods[i];

                    DrawGood(goodReect, ref tmpY, good);
                }
                Widgets.EndScrollView();
            }

            y += 290;

            CacheData();

            Rect trustButton = new Rect(inRect.x, y, 350, 27);
            int  tmpMaxTrust = factionInteraction.Trust < maxAdditionalTrust ? factionInteraction.Trust : maxAdditionalTrust;

            Widgets.Label(trustButton, "TradeSchedulingAgreementWindow_TrustAdditionalLabel".Translate(tmpMaxTrust));
            trustButton.width = 200;
            trustButton.x    += 355;
            Widgets.IntEntry(trustButton, ref trustAdditional, ref trustEditBuffer);
            trustButton.x += 210;
            ClampTrust(ref tmpMaxTrust);
            if (GUIUtils.DrawCustomButton(trustButton, "TradeSchedulingAgreementWindow_TrustAdditionaRecalculate".Translate(), Color.white))
            {
                RecalculateCosts();
            }

            y += 27;

            Text.Anchor = TextAnchor.UpperLeft;

            Rect resultLabelRect = new Rect(inRect.x, y, inRect.width, 105);

            Widgets.Label(resultLabelRect, "TradeSchedulingAgreementWindow_ResultInfo".Translate(totalCost,
                                                                                                 deliveryMethod == DeliveryMethod.Caravan ? "TradeSchedulingAgreementWindow_CaravanDelivery".Translate(factionSettlements[settlement].ToString("f2")) : "TradeSchedulingAgreementWindow_CapsuleDelivery".Translate(),
                                                                                                 agreementDelay.ToString("f2"), trustCost, trustAdditional));

            y += 110;

            Text.Anchor = TextAnchor.MiddleCenter;
            Rect resultButton = new Rect(inRect.x, y, inRect.width, 27);
            bool canSign      = CanSign(out string reason);

            if (GUIUtils.DrawCustomButton(resultButton, "TradeSchedulingAgreementWindow_CreateAgreement".Translate(), canSign ? Color.white : Color.gray))
            {
                if (!canSign)
                {
                    Messages.Message("TradeSchedulingAgreementWindow_CantSignRightNow".Translate(reason), MessageTypeDefOf.NegativeEvent);
                }
                else
                {
                    RecalculateCosts();

                    CreateAgreement(alliance, settlement, totalCost, (int)agreementDelay, settlementGoods.Where(x => x.CountToTransfer > 0).ToList(), factionInteraction, totalTrustCost, this, (int)formCaravanDelay);
                }
            }

            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.UpperLeft;
        }