GammixSAMP

dialogs.inc R5 BETA - By Gammix

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