[Quest API] Add Popup methods to Perl/Lua. (#2533)

* [Quest API] Add Popup methods to Perl/Lua.

# Perl
- Add `quest::popupcentermessage(message)` to Perl.
- Add `quest::popupcolormessage(color, message)` to Perl.
- Add `quest::popupindent()` to Perl.
- Add `quest::popuplink(link)` to Perl.
- Add `quest::popuplink(link, message)` to Perl.

# Lua
- Add `eq.popup(title, message)` to Lua.
- Add `eq.popup(title, message, popup_id)` to Lua.
- Add `eq.popup(title, message, popup_id, buttons)` to Lua.
- Add `eq.popup_center_message(message)` to Lua.
- Add `eq.popup_color_message(color, message)` to Lua.
- Add `eq.popup_indent()` to Lua.
- Add `eq.popup_link(link)` to Lua.
- Add `eq.popup_link(link, message)` to Lua.

# Notes
- Adds the Perl plugins like PWAutoCenter, PWIndent, and PWHyperlink.
- Parses out HTML `<>` tags automatically in `popupautocenter` to properly center stuff like colored messages. (Doesn't work with links)
- This lets Lua users have similar functionality to Perl users.

* Add tables and break.

* Add indent_count to indent method.

* Move to Dialogue Window.
This commit is contained in:
Kinglykrab
2022-11-14 14:05:24 -05:00
committed by GitHub
parent 31e5622dad
commit 9c967c24b8
4 changed files with 272 additions and 1 deletions
+126
View File
@@ -1,3 +1,5 @@
#include <regex>
#include "dialogue_window.h"
void DialogueWindow::Render(Client *c, std::string markdown)
@@ -503,3 +505,127 @@ void DialogueWindow::Render(Client *c, std::string markdown)
c->Message(Chat::White, Strings::Implode(" ", bracket_responses).c_str());
}
}
std::string DialogueWindow::Break(uint32 break_count)
{
if (!break_count) {
return std::string();
}
std::string break_message;
auto count = break_count;
while (count) {
break_message.append("<br>");
count--;
}
return break_message;
}
std::string DialogueWindow::CenterMessage(std::string message)
{
if (message.empty()) {
return std::string();
}
auto cleaned_message = message;
std::regex tags("<[^>]*>");
if (std::regex_search(cleaned_message, tags)) {
std::regex_replace(cleaned_message, tags, cleaned_message);
}
auto message_len = cleaned_message.length();
auto initial_index = (53 - (message_len * .80));
auto index = 0;
std::string buffer;
while (index < initial_index) {
buffer.append("&nbsp;");
index++;
}
return fmt::format("{} {}", buffer, message);
}
std::string DialogueWindow::ColorMessage(std::string color, std::string message)
{
if (message.empty()) {
return std::string();
}
if (!color.empty()) {
const auto &c = html_colors.find(color);
if (c != html_colors.end()) {
return fmt::format(
"<c \"{}\">{}</c>",
c->second,
message
);
}
}
return message;
}
std::string DialogueWindow::Indent(uint32 indent_count)
{
if (!indent_count) {
return std::string();
}
std::string indent_message;
auto count = indent_count;
while (count) {
indent_message.append("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
count--;
}
return indent_message;
}
std::string DialogueWindow::Link(std::string link, std::string message)
{
if (link.empty()) {
return std::string();
}
if (!link.empty()) {
return fmt::format(
"<a href=\"{}\">{}</a>",
link,
!message.empty() ? message : link
);
}
return message;
}
std::string DialogueWindow::Table(std::string message)
{
if (message.empty()) {
return std::string();
}
return fmt::format("<table>{}</table>", message);
}
std::string DialogueWindow::TableCell(std::string message)
{
if (message.empty()) {
return "<td></td>";
}
return fmt::format("<td>{}</td>", message);
}
std::string DialogueWindow::TableRow(std::string message)
{
if (message.empty()) {
return std::string();
}
return fmt::format("<tr>{}</tr>", message);
}