Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ■ Smooth Battle Log by OneEyedEagle (http://oneeyedeagle.lofter.com/)
- # ※ This script needs to be placed under [Draw Text Ex by OneEyedEagle]
- # License - MIT License: http://opensource.org/licenses/mit-license.php
- #==============================================================================
- # - 2020.7.23.22 Compatible with the new version of Draw Text Ex script
- #==============================================================================
- $imported ||= {}
- $imported["EAGLE-BattleLog"] = true
- #==============================================================================
- # - Improves default battlelog and implements a single line text sprite queue
- # - Battlelogs are updated in parallel, no more waiting and smooth text effect!
- #==============================================================================
- class Window_BattleLog < Window_Selectable
- #--------------------------------------------------------------------------
- # ● Initialize
- #--------------------------------------------------------------------------
- def initialize
- super(0, 0, Graphics.width, fitting_height(1))
- self.opacity = 0
- @lines = [] # Array of objects storing sprite block objects
- @index = 0 # Position of the inserted new text block
- @shift_count = 0 # Eliminates the wait count on the first line
- end
- #--------------------------------------------------------------------------
- # ● Max line number
- #--------------------------------------------------------------------------
- def max_line_number
- 4
- end
- #--------------------------------------------------------------------------
- # ● Auto shift frame
- #--------------------------------------------------------------------------
- def auto_shift_frame
- 150
- end
- #--------------------------------------------------------------------------
- # ● Update
- #--------------------------------------------------------------------------
- def update
- super
- hide
- return if @lines.empty?
- @lines.each { |item| item.update }
- @shift_count += 1
- shift_text if @index >= max_line_number || @shift_count > auto_shift_frame
- dispose_text if @lines[0].state == :fin
- end
- #--------------------------------------------------------------------------
- # ● Add text
- #--------------------------------------------------------------------------
- def add_text(text)
- return if text == ""
- @lines.push(Window_Batterlog_Block.new(self, text, @lines.size))
- @index += 1
- end
- #--------------------------------------------------------------------------
- # ● Shift text
- #--------------------------------------------------------------------------
- def shift_text
- return if @lines.empty?
- @lines[0].state = :moveout if @lines[0].state == :movein
- end
- #--------------------------------------------------------------------------
- # ● Dispose text
- #--------------------------------------------------------------------------
- def dispose_text
- @shift_count = 0
- @index -= 1
- @lines.each { |item| item.index -= 1 }
- @lines.shift.dispose
- end
- #--------------------------------------------------------------------------
- # ● Dispose
- #--------------------------------------------------------------------------
- def dispose
- super
- @lines.each { |item| item.dispose }
- end
- #--------------------------------------------------------------------------
- # ● Clear
- #--------------------------------------------------------------------------
- def clear
- end
- #--------------------------------------------------------------------------
- # ● Clear (all)
- #--------------------------------------------------------------------------
- def clear_all
- @lines.each { |item| item.state = :moveout }
- end
- #--------------------------------------------------------------------------
- # ● Line number
- #--------------------------------------------------------------------------
- def line_number
- @lines.size
- end
- #--------------------------------------------------------------------------
- # ● Back one
- #--------------------------------------------------------------------------
- def back_one
- shift_text
- end
- #--------------------------------------------------------------------------
- # ● Back to
- #--------------------------------------------------------------------------
- def back_to(line_number)
- end
- #--------------------------------------------------------------------------
- # ● Replace text
- # Replace the last paragraph with the following.
- #--------------------------------------------------------------------------
- def replace_text(text)
- add_text(text)
- end
- #--------------------------------------------------------------------------
- # ● Last text
- #--------------------------------------------------------------------------
- def last_text
- @lines.empty? ? "" : @lines[-1].text
- end
- #--------------------------------------------------------------------------
- # ● Refresh
- #--------------------------------------------------------------------------
- def refresh
- end
- #--------------------------------------------------------------------------
- # ● Wait
- #--------------------------------------------------------------------------
- def wait
- end
- #--------------------------------------------------------------------------
- # ● Wait for effect
- #--------------------------------------------------------------------------
- def wait_for_effect
- end
- #--------------------------------------------------------------------------
- # ● Wait and clear
- # Minimum wait of message displayed and clear the message when wait is over.
- #--------------------------------------------------------------------------
- def wait_and_clear
- clear
- end
- #--------------------------------------------------------------------------
- # ● Damage display
- #--------------------------------------------------------------------------
- def display_damage(target, item)
- if target.result.missed
- display_miss(target, item)
- elsif target.result.evaded
- display_evasion(target, item)
- else
- return if defined?(SideView)
- display_hp_damage(target, item)
- display_mp_damage(target, item)
- display_tp_damage(target, item)
- end
- end
- end
- class Window_Batterlog_Block < Sprite
- attr_accessor :index, :state
- attr_reader :text
- #--------------------------------------------------------------------------
- # ● Initialization
- #--------------------------------------------------------------------------
- def initialize(window, text, index)
- super(window.viewport)
- @text = text
- @index = index #Automatically adjusts y position for text box.
- @state = :movein
- self.bitmap = Bitmap.new(Graphics.width, line_height)
- self.x = -50
- self.y = get_y
- self.opacity = 0
- refresh
- end
- #--------------------------------------------------------------------------
- # ● Line height
- #--------------------------------------------------------------------------
- def line_height
- Font.default_size + 4
- end
- #--------------------------------------------------------------------------
- # ● Refresh
- #--------------------------------------------------------------------------
- def refresh
- self.bitmap.clear
- draw_background
- draw_text
- end
- #--------------------------------------------------------------------------
- # ● Draw background
- #--------------------------------------------------------------------------
- def draw_background
- self.bitmap.gradient_fill_rect(self.bitmap.rect,
- Color.new(0,0,0,64), Color.new(0,0,0,10))
- end
- #--------------------------------------------------------------------------
- # ● Draw text
- #--------------------------------------------------------------------------
- def draw_text
- reset_font_settings
- d = Process_DrawTextEX.new(@text, {:x0 => 24, :y0 => 2}, self.bitmap)
- d.run
- end
- #--------------------------------------------------------------------------
- # ● Reset font settings
- #--------------------------------------------------------------------------
- def reset_font_settings
- self.bitmap.font.color = Color.new(255,255,255)
- self.bitmap.font.size = Font.default_size
- self.bitmap.font.bold = false
- self.bitmap.font.italic = false
- self.bitmap.font.outline = false
- end
- #--------------------------------------------------------------------------
- # ● Get Y
- #--------------------------------------------------------------------------
- def get_y
- @index = 0 if @index < 0
- @index * line_height + 10
- end
- #--------------------------------------------------------------------------
- # ● Update Y
- #--------------------------------------------------------------------------
- def update_y
- self.y -= 2 if self.y > get_y
- end
- #--------------------------------------------------------------------------
- # ● Update X and opacity
- #--------------------------------------------------------------------------
- def update_x_and_opacity #Useful for initialization and exit
- case @state
- when :movein
- self.opacity += 26
- self.x += 4 if self.x < 0
- when :moveout
- self.opacity -= 26
- self.x -= 4 if self.opacity > 0
- @state = :fin if self.opacity <= 0
- end
- end
- #--------------------------------------------------------------------------
- # ● Update
- #--------------------------------------------------------------------------
- def update
- super
- update_x_and_opacity
- update_y
- end
- #--------------------------------------------------------------------------
- # ● Dispose
- #--------------------------------------------------------------------------
- def dispose
- self.bitmap.dispose
- super
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement