clang-format

This commit is contained in:
TsFreddie 2020-09-22 17:02:03 +01:00
parent 387bc53030
commit d4da82f977
7 changed files with 531 additions and 517 deletions

View file

@ -3,10 +3,10 @@
#include "SDL.h" #include "SDL.h"
#include <base/system.h> #include <base/system.h>
#include <engine/shared/config.h>
#include <engine/graphics.h> #include <engine/graphics.h>
#include <engine/input.h> #include <engine/input.h>
#include <engine/keys.h> #include <engine/keys.h>
#include <engine/shared/config.h>
#include "input.h" #include "input.h"
@ -71,10 +71,10 @@ void CInput::MouseRelative(float *x, float *y)
int nx = 0, ny = 0; int nx = 0, ny = 0;
float Sens = g_Config.m_InpMousesens / 100.0f; float Sens = g_Config.m_InpMousesens / 100.0f;
SDL_GetRelativeMouseState(&nx,&ny); SDL_GetRelativeMouseState(&nx, &ny);
*x = nx*Sens; *x = nx * Sens;
*y = ny*Sens; *y = ny * Sens;
} }
void CInput::MouseModeAbsolute() void CInput::MouseModeAbsolute()
@ -102,7 +102,7 @@ int CInput::MouseDoubleClick()
return 0; return 0;
} }
const char* CInput::GetClipboardText() const char *CInput::GetClipboardText()
{ {
if(m_pClipboardText) if(m_pClipboardText)
{ {
@ -136,7 +136,7 @@ void CInput::NextFrame()
int i; int i;
const Uint8 *pState = SDL_GetKeyboardState(&i); const Uint8 *pState = SDL_GetKeyboardState(&i);
if(i >= KEY_LAST) if(i >= KEY_LAST)
i = KEY_LAST-1; i = KEY_LAST - 1;
mem_copy(m_aInputState, pState, i); mem_copy(m_aInputState, pState, i);
if(m_EditingTextLen == 0) if(m_EditingTextLen == 0)
m_EditingTextLen = -1; m_EditingTextLen = -1;
@ -165,7 +165,7 @@ void CInput::SetIMEState(bool Activate)
} }
} }
const char* CInput::GetIMECandidate() const char *CInput::GetIMECandidate()
{ {
if(m_EditingTextLen > 0) if(m_EditingTextLen > 0)
return m_aEditingText; return m_aEditingText;
@ -185,7 +185,7 @@ void CInput::SetEditingPosition(float X, float Y)
int ScreenHeight = Graphics()->ScreenHeight(); int ScreenHeight = Graphics()->ScreenHeight();
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1); Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
vec2 ScreenScale = vec2(ScreenWidth/(ScreenX1-ScreenX0), ScreenHeight/(ScreenY1-ScreenY0)); vec2 ScreenScale = vec2(ScreenWidth / (ScreenX1 - ScreenX0), ScreenHeight / (ScreenY1 - ScreenY0));
SDL_Rect ImeWindowRect; SDL_Rect ImeWindowRect;
ImeWindowRect.x = X * ScreenScale.x; ImeWindowRect.x = X * ScreenScale.x;
@ -199,19 +199,28 @@ void CInput::SetEditingPosition(float X, float Y)
int CInput::Update() int CInput::Update()
{ {
// keep the counter between 1..0xFFFF, 0 means not pressed // keep the counter between 1..0xFFFF, 0 means not pressed
m_InputCounter = (m_InputCounter%0xFFFF)+1; m_InputCounter = (m_InputCounter % 0xFFFF) + 1;
// these states must always be updated manually because they are not in the GetKeyState from SDL // these states must always be updated manually because they are not in the GetKeyState from SDL
int i = SDL_GetMouseState(NULL, NULL); int i = SDL_GetMouseState(NULL, NULL);
if(i&SDL_BUTTON(1)) m_aInputState[KEY_MOUSE_1] = 1; // 1 is left if(i & SDL_BUTTON(1))
if(i&SDL_BUTTON(3)) m_aInputState[KEY_MOUSE_2] = 1; // 3 is right m_aInputState[KEY_MOUSE_1] = 1; // 1 is left
if(i&SDL_BUTTON(2)) m_aInputState[KEY_MOUSE_3] = 1; // 2 is middle if(i & SDL_BUTTON(3))
if(i&SDL_BUTTON(4)) m_aInputState[KEY_MOUSE_4] = 1; m_aInputState[KEY_MOUSE_2] = 1; // 3 is right
if(i&SDL_BUTTON(5)) m_aInputState[KEY_MOUSE_5] = 1; if(i & SDL_BUTTON(2))
if(i&SDL_BUTTON(6)) m_aInputState[KEY_MOUSE_6] = 1; m_aInputState[KEY_MOUSE_3] = 1; // 2 is middle
if(i&SDL_BUTTON(7)) m_aInputState[KEY_MOUSE_7] = 1; if(i & SDL_BUTTON(4))
if(i&SDL_BUTTON(8)) m_aInputState[KEY_MOUSE_8] = 1; m_aInputState[KEY_MOUSE_4] = 1;
if(i&SDL_BUTTON(9)) m_aInputState[KEY_MOUSE_9] = 1; if(i & SDL_BUTTON(5))
m_aInputState[KEY_MOUSE_5] = 1;
if(i & SDL_BUTTON(6))
m_aInputState[KEY_MOUSE_6] = 1;
if(i & SDL_BUTTON(7))
m_aInputState[KEY_MOUSE_7] = 1;
if(i & SDL_BUTTON(8))
m_aInputState[KEY_MOUSE_8] = 1;
if(i & SDL_BUTTON(9))
m_aInputState[KEY_MOUSE_9] = 1;
{ {
SDL_Event Event; SDL_Event Event;
@ -223,132 +232,144 @@ int CInput::Update()
int Action = IInput::FLAG_PRESS; int Action = IInput::FLAG_PRESS;
switch(Event.type) switch(Event.type)
{ {
case SDL_TEXTEDITING: case SDL_TEXTEDITING:
{
m_EditingTextLen = str_length(Event.edit.text);
if(m_EditingTextLen)
{ {
m_EditingTextLen = str_length(Event.edit.text); str_copy(m_aEditingText, Event.edit.text, sizeof(m_aEditingText));
if(m_EditingTextLen) m_EditingCursor = 0;
{ for(int i = 0; i < Event.edit.start; i++)
str_copy(m_aEditingText, Event.edit.text, sizeof(m_aEditingText)); m_EditingCursor = str_utf8_forward(m_aEditingText, m_EditingCursor);
m_EditingCursor = 0;
for (int i = 0; i < Event.edit.start; i++)
m_EditingCursor = str_utf8_forward(m_aEditingText, m_EditingCursor);
}
break;
} }
case SDL_TEXTINPUT: break;
AddEvent(Event.text.text, 0, IInput::FLAG_TEXT); }
break; case SDL_TEXTINPUT:
// handle keys AddEvent(Event.text.text, 0, IInput::FLAG_TEXT);
case SDL_KEYDOWN: break;
// See SDL_Keymod for possible modifiers: // handle keys
// NONE = 0 case SDL_KEYDOWN:
// LSHIFT = 1 // See SDL_Keymod for possible modifiers:
// RSHIFT = 2 // NONE = 0
// LCTRL = 64 // LSHIFT = 1
// RCTRL = 128 // RSHIFT = 2
// LALT = 256 // LCTRL = 64
// RALT = 512 // RCTRL = 128
// LGUI = 1024 // LALT = 256
// RGUI = 2048 // RALT = 512
// NUM = 4096 // LGUI = 1024
// CAPS = 8192 // RGUI = 2048
// MODE = 16384 // NUM = 4096
// Sum if you want to ignore multiple modifiers. // CAPS = 8192
if(!(Event.key.keysym.mod & g_Config.m_InpIgnoredModifiers)) // MODE = 16384
{ // Sum if you want to ignore multiple modifiers.
Key = Event.key.keysym.sym; if(!(Event.key.keysym.mod & g_Config.m_InpIgnoredModifiers))
Scancode = Event.key.keysym.scancode; {
}
break;
case SDL_KEYUP:
Action = IInput::FLAG_RELEASE;
Key = Event.key.keysym.sym; Key = Event.key.keysym.sym;
Scancode = Event.key.keysym.scancode; Scancode = Event.key.keysym.scancode;
break; }
break;
case SDL_KEYUP:
Action = IInput::FLAG_RELEASE;
Key = Event.key.keysym.sym;
Scancode = Event.key.keysym.scancode;
break;
// handle mouse buttons // handle mouse buttons
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
Action = IInput::FLAG_RELEASE; Action = IInput::FLAG_RELEASE;
if(Event.button.button == 1) // ignore_convention if(Event.button.button == 1) // ignore_convention
{ {
m_ReleaseDelta = time_get() - m_LastRelease; m_ReleaseDelta = time_get() - m_LastRelease;
m_LastRelease = time_get(); m_LastRelease = time_get();
} }
// fall through // fall through
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
if(Event.button.button == SDL_BUTTON_LEFT) Key = KEY_MOUSE_1; // ignore_convention if(Event.button.button == SDL_BUTTON_LEFT)
if(Event.button.button == SDL_BUTTON_RIGHT) Key = KEY_MOUSE_2; // ignore_convention Key = KEY_MOUSE_1; // ignore_convention
if(Event.button.button == SDL_BUTTON_MIDDLE) Key = KEY_MOUSE_3; // ignore_convention if(Event.button.button == SDL_BUTTON_RIGHT)
if(Event.button.button == SDL_BUTTON_X1) Key = KEY_MOUSE_4; // ignore_convention Key = KEY_MOUSE_2; // ignore_convention
if(Event.button.button == SDL_BUTTON_X2) Key = KEY_MOUSE_5; // ignore_convention if(Event.button.button == SDL_BUTTON_MIDDLE)
if(Event.button.button == 6) Key = KEY_MOUSE_6; // ignore_convention Key = KEY_MOUSE_3; // ignore_convention
if(Event.button.button == 7) Key = KEY_MOUSE_7; // ignore_convention if(Event.button.button == SDL_BUTTON_X1)
if(Event.button.button == 8) Key = KEY_MOUSE_8; // ignore_convention Key = KEY_MOUSE_4; // ignore_convention
if(Event.button.button == 9) Key = KEY_MOUSE_9; // ignore_convention if(Event.button.button == SDL_BUTTON_X2)
Scancode = Key; Key = KEY_MOUSE_5; // ignore_convention
break; if(Event.button.button == 6)
Key = KEY_MOUSE_6; // ignore_convention
if(Event.button.button == 7)
Key = KEY_MOUSE_7; // ignore_convention
if(Event.button.button == 8)
Key = KEY_MOUSE_8; // ignore_convention
if(Event.button.button == 9)
Key = KEY_MOUSE_9; // ignore_convention
Scancode = Key;
break;
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
if(Event.wheel.y > 0) Key = KEY_MOUSE_WHEEL_UP; // ignore_convention if(Event.wheel.y > 0)
if(Event.wheel.y < 0) Key = KEY_MOUSE_WHEEL_DOWN; // ignore_convention Key = KEY_MOUSE_WHEEL_UP; // ignore_convention
if(Event.wheel.x > 0) Key = KEY_MOUSE_WHEEL_LEFT; // ignore_convention if(Event.wheel.y < 0)
if(Event.wheel.x < 0) Key = KEY_MOUSE_WHEEL_RIGHT; // ignore_convention Key = KEY_MOUSE_WHEEL_DOWN; // ignore_convention
Action |= IInput::FLAG_RELEASE; if(Event.wheel.x > 0)
Scancode = Key; Key = KEY_MOUSE_WHEEL_LEFT; // ignore_convention
break; if(Event.wheel.x < 0)
Key = KEY_MOUSE_WHEEL_RIGHT; // ignore_convention
Action |= IInput::FLAG_RELEASE;
Scancode = Key;
break;
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
// Ignore keys following a focus gain as they may be part of global // Ignore keys following a focus gain as they may be part of global
// shortcuts // shortcuts
switch (Event.window.event) switch(Event.window.event)
{ {
case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_RESIZED:
#if defined(SDL_VIDEO_DRIVER_X11) #if defined(SDL_VIDEO_DRIVER_X11)
Graphics()->Resize(Event.window.data1, Event.window.data2); Graphics()->Resize(Event.window.data1, Event.window.data2);
#endif
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
if(m_InputGrabbed)
MouseModeRelative();
m_MouseFocus = true;
IgnoreKeys = true;
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
m_MouseFocus = false;
IgnoreKeys = true;
if(m_InputGrabbed)
{
MouseModeAbsolute();
// Remember that we had relative mouse
m_InputGrabbed = true;
}
break;
#if defined(CONF_PLATFORM_MACOSX) // Todo: remove this when fixed in SDL
case SDL_WINDOWEVENT_MAXIMIZED:
MouseModeAbsolute();
MouseModeRelative();
break;
#endif #endif
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
if(m_InputGrabbed)
MouseModeRelative();
m_MouseFocus = true;
IgnoreKeys = true;
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
m_MouseFocus = false;
IgnoreKeys = true;
if(m_InputGrabbed)
{
MouseModeAbsolute();
// Remember that we had relative mouse
m_InputGrabbed = true;
} }
break; break;
#if defined(CONF_PLATFORM_MACOSX) // Todo: remove this when fixed in SDL
case SDL_WINDOWEVENT_MAXIMIZED:
MouseModeAbsolute();
MouseModeRelative();
break;
#endif
}
break;
// other messages // other messages
case SDL_QUIT: case SDL_QUIT:
return 1; return 1;
} }
if(Scancode > KEY_FIRST && Scancode < g_MaxKeys && !IgnoreKeys && (!SDL_IsTextInputActive() || m_EditingTextLen == -1)) if(Scancode > KEY_FIRST && Scancode < g_MaxKeys && !IgnoreKeys && (!SDL_IsTextInputActive() || m_EditingTextLen == -1))
{ {
if(Action&IInput::FLAG_PRESS) if(Action & IInput::FLAG_PRESS)
{ {
m_aInputState[Scancode] = 1; m_aInputState[Scancode] = 1;
m_aInputCount[Scancode] = m_InputCounter; m_aInputCount[Scancode] = m_InputCounter;
} }
AddEvent(0, Scancode, Action); AddEvent(0, Scancode, Action);
} }
} }
} }
@ -357,7 +378,7 @@ int CInput::Update()
int CInput::VideoRestartNeeded() int CInput::VideoRestartNeeded()
{ {
if( m_VideoRestartNeeded ) if(m_VideoRestartNeeded)
{ {
m_VideoRestartNeeded = 0; m_VideoRestartNeeded = 0;
return 1; return 1;
@ -365,4 +386,7 @@ int CInput::VideoRestartNeeded()
return 0; return 0;
} }
IEngineInput *CreateEngineInput() { return new CInput; } IEngineInput *CreateEngineInput()
{
return new CInput;
}

View file

@ -21,8 +21,8 @@ class CInput : public IEngineInput
bool IsEventValid(CEvent *pEvent) const { return pEvent->m_InputCount == m_InputCounter; }; bool IsEventValid(CEvent *pEvent) const { return pEvent->m_InputCount == m_InputCounter; };
// quick access to input // quick access to input
unsigned short m_aInputCount[g_MaxKeys]; // tw-KEY unsigned short m_aInputCount[g_MaxKeys]; // tw-KEY
unsigned char m_aInputState[g_MaxKeys]; // SDL_SCANCODE unsigned char m_aInputState[g_MaxKeys]; // SDL_SCANCODE
int m_InputCounter; int m_InputCounter;
// IME support // IME support
@ -47,7 +47,7 @@ public:
virtual void MouseModeAbsolute(); virtual void MouseModeAbsolute();
virtual void MouseModeRelative(); virtual void MouseModeRelative();
virtual int MouseDoubleClick(); virtual int MouseDoubleClick();
virtual const char* GetClipboardText(); virtual const char *GetClipboardText();
virtual void SetClipboardText(const char *Text); virtual void SetClipboardText(const char *Text);
virtual int Update(); virtual int Update();
@ -57,7 +57,7 @@ public:
virtual bool GetIMEState(); virtual bool GetIMEState();
virtual void SetIMEState(bool Activate); virtual void SetIMEState(bool Activate);
virtual const char* GetIMECandidate(); virtual const char *GetIMECandidate();
virtual int GetEditingCursor(); virtual int GetEditingCursor();
virtual void SetEditingPosition(float X, float Y); virtual void SetEditingPosition(float X, float Y);
}; };

View file

@ -24,7 +24,7 @@ public:
protected: protected:
enum enum
{ {
INPUT_BUFFER_SIZE=32 INPUT_BUFFER_SIZE = 32
}; };
// quick access to events // quick access to events
@ -34,10 +34,10 @@ protected:
public: public:
enum enum
{ {
FLAG_PRESS=1, FLAG_PRESS = 1,
FLAG_RELEASE=2, FLAG_RELEASE = 2,
FLAG_REPEAT=4, FLAG_REPEAT = 4,
FLAG_TEXT=8, FLAG_TEXT = 8,
}; };
// events // events
@ -47,7 +47,7 @@ public:
{ {
if(Index < 0 || Index >= m_NumEvents) if(Index < 0 || Index >= m_NumEvents)
{ {
IInput::CEvent e = {0,0}; IInput::CEvent e = {0, 0};
return e; return e;
} }
return m_aInputEvents[Index]; return m_aInputEvents[Index];
@ -55,7 +55,7 @@ public:
// keys // keys
virtual bool KeyIsPressed(int Key) const = 0; virtual bool KeyIsPressed(int Key) const = 0;
virtual bool KeyPress(int Key, bool CheckCounter=false) const = 0; virtual bool KeyPress(int Key, bool CheckCounter = false) const = 0;
const char *KeyName(int Key) const { return (Key >= 0 && Key < g_MaxKeys) ? g_aaKeyStrings[Key] : g_aaKeyStrings[0]; } const char *KeyName(int Key) const { return (Key >= 0 && Key < g_MaxKeys) ? g_aaKeyStrings[Key] : g_aaKeyStrings[0]; }
virtual void Clear() = 0; virtual void Clear() = 0;
@ -63,19 +63,18 @@ public:
virtual void MouseModeRelative() = 0; virtual void MouseModeRelative() = 0;
virtual void MouseModeAbsolute() = 0; virtual void MouseModeAbsolute() = 0;
virtual int MouseDoubleClick() = 0; virtual int MouseDoubleClick() = 0;
virtual const char* GetClipboardText() = 0; virtual const char *GetClipboardText() = 0;
virtual void SetClipboardText(const char *Text) = 0; virtual void SetClipboardText(const char *Text) = 0;
virtual void MouseRelative(float *x, float *y) = 0; virtual void MouseRelative(float *x, float *y) = 0;
virtual bool GetIMEState() = 0; virtual bool GetIMEState() = 0;
virtual void SetIMEState(bool Activate) = 0; virtual void SetIMEState(bool Activate) = 0;
virtual const char* GetIMECandidate() = 0; virtual const char *GetIMECandidate() = 0;
virtual int GetEditingCursor() = 0; virtual int GetEditingCursor() = 0;
virtual void SetEditingPosition(float X, float Y) = 0; virtual void SetEditingPosition(float X, float Y) = 0;
}; };
class IEngineInput : public IInput class IEngineInput : public IInput
{ {
MACRO_INTERFACE("engineinput", 0) MACRO_INTERFACE("engineinput", 0)

View file

@ -6,13 +6,13 @@
#include <engine/editor.h> #include <engine/editor.h>
#include <engine/engine.h> #include <engine/engine.h>
#include <engine/graphics.h> #include <engine/graphics.h>
#include <engine/textrender.h>
#include <engine/keys.h> #include <engine/keys.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <engine/shared/csv.h> #include <engine/shared/csv.h>
#include <engine/textrender.h>
#include <game/generated/protocol.h>
#include <game/generated/client_data.h> #include <game/generated/client_data.h>
#include <game/generated/protocol.h>
#include <game/client/gameclient.h> #include <game/client/gameclient.h>
@ -23,7 +23,6 @@
#include "chat.h" #include "chat.h"
CChat::CChat() CChat::CChat()
{ {
for(int i = 0; i < MAX_LINES; i++) for(int i = 0; i < MAX_LINES; i++)
@ -32,8 +31,8 @@ CChat::CChat()
m_aLines[i].m_TextContainerIndex = -1; m_aLines[i].m_TextContainerIndex = -1;
} }
#define CHAT_COMMAND(name, params, flags, callback, userdata, help) RegisterCommand(name, params, flags, help); #define CHAT_COMMAND(name, params, flags, callback, userdata, help) RegisterCommand(name, params, flags, help);
#include <game/server/ddracechat.h> #include <game/server/ddracechat.h>
m_Commands.sort_range(); m_Commands.sort_range();
m_Mode = MODE_NONE; m_Mode = MODE_NONE;
@ -84,7 +83,6 @@ void CChat::Reset()
m_CurrentLine = 0; m_CurrentLine = 0;
DisableMode(); DisableMode();
for(int i = 0; i < CHAT_NUM; ++i) for(int i = 0; i < CHAT_NUM; ++i)
m_aLastSoundPlayed[i] = 0; m_aLastSoundPlayed[i] = 0;
} }
@ -105,26 +103,26 @@ void CChat::OnStateChange(int NewState, int OldState)
void CChat::ConSay(IConsole::IResult *pResult, void *pUserData) void CChat::ConSay(IConsole::IResult *pResult, void *pUserData)
{ {
((CChat*)pUserData)->Say(0, pResult->GetString(0)); ((CChat *)pUserData)->Say(0, pResult->GetString(0));
} }
void CChat::ConSayTeam(IConsole::IResult *pResult, void *pUserData) void CChat::ConSayTeam(IConsole::IResult *pResult, void *pUserData)
{ {
((CChat*)pUserData)->Say(1, pResult->GetString(0)); ((CChat *)pUserData)->Say(1, pResult->GetString(0));
} }
void CChat::ConChat(IConsole::IResult *pResult, void *pUserData) void CChat::ConChat(IConsole::IResult *pResult, void *pUserData)
{ {
const char *pMode = pResult->GetString(0); const char *pMode = pResult->GetString(0);
if(str_comp(pMode, "all") == 0) if(str_comp(pMode, "all") == 0)
((CChat*)pUserData)->EnableMode(0); ((CChat *)pUserData)->EnableMode(0);
else if(str_comp(pMode, "team") == 0) else if(str_comp(pMode, "team") == 0)
((CChat*)pUserData)->EnableMode(1); ((CChat *)pUserData)->EnableMode(1);
else else
((CChat*)pUserData)->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", "expected all or team as mode"); ((CChat *)pUserData)->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", "expected all or team as mode");
if(pResult->GetString(1)[0] || g_Config.m_ClChatReset) if(pResult->GetString(1)[0] || g_Config.m_ClChatReset)
((CChat*)pUserData)->m_Input.Set(pResult->GetString(1)); ((CChat *)pUserData)->m_Input.Set(pResult->GetString(1));
} }
void CChat::ConShowChat(IConsole::IResult *pResult, void *pUserData) void CChat::ConShowChat(IConsole::IResult *pResult, void *pUserData)
@ -171,14 +169,15 @@ bool CChat::OnInput(IInput::CEvent Event)
{ {
int max = minimum(i - Begin + 1, (int)sizeof(Line)); int max = minimum(i - Begin + 1, (int)sizeof(Line));
str_utf8_copy(Line, Text + Begin, max); str_utf8_copy(Line, Text + Begin, max);
Begin = i+1; Begin = i + 1;
SayChat(Line); SayChat(Line);
while(Text[i] == '\n') i++; while(Text[i] == '\n')
i++;
} }
} }
int max = minimum(i - Begin + 1, (int)sizeof(Line)); int max = minimum(i - Begin + 1, (int)sizeof(Line));
str_utf8_copy(Line, Text + Begin, max); str_utf8_copy(Line, Text + Begin, max);
Begin = i+1; Begin = i + 1;
m_Input.Add(Line); m_Input.Add(Line);
} }
} }
@ -204,7 +203,7 @@ bool CChat::OnInput(IInput::CEvent Event)
for(int i = m_Input.GetCursorOffset() + SearchDirection; SearchDirection > 0 ? i < m_Input.GetLength() - 1 : i > 0; i += SearchDirection) for(int i = m_Input.GetCursorOffset() + SearchDirection; SearchDirection > 0 ? i < m_Input.GetLength() - 1 : i > 0; i += SearchDirection)
{ {
int Next = i + SearchDirection; int Next = i + SearchDirection;
if( (m_Input.GetString()[Next] == ' ') || if((m_Input.GetString()[Next] == ' ') ||
(m_Input.GetString()[Next] >= 32 && m_Input.GetString()[Next] <= 47) || (m_Input.GetString()[Next] >= 32 && m_Input.GetString()[Next] <= 47) ||
(m_Input.GetString()[Next] >= 58 && m_Input.GetString()[Next] <= 64) || (m_Input.GetString()[Next] >= 58 && m_Input.GetString()[Next] <= 64) ||
(m_Input.GetString()[Next] >= 91 && m_Input.GetString()[Next] <= 96)) (m_Input.GetString()[Next] >= 91 && m_Input.GetString()[Next] <= 96))
@ -249,20 +248,20 @@ bool CChat::OnInput(IInput::CEvent Event)
} }
} }
if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_ESCAPE) if(Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_ESCAPE)
{ {
DisableMode(); DisableMode();
m_pClient->OnRelease(); m_pClient->OnRelease();
if(g_Config.m_ClChatReset) if(g_Config.m_ClChatReset)
m_Input.Clear(); m_Input.Clear();
} }
else if(Event.m_Flags&IInput::FLAG_PRESS && (Event.m_Key == KEY_RETURN || Event.m_Key == KEY_KP_ENTER)) else if(Event.m_Flags & IInput::FLAG_PRESS && (Event.m_Key == KEY_RETURN || Event.m_Key == KEY_KP_ENTER))
{ {
if(m_Input.GetString()[0]) if(m_Input.GetString()[0])
{ {
bool AddEntry = false; bool AddEntry = false;
if(m_LastChatSend+time_freq() < time()) if(m_LastChatSend + time_freq() < time())
{ {
Say(m_Mode == MODE_ALL ? 0 : 1, m_Input.GetString()); Say(m_Mode == MODE_ALL ? 0 : 1, m_Input.GetString());
AddEntry = true; AddEntry = true;
@ -275,9 +274,9 @@ bool CChat::OnInput(IInput::CEvent Event)
if(AddEntry) if(AddEntry)
{ {
CHistoryEntry *pEntry = m_History.Allocate(sizeof(CHistoryEntry)+m_Input.GetLength()); CHistoryEntry *pEntry = m_History.Allocate(sizeof(CHistoryEntry) + m_Input.GetLength());
pEntry->m_Team = m_Mode == MODE_ALL ? 0 : 1; pEntry->m_Team = m_Mode == MODE_ALL ? 0 : 1;
mem_copy(pEntry->m_aText, m_Input.GetString(), m_Input.GetLength()+1); mem_copy(pEntry->m_aText, m_Input.GetString(), m_Input.GetLength() + 1);
} }
} }
m_pHistoryEntry = 0x0; m_pHistoryEntry = 0x0;
@ -285,19 +284,20 @@ bool CChat::OnInput(IInput::CEvent Event)
m_pClient->OnRelease(); m_pClient->OnRelease();
m_Input.Clear(); m_Input.Clear();
} }
if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_TAB) if(Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_TAB)
{ {
// fill the completion buffer // fill the completion buffer
if(m_CompletionChosen < 0) if(m_CompletionChosen < 0)
{ {
const char *pCursor = m_Input.GetString()+m_Input.GetCursorOffset(); const char *pCursor = m_Input.GetString() + m_Input.GetCursorOffset();
for(int Count = 0; Count < m_Input.GetCursorOffset() && *(pCursor-1) != ' '; --pCursor, ++Count); for(int Count = 0; Count < m_Input.GetCursorOffset() && *(pCursor - 1) != ' '; --pCursor, ++Count)
m_PlaceholderOffset = pCursor-m_Input.GetString(); ;
m_PlaceholderOffset = pCursor - m_Input.GetString();
for(m_PlaceholderLength = 0; *pCursor && *pCursor != ' '; ++pCursor) for(m_PlaceholderLength = 0; *pCursor && *pCursor != ' '; ++pCursor)
++m_PlaceholderLength; ++m_PlaceholderLength;
str_copy(m_aCompletionBuffer, m_Input.GetString()+m_PlaceholderOffset, minimum(static_cast<int>(sizeof(m_aCompletionBuffer)), m_PlaceholderLength+1)); str_copy(m_aCompletionBuffer, m_Input.GetString() + m_PlaceholderOffset, minimum(static_cast<int>(sizeof(m_aCompletionBuffer)), m_PlaceholderLength + 1));
} }
if(m_aCompletionBuffer[0] == '/') if(m_aCompletionBuffer[0] == '/')
@ -307,25 +307,25 @@ bool CChat::OnInput(IInput::CEvent Event)
const size_t NumCommands = m_Commands.size(); const size_t NumCommands = m_Commands.size();
if(m_ReverseTAB) if(m_ReverseTAB)
m_CompletionChosen = (m_CompletionChosen-1 + 2*NumCommands)%(2*NumCommands); m_CompletionChosen = (m_CompletionChosen - 1 + 2 * NumCommands) % (2 * NumCommands);
else else
m_CompletionChosen = (m_CompletionChosen+1)%(2*NumCommands); m_CompletionChosen = (m_CompletionChosen + 1) % (2 * NumCommands);
const char *pCommandStart = m_aCompletionBuffer+1; const char *pCommandStart = m_aCompletionBuffer + 1;
for(size_t i = 0; i < 2*NumCommands; ++i) for(size_t i = 0; i < 2 * NumCommands; ++i)
{ {
int SearchType; int SearchType;
int Index; int Index;
if(m_ReverseTAB) if(m_ReverseTAB)
{ {
SearchType = ((m_CompletionChosen-i +2*NumCommands)%(2*NumCommands))/NumCommands; SearchType = ((m_CompletionChosen - i + 2 * NumCommands) % (2 * NumCommands)) / NumCommands;
Index = (m_CompletionChosen-i + NumCommands )%NumCommands; Index = (m_CompletionChosen - i + NumCommands) % NumCommands;
} }
else else
{ {
SearchType = ((m_CompletionChosen+i)%(2*NumCommands))/NumCommands; SearchType = ((m_CompletionChosen + i) % (2 * NumCommands)) / NumCommands;
Index = (m_CompletionChosen+i)%NumCommands; Index = (m_CompletionChosen + i) % NumCommands;
} }
auto &Command = m_Commands[Index]; auto &Command = m_Commands[Index];
@ -333,7 +333,7 @@ bool CChat::OnInput(IInput::CEvent Event)
if(str_comp_nocase_num(Command.pName, pCommandStart, str_length(pCommandStart)) == 0) if(str_comp_nocase_num(Command.pName, pCommandStart, str_length(pCommandStart)) == 0)
{ {
pCompletionCommand = &Command; pCompletionCommand = &Command;
m_CompletionChosen = Index+SearchType*NumCommands; m_CompletionChosen = Index + SearchType * NumCommands;
break; break;
} }
} }
@ -343,7 +343,7 @@ bool CChat::OnInput(IInput::CEvent Event)
{ {
char aBuf[256]; char aBuf[256];
// add part before the name // add part before the name
str_copy(aBuf, m_Input.GetString(), minimum(static_cast<int>(sizeof(aBuf)), m_PlaceholderOffset+1)); str_copy(aBuf, m_Input.GetString(), minimum(static_cast<int>(sizeof(aBuf)), m_PlaceholderOffset + 1));
// add the command // add the command
str_append(aBuf, "/", sizeof(aBuf)); str_append(aBuf, "/", sizeof(aBuf));
@ -356,12 +356,12 @@ bool CChat::OnInput(IInput::CEvent Event)
str_append(aBuf, pSeparator, sizeof(aBuf)); str_append(aBuf, pSeparator, sizeof(aBuf));
// add part after the name // add part after the name
str_append(aBuf, m_Input.GetString()+m_PlaceholderOffset+m_PlaceholderLength, sizeof(aBuf)); str_append(aBuf, m_Input.GetString() + m_PlaceholderOffset + m_PlaceholderLength, sizeof(aBuf));
m_PlaceholderLength = str_length(pSeparator)+str_length(pCompletionCommand->pName)+1; m_PlaceholderLength = str_length(pSeparator) + str_length(pCompletionCommand->pName) + 1;
m_OldChatStringLength = m_Input.GetLength(); m_OldChatStringLength = m_Input.GetLength();
m_Input.Set(aBuf); // TODO: Use Add instead m_Input.Set(aBuf); // TODO: Use Add instead
m_Input.SetCursorOffset(m_PlaceholderOffset+m_PlaceholderLength); m_Input.SetCursorOffset(m_PlaceholderOffset + m_PlaceholderLength);
m_InputUpdate = true; m_InputUpdate = true;
} }
} }
@ -371,27 +371,26 @@ bool CChat::OnInput(IInput::CEvent Event)
const char *pCompletionString = 0; const char *pCompletionString = 0;
if(m_ReverseTAB) if(m_ReverseTAB)
m_CompletionChosen = (m_CompletionChosen-1 + 2*MAX_CLIENTS)%(2*MAX_CLIENTS); m_CompletionChosen = (m_CompletionChosen - 1 + 2 * MAX_CLIENTS) % (2 * MAX_CLIENTS);
else else
m_CompletionChosen = (m_CompletionChosen+1)%(2*MAX_CLIENTS); m_CompletionChosen = (m_CompletionChosen + 1) % (2 * MAX_CLIENTS);
for(int i = 0; i < 2*MAX_CLIENTS; ++i) for(int i = 0; i < 2 * MAX_CLIENTS; ++i)
{ {
int SearchType; int SearchType;
int Index; int Index;
if(m_ReverseTAB) if(m_ReverseTAB)
{ {
SearchType = ((m_CompletionChosen-i +2*MAX_CLIENTS)%(2*MAX_CLIENTS))/MAX_CLIENTS; SearchType = ((m_CompletionChosen - i + 2 * MAX_CLIENTS) % (2 * MAX_CLIENTS)) / MAX_CLIENTS;
Index = (m_CompletionChosen-i + MAX_CLIENTS )%MAX_CLIENTS; Index = (m_CompletionChosen - i + MAX_CLIENTS) % MAX_CLIENTS;
} }
else else
{ {
SearchType = ((m_CompletionChosen+i)%(2*MAX_CLIENTS))/MAX_CLIENTS; SearchType = ((m_CompletionChosen + i) % (2 * MAX_CLIENTS)) / MAX_CLIENTS;
Index = (m_CompletionChosen+i)%MAX_CLIENTS; Index = (m_CompletionChosen + i) % MAX_CLIENTS;
} }
if(!m_pClient->m_Snap.m_paInfoByName[Index]) if(!m_pClient->m_Snap.m_paInfoByName[Index])
continue; continue;
@ -410,7 +409,7 @@ bool CChat::OnInput(IInput::CEvent Event)
if(Found) if(Found)
{ {
pCompletionString = m_pClient->m_aClients[Index2].m_aName; pCompletionString = m_pClient->m_aClients[Index2].m_aName;
m_CompletionChosen = Index+SearchType*MAX_CLIENTS; m_CompletionChosen = Index + SearchType * MAX_CLIENTS;
break; break;
} }
} }
@ -420,14 +419,14 @@ bool CChat::OnInput(IInput::CEvent Event)
{ {
char aBuf[256]; char aBuf[256];
// add part before the name // add part before the name
str_copy(aBuf, m_Input.GetString(), minimum(static_cast<int>(sizeof(aBuf)), m_PlaceholderOffset+1)); str_copy(aBuf, m_Input.GetString(), minimum(static_cast<int>(sizeof(aBuf)), m_PlaceholderOffset + 1));
// add the name // add the name
str_append(aBuf, pCompletionString, sizeof(aBuf)); str_append(aBuf, pCompletionString, sizeof(aBuf));
// add separator // add separator
const char *pSeparator = ""; const char *pSeparator = "";
if(*(m_Input.GetString()+m_PlaceholderOffset+m_PlaceholderLength) != ' ') if(*(m_Input.GetString() + m_PlaceholderOffset + m_PlaceholderLength) != ' ')
pSeparator = m_PlaceholderOffset == 0 ? ": " : " "; pSeparator = m_PlaceholderOffset == 0 ? ": " : " ";
else if(m_PlaceholderOffset == 0) else if(m_PlaceholderOffset == 0)
pSeparator = ":"; pSeparator = ":";
@ -435,12 +434,12 @@ bool CChat::OnInput(IInput::CEvent Event)
str_append(aBuf, pSeparator, sizeof(aBuf)); str_append(aBuf, pSeparator, sizeof(aBuf));
// add part after the name // add part after the name
str_append(aBuf, m_Input.GetString()+m_PlaceholderOffset+m_PlaceholderLength, sizeof(aBuf)); str_append(aBuf, m_Input.GetString() + m_PlaceholderOffset + m_PlaceholderLength, sizeof(aBuf));
m_PlaceholderLength = str_length(pSeparator)+str_length(pCompletionString); m_PlaceholderLength = str_length(pSeparator) + str_length(pCompletionString);
m_OldChatStringLength = m_Input.GetLength(); m_OldChatStringLength = m_Input.GetLength();
m_Input.Set(aBuf); // TODO: Use Add instead m_Input.Set(aBuf); // TODO: Use Add instead
m_Input.SetCursorOffset(m_PlaceholderOffset+m_PlaceholderLength); m_Input.SetCursorOffset(m_PlaceholderOffset + m_PlaceholderLength);
m_InputUpdate = true; m_InputUpdate = true;
} }
} }
@ -448,7 +447,7 @@ bool CChat::OnInput(IInput::CEvent Event)
else else
{ {
// reset name completion process // reset name completion process
if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key != KEY_TAB) if(Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key != KEY_TAB)
if(Event.m_Key != KEY_LSHIFT) if(Event.m_Key != KEY_LSHIFT)
m_CompletionChosen = -1; m_CompletionChosen = -1;
@ -456,15 +455,15 @@ bool CChat::OnInput(IInput::CEvent Event)
m_Input.ProcessInput(Event); m_Input.ProcessInput(Event);
m_InputUpdate = true; m_InputUpdate = true;
} }
if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_LSHIFT) if(Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_LSHIFT)
{ {
m_ReverseTAB = true; m_ReverseTAB = true;
} }
else if(Event.m_Flags&IInput::FLAG_RELEASE && Event.m_Key == KEY_LSHIFT) else if(Event.m_Flags & IInput::FLAG_RELEASE && Event.m_Key == KEY_LSHIFT)
{ {
m_ReverseTAB = false; m_ReverseTAB = false;
} }
if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_UP) if(Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_UP)
{ {
if(m_pHistoryEntry) if(m_pHistoryEntry)
{ {
@ -479,7 +478,7 @@ bool CChat::OnInput(IInput::CEvent Event)
if(m_pHistoryEntry) if(m_pHistoryEntry)
m_Input.Set(m_pHistoryEntry->m_aText); m_Input.Set(m_pHistoryEntry->m_aText);
} }
else if(Event.m_Flags&IInput::FLAG_PRESS && Event.m_Key == KEY_DOWN) else if(Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_DOWN)
{ {
if(m_pHistoryEntry) if(m_pHistoryEntry)
m_pHistoryEntry = m_History.Next(m_pHistoryEntry); m_pHistoryEntry = m_History.Next(m_pHistoryEntry);
@ -493,7 +492,6 @@ bool CChat::OnInput(IInput::CEvent Event)
return true; return true;
} }
void CChat::EnableMode(int Team) void CChat::EnableMode(int Team)
{ {
if(Client()->State() == IClient::STATE_DEMOPLAYBACK) if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
@ -540,7 +538,6 @@ bool CChat::LineShouldHighlight(const char *pLine, const char *pName)
if((pLine == pHL || pHL[-1] == ' ') && (pHL[Length] == 0 || pHL[Length] == ' ' || pHL[Length] == '.' || pHL[Length] == '!' || pHL[Length] == ',' || pHL[Length] == '?' || pHL[Length] == ':')) if((pLine == pHL || pHL[-1] == ' ') && (pHL[Length] == 0 || pHL[Length] == ' ' || pHL[Length] == '.' || pHL[Length] == '!' || pHL[Length] == ',' || pHL[Length] == '?' || pHL[Length] == ':'))
return true; return true;
} }
return false; return false;
@ -610,9 +607,9 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
if(*pLine == 0 || if(*pLine == 0 ||
(ClientID == -1 && !g_Config.m_ClShowChatSystem) || (ClientID == -1 && !g_Config.m_ClShowChatSystem) ||
(ClientID >= 0 && (m_pClient->m_aClients[ClientID].m_aName[0] == '\0' || // unknown client (ClientID >= 0 && (m_pClient->m_aClients[ClientID].m_aName[0] == '\0' || // unknown client
m_pClient->m_aClients[ClientID].m_ChatIgnore || m_pClient->m_aClients[ClientID].m_ChatIgnore ||
(m_pClient->m_Snap.m_LocalClientID != ClientID && g_Config.m_ClShowChatFriends && !m_pClient->m_aClients[ClientID].m_Friend) || (m_pClient->m_Snap.m_LocalClientID != ClientID && g_Config.m_ClShowChatFriends && !m_pClient->m_aClients[ClientID].m_Friend) ||
(m_pClient->m_Snap.m_LocalClientID != ClientID && m_pClient->m_aClients[ClientID].m_Foe)))) (m_pClient->m_Snap.m_LocalClientID != ClientID && m_pClient->m_aClients[ClientID].m_Foe))))
return; return;
// trim right and set maximum length to 256 utf8-characters // trim right and set maximum length to 256 utf8-characters
@ -642,7 +639,7 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
*(const_cast<char *>(pEnd)) = 0; *(const_cast<char *>(pEnd)) = 0;
bool Highlighted = false; bool Highlighted = false;
char *p = const_cast<char*>(pLine); char *p = const_cast<char *>(pLine);
// Only empty string left // Only empty string left
if(*p == 0) if(*p == 0)
@ -657,12 +654,12 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
{ {
if(*p++ == '\n') if(*p++ == '\n')
{ {
*(p-1) = 0; *(p - 1) = 0;
break; break;
} }
} }
m_CurrentLine = (m_CurrentLine+1)%MAX_LINES; m_CurrentLine = (m_CurrentLine + 1) % MAX_LINES;
m_aLines[m_CurrentLine].m_Time = time(); m_aLines[m_CurrentLine].m_Time = time();
m_aLines[m_CurrentLine].m_YOffset[0] = -1.0f; m_aLines[m_CurrentLine].m_YOffset[0] = -1.0f;
m_aLines[m_CurrentLine].m_YOffset[1] = -1.0f; m_aLines[m_CurrentLine].m_YOffset[1] = -1.0f;
@ -695,7 +692,6 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
Highlighted = true; Highlighted = true;
} }
m_aLines[m_CurrentLine].m_Highlighted = Highlighted; m_aLines[m_CurrentLine].m_Highlighted = Highlighted;
if(ClientID < 0) // server or client message if(ClientID < 0) // server or client message
@ -711,7 +707,7 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
if(m_pClient->m_aClients[ClientID].m_Team == TEAM_SPECTATORS) if(m_pClient->m_aClients[ClientID].m_Team == TEAM_SPECTATORS)
m_aLines[m_CurrentLine].m_NameColor = TEAM_SPECTATORS; m_aLines[m_CurrentLine].m_NameColor = TEAM_SPECTATORS;
if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags&GAMEFLAG_TEAMS) if(m_pClient->m_Snap.m_pGameInfoObj && m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags & GAMEFLAG_TEAMS)
{ {
if(m_pClient->m_aClients[ClientID].m_Team == TEAM_RED) if(m_pClient->m_aClients[ClientID].m_Team == TEAM_RED)
m_aLines[m_CurrentLine].m_NameColor = TEAM_RED; m_aLines[m_CurrentLine].m_NameColor = TEAM_RED;
@ -746,14 +742,14 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
char aBuf[1024]; char aBuf[1024];
str_format(aBuf, sizeof(aBuf), "%s%s", m_aLines[m_CurrentLine].m_aName, m_aLines[m_CurrentLine].m_aText); str_format(aBuf, sizeof(aBuf), "%s%s", m_aLines[m_CurrentLine].m_aName, m_aLines[m_CurrentLine].m_aText);
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, Team >= 2?"whisper":(m_aLines[m_CurrentLine].m_Team?"teamchat":"chat"), aBuf, Highlighted); Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, Team >= 2 ? "whisper" : (m_aLines[m_CurrentLine].m_Team ? "teamchat" : "chat"), aBuf, Highlighted);
} }
// play sound // play sound
int64 Now = time(); int64 Now = time();
if(ClientID == -1) if(ClientID == -1)
{ {
if(Now-m_aLastSoundPlayed[CHAT_SERVER] >= time_freq()*3/10) if(Now - m_aLastSoundPlayed[CHAT_SERVER] >= time_freq() * 3 / 10)
{ {
if(g_Config.m_SndServerMessage) if(g_Config.m_SndServerMessage)
{ {
@ -768,7 +764,7 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
} }
else if(Highlighted && Client()->State() != IClient::STATE_DEMOPLAYBACK) else if(Highlighted && Client()->State() != IClient::STATE_DEMOPLAYBACK)
{ {
if(Now-m_aLastSoundPlayed[CHAT_HIGHLIGHT] >= time_freq()*3/10) if(Now - m_aLastSoundPlayed[CHAT_HIGHLIGHT] >= time_freq() * 3 / 10)
{ {
char aBuf[1024]; char aBuf[1024];
str_format(aBuf, sizeof(aBuf), "%s%s", m_aLines[m_CurrentLine].m_aName, m_aLines[m_CurrentLine].m_aText); str_format(aBuf, sizeof(aBuf), "%s%s", m_aLines[m_CurrentLine].m_aName, m_aLines[m_CurrentLine].m_aText);
@ -787,10 +783,9 @@ void CChat::AddLine(int ClientID, int Team, const char *pLine)
} }
else if(Team != 2) else if(Team != 2)
{ {
if(Now-m_aLastSoundPlayed[CHAT_CLIENT] >= time_freq()*3/10) if(Now - m_aLastSoundPlayed[CHAT_CLIENT] >= time_freq() * 3 / 10)
{ {
if((g_Config.m_SndTeamChat || !m_aLines[m_CurrentLine].m_Team) if((g_Config.m_SndTeamChat || !m_aLines[m_CurrentLine].m_Team) && (g_Config.m_SndChat || m_aLines[m_CurrentLine].m_Team))
&& (g_Config.m_SndChat || m_aLines[m_CurrentLine].m_Team))
{ {
m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_CLIENT, 0); m_pClient->m_pSounds->Play(CSounds::CHN_GUI, SOUND_CHAT_CLIENT, 0);
m_aLastSoundPlayed[CHAT_CLIENT] = Now; m_aLastSoundPlayed[CHAT_CLIENT] = Now;
@ -819,7 +814,6 @@ void CChat::OnPrepareLines()
int OffsetType = m_pClient->m_pScoreboard->Active() ? 1 : 0; int OffsetType = m_pClient->m_pScoreboard->Active() ? 1 : 0;
for(int i = 0; i < MAX_LINES; i++) for(int i = 0; i < MAX_LINES; i++)
{ {
int r = ((m_CurrentLine - i) + MAX_LINES) % MAX_LINES; int r = ((m_CurrentLine - i) + MAX_LINES) % MAX_LINES;
if(Now > m_aLines[r].m_Time + 16 * time_freq() && !m_PrevShowChat) if(Now > m_aLines[r].m_Time + 16 * time_freq() && !m_PrevShowChat)
break; break;
@ -865,7 +859,6 @@ void CChat::OnPrepareLines()
// the position the text was created // the position the text was created
m_aLines[r].m_TextYOffset = y; m_aLines[r].m_TextYOffset = y;
// reset the cursor // reset the cursor
TextRender()->SetCursor(&Cursor, Begin, y, FontSize, TEXTFLAG_RENDER); TextRender()->SetCursor(&Cursor, Begin, y, FontSize, TEXTFLAG_RENDER);
Cursor.m_LineWidth = LineWidth; Cursor.m_LineWidth = LineWidth;
@ -951,10 +944,10 @@ void CChat::OnPrepareLines()
void CChat::OnRender() void CChat::OnRender()
{ {
// send pending chat messages // send pending chat messages
if(m_PendingChatCounter > 0 && m_LastChatSend+time_freq() < time()) if(m_PendingChatCounter > 0 && m_LastChatSend + time_freq() < time())
{ {
CHistoryEntry *pEntry = m_History.Last(); CHistoryEntry *pEntry = m_History.Last();
for(int i = m_PendingChatCounter-1; pEntry; --i, pEntry = m_History.Prev(pEntry)) for(int i = m_PendingChatCounter - 1; pEntry; --i, pEntry = m_History.Prev(pEntry))
{ {
if(i == 0) if(i == 0)
{ {
@ -965,16 +958,16 @@ void CChat::OnRender()
--m_PendingChatCounter; --m_PendingChatCounter;
} }
float Width = 300.0f*Graphics()->ScreenAspect(); float Width = 300.0f * Graphics()->ScreenAspect();
Graphics()->MapScreen(0.0f, 0.0f, Width, 300.0f); Graphics()->MapScreen(0.0f, 0.0f, Width, 300.0f);
float x = 5.0f; float x = 5.0f;
float y = 300.0f-20.0f; float y = 300.0f - 20.0f;
if(m_Mode != MODE_NONE) if(m_Mode != MODE_NONE)
{ {
// render chat input // render chat input
CTextCursor Cursor; CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, x, y, 8.0f, TEXTFLAG_RENDER); TextRender()->SetCursor(&Cursor, x, y, 8.0f, TEXTFLAG_RENDER);
Cursor.m_LineWidth = Width-190.0f; Cursor.m_LineWidth = Width - 190.0f;
Cursor.m_MaxLines = 2; Cursor.m_MaxLines = 2;
if(m_Mode == MODE_ALL) if(m_Mode == MODE_ALL)
@ -1002,34 +995,34 @@ void CChat::OnRender()
if(m_InputUpdate) if(m_InputUpdate)
{ {
if(m_ChatStringOffset > 0 && m_Input.GetLength(Editing) < m_OldChatStringLength) if(m_ChatStringOffset > 0 && m_Input.GetLength(Editing) < m_OldChatStringLength)
m_ChatStringOffset = maximum(0, m_ChatStringOffset-(m_OldChatStringLength-m_Input.GetLength(Editing))); m_ChatStringOffset = maximum(0, m_ChatStringOffset - (m_OldChatStringLength - m_Input.GetLength(Editing)));
if(m_ChatStringOffset > m_Input.GetCursorOffset(Editing)) if(m_ChatStringOffset > m_Input.GetCursorOffset(Editing))
m_ChatStringOffset -= m_ChatStringOffset-m_Input.GetCursorOffset(Editing); m_ChatStringOffset -= m_ChatStringOffset - m_Input.GetCursorOffset(Editing);
else else
{ {
CTextCursor Temp = Cursor; CTextCursor Temp = Cursor;
Temp.m_Flags = 0; Temp.m_Flags = 0;
TextRender()->TextEx(&Temp, m_Input.GetString(Editing)+m_ChatStringOffset, m_Input.GetCursorOffset(Editing)-m_ChatStringOffset); TextRender()->TextEx(&Temp, m_Input.GetString(Editing) + m_ChatStringOffset, m_Input.GetCursorOffset(Editing) - m_ChatStringOffset);
TextRender()->TextEx(&Temp, "|", -1); TextRender()->TextEx(&Temp, "|", -1);
while(Temp.m_LineCount > 2) while(Temp.m_LineCount > 2)
{ {
++m_ChatStringOffset; ++m_ChatStringOffset;
Temp = Cursor; Temp = Cursor;
Temp.m_Flags = 0; Temp.m_Flags = 0;
TextRender()->TextEx(&Temp, m_Input.GetString(Editing)+m_ChatStringOffset, m_Input.GetCursorOffset(Editing)-m_ChatStringOffset); TextRender()->TextEx(&Temp, m_Input.GetString(Editing) + m_ChatStringOffset, m_Input.GetCursorOffset(Editing) - m_ChatStringOffset);
TextRender()->TextEx(&Temp, "|", -1); TextRender()->TextEx(&Temp, "|", -1);
} }
} }
m_InputUpdate = false; m_InputUpdate = false;
} }
TextRender()->TextEx(&Cursor, m_Input.GetString(Editing)+m_ChatStringOffset, m_Input.GetCursorOffset(Editing)-m_ChatStringOffset); TextRender()->TextEx(&Cursor, m_Input.GetString(Editing) + m_ChatStringOffset, m_Input.GetCursorOffset(Editing) - m_ChatStringOffset);
static float MarkerOffset = TextRender()->TextWidth(0, 8.0f, "|", -1, -1.0f)/3; static float MarkerOffset = TextRender()->TextWidth(0, 8.0f, "|", -1, -1.0f) / 3;
CTextCursor Marker = Cursor; CTextCursor Marker = Cursor;
Marker.m_X -= MarkerOffset; Marker.m_X -= MarkerOffset;
TextRender()->TextEx(&Marker, "|", -1); TextRender()->TextEx(&Marker, "|", -1);
TextRender()->TextEx(&Cursor, m_Input.GetString(Editing)+m_Input.GetCursorOffset(Editing), -1); TextRender()->TextEx(&Cursor, m_Input.GetString(Editing) + m_Input.GetCursorOffset(Editing), -1);
if(m_pClient->m_pGameConsole->IsClosed()) if(m_pClient->m_pGameConsole->IsClosed())
Input()->SetEditingPosition(Marker.m_X, Marker.m_Y + Marker.m_FontSize); Input()->SetEditingPosition(Marker.m_X, Marker.m_Y + Marker.m_FontSize);
} }
@ -1050,8 +1043,8 @@ void CChat::OnRender()
int OffsetType = m_pClient->m_pScoreboard->Active() ? 1 : 0; int OffsetType = m_pClient->m_pScoreboard->Active() ? 1 : 0;
for(int i = 0; i < MAX_LINES; i++) for(int i = 0; i < MAX_LINES; i++)
{ {
int r = ((m_CurrentLine-i)+MAX_LINES)%MAX_LINES; int r = ((m_CurrentLine - i) + MAX_LINES) % MAX_LINES;
if(Now > m_aLines[r].m_Time+16*time_freq() && !m_PrevShowChat) if(Now > m_aLines[r].m_Time + 16 * time_freq() && !m_PrevShowChat)
break; break;
y -= m_aLines[r].m_YOffset[OffsetType]; y -= m_aLines[r].m_YOffset[OffsetType];
@ -1060,7 +1053,7 @@ void CChat::OnRender()
if(y < HeightLimit) if(y < HeightLimit)
break; break;
float Blend = Now > m_aLines[r].m_Time + 14 * time_freq() && !m_PrevShowChat ? 1.0f - (Now - m_aLines[r].m_Time - 14 * time_freq()) / (2.0f*time_freq()) : 1.0f; float Blend = Now > m_aLines[r].m_Time + 14 * time_freq() && !m_PrevShowChat ? 1.0f - (Now - m_aLines[r].m_Time - 14 * time_freq()) / (2.0f * time_freq()) : 1.0f;
if(m_aLines[r].m_TextContainerIndex != -1) if(m_aLines[r].m_TextContainerIndex != -1)
{ {
@ -1089,7 +1082,7 @@ void CChat::SayChat(const char *pLine)
bool AddEntry = false; bool AddEntry = false;
if(m_LastChatSend+time_freq() < time()) if(m_LastChatSend + time_freq() < time())
{ {
Say(m_Mode == MODE_ALL ? 0 : 1, pLine); Say(m_Mode == MODE_ALL ? 0 : 1, pLine);
AddEntry = true; AddEntry = true;
@ -1102,7 +1095,7 @@ void CChat::SayChat(const char *pLine)
if(AddEntry) if(AddEntry)
{ {
CHistoryEntry *pEntry = m_History.Allocate(sizeof(CHistoryEntry)+str_length(pLine)-1); CHistoryEntry *pEntry = m_History.Allocate(sizeof(CHistoryEntry) + str_length(pLine) - 1);
pEntry->m_Team = m_Mode == MODE_ALL ? 0 : 1; pEntry->m_Team = m_Mode == MODE_ALL ? 0 : 1;
mem_copy(pEntry->m_aText, pLine, str_length(pLine)); mem_copy(pEntry->m_aText, pLine, str_length(pLine));
} }

View file

@ -40,11 +40,11 @@ class CChat : public CComponent
// chat // chat
enum enum
{ {
MODE_NONE=0, MODE_NONE = 0,
MODE_ALL, MODE_ALL,
MODE_TEAM, MODE_TEAM,
CHAT_SERVER=0, CHAT_SERVER = 0,
CHAT_HIGHLIGHT, CHAT_HIGHLIGHT,
CHAT_CLIENT, CHAT_CLIENT,
CHAT_NUM, CHAT_NUM,
@ -65,9 +65,9 @@ class CChat : public CComponent
const char *pName; const char *pName;
const char *pParams; const char *pParams;
bool operator <(const CCommand &Other) const { return str_comp(pName, Other.pName) < 0; } bool operator<(const CCommand &Other) const { return str_comp(pName, Other.pName) < 0; }
bool operator <=(const CCommand &Other) const { return str_comp(pName, Other.pName) <= 0; } bool operator<=(const CCommand &Other) const { return str_comp(pName, Other.pName) <= 0; }
bool operator ==(const CCommand &Other) const { return str_comp(pName, Other.pName) == 0; } bool operator==(const CCommand &Other) const { return str_comp(pName, Other.pName) == 0; }
}; };
sorted_array<CCommand> m_Commands; sorted_array<CCommand> m_Commands;
@ -79,7 +79,7 @@ class CChat : public CComponent
char m_aText[1]; char m_aText[1];
}; };
CHistoryEntry *m_pHistoryEntry; CHistoryEntry *m_pHistoryEntry;
TStaticRingBuffer<CHistoryEntry, 64*1024, CRingBufferBase::FLAG_RECYCLE> m_History; TStaticRingBuffer<CHistoryEntry, 64 * 1024, CRingBufferBase::FLAG_RECYCLE> m_History;
int m_PendingChatCounter; int m_PendingChatCounter;
int64 m_LastChatSend; int64 m_LastChatSend;
int64 m_aLastSoundPlayed[CHAT_NUM]; int64 m_aLastSoundPlayed[CHAT_NUM];

View file

@ -3,33 +3,33 @@
#include <base/tl/sorted_array.h> #include <base/tl/sorted_array.h>
#include <math.h>
#include <limits.h> #include <limits.h>
#include <math.h>
#include <game/generated/client_data.h> #include <game/generated/client_data.h>
#include <base/system.h> #include <base/system.h>
#include <engine/serverbrowser.h>
#include <engine/shared/ringbuffer.h>
#include <engine/shared/config.h>
#include <engine/graphics.h>
#include <engine/textrender.h>
#include <engine/storage.h>
#include <engine/keys.h>
#include <engine/console.h> #include <engine/console.h>
#include <engine/graphics.h>
#include <engine/keys.h>
#include <engine/serverbrowser.h>
#include <engine/shared/config.h>
#include <engine/shared/ringbuffer.h>
#include <engine/storage.h>
#include <engine/textrender.h>
#include <cstring>
#include <cstdio> #include <cstdio>
#include <cstring>
#include <game/client/ui.h> #include <game/client/ui.h>
#include <game/version.h> #include <game/version.h>
#include <game/client/lineinput.h>
#include <game/client/render.h>
#include <game/client/components/controls.h> #include <game/client/components/controls.h>
#include <game/client/components/menus.h> #include <game/client/components/menus.h>
#include <game/client/lineinput.h>
#include <game/client/render.h>
#include "console.h" #include "console.h"
@ -125,7 +125,7 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
for(int i = m_Input.GetCursorOffset() + SearchDirection; SearchDirection > 0 ? i < m_Input.GetLength() - 1 : i > 0; i += SearchDirection) for(int i = m_Input.GetCursorOffset() + SearchDirection; SearchDirection > 0 ? i < m_Input.GetLength() - 1 : i > 0; i += SearchDirection)
{ {
int Next = i + SearchDirection; int Next = i + SearchDirection;
if( (m_Input.GetString()[Next] == ' ') || if((m_Input.GetString()[Next] == ' ') ||
(m_Input.GetString()[Next] >= 32 && m_Input.GetString()[Next] <= 47) || (m_Input.GetString()[Next] >= 32 && m_Input.GetString()[Next] <= 47) ||
(m_Input.GetString()[Next] >= 58 && m_Input.GetString()[Next] <= 64) || (m_Input.GetString()[Next] >= 58 && m_Input.GetString()[Next] <= 64) ||
(m_Input.GetString()[Next] >= 91 && m_Input.GetString()[Next] <= 96)) (m_Input.GetString()[Next] >= 91 && m_Input.GetString()[Next] <= 96))
@ -174,13 +174,13 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
} }
int max = minimum(i - Begin + 1, (int)sizeof(Line)); int max = minimum(i - Begin + 1, (int)sizeof(Line));
str_copy(Line, Text + Begin, max); str_copy(Line, Text + Begin, max);
Begin = i+1; Begin = i + 1;
ExecuteLine(Line); ExecuteLine(Line);
} }
} }
int max = minimum(i - Begin + 1, (int)sizeof(Line)); int max = minimum(i - Begin + 1, (int)sizeof(Line));
str_copy(Line, Text + Begin, max); str_copy(Line, Text + Begin, max);
Begin = i+1; Begin = i + 1;
m_Input.Add(Line); m_Input.Add(Line);
} }
} }
@ -205,7 +205,7 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
m_Input.DeleteFromCursor(); m_Input.DeleteFromCursor();
} }
if(Event.m_Flags&IInput::FLAG_PRESS) if(Event.m_Flags & IInput::FLAG_PRESS)
{ {
if(Event.m_Key == KEY_RETURN || Event.m_Key == KEY_KP_ENTER) if(Event.m_Key == KEY_RETURN || Event.m_Key == KEY_KP_ENTER)
{ {
@ -213,8 +213,8 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
{ {
if(m_Type == CONSOLETYPE_LOCAL || m_pGameConsole->Client()->RconAuthed()) if(m_Type == CONSOLETYPE_LOCAL || m_pGameConsole->Client()->RconAuthed())
{ {
char *pEntry = m_History.Allocate(m_Input.GetLength()+1); char *pEntry = m_History.Allocate(m_Input.GetLength() + 1);
mem_copy(pEntry, m_Input.GetString(), m_Input.GetLength()+1); mem_copy(pEntry, m_Input.GetString(), m_Input.GetLength() + 1);
} }
ExecuteLine(m_Input.GetString()); ExecuteLine(m_Input.GetString());
m_Input.Clear(); m_Input.Clear();
@ -223,28 +223,28 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
Handled = true; Handled = true;
} }
else if (Event.m_Key == KEY_UP) else if(Event.m_Key == KEY_UP)
{ {
if (m_pHistoryEntry) if(m_pHistoryEntry)
{ {
char *pTest = m_History.Prev(m_pHistoryEntry); char *pTest = m_History.Prev(m_pHistoryEntry);
if (pTest) if(pTest)
m_pHistoryEntry = pTest; m_pHistoryEntry = pTest;
} }
else else
m_pHistoryEntry = m_History.Last(); m_pHistoryEntry = m_History.Last();
if (m_pHistoryEntry) if(m_pHistoryEntry)
m_Input.Set(m_pHistoryEntry); m_Input.Set(m_pHistoryEntry);
Handled = true; Handled = true;
} }
else if (Event.m_Key == KEY_DOWN) else if(Event.m_Key == KEY_DOWN)
{ {
if (m_pHistoryEntry) if(m_pHistoryEntry)
m_pHistoryEntry = m_History.Next(m_pHistoryEntry); m_pHistoryEntry = m_History.Next(m_pHistoryEntry);
if (m_pHistoryEntry) if(m_pHistoryEntry)
m_Input.Set(m_pHistoryEntry); m_Input.Set(m_pHistoryEntry);
else else
m_Input.Clear(); m_Input.Clear();
@ -255,20 +255,18 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
if(m_Type == CGameConsole::CONSOLETYPE_LOCAL || m_pGameConsole->Client()->RconAuthed()) if(m_Type == CGameConsole::CONSOLETYPE_LOCAL || m_pGameConsole->Client()->RconAuthed())
{ {
if(m_ReverseTAB) if(m_ReverseTAB)
m_CompletionChosen--; m_CompletionChosen--;
else else
m_CompletionChosen++; m_CompletionChosen++;
m_CompletionEnumerationCount = 0; m_CompletionEnumerationCount = 0;
m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(), PossibleCommandsCompleteCallback, this);
m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(), PossibleCommandsCompleteCallback, this);
// handle wrapping // handle wrapping
if(m_CompletionEnumerationCount && (m_CompletionChosen >= m_CompletionEnumerationCount || m_CompletionChosen <0)) if(m_CompletionEnumerationCount && (m_CompletionChosen >= m_CompletionEnumerationCount || m_CompletionChosen < 0))
{ {
m_CompletionChosen= (m_CompletionChosen + m_CompletionEnumerationCount) % m_CompletionEnumerationCount; m_CompletionChosen = (m_CompletionChosen + m_CompletionEnumerationCount) % m_CompletionEnumerationCount;
m_CompletionEnumerationCount = 0; m_CompletionEnumerationCount = 0;
m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->m_pConsole->PossibleCommands(m_aCompletionBuffer, m_CompletionFlagmask, m_Type != CGameConsole::CONSOLETYPE_LOCAL && m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(), PossibleCommandsCompleteCallback, this);
m_pGameConsole->Client()->RconAuthed() && m_pGameConsole->Client()->UseTempRconCommands(), PossibleCommandsCompleteCallback, this);
} }
} }
} }
@ -298,7 +296,7 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
Handled = true; Handled = true;
} }
} }
if(Event.m_Flags&IInput::FLAG_RELEASE && Event.m_Key == KEY_LSHIFT) if(Event.m_Flags & IInput::FLAG_RELEASE && Event.m_Key == KEY_LSHIFT)
{ {
m_ReverseTAB = false; m_ReverseTAB = false;
Handled = true; Handled = true;
@ -307,7 +305,7 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
if(!Handled) if(!Handled)
m_Input.ProcessInput(Event); m_Input.ProcessInput(Event);
if(Event.m_Flags & (IInput::FLAG_PRESS|IInput::FLAG_TEXT)) if(Event.m_Flags & (IInput::FLAG_PRESS | IInput::FLAG_TEXT))
{ {
if((Event.m_Key != KEY_TAB) && (Event.m_Key != KEY_LSHIFT)) if((Event.m_Key != KEY_TAB) && (Event.m_Key != KEY_LSHIFT))
{ {
@ -321,7 +319,7 @@ void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
char aBuf[64] = {0}; char aBuf[64] = {0};
const char *pSrc = GetString(); const char *pSrc = GetString();
int i = 0; int i = 0;
for(; i < (int)sizeof(aBuf)-1 && *pSrc && *pSrc != ' '; i++, pSrc++) for(; i < (int)sizeof(aBuf) - 1 && *pSrc && *pSrc != ' '; i++, pSrc++)
aBuf[i] = *pSrc; aBuf[i] = *pSrc;
aBuf[i] = 0; aBuf[i] = 0;
@ -344,10 +342,10 @@ void CGameConsole::CInstance::PrintLine(const char *pLine, bool Highlighted)
{ {
int Len = str_length(pLine); int Len = str_length(pLine);
if (Len > 255) if(Len > 255)
Len = 255; Len = 255;
CBacklogEntry *pEntry = m_Backlog.Allocate(sizeof(CBacklogEntry)+Len); CBacklogEntry *pEntry = m_Backlog.Allocate(sizeof(CBacklogEntry) + Len);
pEntry->m_YOffset = -1.0f; pEntry->m_YOffset = -1.0f;
pEntry->m_Highlighted = Highlighted; pEntry->m_Highlighted = Highlighted;
mem_copy(pEntry->m_aText, pLine, Len); mem_copy(pEntry->m_aText, pLine, Len);
@ -355,7 +353,7 @@ void CGameConsole::CInstance::PrintLine(const char *pLine, bool Highlighted)
} }
CGameConsole::CGameConsole() CGameConsole::CGameConsole()
: m_LocalConsole(CONSOLETYPE_LOCAL), m_RemoteConsole(CONSOLETYPE_REMOTE) : m_LocalConsole(CONSOLETYPE_LOCAL), m_RemoteConsole(CONSOLETYPE_REMOTE)
{ {
m_ConsoleType = CONSOLETYPE_LOCAL; m_ConsoleType = CONSOLETYPE_LOCAL;
m_ConsoleState = CONSOLE_CLOSED; m_ConsoleState = CONSOLE_CLOSED;
@ -366,7 +364,7 @@ CGameConsole::CGameConsole()
float CGameConsole::TimeNow() float CGameConsole::TimeNow()
{ {
static long long s_TimeStart = time_get(); static long long s_TimeStart = time_get();
return float(time_get()-s_TimeStart)/float(time_freq()); return float(time_get() - s_TimeStart) / float(time_freq());
} }
CGameConsole::CInstance *CGameConsole::CurrentConsole() CGameConsole::CInstance *CGameConsole::CurrentConsole()
@ -384,7 +382,7 @@ void CGameConsole::OnReset()
static float ConsoleScaleFunc(float t) static float ConsoleScaleFunc(float t)
{ {
//return t; //return t;
return sinf(acosf(1.0f-t)); return sinf(acosf(1.0f - t));
} }
struct CRenderInfo struct CRenderInfo
@ -407,17 +405,17 @@ void CGameConsole::PossibleCommandsRenderCallback(const char *pStr, void *pUser)
float tw = pInfo->m_pSelf->TextRender()->TextWidth(pInfo->m_Cursor.m_pFont, pInfo->m_Cursor.m_FontSize, pStr, -1, -1.0f); float tw = pInfo->m_pSelf->TextRender()->TextWidth(pInfo->m_Cursor.m_pFont, pInfo->m_Cursor.m_FontSize, pStr, -1, -1.0f);
pInfo->m_pSelf->Graphics()->TextureClear(); pInfo->m_pSelf->Graphics()->TextureClear();
pInfo->m_pSelf->Graphics()->QuadsBegin(); pInfo->m_pSelf->Graphics()->QuadsBegin();
pInfo->m_pSelf->Graphics()->SetColor(229.0f/255.0f,185.0f/255.0f,4.0f/255.0f,0.85f); pInfo->m_pSelf->Graphics()->SetColor(229.0f / 255.0f, 185.0f / 255.0f, 4.0f / 255.0f, 0.85f);
pInfo->m_pSelf->RenderTools()->DrawRoundRect(pInfo->m_Cursor.m_X - 2.5f, pInfo->m_Cursor.m_Y - 4.f / 2.f, tw + 5.f, pInfo->m_Cursor.m_FontSize + 4.f, pInfo->m_Cursor.m_FontSize / 3.f); pInfo->m_pSelf->RenderTools()->DrawRoundRect(pInfo->m_Cursor.m_X - 2.5f, pInfo->m_Cursor.m_Y - 4.f / 2.f, tw + 5.f, pInfo->m_Cursor.m_FontSize + 4.f, pInfo->m_Cursor.m_FontSize / 3.f);
pInfo->m_pSelf->Graphics()->QuadsEnd(); pInfo->m_pSelf->Graphics()->QuadsEnd();
// scroll when out of sight // scroll when out of sight
if(pInfo->m_Cursor.m_X < 3.0f) if(pInfo->m_Cursor.m_X < 3.0f)
pInfo->m_Offset = 0.0f; pInfo->m_Offset = 0.0f;
else if(pInfo->m_Cursor.m_X+tw > pInfo->m_Width) else if(pInfo->m_Cursor.m_X + tw > pInfo->m_Width)
pInfo->m_Offset -= pInfo->m_Width/2; pInfo->m_Offset -= pInfo->m_Width / 2;
pInfo->m_pSelf->TextRender()->TextColor(0.05f, 0.05f, 0.05f,1); pInfo->m_pSelf->TextRender()->TextColor(0.05f, 0.05f, 0.05f, 1);
pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pStr, -1); pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pStr, -1);
} }
else else
@ -426,16 +424,16 @@ void CGameConsole::PossibleCommandsRenderCallback(const char *pStr, void *pUser)
if(pMatchStart) if(pMatchStart)
{ {
pInfo->m_pSelf->TextRender()->TextColor(0.5f,0.5f,0.5f,1); pInfo->m_pSelf->TextRender()->TextColor(0.5f, 0.5f, 0.5f, 1);
pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pStr, pMatchStart-pStr); pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pStr, pMatchStart - pStr);
pInfo->m_pSelf->TextRender()->TextColor(229.0f/255.0f,185.0f/255.0f,4.0f/255.0f,1); pInfo->m_pSelf->TextRender()->TextColor(229.0f / 255.0f, 185.0f / 255.0f, 4.0f / 255.0f, 1);
pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pMatchStart, str_length(pInfo->m_pCurrentCmd)); pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pMatchStart, str_length(pInfo->m_pCurrentCmd));
pInfo->m_pSelf->TextRender()->TextColor(0.5f,0.5f,0.5f,1); pInfo->m_pSelf->TextRender()->TextColor(0.5f, 0.5f, 0.5f, 1);
pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pMatchStart+str_length(pInfo->m_pCurrentCmd), -1); pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pMatchStart + str_length(pInfo->m_pCurrentCmd), -1);
} }
else else
{ {
pInfo->m_pSelf->TextRender()->TextColor(0.75f,0.75f,0.75f,1); pInfo->m_pSelf->TextRender()->TextColor(0.75f, 0.75f, 0.75f, 1);
pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pStr, -1); pInfo->m_pSelf->TextRender()->TextEx(&pInfo->m_Cursor, pStr, -1);
} }
} }
@ -447,40 +445,40 @@ void CGameConsole::PossibleCommandsRenderCallback(const char *pStr, void *pUser)
void CGameConsole::OnRender() void CGameConsole::OnRender()
{ {
CUIRect Screen = *UI()->Screen(); CUIRect Screen = *UI()->Screen();
float ConsoleMaxHeight = Screen.h*3/5.0f; float ConsoleMaxHeight = Screen.h * 3 / 5.0f;
float ConsoleHeight; float ConsoleHeight;
float Progress = (TimeNow()-(m_StateChangeEnd-m_StateChangeDuration))/m_StateChangeDuration; float Progress = (TimeNow() - (m_StateChangeEnd - m_StateChangeDuration)) / m_StateChangeDuration;
if (Progress >= 1.0f) if(Progress >= 1.0f)
{ {
if (m_ConsoleState == CONSOLE_CLOSING) if(m_ConsoleState == CONSOLE_CLOSING)
m_ConsoleState = CONSOLE_CLOSED; m_ConsoleState = CONSOLE_CLOSED;
else if (m_ConsoleState == CONSOLE_OPENING) else if(m_ConsoleState == CONSOLE_OPENING)
m_ConsoleState = CONSOLE_OPEN; m_ConsoleState = CONSOLE_OPEN;
Progress = 1.0f; Progress = 1.0f;
} }
if (m_ConsoleState == CONSOLE_OPEN && g_Config.m_ClEditor) if(m_ConsoleState == CONSOLE_OPEN && g_Config.m_ClEditor)
Toggle(CONSOLETYPE_LOCAL); Toggle(CONSOLETYPE_LOCAL);
if (m_ConsoleState == CONSOLE_CLOSED) if(m_ConsoleState == CONSOLE_CLOSED)
return; return;
if (m_ConsoleState == CONSOLE_OPEN) if(m_ConsoleState == CONSOLE_OPEN)
Input()->MouseModeAbsolute(); Input()->MouseModeAbsolute();
float ConsoleHeightScale; float ConsoleHeightScale;
if (m_ConsoleState == CONSOLE_OPENING) if(m_ConsoleState == CONSOLE_OPENING)
ConsoleHeightScale = ConsoleScaleFunc(Progress); ConsoleHeightScale = ConsoleScaleFunc(Progress);
else if (m_ConsoleState == CONSOLE_CLOSING) else if(m_ConsoleState == CONSOLE_CLOSING)
ConsoleHeightScale = ConsoleScaleFunc(1.0f-Progress); ConsoleHeightScale = ConsoleScaleFunc(1.0f - Progress);
else //if (console_state == CONSOLE_OPEN) else //if (console_state == CONSOLE_OPEN)
ConsoleHeightScale = ConsoleScaleFunc(1.0f); ConsoleHeightScale = ConsoleScaleFunc(1.0f);
ConsoleHeight = ConsoleHeightScale*ConsoleMaxHeight; ConsoleHeight = ConsoleHeightScale * ConsoleMaxHeight;
Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h); Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);
@ -488,10 +486,10 @@ void CGameConsole::OnRender()
Graphics()->TextureClear(); Graphics()->TextureClear();
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
IGraphics::CColorVertex Array[4] = { IGraphics::CColorVertex Array[4] = {
IGraphics::CColorVertex(0, 0,0,0, 0.5f), IGraphics::CColorVertex(0, 0, 0, 0, 0.5f),
IGraphics::CColorVertex(1, 0,0,0, 0.5f), IGraphics::CColorVertex(1, 0, 0, 0, 0.5f),
IGraphics::CColorVertex(2, 0,0,0, 0.0f), IGraphics::CColorVertex(2, 0, 0, 0, 0.0f),
IGraphics::CColorVertex(3, 0,0,0, 0.0f)}; IGraphics::CColorVertex(3, 0, 0, 0, 0.0f)};
Graphics()->SetColorVertex(Array, 4); Graphics()->SetColorVertex(Array, 4);
IGraphics::CQuadItem QuadItem(0, ConsoleHeight, Screen.w, 10.0f); IGraphics::CQuadItem QuadItem(0, ConsoleHeight, Screen.w, 10.0f);
Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsDrawTL(&QuadItem, 1);
@ -500,10 +498,10 @@ void CGameConsole::OnRender()
// do background // do background
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_CONSOLE_BG].m_Id); Graphics()->TextureSet(g_pData->m_aImages[IMAGE_CONSOLE_BG].m_Id);
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
Graphics()->SetColor(0.2f, 0.2f, 0.2f,0.9f); Graphics()->SetColor(0.2f, 0.2f, 0.2f, 0.9f);
if(m_ConsoleType == CONSOLETYPE_REMOTE) if(m_ConsoleType == CONSOLETYPE_REMOTE)
Graphics()->SetColor(0.4f, 0.2f, 0.2f,0.9f); Graphics()->SetColor(0.4f, 0.2f, 0.2f, 0.9f);
Graphics()->QuadsSetSubset(0,-ConsoleHeight*0.075f,Screen.w*0.075f*0.5f,0); Graphics()->QuadsSetSubset(0, -ConsoleHeight * 0.075f, Screen.w * 0.075f * 0.5f, 0);
QuadItem = IGraphics::CQuadItem(0, 0, Screen.w, ConsoleHeight); QuadItem = IGraphics::CQuadItem(0, 0, Screen.w, ConsoleHeight);
Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsDrawTL(&QuadItem, 1);
Graphics()->QuadsEnd(); Graphics()->QuadsEnd();
@ -511,12 +509,12 @@ void CGameConsole::OnRender()
// do small bar shadow // do small bar shadow
Graphics()->TextureClear(); Graphics()->TextureClear();
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
Array[0] = IGraphics::CColorVertex(0, 0,0,0, 0.0f); Array[0] = IGraphics::CColorVertex(0, 0, 0, 0, 0.0f);
Array[1] = IGraphics::CColorVertex(1, 0,0,0, 0.0f); Array[1] = IGraphics::CColorVertex(1, 0, 0, 0, 0.0f);
Array[2] = IGraphics::CColorVertex(2, 0,0,0, 0.25f); Array[2] = IGraphics::CColorVertex(2, 0, 0, 0, 0.25f);
Array[3] = IGraphics::CColorVertex(3, 0,0,0, 0.25f); Array[3] = IGraphics::CColorVertex(3, 0, 0, 0, 0.25f);
Graphics()->SetColorVertex(Array, 4); Graphics()->SetColorVertex(Array, 4);
QuadItem = IGraphics::CQuadItem(0, ConsoleHeight-20, Screen.w, 10); QuadItem = IGraphics::CQuadItem(0, ConsoleHeight - 20, Screen.w, 10);
Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsDrawTL(&QuadItem, 1);
Graphics()->QuadsEnd(); Graphics()->QuadsEnd();
@ -524,8 +522,8 @@ void CGameConsole::OnRender()
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_CONSOLE_BAR].m_Id); Graphics()->TextureSet(g_pData->m_aImages[IMAGE_CONSOLE_BAR].m_Id);
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.9f); Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.9f);
Graphics()->QuadsSetSubset(0,0.1f,Screen.w*0.015f,1-0.1f); Graphics()->QuadsSetSubset(0, 0.1f, Screen.w * 0.015f, 1 - 0.1f);
QuadItem = IGraphics::CQuadItem(0,ConsoleHeight-10.0f,Screen.w,10.0f); QuadItem = IGraphics::CQuadItem(0, ConsoleHeight - 10.0f, Screen.w, 10.0f);
Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsDrawTL(&QuadItem, 1);
Graphics()->QuadsEnd(); Graphics()->QuadsEnd();
@ -535,7 +533,7 @@ void CGameConsole::OnRender()
{ {
float FontSize = 10.0f; float FontSize = 10.0f;
float RowHeight = FontSize*1.25f; float RowHeight = FontSize * 1.25f;
float x = 3; float x = 3;
float y = ConsoleHeight - RowHeight - 5.0f; float y = ConsoleHeight - RowHeight - 5.0f;
@ -546,7 +544,7 @@ void CGameConsole::OnRender()
Info.m_Offset = pConsole->m_CompletionRenderOffset; Info.m_Offset = pConsole->m_CompletionRenderOffset;
Info.m_Width = Screen.w; Info.m_Width = Screen.w;
Info.m_pCurrentCmd = pConsole->m_aCompletionBuffer; Info.m_pCurrentCmd = pConsole->m_aCompletionBuffer;
TextRender()->SetCursor(&Info.m_Cursor, x+Info.m_Offset, y+RowHeight+2.0f, FontSize, TEXTFLAG_RENDER); TextRender()->SetCursor(&Info.m_Cursor, x + Info.m_Offset, y + RowHeight + 2.0f, FontSize, TEXTFLAG_RENDER);
// render prompt // render prompt
CTextCursor Cursor; CTextCursor Cursor;
@ -578,11 +576,10 @@ void CGameConsole::OnRender()
x = Cursor.m_X; x = Cursor.m_X;
//console text editing //console text editing
bool Editing = false; bool Editing = false;
int EditingCursor = Input()->GetEditingCursor(); int EditingCursor = Input()->GetEditingCursor();
if (Input()->GetIMEState()) if(Input()->GetIMEState())
{ {
if(str_length(Input()->GetIMECandidate())) if(str_length(Input()->GetIMECandidate()))
{ {
@ -604,7 +601,7 @@ void CGameConsole::OnRender()
TextRender()->SetCursor(&Cursor, x, y, FontSize, 0); TextRender()->SetCursor(&Cursor, x, y, FontSize, 0);
Cursor.m_LineWidth = Screen.w - 10.0f - x; Cursor.m_LineWidth = Screen.w - 10.0f - x;
TextRender()->TextEx(&Cursor, aInputString, pConsole->m_Input.GetCursorOffset(Editing)); TextRender()->TextEx(&Cursor, aInputString, pConsole->m_Input.GetCursorOffset(Editing));
TextRender()->TextEx(&Cursor, aInputString+pConsole->m_Input.GetCursorOffset(Editing), -1); TextRender()->TextEx(&Cursor, aInputString + pConsole->m_Input.GetCursorOffset(Editing), -1);
int Lines = Cursor.m_LineCount; int Lines = Cursor.m_LineCount;
y -= (Lines - 1) * FontSize; y -= (Lines - 1) * FontSize;
@ -612,12 +609,12 @@ void CGameConsole::OnRender()
Cursor.m_LineWidth = Screen.w - 10.0f - x; Cursor.m_LineWidth = Screen.w - 10.0f - x;
TextRender()->TextEx(&Cursor, aInputString, pConsole->m_Input.GetCursorOffset(Editing)); TextRender()->TextEx(&Cursor, aInputString, pConsole->m_Input.GetCursorOffset(Editing));
static float MarkerOffset = TextRender()->TextWidth(0, FontSize, "|", -1, -1.0f)/3; static float MarkerOffset = TextRender()->TextWidth(0, FontSize, "|", -1, -1.0f) / 3;
CTextCursor Marker = Cursor; CTextCursor Marker = Cursor;
Marker.m_X -= MarkerOffset; Marker.m_X -= MarkerOffset;
Marker.m_LineWidth = -1; Marker.m_LineWidth = -1;
TextRender()->TextEx(&Marker, "|", -1); TextRender()->TextEx(&Marker, "|", -1);
TextRender()->TextEx(&Cursor, aInputString+pConsole->m_Input.GetCursorOffset(Editing), -1); TextRender()->TextEx(&Cursor, aInputString + pConsole->m_Input.GetCursorOffset(Editing), -1);
Input()->SetEditingPosition(Marker.m_X, Marker.m_Y + Marker.m_FontSize); Input()->SetEditingPosition(Marker.m_X, Marker.m_Y + Marker.m_FontSize);
// render possible commands // render possible commands
@ -625,8 +622,7 @@ void CGameConsole::OnRender()
{ {
if(pConsole->m_Input.GetString()[0] != 0) if(pConsole->m_Input.GetString()[0] != 0)
{ {
m_pConsole->PossibleCommands(pConsole->m_aCompletionBuffer, pConsole->m_CompletionFlagmask, m_ConsoleType != CGameConsole::CONSOLETYPE_LOCAL && m_pConsole->PossibleCommands(pConsole->m_aCompletionBuffer, pConsole->m_CompletionFlagmask, m_ConsoleType != CGameConsole::CONSOLETYPE_LOCAL && Client()->RconAuthed() && Client()->UseTempRconCommands(), PossibleCommandsRenderCallback, &Info);
Client()->RconAuthed() && Client()->UseTempRconCommands(), PossibleCommandsRenderCallback, &Info);
pConsole->m_CompletionRenderOffset = Info.m_Offset; pConsole->m_CompletionRenderOffset = Info.m_Offset;
if(Info.m_EnumCount <= 0) if(Info.m_EnumCount <= 0)
@ -658,33 +654,33 @@ void CGameConsole::OnRender()
if(pEntry->m_Highlighted) if(pEntry->m_Highlighted)
TextRender()->TextColor(rgb); TextRender()->TextColor(rgb);
else else
TextRender()->TextColor(1,1,1,1); TextRender()->TextColor(1, 1, 1, 1);
// get y offset (calculate it if we haven't yet) // get y offset (calculate it if we haven't yet)
if(pEntry->m_YOffset < 0.0f) if(pEntry->m_YOffset < 0.0f)
{ {
TextRender()->SetCursor(&Cursor, 0.0f, 0.0f, FontSize, 0); TextRender()->SetCursor(&Cursor, 0.0f, 0.0f, FontSize, 0);
Cursor.m_LineWidth = Screen.w-10; Cursor.m_LineWidth = Screen.w - 10;
TextRender()->TextEx(&Cursor, pEntry->m_aText, -1); TextRender()->TextEx(&Cursor, pEntry->m_aText, -1);
pEntry->m_YOffset = Cursor.m_Y+Cursor.m_FontSize+LineOffset; pEntry->m_YOffset = Cursor.m_Y + Cursor.m_FontSize + LineOffset;
} }
OffsetY += pEntry->m_YOffset; OffsetY += pEntry->m_YOffset;
// next page when lines reach the top // next page when lines reach the top
if(y-OffsetY <= RowHeight) if(y - OffsetY <= RowHeight)
break; break;
// just render output from actual backlog page (render bottom up) // just render output from actual backlog page (render bottom up)
if(Page == pConsole->m_BacklogActPage) if(Page == pConsole->m_BacklogActPage)
{ {
TextRender()->SetCursor(&Cursor, 0.0f, y-OffsetY, FontSize, TEXTFLAG_RENDER); TextRender()->SetCursor(&Cursor, 0.0f, y - OffsetY, FontSize, TEXTFLAG_RENDER);
Cursor.m_LineWidth = Screen.w-10.0f; Cursor.m_LineWidth = Screen.w - 10.0f;
TextRender()->TextEx(&Cursor, pEntry->m_aText, -1); TextRender()->TextEx(&Cursor, pEntry->m_aText, -1);
} }
pEntry = pConsole->m_Backlog.Prev(pEntry); pEntry = pConsole->m_Backlog.Prev(pEntry);
// reset color // reset color
TextRender()->TextColor(1,1,1,1); TextRender()->TextColor(1, 1, 1, 1);
} }
// actual backlog page number is too high, render last available page (current checked one, render top down) // actual backlog page number is too high, render last available page (current checked one, render top down)
@ -694,8 +690,8 @@ void CGameConsole::OnRender()
pEntry = pConsole->m_Backlog.First(); pEntry = pConsole->m_Backlog.First();
while(OffsetY > 0.0f && pEntry) while(OffsetY > 0.0f && pEntry)
{ {
TextRender()->SetCursor(&Cursor, 0.0f, y-OffsetY, FontSize, TEXTFLAG_RENDER); TextRender()->SetCursor(&Cursor, 0.0f, y - OffsetY, FontSize, TEXTFLAG_RENDER);
Cursor.m_LineWidth = Screen.w-10.0f; Cursor.m_LineWidth = Screen.w - 10.0f;
TextRender()->TextEx(&Cursor, pEntry->m_aText, -1); TextRender()->TextEx(&Cursor, pEntry->m_aText, -1);
OffsetY -= pEntry->m_YOffset; OffsetY -= pEntry->m_YOffset;
pEntry = pConsole->m_Backlog.Next(pEntry); pEntry = pConsole->m_Backlog.Next(pEntry);
@ -706,14 +702,14 @@ void CGameConsole::OnRender()
// render page // render page
char aBuf[128]; char aBuf[128];
TextRender()->TextColor(1,1,1,1); TextRender()->TextColor(1, 1, 1, 1);
str_format(aBuf, sizeof(aBuf), Localize("-Page %d-"), pConsole->m_BacklogActPage+1); str_format(aBuf, sizeof(aBuf), Localize("-Page %d-"), pConsole->m_BacklogActPage + 1);
TextRender()->Text(0, 10.0f, FontSize / 2.f, FontSize, aBuf, -1.0f); TextRender()->Text(0, 10.0f, FontSize / 2.f, FontSize, aBuf, -1.0f);
// render version // render version
str_copy(aBuf, "v" GAME_VERSION " on " CONF_PLATFORM_STRING " " CONF_ARCH_STRING, sizeof(aBuf)); str_copy(aBuf, "v" GAME_VERSION " on " CONF_PLATFORM_STRING " " CONF_ARCH_STRING, sizeof(aBuf));
float Width = TextRender()->TextWidth(0, FontSize, aBuf, -1, -1.0f); float Width = TextRender()->TextWidth(0, FontSize, aBuf, -1, -1.0f);
TextRender()->Text(0, Screen.w-Width-10.0f, FontSize / 2.f, FontSize, aBuf, -1.0f); TextRender()->Text(0, Screen.w - Width - 10.0f, FontSize / 2.f, FontSize, aBuf, -1.0f);
} }
} }
@ -724,12 +720,12 @@ void CGameConsole::OnMessage(int MsgType, void *pRawMsg)
bool CGameConsole::OnInput(IInput::CEvent Event) bool CGameConsole::OnInput(IInput::CEvent Event)
{ {
// accept input when opening, but not at first frame to discard the input that caused the console to open // accept input when opening, but not at first frame to discard the input that caused the console to open
if(m_ConsoleState != CONSOLE_OPEN && (m_ConsoleState != CONSOLE_OPENING || m_StateChangeEnd == TimeNow()+m_StateChangeDuration)) if(m_ConsoleState != CONSOLE_OPEN && (m_ConsoleState != CONSOLE_OPENING || m_StateChangeEnd == TimeNow() + m_StateChangeDuration))
return false; return false;
if((Event.m_Key >= KEY_F1 && Event.m_Key <= KEY_F12) || (Event.m_Key >= KEY_F13 && Event.m_Key <= KEY_F24)) if((Event.m_Key >= KEY_F1 && Event.m_Key <= KEY_F12) || (Event.m_Key >= KEY_F13 && Event.m_Key <= KEY_F24))
return false; return false;
if(Event.m_Key == KEY_ESCAPE && (Event.m_Flags&IInput::FLAG_PRESS)) if(Event.m_Key == KEY_ESCAPE && (Event.m_Flags & IInput::FLAG_PRESS))
Toggle(m_ConsoleType); Toggle(m_ConsoleType);
else else
CurrentConsole()->OnInput(Event); CurrentConsole()->OnInput(Event);
@ -745,19 +741,19 @@ void CGameConsole::Toggle(int Type)
} }
else else
{ {
if (m_ConsoleState == CONSOLE_CLOSED || m_ConsoleState == CONSOLE_OPEN) if(m_ConsoleState == CONSOLE_CLOSED || m_ConsoleState == CONSOLE_OPEN)
{ {
m_StateChangeEnd = TimeNow()+m_StateChangeDuration; m_StateChangeEnd = TimeNow() + m_StateChangeDuration;
} }
else else
{ {
float Progress = m_StateChangeEnd-TimeNow(); float Progress = m_StateChangeEnd - TimeNow();
float ReversedProgress = m_StateChangeDuration-Progress; float ReversedProgress = m_StateChangeDuration - Progress;
m_StateChangeEnd = TimeNow()+ReversedProgress; m_StateChangeEnd = TimeNow() + ReversedProgress;
} }
if (m_ConsoleState == CONSOLE_CLOSED || m_ConsoleState == CONSOLE_CLOSING) if(m_ConsoleState == CONSOLE_CLOSED || m_ConsoleState == CONSOLE_CLOSING)
{ {
/*Input()->MouseModeAbsolute();*/ /*Input()->MouseModeAbsolute();*/
m_pClient->m_pMenus->UseMouseButtons(false); m_pClient->m_pMenus->UseMouseButtons(false);
@ -788,7 +784,7 @@ void CGameConsole::Dump(int Type)
char aDate[20]; char aDate[20];
str_timestamp(aDate, sizeof(aDate)); str_timestamp(aDate, sizeof(aDate));
str_format(aFilename, sizeof(aFilename), "dumps/%s_dump_%s.txt", Type==CONSOLETYPE_REMOTE?"remote_console":"local_console", aDate); str_format(aFilename, sizeof(aFilename), "dumps/%s_dump_%s.txt", Type == CONSOLETYPE_REMOTE ? "remote_console" : "local_console", aDate);
IOHANDLE io = Storage()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE); IOHANDLE io = Storage()->OpenFile(aFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
if(io) if(io)
{ {

View file

@ -5,8 +5,8 @@
#include <math.h> #include <math.h>
#include <base/system.h>
#include <base/math.h> #include <base/math.h>
#include <base/system.h>
#include <base/vmath.h> #include <base/vmath.h>
#include <engine/config.h> #include <engine/config.h>
@ -16,12 +16,12 @@
#include <engine/graphics.h> #include <engine/graphics.h>
#include <engine/keys.h> #include <engine/keys.h>
#include <engine/serverbrowser.h> #include <engine/serverbrowser.h>
#include <engine/shared/config.h>
#include <engine/storage.h> #include <engine/storage.h>
#include <engine/textrender.h> #include <engine/textrender.h>
#include <engine/shared/config.h>
#include <game/version.h>
#include <game/generated/protocol.h> #include <game/generated/protocol.h>
#include <game/version.h>
#include <engine/client/updater.h> #include <engine/client/updater.h>
@ -34,10 +34,10 @@
#include <game/localization.h> #include <game/localization.h>
#include <mastersrv/mastersrv.h> #include <mastersrv/mastersrv.h>
#include "controls.h"
#include "countryflags.h" #include "countryflags.h"
#include "menus.h" #include "menus.h"
#include "skins.h" #include "skins.h"
#include "controls.h"
ColorRGBA CMenus::ms_GuiColor; ColorRGBA CMenus::ms_GuiColor;
ColorRGBA CMenus::ms_ColorTabbarInactiveOutgame; ColorRGBA CMenus::ms_ColorTabbarInactiveOutgame;
@ -57,7 +57,6 @@ float CMenus::ms_FontmodHeight = 0.8f;
IInput::CEvent CMenus::m_aInputEvents[MAX_INPUTEVENTS]; IInput::CEvent CMenus::m_aInputEvents[MAX_INPUTEVENTS];
int CMenus::m_NumInputEvents; int CMenus::m_NumInputEvents;
CMenus::CMenus() CMenus::CMenus()
{ {
m_Popup = POPUP_NONE; m_Popup = POPUP_NONE;
@ -113,12 +112,12 @@ int CMenus::DoButton_Icon(int ImageId, int SpriteId, const CUIRect *pRect)
// Square and center // Square and center
if(w > h) if(w > h)
{ {
x += (w-h) / 2; x += (w - h) / 2;
w = h; w = h;
} }
else if(h > w) else if(h > w)
{ {
y += (h-w) / 2; y += (h - w) / 2;
h = w; h = w;
} }
@ -139,7 +138,7 @@ int CMenus::DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect,
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
if(!Active) if(!Active)
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.5f); Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.5f);
RenderTools()->SelectSprite(Checked?SPRITE_GUIBUTTON_ON:SPRITE_GUIBUTTON_OFF); RenderTools()->SelectSprite(Checked ? SPRITE_GUIBUTTON_ON : SPRITE_GUIBUTTON_OFF);
IGraphics::CQuadItem QuadItem(pRect->x, pRect->y, pRect->w, pRect->h); IGraphics::CQuadItem QuadItem(pRect->x, pRect->y, pRect->w, pRect->h);
Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsDrawTL(&QuadItem, 1);
if(UI()->HotItem() == pID && Active) if(UI()->HotItem() == pID && Active)
@ -188,10 +187,10 @@ int CMenus::DoButton_Menu(const void *pID, const char *pText, int Checked, const
void CMenus::DoButton_KeySelect(const void *pID, const char *pText, int Checked, const CUIRect *pRect) void CMenus::DoButton_KeySelect(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
{ {
RenderTools()->DrawUIRect(pRect, ColorRGBA(1,1,1,0.5f * ButtonColorMul(pID)), CUI::CORNER_ALL, 5.0f); RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 1, 1, 0.5f * ButtonColorMul(pID)), CUI::CORNER_ALL, 5.0f);
CUIRect Temp; CUIRect Temp;
pRect->HMargin(1.0f, &Temp); pRect->HMargin(1.0f, &Temp);
UI()->DoLabel(&Temp, pText, Temp.h*ms_FontmodHeight, 0); UI()->DoLabel(&Temp, pText, Temp.h * ms_FontmodHeight, 0);
} }
int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners, const ColorRGBA *pDefaultColor, const ColorRGBA *pActiveColor, const ColorRGBA *pHoverColor, float EdgeRounding) int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners, const ColorRGBA *pDefaultColor, const ColorRGBA *pActiveColor, const ColorRGBA *pHoverColor, float EdgeRounding)
@ -222,7 +221,7 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co
} }
CUIRect Temp; CUIRect Temp;
pRect->HMargin(2.0f, &Temp); pRect->HMargin(2.0f, &Temp);
UI()->DoLabel(&Temp, pText, Temp.h*ms_FontmodHeight, 0); UI()->DoLabel(&Temp, pText, Temp.h * ms_FontmodHeight, 0);
return UI()->DoButtonLogic(pID, pText, Checked, pRect); return UI()->DoButtonLogic(pID, pText, Checked, pRect);
} }
@ -230,12 +229,12 @@ int CMenus::DoButton_MenuTab(const void *pID, const char *pText, int Checked, co
int CMenus::DoButton_GridHeader(const void *pID, const char *pText, int Checked, const CUIRect *pRect) int CMenus::DoButton_GridHeader(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
{ {
if(Checked == 2) if(Checked == 2)
RenderTools()->DrawUIRect(pRect, ColorRGBA(1,0.98f,0.5f,0.55f), CUI::CORNER_T, 5.0f); RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 0.98f, 0.5f, 0.55f), CUI::CORNER_T, 5.0f);
else if(Checked) else if(Checked)
RenderTools()->DrawUIRect(pRect, ColorRGBA(1,1,1,0.5f), CUI::CORNER_T, 5.0f); RenderTools()->DrawUIRect(pRect, ColorRGBA(1, 1, 1, 0.5f), CUI::CORNER_T, 5.0f);
CUIRect t; CUIRect t;
pRect->VSplitLeft(5.0f, 0, &t); pRect->VSplitLeft(5.0f, 0, &t);
UI()->DoLabel(&t, pText, pRect->h*ms_FontmodHeight, -1); UI()->DoLabel(&t, pText, pRect->h * ms_FontmodHeight, -1);
return UI()->DoButtonLogic(pID, pText, Checked, pRect); return UI()->DoButtonLogic(pID, pText, Checked, pRect);
} }
@ -249,30 +248,29 @@ int CMenus::DoButton_CheckBox_Common(const void *pID, const char *pText, const c
t.VSplitLeft(5.0f, 0, &t); t.VSplitLeft(5.0f, 0, &t);
c.Margin(2.0f, &c); c.Margin(2.0f, &c);
RenderTools()->DrawUIRect(&c, ColorRGBA(1,1,1,0.25f * ButtonColorMul(pID)), CUI::CORNER_ALL, 3.0f); RenderTools()->DrawUIRect(&c, ColorRGBA(1, 1, 1, 0.25f * ButtonColorMul(pID)), CUI::CORNER_ALL, 3.0f);
TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT); TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGMENT);
bool CheckAble = *pBoxText == 'X'; bool CheckAble = *pBoxText == 'X';
if(CheckAble) if(CheckAble)
{ {
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT)); TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
UI()->DoLabel(&c, "\xEE\x97\x8D", c.h*ms_FontmodHeight, 0); UI()->DoLabel(&c, "\xEE\x97\x8D", c.h * ms_FontmodHeight, 0);
TextRender()->SetCurFont(NULL); TextRender()->SetCurFont(NULL);
} }
else else
UI()->DoLabel(&c, pBoxText, c.h*ms_FontmodHeight, 0); UI()->DoLabel(&c, pBoxText, c.h * ms_FontmodHeight, 0);
TextRender()->SetRenderFlags(0); TextRender()->SetRenderFlags(0);
UI()->DoLabel(&t, pText, c.h*ms_FontmodHeight, -1); UI()->DoLabel(&t, pText, c.h * ms_FontmodHeight, -1);
return UI()->DoButtonLogic(pID, pText, 0, pRect); return UI()->DoButtonLogic(pID, pText, 0, pRect);
} }
int CMenus::DoButton_CheckBox(const void *pID, const char *pText, int Checked, const CUIRect *pRect) int CMenus::DoButton_CheckBox(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
{ {
return DoButton_CheckBox_Common(pID, pText, Checked?"X":"", pRect); return DoButton_CheckBox_Common(pID, pText, Checked ? "X" : "", pRect);
} }
int CMenus::DoButton_CheckBox_Number(const void *pID, const char *pText, int Checked, const CUIRect *pRect) int CMenus::DoButton_CheckBox_Number(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
{ {
char aBuf[16]; char aBuf[16];
@ -365,15 +363,15 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS
else if(s_DoScroll) else if(s_DoScroll)
{ {
// do scrolling // do scrolling
if(UI()->MouseX() < pRect->x && s_ScrollStart-UI()->MouseX() > 10.0f) if(UI()->MouseX() < pRect->x && s_ScrollStart - UI()->MouseX() > 10.0f)
{ {
s_AtIndex = maximum(0, s_AtIndex-1); s_AtIndex = maximum(0, s_AtIndex - 1);
s_ScrollStart = UI()->MouseX(); s_ScrollStart = UI()->MouseX();
UpdateOffset = true; UpdateOffset = true;
} }
else if(UI()->MouseX() > pRect->x+pRect->w && UI()->MouseX()-s_ScrollStart > 10.0f) else if(UI()->MouseX() > pRect->x + pRect->w && UI()->MouseX() - s_ScrollStart > 10.0f)
{ {
s_AtIndex = minimum(Len, s_AtIndex+1); s_AtIndex = minimum(Len, s_AtIndex + 1);
s_ScrollStart = UI()->MouseX(); s_ScrollStart = UI()->MouseX();
UpdateOffset = true; UpdateOffset = true;
} }
@ -431,7 +429,7 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS
{ {
unsigned s = str_length(pDisplayStr); unsigned s = str_length(pDisplayStr);
if(s >= sizeof(aStars)) if(s >= sizeof(aStars))
s = sizeof(aStars)-1; s = sizeof(aStars) - 1;
for(unsigned int i = 0; i < s; ++i) for(unsigned int i = 0; i < s; ++i)
aStars[i] = '*'; aStars[i] = '*';
aStars[s] = 0; aStars[s] = 0;
@ -445,21 +443,21 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS
const char *Text = Input()->GetIMECandidate(); const char *Text = Input()->GetIMECandidate();
if(str_length(Text)) if(str_length(Text))
{ {
int NewTextLen = str_length(Text); int NewTextLen = str_length(Text);
int CharsLeft = StrSize - str_length(aInputing) - 1; int CharsLeft = StrSize - str_length(aInputing) - 1;
int FillCharLen = minimum(NewTextLen, CharsLeft); int FillCharLen = minimum(NewTextLen, CharsLeft);
//Push Char Backward //Push Char Backward
for(int i = str_length(aInputing); i >= s_AtIndex ; i--) for(int i = str_length(aInputing); i >= s_AtIndex; i--)
aInputing[i+FillCharLen] = aInputing[i]; aInputing[i + FillCharLen] = aInputing[i];
for(int i = 0; i < FillCharLen; i++) for(int i = 0; i < FillCharLen; i++)
{ {
if(Text[i] == '\n') if(Text[i] == '\n')
aInputing[s_AtIndex + i] = ' '; aInputing[s_AtIndex + i] = ' ';
else else
aInputing[s_AtIndex + i] = Text[i]; aInputing[s_AtIndex + i] = Text[i];
} }
//s_AtIndex = s_AtIndex+FillCharLen; //s_AtIndex = s_AtIndex+FillCharLen;
pDisplayStr = aInputing; pDisplayStr = aInputing;
} }
} }
@ -467,24 +465,22 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS
if(UI()->LastActiveItem() == pID && !JustGotActive && (UpdateOffset || m_NumInputEvents)) if(UI()->LastActiveItem() == pID && !JustGotActive && (UpdateOffset || m_NumInputEvents))
{ {
float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex, -1.0f); float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex, -1.0f);
if(w-*Offset > Textbox.w) if(w - *Offset > Textbox.w)
{ {
// move to the left // move to the left
float wt = TextRender()->TextWidth(0, FontSize, pDisplayStr, -1, -1.0f); float wt = TextRender()->TextWidth(0, FontSize, pDisplayStr, -1, -1.0f);
do do
{ {
*Offset += minimum(wt-*Offset-Textbox.w, Textbox.w/3); *Offset += minimum(wt - *Offset - Textbox.w, Textbox.w / 3);
} } while(w - *Offset > Textbox.w);
while(w-*Offset > Textbox.w);
} }
else if(w-*Offset < 0.0f) else if(w - *Offset < 0.0f)
{ {
// move to the right // move to the right
do do
{ {
*Offset = maximum(0.0f, *Offset-Textbox.w/3); *Offset = maximum(0.0f, *Offset - Textbox.w / 3);
} } while(w - *Offset < 0.0f);
while(w-*Offset < 0.0f);
} }
} }
UI()->ClipEnable(pRect); UI()->ClipEnable(pRect);
@ -502,21 +498,21 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS
float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex + Input()->GetEditingCursor(), -1.0f); float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex + Input()->GetEditingCursor(), -1.0f);
Textbox = *pRect; Textbox = *pRect;
Textbox.VSplitLeft(2.0f, 0, &Textbox); Textbox.VSplitLeft(2.0f, 0, &Textbox);
Textbox.x += (w-*Offset-TextRender()->TextWidth(0, FontSize, "|", -1, -1.0f)/2); Textbox.x += (w - *Offset - TextRender()->TextWidth(0, FontSize, "|", -1, -1.0f) / 2);
UI()->DoLabel(&Textbox, "|", FontSize, -1); UI()->DoLabel(&Textbox, "|", FontSize, -1);
} }
float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex, -1.0f); float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex, -1.0f);
Textbox = *pRect; Textbox = *pRect;
Textbox.VSplitLeft(2.0f, 0, &Textbox); Textbox.VSplitLeft(2.0f, 0, &Textbox);
Textbox.x += (w-*Offset-TextRender()->TextWidth(0, FontSize, "|", -1, -1.0f)/2); Textbox.x += (w - *Offset - TextRender()->TextWidth(0, FontSize, "|", -1, -1.0f) / 2);
if((2*time_get()/time_freq()) % 2) // make it blink if((2 * time_get() / time_freq()) % 2) // make it blink
UI()->DoLabel(&Textbox, "|", FontSize, -1); UI()->DoLabel(&Textbox, "|", FontSize, -1);
Input()->SetEditingPosition(Textbox.x, Textbox.y + FontSize); Input()->SetEditingPosition(Textbox.x, Textbox.y + FontSize);
} }
UI()->ClipDisable(); UI()->ClipDisable();
return ReturnValue; return ReturnValue;
@ -550,7 +546,7 @@ float CMenus::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current)
static float OffsetY; static float OffsetY;
pRect->HSplitTop(33, &Handle, 0); pRect->HSplitTop(33, &Handle, 0);
Handle.y += (pRect->h-Handle.h)*Current; Handle.y += (pRect->h - Handle.h) * Current;
// logic // logic
float ReturnValue = Current; float ReturnValue = Current;
@ -565,18 +561,20 @@ float CMenus::DoScrollbarV(const void *pID, const CUIRect *pRect, float Current)
m_MouseSlow = true; m_MouseSlow = true;
float Min = pRect->y; float Min = pRect->y;
float Max = pRect->h-Handle.h; float Max = pRect->h - Handle.h;
float Cur = UI()->MouseY()-OffsetY; float Cur = UI()->MouseY() - OffsetY;
ReturnValue = (Cur-Min)/Max; ReturnValue = (Cur - Min) / Max;
if(ReturnValue < 0.0f) ReturnValue = 0.0f; if(ReturnValue < 0.0f)
if(ReturnValue > 1.0f) ReturnValue = 1.0f; ReturnValue = 0.0f;
if(ReturnValue > 1.0f)
ReturnValue = 1.0f;
} }
else if(UI()->HotItem() == pID) else if(UI()->HotItem() == pID)
{ {
if(UI()->MouseButton(0)) if(UI()->MouseButton(0))
{ {
UI()->SetActiveItem(pID); UI()->SetActiveItem(pID);
OffsetY = UI()->MouseY()-Handle.y; OffsetY = UI()->MouseY() - Handle.y;
} }
} }
@ -610,7 +608,7 @@ float CMenus::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current)
static float OffsetX; static float OffsetX;
pRect->VSplitLeft(33, &Handle, 0); pRect->VSplitLeft(33, &Handle, 0);
Handle.x += (pRect->w-Handle.w)*Current; Handle.x += (pRect->w - Handle.w) * Current;
// logic // logic
float ReturnValue = Current; float ReturnValue = Current;
@ -625,18 +623,20 @@ float CMenus::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current)
m_MouseSlow = true; m_MouseSlow = true;
float Min = pRect->x; float Min = pRect->x;
float Max = pRect->w-Handle.w; float Max = pRect->w - Handle.w;
float Cur = UI()->MouseX()-OffsetX; float Cur = UI()->MouseX() - OffsetX;
ReturnValue = (Cur-Min)/Max; ReturnValue = (Cur - Min) / Max;
if(ReturnValue < 0.0f) ReturnValue = 0.0f; if(ReturnValue < 0.0f)
if(ReturnValue > 1.0f) ReturnValue = 1.0f; ReturnValue = 0.0f;
if(ReturnValue > 1.0f)
ReturnValue = 1.0f;
} }
else if(UI()->HotItem() == pID) else if(UI()->HotItem() == pID)
{ {
if(UI()->MouseButton(0)) if(UI()->MouseButton(0))
{ {
UI()->SetActiveItem(pID); UI()->SetActiveItem(pID);
OffsetX = UI()->MouseX()-Handle.x; OffsetX = UI()->MouseX() - Handle.x;
} }
} }
@ -646,17 +646,17 @@ float CMenus::DoScrollbarH(const void *pID, const CUIRect *pRect, float Current)
// render // render
CUIRect Rail; CUIRect Rail;
pRect->HMargin(5.0f, &Rail); pRect->HMargin(5.0f, &Rail);
RenderTools()->DrawUIRect(&Rail, ColorRGBA(1,1,1,0.25f), 0, 0.0f); RenderTools()->DrawUIRect(&Rail, ColorRGBA(1, 1, 1, 0.25f), 0, 0.0f);
CUIRect Slider = Handle; CUIRect Slider = Handle;
Slider.h = Rail.y-Slider.y; Slider.h = Rail.y - Slider.y;
RenderTools()->DrawUIRect(&Slider, ColorRGBA(1,1,1,0.25f), CUI::CORNER_T, 2.5f); RenderTools()->DrawUIRect(&Slider, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_T, 2.5f);
Slider.y = Rail.y+Rail.h; Slider.y = Rail.y + Rail.h;
RenderTools()->DrawUIRect(&Slider, ColorRGBA(1,1,1,0.25f), CUI::CORNER_B, 2.5f); RenderTools()->DrawUIRect(&Slider, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_B, 2.5f);
Slider = Handle; Slider = Handle;
Slider.Margin(5.0f, &Slider); Slider.Margin(5.0f, &Slider);
RenderTools()->DrawUIRect(&Slider, ColorRGBA(1,1,1,0.25f * ButtonColorMul(pID)), CUI::CORNER_ALL, 2.5f); RenderTools()->DrawUIRect(&Slider, ColorRGBA(1, 1, 1, 0.25f * ButtonColorMul(pID)), CUI::CORNER_ALL, 2.5f);
return ReturnValue; return ReturnValue;
} }
@ -741,7 +741,6 @@ int CMenus::DoKeyReader(void *pID, const CUIRect *pRect, int Key, int Modifier,
return NewKey; return NewKey;
} }
int CMenus::RenderMenubar(CUIRect r) int CMenus::RenderMenubar(CUIRect r)
{ {
CUIRect Box = r; CUIRect Box = r;
@ -883,23 +882,23 @@ int CMenus::RenderMenubar(CUIRect r)
{ {
// online menus // online menus
Box.VSplitLeft(90.0f, &Button, &Box); Box.VSplitLeft(90.0f, &Button, &Box);
static int s_GameButton=0; static int s_GameButton = 0;
if(DoButton_MenuTab(&s_GameButton, Localize("Game"), m_ActivePage==PAGE_GAME, &Button, CUI::CORNER_TL)) if(DoButton_MenuTab(&s_GameButton, Localize("Game"), m_ActivePage == PAGE_GAME, &Button, CUI::CORNER_TL))
NewPage = PAGE_GAME; NewPage = PAGE_GAME;
Box.VSplitLeft(90.0f, &Button, &Box); Box.VSplitLeft(90.0f, &Button, &Box);
static int s_PlayersButton=0; static int s_PlayersButton = 0;
if(DoButton_MenuTab(&s_PlayersButton, Localize("Players"), m_ActivePage==PAGE_PLAYERS, &Button, 0)) if(DoButton_MenuTab(&s_PlayersButton, Localize("Players"), m_ActivePage == PAGE_PLAYERS, &Button, 0))
NewPage = PAGE_PLAYERS; NewPage = PAGE_PLAYERS;
Box.VSplitLeft(130.0f, &Button, &Box); Box.VSplitLeft(130.0f, &Button, &Box);
static int s_ServerInfoButton=0; static int s_ServerInfoButton = 0;
if(DoButton_MenuTab(&s_ServerInfoButton, Localize("Server info"), m_ActivePage==PAGE_SERVER_INFO, &Button, 0)) if(DoButton_MenuTab(&s_ServerInfoButton, Localize("Server info"), m_ActivePage == PAGE_SERVER_INFO, &Button, 0))
NewPage = PAGE_SERVER_INFO; NewPage = PAGE_SERVER_INFO;
Box.VSplitLeft(90.0f, &Button, &Box); Box.VSplitLeft(90.0f, &Button, &Box);
static int s_NetworkButton=0; static int s_NetworkButton = 0;
if(DoButton_MenuTab(&s_NetworkButton, Localize("Browser"), m_ActivePage==PAGE_NETWORK, &Button, 0)) if(DoButton_MenuTab(&s_NetworkButton, Localize("Browser"), m_ActivePage == PAGE_NETWORK, &Button, 0))
NewPage = PAGE_NETWORK; NewPage = PAGE_NETWORK;
{ {
@ -914,8 +913,8 @@ int CMenus::RenderMenubar(CUIRect r)
Box.VSplitLeft(100.0f, &Button, &Box); Box.VSplitLeft(100.0f, &Button, &Box);
Box.VSplitLeft(4.0f, 0, &Box); Box.VSplitLeft(4.0f, 0, &Box);
static int s_CallVoteButton=0; static int s_CallVoteButton = 0;
if(DoButton_MenuTab(&s_CallVoteButton, Localize("Call vote"), m_ActivePage==PAGE_CALLVOTE, &Button, CUI::CORNER_TR)) if(DoButton_MenuTab(&s_CallVoteButton, Localize("Call vote"), m_ActivePage == PAGE_CALLVOTE, &Button, CUI::CORNER_TR))
NewPage = PAGE_CALLVOTE; NewPage = PAGE_CALLVOTE;
} }
@ -939,14 +938,14 @@ int CMenus::RenderMenubar(CUIRect r)
Box.VSplitRight(10.0f, &Box, &Button); Box.VSplitRight(10.0f, &Box, &Button);
Box.VSplitRight(33.0f, &Box, &Button); Box.VSplitRight(33.0f, &Box, &Button);
static int s_SettingsButton=0; static int s_SettingsButton = 0;
if(DoButton_MenuTab(&s_SettingsButton, "\xEE\xA2\xB8", m_ActivePage==PAGE_SETTINGS, &Button, CUI::CORNER_T)) if(DoButton_MenuTab(&s_SettingsButton, "\xEE\xA2\xB8", m_ActivePage == PAGE_SETTINGS, &Button, CUI::CORNER_T))
NewPage = PAGE_SETTINGS; NewPage = PAGE_SETTINGS;
Box.VSplitRight(10.0f, &Box, &Button); Box.VSplitRight(10.0f, &Box, &Button);
Box.VSplitRight(33.0f, &Box, &Button); Box.VSplitRight(33.0f, &Box, &Button);
static int s_EditorButton=0; static int s_EditorButton = 0;
if(DoButton_MenuTab(&s_EditorButton, "\xEE\x8F\x89", 0, &Button, CUI::CORNER_T)) if(DoButton_MenuTab(&s_EditorButton, "\xEE\x8F\x89", 0, &Button, CUI::CORNER_T))
{ {
g_Config.m_ClEditor = 1; g_Config.m_ClEditor = 1;
@ -988,11 +987,11 @@ void CMenus::RenderLoading()
// TODO: not supported right now due to separate render thread // TODO: not supported right now due to separate render thread
static int64 LastLoadRender = 0; static int64 LastLoadRender = 0;
float Percent = m_LoadCurrent++/(float)m_LoadTotal; float Percent = m_LoadCurrent++ / (float)m_LoadTotal;
// make sure that we don't render for each little thing we load // make sure that we don't render for each little thing we load
// because that will slow down loading if we have vsync // because that will slow down loading if we have vsync
if(time_get()-LastLoadRender < time_freq()/60) if(time_get() - LastLoadRender < time_freq() / 60)
return; return;
LastLoadRender = time_get(); LastLoadRender = time_get();
@ -1007,31 +1006,30 @@ void CMenus::RenderLoading()
float w = 700; float w = 700;
float h = 200; float h = 200;
float x = Screen.w/2-w/2; float x = Screen.w / 2 - w / 2;
float y = Screen.h/2-h/2; float y = Screen.h / 2 - h / 2;
Graphics()->BlendNormal(); Graphics()->BlendNormal();
Graphics()->TextureClear(); Graphics()->TextureClear();
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,0,0.50f); Graphics()->SetColor(0, 0, 0, 0.50f);
RenderTools()->DrawRoundRect(x, y, w, h, 40.0f); RenderTools()->DrawRoundRect(x, y, w, h, 40.0f);
Graphics()->QuadsEnd(); Graphics()->QuadsEnd();
const char *pCaption = Localize("Loading DDNet Client"); const char *pCaption = Localize("Loading DDNet Client");
CUIRect r; CUIRect r;
r.x = x; r.x = x;
r.y = y+20; r.y = y + 20;
r.w = w; r.w = w;
r.h = h - 130; r.h = h - 130;
UI()->DoLabel(&r, pCaption, 48.0f, 0, -1); UI()->DoLabel(&r, pCaption, 48.0f, 0, -1);
Graphics()->TextureClear(); Graphics()->TextureClear();
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
Graphics()->SetColor(1,1,1,0.75f); Graphics()->SetColor(1, 1, 1, 0.75f);
RenderTools()->DrawRoundRect(x+40, y+h-75, (w-80)*Percent, 25, 5.0f); RenderTools()->DrawRoundRect(x + 40, y + h - 75, (w - 80) * Percent, 25, 5.0f);
Graphics()->QuadsEnd(); Graphics()->QuadsEnd();
Graphics()->Swap(); Graphics()->Swap();
@ -1053,10 +1051,10 @@ void CMenus::RenderNews(CUIRect MainView)
while((pStr = str_next_token(pStr, "\n", aLine, sizeof(aLine)))) while((pStr = str_next_token(pStr, "\n", aLine, sizeof(aLine))))
{ {
const int Len = str_length(aLine); const int Len = str_length(aLine);
if(Len > 0 && aLine[0] == '|' && aLine[Len-1] == '|') if(Len > 0 && aLine[0] == '|' && aLine[Len - 1] == '|')
{ {
MainView.HSplitTop(30.0f, &Label, &MainView); MainView.HSplitTop(30.0f, &Label, &MainView);
aLine[Len-1] = '\0'; aLine[Len - 1] = '\0';
UI()->DoLabelScaled(&Label, aLine + 1, 20.0f, -1); UI()->DoLabelScaled(&Label, aLine + 1, 20.0f, -1);
} }
else else
@ -1309,7 +1307,7 @@ int CMenus::Render()
pExtraText = ""; pExtraText = "";
ExtraAlign = -1; ExtraAlign = -1;
} }
#if defined(CONF_VIDEORECORDER) #if defined(CONF_VIDEORECORDER)
else if(m_Popup == POPUP_RENDER_DEMO) else if(m_Popup == POPUP_RENDER_DEMO)
{ {
pTitle = Localize("Render demo"); pTitle = Localize("Render demo");
@ -1322,7 +1320,7 @@ int CMenus::Render()
pExtraText = Localize("File already exists, do you want to overwrite it?"); pExtraText = Localize("File already exists, do you want to overwrite it?");
ExtraAlign = -1; ExtraAlign = -1;
} }
#endif #endif
else if(m_Popup == POPUP_REMOVE_FRIEND) else if(m_Popup == POPUP_REMOVE_FRIEND)
{ {
pTitle = Localize("Remove friend"); pTitle = Localize("Remove friend");
@ -1389,23 +1387,23 @@ int CMenus::Render()
Box = Screen; Box = Screen;
if(m_Popup != POPUP_FIRST_LAUNCH) if(m_Popup != POPUP_FIRST_LAUNCH)
{ {
Box.VMargin(150.0f/UI()->Scale(), &Box); Box.VMargin(150.0f / UI()->Scale(), &Box);
Box.HMargin(150.0f/UI()->Scale(), &Box); Box.HMargin(150.0f / UI()->Scale(), &Box);
} }
// render the box // render the box
RenderTools()->DrawUIRect(&Box, BgColor, CUI::CORNER_ALL, 15.0f); RenderTools()->DrawUIRect(&Box, BgColor, CUI::CORNER_ALL, 15.0f);
Box.HSplitTop(20.f/UI()->Scale(), &Part, &Box); Box.HSplitTop(20.f / UI()->Scale(), &Part, &Box);
Box.HSplitTop(24.f/UI()->Scale(), &Part, &Box); Box.HSplitTop(24.f / UI()->Scale(), &Part, &Box);
Part.VMargin(20.f/UI()->Scale(), &Part); Part.VMargin(20.f / UI()->Scale(), &Part);
if(TextRender()->TextWidth(0, 24.f, pTitle, -1, -1.0f) > Part.w) if(TextRender()->TextWidth(0, 24.f, pTitle, -1, -1.0f) > Part.w)
UI()->DoLabelScaled(&Part, pTitle, 24.f, -1, (int)Part.w); UI()->DoLabelScaled(&Part, pTitle, 24.f, -1, (int)Part.w);
else else
UI()->DoLabelScaled(&Part, pTitle, 24.f, 0); UI()->DoLabelScaled(&Part, pTitle, 24.f, 0);
Box.HSplitTop(20.f/UI()->Scale(), &Part, &Box); Box.HSplitTop(20.f / UI()->Scale(), &Part, &Box);
Box.HSplitTop(24.f/UI()->Scale(), &Part, &Box); Box.HSplitTop(24.f / UI()->Scale(), &Part, &Box);
Part.VMargin(20.f/UI()->Scale(), &Part); Part.VMargin(20.f / UI()->Scale(), &Part);
float FontSize = m_Popup == POPUP_FIRST_LAUNCH ? 16.0f : 20.f; float FontSize = m_Popup == POPUP_FIRST_LAUNCH ? 16.0f : 20.f;
@ -1426,12 +1424,12 @@ int CMenus::Render()
Box.HSplitBottom(24.f, &Box, &Part); Box.HSplitBottom(24.f, &Box, &Part);
// additional info // additional info
Box.VMargin(20.f/UI()->Scale(), &Box); Box.VMargin(20.f / UI()->Scale(), &Box);
if(m_pClient->Editor()->HasUnsavedData()) if(m_pClient->Editor()->HasUnsavedData())
{ {
char aBuf[256]; char aBuf[256];
str_format(aBuf, sizeof(aBuf), "%s\n%s", Localize("There's an unsaved map in the editor, you might want to save it before you quit the game."), Localize("Quit anyway?")); str_format(aBuf, sizeof(aBuf), "%s\n%s", Localize("There's an unsaved map in the editor, you might want to save it before you quit the game."), Localize("Quit anyway?"));
UI()->DoLabelScaled(&Box, aBuf, 20.f, -1, Part.w-20.0f); UI()->DoLabelScaled(&Box, aBuf, 20.f, -1, Part.w - 20.0f);
} }
// buttons // buttons
@ -1545,7 +1543,7 @@ int CMenus::Render()
if(Client()->MapDownloadTotalsize() > 0) if(Client()->MapDownloadTotalsize() > 0)
{ {
int64 Now = time_get(); int64 Now = time_get();
if(Now-m_DownloadLastCheckTime >= time_freq()) if(Now - m_DownloadLastCheckTime >= time_freq())
{ {
if(m_DownloadLastCheckSize > Client()->MapDownloadAmount()) if(m_DownloadLastCheckSize > Client()->MapDownloadAmount())
{ {
@ -1554,10 +1552,10 @@ int CMenus::Render()
} }
// update download speed // update download speed
float Diff = (Client()->MapDownloadAmount()-m_DownloadLastCheckSize)/((int)((Now-m_DownloadLastCheckTime)/time_freq())); float Diff = (Client()->MapDownloadAmount() - m_DownloadLastCheckSize) / ((int)((Now - m_DownloadLastCheckTime) / time_freq()));
float StartDiff = m_DownloadLastCheckSize-0.0f; float StartDiff = m_DownloadLastCheckSize - 0.0f;
if(StartDiff+Diff > 0.0f) if(StartDiff + Diff > 0.0f)
m_DownloadSpeed = (Diff/(StartDiff+Diff))*(Diff/1.0f) + (StartDiff/(Diff+StartDiff))*m_DownloadSpeed; m_DownloadSpeed = (Diff / (StartDiff + Diff)) * (Diff / 1.0f) + (StartDiff / (Diff + StartDiff)) * m_DownloadSpeed;
else else
m_DownloadSpeed = 0.0f; m_DownloadSpeed = 0.0f;
m_DownloadLastCheckTime = Now; m_DownloadLastCheckTime = Now;
@ -1566,11 +1564,11 @@ int CMenus::Render()
Box.HSplitTop(64.f, 0, &Box); Box.HSplitTop(64.f, 0, &Box);
Box.HSplitTop(24.f, &Part, &Box); Box.HSplitTop(24.f, &Part, &Box);
str_format(aBuf, sizeof(aBuf), "%d/%d KiB (%.1f KiB/s)", Client()->MapDownloadAmount()/1024, Client()->MapDownloadTotalsize()/1024, m_DownloadSpeed/1024.0f); str_format(aBuf, sizeof(aBuf), "%d/%d KiB (%.1f KiB/s)", Client()->MapDownloadAmount() / 1024, Client()->MapDownloadTotalsize() / 1024, m_DownloadSpeed / 1024.0f);
UI()->DoLabel(&Part, aBuf, 20.f, 0, -1); UI()->DoLabel(&Part, aBuf, 20.f, 0, -1);
// time left // time left
int TimeLeft = maximum(1, m_DownloadSpeed > 0.0f ? static_cast<int>((Client()->MapDownloadTotalsize()-Client()->MapDownloadAmount())/m_DownloadSpeed) : 1); int TimeLeft = maximum(1, m_DownloadSpeed > 0.0f ? static_cast<int>((Client()->MapDownloadTotalsize() - Client()->MapDownloadAmount()) / m_DownloadSpeed) : 1);
if(TimeLeft >= 60) if(TimeLeft >= 60)
{ {
TimeLeft /= 60; TimeLeft /= 60;
@ -1589,7 +1587,7 @@ int CMenus::Render()
Box.HSplitTop(24.f, &Part, &Box); Box.HSplitTop(24.f, &Part, &Box);
Part.VMargin(40.0f, &Part); Part.VMargin(40.0f, &Part);
RenderTools()->DrawUIRect(&Part, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 5.0f); RenderTools()->DrawUIRect(&Part, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 5.0f);
Part.w = maximum(10.0f, (Part.w*Client()->MapDownloadAmount())/Client()->MapDownloadTotalsize()); Part.w = maximum(10.0f, (Part.w * Client()->MapDownloadAmount()) / Client()->MapDownloadTotalsize());
RenderTools()->DrawUIRect(&Part, ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f), CUI::CORNER_ALL, 5.0f); RenderTools()->DrawUIRect(&Part, ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f), CUI::CORNER_ALL, 5.0f);
} }
} }
@ -1641,8 +1639,8 @@ int CMenus::Render()
Item.m_Rect.Margin(5.0f, &Item.m_Rect); Item.m_Rect.Margin(5.0f, &Item.m_Rect);
Item.m_Rect.HSplitBottom(10.0f, &Item.m_Rect, &Label); Item.m_Rect.HSplitBottom(10.0f, &Item.m_Rect, &Label);
float OldWidth = Item.m_Rect.w; float OldWidth = Item.m_Rect.w;
Item.m_Rect.w = Item.m_Rect.h*2; Item.m_Rect.w = Item.m_Rect.h * 2;
Item.m_Rect.x += (OldWidth-Item.m_Rect.w)/ 2.0f; Item.m_Rect.x += (OldWidth - Item.m_Rect.w) / 2.0f;
ColorRGBA Color(1.0f, 1.0f, 1.0f, 1.0f); ColorRGBA Color(1.0f, 1.0f, 1.0f, 1.0f);
m_pClient->m_pCountryFlags->Render(pEntry->m_CountryCode, &Color, Item.m_Rect.x, Item.m_Rect.y, Item.m_Rect.w, Item.m_Rect.h); m_pClient->m_pCountryFlags->Render(pEntry->m_CountryCode, &Color, Item.m_Rect.x, Item.m_Rect.y, Item.m_Rect.w, Item.m_Rect.h);
UI()->DoLabel(&Label, pEntry->m_aCountryCodeString, 10.0f, 0); UI()->DoLabel(&Label, pEntry->m_aCountryCodeString, 10.0f, 0);
@ -1732,7 +1730,7 @@ int CMenus::Render()
str_format(aBufOld, sizeof(aBufOld), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename); str_format(aBufOld, sizeof(aBufOld), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename);
int Length = str_length(m_aCurrentDemoFile); int Length = str_length(m_aCurrentDemoFile);
char aBufNew[512]; char aBufNew[512];
if(Length <= 4 || m_aCurrentDemoFile[Length-5] != '.' || str_comp_nocase(m_aCurrentDemoFile+Length-4, "demo")) if(Length <= 4 || m_aCurrentDemoFile[Length - 5] != '.' || str_comp_nocase(m_aCurrentDemoFile + Length - 4, "demo"))
str_format(aBufNew, sizeof(aBufNew), "%s/%s.demo", m_aCurrentDemoFolder, m_aCurrentDemoFile); str_format(aBufNew, sizeof(aBufNew), "%s/%s.demo", m_aCurrentDemoFolder, m_aCurrentDemoFile);
else else
str_format(aBufNew, sizeof(aBufNew), "%s/%s", m_aCurrentDemoFolder, m_aCurrentDemoFile); str_format(aBufNew, sizeof(aBufNew), "%s/%s", m_aCurrentDemoFolder, m_aCurrentDemoFile);
@ -1790,7 +1788,7 @@ int CMenus::Render()
str_format(aBufOld, sizeof(aBufOld), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename); str_format(aBufOld, sizeof(aBufOld), "%s/%s", m_aCurrentDemoFolder, m_lDemos[m_DemolistSelectedIndex].m_aFilename);
int Length = str_length(m_aCurrentDemoFile); int Length = str_length(m_aCurrentDemoFile);
char aBufNew[512]; char aBufNew[512];
if(Length <= 3 || m_aCurrentDemoFile[Length-4] != '.' || str_comp_nocase(m_aCurrentDemoFile+Length-3, "mp4")) if(Length <= 3 || m_aCurrentDemoFile[Length - 4] != '.' || str_comp_nocase(m_aCurrentDemoFile + Length - 3, "mp4"))
str_format(aBufNew, sizeof(aBufNew), "%s.mp4", m_aCurrentDemoFile); str_format(aBufNew, sizeof(aBufNew), "%s.mp4", m_aCurrentDemoFile);
else else
str_format(aBufNew, sizeof(aBufNew), "%s", m_aCurrentDemoFile); str_format(aBufNew, sizeof(aBufNew), "%s", m_aCurrentDemoFile);
@ -1855,9 +1853,9 @@ int CMenus::Render()
UI()->DoLabel(&Part, aBuffer, 12.8f, -1); UI()->DoLabel(&Part, aBuffer, 12.8f, -1);
if(IncDemoSpeed) if(IncDemoSpeed)
m_Speed = clamp(m_Speed + 1, 0, (int)(sizeof(g_aSpeeds)/sizeof(g_aSpeeds[0])-1)); m_Speed = clamp(m_Speed + 1, 0, (int)(sizeof(g_aSpeeds) / sizeof(g_aSpeeds[0]) - 1));
else if(DecDemoSpeed) else if(DecDemoSpeed)
m_Speed = clamp(m_Speed - 1, 0, (int)(sizeof(g_aSpeeds)/sizeof(g_aSpeeds[0])-1)); m_Speed = clamp(m_Speed - 1, 0, (int)(sizeof(g_aSpeeds) / sizeof(g_aSpeeds[0]) - 1));
Part.VSplitLeft(107.0f, 0, &Part); Part.VSplitLeft(107.0f, 0, &Part);
Part.VSplitLeft(Button.h, &Button, &Part); Part.VSplitLeft(Button.h, &Button, &Part);
@ -2015,7 +2013,6 @@ int CMenus::Render()
return 0; return 0;
} }
void CMenus::SetActive(bool Active) void CMenus::SetActive(bool Active)
{ {
if(Active != m_MenuActive) if(Active != m_MenuActive)
@ -2079,7 +2076,7 @@ bool CMenus::OnInput(IInput::CEvent e)
m_LastInput = time_get(); m_LastInput = time_get();
// special handle esc and enter for popup purposes // special handle esc and enter for popup purposes
if(e.m_Flags&IInput::FLAG_PRESS) if(e.m_Flags & IInput::FLAG_PRESS)
{ {
if(e.m_Key == KEY_ESCAPE) if(e.m_Key == KEY_ESCAPE)
{ {
@ -2092,7 +2089,7 @@ bool CMenus::OnInput(IInput::CEvent e)
if(IsActive()) if(IsActive())
{ {
if(e.m_Flags&IInput::FLAG_PRESS) if(e.m_Flags & IInput::FLAG_PRESS)
{ {
// special for popups // special for popups
if(e.m_Key == KEY_RETURN || e.m_Key == KEY_KP_ENTER) if(e.m_Key == KEY_RETURN || e.m_Key == KEY_KP_ENTER)
@ -2196,27 +2193,30 @@ void CMenus::OnRender()
ms_GuiColor.a * 0.8f); ms_GuiColor.a * 0.8f);
ms_ColorTabbarActiveIngame = ColorRGBA( ms_ColorTabbarActiveIngame = ColorRGBA(
ms_GuiColor.r*ColorIngameAcaleA, ms_GuiColor.r * ColorIngameAcaleA,
ms_GuiColor.g*ColorIngameAcaleA, ms_GuiColor.g * ColorIngameAcaleA,
ms_GuiColor.b*ColorIngameAcaleA, ms_GuiColor.b * ColorIngameAcaleA,
ms_GuiColor.a); ms_GuiColor.a);
ms_ColorTabbarHoverIngame = ColorRGBA(1, 1, 1, 0.75f); ms_ColorTabbarHoverIngame = ColorRGBA(1, 1, 1, 0.75f);
// update the ui // update the ui
CUIRect *pScreen = UI()->Screen(); CUIRect *pScreen = UI()->Screen();
float mx = (m_MousePos.x/(float)Graphics()->ScreenWidth())*pScreen->w; float mx = (m_MousePos.x / (float)Graphics()->ScreenWidth()) * pScreen->w;
float my = (m_MousePos.y/(float)Graphics()->ScreenHeight())*pScreen->h; float my = (m_MousePos.y / (float)Graphics()->ScreenHeight()) * pScreen->h;
int Buttons = 0; int Buttons = 0;
if(m_UseMouseButtons) if(m_UseMouseButtons)
{ {
if(Input()->KeyIsPressed(KEY_MOUSE_1)) Buttons |= 1; if(Input()->KeyIsPressed(KEY_MOUSE_1))
if(Input()->KeyIsPressed(KEY_MOUSE_2)) Buttons |= 2; Buttons |= 1;
if(Input()->KeyIsPressed(KEY_MOUSE_3)) Buttons |= 4; if(Input()->KeyIsPressed(KEY_MOUSE_2))
Buttons |= 2;
if(Input()->KeyIsPressed(KEY_MOUSE_3))
Buttons |= 4;
} }
UI()->Update(mx,my,mx*3.0f,my*3.0f,Buttons); UI()->Update(mx, my, mx * 3.0f, my * 3.0f, Buttons);
// render // render
Render(); Render();
@ -2225,7 +2225,7 @@ void CMenus::OnRender()
Graphics()->WrapClamp(); Graphics()->WrapClamp();
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_CURSOR].m_Id); Graphics()->TextureSet(g_pData->m_aImages[IMAGE_CURSOR].m_Id);
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
Graphics()->SetColor(1,1,1,1); Graphics()->SetColor(1, 1, 1, 1);
IGraphics::CQuadItem QuadItem(mx, my, 24, 24); IGraphics::CQuadItem QuadItem(mx, my, 24, 24);
Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsDrawTL(&QuadItem, 1);
Graphics()->QuadsEnd(); Graphics()->QuadsEnd();
@ -2254,50 +2254,52 @@ void CMenus::RenderBackground()
{ {
Graphics()->BlendNormal(); Graphics()->BlendNormal();
float sw = 300*Graphics()->ScreenAspect(); float sw = 300 * Graphics()->ScreenAspect();
float sh = 300; float sh = 300;
Graphics()->MapScreen(0, 0, sw, sh); Graphics()->MapScreen(0, 0, sw, sh);
// render background color // render background color
Graphics()->TextureClear(); Graphics()->TextureClear();
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
ColorRGBA Bottom(ms_GuiColor.r, ms_GuiColor.g, ms_GuiColor.b, 1.0f); ColorRGBA Bottom(ms_GuiColor.r, ms_GuiColor.g, ms_GuiColor.b, 1.0f);
ColorRGBA Top(ms_GuiColor.r, ms_GuiColor.g, ms_GuiColor.b, 1.0f); ColorRGBA Top(ms_GuiColor.r, ms_GuiColor.g, ms_GuiColor.b, 1.0f);
IGraphics::CColorVertex Array[4] = { IGraphics::CColorVertex Array[4] = {
IGraphics::CColorVertex(0, Top.r, Top.g, Top.b, Top.a), IGraphics::CColorVertex(0, Top.r, Top.g, Top.b, Top.a),
IGraphics::CColorVertex(1, 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(2, Bottom.r, Bottom.g, Bottom.b, Bottom.a),
IGraphics::CColorVertex(3, Bottom.r, Bottom.g, Bottom.b, Bottom.a)}; IGraphics::CColorVertex(3, Bottom.r, Bottom.g, Bottom.b, Bottom.a)};
Graphics()->SetColorVertex(Array, 4); Graphics()->SetColorVertex(Array, 4);
IGraphics::CQuadItem QuadItem(0, 0, sw, sh); IGraphics::CQuadItem QuadItem(0, 0, sw, sh);
Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsDrawTL(&QuadItem, 1);
Graphics()->QuadsEnd(); Graphics()->QuadsEnd();
// render the tiles // render the tiles
Graphics()->TextureClear(); Graphics()->TextureClear();
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
float Size = 15.0f; float Size = 15.0f;
float OffsetTime = fmod(LocalTime()*0.15f, 2.0f); float OffsetTime = fmod(LocalTime() * 0.15f, 2.0f);
for(int y = -2; y < (int)(sw/Size); y++) for(int y = -2; y < (int)(sw / Size); y++)
for(int x = -2; x < (int)(sh/Size); x++) for(int x = -2; x < (int)(sh / Size); x++)
{ {
Graphics()->SetColor(0,0,0,0.045f); Graphics()->SetColor(0, 0, 0, 0.045f);
IGraphics::CQuadItem QuadItem((x-OffsetTime)*Size*2+(y&1)*Size, (y+OffsetTime)*Size, Size, Size); IGraphics::CQuadItem QuadItem((x - OffsetTime) * Size * 2 + (y & 1) * Size, (y + OffsetTime) * Size, Size, Size);
Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsDrawTL(&QuadItem, 1);
} }
Graphics()->QuadsEnd(); Graphics()->QuadsEnd();
// render border fade // render border fade
Graphics()->TextureSet(m_TextureBlob); Graphics()->TextureSet(m_TextureBlob);
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
Graphics()->SetColor(1,1,1,1); Graphics()->SetColor(1, 1, 1, 1);
QuadItem = IGraphics::CQuadItem(-100, -100, sw+200, sh+200); QuadItem = IGraphics::CQuadItem(-100, -100, sw + 200, sh + 200);
Graphics()->QuadsDrawTL(&QuadItem, 1); Graphics()->QuadsDrawTL(&QuadItem, 1);
Graphics()->QuadsEnd(); Graphics()->QuadsEnd();
// restore screen // restore screen
{CUIRect Screen = *UI()->Screen(); {
Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);} CUIRect Screen = *UI()->Screen();
Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);
}
} }
bool CMenus::CheckHotKey(int Key) const bool CMenus::CheckHotKey(int Key) const
@ -2327,7 +2329,7 @@ void CMenus::RenderUpdating(const char *pCaption, int current, int total)
// make sure that we don't render for each little thing we load // make sure that we don't render for each little thing we load
// because that will slow down loading if we have vsync // because that will slow down loading if we have vsync
static int64 LastLoadRender = 0; static int64 LastLoadRender = 0;
if(time_get()-LastLoadRender < time_freq()/60) if(time_get() - LastLoadRender < time_freq() / 60)
return; return;
LastLoadRender = time_get(); LastLoadRender = time_get();
@ -2341,31 +2343,31 @@ void CMenus::RenderUpdating(const char *pCaption, int current, int total)
float w = 700; float w = 700;
float h = 200; float h = 200;
float x = Screen.w/2-w/2; float x = Screen.w / 2 - w / 2;
float y = Screen.h/2-h/2; float y = Screen.h / 2 - h / 2;
Graphics()->TextureClear(); Graphics()->TextureClear();
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
Graphics()->SetColor(0,0,0,0.50f); Graphics()->SetColor(0, 0, 0, 0.50f);
RenderTools()->DrawRoundRect(0, y, Screen.w, h, 0.0f); RenderTools()->DrawRoundRect(0, y, Screen.w, h, 0.0f);
Graphics()->QuadsEnd(); Graphics()->QuadsEnd();
CUIRect r; CUIRect r;
r.x = x; r.x = x;
r.y = y+20; r.y = y + 20;
r.w = w; r.w = w;
r.h = h; r.h = h;
UI()->DoLabel(&r, Localize(pCaption), 32.0f, 0, -1); UI()->DoLabel(&r, Localize(pCaption), 32.0f, 0, -1);
if(total>0) if(total > 0)
{ {
float Percent = current/(float)total; float Percent = current / (float)total;
Graphics()->TextureClear(); Graphics()->TextureClear();
Graphics()->QuadsBegin(); Graphics()->QuadsBegin();
Graphics()->SetColor(0.15f,0.15f,0.15f,0.75f); Graphics()->SetColor(0.15f, 0.15f, 0.15f, 0.75f);
RenderTools()->DrawRoundRect(x+40, y+h-75, w-80, 30, 5.0f); RenderTools()->DrawRoundRect(x + 40, y + h - 75, w - 80, 30, 5.0f);
Graphics()->SetColor(1,1,1,0.75f); Graphics()->SetColor(1, 1, 1, 0.75f);
RenderTools()->DrawRoundRect(x+45, y+h-70, (w-85)*Percent, 20, 5.0f); RenderTools()->DrawRoundRect(x + 45, y + h - 70, (w - 85) * Percent, 20, 5.0f);
Graphics()->QuadsEnd(); Graphics()->QuadsEnd();
} }
@ -2398,12 +2400,12 @@ int CMenus::MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser
int Step = Info.m_Format == CImageInfo::FORMAT_RGBA ? 4 : 3; int Step = Info.m_Format == CImageInfo::FORMAT_RGBA ? 4 : 3;
// make the texture gray scale // make the texture gray scale
for(int i = 0; i < Info.m_Width*Info.m_Height; i++) for(int i = 0; i < Info.m_Width * Info.m_Height; i++)
{ {
int v = (d[i*Step]+d[i*Step+1]+d[i*Step+2])/3; int v = (d[i * Step] + d[i * Step + 1] + d[i * Step + 2]) / 3;
d[i*Step] = v; d[i * Step] = v;
d[i*Step+1] = v; d[i * Step + 1] = v;
d[i*Step+2] = v; d[i * Step + 2] = v;
} }
/* same grey like sinks /* same grey like sinks