Class: UI::KeyShortcut

Inherits:
Sprite show all
Defined in:
scripts/01450 Systems/00000 General/00100 UI Generics/00600 KeyShortcut.rb

Overview

Class that show the sprite of a key

Direct Known Subclasses

KeyBinding

Constant Summary collapse

KeyIndex =

KeyIndex that holds the value of the Keyboard constants in the right order according to the texture

%i[A B C D E F G H I J
K L M N O P Q R S T
U V W X Y Z Num0 Num1 Num2 Num3
Num4 Num5 Num6 Num7 Num8 Num9 Space Backspace Enter LShift
LControl LAlt Escape Left Right Up Down].collect(&Input::Keyboard.method(:const_get))
NUMPAD_KEY_INDEX =

KeyIndex for the NumPad Keys

[
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  -1, -1, -1, -1, -1, -1, kbd::Numpad0, kbd::Numpad1, kbd::Numpad2, kbd::Numpad3,
  kbd::Numpad4, kbd::Numpad5, kbd::Numpad6, kbd::Numpad7, kbd::Numpad8, kbd::Numpad9, -1, -1, -1, kbd::RShift,
  kbd::RControl, kbd::RAlt, -1, -1, -1, -1, -1
]

Instance Attribute Summary

Attributes inherited from LiteRGSS::ShaderedSprite

#blendmode, #shader

Attributes inherited from LiteRGSS::Sprite

#__index__, #angle, #bitmap, #height, #mirror, #opacity, #ox, #oy, #src_rect, #viewport, #visible, #width, #x, #y, #z, #zoom, #zoom_x, #zoom_y

Instance Method Summary collapse

Methods inherited from Sprite

#load, #mouse_in?, #set_origin_div, #set_rect, #set_rect_div, #set_z, #simple_mouse_in?, #translate_mouse_coords, #update

Methods inherited from LiteRGSS::Sprite

new, #set_origin, #set_position

Methods inherited from LiteRGSS::Disposable

#dispose, #disposed?

Constructor Details

#initialize(viewport, key, red = false) ⇒ KeyShortcut

Create a new KeyShortcut sprite

Parameters:

  • viewport (Viewport)
  • key (Symbol, Integer)

    Input.trigger? argument (or Keyboard exact key if integer)

  • red (Boolean) (defaults to: false)

    pick the red texture instead of the blue texture



8
9
10
11
12
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00600 KeyShortcut.rb', line 8

def initialize(viewport, key, red = false)
  super(viewport)
  set_bitmap(red ? 'Key_ShortRed' : 'Key_Short', :pokedex)
  key.is_a?(Symbol) ? find_key(key) : show_key(key)
end

Instance Method Details

#find_key(key)

Find the key rect in the Sprite according to the input key requested

Parameters:

  • key (Symbol)

    the Virtual Input Key.



30
31
32
33
34
35
36
37
38
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00600 KeyShortcut.rb', line 30

def find_key(key)
  key_array = Input::Keys[key]
  key_array.each do |i|
    if (id = KeyIndex.index(i) || NUMPAD_KEY_INDEX.index(i))
      return set_rect_div(id % 10, id / 10, 10, 5)
    end
  end
  set_rect_div(9, 4, 10, 5) # A blank key
end

#show_key(key)

Show the exact key (when key from initialize was an interger)



41
42
43
44
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00600 KeyShortcut.rb', line 41

def show_key(key)
  id = KeyIndex.index(key) || NUMPAD_KEY_INDEX.index(key) || 49
  set_rect_div(id % 10, id / 10, 10, 5)
end