Advertisement
Guest User

Color Draws for G2O by Osmith

a guest
Feb 26th, 2017
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.09 KB | None | 0 0
  1. // G2O official site: http://gothic-online.com.pl/
  2. // My Profile on G2O Forum: http://gothic-online.com.pl/forum/member.php?action=profile&uid=54
  3.  
  4. class createColorDraw
  5. {
  6.     constructor(x,y,font,text)
  7.     {
  8.         sliceCoords = [];
  9.         colors = [];
  10.         texts = [];
  11.         draws = [];
  12.        
  13.         local fulltext = text;
  14.         local index = 0;
  15.         do
  16.         {
  17.             local index = fulltext.find("/");
  18.             if (index != null)
  19.             {
  20.                 sliceCoords.append(index);
  21.                 fulltext = fulltext.slice(0,index) + "|" + fulltext.slice(index + 1,fulltext.len());
  22.                 print(index);
  23.             }
  24.             else
  25.             {
  26.                 break;
  27.             }
  28.         } while (index != null)
  29.  
  30.        
  31.        
  32.         local color_text = text;
  33.         for (local i = 0; i < sliceCoords.len(); ++i)
  34.         {
  35.             local rc = color_text.slice(sliceCoords[i].tointeger() + 1, sliceCoords[i].tointeger() + 4);
  36.             local gc = color_text.slice(sliceCoords[i].tointeger() + 5, sliceCoords[i].tointeger() + 8);
  37.             local bc = color_text.slice(sliceCoords[i].tointeger() + 9, sliceCoords[i].tointeger() + 12);
  38.             if (rc.slice(0,1) == "0")
  39.             {
  40.                 rc = rc.slice(1,rc.len());
  41.             }
  42.             else if (rc.slice(0,2) == "00")
  43.             {
  44.                 rc = rc.slice(2,rc.len());
  45.             }
  46.             if (gc.slice(0,1) == "0")
  47.             {
  48.                 gc = gc.slice(1,gc.len());
  49.             }
  50.             else if (gc.slice(0,2) == "00")
  51.             {
  52.                 gc = gc.slice(2,gc.len());
  53.             }
  54.             if (bc.slice(0,1) == "0")
  55.             {
  56.                 bc = bc.slice(1,bc.len());
  57.             }
  58.             else if (bc.slice(0,2) == "00")
  59.             {
  60.                 bc = bc.slice(2,bc.len());
  61.             }
  62.             colors.append({r = rc.tointeger(),g = gc.tointeger(),b = bc.tointeger()});
  63.         }
  64.        
  65.        
  66.         local endtext = text;
  67.         local curindex = 0;
  68.         local lastindex = 0;
  69.         local first_text = false;
  70.        
  71.         for (local i = 0; i < sliceCoords.len(); ++i)
  72.         {
  73.             if (sliceCoords[0] != 0 && first_text == false)
  74.             {
  75.                 texts.append(endtext.slice(0,sliceCoords[i]));
  76.                 first_text = true;
  77.             }
  78.             if (i != (sliceCoords.len() - 1))
  79.             {
  80.                 texts.append(endtext.slice(sliceCoords[i] + 12,sliceCoords[i + 1]));
  81.             }
  82.             else
  83.             {
  84.                 texts.append(text.slice(sliceCoords[i] + 12,text.len()));
  85.             }
  86.         }
  87.        
  88.        
  89.         local texts_id = 0;
  90.         if (texts.len() > sliceCoords.len())
  91.         {
  92.             draws.append(createDraw(texts[texts_id],font,x,y,defaultColor.r,defaultColor.g,defaultColor.b,true));
  93.             texts_id += 1;
  94.         }
  95.         for (local i = 0; i < sliceCoords.len(); ++i)
  96.         {
  97.             if (texts_id != 0)
  98.             {
  99.                 local resolution = getResolution();
  100.                 local pos = getDrawPosition(draws[texts_id - 1]);
  101.                 local calc = (8192.0 / resolution.width) * getTextWidth(font,texts[texts_id - 1]);
  102.                 draws.append(createDraw(texts[texts_id],font,pos.x + calc,y,colors[i].r,colors[i].g,colors[i].b,true));
  103.                 texts_id += 1;
  104.             }
  105.             else
  106.             {
  107.                 draws.append(createDraw(texts[texts_id],font,x,y,colors[i].r,colors[i].g,colors[i].b,true));
  108.                 texts_id += 1;
  109.             }
  110.         }
  111.     }
  112.    
  113.     function show()
  114.     {
  115.         for (local i = 0; i < draws.len(); ++i)
  116.         {
  117.             setDrawVisible(draws[i],true);
  118.         }
  119.     }
  120.    
  121.     function hide()
  122.     {
  123.         for (local i = 0; i < draws.len(); ++i)
  124.         {
  125.             setDrawVisible(draws[i],false);
  126.         }
  127.     }
  128.    
  129.     sliceCoords = -1;
  130.     colors = -1;
  131.     texts = -1;
  132.     draws = -1;
  133.     defaultColor = {r = 255, g = 255, b = 255};
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement