Class: GamePlay::KeyBinding

Inherits:
BaseCleanUpdate show all
Defined in:
scripts/01450 Systems/00105 Options/00003 GamePlay/04800 KeyBinding.rb,
scripts/01450 Systems/00105 Options/00003 GamePlay/04801 KeyBinding_LS.rb

Overview

Class that show the KeyBinding UI and allow to change it

Constant Summary collapse

KEYS =

List of keys use by the 3 modes

[%i[A RIGHT DOWN B]] * 3
MOUSE_ACTION_NAV =

List of mouse action in navigation mode

%i[action_a_nav action_a_nav action_down_nav action_b_nav]
MOUSE_ACTION_SEL =

List of mouse action in selection mode

%i[action_a_sel action_right_sel action_down_sel action_b_sel]
MOUSE_ACTION_BLK =

List of mouse action in blink mode

%i[action_b_blink action_b_blink action_b_blink action_b_blink]

Constants inherited from BaseCleanUpdate

BaseCleanUpdate::AIU_KEY2METHOD

Constants inherited from Base

Base::DEFAULT_TRANSITION, Base::DEFAULT_TRANSITION_PARAMETER

Constants included from Input

Input::ALIAS_KEYS, Input::AXIS_MAPPING, Input::AXIS_SENSITIVITY, Input::DEAD_ZONE, Input::Keyboard, Input::Keys, Input::NON_TRIGGER_ZONE, Input::REPEAT_COOLDOWN, Input::REPEAT_SPACE

Constants included from DisplayMessage

DisplayMessage::MESSAGE_ERROR, DisplayMessage::MESSAGE_PROCESS_ERROR

Instance Attribute Summary

Attributes inherited from Base

#__last_scene, #__result_process, #running, #viewport

Attributes included from DisplayMessage

#message_window

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseCleanUpdate

#automatic_input_update, #update

Methods inherited from Base

#add_disposable, #call_scene, #dispose, #find_parent, #main, #return_to_scene, #snap_to_bitmap, #update, #visible, #visible=

Methods included from Input

dir4, dir8, get_text, joy_axis_position, press?, register_events, released?, repeat?, swap_states, trigger?

Methods included from DisplayMessage

#can_display_message_be_called?, #close_message_window, #display_message, #display_message_and_wait, #message_class, #message_processing?, #message_visible, #message_visible=

Constructor Details

#initializeKeyBinding

Create a new KeyBinding UI



13
14
15
16
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/04800 KeyBinding.rb', line 13

def initialize
  super
  @cool_down = 0
end

Class Method Details

.input_filename

Return the filename with path of the inputs.yml file



61
62
63
64
65
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/04801 KeyBinding_LS.rb', line 61

def input_filename
  directory = File.dirname(Save.save_filename)
  Dir.mkdir!(directory) unless Dir.exist?(directory)
  File.join(directory, 'input.yml')
end

.load_inputs

Load the Inputs



5
6
7
8
9
10
11
12
13
14
15
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/04801 KeyBinding_LS.rb', line 5

def load_inputs
  unless File.exist?(input_filename)
    normalize_inputs
    save_inputs
  end
  load_inputs_internal
  normalize_inputs
rescue StandardError
  normalize_inputs
  save_inputs
end

.load_inputs_internal

Perform the internal operation of loading the inputs



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/04801 KeyBinding_LS.rb', line 18

def load_inputs_internal
  data = YAML.unsafe_load(File.read(input_filename), fallback: false)
  raise 'Bad Input data' unless data.is_a?(Hash)
  UI::KeyBindingViewer::KEYS.each do |infos|
    key = infos[0]
    next unless (key_values = data[key])
    Input::Keys[key].clear
    Input::Keys[key].concat(key_values.collect(&:to_i))
  end
  Input.main_joy = data[:main_joy] || Input.main_joy
  if data[:x_axis].is_a?(Symbol) && Input.const_defined?(data[:x_axis])
    Input.x_axis = Input.const_get(data[:x_axis])
  end
  if data[:y_axis].is_a?(Symbol) && Input.const_defined?(data[:y_axis])
    Input.y_axis = Input.const_get(data[:y_axis])
  end
end

.normalize_inputs

Normalize the Input::Keys contents in order to have a correct display in the UI



37
38
39
40
41
42
43
44
45
46
47
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/04801 KeyBinding_LS.rb', line 37

def normalize_inputs
  Input::Keys.each do |_key, key_array|
    next if key_array.size >= 5
    first_key = key_array[0] || 0
    joy_key = key_array.find { |value| value < 0 } || first_key
    (key_array.size - (joy_key == first_key ? 0 : 1)).upto(3) do |index|
      key_array[index] = first_key
    end
    key_array[4] = joy_key
  end
end

.save_inputs

Save the inputs in the right file



50
51
52
53
54
55
56
57
58
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/04801 KeyBinding_LS.rb', line 50

def save_inputs
  data = { main_joy: Input.main_joy }
  data[:x_axis] = Input.constants.find { |e| Input.const_get(e) == Input.x_axis }
  data[:y_axis] = Input.constants.find { |e| Input.const_get(e) == Input.y_axis }
  UI::KeyBindingViewer::KEYS.each do |infos|
    data[infos[0]] = Input::Keys[infos[0]].clone
  end
  File.open(input_filename, 'w') { |f| YAML.dump(data, f) }
end

Instance Method Details

#create_graphics

Create the grahics of the KeyBinding scene



19
20
21
22
23
24
25
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/04800 KeyBinding.rb', line 19

def create_graphics
  create_viewport
  create_base_ui
  create_overlay
  create_ui
  Graphics.sort_z
end

#update_graphics

Update the graphics



28
29
30
31
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/04800 KeyBinding.rb', line 28

def update_graphics
  @base_ui.update_background_animation
  @ui.update_blink
end

#update_inputs

Update the inputs



34
35
36
37
38
39
40
41
42
43
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/04800 KeyBinding.rb', line 34

def update_inputs
  return @cool_down -= 1 if @cool_down > 0
  if @ui.key_index == -1
    update_navigation_input
  elsif @ui.blinking
    update_key_binding
  else
    update_key_selection
  end
end

#update_mouse(_moved)

Update the mouse

Parameters:

  • _moved (Boolean)

    if the mouse moved



47
48
49
50
51
52
53
54
55
56
# File 'scripts/01450 Systems/00105 Options/00003 GamePlay/04800 KeyBinding.rb', line 47

def update_mouse(_moved)
  if @ui.blinking
    actions = MOUSE_ACTION_BLK
  elsif @ui.key_index >= 0
    actions = MOUSE_ACTION_SEL
  else
    actions = MOUSE_ACTION_NAV
  end
  update_mouse_ctrl_buttons(@base_ui.ctrl, actions, @base_ui.win_text_visible?)
end