From b23dbc9ab782fd41ff17a4b7436081025579bcfc Mon Sep 17 00:00:00 2001 From: Kelsi Date: Tue, 17 Mar 2026 13:59:42 -0700 Subject: [PATCH] feat: apply out-of-range red tint to ranged items on action bar Extend the existing out-of-range check to cover ITEM slots whose inventory type is Ranged (bow/gun/crossbow, 40 yd), RangedRight (wand, 40 yd), or Thrown (30 yd). The check runs after barItemDef is resolved so the inventory type is available. --- src/ui/game_screen.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/ui/game_screen.cpp b/src/ui/game_screen.cpp index 5ba3400b..0c815b94 100644 --- a/src/ui/game_screen.cpp +++ b/src/ui/game_screen.cpp @@ -6713,6 +6713,7 @@ void GameScreen::renderActionBar(game::GameHandler& gameHandler) { // Out-of-range check: red tint when a targeted spell cannot reach the current target. // Only applies to SPELL slots with a known max range (>5 yd) and an active target. + // Item range is checked below after barItemDef is populated. bool outOfRange = false; if (!slot.isEmpty() && slot.type == game::ActionBarSlot::SPELL && slot.id != 0 && !onCooldown && gameHandler.hasTarget()) { @@ -6802,6 +6803,33 @@ void GameScreen::renderActionBar(game::GameHandler& gameHandler) { const bool itemMissing = (slot.type == game::ActionBarSlot::ITEM && slot.id != 0 && barItemDef == nullptr && !onCooldown); + // Ranged item out-of-range check (runs after barItemDef is populated above). + // invType 15=Ranged (bow/gun/crossbow), 26=Thrown, 28=RangedRight (wand/crossbow). + if (!outOfRange && slot.type == game::ActionBarSlot::ITEM && barItemDef + && !onCooldown && gameHandler.hasTarget()) { + constexpr uint8_t INVTYPE_RANGED = 15; + constexpr uint8_t INVTYPE_THROWN = 26; + constexpr uint8_t INVTYPE_RANGEDRIGHT = 28; + uint32_t itemMaxRange = 0; + if (barItemDef->inventoryType == INVTYPE_RANGED || + barItemDef->inventoryType == INVTYPE_RANGEDRIGHT) + itemMaxRange = 40; + else if (barItemDef->inventoryType == INVTYPE_THROWN) + itemMaxRange = 30; + if (itemMaxRange > 0) { + auto& em = gameHandler.getEntityManager(); + auto playerEnt = em.getEntity(gameHandler.getPlayerGuid()); + auto targetEnt = em.getEntity(gameHandler.getTargetGuid()); + if (playerEnt && targetEnt) { + float dx = playerEnt->getX() - targetEnt->getX(); + float dy = playerEnt->getY() - targetEnt->getY(); + float dz = playerEnt->getZ() - targetEnt->getZ(); + if (std::sqrt(dx*dx + dy*dy + dz*dz) > static_cast(itemMaxRange)) + outOfRange = true; + } + } + } + bool clicked = false; if (iconTex) { ImVec4 tintColor(1, 1, 1, 1);