Beispiel #1
0
 void OnGUI()
 {
     if (confirmDialog.IsConfirming())
     {
         string message = "\"" + saveName + "\" already exists. Do you widh to continue?";
         confirmDialog.Show(message, mySkin);
     }
     else if (confirmDialog.MadeChoice())
     {
         if (confirmDialog.ClickedYes())
         {
             SaveGame();
         }
         confirmDialog.EndConfirmation();
     }
     else
     {
         if (SelectionList.MouseDoubleClick())
         {
             PlayClick();
             saveName = SelectionList.GetCurrentEntry();
             StartSave();
         }
         GUI.skin = mySkin;
         DrawMenu();
         // Handle enter being hit when typing in the text field
         if (Event.current.keyCode == KeyCode.Return)
         {
             StartSave();
         }
         // If typing and cancel is hit, nothing happens..
         // doesn't appear to be a quick fix either..
     }
 }
Beispiel #2
0
    void OnGUI()
    {
        if (confirmDialog.IsConfirming())
        {
            string message = "\"" + saveName + "\" already exists. Do you wish to continue?";
            confirmDialog.Show(message, mySkin);
        }
        else if (confirmDialog.MadeChoice())
        {
            if (confirmDialog.ClickedYes())
            {
                SaveGame();
            }
            confirmDialog.EndConfirmation();
        }
        else
        {
            if (SelectionList.MouseDoubleClick())
            {
                PlayClick();
                saveName = SelectionList.GetCurrentEntry();
                StartSave();
            }
        }
        GUI.skin = mySkin;
        DrawMenu();

        if (Event.current.keyCode == KeyCode.Return)
        {
            StartSave();
        }
    }
Beispiel #3
0
    private void DrawMenu()
    {
        float menuHeight = GetMenuHeight();
        float groupLeft  = Screen.width / 2 - ResourceManager.MenuWidth / 2;
        float groupTop   = Screen.height / 2 - menuHeight / 2;
        Rect  groupRect  = new Rect(groupLeft, groupTop, ResourceManager.MenuWidth, menuHeight);

        GUI.BeginGroup(groupRect);
        // Background box
        GUI.Box(new Rect(0, 0, ResourceManager.MenuWidth, menuHeight), "");
        // Menu buttons
        float leftPos = ResourceManager.Padding;
        float topPos  = menuHeight - ResourceManager.Padding - ResourceManager.ButtonHeight;

        if (GUI.Button(new Rect(leftPos, topPos, ResourceManager.ButtonWidth, ResourceManager.ButtonHeight), "Save Game"))
        {
            PlayClick();
            StartSave();
        }
        leftPos += ResourceManager.ButtonWidth + ResourceManager.Padding;
        if (GUI.Button(new Rect(leftPos, topPos, ResourceManager.ButtonWidth, ResourceManager.ButtonHeight), "Cancel"))
        {
            PlayClick();
            CancelSave();
        }

        // Text area for player to type new name
        float textTop   = menuHeight - 2 * ResourceManager.Padding - ResourceManager.ButtonHeight - ResourceManager.TextHeight;
        float textWidth = ResourceManager.MenuWidth - 2 * ResourceManager.Padding;

        saveName = GUI.TextField(new Rect(ResourceManager.Padding, textTop, textWidth, ResourceManager.TextHeight), saveName, 60);
        SelectionList.SetCurrentEntry(saveName);
        GUI.EndGroup();

        // Selection list, needs to be called outside of the group for the menu
        string prevSelection   = SelectionList.GetCurrentEntry();
        float  selectionLeft   = groupRect.x + ResourceManager.Padding;
        float  selectionTop    = groupRect.y + ResourceManager.Padding;
        float  selectionWidth  = groupRect.width - 2 * ResourceManager.Padding;
        float  selectionHeight = groupRect.height - GetMenuItemsHeight() - ResourceManager.Padding;

        SelectionList.Draw(selectionLeft, selectionTop, selectionWidth, selectionHeight, selectionSkin);
        string newSelection = SelectionList.GetCurrentEntry();

        // Set saveName to be name in selected in list if selection has changed
        if (prevSelection != newSelection)
        {
            saveName = newSelection;
        }
    }
Beispiel #4
0
    void OnGUI()
    {
        GUI.skin = mySkin;

        float menuHeight = GetMenuHeight();
        float groupLeft  = Screen.width / 2 - ResourceManager.MenuWidth / 2;
        float groupTop   = Screen.height / 2 - menuHeight / 2;
        Rect  groupRect  = new Rect(groupLeft, groupTop, ResourceManager.MenuWidth, menuHeight);

        GUI.BeginGroup(groupRect);
        //background box
        GUI.Box(new Rect(0, 0, ResourceManager.MenuWidth, menuHeight), "");
        //menu buttons
        float leftPos = ResourceManager.MenuWidth / 2 - ResourceManager.ButtonWidth / 2;
        float topPos  = menuHeight - ResourceManager.Padding - ResourceManager.ButtonHeight;

        if (GUI.Button(new Rect(leftPos, topPos, ResourceManager.ButtonWidth, ResourceManager.ButtonHeight), "Select"))
        {
            SelectPlayer();
        }
        //text area for player to type new name
        float textTop   = menuHeight - 2 * ResourceManager.Padding - ResourceManager.ButtonHeight - ResourceManager.TextHeight;
        float textWidth = ResourceManager.MenuWidth - 2 * ResourceManager.Padding;

        playerName = GUI.TextField(new Rect(ResourceManager.Padding, textTop, textWidth, ResourceManager.TextHeight), playerName, 14);
        SelectionList.SetCurrentEntry(playerName);
        GUI.EndGroup();

        string prevSelection = SelectionList.GetCurrentEntry();

        //selection list, needs to be called outside of the group for the menu
        float selectionLeft   = groupRect.x + ResourceManager.Padding;
        float selectionTop    = groupRect.y + ResourceManager.Padding;
        float selectionWidth  = groupRect.width - 2 * ResourceManager.Padding;
        float selectionHeight = groupRect.height - GetMenuItemsHeight() - ResourceManager.Padding;

        SelectionList.Draw(selectionLeft, selectionTop, selectionWidth, selectionHeight, selectionSkin);

        string newSelection = SelectionList.GetCurrentEntry();

        //set saveName to be name selected in list if selection has changed
        if (prevSelection != newSelection)
        {
            playerName = newSelection;
        }
    }
Beispiel #5
0
    private void StartLoad()
    {
        string newLevel = SelectionList.GetCurrentEntry();

        if (newLevel != "")
        {
            ResourceManager.LevelName = newLevel;
            if (Application.loadedLevelName != "BlankMap1")
            {
                Application.LoadLevel("BlankMap1");
            }
            else if (Application.loadedLevelName != "BlankMap2")
            {
                Application.LoadLevel("BlankMap2");
            }

            Time.timeScale = 1.0f;
        }
    }
    private void StartLoad()
    {
        string newLevel = SelectionList.GetCurrentEntry();

        if (newLevel != "")
        {
            ResourceManager.LevelName = newLevel;
            if (Application.loadedLevelName != "BlankMap1")
            {
                Application.LoadLevel("BlankMap1");
            }
            else if (Application.loadedLevelName != "BlankMap2")
            {
                Application.LoadLevel("BlankMap2");
            }
            //makes sure that the loaded level runs at normal speed
            Time.timeScale = 1.0f;
        }
    }
Beispiel #7
0
    private void StartLoad()
    {
        string newLevel = SelectionList.GetCurrentEntry();

        if (newLevel != "")
        {
            GameResourceManager.LevelName = newLevel;
            // make use of a pair of empty scenes to load details into.
            // We need two of these for the scenario where we load a game into one and then want to load a game again
            if (SceneManager.GetActiveScene().name != "BlankMap1")
            {
                SceneManager.LoadScene("BlankMap1");
            }
            else if (SceneManager.GetActiveScene().name != "BlankMap2")
            {
                SceneManager.LoadScene("BlankMap2");
            }
            //makes sure that the loaded level runs at normal speed
            Time.timeScale = 1.0f;
        }
    }
Beispiel #8
0
    void OnGUI()
    {
        if (SelectionList.MouseDoubleClick())
        {
            PlayClick();
            playerName = SelectionList.GetCurrentEntry();
            SelectPlayer();
        }

        GUI.skin = mySkin;
        float menuHeight = GetMenuHeight();
        float groupLeft  = Screen.width / 2 - ResourceManager.MenuWidth / 2;
        float groupTop   = Screen.height / 2 - menuHeight / 2;
        Rect  groupRect  = new Rect(groupLeft, groupTop, ResourceManager.MenuWidth, menuHeight);

        GUI.BeginGroup(groupRect);
        //background box
        GUI.Box(new Rect(0, 0, ResourceManager.MenuWidth, menuHeight), "");
        //menu buttons
        float leftPos = ResourceManager.MenuWidth / 2 - ResourceManager.ButtonWidth / 2;
        float topPos  = menuHeight - ResourceManager.Padding - ResourceManager.ButtonHeight;

        if (GUI.Button(new Rect(leftPos, topPos, ResourceManager.ButtonWidth, ResourceManager.ButtonHeight), "Select"))
        {
            PlayClick();
            SelectPlayer();
        }

        //text are for player to type new name
        float textTop   = menuHeight - 2 * ResourceManager.Padding - ResourceManager.ButtonHeight - ResourceManager.TextHeight;
        float textWidth = ResourceManager.MenuWidth - 2 * ResourceManager.Padding;

        playerName = GUI.TextField(new Rect(ResourceManager.Padding, textTop, textWidth, ResourceManager.TextHeight), playerName, 14);
        SelectionList.SetCurrentEntry(playerName);

        if (avatarIndex >= 0)
        {
            float avatarLeft   = ResourceManager.MenuWidth / 2 - avatars [avatarIndex].width / 2;
            float avatarTop    = textTop - ResourceManager.Padding - avatars [avatarIndex].height;
            float avatarWidth  = avatars [avatarIndex].width;
            float avatarHeight = avatars [avatarIndex].height;
            GUI.DrawTexture(new Rect(avatarLeft, avatarTop, avatarWidth, avatarHeight), avatars [avatarIndex]);
            float buttonTop  = textTop - ResourceManager.Padding - ResourceManager.ButtonHeight;
            float buttonLeft = ResourceManager.Padding;
            if (GUI.Button(new Rect(buttonLeft, buttonTop, ResourceManager.ButtonHeight, ResourceManager.ButtonHeight), "<"))
            {
                PlayClick();
                avatarIndex -= 1;
                if (avatarIndex < 0)
                {
                    avatarIndex = avatars.Length - 1;
                }
            }
            buttonLeft = ResourceManager.MenuWidth - ResourceManager.Padding - ResourceManager.ButtonHeight;
            if (GUI.Button(new Rect(buttonLeft, buttonTop, ResourceManager.ButtonHeight, ResourceManager.ButtonHeight), ">"))
            {
                PlayClick();
                avatarIndex = (avatarIndex + 1) % avatars.Length;
            }
        }

        GUI.EndGroup();

        string prevSelection = SelectionList.GetCurrentEntry();

        //selection list, needs to be called outside of the group for the menu
        float selectionLeft   = groupRect.x + ResourceManager.Padding;
        float selectionTop    = groupRect.y + ResourceManager.Padding;
        float selectionWidth  = groupRect.width - 2 * ResourceManager.Padding;
        float selectionHeight = groupRect.height - GetMenuItemsHeight() - ResourceManager.Padding;

        SelectionList.Draw(selectionLeft, selectionTop, selectionWidth, selectionHeight, selectionSkin);

        string newSelection = SelectionList.GetCurrentEntry();

        if (prevSelection != newSelection)
        {
            playerName  = newSelection;
            avatarIndex = PlayerManager.GetAvatar(playerName);
        }
    }