#============================================================================== # ★タイマー拡張 ver1.0 by USK #------------------------------------------------------------------------------ # ・タイマーのフォントや位置、背景を設定できます #============================================================================== =begin ・設定項目でタイマーの設定ができます。 ・背景ファイルはGraphics/Systemフォルダに用意してください。 ・背景を使わない場合はBackgroundPicture = "" ・ColorAValで指定した変数の値が0だとタイマーの数字が見えないので注意してください。 =end #-------------------------------------------------------------------------- # ● 設定項目 #-------------------------------------------------------------------------- module USK_Timer BackgroundPicture = "" # マップでのタイマーの背景ファイル名 BackgroundPictureB = "" # 戦闘時のタイマーの背景ファイル名 Divider = ":" # 分と秒の間の記号(1文字で) FontName = "VL Gothic" # 数字のフォント FontSize = 30 # マップでの数字の大きさ FontSizeB = 80 # 戦闘時の数字の大きさ PositionType = 1 # 0 => 左上基準, 1 => プレイヤー基準(マップ時) VariableX = 10 # マップでの基準からのX方向の位置を決める変数のID VariableY = 11 # マップでの基準からのY方向の位置を決める変数のID BgVariableX = 12 # マップでの背景の基準からのX方向の位置を決める変数のID BgVariableY = 13 # マップでの背景の基準からのY方向の位置を決める変数のID VariableXB = 18 # 戦闘時の左上からのX方向の位置を決める変数のID VariableYB = 19 # 戦闘時の左上からのY方向の位置を決める変数のID BgVariableXB = 20 # 戦闘時の背景の左上からのX方向の位置を決める変数のID BgVariableYB = 21 # 戦闘時の背景の左上からのY方向の位置を決める変数のID ColorRVal = 14 # 数字の色R成分を決める変数のID ColorGVal = 15 # 数字の色G成分を決める変数のID ColorBVal = 16 # 数字の色B成分を決める変数のID ColorAVal = 17 # 数字の色B成分を決める変数のID end #============================================================================== # ■ Sprite_Timer #============================================================================== class Sprite_Timer include USK_Timer #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias :usk_initialize :initialize def initialize(viewport) @battle = SceneManager.scene_is?(Scene_Battle) create_number create_background(viewport) usk_initialize(viewport) end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def create_background(viewport) @background = Sprite.new(viewport) bk = @battle ? BackgroundPictureB : BackgroundPicture @background.bitmap = Cache.system(bk) @background.visible = false end #-------------------------------------------------------------------------- # ● #-------------------------------------------------------------------------- def create_number size = @battle ? FontSizeB : FontSize font = Font.new(FontName, size) font.color.set($game_variables[ColorRVal], $game_variables[ColorGVal], $game_variables[ColorBVal]) @number = Cache.number(font) end #-------------------------------------------------------------------------- # ● 解放 #-------------------------------------------------------------------------- alias :usk_dispose :dispose def dispose usk_dispose @background.dispose end #-------------------------------------------------------------------------- # ● ビットマップの作成 #-------------------------------------------------------------------------- def create_bitmap @rect = Rect.new(0, 0, @number.width / 11, @number.height) self.bitmap = Bitmap.new(@rect.width * 5, @rect.height) self.ox = PositionType == 1 ? width >> 1 : 0 @background.ox = PositionType == 1 ? @background.width >> 1 : 0 end #-------------------------------------------------------------------------- # ● 再描画 #-------------------------------------------------------------------------- def redraw self.bitmap.clear @rect.x = 0 if ($game_variables[ColorRVal] != @number.font.color.red || $game_variables[ColorGVal] != @number.font.color.green || $game_variables[ColorBVal] != @number.font.color.blue || $game_variables[ColorAVal] != @number.font.color.alpha) @number.dispose @number = nil create_number end src = Rect.new.set(@rect) m = @total_sec / 60 s = @total_sec % 60 [m / 10, m % 10, 10, s / 10, s % 10].each do |i| src.x = src.width * i self.bitmap.blt(@rect.x, 0, @number, src) @rect.x += @rect.width end end #-------------------------------------------------------------------------- # ● 位置の更新 #-------------------------------------------------------------------------- def update_position if @battle @background.ox = self.ox = 0 self.x = $game_variables[VariableXB] self.y = $game_variables[VariableYB] @background.x = $game_variables[BgVariableXB] @background.y = $game_variables[BgVariableYB] else case PositionType when 1 self.x = $game_player.screen_x + $game_variables[VariableX] self.y = $game_player.screen_y + $game_variables[VariableY] @background.x = $game_player.screen_x + $game_variables[BgVariableX] @background.y = $game_player.screen_y + $game_variables[BgVariableY] else self.x = $game_variables[VariableX] self.y = $game_variables[VariableY] @background.x = $game_variables[BgVariableX] @background.y = $game_variables[BgVariableY] end end @background.z = 199 self.z = 200 end #-------------------------------------------------------------------------- # ● 可視状態の更新 #-------------------------------------------------------------------------- def update_visibility @background.visible = self.visible = $game_timer.working? end end #============================================================================== # ■ Cache #============================================================================== module Cache #-------------------------------------------------------------------------- # ● ビットマップの読み込み #-------------------------------------------------------------------------- def self.number(font = Font.new) @cache ||= {} unless include?([font.name, font.size]) number = "0123456789" + USK_Timer::Divider temp = empty_bitmap temp.font = font rect = temp.text_size("0") temp.dispose @cache[[font.name, font.size]] = Bitmap.new(rect.width * 11, rect.height) @cache[[font.name, font.size]].font = font number.chars do |c| @cache[[font.name, font.size]].draw_text(rect, c, 1) rect.x += rect.width end end @cache[[font.name, font.size]] end end