Y_Less

Text Draw Format converter

Sep 17th, 2011
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.38 KB | None | 0 0
  1. // This is a comment
  2. // uncomment the line below if you want to write a filterscript
  3. //#define FILTERSCRIPT
  4.  
  5. //#define _DEBUG 1
  6.  
  7. #define _YSI_SPECIAL_DEBUG
  8.  
  9. // Define HUGE space in this version!
  10. #define XML_WRITE_BUFFER_SIZE           (8192)
  11.  
  12. #include <a_samp>
  13.  
  14. #include <sscanf2>
  15.  
  16. #include <YSI\y_classes>
  17.  
  18. #include <YSI\y_xml>
  19. #include <YSI\y_ini>
  20. #include <YSI\y_commands>
  21.  
  22. #include <YSI\y_text>
  23.  
  24. #include <YSI\y_stringhash>
  25.  
  26. public OnFilterScriptInit()
  27. {
  28.     printf("LANGUAGE: %d", _:Langs_AddLanguage("EN", "English"));
  29. }
  30.  
  31. text style_generate[all], core[ysi_help];
  32.  
  33. new
  34.     XMLEntry:gWriteRoot,
  35.     XMLEntry:gWriteCur,
  36.     gPrevTag[MAX_INI_TAG] = "\1\0";
  37.  
  38. // Common language formats.  DO NOT load the y_text code in here as we don't
  39. // care about it.
  40.  
  41. forward TextLoader(tag[], name[], value[]);
  42.  
  43. public TextLoader(tag[], name[], value[])
  44. {
  45.     printf("loading %s %s", tag, name);
  46.     if (strcmp(gPrevTag, tag))
  47.     {
  48.         strcpy(gPrevTag, tag);
  49.         gWriteCur = XML_AddParameter(gWriteRoot, "group");
  50.         XML_AddParameter(gWriteCur, "name", tag);
  51.     }
  52.     new
  53.         XMLEntry:ctag = XML_AddParameter(gWriteCur, "entry");
  54.     XML_AddParameter(ctag, "name", name);
  55.     XML_AddParameter(ctag, "style", "client");
  56.     XML_AddParameter(ctag, "colour", "X11_RED");
  57. }
  58.  
  59. new
  60.     XMLEntry:gTextDraws[1024] = {XML_NO_WRITE, ...};//,
  61.     //BitArray:gUseBox<1024> = {Bit:-1, ...};
  62.  
  63. forward TDELoader(tag[], name[], value[]);
  64.  
  65. public TDELoader(tag[], name[], value[])
  66. {
  67.     printf("getting %s %s", tag, name);
  68.     new
  69.         offset = strfind(name, "_") + 1;
  70.     if (!offset)
  71.     {
  72.         return;
  73.     }
  74.     new
  75.         id = strval(name);
  76.     if (gTextDraws[id] == XML_NO_WRITE)
  77.     {
  78.         gTextDraws[id] = XML_AddParameter(gWriteRoot, "textdraw");
  79.         new
  80.             nm[32];
  81.         // Generate a name for this TD from the filename and ID.
  82.         format(nm, sizeof (nm), "%s_%04d", gPrevTag, id);
  83.         XML_AddParameter(gTextDraws[id], "name", nm);
  84.     }
  85.     switch (YHash(name[offset], false))
  86.     {
  87.         case _I(X):
  88.         {
  89.             XML_AddParameter(gTextDraws[id], "x", value);
  90.         }
  91.         case _I(Y):
  92.         {
  93.             XML_AddParameter(gTextDraws[id], "y", value);
  94.         }
  95.         case _I(A,l,i,g,n,m,e,n,t):
  96.         {
  97.             XML_AddParameter(gTextDraws[id], "alignment", value);
  98.         }
  99.         case _I(B,a,c,k,C,o,l,o,r):
  100.         {
  101.             XML_AddParameter(gTextDraws[id], "background", value);
  102.         }
  103.         /*case _I(U,s,e,B,o,x):
  104.         {
  105.             XML_AddParameter(gTextDraws[id], "X", value);
  106.         }*/
  107.         case _I(B,o,x,C,o,l,o,r):
  108.         {
  109.             XML_AddParameter(gTextDraws[id], "box", value);
  110.         }
  111.         case _I(T,e,x,t,S,i,z,e,X):
  112.         {
  113.             XML_AddParameter(gTextDraws[id], "textx", value);
  114.         }
  115.         case _I(T,e,x,t,S,i,z,e,Y):
  116.         {
  117.             XML_AddParameter(gTextDraws[id], "texty", value);
  118.         }
  119.         case _I(C,o,l,o,r):
  120.         {
  121.             XML_AddParameter(gTextDraws[id], "color", value);
  122.         }
  123.         case _I(F,o,n,t):
  124.         {
  125.             XML_AddParameter(gTextDraws[id], "font", value);
  126.         }
  127.         case _I(X,S,i,z,e):
  128.         {
  129.             XML_AddParameter(gTextDraws[id], "letterx", value);
  130.         }
  131.         case _I(Y,S,i,z,e):
  132.         {
  133.             XML_AddParameter(gTextDraws[id], "lettery", value);
  134.         }
  135.         case _I(O,u,t,l,i,n,e):
  136.         {
  137.             XML_AddParameter(gTextDraws[id], "outline", value);
  138.         }
  139.         case _I(P,r,o,p,o,r,t,i,o,n,a,l):
  140.         {
  141.             XML_AddParameter(gTextDraws[id], "proportional", value);
  142.         }
  143.         case _I(S,h,a,d,o,w):
  144.         {
  145.             XML_AddParameter(gTextDraws[id], "shadow", value);
  146.         }
  147.     }
  148. }
  149.  
  150. YCMD:style_generate(playerid, params[], help)
  151. {
  152.     if (help) Text_Send(playerid, STYLE_GENERATE_HELP);
  153.     else if (isnull(params)) Text_Send(playerid, STYLE_GENERATE_PARAMS);
  154.     else
  155.     {
  156.         new
  157.             fname[64];
  158.         gWriteRoot = XML_AddItem("YML");
  159.         gPrevTag = "\1\0";
  160.         format(fname, sizeof (fname), "YSI/text/%s.EN", params);
  161.         INI_ParseFile(fname, "TextLoader", .bPassTag = true);
  162.         format(fname, sizeof (fname), "YSI/%s_LANG_DATA.yml", params);
  163.         XML_WriteItem(fname, gWriteRoot, false, true);
  164.     }
  165.     return 1;
  166. }
  167.  
  168. YCMD:style_convert(playerid, params[], help)
  169. {
  170.     printf("Style_Convert");
  171.     if (help) Text_Send(playerid, STYLE_CONVERT_HELP);
  172.     else if (isnull(params)) Text_Send(playerid, STYLE_CONVERT_PARAMS);
  173.     else
  174.     {
  175.         for (new i = 0; i != sizeof (gTextDraws); ++i)
  176.         {
  177.             gTextDraws[i] = XML_NO_WRITE;
  178.         }
  179.         new
  180.             fname[64];
  181.         gWriteRoot = XML_AddItem("YML");
  182.         gPrevTag = "\1\0";
  183.         format(fname, sizeof (fname), "%s.TDE", params);
  184.         strcpy(gPrevTag, params);
  185.         INI_ParseFile(fname, "TDELoader", .bPassTag = true);
  186.         format(fname, sizeof (fname), "YSI/%s.yml", params);
  187.         XML_WriteItem(fname, gWriteRoot, false, true);
  188.     }
  189.     return 1;
  190. }
Advertisement
Add Comment
Please, Sign In to add comment