Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // draw_text_col(x, y, text, line)
  2.  
  3. var col_prev = draw_get_color();
  4.  
  5. var breaks = ds_list_create();
  6. var strings = ds_list_create();
  7. var colors = ds_list_create();
  8.  
  9. // Parse strings and colors
  10. for (var i = 0; i <= string_length(argument2); i += 1) {
  11.     // Get the color
  12.     if (string_char_at(argument2, i) == "[" && string_char_at(argument2, i + 1) == "c"
  13.         && string_char_at(argument2, i + 2) == " ") {
  14.         i += 3;
  15.        
  16.         // 3 values: R, G, B
  17.         var col;
  18.         col[2] = -1;
  19.         col[1] = -1;
  20.         col[0] = -1;
  21.        
  22.         // Get color
  23.         repeat (3) {
  24.             var col_tmp = "";
  25.            
  26.             // Skip multiple spaces
  27.             while (string_char_at(argument2, i) == " ") i += 1;
  28.        
  29.             while (ord(string_char_at(argument2, i)) >= ord("0") && ord(string_char_at(argument2, i)) <= ord("9")) {
  30.                 col_tmp += string_char_at(argument2, i);
  31.                 i += 1;
  32.             }
  33.             i += 1;
  34.        
  35.             // Skip multiple spaces
  36.             while (string_char_at(argument2, i) == " ") i += 1;
  37.  
  38.             // Assign temporary values
  39.             if (col[0] == -1) col[0] = real(col_tmp);
  40.             else if (col[1] == -1) col[1] = real(col_tmp);
  41.             else if (col[2] == -1) col[2] = real(col_tmp);
  42.         }
  43.         ds_list_add(colors, make_color_rgb(col[0], col[1], col[2]));    // Create color from temp values
  44.         col[0] = -1;
  45.         col[1] = -1;
  46.         col[2] = -1;
  47.        
  48.         // Get associated string(s)
  49.         var text_tmp = "";
  50.         while (i <= string_length(argument2) && string_char_at(argument2, i) != "[") {
  51.             if (string_char_at(argument2, i) == "#") {
  52.                 ds_list_add(strings, text_tmp);
  53.                 ds_list_add(breaks, ds_list_size(strings));
  54.                 ds_list_add(colors, colors[| ds_list_size(colors) - 1]);
  55.                 text_tmp = "";
  56.             }
  57.             else
  58.                 text_tmp += string_char_at(argument2, i);
  59.             i += 1;
  60.         }
  61.         ds_list_add(strings, text_tmp);
  62.        
  63.         i -= 1;     // Prepare for next color(eventually)
  64.     }
  65. }
  66.  
  67. // Take a moment to contemplate how beautyful life is
  68.  
  69. // Setup
  70. var text_x = argument0;
  71. var text_y = argument1;
  72. var line = argument3;
  73. var h = string_height("l") * (1 + 0.1 * line);
  74. var p = 0;
  75.  
  76. // Draw
  77. for (var i = 0; i < ds_list_size(strings); i++) {
  78.     if (i == breaks[| p]) {     // New line
  79.         text_y += h;
  80.         text_x = argument0;
  81.         p += 1;
  82.     }
  83.     draw_set_color(colors[| i]);
  84.     draw_text(text_x, text_y, strings[| i]);
  85.     text_x += string_width(strings[| i]);
  86. }
  87. // Reset color
  88. draw_set_color(col_prev);
  89.  
  90. // Clean
  91. ds_list_destroy(colors);
  92. ds_list_destroy(strings);
  93. ds_list_destroy(breaks);
  94.  
  95. // I <3 U
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement