static void Prefix(ref bool __state) { TradingWindow trading = Find.WindowStack.WindowOfType <TradingWindow>(); if (trading != null) { MpTradeSession.SetTradeSession(Multiplayer.WorldComp.trading[trading.selectedTab]); __state = true; } }
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); }
public void OpenWindow(bool sound = true) { int tab = Multiplayer.WorldComp.trading.IndexOf(this); if (Find.WindowStack.IsOpen <TradingWindow>()) { Find.WindowStack.WindowOfType <TradingWindow>().selectedTab = tab; } else { TradingWindow window = new TradingWindow() { selectedTab = tab }; if (!sound) { window.soundAppear = null; } Find.WindowStack.Add(window); } }
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); } }