Exemplo n.º 1
0
        /// <summary>
        /// Draw connection error overlay. Retry connection and close.
        /// </summary>
        private void DrawConnectionErrorOverlay()
        {
            bool unused_open = true;

            ImGui.OpenPopup("NetworkDisconnected");
            if (ImGui.BeginPopupModal("NetworkDisconnected", ref unused_open, ImGuiWindowFlags.NoMove |
                                      ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.AlwaysAutoResize))
            {
                ImGui.PushFont((ImFontPtr)Frame.Fonts.NormalFont);

                if (Platform == Platform.Android)
                {
                    ImGui.SetWindowFontScale(1 - downScaleNetworkDisconnectedWindow);
                }

                ImGui.TextUnformatted("Lost connection to server.");

                float buttonPositionX = ImGui.CalcTextSize("Lost connection to server.").X;
                ImGui.SetCursorPosX(buttonPositionX);
                ImGui.SetCursorPosY(ImGui.CalcTextSize("UNUSED").Y * 2);

                ImGui.PushStyleColor(ImGuiCol.Button, new Vector4(1, 1, 1, 1));
                ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0, 0, 0, 1));

                Vector2 buttonPadding = new Vector2(14, 20);
                if (Platform == Platform.Android)
                {
                    buttonPadding = new Vector2(14, 60);
                }

                if (runningConnectCheck)
                {
                    ImGui.Button("Retrying Connection... ", ImGui.CalcTextSize("Retrying Connection... ") + buttonPadding);
                }
                else
                {
                    if (ImGui.Button("Retry Connection", ImGui.CalcTextSize("Retrying Connection... ") + buttonPadding))
                    {
                        Task.Factory.StartNew(() =>
                        {
                            runningConnectCheck = true;

                            if (Networking.ReConnect())
                            {
                                string localSessionId = LocalData.RetrieveSession();
                                if (localSessionId != null && localSessionId.Length != 0)
                                {
                                    Networking.SessionVerificationResult += Networking_SessionVerificationResult;
                                    Networking.Send(PacketName.RequestSessionVerification.ToString(), localSessionId);
                                }
                                else
                                {
                                    // User is not logged in.
                                    drawNetworkDisconnected = false;
                                }
                            }

                            runningConnectCheck = false;
                        });
                    }
                }

                ImGui.SetCursorPosX(buttonPositionX);

                if (ImGui.Button("Close app", ImGui.CalcTextSize("Retrying Connection... ") + buttonPadding))
                {
                    PlatformFunctions.Exit();
                }

                Vector2 windowSize          = ImGui.GetWindowSize();
                Vector2 screenSize          = new Vector2(Frame.Width, Frame.Height);
                Vector2 loginWindowPosition = new Vector2((screenSize.X / 2) - (windowSize.X / 2),
                                                          (screenSize.Y / 2) - (windowSize.Y / 2));

                if ((ImGui.GetWindowWidth() + (15 * PlatformFunctions.ScreenDensity())) > (screenSize.X))
                {
                    downScaleNetworkDisconnectedWindow += 0.05f;
                }

                ImGui.SetWindowPos(loginWindowPosition);

                ImGui.PopStyleColor();
                ImGui.PopFont();
                ImGui.EndPopup();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///  This method is used to draw the GUI.
        /// </summary>
        public override void Draw()
        {
            ImGui.GetStyle().WindowBorderSize = 0;

            if (drawNetworkDisconnected)
            {
                DrawConnectionErrorOverlay();
            }

            if (drawLogin)
            {
                loginView.Draw();
                DrawLoginOverlay();
            }

            if (drawAppSelectionView)
            {
                float overlayHeight = DrawMainOverlay();

                appSelectionView.Draw(overlayHeight);
            }

            if (drawApp)
            {
                float overlayHeight = DrawpAppOverlay();

                ImGui.SetNextWindowPos(new Vector2(ImGui.GetWindowPos().X, overlayHeight + 10 * PlatformFunctions.ScreenDensity()), ImGuiCond.Once);

                DrawApp();
            }
        }