Esempio n. 1
0
void CMenus::RenderServerbrowser(CUIRect MainView)
{
	/*
		+-----------------+	+-------+
		|				  |	|		|
		|				  |	| tool	|
		|   server list	  |	| box 	|
		|				  |	|	  	|
		|				  |	|		|
		+-----------------+	|	 	|
			status box	tab	+-------+
	*/

	CUIRect ServerList, ToolBox, StatusBox, TabBar;

	// background
	RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f);
	MainView.Margin(10.0f, &MainView);

	// create server list, status box, tab bar and tool box area
	MainView.VSplitRight(205.0f, &ServerList, &ToolBox);
	ServerList.HSplitBottom(70.0f, &ServerList, &StatusBox);
	StatusBox.VSplitRight(100.0f, &StatusBox, &TabBar);
	ServerList.VSplitRight(5.0f, &ServerList, 0);

	// server list
	{
		RenderServerbrowserServerList(ServerList);
	}

	int ToolboxPage = g_Config.m_UiToolboxPage;

	// tab bar
	{
		CUIRect TabButton0, TabButton1, TabButton2;
		TabBar.HSplitTop(5.0f, 0, &TabBar);
		TabBar.HSplitTop(20.0f, &TabButton0, &TabBar);
		TabBar.HSplitTop(2.5f, 0, &TabBar);
		TabBar.HSplitTop(20.0f, &TabButton1, &TabBar);
		TabBar.HSplitTop(2.5f, 0, &TabBar);
		TabBar.HSplitTop(20.0f, &TabButton2, 0);
		vec4 Active = ms_ColorTabbarActive;
		vec4 InActive = ms_ColorTabbarInactive;
		ms_ColorTabbarActive = vec4(0.0f, 0.0f, 0.0f, 0.3f);
		ms_ColorTabbarInactive = vec4(0.0f, 0.0f, 0.0f, 0.15f);

		static int s_FiltersTab = 0;
		if (DoButton_MenuTab(&s_FiltersTab, Localize("Filter"), ToolboxPage==0, &TabButton0, CUI::CORNER_L))
			ToolboxPage = 0;

		static int s_InfoTab = 0;
		if (DoButton_MenuTab(&s_InfoTab, Localize("Info"), ToolboxPage==1, &TabButton1, CUI::CORNER_L))
			ToolboxPage = 1;

		static int s_FriendsTab = 0;
		if (DoButton_MenuTab(&s_FriendsTab, Localize("Friends"), ToolboxPage==2, &TabButton2, CUI::CORNER_L))
			ToolboxPage = 2;

		ms_ColorTabbarActive = Active;
		ms_ColorTabbarInactive = InActive;
		g_Config.m_UiToolboxPage = ToolboxPage;
	}

	// tool box
	{
		RenderTools()->DrawUIRect(&ToolBox, vec4(0.0f, 0.0f, 0.0f, 0.15f), CUI::CORNER_T, 4.0f);


		if(ToolboxPage == 0)
			RenderServerbrowserFilters(ToolBox);
		else if(ToolboxPage == 1)
			RenderServerbrowserServerDetail(ToolBox);
		else if(ToolboxPage == 2)
			RenderServerbrowserFriends(ToolBox);
	}

	// status box
	{
		CUIRect Button, ButtonArea;
		StatusBox.HSplitTop(5.0f, 0, &StatusBox);

		// version note
		StatusBox.HSplitBottom(15.0f, &StatusBox, &Button);
		char aBuf[64];
		if(str_comp(Client()->LatestVersion(), "0") != 0)
		{
			str_format(aBuf, sizeof(aBuf), Localize("Teeworlds %s is out! Download it at www.teeworlds.com!"), Client()->LatestVersion());
			TextRender()->TextColor(1.0f, 0.4f, 0.4f, 1.0f);
		}
		else
			str_format(aBuf, sizeof(aBuf), Localize("Current version: %s"), GAME_VERSION);
		UI()->DoLabelScaled(&Button, aBuf, 14.0f, -1);
		TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);

		// button area
		StatusBox.VSplitRight(80.0f, &StatusBox, 0);
		StatusBox.VSplitRight(170.0f, &StatusBox, &ButtonArea);
		ButtonArea.VSplitRight(150.0f, 0, &ButtonArea);
		ButtonArea.HSplitTop(20.0f, &Button, &ButtonArea);
		Button.VMargin(2.0f, &Button);

		static int s_RefreshButton = 0;
		if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &Button))
		{
			if(g_Config.m_UiPage == PAGE_INTERNET)
				ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET);
			else if(g_Config.m_UiPage == PAGE_LAN)
				ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN);
			else if(g_Config.m_UiPage == PAGE_FAVORITES)
				ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES);
		}

		ButtonArea.HSplitTop(5.0f, 0, &ButtonArea);
		ButtonArea.HSplitTop(20.0f, &Button, &ButtonArea);
		Button.VMargin(2.0f, &Button);

		static int s_JoinButton = 0;
		if(DoButton_Menu(&s_JoinButton, Localize("Connect"), 0, &Button) || m_EnterPressed)
		{
			Client()->Connect(g_Config.m_UiServerAddress);
			m_EnterPressed = false;
		}

		// address info
		StatusBox.VSplitLeft(20.0f, 0, &StatusBox);
		StatusBox.HSplitTop(20.0f, &Button, &StatusBox);
		UI()->DoLabelScaled(&Button, Localize("Host address"), 14.0f, -1);
		StatusBox.HSplitTop(20.0f, &Button, 0);
		static float Offset = 0.0f;
		DoEditBox(&g_Config.m_UiServerAddress, &Button, g_Config.m_UiServerAddress, sizeof(g_Config.m_UiServerAddress), 14.0f, &Offset);
	}
}
Esempio n. 2
0
void CMenus::RenderServerbrowser(CUIRect MainView)
{
    RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f);

    CUIRect View;
    MainView.Margin(10.0f, &View);

    /*
    	+-----------------+ +------+
    	|                 | |      |
    	|                 | | tool |
    	|                 | | box  |
    	|                 | |      |
    	|                 | +------+
    	+-----------------+  button
          status toolbar      box
    */


    //CUIRect filters;
    CUIRect StatusToolBox;
    CUIRect ToolBox;
    CUIRect ButtonBox;

    // split off a piece for filters, details and scoreboard
    View.VSplitRight(200.0f, &View, &ToolBox);
    ToolBox.HSplitBottom(80.0f, &ToolBox, &ButtonBox);
    View.HSplitBottom(ms_ButtonHeight+5.0f, &View, &StatusToolBox);

    RenderServerbrowserServerList(View);

    int ToolboxPage = g_Config.m_UiToolboxPage;

    ToolBox.VSplitLeft(5.0f, 0, &ToolBox);

    // do tabbar
    {
        CUIRect TabBar;
        CUIRect TabButton0, TabButton1;
        ToolBox.HSplitTop(22.0f, &TabBar, &ToolBox);

        TabBar.VSplitMid(&TabButton0, &TabButton1);
        //TabButton0.VSplitRight(5.0f, &TabButton0, 0);
        //TabButton1.VSplitLeft(5.0f, 0, &TabButton1);

        static int s_FiltersTab = 0;
        if (DoButton_MenuTab(&s_FiltersTab, Localize("Filter"), ToolboxPage==0, &TabButton0, CUI::CORNER_TL))
            ToolboxPage = 0;

        static int s_InfoTab = 0;
        if (DoButton_MenuTab(&s_InfoTab, Localize("Info"), ToolboxPage==1, &TabButton1, CUI::CORNER_TR))
            ToolboxPage = 1;
    }

    g_Config.m_UiToolboxPage = ToolboxPage;

    RenderTools()->DrawUIRect(&ToolBox, vec4(0,0,0,0.15f), 0, 0);

    ToolBox.HSplitTop(5.0f, 0, &ToolBox);

    if(ToolboxPage == 0)
        RenderServerbrowserFilters(ToolBox);
    else if(ToolboxPage == 1)
        RenderServerbrowserServerDetail(ToolBox);

    {
        StatusToolBox.HSplitTop(5.0f, 0, &StatusToolBox);

        CUIRect Button;
        //buttons.VSplitRight(20.0f, &buttons, &button);
        StatusToolBox.VSplitRight(110.0f, &StatusToolBox, &Button);
        Button.VMargin(2.0f, &Button);
        static int s_RefreshButton = 0;
        if(DoButton_Menu(&s_RefreshButton, Localize("Refresh"), 0, &Button))
        {
            if(g_Config.m_UiPage == PAGE_INTERNET)
                ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET);
            else if(g_Config.m_UiPage == PAGE_LAN)
                ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN);
            else if(g_Config.m_UiPage == PAGE_FAVORITES)
                ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES);
        }

        char aBuf[512];
        if(str_comp(Client()->LatestVersion(), "0") != 0)
            str_format(aBuf, sizeof(aBuf), Localize("Teeworlds %s is out! Download it at www.teeworlds.com!"), Client()->LatestVersion());
        else
            str_format(aBuf, sizeof(aBuf), Localize("Current version: %s"), GAME_VERSION);
        UI()->DoLabelScaled(&StatusToolBox, aBuf, 14.0f, -1);
    }

    // do the button box
    {

        ButtonBox.VSplitLeft(5.0f, 0, &ButtonBox);
        ButtonBox.VSplitRight(5.0f, &ButtonBox, 0);

        CUIRect Button;
        ButtonBox.HSplitBottom(ms_ButtonHeight, &ButtonBox, &Button);
        Button.VSplitRight(120.0f, 0, &Button);
        Button.VMargin(2.0f, &Button);
        //button.VMargin(2.0f, &button);
        static int s_JoinButton = 0;
        if(DoButton_Menu(&s_JoinButton, Localize("Connect"), 0, &Button) || m_EnterPressed)
        {
            //dbg_msg("", "%s", g_Config.m_UiServerAddress);
            Client()->Connect(g_Config.m_UiServerAddress);
            m_EnterPressed = false;
        }

        ButtonBox.HSplitBottom(5.0f, &ButtonBox, &Button);
        ButtonBox.HSplitBottom(20.0f, &ButtonBox, &Button);
        static float Offset = 0.0f;
        DoEditBox(&g_Config.m_UiServerAddress, &Button, g_Config.m_UiServerAddress, sizeof(g_Config.m_UiServerAddress), 14.0f, &Offset);
        ButtonBox.HSplitBottom(20.0f, &ButtonBox, &Button);
        UI()->DoLabelScaled(&Button, Localize("Host address"), 14.0f, -1);
    }
}