Ejemplo n.º 1
0
    // Update is called once per frame
    void OnGUI()
    {
        if (started)
        {
            return;
        }
        GUI.skin = skin;
        GUIStyle smallButton = GUI.skin.GetStyle("smallButton");

        int startX = Mathf.Max(0, Screen.width / 2 - 300);
        int startY = Mathf.Max(0, Screen.height / 2 - 150);

        Rect rect = new Rect(
            startX,
            startY,
            Mathf.Min(Screen.width - startX, 600),
            Mathf.Min(Screen.height - startY, 300)
            );

        GUILayout.BeginArea(rect);
        GUIStyle centerStyle = new GUIStyle(GUI.skin.label);

        centerStyle.alignment = TextAnchor.MiddleCenter;
        if (isStarting)
        {
            GUILayout.FlexibleSpace();
            Spinner.DrawAt(new Vector2(rect.width / 2 - 16, rect.height / 2 - 16 - 32));
            GUILayout.Space(32);
            GUILayout.Label("Starting up...", centerStyle);
            GUILayout.FlexibleSpace();
        }
        else if (isRemembering)             //Don't show the login form if remembering
        {
            GUILayout.FlexibleSpace();
            Spinner.DrawAt(new Vector2(rect.width / 2 - 16, rect.height / 2 - 16 - 32));
            GUILayout.Space(32);
            GUILayout.Label("Logging in...", centerStyle);
            GUILayout.FlexibleSpace();
        }
        else
        {
            if (method == LoginMethod.Undecided)
            {
                GUILayout.Label("Welcome to Sanicball!");
                GUILayout.Label("Select an option below. Signing in with Game Jolt will in a future update let you submit your highscores online.");
                GUILayout.FlexibleSpace();
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Sign in with Game Jolt", GUI.skin.GetStyle("smallButtonGreen")))
                {
                    method = LoginMethod.GameJolt;
                }
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Stay anonymous", smallButton))
                {
                    method = LoginMethod.Anon;
                }
                GUILayout.EndHorizontal();
            }
            if (method == LoginMethod.GameJolt)
            {
                GUILayout.Label("GJ username: "******"Focus");
                username = GUILayout.TextField(username, 128);
                GUILayout.Label("User token: ");
                token      = GUILayout.PasswordField(token, (char)0x25CF, 128);
                rememberMe = GUILayout.Toggle(rememberMe, "Remember me");
                GUILayout.FlexibleSpace();
                GUILayout.BeginHorizontal();
                if ((GUILayout.Button("Log in", smallButton) || (Event.current.isKey && Event.current.keyCode == KeyCode.Return)) && !isVerifying)
                {
                    status = "";
                    if (username.Trim().Length <= 0)                       //Has the user typed something in the username field?
                    {
                        status = "You need to type an username.";
                    }
                    else if (token.Trim().Length <= 0)                         //Has the user typed something in the token field?
                    {
                        status = "You need to type in your token.";
                    }
                    else                         //Log in with the Game Jolt API
                    {
                        status      = "@spinner/Logging in...";
                        isVerifying = true;
                        GJAPI.Users.Verify(username, token);
                        GJAPI.Users.VerifyCallback += LogInCallback;
                    }
                }
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Cancel", smallButton))
                {
                    method = LoginMethod.Undecided;
                    status = "";
                }
                GUILayout.EndHorizontal();
            }
            if (method == LoginMethod.Anon)
            {
                if (GameSettings.user.offlineMode)
                {
                    GUILayout.Label("Failed to connect to Game Jolt! However, you can still play multiplayer anonymously.");
                }
                GUILayout.Label("Type the name you want to use:");
                GUI.SetNextControlName("Focus");
                username = GUILayout.TextField(username, 32);
                GUILayout.Label("Your name will be slightly grayed out in multiplayer to avoid impersonation.");
                rememberMe = GUILayout.Toggle(rememberMe, "Remember name");
                GUILayout.FlexibleSpace();
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Okay", smallButton) || (Event.current.isKey && Event.current.keyCode == KeyCode.Return))
                {
                    status = "";
                    if (username.Trim().Length <= 0)
                    {
                        status = "You need to type something.";
                    }
                    else
                    {
                        Accept();
                    }
                }
                if (!GameSettings.user.offlineMode)
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Cancel", smallButton))
                    {
                        method = LoginMethod.Undecided;
                        status = "";
                    }
                }
                GUILayout.EndHorizontal();
            }
            if (status.StartsWith("@spinner/"))
            {
                Spinner.Draw(status.Replace("@spinner/", ""));
            }
            else
            {
                GUILayout.Label(status);
            }
        }
        GUILayout.EndArea();
    }