From c29b3c3922cbe145fd11b67d11b68c71f672d9b6 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 16 Nov 2021 19:58:24 +0300 Subject: [PATCH] Add script command for set text align in npc dialogs --- doc/script_commands.txt | 14 ++++++++ npc/custom/dialogalign.txt | 74 ++++++++++++++++++++++++++++++++++++++ npc/scripts_custom.conf | 1 + src/map/clif.c | 16 +++++++++ src/map/clif.h | 2 ++ src/map/map.h | 12 +++++++ src/map/packets_struct.h | 9 +++++ src/map/script.c | 21 +++++++++++ 8 files changed, 149 insertions(+) create mode 100644 npc/custom/dialogalign.txt diff --git a/doc/script_commands.txt b/doc/script_commands.txt index c1f42924b79..c21a76133d3 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -10878,3 +10878,17 @@ of equipment slots see getequipid(). Gets the grade level of an equipment. --------------------------------------- +*setdialogalign(); + +Set vertical or horizontal align in npc dialog. +Valid aligns: +horizontal align: + DIALOG_ALIGN_LEFT + DIALOG_ALIGN_RIGHT + DIALOG_ALIGN_CENTER +vertical align: + DIALOG_ALIGN_TOP + DIALOG_ALIGN_MIDDLE + DIALOG_ALIGN_BOTTOM + +Works from clients: main 20210203, re 20211103 diff --git a/npc/custom/dialogalign.txt b/npc/custom/dialogalign.txt new file mode 100644 index 00000000000..51432f69124 --- /dev/null +++ b/npc/custom/dialogalign.txt @@ -0,0 +1,74 @@ +//===== Hercules Script ====================================== +//= Dialog text align demo +//===== By: ================================================== +//= 4144 +//===== Current Version: ===================================== +//= 1.0 +//===== Description: ========================================= +//= Dialog align demo in prontera. +//============================================================ + +prontera,162,284,4 script Align demo#prt 4_M_KID1,{ + setdialogalign(DIALOG_ALIGN_LEFT); + mes("Align left"); + next; + setdialogalign(DIALOG_ALIGN_RIGHT); + mes("Align right"); + next; + setdialogalign(DIALOG_ALIGN_CENTER); + mes("Align center"); + next; + // reset horizontal align + setdialogalign(DIALOG_ALIGN_LEFT); + + setdialogalign(DIALOG_ALIGN_TOP); + mes("Align top"); + next; + setdialogalign(DIALOG_ALIGN_MIDDLE); + mes("Align middle"); + next; + setdialogalign(DIALOG_ALIGN_BOTTOM); + mes("Align bottom"); + next; + + setdialogalign(DIALOG_ALIGN_LEFT); + setdialogalign(DIALOG_ALIGN_TOP); + mes("Align left + top"); + next; + setdialogalign(DIALOG_ALIGN_LEFT); + setdialogalign(DIALOG_ALIGN_MIDDLE); + mes("Align left + middle"); + next; + setdialogalign(DIALOG_ALIGN_LEFT); + setdialogalign(DIALOG_ALIGN_BOTTOM); + mes("Align left + bottom"); + next; + + setdialogalign(DIALOG_ALIGN_RIGHT); + setdialogalign(DIALOG_ALIGN_TOP); + mes("Align right + top"); + next; + setdialogalign(DIALOG_ALIGN_RIGHT); + setdialogalign(DIALOG_ALIGN_MIDDLE); + mes("Align right + middle"); + next; + setdialogalign(DIALOG_ALIGN_RIGHT); + setdialogalign(DIALOG_ALIGN_BOTTOM); + mes("Align right + bottom"); + next; + + setdialogalign(DIALOG_ALIGN_CENTER); + setdialogalign(DIALOG_ALIGN_TOP); + mes("Align center + top"); + next; + setdialogalign(DIALOG_ALIGN_CENTER); + setdialogalign(DIALOG_ALIGN_MIDDLE); + mes("Align center + middle"); + next; + setdialogalign(DIALOG_ALIGN_CENTER); + setdialogalign(DIALOG_ALIGN_BOTTOM); + mes("Align center + bottom"); + next; + + close; +} diff --git a/npc/scripts_custom.conf b/npc/scripts_custom.conf index 1218839805c..209784f67f9 100644 --- a/npc/scripts_custom.conf +++ b/npc/scripts_custom.conf @@ -53,6 +53,7 @@ //"npc/custom/bartershop.txt", //"npc/custom/expandedbartershop.txt", //"npc/custom/zeroui.txt", +//"npc/custom/dialogalign.txt", //================= Other Scripts ========================================= // -- MVP Arena diff --git a/src/map/clif.c b/src/map/clif.c index 7ae1fffe103..e842fec7586 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -25135,6 +25135,20 @@ static void clif_macro_reporter_status(struct map_session_data *sd, enum macro_r #endif } +static void clif_sayDialogAlign(struct map_session_data *sd, int npcid, enum say_dialog_align align) +{ +#if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 + nullpo_retv(sd); + + const int fd = sd->fd; + WFIFOHEAD(fd, sizeof(struct PACKET_ZC_SAY_DIALOG_ALIGN)); + struct PACKET_ZC_SAY_DIALOG_ALIGN *p = WFIFOP(fd, 0); + p->PacketType = HEADER_ZC_SAY_DIALOG_ALIGN; + p->align = align; + WFIFOSET(fd, sizeof(struct PACKET_ZC_SAY_DIALOG_ALIGN)); +#endif // PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 +} + /*========================================== * Main client packet processing function *------------------------------------------*/ @@ -26418,4 +26432,6 @@ void clif_defaults(void) clif->pMacroReporterAck = clif_parse_macro_reporter_ack; clif->macro_reporter_select = clif_macro_reporter_select; clif->macro_reporter_status = clif_macro_reporter_status; + + clif->sayDialogAlign = clif_sayDialogAlign; } diff --git a/src/map/clif.h b/src/map/clif.h index 14cd25c0d5f..aa4c30466af 100644 --- a/src/map/clif.h +++ b/src/map/clif.h @@ -1787,6 +1787,8 @@ struct clif_interface { void (*pMacroReporterAck) (int fd, struct map_session_data *sd); void (*macro_reporter_select) (struct map_session_data *sd, const struct macroaidlist *aid_list); void (*macro_reporter_status) (struct map_session_data *sd, enum macro_report_status stype); + + void (*sayDialogAlign) (struct map_session_data *sd, int npcid, enum say_dialog_align align); }; #ifdef HERCULES_CORE diff --git a/src/map/map.h b/src/map/map.h index 3212b100384..8db822db9b3 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -910,6 +910,18 @@ enum map_zone_merge_type { MZMT_NEVERMERGE, ///< Cannot merge with any zones. }; +/** + * align for packet ZC_SAY_DIALOG_ALIGN + **/ +enum say_dialog_align { + DIALOG_ALIGN_LEFT = 0, + DIALOG_ALIGN_RIGHT = 1, + DIALOG_ALIGN_CENTER = 2, + DIALOG_ALIGN_TOP = 3, + DIALOG_ALIGN_MIDDLE = 4, + DIALOG_ALIGN_BOTTOM = 5 +}; + struct map_zone_data { char name[MAP_ZONE_NAME_LENGTH];/* 20'd */ enum map_zone_merge_type merge_type; diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h index edd41c466dc..35544ebc813 100644 --- a/src/map/packets_struct.h +++ b/src/map/packets_struct.h @@ -5175,6 +5175,15 @@ struct PACKET_CZ_CHOOSE_MENU_ZERO { DEFINE_PACKET_HEADER(CZ_CHOOSE_MENU_ZERO, 0x0ba8); #endif // PACKETVER_MAIN_NUM >= 20210317 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20210317 +#if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 +struct PACKET_ZC_SAY_DIALOG_ALIGN { + int16 PacketType; + uint8 align; +} __attribute__((packed)); +DEFINE_PACKET_HEADER(ZC_SAY_DIALOG_ALIGN, 0x0ba1); +#endif // PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 + + #if !defined(sun) && (!defined(__NETBSD__) || __NetBSD_Version__ >= 600000000) // NetBSD 5 and Solaris don't like pragma pack but accept the packed attribute #pragma pack(pop) #endif // not NetBSD < 6 / Solaris diff --git a/src/map/script.c b/src/map/script.c index 0ae0862f294..a357e799111 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -27564,6 +27564,18 @@ static BUILDIN(getequipgrade) return true; } +static BUILDIN(setdialogalign) +{ + struct map_session_data *sd = script->rid2sd(st); + + if (sd == NULL) + return true; + + clif->sayDialogAlign(sd, st->oid, script_getnum(st, 2)); + + return true; +} + /** * Adds a built-in script function. * @@ -27807,6 +27819,7 @@ static void script_parse_builtin(void) BUILDIN_DEF2(select, "prompt", "s*"), BUILDIN_DEF2(select, "zselect", "s*"), BUILDIN_DEF2(select, "zprompt", "s*"), + BUILDIN_DEF(setdialogalign,"i"), // BUILDIN_DEF(goto,"l"), BUILDIN_DEF(callsub,"l*"), @@ -29298,6 +29311,14 @@ static void script_hardcoded_constants(void) script->set_constant("MOBG_POUCH", MOBG_POUCH, false, false); script->set_constant("MOBG_CLASS_CHANGE", MOBG_CLASS_CHANGE, false, false); + script->constdb_comment("Npc dialog text align"); + script->set_constant("DIALOG_ALIGN_LEFT", DIALOG_ALIGN_LEFT, false, false); + script->set_constant("DIALOG_ALIGN_RIGHT", DIALOG_ALIGN_RIGHT, false, false); + script->set_constant("DIALOG_ALIGN_CENTER", DIALOG_ALIGN_CENTER, false, false); + script->set_constant("DIALOG_ALIGN_TOP", DIALOG_ALIGN_TOP, false, false); + script->set_constant("DIALOG_ALIGN_MIDDLE", DIALOG_ALIGN_MIDDLE, false, false); + script->set_constant("DIALOG_ALIGN_BOTTOM", DIALOG_ALIGN_BOTTOM, false, false); + script->constdb_comment("Renewal"); #ifdef RENEWAL script->set_constant("RENEWAL", 1, false, false);