Skip to content

Commit

Permalink
add thickness setting
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaGW2 committed Sep 13, 2024
1 parent 94ef1d9 commit 1b57c8b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 37 deletions.
18 changes: 13 additions & 5 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,44 @@ namespace Settings
130,
true,
0,
360
360,
1
});

RangeIndicators.push_back(RangeIndicator{
0xFFFFFFFF,
240,
true,
0,
360
360,
1
});

RangeIndicators.push_back(RangeIndicator{
0xFFFFFFFF,
360,
true,
0,
360
360,
1
});

RangeIndicators.push_back(RangeIndicator{
0xFFFFFFFF,
600,
true,
0,
360
360,
1
});

RangeIndicators.push_back(RangeIndicator{
0xFFFFFFFF,
900,
true,
0,
360
360,
1
});

for (RangeIndicator& ri : Settings::RangeIndicators)
Expand All @@ -74,6 +79,7 @@ namespace Settings
jRi["IsVisible"] = ri.IsVisible;
jRi["VOffset"] = ri.VOffset;
jRi["Arc"] = ri.Arc;
jRi["Thickness"] = ri.Thickness;

Settings::Settings[RANGE_INDICATORS].push_back(jRi);
}
Expand Down Expand Up @@ -130,6 +136,7 @@ namespace Settings
if (!ri["IsVisible"].is_null()) { ri["IsVisible"].get_to(rangeIndicator.IsVisible); }
if (!ri["VOffset"].is_null()) { ri["VOffset"].get_to(rangeIndicator.VOffset); }
if (!ri["Arc"].is_null()) { ri["Arc"].get_to(rangeIndicator.Arc); } else { rangeIndicator.Arc = 360; }
if (!ri["Thickness"].is_null()) { ri["Thickness"].get_to(rangeIndicator.Thickness); } else { rangeIndicator.Thickness = 1; }

RangeIndicators.push_back(rangeIndicator);
}
Expand All @@ -149,6 +156,7 @@ namespace Settings
jRi["IsVisible"] = ri.IsVisible;
jRi["VOffset"] = ri.VOffset;
jRi["Arc"] = ri.Arc;
jRi["Thickness"] = ri.Thickness;
Settings[RANGE_INDICATORS].push_back(jRi);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct RangeIndicator
bool IsVisible;
float VOffset;
float Arc;
float Thickness;
};

extern const char* IS_VISIBLE;
Expand Down
88 changes: 56 additions & 32 deletions src/entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ bool DepthOK(float& aDepth)
return /*aDepth >= 0.0f && */aDepth <= 1.0f;
}

void DrawCircle(ProjectionData aProjection, ImDrawList* aDrawList, ImColor aColor, float aRadius, float aVOffset, float aArc, bool aShaded = true, bool aShowFlanks = false)
void DrawCircle(ProjectionData aProjection, ImDrawList* aDrawList, ImColor aColor, float aRadius, float aVOffset, float aArc, float aThickness, bool aShaded = true, bool aShowFlanks = false)
{
float fRot = atan2f(MumbleLink->CameraFront.X, MumbleLink->CameraFront.Z) * 180.0f / 3.14159f;
float camRot = fRot;
Expand Down Expand Up @@ -194,26 +194,14 @@ void DrawCircle(ProjectionData aProjection, ImDrawList* aDrawList, ImColor aColo
circle.push_back(Vector3{ x, aProjection.AgentPosition.Y + aVOffset, z });
}

float offsetRF = 0 + flankOffset + facingDeg;
float offsetLF = 360.0f - flankOffset + facingDeg;

if (offsetRF > 360.0f) { offsetRF -= 360.0f; }
if (offsetRF < 0.0f) { offsetRF += 360.0f; }
if (offsetLF > 360.0f) { offsetLF -= 360.0f; }
if (offsetLF < 0.0f) { offsetLF += 360.0f; }

float cosRF = cos(offsetRF * 3.14159f / 180.0f);
float sinRF = sin(offsetRF * 3.14159f / 180.0f);
float cosLF = cos(offsetLF * 3.14159f / 180.0f);
float sinLF = sin(offsetLF * 3.14159f / 180.0f);

Vector3 rightFlank = { aRadius * sinRF + aProjection.AgentPosition.X, aProjection.AgentPosition.Y + aVOffset, aRadius * cosRF + aProjection.AgentPosition.Z };
Vector3 leftFlank = { aRadius * sinLF + aProjection.AgentPosition.X, aProjection.AgentPosition.Y + aVOffset, aRadius * cosLF + aProjection.AgentPosition.Z };
Vector3 rightFlank;
Vector3 leftFlank;

ImDrawList* dl = ImGui::GetBackgroundDrawList();

std::vector<Vector3> circleProj;

/* generate circle points */
for (size_t i = 0; i < circle.size(); i++)
{
dx::XMVECTOR point = { circle[i].X, circle[i].Y, circle[i].Z };
Expand All @@ -236,8 +224,25 @@ void DrawCircle(ProjectionData aProjection, ImDrawList* aDrawList, ImColor aColo

Vector3 origin{};

/* transform flanks */
if (aShowFlanks)
{
float offsetRF = 0 + flankOffset + facingDeg;
float offsetLF = 360.0f - flankOffset + facingDeg;

if (offsetRF > 360.0f) { offsetRF -= 360.0f; }
if (offsetRF < 0.0f) { offsetRF += 360.0f; }
if (offsetLF > 360.0f) { offsetLF -= 360.0f; }
if (offsetLF < 0.0f) { offsetLF += 360.0f; }

float cosRF = cos(offsetRF * 3.14159f / 180.0f);
float sinRF = sin(offsetRF * 3.14159f / 180.0f);
float cosLF = cos(offsetLF * 3.14159f / 180.0f);
float sinLF = sin(offsetLF * 3.14159f / 180.0f);

rightFlank = { aRadius * sinRF + aProjection.AgentPosition.X, aProjection.AgentPosition.Y + aVOffset, aRadius * cosRF + aProjection.AgentPosition.Z };
leftFlank = { aRadius * sinLF + aProjection.AgentPosition.X, aProjection.AgentPosition.Y + aVOffset, aRadius * cosLF + aProjection.AgentPosition.Z };

/* don't forget these three for facing cone */
dx::XMVECTOR RFProj = dx::XMVector3Project({ rightFlank.X, rightFlank.Y, rightFlank.Z }, 0, 0, NexusLink->Width, NexusLink->Height, 1.0f, 10000.0f, aProjection.ProjectionMatrix, aProjection.ViewMatrix, aProjection.WorldMatrix);
dx::XMVECTOR LFProj = dx::XMVector3Project({ leftFlank.X, leftFlank.Y, leftFlank.Z }, 0, 0, NexusLink->Width, NexusLink->Height, 1.0f, 10000.0f, aProjection.ProjectionMatrix, aProjection.ViewMatrix, aProjection.WorldMatrix);
Expand Down Expand Up @@ -270,7 +275,7 @@ void DrawCircle(ProjectionData aProjection, ImDrawList* aDrawList, ImColor aColo
Vector3& p1 = circleProj[i - 1];
Vector3& p2 = circleProj[i];
if (DepthOK(p1.Z) && DepthOK(p2.Z))
dl->AddLine(ImVec2(p1.X + 1.0f, p1.Y + 1.0f), ImVec2(p2.X + 1.0f, p2.Y + 1.0f), shadowColor);
dl->AddLine(ImVec2(p1.X + 1.0f, p1.Y + 1.0f), ImVec2(p2.X + 1.0f, p2.Y + 1.0f), shadowColor, aThickness);
}
}

Expand All @@ -279,22 +284,22 @@ void DrawCircle(ProjectionData aProjection, ImDrawList* aDrawList, ImColor aColo
Vector3& p1 = circleProj[circleProj.size() - 1];
Vector3& p2 = circleProj[0];
if (DepthOK(p1.Z) && DepthOK(p2.Z))
dl->AddLine(ImVec2(p1.X + 1.0f, p1.Y + 1.0f), ImVec2(p2.X + 1.0f, p2.Y + 1.0f), shadowColor);
dl->AddLine(ImVec2(p1.X + 1.0f, p1.Y + 1.0f), ImVec2(p2.X + 1.0f, p2.Y + 1.0f), shadowColor, aThickness);
}
else /*if (aShowFlanks)*/
{
Vector3& p1 = circleProj[circleProj.size() - 1];
Vector3& p2 = circleProj[0];
if (DepthOK(p1.Z) && DepthOK(p2.Z))
dl->AddLine(ImVec2(p1.X + 1.0f, p1.Y + 1.0f), ImVec2(rightFlank.X + 1.0f, rightFlank.Y + 1.0f), shadowColor);
dl->AddLine(ImVec2(p1.X + 1.0f, p1.Y + 1.0f), ImVec2(rightFlank.X + 1.0f, rightFlank.Y + 1.0f), shadowColor, aThickness);
}

if (aShowFlanks)
{
if (DepthOK(rightFlank.Z) && DepthOK(origin.Z))
dl->AddLine(ImVec2(rightFlank.X + 1.0f, rightFlank.Y + 1.0f), ImVec2(origin.X + 1.0f, origin.Y + 1.0f), shadowColor);
dl->AddLine(ImVec2(rightFlank.X + 1.0f, rightFlank.Y + 1.0f), ImVec2(origin.X + 1.0f, origin.Y + 1.0f), shadowColor, aThickness);
if (DepthOK(leftFlank.Z) && DepthOK(origin.Z))
dl->AddLine(ImVec2(leftFlank.X + 1.0f, leftFlank.Y + 1.0f), ImVec2(origin.X + 1.0f, origin.Y + 1.0f), shadowColor);
dl->AddLine(ImVec2(leftFlank.X + 1.0f, leftFlank.Y + 1.0f), ImVec2(origin.X + 1.0f, origin.Y + 1.0f), shadowColor, aThickness);
}
}

Expand All @@ -306,7 +311,7 @@ void DrawCircle(ProjectionData aProjection, ImDrawList* aDrawList, ImColor aColo
Vector3& p1 = circleProj[i - 1];
Vector3& p2 = circleProj[i];
if (DepthOK(p1.Z) && DepthOK(p2.Z))
dl->AddLine(ImVec2(p1.X, p1.Y), ImVec2(p2.X, p2.Y), aColor);
dl->AddLine(ImVec2(p1.X, p1.Y), ImVec2(p2.X, p2.Y), aColor, aThickness);
}
}

Expand All @@ -315,22 +320,22 @@ void DrawCircle(ProjectionData aProjection, ImDrawList* aDrawList, ImColor aColo
Vector3& p1 = circleProj[circleProj.size() - 1];
Vector3& p2 = circleProj[0];
if (DepthOK(p1.Z) && DepthOK(p2.Z))
dl->AddLine(ImVec2(p1.X, p1.Y), ImVec2(p2.X, p2.Y), aColor);
dl->AddLine(ImVec2(p1.X, p1.Y), ImVec2(p2.X, p2.Y), aColor, aThickness);
}
else /*if (aShowFlanks)*/
{
Vector3& p1 = circleProj[circleProj.size() - 1];
Vector3& p2 = circleProj[0];
if (DepthOK(p1.Z) && DepthOK(p2.Z))
dl->AddLine(ImVec2(p1.X, p1.Y), ImVec2(rightFlank.X, rightFlank.Y), aColor);
dl->AddLine(ImVec2(p1.X, p1.Y), ImVec2(rightFlank.X, rightFlank.Y), aColor, aThickness);
}

if (aShowFlanks)
{
if (DepthOK(rightFlank.Z) && DepthOK(origin.Z))
dl->AddLine(ImVec2(rightFlank.X, rightFlank.Y), ImVec2(origin.X, origin.Y), aColor);
dl->AddLine(ImVec2(rightFlank.X, rightFlank.Y), ImVec2(origin.X, origin.Y), aColor, aThickness);
if (DepthOK(leftFlank.Z) && DepthOK(origin.Z))
dl->AddLine(ImVec2(leftFlank.X, leftFlank.Y), ImVec2(origin.X, origin.Y), aColor);
dl->AddLine(ImVec2(leftFlank.X, leftFlank.Y), ImVec2(origin.X, origin.Y), aColor, aThickness);
}
}

Expand Down Expand Up @@ -394,14 +399,14 @@ void AddonRender()
radius = 80.0f;
break;
}
DrawCircle(projectionCtx, dl, Settings::HitboxRGBA, radius, 0, 360, true, true);
DrawCircle(projectionCtx, dl, Settings::HitboxRGBA, radius, 0, 360, 1, true, true);
}

for (RangeIndicator& ri : Settings::RangeIndicators)
{
if (!ri.IsVisible) { continue; }

DrawCircle(projectionCtx, dl, ri.RGBA, ri.Radius, ri.VOffset, ri.Arc, true, false);
DrawCircle(projectionCtx, dl, ri.RGBA, ri.Radius, ri.VOffset, ri.Arc, ri.Thickness, true, false);
}
}

Expand Down Expand Up @@ -455,7 +460,7 @@ void AddonOptions()

int indexRemove = -1;

ImGui::BeginTable("#rangeindicatorslist", 7, ImGuiTableFlags_SizingFixedFit);
ImGui::BeginTable("#rangeindicatorslist", 8, ImGuiTableFlags_SizingFixedFit);

ImGui::TableNextRow();

Expand All @@ -468,6 +473,9 @@ void AddonOptions()
ImGui::TableSetColumnIndex(4);
ImGui::Text("Vertical Offset");

ImGui::TableSetColumnIndex(5);
ImGui::Text("Thickness");

std::lock_guard<std::mutex> lock(Settings::RangesMutex);
for (size_t i = 0; i < Settings::RangeIndicators.size(); i++)
{
Expand All @@ -489,7 +497,7 @@ void AddonOptions()
Settings::Save(SettingsPath);
}

float inputWidth = ImGui::GetWindowContentRegionWidth() / 4;
float inputWidth = ImGui::GetWindowContentRegionWidth() / 5;

ImGui::TableSetColumnIndex(2);
ImGui::PushItemWidth(inputWidth);
Expand All @@ -505,6 +513,10 @@ void AddonOptions()
if (ImGui::InputFloat(("##Arc" + std::to_string(i)).c_str(), &ri.Arc, 1.0f, 1.0f, "%.0f"))
{
bool sort = true;

if (ri.Arc < 0) { ri.Arc = 0; }
if (ri.Arc > 360) { ri.Arc = 360; }

Settings::Settings[RANGE_INDICATORS][i]["Arc"] = ri.Arc;
Settings::Save(SettingsPath);
}
Expand All @@ -518,6 +530,17 @@ void AddonOptions()
}

ImGui::TableSetColumnIndex(5);
ImGui::PushItemWidth(inputWidth);
if (ImGui::InputFloat(("##Thickness" + std::to_string(i)).c_str(), &ri.Thickness, 1.0f, 1.0f, "%.0f"))
{
if (ri.Thickness < 1) { ri.Thickness = 1; }
if (ri.Thickness > 25) { ri.Thickness = 25; }

Settings::Settings[RANGE_INDICATORS][i]["Thickness"] = ri.Thickness;
Settings::Save(SettingsPath);
}

ImGui::TableSetColumnIndex(6);
if (ImGui::SmallButton(("Remove##" + std::to_string(i)).c_str()))
{
indexRemove = i;
Expand All @@ -535,12 +558,13 @@ void AddonOptions()

if (ImGui::SmallButton("Add"))
{
Settings::RangeIndicators.push_back(RangeIndicator{ 0xFFFFFFFF, 0, true });
Settings::RangeIndicators.push_back(RangeIndicator{ 0xFFFFFFFF, 360, true, 0, 1 });
json jRi{};
jRi["RGBA"] = 0xFFFFFFFF;
jRi["Radius"] = 0;
jRi["Radius"] = 360;
jRi["IsVisible"] = true;
jRi["VOffset"] = 0;
jRi["Thickness"] = 1;
Settings::Settings[RANGE_INDICATORS].push_back(jRi);
Settings::Save(SettingsPath);
}
Expand Down

0 comments on commit 1b57c8b

Please sign in to comment.