GammixSAMP

dialogs2.inc R2 -Description labels version - By Gammix

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