[Dialogue] Add support for Dialogue Window buttons. (#1546)

* [Dialogue] Add support for Dialogue Window buttons.
- Also changes "mysterious" identifier to "{mysterious}".
- Both button names are required for anything to show up, otherwise it defaults to Yes/No similar to Client::SendFullPopup.

* Move SetEntityVariable so responses can override default button response.

* Add negativeid support so you can override button two popup ID.

* Fix log.

* Update dialogue_window.cpp

Convert button names to strings and negativeid to secondrespondid.
This commit is contained in:
Kinglykrab 2021-09-19 19:24:04 -04:00 committed by GitHub
parent c15c54e920
commit 6a5face0aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 141 additions and 16 deletions

View File

@ -203,8 +203,10 @@ enum eInnateSkill {
InnateDisabled = 255 InnateDisabled = 255
}; };
const std::string DIAWIND_RESPONSE_KEY = "diawind_npcresponse"; const std::string DIAWIND_RESPONSE_ONE_KEY = "diawind_npc_response_one";
const uint32 POPUPID_DIAWIND = 999; const std::string DIAWIND_RESPONSE_TWO_KEY = "diawind_npc_response_two";
const uint32 POPUPID_DIAWIND_ONE = 99999;
const uint32 POPUPID_DIAWIND_TWO = 100000;
const uint32 POPUPID_UPDATE_SHOWSTATSWINDOW = 1000000; const uint32 POPUPID_UPDATE_SHOWSTATSWINDOW = 1000000;
struct ClientReward struct ClientReward

View File

@ -11155,9 +11155,18 @@ void Client::Handle_OP_PopupResponse(const EQApplicationPacket *app)
return; return;
break; break;
case POPUPID_DIAWIND: case POPUPID_DIAWIND_ONE:
if (EntityVariableExists(DIAWIND_RESPONSE_KEY.c_str())) { if (EntityVariableExists(DIAWIND_RESPONSE_ONE_KEY.c_str())) {
response = GetEntityVariable(DIAWIND_RESPONSE_KEY.c_str()); response = GetEntityVariable(DIAWIND_RESPONSE_ONE_KEY.c_str());
if (!response.empty()) {
ChannelMessageReceived(8, 0, 100, response.c_str());
}
}
break;
case POPUPID_DIAWIND_TWO:
if (EntityVariableExists(DIAWIND_RESPONSE_TWO_KEY.c_str())) {
response = GetEntityVariable(DIAWIND_RESPONSE_TWO_KEY.c_str());
if (!response.empty()) { if (!response.empty()) {
ChannelMessageReceived(8, 0, 100, response.c_str()); ChannelMessageReceived(8, 0, 100, response.c_str());
} }

View File

@ -11,7 +11,8 @@ void DialogueWindow::Render(Client *c, std::string markdown)
} }
// zero this out // zero this out
c->SetEntityVariable(DIAWIND_RESPONSE_KEY.c_str(), ""); c->SetEntityVariable(DIAWIND_RESPONSE_ONE_KEY.c_str(), "");
c->SetEntityVariable(DIAWIND_RESPONSE_TWO_KEY.c_str(), "");
// simple find and replace for the markdown // simple find and replace for the markdown
find_replace(output, "~", "</c>"); find_replace(output, "~", "</c>");
@ -32,10 +33,10 @@ void DialogueWindow::Render(Client *c, std::string markdown)
// mysterious voice // mysterious voice
bool render_mysterious_voice = false; bool render_mysterious_voice = false;
if (markdown.find("mysterious") != std::string::npos) { if (markdown.find("{mysterious}") != std::string::npos) {
render_mysterious_voice = true; render_mysterious_voice = true;
LogDiaWind("Client [{}] Rendering mysterious voice", c->GetCleanName()); LogDiaWind("Client [{}] Rendering mysterious voice", c->GetCleanName());
find_replace(output, "mysterious", ""); find_replace(output, "{mysterious}", "");
} }
// noquotes // noquotes
@ -98,10 +99,10 @@ void DialogueWindow::Render(Client *c, std::string markdown)
} }
} }
uint32 popup_id = POPUPID_DIAWIND; uint32 popup_id = POPUPID_DIAWIND_ONE;
uint32 negative_id = 0; uint32 negative_id = POPUPID_DIAWIND_TWO;
char *button_name_0 = nullptr; std::string button_one_name;
char *button_name_1 = nullptr; std::string button_two_name;
uint32 sound_controls = 0; uint32 sound_controls = 0;
// window type // window type
@ -171,6 +172,96 @@ void DialogueWindow::Render(Client *c, std::string markdown)
} }
} }
// secondresponseid
std::string secondresponseid;
if (markdown.find("secondresponseid") != std::string::npos) {
LogDiaWind("Client [{}] Rendering secondresponseid option", c->GetCleanName());
auto first_split = split_string(output, "secondresponseid:");
if (!first_split.empty()) {
auto second_split = split_string(first_split[1], " ");
if (!second_split.empty()) {
secondresponseid = second_split[0];
LogDiaWindDetail("Client [{}] Rendering secondresponseid option secondresponseid [{}]", c->GetCleanName(), secondresponseid);
}
if (first_split[1].length() == 1) {
secondresponseid = first_split[1];
LogDiaWindDetail(
"Client [{}] Rendering secondresponseid (end) option secondresponseid [{}]",
c->GetCleanName(),
secondresponseid
);
}
find_replace(output, fmt::format("secondresponseid:{}", secondresponseid), "");
if (!secondresponseid.empty()) {
negative_id = (StringIsNumber(secondresponseid) ? std::atoi(secondresponseid.c_str()) : 0);
}
}
}
// Buttons Text
std::string button_one;
std::string button_two;
if (
markdown.find("button_one") != std::string::npos &&
markdown.find("button_two") != std::string::npos
) {
LogDiaWind("Client [{}] Rendering button_one option.", c->GetCleanName());
auto one_first_split = split_string(output, "button_one:");
if (!one_first_split.empty()) {
auto one_second_split = split_string(one_first_split[1], " ");
if (!one_second_split.empty()) {
button_one = one_second_split[0];
LogDiaWindDetail("Client [{}] Rendering button_one option button_one [{}]", c->GetCleanName(), button_one);
}
if (one_first_split[1].length() == 1) {
button_one = one_first_split[1];
LogDiaWindDetail(
"Client [{}] Rendering button_one (end) option button_one [{}]",
c->GetCleanName(),
button_one
);
}
find_replace(output, fmt::format("button_one:{}", button_one), "");
if (!button_one.empty()) {
button_one_name = button_one.c_str();
}
}
LogDiaWind("Client [{}] Rendering button_two option.", c->GetCleanName());
auto two_first_split = split_string(output, "button_two:");
if (!two_first_split.empty()) {
auto two_second_split = split_string(two_first_split[1], " ");
if (!two_second_split.empty()) {
button_two = two_second_split[0];
LogDiaWindDetail("Client [{}] Rendering button_two option button_two [{}]", c->GetCleanName(), button_two);
}
if (two_first_split[1].length() == 1) {
button_two = two_first_split[1];
LogDiaWindDetail(
"Client [{}] Rendering button_two (end) option button_two [{}]",
c->GetCleanName(),
button_two
);
}
find_replace(output, fmt::format("button_two:{}", button_two), "");
if (!button_two.empty()) {
button_two_name = button_two.c_str();
}
}
}
// bracket responses // bracket responses
std::vector<std::string> responses; std::vector<std::string> responses;
std::vector<std::string> bracket_responses; std::vector<std::string> bracket_responses;
@ -209,13 +300,25 @@ void DialogueWindow::Render(Client *c, std::string markdown)
} }
} }
// Placed here to allow silent message or other message to override default for custom values.
if (!button_one_name.empty() && !button_two_name.empty()) {
c->SetEntityVariable(
DIAWIND_RESPONSE_ONE_KEY.c_str(),
button_one_name.c_str()
);
c->SetEntityVariable(
DIAWIND_RESPONSE_TWO_KEY.c_str(),
button_two_name.c_str()
);
}
// handle silent prompts from the [> silent syntax // handle silent prompts from the [> silent syntax
std::string silent_message; std::string silent_message;
if (responses.empty() && markdown.find('[') != std::string::npos && markdown.find('>') != std::string::npos) { if (responses.empty() && markdown.find('[') != std::string::npos && markdown.find('>') != std::string::npos) {
silent_message = get_between(output, "[", ">"); silent_message = get_between(output, "[", ">");
// temporary and used during the response // temporary and used during the response
c->SetEntityVariable(DIAWIND_RESPONSE_KEY.c_str(), silent_message.c_str()); c->SetEntityVariable(DIAWIND_RESPONSE_ONE_KEY.c_str(), silent_message.c_str());
// pop the silent message off // pop the silent message off
find_replace(output, fmt::format("[{}>", silent_message), ""); find_replace(output, fmt::format("[{}>", silent_message), "");
@ -225,7 +328,7 @@ void DialogueWindow::Render(Client *c, std::string markdown)
silent_message = responses[0]; silent_message = responses[0];
// temporary and used during the response // temporary and used during the response
c->SetEntityVariable(DIAWIND_RESPONSE_KEY.c_str(), silent_message.c_str()); c->SetEntityVariable(DIAWIND_RESPONSE_ONE_KEY.c_str(), silent_message.c_str());
// pop the silent message off // pop the silent message off
find_replace(output, fmt::format("[{}]", silent_message), ""); find_replace(output, fmt::format("[{}]", silent_message), "");
@ -282,6 +385,17 @@ void DialogueWindow::Render(Client *c, std::string markdown)
); );
} }
if (!button_one_name.empty() && !button_two_name.empty()) {
click_response = fmt::format(
"<c \"#F07F00\">Click [{}] to respond with [{}]...<br>"
"Click [{}] to respond with [{}]...</c>",
button_one_name,
button_one_name,
button_two_name,
button_two_name
);
}
// post processing of color markdowns // post processing of color markdowns
// {spring_green_1} = <c "#5EFB6E"> // {spring_green_1} = <c "#5EFB6E">
if (markdown.find('{') != std::string::npos && markdown.find('}') != std::string::npos) { if (markdown.find('{') != std::string::npos && markdown.find('}') != std::string::npos) {
@ -325,8 +439,8 @@ void DialogueWindow::Render(Client *c, std::string markdown)
negative_id, negative_id,
window_type, window_type,
window_expire_seconds, window_expire_seconds,
button_name_0, button_one_name.c_str(),
button_name_1, button_two_name.c_str(),
sound_controls sound_controls
); );