Compare commits

...

2 Commits

1 changed files with 17 additions and 2 deletions

View File

@ -4,6 +4,9 @@ extends Control
signal chosen(wp : Globals.Weapons)
func validate_weapon_enum(wp : Globals.Weapons) -> bool:
return false if wp >= Globals.Weapons.size() else true
func create_weapon(wp : Globals.Weapons) -> void:
var item : WeaponButton = template.duplicate()
item.set_name(Globals.Weapons.keys()[wp])
@ -23,7 +26,6 @@ func collect_all_weapons() -> void:
var size : int = Globals.Weapons.size()
for i in range(size):
print(Globals.Weapons.keys()[i])
create_weapon(i)
return
@ -34,13 +36,26 @@ func _ready() -> void:
return
func _input(ev : InputEvent) -> void:
# https://docs.godotengine.org/en/stable/tutorials/inputs/input_examples.html#keyboard-events
if ev is InputEventKey and ev.pressed:
var num : int = 0
if ev.keycode >= KEY_0 and ev.keycode <= KEY_9:
num = ev.keycode - 48
elif ev.keycode >= KEY_KP_0 and ev.keycode <= KEY_KP_9:
num = ev.keycode - 4194438
else:
return
if validate_weapon_enum(num - 1):
_on_button_weapon_button_pressed(num - 1) # Simulate button press; Allow selecting 0-9 with keyboard
if ev.is_action_released("equip_weapon"): # If equip_weapon key is pressed while weapon_selector is active, close it.
queue_free()
return
func _on_button_weapon_button_pressed(wp : Globals.Weapons) -> void:
print(Globals.weapons_fancy_names[wp])
emit_signal("chosen", wp)
queue_free()
return