136 changes: 73 additions & 63 deletions src/game/client/components/menus.cpp

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions src/game/client/components/menus.h
Expand Up @@ -21,21 +21,22 @@ class CMenusKeyBinder : public CComponent
bool m_TakeKey;
bool m_GotKey;
IInput::CEvent m_Key;
int m_Modifier;
CMenusKeyBinder();
virtual bool OnInput(IInput::CEvent Event);
};

class CMenus : public CComponent
{
static vec4 ms_GuiColor;
static vec4 ms_ColorTabbarInactiveOutgame;
static vec4 ms_ColorTabbarActiveOutgame;
static vec4 ms_ColorTabbarInactiveIngame;
static vec4 ms_ColorTabbarActiveIngame;
static vec4 ms_ColorTabbarInactive;
static vec4 ms_ColorTabbarActive;
static ColorRGBA ms_GuiColor;
static ColorRGBA ms_ColorTabbarInactiveOutgame;
static ColorRGBA ms_ColorTabbarActiveOutgame;
static ColorRGBA ms_ColorTabbarInactiveIngame;
static ColorRGBA ms_ColorTabbarActiveIngame;
static ColorRGBA ms_ColorTabbarInactive;
static ColorRGBA ms_ColorTabbarActive;

vec4 ButtonColorMul(const void *pID);
float ButtonColorMul(const void *pID);


int DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
Expand Down Expand Up @@ -71,7 +72,7 @@ class CMenus : public CComponent
float DoScrollbarV(const void *pID, const CUIRect *pRect, float Current);
float DoScrollbarH(const void *pID, const CUIRect *pRect, float Current);
void DoButton_KeySelect(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
int DoKeyReader(void *pID, const CUIRect *pRect, int Key);
int DoKeyReader(void *pID, const CUIRect *pRect, int Key, int Modifier, int *NewModifier);

//static int ui_do_key_reader(void *id, const CUIRect *rect, int key);
void UiDoGetButtons(int Start, int Stop, CUIRect View, CUIRect ScopeView);
Expand Down Expand Up @@ -366,7 +367,7 @@ class CMenus : public CComponent
CGhostItem() : m_Slot(-1), m_Own(false) { m_aFilename[0] = 0; }

bool operator<(const CGhostItem &Other) { return m_Time < Other.m_Time; }

bool Active() const { return m_Slot != -1; }
bool HasFile() const { return m_aFilename[0]; }
};
Expand Down
90 changes: 40 additions & 50 deletions src/game/client/components/menus_browser.cpp
Expand Up @@ -31,7 +31,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
View.HSplitBottom(28.0f, &View, &Status);

// split of the scrollbar
RenderTools()->DrawUIRect(&Headers, vec4(1,1,1,0.25f), CUI::CORNER_T, 5.0f);
RenderTools()->DrawUIRect(&Headers, ColorRGBA(1,1,1,0.25f), CUI::CORNER_T, 5.0f);
Headers.VSplitRight(20.0f, &Headers, 0);

struct CColumn
Expand Down Expand Up @@ -125,7 +125,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
}
}

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

CUIRect Scroll;
View.VSplitRight(15, &View, &Scroll);
Expand Down Expand Up @@ -184,8 +184,8 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
{
if(m_aInputEvents[i].m_Key == KEY_DOWN) NewIndex = m_SelectedIndex + 1;
else if(m_aInputEvents[i].m_Key == KEY_UP) NewIndex = m_SelectedIndex - 1;
else if(m_aInputEvents[i].m_Key == KEY_PAGEUP) NewIndex = max(m_SelectedIndex - 25, 0);
else if(m_aInputEvents[i].m_Key == KEY_PAGEDOWN) NewIndex = min(m_SelectedIndex + 25, NumServers - 1);
else if(m_aInputEvents[i].m_Key == KEY_PAGEUP) NewIndex = maximum(m_SelectedIndex - 25, 0);
else if(m_aInputEvents[i].m_Key == KEY_PAGEDOWN) NewIndex = minimum(m_SelectedIndex + 25, NumServers - 1);
else if(m_aInputEvents[i].m_Key == KEY_HOME) NewIndex = 0;
else if(m_aInputEvents[i].m_Key == KEY_END) NewIndex = NumServers - 1;
}
Expand Down Expand Up @@ -280,7 +280,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
{
CUIRect r = Row;
r.Margin(0.5f, &r);
RenderTools()->DrawUIRect(&r, vec4(1,1,1,0.5f), CUI::CORNER_ALL, 4.0f);
RenderTools()->DrawUIRect(&r, ColorRGBA(1,1,1,0.5f), CUI::CORNER_ALL, 4.0f);
}

// clip the selection
Expand Down Expand Up @@ -418,8 +418,8 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
str_format(aTemp, sizeof(aTemp), "%i", pItem->m_Latency);
if(g_Config.m_UiColorizePing)
{
vec3 rgb = HslToRgb(vec3((300.0f - clamp(pItem->m_Latency, 0, 300)) / 1000.0f, 1.0f, 0.5f));
TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.0f);
ColorRGBA rgb = color_cast<ColorRGBA>(ColorHSLA((300.0f - clamp(pItem->m_Latency, 0, 300)) / 1000.0f, 1.0f, 0.5f));
TextRender()->TextColor(rgb);
}

UI()->DoLabelScaled(&Button, aTemp, 12.0f, 1);
Expand All @@ -439,25 +439,25 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)

if(g_Config.m_UiColorizeGametype)
{
vec3 hsl = vec3(1.0f, 1.0f, 1.0f);
ColorHSLA hsl = ColorHSLA(1.0f, 1.0f, 1.0f);

if(IsVanilla(pItem))
hsl = vec3(0.33f, 1.0f, 0.75f);
hsl = ColorHSLA(0.33f, 1.0f, 0.75f);
else if(IsCatch(pItem))
hsl = vec3(0.17f, 1.0f, 0.75f);
hsl = ColorHSLA(0.17f, 1.0f, 0.75f);
else if(IsInsta(pItem))
hsl = vec3(0.00f, 1.0f, 0.75f);
hsl = ColorHSLA(0.00f, 1.0f, 0.75f);
else if(IsFNG(pItem))
hsl = vec3(0.83f, 1.0f, 0.75f);
hsl = ColorHSLA(0.83f, 1.0f, 0.75f);
else if(IsDDNet(pItem))
hsl = vec3(0.58f, 1.0f, 0.75f);
hsl = ColorHSLA(0.58f, 1.0f, 0.75f);
else if(IsDDRace(pItem))
hsl = vec3(0.75f, 1.0f, 0.75f);
hsl = ColorHSLA(0.75f, 1.0f, 0.75f);
else if(IsRace(pItem))
hsl = vec3(0.46f, 1.0f, 0.75f);
hsl = ColorHSLA(0.46f, 1.0f, 0.75f);

vec3 rgb = HslToRgb(hsl);
TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.0f);
ColorRGBA rgb = color_cast<ColorRGBA>(hsl);
TextRender()->TextColor(rgb);
TextRender()->TextEx(&Cursor, pItem->m_aGameType, -1);
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
}
Expand All @@ -478,7 +478,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
Client()->Connect(g_Config.m_UiServerAddress);
}

RenderTools()->DrawUIRect(&Status, vec4(1,1,1,0.25f), CUI::CORNER_B, 5.0f);
RenderTools()->DrawUIRect(&Status, ColorRGBA(1,1,1,0.25f), CUI::CORNER_B, 5.0f);
Status.Margin(5.0f, &Status);

CUIRect QuickSearch, QuickExclude, Button, Status2, Status3;
Expand Down Expand Up @@ -540,8 +540,8 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)

// server filter
ServerFilter.HSplitTop(ms_ListheaderHeight, &FilterHeader, &ServerFilter);
RenderTools()->DrawUIRect(&FilterHeader, vec4(1,1,1,0.25f), CUI::CORNER_T, 4.0f);
RenderTools()->DrawUIRect(&ServerFilter, vec4(0,0,0,0.15f), CUI::CORNER_B, 4.0f);
RenderTools()->DrawUIRect(&FilterHeader, ColorRGBA(1,1,1,0.25f), CUI::CORNER_T, 4.0f);
RenderTools()->DrawUIRect(&ServerFilter, ColorRGBA(0,0,0,0.15f), CUI::CORNER_B, 4.0f);
UI()->DoLabelScaled(&FilterHeader, Localize("Server filter"), FontSize+2.0f, 0);
CUIRect Button, Button2;

Expand Down Expand Up @@ -631,7 +631,7 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
float OldWidth = Rect.w;
Rect.w = Rect.h*2;
Rect.x += (OldWidth-Rect.w)/2.0f;
vec4 Color(1.0f, 1.0f, 1.0f, g_Config.m_BrFilterCountry?1.0f: 0.5f);
ColorRGBA Color(1.0f, 1.0f, 1.0f, g_Config.m_BrFilterCountry?1.0f: 0.5f);
m_pClient->m_pCountryFlags->Render(g_Config.m_BrFilterCountryIndex, &Color, Rect.x, Rect.y, Rect.w, Rect.h);

if(g_Config.m_BrFilterCountry && UI()->DoButtonLogic(&g_Config.m_BrFilterCountryIndex, "", 0, &Rect))
Expand Down Expand Up @@ -762,11 +762,7 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
ServerBrowser()->Refresh(ServerBrowser()->GetCurrentType());
}

vec4 Color(1.0f, 1.0f, 1.0f, 1.0f);

if(!Active)
Color.a = 0.2f;
TextRender()->TextColor(Color.r, Color.g, Color.b, Color.a);
TextRender()->TextColor(1.0f, 1.0f, 1.0f, Active ? 1.0f : 0.2f);
UI()->DoLabelScaled(&Rect, pName, FontSize, 0);
TextRender()->TextColor(1.0, 1.0, 1.0, 1.0f);
}
Expand All @@ -777,8 +773,6 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
char *pFilterExcludeCountries = Network == IServerBrowser::NETWORK_DDNET ? g_Config.m_BrFilterExcludeCountries : g_Config.m_BrFilterExcludeCountriesKoG;
ServerFilter.HSplitTop(17.0f, &ServerFilter, &ServerFilter);

vec4 Color(1.0f, 1.0f, 1.0f, 1.0f);

const float FlagWidth = 40.0f;
const float FlagHeight = 20.0f;

Expand Down Expand Up @@ -844,11 +838,7 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
ServerBrowser()->Refresh(ServerBrowser()->GetCurrentType());
}

vec4 Color(1.0f, 1.0f, 1.0f, 1.0f);

if(!Active)
Color.a = 0.2f;

ColorRGBA Color(1.0f, 1.0f, 1.0f, Active ? 1.0f : 0.2f);
m_pClient->m_pCountryFlags->Render(FlagID, &Color, Pos.x, Pos.y, FlagWidth, FlagHeight);
}
}
Expand Down Expand Up @@ -897,8 +887,8 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
CTextCursor Cursor;
const float FontSize = 12.0f;
ServerDetails.HSplitTop(ms_ListheaderHeight, &ServerHeader, &ServerDetails);
RenderTools()->DrawUIRect(&ServerHeader, vec4(1,1,1,0.25f), CUI::CORNER_T, 4.0f);
RenderTools()->DrawUIRect(&ServerDetails, vec4(0,0,0,0.15f), CUI::CORNER_B, 4.0f);
RenderTools()->DrawUIRect(&ServerHeader, ColorRGBA(1,1,1,0.25f), CUI::CORNER_T, 4.0f);
RenderTools()->DrawUIRect(&ServerDetails, ColorRGBA(0,0,0,0.15f), CUI::CORNER_B, 4.0f);
UI()->DoLabelScaled(&ServerHeader, Localize("Server details"), FontSize+2.0f, 0);

if(pSelectedServer)
Expand Down Expand Up @@ -986,10 +976,10 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
Client()->ServerBrowserUpdate();
}

vec4 Colour = pSelectedServer->m_aClients[i].m_FriendState == IFriends::FRIEND_NO ?
vec4(1.0f, 1.0f, 1.0f, (i%2+1)*0.05f) :
vec4(0.5f, 1.0f, 0.5f, 0.15f+(i%2+1)*0.05f);
RenderTools()->DrawUIRect(&Name, Colour, CUI::CORNER_ALL, 4.0f);
ColorRGBA Color = pSelectedServer->m_aClients[i].m_FriendState == IFriends::FRIEND_NO ?
ColorRGBA(1.0f, 1.0f, 1.0f, (i%2+1)*0.05f) :
ColorRGBA(0.5f, 1.0f, 0.5f, 0.15f+(i%2+1)*0.05f);
RenderTools()->DrawUIRect(&Name, Color, CUI::CORNER_ALL, 4.0f);
Name.VSplitLeft(5.0f, 0, &Name);
Name.VSplitLeft(34.0f, &Score, &Name);
Name.VSplitRight(34.0f, &Name, &Flag);
Expand Down Expand Up @@ -1065,8 +1055,8 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
TextRender()->TextEx(&Cursor, pClan, -1);

// flag
vec4 Color(1.0f, 1.0f, 1.0f, 0.5f);
m_pClient->m_pCountryFlags->Render(pSelectedServer->m_aClients[i].m_Country, &Color, Flag.x, Flag.y, Flag.w, Flag.h);
ColorRGBA FColor(1.0f, 1.0f, 1.0f, 0.5f);
m_pClient->m_pCountryFlags->Render(pSelectedServer->m_aClients[i].m_Country, &FColor, Flag.x, Flag.y, Flag.w, Flag.h);
}

UiDoListboxEnd(&s_ScrollValue, 0);
Expand Down Expand Up @@ -1100,8 +1090,8 @@ void CMenus::RenderServerbrowserFriends(CUIRect View)

// header
ServerFriends.HSplitTop(ms_ListheaderHeight, &FilterHeader, &ServerFriends);
RenderTools()->DrawUIRect(&FilterHeader, vec4(1,1,1,0.25f), CUI::CORNER_T, 4.0f);
RenderTools()->DrawUIRect(&ServerFriends, vec4(0,0,0,0.15f), 0, 4.0f);
RenderTools()->DrawUIRect(&FilterHeader, ColorRGBA(1,1,1,0.25f), CUI::CORNER_T, 4.0f);
RenderTools()->DrawUIRect(&ServerFriends, ColorRGBA(0,0,0,0.15f), 0, 4.0f);
UI()->DoLabelScaled(&FilterHeader, Localize("Friends"), FontSize+4.0f, 0);
CUIRect Button, List;

Expand All @@ -1125,14 +1115,14 @@ void CMenus::RenderServerbrowserFriends(CUIRect View)
Item.m_Rect.Margin(1.5f, &Item.m_Rect);
CUIRect OnState;
Item.m_Rect.VSplitRight(30.0f, &Item.m_Rect, &OnState);
RenderTools()->DrawUIRect(&Item.m_Rect, vec4(1.0f, 1.0f, 1.0f, 0.1f), CUI::CORNER_L, 4.0f);
RenderTools()->DrawUIRect(&Item.m_Rect, ColorRGBA(1.0f, 1.0f, 1.0f, 0.1f), CUI::CORNER_L, 4.0f);

Item.m_Rect.VMargin(2.5f, &Item.m_Rect);
Item.m_Rect.HSplitTop(12.0f, &Item.m_Rect, &Button);
UI()->DoLabelScaled(&Item.m_Rect, m_lFriends[i].m_pFriendInfo->m_aName, FontSize, -1);
UI()->DoLabelScaled(&Button, m_lFriends[i].m_pFriendInfo->m_aClan, FontSize, -1);

RenderTools()->DrawUIRect(&OnState, m_lFriends[i].m_NumFound ? vec4(0.0f, 1.0f, 0.0f, 0.25f) : vec4(1.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_R, 4.0f);
RenderTools()->DrawUIRect(&OnState, m_lFriends[i].m_NumFound ? ColorRGBA(0.0f, 1.0f, 0.0f, 0.25f) : ColorRGBA(1.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_R, 4.0f);
OnState.HMargin((OnState.h-FontSize)/3, &OnState);
OnState.VMargin(5.0f, &OnState);
char aBuf[64];
Expand Down Expand Up @@ -1256,10 +1246,10 @@ void CMenus::RenderServerbrowser(CUIRect MainView)
TabBar.HSplitTop(20.0f, &TabButton1, &TabBar);
TabBar.HSplitTop(2.5f, 0, &TabBar);
TabBar.HSplitTop(20.0f, &TabButton2, 0);
vec4 Active = ms_ColorTabbarActive;
vec4 InActive = ms_ColorTabbarInactive;
ms_ColorTabbarActive = vec4(0.0f, 0.0f, 0.0f, 0.3f);
ms_ColorTabbarInactive = vec4(0.0f, 0.0f, 0.0f, 0.15f);
ColorRGBA Active = ms_ColorTabbarActive;
ColorRGBA InActive = ms_ColorTabbarInactive;
ms_ColorTabbarActive = ColorRGBA(0.0f, 0.0f, 0.0f, 0.3f);
ms_ColorTabbarInactive = ColorRGBA(0.0f, 0.0f, 0.0f, 0.15f);

static int s_FiltersTab = 0;
if(DoButton_MenuTab(&s_FiltersTab, Localize("Filter"), ToolboxPage==0, &TabButton0, CUI::CORNER_L))
Expand All @@ -1280,7 +1270,7 @@ void CMenus::RenderServerbrowser(CUIRect MainView)

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


if(ToolboxPage == 0)
Expand Down
38 changes: 19 additions & 19 deletions src/game/client/components/menus_demo.cpp
Expand Up @@ -25,14 +25,14 @@

int CMenus::DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
{
RenderTools()->DrawUIRect(pRect, vec4(1,1,1, Checked ? 0.10f : 0.5f)*ButtonColorMul(pID), CUI::CORNER_ALL, 5.0f);
RenderTools()->DrawUIRect(pRect, ColorRGBA(1,1,1, (Checked ? 0.10f : 0.5f)*ButtonColorMul(pID)), CUI::CORNER_ALL, 5.0f);
UI()->DoLabel(pRect, pText, 14.0f, 0);
return UI()->DoButtonLogic(pID, pText, Checked, pRect);
}

int CMenus::DoButton_Sprite(const void *pID, int ImageID, int SpriteID, int Checked, const CUIRect *pRect, int Corners)
{
RenderTools()->DrawUIRect(pRect, Checked ? vec4(1.0f, 1.0f, 1.0f, 0.10f) : vec4(1.0f, 1.0f, 1.0f, 0.5f)*ButtonColorMul(pID), Corners, 5.0f);
RenderTools()->DrawUIRect(pRect, ColorRGBA(1.0f, 1.0f, 1.0f, (Checked ? 0.10f : 0.5f)*ButtonColorMul(pID)), Corners, 5.0f);
Graphics()->TextureSet(g_pData->m_aImages[ImageID].m_Id);
Graphics()->QuadsBegin();
if(!Checked)
Expand Down Expand Up @@ -84,7 +84,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
Box.HMargin(150.0f/UI()->Scale(), &Box);

// render the box
RenderTools()->DrawUIRect(&Box, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 15.0f);
RenderTools()->DrawUIRect(&Box, ColorRGBA(0,0,0,0.5f), CUI::CORNER_ALL, 15.0f);

Box.HSplitTop(20.f/UI()->Scale(), &Part, &Box);
Box.HSplitTop(24.f/UI()->Scale(), &Part, &Box);
Expand Down Expand Up @@ -164,7 +164,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
}

// handle keyboard shortcuts independent of active menu
if(m_pClient->m_pGameConsole->IsClosed())
if(m_pClient->m_pGameConsole->IsClosed() && m_DemoPlayerState == DEMOPLAYER_NONE)
{
// increase/decrease speed
if(Input()->KeyPress(KEY_MOUSE_WHEEL_UP) || Input()->KeyPress(KEY_UP))
Expand Down Expand Up @@ -271,13 +271,13 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
char aBuffer[128];

// draw seek bar
RenderTools()->DrawUIRect(&SeekBar, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 5.0f);
RenderTools()->DrawUIRect(&SeekBar, ColorRGBA(0,0,0,0.5f), CUI::CORNER_ALL, 5.0f);

// draw filled bar
float Amount = CurrentTick/(float)TotalTicks;
CUIRect FilledBar = SeekBar;
FilledBar.w = 10.0f + (FilledBar.w-10.0f)*Amount;
RenderTools()->DrawUIRect(&FilledBar, vec4(1,1,1,0.5f), CUI::CORNER_ALL, 5.0f);
RenderTools()->DrawUIRect(&FilledBar, ColorRGBA(1,1,1,0.5f), CUI::CORNER_ALL, 5.0f);

// draw markers
for(int i = 0; i < pInfo->m_NumTimelineMarkers; i++)
Expand Down Expand Up @@ -389,7 +389,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
// combined play and pause button
ButtonBar.VSplitLeft(ButtonbarHeight, &Button, &ButtonBar);
static int s_PlayPauseButton = 0;
if(DoButton_Sprite(&s_PlayPauseButton, IMAGE_DEMOBUTTONS, SPRITE_DEMOBUTTON_PAUSE, false, &Button, CUI::CORNER_ALL))
if(DoButton_Sprite(&s_PlayPauseButton, IMAGE_DEMOBUTTONS, pInfo->m_Paused ? SPRITE_DEMOBUTTON_PLAY : SPRITE_DEMOBUTTON_PAUSE, false, &Button, CUI::CORNER_ALL))
{
if(pInfo->m_Paused)
{
Expand Down Expand Up @@ -511,17 +511,17 @@ void CMenus::UiDoListboxStart(const void *pID, const CUIRect *pRect, float RowHe

// draw header
View.HSplitTop(ms_ListheaderHeight, &Header, &View);
RenderTools()->DrawUIRect(&Header, vec4(1,1,1,0.25f), CUI::CORNER_T, 5.0f);
RenderTools()->DrawUIRect(&Header, ColorRGBA(1,1,1,0.25f), CUI::CORNER_T, 5.0f);
UI()->DoLabel(&Header, pTitle, Header.h*ms_FontmodHeight, 0);

// draw footers
View.HSplitBottom(ms_ListheaderHeight, &View, &Footer);
RenderTools()->DrawUIRect(&Footer, vec4(1,1,1,0.25f), CUI::CORNER_B, 5.0f);
RenderTools()->DrawUIRect(&Footer, ColorRGBA(1,1,1,0.25f), CUI::CORNER_B, 5.0f);
Footer.VSplitLeft(10.0f, 0, &Footer);
UI()->DoLabel(&Footer, pBottomText, Header.h*ms_FontmodHeight, 0);

// background
RenderTools()->DrawUIRect(&View, vec4(0,0,0,0.15f), 0, 0);
RenderTools()->DrawUIRect(&View, ColorRGBA(0,0,0,0.15f), 0, 0);

// prepare the scroll
View.VSplitRight(15, &View, &Scroll);
Expand Down Expand Up @@ -659,8 +659,8 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(const void *pId, bool Selected,
{
if(m_aInputEvents[i].m_Key == KEY_DOWN) NewIndex = gs_ListBoxNewSelected + 1;
else if(m_aInputEvents[i].m_Key == KEY_UP) NewIndex = gs_ListBoxNewSelected - 1;
else if(m_aInputEvents[i].m_Key == KEY_PAGEUP) NewIndex = max(gs_ListBoxNewSelected - 20, 0);
else if(m_aInputEvents[i].m_Key == KEY_PAGEDOWN) NewIndex = min(gs_ListBoxNewSelected + 20, gs_ListBoxNumItems - 1);
else if(m_aInputEvents[i].m_Key == KEY_PAGEUP) NewIndex = maximum(gs_ListBoxNewSelected - 20, 0);
else if(m_aInputEvents[i].m_Key == KEY_PAGEDOWN) NewIndex = minimum(gs_ListBoxNewSelected + 20, gs_ListBoxNumItems - 1);
else if(m_aInputEvents[i].m_Key == KEY_HOME) NewIndex = 0;
else if(m_aInputEvents[i].m_Key == KEY_END) NewIndex = gs_ListBoxNumItems - 1;
}
Expand Down Expand Up @@ -698,7 +698,7 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(const void *pId, bool Selected,
//selected_index = i;
CUIRect r = Item.m_Rect;
r.Margin(1.5f, &r);
RenderTools()->DrawUIRect(&r, vec4(1,1,1,0.5f), CUI::CORNER_ALL, 4.0f);
RenderTools()->DrawUIRect(&r, ColorRGBA(1,1,1,0.5f), CUI::CORNER_ALL, 4.0f);
}

return Item;
Expand Down Expand Up @@ -736,7 +736,7 @@ int CMenus::DemolistFetchCallback(const char *pName, time_t Date, int IsDir, int
}
else
{
str_copy(Item.m_aName, pName, min(static_cast<int>(sizeof(Item.m_aName)), str_length(pName) - 4));
str_copy(Item.m_aName, pName, minimum(static_cast<int>(sizeof(Item.m_aName)), str_length(pName) - 4));
Item.m_InfosLoaded = false;
Item.m_Date = Date;
}
Expand Down Expand Up @@ -856,7 +856,7 @@ void CMenus::RenderDemoList(CUIRect MainView)
// render demo info
MainView.VMargin(5.0f, &MainView);
MainView.HSplitBottom(5.0f, &MainView, 0);
RenderTools()->DrawUIRect(&MainView, vec4(0,0,0,0.15f), CUI::CORNER_B, 4.0f);
RenderTools()->DrawUIRect(&MainView, ColorRGBA(0,0,0,0.15f), CUI::CORNER_B, 4.0f);
if(!m_DemolistSelectedIsDir && m_DemolistSelectedIndex >= 0 && m_lDemos[m_DemolistSelectedIndex].m_Valid)
{
CUIRect Left, Right, Labels;
Expand Down Expand Up @@ -967,7 +967,7 @@ void CMenus::RenderDemoList(CUIRect MainView)
{COL_DATE, SORT_DATE, Localize("Date"), 1, 160.0f, 1, {0}, {0}},
};

RenderTools()->DrawUIRect(&Headers, vec4(0.0f,0,0,0.15f), 0, 0);
RenderTools()->DrawUIRect(&Headers, ColorRGBA(0.0f,0,0,0.15f), 0, 0);

int NumCols = sizeof(s_aCols)/sizeof(CColumn);

Expand Down Expand Up @@ -1057,8 +1057,8 @@ void CMenus::RenderDemoList(CUIRect MainView)
{
if(m_aInputEvents[i].m_Key == KEY_DOWN) NewIndex = m_DemolistSelectedIndex + 1;
else if(m_aInputEvents[i].m_Key == KEY_UP) NewIndex = m_DemolistSelectedIndex - 1;
else if(m_aInputEvents[i].m_Key == KEY_PAGEUP) NewIndex = max(m_DemolistSelectedIndex - 20, 0);
else if(m_aInputEvents[i].m_Key == KEY_PAGEDOWN) NewIndex = min(m_DemolistSelectedIndex + 20, m_lDemos.size() - 1);
else if(m_aInputEvents[i].m_Key == KEY_PAGEUP) NewIndex = maximum(m_DemolistSelectedIndex - 20, 0);
else if(m_aInputEvents[i].m_Key == KEY_PAGEDOWN) NewIndex = minimum(m_DemolistSelectedIndex + 20, m_lDemos.size() - 1);
else if(m_aInputEvents[i].m_Key == KEY_HOME) NewIndex = 0;
else if(m_aInputEvents[i].m_Key == KEY_END) NewIndex = m_lDemos.size() - 1;
}
Expand Down Expand Up @@ -1120,7 +1120,7 @@ void CMenus::RenderDemoList(CUIRect MainView)
{
CUIRect r = Row;
r.Margin(1.5f, &r);
RenderTools()->DrawUIRect(&r, vec4(1,1,1,0.5f), CUI::CORNER_ALL, 4.0f);
RenderTools()->DrawUIRect(&r, ColorRGBA(1,1,1,0.5f), CUI::CORNER_ALL, 4.0f);
}

// clip the selection
Expand Down
26 changes: 13 additions & 13 deletions src/game/client/components/menus_ingame.cpp
Expand Up @@ -163,7 +163,7 @@ void CMenus::RenderPlayers(CUIRect MainView)

// player options
MainView.Margin(10.0f, &Options);
RenderTools()->DrawUIRect(&Options, vec4(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 10.0f);
RenderTools()->DrawUIRect(&Options, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 10.0f);
Options.Margin(10.0f, &Options);
Options.HSplitTop(50.0f, &Button, &Options);
UI()->DoLabelScaled(&Button, Localize("Player options"), 34.0f, -1);
Expand Down Expand Up @@ -234,7 +234,7 @@ void CMenus::RenderPlayers(CUIRect MainView)
continue;

if(Count%2 == 1)
RenderTools()->DrawUIRect(&Item.m_Rect, vec4(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 10.0f);
RenderTools()->DrawUIRect(&Item.m_Rect, ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), CUI::CORNER_ALL, 10.0f);
Item.m_Rect.VSplitRight(300.0f, &Player, &Item.m_Rect);

// player info
Expand All @@ -257,7 +257,7 @@ void CMenus::RenderPlayers(CUIRect MainView)

//TextRender()->SetCursor(&Cursor, Button2.x,Button2.y, 14.0f, TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END);
//Cursor.m_LineWidth = Button.w;
vec4 Color(1.0f, 1.0f, 1.0f, 0.5f);
ColorRGBA Color(1.0f, 1.0f, 1.0f, 0.5f);
m_pClient->m_pCountryFlags->Render(m_pClient->m_aClients[Index].m_Country, &Color,
Button2.x, Button2.y + Button2.h/2.0f - 0.75*Button2.h/2.0f, 1.5f*Button2.h, 0.75f*Button2.h);

Expand Down Expand Up @@ -364,7 +364,7 @@ void CMenus::RenderServerInfo(CUIRect MainView)
// serverinfo
View.HSplitTop(View.h/2/UI()->Scale()-5.0f, &ServerInfo, &Motd);
ServerInfo.VSplitLeft(View.w/2/UI()->Scale()-5.0f, &ServerInfo, &GameInfo);
RenderTools()->DrawUIRect(&ServerInfo, vec4(1,1,1,0.25f), CUI::CORNER_ALL, 10.0f);
RenderTools()->DrawUIRect(&ServerInfo, ColorRGBA(1,1,1,0.25f), CUI::CORNER_ALL, 10.0f);

ServerInfo.Margin(5.0f, &ServerInfo);

Expand Down Expand Up @@ -408,7 +408,7 @@ void CMenus::RenderServerInfo(CUIRect MainView)

// gameinfo
GameInfo.VSplitLeft(10.0f, 0x0, &GameInfo);
RenderTools()->DrawUIRect(&GameInfo, vec4(1,1,1,0.25f), CUI::CORNER_ALL, 10.0f);
RenderTools()->DrawUIRect(&GameInfo, ColorRGBA(1,1,1,0.25f), CUI::CORNER_ALL, 10.0f);

GameInfo.Margin(5.0f, &GameInfo);

Expand Down Expand Up @@ -442,7 +442,7 @@ void CMenus::RenderServerInfo(CUIRect MainView)

// motd
Motd.HSplitTop(10.0f, 0, &Motd);
RenderTools()->DrawUIRect(&Motd, vec4(1,1,1,0.25f), CUI::CORNER_ALL, 10.0f);
RenderTools()->DrawUIRect(&Motd, ColorRGBA(1,1,1,0.25f), CUI::CORNER_ALL, 10.0f);
Motd.Margin(5.0f, &Motd);
y = 0.0f;
x = 5.0f;
Expand Down Expand Up @@ -906,7 +906,7 @@ void CMenus::RenderGhost(CUIRect MainView)
View.HSplitBottom(28.0f, &View, &Status);

// split of the scrollbar
RenderTools()->DrawUIRect(&Headers, vec4(1,1,1,0.25f), CUI::CORNER_T, 5.0f);
RenderTools()->DrawUIRect(&Headers, ColorRGBA(1,1,1,0.25f), CUI::CORNER_T, 5.0f);
Headers.VSplitRight(20.0f, &Headers, 0);

struct CColumn
Expand Down Expand Up @@ -947,7 +947,7 @@ void CMenus::RenderGhost(CUIRect MainView)
for(int i = 0; i < NumCols; i++)
DoButton_GridHeader(s_aCols[i].m_Caption, s_aCols[i].m_Caption, 0, &s_aCols[i].m_Rect);

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

CUIRect Scroll;
View.VSplitRight(15, &View, &Scroll);
Expand Down Expand Up @@ -1031,7 +1031,7 @@ void CMenus::RenderGhost(CUIRect MainView)
{
CUIRect r = Row;
r.Margin(1.5f, &r);
RenderTools()->DrawUIRect(&r, vec4(1,1,1,0.5f), CUI::CORNER_ALL, 4.0f);
RenderTools()->DrawUIRect(&r, ColorRGBA(1,1,1,0.5f), CUI::CORNER_ALL, 4.0f);
}

// clip the selection
Expand All @@ -1049,11 +1049,11 @@ void CMenus::RenderGhost(CUIRect MainView)
}
}

vec3 rgb = vec3(1.0f, 1.0f, 1.0f);
ColorRGBA rgb = ColorRGBA(1.0f, 1.0f, 1.0f);
if(pItem->m_Own)
rgb = HslToRgb(vec3(0.33f, 1.0f, 0.75f));
rgb = color_cast<ColorRGBA>(ColorHSLA(0.33f, 1.0f, 0.75f));

TextRender()->TextColor(rgb.r, rgb.g, rgb.b, pItem->HasFile() ? 1.0f : 0.5f);
TextRender()->TextColor(rgb.SetAlpha(pItem->HasFile() ? 1.0f : 0.5f));

for(int c = 0; c < NumCols; c++)
{
Expand Down Expand Up @@ -1106,7 +1106,7 @@ void CMenus::RenderGhost(CUIRect MainView)
if(NewSelected != -1)
s_SelectedIndex = NewSelected;

RenderTools()->DrawUIRect(&Status, vec4(1,1,1,0.25f), CUI::CORNER_B, 5.0f);
RenderTools()->DrawUIRect(&Status, ColorRGBA(1,1,1,0.25f), CUI::CORNER_B, 5.0f);
Status.Margin(5.0f, &Status);

CUIRect Button;
Expand Down
387 changes: 209 additions & 178 deletions src/game/client/components/menus_settings.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/game/client/components/nameplates.cpp
Expand Up @@ -107,9 +107,9 @@ void CNamePlates::RenderNameplate(
}

float tw = m_aNamePlates[ClientID].m_NameTextWidth;
vec3 rgb = vec3(1.0f, 1.0f, 1.0f);
ColorRGBA rgb = ColorRGBA(1.0f, 1.0f, 1.0f);
if(g_Config.m_ClNameplatesTeamcolors && m_pClient->m_Teams.Team(ClientID))
rgb = HslToRgb(vec3(m_pClient->m_Teams.Team(ClientID) / 64.0f, 1.0f, 0.75f));
rgb = color_cast<ColorRGBA>(ColorHSLA(m_pClient->m_Teams.Team(ClientID) / 64.0f, 1.0f, 0.75f));

STextRenderColor TColor;
STextRenderColor TOutlineColor;
Expand Down
4 changes: 2 additions & 2 deletions src/game/client/components/particles.h
Expand Up @@ -19,7 +19,7 @@ struct CParticle
m_Gravity = 0;
m_Friction = 0;
m_FlowAffected = 1.0f;
m_Color = vec4(1,1,1,1);
m_Color = ColorRGBA(1,1,1,1);
}

vec2 m_Pos;
Expand All @@ -40,7 +40,7 @@ struct CParticle
float m_Gravity;
float m_Friction;

vec4 m_Color;
ColorRGBA m_Color;

// set by the particle system
float m_Life;
Expand Down
164 changes: 68 additions & 96 deletions src/game/client/components/players.cpp

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/game/client/components/players.h
Expand Up @@ -9,7 +9,8 @@ class CPlayers : public CComponent
friend class CGhost;

CTeeRenderInfo m_aRenderInfo[MAX_CLIENTS];
void RenderHand(class CTeeRenderInfo *pInfo, vec2 CenterPos, vec2 Dir, float AngleOffset, vec2 PostRotOffset);
bool IsOtherTeam(int ClientID);
void RenderHand(class CTeeRenderInfo *pInfo, vec2 CenterPos, vec2 Dir, float AngleOffset, vec2 PostRotOffset, float Alpha = 1.0f);
void RenderPlayer(
const CNetObj_Character *pPrevChar,
const CNetObj_Character *pPlayerChar,
Expand Down
2 changes: 1 addition & 1 deletion src/game/client/components/race_demo.cpp
Expand Up @@ -182,7 +182,7 @@ int CRaceDemo::RaceDemolistFetchCallback(const char *pName, time_t Date, int IsD
return 0;

CDemoItem Item;
str_copy(Item.m_aName, pName, min(static_cast<int>(sizeof(Item.m_aName)), Length - 4));
str_copy(Item.m_aName, pName, minimum(static_cast<int>(sizeof(Item.m_aName)), Length - 4));

const char *pTime = Item.m_aName + MapLen + 1;
const char *pTEnd = pTime;
Expand Down
24 changes: 12 additions & 12 deletions src/game/client/components/scoreboard.cpp
Expand Up @@ -135,8 +135,8 @@ void CScoreboard::RenderSpectators(float x, float y, float w)

if(m_pClient->m_aClients[pInfo->m_ClientID].m_AuthLevel)
{
vec4 Color = m_pClient->m_pSkins->GetColorV4(g_Config.m_ClAuthedPlayerColor);
TextRender()->TextColor(Color.r, Color.g, Color.b, Color.a);
ColorRGBA Color = color_cast<ColorRGBA>(ColorHSLA(g_Config.m_ClAuthedPlayerColor));
TextRender()->TextColor(Color);
}

if(g_Config.m_ClShowIDs)
Expand Down Expand Up @@ -367,8 +367,8 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
{
Graphics()->TextureSet(-1);
Graphics()->QuadsBegin();
vec3 rgb = HslToRgb(vec3(DDTeam / 64.0f, 1.0f, 0.5f));
Graphics()->SetColor(rgb.r, rgb.g, rgb.b, 0.5f);
ColorRGBA rgb = color_cast<ColorRGBA>(ColorHSLA(DDTeam / 64.0f, 1.0f, 0.5f, 0.5f));
Graphics()->SetColor(rgb);

int Corners = 0;

Expand Down Expand Up @@ -456,8 +456,8 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
TextRender()->SetCursor(&Cursor, NameOffset, y + (LineHeight - FontSize) / 2.f, FontSize, TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END);
if(m_pClient->m_aClients[pInfo->m_ClientID].m_AuthLevel)
{
vec4 Color = m_pClient->m_pSkins->GetColorV4(g_Config.m_ClAuthedPlayerColor);
TextRender()->TextColor(Color.r, Color.g, Color.b, Color.a);
ColorRGBA Color = color_cast<ColorRGBA>(ColorHSLA(g_Config.m_ClAuthedPlayerColor));
TextRender()->TextColor(Color);
}

if(g_Config.m_ClShowIDs)
Expand All @@ -476,10 +476,10 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch

// clan
if(str_comp(m_pClient->m_aClients[pInfo->m_ClientID].m_aClan,
m_pClient->m_aClients[GameClient()->m_LocalIDs[0]].m_aClan) == 0)
m_pClient->m_aClients[GameClient()->m_LocalIDs[g_Config.m_ClDummy]].m_aClan) == 0)
{
vec4 Color = m_pClient->m_pSkins->GetColorV4(g_Config.m_ClSameClanColor);
TextRender()->TextColor(Color.r, Color.g, Color.b, Color.a);
ColorRGBA Color = color_cast<ColorRGBA>(ColorHSLA(g_Config.m_ClSameClanColor));
TextRender()->TextColor(Color);
}
else
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
Expand All @@ -492,15 +492,15 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);

// country flag
vec4 Color(1.0f, 1.0f, 1.0f, 0.5f);
ColorRGBA Color(1.0f, 1.0f, 1.0f, 0.5f);
m_pClient->m_pCountryFlags->Render(m_pClient->m_aClients[pInfo->m_ClientID].m_Country, &Color,
CountryOffset, y+(Spacing+TeeSizeMod*5.0f)/2.0f, CountryLength, LineHeight-Spacing-TeeSizeMod*5.0f);

// ping
if(g_Config.m_ClEnablePingColor)
{
vec3 rgb = HslToRgb(vec3((300.0f - clamp(pInfo->m_Latency, 0, 300)) / 1000.0f, 1.0f, 0.5f));
TextRender()->TextColor(rgb.r, rgb.g, rgb.b, 1.0f);
ColorRGBA rgb = color_cast<ColorRGBA>(ColorHSLA((300.0f - clamp(pInfo->m_Latency, 0, 300)) / 1000.0f, 1.0f, 0.5f));
TextRender()->TextColor(rgb);
}
str_format(aBuf, sizeof(aBuf), "%d", clamp(pInfo->m_Latency, 0, 1000));
tw = TextRender()->TextWidth(nullptr, FontSize, aBuf, -1);
Expand Down
15 changes: 2 additions & 13 deletions src/game/client/components/skins.cpp
Expand Up @@ -82,7 +82,7 @@ int CSkins::SkinScan(const char *pName, int IsDir, int DirType, void *pUser)
}
}

Skin.m_BloodColor = normalize(vec3(aColors[0], aColors[1], aColors[2]));
Skin.m_BloodColor = ColorRGBA(normalize(vec3(aColors[0], aColors[1], aColors[2])));
}

// create colorless version
Expand Down Expand Up @@ -175,7 +175,7 @@ void CSkins::OnInit()
DummySkin.m_OrgTexture = -1;
DummySkin.m_ColorTexture = -1;
str_copy(DummySkin.m_aName, "dummy", sizeof(DummySkin.m_aName));
DummySkin.m_BloodColor = vec3(1.0f, 1.0f, 1.0f);
DummySkin.m_BloodColor = ColorRGBA(1.0f, 1.0f, 1.0f);
m_aSkins.add(DummySkin);
}
}
Expand Down Expand Up @@ -229,14 +229,3 @@ int CSkins::FindImpl(const char *pName) const
}
return -1;
}

vec3 CSkins::GetColorV3(int v)
{
return HslToRgb(vec3(((v>>16)&0xff)/255.0f, ((v>>8)&0xff)/255.0f, 0.5f+(v&0xff)/255.0f*0.5f));
}

vec4 CSkins::GetColorV4(int v)
{
vec3 r = GetColorV3(v);
return vec4(r.r, r.g, r.b, 1.0f);
}
5 changes: 2 additions & 3 deletions src/game/client/components/skins.h
Expand Up @@ -3,6 +3,7 @@
#ifndef GAME_CLIENT_COMPONENTS_SKINS_H
#define GAME_CLIENT_COMPONENTS_SKINS_H
#include <base/vmath.h>
#include <base/color.h>
#include <base/tl/sorted_array.h>
#include <game/client/component.h>

Expand All @@ -16,15 +17,13 @@ class CSkins : public CComponent
int m_OrgTexture;
int m_ColorTexture;
char m_aName[24];
vec3 m_BloodColor;
ColorRGBA m_BloodColor;

bool operator<(const CSkin &Other) { return str_comp(m_aName, Other.m_aName) < 0; }
};

void OnInit();

vec3 GetColorV3(int v);
vec4 GetColorV4(int v);
int Num();
const CSkin *Get(int Index);
int Find(const char *pName) const;
Expand Down
8 changes: 3 additions & 5 deletions src/game/client/components/spectator.cpp
Expand Up @@ -327,8 +327,8 @@ void CSpectator::OnRender()
{
Graphics()->TextureSet(-1);
Graphics()->QuadsBegin();
vec3 rgb = HslToRgb(vec3(DDTeam / 64.0f, 1.0f, 0.5f));
Graphics()->SetColor(rgb.r, rgb.g, rgb.b, 0.5f);
ColorRGBA rgb = color_cast<ColorRGBA>(ColorHSLA(DDTeam / 64.0f, 1.0f, 0.5f, 0.5f));
Graphics()->SetColor(rgb);

int Corners = 0;

Expand Down Expand Up @@ -393,10 +393,8 @@ void CSpectator::OnRender()
}

CTeeRenderInfo TeeInfo = m_pClient->m_aClients[m_pClient->m_Snap.m_paInfoByDDTeam[i]->m_ClientID].m_RenderInfo;
TeeInfo.m_ColorBody.a = TeeAlpha;
TeeInfo.m_ColorFeet.a = TeeAlpha;
TeeInfo.m_Size *= TeeSizeMod;
RenderTools()->RenderTee(CAnimState::GetIdle(), &TeeInfo, EMOTE_NORMAL, vec2(1.0f, 0.0f), vec2(Width/2.0f+x+20.0f, Height/2.0f+y+20.0f), true);
RenderTools()->RenderTee(CAnimState::GetIdle(), &TeeInfo, EMOTE_NORMAL, vec2(1.0f, 0.0f), vec2(Width/2.0f+x+20.0f, Height/2.0f+y+20.0f), TeeAlpha);

y += LineHeight;
}
Expand Down
8 changes: 4 additions & 4 deletions src/game/client/components/voting.cpp
Expand Up @@ -282,13 +282,13 @@ void CVoting::OnRender()

void CVoting::RenderBars(CUIRect Bars, bool Text)
{
RenderTools()->DrawUIRect(&Bars, vec4(0.8f,0.8f,0.8f,0.5f), CUI::CORNER_ALL, Bars.h/3);
RenderTools()->DrawUIRect(&Bars, ColorRGBA(0.8f,0.8f,0.8f,0.5f), CUI::CORNER_ALL, Bars.h/3);

CUIRect Splitter = Bars;
Splitter.x = Splitter.x+Splitter.w/2;
Splitter.w = Splitter.h/2.0f;
Splitter.x -= Splitter.w/2;
RenderTools()->DrawUIRect(&Splitter, vec4(0.4f,0.4f,0.4f,0.5f), CUI::CORNER_ALL, Splitter.h/4);
RenderTools()->DrawUIRect(&Splitter, ColorRGBA(0.4f,0.4f,0.4f,0.5f), CUI::CORNER_ALL, Splitter.h/4);

if(m_Total)
{
Expand All @@ -297,7 +297,7 @@ void CVoting::RenderBars(CUIRect Bars, bool Text)
{
CUIRect YesArea = Bars;
YesArea.w *= m_Yes/(float)m_Total;
RenderTools()->DrawUIRect(&YesArea, vec4(0.2f,0.9f,0.2f,0.85f), CUI::CORNER_ALL, Bars.h/3);
RenderTools()->DrawUIRect(&YesArea, ColorRGBA(0.2f,0.9f,0.2f,0.85f), CUI::CORNER_ALL, Bars.h/3);

if(Text)
{
Expand All @@ -315,7 +315,7 @@ void CVoting::RenderBars(CUIRect Bars, bool Text)
CUIRect NoArea = Bars;
NoArea.w *= m_No/(float)m_Total;
NoArea.x = (Bars.x + Bars.w)-NoArea.w;
RenderTools()->DrawUIRect(&NoArea, vec4(0.9f,0.2f,0.2f,0.85f), CUI::CORNER_ALL, Bars.h/3);
RenderTools()->DrawUIRect(&NoArea, ColorRGBA(0.9f,0.2f,0.2f,0.85f), CUI::CORNER_ALL, Bars.h/3);

if(Text)
{
Expand Down
174 changes: 67 additions & 107 deletions src/game/client/gameclient.cpp

Large diffs are not rendered by default.

112 changes: 42 additions & 70 deletions src/game/client/gameclient.h
Expand Up @@ -3,6 +3,7 @@
#ifndef GAME_CLIENT_GAMECLIENT_H
#define GAME_CLIENT_GAMECLIENT_H

#include <base/color.h>
#include <base/vmath.h>
#include <engine/client.h>
#include <engine/console.h>
Expand All @@ -18,15 +19,45 @@
#include <game/client/prediction/entities/laser.h>
#include <game/client/prediction/entities/pickup.h>

#define MIN3(x,y,z) ((y) <= (z) ? \
((x) <= (y) ? (x) : (y)) \
: \
((x) <= (z) ? (x) : (z)))
class CGameClient;

#define MAX3(x,y,z) ((y) >= (z) ? \
((x) >= (y) ? (x) : (y)) \
: \
((x) >= (z) ? (x) : (z)))
class CWeaponData
{
public:
int m_Tick;
vec2 m_Pos;
vec2 m_Direction;
vec2 StartPos() { return m_Pos + m_Direction * 28.0f * 0.75f; }
};

class CLocalProjectile
{
public:
int m_Active;
CGameClient *m_pGameClient;
CWorldCore *m_pWorld;
CCollision *m_pCollision;

vec2 m_Direction;
vec2 m_Pos;
int m_StartTick;
int m_Type;

int m_Owner;
int m_Weapon;
bool m_Explosive;
int m_Bouncing;
bool m_Freeze;
bool m_ExtraInfo;

vec2 GetPos(float Time);
void CreateExplosion(vec2 Pos, int LocalClientID);
void Tick(int CurrentTick, int GameTickSpeed, int LocalClientID);
void Init(CGameClient *pGameClient, CWorldCore *pWorld, CCollision *pCollision, const CNetObj_Projectile *pProj);
void Init(CGameClient *pGameClient, CWorldCore *pWorld, CCollision *pCollision, vec2 Vel, vec2 Pos, int StartTick, int Type, int Owner, int Weapon, bool Explosive, int Bouncing, bool Freeze, bool ExtraInfo);
bool GameLayerClipped(vec2 CheckPos);
void Deactivate() { m_Active = 0; }
};

class CGameClient : public IGameClient
{
Expand Down Expand Up @@ -83,12 +114,11 @@ class CGameClient : public IGameClient

static void ConTeam(IConsole::IResult *pResult, void *pUserData);
static void ConKill(IConsole::IResult *pResult, void *pUserData);
static void ConColorFromRgb(IConsole::IResult *pResult, void *pUserData);
static void ConColorToRgb(IConsole::IResult *pResult, void *pUserData);

static void ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainSpecialDummyInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainSpecialDummy(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainClTextEntitiesSize(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);

public:
IKernel *Kernel() { return IInterface::Kernel(); }
Expand Down Expand Up @@ -224,9 +254,8 @@ class CGameClient : public IGameClient
bool m_HasTelegunGun;
bool m_HasTelegunGrenade;
bool m_HasTelegunLaser;
bool m_Frozen;
int m_FreezeEnd;
bool m_DeepFrozen;
bool m_Spectating;


CCharacterCore m_Predicted;
Expand Down Expand Up @@ -402,63 +431,6 @@ class CGameClient : public IGameClient
class CTeamsCore m_TeamsPredicted;
};


inline float HueToRgb(float v1, float v2, float h)
{
if(h < 0.0f) h += 1;
if(h > 1.0f) h -= 1;
if((6.0f * h) < 1.0f) return v1 + (v2 - v1) * 6.0f * h;
if((2.0f * h) < 1.0f) return v2;
if((3.0f * h) < 2.0f) return v1 + (v2 - v1) * ((2.0f/3.0f) - h) * 6.0f;
return v1;
}

inline vec3 HslToRgb(vec3 HSL)
{
if(HSL.s == 0.0f)
return vec3(HSL.l, HSL.l, HSL.l);
else
{
float v2 = HSL.l < 0.5f ? HSL.l * (1.0f + HSL.s) : (HSL.l+HSL.s) - (HSL.s*HSL.l);
float v1 = 2.0f * HSL.l - v2;

return vec3(HueToRgb(v1, v2, HSL.h + (1.0f/3.0f)), HueToRgb(v1, v2, HSL.h), HueToRgb(v1, v2, HSL.h - (1.0f/3.0f)));
}
}

inline vec3 RgbToHsl(vec3 RGB)
{
vec3 HSL;
float MaxColor = MAX3(RGB.r, RGB.g, RGB.b);
float MinColor = MIN3(RGB.r, RGB.g, RGB.b);
if (MinColor == MaxColor)
return vec3(0.0f, 0.0f, RGB.g * 255.0f);
else
{
HSL.l = (MinColor + MaxColor) / 2;

if (HSL.l < 0.5)
HSL.s = (MaxColor - MinColor) / (MaxColor + MinColor);
else
HSL.s = (MaxColor - MinColor) / (2.0 - MaxColor - MinColor);

if (RGB.r == MaxColor)
HSL.h = (RGB.g - RGB.b) / (MaxColor - MinColor);
else if (RGB.g == MaxColor)
HSL.h = 2.0 + (RGB.b - RGB.r) / (MaxColor - MinColor);
else
HSL.h = 4.0 + (RGB.r - RGB.g) / (MaxColor - MinColor);

HSL.h /= 6; //to bring it to a number between 0 and 1
if (HSL.h < 0) HSL.h++;
}
HSL.h = int(HSL.h * 255.0);
HSL.s = int(HSL.s * 255.0);
HSL.l = int(HSL.l * 255.0);
return HSL;

}

vec3 CalculateNameColor(vec3 TextColorHSL);
ColorRGBA CalculateNameColor(ColorHSLA TextColorHSL);

#endif
132 changes: 78 additions & 54 deletions src/game/client/prediction/entities/character.cpp
Expand Up @@ -457,6 +457,8 @@ void CCharacter::FireWeapon()

}

m_AttackTick = GameWorld()->GameTick();

if(!m_ReloadTimer)
{
float FireDelay;
Expand Down Expand Up @@ -490,7 +492,7 @@ bool CCharacter::GiveWeapon(int Weapon, int Ammo)
{
m_aWeapons[Weapon].m_Got = true;
if(!m_FreezeTime)
m_aWeapons[Weapon].m_Ammo = min(g_pData->m_Weapons.m_aId[Weapon].m_Maxammo, Ammo);
m_aWeapons[Weapon].m_Ammo = minimum(g_pData->m_Weapons.m_aId[Weapon].m_Maxammo, Ammo);
return true;
}
return false;
Expand Down Expand Up @@ -553,6 +555,7 @@ void CCharacter::Tick()
// Previnput
m_PrevInput = m_Input;

m_PrevPrevPos = m_PrevPos;
m_PrevPos = m_Core.m_Pos;
return;
}
Expand Down Expand Up @@ -689,6 +692,42 @@ void CCharacter::HandleTiles(int Index)
m_TileSFlagsB = (Collision()->m_pSwitchers && Collision()->m_pSwitchers[Collision()->GetDTileNumber(MapIndexB)].m_Status[Team()])?(Team() != TEAM_SUPER)? Collision()->GetDTileFlags(MapIndexB) : 0 : 0;
m_TileSIndexT = (Collision()->m_pSwitchers && Collision()->m_pSwitchers[Collision()->GetDTileNumber(MapIndexT)].m_Status[Team()])?(Team() != TEAM_SUPER)? Collision()->GetDTileIndex(MapIndexT) : 0 : 0;
m_TileSFlagsT = (Collision()->m_pSwitchers && Collision()->m_pSwitchers[Collision()->GetDTileNumber(MapIndexT)].m_Status[Team()])?(Team() != TEAM_SUPER)? Collision()->GetDTileFlags(MapIndexT) : 0 : 0;

// stopper
if(((m_TileIndex == TILE_STOP && m_TileFlags == ROTATION_270) || (m_TileIndexL == TILE_STOP && m_TileFlagsL == ROTATION_270) || (m_TileIndexL == TILE_STOPS && (m_TileFlagsL == ROTATION_90 || m_TileFlagsL ==ROTATION_270)) || (m_TileIndexL == TILE_STOPA) || (m_TileFIndex == TILE_STOP && m_TileFFlags == ROTATION_270) || (m_TileFIndexL == TILE_STOP && m_TileFFlagsL == ROTATION_270) || (m_TileFIndexL == TILE_STOPS && (m_TileFFlagsL == ROTATION_90 || m_TileFFlagsL == ROTATION_270)) || (m_TileFIndexL == TILE_STOPA) || (m_TileSIndex == TILE_STOP && m_TileSFlags == ROTATION_270) || (m_TileSIndexL == TILE_STOP && m_TileSFlagsL == ROTATION_270) || (m_TileSIndexL == TILE_STOPS && (m_TileSFlagsL == ROTATION_90 || m_TileSFlagsL == ROTATION_270)) || (m_TileSIndexL == TILE_STOPA)) && m_Core.m_Vel.x > 0)
{
if((int)Collision()->GetPos(MapIndexL).x)
if((int)Collision()->GetPos(MapIndexL).x < (int)m_Core.m_Pos.x)
m_Core.m_Pos = m_PrevPos;
m_Core.m_Vel.x = 0;
}
if(((m_TileIndex == TILE_STOP && m_TileFlags == ROTATION_90) || (m_TileIndexR == TILE_STOP && m_TileFlagsR == ROTATION_90) || (m_TileIndexR == TILE_STOPS && (m_TileFlagsR == ROTATION_90 || m_TileFlagsR == ROTATION_270)) || (m_TileIndexR == TILE_STOPA) || (m_TileFIndex == TILE_STOP && m_TileFFlags == ROTATION_90) || (m_TileFIndexR == TILE_STOP && m_TileFFlagsR == ROTATION_90) || (m_TileFIndexR == TILE_STOPS && (m_TileFFlagsR == ROTATION_90 || m_TileFFlagsR == ROTATION_270)) || (m_TileFIndexR == TILE_STOPA) || (m_TileSIndex == TILE_STOP && m_TileSFlags == ROTATION_90) || (m_TileSIndexR == TILE_STOP && m_TileSFlagsR == ROTATION_90) || (m_TileSIndexR == TILE_STOPS && (m_TileSFlagsR == ROTATION_90 || m_TileSFlagsR == ROTATION_270)) || (m_TileSIndexR == TILE_STOPA)) && m_Core.m_Vel.x < 0)
{
if((int)Collision()->GetPos(MapIndexR).x)
if((int)Collision()->GetPos(MapIndexR).x > (int)m_Core.m_Pos.x)
m_Core.m_Pos = m_PrevPos;
m_Core.m_Vel.x = 0;
}
if(((m_TileIndex == TILE_STOP && m_TileFlags == ROTATION_180) || (m_TileIndexB == TILE_STOP && m_TileFlagsB == ROTATION_180) || (m_TileIndexB == TILE_STOPS && (m_TileFlagsB == ROTATION_0 || m_TileFlagsB == ROTATION_180)) || (m_TileIndexB == TILE_STOPA) || (m_TileFIndex == TILE_STOP && m_TileFFlags == ROTATION_180) || (m_TileFIndexB == TILE_STOP && m_TileFFlagsB == ROTATION_180) || (m_TileFIndexB == TILE_STOPS && (m_TileFFlagsB == ROTATION_0 || m_TileFFlagsB == ROTATION_180)) || (m_TileFIndexB == TILE_STOPA) || (m_TileSIndex == TILE_STOP && m_TileSFlags == ROTATION_180) || (m_TileSIndexB == TILE_STOP && m_TileSFlagsB == ROTATION_180) || (m_TileSIndexB == TILE_STOPS && (m_TileSFlagsB == ROTATION_0 || m_TileSFlagsB == ROTATION_180)) || (m_TileSIndexB == TILE_STOPA)) && m_Core.m_Vel.y < 0)
{
if((int)Collision()->GetPos(MapIndexB).y)
if((int)Collision()->GetPos(MapIndexB).y > (int)m_Core.m_Pos.y)
m_Core.m_Pos = m_PrevPos;
m_Core.m_Vel.y = 0;
}
if(((m_TileIndex == TILE_STOP && m_TileFlags == ROTATION_0) || (m_TileIndexT == TILE_STOP && m_TileFlagsT == ROTATION_0) || (m_TileIndexT == TILE_STOPS && (m_TileFlagsT == ROTATION_0 || m_TileFlagsT == ROTATION_180)) || (m_TileIndexT == TILE_STOPA) || (m_TileFIndex == TILE_STOP && m_TileFFlags == ROTATION_0) || (m_TileFIndexT == TILE_STOP && m_TileFFlagsT == ROTATION_0) || (m_TileFIndexT == TILE_STOPS && (m_TileFFlagsT == ROTATION_0 || m_TileFFlagsT == ROTATION_180)) || (m_TileFIndexT == TILE_STOPA) || (m_TileSIndex == TILE_STOP && m_TileSFlags == ROTATION_0) || (m_TileSIndexT == TILE_STOP && m_TileSFlagsT == ROTATION_0) || (m_TileSIndexT == TILE_STOPS && (m_TileSFlagsT == ROTATION_0 || m_TileSFlagsT == ROTATION_180)) || (m_TileSIndexT == TILE_STOPA)) && m_Core.m_Vel.y > 0)
{
if((int)Collision()->GetPos(MapIndexT).y)
if((int)Collision()->GetPos(MapIndexT).y < (int)m_Core.m_Pos.y)
m_Core.m_Pos = m_PrevPos;
m_Core.m_Vel.y = 0;
m_Core.m_Jumped = 0;
m_Core.m_JumpedTotal = 0;
}

if(!GameWorld()->m_WorldConfig.m_PredictTiles)
return;

if(Index < 0)
{
m_LastRefillJumps = false;
Expand Down Expand Up @@ -798,38 +837,6 @@ void CCharacter::HandleTiles(int Index)
m_LastRefillJumps = false;
}

// stopper
if(((m_TileIndex == TILE_STOP && m_TileFlags == ROTATION_270) || (m_TileIndexL == TILE_STOP && m_TileFlagsL == ROTATION_270) || (m_TileIndexL == TILE_STOPS && (m_TileFlagsL == ROTATION_90 || m_TileFlagsL ==ROTATION_270)) || (m_TileIndexL == TILE_STOPA) || (m_TileFIndex == TILE_STOP && m_TileFFlags == ROTATION_270) || (m_TileFIndexL == TILE_STOP && m_TileFFlagsL == ROTATION_270) || (m_TileFIndexL == TILE_STOPS && (m_TileFFlagsL == ROTATION_90 || m_TileFFlagsL == ROTATION_270)) || (m_TileFIndexL == TILE_STOPA) || (m_TileSIndex == TILE_STOP && m_TileSFlags == ROTATION_270) || (m_TileSIndexL == TILE_STOP && m_TileSFlagsL == ROTATION_270) || (m_TileSIndexL == TILE_STOPS && (m_TileSFlagsL == ROTATION_90 || m_TileSFlagsL == ROTATION_270)) || (m_TileSIndexL == TILE_STOPA)) && m_Core.m_Vel.x > 0)
{
if((int)Collision()->GetPos(MapIndexL).x)
if((int)Collision()->GetPos(MapIndexL).x < (int)m_Core.m_Pos.x)
m_Core.m_Pos = m_PrevPos;
m_Core.m_Vel.x = 0;
}
if(((m_TileIndex == TILE_STOP && m_TileFlags == ROTATION_90) || (m_TileIndexR == TILE_STOP && m_TileFlagsR == ROTATION_90) || (m_TileIndexR == TILE_STOPS && (m_TileFlagsR == ROTATION_90 || m_TileFlagsR == ROTATION_270)) || (m_TileIndexR == TILE_STOPA) || (m_TileFIndex == TILE_STOP && m_TileFFlags == ROTATION_90) || (m_TileFIndexR == TILE_STOP && m_TileFFlagsR == ROTATION_90) || (m_TileFIndexR == TILE_STOPS && (m_TileFFlagsR == ROTATION_90 || m_TileFFlagsR == ROTATION_270)) || (m_TileFIndexR == TILE_STOPA) || (m_TileSIndex == TILE_STOP && m_TileSFlags == ROTATION_90) || (m_TileSIndexR == TILE_STOP && m_TileSFlagsR == ROTATION_90) || (m_TileSIndexR == TILE_STOPS && (m_TileSFlagsR == ROTATION_90 || m_TileSFlagsR == ROTATION_270)) || (m_TileSIndexR == TILE_STOPA)) && m_Core.m_Vel.x < 0)
{
if((int)Collision()->GetPos(MapIndexR).x)
if((int)Collision()->GetPos(MapIndexR).x > (int)m_Core.m_Pos.x)
m_Core.m_Pos = m_PrevPos;
m_Core.m_Vel.x = 0;
}
if(((m_TileIndex == TILE_STOP && m_TileFlags == ROTATION_180) || (m_TileIndexB == TILE_STOP && m_TileFlagsB == ROTATION_180) || (m_TileIndexB == TILE_STOPS && (m_TileFlagsB == ROTATION_0 || m_TileFlagsB == ROTATION_180)) || (m_TileIndexB == TILE_STOPA) || (m_TileFIndex == TILE_STOP && m_TileFFlags == ROTATION_180) || (m_TileFIndexB == TILE_STOP && m_TileFFlagsB == ROTATION_180) || (m_TileFIndexB == TILE_STOPS && (m_TileFFlagsB == ROTATION_0 || m_TileFFlagsB == ROTATION_180)) || (m_TileFIndexB == TILE_STOPA) || (m_TileSIndex == TILE_STOP && m_TileSFlags == ROTATION_180) || (m_TileSIndexB == TILE_STOP && m_TileSFlagsB == ROTATION_180) || (m_TileSIndexB == TILE_STOPS && (m_TileSFlagsB == ROTATION_0 || m_TileSFlagsB == ROTATION_180)) || (m_TileSIndexB == TILE_STOPA)) && m_Core.m_Vel.y < 0)
{
if((int)Collision()->GetPos(MapIndexB).y)
if((int)Collision()->GetPos(MapIndexB).y > (int)m_Core.m_Pos.y)
m_Core.m_Pos = m_PrevPos;
m_Core.m_Vel.y = 0;
}
if(((m_TileIndex == TILE_STOP && m_TileFlags == ROTATION_0) || (m_TileIndexT == TILE_STOP && m_TileFlagsT == ROTATION_0) || (m_TileIndexT == TILE_STOPS && (m_TileFlagsT == ROTATION_0 || m_TileFlagsT == ROTATION_180)) || (m_TileIndexT == TILE_STOPA) || (m_TileFIndex == TILE_STOP && m_TileFFlags == ROTATION_0) || (m_TileFIndexT == TILE_STOP && m_TileFFlagsT == ROTATION_0) || (m_TileFIndexT == TILE_STOPS && (m_TileFFlagsT == ROTATION_0 || m_TileFFlagsT == ROTATION_180)) || (m_TileFIndexT == TILE_STOPA) || (m_TileSIndex == TILE_STOP && m_TileSFlags == ROTATION_0) || (m_TileSIndexT == TILE_STOP && m_TileSFlagsT == ROTATION_0) || (m_TileSIndexT == TILE_STOPS && (m_TileSFlagsT == ROTATION_0 || m_TileSFlagsT == ROTATION_180)) || (m_TileSIndexT == TILE_STOPA)) && m_Core.m_Vel.y > 0)
{
if((int)Collision()->GetPos(MapIndexT).y)
if((int)Collision()->GetPos(MapIndexT).y < (int)m_Core.m_Pos.y)
m_Core.m_Pos = m_PrevPos;
m_Core.m_Vel.y = 0;
m_Core.m_Jumped = 0;
m_Core.m_JumpedTotal = 0;
}

// handle switch tiles
if(Collision()->IsSwitch(MapIndex) == TILE_SWITCHOPEN && Team() != TEAM_SUPER)
{
Expand Down Expand Up @@ -881,26 +888,27 @@ void CCharacter::HandleTiles(int Index)

void CCharacter::DDRaceTick()
{
if(!GameWorld()->m_WorldConfig.m_PredictTiles || !GameWorld()->m_WorldConfig.m_PredictWeapons)
return;
mem_copy(&m_Input, &m_SavedInput, sizeof(m_Input));
if(m_FreezeTime > 0 || m_FreezeTime == -1)
{
if(m_FreezeTime > 0)
m_FreezeTime--;
else
m_Ninja.m_ActivationTick = GameWorld()->GameTick();
m_Input.m_Direction = 0;
m_Input.m_Jump = 0;
m_Input.m_Hook = 0;
if(!m_CanMoveInFreeze)
{
m_Input.m_Direction = 0;
m_Input.m_Jump = 0;
m_Input.m_Hook = 0;
}
if (m_FreezeTime == 1)
UnFreeze();
}
}

void CCharacter::DDRacePostCoreTick()
{
if(!GameWorld()->m_WorldConfig.m_PredictTiles)
if(!GameWorld()->m_WorldConfig.m_PredictDDRace)
return;

if (m_EndlessHook)
Expand Down Expand Up @@ -997,46 +1005,59 @@ CCharacter::CCharacter(CGameWorld *pGameWorld, int ID, CNetObj_Character *pChar,
m_LastWeapon = WEAPON_HAMMER;
m_QueuedWeapon = -1;
m_LastRefillJumps = false;
m_Pos = vec2(pChar->m_X, pChar->m_Y);
m_PrevPos = m_Pos;
m_PrevPrevPos = m_PrevPos = m_Pos = vec2(pChar->m_X, pChar->m_Y);
m_Core.Reset();
m_Core.Init(&GameWorld()->m_Core, GameWorld()->Collision(), GameWorld()->Teams());
m_Core.m_Id = ID;
SetSolo(false);
m_EndlessHook = false;
m_Hit = HIT_ALL;
m_SuperJump = false;
m_Jetpack = false;
m_Core.m_Jumps = 2;
mem_zero(&m_Ninja, sizeof(m_Ninja));
mem_zero(&m_SavedInput, sizeof(m_SavedInput));
m_LatestInput = m_LatestPrevInput = m_PrevInput = m_Input = m_SavedInput;
m_ProximityRadius = ms_PhysSize;
m_Core.m_LeftWall = 1;
m_NumInputs = 0;
m_FreezeTime = 0;
m_FreezeTick = 0;
m_DeepFreeze = 0;
m_ReloadTimer = 0;
//GiveAllWeapons();
//GiveWeapon(WEAPON_HAMMER, -1);
m_NumObjectsHit = 0;
m_LastRefillJumps = false;
m_LastJetpackStrength = 400.0;
m_Super = false;
m_CanMoveInFreeze = false;
m_Alive = true;

ResetPrediction();
Read(pChar, pExtended, false);

GameWorld()->InsertEntity(this);
}

void CCharacter::ResetPrediction()
{
SetSolo(false);
m_EndlessHook = false;
m_Hit = HIT_ALL;
m_SuperJump = false;
m_Jetpack = false;
m_NinjaJetpack = false;
m_Core.m_Jumps = 2;
m_NumInputs = 0;
m_FreezeTime = 0;
m_FreezeTick = 0;
m_DeepFreeze = 0;
m_Super = false;
for(int w = 0; w < NUM_WEAPONS; w++)
SetWeaponGot(w, false);
if(m_Core.m_HookedPlayer >= 0)
{
m_Core.m_HookedPlayer = -1;
m_Core.m_HookState = HOOK_IDLE;
}
}

void CCharacter::Read(CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended, bool IsLocal)
{
vec2 PosBefore = m_Pos;

m_Core.Read((CNetObj_CharacterCore*) pChar);
m_Pos = m_Core.m_Pos;
m_AttackTick = pChar->m_AttackTick;

if(distance(PosBefore, m_Pos) > 2.f) // misprediction, don't use prevpos
m_PrevPos = m_Pos;
Expand Down Expand Up @@ -1088,6 +1109,9 @@ void CCharacter::Read(CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtende
{
m_LastJetpackStrength = Tuning()->m_JetpackStrength;
m_Jetpack = true;
m_aWeapons[WEAPON_GUN].m_Got = true;
m_aWeapons[WEAPON_GUN].m_Ammo = -1;
m_NinjaJetpack = pChar->m_Weapon == WEAPON_NINJA;
}
else if(pChar->m_Weapon != WEAPON_NINJA)
m_Jetpack = false;
Expand Down Expand Up @@ -1143,7 +1167,7 @@ void CCharacter::Read(CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtende
SetSolo(pExtended->m_Flags & CHARACTERFLAG_SOLO);
m_Super = pExtended->m_Flags & CHARACTERFLAG_SUPER;
if(m_Super)
TeamsCore()->Team(GetCID(), TEAM_SUPER);
TeamsCore()->Team(GetCID(), TeamsCore()->m_IsDDRace16 ? VANILLA_TEAM_SUPER : TEAM_SUPER);
m_EndlessHook = pExtended->m_Flags & CHARACTERFLAG_ENDLESS_HOOK;
m_Core.m_Collision = !(pExtended->m_Flags & CHARACTERFLAG_NO_COLLISION);
m_Core.m_Hook = !(pExtended->m_Flags & CHARACTERFLAG_NO_HOOK);
Expand Down
6 changes: 6 additions & 0 deletions src/game/client/prediction/entities/character.h
Expand Up @@ -74,6 +74,7 @@ class CCharacter : public CEntity
bool m_Super;
bool m_SuperJump;
bool m_Jetpack;
bool m_NinjaJetpack;
int m_FreezeTime;
int m_FreezeTick;
bool m_DeepFreeze;
Expand All @@ -88,6 +89,7 @@ class CCharacter : public CEntity
};
int m_Hit;
vec2 m_PrevPos;
vec2 m_PrevPrevPos;

int m_TileIndex;
int m_TileFlags;
Expand Down Expand Up @@ -139,6 +141,7 @@ class CCharacter : public CEntity
int GetCID() { return m_ID; }
void SetInput(CNetObj_PlayerInput *pNewInput) { m_LatestInput = m_Input = *pNewInput; };
int GetJumped() { return m_Core.m_Jumped; }
int GetAttackTick() { return m_AttackTick; }

CCharacter(CGameWorld *pGameWorld, int ID, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended = 0);
void Read(CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended, bool IsLocal);
Expand All @@ -148,8 +151,10 @@ class CCharacter : public CEntity
int m_LastJetpackStrength;
bool m_KeepHooked;
int m_GameTeam;
bool m_CanMoveInFreeze;

bool Match(CCharacter *pChar);
void ResetPrediction();
CCharacter() { m_Alive = false; }

private:
Expand All @@ -169,6 +174,7 @@ class CCharacter : public CEntity
int m_QueuedWeapon;

int m_ReloadTimer;
int m_AttackTick;

// these are non-heldback inputs
CNetObj_PlayerInput m_LatestPrevInput;
Expand Down
21 changes: 13 additions & 8 deletions src/game/client/prediction/entities/pickup.cpp
Expand Up @@ -14,6 +14,8 @@ void CPickup::Tick()
CCharacter * pChr = apEnts[i];
if(pChr && pChr->IsAlive())
{
if(GameWorld()->m_WorldConfig.m_IsVanilla && distance(m_Pos, pChr->m_Pos) >= 20.0f*2) // pickup distance is shorter on vanilla due to using ClosestEntity
continue;
if(m_Layer == LAYER_SWITCH && !Collision()->m_pSwitchers[m_Number].m_Status[pChr->Team()]) continue;
bool sound = false;
// player picked us up, is someone was hooking us, let them go
Expand All @@ -24,7 +26,10 @@ void CPickup::Tick()
break;

case POWERUP_ARMOR:
if(pChr->Team() == TEAM_SUPER) continue;
if(!GameWorld()->m_WorldConfig.m_IsDDRace || !GameWorld()->m_WorldConfig.m_PredictDDRace)
continue;
if(pChr->m_Super)
continue;
for(int i = WEAPON_SHOTGUN; i < NUM_WEAPONS; i++)
{
if(pChr->GetWeaponGot(i))
Expand All @@ -47,17 +52,17 @@ void CPickup::Tick()
break;

case POWERUP_WEAPON:

if(m_Subtype >= 0 && m_Subtype < NUM_WEAPONS && (!pChr->GetWeaponGot(m_Subtype) || (pChr->GetWeaponAmmo(m_Subtype) != -1 && !pChr->m_FreezeTime)))
pChr->GiveWeapon(m_Subtype, -1);
break;

case POWERUP_NINJA:
{
// activate ninja on target player
pChr->GiveNinja();
break;
}
case POWERUP_NINJA:
{
// activate ninja on target player
pChr->GiveNinja();
break;
}

default:
break;
};
Expand Down
3 changes: 3 additions & 0 deletions src/game/client/prediction/entities/projectile.cpp
Expand Up @@ -81,6 +81,9 @@ void CProjectile::Tick()

CCharacter *pTargetChr = GameWorld()->IntersectCharacter(PrevPos, ColPos, m_Freeze ? 1.0f : 6.0f, ColPos, pOwnerChar, m_Owner);

if(GameWorld()->m_WorldConfig.m_IsSolo && !(m_Weapon == WEAPON_SHOTGUN && GameWorld()->m_WorldConfig.m_IsDDRace))
pTargetChr = 0;

if(m_LifeSpan > -1)
m_LifeSpan--;

Expand Down
42 changes: 35 additions & 7 deletions src/game/client/prediction/gameworld.cpp
Expand Up @@ -295,6 +295,9 @@ CEntity *CGameWorld::GetEntity(int ID, int EntType)

void CGameWorld::CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamage, int ActivatedTeam, int64_t Mask)
{
if(Owner < 0 && m_WorldConfig.m_IsSolo && !(Weapon == WEAPON_SHOTGUN && m_WorldConfig.m_IsDDRace))
return;

// deal damage
CCharacter *apEnts[MAX_CLIENTS] = {0};
float Radius = 135.0f;
Expand Down Expand Up @@ -375,17 +378,42 @@ void CGameWorld::NetObjAdd(int ObjID, int ObjType, const void *pObjData)
return;
}
}
for(CProjectile *pProj = (CProjectile*) FindFirst(CGameWorld::ENTTYPE_PROJECTILE); pProj; pProj = (CProjectile*) pProj->TypeNext())
if(!UseExtraInfo((CNetObj_Projectile*)pObjData))
{
if(pProj->m_ID == -1 && NetProj.GetOwner() < 0 && NetProj.Match(pProj))
// try to match the newly received (unrecognized) projectile with a locally fired one
for(CProjectile *pProj = (CProjectile*) FindFirst(CGameWorld::ENTTYPE_PROJECTILE); pProj; pProj = (CProjectile*) pProj->TypeNext())
{
pProj->m_ID = ObjID;
pProj->Keep();
return;
if(pProj->m_ID == -1 && NetProj.Match(pProj))
{
pProj->m_ID = ObjID;
pProj->Keep();
return;
}
}
// otherwise try to determine its owner by checking if there is only one player nearby
if(NetProj.m_StartTick >= GameTick()-4)
{
const vec2 NetPos = NetProj.m_Pos - normalize(NetProj.m_Direction)*28.0*0.75;
const bool Prev = (GameTick()-NetProj.m_StartTick) > 1;
float First = 200.0, Second = 200.0;
CCharacter *pClosest = 0;
for(CCharacter *pChar = (CCharacter*) FindFirst(ENTTYPE_CHARACTER); pChar; pChar = (CCharacter *) pChar->TypeNext())
{
float Dist = distance(Prev ? pChar->m_PrevPrevPos : pChar->m_PrevPos, NetPos);
if(Dist < First)
{
pClosest = pChar;
First = Dist;
}
else if(Dist < Second)
Second = Dist;
}
if(pClosest && maximum(First, 2.f)*1.2f < Second)
NetProj.m_Owner = pClosest->m_ID;
}
}
CEntity *pEnt = new CProjectile(NetProj);
InsertEntity(pEnt);
CProjectile *pProj = new CProjectile(NetProj);
InsertEntity((CEntity*)pProj);
}
else if(ObjType == NETOBJTYPE_PICKUP && m_WorldConfig.m_PredictWeapons)
{
Expand Down
4 changes: 3 additions & 1 deletion src/game/client/prediction/gameworld.h
Expand Up @@ -69,8 +69,10 @@ class CGameWorld
bool m_IsFNG;
bool m_InfiniteAmmo;
bool m_PredictTiles;
bool m_PredictFreeze;
int m_PredictFreeze;
bool m_PredictWeapons;
bool m_PredictDDRace;
bool m_IsSolo;
} m_WorldConfig;

bool m_IsValidCopy;
Expand Down
18 changes: 5 additions & 13 deletions src/game/client/render.cpp
Expand Up @@ -284,13 +284,13 @@ void CRenderTools::DrawRoundRect(float x, float y, float w, float h, float r)
DrawRoundRectExt(x,y,w,h,r,0xf);
}

void CRenderTools::DrawUIRect(const CUIRect *r, vec4 Color, int Corners, float Rounding)
void CRenderTools::DrawUIRect(const CUIRect *r, ColorRGBA Color, int Corners, float Rounding)
{
Graphics()->TextureSet(-1);

// TODO: FIX US
Graphics()->QuadsBegin();
Graphics()->SetColor(Color.r, Color.g, Color.b, Color.a);
Graphics()->SetColor(Color);
DrawRoundRectExt(r->x,r->y,r->w,r->h,Rounding*UI()->Scale(), Corners);
Graphics()->QuadsEnd();
}
Expand Down Expand Up @@ -327,7 +327,7 @@ void CRenderTools::DrawCircle(float x, float y, float r, int Segments)
Graphics()->QuadsDrawFreeform(Array, NumItems);
}

void CRenderTools::RenderTee(CAnimState *pAnim, CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, bool Alpha)
void CRenderTools::RenderTee(CAnimState *pAnim, CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha)
{
vec2 Direction = Dir;
vec2 Position = Pos;
Expand All @@ -350,11 +350,7 @@ void CRenderTools::RenderTee(CAnimState *pAnim, CTeeRenderInfo *pInfo, int Emote
Graphics()->QuadsSetRotation(pAnim->GetBody()->m_Angle*pi*2);

// draw body
if(Alpha)
Graphics()->SetColor(pInfo->m_ColorBody.r, pInfo->m_ColorBody.g, pInfo->m_ColorBody.b, pInfo->m_ColorBody.a);
else
Graphics()->SetColor(pInfo->m_ColorBody.r, pInfo->m_ColorBody.g, pInfo->m_ColorBody.b, 1.0f);

Graphics()->SetColor(pInfo->m_ColorBody.r, pInfo->m_ColorBody.g, pInfo->m_ColorBody.b, Alpha);
vec2 BodyPos = Position + vec2(pAnim->GetBody()->m_X, pAnim->GetBody()->m_Y)*AnimScale;
float BodySize = g_Config.m_ClFatSkins ? BaseSize * 1.3 : BaseSize;
Graphics()->RenderQuadContainerAsSprite(m_TeeQuadContainerIndex, OutLine, BodyPos.x, BodyPos.y, BodySize / 64.f, BodySize / 64.f);
Expand Down Expand Up @@ -413,11 +409,7 @@ void CRenderTools::RenderTee(CAnimState *pAnim, CTeeRenderInfo *pInfo, int Emote
cs = 0.5f;
}


if(Alpha)
Graphics()->SetColor(pInfo->m_ColorFeet.r*cs, pInfo->m_ColorFeet.g*cs, pInfo->m_ColorFeet.b*cs, pInfo->m_ColorFeet.a*cs);
else
Graphics()->SetColor(pInfo->m_ColorFeet.r*cs, pInfo->m_ColorFeet.g*cs, pInfo->m_ColorFeet.b*cs, 1.0f);
Graphics()->SetColor(pInfo->m_ColorFeet.r*cs, pInfo->m_ColorFeet.g*cs, pInfo->m_ColorFeet.b*cs, Alpha);

Graphics()->RenderQuadContainerAsSprite(m_TeeQuadContainerIndex, QuadOffset, Position.x + pFoot->m_X*AnimScale, Position.y + pFoot->m_Y*AnimScale, w / 64.f, h / 32.f);
}
Expand Down
25 changes: 13 additions & 12 deletions src/game/client/render.h
Expand Up @@ -4,6 +4,7 @@
#define GAME_CLIENT_RENDER_H

#include <base/vmath.h>
#include <base/color.h>
#include <game/mapitems.h>
#include "ui.h"

Expand All @@ -14,15 +15,15 @@ class CTeeRenderInfo
CTeeRenderInfo()
{
m_Texture = -1;
m_ColorBody = vec4(1,1,1,1);
m_ColorFeet = vec4(1,1,1,1);
m_ColorBody = ColorRGBA(1,1,1);
m_ColorFeet = ColorRGBA(1,1,1);
m_Size = 1.0f;
m_GotAirJump = 1;
};

int m_Texture;
vec4 m_ColorBody;
vec4 m_ColorFeet;
ColorRGBA m_ColorBody;
ColorRGBA m_ColorFeet;
float m_Size;
int m_GotAirJump;
};
Expand Down Expand Up @@ -69,25 +70,25 @@ class CRenderTools

int CreateRoundRectQuadContainer(float x, float y, float w, float h, float r, int Corners);

void DrawUIRect(const CUIRect *pRect, vec4 Color, int Corners, float Rounding);
void DrawUIRect(const CUIRect *pRect, ColorRGBA Color, int Corners, float Rounding);

void DrawCircle(float x, float y, float r, int Segments);

// larger rendering methods
void RenderTilemapGenerateSkip(class CLayers *pLayers);

// object render methods (gc_render_obj.cpp)
void RenderTee(class CAnimState *pAnim, CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, bool Alpha = false);
void RenderTee(class CAnimState *pAnim, CTeeRenderInfo *pInfo, int Emote, vec2 Dir, vec2 Pos, float Alpha = 1.0f);

// map render methods (gc_render_map.cpp)
static void RenderEvalEnvelope(CEnvPoint *pPoints, int NumPoints, int Channels, float Time, float *pResult);
void RenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser);
void ForceRenderQuads(CQuad *pQuads, int NumQuads, int Flags, ENVELOPE_EVAL pfnEval, void *pUser, float Alpha = 1.0f);
void RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 Color, int RenderFlags, ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset);
void RenderTilemap(CTile *pTiles, int w, int h, float Scale, ColorRGBA Color, int RenderFlags, ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset);

// render a rectangle made of IndexIn tiles, over a background made of IndexOut tiles
// the rectangle include all tiles in [RectX, RectX+RectW-1] x [RectY, RectY+RectH-1]
void RenderTileRectangle(int RectX, int RectY, int RectW, int RectH, unsigned char IndexIn, unsigned char IndexOut, float Scale, vec4 Color, int RenderFlags, ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset);
void RenderTileRectangle(int RectX, int RectY, int RectW, int RectH, unsigned char IndexIn, unsigned char IndexOut, float Scale, ColorRGBA Color, int RenderFlags, ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset);

// helpers
void MapscreenToWorld(float CenterX, float CenterY, float ParallaxX, float ParallaxY,
Expand All @@ -99,10 +100,10 @@ class CRenderTools
void RenderSpeedupOverlay(CSpeedupTile *pTele, int w, int h, float Scale, float Alpha=1.0f);
void RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float Scale, float Alpha=1.0f);
void RenderTuneOverlay(CTuneTile *pTune, int w, int h, float Scale, float Alpha=1.0f);
void RenderTelemap(CTeleTile *pTele, int w, int h, float Scale, vec4 Color, int RenderFlags);
void RenderSpeedupmap(CSpeedupTile *pTele, int w, int h, float Scale, vec4 Color, int RenderFlags);
void RenderSwitchmap(CSwitchTile *pSwitch, int w, int h, float Scale, vec4 Color, int RenderFlags);
void RenderTunemap(CTuneTile *pTune, int w, int h, float Scale, vec4 Color, int RenderFlags);
void RenderTelemap(CTeleTile *pTele, int w, int h, float Scale, ColorRGBA Color, int RenderFlags);
void RenderSpeedupmap(CSpeedupTile *pTele, int w, int h, float Scale, ColorRGBA Color, int RenderFlags);
void RenderSwitchmap(CSwitchTile *pSwitch, int w, int h, float Scale, ColorRGBA Color, int RenderFlags);
void RenderTunemap(CTuneTile *pTune, int w, int h, float Scale, ColorRGBA Color, int RenderFlags);
};

#endif
43 changes: 27 additions & 16 deletions src/game/client/render_map.cpp
Expand Up @@ -178,7 +178,7 @@ void CRenderTools::ForceRenderQuads(CQuad *pQuads, int NumQuads, int RenderFlags

void CRenderTools::RenderTileRectangle(int RectX, int RectY, int RectW, int RectH,
unsigned char IndexIn, unsigned char IndexOut,
float Scale, vec4 Color, int RenderFlags,
float Scale, ColorRGBA Color, int RenderFlags,
ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset)
{
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
Expand Down Expand Up @@ -254,7 +254,7 @@ void CRenderTools::RenderTileRectangle(int RectX, int RectY, int RectW, int Rect
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}

void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 Color, int RenderFlags,
void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, ColorRGBA Color, int RenderFlags,
ENVELOPE_EVAL pfnEval, void *pUser, int ColorEnv, int ColorEnvOffset)
{
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
Expand Down Expand Up @@ -415,6 +415,9 @@ void CRenderTools::RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale
if(EndX - StartX > Graphics()->ScreenWidth() / g_Config.m_GfxTextOverlay || EndY - StartY > Graphics()->ScreenHeight() / g_Config.m_GfxTextOverlay)
return; // its useless to render text at this distance

float Size = g_Config.m_ClTextEntitiesSize/100.f;
float ToCenterOffset = (1-Size)/2.f;

for(int y = StartY; y < EndY; y++)
for(int x = StartX; x < EndX; x++)
{
Expand All @@ -439,7 +442,7 @@ void CRenderTools::RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale
char aBuf[16];
str_format(aBuf, sizeof(aBuf), "%d", Index);
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
UI()->TextRender()->Text(0, mx*Scale - 3.f, my*Scale, Scale - 5.f, aBuf, -1);
UI()->TextRender()->Text(0, mx*Scale - 3.f, (my+ToCenterOffset)*Scale, Size*Scale, aBuf, -1);
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
}
}
Expand All @@ -460,6 +463,9 @@ void CRenderTools::RenderSpeedupOverlay(CSpeedupTile *pSpeedup, int w, int h, fl
if(EndX - StartX > Graphics()->ScreenWidth() / g_Config.m_GfxTextOverlay || EndY - StartY > Graphics()->ScreenHeight() / g_Config.m_GfxTextOverlay)
return; // its useless to render text at this distance

float Size = g_Config.m_ClTextEntitiesSize / 100.f;
float ToCenterOffset = (1-Size)/2.f;

for(int y = StartY; y < EndY; y++)
for(int x = StartX; x < EndX; x++)
{
Expand Down Expand Up @@ -498,13 +504,13 @@ void CRenderTools::RenderSpeedupOverlay(CSpeedupTile *pSpeedup, int w, int h, fl
char aBuf[16];
str_format(aBuf, sizeof(aBuf), "%d", Force);
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
UI()->TextRender()->Text(0, mx*Scale, (my*Scale) + 16.f + ((16.f - (Scale - 20.f)) / 2.f), Scale - 20.f, aBuf, -1);
UI()->TextRender()->Text(0, mx*Scale, (my+0.5+ToCenterOffset/2)*Scale, Size*Scale/2.f, aBuf, -1);
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
if(MaxSpeed)
{
str_format(aBuf, sizeof(aBuf), "%d", MaxSpeed);
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
UI()->TextRender()->Text(0, mx*Scale, (my*Scale) + ((16.f - (Scale - 20.f)) / 2.f), Scale - 20.f, aBuf, -1);
UI()->TextRender()->Text(0, mx*Scale, (my+ToCenterOffset/2)*Scale, Size*Scale/2.f, aBuf, -1);
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
}
}
Expand All @@ -529,6 +535,9 @@ void CRenderTools::RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float
if(EndX - StartX > Graphics()->ScreenWidth() / g_Config.m_GfxTextOverlay || EndY - StartY > Graphics()->ScreenHeight() / g_Config.m_GfxTextOverlay)
return; // its useless to render text at this distance

float Size = g_Config.m_ClTextEntitiesSize/100.f;
float ToCenterOffset = (1-Size)/2.f;

for(int y = StartY; y < EndY; y++)
for(int x = StartX; x < EndX; x++)
{
Expand All @@ -553,7 +562,7 @@ void CRenderTools::RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float
char aBuf[16];
str_format(aBuf, sizeof(aBuf), "%d", Index);
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
UI()->TextRender()->Text(0, mx*Scale, my*Scale + 16.f + ((16.f - (Scale - 20.f)) / 2.f), Scale - 20.f, aBuf, -1);
UI()->TextRender()->Text(0, mx*Scale, (my+ToCenterOffset/2)*Scale, Size*Scale/2.f, aBuf, -1);
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
}

Expand All @@ -563,7 +572,7 @@ void CRenderTools::RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float
char aBuf[16];
str_format(aBuf, sizeof(aBuf), "%d", Delay);
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
UI()->TextRender()->Text(0, mx*Scale, my*Scale + ((16.f - (Scale - 20.f)) / 2.f), Scale - 20.f, aBuf, -1);
UI()->TextRender()->Text(0, mx*Scale, (my+0.5f+ToCenterOffset/2)* Scale, Size*Scale/2.f, aBuf, -1);
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
}
}
Expand All @@ -587,6 +596,8 @@ void CRenderTools::RenderTuneOverlay(CTuneTile *pTune, int w, int h, float Scale
if(EndX - StartX > Graphics()->ScreenWidth() / g_Config.m_GfxTextOverlay || EndY - StartY > Graphics()->ScreenHeight() / g_Config.m_GfxTextOverlay)
return; // its useless to render text at this distance

float Size = g_Config.m_ClTextEntitiesSize/100.f;

for(int y = StartY; y < EndY; y++)
for(int x = StartX; x < EndX; x++)
{
Expand All @@ -611,15 +622,15 @@ void CRenderTools::RenderTuneOverlay(CTuneTile *pTune, int w, int h, float Scale
char aBuf[16];
str_format(aBuf, sizeof(aBuf), "%d", Index);
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, Alpha);
UI()->TextRender()->Text(0, mx*Scale+11.f, my*Scale+6.f, Scale/1.5f-5.f, aBuf, -1); // numbers shouldn't be too big and in the center of the tile
UI()->TextRender()->Text(0, mx*Scale+11.f, my*Scale+6.f, Size*Scale/1.5f-5.f, aBuf, -1); // numbers shouldn't be too big and in the center of the tile
UI()->TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
}
}

Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}

void CRenderTools::RenderTelemap(CTeleTile *pTele, int w, int h, float Scale, vec4 Color, int RenderFlags)
void CRenderTools::RenderTelemap(CTeleTile *pTele, int w, int h, float Scale, ColorRGBA Color, int RenderFlags)
{
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
Expand All @@ -630,7 +641,7 @@ void CRenderTools::RenderTelemap(CTeleTile *pTele, int w, int h, float Scale, ve
float FinalTilesetScale = FinalTileSize/TilePixelSize;

Graphics()->QuadsBegin();
Graphics()->SetColor(Color.r, Color.g, Color.b, Color.a);
Graphics()->SetColor(Color);

int StartY = (int)(ScreenY0/Scale)-1;
int StartX = (int)(ScreenX0/Scale)-1;
Expand Down Expand Up @@ -710,7 +721,7 @@ void CRenderTools::RenderTelemap(CTeleTile *pTele, int w, int h, float Scale, ve
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}

void CRenderTools::RenderSpeedupmap(CSpeedupTile *pSpeedupTile, int w, int h, float Scale, vec4 Color, int RenderFlags)
void CRenderTools::RenderSpeedupmap(CSpeedupTile *pSpeedupTile, int w, int h, float Scale, ColorRGBA Color, int RenderFlags)
{
//Graphics()->TextureSet(img_get(tmap->image));
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
Expand All @@ -723,7 +734,7 @@ void CRenderTools::RenderSpeedupmap(CSpeedupTile *pSpeedupTile, int w, int h, fl
float FinalTilesetScale = FinalTileSize/TilePixelSize;

Graphics()->QuadsBegin();
Graphics()->SetColor(Color.r, Color.g, Color.b, Color.a);
Graphics()->SetColor(Color);

int StartY = (int)(ScreenY0/Scale)-1;
int StartX = (int)(ScreenX0/Scale)-1;
Expand Down Expand Up @@ -803,7 +814,7 @@ void CRenderTools::RenderSpeedupmap(CSpeedupTile *pSpeedupTile, int w, int h, fl
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}

void CRenderTools::RenderSwitchmap(CSwitchTile *pSwitchTile, int w, int h, float Scale, vec4 Color, int RenderFlags)
void CRenderTools::RenderSwitchmap(CSwitchTile *pSwitchTile, int w, int h, float Scale, ColorRGBA Color, int RenderFlags)
{
//Graphics()->TextureSet(img_get(tmap->image));
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
Expand All @@ -816,7 +827,7 @@ void CRenderTools::RenderSwitchmap(CSwitchTile *pSwitchTile, int w, int h, float
float FinalTilesetScale = FinalTileSize/TilePixelSize;

Graphics()->QuadsBegin();
Graphics()->SetColor(Color.r, Color.g, Color.b, Color.a);
Graphics()->SetColor(Color);

int StartY = (int)(ScreenY0/Scale)-1;
int StartX = (int)(ScreenX0/Scale)-1;
Expand Down Expand Up @@ -939,7 +950,7 @@ void CRenderTools::RenderSwitchmap(CSwitchTile *pSwitchTile, int w, int h, float
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
}

void CRenderTools::RenderTunemap(CTuneTile *pTune, int w, int h, float Scale, vec4 Color, int RenderFlags)
void CRenderTools::RenderTunemap(CTuneTile *pTune, int w, int h, float Scale, ColorRGBA Color, int RenderFlags)
{
float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
Expand All @@ -950,7 +961,7 @@ void CRenderTools::RenderTunemap(CTuneTile *pTune, int w, int h, float Scale, ve
float FinalTilesetScale = FinalTileSize/TilePixelSize;

Graphics()->QuadsBegin();
Graphics()->SetColor(Color.r, Color.g, Color.b, Color.a);
Graphics()->SetColor(Color);

int StartY = (int)(ScreenY0/Scale)-1;
int StartX = (int)(ScreenX0/Scale)-1;
Expand Down
52 changes: 26 additions & 26 deletions src/game/editor/auto_map.cpp
Expand Up @@ -109,7 +109,7 @@ void CAutoMapper::Load(const char* pTileName)
NewIndexRule.m_Flag = 0;
NewIndexRule.m_RandomProbability = 1.0;
NewIndexRule.m_DefaultRule = true;
NewIndexRule.m_SkipEmpty = false;
NewIndexRule.m_SkipEmpty = false;
NewIndexRule.m_SkipFull = false;

if(str_length(aOrientation1) > 0)
Expand Down Expand Up @@ -258,19 +258,19 @@ void CAutoMapper::Load(const char* pTileName)
CPosRule NewPosRule = {x, y, Value, NewIndexList};
pCurrentIndex->m_aRules.add(NewPosRule);

pCurrentConf->m_StartX = min(pCurrentConf->m_StartX, NewPosRule.m_X);
pCurrentConf->m_StartY = min(pCurrentConf->m_StartY, NewPosRule.m_Y);
pCurrentConf->m_EndX = max(pCurrentConf->m_EndX, NewPosRule.m_X);
pCurrentConf->m_EndY = max(pCurrentConf->m_EndY, NewPosRule.m_Y);

if(x == 0 && y == 0) {
for(int i = 0; i < NewIndexList.size(); ++i)
{
if(Value == CPosRule::INDEX && NewIndexList[i].m_ID == 0)
pCurrentIndex->m_SkipFull = true;
else
pCurrentIndex->m_SkipEmpty = true;
}
pCurrentConf->m_StartX = minimum(pCurrentConf->m_StartX, NewPosRule.m_X);
pCurrentConf->m_StartY = minimum(pCurrentConf->m_StartY, NewPosRule.m_Y);
pCurrentConf->m_EndX = maximum(pCurrentConf->m_EndX, NewPosRule.m_X);
pCurrentConf->m_EndY = maximum(pCurrentConf->m_EndY, NewPosRule.m_Y);

if(x == 0 && y == 0) {
for(int i = 0; i < NewIndexList.size(); ++i)
{
if(Value == CPosRule::INDEX && NewIndexList[i].m_ID == 0)
pCurrentIndex->m_SkipFull = true;
else
pCurrentIndex->m_SkipEmpty = true;
}
}
}
}
Expand Down Expand Up @@ -323,13 +323,13 @@ void CAutoMapper::Load(const char* pTileName)
CIndexInfo NewIndexInfo = {0, 0, false};
NewIndexList.add(NewIndexInfo);
CPosRule NewPosRule = {0, 0, CPosRule::NOTINDEX, NewIndexList};
pIndexRule->m_aRules.add(NewPosRule);
pIndexRule->m_SkipEmpty = true;
pIndexRule->m_SkipFull = false;
}
if(pIndexRule->m_SkipEmpty && pIndexRule->m_SkipFull)
{
pIndexRule->m_aRules.add(NewPosRule);

pIndexRule->m_SkipEmpty = true;
pIndexRule->m_SkipFull = false;
}
if(pIndexRule->m_SkipEmpty && pIndexRule->m_SkipFull)
{
pIndexRule->m_SkipFull = false;
}
}
Expand Down Expand Up @@ -452,10 +452,10 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedO

for(int i = 0; i < pRun->m_aIndexRules.size(); ++i)
{
CIndexRule *pIndexRule = &pRun->m_aIndexRules[i];
if(pIndexRule->m_SkipEmpty && pTile->m_Index == 0) // skip empty tiles
continue;
if(pIndexRule->m_SkipFull && pTile->m_Index != 0) // skip full tiles
CIndexRule *pIndexRule = &pRun->m_aIndexRules[i];
if(pIndexRule->m_SkipEmpty && pTile->m_Index == 0) // skip empty tiles
continue;
if(pIndexRule->m_SkipFull && pTile->m_Index != 0) // skip full tiles
continue;

bool RespectRules = true;
Expand Down Expand Up @@ -501,7 +501,7 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedO
if(RespectRules &&
(pIndexRule->m_RandomProbability >= 1.0 || HashLocation(Seed, h, i, x + SeedOffsetX, y + SeedOffsetY) < HASH_MAX * pIndexRule->m_RandomProbability))
{
pTile->m_Index = pIndexRule->m_ID;
pTile->m_Index = pIndexRule->m_ID;
pTile->m_Flags = pIndexRule->m_Flag;
}
}
Expand Down
120 changes: 60 additions & 60 deletions src/game/editor/editor.cpp
Expand Up @@ -86,7 +86,7 @@ int CEditor::ms_SpeedupTexture;
int CEditor::ms_SwitchTexture;
int CEditor::ms_TuneTexture;

vec3 CEditor::ms_PickerColor;
ColorHSVA CEditor::ms_PickerColor;
int CEditor::ms_SVPicker;
int CEditor::ms_HuePicker;

Expand Down Expand Up @@ -258,8 +258,8 @@ void CLayerGroup::GetSize(float *w, float *h)
{
float lw, lh;
m_lLayers[i]->GetSize(&lw, &lh);
*w = max(*w, lw);
*h = max(*h, lh);
*w = maximum(*w, lw);
*h = maximum(*h, lh);
}
}

Expand Down Expand Up @@ -374,13 +374,13 @@ int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned Str
// do scrolling
if(UI()->MouseX() < pRect->x && s_ScrollStart-UI()->MouseX() > 10.0f)
{
s_AtIndex = max(0, s_AtIndex-1);
s_AtIndex = maximum(0, s_AtIndex-1);
s_ScrollStart = UI()->MouseX();
UpdateOffset = true;
}
else if(UI()->MouseX() > pRect->x+pRect->w && UI()->MouseX()-s_ScrollStart > 10.0f)
{
s_AtIndex = min(Len, s_AtIndex+1);
s_AtIndex = minimum(Len, s_AtIndex+1);
s_ScrollStart = UI()->MouseX();
UpdateOffset = true;
}
Expand Down Expand Up @@ -417,7 +417,7 @@ int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned Str
{
if(!UI()->MouseButton(0))
{
s_AtIndex = min(s_AtIndex, str_length(pStr));
s_AtIndex = minimum(s_AtIndex, str_length(pStr));
s_DoScroll = false;
UI()->SetActiveItem(0);
}
Expand All @@ -436,7 +436,7 @@ int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned Str
UI()->SetHotItem(pID);

CUIRect Textbox = *pRect;
RenderTools()->DrawUIRect(&Textbox, vec4(1, 1, 1, 0.5f), Corners, 3.0f);
RenderTools()->DrawUIRect(&Textbox, ColorRGBA(1, 1, 1, 0.5f), Corners, 3.0f);
Textbox.VMargin(2.0f, &Textbox);

const char *pDisplayStr = pStr;
Expand All @@ -463,7 +463,7 @@ int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned Str
float wt = TextRender()->TextWidth(0, FontSize, pDisplayStr, -1);
do
{
*Offset += min(wt-*Offset-Textbox.w, Textbox.w/3);
*Offset += minimum(wt-*Offset-Textbox.w, Textbox.w/3);
}
while(w-*Offset > Textbox.w);
}
Expand All @@ -472,7 +472,7 @@ int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned Str
// move to the right
do
{
*Offset = max(0.0f, *Offset-Textbox.w/3);
*Offset = maximum(0.0f, *Offset-Textbox.w/3);
}
while(w-*Offset < 0.0f);
}
Expand All @@ -498,13 +498,13 @@ int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned Str
return ReturnValue;
}

vec4 CEditor::ButtonColorMul(const void *pID)
float CEditor::ButtonColorMul(const void *pID)
{
if(UI()->ActiveItem() == pID)
return vec4(1,1,1,0.5f);
return 0.5f;
else if(UI()->HotItem() == pID)
return vec4(1,1,1,1.5f);
return vec4(1,1,1,1);
return 1.5f;
return 1.0f;
}

float CEditor::UiDoScrollbarV(const void *pID, const CUIRect *pRect, float Current)
Expand Down Expand Up @@ -546,67 +546,67 @@ float CEditor::UiDoScrollbarV(const void *pID, const CUIRect *pRect, float Curre
// render
CUIRect Rail;
pRect->VMargin(5.0f, &Rail);
RenderTools()->DrawUIRect(&Rail, vec4(1,1,1,0.25f), 0, 0.0f);
RenderTools()->DrawUIRect(&Rail, ColorRGBA(1,1,1,0.25f), 0, 0.0f);

CUIRect Slider = Handle;
Slider.w = Rail.x-Slider.x;
RenderTools()->DrawUIRect(&Slider, vec4(1,1,1,0.25f), CUI::CORNER_L, 2.5f);
RenderTools()->DrawUIRect(&Slider, ColorRGBA(1,1,1,0.25f), CUI::CORNER_L, 2.5f);
Slider.x = Rail.x+Rail.w;
RenderTools()->DrawUIRect(&Slider, vec4(1,1,1,0.25f), CUI::CORNER_R, 2.5f);
RenderTools()->DrawUIRect(&Slider, ColorRGBA(1,1,1,0.25f), CUI::CORNER_R, 2.5f);

Slider = Handle;
Slider.Margin(5.0f, &Slider);
RenderTools()->DrawUIRect(&Slider, vec4(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 Ret;
}

vec4 CEditor::GetButtonColor(const void *pID, int Checked)
ColorRGBA CEditor::GetButtonColor(const void *pID, int Checked)
{
if(Checked < 0)
return vec4(0,0,0,0.5f);
return ColorRGBA(0,0,0,0.5f);

switch(Checked)
{
case 7: // selected + game layers
if(UI()->HotItem() == pID)
return vec4(1,0,0,0.4f);
return vec4(1,0,0,0.2f);
return ColorRGBA(1,0,0,0.4f);
return ColorRGBA(1,0,0,0.2f);

case 6: // game layers
if(UI()->HotItem() == pID)
return vec4(1,1,1,0.4f);
return vec4(1,1,1,0.2f);
return ColorRGBA(1,1,1,0.4f);
return ColorRGBA(1,1,1,0.2f);

case 5: // selected + image/sound should be embedded
if(UI()->HotItem() == pID)
return vec4(1,0,0,0.75f);
return vec4(1,0,0,0.5f);
return ColorRGBA(1,0,0,0.75f);
return ColorRGBA(1,0,0,0.5f);

case 4: // image/sound should be embedded
if(UI()->HotItem() == pID)
return vec4(1,0,0,1.0f);
return vec4(1,0,0,0.875f);
return ColorRGBA(1,0,0,1.0f);
return ColorRGBA(1,0,0,0.875f);

case 3: // selected + unused image/sound
if(UI()->HotItem() == pID)
return vec4(1,0,1,0.75f);
return vec4(1,0,1,0.5f);
return ColorRGBA(1,0,1,0.75f);
return ColorRGBA(1,0,1,0.5f);

case 2: // unused image/sound
if(UI()->HotItem() == pID)
return vec4(0,0,1,0.75f);
return vec4(0,0,1,0.5f);
return ColorRGBA(0,0,1,0.75f);
return ColorRGBA(0,0,1,0.5f);

case 1: // selected
if(UI()->HotItem() == pID)
return vec4(1,0,0,0.75f);
return vec4(1,0,0,0.5f);
return ColorRGBA(1,0,0,0.75f);
return ColorRGBA(1,0,0,0.5f);

default: // regular
if(UI()->HotItem() == pID)
return vec4(1,1,1,0.75f);
return vec4(1,1,1,0.5f);
return ColorRGBA(1,1,1,0.75f);
return ColorRGBA(1,1,1,0.5f);
}
}

Expand Down Expand Up @@ -639,11 +639,11 @@ int CEditor::DoButton_Editor(const void *pID, const char *pText, int Checked, co
return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip);
}

int CEditor::DoButton_Env(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pToolTip, vec3 BaseColor)
int CEditor::DoButton_Env(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pToolTip, ColorRGBA BaseColor)
{
float Bright = Checked ? 1.0f : 0.5f;
float Alpha = UI()->HotItem() == pID ? 1.0f : 0.75f;
vec4 Color = vec4(BaseColor.r*Bright, BaseColor.g*Bright, BaseColor.b*Bright, Alpha);
ColorRGBA Color = ColorRGBA(BaseColor.r*Bright, BaseColor.g*Bright, BaseColor.b*Bright, Alpha);

RenderTools()->DrawUIRect(pRect, Color, CUI::CORNER_ALL, 3.0f);
UI()->DoLabel(pRect, pText, 10.f, 0, -1);
Expand All @@ -665,7 +665,7 @@ int CEditor::DoButton_File(const void *pID, const char *pText, int Checked, cons
int CEditor::DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip)
{
CUIRect r = *pRect;
RenderTools()->DrawUIRect(&r, vec4(0.5f, 0.5f, 0.5f, 1.0f), CUI::CORNER_T, 3.0f);
RenderTools()->DrawUIRect(&r, ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f), CUI::CORNER_T, 3.0f);

r = *pRect;
r.VMargin(5.0f, &r);
Expand Down Expand Up @@ -714,7 +714,7 @@ int CEditor::DoButton_ButtonDec(const void *pID, const char *pText, int Checked,
return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip);
}

int CEditor::DoButton_ColorPicker(const void *pID, const CUIRect *pRect, vec4 *pColor, const char *pToolTip)
int CEditor::DoButton_ColorPicker(const void *pID, const CUIRect *pRect, ColorRGBA *pColor, const char *pToolTip)
{
RenderTools()->DrawUIRect(pRect, *pColor, 0, 0.0f);
return DoButton_Editor_Common(pID, 0x0, 0, pRect, 0, pToolTip);
Expand Down Expand Up @@ -775,7 +775,7 @@ void CEditor::RenderBackground(CUIRect View, int Texture, float Size, float Brig
Graphics()->QuadsEnd();
}

int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip, bool IsDegree, bool IsHex, int Corners, vec4* Color)
int CEditor::UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip, bool IsDegree, bool IsHex, int Corners, ColorRGBA* Color)
{
// logic
static float s_Value;
Expand Down Expand Up @@ -1278,7 +1278,7 @@ void CEditor::DoToolbar(CUIRect ToolBar)
if(m_Brush.m_lLayers[i]->m_Type == LAYERTYPE_TILES)
{
TileLayer = true;
s_RotationAmount = max(90, (s_RotationAmount/90)*90);
s_RotationAmount = maximum(90, (s_RotationAmount/90)*90);
break;
}
s_RotationAmount = UiDoValueSelector(&s_RotationAmount, &Button, "", s_RotationAmount, TileLayer?90:1, 359, TileLayer?90:1, TileLayer?10.0f:2.0f, "Rotation of the brush in degrees. Use left mouse button to drag and change the value. Hold shift to be more precise.", true);
Expand Down Expand Up @@ -2386,7 +2386,7 @@ void CEditor::DoMapEditor(CUIRect View)
else
{
// fix aspect ratio of the image in the picker
float Max = min(View.w, View.h);
float Max = minimum(View.w, View.h);
View.w = View.h = Max;
}

Expand Down Expand Up @@ -2998,7 +2998,7 @@ void CEditor::DoMapEditor(CUIRect View)
}


int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *pNewVal, vec4 Color)
int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *pNewVal, ColorRGBA Color)
{
int Change = -1;

Expand Down Expand Up @@ -3128,7 +3128,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *
NewColorHex |= UiDoValueSelector(((char *)&pIDs[i]-1), &Shifter, "", (pProps[i].m_Value >> 8)&0xFFFFFF, 0, 0xFFFFFF, 1, 1.0f, "Use left mouse button to drag and change the color value. Hold shift to be more precise. Rightclick to edit as text.", false, true) << 8;

// color picker
vec4 Color = vec4(
ColorRGBA Color = ColorRGBA(
((pProps[i].m_Value >> s_aShift[0])&0xff)/255.0f,
((pProps[i].m_Value >> s_aShift[1])&0xff)/255.0f,
((pProps[i].m_Value >> s_aShift[2])&0xff)/255.0f,
Expand All @@ -3137,13 +3137,13 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *
static int s_ColorPicker, s_ColorPickerID;
if(DoButton_ColorPicker(&s_ColorPicker, &ColorBox, &Color))
{
ms_PickerColor = RgbToHsv(vec3(Color.r, Color.g, Color.b));
ms_PickerColor = color_cast<ColorHSVA>(Color);
UiInvokePopupMenu(&s_ColorPickerID, 0, UI()->MouseX(), UI()->MouseY(), 180, 150, PopupColorPicker);
}

if(UI()->HotItem() == &ms_SVPicker || UI()->HotItem() == &ms_HuePicker)
{
vec3 c = HsvToRgb(ms_PickerColor);
ColorRGBA c = color_cast<ColorRGBA>(ms_PickerColor);
NewColor = ((int)(c.r * 255.0f)&0xff) << 24 | ((int)(c.g * 255.0f)&0xff) << 16 | ((int)(c.b * 255.0f)&0xff) << 8 | (pProps[i].m_Value&0xff);
}

Expand Down Expand Up @@ -3201,11 +3201,11 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *
Up.VSplitLeft(1.0f, 0, &Up);
Left.VSplitLeft(10.0f, &Left, &Shifter);
Shifter.VSplitRight(10.0f, &Shifter, &Right);
RenderTools()->DrawUIRect(&Shifter, vec4(1,1,1,0.5f), 0, 0.0f);
RenderTools()->DrawUIRect(&Shifter, ColorRGBA(1,1,1,0.5f), 0, 0.0f);
UI()->DoLabel(&Shifter, "X", 10.0f, 0, -1);
Up.VSplitLeft(10.0f, &Up, &Shifter);
Shifter.VSplitRight(10.0f, &Shifter, &Down);
RenderTools()->DrawUIRect(&Shifter, vec4(1,1,1,0.5f), 0, 0.0f);
RenderTools()->DrawUIRect(&Shifter, ColorRGBA(1,1,1,0.5f), 0, 0.0f);
UI()->DoLabel(&Shifter, "Y", 10.0f, 0, -1);
if(DoButton_ButtonDec(&pIDs[i], "-", 0, &Left, 0, "Left"))
{
Expand Down Expand Up @@ -3966,7 +3966,7 @@ void CEditor::RenderImages(CUIRect ToolBox, CUIRect View)
r.w = r.h;
else
r.h = r.w;
float Max = (float)(max(m_Map.m_lImages[i]->m_Width, m_Map.m_lImages[i]->m_Height));
float Max = (float)(maximum(m_Map.m_lImages[i]->m_Width, m_Map.m_lImages[i]->m_Height));
r.w *= m_Map.m_lImages[i]->m_Width/Max;
r.h *= m_Map.m_lImages[i]->m_Height/Max;
Graphics()->TextureSet(m_Map.m_lImages[i]->m_TexID);
Expand Down Expand Up @@ -4139,9 +4139,9 @@ static int EditorListdirCallback(const char *pName, int IsDir, int StorageType,
else
{
if(pEditor->m_FileDialogFileType == CEditor::FILETYPE_SOUND)
str_copy(Item.m_aName, pName, min(static_cast<int>(sizeof(Item.m_aName)), Length-4));
str_copy(Item.m_aName, pName, minimum(static_cast<int>(sizeof(Item.m_aName)), Length-4));
else
str_copy(Item.m_aName, pName, min(static_cast<int>(sizeof(Item.m_aName)), Length-3));
str_copy(Item.m_aName, pName, minimum(static_cast<int>(sizeof(Item.m_aName)), Length-3));
}
Item.m_IsDir = IsDir != 0;
Item.m_IsLink = false;
Expand Down Expand Up @@ -4192,10 +4192,10 @@ void CEditor::RenderFileDialog()
CUIRect Preview;
float Width = View.w, Height = View.h;

RenderTools()->DrawUIRect(&View, vec4(0,0,0,0.25f), 0, 0);
RenderTools()->DrawUIRect(&View, ColorRGBA(0,0,0,0.25f), 0, 0);
View.VMargin(150.0f, &View);
View.HMargin(50.0f, &View);
RenderTools()->DrawUIRect(&View, vec4(0,0,0,0.75f), CUI::CORNER_ALL, 5.0f);
RenderTools()->DrawUIRect(&View, ColorRGBA(0,0,0,0.75f), CUI::CORNER_ALL, 5.0f);
View.Margin(10.0f, &View);

CUIRect Title, FileBox, FileBoxLabel, ButtonBar, Scroll, PathBox;
Expand All @@ -4213,7 +4213,7 @@ void CEditor::RenderFileDialog()
View.VSplitRight(15.0f, &View, &Scroll);

// title
RenderTools()->DrawUIRect(&Title, vec4(1, 1, 1, 0.25f), CUI::CORNER_ALL, 4.0f);
RenderTools()->DrawUIRect(&Title, ColorRGBA(1, 1, 1, 0.25f), CUI::CORNER_ALL, 4.0f);
Title.VMargin(10.0f, &Title);
UI()->DoLabel(&Title, m_pFileDialogTitle, 12.0f, -1, -1);

Expand Down Expand Up @@ -4255,7 +4255,7 @@ void CEditor::RenderFileDialog()
// clearSearchbox button
{
static int s_ClearButton = 0;
RenderTools()->DrawUIRect(&ClearBox, vec4(1, 1, 1, 0.33f)*ButtonColorMul(&s_ClearButton), CUI::CORNER_R, 3.0f);
RenderTools()->DrawUIRect(&ClearBox, ColorRGBA(1, 1, 1, 0.33f*ButtonColorMul(&s_ClearButton)), CUI::CORNER_R, 3.0f);
UI()->DoLabel(&ClearBox, "Ă—", 10.0f, 0);
if(UI()->DoButtonLogic(&s_ClearButton, "Ă—", 0, &ClearBox))
{
Expand Down Expand Up @@ -4858,12 +4858,12 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
char aBuf[512];
str_format(aBuf, sizeof(aBuf),"%d/%d", m_SelectedEnvelope+1, m_Map.m_lEnvelopes.size());

vec4 EnvColor = vec4(1, 1, 1, 0.5f);
ColorRGBA EnvColor = ColorRGBA(1, 1, 1, 0.5f);
if(m_Map.m_lEnvelopes.size())
{
EnvColor = IsEnvelopeUsed(m_SelectedEnvelope) ?
vec4(1, 0.7f, 0.7f, 0.5f) :
vec4(0.7f, 1, 0.7f, 0.5f);
ColorRGBA(1, 0.7f, 0.7f, 0.5f) :
ColorRGBA(0.7f, 1, 0.7f, 0.5f);
}

RenderTools()->DrawUIRect(&Shifter, EnvColor, 0, 0.0f);
Expand Down Expand Up @@ -4921,7 +4921,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
static int sEnvelopeEditorID = 0;
static int s_ActiveChannels = 0xf;

vec3 aColors[] = {vec3(1,0.2f,0.2f), vec3(0.2f,1,0.2f), vec3(0.2f,0.2f,1), vec3(1,1,0.2f)};
ColorRGBA aColors[] = {ColorRGBA(1,0.2f,0.2f), ColorRGBA(0.2f,1,0.2f), ColorRGBA(0.2f,0.2f,1), ColorRGBA(1,1,0.2f)};

if(pEnvelope)
{
Expand Down Expand Up @@ -6108,7 +6108,7 @@ void CEditor::Init()
m_Map.m_UndoModified = 0;
m_LastUndoUpdateTime = time_get();

ms_PickerColor = vec3(1.0f, 0.0f, 0.0f);
ms_PickerColor = ColorHSVA(1.0f, 0.0f, 0.0f);
}

void CEditor::DoMapBorder()
Expand Down
14 changes: 7 additions & 7 deletions src/game/editor/editor.h
Expand Up @@ -788,7 +788,7 @@ class CEditor : public IEditor
bool IsQuadSelected(int Index);
int FindSelectedQuadIndex(int Index);

int DoProperties(CUIRect *pToolbox, CProperty *pProps, int *pIDs, int *pNewVal, vec4 Color = vec4(1,1,1,0.5f));
int DoProperties(CUIRect *pToolbox, CProperty *pProps, int *pIDs, int *pNewVal, ColorRGBA Color = ColorRGBA(1,1,1,0.5f));

int m_Mode;
int m_Dialog;
Expand Down Expand Up @@ -936,7 +936,7 @@ class CEditor : public IEditor
void DoMapBorder();
int DoButton_Editor_Common(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip);
int DoButton_Editor(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip);
int DoButton_Env(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pToolTip, vec3 Color);
int DoButton_Env(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pToolTip, ColorRGBA Color);

int DoButton_Tab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip);
int DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize=10.0f);
Expand All @@ -948,7 +948,7 @@ class CEditor : public IEditor
int DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip);
int DoButton_MenuItem(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags=0, const char *pToolTip=0);

int DoButton_ColorPicker(const void *pID, const CUIRect *pRect, vec4 *pColor, const char *pToolTip=0);
int DoButton_ColorPicker(const void *pID, const CUIRect *pRect, ColorRGBA *pColor, const char *pToolTip=0);

int DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden=false, int Corners=CUI::CORNER_ALL);

Expand All @@ -959,7 +959,7 @@ class CEditor : public IEditor
void UiInvokePopupMenu(void *pID, int Flags, float X, float Y, float W, float H, int (*pfnFunc)(CEditor *pEditor, CUIRect Rect), void *pExtra=0);
void UiDoPopupMenu();

int UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip, bool IsDegree=false, bool IsHex=false, int corners=CUI::CORNER_ALL, vec4* Color=0);
int UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip, bool IsDegree=false, bool IsHex=false, int corners=CUI::CORNER_ALL, ColorRGBA* Color=0);

static int PopupGroup(CEditor *pEditor, CUIRect View);
static int PopupLayer(CEditor *pEditor, CUIRect View);
Expand Down Expand Up @@ -996,7 +996,7 @@ class CEditor : public IEditor
void PopupSelectSoundInvoke(int Current, float x, float y);
int PopupSelectSoundResult();

vec4 ButtonColorMul(const void *pID);
float ButtonColorMul(const void *pID);

void DoQuadEnvelopes(const array<CQuad> &m_lQuads, int TexID = -1);
void DoQuadEnvPoint(const CQuad *pQuad, int QIndex, int pIndex);
Expand All @@ -1008,7 +1008,7 @@ class CEditor : public IEditor
void DoToolbar(CUIRect Toolbar);
void DoQuad(CQuad *pQuad, int Index);
float UiDoScrollbarV(const void *pID, const CUIRect *pRect, float Current);
vec4 GetButtonColor(const void *pID, int Checked);
ColorRGBA GetButtonColor(const void *pID, int Checked);

static void ReplaceImage(const char *pFilename, int StorageType, void *pUser);
static void ReplaceSound(const char *pFileName, int StorageType, void *pUser);
Expand Down Expand Up @@ -1036,7 +1036,7 @@ class CEditor : public IEditor
int GetLineDistance();
void ZoomMouseTarget(float ZoomFactor);

static vec3 ms_PickerColor;
static ColorHSVA ms_PickerColor;
static int ms_SVPicker;
static int ms_HuePicker;

Expand Down
4 changes: 2 additions & 2 deletions src/game/editor/layer_quads.cpp
Expand Up @@ -224,8 +224,8 @@ void CLayerQuads::GetSize(float *w, float *h)
{
for(int p = 0; p < 5; p++)
{
*w = max(*w, fx2f(m_lQuads[i].m_aPoints[p].x));
*h = max(*h, fx2f(m_lQuads[i].m_aPoints[p].y));
*w = maximum(*w, fx2f(m_lQuads[i].m_aPoints[p].x));
*h = maximum(*h, fx2f(m_lQuads[i].m_aPoints[p].y));
}
}
}
Expand Down
44 changes: 22 additions & 22 deletions src/game/editor/layer_tiles.cpp
Expand Up @@ -85,7 +85,7 @@ void CLayerTiles::Render(bool Tileset)
if(m_Image >= 0 && m_Image < m_pEditor->m_Map.m_lImages.size())
m_TexID = m_pEditor->m_Map.m_lImages[m_Image]->m_TexID;
Graphics()->TextureSet(m_TexID);
vec4 Color = vec4(m_Color.r/255.0f, m_Color.g/255.0f, m_Color.b/255.0f, m_Color.a/255.0f);
ColorRGBA Color = ColorRGBA(m_Color.r/255.0f, m_Color.g/255.0f, m_Color.b/255.0f, m_Color.a/255.0f);
Graphics()->BlendNone();
m_pEditor->RenderTools()->RenderTilemap(m_pTiles, m_Width, m_Height, 32.0f, Color, LAYERRENDERFLAG_OPAQUE,
m_pEditor->EnvelopeEval, m_pEditor, m_ColorEnv, m_ColorEnvOffset);
Expand Down Expand Up @@ -419,7 +419,7 @@ void CLayerTiles::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect)

CLayerTiles *pLt = static_cast<CLayerTiles*>(pBrush);

bool Destructive = m_pEditor->m_BrushDrawDestructive || IsEmpty(pLt);
bool Destructive = m_pEditor->m_BrushDrawDestructive || Empty || IsEmpty(pLt);

for(int y = 0; y < h; y++)
{
Expand All @@ -432,7 +432,7 @@ void CLayerTiles::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect)
continue;

bool HasTile = GetTile(fx, fy).m_Index;
if(pLt->GetTile(x, y).m_Index == TILE_THROUGH_CUT)
if(!Empty && pLt->GetTile(x, y).m_Index == TILE_THROUGH_CUT)
{
if(m_Game && m_pEditor->m_Map.m_pFrontLayer)
{
Expand All @@ -448,7 +448,7 @@ void CLayerTiles::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect)
continue;

if(Empty)
m_pTiles[fy*m_Width+fx].m_Index = 1;
m_pTiles[fy*m_Width+fx].m_Index = 0;
else
SetTile(fx, fy, pLt->m_pTiles[(y*pLt->m_Width + x%pLt->m_Width) % (pLt->m_Width*pLt->m_Height)]);
}
Expand Down Expand Up @@ -589,8 +589,8 @@ void CLayerTiles::Resize(int NewW, int NewH)
mem_zero(pNewData, NewW*NewH*sizeof(CTile));

// copy old data
for(int y = 0; y < min(NewH, m_Height); y++)
mem_copy(&pNewData[y*NewW], &m_pTiles[y*m_Width], min(m_Width, NewW)*sizeof(CTile));
for(int y = 0; y < minimum(NewH, m_Height); y++)
mem_copy(&pNewData[y*NewW], &m_pTiles[y*m_Width], minimum(m_Width, NewW)*sizeof(CTile));

// replace old
delete [] m_pTiles;
Expand Down Expand Up @@ -674,10 +674,10 @@ void CLayerTiles::ShowInfo()
Graphics()->TextureSet(m_pEditor->Client()->GetDebugFont());
Graphics()->QuadsBegin();

int StartY = max(0, (int)(ScreenY0/32.0f)-1);
int StartX = max(0, (int)(ScreenX0/32.0f)-1);
int EndY = min((int)(ScreenY1/32.0f)+1, m_Height);
int EndX = min((int)(ScreenX1/32.0f)+1, m_Width);
int StartY = maximum(0, (int)(ScreenY0/32.0f)-1);
int StartX = maximum(0, (int)(ScreenX0/32.0f)-1);
int EndY = minimum((int)(ScreenY1/32.0f)+1, m_Height);
int EndX = minimum((int)(ScreenX1/32.0f)+1, m_Width);

for(int y = StartY; y < EndY; y++)
for(int x = StartX; x < EndX; x++)
Expand Down Expand Up @@ -1001,8 +1001,8 @@ void CLayerTele::Resize(int NewW, int NewH)
mem_zero(pNewTeleData, NewW*NewH*sizeof(CTeleTile));

// copy old data
for(int y = 0; y < min(NewH, m_Height); y++)
mem_copy(&pNewTeleData[y*NewW], &m_pTeleTile[y*m_Width], min(m_Width, NewW)*sizeof(CTeleTile));
for(int y = 0; y < minimum(NewH, m_Height); y++)
mem_copy(&pNewTeleData[y*NewW], &m_pTeleTile[y*m_Width], minimum(m_Width, NewW)*sizeof(CTeleTile));

// replace old
delete [] m_pTeleTile;
Expand Down Expand Up @@ -1212,7 +1212,7 @@ void CLayerTele::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect)

CLayerTele *pLt = static_cast<CLayerTele*>(pBrush);

bool Destructive = m_pEditor->m_BrushDrawDestructive || IsEmpty(pLt);
bool Destructive = m_pEditor->m_BrushDrawDestructive || Empty || IsEmpty(pLt);

for(int y = 0; y < h; y++)
{
Expand Down Expand Up @@ -1273,8 +1273,8 @@ void CLayerSpeedup::Resize(int NewW, int NewH)
mem_zero(pNewSpeedupData, NewW*NewH*sizeof(CSpeedupTile));

// copy old data
for(int y = 0; y < min(NewH, m_Height); y++)
mem_copy(&pNewSpeedupData[y*NewW], &m_pSpeedupTile[y*m_Width], min(m_Width, NewW)*sizeof(CSpeedupTile));
for(int y = 0; y < minimum(NewH, m_Height); y++)
mem_copy(&pNewSpeedupData[y*NewW], &m_pSpeedupTile[y*m_Width], minimum(m_Width, NewW)*sizeof(CSpeedupTile));

// replace old
delete [] m_pSpeedupTile;
Expand Down Expand Up @@ -1499,7 +1499,7 @@ void CLayerSpeedup::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect)

CLayerSpeedup *pLt = static_cast<CLayerSpeedup*>(pBrush);

bool Destructive = m_pEditor->m_BrushDrawDestructive || IsEmpty(pLt);
bool Destructive = m_pEditor->m_BrushDrawDestructive || Empty || IsEmpty(pLt);

for(int y = 0; y < h; y++)
{
Expand Down Expand Up @@ -1608,8 +1608,8 @@ void CLayerSwitch::Resize(int NewW, int NewH)
mem_zero(pNewSwitchData, NewW*NewH*sizeof(CSwitchTile));

// copy old data
for(int y = 0; y < min(NewH, m_Height); y++)
mem_copy(&pNewSwitchData[y*NewW], &m_pSwitchTile[y*m_Width], min(m_Width, NewW)*sizeof(CSwitchTile));
for(int y = 0; y < minimum(NewH, m_Height); y++)
mem_copy(&pNewSwitchData[y*NewW], &m_pSwitchTile[y*m_Width], minimum(m_Width, NewW)*sizeof(CSwitchTile));

// replace old
delete [] m_pSwitchTile;
Expand Down Expand Up @@ -1832,7 +1832,7 @@ void CLayerSwitch::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect)

CLayerSwitch *pLt = static_cast<CLayerSwitch*>(pBrush);

bool Destructive = m_pEditor->m_BrushDrawDestructive || IsEmpty(pLt);
bool Destructive = m_pEditor->m_BrushDrawDestructive || Empty || IsEmpty(pLt);

for(int y = 0; y < h; y++)
{
Expand Down Expand Up @@ -1901,8 +1901,8 @@ void CLayerTune::Resize(int NewW, int NewH)
mem_zero(pNewTuneData, NewW*NewH*sizeof(CTuneTile));

// copy old data
for(int y = 0; y < min(NewH, m_Height); y++)
mem_copy(&pNewTuneData[y*NewW], &m_pTuneTile[y*m_Width], min(m_Width, NewW)*sizeof(CTuneTile));
for(int y = 0; y < minimum(NewH, m_Height); y++)
mem_copy(&pNewTuneData[y*NewW], &m_pTuneTile[y*m_Width], minimum(m_Width, NewW)*sizeof(CTuneTile));

// replace old
delete [] m_pTuneTile;
Expand Down Expand Up @@ -2114,7 +2114,7 @@ void CLayerTune::FillSelection(bool Empty, CLayer *pBrush, CUIRect Rect)

CLayerTune *pLt = static_cast<CLayerTune*>(pBrush);

bool Destructive = m_pEditor->m_BrushDrawDestructive || IsEmpty(pLt);
bool Destructive = m_pEditor->m_BrushDrawDestructive || Empty || IsEmpty(pLt);

for(int y = 0; y < h; y++)
{
Expand Down