#============================================================================== # ■ Window_NameEdit #------------------------------------------------------------------------------ #  名前入力画面で、名前を編集するウィンドウです。 #============================================================================== class Window_NameEdit < Window_Base #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :max_char #-------------------------------------------------------------------------- # ● オブジェクト初期化 # value : 指定オブジェクト # max_char : 最大文字数 #-------------------------------------------------------------------------- def initialize(obj, max_char) super(0, 0, 640, 128) self.contents = Bitmap.new(width - 32, height - 32) obj_set(obj, max_char) end #-------------------------------------------------------------------------- # ● オブジェクト変更 #-------------------------------------------------------------------------- def obj_set(obj, max_char = 16) @obj = obj @name = (obj.class.method_defined?("name") ? obj.name : "") @name = (obj.is_a?(String) ? obj : "") @max_char = max_char # 名前を最大文字数以内に収める name_array = @name.split(//)[0...@max_char] @name = "" for i in 0...name_array.size @name += name_array[i] end @default_name = @name @index = name_array.size refresh update_cursor_rect end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.contents.clear # 名前を描画 name_array = @name.split(//) for i in 0...@max_char c = name_array[i] if c == nil c = "_" end x = 320 - @max_char * 14 + i * 28 self.contents.draw_text(x, 32, 28, 32, c, 1) end # グラフィックを描画 if @obj.class.method_defined?("battler_name") draw_actor_graphic(@actor, 320 - [@max_char, 16].min * 14 - 40, 80) elsif @obj.class.method_defined?("icon_name") icon = RPG::Cache.icon(@obj.icon_name) self.contents.blt(320 - [@max_char, 16].min * 14 - 28, 32, icon, Rect.new(0, 0, 24, 24)) end end end #============================================================================== # ■ Scene_Map #------------------------------------------------------------------------------ #  マップ画面の処理を行うクラスです。 #============================================================================== class Scene_Map #-------------------------------------------------------------------------- # ● 名前入力の呼び出し #-------------------------------------------------------------------------- def call_name # 名前入力呼び出しフラグをクリア $game_temp.name_calling = false # プレイヤーの姿勢を矯正 $game_player.straighten # 名前入力画面に切り替え $scene = Scene_Name.new($game_actors[$game_temp.name_actor_id], $game_temp.name_max_char, self.class) end end #============================================================================== # ■ Scene_Name #------------------------------------------------------------------------------ #  名前入力画面の処理を行うクラスです。 #============================================================================== class Scene_Name #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(type, method, char, prev, index = -1) @type = type @method = method @char = char @prev_class = prev @prev_index = index end #-------------------------------------------------------------------------- # ● メイン処理 #-------------------------------------------------------------------------- def main # ウィンドウを作成 @edit_window = Window_NameEdit.new(@type, @char) @input_window = Window_NameInput.new # トランジション実行 Graphics.transition # メインループ loop do # ゲーム画面を更新 Graphics.update # 入力情報を更新 Input.update # フレーム更新 update # 画面が切り替わったらループを中断 if $scene != self break end end # トランジション準備 Graphics.freeze # ウィンドウを解放 @edit_window.dispose @input_window.dispose end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update # ウィンドウを更新 @edit_window.update @input_window.update # B ボタンが押された場合 if Input.repeat?(Input::B) # カーソル位置が 0 の場合 if @edit_window.index == 0 return end # キャンセル SE を演奏 $game_system.se_play($data_system.cancel_se) # 文字を削除 @edit_window.back return end # C ボタンが押された場合 if Input.trigger?(Input::C) # カーソル位置が [決定] の場合 if @input_window.character == nil # 名前が空の場合 if @edit_window.name == "" # デフォルトの名前に戻す @edit_window.restore_default # 名前が空の場合 if @edit_window.name == "" # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) return end # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) return end # 名前を変更 eval("#{@type}.#{method} = @edit_window.name") # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) # マップ画面に切り替え if @prev_index >= 0 $scene = @prev_class.new(@prev_index) else $scene = @prev_class.new end return end # カーソル位置が最大の場合 if @edit_window.index == @char # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) return end # 文字が空の場合 if @input_window.character == "" # ブザー SE を演奏 $game_system.se_play($data_system.buzzer_se) return end # 決定 SE を演奏 $game_system.se_play($data_system.decision_se) # 文字を追加 @edit_window.add(@input_window.character) return end end end