refactor(chat): extract ItemTooltipRenderer, slim render(), consolidate utils

- Extract renderItemTooltip() (510 LOC) from ChatMarkupRenderer into
  dedicated ItemTooltipRenderer class; chat_markup_renderer.cpp 766→192 LOC
- Extract formatChatMessage(), detectChannelPrefix(), inputTextCallback()
  from render(); render() 711→376 LOC
- Consolidate replaceGenderPlaceholders() from 3 copies into
  chat_utils::replaceGenderPlaceholders(); remove 118 LOC duplicate from
  quest_log_screen.cpp, update 8 call sites in window_manager.cpp
- Delete chat_panel_commands.cpp (359 LOC) — absorb sendChatMessage,
  executeMacroText, PortBot helpers into chat_panel.cpp; move
  evaluateMacroConditionals to macro_eval_convenience.cpp
- Delete chat_panel_utils.cpp (229 LOC) — absorb small utilities into
  chat_panel.cpp
- Replace 3 forward declarations of evaluateMacroConditionals with
  #include "ui/chat/macro_evaluator.hpp"

Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
This commit is contained in:
Pavel Okhlopkov 2026-04-12 15:46:03 +03:00
parent 42f1bb98ea
commit ada019e0d4
17 changed files with 1302 additions and 1463 deletions

View file

@ -47,15 +47,6 @@ public:
void render(const std::vector<ChatSegment>& segments,
const ImVec4& baseColor,
const MarkupRenderContext& ctx) const;
/**
* Render a full item tooltip for the given item entry.
* Extracted from the renderItemLinkTooltip inline lambda.
*/
static void renderItemTooltip(uint32_t itemEntry,
game::GameHandler& gameHandler,
InventoryScreen& inventoryScreen,
pipeline::AssetManager* assetMgr);
};
} // namespace ui

View file

@ -1,14 +1,18 @@
#pragma once
#include "game/world_packets.hpp"
#include "game/entity.hpp"
#include <algorithm>
#include <cctype>
#include <memory>
#include <string>
namespace wowee {
// Forward declaration
namespace game { class GameHandler; }
// Forward declarations
namespace game {
class GameHandler;
}
namespace ui {
namespace chat_utils {
@ -38,6 +42,17 @@ inline std::string toLower(std::string s) {
return s;
}
/**
* Replace $g/$G gender, $n/$N name, $c/$C class, $r/$R race,
* $p/$o/$s/$S pronoun, $b/$B linebreak, and |n linebreak placeholders.
* Extracted from ChatPanel::replaceGenderPlaceholders (Phase 6.6).
*/
std::string replaceGenderPlaceholders(const std::string& text,
game::GameHandler& gameHandler);
/** Get display name for any entity (Player/Unit/GameObject). */
std::string getEntityDisplayName(const std::shared_ptr<game::Entity>& entity);
} // namespace chat_utils
} // namespace ui
} // namespace wowee

View file

@ -0,0 +1,28 @@
#pragma once
#include <cstdint>
namespace wowee {
namespace game { class GameHandler; }
namespace pipeline { class AssetManager; }
namespace ui {
class InventoryScreen;
/**
* Renders a full WoW-style item tooltip via ImGui.
*
* Extracted from ChatMarkupRenderer::renderItemTooltip (Phase 6.7).
* Handles: item name/quality color, armor/DPS, stats, sockets, set bonuses,
* durability, sell price, required level, comparison tooltip.
*/
class ItemTooltipRenderer {
public:
static void render(uint32_t itemEntry,
game::GameHandler& gameHandler,
InventoryScreen& inventoryScreen,
pipeline::AssetManager* assetMgr);
};
} // namespace ui
} // namespace wowee

View file

@ -7,6 +7,7 @@
#include <string>
namespace wowee {
namespace game { class GameHandler; }
namespace ui {
class IGameState;
@ -46,5 +47,11 @@ private:
IModifierState& modState_;
};
// Convenience free function — thin wrapper over MacroEvaluator.
// Used by command modules (combat_commands, system_commands, target_commands).
std::string evaluateMacroConditionals(const std::string& rawArg,
game::GameHandler& gameHandler,
uint64_t& targetOverride);
} // namespace ui
} // namespace wowee

View file

@ -125,9 +125,6 @@ public:
// UIServices injection (Phase B singleton breaking)
void setServices(const UIServices& services) { services_ = services; }
/** Replace $g/$G and $n/$N gender/name placeholders in quest/chat text. */
std::string replaceGenderPlaceholders(const std::string& text, game::GameHandler& gameHandler);
// ---- Accessors for command system (Phase 3) ----
char* getChatInputBuffer() { return chatInputBuffer_; }
size_t getChatInputBufferSize() const { return sizeof(chatInputBuffer_); }
@ -203,7 +200,8 @@ private:
// ---- Helpers ----
void sendChatMessage(game::GameHandler& gameHandler);
// getChatTypeName / getChatTypeColor now static in ChatTabManager
static int inputTextCallback(ImGuiInputTextCallbackData* data);
void detectChannelPrefix(game::GameHandler& gameHandler);
// Cached game handler for input callback (set each frame in render)
game::GameHandler* cachedGameHandler_ = nullptr;