=begin ◆概要 ひきも記様「FC版DQ3風スクリプト」で名前入力画面もDQ3風ウィンドウにします。 ◆機能 ・導入するだけでそれっぽくなります。 ・デフォルトから色とかも変えました。 ◆仕様 ・「かな」「カナ」「決定」はカーソルが被ります。 ◆使用上の注意 ・一番下に置いたときのみ動作を確認しています。 ・ひきも記様の利用規約に従って使用してください。 =end #============================================================================== # ■ DQWindow_NameEdit #============================================================================== class DQWindow_NameEdit < DQWindow #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :name # 名前 attr_reader :index # カーソル位置 attr_reader :max_char # 最大文字数 attr_accessor :active # アクティブフラグ #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(actor, max_char) super(88, 20, 368, 128) @actor = actor @name = actor.name @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 self.active = false refresh update_cursor end #-------------------------------------------------------------------------- # ● デフォルトの名前に戻す #-------------------------------------------------------------------------- def restore_default @name = @default_name @index = @name.split(//).size refresh update_cursor end #-------------------------------------------------------------------------- # ● 文字の追加 #-------------------------------------------------------------------------- def add(character) if @index < @max_char and character != "" @name += character @index += 1 refresh update_cursor end end #-------------------------------------------------------------------------- # ● 文字の削除 #-------------------------------------------------------------------------- def back if @index > 0 name_array = @name.split(//) # 一字削除 @name = "" for i in 0...name_array.size-1 @name += name_array[i] end @index -= 1 refresh update_cursor end end #-------------------------------------------------------------------------- # ● 項目を描画する矩形の取得 #-------------------------------------------------------------------------- def item_rect(index) rect = Rect.new(0, 0, 0, 0) rect.x = 220 - (@max_char + 1) * 12 + index * 24 rect.y = 36 rect.width = 24 rect.height = WLH return rect end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.contents.clear #~ draw_actor_face(@actor, 0, 0) name_array = @name.split(//) for i in 0...@max_char c = name_array[i] c = '_' if c == nil self.contents.draw_text(item_rect(i), c, 1) end end #-------------------------------------------------------------------------- # ● カーソルの更新 #-------------------------------------------------------------------------- def update_cursor #~ self.cursor_rect = item_rect(@index) end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update super update_cursor end end #============================================================================== # ■ DQWindow_NameInput #============================================================================== class DQWindow_NameInput < DQWindow #-------------------------------------------------------------------------- # ● 文字表 #-------------------------------------------------------------------------- HIRAGANA = [ 'あ','い','う','え','お', 'が','ぎ','ぐ','げ','ご', 'か','き','く','け','こ', 'ざ','じ','ず','ぜ','ぞ', 'さ','し','す','せ','そ', 'だ','ぢ','づ','で','ど', 'た','ち','つ','て','と', 'ば','び','ぶ','べ','ぼ', 'な','に','ぬ','ね','の', 'ぱ','ぴ','ぷ','ぺ','ぽ', 'は','ひ','ふ','へ','ほ', 'ぁ','ぃ','ぅ','ぇ','ぉ', 'ま','み','む','め','も', 'っ','ゃ','ゅ','ょ','ゎ', 'や','ゆ','よ','わ','ん', 'ー','〜','・','=','☆', 'ら','り','る','れ','ろ', 'ヴ','を','','カナ','決定'] KATAKANA = [ 'ア','イ','ウ','エ','オ', 'ガ','ギ','グ','ゲ','ゴ', 'カ','キ','ク','ケ','コ', 'ザ','ジ','ズ','ゼ','ゾ', 'サ','シ','ス','セ','ソ', 'ダ','ヂ','ヅ','デ','ド', 'タ','チ','ツ','テ','ト', 'バ','ビ','ブ','ベ','ボ', 'ナ','ニ','ヌ','ネ','ノ', 'パ','ピ','プ','ペ','ポ', 'ハ','ヒ','フ','ヘ','ホ', 'ァ','ィ','ゥ','ェ','ォ', 'マ','ミ','ム','メ','モ', 'ッ','ャ','ュ','ョ','ヮ', 'ヤ','ユ','ヨ','ワ','ン', 'ー','〜','・','=','☆', 'ラ','リ','ル','レ','ロ', 'ヴ','ヲ','','かな','決定'] TABLE = [HIRAGANA, KATAKANA] #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :active # アクティブフラグ #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(mode = 0) super(88, 148, 368, 248) @mode = mode @index = 0 setup_cursor refresh update_cursor end #-------------------------------------------------------------------------- # ● カーソルスプライトの作成 #-------------------------------------------------------------------------- def setup_cursor @cursor_sprite = Sprite.new(@viewport2) @cursor_sprite.bitmap = Cache.system("DQWindow") @cursor_sprite.src_rect.set(8, 8, 8, 8) @cursor_count = 0 update_cursor end #-------------------------------------------------------------------------- # ● 文字の取得 #-------------------------------------------------------------------------- def character if @index < 88 return TABLE[@mode][@index] else return "" end end #-------------------------------------------------------------------------- # ● カーソル位置 モード切り替え判定 (かな/カナ) #-------------------------------------------------------------------------- def is_mode_change return (@index == 88) end #-------------------------------------------------------------------------- # ● カーソル位置 決定判定 #-------------------------------------------------------------------------- def is_decision return (@index == 89) end #-------------------------------------------------------------------------- # ● 項目を描画する矩形の取得 #-------------------------------------------------------------------------- def item_rect(index) rect = Rect.new(0, 0, 0, 0) rect.x = index % 10 * 32 + index % 10 / 5 * 16 rect.y = index / 10 * WLH rect.width = 32 rect.height = WLH return rect end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh self.contents.clear for i in 0..89 rect = item_rect(i) rect.x += 2 rect.width -= 4 self.contents.draw_text(rect, TABLE[@mode][i], 1) end end #-------------------------------------------------------------------------- # ● カーソルの更新 #-------------------------------------------------------------------------- def update_cursor @cursor_count = ((@cursor_count || 0) + 1) % 30 @cursor_sprite.visible = ((not self.active) or @cursor_count < 15) rect = item_rect(@index) # 選択されている項目の矩形を取得 @cursor_sprite.x = @contents_sprite.x + rect.x @cursor_sprite.y = @contents_sprite.y + rect.y + (WLH - 8) / 2 end #-------------------------------------------------------------------------- # ● カーソルを下に移動 #-------------------------------------------------------------------------- def cursor_down(wrap) if @index < 80 @index += 10 elsif wrap @index -= 80 end end #-------------------------------------------------------------------------- # ● カーソルを上に移動 #-------------------------------------------------------------------------- def cursor_up(wrap) if @index >= 10 @index -= 10 elsif wrap @index += 80 end end #-------------------------------------------------------------------------- # ● カーソルを右に移動 #-------------------------------------------------------------------------- def cursor_right(wrap) if @index % 10 < 9 @index += 1 elsif wrap @index -= 9 end end #-------------------------------------------------------------------------- # ● カーソルを左に移動 #-------------------------------------------------------------------------- def cursor_left(wrap) if @index % 10 > 0 @index -= 1 elsif wrap @index += 9 end end #-------------------------------------------------------------------------- # ● カーソルを決定へ移動 #-------------------------------------------------------------------------- def cursor_to_decision @index = 89 end #-------------------------------------------------------------------------- # ● 次のページへ移動 #-------------------------------------------------------------------------- def cursor_pagedown @mode = (@mode + 1) % TABLE.size refresh end #-------------------------------------------------------------------------- # ● 前のページへ移動 #-------------------------------------------------------------------------- def cursor_pageup @mode = (@mode + TABLE.size - 1) % TABLE.size refresh end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update super last_mode = @mode last_index = @index if Input.repeat?(Input::DOWN) cursor_down(Input.trigger?(Input::DOWN)) end if Input.repeat?(Input::UP) cursor_up(Input.trigger?(Input::UP)) end if Input.repeat?(Input::RIGHT) cursor_right(Input.trigger?(Input::RIGHT)) end if Input.repeat?(Input::LEFT) cursor_left(Input.trigger?(Input::LEFT)) end if Input.trigger?(Input::A) cursor_to_decision end if Input.trigger?(Input::R) cursor_pagedown end if Input.trigger?(Input::L) cursor_pageup end if Input.trigger?(Input::C) and is_mode_change cursor_pagedown end if @index != last_index or @mode != last_mode Sound.play_cursor end update_cursor end end #============================================================================== # ■ Scene_Name #============================================================================== class Scene_Name < Scene_Base #-------------------------------------------------------------------------- # ● 開始処理 #-------------------------------------------------------------------------- def start super create_menu_background @actor = $game_actors[$game_temp.name_actor_id] @edit_window = DQWindow_NameEdit.new(@actor, $game_temp.name_max_char) @input_window = DQWindow_NameInput.new end end