Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #== Szyu Scripts presents =====================================================
- # * Szyu Scripts' Simple Loading Bar
- # Version 1.0
- # by Szyu
- #
- #== About =====================================================================
- # * This script adds a pseudo loading bar/screen to your game.
- #
- #== How to Use ================================================================
- # * Where you want to use the loading bar, create initiate a new object from
- # Window_LoadingBar:
- # @window_loading_bar = Window_LoadingBar.new((Graphics.width-120)/2,
- # (Graphics.height-48)/2,120,48,method(:on_finished))
- #
- # * In the on_finished method, dispose of the object like
- # def on_finished
- # @window_loading_bar.close.dispose
- # @window_loading_bar = nil
- # # do other stuff here when finished loading
- # end
- #
- # * You can adjust the speed of the loading bar by setting the progress_speed:
- # @window_loading_bar.progress_speed = x # default is 2
- #
- #== Terms of Use ==============================================================
- # * You are free to use this script for commercial and non-commercial projects.
- # However I'd like you to inform me of the projects you are planning to use it
- # in, so I can keep track of where my scripts are used.
- #
- #== Import ====================================================================
- $imported = {} if $imported.nil?
- $imported["SZ_LoadingBar"] = true
- #==============================================================================
- #==============================================================================
- # ** Window_Loading
- #==============================================================================
- class Window_LoadingBar < Window_Base
- attr_accessor :progress
- attr_reader :finished
- #--------------------------------------------------------------------------
- # * Initialize
- #--------------------------------------------------------------------------
- def initialize(x,y,w, h, on_finished_prc)
- super(x,y,w,h)
- @progress = 0
- @finished = false
- @on_finished = on_finished_prc
- @progress_speed = 2
- refresh
- end
- #--------------------------------------------------------------------------
- # * Set Progress Speed
- #--------------------------------------------------------------------------
- def progress_speed=(speed)
- @progress_speed = speed
- end
- #--------------------------------------------------------------------------
- # * Update
- #--------------------------------------------------------------------------
- def update
- super
- return if @finished
- @progress += @progress_speed
- refresh
- if @progress >= 100
- @finished = true
- @on_finished.call if @on_finished
- end
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- contents.clear
- h = line_height
- draw_loading_gauge(0,(contents.height-h)/2,width,h, @progress.to_f/100, hp_gauge_color1, hp_gauge_color2)
- end
- #--------------------------------------------------------------------------
- # * Draw Loading Gauge
- #--------------------------------------------------------------------------
- def draw_loading_gauge(x, y, width, height, rate, color1, color2)
- fill_w = (width * rate).to_i
- gauge_y = y
- contents.fill_rect(x, gauge_y, width, line_height, gauge_back_color)
- contents.gradient_fill_rect(x, gauge_y, fill_w, line_height, color1, color2)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement