static void Postfix(bool __state) { if (__state) { MpTradeSession.SetTradeSession(null); } }
static void Prefix(ref bool __state) { TradingWindow trading = Find.WindowStack.WindowOfType <TradingWindow>(); if (trading != null) { MpTradeSession.SetTradeSession(Multiplayer.WorldComp.trading[trading.selectedTab]); __state = true; } }
public static void SetTradeSession(MpTradeSession session, bool force = false) { if (!force && TradeSession.deal == session?.deal) { return; } current = session; TradeSession.trader = session?.trader; TradeSession.playerNegotiator = session?.playerNegotiator; TradeSession.giftMode = session?.giftMode ?? false; TradeSession.deal = session?.deal; }
static bool Prefix(ref bool __state, ref string __result) { TradingWindow trading = Find.WindowStack.WindowOfType <TradingWindow>(); if (trading == null || Multiplayer.WorldComp.trading[trading.selectedTab] == null) { __result = ""; return(false); } MpTradeSession.SetTradeSession(Multiplayer.WorldComp.trading[trading.selectedTab]); __state = true; return(true); }
private void RecreateDialog() { var session = Multiplayer.WorldComp.trading[selectedTab]; MpTradeSession.SetTradeSession(session); dialog = MpUtil.NewObjectNoCtor <Dialog_Trade>(); dialog.quickSearchWidget = new QuickSearchWidget(); dialog.giftsOnly = session.giftsOnly; dialog.sorter1 = TransferableSorterDefOf.Category; dialog.sorter2 = TransferableSorterDefOf.MarketValue; dialog.CacheTradeables(); session.deal.uiShouldReset = UIShouldReset.None; removed.Clear(); added.Clear(); MpTradeSession.SetTradeSession(null); }
private void RecreateDialog() { var session = Multiplayer.WorldComp.trading[selectedTab]; CancelDialogTradeCtor.cancel = true; MpTradeSession.SetTradeSession(session); dialog = new Dialog_Trade(null, null); dialog.giftsOnly = session.giftsOnly; dialog.sorter1 = TransferableSorterDefOf.Category; dialog.sorter2 = TransferableSorterDefOf.MarketValue; dialog.CacheTradeables(); session.deal.uiShouldReset = UIShouldReset.None; removed.Clear(); added.Clear(); MpTradeSession.SetTradeSession(null); CancelDialogTradeCtor.cancel = false; }
static bool Prefix(Pawn playerNegotiator, ITrader trader, bool giftsOnly) { if (cancel) { return(false); } if (Multiplayer.ExecutingCmds || Multiplayer.Ticking) { MpTradeSession.TryCreate(trader, playerNegotiator, giftsOnly); if (TickPatch.currentExecutingCmdIssuedBySelf) { Find.WindowStack.Add(new TradingWindow()); } return(false); } return(true); }
public static MpTradeSession TryCreate(ITrader trader, Pawn playerNegotiator, bool giftMode) { // todo show error messages? if (Multiplayer.WorldComp.trading.Any(s => s.trader == trader)) { return(null); } if (Multiplayer.WorldComp.trading.Any(s => s.playerNegotiator == playerNegotiator)) { return(null); } MpTradeSession session = new MpTradeSession(trader, playerNegotiator, giftMode); Multiplayer.WorldComp.trading.Add(session); CancelTradeDealReset.cancel = true; SetTradeSession(session, true); try { session.deal = new MpTradeDeal(session); Thing permSilver = ThingMaker.MakeThing(ThingDefOf.Silver, null); permSilver.stackCount = 0; session.deal.permanentSilver = permSilver; session.deal.AddToTradeables(permSilver, Transactor.Trader); session.deal.AddAllTradeables(); session.StartWaitingJobs(); } finally { SetTradeSession(null); CancelTradeDealReset.cancel = false; } return(session); }
static bool Prefix(Pawn playerNegotiator, ITrader trader, bool giftsOnly) { if (Multiplayer.ExecutingCmds || Multiplayer.Ticking) { MpTradeSession trade = MpTradeSession.TryCreate(trader, playerNegotiator, giftsOnly); if (trade != null) { if (playerNegotiator.Map == Find.CurrentMap && playerNegotiator.CurJob.loadID == SyncMethods.tradeJobStartedByMe) { SyncMethods.tradeJobStartedByMe = -1; trade.OpenWindow(); } else if (trader is Settlement && Find.World.renderer.wantedMode == WorldRenderMode.Planet) { trade.OpenWindow(); } } return(false); } return(true); }
public MpTradeDeal(MpTradeSession session) { this.session = session; }
public override void DoWindowContents(Rect inRect) { added.RemoveAll(kv => Time.time - kv.Value > 1f); removed.RemoveAll(kv => Time.time - kv.Value > 0.5f && RemoveCachedTradeable(kv.Key)); tabs.Clear(); var trading = Multiplayer.WorldComp.trading; for (int i = 0; i < trading.Count; i++) { int j = i; tabs.Add(new TabRecord(trading[i].Label, () => selectedTab = j, () => selectedTab == j)); } if (selectedTab == -1 && trading.Count > 0) { selectedTab = 0; } if (selectedTab == -1) { Close(); return; } int rows = Mathf.CeilToInt(tabs.Count / 3f); inRect.yMin += rows * TabDrawer.TabHeight + 3; TabDrawer.DrawTabs(inRect, tabs, rows); inRect.yMin += 10f; var session = Multiplayer.WorldComp.trading[selectedTab]; if (session.sessionId != selectedSession) { RecreateDialog(); selectedSession = session.sessionId; } { MpTradeSession.SetTradeSession(session); drawingTrade = this; if (session.deal.ShouldRecache) { session.deal.Recache(); } if (session.deal.uiShouldReset != UIShouldReset.None) { if (session.deal.uiShouldReset != UIShouldReset.Silent) { BeforeCache(); } dialog.CacheTradeables(); dialog.CountToTransferChanged(); session.deal.uiShouldReset = UIShouldReset.None; } if (session.deal.caravanDirty) { dialog.CountToTransferChanged(); session.deal.caravanDirty = false; } GUI.BeginGroup(inRect); { Rect groupRect = new Rect(0, 0, inRect.width, inRect.height); dialog.DoWindowContents(groupRect); } GUI.EndGroup(); int?traderLeavingIn = GetTraderTime(TradeSession.trader); if (traderLeavingIn != null) { float num = inRect.width - 590f; Rect position = new Rect(inRect.x + num, inRect.y, inRect.width - num, 58f); Rect traderNameRect = new Rect(position.x + position.width / 2f, position.y, position.width / 2f - 1f, position.height); Rect traderTimeRect = traderNameRect.Up(traderNameRect.height - 5f); Text.Anchor = TextAnchor.LowerRight; Widgets.Label(traderTimeRect, "MpTraderLeavesIn".Translate(traderLeavingIn?.ToStringTicksToPeriod())); Text.Anchor = TextAnchor.UpperLeft; } if (cancelPressed) { CancelTradeSession(session); cancelPressed = false; } session.giftMode = TradeSession.giftMode; drawingTrade = null; MpTradeSession.SetTradeSession(null); } }
static void CancelTradeSession(MpTradeSession session) { Multiplayer.WorldComp.RemoveTradeSession(session); }