Skip to content

Commit

Permalink
added right click to teleport in the level
Browse files Browse the repository at this point in the history
  • Loading branch information
zappatic committed Mar 20, 2021
1 parent d74288b commit ef37282
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions injected/include/SeedFinderUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ namespace SeedFinder
static std::chrono::system_clock::time_point msMouseMovedTime;
static ImVec2 msMouseLastPosition;
static bool msHideUI;
static ImVec2 normalize(ImVec2 pos);
};
} // namespace SeedFinder
40 changes: 40 additions & 0 deletions injected/src/SeedFinderUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ namespace SeedFinder
msSeedFinder->render();
ImGui::End();
}

auto& io = ImGui::GetIO();
ImGui::SetNextWindowSize(io.DisplaySize);
ImGui::SetNextWindowPos({0, 0});
ImGui::Begin("Clickhandler", NULL,
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse |
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNavInputs |
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoBackground);

ImGui::InvisibleButton("canvas", ImGui::GetContentRegionMax(), ImGuiButtonFlags_MouseButtonRight);

if (ImGui::IsMouseClicked(1) && ImGui::IsWindowFocused())
{
auto state = State::get();
auto player = state.items()->player(0);
if (player != nullptr)
{
ImVec2 mpos = normalize(io.MousePos);
const auto [clickX, clickY] = state.click_position(mpos.x, mpos.y);
player->teleport_abs(clickX, clickY, 0, 0);
}
}
ImGui::End();
}

void SeedFinderUI::postDraw()
Expand All @@ -99,4 +122,21 @@ namespace SeedFinder
}
}

ImVec2 SeedFinderUI::normalize(ImVec2 pos)
{
ImGuiIO& io = ImGui::GetIO();
ImVec2 res = io.DisplaySize;
if (res.x / res.y > 1.78)
{
pos.x -= (res.x - res.y / 9 * 16) / 2;
res.x = res.y / 9 * 16;
}
else if (res.x / res.y < 1.77)
{
pos.y -= (res.y - res.x / 16 * 9) / 2;
res.y = res.x / 16 * 9;
}
ImVec2 normal = ImVec2((pos.x - res.x / 2) * (1.0 / (res.x / 2)), -(pos.y - res.y / 2) * (1.0 / (res.y / 2)));
return normal;
}
} // namespace SeedFinder

0 comments on commit ef37282

Please sign in to comment.