Advertisement
neutale

OneEyedEagle - Smooth Battle Log

Nov 14th, 2020 (edited)
2,155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.91 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Smooth Battle Log by OneEyedEagle (http://oneeyedeagle.lofter.com/)
  3. # ※ This script needs to be placed under [Draw Text Ex by OneEyedEagle]
  4. # License - MIT License: http://opensource.org/licenses/mit-license.php
  5. #==============================================================================
  6. # - 2020.7.23.22 Compatible with the new version of Draw Text Ex script
  7. #==============================================================================
  8. $imported ||= {}
  9. $imported["EAGLE-BattleLog"] = true
  10. #==============================================================================
  11. # - Improves default battlelog and implements a single line text sprite queue
  12. # - Battlelogs are updated in parallel, no more waiting and smooth text effect!
  13. #==============================================================================
  14.  
  15. class Window_BattleLog < Window_Selectable
  16.   #--------------------------------------------------------------------------
  17.   # ● Initialize
  18.   #--------------------------------------------------------------------------
  19.   def initialize
  20.     super(0, 0, Graphics.width, fitting_height(1))
  21.     self.opacity = 0
  22.     @lines = [] # Array of objects storing sprite block objects
  23.     @index = 0  # Position of the inserted new text block
  24.     @shift_count = 0 # Eliminates the wait count on the first line
  25.   end
  26.   #--------------------------------------------------------------------------
  27.   # ● Max line number
  28.   #--------------------------------------------------------------------------
  29.   def max_line_number
  30.     4
  31.   end
  32.   #--------------------------------------------------------------------------
  33.   # ● Auto shift frame
  34.   #--------------------------------------------------------------------------
  35.   def auto_shift_frame
  36.     150
  37.   end
  38.   #--------------------------------------------------------------------------
  39.   # ● Update
  40.   #--------------------------------------------------------------------------
  41.   def update
  42.     super
  43.     hide
  44.     return if @lines.empty?
  45.     @lines.each { |item| item.update }
  46.     @shift_count += 1
  47.     shift_text if @index >= max_line_number || @shift_count > auto_shift_frame
  48.     dispose_text if @lines[0].state == :fin
  49.   end
  50.   #--------------------------------------------------------------------------
  51.   # ● Add text
  52.   #--------------------------------------------------------------------------
  53.   def add_text(text)
  54.     return if text == ""
  55.     @lines.push(Window_Batterlog_Block.new(self, text, @lines.size))
  56.     @index += 1
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # ● Shift text
  60.   #--------------------------------------------------------------------------
  61.   def shift_text
  62.     return if @lines.empty?
  63.     @lines[0].state = :moveout if @lines[0].state == :movein
  64.   end
  65.   #--------------------------------------------------------------------------
  66.   # ● Dispose text
  67.   #--------------------------------------------------------------------------
  68.   def dispose_text
  69.     @shift_count = 0
  70.     @index -= 1
  71.     @lines.each { |item| item.index -= 1 }
  72.     @lines.shift.dispose
  73.   end
  74.   #--------------------------------------------------------------------------
  75.   # ● Dispose
  76.   #--------------------------------------------------------------------------
  77.   def dispose
  78.     super
  79.     @lines.each { |item| item.dispose }
  80.   end
  81.   #--------------------------------------------------------------------------
  82.   # ● Clear
  83.   #--------------------------------------------------------------------------
  84.   def clear
  85.   end
  86.   #--------------------------------------------------------------------------
  87.   # ● Clear (all)
  88.   #--------------------------------------------------------------------------
  89.   def clear_all
  90.     @lines.each { |item| item.state = :moveout }
  91.   end
  92.   #--------------------------------------------------------------------------
  93.   # ● Line number
  94.   #--------------------------------------------------------------------------
  95.   def line_number
  96.     @lines.size
  97.   end
  98.   #--------------------------------------------------------------------------
  99.   # ● Back one
  100.   #--------------------------------------------------------------------------
  101.   def back_one
  102.     shift_text
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   # ● Back to
  106.   #--------------------------------------------------------------------------
  107.   def back_to(line_number)
  108.   end
  109.   #--------------------------------------------------------------------------
  110.   # ● Replace text
  111.   #    Replace the last paragraph with the following.
  112.   #--------------------------------------------------------------------------
  113.   def replace_text(text)
  114.     add_text(text)
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # ● Last text
  118.   #--------------------------------------------------------------------------
  119.   def last_text
  120.     @lines.empty? ? "" : @lines[-1].text
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # ● Refresh
  124.   #--------------------------------------------------------------------------
  125.   def refresh
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # ● Wait
  129.   #--------------------------------------------------------------------------
  130.   def wait
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # ● Wait for effect
  134.   #--------------------------------------------------------------------------
  135.   def wait_for_effect
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # ● Wait and clear
  139.   # Minimum wait of message displayed and clear the message when wait is over.
  140.   #--------------------------------------------------------------------------
  141.   def wait_and_clear
  142.     clear
  143.   end
  144.   #--------------------------------------------------------------------------
  145.   # ● Damage display
  146.   #--------------------------------------------------------------------------
  147.   def display_damage(target, item)
  148.     if target.result.missed
  149.       display_miss(target, item)
  150.     elsif target.result.evaded
  151.       display_evasion(target, item)
  152.     else
  153.       return if defined?(SideView)
  154.       display_hp_damage(target, item)
  155.       display_mp_damage(target, item)
  156.       display_tp_damage(target, item)
  157.     end
  158.   end
  159. end
  160.  
  161. class Window_Batterlog_Block < Sprite
  162.   attr_accessor :index, :state
  163.   attr_reader :text
  164.   #--------------------------------------------------------------------------
  165.   # ● Initialization
  166.   #--------------------------------------------------------------------------
  167.   def initialize(window, text, index)
  168.     super(window.viewport)
  169.     @text = text
  170.     @index = index  #Automatically adjusts y position for text box.
  171.     @state = :movein
  172.     self.bitmap = Bitmap.new(Graphics.width, line_height)
  173.     self.x = -50
  174.     self.y = get_y
  175.     self.opacity = 0
  176.     refresh
  177.   end
  178.   #--------------------------------------------------------------------------
  179.   # ● Line height
  180.   #--------------------------------------------------------------------------
  181.   def line_height
  182.     Font.default_size + 4
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # ● Refresh
  186.   #--------------------------------------------------------------------------
  187.   def refresh
  188.     self.bitmap.clear
  189.     draw_background
  190.     draw_text
  191.   end
  192.   #--------------------------------------------------------------------------
  193.   # ● Draw background
  194.   #--------------------------------------------------------------------------
  195.   def draw_background
  196.     self.bitmap.gradient_fill_rect(self.bitmap.rect,
  197.       Color.new(0,0,0,64), Color.new(0,0,0,10))
  198.   end
  199.   #--------------------------------------------------------------------------
  200.   # ● Draw text
  201.   #--------------------------------------------------------------------------
  202.   def draw_text
  203.     reset_font_settings
  204.     d = Process_DrawTextEX.new(@text, {:x0 => 24, :y0 => 2}, self.bitmap)
  205.     d.run
  206.   end
  207.   #--------------------------------------------------------------------------
  208.   # ● Reset font settings
  209.   #--------------------------------------------------------------------------
  210.   def reset_font_settings
  211.     self.bitmap.font.color = Color.new(255,255,255)
  212.     self.bitmap.font.size = Font.default_size
  213.     self.bitmap.font.bold = false
  214.     self.bitmap.font.italic = false
  215.     self.bitmap.font.outline = false
  216.   end
  217.   #--------------------------------------------------------------------------
  218.   # ● Get Y
  219.   #--------------------------------------------------------------------------
  220.   def get_y
  221.     @index = 0 if @index < 0
  222.     @index * line_height + 10
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # ● Update Y
  226.   #--------------------------------------------------------------------------
  227.   def update_y
  228.     self.y -= 2 if self.y > get_y
  229.   end
  230.   #--------------------------------------------------------------------------
  231.   # ● Update X and opacity
  232.   #--------------------------------------------------------------------------
  233.   def update_x_and_opacity #Useful for initialization and exit
  234.     case @state
  235.     when :movein
  236.       self.opacity += 26
  237.       self.x += 4 if self.x < 0
  238.     when :moveout
  239.       self.opacity -= 26
  240.       self.x -= 4 if self.opacity > 0
  241.       @state = :fin if self.opacity <= 0
  242.     end
  243.   end
  244.   #--------------------------------------------------------------------------
  245.   # ● Update
  246.   #--------------------------------------------------------------------------
  247.   def update
  248.     super
  249.     update_x_and_opacity
  250.     update_y
  251.   end
  252.   #--------------------------------------------------------------------------
  253.   # ● Dispose
  254.   #--------------------------------------------------------------------------
  255.   def dispose
  256.     self.bitmap.dispose
  257.     super
  258.   end
  259. end
  260.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement