ddnet/src/game/client/components/menus.cpp

1395 lines
38 KiB
C++
Raw Normal View History

2010-05-29 07:25:38 +00:00
// copyright (c) 2007 magnus auvinen, see licence.txt for more info
#include <math.h>
#include <base/system.h>
2010-05-29 07:25:38 +00:00
#include <base/math.h>
#include <base/vmath.h>
2010-05-29 07:25:38 +00:00
#include "menus.h"
#include "skins.h"
#include <string>
#include <string.h>
2010-05-29 07:25:38 +00:00
#include <engine/graphics.h>
#include <engine/textrender.h>
#include <engine/serverbrowser.h>
#include <engine/keys.h>
#include <engine/shared/config.h>
2009-06-13 17:18:06 +00:00
2010-05-29 07:25:38 +00:00
#include <game/version.h>
#include <game/generated/protocol.h>
2010-05-29 07:25:38 +00:00
#include <game/generated/client_data.h>
#include <game/client/gameclient.h>
#include <game/client/lineinput.h>
#include <game/localization.h>
#include <mastersrv/mastersrv.h>
2010-05-29 07:25:38 +00:00
vec4 CMenus::ms_GuiColor;
vec4 CMenus::ms_ColorTabbarInactiveOutgame;
vec4 CMenus::ms_ColorTabbarActiveOutgame;
vec4 CMenus::ms_ColorTabbarInactive;
vec4 CMenus::ms_ColorTabbarActive;
vec4 CMenus::ms_ColorTabbarInactiveIngame;
vec4 CMenus::ms_ColorTabbarActiveIngame;
2010-05-29 07:25:38 +00:00
float CMenus::ms_ButtonHeight = 25.0f;
float CMenus::ms_ListheaderHeight = 17.0f;
float CMenus::ms_FontmodHeight = 0.8f;
2010-05-29 07:25:38 +00:00
IInput::CEvent CMenus::m_aInputEvents[MAX_INPUTEVENTS];
int CMenus::m_NumInputEvents;
2010-05-29 07:25:38 +00:00
inline float HueToRgb(float v1, float v2, float h)
2008-08-30 21:09:13 +00:00
{
if(h < 0) h += 1;
if(h > 1) h -= 1;
if((6 * h) < 1) return v1 + ( v2 - v1 ) * 6 * h;
if((2 * h) < 1) return v2;
if((3 * h) < 2) return v1 + ( v2 - v1 ) * ((2.0f/3.0f) - h) * 6;
return v1;
}
2010-05-29 07:25:38 +00:00
inline vec3 HslToRgb(vec3 In)
2008-08-30 21:09:13 +00:00
{
float v1, v2;
2010-05-29 07:25:38 +00:00
vec3 Out;
2008-08-30 21:09:13 +00:00
2010-05-29 07:25:38 +00:00
if(In.s == 0)
2008-08-30 21:09:13 +00:00
{
2010-05-29 07:25:38 +00:00
Out.r = In.l;
Out.g = In.l;
Out.b = In.l;
2008-08-30 21:09:13 +00:00
}
else
{
2010-05-29 07:25:38 +00:00
if(In.l < 0.5f)
v2 = In.l * (1 + In.s);
2008-08-30 21:09:13 +00:00
else
2010-05-29 07:25:38 +00:00
v2 = (In.l+In.s) - (In.s*In.l);
2008-08-30 21:09:13 +00:00
2010-05-29 07:25:38 +00:00
v1 = 2 * In.l - v2;
2008-08-30 21:09:13 +00:00
2010-05-29 07:25:38 +00:00
Out.r = HueToRgb(v1, v2, In.h + (1.0f/3.0f));
Out.g = HueToRgb(v1, v2, In.h);
Out.b = HueToRgb(v1, v2, In.h - (1.0f/3.0f));
2008-08-30 21:09:13 +00:00
}
2010-05-29 07:25:38 +00:00
return Out;
2008-08-30 21:09:13 +00:00
}
2010-05-29 07:25:38 +00:00
CMenus::CMenus()
{
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_NONE;
m_ActivePage = PAGE_INTERNET;
m_GamePage = PAGE_GAME;
2010-05-29 07:25:38 +00:00
m_NeedRestart = false;
m_NeedSendinfo = false;
m_MenuActive = true;
m_UseMouseButtons = true;
2010-05-29 07:25:38 +00:00
m_EscapePressed = false;
m_EnterPressed = false;
m_NumInputEvents = 0;
2008-09-12 07:20:26 +00:00
2010-05-29 07:25:38 +00:00
m_LastInput = time_get();
2010-06-04 20:14:02 +00:00
m_Download.m_ElapsedTick = 50;
m_Download.m_ElapsedSec = 0;
m_Download.m_Speed = 0;
m_Download.m_TimeNeeded = 0;
m_Download.m_TimeRemaining = 0;
2010-06-04 20:14:02 +00:00
str_copy(m_aCurrentDemoFolder, "demos", sizeof(m_aCurrentDemoFolder));
}
void CMenus::ResetDownloadVars() {
m_Download.m_ElapsedTick = 50;
m_Download.m_ElapsedSec = 0;
m_Download.m_Speed = 0;
m_Download.m_TimeNeeded = 0;
m_Download.m_TimeRemaining = 0;
}
2010-05-29 07:25:38 +00:00
vec4 CMenus::ButtonColorMul(const void *pID)
{
2009-10-27 14:38:53 +00:00
if(UI()->ActiveItem() == pID)
return vec4(1,1,1,0.5f);
2009-10-27 14:38:53 +00:00
else if(UI()->HotItem() == pID)
return vec4(1,1,1,1.5f);
return vec4(1,1,1,1);
}
2010-05-29 07:25:38 +00:00
int CMenus::DoButton_BrowseIcon(int What, const CUIRect *pRect)
{
2010-05-29 07:25:38 +00:00
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_BROWSEICONS].m_Id);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsBegin();
2010-05-29 07:25:38 +00:00
RenderTools()->SelectSprite(What);
IGraphics::CQuadItem QuadItem(pRect->x, pRect->y, pRect->w, pRect->h);
Graphics()->QuadsDrawTL(&QuadItem, 1);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsEnd();
return 0;
}
2010-05-29 07:25:38 +00:00
int CMenus::DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
{
2010-05-29 07:25:38 +00:00
RenderTools()->DrawUIRect(pRect, vec4(1,1,1,0.5f)*ButtonColorMul(pID), CUI::CORNER_ALL, 5.0f);
UI()->DoLabel(pRect, pText, pRect->h*ms_FontmodHeight, 0);
2009-10-27 14:38:53 +00:00
return UI()->DoButtonLogic(pID, pText, Checked, pRect);
}
2010-05-29 07:25:38 +00:00
void CMenus::DoButton_KeySelect(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
{
2010-05-29 07:25:38 +00:00
RenderTools()->DrawUIRect(pRect, vec4(1,1,1,0.5f)*ButtonColorMul(pID), CUI::CORNER_ALL, 5.0f);
UI()->DoLabel(pRect, pText, pRect->h*ms_FontmodHeight, 0);
}
2010-05-29 07:25:38 +00:00
int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners)
{
2009-10-27 14:38:53 +00:00
vec4 ColorMod(1,1,1,1);
2009-10-27 14:38:53 +00:00
if(Checked)
2010-05-29 07:25:38 +00:00
RenderTools()->DrawUIRect(pRect, ms_ColorTabbarActive, Corners, 10.0f);
else
2010-05-29 07:25:38 +00:00
RenderTools()->DrawUIRect(pRect, ms_ColorTabbarInactive, Corners, 10.0f);
UI()->DoLabel(pRect, pText, pRect->h*ms_FontmodHeight, 0);
2009-10-27 14:38:53 +00:00
return UI()->DoButtonLogic(pID, pText, Checked, pRect);
}
2010-05-29 07:25:38 +00:00
int CMenus::DoButton_SettingsTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
{
2009-10-27 14:38:53 +00:00
if(Checked)
2010-05-29 07:25:38 +00:00
RenderTools()->DrawUIRect(pRect, ms_ColorTabbarActive, CUI::CORNER_R, 10.0f);
else
2010-05-29 07:25:38 +00:00
RenderTools()->DrawUIRect(pRect, ms_ColorTabbarInactive, CUI::CORNER_R, 10.0f);
UI()->DoLabel(pRect, pText, pRect->h*ms_FontmodHeight, 0);
2009-10-27 14:38:53 +00:00
return UI()->DoButtonLogic(pID, pText, Checked, pRect);
}
2010-05-29 07:25:38 +00:00
int CMenus::DoButton_GridHeader(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
//void CMenus::ui_draw_grid_header(const void *id, const char *text, int checked, const CUIRect *r, const void *extra)
{
2009-10-27 14:38:53 +00:00
if(Checked)
RenderTools()->DrawUIRect(pRect, vec4(1,1,1,0.5f), CUI::CORNER_T, 5.0f);
CUIRect t;
pRect->VSplitLeft(5.0f, 0, &t);
2010-05-29 07:25:38 +00:00
UI()->DoLabel(&t, pText, pRect->h*ms_FontmodHeight, -1);
2009-10-27 14:38:53 +00:00
return UI()->DoButtonLogic(pID, pText, Checked, pRect);
}
2010-05-29 07:25:38 +00:00
int CMenus::DoButton_ListRow(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
{
2009-10-27 14:38:53 +00:00
if(Checked)
{
2009-10-27 14:38:53 +00:00
CUIRect sr = *pRect;
sr.Margin(1.5f, &sr);
RenderTools()->DrawUIRect(&sr, vec4(1,1,1,0.5f), CUI::CORNER_ALL, 4.0f);
}
2010-05-29 07:25:38 +00:00
UI()->DoLabel(pRect, pText, pRect->h*ms_FontmodHeight, -1);
2009-10-27 14:38:53 +00:00
return UI()->DoButtonLogic(pID, pText, Checked, pRect);
}
2010-05-29 07:25:38 +00:00
int CMenus::DoButton_CheckBox_Common(const void *pID, const char *pText, const char *pBoxText, const CUIRect *pRect)
//void CMenus::ui_draw_checkbox_common(const void *id, const char *text, const char *boxtext, const CUIRect *r, const void *extra)
{
2009-10-27 14:38:53 +00:00
CUIRect c = *pRect;
CUIRect t = *pRect;
c.w = c.h;
t.x += c.w;
t.w -= c.w;
2009-10-27 14:38:53 +00:00
t.VSplitLeft(5.0f, 0, &t);
2009-10-27 14:38:53 +00:00
c.Margin(2.0f, &c);
2010-05-29 07:25:38 +00:00
RenderTools()->DrawUIRect(&c, vec4(1,1,1,0.25f)*ButtonColorMul(pID), CUI::CORNER_ALL, 3.0f);
c.y += 2;
2010-05-29 07:25:38 +00:00
UI()->DoLabel(&c, pBoxText, pRect->h*ms_FontmodHeight*0.6f, 0);
UI()->DoLabel(&t, pText, pRect->h*ms_FontmodHeight*0.8f, -1);
2009-10-27 14:38:53 +00:00
return UI()->DoButtonLogic(pID, pText, 0, pRect);
}
2010-05-29 07:25:38 +00:00
int CMenus::DoButton_CheckBox(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
{
2009-10-27 14:38:53 +00:00
return DoButton_CheckBox_Common(pID, pText, Checked?"X":"", pRect);
}
2010-05-29 07:25:38 +00:00
int CMenus::DoButton_CheckBox_Number(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
{
2010-05-29 07:25:38 +00:00
char aBuf[16];
str_format(aBuf, sizeof(aBuf), "%d", Checked);
return DoButton_CheckBox_Common(pID, pText, aBuf, pRect);
}
int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden, int Corners)
{
2009-10-27 14:38:53 +00:00
int Inside = UI()->MouseInside(pRect);
2010-05-29 07:25:38 +00:00
bool ReturnValue = false;
static int s_AtIndex = 0;
2009-10-27 14:38:53 +00:00
if(UI()->LastActiveItem() == pID)
{
2010-05-29 07:25:38 +00:00
int Len = str_length(pStr);
if(Len == 0)
s_AtIndex = 0;
2008-10-20 23:43:15 +00:00
2009-10-27 14:38:53 +00:00
if(Inside && UI()->MouseButton(0))
{
2010-05-29 07:25:38 +00:00
int MxRel = (int)(UI()->MouseX() - pRect->x);
2010-05-29 07:25:38 +00:00
for(int i = 1; i <= Len; i++)
{
if(TextRender()->TextWidth(0, FontSize, pStr, i) - *Offset + 10 > MxRel)
{
2010-05-29 07:25:38 +00:00
s_AtIndex = i - 1;
break;
}
2010-05-29 07:25:38 +00:00
if(i == Len)
s_AtIndex = Len;
}
}
2010-05-29 07:25:38 +00:00
for(int i = 0; i < m_NumInputEvents; i++)
{
2010-05-29 07:25:38 +00:00
Len = str_length(pStr);
ReturnValue |= CLineInput::Manipulate(m_aInputEvents[i], pStr, StrSize, &Len, &s_AtIndex);
}
}
2009-10-27 14:38:53 +00:00
bool JustGotActive = false;
2009-10-27 14:38:53 +00:00
if(UI()->ActiveItem() == pID)
{
2009-10-27 14:38:53 +00:00
if(!UI()->MouseButton(0))
UI()->SetActiveItem(0);
}
2009-10-27 14:38:53 +00:00
else if(UI()->HotItem() == pID)
{
2009-10-27 14:38:53 +00:00
if(UI()->MouseButton(0))
{
2009-10-27 14:38:53 +00:00
if (UI()->LastActiveItem() != pID)
JustGotActive = true;
UI()->SetActiveItem(pID);
}
}
2009-10-27 14:38:53 +00:00
if(Inside)
UI()->SetHotItem(pID);
2009-10-27 14:38:53 +00:00
CUIRect Textbox = *pRect;
2010-05-29 07:25:38 +00:00
RenderTools()->DrawUIRect(&Textbox, vec4(1, 1, 1, 0.5f), Corners, 3.0f);
Textbox.VMargin(2.0f, &Textbox);
Textbox.HMargin(2.0f, &Textbox);
2009-10-27 14:38:53 +00:00
const char *pDisplayStr = pStr;
char aStars[128];
2009-10-27 14:38:53 +00:00
if(Hidden)
{
2010-05-29 07:25:38 +00:00
unsigned s = str_length(pStr);
2009-10-27 14:38:53 +00:00
if(s >= sizeof(aStars))
s = sizeof(aStars)-1;
2010-05-29 07:25:38 +00:00
for(unsigned int i = 0; i < s; ++i)
aStars[i] = '*';
2009-10-27 14:38:53 +00:00
aStars[s] = 0;
pDisplayStr = aStars;
}
// check if the text has to be moved
if(UI()->LastActiveItem() == pID && !JustGotActive && m_NumInputEvents)
{
float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex)*UI()->Scale();
if(w-*Offset > Textbox.w)
{
// move to the left
float wt = TextRender()->TextWidth(0, FontSize, pDisplayStr, -1)*UI()->Scale();
do
{
*Offset += min(wt-*Offset-Textbox.w, Textbox.w/3);
}
while(w-*Offset > Textbox.w);
}
else if(w-*Offset < 0.0f)
{
// move to the right
do
{
*Offset = max(0.0f, *Offset-Textbox.w/3);
}
while(w-*Offset < 0.0f);
}
}
UI()->ClipEnable(pRect);
Textbox.x -= *Offset*UI()->Scale();
2009-10-27 14:38:53 +00:00
UI()->DoLabel(&Textbox, pDisplayStr, FontSize, -1);
// render the cursor
2010-05-29 07:25:38 +00:00
if(UI()->LastActiveItem() == pID && !JustGotActive)
{
2010-05-29 07:25:38 +00:00
float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex);
Textbox = *pRect;
Textbox.VSplitLeft(2.0f, 0, &Textbox);
Textbox.x += (w-*Offset-TextRender()->TextWidth(0, FontSize, "|", -1)/2)*UI()->Scale();
if((2*time_get()/time_freq()) % 2) // make it blink
UI()->DoLabel(&Textbox, "|", FontSize, -1);
}
UI()->ClipDisable();
2009-10-27 14:38:53 +00:00
return ReturnValue;
}
2010-05-29 07:25:38 +00:00
float CMenus::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current)
{
2009-10-27 14:38:53 +00:00
CUIRect Handle;
static float OffsetY;
pRect->HSplitTop(33, &Handle, 0);
2009-10-27 14:38:53 +00:00
Handle.y += (pRect->h-Handle.h)*Current;
2010-05-29 07:25:38 +00:00
// logic
2009-10-27 14:38:53 +00:00
float ReturnValue = Current;
int Inside = UI()->MouseInside(&Handle);
2009-10-27 14:38:53 +00:00
if(UI()->ActiveItem() == pID)
{
2009-10-27 14:38:53 +00:00
if(!UI()->MouseButton(0))
UI()->SetActiveItem(0);
2010-05-29 07:25:38 +00:00
float Min = pRect->y;
float Max = pRect->h-Handle.h;
float Cur = UI()->MouseY()-OffsetY;
ReturnValue = (Cur-Min)/Max;
2009-10-27 14:38:53 +00:00
if(ReturnValue < 0.0f) ReturnValue = 0.0f;
if(ReturnValue > 1.0f) ReturnValue = 1.0f;
}
2009-10-27 14:38:53 +00:00
else if(UI()->HotItem() == pID)
{
2009-10-27 14:38:53 +00:00
if(UI()->MouseButton(0))
{
2009-10-27 14:38:53 +00:00
UI()->SetActiveItem(pID);
OffsetY = UI()->MouseY()-Handle.y;
}
}
2009-10-27 14:38:53 +00:00
if(Inside)
UI()->SetHotItem(pID);
// render
2009-10-27 14:38:53 +00:00
CUIRect Rail;
pRect->VMargin(5.0f, &Rail);
RenderTools()->DrawUIRect(&Rail, vec4(1,1,1,0.25f), 0, 0.0f);
CUIRect Slider = Handle;
Slider.w = Rail.x-Slider.x;
RenderTools()->DrawUIRect(&Slider, vec4(1,1,1,0.25f), CUI::CORNER_L, 2.5f);
Slider.x = Rail.x+Rail.w;
RenderTools()->DrawUIRect(&Slider, vec4(1,1,1,0.25f), CUI::CORNER_R, 2.5f);
Slider = Handle;
Slider.Margin(5.0f, &Slider);
2010-05-29 07:25:38 +00:00
RenderTools()->DrawUIRect(&Slider, vec4(1,1,1,0.25f)*ButtonColorMul(pID), CUI::CORNER_ALL, 2.5f);
2009-10-27 14:38:53 +00:00
return ReturnValue;
}
2010-05-29 07:25:38 +00:00
float CMenus::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current)
{
2009-10-27 14:38:53 +00:00
CUIRect Handle;
static float OffsetX;
pRect->VSplitLeft(33, &Handle, 0);
2009-10-27 14:38:53 +00:00
Handle.x += (pRect->w-Handle.w)*Current;
2010-05-29 07:25:38 +00:00
// logic
2009-10-27 14:38:53 +00:00
float ReturnValue = Current;
int Inside = UI()->MouseInside(&Handle);
2009-10-27 14:38:53 +00:00
if(UI()->ActiveItem() == pID)
{
2009-10-27 14:38:53 +00:00
if(!UI()->MouseButton(0))
UI()->SetActiveItem(0);
2010-05-29 07:25:38 +00:00
float Min = pRect->x;
float Max = pRect->w-Handle.w;
float Cur = UI()->MouseX()-OffsetX;
ReturnValue = (Cur-Min)/Max;
2009-10-27 14:38:53 +00:00
if(ReturnValue < 0.0f) ReturnValue = 0.0f;
if(ReturnValue > 1.0f) ReturnValue = 1.0f;
}
2009-10-27 14:38:53 +00:00
else if(UI()->HotItem() == pID)
{
2009-10-27 14:38:53 +00:00
if(UI()->MouseButton(0))
{
2009-10-27 14:38:53 +00:00
UI()->SetActiveItem(pID);
OffsetX = UI()->MouseX()-Handle.x;
}
}
2009-10-27 14:38:53 +00:00
if(Inside)
UI()->SetHotItem(pID);
// render
2009-10-27 14:38:53 +00:00
CUIRect Rail;
pRect->HMargin(5.0f, &Rail);
RenderTools()->DrawUIRect(&Rail, vec4(1,1,1,0.25f), 0, 0.0f);
CUIRect Slider = Handle;
Slider.h = Rail.y-Slider.y;
RenderTools()->DrawUIRect(&Slider, vec4(1,1,1,0.25f), CUI::CORNER_T, 2.5f);
Slider.y = Rail.y+Rail.h;
RenderTools()->DrawUIRect(&Slider, vec4(1,1,1,0.25f), CUI::CORNER_B, 2.5f);
Slider = Handle;
Slider.Margin(5.0f, &Slider);
2010-05-29 07:25:38 +00:00
RenderTools()->DrawUIRect(&Slider, vec4(1,1,1,0.25f)*ButtonColorMul(pID), CUI::CORNER_ALL, 2.5f);
2009-10-27 14:38:53 +00:00
return ReturnValue;
}
2010-05-29 07:25:38 +00:00
int CMenus::DoKeyReader(void *pID, const CUIRect *pRect, int Key)
{
// process
2009-10-27 14:38:53 +00:00
static void *pGrabbedID = 0;
static bool MouseReleased = true;
int Inside = UI()->MouseInside(pRect);
int NewKey = Key;
2009-10-27 14:38:53 +00:00
if(!UI()->MouseButton(0) && pGrabbedID == pID)
MouseReleased = true;
2009-10-27 14:38:53 +00:00
if(UI()->ActiveItem() == pID)
{
2010-05-29 07:25:38 +00:00
if(m_Binder.m_GotKey)
{
2010-05-29 07:25:38 +00:00
NewKey = m_Binder.m_Key.m_Key;
m_Binder.m_GotKey = false;
2009-10-27 14:38:53 +00:00
UI()->SetActiveItem(0);
MouseReleased = false;
pGrabbedID = pID;
}
}
2009-10-27 14:38:53 +00:00
else if(UI()->HotItem() == pID)
{
2009-10-27 14:38:53 +00:00
if(UI()->MouseButton(0) && MouseReleased)
{
2010-05-29 07:25:38 +00:00
m_Binder.m_TakeKey = true;
m_Binder.m_GotKey = false;
2009-10-27 14:38:53 +00:00
UI()->SetActiveItem(pID);
}
}
2009-10-27 14:38:53 +00:00
if(Inside)
UI()->SetHotItem(pID);
// draw
2009-10-27 14:38:53 +00:00
if (UI()->ActiveItem() == pID)
DoButton_KeySelect(pID, "???", 0, pRect);
else
{
2009-10-27 14:38:53 +00:00
if(Key == 0)
DoButton_KeySelect(pID, "", 0, pRect);
else
2010-05-29 07:25:38 +00:00
DoButton_KeySelect(pID, Input()->KeyName(Key), 0, pRect);
}
2009-10-27 14:38:53 +00:00
return NewKey;
}
2010-05-29 07:25:38 +00:00
int CMenus::RenderMenubar(CUIRect r)
{
2010-05-29 07:25:38 +00:00
CUIRect Box = r;
CUIRect Button;
2010-05-29 07:25:38 +00:00
m_ActivePage = g_Config.m_UiPage;
int NewPage = -1;
2010-05-29 07:25:38 +00:00
if(Client()->State() != IClient::STATE_OFFLINE)
m_ActivePage = m_GamePage;
2010-05-29 07:25:38 +00:00
if(Client()->State() == IClient::STATE_OFFLINE)
{
2010-05-29 07:25:38 +00:00
// offline menus
if(0) // this is not done yet
{
2010-05-29 07:25:38 +00:00
Box.VSplitLeft(90.0f, &Button, &Box);
static int s_NewsButton=0;
if (DoButton_MenuTab(&s_NewsButton, Localize("News"), m_ActivePage==PAGE_NEWS, &Button, 0))
NewPage = PAGE_NEWS;
Box.VSplitLeft(30.0f, 0, &Box);
}
2010-05-29 07:25:38 +00:00
Box.VSplitLeft(100.0f, &Button, &Box);
static int s_InternetButton=0;
if(DoButton_MenuTab(&s_InternetButton, Localize("Internet"), m_ActivePage==PAGE_INTERNET, &Button, CUI::CORNER_TL))
{
2010-05-29 07:25:38 +00:00
ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET);
NewPage = PAGE_INTERNET;
}
2010-05-29 07:25:38 +00:00
//Box.VSplitLeft(4.0f, 0, &Box);
Box.VSplitLeft(80.0f, &Button, &Box);
static int s_LanButton=0;
if(DoButton_MenuTab(&s_LanButton, Localize("LAN"), m_ActivePage==PAGE_LAN, &Button, 0))
{
2010-05-29 07:25:38 +00:00
ServerBrowser()->Refresh(IServerBrowser::TYPE_LAN);
NewPage = PAGE_LAN;
}
2009-10-27 14:38:53 +00:00
//box.VSplitLeft(4.0f, 0, &box);
2010-05-29 07:25:38 +00:00
Box.VSplitLeft(110.0f, &Button, &Box);
static int s_FavoritesButton=0;
if(DoButton_MenuTab(&s_FavoritesButton, Localize("Favorites"), m_ActivePage==PAGE_FAVORITES, &Button, CUI::CORNER_TR))
{
2010-05-29 07:25:38 +00:00
ServerBrowser()->Refresh(IServerBrowser::TYPE_FAVORITES);
NewPage = PAGE_FAVORITES;
}
2010-05-29 07:25:38 +00:00
Box.VSplitLeft(4.0f*5, 0, &Box);
Box.VSplitLeft(100.0f, &Button, &Box);
static int s_DemosButton=0;
if(DoButton_MenuTab(&s_DemosButton, Localize("Demos"), m_ActivePage==PAGE_DEMOS, &Button, CUI::CORNER_T))
{
2010-05-29 07:25:38 +00:00
DemolistPopulate();
NewPage = PAGE_DEMOS;
}
}
else
{
2010-05-29 07:25:38 +00:00
// online menus
Box.VSplitLeft(90.0f, &Button, &Box);
static int s_GameButton=0;
if(DoButton_MenuTab(&s_GameButton, Localize("Game"), m_ActivePage==PAGE_GAME, &Button, CUI::CORNER_T))
NewPage = PAGE_GAME;
Box.VSplitLeft(4.0f, 0, &Box);
Box.VSplitLeft(140.0f, &Button, &Box);
static int s_ServerInfoButton=0;
if(DoButton_MenuTab(&s_ServerInfoButton, Localize("Server info"), m_ActivePage==PAGE_SERVER_INFO, &Button, CUI::CORNER_T))
NewPage = PAGE_SERVER_INFO;
Box.VSplitLeft(4.0f, 0, &Box);
Box.VSplitLeft(140.0f, &Button, &Box);
static int s_CallVoteButton=0;
if(DoButton_MenuTab(&s_CallVoteButton, Localize("Call vote"), m_ActivePage==PAGE_CALLVOTE, &Button, CUI::CORNER_T))
NewPage = PAGE_CALLVOTE;
if(Client()->RconAuthed()) {
Box.VSplitLeft(4.0f, 0, &Box);
Box.VSplitLeft(100.0f, &Button, &Box);
static int s_RCONButton=0;
if(DoButton_MenuTab(&s_RCONButton, Localize("RCON"), m_ActivePage==PAGE_RCON, &Button, CUI::CORNER_T))
NewPage = PAGE_RCON;
Box.VSplitLeft(30.0f, 0, &Box);
}
}
/*
2009-10-27 14:38:53 +00:00
box.VSplitRight(110.0f, &box, &button);
static int system_button=0;
2010-05-29 07:25:38 +00:00
if (UI()->DoButton(&system_button, "System", g_Config.m_UiPage==PAGE_SYSTEM, &button))
g_Config.m_UiPage = PAGE_SYSTEM;
2009-10-27 14:38:53 +00:00
box.VSplitRight(30.0f, &box, 0);
*/
2010-05-29 07:25:38 +00:00
Box.VSplitRight(90.0f, &Box, &Button);
static int s_QuitButton=0;
if(DoButton_MenuTab(&s_QuitButton, Localize("Quit"), 0, &Button, CUI::CORNER_T))
m_Popup = POPUP_QUIT;
Box.VSplitRight(10.0f, &Box, &Button);
Box.VSplitRight(130.0f, &Box, &Button);
static int s_SettingsButton=0;
if(DoButton_MenuTab(&s_SettingsButton, Localize("Settings"), m_ActivePage==PAGE_SETTINGS, &Button, CUI::CORNER_T))
NewPage = PAGE_SETTINGS;
2010-05-29 07:25:38 +00:00
if(NewPage != -1)
{
2010-05-29 07:25:38 +00:00
if(Client()->State() == IClient::STATE_OFFLINE)
g_Config.m_UiPage = NewPage;
else
2010-05-29 07:25:38 +00:00
m_GamePage = NewPage;
}
return 0;
}
2010-05-29 07:25:38 +00:00
void CMenus::RenderLoading(float Percent)
{
2010-05-29 07:25:38 +00:00
static int64 LastLoadRender = 0;
// make sure that we don't render for each little thing we load
// because that will slow down loading if we have vsync
2010-05-29 07:25:38 +00:00
if(time_get()-LastLoadRender < time_freq()/60)
return;
2010-05-29 07:25:38 +00:00
LastLoadRender = time_get();
// need up date this here to get correct
2010-05-29 07:25:38 +00:00
vec3 Rgb = HslToRgb(vec3(g_Config.m_UiColorHue/255.0f, g_Config.m_UiColorSat/255.0f, g_Config.m_UiColorLht/255.0f));
ms_GuiColor = vec4(Rgb.r, Rgb.g, Rgb.b, g_Config.m_UiColorAlpha/255.0f);
2010-05-29 07:25:38 +00:00
CUIRect Screen = *UI()->Screen();
Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);
2010-05-29 07:25:38 +00:00
RenderBackground();
float tw;
float w = 700;
float h = 200;
2010-05-29 07:25:38 +00:00
float x = Screen.w/2-w/2;
float y = Screen.h/2-h/2;
2009-10-27 14:38:53 +00:00
Graphics()->BlendNormal();
2009-10-27 14:38:53 +00:00
Graphics()->TextureSet(-1);
Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,0,0.50f);
2010-05-29 07:25:38 +00:00
RenderTools()->DrawRoundRect(x, y, w, h, 40.0f);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsEnd();
2010-05-29 07:25:38 +00:00
const char *pCaption = Localize("Loading");
2010-05-29 07:25:38 +00:00
tw = TextRender()->TextWidth(0, 48.0f, pCaption, -1);
2009-10-27 14:38:53 +00:00
CUIRect r;
r.x = x;
r.y = y+20;
r.w = w;
r.h = h;
2010-05-29 07:25:38 +00:00
UI()->DoLabel(&r, pCaption, 48.0f, 0, -1);
2009-10-27 14:38:53 +00:00
Graphics()->TextureSet(-1);
Graphics()->QuadsBegin();
Graphics()->SetColor(1,1,1,0.75f);
2010-05-29 07:25:38 +00:00
RenderTools()->DrawRoundRect(x+40, y+h-75, (w-80)*Percent, 25, 5.0f);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsEnd();
2010-05-29 07:25:38 +00:00
Graphics()->Swap();
}
2010-05-29 07:25:38 +00:00
void CMenus::RenderNews(CUIRect MainView)
{
2010-05-29 07:25:38 +00:00
RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f);
}
2010-05-29 07:25:38 +00:00
void CMenus::OnInit()
{
2009-06-13 16:54:04 +00:00
/*
array<string> my_strings;
array<string>::range r2;
my_strings.add("4");
my_strings.add("6");
my_strings.add("1");
my_strings.add("3");
my_strings.add("7");
my_strings.add("5");
my_strings.add("2");
for(array<string>::range r = my_strings.all(); !r.empty(); r.pop_front())
dbg_msg("", "%s", r.front().cstr());
sort(my_strings.all());
dbg_msg("", "after:");
for(array<string>::range r = my_strings.all(); !r.empty(); r.pop_front())
dbg_msg("", "%s", r.front().cstr());
array<int> myarray;
myarray.add(4);
myarray.add(6);
myarray.add(1);
myarray.add(3);
myarray.add(7);
myarray.add(5);
myarray.add(2);
for(array<int>::range r = myarray.all(); !r.empty(); r.pop_front())
dbg_msg("", "%d", r.front());
sort(myarray.all());
sort_verify(myarray.all());
dbg_msg("", "after:");
for(array<int>::range r = myarray.all(); !r.empty(); r.pop_front())
dbg_msg("", "%d", r.front());
exit(-1);
// */
2010-05-29 07:25:38 +00:00
if(g_Config.m_ClShowWelcome)
m_Popup = POPUP_FIRST_LAUNCH;
g_Config.m_ClShowWelcome = 0;
Console()->Chain("add_favorite", ConchainServerbrowserUpdate, this);
}
2010-05-29 07:25:38 +00:00
void CMenus::PopupMessage(const char *pTopic, const char *pBody, const char *pButton)
{
// reset active item
UI()->SetActiveItem(0);
2010-05-29 07:25:38 +00:00
str_copy(m_aMessageTopic, pTopic, sizeof(m_aMessageTopic));
str_copy(m_aMessageBody, pBody, sizeof(m_aMessageBody));
str_copy(m_aMessageButton, pButton, sizeof(m_aMessageButton));
m_Popup = POPUP_MESSAGE;
}
2010-05-29 07:25:38 +00:00
int CMenus::Render()
{
2010-05-29 07:25:38 +00:00
CUIRect Screen = *UI()->Screen();
Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);
2010-05-29 07:25:38 +00:00
static bool s_First = true;
if(s_First)
{
2010-05-29 07:25:38 +00:00
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);
s_First = false;
}
2010-05-29 07:25:38 +00:00
if(Client()->State() == IClient::STATE_ONLINE)
{
2010-05-29 07:25:38 +00:00
ms_ColorTabbarInactive = ms_ColorTabbarInactiveIngame;
ms_ColorTabbarActive = ms_ColorTabbarActiveIngame;
}
else
{
2010-05-29 07:25:38 +00:00
RenderBackground();
ms_ColorTabbarInactive = ms_ColorTabbarInactiveOutgame;
ms_ColorTabbarActive = ms_ColorTabbarActiveOutgame;
}
2010-05-29 07:25:38 +00:00
CUIRect TabBar;
CUIRect MainView;
// some margin around the screen
2010-05-29 07:25:38 +00:00
Screen.Margin(10.0f, &Screen);
2010-05-29 07:25:38 +00:00
if(m_Popup == POPUP_NONE)
{
// do tab bar
2010-05-29 07:25:38 +00:00
Screen.HSplitTop(24.0f, &TabBar, &MainView);
TabBar.VMargin(20.0f, &TabBar);
RenderMenubar(TabBar);
// news is not implemented yet
2010-05-29 07:25:38 +00:00
if(g_Config.m_UiPage <= PAGE_NEWS || g_Config.m_UiPage > PAGE_SETTINGS || (Client()->State() == IClient::STATE_OFFLINE && g_Config.m_UiPage >= PAGE_GAME && g_Config.m_UiPage <= PAGE_CALLVOTE))
{
2010-05-29 07:25:38 +00:00
ServerBrowser()->Refresh(IServerBrowser::TYPE_INTERNET);
g_Config.m_UiPage = PAGE_INTERNET;
}
// render current page
2010-05-29 07:25:38 +00:00
if(Client()->State() != IClient::STATE_OFFLINE)
{
2010-05-29 07:25:38 +00:00
if(m_GamePage == PAGE_GAME)
RenderGame(MainView);
else if(m_GamePage == PAGE_SERVER_INFO)
RenderServerInfo(MainView);
else if(m_GamePage == PAGE_CALLVOTE)
RenderServerControl(MainView);
else if(m_GamePage == PAGE_SETTINGS)
RenderSettings(MainView);
else if(m_GamePage == PAGE_RCON)
RenderRCON(MainView);
}
2010-05-29 07:25:38 +00:00
else if(g_Config.m_UiPage == PAGE_NEWS)
RenderNews(MainView);
else if(g_Config.m_UiPage == PAGE_INTERNET)
RenderServerbrowser(MainView);
else if(g_Config.m_UiPage == PAGE_LAN)
RenderServerbrowser(MainView);
else if(g_Config.m_UiPage == PAGE_DEMOS)
RenderDemoList(MainView);
else if(g_Config.m_UiPage == PAGE_FAVORITES)
RenderServerbrowser(MainView);
else if(g_Config.m_UiPage == PAGE_SETTINGS)
RenderSettings(MainView);
ResetDownloadVars();
}
else
{
// make sure that other windows doesn't do anything funnay!
2009-10-27 14:38:53 +00:00
//UI()->SetHotItem(0);
//UI()->SetActiveItem(0);
char aBuf[512];
char aBuf2[256];
char aBuf3[128];
std::string BufString;
2010-05-29 07:25:38 +00:00
const char *pTitle = "";
const char *pExtraText = "";
const char *pButtonText = "";
const char *pFooterText = "";
2010-05-29 07:25:38 +00:00
int ExtraAlign = 0;
bool FooterTextUse = false;
2010-05-29 07:25:38 +00:00
if(m_Popup == POPUP_MESSAGE)
{
2010-05-29 07:25:38 +00:00
pTitle = m_aMessageTopic;
pExtraText = m_aMessageBody;
pButtonText = m_aMessageButton;
}
2010-05-29 07:25:38 +00:00
else if(m_Popup == POPUP_CONNECTING)
{
2010-05-29 07:25:38 +00:00
pTitle = Localize("Connecting to");
pExtraText = g_Config.m_UiServerAddress; // TODO: query the client about the address
pButtonText = Localize("Abort");
if(Client()->MapDownloadTotalsize() > 0)
{
/*
2010-05-29 07:25:38 +00:00
pTitle = Localize("Downloading map");
str_format(aBuf, sizeof(aBuf), "%d/%d KiB", Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024);
pExtraText = aBuf;
*/
// Ticks
if(m_Download.m_ElapsedTick <= 0)
{
m_Download.m_ElapsedSec++;
m_Download.m_ElapsedTick = 50;
// Calc Speed
m_Download.m_Speed = Client()->MapDownloadAmount()/1024 - m_Download.m_LastSize;
/* download.speed = (float)client_mapdownload_amount()/1024/download.timeneeded; */ // OLD CALC SYS
m_Download.m_LastSize = Client()->MapDownloadAmount()/1024;
}
else if(m_Download.m_ElapsedTick > 0)
m_Download.m_ElapsedTick--;
// Time elapsed
m_Download.m_TimeNeeded = (float)m_Download.m_ElapsedSec + (50-m_Download.m_ElapsedTick)/50.0;
// Calc Time remaining
if(m_Download.m_Speed != 0.0)
m_Download.m_TimeRemaining = ((float)Client()->MapDownloadTotalsize()/1024-Client()->MapDownloadAmount()/1024)/m_Download.m_Speed;
else
m_Download.m_TimeRemaining = 0;
// Check for negativ values, set them to 0
if(m_Download.m_Speed < 0.0)
m_Download.m_Speed = 0;
if(m_Download.m_TimeNeeded < 0.0)
m_Download.m_TimeNeeded = 0;
if(m_Download.m_TimeRemaining < 0.0)
m_Download.m_TimeRemaining = 0;
// Set the texts
str_format(aBuf2, sizeof(aBuf2),"Downloading map '%s'", Client()->MapDownloadName());
char aBufForParam[50];
char aBufForNum[20];
const int end = 32;
if(g_Config.m_ClDownloadExtensionStatusPercent)
{
str_format(aBufForParam, sizeof(aBufForParam), "Status....................");
str_format(aBufForNum, sizeof(aBufForNum), ": %3.2f%%\n", ((float)Client()->MapDownloadAmount()/1024.0*100.0)/((float)Client()->MapDownloadTotalsize()/1024.0));
int lenOfParam = strlen(aBufForNum);
for(int i = end, j = lenOfParam; j >= 0; --j, --i) {
aBufForParam[i] = aBufForNum[j];
}
BufString += aBufForParam;
}
if(g_Config.m_ClDownloadExtensionSize)
{
str_format(aBufForParam, sizeof(aBufForParam), "Size......................");
str_format(aBufForNum, sizeof(aBufForNum), ": %d/%d KiB\n", Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024);
int lenOfParam = strlen(aBufForNum);
for(int i = end, j = lenOfParam; j >= 0; --j, --i) {
aBufForParam[i] = aBufForNum[j];
}
BufString += aBufForParam;
}
if(g_Config.m_ClDownloadExtensionSpeed)
{
str_format(aBufForParam, sizeof(aBufForParam), "Download speed............");
str_format(aBufForNum, sizeof(aBufForNum), ": %3.1f KiB/s\n", m_Download.m_Speed);
int lenOfParam = strlen(aBufForNum);
for(int i = end, j = lenOfParam; j >= 0; --j, --i) {
aBufForParam[i] = aBufForNum[j];
}
BufString += aBufForParam;
}
if(g_Config.m_ClDownloadExtensionTimeElapsed)
{
str_format(aBufForParam, sizeof(aBufForParam), "Time elapsed..............");
str_format(aBufForNum, sizeof(aBufForNum), ": %3.1f sec\n", m_Download.m_TimeNeeded);
int lenOfParam = strlen(aBufForNum);
for(int i = end, j = lenOfParam; j >= 0; --j, --i) {
aBufForParam[i] = aBufForNum[j];
}
BufString += aBufForParam;
}
if(g_Config.m_ClDownloadExtensionTimeRemaining)
{
str_format(aBufForParam, sizeof(aBufForParam), "Time remaining............");
str_format(aBufForNum, sizeof(aBufForNum), ": %3.1f sec", m_Download.m_TimeRemaining);
int lenOfParam = strlen(aBufForNum);
for(int i = end, j = lenOfParam + 1; j >= 0; --j, --i) {
aBufForParam[i] = aBufForNum[j];
}
BufString += aBufForParam;
}
pTitle = aBuf2;
pExtraText = BufString.c_str();
ExtraAlign = 0;
// START - Render Status Bar
if(g_Config.m_ClDownloadExtensionStatusBar)
{
CUIRect Screen = *UI()->Screen();
Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);
float w = 700;
float h = 200;
float x = Screen.w/2-w/2;
float y = Screen.h/2-h/2;
Graphics()->TextureSet(-1);
Graphics()->QuadsBegin();
Graphics()->SetColor(g_Config.m_ClDownloadExtensionStatusBar_r/255.0f, g_Config.m_ClDownloadExtensionStatusBar_g/255.0f, g_Config.m_ClDownloadExtensionStatusBar_b/255.0f, g_Config.m_ClDownloadExtensionStatusBar_a/255.0f);
RenderTools()->DrawRoundRect(x+40, y+h-75+20, (w-80)*(Client()->MapDownloadAmount()/1024*100)/(Client()->MapDownloadTotalsize()/1024)/100, 25, 5.0f);
Graphics()->QuadsEnd();
}
// END - Render Staus Bar
// Mod By KillaBilla
//footer_text = "DownloadExtension Mod\nVersion: 1.3\nMod by KillaBilla";
//footer_text_use = true;
}
}
2010-05-29 07:25:38 +00:00
else if(m_Popup == POPUP_DISCONNECTED)
{
2010-05-29 07:25:38 +00:00
pTitle = Localize("Disconnected");
pExtraText = Client()->ErrorString();
pButtonText = Localize("Ok");
ExtraAlign = -1;
}
2010-05-29 07:25:38 +00:00
else if(m_Popup == POPUP_PURE)
{
2010-05-29 07:25:38 +00:00
pTitle = Localize("Disconnected");
pExtraText = Localize("The server is running a non-standard tuning on a pure game type.");
pButtonText = Localize("Ok");
ExtraAlign = -1;
}
2010-05-29 07:25:38 +00:00
else if(m_Popup == POPUP_PASSWORD)
{
2010-06-02 19:03:15 +00:00
pTitle = Localize("Password incorrect");
2010-05-29 07:25:38 +00:00
pExtraText = Client()->ErrorString();
pButtonText = Localize("Try again");
}
2010-05-29 07:25:38 +00:00
else if(m_Popup == POPUP_QUIT)
{
2010-05-29 07:25:38 +00:00
pTitle = Localize("Quit");
pExtraText = Localize("Are you sure that you want to quit?");
}
2010-05-29 07:25:38 +00:00
else if(m_Popup == POPUP_FIRST_LAUNCH)
{
2010-05-29 07:25:38 +00:00
pTitle = Localize("Welcome to Teeworlds");
pExtraText = Localize("As this is the first time you launch the game, please enter your nick name below. It's recommended that you check the settings to adjust them to your liking before joining a server.");
pButtonText = Localize("Ok");
ExtraAlign = -1;
}
CUIRect Box, Part, Text;
2010-05-29 07:25:38 +00:00
Box = Screen;
Box.VMargin(150.0f, &Box);
Box.HMargin(150.0f, &Box);
// render the box
2010-05-29 07:25:38 +00:00
RenderTools()->DrawUIRect(&Box, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 15.0f);
2010-05-29 07:25:38 +00:00
Box.HSplitTop(20.f, &Part, &Box);
Box.HSplitTop(24.f, &Part, &Box);
UI()->DoLabel(&Part, pTitle, 24.f, 0);
Box.HSplitTop(20.f, &Part, &Box);
Box.HSplitTop(24.f, &Part, &Box);
Part.VMargin(20.f, &Part);
2010-05-29 07:25:38 +00:00
if(ExtraAlign == -1)
UI()->DoLabel(&Part, pExtraText, 20.f, -1, (int)Part.w);
else
2010-05-29 07:25:38 +00:00
UI()->DoLabel(&Part, pExtraText, 20.f, 0, -1);
2010-05-29 07:25:38 +00:00
if(m_Popup == POPUP_QUIT)
{
2010-05-29 07:25:38 +00:00
CUIRect Yes, No;
Box.HSplitBottom(20.f, &Box, &Part);
Box.HSplitBottom(24.f, &Box, &Part);
Part.VMargin(80.0f, &Part);
2010-05-29 07:25:38 +00:00
Part.VSplitMid(&No, &Yes);
2010-05-29 07:25:38 +00:00
Yes.VMargin(20.0f, &Yes);
No.VMargin(20.0f, &No);
2010-05-29 07:25:38 +00:00
static int s_ButtonAbort = 0;
if(DoButton_Menu(&s_ButtonAbort, Localize("No"), 0, &No) || m_EscapePressed)
m_Popup = POPUP_NONE;
2010-05-29 07:25:38 +00:00
static int s_ButtonTryAgain = 0;
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Yes"), 0, &Yes) || m_EnterPressed)
Client()->Quit();
}
2010-05-29 07:25:38 +00:00
else if(m_Popup == POPUP_PASSWORD)
{
2010-05-29 07:25:38 +00:00
CUIRect Label, TextBox, TryAgain, Abort;
2010-05-29 07:25:38 +00:00
Box.HSplitBottom(20.f, &Box, &Part);
Box.HSplitBottom(24.f, &Box, &Part);
Part.VMargin(80.0f, &Part);
2010-05-29 07:25:38 +00:00
Part.VSplitMid(&Abort, &TryAgain);
2010-05-29 07:25:38 +00:00
TryAgain.VMargin(20.0f, &TryAgain);
Abort.VMargin(20.0f, &Abort);
2010-05-29 07:25:38 +00:00
static int s_ButtonAbort = 0;
if(DoButton_Menu(&s_ButtonAbort, Localize("Abort"), 0, &Abort) || m_EscapePressed)
m_Popup = POPUP_NONE;
2010-05-29 07:25:38 +00:00
static int s_ButtonTryAgain = 0;
if(DoButton_Menu(&s_ButtonTryAgain, Localize("Try again"), 0, &TryAgain) || m_EnterPressed)
{
2010-05-29 07:25:38 +00:00
Client()->Connect(g_Config.m_UiServerAddress);
}
2010-05-29 07:25:38 +00:00
Box.HSplitBottom(60.f, &Box, &Part);
Box.HSplitBottom(24.f, &Box, &Part);
2010-05-29 07:25:38 +00:00
Part.VSplitLeft(60.0f, 0, &Label);
Label.VSplitLeft(100.0f, 0, &TextBox);
TextBox.VSplitLeft(20.0f, 0, &TextBox);
TextBox.VSplitRight(60.0f, &TextBox, 0);
UI()->DoLabel(&Label, Localize("Password"), 18.0f, -1);
static float Offset = 0.0f;
DoEditBox(&g_Config.m_Password, &TextBox, g_Config.m_Password, sizeof(g_Config.m_Password), 12.0f, &Offset, true);
}
2010-05-29 07:25:38 +00:00
else if(m_Popup == POPUP_FIRST_LAUNCH)
{
2010-05-29 07:25:38 +00:00
CUIRect Label, TextBox;
2010-05-29 07:25:38 +00:00
Box.HSplitBottom(20.f, &Box, &Part);
Box.HSplitBottom(24.f, &Box, &Part);
Part.VMargin(80.0f, &Part);
2010-05-29 07:25:38 +00:00
static int s_EnterButton = 0;
if(DoButton_Menu(&s_EnterButton, Localize("Enter"), 0, &Part) || m_EnterPressed)
m_Popup = POPUP_NONE;
2010-05-29 07:25:38 +00:00
Box.HSplitBottom(40.f, &Box, &Part);
Box.HSplitBottom(24.f, &Box, &Part);
2010-05-29 07:25:38 +00:00
Part.VSplitLeft(60.0f, 0, &Label);
Label.VSplitLeft(100.0f, 0, &TextBox);
TextBox.VSplitLeft(20.0f, 0, &TextBox);
TextBox.VSplitRight(60.0f, &TextBox, 0);
UI()->DoLabel(&Label, Localize("Nickname"), 18.0f, -1);
static float Offset = 0.0f;
DoEditBox(&g_Config.m_PlayerName, &TextBox, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 12.0f, &Offset);
}
else
{
2010-05-29 07:25:38 +00:00
Box.HSplitBottom(20.f, &Box, &Part);
Box.HSplitBottom(24.f, &Box, &Part);
Part.VMargin(120.0f, &Part);
2010-05-29 07:25:38 +00:00
static int s_Button = 0;
if(DoButton_Menu(&s_Button, pButtonText, 0, &Part) || m_EscapePressed || m_EnterPressed)
{
2010-05-29 07:25:38 +00:00
if(m_Popup == POPUP_CONNECTING)
Client()->Disconnect();
m_Popup = POPUP_NONE;
}
}
}
return 0;
}
2010-05-29 07:25:38 +00:00
void CMenus::SetActive(bool Active)
{
2010-05-29 07:25:38 +00:00
m_MenuActive = Active;
if(!m_MenuActive && m_NeedSendinfo)
{
2010-05-29 07:25:38 +00:00
m_pClient->SendInfo(false);
m_NeedSendinfo = false;
}
}
2010-05-29 07:25:38 +00:00
void CMenus::OnReset()
{
}
2010-05-29 07:25:38 +00:00
bool CMenus::OnMouseMove(float x, float y)
{
2010-05-29 07:25:38 +00:00
m_LastInput = time_get();
2008-09-12 07:20:26 +00:00
2010-05-29 07:25:38 +00:00
if(!m_MenuActive)
return false;
2010-05-29 07:25:38 +00:00
m_MousePos.x += x;
m_MousePos.y += y;
if(m_MousePos.x < 0) m_MousePos.x = 0;
if(m_MousePos.y < 0) m_MousePos.y = 0;
if(m_MousePos.x > Graphics()->ScreenWidth()) m_MousePos.x = Graphics()->ScreenWidth();
if(m_MousePos.y > Graphics()->ScreenHeight()) m_MousePos.y = Graphics()->ScreenHeight();
return true;
}
2010-05-29 07:25:38 +00:00
bool CMenus::OnInput(IInput::CEvent e)
{
2010-05-29 07:25:38 +00:00
m_LastInput = time_get();
2008-09-12 07:20:26 +00:00
2008-10-21 18:25:28 +00:00
// special handle esc and enter for popup purposes
2010-05-29 07:25:38 +00:00
if(e.m_Flags&IInput::FLAG_PRESS)
2008-08-27 20:23:50 +00:00
{
2010-05-29 07:25:38 +00:00
if(e.m_Key == KEY_ESCAPE)
{
2010-05-29 07:25:38 +00:00
m_EscapePressed = true;
SetActive(!IsActive());
2008-10-21 18:25:28 +00:00
return true;
}
2008-10-21 18:25:28 +00:00
}
2010-05-29 07:25:38 +00:00
if(IsActive())
2008-10-21 18:25:28 +00:00
{
// special for popups
2010-05-29 07:25:38 +00:00
if(e.m_Flags&IInput::FLAG_PRESS && e.m_Key == KEY_RETURN)
m_EnterPressed = true;
2010-05-29 07:25:38 +00:00
if(m_NumInputEvents < MAX_INPUTEVENTS)
m_aInputEvents[m_NumInputEvents++] = e;
2008-08-27 20:23:50 +00:00
return true;
}
return false;
}
2010-05-29 07:25:38 +00:00
void CMenus::OnStateChange(int NewState, int OldState)
{
2010-05-29 07:25:38 +00:00
// reset active item
UI()->SetActiveItem(0);
if(NewState == IClient::STATE_OFFLINE)
{
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_NONE;
if(Client()->ErrorString() && Client()->ErrorString()[0] != 0)
{
2010-05-29 07:25:38 +00:00
if(str_find(Client()->ErrorString(), "password"))
{
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_PASSWORD;
UI()->SetHotItem(&g_Config.m_Password);
UI()->SetActiveItem(&g_Config.m_Password);
}
else
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_DISCONNECTED;
}
}
else if(NewState == IClient::STATE_LOADING)
{
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_CONNECTING;
//client_serverinfo_request();
}
2010-05-29 07:25:38 +00:00
else if(NewState == IClient::STATE_CONNECTING)
m_Popup = POPUP_CONNECTING;
else if (NewState == IClient::STATE_ONLINE || NewState == IClient::STATE_DEMOPLAYBACK)
{
2010-05-29 07:25:38 +00:00
m_Popup = POPUP_NONE;
SetActive(false);
}
}
extern "C" void font_debug_render();
2010-05-29 07:25:38 +00:00
void CMenus::OnRender()
{
2009-06-07 16:06:03 +00:00
/*
// text rendering test stuff
render_background();
2010-05-29 07:25:38 +00:00
CTextCursor cursor;
TextRender()->SetCursor(&cursor, 10, 10, 20, TEXTFLAG_RENDER);
TextRender()->TextEx(&cursor, "ようこそ - ガイド", -1);
2009-06-07 16:06:03 +00:00
2010-05-29 07:25:38 +00:00
TextRender()->SetCursor(&cursor, 10, 30, 15, TEXTFLAG_RENDER);
TextRender()->TextEx(&cursor, "ようこそ - ガイド", -1);
2009-06-07 16:06:03 +00:00
2009-10-27 14:38:53 +00:00
//Graphics()->TextureSet(-1);
Graphics()->QuadsBegin();
Graphics()->QuadsDrawTL(60, 60, 5000, 5000);
Graphics()->QuadsEnd();
2009-06-07 16:06:03 +00:00
return;*/
2010-05-29 07:25:38 +00:00
if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
SetActive(true);
2010-05-29 07:25:38 +00:00
if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
{
2010-05-29 07:25:38 +00:00
CUIRect Screen = *UI()->Screen();
Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);
RenderDemoPlayer(Screen);
}
2008-08-27 20:23:50 +00:00
2010-05-29 07:25:38 +00:00
if(Client()->State() == IClient::STATE_ONLINE && m_pClient->m_ServerMode == m_pClient->SERVERMODE_PUREMOD)
{
2010-05-29 07:25:38 +00:00
Client()->Disconnect();
SetActive(true);
m_Popup = POPUP_PURE;
}
2010-05-29 07:25:38 +00:00
if(!IsActive())
{
2010-05-29 07:25:38 +00:00
m_EscapePressed = false;
m_EnterPressed = false;
m_NumInputEvents = 0;
return;
}
// update colors
2010-05-29 07:25:38 +00:00
vec3 Rgb = HslToRgb(vec3(g_Config.m_UiColorHue/255.0f, g_Config.m_UiColorSat/255.0f, g_Config.m_UiColorLht/255.0f));
ms_GuiColor = vec4(Rgb.r, Rgb.g, Rgb.b, g_Config.m_UiColorAlpha/255.0f);
ms_ColorTabbarInactiveOutgame = vec4(0,0,0,0.25f);
ms_ColorTabbarActiveOutgame = vec4(0,0,0,0.5f);
float ColorIngameScaleI = 0.5f;
float ColorIngameAcaleA = 0.2f;
ms_ColorTabbarInactiveIngame = vec4(
ms_GuiColor.r*ColorIngameScaleI,
ms_GuiColor.g*ColorIngameScaleI,
ms_GuiColor.b*ColorIngameScaleI,
ms_GuiColor.a*0.8f);
2010-05-29 07:25:38 +00:00
ms_ColorTabbarActiveIngame = vec4(
ms_GuiColor.r*ColorIngameAcaleA,
ms_GuiColor.g*ColorIngameAcaleA,
ms_GuiColor.b*ColorIngameAcaleA,
ms_GuiColor.a);
// update the ui
2010-05-29 07:25:38 +00:00
CUIRect *pScreen = UI()->Screen();
float mx = (m_MousePos.x/(float)Graphics()->ScreenWidth())*pScreen->w;
float my = (m_MousePos.y/(float)Graphics()->ScreenHeight())*pScreen->h;
2010-05-29 07:25:38 +00:00
int Buttons = 0;
if(m_UseMouseButtons)
{
if(Input()->KeyPressed(KEY_MOUSE_1)) Buttons |= 1;
if(Input()->KeyPressed(KEY_MOUSE_2)) Buttons |= 2;
if(Input()->KeyPressed(KEY_MOUSE_3)) Buttons |= 4;
}
2010-05-29 07:25:38 +00:00
UI()->Update(mx,my,mx*3.0f,my*3.0f,Buttons);
2009-01-10 11:16:21 +00:00
// render
2010-05-29 07:25:38 +00:00
if(Client()->State() != IClient::STATE_DEMOPLAYBACK)
Render();
2009-01-10 11:16:21 +00:00
// render cursor
2010-05-29 07:25:38 +00:00
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_CURSOR].m_Id);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsBegin();
Graphics()->SetColor(1,1,1,1);
2010-05-29 07:25:38 +00:00
IGraphics::CQuadItem QuadItem(mx, my, 24, 24);
Graphics()->QuadsDrawTL(&QuadItem, 1);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsEnd();
2009-01-10 11:16:21 +00:00
// render debug information
2010-05-29 07:25:38 +00:00
if(g_Config.m_Debug)
{
2010-05-29 07:25:38 +00:00
CUIRect Screen = *UI()->Screen();
Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);
char aBuf[512];
str_format(aBuf, sizeof(aBuf), "%p %p %p", UI()->HotItem(), UI()->ActiveItem(), UI()->LastActiveItem());
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, 10, 10, 10, TEXTFLAG_RENDER);
TextRender()->TextEx(&Cursor, aBuf, -1);
}
2010-05-29 07:25:38 +00:00
m_EscapePressed = false;
m_EnterPressed = false;
m_NumInputEvents = 0;
}
2008-09-11 22:45:28 +00:00
2010-05-29 07:25:38 +00:00
static int gs_TextureBlob = -1;
2010-05-29 07:25:38 +00:00
void CMenus::RenderBackground()
2008-09-11 22:45:28 +00:00
{
2009-10-27 14:38:53 +00:00
//Graphics()->Clear(1,1,1);
//render_sunrays(0,0);
2010-05-29 07:25:38 +00:00
if(gs_TextureBlob == -1)
gs_TextureBlob = Graphics()->LoadTexture("blob.png", CImageInfo::FORMAT_AUTO, 0);
2009-10-27 14:38:53 +00:00
float sw = 300*Graphics()->ScreenAspect();
float sh = 300;
2009-10-27 14:38:53 +00:00
Graphics()->MapScreen(0, 0, sw, sh);
// render background color
2009-10-27 14:38:53 +00:00
Graphics()->TextureSet(-1);
Graphics()->QuadsBegin();
//vec4 bottom(gui_color.r*0.3f, gui_color.g*0.3f, gui_color.b*0.3f, 1.0f);
//vec4 bottom(0, 0, 0, 1.0f);
2010-05-29 07:25:38 +00:00
vec4 Bottom(ms_GuiColor.r, ms_GuiColor.g, ms_GuiColor.b, 1.0f);
vec4 Top(ms_GuiColor.r, ms_GuiColor.g, ms_GuiColor.b, 1.0f);
IGraphics::CColorVertex Array[4] = {
IGraphics::CColorVertex(0, Top.r, Top.g, Top.b, Top.a),
IGraphics::CColorVertex(1, Top.r, Top.g, Top.b, Top.a),
IGraphics::CColorVertex(2, Bottom.r, Bottom.g, Bottom.b, Bottom.a),
IGraphics::CColorVertex(3, Bottom.r, Bottom.g, Bottom.b, Bottom.a)};
Graphics()->SetColorVertex(Array, 4);
IGraphics::CQuadItem QuadItem(0, 0, sw, sh);
Graphics()->QuadsDrawTL(&QuadItem, 1);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsEnd();
// render the tiles
2009-10-27 14:38:53 +00:00
Graphics()->TextureSet(-1);
Graphics()->QuadsBegin();
2010-05-29 07:25:38 +00:00
float Size = 15.0f;
float OffsetTime = fmod(Client()->LocalTime()*0.15f, 2.0f);
for(int y = -2; y < (int)(sw/Size); y++)
for(int x = -2; x < (int)(sh/Size); x++)
{
2009-10-27 14:38:53 +00:00
Graphics()->SetColor(0,0,0,0.045f);
2010-05-29 07:25:38 +00:00
IGraphics::CQuadItem QuadItem((x-OffsetTime)*Size*2+(y&1)*Size, (y+OffsetTime)*Size, Size, Size);
Graphics()->QuadsDrawTL(&QuadItem, 1);
}
2009-10-27 14:38:53 +00:00
Graphics()->QuadsEnd();
// render border fade
2010-05-29 07:25:38 +00:00
Graphics()->TextureSet(gs_TextureBlob);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,0,0.5f);
2010-05-29 07:25:38 +00:00
QuadItem = IGraphics::CQuadItem(-100, -100, sw+200, sh+200);
Graphics()->QuadsDrawTL(&QuadItem, 1);
2009-10-27 14:38:53 +00:00
Graphics()->QuadsEnd();
// restore screen
2010-05-29 07:25:38 +00:00
{CUIRect Screen = *UI()->Screen();
Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);}
2008-09-11 22:45:28 +00:00
}