Skip to content

Commit

Permalink
Bindwheel polish
Browse files Browse the repository at this point in the history
  • Loading branch information
SollyBunny committed Nov 22, 2024
1 parent 67fd4d1 commit 1f05bcc
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 257 deletions.
68 changes: 35 additions & 33 deletions src/game/client/components/bindwheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CBindWheel::CBindWheel()
{
OnReset();
}

void CBindWheel::ConExecuteHover(IConsole::IResult *pResult, void *pUserData)
{
CBindWheel *pThis = (CBindWheel *)pUserData;
Expand All @@ -29,14 +30,21 @@ void CBindWheel::ConOpenBindwheel(IConsole::IResult *pResult, void *pUserData)
pThis->m_Active = pResult->GetInteger(0) != 0;
}

void CBindWheel::ConAddBindwheel_Legacy(IConsole::IResult *pResult, void *pUserData)
void CBindWheel::ConAddBindwheelLegacy(IConsole::IResult *pResult, void *pUserData)
{
//int Bindpos_Legacy = pResult->GetInteger(0);
int BindPos = pResult->GetInteger(0);
if (BindPos < 0 || BindPos >= MAX_BINDS)
return;

const char *aName = pResult->GetString(1);
const char *aCommand = pResult->GetString(2);

CBindWheel *pThis = static_cast<CBindWheel *>(pUserData);
pThis->AddBind(aName, aCommand);
while(pThis->m_vBinds.size() <= (size_t)BindPos)
pThis->AddBind("EMPTY", "");

str_copy(pThis->m_vBinds[BindPos].m_aName, aName);
str_copy(pThis->m_vBinds[BindPos].m_aCommand, aCommand);
}

void CBindWheel::ConAddBindwheel(IConsole::IResult *pResult, void *pUserData)
Expand Down Expand Up @@ -65,27 +73,21 @@ void CBindWheel::ConRemoveAllBinds(IConsole::IResult *pResult, void *pUserData)

void CBindWheel::AddBind(const char *pName, const char *pCommand)
{
if((pName[0] == 0 && pCommand[0] == 0) || m_vBinds.size() > MAX_BINDS)
if((pName[0] == '\0' && pCommand[0] == '\0') || m_vBinds.size() >= MAX_BINDS)
return;

// Don't allow duplicates
// for(SBind &Bind : m_vBinds)
//{
// if(!str_comp(Bind.m_aName, pName) && !str_comp(Bind.m_aCommand, pCommand))
// return;
//}
SBind TempBind;
str_copy(TempBind.m_aName, pName);
str_copy(TempBind.m_aCommand, pCommand);
m_vBinds.push_back(TempBind);
SBind Bind;
str_copy(Bind.m_aName, pName);
str_copy(Bind.m_aCommand, pCommand);
m_vBinds.push_back(Bind);
}

void CBindWheel::RemoveBind(const char *pName, const char *pCommand)
{
SBind TempBind;
str_copy(TempBind.m_aName, pName);
str_copy(TempBind.m_aCommand, pCommand);
auto it = std::find(m_vBinds.begin(), m_vBinds.end(), TempBind);
SBind Bind;
str_copy(Bind.m_aName, pName);
str_copy(Bind.m_aCommand, pCommand);
auto it = std::find(m_vBinds.begin(), m_vBinds.end(), Bind);
if(it != m_vBinds.end())
m_vBinds.erase(it);
}
Expand All @@ -112,7 +114,7 @@ void CBindWheel::OnConsoleInit()
Console()->Register("+bindwheel", "", CFGFLAG_CLIENT, ConOpenBindwheel, this, "Open bindwheel selector");
Console()->Register("+bindwheel_execute_hover", "", CFGFLAG_CLIENT, ConExecuteHover, this, "Execute hovered bindwheel bind");

Console()->Register("bindwheel", "i[index] s[name] s[command]", CFGFLAG_CLIENT, ConAddBindwheel_Legacy, this, "DONT USE THIS! USE add_bindwheel INSTEAD!");
Console()->Register("bindwheel", "i[index] s[name] s[command]", CFGFLAG_CLIENT, ConAddBindwheelLegacy, this, "DONT USE THIS! USE add_bindwheel INSTEAD!");
Console()->Register("add_bindwheel", "s[name] s[command]", CFGFLAG_CLIENT, ConAddBindwheel, this, "Add a bind to the bindwheel");
Console()->Register("remove_bindwheel", "s[name] s[command]", CFGFLAG_CLIENT, ConRemoveBindwheel, this, "Remove a bind from the bindwheel");
Console()->Register("delete_all_bindwheel_binds", "", CFGFLAG_CLIENT, ConRemoveAllBinds, this, "Removes all bindwheel binds");
Expand Down Expand Up @@ -150,7 +152,7 @@ void CBindWheel::OnRender()
if(!m_Active)
{
if(g_Config.m_ClResetBindWheelMouse)
m_SelectorMouse = vec2(0, 0);
m_SelectorMouse = vec2(0.0f, 0.0f);
if(m_WasActive && m_SelectedBind != -1)
ExecuteBindwheel(m_SelectedBind);
m_WasActive = false;
Expand All @@ -163,15 +165,15 @@ void CBindWheel::OnRender()
m_SelectorMouse = normalize(m_SelectorMouse) * 170.0f;

int SegmentCount = m_vBinds.size();
float SegmentAngle = 2 * pi / SegmentCount;

float SelectedAngle = angle(m_SelectorMouse) + SegmentAngle / 2;
if(SelectedAngle < 0)
SelectedAngle += 2 * pi;
float SegmentAngle = 2.0f * pi / SegmentCount;

m_SelectedBind = -1;
float SelectedAngle = angle(m_SelectorMouse) + SegmentAngle / 2.0f;
if(SelectedAngle < 0.0f)
SelectedAngle += 2.0f * pi;
if(length(m_SelectorMouse) > 110.0f)
m_SelectedBind = (int)(SelectedAngle / (2 * pi) * SegmentCount);
m_SelectedBind = (int)(SelectedAngle / (2.0f * pi) * SegmentCount);
else
m_SelectedBind = -1;

CUIRect Screen = *Ui()->Screen();

Expand All @@ -180,12 +182,12 @@ void CBindWheel::OnRender()
Graphics()->BlendNormal();
Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(0, 0, 0, 0.3f);
DrawCircle(Screen.w / 2, Screen.h / 2, 190.0f, 64);
Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.3f);
DrawCircle(Screen.w / 2.0f, Screen.h / 2.0f, 190.0f, 64);
Graphics()->QuadsEnd();
Graphics()->WrapClamp();

const float Theta = pi * 2 / m_vBinds.size();
const float Theta = pi * 2.0f / m_vBinds.size();
for(int i = 0; i < static_cast<int>(m_vBinds.size()); i++)
{
const SBind &Bind = m_vBinds[i];
Expand All @@ -201,11 +203,11 @@ void CBindWheel::OnRender()

Graphics()->TextureClear();
Graphics()->QuadsBegin();
Graphics()->SetColor(1.0, 1.0, 1.0, 0.3f);
DrawCircle(Screen.w / 2, Screen.h / 2, 100.0f, 64);
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.3f);
DrawCircle(Screen.w / 2.0f, Screen.h / 2.0f, 100.0f, 64);
Graphics()->QuadsEnd();

RenderTools()->RenderCursor(m_SelectorMouse + vec2(Screen.w, Screen.h) / 2, 24.0f);
RenderTools()->RenderCursor(m_SelectorMouse + vec2(Screen.w, Screen.h) / 2.0f, 24.0f);
}

void CBindWheel::ExecuteBindwheel(int Bind)
Expand Down
9 changes: 4 additions & 5 deletions src/game/client/components/bindwheel.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#ifndef GAME_CLIENT_COMPONENTS_BIND_WHEEL_H
#define GAME_CLIENT_COMPONENTS_BIND_WHEEL_H
#ifndef GAME_CLIENT_COMPONENTS_BINDWHEEL_H
#define GAME_CLIENT_COMPONENTS_BINDWHEEL_H
#include <game/client/component.h>
class IConfigManager;

Expand All @@ -22,7 +22,7 @@ class CBindWheel : public CComponent
int m_SelectedBind;

static void ConOpenBindwheel(IConsole::IResult *pResult, void *pUserData);
static void ConAddBindwheel_Legacy(IConsole::IResult *pResult, void *pUserData);
static void ConAddBindwheelLegacy(IConsole::IResult *pResult, void *pUserData);
static void ConAddBindwheel(IConsole::IResult *pResult, void *pUserData);
static void ConRemoveBindwheel(IConsole::IResult *pResult, void *pUserData);
static void ConRemoveAllBinds(IConsole::IResult *pResult, void *pUserData);
Expand All @@ -38,8 +38,7 @@ class CBindWheel : public CComponent

bool operator==(const SBind &Other) const
{
return str_comp(m_aName, Other.m_aName) == 0 &&
str_comp(m_aCommand, Other.m_aCommand) == 0;
return str_comp(m_aName, Other.m_aName) == 0 && str_comp(m_aCommand, Other.m_aCommand) == 0;
}
};

Expand Down
Loading

0 comments on commit 1f05bcc

Please sign in to comment.