4803: Make hook collision line size adjustable r=def- a=sjrc6

I felt the hook line was too thin and hard to see sometimes. This adds a config and a setting slider to adjust the size. 

I made it so size 0 will render exactly the same as before so there is no change unless you increase the size. 

The size scales as you zoom in/out in order to prevent the hookline from shrinking and eventually disappearing, this is functionally the same as it worked before since it would always be exactly 1 pixel wide.

## Checklist

- [x] Tested the change ingame
- [x] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)
![HookSizeSettings](https://user-images.githubusercontent.com/22122579/158001940-abfd7910-0c6b-48b1-91cd-328c190448a7.png)
![HookSize0](https://user-images.githubusercontent.com/22122579/158001993-05c7f482-6b39-46e2-95a8-8859e99ec2d5.png)
![HookSize5](https://user-images.githubusercontent.com/22122579/158002018-2eb98fad-59c7-4615-8598-6d0b33d0a699.png)
![HookSize10](https://user-images.githubusercontent.com/22122579/158002022-bc0e462b-0f5f-4e46-85ee-70e23dc8d849.png)
![HookSize20](https://user-images.githubusercontent.com/22122579/158002024-9526116a-f4c4-4929-a35e-f702e10633cc.png)



Co-authored-by: Tater <Mr.Potatooh@gmail.com>
This commit is contained in:
bors[bot] 2022-03-12 09:46:22 +00:00 committed by GitHub
commit 86bc885391
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 4 deletions

View file

@ -370,6 +370,7 @@ MACRO_CONFIG_INT(ClPredictFreeze, cl_predict_freeze, 1, 0, 2, CFGFLAG_CLIENT | C
MACRO_CONFIG_INT(ClShowNinja, cl_show_ninja, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show ninja skin")
MACRO_CONFIG_INT(ClShowHookCollOther, cl_show_hook_coll_other, 1, 0, 2, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show other players' hook collision line (2 to always show)")
MACRO_CONFIG_INT(ClShowHookCollOwn, cl_show_hook_coll_own, 1, 0, 2, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show own players' hook collision line (2 to always show)")
MACRO_CONFIG_INT(ClHookCollSize, cl_hook_coll_size, 0, 0, 20, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Size of hook collision line")
MACRO_CONFIG_COL(ClHookCollColorNoColl, cl_hook_coll_color_no_coll, 65407, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Specifies the color of a hookline that hits nothing.")
MACRO_CONFIG_COL(ClHookCollColorHookableColl, cl_hook_coll_color_hookable_coll, 6401973, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Specifies the color of a hookline that hits hookable tiles.")

View file

@ -2151,6 +2151,17 @@ void CMenus::RenderSettingsHUD(CUIRect MainView)
UI()->DoLabelScaled(&SectionTwo, Localize("Hookline"), 20.0f, TEXTALIGN_LEFT);
MainView.Margin(5.0f, &MainView);
{
CUIRect Button, Label;
MainView.HSplitTop(5.0f, &Button, &MainView);
MainView.HSplitTop(20.0f, &Button, &MainView);
Button.VSplitLeft(40.0f, &Label, &Button);
UI()->DoLabelScaled(&Label, Localize("Size"), 14.0f, TEXTALIGN_LEFT);
g_Config.m_ClHookCollSize = (int)(UIEx()->DoScrollbarH(&g_Config.m_ClHookCollSize, &Button, g_Config.m_ClHookCollSize / 20.0f) * 20.0f);
}
MainView.HSplitTop(5.0f, 0x0, &MainView);
MainView.HSplitTop(25.0f, &SectionTwo, &MainView);

View file

@ -294,7 +294,11 @@ void CPlayers::RenderPlayer(
vec2 InitPos = Position;
vec2 FinishPos = InitPos + ExDirection * (m_pClient->m_Tuning[g_Config.m_ClDummy].m_HookLength - 42.0f);
Graphics()->LinesBegin();
if(g_Config.m_ClHookCollSize > 0)
Graphics()->QuadsBegin();
else
Graphics()->LinesBegin();
ColorRGBA HookCollColor = color_cast<ColorRGBA>(ColorHSLA(g_Config.m_ClHookCollColorNoColl));
float PhysSize = 28.0f;
@ -352,9 +356,24 @@ void CPlayers::RenderPlayer(
HookCollColor = color_invert(HookCollColor);
}
Graphics()->SetColor(HookCollColor.WithAlpha(Alpha));
IGraphics::CLineItem LineItem(InitPos.x, InitPos.y, FinishPos.x, FinishPos.y);
Graphics()->LinesDraw(&LineItem, 1);
Graphics()->LinesEnd();
if(g_Config.m_ClHookCollSize > 0)
{
float LineWidth = 0.5f + (float)(g_Config.m_ClHookCollSize - 1) * 0.25f;
vec2 PerpToAngle = normalize(vec2(ExDirection.y, -ExDirection.x)) * GameClient()->m_Camera.m_Zoom;
vec2 Pos0 = FinishPos + PerpToAngle * -LineWidth;
vec2 Pos1 = FinishPos + PerpToAngle * LineWidth;
vec2 Pos2 = InitPos + PerpToAngle * -LineWidth;
vec2 Pos3 = InitPos + PerpToAngle * LineWidth;
IGraphics::CFreeformItem FreeformItem(Pos0.x, Pos0.y, Pos1.x, Pos1.y, Pos2.x, Pos2.y, Pos3.x, Pos3.y);
Graphics()->QuadsDrawFreeform(&FreeformItem, 1);
Graphics()->QuadsEnd();
}
else
{
IGraphics::CLineItem LineItem(InitPos.x, InitPos.y, FinishPos.x, FinishPos.y);
Graphics()->LinesDraw(&LineItem, 1);
Graphics()->LinesEnd();
}
}
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f);