[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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 272 additions and 1 deletions

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);
}

View File

@ -388,6 +388,14 @@ const std::map<std::string, int> animations = {
class DialogueWindow {
public:
static void Render(Client *c, std::string markdown);
static std::string Break(uint32 break_count = 1);
static std::string CenterMessage(std::string message);
static std::string ColorMessage(std::string color, std::string message);
static std::string Indent(uint32 indent_count = 1);
static std::string Link(std::string link, std::string message = std::string());
static std::string Table(std::string message);
static std::string TableCell(std::string message = std::string());
static std::string TableRow(std::string message);
};

View File

@ -26,6 +26,7 @@
#include "../common/misc_functions.h"
#include "../common/eqemu_logsys.h"
#include "dialogue_window.h"
#include "embperl.h"
#include "embxs.h"
#include "entity.h"
@ -3748,6 +3749,54 @@ std::string Perl__getaaname(int aa_id)
return zone->GetAAName(aa_id);
}
std::string Perl__popupbreak() {
return DialogueWindow::Break();
}
std::string Perl__popupbreak(uint32 break_count) {
return DialogueWindow::Break(break_count);
}
std::string Perl__popupcentermessage(std::string message) {
return DialogueWindow::CenterMessage(message);
}
std::string Perl__popupcolormessage(std::string color, std::string message) {
return DialogueWindow::ColorMessage(color, message);
}
std::string Perl__popupindent() {
return DialogueWindow::Indent();
}
std::string Perl__popupindent(uint32 indent_count) {
return DialogueWindow::Indent(indent_count);
}
std::string Perl__popuplink(std::string link) {
return DialogueWindow::Link(link);
}
std::string Perl__popuplink(std::string link, std::string message) {
return DialogueWindow::Link(link, message);
}
std::string Perl__popuptable(std::string message) {
return DialogueWindow::Table(message);
}
std::string Perl__popuptablecell() {
return DialogueWindow::TableCell();
}
std::string Perl__popuptablecell(std::string message) {
return DialogueWindow::TableCell(message);
}
std::string Perl__popuptablerow(std::string message) {
return DialogueWindow::TableRow(message);
}
void perl_register_quest()
{
perl::interpreter perl(PERL_GET_THX);
@ -4220,6 +4269,18 @@ void perl_register_quest()
package.add("popup", (void(*)(const char*, const char*, int))&Perl__popup);
package.add("popup", (void(*)(const char*, const char*, int, int))&Perl__popup);
package.add("popup", (void(*)(const char*, const char*, int, int, int))&Perl__popup);
package.add("popupbreak", (std::string(*)())&Perl__popupbreak);
package.add("popupbreak", (std::string(*)(uint32))&Perl__popupbreak);
package.add("popupcentermessage", &Perl__popupcentermessage);
package.add("popupcolormessage", &Perl__popupcolormessage);
package.add("popupindent", (std::string(*)())&Perl__popupindent);
package.add("popupindent", (std::string(*)(uint32))&Perl__popupindent);
package.add("popuplink", (std::string(*)(std::string))&Perl__popuplink);
package.add("popuplink", (std::string(*)(std::string, std::string))&Perl__popuplink);
package.add("popuptable", &Perl__popuptable);
package.add("popuptablecell", (std::string(*)())&Perl__popuptablecell);
package.add("popuptablecell", (std::string(*)(std::string))&Perl__popuptablecell);
package.add("popuptablerow", &Perl__popuptablerow);
package.add("processmobswhilezoneempty", &Perl__processmobswhilezoneempty);
package.add("pvp", &Perl__pvp);
package.add("qs_player_event", &Perl__qs_player_event);

View File

@ -27,6 +27,7 @@
#include "lua_encounter.h"
#include "data_bucket.h"
#include "expedition.h"
#include "dialogue_window.h"
struct Events { };
struct Factions { };
@ -772,6 +773,18 @@ void lua_end_dz_task(bool send_fail) {
quest_manager.EndCurrentDzTask(send_fail);
}
void lua_popup(const char *title, const char *text) {
quest_manager.popup(title, text, 0, 0, 0);
}
void lua_popup(const char *title, const char *text, uint32 id) {
quest_manager.popup(title, text, id, 0, 0);
}
void lua_popup(const char *title, const char *text, uint32 id, uint32 buttons) {
quest_manager.popup(title, text, id, buttons, 0);
}
void lua_popup(const char *title, const char *text, uint32 id, uint32 buttons, uint32 duration) {
quest_manager.popup(title, text, id, buttons, duration);
}
@ -3464,6 +3477,54 @@ std::string lua_get_aa_name(int aa_id) {
return zone->GetAAName(aa_id);
}
std::string lua_popup_break() {
return DialogueWindow::Break();
}
std::string lua_popup_break(uint32 break_count) {
return DialogueWindow::Break(break_count);
}
std::string lua_popup_center_message(std::string message) {
return DialogueWindow::CenterMessage(message);
}
std::string lua_popup_color_message(std::string color, std::string message) {
return DialogueWindow::ColorMessage(color, message);
}
std::string lua_popup_indent() {
return DialogueWindow::Indent();
}
std::string lua_popup_indent(uint32 indent_count) {
return DialogueWindow::Indent(indent_count);
}
std::string lua_popup_link(std::string link) {
return DialogueWindow::Link(link);
}
std::string lua_popup_link(std::string link, std::string message) {
return DialogueWindow::Link(link, message);
}
std::string lua_popup_table(std::string message) {
return DialogueWindow::Table(message);
}
std::string lua_popup_table_cell() {
return DialogueWindow::TableCell();
}
std::string lua_popup_table_cell(std::string message) {
return DialogueWindow::TableCell(message);
}
std::string lua_popup_table_row(std::string message) {
return DialogueWindow::TableRow(message);
}
#define LuaCreateNPCParse(name, c_type, default_value) do { \
cur = table[#name]; \
if(luabind::type(cur) != LUA_TNIL) { \
@ -3774,7 +3835,6 @@ luabind::scope lua_register_general() {
luabind::def("get_dz_task_id", &lua_get_dz_task_id),
luabind::def("end_dz_task", (void(*)())&lua_end_dz_task),
luabind::def("end_dz_task", (void(*)(bool))&lua_end_dz_task),
luabind::def("popup", &lua_popup),
luabind::def("clear_spawn_timers", &lua_clear_spawn_timers),
luabind::def("zone_emote", &lua_zone_emote),
luabind::def("world_emote", &lua_world_emote),
@ -3934,6 +3994,22 @@ luabind::scope lua_register_general() {
luabind::def("is_raining", &lua_is_raining),
luabind::def("is_snowing", &lua_is_snowing),
luabind::def("get_aa_name", &lua_get_aa_name),
luabind::def("popup", (void(*)(const char*,const char*))&lua_popup),
luabind::def("popup", (void(*)(const char*,const char*,uint32))&lua_popup),
luabind::def("popup", (void(*)(const char*,const char*,uint32,uint32))&lua_popup),
luabind::def("popup", (void(*)(const char*,const char*,uint32,uint32,uint32))&lua_popup),
luabind::def("popup_break", (std::string(*)(void))&lua_popup_break),
luabind::def("popup_break", (std::string(*)(uint32))&lua_popup_break),
luabind::def("popup_center_message", &lua_popup_center_message),
luabind::def("popup_color_message", &lua_popup_color_message),
luabind::def("popup_indent", (std::string(*)(void))&lua_popup_indent),
luabind::def("popup_indent", (std::string(*)(uint32))&lua_popup_indent),
luabind::def("popup_link", (std::string(*)(std::string))&lua_popup_link),
luabind::def("popup_link", (std::string(*)(std::string,std::string))&lua_popup_link),
luabind::def("popup_table", &lua_popup_table),
luabind::def("popup_table_cell", (std::string(*)(void))&lua_popup_table_cell),
luabind::def("popup_table_cell", (std::string(*)(std::string))&lua_popup_table_cell),
luabind::def("popup_table_row", &lua_popup_table_row),
/*
Cross Zone