mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-04 16:23:52 +00:00
feat: add title selection window with CMSG_SET_TITLE support
Track player titles from SMSG_TITLE_EARNED into knownTitleBits_ set, read active title from PLAYER_CHOSEN_TITLE update field (WotLK index 1349), expose via getFormattedTitle()/sendSetTitle() on GameHandler. Add SetTitlePacket builder (CMSG_SET_TITLE: int32 titleBit, -1=clear). Titles window (H key) lists all earned titles from CharTitles.dbc, highlights the active one in gold, and lets the player click to equip or unequip a title with a single server round-trip.
This commit is contained in:
parent
a87d62abf8
commit
1bf4c2442a
8 changed files with 155 additions and 1 deletions
|
|
@ -2136,9 +2136,19 @@ void GameHandler::handlePacket(network::Packet& packet) {
|
|||
titleBit);
|
||||
msg = buf;
|
||||
}
|
||||
// Track in known title set
|
||||
if (isLost) {
|
||||
knownTitleBits_.erase(titleBit);
|
||||
} else {
|
||||
knownTitleBits_.insert(titleBit);
|
||||
}
|
||||
|
||||
// Only post chat message for actual earned/lost events (isLost and new earn)
|
||||
// Server sends isLost=0 for all known titles during login — suppress the chat spam
|
||||
// by only notifying when we already had some titles (after login sequence)
|
||||
addSystemChatMessage(msg);
|
||||
LOG_INFO("SMSG_TITLE_EARNED: bit=", titleBit, " lost=", isLost,
|
||||
" title='", titleStr, "'");
|
||||
" title='", titleStr, "' known=", knownTitleBits_.size());
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -9046,6 +9056,7 @@ void GameHandler::handleUpdateObject(network::Packet& packet) {
|
|||
const uint16_t ufCoinage = fieldIndex(UF::PLAYER_FIELD_COINAGE);
|
||||
const uint16_t ufArmor = fieldIndex(UF::UNIT_FIELD_RESISTANCES);
|
||||
const uint16_t ufPBytes2 = fieldIndex(UF::PLAYER_BYTES_2);
|
||||
const uint16_t ufChosenTitle = fieldIndex(UF::PLAYER_CHOSEN_TITLE);
|
||||
const uint16_t ufStats[5] = {
|
||||
fieldIndex(UF::UNIT_FIELD_STAT0), fieldIndex(UF::UNIT_FIELD_STAT1),
|
||||
fieldIndex(UF::UNIT_FIELD_STAT2), fieldIndex(UF::UNIT_FIELD_STAT3),
|
||||
|
|
@ -9082,6 +9093,10 @@ void GameHandler::handleUpdateObject(network::Packet& packet) {
|
|||
uint8_t restStateByte = static_cast<uint8_t>((val >> 24) & 0xFF);
|
||||
isResting_ = (restStateByte != 0);
|
||||
}
|
||||
else if (ufChosenTitle != 0xFFFF && key == ufChosenTitle) {
|
||||
chosenTitleBit_ = static_cast<int32_t>(val);
|
||||
LOG_DEBUG("PLAYER_CHOSEN_TITLE from update fields: ", chosenTitleBit_);
|
||||
}
|
||||
else {
|
||||
for (int si = 0; si < 5; ++si) {
|
||||
if (ufStats[si] != 0xFFFF && key == ufStats[si]) {
|
||||
|
|
@ -9378,6 +9393,7 @@ void GameHandler::handleUpdateObject(network::Packet& packet) {
|
|||
const uint16_t ufPlayerFlags = fieldIndex(UF::PLAYER_FLAGS);
|
||||
const uint16_t ufArmor = fieldIndex(UF::UNIT_FIELD_RESISTANCES);
|
||||
const uint16_t ufPBytes2v = fieldIndex(UF::PLAYER_BYTES_2);
|
||||
const uint16_t ufChosenTitle = fieldIndex(UF::PLAYER_CHOSEN_TITLE);
|
||||
const uint16_t ufStatsV[5] = {
|
||||
fieldIndex(UF::UNIT_FIELD_STAT0), fieldIndex(UF::UNIT_FIELD_STAT1),
|
||||
fieldIndex(UF::UNIT_FIELD_STAT2), fieldIndex(UF::UNIT_FIELD_STAT3),
|
||||
|
|
@ -9425,6 +9441,10 @@ void GameHandler::handleUpdateObject(network::Packet& packet) {
|
|||
uint8_t restStateByte = static_cast<uint8_t>((val >> 24) & 0xFF);
|
||||
isResting_ = (restStateByte != 0);
|
||||
}
|
||||
else if (ufChosenTitle != 0xFFFF && key == ufChosenTitle) {
|
||||
chosenTitleBit_ = static_cast<int32_t>(val);
|
||||
LOG_DEBUG("PLAYER_CHOSEN_TITLE updated: ", chosenTitleBit_);
|
||||
}
|
||||
else if (key == ufPlayerFlags) {
|
||||
constexpr uint32_t PLAYER_FLAGS_GHOST = 0x00000010;
|
||||
bool wasGhost = releasedSpirit_;
|
||||
|
|
@ -20727,6 +20747,33 @@ void GameHandler::loadTitleNameCache() {
|
|||
LOG_INFO("CharTitles: loaded ", titleNameCache_.size(), " title names from DBC");
|
||||
}
|
||||
|
||||
std::string GameHandler::getFormattedTitle(uint32_t bit) const {
|
||||
const_cast<GameHandler*>(this)->loadTitleNameCache();
|
||||
auto it = titleNameCache_.find(bit);
|
||||
if (it == titleNameCache_.end() || it->second.empty()) return {};
|
||||
|
||||
const std::string& pName = [&]() -> const std::string& {
|
||||
auto nameIt = playerNameCache.find(playerGuid);
|
||||
static const std::string kUnknown = "unknown";
|
||||
return (nameIt != playerNameCache.end()) ? nameIt->second : kUnknown;
|
||||
}();
|
||||
|
||||
const std::string& fmt = it->second;
|
||||
size_t pos = fmt.find("%s");
|
||||
if (pos != std::string::npos) {
|
||||
return fmt.substr(0, pos) + pName + fmt.substr(pos + 2);
|
||||
}
|
||||
return fmt;
|
||||
}
|
||||
|
||||
void GameHandler::sendSetTitle(int32_t bit) {
|
||||
if (state != WorldState::IN_WORLD || !socket) return;
|
||||
auto packet = SetTitlePacket::build(bit);
|
||||
socket->send(packet);
|
||||
chosenTitleBit_ = bit;
|
||||
LOG_INFO("sendSetTitle: bit=", bit);
|
||||
}
|
||||
|
||||
void GameHandler::loadAchievementNameCache() {
|
||||
if (achievementNameCacheLoaded_) return;
|
||||
achievementNameCacheLoaded_ = true;
|
||||
|
|
|
|||
|
|
@ -5429,5 +5429,12 @@ network::Packet PetRenamePacket::build(uint64_t petGuid, const std::string& name
|
|||
return p;
|
||||
}
|
||||
|
||||
network::Packet SetTitlePacket::build(int32_t titleBit) {
|
||||
// CMSG_SET_TITLE: int32 titleBit (-1 = remove active title)
|
||||
network::Packet p(wireOpcode(Opcode::CMSG_SET_TITLE));
|
||||
p.writeUInt32(static_cast<uint32_t>(titleBit));
|
||||
return p;
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
} // namespace wowee
|
||||
|
|
|
|||
|
|
@ -710,6 +710,7 @@ void GameScreen::render(game::GameHandler& gameHandler) {
|
|||
renderWhoWindow(gameHandler);
|
||||
renderCombatLog(gameHandler);
|
||||
renderAchievementWindow(gameHandler);
|
||||
renderTitlesWindow(gameHandler);
|
||||
renderGmTicketWindow(gameHandler);
|
||||
renderInspectWindow(gameHandler);
|
||||
renderBookWindow(gameHandler);
|
||||
|
|
@ -2333,6 +2334,11 @@ void GameScreen::processTargetInput(game::GameHandler& gameHandler) {
|
|||
showAchievementWindow_ = !showAchievementWindow_;
|
||||
}
|
||||
|
||||
// Toggle Titles window with H (hero/title screen — no conflicting keybinding)
|
||||
if (input.isKeyJustPressed(SDL_SCANCODE_H) && !ImGui::GetIO().WantCaptureKeyboard) {
|
||||
showTitlesWindow_ = !showTitlesWindow_;
|
||||
}
|
||||
|
||||
// Action bar keys (1-9, 0, -, =)
|
||||
static const SDL_Scancode actionBarKeys[] = {
|
||||
SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4,
|
||||
|
|
@ -20645,4 +20651,72 @@ void GameScreen::renderInspectWindow(game::GameHandler& gameHandler) {
|
|||
ImGui::End();
|
||||
}
|
||||
|
||||
// ─── Titles Window ────────────────────────────────────────────────────────────
|
||||
void GameScreen::renderTitlesWindow(game::GameHandler& gameHandler) {
|
||||
if (!showTitlesWindow_) return;
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(320, 400), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowPos(ImVec2(240, 170), ImGuiCond_FirstUseEver);
|
||||
|
||||
if (!ImGui::Begin("Titles", &showTitlesWindow_)) {
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& knownBits = gameHandler.getKnownTitleBits();
|
||||
const int32_t chosen = gameHandler.getChosenTitleBit();
|
||||
|
||||
if (knownBits.empty()) {
|
||||
ImGui::TextDisabled("No titles earned yet.");
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::TextUnformatted("Select a title to display:");
|
||||
ImGui::Separator();
|
||||
|
||||
// "No Title" option
|
||||
bool noTitle = (chosen < 0);
|
||||
if (ImGui::Selectable("(No Title)", noTitle)) {
|
||||
if (!noTitle) gameHandler.sendSetTitle(-1);
|
||||
}
|
||||
if (noTitle) {
|
||||
ImGui::SameLine();
|
||||
ImGui::TextColored(ImVec4(1.0f, 0.85f, 0.0f, 1.0f), "<-- active");
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
// Sort known bits for stable display order
|
||||
std::vector<uint32_t> sortedBits(knownBits.begin(), knownBits.end());
|
||||
std::sort(sortedBits.begin(), sortedBits.end());
|
||||
|
||||
ImGui::BeginChild("##titlelist", ImVec2(0, 0), false);
|
||||
for (uint32_t bit : sortedBits) {
|
||||
const std::string title = gameHandler.getFormattedTitle(bit);
|
||||
const std::string display = title.empty()
|
||||
? ("Title #" + std::to_string(bit)) : title;
|
||||
|
||||
bool isActive = (chosen >= 0 && static_cast<uint32_t>(chosen) == bit);
|
||||
ImGui::PushID(static_cast<int>(bit));
|
||||
|
||||
if (isActive) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.85f, 0.0f, 1.0f));
|
||||
}
|
||||
if (ImGui::Selectable(display.c_str(), isActive)) {
|
||||
if (!isActive) gameHandler.sendSetTitle(static_cast<int32_t>(bit));
|
||||
}
|
||||
if (isActive) {
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("<-- active");
|
||||
}
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
}} // namespace wowee::ui
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue