class Loading_Screen < Sprite def initialize super(nil) @count = 0 @index=rand(4) @countTar = 17 #update rate @cloak = [true,false].sample @imported_text = "" @progress_total = nil @progress_now = 0 @progress_text = nil @progress_last_redraw = nil genPIC end def genPIC @importTextSprite = Sprite.new @importTextSprite.bitmap = Bitmap.new(Graphics.width,30) @importTextSprite_rect = Rect.new(0,0,Graphics.width,30) @importTextSprite.bitmap.clear_rect(@importTextSprite_rect) @importTextSprite.bitmap.font.outline = false @importTextSprite.bitmap.font.size = 12 @importTextSprite.bitmap.font.bold = true @importTextSprite.y = Graphics.height-40#/2+@aniPic0.height/3 @importTextSprite.bitmap.draw_text(-4, 0,Graphics.width,40,@imported_text,1) if $TEST @testSprite = Sprite.new @testSprite.bitmap = Bitmap.new(70,30)#(Graphics.width,Graphics.height) @testSprite_rect = Rect.new(0,0,70,30) @testSprite.bitmap.clear_rect(@testSprite_rect) @testSprite.bitmap.font.outline = false @testSprite.bitmap.font.size = 14 @testSprite.bitmap.draw_text(8, -10,70,40,"DEV MODE",0) end @aniPic0 = Sprite.new @aniPic1 = Sprite.new @aniPic2 = Sprite.new @aniPic3 = Sprite.new @aniPic0.opacity = 0 if @aniPic0 @aniPic1.opacity = 0 if @aniPic1 @aniPic2.opacity = 0 if @aniPic2 @aniPic3.opacity = 0 if @aniPic3 if @cloak @aniPic0.bitmap = Bitmap.new("Graphics/System/LoadingScreenCloak0.png") @aniPic1.bitmap = Bitmap.new("Graphics/System/LoadingScreenCloak1.png") @aniPic2.bitmap = Bitmap.new("Graphics/System/LoadingScreenCloak2.png") @aniPic3.bitmap = Bitmap.new("Graphics/System/LoadingScreenCloak3.png") else @aniPic0.bitmap = Bitmap.new("Graphics/System/LoadingScreenFrame0.png") @aniPic1.bitmap = Bitmap.new("Graphics/System/LoadingScreenFrame1.png") @aniPic2.bitmap = Bitmap.new("Graphics/System/LoadingScreenFrame2.png") @aniPic3.bitmap = Bitmap.new("Graphics/System/LoadingScreenFrame3.png") end tmpX=Graphics.width/2 - (@aniPic0.width)/2 tmpY=Graphics.height/2 - (@aniPic0.height)/2 @aniPic0.x = tmpX @aniPic1.x = tmpX @aniPic2.x = tmpX @aniPic3.x = tmpX @aniPic0.y = tmpY @aniPic1.y = tmpY @aniPic2.y = tmpY @aniPic3.y = tmpY @aniPic0.z = 1000 @aniPic1.z = 1000 @aniPic2.z = 1000 @aniPic3.z = 1000 end def hide @aniPic0.opacity = 0 @aniPic1.opacity = 0 @aniPic2.opacity = 0 @aniPic3.opacity = 0 end def show @aniPic0.opacity = 255 @aniPic1.opacity = 0 @aniPic2.opacity = 0 @aniPic3.opacity = 0 end def next_pic case @index when 0 ; @aniPic0.opacity = 255 ; @aniPic1.opacity = 0 ; @aniPic2.opacity = 0 ; @aniPic3.opacity = 0 when 1 ; @aniPic1.opacity = 255 ; @aniPic0.opacity = 0 ; @aniPic2.opacity = 0 ; @aniPic3.opacity = 0 when 2 ; @aniPic2.opacity = 255 ; @aniPic0.opacity = 0 ; @aniPic1.opacity = 0 ; @aniPic1.opacity = 0 when 3 ; @aniPic3.opacity = 255 ; @aniPic0.opacity = 0 ; @aniPic1.opacity = 0 ; @aniPic2.opacity = 0 end @index += 1 @index = 0 if @index >= 4 end def next_text(tmp_text=nil) return if !tmp_text if @imported_text != tmp_text.upcase @imported_text = tmp_text.upcase @importTextSprite.bitmap.clear_rect(@importTextSprite_rect) @importTextSprite.bitmap.draw_text(0, 0,Graphics.width,40,@imported_text,1) Graphics.update end end def update(tmp_text) @count += 1 next_text(tmp_text) if @count >= @countTar next_pic Graphics.update @count = 0 end end def progress_active? !@progress_total.nil? end def begin_progress(total, text = "Загрузка...") @progress_total = [total.to_i, 1].max @progress_now = 0 @progress_text = text.to_s @progress_last_redraw = nil ensure_progress_sprite redraw_progress(true) end def step_progress(text = nil, inc = 1) return unless progress_active? @progress_text = text.to_s if text @progress_now = [@progress_now + inc.to_i, @progress_total].min redraw_progress(false) end def set_progress(done, total = nil, text = nil) @progress_total = [total.to_i, 1].max if total return unless progress_active? @progress_now = [[done.to_i, 0].max, @progress_total].min @progress_text = text.to_s if text redraw_progress(true) end def finish_progress(text = nil) return unless progress_active? @progress_now = @progress_total @progress_text = text.to_s if text redraw_progress(true) end def ensure_progress_sprite return if @progressSprite && !@progressSprite.disposed? @progressSprite = Sprite.new @progressSprite.z = 2001 @progressSprite.bitmap = Bitmap.new(Graphics.width, 78) @progressRect = Rect.new(0, 0, Graphics.width, 78) @progressSprite.y = Graphics.height - 112 @progressPercentSprite = Sprite.new @progressPercentSprite.z = 2002 @progressPercentSprite.bitmap = Bitmap.new(Graphics.width, 26) @progressPercentRect = Rect.new(0, 0, Graphics.width, 26) @progressPercentSprite.y = @progressSprite.y - 18 @progressPercentSprite.bitmap.font.name = "Unifont" @progressPercentSprite.bitmap.font.size = 16 @progressPercentSprite.bitmap.font.bold = false @progressPercentSprite.bitmap.font.outline = false @progressPercentSprite.bitmap.font.color = Color.new(255, 255, 255) end def redraw_progress(force = false) return unless progress_active? now = begin Process.clock_gettime(Process::CLOCK_MONOTONIC) rescue StandardError Time.now.to_f end return if !force && @progress_last_redraw && (now - @progress_last_redraw) < 0.05 @progress_last_redraw = now ensure_progress_sprite ratio = @progress_total.to_i > 0 ? (@progress_now.to_f / @progress_total.to_f) : 0.0 ratio = [[ratio, 0.0].max, 1.0].min percent = (ratio * 100).to_i next_text(@progress_text) pbmp = @progressPercentSprite.bitmap pbmp.clear_rect(@progressPercentRect) pbmp.font.name = "Unifont" pbmp.font.size = 16 pbmp.font.bold = false pbmp.font.outline = false pbmp.font.color = Color.new(255, 255, 255) pbmp.draw_text(0, 0, Graphics.width, 24, "#{percent}%", 1) bmp = @progressSprite.bitmap bmp.clear_rect(@progressRect) x = 70 y = 28 w = Graphics.width - 140 h = 11 border = 2 # внешняя обводка, чтобы был виден конец полосы bmp.fill_rect(x - border, y - border, w + border * 2, h + border * 2, Color.new(92, 92, 92, 255)) # тёмная подложка пустой части bmp.fill_rect(x, y, w, h, Color.new(74, 74, 74, 255)) # внутренняя зелёная подложка bmp.fill_rect(x + 3, y + 3, w - 6, h - 5, Color.new(101, 188, 24, 255)) # основная яркая заливка прогресса fill_w = (w * ratio).to_i bmp.fill_rect(x, y, fill_w, h, Color.new(126, 255, 0, 255)) if fill_w > 0 # нижний внутренний тон поверх прогресса inner_fill_w = [[fill_w - 5, 0].max, w - 6].min bmp.fill_rect(x + 3, y + 3, inner_fill_w, h - 5, Color.new(101, 188, 24, 255)) if inner_fill_w > 0 Graphics.update end def dispose if @progressSprite if @progressSprite.bitmap && !@progressSprite.bitmap.disposed? @progressSprite.bitmap.dispose end @progressSprite.dispose unless @progressSprite.disposed? @progressSprite = nil end if @progressPercentSprite if @progressPercentSprite.bitmap && !@progressPercentSprite.bitmap.disposed? @progressPercentSprite.bitmap.dispose end @progressPercentSprite.dispose unless @progressPercentSprite.disposed? @progressPercentSprite = nil end @aniPic0.dispose if @aniPic0 @aniPic1.dispose if @aniPic1 @aniPic2.dispose if @aniPic2 @aniPic3.dispose if @aniPic3 @importTextSprite.dispose if @importTextSprite @testSprite.dispose if @testSprite super end end $loading_screen = Loading_Screen.new