mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-19 13:28:25 +00:00
[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:
@@ -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(" ");
|
||||
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(" ");
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user