Ejemplo n.º 1
0
        static void DrawSkippingWindow()
        {
            if (Multiplayer.Client == null || TickPatch.skipTo < 0)
            {
                return;
            }

            string text        = $"{"MpSimulating".Translate()}{MpUtil.FixedEllipsis()}";
            float  textWidth   = Text.CalcSize(text).x;
            float  windowWidth = Math.Max(240f, textWidth + 40f);
            Rect   rect        = new Rect(0, 0, windowWidth, 75f).CenterOn(new Rect(0, 0, UI.screenWidth, UI.screenHeight));

            if (Multiplayer.IsReplay && !TickPatch.disableSkipCancel && Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Escape)
            {
                TickPatch.ClearSkipping();
                Event.current.Use();
            }

            Find.WindowStack.ImmediateWindow(SkippingWindowId, rect, WindowLayer.Super, () =>
            {
                Text.Anchor = TextAnchor.MiddleCenter;
                Text.Font   = GameFont.Small;
                Widgets.Label(rect.AtZero(), text);
                Text.Anchor = TextAnchor.UpperLeft;
            }, absorbInputAroundWindow: true);
        }
Ejemplo n.º 2
0
        public static void StopMultiplayer()
        {
            if (Multiplayer.session != null)
            {
                Multiplayer.session.Stop();
                Multiplayer.session = null;
                Prefs.Apply();
            }

            Multiplayer.game = null;

            TickPatch.ClearSkipping();
            TickPatch.Timer       = 0;
            TickPatch.tickUntil   = 0;
            TickPatch.accumulator = 0;

            Find.WindowStack?.WindowOfType <ServerBrowser>()?.Cleanup(true);

            foreach (var entry in Sync.bufferedChanges)
            {
                entry.Value.Clear();
            }

            ClearCaches();

            if (Multiplayer.arbiterInstance)
            {
                Multiplayer.arbiterInstance = false;
                Application.Quit();
            }
        }
        static void DrawSkippingWindow()
        {
            if (Multiplayer.Client == null || !TickPatch.Skipping)
            {
                return;
            }

            string text         = $"{TickPatch.skippingTextKey.Translate()}{MpUtil.FixedEllipsis()}";
            float  textWidth    = Text.CalcSize(text).x;
            float  windowWidth  = Math.Max(240f, textWidth + 40f);
            float  windowHeight = TickPatch.cancelSkip != null ? 100f : 75f;
            Rect   rect         = new Rect(0, 0, windowWidth, windowHeight).CenterOn(new Rect(0, 0, UI.screenWidth, UI.screenHeight));

            if (TickPatch.canESCSkip && Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Escape)
            {
                TickPatch.ClearSkipping();
                Event.current.Use();
            }

            Find.WindowStack.ImmediateWindow(SkippingWindowId, rect, WindowLayer.Super, () =>
            {
                var textRect = rect.AtZero();
                if (TickPatch.cancelSkip != null)
                {
                    textRect.yMin   += 5f;
                    textRect.height -= 50f;
                }

                Text.Anchor = TextAnchor.MiddleCenter;
                Text.Font   = GameFont.Small;
                Widgets.Label(textRect, text);
                Text.Anchor = TextAnchor.UpperLeft;

                if (TickPatch.cancelSkip != null && Widgets.ButtonText(new Rect(0, textRect.yMax, 100f, 35f).CenteredOnXIn(textRect), TickPatch.skipCancelButtonKey.Translate()))
                {
                    TickPatch.cancelSkip();
                }
            }, absorbInputAroundWindow: true);
        }