Permanent
Creation

RPGツクールXP/VX用のRGSS素材です。
一部英語版対応です。 (A few materials can be used for English RPG MAKER XP/VX.)
競合率はルファーの独断と偏見なのでたまにハズレます。


#==============================================================================
# ■ ダイナミックメッセージ
#------------------------------------------------------------------------------
#  文章ウィンドウを動的に"流し"ます。シェイク機能を装備。
# (C)     ルファー
# WebSite https://tkoolerlufar.pages.dev/
#==============================================================================

=begin
  =対応RGSS
  1

  =他の素材との競合の可能性
  !!. それなりに気をつけてるけど、文章ウィンドウ改造系スクリプトとはいまいち?

  =導入方法
  Interpreter 3より下に新セクションを作成して、このプログラムをそこにコピーする

  =シェイク方法
  イベントコマンド「スクリプト」で、
    $game_temp.message_vshake = true
  という処理を入れると、次回の文章コマンドで文章ウィンドウが縦に振動します。
  同様に、
    $game_temp.message_hshake = true
  という処理を入れると、次回の文章コマンドで文章ウィンドウが横に振動します。
  また、
    $game_temp.message_hshake = true
    $game_temp.message_vshake = true
  という処理を入れると、次回の文章コマンドで文章ウィンドウが斜めに振動します。

  =備考
  「ワイドモード」に対応してます。

  =更新履歴
  2010/09/08 滑らかモードOFFのときにウィンドウが全く縦振動しない仕様を修正
             この仕様変更に伴い円運動機能を廃止、代わりに斜め振動機能を実装
             新規定義しているメソッド・プロパティの誤表記を修正

  2010/03/01 公開

  =再定義しているメソッド
  Game_Temp#initialize (エイリアス使用)
  Window_Message#initialize (エイリアス使用)
  Window_Message#terminate_message (エイリアス使用)
  Window_Message#refresh (エイリアス使用)
  Window_Message#update (エイリアス使用)
  Interpreter#command_104 (エイリアス使用)

  =新規定義しているメソッド
  Window_Message#_Lufar12_UpdateShake

  =再定義しているプロパティ
  Window_Message#x (エイリアス使用)
  Window_Message#y (エイリアス使用)

  =新規定義しているプロパティ
  Game_Temp#message_hshake
  Game_Temp#message_vshake
  Window_Message#_Lufar12_RealX
  Window_Message#_Lufar12_RealY
=end
#----------------------------------------------------------------------------
# ◆ Game_Temp クラス
#----------------------------------------------------------------------------
class Game_Temp
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_accessor :message_hshake           ## メッセージ 水平シェイクフラグ
  attr_accessor :message_vshake           ## メッセージ 垂直シェイクフラグ
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  alias _Lufar12_PrototypeOfInit initialize
  def initialize
    _Lufar12_PrototypeOfInit()
    @message_hshake = false
    @message_vshake = false
  end
end
#----------------------------------------------------------------------------
# ◆ Window_Message クラス
#----------------------------------------------------------------------------
class Window_Message < Window_Selectable
  #--------------------------------------------------------------------------
  # ○ 定数
  #--------------------------------------------------------------------------
  WIDTH = 480                             ## 幅
  HEIGHT = 160                            ## 高さ
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  alias _Lufar12_PrototypeOfInit initialize
  def initialize
    @x = 0
    @y = 0
    @shake_x = 0
    @shake_y = 0
    @real_x = 0
    @real_y = 0
    _Lufar12_PrototypeOfInit()
    @gold_window         = nil unless defined? @gold_window
    @input_number_window = nil unless defined? @input_number_window
    @x_velocity = 0
    @y_velocity = 0
    self.ox = 0
    self.oy = 0
    self.width = WIDTH
    self.height = HEIGHT
    @fade_in_duration = 0
    @hshake = false
    @vshake = false
  end
  #--------------------------------------------------------------------------
  # ○ 座標の取得・設定
  #--------------------------------------------------------------------------
  alias _Lufar12_RealX  x  unless method_defined?(:_Lufar12_RealX)
  alias _Lufar12_RealY  y  unless method_defined?(:_Lufar12_RealY)
  alias _Lufar12_RealX= x= unless method_defined?(:_Lufar12_RealX=)
  alias _Lufar12_RealY= y= unless method_defined?(:_Lufar12_RealY=)
  def x
    @x
  end
  def y
    @y
  end
  def real_x
    @real_x
  end
  def real_y
    @real_y
  end
  def x=(val)
    @x = val
    @x_velocity = (x - real_x) / (Graphics.frame_rate / 10 + 4)
    if @x_velocity == 0
      @x_velocity = +1 if x < real_x
      @x_velocity = -1 if x > real_x
    end
  end
  def y=(val)
    @y = val
    @y_velocity = (y - real_y) / (Graphics.frame_rate / 10 + 4)
    if @y_velocity == 0
      @y_velocity = +1 if y < real_y
      @y_velocity = -1 if y > real_y
    end
  end
  def real_x=(val)
    @real_x = val
    self._Lufar12_RealX = @real_x + @shake_x
  end
  def real_y=(val)
    @real_y = val
    self._Lufar12_RealY = @real_y + @shake_y
  end
  #--------------------------------------------------------------------------
  # ● メッセージ終了処理
  #--------------------------------------------------------------------------
  alias _Lufar12_PrototypeOfTermination terminate_message
  def terminate_message
    _Lufar12_PrototypeOfTermination
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  alias _Lufar12_PrototypeOfRefreshment refresh
  def refresh
    @hshake = $game_temp.message_hshake
    $game_temp.message_hshake = false
    @vshake = $game_temp.message_vshake
    $game_temp.message_vshake = false
    @message_position = $game_temp.in_battle ? 0 : $game_system.message_position
    _Lufar12_ResetRealPosition
    reset_window
    @fade_in_duration = 16
    _Lufar12_UpdateShake
    _Lufar12_PrototypeOfRefreshment
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  alias _Lufar12_PrototypeOfUpdating update
  def update
    self.real_x += @x_velocity
    self.real_y += @y_velocity
    if(@x_velocity > 0 && self.real_x > @x ||
       @x_velocity < 0 && self.real_x < @x)
      self.real_x = @x
    end
    if(@y_velocity > 0 && self.real_y > @y ||
       @y_velocity < 0 && self.real_y < @y)
      self.real_y = @y
    end
    @x_velocity = 0 if self.real_x == @x
    @y_velocity = 0 if self.real_y == @y
    ## フェードイン?
    if @fade_in
      @fade_in_duration -= 1
      if @fade_in_duration <= 0
        @hshake = @vshake = false
        @fade_in = false
      end
      _Lufar12_UpdateShake
      self.contents_opacity = 255
      self.contents_opacity -= @fade_in_duration * 15 unless @hshake || @vshake
      return if @fade_in_duration > 0
    end
    # フレーム更新
    _Lufar12_PrototypeOfUpdating
    self.contents_opacity = 0xFF if @fade_in and @hshake || @vshake
    ## フェードアウト?
    if @fade_out
      self.x = 640 if @x_velocity == 0
      self.opacity = 255
      if real_x >= 640 or real_x <= -WIDTH or
         real_y >= 480 or real_y <= -HEIGHT
        self.visible = false
        @fade_out = false
        $game_temp.message_window_showing = false
      end
    end
  end
  #--------------------------------------------------------------------------
  # ○ 実座標リセット
  #--------------------------------------------------------------------------
  def _Lufar12_ResetRealPosition
    if $game_system.message_frame != 0 or @hshake or @vshake
      self.real_x = (640 - WIDTH) / 2
      case @message_position
      when 0  # 上
        self.real_y = 16
      when 1  # 中
        self.real_y = (480 - HEIGHT) / 2
      when 2  # 下
        self.real_y = 464 - HEIGHT
      end
      if (defined? Lufar::WIDEMODE) and $game_screen.wide
        case @message_position
        when 0  # 上
          self.real_y += 60
        when 2  # 下
          self.real_y -= 60
        end
      end
    elsif !self.visible
      case @message_position
      when 0  # 上
        self.real_x = (640 - WIDTH) / 2
        self.real_y = -HEIGHT
      when 1  # 中
        self.real_x = -WIDTH
        self.real_y = (480 - HEIGHT) / 2
      when 2  # 下
        self.real_x = (640 - WIDTH) / 2
        self.real_y = 480
      end
    end
    self.x = (640 - WIDTH) / 2
  end
  #--------------------------------------------------------------------------
  # ○ シェイク更新
  #--------------------------------------------------------------------------
  def _Lufar12_UpdateShake
    @shake_x = if @hshake then case Graphics.frame_count & 0b11
      when 0     then +(@fade_in_duration + 1 & ~1)
      when 1, 3  then                             0
      when 2     then -(@fade_in_duration + 1 & ~1)
      end; else                                   0
    end
    @shake_y = if @vshake then case Graphics.frame_count & 0b11
      when 0     then +(@fade_in_duration + 1 & ~1)
      when 1, 3  then                             0
      when 2     then -(@fade_in_duration + 1 & ~1)
      end; else                                   0
    end
    self.real_x = real_x
    self.real_y = real_y
  end
end
#----------------------------------------------------------------------------
# ◆ Interpreter クラス
#----------------------------------------------------------------------------
class Interpreter
  #--------------------------------------------------------------------------
  # ● 文章オプション変更
  #--------------------------------------------------------------------------
  alias _Lufar12_PrototypeOfCommand104 command_104
  def command_104
    if _Lufar12_PrototypeOfCommand104
      return true
    end
    # 各オプションを変更
    $game_system.message_position = @parameters[0]
    $game_system.message_frame = @parameters[1]
    # 継続
    return true
  end
end

戻る