freshtext.inc 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. //============================================//
  2. //===============[ Fresh Text ]===============//
  3. //============================================//
  4. #include <a_samp>
  5. //============================================//
  6. #define MAX_STREAMED_TEXTDRAWS 5000
  7. //============================================//
  8. enum textInfo
  9. {
  10. tCreated,
  11. tOwner[MAX_PLAYER_NAME],
  12. Text:tID,
  13. tString[1024],
  14. Float:tPosX,
  15. Float:tPosY,
  16. Float:tLetterSizeX,
  17. Float:tLetterSizeY,
  18. Float:tTextSizeX,
  19. Float:tTextSizeY,
  20. tFont,
  21. tAlignment,
  22. tColor,
  23. tBox,
  24. tBoxColor,
  25. tShadow,
  26. tOutline,
  27. tProportional,
  28. tBackgroundColor
  29. };
  30. new TextInfo[MAX_STREAMED_TEXTDRAWS][textInfo];
  31. //============================================//
  32. forward Text:TextDrawCreateEx(Float:x, Float:y, text[]);
  33. forward TextDrawDestroyEx(Text:text);
  34. forward TextDrawLetterSizeEx(Text:text, Float:x, Float:y);
  35. forward TextDrawTextSizeEx(Text:text, Float:x, Float:y);
  36. forward TextDrawAlignmentEx(Text:text, alignment);
  37. forward TextDrawColorEx(Text:text, color);
  38. forward TextDrawUseBoxEx(Text:text, use);
  39. forward TextDrawBoxColorEx(Text:text, color);
  40. forward TextDrawSetShadowEx(Text:text, size);
  41. forward TextDrawSetOutlineEx(Text:text, size);
  42. forward TextDrawBackgroundColorEx(Text:text, color);
  43. forward TextDrawFontEx(Text:text, font);
  44. forward TextDrawSetProportionalEx(Text:text, set);
  45. forward TextDrawShowForPlayerEx(playerid, Text:text);
  46. forward TextDrawHideForPlayerEx(playerid, Text:text);
  47. forward TextDrawSetStringEx(Text:text, string[]);
  48. forward Text_OnPlayerDisconnect(playerid);
  49. //============================================//
  50. public Text:TextDrawCreateEx(Float:x, Float:y, text[])
  51. {
  52. for(new i=0; i < sizeof(TextInfo); i++)
  53. {
  54. if(TextInfo[i][tCreated] == 0)
  55. {
  56. TextInfo[i][tPosX]=x;
  57. TextInfo[i][tPosY]=y;
  58. format(TextInfo[i][tString], 1024,"%s",text);
  59. TextInfo[i][tCreated]=1;
  60. SendDebugMessage(i, "TextDrawCreate");
  61. return Text:i;
  62. }
  63. }
  64. return Text:INVALID_TEXT_DRAW;
  65. }
  66. //============================================//
  67. public TextDrawDestroyEx(Text:text)
  68. {
  69. for(new i=0; i < sizeof(TextInfo); i++)
  70. {
  71. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  72. {
  73. TextInfo[i][tCreated]=0;
  74. TextDrawDestroy(TextInfo[i][tID]);
  75. SendDebugMessage(i, "TextDrawDestroy");
  76. return true;
  77. }
  78. }
  79. return true;
  80. }
  81. //============================================//
  82. public TextDrawLetterSizeEx(Text:text, Float:x, Float:y)
  83. {
  84. for(new i=0; i < sizeof(TextInfo); i++)
  85. {
  86. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  87. {
  88. TextInfo[i][tLetterSizeX]=x;
  89. TextInfo[i][tLetterSizeY]=y;
  90. SendDebugMessage(i, "LetterSize");
  91. return true;
  92. }
  93. }
  94. return true;
  95. }
  96. //============================================//
  97. public TextDrawTextSizeEx(Text:text, Float:x, Float:y)
  98. {
  99. for(new i=0; i < sizeof(TextInfo); i++)
  100. {
  101. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  102. {
  103. TextInfo[i][tTextSizeX]=x;
  104. TextInfo[i][tTextSizeY]=y;
  105. SendDebugMessage(i, "TextSize");
  106. return true;
  107. }
  108. }
  109. return true;
  110. }
  111. //============================================//
  112. public TextDrawAlignmentEx(Text:text, alignment)
  113. {
  114. for(new i=0; i < sizeof(TextInfo); i++)
  115. {
  116. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  117. {
  118. TextInfo[i][tAlignment]=alignment;
  119. SendDebugMessage(i, "SetAlignment");
  120. return true;
  121. }
  122. }
  123. return true;
  124. }
  125. //============================================//
  126. public TextDrawColorEx(Text:text, color)
  127. {
  128. for(new i=0; i < sizeof(TextInfo); i++)
  129. {
  130. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  131. {
  132. TextInfo[i][tColor]=color;
  133. SendDebugMessage(i, "TextColor");
  134. return true;
  135. }
  136. }
  137. return true;
  138. }
  139. //============================================//
  140. public TextDrawUseBoxEx(Text:text, use)
  141. {
  142. for(new i=0; i < sizeof(TextInfo); i++)
  143. {
  144. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  145. {
  146. TextInfo[i][tBox]=use;
  147. SendDebugMessage(i, "UseBox");
  148. return true;
  149. }
  150. }
  151. return true;
  152. }
  153. //============================================//
  154. public TextDrawBoxColorEx(Text:text, color)
  155. {
  156. for(new i=0; i < sizeof(TextInfo); i++)
  157. {
  158. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  159. {
  160. TextInfo[i][tBoxColor]=color;
  161. SendDebugMessage(i, "SetBoxColor");
  162. return true;
  163. }
  164. }
  165. return true;
  166. }
  167. //============================================//
  168. public TextDrawSetShadowEx(Text:text, size)
  169. {
  170. for(new i=0; i < sizeof(TextInfo); i++)
  171. {
  172. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  173. {
  174. TextInfo[i][tShadow]=size;
  175. SendDebugMessage(i, "SetShadow");
  176. return true;
  177. }
  178. }
  179. return true;
  180. }
  181. //============================================//
  182. public TextDrawSetOutlineEx(Text:text, size)
  183. {
  184. for(new i=0; i < sizeof(TextInfo); i++)
  185. {
  186. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  187. {
  188. TextInfo[i][tOutline]=size;
  189. SendDebugMessage(i, "SetOutline");
  190. return true;
  191. }
  192. }
  193. return true;
  194. }
  195. //============================================//
  196. public TextDrawBackgroundColorEx(Text:text, color)
  197. {
  198. for(new i=0; i < sizeof(TextInfo); i++)
  199. {
  200. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  201. {
  202. TextInfo[i][tBackgroundColor]=color;
  203. SendDebugMessage(i, "SetBGColor");
  204. return true;
  205. }
  206. }
  207. return true;
  208. }
  209. //============================================//
  210. public TextDrawFontEx(Text:text, font)
  211. {
  212. for(new i=0; i < sizeof(TextInfo); i++)
  213. {
  214. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  215. {
  216. TextInfo[i][tFont]=font;
  217. SendDebugMessage(i, "SetFont");
  218. return true;
  219. }
  220. }
  221. return true;
  222. }
  223. //============================================//
  224. public TextDrawSetProportionalEx(Text:text, set)
  225. {
  226. for(new i=0; i < sizeof(TextInfo); i++)
  227. {
  228. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  229. {
  230. TextInfo[i][tProportional]=set;
  231. SendDebugMessage(i, "SetProportional");
  232. return true;
  233. }
  234. }
  235. return true;
  236. }
  237. //============================================//
  238. public TextDrawShowForPlayerEx(playerid, Text:text)
  239. {
  240. for(new i=0; i < sizeof(TextInfo); i++)
  241. {
  242. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  243. {
  244. TextInfo[i][tID]=TextDrawCreate(TextInfo[i][tPosX], TextInfo[i][tPosY], TextInfo[i][tString]);
  245. TextDrawLetterSize(TextInfo[i][tID], TextInfo[i][tLetterSizeX], TextInfo[i][tLetterSizeY]);
  246. TextDrawTextSize(TextInfo[i][tID], TextInfo[i][tTextSizeX], TextInfo[i][tTextSizeY]);
  247. TextDrawAlignment(TextInfo[i][tID], TextInfo[i][tAlignment]);
  248. TextDrawColor(TextInfo[i][tID], TextInfo[i][tColor]);
  249. TextDrawUseBox(TextInfo[i][tID], TextInfo[i][tBox]);
  250. TextDrawBoxColor(TextInfo[i][tID], TextInfo[i][tBoxColor]);
  251. TextDrawSetShadow(TextInfo[i][tID], TextInfo[i][tShadow]);
  252. TextDrawSetOutline(TextInfo[i][tID], TextInfo[i][tOutline]);
  253. TextDrawBackgroundColor(TextInfo[i][tID], TextInfo[i][tBackgroundColor]);
  254. TextDrawFont(TextInfo[i][tID], TextInfo[i][tFont]);
  255. TextDrawSetProportional(TextInfo[i][tID], TextInfo[i][tProportional]);
  256. TextDrawShowForPlayer(playerid, TextInfo[i][tID]);
  257. format(TextInfo[i][tOwner], 24,"%s",GetPlayerNameEx(playerid));
  258. SendDebugMessage(i, "TextDrawShowForPlayer");
  259. return true;
  260. }
  261. }
  262. return true;
  263. }
  264. //============================================//
  265. public TextDrawHideForPlayerEx(playerid, Text:text)
  266. {
  267. for(new i=0; i < sizeof(TextInfo); i++)
  268. {
  269. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  270. {
  271. TextDrawHideForPlayer(playerid, TextInfo[i][tID]);
  272. TextDrawDestroy(TextInfo[i][tID]);
  273. SendDebugMessage(i, "TextDrawHideForPlayer");
  274. return true;
  275. }
  276. }
  277. return true;
  278. }
  279. //============================================//
  280. public TextDrawSetStringEx(Text:text, string[])
  281. {
  282. for(new i=0; i < sizeof(TextInfo); i++)
  283. {
  284. if(TextInfo[i][tCreated] == 1 && TextInfo[i][tID] == text)
  285. {
  286. TextDrawSetString(TextInfo[i][tID], string);
  287. SendDebugMessage(i, "SetString");
  288. return true;
  289. }
  290. }
  291. return true;
  292. }
  293. //============================================//
  294. public Text_OnPlayerDisconnect(playerid)
  295. {
  296. for(new i=0; i < sizeof(TextInfo); i++)
  297. {
  298. if(TextInfo[i][tCreated] == 1 && strcmp(GetPlayerNameEx(playerid), TextInfo[i][tOwner], true) == 0)
  299. {
  300. TextDrawHideForPlayerEx(playerid, TextInfo[i][tID]);
  301. SendDebugMessage(i, "Disconnect");
  302. }
  303. }
  304. return true;
  305. }
  306. //============================================//
  307. stock GetPlayerNameEx(playerid)
  308. {
  309. new name[MAX_PLAYER_NAME];
  310. GetPlayerName(playerid, name, sizeof(name));
  311. return name;
  312. }
  313. //============================================//
  314. stock SendDebugMessage(id, func[])
  315. {
  316. new string[128];
  317. format(string, sizeof(string),"(DEBUG): ID:%d - Function: %s", id, func);
  318. print(string);
  319. }
  320. //============================================//
  321. #define TextDrawCreate TextDrawCreateEx
  322. #define TextDrawDestroy TextDrawDestroyEx
  323. #define TextDrawLetterSize TextDrawLetterSizeEx
  324. #define TextDrawTextSize TextDrawTextSizeEx
  325. #define TextDrawAlignment TextDrawAlignmentEx
  326. #define TextDrawColor TextDrawColorEx
  327. #define TextDrawUseBox TextDrawUseBoxEx
  328. #define TextDrawBoxColor TextDrawBoxColorEx
  329. #define TextDrawSetShadow TextDrawSetShadowEx
  330. #define TextDrawSetOutline TextDrawSetOutlineEx
  331. #define TextDrawBackgroundColor TextDrawBackgroundColorEx
  332. #define TextDrawFont TextDrawFontEx
  333. #define TextDrawSetProportional TextDrawSetProportionalEx
  334. #define TextDrawShowForPlayer TextDrawShowForPlayerEx
  335. #define TextDrawHideForPlayer TextDrawHideForPlayerEx
  336. #define TextDrawShowForAll TextDrawShowForAllEx
  337. #define TextDrawHideForAll TextDrawHideForAllEx
  338. #define TextDrawSetString TextDrawSetStringEx
  339. //============================================//