Skip to content

Commit

Permalink
Add script command for set text align in npc dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
4144 committed Nov 16, 2021
1 parent f2c77fa commit c29b3c3
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 0 deletions.
14 changes: 14 additions & 0 deletions doc/script_commands.txt
Expand Up @@ -10878,3 +10878,17 @@ of equipment slots see getequipid().
Gets the grade level of an equipment.

---------------------------------------
*setdialogalign(<align>);

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
74 changes: 74 additions & 0 deletions 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;
}
1 change: 1 addition & 0 deletions npc/scripts_custom.conf
Expand Up @@ -53,6 +53,7 @@
//"npc/custom/bartershop.txt",
//"npc/custom/expandedbartershop.txt",
//"npc/custom/zeroui.txt",
//"npc/custom/dialogalign.txt",

//================= Other Scripts =========================================
// -- MVP Arena
Expand Down
16 changes: 16 additions & 0 deletions src/map/clif.c
Expand Up @@ -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
*------------------------------------------*/
Expand Down Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions src/map/clif.h
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/map/map.h
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/map/packets_struct.h
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/map/script.c
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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*"),
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c29b3c3

Please sign in to comment.