Class: PFM::Choice_Helper

Inherits:
Object show all
Defined in:
scripts/01450 Systems/00000 General/00001 PFM/00200 Helpers/00200 Choice_Helper.rb

Overview

Class that help to make choice inside Interfaces

Instance Method Summary collapse

Constructor Details

#initialize(klass, can_cancel = true, cancel_index = nil) ⇒ Choice_Helper

Create a new Choice_Helper

Parameters:

  • klass (Class)

    class used to display the choice

  • can_cancel (Boolean) (defaults to: true)

    if the user can cancel the choice

  • cancel_index (Integer, nil) (defaults to: nil)

    Index returned if the user cancel



8
9
10
11
12
13
14
15
16
17
# File 'scripts/01450 Systems/00000 General/00001 PFM/00200 Helpers/00200 Choice_Helper.rb', line 8

def initialize(klass, can_cancel = true, cancel_index = nil)
  # List of registered choices
  # @type [Array<Hash>]
  @choices = []
  # Class used to display the choice
  # @type [Class]
  @class = klass
  @can_cancel = can_cancel
  @cancel_index = cancel_index
end

Instance Method Details

#cancel

Cancel the choice from outside



26
27
28
# File 'scripts/01450 Systems/00000 General/00001 PFM/00200 Helpers/00200 Choice_Helper.rb', line 26

def cancel
  @canceled = true
end

#display_choice(viewport, x, y, width, *args, on_update: nil, align_right: false) ⇒ Integer

Display the choice

Parameters:

  • viewport (Viewport)

    viewport in wich the choice is shown

  • x (Integer)

    x coordinate of the choice window

  • y (Integer)

    y coordinate of the choice window

  • width (Integer)

    width of the choice window

  • on_update (#call, nil) (defaults to: nil)

    handle to call during choice update

  • align_right (Boolean) (defaults to: false)

    tell if the x/y coordinate are the top right coordinate of the choice

  • args (Array)

    argument to send to the on_update handle

Returns:

  • (Integer)

    the choice made by the user



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'scripts/01450 Systems/00000 General/00001 PFM/00200 Helpers/00200 Choice_Helper.rb', line 51

def display_choice(viewport, x, y, width, *args, on_update: nil, align_right: false)
  @canceled = false
  # @type [Yuki::ChoiceWindow]
  window = build_choice_window(viewport, x, y, width, align_right)
  loop do
    Graphics.update
    next if Graphics::FPSBalancer.global.skipping? && (!$scene.message_window || $scene.message_window.can_sub_window_be_updated?)

    window.update
    on_update&.call(*args)
    break if check_cancel(window)
    break if check_validate(window)
  end
  $game_system.se_play($data_system.decision_se)
  index = window.index
  window.dispose
  call_validate_handle(index)
  return index
end

#register_choice(text, *args, disable_detect: nil, on_validate: nil, color: nil) ⇒ self

Register a choice

Parameters:

  • text (String)
  • disable_detect (#call, nil) (defaults to: nil)

    handle to call to detect if the choice is disabled or not

  • on_validate (#call, nil) (defaults to: nil)

    handle to call when the choice validated on this choice

  • color (Integer, nil) (defaults to: nil)

    non default color to use on this choice

  • args (Array)

    arguments to send to the disable_detect and on_validate handler

Returns:

  • (self)


37
38
39
40
# File 'scripts/01450 Systems/00000 General/00001 PFM/00200 Helpers/00200 Choice_Helper.rb', line 37

def register_choice(text, *args, disable_detect: nil, on_validate: nil, color: nil)
  @choices << { text: text, args: args, disable_detect: disable_detect, on_validate: on_validate, color: color }
  return self
end

#sizeInteger

Return the number of choices (for calculation)

Returns:



21
22
23
# File 'scripts/01450 Systems/00000 General/00001 PFM/00200 Helpers/00200 Choice_Helper.rb', line 21

def size
  return @choices.size
end