Skip to content

Commit

Permalink
add tab shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
TinyTakinTeller committed Jan 11, 2025
1 parent d00145a commit 29eb7f4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
29 changes: 29 additions & 0 deletions scenes/autostart/main/main.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
extends Node

const SHORTCUTS_1: Array = [KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9]
const SHORTCUTS_2: Array = [
KEY_KP_0,
KEY_KP_1,
KEY_KP_2,
KEY_KP_3,
KEY_KP_4,
KEY_KP_5,
KEY_KP_6,
KEY_KP_7,
KEY_KP_8,
KEY_KP_9
]

var _infinity_count: int = -1

@onready var main_control: Control = %MainControl
Expand All @@ -22,12 +36,27 @@ var _infinity_count: int = -1
@onready var cat_sprite_2d: Sprite2D = %CatSprite2D
@onready var world_screen: WorldScreen = %WorldScreen
@onready var soul_sprite: SoulSprite = %SoulSprite
@onready var developer_console: DeveloperConsole = %DeveloperConsole

###############
## overrides ##
###############


func _input(event: InputEvent) -> void:
if event is InputEventKey and not developer_console.visible:
var tab_shortcut: int = -1
for key_shortcut: int in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
for shortcuts: Array in [SHORTCUTS_1, SHORTCUTS_2]:
var key: Key = shortcuts[key_shortcut]
if Input.is_key_pressed(key) or Input.is_physical_key_pressed(key):
tab_shortcut = key_shortcut
if Game.PARAMS["debug_logs"]:
prints("Shortcut input: ", key, key_shortcut)
if tab_shortcut != -1:
tab_tracker.change_tab_shortcut(tab_shortcut)


func _ready() -> void:
_connect_signals()
_initialize()
Expand Down
1 change: 1 addition & 0 deletions scenes/autostart/main/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ theme_override_constants/margin_right = 0
layout_mode = 2

[node name="DeveloperConsole" parent="CanvasLayer/MainControl/MainUI" instance=ExtResource("20_yijsf")]
unique_name_in_owner = true
visible = false
layout_mode = 1

Expand Down
9 changes: 9 additions & 0 deletions scenes/ui/tab_tracker/tab_tracker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,21 @@ func change_tab(index: int) -> void:
_handle_tab_clicked(tab_tracker_item._tab_data)


func change_tab_shortcut(number: int) -> void:
if number >= h_box_container.get_child_count():
return
var tab_tracker_item: TabTrackerItem = h_box_container.get_child(number)
_handle_tab_clicked(tab_tracker_item._tab_data)


##############
## handlers ##
##############


func _handle_tab_clicked(tab_data: TabData) -> void:
if tab_data == null:
return
for tab_tracker_item: TabTrackerItem in h_box_container.get_children():
if tab_tracker_item._tab_data.id == tab_data.id:
tab_tracker_item.button.disabled = true
Expand Down

0 comments on commit 29eb7f4

Please sign in to comment.