mirror of
https://github.com/azerothcore/mod-transmog
synced 2025-11-29 22:48:30 +08:00
feat: Implement Search feature for transmogs (#93)
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#define PRESETS // comment this line to disable preset feature totally
|
#define PRESETS // comment this line to disable preset feature totally
|
||||||
#define HIDDEN_ITEM_ID 1 // used for hidden transmog - do not use a valid equipment ID
|
#define HIDDEN_ITEM_ID 1 // used for hidden transmog - do not use a valid equipment ID
|
||||||
#define MAX_OPTIONS 25 // do not alter
|
#define MAX_OPTIONS 25 // do not alter
|
||||||
|
#define MAX_SEARCH_STRING_LENGTH 50
|
||||||
|
|
||||||
class Item;
|
class Item;
|
||||||
class Player;
|
class Player;
|
||||||
@@ -62,6 +63,7 @@ public:
|
|||||||
typedef std::unordered_map<ObjectGuid, uint32> transmog2Data;
|
typedef std::unordered_map<ObjectGuid, uint32> transmog2Data;
|
||||||
typedef std::unordered_map<ObjectGuid, transmog2Data> transmogMap;
|
typedef std::unordered_map<ObjectGuid, transmog2Data> transmogMap;
|
||||||
typedef std::unordered_map<uint32, std::vector<uint32>> collectionCacheMap;
|
typedef std::unordered_map<uint32, std::vector<uint32>> collectionCacheMap;
|
||||||
|
typedef std::unordered_map<uint32, std::string> searchStringMap;
|
||||||
transmogMap entryMap; // entryMap[pGUID][iGUID] = entry
|
transmogMap entryMap; // entryMap[pGUID][iGUID] = entry
|
||||||
transmogData dataMap; // dataMap[iGUID] = pGUID
|
transmogData dataMap; // dataMap[iGUID] = pGUID
|
||||||
collectionCacheMap collectionCache;
|
collectionCacheMap collectionCache;
|
||||||
@@ -77,6 +79,7 @@ public:
|
|||||||
typedef std::map<uint8, std::string> presetIdMap;
|
typedef std::map<uint8, std::string> presetIdMap;
|
||||||
typedef std::unordered_map<ObjectGuid, presetIdMap> presetNameMap;
|
typedef std::unordered_map<ObjectGuid, presetIdMap> presetNameMap;
|
||||||
presetNameMap presetByName; // presetByName[pGUID][presetID] = presetName
|
presetNameMap presetByName; // presetByName[pGUID][presetID] = presetName
|
||||||
|
searchStringMap searchStringByPlayer;
|
||||||
|
|
||||||
void PresetTransmog(Player* player, Item* itemTransmogrified, uint32 fakeEntry, uint8 slot);
|
void PresetTransmog(Player* player, Item* itemTransmogrified, uint32 fakeEntry, uint8 slot);
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ public:
|
|||||||
bool OnGossipHello(Player* player, Creature* creature) override
|
bool OnGossipHello(Player* player, Creature* creature) override
|
||||||
{
|
{
|
||||||
WorldSession* session = player->GetSession();
|
WorldSession* session = player->GetSession();
|
||||||
|
|
||||||
|
// Clear the search string for the player
|
||||||
|
sT->searchStringByPlayer.erase(player->GetGUID().GetCounter());
|
||||||
|
|
||||||
if (sT->GetEnableTransmogInfo())
|
if (sT->GetEnableTransmogInfo())
|
||||||
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/INV_Misc_Book_11:30:30:-18:0|tHow does transmogrification work?", EQUIPMENT_SLOT_END + 9, 0);
|
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/INV_Misc_Book_11:30:30:-18:0|tHow does transmogrification work?", EQUIPMENT_SLOT_END + 9, 0);
|
||||||
for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot)
|
for (uint8 slot = EQUIPMENT_SLOT_START; slot < EQUIPMENT_SLOT_END; ++slot)
|
||||||
@@ -273,7 +277,18 @@ public:
|
|||||||
bool OnGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 action, const char* code) override
|
bool OnGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 action, const char* code) override
|
||||||
{
|
{
|
||||||
player->PlayerTalkClass->ClearMenus();
|
player->PlayerTalkClass->ClearMenus();
|
||||||
if (sender || action)
|
if (sender)
|
||||||
|
{
|
||||||
|
// "sender" is an equipment slot for a search - execute the search
|
||||||
|
std::string searchString(code);
|
||||||
|
if (searchString.length() > MAX_SEARCH_STRING_LENGTH)
|
||||||
|
searchString = searchString.substr(0, MAX_SEARCH_STRING_LENGTH);
|
||||||
|
sT->searchStringByPlayer.erase(player->GetGUID().GetCounter());
|
||||||
|
sT->searchStringByPlayer.insert({player->GetGUID().GetCounter(), searchString});
|
||||||
|
OnGossipSelect(player, creature, EQUIPMENT_SLOT_END, sender - 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (action)
|
||||||
return true; // should never happen
|
return true; // should never happen
|
||||||
if (!sT->GetEnableSets())
|
if (!sT->GetEnableSets())
|
||||||
{
|
{
|
||||||
@@ -344,6 +359,7 @@ public:
|
|||||||
WorldSession* session = player->GetSession();
|
WorldSession* session = player->GetSession();
|
||||||
Item* oldItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
|
Item* oldItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
|
||||||
bool sendGossip = true;
|
bool sendGossip = true;
|
||||||
|
bool hasSearchString;
|
||||||
if (oldItem)
|
if (oldItem)
|
||||||
{
|
{
|
||||||
uint32 price = sT->GetSpecialPrice(oldItem->GetTemplate());
|
uint32 price = sT->GetSpecialPrice(oldItem->GetTemplate());
|
||||||
@@ -361,7 +377,7 @@ public:
|
|||||||
|
|
||||||
uint16 pageNumber = 0;
|
uint16 pageNumber = 0;
|
||||||
uint32 startValue = 0;
|
uint32 startValue = 0;
|
||||||
uint32 endValue = MAX_OPTIONS - 3;
|
uint32 endValue = MAX_OPTIONS - 4;
|
||||||
bool lastPage = false;
|
bool lastPage = false;
|
||||||
if (gossipPageNumber > EQUIPMENT_SLOT_END + 10)
|
if (gossipPageNumber > EQUIPMENT_SLOT_END + 10)
|
||||||
{
|
{
|
||||||
@@ -372,6 +388,25 @@ public:
|
|||||||
uint32 accountId = player->GetSession()->GetAccountId();
|
uint32 accountId = player->GetSession()->GetAccountId();
|
||||||
if (sT->collectionCache.find(accountId) != sT->collectionCache.end())
|
if (sT->collectionCache.find(accountId) != sT->collectionCache.end())
|
||||||
{
|
{
|
||||||
|
std::unordered_map<uint32, std::string>::iterator searchStringIterator = sT->searchStringByPlayer.find(player->GetGUID().GetCounter());
|
||||||
|
hasSearchString = !(searchStringIterator == sT->searchStringByPlayer.end());
|
||||||
|
std::string searchDisplayValue(hasSearchString ? searchStringIterator->second : "Search....");
|
||||||
|
// Offset values to add Search gossip item
|
||||||
|
if (pageNumber == 0)
|
||||||
|
{
|
||||||
|
if (hasSearchString)
|
||||||
|
{
|
||||||
|
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(30620, 30, 30, -18, 0) + "Searching for: " + searchDisplayValue, slot + 1, 0, "Search for what item?", 0, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AddGossipItemFor(player, GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(30620, 30, 30, -18, 0) + "Search....", slot + 1, 0, "Search for what item?", 0, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startValue--;
|
||||||
|
}
|
||||||
std::vector<Item*> allowedItems;
|
std::vector<Item*> allowedItems;
|
||||||
if (sT->GetAllowHiddenTransmog())
|
if (sT->GetAllowHiddenTransmog())
|
||||||
{
|
{
|
||||||
@@ -395,6 +430,8 @@ public:
|
|||||||
continue;
|
continue;
|
||||||
if (sT->GetFakeEntry(oldItem->GetGUID()) == newItem->GetEntry())
|
if (sT->GetFakeEntry(oldItem->GetGUID()) == newItem->GetEntry())
|
||||||
continue;
|
continue;
|
||||||
|
if (hasSearchString && newItem->GetTemplate()->Name1.find(searchDisplayValue) == std::string::npos)
|
||||||
|
continue;
|
||||||
allowedItems.push_back(newItem);
|
allowedItems.push_back(newItem);
|
||||||
}
|
}
|
||||||
for (uint32 i = startValue; i <= endValue; i++)
|
for (uint32 i = startValue; i <= endValue; i++)
|
||||||
|
|||||||
Reference in New Issue
Block a user