Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BH/BH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void BH::Initialize()
new StashExport();
new MapNotify();
new ChatColor();
new ChatItemLinks();

moduleManager->LoadModules();

Expand Down
5 changes: 5 additions & 0 deletions BH/BH.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ struct BHApp
SettingsBool usingHDText = { false, false };
} d2gl;

struct
{
SettingsBool enabled = { true, true }; // chat item links (Modules/ItemLinks)
} itemLinks;

struct
{
pd2PlaySoundImpl_t pd2PlaySoundImpl = NULL;
Expand Down
7 changes: 7 additions & 0 deletions BH/BH.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ powershell.exe -NoProfile -File "$(ProjectDir)..\..\scripts\CopyDataFolder.ps1"<
<ClCompile Include="Modules\Gamefilter\ParsedFilterString.cpp" />
<ClCompile Include="Modules\GameSettings\GameSettings.cpp" />
<ClCompile Include="Modules\Item\Item.cpp" />
<ClCompile Include="Modules\ItemLinks\ItemLinkCodec.cpp" />
<ClCompile Include="Modules\ItemLinks\ItemLinkGame.cpp" />
<ClCompile Include="Modules\ItemLinks\ItemLinks.cpp" />
<ClCompile Include="Modules\Item\ItemDisplay.cpp" />
<ClCompile Include="Modules\MapNotify\MapNotify.cpp" />
<ClCompile Include="Modules\Module.cpp" />
Expand Down Expand Up @@ -244,6 +247,10 @@ powershell.exe -NoProfile -File "$(ProjectDir)..\..\scripts\CopyDataFolder.ps1"<
<ClInclude Include="Modules\Gamefilter\ParsedFilterString.h" />
<ClInclude Include="Modules\GameSettings\GameSettings.h" />
<ClInclude Include="Modules\Item\Item.h" />
<ClInclude Include="Modules\ItemLinks\ChatLinkApi.h" />
<ClInclude Include="Modules\ItemLinks\ItemLinkCodec.h" />
<ClInclude Include="Modules\ItemLinks\ItemLinkGame.h" />
<ClInclude Include="Modules\ItemLinks\ItemLinks.h" />
<ClInclude Include="Modules\Item\ItemDisplay.h" />
<ClInclude Include="Modules\MapNotify\MapNotify.h" />
<ClInclude Include="Modules\Module.h" />
Expand Down
24 changes: 24 additions & 0 deletions BH/BH.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@
<ClCompile Include="Modules\ChatColor\ChatColor.cpp">
<Filter>Modules\ChatColor</Filter>
</ClCompile>
<ClCompile Include="Modules\ItemLinks\ItemLinks.cpp">
<Filter>Modules\ItemLinks</Filter>
</ClCompile>
<ClCompile Include="Modules\ItemLinks\ItemLinkCodec.cpp">
<Filter>Modules\ItemLinks</Filter>
</ClCompile>
<ClCompile Include="Modules\ItemLinks\ItemLinkGame.cpp">
<Filter>Modules\ItemLinks</Filter>
</ClCompile>
<ClCompile Include="Modules\Gamefilter\Gamefilter.cpp">
<Filter>Modules\Gamefilter</Filter>
</ClCompile>
Expand Down Expand Up @@ -174,6 +183,18 @@
<ClInclude Include="Modules\ChatColor\ChatColor.h">
<Filter>Modules\ChatColor</Filter>
</ClInclude>
<ClInclude Include="Modules\ItemLinks\ItemLinks.h">
<Filter>Modules\ItemLinks</Filter>
</ClInclude>
<ClInclude Include="Modules\ItemLinks\ItemLinkCodec.h">
<Filter>Modules\ItemLinks</Filter>
</ClInclude>
<ClInclude Include="Modules\ItemLinks\ItemLinkGame.h">
<Filter>Modules\ItemLinks</Filter>
</ClInclude>
<ClInclude Include="Modules\ItemLinks\ChatLinkApi.h">
<Filter>Modules\ItemLinks</Filter>
</ClInclude>
<ClInclude Include="Modules\Gamefilter\Gamefilter.h">
<Filter>Modules\Gamefilter</Filter>
</ClInclude>
Expand Down Expand Up @@ -258,6 +279,9 @@
<Filter Include="Modules\ChatColor">
<UniqueIdentifier>{f652bd02-2b0b-46a4-843c-20a0a9ea472d}</UniqueIdentifier>
</Filter>
<Filter Include="Modules\ItemLinks">
<UniqueIdentifier>{6d2a8f41-3b7e-4c19-9e5a-0f4b2c7d8e13}</UniqueIdentifier>
</Filter>
<Filter Include="Modules\Gamefilter">
<UniqueIdentifier>{b2342ae5-3b17-4a7e-bd84-a5173ecce46d}</UniqueIdentifier>
</Filter>
Expand Down
3 changes: 3 additions & 0 deletions BH/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ set(MODULE_SOURCES "Modules/Module.cpp"
"Modules/Gamefilter/Gamefilter.cpp"
"Modules/Item/Item.cpp"
"Modules/Item/ItemDisplay.cpp"
"Modules/ItemLinks/ItemLinkCodec.cpp"
"Modules/ItemLinks/ItemLinkGame.cpp"
"Modules/ItemLinks/ItemLinks.cpp"
"Modules/ItemMover/ItemMover.cpp"
"Modules/Party/Party.cpp"
"Modules/ScreenInfo/ScreenInfo.cpp"
Expand Down
8 changes: 8 additions & 0 deletions BH/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ void Config::SaveConfig()
jsonGame["always_show_items"] = App.game.alwaysShowItems.value;
App.jsonConfig["game"] = jsonGame;

// Chat item links
json jsonItemLinks;
jsonItemLinks["enabled"] = App.itemLinks.enabled.value;
App.jsonConfig["item_links"] = jsonItemLinks;

// Party settings
json jsonParty;
jsonParty["auto_party"]["enabled"] = App.party.autoParty.toggle.isEnabled;
Expand Down Expand Up @@ -391,6 +396,9 @@ void Config::LoadConfig()
App.game.experienceMeter.value = GetBool("/game"_json_pointer, "experience_meter", App.game.experienceMeter);
App.game.alwaysShowItems.value = GetBool("/game"_json_pointer, "always_show_items", App.game.alwaysShowItems);

// Chat item links
App.itemLinks.enabled.value = GetBool("/item_links"_json_pointer, "enabled", App.itemLinks.enabled);

// Party settings
App.party.autoParty.toggle = GetToggle("/party"_json_pointer, "auto_party", App.party.autoParty);
App.party.autoCorpseLoot.toggle = GetToggle("/party"_json_pointer, "auto_corpse_loot", App.party.autoCorpseLoot);
Expand Down
1 change: 1 addition & 0 deletions BH/Modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
#include "Modules\Party\Party.h"
#include "Modules\StashExport\StashExport.h"
#include "Modules\ChatColor\ChatColor.h"
#include "Modules\ItemLinks\ItemLinks.h"
#include "Modules/GameSettings/GameSettings.h"
34 changes: 34 additions & 0 deletions BH/Modules/ItemLinks/ChatLinkApi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once
// Chat item links: the API other chat UIs use to show and open item links.
//
// The ItemLinks module already renders links in the game's own chat (overlay and message log). A
// replacement chat UI that stores and draws messages itself calls these instead:
// - FormatMessage once per received message body: plain text and link runs (validated tokens
// become "[Item Name]" in the item's quality colour; invalid tokens stay plain text);
// - OnClick when the player left-clicks a link run: opens the game's own item tooltip;
// - Release when the message leaves its buffer.
#include <string>
#include <vector>

struct ChatRun {
std::wstring text;
int color; // D2 text colour index, or -1 = the line's own colour
int link; // 0 = plain text, else a link handle (> 0)
};

namespace ItemLinks {

// Split a message body into runs. Accepts raw "#i<token>" words and text the game-chat path has
// already rewritten (its zero-width link markers); a "[typed name] " right before a token is folded
// into the link run. Each link run holds one reference on its handle.
void FormatMessage(const wchar_t* msg, std::vector<ChatRun>& out);

// Drop one reference (0 / unknown handles are ignored). The item data is freed with the last one.
void Release(int link);

// Open the native item tooltip for `link`, anchored on the clicked run: x = run centre, yTop/yBottom
// = the run's box. The ItemLinks module draws it every frame until Esc, another click, or leaving
// the game. Returns true when the click was consumed.
bool OnClick(int link, int x, int yTop, int yBottom);

} // namespace ItemLinks
Loading
Loading