public int GetCountForItem(ThingType thingTypeFilter, Tradeable tradeable) { int key = tradeable.GetHashCode(); if (requestedItems[thingTypeFilter].dict.ContainsKey(key)) { return(requestedItems[thingTypeFilter].dict[key].amount); } return(0); }
private static void DrawPrice(Rect rect, Tradeable trad, TradeAction action) { if (trad.IsCurrency || !trad.TraderWillTrade) { return; } rect = rect.Rounded(); if (Mouse.IsOver(rect)) { Widgets.DrawHighlight(rect); } float num = trad.PriceFor(action); PriceType pType = PriceTypeUtlity.ClosestPriceType(num / trad.BaseMarketValue); switch (pType) { case PriceType.VeryCheap: GUI.color = new Color(0f, 1f, 0f); break; case PriceType.Cheap: GUI.color = new Color(0.5f, 1f, 0.5f); break; case PriceType.Normal: GUI.color = Color.white; break; case PriceType.Expensive: GUI.color = new Color(1f, 0.5f, 0.5f); break; case PriceType.Exorbitant: GUI.color = new Color(1f, 0f, 0f); break; } float factor = TradeUtility.RandomPriceFactorFor(TradeSession.trader, trad); factor = (factor - 1) * 100; string label = "$" + num.ToString("F2") + " (" + factor.ToString("F1") + "%)"; Func <string> textGetter = delegate { if (!trad.HasAnyThing) { return(string.Empty); } return(((action != TradeAction.PlayerBuys) ? "SellPriceDesc".Translate() : "BuyPriceDesc".Translate()) + "\n\n" + "PriceTypeDesc".Translate(("PriceType" + pType).Translate())); }; TooltipHandler.TipRegion(rect, new TipSignal(textGetter, trad.GetHashCode() * 297)); Rect rect2 = new Rect(rect); rect2.xMax -= 5f; rect2.xMin += 5f; if (Text.Anchor == TextAnchor.MiddleLeft) { rect2.xMax += 300f; } if (Text.Anchor == TextAnchor.MiddleRight) { rect2.xMin -= 300f; } Widgets.Label(rect2, label); GUI.color = Color.white; }
private float DrawPrice(Rect rect, Tradeable trad) { rect = rect.Rounded(); if (Mouse.IsOver(rect)) { Widgets.DrawHighlight(rect); } var priceType = GetPriceTypeFor(trad); var finalPrice = CalcRequestedItemPrice(trad); TooltipHandler.TipRegion(rect, new TipSignal(() => GetPriceTooltip(faction, negotiator, trad, finalPrice), trad.GetHashCode() * 297)); switch (priceType) { case PriceType.VeryCheap: GUI.color = new Color(0, 1, 0); break; case PriceType.Cheap: GUI.color = new Color(0.5f, 1, 0.5f); break; case PriceType.Normal: GUI.color = Color.white; break; case PriceType.Expensive: GUI.color = new Color(1, 0.5f, 0.5f); break; case PriceType.Exorbitant: GUI.color = new Color(1, 0, 0); break; } var label = finalPrice.ToStringMoney("F2"); var priceTextArea = new Rect(rect); priceTextArea.xMax -= 5f; priceTextArea.xMin += 5f; if (Text.Anchor == TextAnchor.MiddleLeft) { priceTextArea.xMax += 300f; } if (Text.Anchor == TextAnchor.MiddleRight) { priceTextArea.xMin -= 300f; } Widgets.Label(priceTextArea, label); GUI.color = Color.white; return(finalPrice); }
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(); }