Class: Window_Selectable

Inherits:
Window_Base show all
Defined in:
Window_Selectable.rb

Overview

** Window_Selectable


This window class contains cursor movement and scroll functions.

Direct Known Subclasses

Window_BattleEnemy, Window_BattleLog, Window_BattleStatus, Window_Command, Window_DebugLeft, Window_DebugRight, Window_EquipSlot, Window_ItemList, Window_MenuStatus, Window_NameInput, Window_ShopBuy, Window_ShopNumber, Window_SkillList, Window_Status

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Window_Base

#activate, #actor_name, #calc_line_height, #change_color, #close, #contents_width, #convert_escape_characters, #create_contents, #crisis_color, #deactivate, #dispose, #draw_actor_class, #draw_actor_face, #draw_actor_graphic, #draw_actor_hp, #draw_actor_icons, #draw_actor_level, #draw_actor_mp, #draw_actor_name, #draw_actor_nickname, #draw_actor_param, #draw_actor_simple_status, #draw_actor_tp, #draw_character, #draw_currency_value, #draw_current_and_max_values, #draw_face, #draw_gauge, #draw_icon, #draw_item_name, #draw_text, #draw_text_ex, #fitting_height, #gauge_back_color, #hide, #hp_color, #hp_gauge_color1, #hp_gauge_color2, #knockout_color, #line_height, #make_font_bigger, #make_font_smaller, #mp_color, #mp_cost_color, #mp_gauge_color1, #mp_gauge_color2, #normal_color, #obtain_escape_code, #obtain_escape_param, #open, #param_change_color, #party_member_name, #pending_color, #power_down_color, #power_up_color, #process_character, #process_draw_icon, #process_escape_character, #process_new_line, #process_new_page, #process_normal_character, #reset_font_settings, #show, #standard_padding, #system_color, #text_color, #text_size, #tp_color, #tp_cost_color, #tp_gauge_color1, #tp_gauge_color2, #translucent_alpha, #update_close, #update_open, #update_tone

Constructor Details

- (Window_Selectable) initialize(x, y, width, height)


  • Object Initialization




18
19
20
21
22
23
24
25
26
# 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 Attribute Details

- (Object) cursor_all

select all cursors flag



14
15
16
# File 'Window_Selectable.rb', line 14

def cursor_all
  @cursor_all
end

- (Object) cursor_fix

fix cursor flag



13
14
15
# File 'Window_Selectable.rb', line 13

def cursor_fix
  @cursor_fix
end

- (Object) help_window

help window



12
13
14
# File 'Window_Selectable.rb', line 12

def help_window
  @help_window
end

- (Object) index


  • Public Instance Variables




11
12
13
# File 'Window_Selectable.rb', line 11

def index
  @index
end

Instance Method Details

- (Object) active=(active)


  • Change Active State




93
94
95
96
97
# File 'Window_Selectable.rb', line 93

def active=(active)
  super
  update_cursor
  call_update_help
end

- (Object) bottom_row


  • Get Bottom Row




159
160
161
# File 'Window_Selectable.rb', line 159

def bottom_row
  top_row + page_row_max - 1
end

- (Object) bottom_row=(row)


  • Set Bottom Row




165
166
167
# File 'Window_Selectable.rb', line 165

def bottom_row=(row)
  self.top_row = row - (page_row_max - 1)
end

- (Object) call_cancel_handler


  • Call Cancel Handler




345
346
347
# File 'Window_Selectable.rb', line 345

def call_cancel_handler
  call_handler(:cancel)
end

- (Object) call_handler(symbol)


  • Call Handler




211
212
213
# File 'Window_Selectable.rb', line 211

def call_handler(symbol)
  @handler[symbol].call if handle?(symbol)
end

- (Object) call_ok_handler


  • Call OK Handler




330
331
332
# File 'Window_Selectable.rb', line 330

def call_ok_handler
  call_handler(:ok)
end

- (Object) call_update_help


  • Call Help Window Update Method




390
391
392
# File 'Window_Selectable.rb', line 390

def call_update_help
  update_help if active && @help_window
end

- (Boolean) cancel_enabled?


  • Get Activation State of Cancel Processing


Returns:

  • (Boolean)


311
312
313
# File 'Window_Selectable.rb', line 311

def cancel_enabled?
  handle?(:cancel)
end

- (Object) clear_item(index)


  • Erase Item




419
420
421
# File 'Window_Selectable.rb', line 419

def clear_item(index)
  contents.clear_rect(item_rect(index))
end

- (Object) col_max


  • Get Digit Count




30
31
32
# File 'Window_Selectable.rb', line 30

def col_max
  return 1
end

- (Object) contents_height


  • Calculate Height of Window Contents




66
67
68
# File 'Window_Selectable.rb', line 66

def contents_height
  [super - super % item_height, row_max * item_height].max
end

- (Boolean) current_item_enabled?


  • Get Activation State of Selection Item


Returns:

  • (Boolean)


402
403
404
# File 'Window_Selectable.rb', line 402

def current_item_enabled?
  return true
end

- (Object) cursor_down(wrap = false)


  • Move Cursor Down




223
224
225
226
227
# File 'Window_Selectable.rb', line 223

def cursor_down(wrap = false)
  if index < item_max - col_max || (wrap && col_max == 1)
    select((index + col_max) % item_max)
  end
end

- (Object) cursor_left(wrap = false)


  • Move Cursor Left




247
248
249
250
251
# File 'Window_Selectable.rb', line 247

def cursor_left(wrap = false)
  if col_max >= 2 && (index > 0 || (wrap && horizontal?))
    select((index - 1 + item_max) % item_max)
  end
end

- (Boolean) cursor_movable?


  • Determine if Cursor is Moveable


Returns:

  • (Boolean)


217
218
219
# File 'Window_Selectable.rb', line 217

def cursor_movable?
  active && open? && !@cursor_fix && !@cursor_all && item_max > 0
end

- (Object) cursor_pagedown


  • Move Cursor One Page Down




255
256
257
258
259
260
# File 'Window_Selectable.rb', line 255

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

- (Object) cursor_pageup


  • Move Cursor One Page Up




264
265
266
267
268
269
# File 'Window_Selectable.rb', line 264

def cursor_pageup
  if top_row > 0
    self.top_row -= page_row_max
    select([@index - page_item_max, 0].max)
  end
end

- (Object) cursor_right(wrap = false)


  • Move Cursor Right




239
240
241
242
243
# File 'Window_Selectable.rb', line 239

def cursor_right(wrap = false)
  if col_max >= 2 && (index < item_max - 1 || (wrap && horizontal?))
    select((index + 1) % item_max)
  end
end

- (Object) cursor_up(wrap = false)


  • Move Cursor Up




231
232
233
234
235
# File 'Window_Selectable.rb', line 231

def cursor_up(wrap = false)
  if index >= col_max || (wrap && col_max == 1)
    select((index - col_max + item_max) % item_max)
  end
end

- (Object) draw_all_items


  • Draw All Items




408
409
410
# File 'Window_Selectable.rb', line 408

def draw_all_items
  item_max.times {|i| draw_item(i) }
end

- (Object) draw_item(index)


  • Draw Item




414
415
# File 'Window_Selectable.rb', line 414

def draw_item(index)
end

- (Object) ensure_cursor_visible


  • Scroll Cursor to Position Within Screen




383
384
385
386
# File 'Window_Selectable.rb', line 383

def ensure_cursor_visible
  self.top_row = row if row < top_row
  self.bottom_row = row if row > bottom_row
end

- (Boolean) handle?(symbol)


  • Check for Handler Existence


Returns:

  • (Boolean)


205
206
207
# File 'Window_Selectable.rb', line 205

def handle?(symbol)
  @handler.include?(symbol)
end

- (Object) height=(height)


  • Set Height




86
87
88
89
# File 'Window_Selectable.rb', line 86

def height=(height)
  super
  update_padding
end

- (Boolean) horizontal?


  • Determine Horizontal Selection


Returns:

  • (Boolean)


153
154
155
# File 'Window_Selectable.rb', line 153

def horizontal?
  page_row_max == 1
end

- (Object) item_height


  • Get Item Height




54
55
56
# File 'Window_Selectable.rb', line 54

def item_height
  line_height
end

- (Object) item_max


  • Get Number of Items




42
43
44
# File 'Window_Selectable.rb', line 42

def item_max
  return 0
end

- (Object) item_rect(index)


  • Get Rectangle for Drawing Items




171
172
173
174
175
176
177
178
# File 'Window_Selectable.rb', line 171

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

- (Object) item_rect_for_text(index)


  • Get Rectangle for Drawing Items (for Text)




182
183
184
185
186
187
# File 'Window_Selectable.rb', line 182

def item_rect_for_text(index)
  rect = item_rect(index)
  rect.x += 4
  rect.width -= 8
  rect
end

- (Object) item_width


  • Get Item Width




48
49
50
# File 'Window_Selectable.rb', line 48

def item_width
  (width - standard_padding * 2 + spacing) / col_max - spacing
end

- (Boolean) ok_enabled?


  • Get Activation State of OK Processing


Returns:

  • (Boolean)


305
306
307
# File 'Window_Selectable.rb', line 305

def ok_enabled?
  handle?(:ok)
end

- (Object) page_item_max


  • Get Number of Items Displayable on 1 Page




147
148
149
# File 'Window_Selectable.rb', line 147

def page_item_max
  page_row_max * col_max
end

- (Object) page_row_max


  • Get Number of Rows Displayable on 1 Page




141
142
143
# File 'Window_Selectable.rb', line 141

def page_row_max
  (height - padding - padding_bottom) / item_height
end

- (Object) process_cancel


  • Processing When Cancel Button Is Pressed




336
337
338
339
340
341
# File 'Window_Selectable.rb', line 336

def process_cancel
  Sound.play_cancel
  Input.update
  deactivate
  call_cancel_handler
end

- (Object) process_cursor_move


  • Cursor Movement Processing




281
282
283
284
285
286
287
288
289
290
291
# File 'Window_Selectable.rb', line 281

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

- (Object) process_handling


  • Handling Processing for OK and Cancel Etc.




295
296
297
298
299
300
301
# File 'Window_Selectable.rb', line 295

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

- (Object) process_ok


  • Processing When OK Button Is Pressed




317
318
319
320
321
322
323
324
325
326
# File 'Window_Selectable.rb', line 317

def process_ok
  if current_item_enabled?
    Sound.play_ok
    Input.update
    deactivate
    call_ok_handler
  else
    Sound.play_buzzer
  end
end

- (Object) process_pagedown


  • Processing When R Button (Page Down) Is Pressed




360
361
362
363
364
365
# File 'Window_Selectable.rb', line 360

def process_pagedown
  Sound.play_cursor
  Input.update
  deactivate
  call_handler(:pagedown)
end

- (Object) process_pageup


  • Processing When L Button (Page Up) Is Pressed




351
352
353
354
355
356
# File 'Window_Selectable.rb', line 351

def process_pageup
  Sound.play_cursor
  Input.update
  deactivate
  call_handler(:pageup)
end

- (Object) redraw_current_item


  • Redraw Selection Item




432
433
434
# File 'Window_Selectable.rb', line 432

def redraw_current_item
  redraw_item(@index)
end

- (Object) redraw_item(index)


  • Redraw Item




425
426
427
428
# File 'Window_Selectable.rb', line 425

def redraw_item(index)
  clear_item(index) if index >= 0
  draw_item(index)  if index >= 0
end

- (Object) refresh


  • Refresh




438
439
440
441
# File 'Window_Selectable.rb', line 438

def refresh
  contents.clear
  draw_all_items
end

- (Object) row


  • Get Current Line




121
122
123
# File 'Window_Selectable.rb', line 121

def row
  index / col_max #/
end

- (Object) row_max


  • Get Row Count




60
61
62
# File 'Window_Selectable.rb', line 60

def row_max
  [(item_max + col_max - 1) / col_max, 1].max
end

- (Object) select(index)


  • Select Item




109
110
111
# File 'Window_Selectable.rb', line 109

def select(index)
  self.index = index if index
end

- (Object) set_handler(symbol, method)


  • Set Handler Corresponding to Operation

    method : Method set as a handler (Method object)



199
200
201
# File 'Window_Selectable.rb', line 199

def set_handler(symbol, method)
  @handler[symbol] = method
end

- (Object) spacing


  • Get Spacing for Items Arranged Side by Side




36
37
38
# File 'Window_Selectable.rb', line 36

def spacing
  return 32
end

- (Object) top_row


  • Get Top Row




127
128
129
# File 'Window_Selectable.rb', line 127

def top_row
  oy / item_height
end

- (Object) top_row=(row)


  • Set Top Row




133
134
135
136
137
# File 'Window_Selectable.rb', line 133

def top_row=(row)
  row = 0 if row < 0
  row = row_max - 1 if row > row_max - 1
  self.oy = row * item_height
end

- (Object) unselect


  • Deselect Item




115
116
117
# File 'Window_Selectable.rb', line 115

def unselect
  self.index = -1
end

- (Object) update


  • Frame Update




273
274
275
276
277
# File 'Window_Selectable.rb', line 273

def update
  super
  process_cursor_move
  process_handling
end

- (Object) update_cursor


  • Update Cursor




369
370
371
372
373
374
375
376
377
378
379
# File 'Window_Selectable.rb', line 369

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

- (Object) update_help


  • Update Help Window




396
397
398
# File 'Window_Selectable.rb', line 396

def update_help
  @help_window.clear
end

- (Object) update_padding


  • Update Padding




72
73
74
75
# File 'Window_Selectable.rb', line 72

def update_padding
  super
  update_padding_bottom
end

- (Object) update_padding_bottom


  • Update Bottom Padding




79
80
81
82
# File 'Window_Selectable.rb', line 79

def update_padding_bottom
  surplus = (height - standard_padding * 2) % item_height
  self.padding_bottom = padding + surplus
end