Guest User

Dialog inc

a guest
Jun 10th, 2015
588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.79 KB | None | 0 0
  1. /*
  2. Dialogs Include (dialogs.inc)
  3. * New dialog functions and NEW Model-Preview dialog, now within SAMP "ShowPlayerDialog", a new style!
  4. * Just add a new style: DIALOG_STYLE_PREVMODEL
  5.  
  6. Author: (creator)
  7. * Gammix
  8. * Y_Less - ceildiv macro, and connection check suggest
  9.  
  10. (c) Copyright 2015
  11. * This file is provided as is (no warranties).
  12. */
  13.  
  14. /*
  15. FUNCTIONS:
  16. native ShowPlayerDialog(playerid, dialogid, style, caption[], info[], button1[], button2[] = "", infosize = sizeof(info));
  17. native HidePlayerDialog(playerid);
  18. native GetPlayerDialogID(playerid);
  19. native GetPlayerDialogStyle(playerid);
  20. native SetupPrevModelDialog(Float:mx, Float:my, Float:mz, Float:mzoom = 1.0, mbgcolor = 0x4A5A6BFF, hovercolor = 0x8B0000FF, selectcolor = 0x8B0000FF);
  21.  
  22. CALLBACKS:
  23. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  24. */
  25.  
  26. #if !defined INVALID_DIALOG_ID
  27. #define INVALID_DIALOG_ID -1//make sure the INVALID_DIALOG_ID is '-1' only!
  28. #endif
  29.  
  30. #define MAX_DIALOG_MODELS 400//maximum number of listitems a PREVIEW MODEL Dialog can have
  31.  
  32. #define DIALOG_STYLE_PREVMODEL 10//the new dialog style id, you may change if not suitable or for future usage! This may effect HidePlayerDialog.
  33.  
  34. #define MODELS_PER_LINE (6)//Max models that can be displayed in a line
  35.  
  36. #define MODELS_PER_PAGE ((MODELS_PER_LINE) * 3)//Max models that can be displayed in a page
  37.  
  38. //Dialog Textdraws
  39. static PlayerText:gPlayerButtonsTD[MAX_PLAYERS][2];
  40. static PlayerText:gPlayerHeaderTD[MAX_PLAYERS];
  41. static PlayerText:gPlayerPageTD[MAX_PLAYERS];
  42. static PlayerText:gPlayerModelTD[MAX_PLAYERS][MODELS_PER_PAGE];
  43. //
  44. static Text:gBackgroundTD;
  45. static Text:gContentBoxTD[2];
  46. static Text:gButtonsTD[14];
  47.  
  48. static gPlayerList[MAX_PLAYERS][MAX_DIALOG_MODELS];
  49. static gPlayerTotalModels[MAX_PLAYERS];
  50.  
  51. enum DialogEnum
  52. {
  53. E_DIALOG_ID,
  54. E_DIALOG_TYPE,
  55. E_DIALOG_PAGE,
  56. E_DIALOG_SELECTED_ITEM,
  57. E_DIALOG_CLICK_TICK
  58. }
  59. static gPlayerDialog[MAX_PLAYERS][DialogEnum];
  60.  
  61. enum SetupDialogEnum
  62. {
  63. Float:E_MODEL_X,
  64. Float:E_MODEL_Y,
  65. Float:E_MODEL_Z,
  66. Float:E_MODEL_ZOOM,
  67. E_MODEL_BACKGROUND_COLOR,
  68. E_MODEL_HOVER_COLOR,
  69. E_MODEL_SELECT_COLOR
  70. }
  71. static gSetupDialog[SetupDialogEnum];
  72.  
  73. stock GetPlayerDialogID(playerid)
  74. {
  75. if(! IsPlayerConnected(playerid)) return false;
  76. return gPlayerDialog[playerid][E_DIALOG_ID];
  77. }
  78.  
  79. stock GetPlayerDialogStyle(playerid)
  80. {
  81. if(! IsPlayerConnected(playerid)) return false;
  82. return gPlayerDialog[playerid][E_DIALOG_TYPE];
  83. }
  84.  
  85. stock SetupPrevModelDialog(Float:mx, Float:my, Float:mz, Float:mzoom = 1.0, mbgcolor = 0x00FFFF10, hovercolor = 0x8B0000FF, selectcolor = 0x8B0000FF)
  86. {
  87. gSetupDialog[E_MODEL_X] = mx;
  88. gSetupDialog[E_MODEL_Y] = my;
  89. gSetupDialog[E_MODEL_Z] = mz;
  90. gSetupDialog[E_MODEL_ZOOM] = mzoom;
  91. gSetupDialog[E_MODEL_BACKGROUND_COLOR] = mbgcolor;
  92. gSetupDialog[E_MODEL_HOVER_COLOR] = hovercolor;
  93. gSetupDialog[E_MODEL_SELECT_COLOR] = selectcolor;
  94. return true;
  95. }
  96.  
  97. #define ceildiv(%0,%1) (((%0)-1)/(%1)+1)//thansk to Y_Less
  98. Dialog_TotalPages(playerid)
  99. {
  100. if(! IsPlayerConnected(playerid)) return false;
  101. return ceildiv(gPlayerTotalModels[playerid], MODELS_PER_PAGE);
  102. }
  103.  
  104. //----Internal functions
  105.  
  106. static Text:Dialog_TextDrawAdd(Float:posX, Float:posY, string[], bgcolor, font, Float:lettersizeX, Float:lettersizeY, textcolor, allign = 0, outline = 1, bool:proportional = true, shadow = 1, bool:usebox = false, boxcolor = 0, Float:textsizeX = -1.0, Float:textsizeY = -1.0, model = 0, Float:rotX = 0.0, Float:rotY = 0.0, Float:rotZ = 0.0, Float:zoom = 1.0)
  107. {
  108. static Text:gTextDraw;
  109. gTextDraw = TextDrawCreate(posX, posY, string);
  110. TextDrawBackgroundColor(gTextDraw, bgcolor);
  111. TextDrawFont(gTextDraw, font);
  112. TextDrawLetterSize(gTextDraw, lettersizeX, lettersizeY);
  113. TextDrawColor(gTextDraw, textcolor);
  114. TextDrawAlignment(gTextDraw, allign);
  115. TextDrawSetOutline(gTextDraw, outline);
  116. TextDrawSetProportional(gTextDraw, proportional);
  117. TextDrawSetShadow(gTextDraw, shadow);
  118. TextDrawUseBox(gTextDraw, usebox);
  119. if(usebox) TextDrawBoxColor(gTextDraw, boxcolor);
  120. if(textsizeX != -1.0 && textsizeY != -1.0) TextDrawTextSize(gTextDraw, textsizeX, textsizeY);
  121. if(font == 5)
  122. {
  123. TextDrawSetPreviewModel(gTextDraw, model);
  124. TextDrawSetPreviewRot(gTextDraw, rotX, rotY, rotZ, zoom);
  125. }
  126. return gTextDraw;
  127. }
  128.  
  129. static PlayerText:Dialog_PlayerTextDrawAdd(playerid, Float:posX, Float:posY, string[], bgcolor, font, Float:lettersizeX, Float:lettersizeY, textcolor, allign = 0, outline = 1, bool:proportional = true, shadow = 1, bool:usebox = false, boxcolor = 0, Float:textsizeX = -1.0, Float:textsizeY = -1.0, model = 0, Float:rotX = 0.0, Float:rotY = 0.0, Float:rotZ = 0.0, Float:zoom = 1.0, selectable = 0)
  130. {
  131. static PlayerText:gTextDraw;
  132. gTextDraw = CreatePlayerTextDraw(playerid, posX, posY, string);
  133. PlayerTextDrawBackgroundColor(playerid, gTextDraw, bgcolor);
  134. PlayerTextDrawFont(playerid, gTextDraw, font);
  135. PlayerTextDrawLetterSize(playerid, gTextDraw, lettersizeX, lettersizeY);
  136. PlayerTextDrawColor(playerid, gTextDraw, textcolor);
  137. PlayerTextDrawAlignment(playerid, gTextDraw, allign);
  138. PlayerTextDrawSetOutline(playerid, gTextDraw, outline);
  139. PlayerTextDrawSetProportional(playerid, gTextDraw, proportional);
  140. PlayerTextDrawSetShadow(playerid, gTextDraw, shadow);
  141. PlayerTextDrawUseBox(playerid, gTextDraw, usebox);
  142. if(usebox) PlayerTextDrawBoxColor(playerid, gTextDraw, boxcolor);
  143. if(textsizeX != -1.0 && textsizeY != -1.0) PlayerTextDrawTextSize(playerid, gTextDraw, textsizeX, textsizeY);
  144. if(font == 5)
  145. {
  146. PlayerTextDrawSetPreviewModel(playerid, gTextDraw, model);
  147. PlayerTextDrawSetPreviewRot(playerid, gTextDraw, rotX, rotY, rotZ, zoom);
  148. }
  149. PlayerTextDrawSetSelectable(playerid, gTextDraw, selectable);
  150. return gTextDraw;
  151. }
  152.  
  153. static Dialog_isnumeric(str[])
  154. {
  155. new ch, i;
  156. while ((ch = str[i++])) if (!('0' <= ch <= '9')) return false;
  157. return true;
  158. }
  159.  
  160. static Dialog_CreateGlobalTD()
  161. {
  162. gBackgroundTD = Dialog_TextDrawAdd(132.000000, 123.000000, "BACKGROUND", 255, 1, 0.000000, 25.000000, -1, 0, false, true, 0, true, 150, 500.000000, 0.000000);
  163. gContentBoxTD[0] = Dialog_TextDrawAdd(137.000000, 131.000000, "BOX", 255, 1, 0.000000, 20.900007, -156, 0, false, true, 0, true, -156, 493.000000, 0.000000);
  164. gContentBoxTD[1] = Dialog_TextDrawAdd(138.000000, 132.000000, "BOX", 255, 1, 0.000000, 20.700010, -1, 0, false, true, 0, true, 230, 492.000000, 0.000000);
  165. return true;
  166. }
  167.  
  168. static Dialog_DestroyGlobalTD()
  169. {
  170. TextDrawHideForAll(gBackgroundTD);
  171. TextDrawDestroy(gBackgroundTD);
  172. TextDrawHideForAll(gContentBoxTD[0]);
  173. TextDrawDestroy(gContentBoxTD[0]);
  174. TextDrawHideForAll(gContentBoxTD[1]);
  175. TextDrawDestroy(gContentBoxTD[1]);
  176. return true;
  177. }
  178.  
  179. static Dialog_CreateGlobalButtonsTD()
  180. {
  181. gButtonsTD[0] = Dialog_TextDrawAdd(200.000000, 329.000000, "BUTTON1", 255, 1, 0.000000, 1.300007, -1, 0, false, true, 0, true, -156, 256.000000, 27.000000);
  182. gButtonsTD[1] = Dialog_TextDrawAdd(197.000000, 328.000000, "LD_OTB2:butnA", 255, 4, 0.000000, 1.300008, 255, 0, false, true, 0, true, 255, 63.000000, 18.000000, 0, 0.0, 0.0, 0.0, 1);
  183. TextDrawSetSelectable(gButtonsTD[1], 1);//i have to do this seperately, idk why its not set to selectable when in the funcion Dialog_TextDrawAdd. Though it works in the case of player texts!
  184. gButtonsTD[2] = Dialog_TextDrawAdd(194.000000, 322.000000, "( )", 255, 1, 0.389999, 2.299999, -131, 0, false, true, 0, false);
  185.  
  186. gButtonsTD[3] = Dialog_TextDrawAdd(284.000000, 329.000000, "BUTTON2", 255, 1, 0.000000, 1.300007, -1, 0, false, true, 0, true, -156, 340.000000, 27.000000);
  187. gButtonsTD[4] = Dialog_TextDrawAdd(280.000000, 328.000000, "LD_OTB2:butnA", 255, 4, 0.000000, 1.300008, 255, 0, false, true, 0, true, 255, 65.000000, 18.000000, 0, 0.0, 0.0, 0.0, 1);
  188. TextDrawSetSelectable(gButtonsTD[4], 1);
  189. gButtonsTD[5] = Dialog_TextDrawAdd(278.000000, 322.000000, "( )", 255, 1, 0.389999, 2.299999, -131, 0, false, true, 0, false);
  190.  
  191. gButtonsTD[6] = Dialog_TextDrawAdd(371.000000, 329.000000, "BUTTON3", 255, 1, 0.000000, 1.300007, -1, 0, false, true, 0, true, -156, 386.000000, 27.000000);
  192. gButtonsTD[7] = Dialog_TextDrawAdd(367.000000, 328.000000, "LD_OTB2:butnA", 255, 4, 0.000000, 1.300008, 255, 0, false, true, 0, true, 255, 23.000000, 18.000000, 0, 0.0, 0.0, 0.0, 1);
  193. TextDrawSetSelectable(gButtonsTD[7], 1);
  194. gButtonsTD[8] = Dialog_TextDrawAdd(365.000000, 322.000000, "( )", 255, 1, 0.389999, 2.299999, -131, 0, false, true, 0, false);
  195. gButtonsTD[9] = Dialog_TextDrawAdd(378.000000, 328.000000, "<", 0, 1, 0.269999, 1.299999, -56, 2, false, true, 0, false);
  196.  
  197. gButtonsTD[10] = Dialog_TextDrawAdd(402.000000, 329.000000, "BUTTON4", 255, 1, 0.000000, 1.300007, -1, 0, false, true, 0, true, -156, 417.000000, 27.000000);
  198. gButtonsTD[11] = Dialog_TextDrawAdd(399.000000, 328.000000, "LD_OTB2:butnA", 255, 4, 0.000000, 1.300008, 255, 0, false, true, 0, true, 255, 21.000000, 18.000000, 0, 0.0, 0.0, 0.0, 1);
  199. TextDrawSetSelectable(gButtonsTD[11], 1);
  200. gButtonsTD[12] = Dialog_TextDrawAdd(396.000000, 322.000000, "( )", 255, 1, 0.389999, 2.299999, -131, 0, false, true, 0, false);
  201. gButtonsTD[13] = Dialog_TextDrawAdd(410.000000, 328.000000, ">", 0, 1, 0.269999, 1.299999, -56, 2, false, true, 0, false);
  202. return true;
  203. }
  204.  
  205. static Dialog_DestroyGlobalButtonsTD()
  206. {
  207. for(new i; i != 14;i++)
  208. {
  209. TextDrawHideForAll(gButtonsTD[i]);
  210. TextDrawDestroy(gButtonsTD[i]);
  211. }
  212. return true;
  213. }
  214.  
  215. static Dialog_Update(playerid, selected = 0)
  216. {
  217. new Float:BASE_X = 140.0;
  218. new Float:BASE_Y = 132.0;
  219. new bgcolor = 0;
  220. new switch_line = 0;
  221. new current_items = ((gPlayerDialog[playerid][E_DIALOG_PAGE]) * MODELS_PER_PAGE);
  222.  
  223. //destroy model player:textdraws
  224.  
  225. for(new i; i != MODELS_PER_PAGE; i++)
  226. {
  227. if(gPlayerModelTD[playerid][i] != PlayerText:INVALID_TEXT_DRAW)
  228. {
  229. PlayerTextDrawHide(playerid, gPlayerModelTD[playerid][i]);
  230. PlayerTextDrawDestroy(playerid, gPlayerModelTD[playerid][i]);
  231. gPlayerModelTD[playerid][i] = PlayerText:INVALID_TEXT_DRAW;
  232. }
  233. }
  234.  
  235. for(new i; i != MODELS_PER_PAGE; i++)
  236. {
  237. if(current_items >= (gPlayerTotalModels[playerid])) break;
  238.  
  239. if(i == selected)
  240. {
  241. gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM] = current_items;
  242. bgcolor = gSetupDialog[E_MODEL_SELECT_COLOR];
  243. }
  244. else bgcolor = gSetupDialog[E_MODEL_BACKGROUND_COLOR];
  245.  
  246. gPlayerModelTD[playerid][i] = Dialog_PlayerTextDrawAdd(playerid, BASE_X, BASE_Y, "model", bgcolor, 5, 0.500000, 1.000000, -1, 0, 0, true, 0, true, 0, 56.000000, 61.000000, gPlayerList[playerid][current_items], gSetupDialog[E_MODEL_X], gSetupDialog[E_MODEL_Y], gSetupDialog[E_MODEL_Z], gSetupDialog[E_MODEL_ZOOM], true);
  247. PlayerTextDrawShow(playerid, gPlayerModelTD[playerid][i]);
  248.  
  249. BASE_X += 57.0;
  250. switch_line += 1;
  251. if(switch_line == MODELS_PER_LINE)
  252. {
  253. switch_line = 0;
  254. BASE_Y += 62.0;
  255. BASE_X = 140.0;
  256. }
  257. current_items += 1;
  258. }
  259. return true;
  260. }
  261.  
  262. static Dialog_UpdatePage(playerid)
  263. {
  264. new string[10];
  265. if(GetPlayerDialogStyle(playerid) == DIALOG_STYLE_PREVMODEL)
  266. {
  267. format(string, sizeof(string), "%d/%d", (gPlayerDialog[playerid][E_DIALOG_PAGE] + 1), Dialog_TotalPages(playerid));
  268. PlayerTextDrawSetString(playerid, gPlayerPageTD[playerid], string);
  269. }
  270. return true;
  271. }
  272.  
  273. //Note: if you use this in a filterscript, please define "FILTERSCRIPT" in your script
  274. #if defined FILTERSCRIPT// if used in a filterscript
  275.  
  276. public OnFilterScriptInit()
  277. {
  278. Dialog_CreateGlobalTD();
  279. Dialog_CreateGlobalButtonsTD();
  280.  
  281. SetupPrevModelDialog(0.0, 0.0, 0.0);
  282.  
  283. #if defined Dialog_OnFilterScriptInit
  284. return Dialog_OnFilterScriptInit();
  285. #else
  286. return 1;
  287. #endif
  288. }
  289. #if defined _ALS_OnFilterScriptInit
  290. #undef OnFilterScriptInit
  291. #else
  292. #define _ALS_OnFilterScriptInit
  293. #endif
  294. #define OnFilterScriptInit Dialog_OnFilterScriptInit
  295. #if defined Dialog_OnFilterScriptInit
  296. forward Dialog_OnFilterScriptInit();
  297. #endif
  298.  
  299. public OnFilterScriptExit()
  300. {
  301. Dialog_DestroyGlobalTD();
  302. Dialog_DestroyGlobalButtonsTD();
  303.  
  304. #if defined Dialog_OnFilterScriptExit
  305. return Dialog_OnFilterScriptExit();
  306. #else
  307. return 1;
  308. #endif
  309. }
  310. #if defined _ALS_OnFilterScriptExit
  311. #undef OnFilterScriptExit
  312. #else
  313. #define _ALS_OnFilterScriptExit
  314. #endif
  315. #define OnFilterScriptExit Dialog_OnFilterScriptExit
  316. #if defined Dialog_OnFilterScriptExit
  317. forward Dialog_OnFilterScriptExit();
  318. #endif
  319.  
  320. #else// if used in a gamemode
  321.  
  322. public OnGameModeInit()
  323. {
  324. Dialog_CreateGlobalTD();
  325. Dialog_CreateGlobalButtonsTD();
  326.  
  327. SetupPrevModelDialog(0.0, 0.0, 0.0);
  328.  
  329. #if defined Dialog_OnGameModeInit
  330. return Dialog_OnGameModeInit();
  331. #else
  332. return 1;
  333. #endif
  334. }
  335. #if defined _ALS_OnGameModeInit
  336. #undef OnGameModeInit
  337. #else
  338. #define _ALS_OnGameModeInit
  339. #endif
  340. #define OnGameModeInit Dialog_OnGameModeInit
  341. #if defined Dialog_OnGameModeInit
  342. forward Dialog_OnGameModeInit();
  343. #endif
  344.  
  345. public OnGameModeExit()
  346. {
  347. Dialog_DestroyGlobalTD();
  348. Dialog_DestroyGlobalButtonsTD();
  349.  
  350. #if defined Dialog_OnGameModeExit
  351. return Dialog_OnGameModeExit();
  352. #else
  353. return 1;
  354. #endif
  355. }
  356. #if defined _ALS_OnGameModeExit
  357. #undef OnGameModeExit
  358. #else
  359. #define _ALS_OnGameModeExit
  360. #endif
  361. #define OnGameModeExit Dialog_OnGameModeExit
  362. #if defined Dialog_OnGameModeExit
  363. forward Dialog_OnGameModeExit();
  364. #endif
  365.  
  366. #endif
  367.  
  368. public OnPlayerConnect(playerid)
  369. {
  370. for(new i; i != 2; i++) gPlayerButtonsTD[playerid][i] = PlayerText:INVALID_TEXT_DRAW;
  371.  
  372. gPlayerHeaderTD[playerid] = PlayerText:INVALID_TEXT_DRAW;
  373. gPlayerPageTD[playerid] = PlayerText:INVALID_TEXT_DRAW;
  374.  
  375. for(new i; i != MODELS_PER_PAGE; i++) gPlayerModelTD[playerid][i] = PlayerText:INVALID_TEXT_DRAW;
  376.  
  377. gPlayerDialog[playerid][E_DIALOG_ID] = INVALID_DIALOG_ID;
  378. gPlayerDialog[playerid][E_DIALOG_TYPE] = -1;
  379. gPlayerDialog[playerid][E_DIALOG_PAGE] = 0;
  380. gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM] = 0;
  381. gPlayerDialog[playerid][E_DIALOG_CLICK_TICK] = 0;
  382.  
  383. #if defined Dialog_OnPlayerConnect
  384. return Dialog_OnPlayerConnect(playerid);
  385. #else
  386. return 1;
  387. #endif
  388. }
  389. #if defined _ALS_OnPlayerConnect
  390. #undef OnPlayerConnect
  391. #else
  392. #define _ALS_OnPlayerConnect
  393. #endif
  394. #define OnPlayerConnect Dialog_OnPlayerConnect
  395. #if defined Dialog_OnPlayerConnect
  396. forward Dialog_OnPlayerConnect(playerid);
  397. #endif
  398.  
  399. public OnPlayerDisconnect(playerid, reason)
  400. {
  401. gPlayerPageTD[playerid] = PlayerText:INVALID_TEXT_DRAW;
  402. gPlayerHeaderTD[playerid] = PlayerText:INVALID_TEXT_DRAW;
  403. for(new i; i != 2; i++) gPlayerButtonsTD[playerid][i] = PlayerText:INVALID_TEXT_DRAW;
  404. for(new i; i != MODELS_PER_PAGE; i++) gPlayerModelTD[playerid][i] = PlayerText:INVALID_TEXT_DRAW;
  405.  
  406. #if defined Dialog_OnPlayerDisconnect
  407. return Dialog_OnPlayerDisconnect(playerid, reason);
  408. #else
  409. return 1;
  410. #endif
  411. }
  412. #if defined _ALS_OnPlayerDisconnect
  413. #undef OnPlayerDisconnect
  414. #else
  415. #define _ALS_OnPlayerDisconnect
  416. #endif
  417. #define OnPlayerDisconnect Dialog_OnPlayerDisconnect
  418. #if defined Dialog_OnPlayerDisconnect
  419. forward Dialog_OnPlayerDisconnect(playerid, reason);
  420. #endif
  421.  
  422. stock HidePlayerDialog(playerid)
  423. {
  424. if(! IsPlayerConnected(playerid)) return false;
  425.  
  426. if(GetPlayerDialogID(playerid) != INVALID_DIALOG_ID)
  427. {
  428. if(GetPlayerDialogStyle(playerid) == DIALOG_STYLE_PREVMODEL)
  429. {
  430. //hide the base buttons textdraws
  431. for(new i; i != 14; i++) TextDrawHideForPlayer(playerid, gButtonsTD[i]);
  432.  
  433. //hide dialog base textdraws
  434. TextDrawHideForPlayer(playerid, gBackgroundTD);
  435. TextDrawHideForPlayer(playerid, gContentBoxTD[0]);
  436. TextDrawHideForPlayer(playerid, gContentBoxTD[1]);
  437.  
  438. //destroy dialog page player:textdraw
  439. PlayerTextDrawHide(playerid, gPlayerPageTD[playerid]);
  440. PlayerTextDrawDestroy(playerid, gPlayerPageTD[playerid]);
  441. gPlayerPageTD[playerid] = PlayerText:INVALID_TEXT_DRAW;
  442.  
  443. //destroy dialog header player:textdraw
  444. PlayerTextDrawHide(playerid, gPlayerHeaderTD[playerid]);
  445. PlayerTextDrawDestroy(playerid, gPlayerHeaderTD[playerid]);
  446. gPlayerHeaderTD[playerid] = PlayerText:INVALID_TEXT_DRAW;
  447.  
  448. //destroy dialog buttons player:textdraw
  449. for(new i; i != 2; i++)
  450. {
  451. PlayerTextDrawHide(playerid, gPlayerButtonsTD[playerid][i]);
  452. PlayerTextDrawDestroy(playerid, gPlayerButtonsTD[playerid][i]);
  453. gPlayerButtonsTD[playerid][i] = PlayerText:INVALID_TEXT_DRAW;
  454. }
  455.  
  456. //destroy model player:textdraws
  457. for(new i; i != MODELS_PER_PAGE; i++)
  458. {
  459. if(gPlayerModelTD[playerid][i] != PlayerText:INVALID_TEXT_DRAW)
  460. {
  461. PlayerTextDrawHide(playerid, gPlayerModelTD[playerid][i]);
  462. PlayerTextDrawDestroy(playerid, gPlayerModelTD[playerid][i]);
  463. gPlayerModelTD[playerid][i] = PlayerText:INVALID_TEXT_DRAW;
  464. }
  465. }
  466.  
  467. CancelSelectTextDraw(playerid);
  468. }
  469. else
  470. {
  471. ShowPlayerDialog(playerid, INVALID_DIALOG_ID, DIALOG_STYLE_MSGBOX, "hide", "hide", "hide", "");
  472. }
  473. }
  474. gPlayerDialog[playerid][E_DIALOG_ID] = INVALID_DIALOG_ID;
  475. gPlayerDialog[playerid][E_DIALOG_TYPE] = -1;
  476. gPlayerDialog[playerid][E_DIALOG_PAGE] = 0;
  477. gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM] = 0;
  478. gPlayerDialog[playerid][E_DIALOG_CLICK_TICK] = GetTickCount();
  479. return true;
  480. }
  481.  
  482. stock Dialog_Show(playerid, dialogid, style, caption[], info[], button1[], button2[] = "", infosize = sizeof(info))
  483. {
  484. if(! IsPlayerConnected(playerid)) return false;
  485.  
  486. gPlayerDialog[playerid][E_DIALOG_ID] = dialogid;
  487. gPlayerDialog[playerid][E_DIALOG_TYPE] = style;
  488. gPlayerDialog[playerid][E_DIALOG_CLICK_TICK] = GetTickCount();
  489.  
  490. if(dialogid == INVALID_DIALOG_ID) return HidePlayerDialog(playerid);
  491.  
  492. switch(style)
  493. {
  494. case DIALOG_STYLE_PREVMODEL:
  495. {
  496. if(infosize > MAX_DIALOG_MODELS)
  497. {
  498. print("WARNING: Max dialog models limit reached, please increase \"MAX_DIALOG_MODELS\" to increase the index from <dialogs.inc>.");
  499. printf("WARNING: Accessing only %i listitems but found %i listitems from array, need an increase of %i.", MAX_DIALOG_MODELS, infosize, (infosize - MAX_DIALOG_MODELS));
  500. infosize = MAX_DIALOG_MODELS;
  501. }
  502.  
  503. if(infosize > 0)
  504. {
  505. for(new i = 0; i < infosize; i++)
  506. {
  507. gPlayerList[playerid][i] = info[i];
  508. }
  509. gPlayerDialog[playerid][E_DIALOG_PAGE] = 0;
  510. gPlayerTotalModels[playerid] = infosize;
  511. gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM] = 0;
  512.  
  513. //Show the dialog base textdraws
  514. TextDrawShowForPlayer(playerid, gBackgroundTD);
  515. TextDrawShowForPlayer(playerid, gContentBoxTD[0]);
  516. TextDrawShowForPlayer(playerid, gContentBoxTD[1]);
  517.  
  518. Dialog_Update(playerid, 0);
  519.  
  520. //Show the buttons base textdraws
  521. for(new i = 0; i != 14; i++) TextDrawShowForPlayer(playerid, gButtonsTD[i]);
  522.  
  523. //Creating the header player:textdraw
  524. if(gPlayerHeaderTD[playerid] != PlayerText:INVALID_TEXT_DRAW) PlayerTextDrawDestroy(playerid, gPlayerHeaderTD[playerid]);
  525. gPlayerHeaderTD[playerid] = Dialog_PlayerTextDrawAdd(playerid, 132.000000, 112.000000, caption, 255, 1, 0.270000, 1.100000, -1, 0, false, true, 0, true, 255, 500.000000, 0.000000);
  526. PlayerTextDrawShow(playerid, gPlayerHeaderTD[playerid]);
  527.  
  528. //Creating the button 1 player:textdraw
  529. if(gPlayerButtonsTD[playerid][0] != PlayerText:INVALID_TEXT_DRAW) PlayerTextDrawDestroy(playerid, gPlayerButtonsTD[playerid][0]);
  530. gPlayerButtonsTD[playerid][0] = Dialog_PlayerTextDrawAdd(playerid, 229.000000, 328.000000, button1, 0, 1, 0.269999, 1.299999, -56, 2, false, true, 0);
  531. PlayerTextDrawShow(playerid, gPlayerButtonsTD[playerid][0]);
  532.  
  533. //Creating the button 2 player:textdraw
  534. if(gPlayerButtonsTD[playerid][1] != PlayerText:INVALID_TEXT_DRAW) PlayerTextDrawDestroy(playerid, gPlayerButtonsTD[playerid][1]);
  535. gPlayerButtonsTD[playerid][1] = Dialog_PlayerTextDrawAdd(playerid, 313.000000, 328.000000, button2, 0, 1, 0.269999, 1.299999, -56, 2, false, true, 0);
  536. PlayerTextDrawShow(playerid, gPlayerButtonsTD[playerid][1]);
  537.  
  538. //Creating the page player:textdraw
  539. new string[10];
  540. format(string, sizeof(string), "1/%d", Dialog_TotalPages(playerid));
  541. if(gPlayerPageTD[playerid] != PlayerText:INVALID_TEXT_DRAW) PlayerTextDrawDestroy(playerid, gPlayerPageTD[playerid]);
  542. gPlayerPageTD[playerid] = Dialog_PlayerTextDrawAdd(playerid, 500.000000, 112.000000, string, 255, 1, 0.270000, 1.100000, -1, 3, false, true);
  543. PlayerTextDrawShow(playerid, gPlayerPageTD[playerid]);
  544.  
  545. return SelectTextDraw(playerid, gSetupDialog[E_MODEL_HOVER_COLOR]);
  546. }
  547. }
  548. default:
  549. {
  550. if(GetPlayerDialogStyle(playerid) == DIALOG_STYLE_PREVMODEL) HidePlayerDialog(playerid);
  551.  
  552. return ShowPlayerDialog(playerid, dialogid, style, caption, info, button1, button2);
  553. }
  554. }
  555. return false;
  556. }
  557. #if defined _ALS_ShowPlayerDialog
  558. #undef ShowPlayerDialog
  559. #else
  560. #define _ALS_ShowPlayerDialog
  561. #endif
  562. #define ShowPlayerDialog Dialog_Show
  563.  
  564. #define BUTTON_1 gButtonsTD[1]//button 1, clickable TD; gives you response = 0
  565. #define BUTTON_2 gButtonsTD[4]//button 2, clickable TD; gives you response = 1
  566. #define BUTTON_PREVIOUS gButtonsTD[7]//button <, clickable TD; gives you previous page
  567. #define BUTTON_NEXT gButtonsTD[11]//button >, clickable TD; gives you next page
  568.  
  569. public OnPlayerClickTextDraw(playerid, Text:clickedid)
  570. {
  571. if(GetPlayerDialogStyle(playerid) == DIALOG_STYLE_PREVMODEL)
  572. {
  573. new model[15] = "Unknown";
  574. if(Dialog_isnumeric(gPlayerList[playerid][gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM]])) format(model, sizeof(model), "%d", gPlayerList[playerid][gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM]]);
  575.  
  576. if(gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM] < 0) gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM] = 0;
  577.  
  578. if(clickedid == Text:INVALID_TEXT_DRAW)//if pressed ESC key
  579. {
  580. if(! CallLocalFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 0, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model))
  581. {
  582. CallRemoteFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 0, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model);
  583. }
  584. return 1;
  585. }
  586.  
  587. if(clickedid == BUTTON_1)//if clicked 'BUTTON1'
  588. {
  589. if(! CallLocalFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 1, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model))
  590. {
  591. CallRemoteFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 1, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model);
  592. }
  593. return 1;
  594. }
  595.  
  596. if(clickedid == BUTTON_2)//if clicked 'BUTTON2'
  597. {
  598. if(! CallLocalFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 0, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model))
  599. {
  600. CallRemoteFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 0, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model);
  601. }
  602. return 1;
  603. }
  604.  
  605. if(clickedid == BUTTON_NEXT)//if clicked '>' - next page
  606. {
  607. if(gPlayerDialog[playerid][E_DIALOG_PAGE] < (Dialog_TotalPages(playerid) - 1))
  608. {
  609. gPlayerDialog[playerid][E_DIALOG_PAGE] += 1;
  610. Dialog_Update(playerid);
  611. Dialog_UpdatePage(playerid);
  612. }
  613. else
  614. {
  615. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  616. }
  617. }
  618.  
  619. if(clickedid == BUTTON_PREVIOUS)//if clicked '<' - previous page
  620. {
  621. if(gPlayerDialog[playerid][E_DIALOG_PAGE] > 0)
  622. {
  623. gPlayerDialog[playerid][E_DIALOG_PAGE] -= 1;
  624. Dialog_Update(playerid);
  625. Dialog_UpdatePage(playerid);
  626. }
  627. else
  628. {
  629. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  630. }
  631. }
  632. }
  633.  
  634. #if defined Dialog_OnPlayerClickTextDraw
  635. return Dialog_OnPlayerClickTextDraw(playerid, Text:clickedid);
  636. #else
  637. return 1;
  638. #endif
  639. }
  640. #if defined _ALS_OnPlayerClickTextDraw
  641. #undef OnPlayerClickTextDraw
  642. #else
  643. #define _ALS_OnPlayerClickTextDraw
  644. #endif
  645. #define OnPlayerClickTextDraw Dialog_OnPlayerClickTextDraw
  646. #if defined Dialog_OnPlayerClickTextDraw
  647. forward Dialog_OnPlayerClickTextDraw(playerid, Text:clickedid);
  648. #endif
  649.  
  650. public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid)
  651. {
  652. if(GetPlayerDialogStyle(playerid) == DIALOG_STYLE_PREVMODEL)
  653. {
  654. //clicks on a model
  655. for(new x = 0; x < MODELS_PER_PAGE; x++)
  656. {
  657. //double click
  658. if((GetTickCount() - gPlayerDialog[playerid][E_DIALOG_CLICK_TICK]) < 200)
  659. {
  660. if(playertextid == gPlayerModelTD[playerid][x])
  661. {
  662. new model[15] = "Unknown";
  663. if(Dialog_isnumeric(gPlayerList[playerid][gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM]])) format(model, sizeof(model), "%d", gPlayerList[playerid][gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM]]);
  664.  
  665. if(gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM] < 0) gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM] = 0;
  666.  
  667. if(! CallLocalFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 1, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model))
  668. {
  669. CallRemoteFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 1, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model);
  670. }
  671. return 1;
  672. }
  673. }
  674. //single click (just highlight the listitem)
  675. else
  676. {
  677. if(playertextid == gPlayerModelTD[playerid][x])
  678. {
  679. gPlayerDialog[playerid][E_DIALOG_CLICK_TICK] = GetTickCount();
  680. return Dialog_Update(playerid, x);
  681. }
  682. }
  683. }
  684. }
  685.  
  686. #if defined Dialog_OnPlayerClickPlayerTD
  687. return Dialog_OnPlayerClickPlayerTD(playerid, PlayerText:playertextid);
  688. #else
  689. return 1;
  690. #endif
  691. }
  692. #if defined _ALS_OnPlayerClickPlayerTD
  693. #undef OnPlayerClickPlayerTextDraw
  694. #else
  695. #define _ALS_OnPlayerClickPlayerTD
  696. #endif
  697. #define OnPlayerClickPlayerTextDraw Dialog_OnPlayerClickPlayerTD
  698. #if defined Dialog_OnPlayerClickPlayerTD
  699. forward Dialog_OnPlayerClickPlayerTD(playerid, PlayerText:playertextid);
  700. #endif
  701.  
  702. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  703. {
  704. if(GetPlayerDialogStyle(playerid) == DIALOG_STYLE_PREVMODEL) HidePlayerDialog(playerid);
  705. else
  706. {
  707. gPlayerDialog[playerid][E_DIALOG_ID] = INVALID_DIALOG_ID;
  708. gPlayerDialog[playerid][E_DIALOG_TYPE] = -1;
  709. gPlayerDialog[playerid][E_DIALOG_PAGE] = 0;
  710. gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM] = 0;
  711. gPlayerDialog[playerid][E_DIALOG_CLICK_TICK] = GetTickCount();
  712. }
  713.  
  714. #if defined Dialog_OnDialogResponse
  715. return Dialog_OnDialogResponse(playerid, dialogid, response, listitem, inputtext);
  716. #else
  717. return 1;
  718. #endif
  719. }
  720. #if defined _ALS_OnDialogResponse
  721. #undef OnDialogResponse
  722. #else
  723. #define _ALS_OnDialogResponse
  724. #endif
  725. #define OnDialogResponse Dialog_OnDialogResponse
  726. #if defined Dialog_OnDialogResponse
  727. forward Dialog_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
  728. #endif
Advertisement
Add Comment
Please, Sign In to add comment