カーソルの移動やスクロールの機能を持つウィンドウクラスです。

Methods
A
B
C
D
E
H
I
N
O
P
R
S
T
U
Attributes
[RW] cursor_all
[RW] cursor_fix
[R] help_window
[R] index

公開インスタンス変数

Class Public methods
new(x, y, width, height)

オブジェクト初期化

# File Window_Selectable.rb, line 18
def initialize(x, y, width, height)
  super
  @index = -1
  @handler = {}
  @cursor_fix = false
  @cursor_all = false
  update_padding
  deactivate
end
Instance Public methods
active=(active)

アクティブ状態の変更

# File Window_Selectable.rb, line 104
def active=(active)
  super
  update_cursor
  call_update_help
end
bottom_row()

末尾の行の取得

# File Window_Selectable.rb, line 180
def bottom_row
  top_row + page_row_max - 1
end
bottom_row=(row)

末尾の行の設定

# File Window_Selectable.rb, line 187
def bottom_row=(row)
  self.top_row = row - (page_row_max - 1)
end
call_cancel_handler()

キャンセルハンドラの呼び出し

# File Window_Selectable.rb, line 389
def call_cancel_handler
  call_handler(:cancel)
end
call_handler(symbol)

ハンドラの呼び出し

# File Window_Selectable.rb, line 239
def call_handler(symbol)
  @handler[symbol].call if handle?(symbol)
end
call_ok_handler()

決定ハンドラの呼び出し

# File Window_Selectable.rb, line 372
def call_ok_handler
  call_handler(:ok)
end
call_update_help()

ヘルプウィンドウ更新メソッドの呼び出し

# File Window_Selectable.rb, line 439
def call_update_help
  update_help if active && @help_window
end
cancel_enabled?()

キャンセル処理の有効状態を取得

# File Window_Selectable.rb, line 351
def cancel_enabled?
  handle?(:cancel)
end
clear_item(index)

項目の消去

# File Window_Selectable.rb, line 473
def clear_item(index)
  contents.clear_rect(item_rect(index))
end
col_max()

桁数の取得

# File Window_Selectable.rb, line 31
def col_max
  return 1
end
contents_height()

ウィンドウ内容の高さを計算

# File Window_Selectable.rb, line 73
def contents_height
  [super - super % item_height, row_max * item_height].max
end
current_item_enabled?()

選択項目の有効状態を取得

# File Window_Selectable.rb, line 453
def current_item_enabled?
  return true
end
cursor_down(wrap = false)

カーソルを下に移動

# File Window_Selectable.rb, line 253
def cursor_down(wrap = false)
  if index < item_max - col_max || (wrap && col_max == 1)
    select((index + col_max) % item_max)
  end
end
cursor_left(wrap = false)

カーソルを左に移動

# File Window_Selectable.rb, line 280
def cursor_left(wrap = false)
  if col_max >= 2 && (index > 0 || (wrap && horizontal?))
    select((index - 1 + item_max) % item_max)
  end
end
cursor_movable?()

カーソルの移動可能判定

# File Window_Selectable.rb, line 246
def cursor_movable?
  active && open? && !@cursor_fix && !@cursor_all && item_max > 0
end
cursor_pagedown()

カーソルを 1 ページ後ろに移動

# File Window_Selectable.rb, line 289
def cursor_pagedown
  if top_row + page_row_max < row_max
    self.top_row += page_row_max
    select([@index + page_item_max, item_max - 1].min)
  end
end
cursor_pageup()

カーソルを 1 ページ前に移動

# File Window_Selectable.rb, line 299
def cursor_pageup
  if top_row > 0
    self.top_row -= page_row_max
    select([@index - page_item_max, 0].max)
  end
end
cursor_right(wrap = false)

カーソルを右に移動

# File Window_Selectable.rb, line 271
def cursor_right(wrap = false)
  if col_max >= 2 && (index < item_max - 1 || (wrap && horizontal?))
    select((index + 1) % item_max)
  end
end
cursor_up(wrap = false)

カーソルを上に移動

# File Window_Selectable.rb, line 262
def cursor_up(wrap = false)
  if index >= col_max || (wrap && col_max == 1)
    select((index - col_max + item_max) % item_max)
  end
end
draw_all_items()

全項目の描画

# File Window_Selectable.rb, line 460
def draw_all_items
  item_max.times {|i| draw_item(i) }
end
draw_item(index)

項目の描画

# File Window_Selectable.rb, line 467
def draw_item(index)
end
ensure_cursor_visible()

カーソル位置が画面内になるようにスクロール

# File Window_Selectable.rb, line 431
def ensure_cursor_visible
  self.top_row = row if row < top_row
  self.bottom_row = row if row > bottom_row
end
handle?(symbol)

ハンドラの存在確認

# File Window_Selectable.rb, line 232
def handle?(symbol)
  @handler.include?(symbol)
end
height=(height)

高さの設定

# File Window_Selectable.rb, line 96
def height=(height)
  super
  update_padding
end
help_window=(help_window)

ヘルプウィンドウの設定

# File Window_Selectable.rb, line 216
def help_window=(help_window)
  @help_window = help_window
  call_update_help
end
horizontal?()

横選択判定

# File Window_Selectable.rb, line 173
def horizontal?
  page_row_max == 1
end
index=(index)

カーソル位置の設定

# File Window_Selectable.rb, line 113
def index=(index)
  @index = index
  update_cursor
  call_update_help
end
item_height()

項目の高さを取得

# File Window_Selectable.rb, line 59
def item_height
  line_height
end
item_max()

項目数の取得

# File Window_Selectable.rb, line 45
def item_max
  return 0
end
item_rect(index)

項目を描画する矩形の取得

# File Window_Selectable.rb, line 194
def item_rect(index)
  rect = Rect.new
  rect.width = item_width
  rect.height = item_height
  rect.x = index % col_max * (item_width + spacing)
  rect.y = index / col_max * item_height
  rect
end
item_rect_for_text(index)

項目を描画する矩形の取得(テキスト用)

# File Window_Selectable.rb, line 206
def item_rect_for_text(index)
  rect = item_rect(index)
  rect.x += 4
  rect.width -= 8
  rect
end
item_width()

項目の幅を取得

# File Window_Selectable.rb, line 52
def item_width
  (width - standard_padding * 2 + spacing) / col_max - spacing
end
ok_enabled?()

決定処理の有効状態を取得

# File Window_Selectable.rb, line 344
def ok_enabled?
  handle?(:ok)
end
page_item_max()

1 ページに表示できる項目数の取得

# File Window_Selectable.rb, line 166
def page_item_max
  page_row_max * col_max
end
page_row_max()

1 ページに表示できる行数の取得

# File Window_Selectable.rb, line 159
def page_row_max
  (height - padding - padding_bottom) / item_height
end
process_cancel()

キャンセルボタンが押されたときの処理

# File Window_Selectable.rb, line 379
def process_cancel
  Sound.play_cancel
  Input.update
  deactivate
  call_cancel_handler
end
process_cursor_move()

カーソルの移動処理

# File Window_Selectable.rb, line 318
def process_cursor_move
  return unless cursor_movable?
  last_index = @index
  cursor_down (Input.trigger?(:DOWN))  if Input.repeat?(:DOWN)
  cursor_up   (Input.trigger?(:UP))    if Input.repeat?(:UP)
  cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
  cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
  cursor_pagedown   if !handle?(:pagedown) && Input.trigger?(:R)
  cursor_pageup     if !handle?(:pageup)   && Input.trigger?(:L)
  Sound.play_cursor if @index != last_index
end
process_handling()

決定やキャンセルなどのハンドリング処理

# File Window_Selectable.rb, line 333
def process_handling
  return unless open? && active
  return process_ok       if ok_enabled?        && Input.trigger?(:C)
  return process_cancel   if cancel_enabled?    && Input.trigger?(:B)
  return process_pagedown if handle?(:pagedown) && Input.trigger?(:R)
  return process_pageup   if handle?(:pageup)   && Input.trigger?(:L)
end
process_ok()

決定ボタンが押されたときの処理

# File Window_Selectable.rb, line 358
def process_ok
  if current_item_enabled?
    Sound.play_ok
    Input.update
    deactivate
    call_ok_handler
  else
    Sound.play_buzzer
  end
end
process_pagedown()

R ボタン(PageDown)が押されたときの処理

# File Window_Selectable.rb, line 406
def process_pagedown
  Sound.play_cursor
  Input.update
  deactivate
  call_handler(:pagedown)
end
process_pageup()

L ボタン(PageUp)が押されたときの処理

# File Window_Selectable.rb, line 396
def process_pageup
  Sound.play_cursor
  Input.update
  deactivate
  call_handler(:pageup)
end
redraw_current_item()

選択項目の再描画

# File Window_Selectable.rb, line 488
def redraw_current_item
  redraw_item(@index)
end
redraw_item(index)

項目の再描画

# File Window_Selectable.rb, line 480
def redraw_item(index)
  clear_item(index) if index >= 0
  draw_item(index)  if index >= 0
end
refresh()

リフレッシュ

# File Window_Selectable.rb, line 495
def refresh
  contents.clear
  draw_all_items
end
row()

現在の行の取得

# File Window_Selectable.rb, line 136
def row
  index / col_max
end
row_max()

行数の取得

# File Window_Selectable.rb, line 66
def row_max
  [(item_max + col_max - 1) / col_max, 1].max
end
select(index)

項目の選択

# File Window_Selectable.rb, line 122
def select(index)
  self.index = index if index
end
set_handler(symbol, method)

動作に対応するハンドラの設定

method : ハンドラとして設定するメソッド (Method オブジェクト)

# File Window_Selectable.rb, line 225
def set_handler(symbol, method)
  @handler[symbol] = method
end
spacing()

横に項目が並ぶときの空白の幅を取得

# File Window_Selectable.rb, line 38
def spacing
  return 32
end
top_row()

先頭の行の取得

# File Window_Selectable.rb, line 143
def top_row
  oy / item_height
end
top_row=(row)

先頭の行の設定

# File Window_Selectable.rb, line 150
def top_row=(row)
  row = 0 if row < 0
  row = row_max - 1 if row > row_max - 1
  self.oy = row * item_height
end
unselect()

項目の選択解除

# File Window_Selectable.rb, line 129
def unselect
  self.index = -1
end
update()

フレーム更新

# File Window_Selectable.rb, line 309
def update
  super
  process_cursor_move
  process_handling
end
update_cursor()

カーソルの更新

# File Window_Selectable.rb, line 416
def update_cursor
  if @cursor_all
    cursor_rect.set(0, 0, contents.width, row_max * item_height)
    self.top_row = 0
  elsif @index < 0
    cursor_rect.empty
  else
    ensure_cursor_visible
    cursor_rect.set(item_rect(@index))
  end
end
update_help()

ヘルプウィンドウの更新

# File Window_Selectable.rb, line 446
def update_help
  @help_window.clear
end
update_padding()

パディングの更新

# File Window_Selectable.rb, line 80
def update_padding
  super
  update_padding_bottom
end
update_padding_bottom()

下端パディングの更新

# File Window_Selectable.rb, line 88
def update_padding_bottom
  surplus = (height - standard_padding * 2) % item_height
  self.padding_bottom = padding + surplus
end