Exemplo n.º 1
0
    // FIX ISSUES HERE with http://answers.unity3d.com/questions/13443/is-there-a-way-to-measure-the-pixel-withheight-of.html
    void DrawChatBox()
    {
        Rect rView = m_rectBox;

        rView.x      = 0;
        rView.y      = 0;
        rView.height = m_listChatEntries.Count * 30;

        Rect rBox = m_rectBox;

        rBox.width += 20;
        //GUI.BeginScrollView(rBox,  m_v2ScrollPos, rView, false, false);

        //m_v2ScrollPos = new Vector2(m_v2ScrollPos.x, rView.height);
        if (m_listChatEntries.Count < 7)        // quick fix for something frustating
        {
            m_v2ScrollPos.y = 0;
        }
        UnityGUIExt.BeginScrollView(rBox, m_v2ScrollPos, rView, false, false);
        m_oScrollbar.Initialise(m_rectBox, rView, m_rectBox.width + 5, 0, m_rectBox.height, (m_rectBox.height / rView.height) * m_rectBox.height, m_v2ScrollPos);
        m_v2ScrollPos = m_oScrollbar.DoUpdate();

        if (m_rectBox.height / rView.height < 1.0f)
        {
            m_bDrawScroll = true;
        }
        else
        {
            m_bDrawScroll = false;
        }

        foreach (CChatEntry cEntry in m_listChatEntries)
        {
            if (cEntry.sName == "")
            {
                //Game message
                GUILayout.Label(cEntry.sMessage);
            }
            else
            {
                GUILayout.Label(cEntry.sName + ": " + cEntry.sMessage);
            }
        }
        //GUI.EndScrollView();
        UnityGUIExt.EndScrollView();
    }
Exemplo n.º 2
0
    void ProcessServerListGUI()
    {
        ServerScanner.TServerInfo[] taOnlineServers = GetComponent <ServerScanner>().GetServerList();

        if (taOnlineServers != null &&
            taOnlineServers.Length > 0)
        {
            // This box contains the box that contains the server list. It acts as the parent to everything.
            m_rectServer = UnityGUIExt.CreateRect(-99.0f, 325.0f, 542.0f, 386.0f,
                                                  UnityGUIExt.GUI_ALLIGN.TOP_CENTRE,
                                                  UnityGUIExt.GUI_ALLIGN.CENTRE);

            Rect rectHostEntry  = new Rect(0, 0, 543.0f, 95.0f);
            Rect rectHostName   = new Rect(130, 11, 100.0f, 100.0f);
            Rect rectNumPlayers = new Rect(105, 53, 100.0f, 100.0f);

            // This box contains the list of servers
            // It is relatively positioned to the parent
            // The height is determined by the number of hosted games
            m_rectServersContainer        = new Rect(0.0f, 0.0f, 525.0f, 0.0f);
            m_rectServersContainer.height = (taOnlineServers.Length * rectHostEntry.height);

            GUI.BeginScrollView(m_rectServer, m_v2ScrollPos, m_rectServersContainer);

            // Work out if a scroll bar is needed
            // If the box containing the server list is larger than the parent box then we need a scrollbar
            float fScrollbarSize = (m_rectServer.height / m_rectServersContainer.height);

            if (fScrollbarSize < 1.0f)
            {
                m_oScroller.Initialise(m_rectServer, m_rectServersContainer, m_rectServer.width - 15, 0, m_rectServer.height, fScrollbarSize * m_rectServer.height, m_v2ScrollPos);
                m_v2ScrollPos = m_oScroller.DoUpdate();
            }

            // Grab the mouse pos and convert it into the parent box's space

            Vector2 vCursor = GameApp.GetInstance().GetCursor().GetScreenPosition();
            vCursor.x -= m_rectServer.x;
            vCursor.y -= m_rectServer.y - m_v2ScrollPos.y;

            int i = 0;
            foreach (ServerScanner.TServerInfo tServerInfo in taOnlineServers)
            {
                // Draw the entry
                GUI.DrawTexture(rectHostEntry, m_HostEntry);
                GUI.Label(rectHostName, tServerInfo.sGameName);
                GUI.Label(rectNumPlayers, tServerInfo.uiNumConnectedPlayers + " / " + tServerInfo.uiPlayerLimit);

                // Check for selection
                if (rectHostEntry.Contains(vCursor))
                {
                    if (GameApp.GetInstance().GetCursor().IsMouseDown())
                    {
                        m_iChosenServer = i;
                    }

//					// Double click
//					// Does not function properly
                    Event evMouse = Event.current;
                    if (evMouse.isMouse && evMouse.clickCount == 2)
                    {
                        JoinGame(taOnlineServers[m_iChosenServer].saIp[0], m_strPlayerName);
                    }
                }

                // Highlight the chosen server
                if (m_iChosenServer == i)
                {
                    GUI.DrawTexture(rectHostEntry, m_tSelected);
                }

                // Increment to/for next entry
                rectHostEntry.y  += rectHostEntry.height;
                rectHostName.y   += rectHostEntry.height;
                rectNumPlayers.y += rectHostEntry.height;

                ++i;
            }

            // Store the IP of the chosen server
            if (m_iChosenServer != m_kiINVALID)
            {
                m_sChosenServer = taOnlineServers[m_iChosenServer].saIp[0];
            }

            GUI.EndScrollView();
        }
    }