Shift-click bag items to insert item links into chat input

This commit is contained in:
Kelsi 2026-03-11 21:09:42 -07:00
parent e415451f89
commit 43c239ee2f
3 changed files with 45 additions and 0 deletions

View file

@ -176,6 +176,9 @@ private:
int dropBackpackIndex_ = -1;
std::string dropItemName_;
// Pending chat item link from shift-click
std::string pendingChatItemLink_;
public:
static ImVec4 getQualityColor(game::ItemQuality quality);
@ -190,6 +193,13 @@ public:
/// Drop the currently held item into a specific equipment slot.
/// Returns true if the drop was accepted and consumed.
bool dropHeldItemToEquipSlot(game::Inventory& inv, game::EquipSlot slot);
/// Returns a WoW item link string if the user shift-clicked a bag item, then clears it.
std::string getAndClearPendingChatLink() {
std::string out = std::move(pendingChatItemLink_);
pendingChatItemLink_.clear();
return out;
}
/// Drop the currently held item into a bank slot via CMSG_SWAP_ITEM.
void dropIntoBankSlot(game::GameHandler& gh, uint8_t dstBag, uint8_t dstSlot);
/// Pick up an item from main bank slot (click-and-hold from bank window).

View file

@ -511,6 +511,19 @@ void GameScreen::render(game::GameHandler& gameHandler) {
inventoryScreen.setGameHandler(&gameHandler);
inventoryScreen.render(gameHandler.getInventory(), gameHandler.getMoneyCopper());
// Insert item link into chat if player shift-clicked a bag item
{
std::string pendingLink = inventoryScreen.getAndClearPendingChatLink();
if (!pendingLink.empty()) {
size_t curLen = strlen(chatInputBuffer);
if (curLen + pendingLink.size() + 1 < sizeof(chatInputBuffer)) {
strncat(chatInputBuffer, pendingLink.c_str(), sizeof(chatInputBuffer) - curLen - 1);
chatInputMoveCursorToEnd = true;
refocusChatInput = true;
}
}
}
// Character screen (C key toggle handled inside render())
inventoryScreen.renderCharacterScreen(gameHandler);

View file

@ -1737,6 +1737,28 @@ void InventoryScreen::renderItemSlot(game::Inventory& inventory, const game::Ite
}
}
// Shift+left-click: insert item link into chat input
if (ImGui::IsItemHovered() && !holdingItem &&
ImGui::IsMouseClicked(ImGuiMouseButton_Left) &&
ImGui::GetIO().KeyShift &&
item.itemId != 0 && !item.name.empty()) {
// Build WoW item link: |cff<qualHex>|Hitem:<id>:0:0:0:0:0:0:0:0|h[<name>]|h|r
const char* qualHex = "9d9d9d";
switch (item.quality) {
case game::ItemQuality::COMMON: qualHex = "ffffff"; break;
case game::ItemQuality::UNCOMMON: qualHex = "1eff00"; break;
case game::ItemQuality::RARE: qualHex = "0070dd"; break;
case game::ItemQuality::EPIC: qualHex = "a335ee"; break;
case game::ItemQuality::LEGENDARY: qualHex = "ff8000"; break;
default: break;
}
char linkBuf[512];
snprintf(linkBuf, sizeof(linkBuf),
"|cff%s|Hitem:%u:0:0:0:0:0:0:0:0|h[%s]|h|r",
qualHex, item.itemId, item.name.c_str());
pendingChatItemLink_ = linkBuf;
}
if (ImGui::IsItemHovered() && !holdingItem) {
// Pass inventory for backpack/bag items only; equipped items compare against themselves otherwise
const game::Inventory* tooltipInv = (kind == SlotKind::EQUIPMENT) ? nullptr : &inventory;