GammixSAMP

dialogs2.inc Description labels version - By Gammix

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