From 6f7363fbcb8b66a6a1563e9fcaec9cdc8b8d8319 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Tue, 10 Mar 2026 05:50:26 -0700 Subject: [PATCH] ui: click-to-target via nameplate hit testing Left-clicking anywhere within a nameplate's bounding box (name text + health bar) calls setTarget() for that unit. Uses manual mouse position hit testing since nameplates are drawn on the background DrawList rather than as ImGui widgets. Click is ignored when ImGui has captured the mouse (e.g. when a window is open). --- src/ui/game_screen.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ui/game_screen.cpp b/src/ui/game_screen.cpp index 1a12493a..8467a5d1 100644 --- a/src/ui/game_screen.cpp +++ b/src/ui/game_screen.cpp @@ -4902,6 +4902,18 @@ void GameScreen::renderNameplates(game::GameHandler& gameHandler) { : IM_COL32(240, 200, 100, A(230)); drawList->AddText(ImVec2(nameX + 1.0f, nameY + 1.0f), IM_COL32(0, 0, 0, A(160)), labelBuf); drawList->AddText(ImVec2(nameX, nameY), nameColor, labelBuf); + + // Click to target: detect left-click inside the combined nameplate region + if (!ImGui::GetIO().WantCaptureMouse && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { + ImVec2 mouse = ImGui::GetIO().MousePos; + float nx0 = nameX - 2.0f; + float ny0 = nameY - 1.0f; + float nx1 = nameX + textSize.x + 2.0f; + float ny1 = sy + barH + 2.0f; + if (mouse.x >= nx0 && mouse.x <= nx1 && mouse.y >= ny0 && mouse.y <= ny1) { + gameHandler.setTarget(guid); + } + } } }