[XP] Window Message Mod

Window Message Mod
Authors: ThallionDarkshine
Version: 1.1
Type: Message Add-on
Key Term: Message Add-on



Introduction

This is a small Window_Message mod I made a while ago to allow letter-by-letter text. It now also includes a way to create text animations such as growing, shrinking, rotating, or shaking text. You can also format text with things like bold, underline, etc.

New feature! You can now create text gradients!

Text Animations:
  • Grow
  • Rotate (rock back and forth)
  • Shrink
  • Shake
  • Float
  • Hue Rotate
  • Bounce

Formatting Properties
  • Bold
  • Italic
  • Underline
  • Overline (pretty much useless but I made it anyways)
  • Strikethrough


Features

  • Specify how many letters are added at a time, and at what interval they are added.
  • Specify word-by-word text
  • Message shortcut to change letter-by-letter options from default.
  • Create animated text!
  • Format text, making it bold, italic, etc.


Screenshots

I'll put some up if requested, but there's not that much to see.


Demo

None yet.


Script

Content Hidden Spoiler
  1.  
  2. # Instructions on use of this script
  3. #   - To change the letter-by-letter mode, use:
  4. #       \l[CHAR_AMOUNT, FRAMES]
  5. #         CHAR_AMOUNT - How many chars to add to the string every time it updates
  6. #           note - Use 0 for word-by-word or any negative number for no letter-by-letter
  7. #         FRAMES - How often to add CHAR_AMOUNT characters to the string
  8. #   - To create animated text, use:
  9. #       \a[TYPE]
  10. #         TYPE - Which type of animation the text should have
  11. #           0 - Turn off Animation
  12. #           1 - Grow
  13. #           2 - Rock
  14. #           3 - Shrink
  15. #           4 - Shake
  16. #           5 - Float
  17. #           6 - Color Rotate
  18. #           7 - Bounce
  19. #           8 - Fade
  20. #      note - you can use simply \a to turn off the animation
  21. #   - Formatting Stuff
  22. #       Bold - <b></b>
  23. #       Italic - <i></i>
  24. #       Underline - <u></u>
  25. #       Overline - <o></o>
  26. #       Strikethrough - <s></s>
  27. #   - To create gradient text, use:
  28. #       <grad=COLOR1:COLOR2></grad>
  29. #         COLOR1 - The left color.
  30. #         COLOR2 - The right color.
  31. #         note - colors can be specified either as RED, GREEN, BLUE or as COLOR_ID
  32.  
  33. class Window_Message
  34.   # text mode:
  35.   #   0 - Normal
  36.   #   1 - Letter-by-Letter
  37.   #   2 - Word-by-Word
  38.   DEFAULT_MODE = 1
  39.   # default amount of characters at a time
  40.   DEFAULT_CHARS = 1
  41.   # default number of frames to characters
  42.   DEFAULT_FRAMES = 5
  43.  
  44.   def get_text
  45.     text = $game_temp.message_text
  46.     @wait_points = []
  47.     @wait_count = 0
  48.     if text.gsub!(/\\l(?:\[([\-\d]+)(?:\s*\,\s*([\-\d]+))?\])?/, '') != nil
  49.       @l_l = true
  50.       @l_amnt = $1.nil? ? Window_Message::DEFAULT_CHARS : $1.to_i
  51.       @l_frames = $2.nil? ? Window_Message::DEFAULT_FRAMES : $2.to_i
  52.       @frames = 0
  53.       @length = 0
  54.       if @l_amnt < 0
  55.         @l_l = false
  56.       end
  57.     else
  58.       case Window_Message::DEFAULT_MODE
  59.       when 0:
  60.         @l_l = false
  61.       when 1:
  62.         @l_l = true
  63.         @l_amnt = Window_Message::DEFAULT_CHARS
  64.         @l_frames = Window_Message::DEFAULT_FRAMES
  65.         @frames = 0
  66.         @length = 0
  67.       when 2:
  68.         @l_l = true
  69.         @l_amnt = 0
  70.         @l_frames = Window_Message::DEFAULT_FRAMES
  71.         @frames = 0
  72.         @length = 0
  73.       end
  74.     end
  75.     @text = ""
  76.     begin
  77.       last_text = text.clone
  78.       text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  79.     end until text == last_text
  80.     text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  81.       $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  82.     end
  83.     # Change "\\\\" to "\000" for convenience
  84.     text.gsub!(/\\\\/) { "\000" }
  85.     unformatted = text.clone
  86.     unformatted.gsub!(/\\[Cc]\[([0-9]+)\]/, "")
  87.     unformatted.gsub!(/\\[Aa]\[(\d+)\]/, "")
  88.     unformatted.gsub!(/\<\/?[a-z]+\>/, '')
  89.     unformatted.gsub!(/\<\/?grad\=(\d+(?:\s*\,\s*\d+)*)\:(\d+(?:\s*\,\s*\d+)*)\>/, '')
  90.     unformatted.gsub!(/\\[Gg]/, '')
  91.     # Change "\\C" to "\001"
  92.     text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  93.     if text.gsub!(/\\[Gg]/, '') != nil and @l_l
  94.       @gold_window = Window_Gold.new
  95.       @gold_window.x = 560 - @gold_window.width
  96.       if $game_temp.in_battle
  97.         @gold_window.y = 192
  98.       else
  99.         @gold_window.y = self.y >= 128 ? 32 : 384
  100.       end
  101.       @gold_window.opacity = self.opacity
  102.       @gold_window.back_opacity = self.back_opacity
  103.     end
  104.     while !(ind=unformatted.index(/\\[Ww]\[(\d+)\]/)).nil?
  105.       unformatted.sub!(/\\[Ww]\[(\d+)\]/, "")
  106.       text.sub!(/\\[Ww]\[(\d+)\]/, "")
  107.       @wait_points.push([ind - 1, $1.to_i])
  108.     end
  109.     x, y = 0, 0
  110.     gradients = []
  111.     @gradients = []
  112.     # Get 1 text character in c (loop until unable to get text)
  113.     while ((c = text.slice!(/./m)) != nil)
  114.       @text += c
  115.       if c == "\001" or c == "\002"
  116.         next
  117.       end
  118.       if c == "<"    
  119.         if text.index(/grad\=(\d+(?:\s*\,\s*\d+)*)\:(\d+(?:\s*\,\s*\d+)*)\>/) == 0
  120.           gradient = [$1, $2, 4 + x, 32 * y, 0, 32]
  121.           gradients.push(gradient)
  122.           @text = @text.split('')
  123.           @text = (@text.length == 1 ? "" : @text[0..@text.length - 2].join(''))
  124.           text.sub!(/(grad\=(\d+(?:\s*\,\s*\d+)*)\:(\d+(?:\s*\,\s*\d+)*)\>)/, '')
  125.           next
  126.         elsif text.index('/grad>') == 0
  127.           unless gradients.length == 0 or gradients.last[0].nil?
  128.             gradient = gradients.pop()
  129.             w = [gradient[4], x + 4 - gradient[2]].max
  130.             h = [gradient[5], y * 32 - gradient[3]].max
  131.             rect = Rect.new(gradient[2], gradient[3], w, h)
  132.             @gradients.push([gradient[0], gradient[1], rect])
  133.           end
  134.           @text = @text.split('')
  135.           @text = @text[0..@text.length - 2].join('')
  136.           text.sub!(/(\/?[a-z]+\>)/, '')
  137.           next
  138.         end
  139.         if text.index(/\/?[a-z]+\>/) == 0
  140.           text.sub!(/(\/?[a-z]+\>)/, '')
  141.           @text += $1
  142.         end
  143.       end
  144.       if c == "\n"
  145.         unless gradients.length == 0 or gradients.last[0].nil?
  146.           gradients[-1][4] = [gradients[-1][3], x + 4 - gradients[-1][1]].max
  147.           gradients[-1][5] += 32
  148.         end
  149.         x = 0
  150.         y += 32
  151.         if y >= $game_temp.choice_start
  152.           x = 8
  153.         end
  154.       end
  155.       x += self.contents.text_size(c).width
  156.     end
  157.     unless gradients.length == 0 or gradients.last[0].nil?
  158.       gradient = gradients.pop()
  159.       w = [gradient[4], x + 4 - gradient[2]].max
  160.       h = [gradient[5], y * 32 - gradient[3]].max
  161.       rect = Rect.new(gradient[2], gradient[3], w, h)
  162.       @gradients.push([gradient[0], gradient[1], rect])
  163.     end
  164.     @unformatted = unformatted.clone
  165.     @length = unformatted.length unless @l_l
  166.   end
  167.  
  168.   alias tdks_message_refresh refresh
  169.   def refresh
  170.     if !$game_temp.message_text.nil?
  171.       get_text
  172.       @animations.each { |ani| ani.bitmap.dispose;ani.dispose } unless @animations.nil?
  173.     end
  174.     @animations = []
  175.     self.contents.clear
  176.     self.contents.font.color = normal_color
  177.     x = y = 0
  178.     @cursor_width = 0
  179.     # Indent if choice
  180.     if $game_temp.choice_start == 0
  181.       x = 8
  182.     end
  183.     # If waiting for a message to be displayed
  184.     if @text != nil
  185.       self.contents.font = Font.new
  186.       self.contents.font.underline = false
  187.       self.contents.font.overline = false
  188.       self.contents.font.strikethrough = false
  189.       text = @text.clone
  190.       real_index = 0
  191.       index = 1
  192.       animation = [0, 0, 0, 0, 0]
  193.       p_bold = p_italic = p_underline = p_overline = p_strikethrough = []
  194.       # Control text processing
  195.       begin
  196.         last_text = text.clone
  197.         text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  198.       end until text == last_text
  199.       text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  200.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  201.       end
  202.       # Change "\\\\" to "\000" for convenience
  203.       text.gsub!(/\\\\/) { "\000" }
  204.       # Change "\\C" to "\001" and "\\G" to "\002"
  205.       text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  206.       if @length == @text.length
  207.         text.gsub!(/\\[Aa]/) { "\002" }
  208.       else
  209.         text.gsub!(/\\[Aa](?:\[(\d+)\])?/, "")
  210.       end
  211.       # Get 1 text character in c (loop until unable to get text)
  212.       while ((c = text.slice!(/./m)) != nil)
  213.         break if @length == 0
  214.         real_index += 1
  215.         # If \\
  216.         if c == "\000"
  217.           # Return to original text
  218.           c = "\\"
  219.         end
  220.         # If \C[n]
  221.         if c == "\001"
  222.           # Change text color
  223.           text.sub!(/\[([0-9]+)\]/, "")
  224.           color = $1.to_i
  225.           if color >= 0 and color <= 7
  226.             self.contents.font.color = text_color(color)
  227.           end
  228.           # go to next text
  229.           next
  230.         end
  231.         if c == "\002" and @length == @text.length
  232.           if animation[0] != 0
  233.             animation[1][-1].width = x + 4 - animation[1][-1].x
  234.             @animations.push(animation)
  235.           end
  236.           animation = [0, [Rect.new(4 + x, 32 * y, 0, 32)]]
  237.           if text.index(/\[(\d+)\]/) == 0
  238.             text.sub!(/\[(\d+)\]/, "")
  239.             animation[0] = $1.to_i
  240.           else
  241.             animation[0] = 0
  242.           end
  243.           next
  244.         end
  245.         if c == "<"
  246.           if text.index('b>') == 0
  247.             p_bold.push(self.contents.font.bold)
  248.             self.contents.font.bold = true
  249.           elsif text.index('i>') == 0
  250.             p_italic.push(self.contents.font.italic)
  251.             self.contents.font.italic = true
  252.           elsif text.index('u>') == 0
  253.             p_underline.push(self.contents.font.underline)
  254.             self.contents.font.underline = true
  255.           elsif text.index('o>') == 0
  256.             p_overline.push(self.contents.font.overline)
  257.             self.contents.font.overline = true
  258.           elsif text.index('s>') == 0
  259.             p_strikethrough.push(self.contents.font.strikethrough)
  260.             self.contents.font.strikethrough = true
  261.           end
  262.           if text.index('/b>') == 0
  263.             self.contents.font.bold = p_bold.pop
  264.           elsif text.index('/i>') == 0
  265.             self.contents.font.italic = p_italic.pop
  266.           elsif text.index('/u>') == 0
  267.             self.contents.font.underline = p_underline.pop
  268.           elsif text.index('/o>') == 0
  269.             self.contents.font.overline = p_overline.pop
  270.           elsif text.index('/s>') == 0
  271.             self.contents.font.strikethrough = p_strikethrough.pop
  272.           end
  273.           font = self.contents.font
  274.           if text.index(/\/?[a-z]+\>/) == 0
  275.             text.sub!(/\/?[a-z]+\>/, '')
  276.             next
  277.           end
  278.         end
  279.         # If new line text
  280.         if c == "\n"
  281.           # Update cursor width if choice
  282.           if y >= $game_temp.choice_start
  283.             @cursor_width = [@cursor_width, x].max
  284.           end
  285.           if animation[0] != 0
  286.             animation[1][-1].width = x + 4 - animation[1][-1].x
  287.           end
  288.           # Add 1 to y
  289.           y += 1
  290.           x = 0
  291.           # Indent if choice
  292.           if y >= $game_temp.choice_start
  293.             x = 8
  294.           end
  295.           if animation[0] != 0
  296.             animation[1].push(Rect.new(x + 4, y * 32, 0, 32))
  297.           end
  298.           # go to next text
  299.           next
  300.         end
  301.         # Draw text
  302.         self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
  303.         # Add x to drawn text width
  304.         x += self.contents.text_size(c).width
  305.         index += 1
  306.         break if index > @length
  307.       end
  308.       if animation[0] != 0
  309.         animation[1][-1].width = x + 4 - animation[1][-1].x
  310.         @animations.push(animation)
  311.       end
  312.     end
  313.     # If choice
  314.     if $game_temp.choice_max > 0
  315.       @item_max = $game_temp.choice_max
  316.       self.active = true
  317.       self.index = 0
  318.     end
  319.     # If number input
  320.     if $game_temp.num_input_variable_id > 0
  321.       digits_max = $game_temp.num_input_digits_max
  322.       number = $game_variables[$game_temp.num_input_variable_id]
  323.       @input_number_window = Window_InputNumber.new(digits_max)
  324.       @input_number_window.number = number
  325.       @input_number_window.x = self.x + 8
  326.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  327.     end
  328.     $game_temp.message_text = nil
  329.     overlay_grad = Win32API.new('overlay_grad.dll', 'overlay_grad', 'liiiiiiiiii', 'b')
  330.     @gradients.reverse.each { |i|
  331.       c1 = (i[0].index(',').nil? ? text_color(i[0].to_i) : Color.new(*i[0].split(/\s*\,\s*/).map { |e| e.to_i } ))
  332.       c2 = (i[1].index(',').nil? ? text_color(i[1].to_i) : Color.new(*i[1].split(/\s*\,\s*/).map { |e| e.to_i } ))
  333.       overlay_grad.call(self.contents.__id__, i[2].x, i[2].y, i[2].width, i[2].height, c1.red, c1.green, c1.blue, c2.red, c2.green, c2.blue)
  334.     }
  335.     if @length == @text.length
  336.       @animations = @animations.map { |ani| p ani[1];AnimationSprite.new(ani[0], self.x + 16, self.y + 16, self.z + 1, ani[1], self.contents) }
  337.       @animations.each { |i| i.opacity = (@fade_in ? 0 : 255) }
  338.     end
  339.   end
  340.  
  341.   alias tdks_message_update update
  342.   def update
  343.     if !@wait_count.nil? and @wait_count > 0
  344.       @wait_count -= 1
  345.       return
  346.     end
  347.     # If letter-by-letter
  348.     if !(@fade_in or (@fade_out == false and $game_temp.message_text != nil)) and @l_l and self.contents_opacity == 255
  349.       @frames += 1
  350.       if Input.trigger?(Input::C)
  351.         @length = @text.length
  352.       end
  353.       return unless @frames % @l_frames == 0
  354.       prev_len = @length
  355.       unless @l_amnt == 0
  356.         @length = [@length + @l_amnt, @text.length].min
  357.       else
  358.         s_text = @unformatted[0...@length]
  359.         e_text = @unformatted[@length...@unformatted.length].clone
  360.         e_text.gsub!(/\A[\n\r]+/, '')
  361.         if e_text.index(/\w+/) == 0
  362.           e_text.sub(/(\w+)/, '')
  363.           @length += $1.length
  364.           e_text = @unformatted[@length...@unformatted.length]
  365.           if e_text.index(/[^\w]+/) == 0
  366.             e_text.sub(/([^\w]+)/, '')
  367.             tmp = $1.gsub(/[\n\r]/, '')
  368.             @length += tmp.length
  369.           end
  370.         elsif e_text.index(/[^\w]+/) == 0
  371.           e_text.sub(/([^\w]+)/, '')
  372.           tmp = $1.gsub(/[\n\r]/, '')
  373.           @length += tmp.length
  374.           e_text = @unformatted[@length...@unformatted.length]
  375.           if e_text.index(/\w+/) == 0
  376.             e_text.sub(/(\w+)/, '')
  377.             @length += $1.length
  378.           end
  379.         end
  380.       end
  381.       unless Input.trigger?(Input::C)
  382.         if (wait = @wait_points.detect { |i| i[0].between?(prev_len, @length) }) != nil
  383.           frames = wait[1]
  384.           @wait_points.delete(wait)
  385.           @wait_count = frames
  386.           @length = wait[0] - 1 if frames > 0
  387.         end
  388.       end
  389.       len = @unformatted.gsub(/[\n\r]/, '').length
  390.       if @length >= len
  391.         @length = @text.length
  392.         @l_l = false
  393.       end
  394.       refresh
  395.       return
  396.     end
  397.     @animations.each { |ani| ani.update } unless @animations.nil? or @animations.empty? or @fade_out
  398.     super
  399.     # If fade in
  400.     if @fade_in
  401.       self.contents_opacity += 24
  402.       @animations.each { |i| i.opacity = self.contents_opacity } unless @animations.nil?
  403.       if @input_number_window != nil
  404.         @input_number_window.contents_opacity += 24
  405.       end
  406.       if self.contents_opacity == 255
  407.         @fade_in = false
  408.       end
  409.       return
  410.     end
  411.     # If inputting number
  412.     if @input_number_window != nil
  413.       @input_number_window.update
  414.       # Confirm
  415.       if Input.trigger?(Input::C)
  416.         $game_system.se_play($data_system.decision_se)
  417.         $game_variables[$game_temp.num_input_variable_id] =
  418.           @input_number_window.number
  419.         $game_map.need_refresh = true
  420.         # Dispose of number input window
  421.         @input_number_window.dispose
  422.         @input_number_window = nil
  423.         terminate_message
  424.       end
  425.       return
  426.     end
  427.     # If message is being displayed
  428.     if @contents_showing
  429.       # If choice isn't being displayed, show pause sign
  430.       if $game_temp.choice_max == 0
  431.         self.pause = true
  432.       end
  433.       # Cancel
  434.       if Input.trigger?(Input::B)
  435.         if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
  436.           $game_system.se_play($data_system.cancel_se)
  437.           $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  438.           terminate_message
  439.         end
  440.       end
  441.       # Confirm
  442.       if Input.trigger?(Input::C)
  443.         if $game_temp.choice_max > 0
  444.           $game_system.se_play($data_system.decision_se)
  445.           $game_temp.choice_proc.call(self.index)
  446.         end
  447.         terminate_message
  448.       end
  449.       return
  450.     end
  451.     # If display wait message or choice exists when not fading out
  452.     if @fade_out == false and $game_temp.message_text != nil
  453.       @contents_showing = true
  454.       $game_temp.message_window_showing = true
  455.       reset_window
  456.       @fade_in = true
  457.       refresh
  458.       Graphics.frame_reset
  459.       self.visible = true
  460.       self.contents_opacity = 0
  461.       if @input_number_window != nil
  462.         @input_number_window.contents_opacity = 0
  463.       end
  464.       return
  465.     end
  466.     # If message which should be displayed is not shown, but window is visible
  467.     if self.visible
  468.       @fade_out = true
  469.       self.opacity -= 48
  470.       @animations.each { |i| i.opacity = self.opacity } unless @animations.nil?
  471.       if self.opacity == 0
  472.         self.visible = false
  473.         @animations.each { |i| i.bitmap.dispose;i.dispose }
  474.         @fade_out = false
  475.         $game_temp.message_window_showing = false
  476.       end
  477.       return
  478.     end
  479.   end
  480. end
  481.  
  482. class Font
  483.   attr_accessor :underline, :overline, :strikethrough
  484.   attr_accessor :outline, :outline_color, :outline_distance
  485.   attr_accessor :shadow, :shadow_color, :shadow_ox, :shadow_oy
  486.  
  487.   alias tdks_message_init initialize
  488.   def initialize(*args)
  489.     tdks_message_init(*args)
  490.     @underline = false
  491.     @overline = false
  492.     @strikethrough = false
  493.     @outline, @outline_color, @outline_distance = false, Color.new(0, 0, 0), 0
  494.     @shadow, @shadow_color, @shadow_ox, @shadow_oy = false, Color.new(127, 127, 127, 170), 2, 2
  495.   end
  496. end
  497.  
  498. class Bitmap
  499.   alias tdks_message_draw_text draw_text
  500.   def draw_text(*args)
  501.     unless args[0].is_a?(Rect)
  502.       args[0..3] = Rect.new(*args[0..3])
  503.     end
  504.     args[2] = 0 if args[2].nil?
  505.     args[3] = 1 if args[3].nil?
  506.     case args[3]
  507.     when 0
  508.       args[0].height = text_size(args[1]).height
  509.     when 1
  510.       h = text_size(args[1]).height
  511.       args[0].y += (args[0].height - h) / 2
  512.       args[0].height = h
  513.     when 2
  514.       h = text_size(args[1]).height
  515.       args[0].y += args[0].height
  516.       args[0].height = h
  517.     end
  518.     text = args[1].clone
  519.     text = text.split(/[\n\r]/)
  520.     rect = args[0].clone
  521.     case args[3]
  522.     when 1
  523.       amnt = (text.length / 2.0).floor
  524.       text[0...amnt].each { |ln| rect.y -= text_size(ln).height } if amnt > 0
  525.       rect.y += text_size(text[0]).height / 2 if amnt % 2 == 1
  526.     when 2
  527.       text.each { |ln| rect.y -= text_size(ln).height }
  528.     end
  529.     text.each { |ln|
  530.       orig_x = rect.x
  531.       size = text_size(ln)
  532.       case args[2]
  533.       when 1
  534.         rect.x += (rect.width - size.width) / 2
  535.       when 2
  536.         rect.x += rect.width - size.width
  537.       end
  538.       if font.shadow
  539.         prev_color = font.color.clone
  540.         font.color = font.shadow_color
  541.         tdks_message_draw_text(rect.x + font.shadow_ox, rect.y + font.shadow_oy, rect.width, rect.height, ln)
  542.         font.color = prev_color
  543.       end
  544.       if font.outline
  545.         prev_color = font.color.clone
  546.         font.color = font.outline_color
  547.         (-font.outline_distance..font.outline_distance).each { |ox|
  548.           (-font.outline_distance..font.outline_distance).each { |oy|
  549.             next if ox == 0 and oy == 0
  550.             tdks_message_draw_text(rect.x + ox, rect.y + oy, rect.width, rect.height, ln)
  551.           }
  552.         }
  553.         font.color = prev_color
  554.       end
  555.       tdks_message_draw_text(rect, ln)
  556.       if font.overline
  557.         fill_rect(rect.x, rect.y + (size.height / 15.0).ceil, size.width, (size.height / 15.0).ceil, font.color)
  558.       end
  559.       if font.strikethrough
  560.         fill_rect(rect.x, rect.y + size.height / 2, size.width, (size.height / 15.0).ceil, font.color)
  561.       end
  562.       rect.y += size.height
  563.       if font.underline
  564.         fill_rect(rect.x, rect.y - (2 * size.height / 15.0).ceil, size.width, (size.height / 15.0).ceil, font.color)
  565.       end
  566.       rect.x = orig_x
  567.     }
  568.   end
  569.  
  570.   def draw_gradient_text(c1, c2, *args)
  571.     unless args[0].is_a?(Rect)
  572.       args[0..3] = Rect.new(*args[0..3])
  573.     end
  574.     rect = args[0]
  575.     tmp = Bitmap.new(rect.width, rect.height)
  576.     tmp.draw_text(tmp.rect, *args[1...args.length])
  577.     overlay_grad = Win32API.new('overlay_grad.dll', 'overlay_grad', 'liiiiiiiiii', 'b')
  578.     overlay_grad.call(tmp.__id__, args[0].x, args[0].y, args[0].width, args[0].height, c1.red, c1.green, c1.blue, c2.red, c2.green, c2.blue)
  579.     blt(rect.x, rect.y, tmp, tmp.rect)
  580.   end
  581. end
  582.  
  583. class AnimationSprite < Sprite
  584.   def initialize(type, x, y, z, rects, src_bitmap)
  585.     super()
  586.     @type = type
  587.     rects.delete_if { |rect| rect.width == 0 or rect.height == 0 }
  588.     ry = rects.min { |i, e| i.y <=> e.y }.y
  589.     rx = rects.min { |i, e| i.x <=> e.x }.x
  590.     h = rects.max { |i, e| i.y + i.height <=> e.y + e.height }
  591.     h = h.y + h.height - ry
  592.     w = rects.max { |i, e| i.x + i.width <=> e.x + e.width }
  593.     w = w.x + w.width - rx
  594.     p rx, ry, w, h
  595.     self.x, self.y, self.z = x + rx, y + ry, z
  596.     self.ox, self.oy = w / 2, h / 2
  597.     self.x += ox
  598.     self.y += oy
  599.     self.bitmap = Bitmap.new(w, h)
  600.     rects.each { |rect|
  601.       bitmap.blt(rect.x - rx, rect.y - ry, src_bitmap, rect)
  602.       src_bitmap.fill_rect(rect, Color.new(0, 0, 0, 0))
  603.     }
  604.     @frames = 0
  605.     @fplus = 1
  606.     case @type
  607.     when 4:
  608.       @shake = [0, 0]
  609.       @shaked = 1
  610.     when 6:
  611.       @frames = -40
  612.     when 7:
  613.       @frames = 2
  614.     end
  615.   end
  616.  
  617.   def update
  618.     return if self.disposed?
  619.     @frames += @fplus
  620.     case @type
  621.     when 1:
  622.       z = 1.0 + @frames * 0.1 / 20
  623.       @fplus = -1 if @frames == 20
  624.       @fplus = 1 if @frames == 0
  625.       self.zoom_x = z
  626.       self.zoom_y = z
  627.     when 2:
  628.       a = @frames * 5.0 / 12
  629.       @fplus = -1 if @frames == 12
  630.       @fplus = 1 if @frames == -12
  631.       self.angle = a
  632.     when 3:
  633.       z = 1.0 - @frames * 0.1 / 20
  634.       @fplus = -1 if @frames == 20
  635.       @fplus = 1 if @frames == 0
  636.       self.zoom_x = z
  637.       self.zoom_y = z
  638.     when 4:
  639.       shake_power = 1
  640.       shake_speed = 10
  641.       delta = (shake_power * shake_speed * @fplus) / 15.0 + rand(3) - 1
  642.       @shake[0] += delta
  643.       if @shake[0] > shake_power
  644.         @fplus = -1
  645.       end
  646.       if @shake[0] < - shake_power
  647.         @fplus = 1
  648.       end
  649.       delta = (shake_power * shake_speed * @shaked) / 15.0 + rand(3) - 1
  650.       @shake[1] += delta
  651.       if @shake[1] > shake_power
  652.         @shaked = -1
  653.       end
  654.       if @shake[1] < - shake_power
  655.         @shaked = 1
  656.       end
  657.       self.ox = self.bitmap.width / 2 + @shake[0]
  658.       self.oy = self.bitmap.height / 2 + @shake[1]
  659.     when 5:
  660.       amnt = 5
  661.       amnt *= Math.sin(Math::PI * @frames / 30.0)
  662.       self.oy = self.bitmap.height / 2 + amnt
  663.     when 6:
  664.       if @frames < 0
  665.         a = 255 + @frames * 255 / 40
  666.         self.color.set(255, 0, 0, a)
  667.         return
  668.       end
  669.       r = g = b = 0
  670.       tmp = (@frames % 360) * 255 / 360
  671.       while tmp < 0
  672.         tmp += 255
  673.       end
  674.       if tmp < 85
  675.         g = tmp * 3
  676.         r = (85 - tmp) * 3
  677.       elsif tmp < 170
  678.         b = (tmp - 85) * 3
  679.         g = (170 - tmp) * 3
  680.       else
  681.         r = (tmp - 170) * 3
  682.         b = (255 - tmp) * 3
  683.       end
  684.       self.color.set(r, g, b)
  685.     when 7:
  686.       amnt = 10
  687.       amnt *= Math.sin(Math::PI * @frames / 30.0).abs
  688.       self.oy = self.bitmap.height / 2 + amnt - 5
  689.     when 8:
  690.       self.opacity = 255 - 170 * @frames / 20
  691.       @fplus = -1 if @frames == 20
  692.       @fplus = 1 if @frames == 0
  693.     end
  694.   end
  695. end
  696.  
Expand to see the code.



Instructions

You can configure default message options. Instructions on how to configure are in the script.
Instructions on the different message tags you can use are also in the script.
A dll is now required for the gradient text feature. It is found here.


Compatibility

Probably won't work with any other custom message scripts, but if you like, I'll try to tweak it to work with that specific script.


Credits and Thanks

  • ThallionDarkshine


Author's Notes

A dll is now required for the gradient text feature. It is found here.
Text animations! Can't believe I missed this thread, I haven't seen that done before. Very cool. I like the options you have for the letter by letter parts, too, very useful.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=77061