From 4cd9cd4925f8a02aac47740e743f61b14366e640 Mon Sep 17 00:00:00 2001 From: Page Asgardius Date: Sat, 7 Sep 2024 09:25:58 -0700 Subject: [PATCH] gamepad detect --- backgounds/disclaimer.gd | 18 +++++++++++++++++- backgounds/result.gd | 14 ++++++++++++++ backgounds/wip.gd | 16 +++++++++++++++- gamepad.gd | 2 +- levels/ui/alsatest.gd | 2 ++ levels/ui/ceres.gd | 4 +++- levels/ui/cscene.gd | 4 +++- levels/ui/debug.gd | 4 +++- levels/ui/missinggamepad.tscn | 27 +++++++++++++++++++++++++++ levels/ui/musictest.gd | 4 +++- levels/ui/newgame.gd | 4 +++- levels/ui/scene.gd | 2 ++ levels/ui/sfxtest.gd | 2 ++ levels/ui/soundtest.gd | 4 +++- levels/ui/testrooms.gd | 4 +++- levels/ui/tmenu.gd | 2 ++ levels/ui/vmboot.gd | 1 + main.gd | 16 ++++++++++++++++ project.godot | 1 + text.csv | 5 +++-- title.gd | 21 ++++++++++++++++++++- 21 files changed, 144 insertions(+), 13 deletions(-) create mode 100644 levels/ui/missinggamepad.tscn diff --git a/backgounds/disclaimer.gd b/backgounds/disclaimer.gd index ef6f844..83893ea 100644 --- a/backgounds/disclaimer.gd +++ b/backgounds/disclaimer.gd @@ -1,10 +1,14 @@ extends Node2D +var presscontinue +const gamepadtest = preload("res://gamepad.gd") var rmusic := AudioStreamPlayer.new() var wait # Called when the node enters the scene tree for the first time. func _ready(): - Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) + presscontinue = $Label2 + updatehud() + #Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) add_child(rmusic) var titlemusic = load(Global.musictracks[1]) rmusic.stream = titlemusic @@ -20,6 +24,8 @@ func _process(delta): pass func _input(event): + gamepadtest.new(event) + updatehud() # Mouse in viewport coordinates. if Input.is_action_just_pressed("ui_accept"): #print("Mouse Click/Unclick at: ", event.position) @@ -36,3 +42,13 @@ func _title(): #get_tree().root.add_child(title) #get_tree().root.remove_child(boot) #boot.queue_free() + +func updatehud(): + if Global.gamepad == 0: + presscontinue.set_text(tr("TEXT_CONTINUE_KB")) + elif Global.gamepad == 1: + presscontinue.set_text(tr("TEXT_CONTINUE_US")) + elif Global.gamepad == 2: + presscontinue.set_text(tr("TEXT_CONTINUE_JA")) + elif Global.gamepad == 3: + presscontinue.set_text(tr("TEXT_CONTINUE_GEO")) diff --git a/backgounds/result.gd b/backgounds/result.gd index ead5eea..7ace728 100644 --- a/backgounds/result.gd +++ b/backgounds/result.gd @@ -1,9 +1,12 @@ extends Node2D +var presscontinue var rmusic := AudioStreamPlayer.new() var wait # Called when the node enters the scene tree for the first time. func _ready(): + presscontinue = $Label2 + updatehud() Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) add_child(rmusic) var titlemusic = load(Global.musictracks[7]) @@ -19,6 +22,7 @@ func _process(delta): pass func _input(event): + updatehud() # Mouse in viewport coordinates. if Input.is_action_just_pressed("ui_accept"): #print("Mouse Click/Unclick at: ", event.position) @@ -34,3 +38,13 @@ func _title(): #get_tree().root.add_child(title) #get_tree().root.remove_child(boot) #boot.queue_free() + +func updatehud(): + if Global.gamepad == 0: + presscontinue.set_text(tr("TEXT_CONTINUE_KB")) + elif Global.gamepad == 1: + presscontinue.set_text(tr("TEXT_CONTINUE_US")) + elif Global.gamepad == 2: + presscontinue.set_text(tr("TEXT_CONTINUE_JA")) + elif Global.gamepad == 3: + presscontinue.set_text(tr("TEXT_CONTINUE_GEO")) diff --git a/backgounds/wip.gd b/backgounds/wip.gd index 74eaf21..02b368e 100644 --- a/backgounds/wip.gd +++ b/backgounds/wip.gd @@ -1,10 +1,13 @@ extends Node2D +var presscontinue var rmusic := AudioStreamPlayer.new() var wait # Called when the node enters the scene tree for the first time. func _ready(): - Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) + presscontinue = $Label2 + updatehud() + #Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) add_child(rmusic) var titlemusic = load(Global.musictracks[1]) rmusic.stream = titlemusic @@ -19,6 +22,7 @@ func _process(delta): pass func _input(event): + updatehud() # Mouse in viewport coordinates. if Input.is_action_just_pressed("ui_accept"): #print("Mouse Click/Unclick at: ", event.position) @@ -34,3 +38,13 @@ func _title(): #get_tree().root.add_child(title) #get_tree().root.remove_child(boot) #boot.queue_free() + +func updatehud(): + if Global.gamepad == 0: + presscontinue.set_text(tr("TEXT_CONTINUE_KB")) + elif Global.gamepad == 1: + presscontinue.set_text(tr("TEXT_CONTINUE_US")) + elif Global.gamepad == 2: + presscontinue.set_text(tr("TEXT_CONTINUE_JA")) + elif Global.gamepad == 3: + presscontinue.set_text(tr("TEXT_CONTINUE_GEO")) diff --git a/gamepad.gd b/gamepad.gd index e29ad08..b1e6c28 100644 --- a/gamepad.gd +++ b/gamepad.gd @@ -7,7 +7,7 @@ func _init(event): Global.gamepad = 2 elif str(Input.get_joy_name(0)).begins_with("Sony Computer Entertainment") || str(Input.get_joy_name(0)).begins_with("PS4") || str(Input.get_joy_name(0)).begins_with("PS5"): Global.gamepad = 3 - elif Global.gamepad == 0 && str(Input.get_joy_name(0)).is_empty(): + elif !str(Input.get_joy_name(0)).is_empty(): Global.gamepad = 1 if event is InputEventMouse: Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) diff --git a/levels/ui/alsatest.gd b/levels/ui/alsatest.gd index 66ab347..8916c64 100644 --- a/levels/ui/alsatest.gd +++ b/levels/ui/alsatest.gd @@ -1,4 +1,5 @@ extends Control +const gamepadtest = preload("res://gamepad.gd") var bgsound := AudioStreamPlayer.new() var fl var fr @@ -27,6 +28,7 @@ func _ready() -> void: bgsound.play(0) func _input(event): + gamepadtest.new(event) # Mouse in viewport coordinates. if Input.is_action_just_pressed("ui_cancel"): get_tree().change_scene_to_file("res://levels/ui/soundtest.tscn") diff --git a/levels/ui/ceres.gd b/levels/ui/ceres.gd index bd1e895..fa31f93 100644 --- a/levels/ui/ceres.gd +++ b/levels/ui/ceres.gd @@ -1,6 +1,7 @@ extends Control +const gamepadtest = preload("res://gamepad.gd") func _ready(): - Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) + #Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) $VBoxContainer/L20.grab_focus() # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -24,6 +25,7 @@ func _level(): #boot.queue_free() func _input(event): + gamepadtest.new(event) # Mouse in viewport coordinates. if Input.is_action_just_pressed("ui_cancel"): _on_back_pressed() diff --git a/levels/ui/cscene.gd b/levels/ui/cscene.gd index 3baf2eb..b3a9d50 100644 --- a/levels/ui/cscene.gd +++ b/levels/ui/cscene.gd @@ -1,6 +1,7 @@ extends Control +const gamepadtest = preload("res://gamepad.gd") func _ready(): - Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) + #Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) $"VBoxContainer/Disclaimer".grab_focus() # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -24,6 +25,7 @@ func _level(): #boot.queue_free() func _input(event): + gamepadtest.new(event) # Mouse in viewport coordinates. if Input.is_action_just_pressed("ui_cancel"): _on_back_pressed() diff --git a/levels/ui/debug.gd b/levels/ui/debug.gd index 37fd917..74285fb 100644 --- a/levels/ui/debug.gd +++ b/levels/ui/debug.gd @@ -1,7 +1,8 @@ extends Control +const gamepadtest = preload("res://gamepad.gd") func _ready(): _statrebase() - Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) + #Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) Global.debug = true $"VBoxContainer/Gamepad Test".grab_focus() @@ -26,6 +27,7 @@ func _level(): #boot.queue_free() func _input(event): + gamepadtest.new(event) # Mouse in viewport coordinates. if Input.is_action_just_pressed("ui_cancel"): _on_back_pressed() diff --git a/levels/ui/missinggamepad.tscn b/levels/ui/missinggamepad.tscn new file mode 100644 index 0000000..b10f850 --- /dev/null +++ b/levels/ui/missinggamepad.tscn @@ -0,0 +1,27 @@ +[gd_scene format=3 uid="uid://cbeya2ihapatq"] + +[node name="Missinggamepad" type="Node2D"] + +[node name="ColorRect" type="ColorRect" parent="."] +offset_left = 105.0 +offset_top = 211.0 +offset_right = 1177.0 +offset_bottom = 511.0 +color = Color(0, 0, 0, 1) + +[node name="Label" type="Label" parent="."] +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = 105.0 +offset_top = 211.0 +offset_right = 1177.0 +offset_bottom = 511.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_font_sizes/font_size = 40 +text = "TEXT_GAMEPAD_DISCONNECTED" +horizontal_alignment = 1 +vertical_alignment = 1 diff --git a/levels/ui/musictest.gd b/levels/ui/musictest.gd index 38a4d04..9547ada 100644 --- a/levels/ui/musictest.gd +++ b/levels/ui/musictest.gd @@ -1,10 +1,11 @@ extends Control +const gamepadtest = preload("res://gamepad.gd") var player := AudioStreamPlayer.new() var infobox func _ready(): - Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) + #Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) add_child(player) player.mix_target = 1 player.bus = &"Music" @@ -33,6 +34,7 @@ func _level(): #boot.queue_free() func _input(event): + gamepadtest.new(event) # Mouse in viewport coordinates. if Input.is_action_just_pressed("ui_cancel"): _on_back_pressed() diff --git a/levels/ui/newgame.gd b/levels/ui/newgame.gd index bed714e..52b499b 100644 --- a/levels/ui/newgame.gd +++ b/levels/ui/newgame.gd @@ -1,6 +1,7 @@ extends Control +const gamepadtest = preload("res://gamepad.gd") func _ready(): - Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) + #Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) $VBoxContainer/Thisfirst.grab_focus() # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -24,6 +25,7 @@ func _level(): #boot.queue_free() func _input(event): + gamepadtest.new(event) if Input.is_action_just_pressed("ui_cancel"): get_tree().change_scene_to_file("res://levels/ui/tmenu.tscn") # Mouse in viewport coordinates. diff --git a/levels/ui/scene.gd b/levels/ui/scene.gd index e4f466a..2b0e5a4 100644 --- a/levels/ui/scene.gd +++ b/levels/ui/scene.gd @@ -1,4 +1,5 @@ extends Control +const gamepadtest = preload("res://gamepad.gd") func _ready(): Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) $"VBoxContainer/Disclaimer".grab_focus() @@ -24,6 +25,7 @@ func _level(): #boot.queue_free() func _input(event): + gamepadtest.new(event) # Mouse in viewport coordinates. if Input.is_action_just_pressed("ui_cancel"): _on_back_pressed() diff --git a/levels/ui/sfxtest.gd b/levels/ui/sfxtest.gd index 19754f2..582edc3 100644 --- a/levels/ui/sfxtest.gd +++ b/levels/ui/sfxtest.gd @@ -1,4 +1,5 @@ extends Control +const gamepadtest = preload("res://gamepad.gd") var player := AudioStreamPlayer.new() @@ -31,6 +32,7 @@ func _level(): #boot.queue_free() func _input(event): + gamepadtest.new(event) # Mouse in viewport coordinates. if Input.is_action_just_pressed("ui_cancel"): _on_back_pressed() diff --git a/levels/ui/soundtest.gd b/levels/ui/soundtest.gd index 78455e6..50d7c31 100644 --- a/levels/ui/soundtest.gd +++ b/levels/ui/soundtest.gd @@ -1,7 +1,8 @@ extends Control +const gamepadtest = preload("res://gamepad.gd") var alsatest func _ready(): - Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) + #Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) alsatest = $VBoxContainer/ALSA $"VBoxContainer/Music".grab_focus() if OS.get_name() == "Linux": @@ -13,6 +14,7 @@ func _process(delta): func _input(event): + gamepadtest.new(event) # Mouse in viewport coordinates. if Input.is_action_just_pressed("ui_cancel"): _on_back_pressed() diff --git a/levels/ui/testrooms.gd b/levels/ui/testrooms.gd index 819c20e..43b7966 100644 --- a/levels/ui/testrooms.gd +++ b/levels/ui/testrooms.gd @@ -1,6 +1,7 @@ extends Control +const gamepadtest = preload("res://gamepad.gd") func _ready(): - Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) + #Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) $"VBoxContainer/Testspawn".grab_focus() # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -24,6 +25,7 @@ func _level(): #boot.queue_free() func _input(event): + gamepadtest.new(event) # Mouse in viewport coordinates. if Input.is_action_just_pressed("ui_cancel"): _on_back_pressed() diff --git a/levels/ui/tmenu.gd b/levels/ui/tmenu.gd index bfd1ded..a2ccbf3 100644 --- a/levels/ui/tmenu.gd +++ b/levels/ui/tmenu.gd @@ -1,4 +1,5 @@ extends Control +const gamepadtest = preload("res://gamepad.gd") func _ready(): Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) $VBoxContainer/Start.grab_focus() @@ -24,6 +25,7 @@ func _level(): #boot.queue_free() func _input(event): + gamepadtest.new(event) if Input.is_action_just_pressed("ui_cancel"): get_tree().change_scene_to_file("res://title.tscn") # Mouse in viewport coordinates. diff --git a/levels/ui/vmboot.gd b/levels/ui/vmboot.gd index 9d2f99f..0c91768 100644 --- a/levels/ui/vmboot.gd +++ b/levels/ui/vmboot.gd @@ -4,6 +4,7 @@ var stage = 0 var bg # Called when the node enters the scene tree for the first time. func _ready(): + Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) bg = $TextureRect bg.texture = load(backgrounds[stage]) #pass # Replace with function body. diff --git a/main.gd b/main.gd index 6371b8e..3d95e25 100644 --- a/main.gd +++ b/main.gd @@ -1,4 +1,6 @@ extends Node +var presscontinue +const gamepadtest = preload("res://gamepad.gd") const loadgame = preload("res://load.gd") const savegame = preload("res://save.gd") @@ -6,6 +8,8 @@ const savegame = preload("res://save.gd") # Called when the node enters the scene tree for the first time. func _ready(): + presscontinue = $Label + updatehud() Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) #OS.get_data_dir().rsplit("/", true, 7)[2] #loadgame.new() @@ -22,6 +26,9 @@ func _process(delta): pass func _input(event): + gamepadtest.new(event) + updatehud() + # Mouse in viewport coordinates. if !Global.sk && Input.is_action_just_pressed("ui_accept"): #print("Mouse Click/Unclick at: ", event.position) @@ -34,3 +41,12 @@ func _title(): #get_tree().root.add_child(title) #get_tree().root.remove_child(boot) #boot.queue_free() +func updatehud(): + if Global.gamepad == 0: + presscontinue.set_text(tr("TEXT_CONTINUE_KB")) + elif Global.gamepad == 1: + presscontinue.set_text(tr("TEXT_CONTINUE_US")) + elif Global.gamepad == 2: + presscontinue.set_text(tr("TEXT_CONTINUE_JA")) + elif Global.gamepad == 3: + presscontinue.set_text(tr("TEXT_CONTINUE_GEO")) diff --git a/project.godot b/project.godot index bbde18f..f28b4c5 100644 --- a/project.godot +++ b/project.godot @@ -103,6 +103,7 @@ Pause={ [internationalization] locale/translations=PackedStringArray("res://text.en.translation", "res://text.es.translation", "res://text.ja.translation") +locale/test="en" [physics] diff --git a/text.csv b/text.csv index f47ce4b..9e9a171 100644 --- a/text.csv +++ b/text.csv @@ -1,5 +1,6 @@ ;en;es;ja TEXT_DISCLAIMER;Disclaimer\nPlaying with fireworks inside a videogame can give hours of fun,\nbut in real life is dangerous\nLife insurance exists only on fiction;Descargo de responsabilidad\nJugar con explosivos dentro de un videojuego puede dar horas de diversión\npero en la vida real es peligroso\nLos seguros de vida solamente existen en la ficción;免責事項\nビデオゲームの中で花火で遊ぶと何時間も楽しめます。\nしかし現実では危険である\n生命保険はフィクションの上にのみ存在する +TEXT_GAMEPAD_DISCONNECTED;Game Controller was disconnected\nPlease connect you game controller again\nand press any button\nor press Enter to continue with keyboard; El mando de juego ha sido desconectado\nFavor de conectar el mando y presione cualquier botón\no presione Intro para continuar con el teclado;ゲーム コントローラが切断されました\nゲーム コントローラを再度接続し、任意のボタンを押す\nか、キーボードで Enter キーを押して続行してください。 TEXT_WIP;This game is under development\nMore content will be added in following releases;Este juego está en desarrollo\nMás contenido se agregará en los siguientes lanzamientos;このゲームは現在開発中です\n今後のリリースではさらにコンテンツが追加される予定です TEXT_CONTINUE;Press Enter or B to continue;Presiona Intro o B para continuar;Enter または B を押して続行します TEXT_CONTINUE_KB;Press Enter to continue;Presiona Intro para continuar;Enterを押して続行します @@ -132,8 +133,8 @@ CUTSCENE_0_0;most underrated children will be the best magicians\nFalcighol Arch CUTSCENE_0_1;Hello, my name is Midori Asgardius, I am a 15 year old elf girl;Hola, mi nombre es Midori Asgardius,\nSoy una niña elfo de 15 años;こんにちは、私の名前はミドリ・アスガルディウスです。\n15歳のエルフの女の子です CUTSCENE_0_2;They say I run around here and there as if fear didn't exist;Dicen que corro de aquí para allá como si el miedo no existiera;まるで恐怖が存在しないかのように、私はあちこち走り回っていると彼らは言う CUTSCENE_0_3;But I'm actually a pretty shy and reserved girl;Pero en realidad soy una niña bastante tímida y reservada;でも実際は私はかなり内気で控えめな女の子です -CUTSCENE_0_4;I love reading, when I concentrate\nno one will bother me;Me encanta leer, cuando me\nconcentro nadie me molestará;私は読書が大好きです。集中すれば誰にも邪魔されません -CUTSCENE_0_5;A very funny anecdote was when I set fire to\nmy adoptive mother's, trophy room;Una anécdota muy divertida fue cuando incendié la\nsala de trofeos de mi madre adoptiva;とても面白い逸話は、\n私が養母のトロフィールームに火をつけた時のことです +CUTSCENE_0_4;I love reading, when I concentrate\nnobody will bother me;Me encanta leer, cuando me\nconcentro nadie me molestará;私は読書が大好きです。集中すれば誰にも邪魔されません +CUTSCENE_0_5;A very funny anecdote was when I set fire to\nmy adoptive mother's trophy room;Una anécdota muy divertida fue cuando incendié la\nsala de trofeos de mi madre adoptiva;とても面白い逸話は、\n私が養母のトロフィールームに火をつけた時のことです CUTSCENE_1_0;The punishment that day was very painful\nI was crying for the rest of the day;El castigo de ese dia fue muy doloroso\nEstuve llorando el resto del dia;その日の罰はとても痛かった\n私は一日中泣いていた CUTSCENE_1_1;According to my father, my adoptive mother was crying as well;Segun mi padre, mi madre adoptiva también estuvo llorando;父によると、養母も泣いていたそうです CUTSCENE_1_2;Tonight the asteroid in the sky looks beautiful;Esta noche el asteroide en el cielo se ve hermoso;今夜、空の小惑星は美しく見える diff --git a/title.gd b/title.gd index f236e99..b22f902 100644 --- a/title.gd +++ b/title.gd @@ -1,5 +1,6 @@ extends Control - +var presscontinue +var pressexit # Called when the node enters the scene tree for the first time. var bgsound := AudioStreamPlayer.new() @@ -9,6 +10,9 @@ const gamepadtest = preload("res://gamepad.gd") #var wormhole = preload("res://backgounds/wormhole.tscn").instantiate() func _ready(): + presscontinue = $start + pressexit = $exit + updatehud() #Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN) #if (OS.get_name() != "Linux" && !OS.get_name().ends_with("BSD")) || OS.get_distribution_name().contains("Kali") || !OS.get_data_dir().begins_with("/home") || OS.get_environment("WSL_DISTRO_NAME").length() < 0: # Global.sk = true @@ -30,6 +34,7 @@ func _process(delta): func _input(event): # Mouse in viewport coordinates. gamepadtest.new(event) + updatehud() if Input.is_action_just_pressed("ui_accept"): #print("Mouse Click/Unclick at: ", event.position) get_tree().change_scene_to_file("res://levels/ui/tmenu.tscn") @@ -52,3 +57,17 @@ func _level(): #get_tree().root.add_child(title) #get_tree().root.remove_child(boot) #boot.queue_free() + +func updatehud(): + if Global.gamepad == 0: + presscontinue.set_text(tr("TEXT_START_KB")) + pressexit.set_text(tr("TEXT_EXIT_KB")) + elif Global.gamepad == 1: + presscontinue.set_text(tr("TEXT_START_US")) + pressexit.set_text(tr("TEXT_EXIT_US")) + elif Global.gamepad == 2: + presscontinue.set_text(tr("TEXT_START_JA")) + pressexit.set_text(tr("TEXT_EXIT_JA")) + elif Global.gamepad == 3: + presscontinue.set_text(tr("TEXT_START_GEO")) + pressexit.set_text(tr("TEXT_EXIT_GEO"))