Exemplo n.º 1
0
    public void LoginbackScene()
    {
        Debug.Log("Calling success!");
        StartMenuScript nv = new StartMenuScript();

        nv.backScene();
    }
Exemplo n.º 2
0
    // Connect to server address at port 1337 (main server) and get a new port on which to login or sign up.
    public void connectToMainServer(bool newAcct)
    {
        Socket cnxn = null;

        try {
            // 1st step: Connect to main server and send handshake.
            cnxn = new Socket(ip, 1337);

            ObjectOutputStream output = new ObjectOutputStream(cnxn.getOutputStream());
            output.writeInt(handshake);
            output.flush();

            // Must now send username.
            string username = newAcct ? usernameReg.text : usernameLogin.text;
            output.writeObject(username);
            output.flush();

            // Receive whatever port the server sends (random or determined).
            cnxn.setSoTimeout(10000);             // 10-sec timeout for input reads
            ObjectInputStream input = new ObjectInputStream(cnxn.getInputStream());
            int nextPort            = input.readInt();

            // Close streams and connection.
            input.close();
            output.close();
            cnxn.close();

            // We got a port now! At this point, either log in or sign up.
            if (newAcct)
            {
                signup(nextPort);
            }
            else
            {
                loginAndPlay(nextPort);
            }
        } catch (java.lang.Exception e) {
            // Display some kind of error window if there was a connection error (basically a Java exception).
            // If the socket is null, the connection attempt failed; otherwise, the connection timed out, or something else happened.
            StartMenuScript sms = (StartMenuScript)(startMenu.GetComponent(typeof(StartMenuScript)));
            if (cnxn == null)
            {
                sms.RaiseErrorWindow("Failed to connect. Check your connection settings. The main server may be down.");
            }
            else if (e.GetType() == typeof(SocketTimeoutException))
            {
                sms.RaiseErrorWindow("Connection timed out. Check your connection. The main server may have gone down.");
            }
            else
            {
                sms.RaiseErrorWindow("An unknown exception occurred when trying to connect to the main server.");
            }
        } catch (System.Exception e) {
            // This handles C# exceptions. These shouldn't happen, which is why the errors are printed to the console (for us to test for ourselves).
            print("Encountered a C# exception:\n");
            print(e.Message);
        }
    }
    public void Start()
    {
        startMenu = GetComponentInParent <VerticalLayoutGroup>().GetComponentInParent <StartMenuScript>();

        itemText  = GetComponentInChildren <Text>();
        itemImage = transform.GetChild(1).GetComponent <Image>();

        SetProperties();
    }
Exemplo n.º 4
0
 // Use this for initialization
 void Awake()
 {
     if (instance == null)
     {
         //...set this one to be it...
         instance = this;
     }
     //...otherwise...
     else if (instance != this)
     {
         //...destroy this one because it is a duplicate.
         Destroy(gameObject);
     }
 }
    private void OnEnable()
    {
        inGameUI.GetComponent <ScoreCounter>().enabled = false;
        inGameUI.GetComponent <Canvas>().enabled       = false;
        sMenuScript = startMenu.GetComponent <StartMenuScript>();
        calculateBounty();
        DetermineHighScore(score);
        DisplayScore();
        gameOverUI.GetComponent <Canvas>().enabled = true;
        Analytics.CustomEvent("Score From Round: ", new Dictionary <string, object>
        {
            { "Score: ", GetScoreRange(score) },
        }
                              );

        Analytics.CustomEvent("Highest Streak: ", new Dictionary <string, object>
        {
            { "Streak: ", GetStreakRange(streak) },
        }
                              );


        this.GetComponent <PlayerController>().enabled          = false;
        this.GetComponent <PlayerAnimationController>().enabled = false;

        if (played)
        {
            reviveButtons.SetActive(false);
            noReviveButtons.SetActive(true);
            DisplayScore();
        }
        else
        {
            played = true;
        }
    }
 private void Awake()
 {
     startMenu = this;
 }
Exemplo n.º 7
0
    private void OnGUI()
    {
        //Window Scene
        GUILayout.Label("Window", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Title Bar Sprite:");
        windowSprite = (Sprite)EditorGUILayout.ObjectField(windowSprite, typeof(Sprite), allowSceneObjects: true);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Window Name:");
        windowName = EditorGUILayout.TextField("", windowName);
        EditorGUILayout.EndHorizontal();

        windowSize = EditorGUILayout.Vector2Field("Window Size: ", windowSize);

        EditorGUILayout.Space();

        if (GUILayout.Button("Create Window"))
        {
            //When pressed, the icon will create an instance in the scene.
            if (windowSprite == null)
            {
                Debug.LogWarning("Window Sprite cannot contain an empty field");
            }
            else if (windowName == null)
            {
                Debug.LogWarning("Window Name cannot contain an empty field");
            }
            else
            {
                string path = "Assets/Prefabs/Windows/" + windowName + ".prefab";
                path = AssetDatabase.GenerateUniqueAssetPath(path);

                GameObject tmpWindow = Instantiate(windowPrefab);

                tmpWindow.GetComponent <RectTransform>().sizeDelta = new Vector2(windowSize.x + 4, windowSize.y + 4);
                WindowScript windowScript = tmpWindow.GetComponent <WindowScript>();
                windowScript.titleBarIcon.sprite = windowSprite;
                windowScript.titleBarText.text   = windowName;

                PrefabUtility.SaveAsPrefabAsset(tmpWindow, path);

                Destroy(tmpWindow);

                EditorUtility.FocusProjectWindow();
                Selection.activeObject = windowPrefab;
                Debug.Log(":)");
            }
        }

        EditorGUILayout.Space();

        //Icon Settings
        GUILayout.Label("Icon", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Sprite:");
        iconSprite = (Sprite)EditorGUILayout.ObjectField(iconSprite, typeof(Sprite), allowSceneObjects: true);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Name:");
        iconString = EditorGUILayout.TextField("", iconString);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Window:");
        iconWindow = (GameObject)EditorGUILayout.ObjectField(iconWindow, typeof(GameObject), allowSceneObjects: true);
        EditorGUILayout.EndHorizontal();

        if (GUILayout.Button("Create Icon"))
        {
            //When pressed, the icon will create an instance in the scene.
            if (iconSprite == null)
            {
                Debug.LogWarning("Icon Sprite cannot contain an empty field");
            }
            else if (iconString == null)
            {
                Debug.LogWarning("Icon Name cannot contain an empty field");
            }
            else if (iconWindow == null)
            {
                Debug.LogWarning("Window cannot contain an empty field, create one if you need to.");
            }
            else
            {
                Icon iconScriptableObject = CreateInstance <Icon>();
                iconScriptableObject.iconName   = iconString;
                iconScriptableObject.iconSprite = iconSprite;
                iconScriptableObject.window     = iconWindow;

                AssetDatabase.CreateAsset(iconScriptableObject, "Assets/ScriptableObjects/Icons/" + iconString + ".asset");
                AssetDatabase.SaveAssets();

                GameObject tmpIcon    = Instantiate(iconPrefab);
                IconScript iconScript = tmpIcon.GetComponent <IconScript>();
                iconScript.icon             = iconScriptableObject;
                iconScript.transform.parent = ThemeManager.instance.iconSpace.transform;

                EditorUtility.FocusProjectWindow();
                Selection.activeObject = iconScriptableObject;
                Debug.Log(":)");
            }
        }

        EditorGUILayout.Space();

        //Start Menu Item Settings
        GUILayout.Label("Start Menu Item", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Sprite:");
        itemSprite = (Sprite)EditorGUILayout.ObjectField(itemSprite, typeof(Sprite), allowSceneObjects: true);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Name:");
        itemName = EditorGUILayout.TextField("", itemName);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Window:");
        itemWindow = (GameObject)EditorGUILayout.ObjectField(itemWindow, typeof(GameObject), allowSceneObjects: true);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        putOnStartMenu = EditorGUILayout.Toggle("Add to start menu?", putOnStartMenu);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();

        if (GUILayout.Button("Create Start Menu Button"))
        {
            //When pressed, the icon will create an instance in the scene.
            if (itemSprite == null)
            {
                Debug.LogWarning("Item Sprite cannot contain an empty field");
            }
            else if (itemName == null)
            {
                Debug.LogWarning("Item Name cannot contain an empty field");
            }
            else if (itemWindow == null)
            {
                Debug.LogWarning("Window cannot contain an empty field, create one if you need to.");
            }
            else
            {
                StartMenuItem itemScriptableObject = CreateInstance <StartMenuItem>();
                itemScriptableObject.menuName = itemName;
                itemScriptableObject.sprite   = itemSprite;
                itemScriptableObject.window   = itemWindow;

                AssetDatabase.CreateAsset(itemScriptableObject, "Assets/ScriptableObjects/Start Menu Items/" + itemName + ".asset");
                AssetDatabase.SaveAssets();

                if (putOnStartMenu)
                {
                    StartMenuScript startMenu = ThemeManager.instance.taskbarCanvas.GetComponentInChildren <StartMenuScript>();
                    startMenu.startMenuItems.Add(itemScriptableObject);
                }

                EditorUtility.FocusProjectWindow();
                Selection.activeObject = itemScriptableObject;
                Debug.Log(":)");
            }
        }

        EditorGUILayout.Space();
        //Notification Settings
        GUILayout.Label("Create a new Notification", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Sprite:");
        NotificationSprite = (Sprite)EditorGUILayout.ObjectField(NotificationSprite, typeof(Sprite), allowSceneObjects: true);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Name:");
        notificationName = EditorGUILayout.TextField("", notificationName);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Lifespan:");
        notificationLifespan = EditorGUILayout.FloatField(notificationLifespan);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Tooltip Text:");
        notificationToolTip = EditorGUILayout.TextField("", notificationToolTip);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        notificationPopupDespawn = EditorGUILayout.Toggle("Despawn?", notificationPopupDespawn);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Space();
        GUILayout.Label("Popup Settings", EditorStyles.boldLabel);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Popup Lifespan:");
        notificationPopupLifespan = EditorGUILayout.FloatField(notificationPopupLifespan);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Popup Title:");
        notificationPopupTitle = EditorGUILayout.TextField("", notificationPopupTitle);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Popup Description:");
        notificationPopupDescription = EditorGUILayout.TextField("", notificationPopupDescription);
        EditorGUILayout.EndHorizontal();

        if (GUILayout.Button("Create Notification"))
        {
            //When pressed, the icon will create an instance in the scene.
            if (NotificationSprite == null)
            {
                Debug.LogWarning("Notification Sprite cannot contain an empty field");
            }
            else if (notificationName == null)
            {
                Debug.LogWarning("Notification Name cannot contain an empty field");
            }
            else if (notificationToolTip == null)
            {
                Debug.LogWarning("Tooltip cannot contain an empty field");
            }
            else if (notificationPopupLifespan <= 0)
            {
                Debug.LogWarning("The popup needs to have a lifespan, or to be put on permamently.");
            }
            else if (notificationLifespan <= 0 && !notificationPopupDespawn)
            {
                Debug.LogWarning("Lifespan needs to be greater than 0 or to be on permamently.");
            }
            else if (notificationPopupTitle == null)
            {
                Debug.LogWarning("Notification Popup Title cannot be an empty field");
            }
            else if (notificationPopupDescription == null)
            {
                Debug.LogWarning("Notification Description cannot be an empty field");
            }
            else
            {
                Notification notification = CreateInstance <Notification>();

                notification.notificationSprite      = NotificationSprite;
                notification.notificationTitle       = notificationPopupTitle;
                notification.notificationToolTipText = notificationToolTip;
                notification.notificationText        = notificationPopupDescription;
                notification.stayOnPermamently       = notificationPopupDespawn;
                notification.notificationLifespan    = notificationPopupLifespan;

                AssetDatabase.CreateAsset(notification, "Assets/ScriptableObjects/Notifications/" + notificationName + ".asset");
                AssetDatabase.SaveAssets();

                GameObject      tmpNotif    = Instantiate(notificationPrefab);
                NotificationObj notifScript = tmpNotif.GetComponent <NotificationObj>();
                notifScript.notification     = notification;
                notifScript.transform.parent = ThemeManager.instance.taskbar.GetComponentInChildren <NotificationAreaScript>().NotificationsSpace.transform;

                EditorUtility.FocusProjectWindow();
                Selection.activeObject = notification;
                Debug.Log(":)");
            }
        }
    }
Exemplo n.º 8
0
    // This method allows the user to log in and play (if login is successful). Automatically called by either connectToMainServer() or signup().
    public void loginAndPlay(int port)
    {
        // Check if user left either field blank.
        if (usernameLogin.text.Equals("") || passwordLogin.text.Equals(""))
        {
            loginErrorMessage.enabled = true;
            return;
        }

        // First, connect to the subserver at the given port.
        Socket cnxn         = null;
        bool   playerInGame = false;       // tracks whether the player is in-game (i.e. not in the main menu)

        try {
            cnxn = new Socket(ip, port);
            ObjectOutputStream output = new ObjectOutputStream(cnxn.getOutputStream());

            // Send handshake
            output.writeInt(handshake);
            output.flush();

            // Now that we have connected and sent our handshake, we can send commands.
            // First: log in.
            output.writeInt(LOGIN);
            output.flush();

            output.writeObject(usernameLogin.text);
            output.flush();

            output.writeObject(passwordLogin.text);
            output.flush();

            // Check if login was successful or failed
            ObjectInputStream input = new ObjectInputStream(cnxn.getInputStream());
            cnxn.setSoTimeout(10000);
            if (input.readInt() != SPU.ServerResponse.LOGIN_OK.ordinal())
            {
                // Login failed at this point. Disconnect from the server so the user can try again.
                loginErrorMessage.enabled = true;
                output.writeInt(DISCONNECT);
                output.flush();
                input.close();
                output.close();
                cnxn.close();
                return;
            }
            // At this point, login was successful.
            ((StartMenuScript)(startMenu.GetComponent(typeof(StartMenuScript)))).saveLogin();
            loginErrorMessage.enabled = false;

            // Need to get the map first so the user can see stuff. First send the command, then receive the map and visibility.
            output.writeInt(GETCOND);
            output.flush();

            int          visibility = input.readInt();
            SPU.Tile[][] map        = (SPU.Tile[][])(input.readObject());

            // Load the game and start necessary threads.
            isLoading = true;
            StartCoroutine("LoadGame");
            while (isLoading)
            {
                ;
            }
            playerInGame = true;
            Destroy(GameObject.Find("Login Menu"));
            Destroy(GameObject.Find("Registration Menu"));
            Destroy(GameObject.Find("Main Menu Music"));

            // Create a thread to process user inputs (i.e. for the menu and for player movement)
            userInputThread = new System.Threading.Thread(new ThreadStart(new UserInputThread().ProcessInput));
            userInputThread.Start();
            while (!userInputThread.IsAlive)
            {
                ;                                         //loop until thread activates
            }
            // TO DO MUCH LATER: Draw the map, using visibility to determine visible tiles, and put this in the new scene.

            // At this point, process move commands one at a time (or logout if the user chooses).

            while (cmd != LOGOUT)
            {
                // First write the command...
                output.writeInt(cmd);
                output.flush();
                // ...then receive the updated visibility and map from the server.
                visibility = input.readInt();
                map        = (SPU.Tile[][])(input.readObject());
            }

            // At this point, user is ready to log out (cmd == LOGOUT).
            output.writeInt(LOGOUT);
            output.flush();

            // The game can just exit everything completely if the user is quitting to desktop.
            if (isQuitting)
            {
                Application.Quit();
            }

            input.close();
            output.close();
            cnxn.close();
            Destroy(GameObject.Find("BG Music"));
            isLoading = true;
            StartCoroutine("LoadMainMenu");
            while (isLoading)
            {
                ;
            }
            Destroy(this);
        }catch (java.lang.Exception e) {
            // Deal with a failed connection attempt
            StartMenuScript sms = (StartMenuScript)(startMenu.GetComponent(typeof(StartMenuScript)));
            if (cnxn == null)
            {
                sms.RaiseErrorWindow("Failed to connect. Check your connection settings. The subserver may be down.");
            }
            else if (e.GetType() == typeof(SocketTimeoutException) && !playerInGame)
            {
                sms.RaiseErrorWindow("Connection timed out. Check your connection. The subserver may have gone down.");
            }
            else
            {
                // Return to the main menu, since connection has timed out.
                Destroy(startMenu);
                Destroy(GameObject.Find("BG Music"));
                userInputThread.Abort();
                userInputThread.Join();
                isLoading = true;
                StartCoroutine("LoadMainMenu");
                while (isLoading)
                {
                    ;
                }
                StartMenuScript sms2 = ((StartMenuScript)(GameObject.Find("Start Menu").GetComponent <StartMenuScript>()));
                sms2.RaiseErrorWindow("Connection timed out. Check your connection. The subserver may have gone down.");
                Destroy(this);
            }
        }catch (System.Exception e) {
            // This handles C# exceptions. These shouldn't happen, which is why the errors are printed to the console (for us to test for ourselves).
            print("Encountered a C# exception:\n");
            print(e.StackTrace);
        }
    }
Exemplo n.º 9
0
    // Sign up on a given port. If registration is successful, the client will automatically log in for the user to begin playing.
    // Automatically called by connectToMainServer().
    public void signup(int port)
    {
        // Check if user left either field blank.
        if (usernameReg.text.Equals("") || passwordReg.text.Equals(""))
        {
            regFailedMessage.enabled = true;
            return;
        }

        // First, connect to the subserver at the given port.
        Socket cnxn        = null;
        bool   acctCreated = false;

        try {
            cnxn = new Socket(ip, port);
            ObjectOutputStream output = new ObjectOutputStream(cnxn.getOutputStream());

            // Send handshake
            output.writeInt(handshake);
            output.flush();

            // Now that we have connected and sent our handshake, we can send commands.
            // Here we will just sign up, close the connection, and log in using the given name and PW.

            output.writeInt(SIGNUP);
            output.flush();

            // Send username and PW.
            output.writeObject(usernameReg.text);
            output.flush();

            output.writeObject(passwordReg.text);
            output.flush();

            // Check if acc was created
            ObjectInputStream input = new ObjectInputStream(cnxn.getInputStream());
            cnxn.setSoTimeout(10000);
            acctCreated = input.readInt() == SPU.ServerResponse.ACCOUNT_CREATE_OK.ordinal();
            if (!acctCreated)
            {
                // Display an error message if registration failed.
                StartMenuScript sms = (StartMenuScript)(startMenu.GetComponent(typeof(StartMenuScript)));
                sms.RaiseErrorWindow("Account creation failed. That name may already be taken.");
            }

            // At this point, the user is (hopefully) signed up for the server on the given port. So, log in.
            // (Close connection and streams first!)
            output.close();
            input.close();
            cnxn.close();
            regFailedMessage.enabled = false;

            // If registration succeeded, at this point the client will auto-login and start playing the game.
            if (acctCreated)
            {
                usernameLogin.text = usernameReg.text;
                passwordLogin.text = passwordReg.text;
                ((StartMenuScript)(startMenu.GetComponent(typeof(StartMenuScript)))).RegToLogin();
                loginAndPlay(port);
            }
        }catch (java.lang.Exception e) {
            // Display some kind of error window if there was a connection error (basically a Java exception).
            // If the socket is null, the connection attempt failed; otherwise, the connection timed out, or something else happened.
            StartMenuScript sms = (StartMenuScript)(startMenu.GetComponent(typeof(StartMenuScript)));
            if (cnxn == null)
            {
                sms.RaiseErrorWindow("Failed to connect. Check your connection settings. The subserver may be down.");
            }
            else if (e.GetType() == typeof(SocketTimeoutException) && !acctCreated)
            {
                sms.RaiseErrorWindow("Connection timed out. Check your connection. The subserver may have gone down.");
            }
            else if (acctCreated)
            {
                sms.RaiseErrorWindow("Connection timed out, but registration was successful. The subserver may have gone down suddenly.");
            }
            else
            {
                sms.RaiseErrorWindow("An unknown exception occurred when trying to connect to the main server.");
            }
        }catch (System.Exception e) {
            // This handles C# exceptions. These shouldn't happen, which is why the errors are printed to the console (for us to test for ourselves).
            print("Encountered a C# exception:\n");
            print(e.StackTrace);
        }
    }
Exemplo n.º 10
0
 void Awake()
 {
     Instance = this;
 }
Exemplo n.º 11
0
 void Awake()
 {
     _instance = this;
     GameManager.Instance.FBInit();
 }
Exemplo n.º 12
0
 public void SetTarget(StartMenuScript _target)
 {
     target = _target;
 }