Class: UI::KeyBindingViewer

Inherits:
SpriteStack show all
Defined in:
scripts/01450 Systems/00105 Options/00002 UI/00100 KeyBindingViewer.rb

Overview

Class that allow to see the KeyBinding for the PSDK virtual key

This object has two indexes :

- main_index : It's the index of the PSDK Key we want to see
- key_index : It's the index of the Binding we want to change
    if key_index is negative, it's not showing the index sprite

This object has a blink state linked to #update_blink allowing to tell the key is currently being edited

Constant Summary collapse

FT_X =

X position of the first text

12
ST_X =

X position of the second text

72
LT_X =

X position of the last text & the first button

208
FKT_Y =

Y position of the first key text

26
KEYS =

List of the Key to create with their information (PSDK name, Descr)

[
  [:A, 4, 13],
  [:B, 5, 14],
  [:X, 6, 15],
  [:Y, 7, 16],
  [:UP, 8, 17],
  [:DOWN, 9, 18],
  [:RIGHT, 10, 19],
  [:LEFT, 11, 20]
]

Constants inherited from SpriteStack

SpriteStack::NO_INITIAL_IMAGE

Instance Attribute Summary collapse

Attributes inherited from SpriteStack

#animated, #data, #moving, #stack, #viewport, #x, #y

Instance Method Summary collapse

Methods inherited from SpriteStack

#[], #add_background, #add_line, #add_text, #anime, #anime_delta_set, #dispose, #each, #execute_anime, #move, #move_to, #opacity, #opacity=, #push, #push_sprite, #set_origin, #set_position, #simple_mouse_in?, #size, #stop_animation, #translate_mouse_coords, #update_animation, #update_position, #visible, #visible=, #with_cache, #with_font, #with_surface, #z, #z=

Constructor Details

#initialize(viewport) ⇒ KeyBindingViewer

Create a new KeyBindingViewer



26
27
28
29
30
31
32
33
34
35
36
37
# File 'scripts/01450 Systems/00105 Options/00002 UI/00100 KeyBindingViewer.rb', line 26

def initialize(viewport)
  super(viewport, 3, 48)
  push(0, 0, 'key_binding/cadre')
  @main_selector = push(FT_X - 1, FKT_Y + 1, 'key_binding/selecteur_blue')
  @sub_selector = push(LT_X + 1, FKT_Y + 1, 'key_binding/selecteur_red')
  create_top_line
  create_keys
  @counter = 0
  self.main_index = 0
  self.key_index = -1
  self.blinking = false
end

Instance Attribute Details

#blinkingBoolean

Returns if the UI is in blinking mode.

Returns:

  • (Boolean)

    if the UI is in blinking mode



20
21
22
# File 'scripts/01450 Systems/00105 Options/00002 UI/00100 KeyBindingViewer.rb', line 20

def blinking
  @blinking
end

#key_indexInteger

Returns the key index.

Returns:



24
25
26
# File 'scripts/01450 Systems/00105 Options/00002 UI/00100 KeyBindingViewer.rb', line 24

def key_index
  @key_index
end

#main_indexInteger

Returns the main index.

Returns:



22
23
24
# File 'scripts/01450 Systems/00105 Options/00002 UI/00100 KeyBindingViewer.rb', line 22

def main_index
  @main_index
end

Instance Method Details

#current_keySymbol

Get the current key (to update the Input::Keys)

Returns:

  • (Symbol)


100
101
102
103
# File 'scripts/01450 Systems/00105 Options/00002 UI/00100 KeyBindingViewer.rb', line 100

def current_key
  return :A if @key_index < 0
  @buttons[@main_index * 5 + @key_index]&.key || :A
end

#current_key_index

Get the current key index according to the button



106
107
108
109
# File 'scripts/01450 Systems/00105 Options/00002 UI/00100 KeyBindingViewer.rb', line 106

def current_key_index
  return -1 if @key_index < 0
  @buttons[@main_index * 5 + @key_index]&.index || 0
end

#update

Update all the buttons



64
65
66
# File 'scripts/01450 Systems/00105 Options/00002 UI/00100 KeyBindingViewer.rb', line 64

def update
  @buttons.each(&:update)
end

Update the blink animation



52
53
54
55
56
57
58
59
60
61
# File 'scripts/01450 Systems/00105 Options/00002 UI/00100 KeyBindingViewer.rb', line 52

def update_blink
  return unless @blinking
  @counter += 1
  if @counter == 30
    @buttons[@main_index * 5 + @key_index]&.visible = false
  elsif @counter >= 60
    @buttons[@main_index * 5 + @key_index]&.visible = true
    @counter = 0
  end
end