【解決済み】【RGSS3】選択肢の文章を中央に表示したい

タツミ
記事: 34
登録日時: 2015年12月29日(火) 23:51

【解決済み】【RGSS3】選択肢の文章を中央に表示したい

投稿記事by タツミ » 2016年10月25日(火) 22:29

コマンドイベント『選択肢の表示』で表示される文章を中央に表示したいと考えています、どうしたらよいでしょうか?
最後に編集したユーザー タツミ on 2016年10月26日(水) 10:31 [ 編集 1 回目 ]

faida
記事: 272
登録日時: 2015年12月17日(木) 16:44

Re: 【RGSS3】選択肢の文章を中央に表示したい

投稿記事by faida » 2016年10月26日(水) 09:42

ウィンドウを中央に表示したいという意味ならこちら。

コード: 全て選択

class Window_ChoiceList
  #--------------------------------------------------------------------------
  # ● ウィンドウ位置の更新
  #--------------------------------------------------------------------------
  def update_placement
    self.width = [max_choice_width + 12, 96].max + padding * 2
    self.width = [width, Graphics.width].min
    self.height = fitting_height($game_message.choices.size)
    self.x = (Graphics.width - width) / 2 # ここを変更
    if @message_window.y >= Graphics.height / 2
      self.y = @message_window.y - height
    else
      self.y = @message_window.y + @message_window.height
    end
  end
end
ウィンドウ内でテキストを中央に表示したいという意味ならこちら。

コード: 全て選択

class Window_ChoiceList
  #--------------------------------------------------------------------------
  # ● アライメントの取得
  #--------------------------------------------------------------------------
  def alignment
    return 1
  end
  #--------------------------------------------------------------------------
  # ● 項目を描画する矩形の取得(テキスト用)
  #--------------------------------------------------------------------------
  def item_rect_for_text(index)
    rect = item_rect(index)
    if @list[index]
      str = command_name(index)
      case alignment
      when 0
        rect.x += 4
      when 1
        rect.x += (contents.width - text_size_ex(str).width) / 2
      when 2
        rect.x += contents.width - text_size_ex(str).width - 4
      end
    else
      rect.x += 4
    end
    rect.width -= 8
    rect
  end
  def text_size_ex(str)
    reset_font_settings
    str = convert_escape_characters(str)
    pos = {:x => 0, :y => 0, :new_x => 0, :height => calc_line_height(str)}
    process_character_s(str.slice!(0, 1), str, pos) until str.empty?
    Rect.new(0, 0, pos[:x], pos[:height])
  end
  #--------------------------------------------------------------------------
  # ● 文字の処理
  #--------------------------------------------------------------------------
  def process_character_s(c, str, pos)
    case c
    when "\e"   # 制御文字
      process_escape_character_s(obtain_escape_code(str), str, pos)
    else        # 普通の文字
      pos[:x] += text_size(c).width
    end
  end
  #--------------------------------------------------------------------------
  # ● 制御文字の処理
  #     code : 制御文字の本体部分(「\C[1]」なら「C」)
  #--------------------------------------------------------------------------
  def process_escape_character_s(code, text, pos)
    case code.upcase
    when 'C'
      obtain_escape_param(text)
    when 'I'
      obtain_escape_param(text); pos[:x] += 24
    when '{'
      contents.font.size += 8 if contents.font.size <= 64
    when '}'
      contents.font.size -= 8 if contents.font.size >= 16
    end
  end
end
------------------------------------------------------------------
自作の(改造でない)スクリプト、プラグイン素材に
関しては、リードミーもしくは作中に
「faida」と記名していただければ
利用可能です。
タツミ
記事: 34
登録日時: 2015年12月29日(火) 23:51

Re: 【RGSS3】選択肢の文章を中央に表示したい

投稿記事by タツミ » 2016年10月26日(水) 10:30

ウィンドウ内のテキストを中央に表示するとができました。
faida様、ありがとうございます。

このトピックは解決済みとさせていただきます。

“VX / Ace:質問” へ戻る