Exemplo n.º 1
0
        static void DrawModalWindow(string text, Func <bool> shouldShow, Action onCancel, string cancelButtonLabel)
        {
            string textWithEllipsis = $"{text}{MpUI.FixedEllipsis()}";
            float  textWidth        = Text.CalcSize(textWithEllipsis).x;
            float  windowWidth      = Math.Max(240f, textWidth + 40f);
            float  windowHeight     = onCancel != null ? 100f : 75f;
            var    rect             = new Rect(0, 0, windowWidth, windowHeight).CenterOn(new Rect(0, 0, UI.screenWidth, UI.screenHeight));

            Find.WindowStack.ImmediateWindow(ModalWindowId, rect, WindowLayer.Super, () =>
            {
                if (!shouldShow())
                {
                    return;
                }

                var textRect = rect.AtZero();
                if (onCancel != null)
                {
                    textRect.yMin   += 5f;
                    textRect.height -= 50f;
                }

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

                var cancelBtn = new Rect(0, textRect.yMax, 100f, 35f).CenteredOnXIn(textRect);

                if (onCancel != null && Widgets.ButtonText(cancelBtn, cancelButtonLabel))
                {
                    onCancel();
                }
            }, absorbInputAroundWindow: true);
        }
Exemplo n.º 2
0
        private void DrawLan(Rect inRect)
        {
            using (MpStyle.Set(TextAnchor.MiddleCenter))
                Widgets.Label(new Rect(inRect.x, 8f, inRect.width, 40), "MpLanSearching".Translate() + MpUI.FixedEllipsis());
            inRect.yMin += 40f;

            float margin  = 100;
            Rect  outRect = new Rect(margin, inRect.yMin + 10, inRect.width - 2 * margin, inRect.height - 20);

            float height   = servers.Count * 40;
            Rect  viewRect = new Rect(0, 0, outRect.width - 16f, height);

            Widgets.BeginScrollView(outRect, ref lanScroll, viewRect, true);

            float y = 0;
            int   i = 0;

            foreach (LanServer server in servers)
            {
                Rect entryRect = new Rect(0, y, viewRect.width, 40);
                if (i % 2 == 0)
                {
                    Widgets.DrawAltRect(entryRect);
                }

                using (MpStyle.Set(TextAnchor.MiddleLeft))
                    Widgets.Label(entryRect.Right(5), "" + server.endpoint);

                Rect playButton = new Rect(entryRect.xMax - 75, entryRect.y + 5, 70, 40 - 10);
                if (Widgets.ButtonText(playButton, ">>"))
                {
                    Close(false);
                    Log.Message("Connecting to lan server");

                    var address = server.endpoint.Address.ToString();
                    var port    = server.endpoint.Port;
                    ClientUtil.TryConnectWithWindow(address, port);
                }

                y += entryRect.height;
                i++;
            }

            Widgets.EndScrollView();
        }