feat: implement client-side macro text storage and execution

Macros in WoW are client-side — the server sends only a macro index via
SMSG_ACTION_BUTTONS, never the text. This commit adds local storage and
a UI so macro slots are actually usable.

- GameHandler: getMacroText/setMacroText accessors backed by macros_ map;
  text is persisted to the character .cfg file as macro_N_text= entries
- Action bar left-click: MACRO slot executes first line of macro text as
  a chat/slash command (same path as /cast, /use, etc.)
- Context menu: "Execute" and "Edit" items for MACRO slots; "Edit" opens
  a multiline modal editor (320×80 px, up to 255 chars) with Save/Cancel
- Tooltip: shows macro text body below the index; hints "right-click to
  Edit" when no text is set yet
This commit is contained in:
Kelsi 2026-03-18 02:07:59 -07:00
parent 1588c1029a
commit 2c86fb4fa6
4 changed files with 96 additions and 0 deletions

View file

@ -7483,6 +7483,16 @@ void GameScreen::renderActionBar(game::GameHandler& gameHandler) {
gameHandler.castSpell(slot.id, target);
} else if (slot.type == game::ActionBarSlot::ITEM && slot.id != 0) {
gameHandler.useItemById(slot.id);
} else if (slot.type == game::ActionBarSlot::MACRO) {
const std::string& text = gameHandler.getMacroText(slot.id);
if (!text.empty()) {
// Execute first line of macro as a chat command
size_t nl = text.find('\n');
std::string firstLine = (nl != std::string::npos) ? text.substr(0, nl) : text;
strncpy(chatInputBuffer, firstLine.c_str(), sizeof(chatInputBuffer) - 1);
chatInputBuffer[sizeof(chatInputBuffer) - 1] = '\0';
sendChatMessage(gameHandler);
}
}
}
@ -7513,6 +7523,24 @@ void GameScreen::renderActionBar(game::GameHandler& gameHandler) {
}
} else if (slot.type == game::ActionBarSlot::MACRO) {
ImGui::TextDisabled("Macro #%u", slot.id);
ImGui::Separator();
if (ImGui::MenuItem("Execute")) {
const std::string& text = gameHandler.getMacroText(slot.id);
if (!text.empty()) {
size_t nl = text.find('\n');
std::string firstLine = (nl != std::string::npos) ? text.substr(0, nl) : text;
strncpy(chatInputBuffer, firstLine.c_str(), sizeof(chatInputBuffer) - 1);
chatInputBuffer[sizeof(chatInputBuffer) - 1] = '\0';
sendChatMessage(gameHandler);
}
}
if (ImGui::MenuItem("Edit")) {
const std::string& txt = gameHandler.getMacroText(slot.id);
strncpy(macroEditorBuf_, txt.c_str(), sizeof(macroEditorBuf_) - 1);
macroEditorBuf_[sizeof(macroEditorBuf_) - 1] = '\0';
macroEditorId_ = slot.id;
macroEditorOpen_ = true;
}
}
ImGui::Separator();
if (ImGui::MenuItem("Clear Slot")) {
@ -7574,6 +7602,13 @@ void GameScreen::renderActionBar(game::GameHandler& gameHandler) {
} else if (slot.type == game::ActionBarSlot::MACRO) {
ImGui::BeginTooltip();
ImGui::Text("Macro #%u", slot.id);
const std::string& macroText = gameHandler.getMacroText(slot.id);
if (!macroText.empty()) {
ImGui::Separator();
ImGui::TextUnformatted(macroText.c_str());
} else {
ImGui::TextDisabled("(no text — right-click to Edit)");
}
ImGui::EndTooltip();
} else if (slot.type == game::ActionBarSlot::ITEM) {
ImGui::BeginTooltip();
@ -7786,6 +7821,28 @@ void GameScreen::renderActionBar(game::GameHandler& gameHandler) {
if (i > 0) ImGui::SameLine(0, spacing);
renderBarSlot(i, keyLabels1[i]);
}
// Macro editor modal — opened by "Edit" in action bar context menus
if (macroEditorOpen_) {
ImGui::OpenPopup("Edit Macro###MacroEdit");
macroEditorOpen_ = false;
}
if (ImGui::BeginPopupModal("Edit Macro###MacroEdit", nullptr,
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse)) {
ImGui::Text("Macro #%u (first line executes on click)", macroEditorId_);
ImGui::SetNextItemWidth(320.0f);
ImGui::InputTextMultiline("##MacroText", macroEditorBuf_, sizeof(macroEditorBuf_),
ImVec2(320.0f, 80.0f));
if (ImGui::Button("Save")) {
gameHandler.setMacroText(macroEditorId_, std::string(macroEditorBuf_));
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("Cancel")) {
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}
ImGui::End();