From eb308dcad295faf74fe63f55c69a389c00acfb0b Mon Sep 17 00:00:00 2001 From: Pokye <98105181+Pokye@users.noreply.github.com> Date: Mon, 26 Feb 2024 18:08:52 -0300 Subject: [PATCH] Implemented Dialog Types (#8110) Fixes #8109 Co-authored-by: Aleos Co-authored-by: Lemongrass3110 --- doc/script_commands.txt | 34 +++++++++++++ src/map/clif.cpp | 51 +++++++++++++++++++ src/map/clif.hpp | 5 ++ src/map/map.hpp | 12 +++++ src/map/script.cpp | 105 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 207 insertions(+) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 1ea3f1ec64..911015cf27 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -11412,3 +11412,37 @@ Example: autoloot(10000); // 100.00% --------------------------------------- + +*setdialogalign(); + +Set vertical or horizontal align in NPC dialog. +Valid aligns: +- horizontal align: + DIALOG_ALIGN_LEFT + DIALOG_ALIGN_CENTER + DIALOG_ALIGN_RIGHT + +- vertical align: + DIALOG_ALIGN_TOP + DIALOG_ALIGN_MIDDLE + DIALOG_ALIGN_BOTTOM + +--------------------------------------- + +*setdialogsize(, ) + +Set size for NPC dialog in pixels. + +--------------------------------------- + +*setdialogpos(, ) + +Set position for NPC dialog in pixels. + +--------------------------------------- + +*setdialogpospercent(, ) + +Set position for NPC dialog in screen size percent. + +--------------------------------------- diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 103a6fa4bf..da3cb98003 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -25187,6 +25187,57 @@ void clif_parse_reset_skill( int fd, map_session_data* sd ){ #endif } +void clif_set_dialog_align(map_session_data& sd, int npcid, e_say_dialog_align align) +{ +#if PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024 + PACKET_ZC_DIALOG_TEXT_ALIGN p = {}; + + p.PacketType = HEADER_ZC_DIALOG_TEXT_ALIGN; + p.align = align; + + clif_send( &p, sizeof( p ), &sd.bl, SELF ); +#endif // PACKETVER_MAIN_NUM >= 20210203 || PACKETVER_RE_NUM >= 20211103 || PACKETVER_ZERO_NUM >= 20221024 +} + +void clif_set_npc_window_size(map_session_data& sd, int width, int height) +{ +#if PACKETVER_MAIN_NUM >= 20220504 + PACKET_ZC_DIALOG_WINDOW_SIZE p = {}; + + p.PacketType = HEADER_ZC_DIALOG_WINDOW_SIZE; + p.width = width; + p.height = height; + + clif_send( &p, sizeof( p ), &sd.bl, SELF ); +#endif // PACKETVER_MAIN_NUM >= 20220504 +} + +void clif_set_npc_window_pos(map_session_data& sd, int x, int y) +{ +#if PACKETVER_MAIN_NUM >= 20220504 + PACKET_ZC_DIALOG_WINDOW_POS p = {}; + + p.PacketType = HEADER_ZC_DIALOG_WINDOW_POS; + p.x = x; + p.y = y; + + clif_send( &p, sizeof( p ), &sd.bl, SELF ); +#endif // PACKETVER_MAIN_NUM >= 20220504 +} + +void clif_set_npc_window_pos_percent(map_session_data& sd, int x, int y) +{ +#if PACKETVER_MAIN_NUM >= 20220504 + PACKET_ZC_DIALOG_WINDOW_POS2 p = {}; + + p.PacketType = HEADER_ZC_DIALOG_WINDOW_POS2; + p.x = x; + p.y = y; + + clif_send( &p, sizeof( p ), &sd.bl, SELF ); +#endif // PACKETVER_MAIN_NUM >= 20220504 +} + /*========================================== * Main client packet processing function *------------------------------------------*/ diff --git a/src/map/clif.hpp b/src/map/clif.hpp index 9155b92428..b94acdca55 100644 --- a/src/map/clif.hpp +++ b/src/map/clif.hpp @@ -1254,4 +1254,9 @@ void clif_macro_reporter_status(map_session_data &sd, e_macro_report_status styp void clif_dynamicnpc_result( map_session_data& sd, e_dynamicnpc_result result ); +void clif_set_dialog_align(map_session_data& sd, int npcid, e_say_dialog_align align); +void clif_set_npc_window_size(map_session_data& sd, int width, int height); +void clif_set_npc_window_pos(map_session_data& sd, int x, int y); +void clif_set_npc_window_pos_percent(map_session_data& sd, int x, int y); + #endif /* CLIF_HPP */ diff --git a/src/map/map.hpp b/src/map/map.hpp index 13f1f29527..cea7c8b463 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -861,6 +861,18 @@ struct map_data_other_server { uint16 port; }; +/** + * align for packet ZC_SAY_DIALOG_ALIGN + **/ +enum e_say_dialog_align : uint8 { + 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 inter_conf { uint32 start_status_points; bool emblem_woe_change; diff --git a/src/map/script.cpp b/src/map/script.cpp index bb817be7a6..dd27f28d97 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -27123,6 +27123,106 @@ BUILDIN_FUNC(opentips){ #endif } +BUILDIN_FUNC(setdialogalign){ + map_session_data *sd; + + if ( !script_rid2sd(sd) ) { + return SCRIPT_CMD_FAILURE; + } + + int32 align = script_getnum( st, 2 ); + + if( align < DIALOG_ALIGN_LEFT || align > DIALOG_ALIGN_BOTTOM ){ + ShowError( "buildin_setdialogalign: Unknown align value %d\n", align ); + return SCRIPT_CMD_FAILURE; + } + + clif_set_dialog_align( *sd, st->oid, static_cast( align ) ); + + return SCRIPT_CMD_SUCCESS; +} + +BUILDIN_FUNC(setdialogsize){ + map_session_data *sd; + + if ( !script_rid2sd(sd) ) { + script_pushint(st, 0); + return SCRIPT_CMD_FAILURE; + } + + int32 x = script_getnum( st, 2 ); + + if( x < 0 || x > INT16_MAX ){ + ShowError( "buildin_setdialogsize: x size %d is out of range [0,%d]\n", x, INT16_MAX ); + return SCRIPT_CMD_FAILURE; + } + + int32 y = script_getnum( st, 3 ); + + if( y < 0 || y > INT16_MAX ){ + ShowError( "buildin_setdialogsize: y size %d is out of range [0,%d]\n", y, INT16_MAX ); + return SCRIPT_CMD_FAILURE; + } + + clif_set_npc_window_size( *sd, x, y ); + + return SCRIPT_CMD_SUCCESS; +} + +BUILDIN_FUNC(setdialogpos){ + map_session_data *sd; + + if ( !script_rid2sd(sd) ) { + script_pushint(st, 0); + return SCRIPT_CMD_FAILURE; + } + + int32 x = script_getnum( st, 2 ); + + if( x < 0 || x > INT16_MAX ){ + ShowError( "buildin_setdialogpos: x position %d is out of range [0,%d]\n", x, INT16_MAX ); + return SCRIPT_CMD_FAILURE; + } + + int32 y = script_getnum( st, 3 ); + + if( y < 0 || y > INT16_MAX ){ + ShowError( "buildin_setdialogpos: y position %d is out of range [0,%d]\n", y, INT16_MAX ); + return SCRIPT_CMD_FAILURE; + } + + clif_set_npc_window_pos( *sd, x, y ); + + return SCRIPT_CMD_SUCCESS; +} + +BUILDIN_FUNC(setdialogpospercent){ + map_session_data *sd; + + if ( !script_rid2sd(sd) ) { + script_pushint(st, 0); + return SCRIPT_CMD_FAILURE; + } + + int32 x = script_getnum( st, 2 ); + + if( x < 0 || x > 100 ){ + ShowError( "buildin_setdialogpospercent: x rate %d is out of range [0,100]\n", x ); + return SCRIPT_CMD_FAILURE; + } + + int32 y = script_getnum( st, 3 ); + + if( y < 0 || y > 100 ){ + ShowError( "buildin_setdialogpospercent: y rate %d is out of range [0,100]\n", y ); + return SCRIPT_CMD_FAILURE; + } + + clif_set_npc_window_pos_percent( *sd, x, y ); + + return SCRIPT_CMD_SUCCESS; +} + #include // declarations that were supposed to be exported from npc_chat.cpp @@ -27883,6 +27983,11 @@ struct script_function buildin_func[] = { BUILDIN_DEF(autoloot,"??"), BUILDIN_DEF(opentips, "i?"), + BUILDIN_DEF(setdialogalign, "i"), + BUILDIN_DEF(setdialogsize, "ii"), + BUILDIN_DEF(setdialogpos, "ii"), + BUILDIN_DEF(setdialogpospercent, "ii"), + #include {NULL,NULL,NULL},