Esempio n. 1
0
        // Try to get a score from the cache.
        public void GetScore(string levelname, HighScores.ScoreType type)
        {
            // If we are currently loading scores, wait for that one to finish first.
            if (loadingScores)
            {
                return;
            }

            Dictionary <string, CacheEntry> lookup = null;

            if (type == HighScores.ScoreType.Speed)
            {
                lookup = speedCache;
            }
            else
            {
                lookup = timeCache;
            }

            if (!lookup.ContainsKey(levelname))
            {
                loadingLevelName = levelname;
                loadingScoreType = type;
                Networking.GetScores(LoadedScores, levelname,
                                     type == HighScores.ScoreType.Speed ? Networking.Metric.SPEED : Networking.Metric.TIME,
                                     0, 10);
                loadingScores = true;
            }
            else
            {
                RetrievedCallback(lookup[levelname].scores, levelname);
            }
        }
    // Draw the highscores.
    void OnGUI()
    {
        if (LevelSelectGUI.menuState != LevelSelectGUI.MenuState.LEVEL_SELECT)
            enable = false;

        if (!enable) {
            GUIController.HideText("ScoreTypeName");
            return;
        }

        // Set skin and store old skin
        GUISkin oldSkin = GUI.skin;
        GUI.skin = Screen.width > 1500 ? biggerSkin : guiSkin;

        // Find out whether or not a planet is selected
        if (LevelSelectGUI.currentPlanet == null || !enable)
            return;

        // Calculate the how large things need to be.
        float labelPosX = Screen.width / 20;
        float labelPosY = Screen.height / 20;
        float labelWidth = Screen.width - (Screen.width / 10);
        float labelHeight = (Screen.height / 12);
        float buttonX = labelPosX;
        float buttonY = labelPosY;
        float buttonWidth = (Screen.width / 6);
        float buttonHeight = labelHeight;
        float buttonScoreTypeX = labelPosX + buttonWidth;
        float buttonScoreTypeY = buttonY;
        float scrollPosX = labelPosX;
        float scrollPosY = buttonY + buttonHeight;
        float scrollWidth = labelWidth;
        float scrollHeight = (Screen.height / 2.0f);
        float playButtonX = scrollPosX;
        float playButtonY = scrollPosY + scrollHeight + 5;
        float playButtonWidth = scrollWidth;
        float playButtonHeight = scrollHeight / 4;

        // Update the mouse position
        if (InputManager.currentPosition.x > labelPosX && InputManager.currentPosition.y > (Screen.height - (playButtonY + playButtonHeight)))
        {
            if (InputManager.held)
            {
                if ((lastMousePos - InputManager.currentPosition).y < 10.0f)
                    scrolled.y -= (lastMousePos - InputManager.currentPosition).y;
            }
        }
        lastMousePos = InputManager.currentPosition;

        // Draw a texture at the back
        GUI.DrawTexture(new Rect(labelPosX, labelHeight + labelPosY, playButtonX + playButtonWidth - (Screen.width / 20), playButtonY + playButtonHeight - labelHeight - buttonY), BG);

        // Draw a label at the top of the menu.
        string label = (locality == Locality.Internet ? "Internet" : "Local") + " " +
                       (scoreType == HighScores.ScoreType.Speed ? "Top Scores" : "Fastest Times");
        GUIController.ShowText("ScoreTypeName", label);

        // Draw the play replay button
        if (GUI.Button(new Rect(playButtonX, playButtonY, playButtonWidth, playButtonHeight), "Play Replay"))
        {
            LevelSelectGUI.worldToShow = LevelSelectGUI.currentWorld;
            LevelSelectGUI.levelToShow = LevelSelectGUI.currentLevel.number;

            if (locality == Locality.Local && selectedIndex < recordings.Count)
            {
                GameRecorder.StartPlaybackFromMenu(recordings[selectedIndex]);
            }
            else
            {
                // Grab the recording from the net.
                if (scores != null)
                    Networking.GetRecording(LoadRecordingFromInternet, scores[selectedIndex].id);
            }

            if (selectedIndex < recordings.Count)
                GameRecorder.StartPlaybackFromMenu(recordings[selectedIndex]);
        }

        // Draw the button to switch from local to internet
        // and vice versa.
        string buttonText = "";
        switch (locality)
        {
        case Locality.Local:
            buttonText = "Internet Scores";
            break;
        case Locality.Internet:
            buttonText = "Local Scores";
            break;
        default:
            buttonText = "Wut";
            break;
        }

        if (Options.Networking)
        {
            if (GUI.Button(new Rect(buttonX, buttonY, buttonWidth, buttonHeight), buttonText))
            {
                if (locality == Locality.Local)
                    locality = Locality.Internet;
                else
                    locality = Locality.Local;

                // Refresh the scores
                LoadReplays();
            }
        }

        // Button to switch score type.
        string scoreTypeText = "";
        switch (scoreType)
        {
        case HighScores.ScoreType.Speed:
            scoreTypeText = "View Fastest Times";
            break;
        case HighScores.ScoreType.Time:
            scoreTypeText = "View Highest Scores";
            break;
        default:
            scoreTypeText = "Wut";
            break;
        }

        if (GUI.Button(new Rect(buttonScoreTypeX, buttonScoreTypeY, buttonWidth, buttonHeight), scoreTypeText))
        {
            if (scoreType == HighScores.ScoreType.Speed)
                scoreType = HighScores.ScoreType.Time;
            else
                scoreType = HighScores.ScoreType.Speed;

            // Refresh the scores
            LoadReplays();
        }

        // The scrolling menu stuff
        GUILayout.BeginArea(new Rect(scrollPosX, scrollPosY, scrollWidth, scrollHeight));

            scrolled = GUILayout.BeginScrollView(scrolled);

                if (names != null)
                    selectedIndex = GUILayout.SelectionGrid(selectedIndex, names, 1);

            GUILayout.EndScrollView();

        GUILayout.EndArea();

        // Restore old skin
        GUI.skin = oldSkin;
    }
        // Try to get a score from the cache.
        public void GetScore(string levelname, HighScores.ScoreType type)
        {
            // If we are currently loading scores, wait for that one to finish first.
            if (loadingScores)
            {
                return;
            }

            Dictionary<string, CacheEntry> lookup = null;
            if (type == HighScores.ScoreType.Speed)
            {
                lookup = speedCache;
            } else
            {
                lookup = timeCache;
            }

            if (!lookup.ContainsKey(levelname))
            {
                loadingLevelName = levelname;
                loadingScoreType = type;
                Networking.GetScores(LoadedScores, levelname,
                                     type == HighScores.ScoreType.Speed ? Networking.Metric.SPEED : Networking.Metric.TIME,
                                     0, 10);
                loadingScores = true;
            }
            else
            {
                RetrievedCallback(lookup[levelname].scores, levelname);
            }
        }
Esempio n. 4
0
    // Draw the highscores.
    void OnGUI()
    {
        if (LevelSelectGUI.menuState != LevelSelectGUI.MenuState.LEVEL_SELECT)
        {
            enable = false;
        }

        if (!enable)
        {
            GUIController.HideText("ScoreTypeName");
            return;
        }

        // Set skin and store old skin
        GUISkin oldSkin = GUI.skin;

        GUI.skin = Screen.width > 1500 ? biggerSkin : guiSkin;

        // Find out whether or not a planet is selected
        if (LevelSelectGUI.currentPlanet == null || !enable)
        {
            return;
        }

        // Calculate the how large things need to be.
        float labelPosX        = Screen.width / 20;
        float labelPosY        = Screen.height / 20;
        float labelWidth       = Screen.width - (Screen.width / 10);
        float labelHeight      = (Screen.height / 12);
        float buttonX          = labelPosX;
        float buttonY          = labelPosY;
        float buttonWidth      = (Screen.width / 6);
        float buttonHeight     = labelHeight;
        float buttonScoreTypeX = labelPosX + buttonWidth;
        float buttonScoreTypeY = buttonY;
        float scrollPosX       = labelPosX;
        float scrollPosY       = buttonY + buttonHeight;
        float scrollWidth      = labelWidth;
        float scrollHeight     = (Screen.height / 2.0f);
        float playButtonX      = scrollPosX;
        float playButtonY      = scrollPosY + scrollHeight + 5;
        float playButtonWidth  = scrollWidth;
        float playButtonHeight = scrollHeight / 4;

        // Update the mouse position
        if (InputManager.currentPosition.x > labelPosX && InputManager.currentPosition.y > (Screen.height - (playButtonY + playButtonHeight)))
        {
            if (InputManager.held)
            {
                if ((lastMousePos - InputManager.currentPosition).y < 10.0f)
                {
                    scrolled.y -= (lastMousePos - InputManager.currentPosition).y;
                }
            }
        }
        lastMousePos = InputManager.currentPosition;

        // Draw a texture at the back
        GUI.DrawTexture(new Rect(labelPosX, labelHeight + labelPosY, playButtonX + playButtonWidth - (Screen.width / 20), playButtonY + playButtonHeight - labelHeight - buttonY), BG);

        // Draw a label at the top of the menu.
        string label = (locality == Locality.Internet ? "Internet" : "Local") + " " +
                       (scoreType == HighScores.ScoreType.Speed ? "Top Scores" : "Fastest Times");

        GUIController.ShowText("ScoreTypeName", label);

        // Draw the play replay button
        if (GUI.Button(new Rect(playButtonX, playButtonY, playButtonWidth, playButtonHeight), "Play Replay"))
        {
            LevelSelectGUI.worldToShow = LevelSelectGUI.currentWorld;
            LevelSelectGUI.levelToShow = LevelSelectGUI.currentLevel.number;

            if (locality == Locality.Local && selectedIndex < recordings.Count)
            {
                GameRecorder.StartPlaybackFromMenu(recordings[selectedIndex]);
            }
            else
            {
                // Grab the recording from the net.
                if (scores != null)
                {
                    Networking.GetRecording(LoadRecordingFromInternet, scores[selectedIndex].id);
                }
            }

            if (selectedIndex < recordings.Count)
            {
                GameRecorder.StartPlaybackFromMenu(recordings[selectedIndex]);
            }
        }

        // Draw the button to switch from local to internet
        // and vice versa.
        string buttonText = "";

        switch (locality)
        {
        case Locality.Local:
            buttonText = "Internet Scores";
            break;

        case Locality.Internet:
            buttonText = "Local Scores";
            break;

        default:
            buttonText = "Wut";
            break;
        }

        if (Options.Networking)
        {
            if (GUI.Button(new Rect(buttonX, buttonY, buttonWidth, buttonHeight), buttonText))
            {
                if (locality == Locality.Local)
                {
                    locality = Locality.Internet;
                }
                else
                {
                    locality = Locality.Local;
                }

                // Refresh the scores
                LoadReplays();
            }
        }

        // Button to switch score type.
        string scoreTypeText = "";

        switch (scoreType)
        {
        case HighScores.ScoreType.Speed:
            scoreTypeText = "View Fastest Times";
            break;

        case HighScores.ScoreType.Time:
            scoreTypeText = "View Highest Scores";
            break;

        default:
            scoreTypeText = "Wut";
            break;
        }

        if (GUI.Button(new Rect(buttonScoreTypeX, buttonScoreTypeY, buttonWidth, buttonHeight), scoreTypeText))
        {
            if (scoreType == HighScores.ScoreType.Speed)
            {
                scoreType = HighScores.ScoreType.Time;
            }
            else
            {
                scoreType = HighScores.ScoreType.Speed;
            }

            // Refresh the scores
            LoadReplays();
        }

        // The scrolling menu stuff
        GUILayout.BeginArea(new Rect(scrollPosX, scrollPosY, scrollWidth, scrollHeight));

        scrolled = GUILayout.BeginScrollView(scrolled);

        if (names != null)
        {
            selectedIndex = GUILayout.SelectionGrid(selectedIndex, names, 1);
        }

        GUILayout.EndScrollView();

        GUILayout.EndArea();

        // Restore old skin
        GUI.skin = oldSkin;
    }