Skip to content

Commit

Permalink
Add mestipbox script command
Browse files Browse the repository at this point in the history
  • Loading branch information
guilherme-gm committed Jun 8, 2024
1 parent 524df5d commit 2ca5601
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doc/script_commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2729,6 +2729,22 @@ Parameters:
The height of the browser window (when using in-game browser).
When not provided (or -1), width/height is not specified.

---------------------------------------

*mestipbox("<label>", <tip_id>)

Generates and returns a <TIPBOX> tag. When presented in certain places (like with "mes" and "mesf"),
this will display a clickable text (<label>) which when clicked, opens the TipBox UI with the given <tip_id>.

If the current client doesn't support this feature, returns a simple string with "<label>"

Parameters:
- label: (string, required)
The visible and clickable text. (example: "Super Tip")

- tip_id: (int, required)
The tip ID (as set in TipBox lua file)
If 0, it shows a random tipbox

---------------------------------------
//=====================================
Expand Down
15 changes: 15 additions & 0 deletions npc/dev/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,19 @@ function script F_TestMesUrl_Dimensions {
return .@pass;
}

function script F_TestMesTipBox {
.@str$ = mestipbox("Some tip", 1);

.@pass = false;
if (PACKETVER < 20170712) {
.@pass = (.@str$ == "Some tip");
} else {
.@pass = (.@str$ == "<TIPBOX>Some tip<INFO>1</INFO></TIPBOX>");
}

return .@pass;
}

function script HerculesSelfTestHelper {
if (.once > 0)
return .errors;
Expand Down Expand Up @@ -1082,6 +1095,8 @@ function script HerculesSelfTestHelper {
callsub(OnCheck, "mesurl: basic usage", F_TestMesUrl_Basic(), true);
callsub(OnCheck, "mesurl: with dimensions", F_TestMesUrl_Dimensions(), true);

callsub(OnCheck, "mestipbox", F_TestMesTipBox(), true);

if (.errors) {
consolemes(CONSOLEMES_DEBUG, "Script engine self-test [ \033[0;31mFAILED\033[0m ]");
consolemes(CONSOLEMES_DEBUG, "**** The test was completed with " + .errors + " errors. ****");
Expand Down
28 changes: 28 additions & 0 deletions src/map/clif.c
Original file line number Diff line number Diff line change
Expand Up @@ -26207,6 +26207,33 @@ static void clif_format_url(StringBuf *buf, const char *label, const char *url,
#endif
}

/**
* Creates a "tipbox" tag (<TIPBOX>) string into buf based on the given parameters.
* The resulting format and feature support is client-specific.
*
* Clicking the text generated by this will either open the TipBox with <tip_id> being shown
* or just return the label (if not supported)
*
* @param buf buffer where the string will be written to
* @param label visible label
* @param tip_id Tip ID
*/
static void clif_format_tipbox(StringBuf *buf, const char *label, int tip_id)
{
nullpo_retv(buf);
nullpo_retv(label);

// Not completely sure on the date. This is the date when TipBox system was implemented.
#if PACKETVER >= 20170712
StrBuf->Printf(buf, "<TIPBOX>%s<INFO>%d</INFO></TIPBOX>", label, tip_id);
#else
// Unsupported feature, fallback to a basic text
StrBuf->Printf(buf, "%s", label);
#endif
}



/*==========================================
* Main client packet processing function
*------------------------------------------*/
Expand Down Expand Up @@ -27581,4 +27608,5 @@ void clif_defaults(void)
clif->format_itemlink = clif_format_itemlink;
clif->format_navigation = clif_format_navigation;
clif->format_url = clif_format_url;
clif->format_tipbox = clif_format_tipbox;
}
1 change: 1 addition & 0 deletions src/map/clif.h
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ struct clif_interface {
void (*format_itemlink) (struct StringBuf *buf, const struct item *it);
void (*format_navigation) (struct StringBuf *buf, const char *label, const char *mapname, int x, int y, enum navigation_mode mode, enum navigation_service services_flag, bool show_window, int monster_id);
void (*format_url) (struct StringBuf *buf, const char *label, const char *url, int width, int height);
void (*format_tipbox) (struct StringBuf *buf, const char *label, int tip_id);
/* auth */
void (*authok) (struct map_session_data *sd);
void (*auth_error) (int fd, int errorCode);
Expand Down
21 changes: 21 additions & 0 deletions src/map/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -28542,6 +28542,26 @@ static BUILDIN(mesurl)
return true;
}

/**
* create a <TIPBOX> tag
*
* mestipbox("<label>", <tip_id>)
*/
static BUILDIN(mestipbox)
{
const char *label = script_getstr(st, 2);
int tip_id = script_getnum(st, 3);

StringBuf buf;
StrBuf->Init(&buf);

clif->format_tipbox(&buf, label, tip_id);
script_pushstrcopy(st, StrBuf->Value(&buf));

StrBuf->Destroy(&buf);
return true;
}

/**
* Adds a built-in script function.
*
Expand Down Expand Up @@ -29420,6 +29440,7 @@ static void script_parse_builtin(void)
BUILDIN_DEF(setgoldpcmode, "i?"),

BUILDIN_DEF(mesurl, "ss??"),
BUILDIN_DEF(mestipbox, "si"),
};
int i, len = ARRAYLENGTH(BUILDIN);
RECREATE(script->buildin, char *, script->buildin_count + len); // Pre-alloc to speed up
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/HPMHooking/HPMHooking.Defs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,8 @@ typedef void (*HPMHOOK_pre_clif_format_navigation) (struct StringBuf **buf, cons
typedef void (*HPMHOOK_post_clif_format_navigation) (struct StringBuf *buf, const char *label, const char *mapname, int x, int y, enum navigation_mode mode, enum navigation_service services_flag, bool show_window, int monster_id);
typedef void (*HPMHOOK_pre_clif_format_url) (struct StringBuf **buf, const char **label, const char **url, int *width, int *height);
typedef void (*HPMHOOK_post_clif_format_url) (struct StringBuf *buf, const char *label, const char *url, int width, int height);
typedef void (*HPMHOOK_pre_clif_format_tipbox) (struct StringBuf **buf, const char **label, int *tip_id);
typedef void (*HPMHOOK_post_clif_format_tipbox) (struct StringBuf *buf, const char *label, int tip_id);
typedef void (*HPMHOOK_pre_clif_authok) (struct map_session_data **sd);
typedef void (*HPMHOOK_post_clif_authok) (struct map_session_data *sd);
typedef void (*HPMHOOK_pre_clif_auth_error) (int *fd, int *errorCode);
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@ struct {
struct HPMHookPoint *HP_clif_format_navigation_post;
struct HPMHookPoint *HP_clif_format_url_pre;
struct HPMHookPoint *HP_clif_format_url_post;
struct HPMHookPoint *HP_clif_format_tipbox_pre;
struct HPMHookPoint *HP_clif_format_tipbox_post;
struct HPMHookPoint *HP_clif_authok_pre;
struct HPMHookPoint *HP_clif_authok_post;
struct HPMHookPoint *HP_clif_auth_error_pre;
Expand Down Expand Up @@ -8281,6 +8283,8 @@ struct {
int HP_clif_format_navigation_post;
int HP_clif_format_url_pre;
int HP_clif_format_url_post;
int HP_clif_format_tipbox_pre;
int HP_clif_format_tipbox_post;
int HP_clif_authok_pre;
int HP_clif_authok_post;
int HP_clif_auth_error_pre;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(clif->format_itemlink, HP_clif_format_itemlink) },
{ HP_POP(clif->format_navigation, HP_clif_format_navigation) },
{ HP_POP(clif->format_url, HP_clif_format_url) },
{ HP_POP(clif->format_tipbox, HP_clif_format_tipbox) },
{ HP_POP(clif->authok, HP_clif_authok) },
{ HP_POP(clif->auth_error, HP_clif_auth_error) },
{ HP_POP(clif->authrefuse, HP_clif_authrefuse) },
Expand Down
26 changes: 26 additions & 0 deletions src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9085,6 +9085,32 @@ void HP_clif_format_url(struct StringBuf *buf, const char *label, const char *ur
}
return;
}
void HP_clif_format_tipbox(struct StringBuf *buf, const char *label, int tip_id) {
int hIndex = 0;
if (HPMHooks.count.HP_clif_format_tipbox_pre > 0) {
void (*preHookFunc) (struct StringBuf **buf, const char **label, int *tip_id);
*HPMforce_return = false;
for (hIndex = 0; hIndex < HPMHooks.count.HP_clif_format_tipbox_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_clif_format_tipbox_pre[hIndex].func;
preHookFunc(&buf, &label, &tip_id);
}
if (*HPMforce_return) {
*HPMforce_return = false;
return;
}
}
{
HPMHooks.source.clif.format_tipbox(buf, label, tip_id);
}
if (HPMHooks.count.HP_clif_format_tipbox_post > 0) {
void (*postHookFunc) (struct StringBuf *buf, const char *label, int tip_id);
for (hIndex = 0; hIndex < HPMHooks.count.HP_clif_format_tipbox_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_clif_format_tipbox_post[hIndex].func;
postHookFunc(buf, label, tip_id);
}
}
return;
}
void HP_clif_authok(struct map_session_data *sd) {
int hIndex = 0;
if (HPMHooks.count.HP_clif_authok_pre > 0) {
Expand Down

0 comments on commit 2ca5601

Please sign in to comment.