GammixSAMP

dialogs.inc R4 - By Gammix

May 15th, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.15 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 300//maximum number of listitems a PREVIEW MODEL Dialog can have
  31.  
  32. #define DIALOG_STYLE_PREVMODEL 6//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. Dialog_CreateGlobalTD()
  154. {
  155. 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);
  156. 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);
  157. 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);
  158. return true;
  159. }
  160.  
  161. Dialog_DestroyGlobalTD()
  162. {
  163. TextDrawHideForAll(gBackgroundTD);
  164. TextDrawDestroy(gBackgroundTD);
  165. TextDrawHideForAll(gContentBoxTD[0]);
  166. TextDrawDestroy(gContentBoxTD[0]);
  167. TextDrawHideForAll(gContentBoxTD[1]);
  168. TextDrawDestroy(gContentBoxTD[1]);
  169. return true;
  170. }
  171.  
  172. Dialog_CreateGlobalButtonsTD()
  173. {
  174. 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);
  175. 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);
  176. 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!
  177. gButtonsTD[2] = Dialog_TextDrawAdd(194.000000, 322.000000, "( )", 255, 1, 0.389999, 2.299999, -131, 0, false, true, 0, false);
  178.  
  179. 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);
  180. 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);
  181. TextDrawSetSelectable(gButtonsTD[4], 1);
  182. gButtonsTD[5] = Dialog_TextDrawAdd(278.000000, 322.000000, "( )", 255, 1, 0.389999, 2.299999, -131, 0, false, true, 0, false);
  183.  
  184. 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);
  185. 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);
  186. TextDrawSetSelectable(gButtonsTD[7], 1);
  187. gButtonsTD[8] = Dialog_TextDrawAdd(365.000000, 322.000000, "( )", 255, 1, 0.389999, 2.299999, -131, 0, false, true, 0, false);
  188. gButtonsTD[9] = Dialog_TextDrawAdd(378.000000, 328.000000, "<", 0, 1, 0.269999, 1.299999, -56, 2, false, true, 0, false);
  189.  
  190. 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);
  191. 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);
  192. TextDrawSetSelectable(gButtonsTD[11], 1);
  193. gButtonsTD[12] = Dialog_TextDrawAdd(396.000000, 322.000000, "( )", 255, 1, 0.389999, 2.299999, -131, 0, false, true, 0, false);
  194. gButtonsTD[13] = Dialog_TextDrawAdd(410.000000, 328.000000, ">", 0, 1, 0.269999, 1.299999, -56, 2, false, true, 0, false);
  195. return true;
  196. }
  197.  
  198. Dialog_DestroyGlobalButtonsTD()
  199. {
  200. for(new i; i != 14;i++)
  201. {
  202. TextDrawHideForAll(gButtonsTD[i]);
  203. TextDrawDestroy(gButtonsTD[i]);
  204. }
  205. return true;
  206. }
  207.  
  208. //Note: if you use this in a filterscript, please define "FILTERSCRIPT" in your script
  209. #if defined FILTERSCRIPT// if used in a filterscript
  210.  
  211. public OnFilterScriptInit()
  212. {
  213. Dialog_CreateGlobalTD();
  214. Dialog_CreateGlobalButtonsTD();
  215.  
  216. SetupPrevModelDialog(0.0, 0.0, 0.0);
  217.  
  218. return CallLocalFunction("Dialog_OnFilterScriptInit", " ");
  219. }
  220. #if defined _ALS_OnFilterScriptInit
  221. #undef OnFilterScriptInit
  222. #else
  223. #define _ALS_OnFilterScriptInit
  224. #endif
  225. #define OnFilterScriptInit Dialog_OnFilterScriptInit
  226. forward Dialog_OnFilterScriptInit();
  227.  
  228. public OnFilterScriptExit()
  229. {
  230. Dialog_DestroyGlobalTD();
  231. Dialog_DestroyGlobalButtonsTD();
  232.  
  233. return CallLocalFunction("Dialog_OnFilterScriptExit", " ");
  234. }
  235. #if defined _ALS_OnFilterScriptExit
  236. #undef OnFilterScriptExit
  237. #else
  238. #define _ALS_OnFilterScriptExit
  239. #endif
  240. #define OnFilterScriptExit Dialog_OnFilterScriptExit
  241. forward Dialog_OnFilterScriptExit();
  242.  
  243. #else// if used in a gamemode
  244.  
  245. public OnGameModeInit()
  246. {
  247. Dialog_CreateGlobalTD();
  248. Dialog_CreateGlobalButtonsTD();
  249.  
  250. SetupPrevModelDialog(0.0, 0.0, 0.0);
  251.  
  252. return CallLocalFunction("Dialog_OnGameModeInit", " ");
  253. }
  254. #if defined _ALS_OnGameModeInit
  255. #undef OnGameModeInit
  256. #else
  257. #define _ALS_OnGameModeInit
  258. #endif
  259. #define OnGameModeInit Dialog_OnGameModeInit
  260. forward Dialog_OnGameModeInit();
  261.  
  262. public OnGameModeExit()
  263. {
  264. Dialog_DestroyGlobalTD();
  265. Dialog_DestroyGlobalButtonsTD();
  266.  
  267. return CallLocalFunction("Dialog_OnGameModeExit", " ");
  268. }
  269. #if defined _ALS_OnGameModeExit
  270. #undef OnGameModeExit
  271. #else
  272. #define _ALS_OnGameModeExit
  273. #endif
  274. #define OnGameModeExit Dialog_OnGameModeExit
  275. forward Dialog_OnGameModeExit();
  276.  
  277. #endif
  278.  
  279. public OnPlayerConnect(playerid)
  280. {
  281. for(new i; i != 2; i++) gPlayerButtonsTD[playerid][i] = PlayerText:INVALID_TEXT_DRAW;
  282.  
  283. gPlayerHeaderTD[playerid] = PlayerText:INVALID_TEXT_DRAW;
  284. gPlayerPageTD[playerid] = PlayerText:INVALID_TEXT_DRAW;
  285.  
  286. for(new i; i != MODELS_PER_PAGE; i++) gPlayerModelTD[playerid][i] = PlayerText:INVALID_TEXT_DRAW;
  287.  
  288. gPlayerDialog[playerid][E_DIALOG_ID] = INVALID_DIALOG_ID;
  289. gPlayerDialog[playerid][E_DIALOG_TYPE] = -1;
  290. gPlayerDialog[playerid][E_DIALOG_PAGE] = 0;
  291. gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM] = 0;
  292. gPlayerDialog[playerid][E_DIALOG_CLICK_TICK] = 0;
  293.  
  294. return CallLocalFunction("Dialog_OnPlayerConnect", "i", playerid);
  295. }
  296. #if defined _ALS_OnPlayerConnect
  297. #undef OnPlayerConnect
  298. #else
  299. #define _ALS_OnPlayerConnect
  300. #endif
  301. #define OnPlayerConnect Dialog_OnPlayerConnect
  302. forward Dialog_OnPlayerConnect(playerid);
  303.  
  304. stock HidePlayerDialog(playerid)
  305. {
  306. if(! IsPlayerConnected(playerid)) return false;
  307.  
  308. if(GetPlayerDialogStyle(playerid) == DIALOG_STYLE_PREVMODEL)
  309. {
  310. //hide the base buttons textdraws
  311. for(new i; i != 14; i++) TextDrawHideForPlayer(playerid, gButtonsTD[i]);
  312.  
  313. //hide dialog base textdraws
  314. TextDrawHideForPlayer(playerid, gBackgroundTD);
  315. TextDrawHideForPlayer(playerid, gContentBoxTD[0]);
  316. TextDrawHideForPlayer(playerid, gContentBoxTD[1]);
  317.  
  318. //destroy dialog page player:textdraw
  319. PlayerTextDrawHide(playerid, gPlayerPageTD[playerid]);
  320. PlayerTextDrawDestroy(playerid, gPlayerPageTD[playerid]);
  321. gPlayerPageTD[playerid] = PlayerText:INVALID_TEXT_DRAW;
  322.  
  323. //destroy dialog header player:textdraw
  324. PlayerTextDrawHide(playerid, gPlayerHeaderTD[playerid]);
  325. PlayerTextDrawDestroy(playerid, gPlayerHeaderTD[playerid]);
  326. gPlayerHeaderTD[playerid] = PlayerText:INVALID_TEXT_DRAW;
  327.  
  328. //destroy dialog buttons player:textdraw
  329. for(new i; i != 2; i++)
  330. {
  331. PlayerTextDrawHide(playerid, gPlayerButtonsTD[playerid][i]);
  332. PlayerTextDrawDestroy(playerid, gPlayerButtonsTD[playerid][i]);
  333. gPlayerButtonsTD[playerid][i] = PlayerText:INVALID_TEXT_DRAW;
  334. }
  335.  
  336. //destroy model player:textdraws
  337. for(new i; i != MODELS_PER_PAGE; i++)
  338. {
  339. if(gPlayerModelTD[playerid][i] != PlayerText:INVALID_TEXT_DRAW)
  340. {
  341. PlayerTextDrawHide(playerid, gPlayerModelTD[playerid][i]);
  342. PlayerTextDrawDestroy(playerid, gPlayerModelTD[playerid][i]);
  343. gPlayerModelTD[playerid][i] = PlayerText:INVALID_TEXT_DRAW;
  344. }
  345. }
  346.  
  347. CancelSelectTextDraw(playerid);
  348. }
  349. else
  350. {
  351. ShowPlayerDialog(playerid, -1, DIALOG_STYLE_MSGBOX, "hide", "hide", "hide", "");
  352. }
  353. gPlayerDialog[playerid][E_DIALOG_ID] = INVALID_DIALOG_ID;
  354. gPlayerDialog[playerid][E_DIALOG_TYPE] = -1;
  355. gPlayerDialog[playerid][E_DIALOG_PAGE] = 0;
  356. gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM] = 0;
  357. gPlayerDialog[playerid][E_DIALOG_CLICK_TICK] = 0;
  358. return true;
  359. }
  360.  
  361. Dialog_Update(playerid, selected = 0)
  362. {
  363. new Float:BASE_X = 140.0;
  364. new Float:BASE_Y = 132.0;
  365. new bgcolor = 0;
  366. new switch_line = 0;
  367. new current_items = ((gPlayerDialog[playerid][E_DIALOG_PAGE]) * MODELS_PER_PAGE);
  368.  
  369. //destroy model player:textdraws
  370.  
  371. for(new i; i != MODELS_PER_PAGE; i++)
  372. {
  373. if(gPlayerModelTD[playerid][i] != PlayerText:INVALID_TEXT_DRAW)
  374. {
  375. PlayerTextDrawHide(playerid, gPlayerModelTD[playerid][i]);
  376. PlayerTextDrawDestroy(playerid, gPlayerModelTD[playerid][i]);
  377. gPlayerModelTD[playerid][i] = PlayerText:INVALID_TEXT_DRAW;
  378. }
  379. }
  380.  
  381. for(new i; i != MODELS_PER_PAGE; i++)
  382. {
  383. if(current_items >= (gPlayerTotalModels[playerid])) break;
  384.  
  385. if(i == selected)
  386. {
  387. gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM] = current_items;
  388. bgcolor = gSetupDialog[E_MODEL_SELECT_COLOR];
  389. }
  390. else bgcolor = gSetupDialog[E_MODEL_BACKGROUND_COLOR];
  391.  
  392. gPlayerModelTD[playerid][i] = Dialog_PlayerTextDrawAdd(playerid, BASE_X, BASE_Y, "model", bgcolor, 5, 0.500000, 1.000000, -1, 0, false, 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);
  393. PlayerTextDrawShow(playerid, gPlayerModelTD[playerid][i]);
  394.  
  395. BASE_X += 57.0;
  396. switch_line += 1;
  397. if(switch_line == MODELS_PER_LINE)
  398. {
  399. switch_line = 0;
  400. BASE_Y += 62.0;
  401. BASE_X = 140.0;
  402. }
  403. current_items += 1;
  404. }
  405. return true;
  406. }
  407.  
  408. Dialog_UpdatePage(playerid)
  409. {
  410. new string[10];
  411. if(GetPlayerDialogStyle(playerid) == DIALOG_STYLE_PREVMODEL)
  412. {
  413. format(string, sizeof(string), "%d/%d", (gPlayerDialog[playerid][E_DIALOG_PAGE] + 1), Dialog_TotalPages(playerid));
  414. PlayerTextDrawSetString(playerid, gPlayerPageTD[playerid], string);
  415. }
  416. return true;
  417. }
  418.  
  419. stock Dialog_Show(playerid, dialogid, style, caption[], info[], button1[], button2[] = "", infosize = sizeof(info))
  420. {
  421. if(! IsPlayerConnected(playerid)) return false;
  422.  
  423. if(dialogid == INVALID_DIALOG_ID)
  424. {
  425. if(style == DIALOG_STYLE_PREVMODEL) return HidePlayerDialog(playerid);
  426. else return ShowPlayerDialog(playerid, dialogid, style, caption, info, button1, button2);
  427. }
  428.  
  429. gPlayerDialog[playerid][E_DIALOG_ID] = dialogid;
  430. gPlayerDialog[playerid][E_DIALOG_TYPE] = style;
  431.  
  432. switch(style)
  433. {
  434. case DIALOG_STYLE_PREVMODEL:
  435. {
  436. if(infosize > MAX_DIALOG_MODELS)
  437. {
  438. infosize = MAX_DIALOG_MODELS;
  439. print("WARNING: Max dialog models limit reached, please increase \"MAX_DIALOG_MODELS\" to increase the index from <dialogs.inc>.");
  440. }
  441.  
  442. if(infosize > 0)
  443. {
  444. for(new i = 0; i < infosize; i++)
  445. {
  446. gPlayerList[playerid][i] = info[i];
  447. }
  448. gPlayerDialog[playerid][E_DIALOG_PAGE] = 0;
  449. gPlayerTotalModels[playerid] = infosize;
  450. gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM] = 0;
  451.  
  452. //Show the dialog base textdraws
  453. TextDrawShowForPlayer(playerid, gBackgroundTD);
  454. TextDrawShowForPlayer(playerid, gContentBoxTD[0]);
  455. TextDrawShowForPlayer(playerid, gContentBoxTD[1]);
  456.  
  457. Dialog_Update(playerid, 0);
  458.  
  459. //Show the buttons base textdraws
  460. for(new i = 0; i != 14; i++) TextDrawShowForPlayer(playerid, gButtonsTD[i]);
  461.  
  462. //Creating the header player:textdraw
  463. if(gPlayerHeaderTD[playerid] != PlayerText:INVALID_TEXT_DRAW) PlayerTextDrawDestroy(playerid, gPlayerHeaderTD[playerid]);
  464. 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);
  465. PlayerTextDrawShow(playerid, gPlayerHeaderTD[playerid]);
  466.  
  467. //Creating the button 1 player:textdraw
  468. if(gPlayerButtonsTD[playerid][0] != PlayerText:INVALID_TEXT_DRAW) PlayerTextDrawDestroy(playerid, gPlayerButtonsTD[playerid][0]);
  469. gPlayerButtonsTD[playerid][0] = Dialog_PlayerTextDrawAdd(playerid, 229.000000, 328.000000, button1, 0, 1, 0.269999, 1.299999, -56, 2, false, true, 0);
  470. PlayerTextDrawShow(playerid, gPlayerButtonsTD[playerid][0]);
  471.  
  472. //Creating the button 2 player:textdraw
  473. if(gPlayerButtonsTD[playerid][1] != PlayerText:INVALID_TEXT_DRAW) PlayerTextDrawDestroy(playerid, gPlayerButtonsTD[playerid][1]);
  474. gPlayerButtonsTD[playerid][1] = Dialog_PlayerTextDrawAdd(playerid, 313.000000, 328.000000, button2, 0, 1, 0.269999, 1.299999, -56, 2, false, true, 0);
  475. PlayerTextDrawShow(playerid, gPlayerButtonsTD[playerid][1]);
  476.  
  477. //Creating the page player:textdraw
  478. new string[10];
  479. format(string, sizeof(string), "1/%d", Dialog_TotalPages(playerid));
  480. if(gPlayerPageTD[playerid] != PlayerText:INVALID_TEXT_DRAW) PlayerTextDrawDestroy(playerid, gPlayerPageTD[playerid]);
  481. gPlayerPageTD[playerid] = Dialog_PlayerTextDrawAdd(playerid, 500.000000, 112.000000, string, 255, 1, 0.270000, 1.100000, -1, 3, false, true);
  482. PlayerTextDrawShow(playerid, gPlayerPageTD[playerid]);
  483.  
  484. return SelectTextDraw(playerid, gSetupDialog[E_MODEL_HOVER_COLOR]);
  485. }
  486. }
  487. default:
  488. {
  489. return ShowPlayerDialog(playerid, dialogid, style, caption, info, button1, button2);
  490. }
  491. }
  492. return false;
  493. }
  494. #if defined _ALS_ShowPlayerDialog
  495. #undef ShowPlayerDialog
  496. #else
  497. #define _ALS_ShowPlayerDialog
  498. #endif
  499. #define ShowPlayerDialog Dialog_Show
  500.  
  501. #define BUTTON_1 gButtonsTD[1]//button 1, clickable TD; gives you response = 0
  502. #define BUTTON_2 gButtonsTD[4]//button 2, clickable TD; gives you response = 1
  503. #define BUTTON_PREVIOUS gButtonsTD[7]//button <, clickable TD; gives you previous page
  504. #define BUTTON_NEXT gButtonsTD[11]//button >, clickable TD; gives you next page
  505.  
  506. public OnPlayerClickTextDraw(playerid, Text:clickedid)
  507. {
  508. if(clickedid == Text:INVALID_TEXT_DRAW)//if pressed ESC key
  509. {
  510. if(GetPlayerDialogStyle(playerid) == DIALOG_STYLE_PREVMODEL)
  511. {
  512. new model[15];
  513. format(model, sizeof(model), "%d", gPlayerList[playerid][gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM]]);
  514. if(! CallLocalFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 0, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model))
  515. {
  516. CallRemoteFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 0, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model);
  517. }
  518. return 1;
  519. }
  520. }
  521.  
  522. if(clickedid == BUTTON_1)//if clicked 'BUTTON1'
  523. {
  524. new model[15];
  525. format(model, sizeof(model), "%d", gPlayerList[playerid][gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM]]);
  526.  
  527. if(! CallLocalFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 1, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model))
  528. {
  529. CallRemoteFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 1, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model);
  530. }
  531. return 1;
  532. }
  533.  
  534. if(clickedid == BUTTON_2)//if clicked 'BUTTON2'
  535. {
  536. new model[15];
  537. format(model, sizeof(model), "%d", gPlayerList[playerid][gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM]]);
  538.  
  539. if(! CallLocalFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 0, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model))
  540. {
  541. CallRemoteFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 0, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model);
  542. }
  543. return 1;
  544. }
  545.  
  546. if(clickedid == BUTTON_NEXT)//if clicked '>' - next page
  547. {
  548. if(gPlayerDialog[playerid][E_DIALOG_PAGE] < (Dialog_TotalPages(playerid) - 1))
  549. {
  550. gPlayerDialog[playerid][E_DIALOG_PAGE] += 1;
  551. Dialog_Update(playerid);
  552. Dialog_UpdatePage(playerid);
  553. }
  554. else
  555. {
  556. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  557. }
  558. }
  559.  
  560. if(clickedid == BUTTON_PREVIOUS)//if clicked '<' - previous page
  561. {
  562. if(gPlayerDialog[playerid][E_DIALOG_PAGE] > 0)
  563. {
  564. gPlayerDialog[playerid][E_DIALOG_PAGE] -= 1;
  565. Dialog_Update(playerid);
  566. Dialog_UpdatePage(playerid);
  567. }
  568. else
  569. {
  570. PlayerPlaySound(playerid, 1085, 0.0, 0.0, 0.0);
  571. }
  572. }
  573.  
  574. return CallLocalFunction("Dialog_OnPlayerClickTextDraw", "ii", playerid, _:clickedid);
  575. }
  576. #if defined _ALS_OnPlayerClickTextDraw
  577. #undef OnPlayerClickTextDraw
  578. #else
  579. #define _ALS_OnPlayerClickTextDraw
  580. #endif
  581. #define OnPlayerClickTextDraw Dialog_OnPlayerClickTextDraw
  582. forward Dialog_OnPlayerClickTextDraw(playerid, Text:clickedid);
  583.  
  584. public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid)
  585. {
  586. //clicks on a model
  587. for(new x = 0; x < MODELS_PER_PAGE; x++)
  588. {
  589. //double click
  590. if((GetTickCount() - gPlayerDialog[playerid][E_DIALOG_CLICK_TICK]) < 200)
  591. {
  592. if(playertextid == gPlayerModelTD[playerid][x])
  593. {
  594. new model[15];
  595. format(model, sizeof(model), "%d", gPlayerList[playerid][gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM]]);
  596.  
  597. if(! CallLocalFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 1, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model))
  598. {
  599. CallRemoteFunction("OnDialogResponse", "dddds", playerid, gPlayerDialog[playerid][E_DIALOG_ID], 1, gPlayerDialog[playerid][E_DIALOG_SELECTED_ITEM], model);
  600. }
  601. return 1;
  602. }
  603. }
  604. //single click (just highlight the listitem)
  605. else
  606. {
  607. if(playertextid == gPlayerModelTD[playerid][x])
  608. {
  609. gPlayerDialog[playerid][E_DIALOG_CLICK_TICK] = GetTickCount();
  610. return Dialog_Update(playerid, x);
  611. }
  612. }
  613. }
  614.  
  615. return CallLocalFunction("Dialog_OnPlayerClickPlayerTD", "ii", playerid, _:playertextid);
  616. }
  617. #if defined _ALS_OnPlayerClickPlayerTD
  618. #undef OnPlayerClickPlayerTextDraw
  619. #else
  620. #define _ALS_OnPlayerClickPlayerTD
  621. #endif
  622. #define OnPlayerClickPlayerTextDraw Dialog_OnPlayerClickPlayerTD
  623. forward Dialog_OnPlayerClickPlayerTD(playerid, PlayerText:playertextid);
  624.  
  625. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  626. {
  627. if(dialogid == INVALID_DIALOG_ID) return HidePlayerDialog(playerid);
  628.  
  629. if(GetPlayerDialogStyle(playerid) == DIALOG_STYLE_PREVMODEL) HidePlayerDialog(playerid);
  630. else gPlayerDialog[playerid][E_DIALOG_ID] = INVALID_DIALOG_ID;
  631.  
  632. return CallLocalFunction("Dialog_OnDialogResponse", "iiiis", playerid, dialogid, response, listitem, inputtext);
  633. }
  634. #if defined _ALS_OnDialogResponse
  635. #undef OnDialogResponse
  636. #else
  637. #define _ALS_OnDialogResponse
  638. #endif
  639. #define OnDialogResponse Dialog_OnDialogResponse
  640. forward Dialog_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]);
Advertisement
Add Comment
Please, Sign In to add comment