public static void AskPayByBankNotes(Tradeable currency, bool isVirtual = false) { if (!isVirtual && !Methods.CanColonyAffordTrade(TradeSession.deal)) { Find.WindowStack.WindowOfType <Dialog_Trade>().FlashSilver(); Messages.Message("MessageColonyCannotAfford".Translate(), MessageTypeDefOf.RejectInput); return; } int playersilver = currency.CountHeldBy(Transactor.Colony); int notesCountAvaliable = GetNotesCountAvaliable(Transactor.Colony); int countToTransfer = currency.CountToTransfer; int num = 0; for (int num2 = Methods.cacheNotes.Count - 1; num2 > -1; num2--) { num += Methods.cacheNotes[num2].CountHeldBy(Transactor.Trader); } Find.WindowStack.Add(new Dialog_PayByBankNotes(countToTransfer, playersilver, notesCountAvaliable, currency.CountHeldBy(Transactor.Trader), num, isVirtual)); }
public override void DoWindowContents(Rect inRect) { Rect rect = new Rect(inRect.x, inRect.y, inRect.width, 45f); Text.Anchor = TextAnchor.MiddleCenter; Text.Font = GameFont.Medium; if (isVirtual) { Widgets.Label(rect, VirtualTrader.TipString(1)); TooltipHandler.TipRegion(rect, VirtualTrader.TipString(2)); } else { Widgets.Label(rect, "AdjustPayment".Translate()); } float height = rect.height; Color color = GUI.color; GUI.color = Color.gray; Widgets.DrawLineHorizontal(inRect.x, height, inRect.width); GUI.color = color; height += 2.5f; Rect rect2 = new Rect(inRect.x, height, inRect.width, 30f); DrawTradeableRow(rect2, silverTradeable, 1); int countToTransfer = notesTradeable.CountToTransfer; int countToTransfer2 = silverTradeable.CountToTransfer; Rect rect3 = new Rect(inRect.x, height + 30f, inRect.width, 30f); DrawTradeableRow(rect3, notesTradeable, 2); if (countToTransfer != notesTradeable.CountToTransfer) { if (!isVirtual || !VirtualTrader.UniqueBalanceMethod) { int countToTransfer3 = silverTradeable.CountToTransfer; silverTradeable.ForceTo(countToTransfer3 + (countToTransfer - notesTradeable.CountToTransfer) * 1000); } else { int notes = notesTradeable.CountToTransfer; int silver = silverTradeable.CountToTransfer; VirtualTrader.BalanceMethod(countToTransfer2, countToTransfer, ref silver, ref notes); notesTradeable.ForceTo(notes); silverTradeable.ForceTo(silver); } } Rect rect4 = new Rect(rect2.x, rect2.y, 27f, 27f); if (Mouse.IsOver(rect4)) { Widgets.DrawHighlight(rect4); } Widgets.ThingIcon(rect4, silverTradeable.AnyThing); Rect rect5 = new Rect(rect2.x, rect3.y, 27f, 27f); if (Mouse.IsOver(rect5)) { Widgets.DrawHighlight(rect5); } Widgets.ThingIcon(rect5, notesTradeable.AnyThing); if (isVirtual) { TooltipHandler.TipRegion(rect4, VirtualTrader.TipString(3)); TooltipHandler.TipRegion(rect5, VirtualTrader.TipString(4)); } else { TooltipHandler.TipRegion(rect4, "SilverTip".Translate()); TooltipHandler.TipRegion(rect5, "BankNoteTip".Translate()); } float num = 120f; float height2 = 40f; if (Widgets.ButtonText(new Rect(inRect.width * 9f / 16f, inRect.height - 55f, num, height2), "CancelButton".Translate())) { Event.current.Use(); Close(doCloseSound: false); } if (Widgets.ButtonText(new Rect(inRect.width * 7f / 16f - num, inRect.height - 55f, num, height2), "AcceptButton".Translate())) { Action ExecuteTrade = delegate { currencyfmt = new Pair <int, int>(notesTradeable.CountToTransfer, silverTradeable.CountToTransfer); if (TradeSession.deal.DoExecute()) { SoundDefOf.ExecuteTrade.PlayOneShotOnCamera(); if (TradeSession.trader is Pawn pawn) { TaleRecorder.RecordTale(TaleDefOf.TradedWith, TradeSession.playerNegotiator, pawn); } if (isVirtual) { VirtualTrader.CloseTradeUI(); } else { Find.WindowStack.WindowOfType <Dialog_Trade>().Close(doCloseSound: false); } } Close(doCloseSound: false); }; Action ConfirmedExecuteTrade = delegate { silverTradeable.ForceTo(silverTradeable.CountHeldBy(Transactor.Trader)); ExecuteTrade(); }; ((Action) delegate { if (!TestPlayerSilver()) { Messages.Message("NotEnoughSilverColony".Translate(), MessageTypeDefOf.RejectInput); } else if (isVirtual && VirtualTrader.CustomCheckViolation(silverTradeable, notesTradeable)) { VirtualTrader.CustomViolationAction(); } else if (!TestTraderSilver()) { SoundDefOf.ClickReject.PlayOneShotOnCamera(); Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation("ConfirmTraderShortFunds".Translate(), ConfirmedExecuteTrade)); } else { ExecuteTrade(); } })(); Event.current.Use(); } }
public void DrawTradeableRow(Rect rect, Tradeable trad, int index) { if (index == 1) { Widgets.DrawLightHighlight(rect); } Text.Font = GameFont.Small; GUI.BeginGroup(rect); float width = rect.width; int num = trad.CountHeldBy(Transactor.Trader); if (num != 0) { Rect rect2 = new Rect(width - 75f, 0f, 75f, rect.height); if (Mouse.IsOver(rect2)) { Widgets.DrawHighlight(rect2); } Text.Anchor = TextAnchor.MiddleRight; Rect rect3 = rect2; rect3.xMin += 5f; rect3.xMax -= 5f; Widgets.Label(rect3, num.ToStringCached()); TooltipHandler.TipRegion(rect2, "TraderCount".Translate()); } width -= 85f; Rect rect4 = new Rect(width - 240f, 0f, 240f, rect.height); if (index == 2 && notesTradeable.CountHeldBy(Transactor.Colony) == 0 && notesTradeable.CountHeldBy(Transactor.Trader) == 0) { Text.Anchor = TextAnchor.MiddleCenter; Color color = GUI.color; GUI.color = Color.gray; Widgets.Label(rect4, "NoNotes".Translate()); GUI.color = color; } else if (index == 1 && isVirtual && VirtualTrader.SilverAlsoAdjustable) { ExtUtil.DoCountAdjustInterfaceForSilver(rect4, trad, index, -trad.CountHeldBy(Transactor.Colony), trad.CountHeldBy(Transactor.Trader), flash: false); } else { TransferableUIUtility.DoCountAdjustInterface(rect4, trad, index, -trad.CountHeldBy(Transactor.Colony), trad.CountHeldBy(Transactor.Trader)); } width -= 240f; int num2 = trad.CountHeldBy(Transactor.Colony); if (num2 != 0) { Rect rect5 = new Rect(width - 75f - 10f, 0f, 75f, rect.height); if (Mouse.IsOver(rect5)) { Widgets.DrawHighlight(rect5); } Text.Anchor = TextAnchor.MiddleLeft; Rect rect6 = rect5; rect6.xMin += 5f; rect6.xMax -= 5f; Widgets.Label(rect6, num2.ToStringCached()); TooltipHandler.TipRegion(rect5, "ColonyCount".Translate()); } GenUI.ResetLabelAlign(); GUI.EndGroup(); }
private void DrawTradeableRow(Rect rowRect, ThingEntry entry, int index) { if (index % 2 == 1) { Widgets.DrawLightHighlight(rowRect); } Tradeable trade = entry.tradeable; // Begin Row group GUI.BeginGroup(rowRect); float x = 0; // starting from left // Draw item icon and info icon Text.Anchor = TextAnchor.MiddleLeft; Rect idRect = new Rect(x, 0, iconNameAreaWidth, rowRect.height); TransferableUIUtility.DoExtraAnimalIcons(trade, rowRect, ref x); DrawTradeableLabels(idRect, entry); x += iconNameAreaWidth; // Draw the price for requesting the item Rect priceTextArea = new Rect(x, 0, priceTextAreaWidth, rowRect.height); float price = DrawPrice(priceTextArea, trade); x += priceTextAreaWidth; // Draw the number the colony currently has, if any int colonyItemCount = trade.CountHeldBy(Transactor.Colony); if (colonyItemCount != 0) { Rect colonyItemCountArea = new Rect(x, 0, colonyItemCountAreaWidth, rowRect.height); if (Mouse.IsOver(colonyItemCountArea)) { Widgets.DrawHighlight(colonyItemCountArea); } Rect paddedRect = colonyItemCountArea; paddedRect.xMin += 5f; paddedRect.xMax -= 5f; Widgets.Label(paddedRect, colonyItemCount.ToStringCached()); TooltipHandler.TipRegion(colonyItemCountArea, colonyCountTooltipText); } // Draw the input box to select number of requests Rect countAdjustInterfaceRect = new Rect(rightAlignOffset, 0, rightContentSize, rowRect.height); Rect interactiveNumericFieldArea = new Rect(countAdjustInterfaceRect.center.x - 45f, countAdjustInterfaceRect.center.y - 12.5f, 90f, 25f).Rounded(); Rect paddedNumericFieldArea = interactiveNumericFieldArea.ContractedBy(2f); paddedNumericFieldArea.xMax -= 15f; paddedNumericFieldArea.xMin += 16f; int amountRequested = requestSession.deal.GetCountForItem(thingTypeFilter, trade); string amountAsString = amountRequested.ToString(); Widgets.TextFieldNumeric(paddedNumericFieldArea, ref amountRequested, ref amountAsString, 0, float.MaxValue); requestSession.deal.AdjustItemRequest(thingTypeFilter, entry, amountRequested, price); // Draw the reset to zero button by input field if (amountRequested > 0) { Rect resetToZeroButton = interactiveNumericFieldArea; resetToZeroButton.x -= resetItemCountAreaWidth - 5; resetToZeroButton.width = resetItemCountAreaWidth; if (Widgets.ButtonText(resetToZeroButton, "0")) { requestSession.deal.AdjustItemRequest(thingTypeFilter, entry, 0, price); } } // End Row group GenUI.ResetLabelAlign(); GUI.EndGroup(); }
public static void DrawTradeableRow(Rect rect, Tradeable trad, int index) { if (index % 2 == 1) { GUI.DrawTexture(rect, TradeUI.TradeAlternativeBGTex); } Text.Font = GameFont.Small; GUI.BeginGroup(rect); float num = rect.width; int num2 = trad.CountHeldBy(Transactor.Trader); if (num2 != 0) { Rect rect2 = new Rect(num - 75f, 0f, 75f, rect.height); if (Mouse.IsOver(rect2)) { Widgets.DrawHighlight(rect2); } Text.Anchor = TextAnchor.MiddleRight; Rect rect3 = rect2; rect3.xMin += 5f; rect3.xMax -= 5f; Widgets.Label(rect3, num2.ToStringCached()); TooltipHandler.TipRegion(rect2, "TraderCount".Translate()); Rect rect4 = new Rect(rect2.x - 100f, 0f, 100f, rect.height); Text.Anchor = TextAnchor.MiddleRight; TradeUI.DrawPrice(rect4, trad, TradeAction.PlayerBuys); } num -= 175f; Rect rect5 = new Rect(num - 240f, 0f, 240f, rect.height); TradeUI.DrawCountAdjustInterface(rect5, trad); num -= 240f; int num3 = trad.CountHeldBy(Transactor.Colony); if (num3 != 0) { Rect rect6 = new Rect(num - 100f, 0f, 100f, rect.height); Text.Anchor = TextAnchor.MiddleLeft; TradeUI.DrawPrice(rect6, trad, TradeAction.PlayerSells); Rect rect7 = new Rect(rect6.x - 75f, 0f, 75f, rect.height); if (Mouse.IsOver(rect7)) { Widgets.DrawHighlight(rect7); } Text.Anchor = TextAnchor.MiddleLeft; Rect rect8 = rect7; rect8.xMin += 5f; rect8.xMax -= 5f; Widgets.Label(rect8, num3.ToStringCached()); TooltipHandler.TipRegion(rect7, "ColonyCount".Translate()); } num -= 175f; Rect rect9 = new Rect(0f, 0f, num, rect.height); if (Mouse.IsOver(rect9)) { Widgets.DrawHighlight(rect9); } Rect rect10 = new Rect(0f, 0f, 27f, 27f); Widgets.ThingIcon(rect10, trad.AnyThing); Widgets.InfoCardButton(40f, 0f, trad.AnyThing); Text.Anchor = TextAnchor.MiddleLeft; Rect rect11 = new Rect(80f, 0f, rect9.width - 80f, rect.height); Text.WordWrap = false; Widgets.Label(rect11, trad.Label); Text.WordWrap = true; Tradeable localTrad = trad; TooltipHandler.TipRegion(rect9, new TipSignal(delegate { if (!localTrad.HasAnyThing) { return(string.Empty); } return(localTrad.Label + ": " + localTrad.TipDescription); }, localTrad.GetHashCode())); GenUI.ResetLabelAlign(); GUI.EndGroup(); }
private static void DrawCountAdjustInterface(Rect rect, Tradeable trad) { Rect rect2 = new Rect(rect.center.x - 45f, rect.center.y - 12.5f, 90f, 25f); if (Time.time - Dialog_Trade.lastCurrencyFlashTime < 1f && trad.IsCurrency) { GUI.DrawTexture(rect2, TradeUI.SilverFlashTex); } if (!trad.IsCurrency) { int num = trad.CountHeldBy(Transactor.Colony) + trad.CountHeldBy(Transactor.Trader); float num2 = (float)num / 400f; if (num2 < 1f) { num2 = 1f; } if (DragSliderManager.DragSlider(rect2, num2, new DragSliderCallback(TradeSliders.TradeSliderDraggingStarted), new DragSliderCallback(TradeSliders.TradeSliderDraggingUpdate), new DragSliderCallback(TradeSliders.TradeSliderDraggingCompleted))) { TradeSliders.dragTrad = trad; TradeSliders.dragBaseAmount = trad.countToDrop; TradeSliders.dragLimitWarningGiven = false; } } int countToDrop = trad.countToDrop; string label; if (countToDrop > 0) { label = countToDrop.ToString(); } else if (countToDrop < 0) { label = (-countToDrop).ToString(); } else { GUI.color = TradeUI.NoTradeColor; label = "0"; } if (Mouse.IsOver(rect2)) { GUI.color = Color.yellow; } if (trad.IsCurrency) { GUI.color = Color.white; } Text.Anchor = TextAnchor.MiddleCenter; Widgets.Label(rect2, label); Text.Anchor = TextAnchor.UpperLeft; GUI.color = Color.white; if (!trad.IsCurrency) { if (trad.CanSetToDropOneMore().Accepted) { Rect rect3 = new Rect(rect2.x - 30f, rect.y, 30f, rect.height); if (Widgets.TextButton(rect3, "<", true, false)) { AcceptanceReport acceptanceReport = trad.TrySetToDropOneMore(); if (!acceptanceReport.Accepted) { Messages.Message(acceptanceReport.Reason, MessageSound.RejectInput); } else { SoundDefOf.TickHigh.PlayOneShotOnCamera(); } } rect3.x -= rect3.width; if (Widgets.TextButton(rect3, "<<", true, false)) { trad.SetToDropMax(); SoundDefOf.TickHigh.PlayOneShotOnCamera(); } } if (trad.CanSetToLaunchOneMore().Accepted) { Rect rect4 = new Rect(rect2.xMax, rect.y, 30f, rect.height); if (Widgets.TextButton(rect4, ">", true, false)) { AcceptanceReport acceptanceReport2 = trad.TrySetToLaunchOneMore(); if (!acceptanceReport2.Accepted) { Messages.Message(acceptanceReport2.Reason, MessageSound.RejectInput); } else { SoundDefOf.TickLow.PlayOneShotOnCamera(); } } rect4.x += rect4.width; if (Widgets.TextButton(rect4, ">>", true, false)) { trad.SetToLaunchMax(); SoundDefOf.TickLow.PlayOneShotOnCamera(); } } } if (trad.countToDrop != 0) { Rect position = new Rect(rect2.x + rect2.width / 2f - (float)(TradeUI.TradeArrow.width / 2), rect2.y + rect2.height / 2f - (float)(TradeUI.TradeArrow.height / 2), (float)TradeUI.TradeArrow.width, (float)TradeUI.TradeArrow.height); if (trad.countToDrop > 0) { position.x += position.width; position.width *= -1f; } GUI.DrawTexture(position, TradeUI.TradeArrow); } if (!trad.TraderWillTrade) { GUI.color = new Color(0.5f, 0.5f, 0.5f); Widgets.DrawLineHorizontal(rect2.x + rect2.width / 3f, rect2.y + rect2.height / 2f, rect2.width / 3f); GUI.color = Color.white; } }