Skip to content

Commit

Permalink
Add support for script without const-correctness fixes
Browse files Browse the repository at this point in the history
Add ability to disable tags support with MDIALOG_DISABLE_TAGS definition
  • Loading branch information
ziggi committed Oct 7, 2018
1 parent 4e5ae6d commit b71a3c8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Tag | Description

![tags example](https://user-images.githubusercontent.com/1020099/30522188-aac33382-9bd4-11e7-9d78-92b240309931.png)

You also can disable tags with definition of `MDIALOG_DISABLE_TAGS` before `mdialog` including. This can be useful if you are not interested in this feature and wants a little bit more performance.

# Usage
You can use `DialogCreate:` and `DialogResponse:` prefixes:
```Pawn
Expand Down
44 changes: 39 additions & 5 deletions mdialog.inc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@
#endif
#endif

#if !defined FIX_const
#define FIX_const 0
#define MDIALOG_FIX_CLEAR
#endif

#if !FIX_const
native MDialog_ShowPlayerDialog(playerid, dialogid, style, const caption[], const info[], const button1[], const button2[]) = ShowPlayerDialog;

#if defined _ALS_ShowPlayerDialog
#undef ShowPlayerDialog
#else
#define _ALS_ShowPlayerDialog
#endif

#define ShowPlayerDialog MDialog_ShowPlayerDialog

#if defined MDIALOG_FIX_CLEAR
#undef MDIALOG_FIX_CLEAR
#undef FIX_const
#endif
#endif

#if !defined isnull
#define isnull(%1) \
((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
Expand Down Expand Up @@ -94,6 +116,7 @@ enum E_MDIALOG_TAG {
Vars
*/

#if !defined MDIALOG_DISABLE_TAGS
static
Float:gCharSize[256] = {
-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0,
Expand Down Expand Up @@ -327,10 +350,12 @@ static
gTag[E_MDIALOG_TAG][] = {
"\\c",
"\\r"
};
},
gTagLength[E_MDIALOG_TAG];

#endif

static
gTagLength[E_MDIALOG_TAG],
bool:gIsDialogOpen[MAX_PLAYERS char],
gDialogFunction[MAX_PLAYERS][MAX_FUNCTION_NAME char];

Expand All @@ -340,9 +365,11 @@ static

public OnGameModeInit()
{
#if !defined MDIALOG_DISABLE_TAGS
for (new tag = 0; tag < sizeof(gTag); tag++) {
gTagLength[E_MDIALOG_TAG:tag] = strlen(gTag[E_MDIALOG_TAG:tag]);
}
#endif

#if defined MDialog_OnGameModeInit
return MDialog_OnGameModeInit();
Expand Down Expand Up @@ -373,9 +400,13 @@ static stock _Dialog_Open(playerid, const function[], style, const caption[], co

switch (style) {
case DIALOG_STYLE_MSGBOX, DIALOG_STYLE_INPUT, DIALOG_STYLE_PASSWORD: {
static info_result[MDIALOG_MAX_INFO_SIZE];
_MDialog_ProcessTags(info, info_result);
return ShowPlayerDialog(playerid, MDIALOG_DIALOG_ID, style, caption, info_result, button1, button2);
#if defined MDIALOG_DISABLE_TAGS
return ShowPlayerDialog(playerid, MDIALOG_DIALOG_ID, style, caption, info, button1, button2);
#else
static info_result[MDIALOG_MAX_INFO_SIZE];
_MDialog_ProcessTags(info, info_result);
return ShowPlayerDialog(playerid, MDIALOG_DIALOG_ID, style, caption, info_result, button1, button2);
#endif
}
}

Expand Down Expand Up @@ -578,6 +609,7 @@ public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
/*
_MDialog_ProcessTags
*/
#if !defined MDIALOG_DISABLE_TAGS

static stock _MDialog_ProcessTags(const info[], result_info[], const size = sizeof(result_info))
{
Expand Down Expand Up @@ -730,6 +762,8 @@ static stock _MDialog_ProcessTags(const info[], result_info[], const size = size
}
}

#endif

/*
Other functions
*/
Expand Down

0 comments on commit b71a3c8

Please sign in to comment.