예제 #1
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;
        }
    }
예제 #2
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;
        }
    }
예제 #3
0
    void OnGUI()
    {
        if (SelectionList.MouseDoubleClick())
        {
            PlayClick();
            StartLoad();
        }

        GUI.skin = mainSkin;
        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), "Load Game"))
        {
            PlayClick();
            StartLoad();
        }
        leftPos += ResourceManager.ButtonWidth + ResourceManager.Padding;
        if (GUI.Button(new Rect(leftPos, topPos, ResourceManager.ButtonWidth, ResourceManager.ButtonHeight), "Cancel"))
        {
            PlayClick();
            CancelLoad();
        }
        GUI.EndGroup();

        // 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);
    }
예제 #4
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);
        }
    }