godot-third-person-basic-scene/scenes/hud/hud.gd

104 lines
2.9 KiB
GDScript

extends Control
var git_branch:String
var git_commit:String
var tag_release:String
func _ready():
#$MenuTheme.connect("update_theme", update_theme.bind())
#var fileCheck = FileAccess.open("res://commit.txt")
if FileAccess.file_exists("res://commit.txt"):
var file = FileAccess.open("res://commit.txt", FileAccess.READ)
tag_release = file.get_as_text().strip_escapes()
file = null # File is closed.
Common.msg_debug("Tag: " + tag_release)
elif FileAccess.file_exists("res://.git/HEAD"):
var file = FileAccess.open("res://.git/HEAD", FileAccess.READ)
var content = file.get_as_text().strip_escapes()
git_branch = content.split(' ')[1]
#file.open("res://.git/" + git_branch, FileAccess.READ)
file = null # File is closed.
file = FileAccess.open("res://.git/" + git_branch, FileAccess.READ)
git_commit = file.get_as_text().strip_escapes()
file = null # File is closed.
Common.msg_debug("Commit: " + git_commit)
else:
git_branch = "Unknown"
git_commit = "Unknown"
func update_theme():
var select_theme = load(Themes.THEMES_CONTROL[Themes.current_theme])
#$Control.set_theme(Themes.THEMES_CONTROL[Themes.current_theme])
Common.msg_debug($Control)
self.set_theme(select_theme)
func _input(_event:InputEvent):
if Input.is_action_just_pressed("ui_menu"):
$Menu.visible = ! $Menu.visible
if $Menu.visible:
# Force focus on Keys
$Menu/About.grab_focus()
Common.set_menu_visible(true)
else:
Common.set_menu_visible(false)
# elif $Menu.visible:
# if _event.is_action_pressed("INPUT_ACTION_RIGHT"):
# print("INPUT_ACTION_RIGHT 2")
# #$Control.accept_event()
# #Input.flush_buffered_events()
# elif _event.is_action_pressed("INPUT_ACTION_LEFT"):
# print("INPUT_ACTION_LEFT 2")
# elif Input.is_action_just_pressed("INPUT_ACTION_LEFT"):
# print("INPUT_ACTION_LEFT")
# elif Input.is_action_just_pressed("INPUT_ACTION_RIGHT"):
# print("INPUT_ACTION_RIGHT")
# #set_input_as_handled()
# #accept_event()
# #Viewport.set_input_as_handled()
# #self.get_parent_control().set_input_as_handled()
func _on_timer_timeout():
$Message/Label.visible = false
func _on_quit_pressed():
$ConfirmQuit.popup_centered()
$ConfirmQuit.visible = true
func _on_confirmation_dialog_confirmed():
get_tree().quit()
func _on_languages_pressed():
#$MenuLanguage/Window.popup_centered()
$MenuLanguage.show_window()
func _on_keys_pressed():
$MenuControl.configure_control()
$MenuControl/Window.visible = true
func _on_themes_pressed():
$MenuTheme/Window.popup_centered()
$MenuTheme/Window.visible = true
func _on_about_pressed():
var aboutmessage:String
if tag_release.is_empty():
aboutmessage = "Khaganat client test\nBranch: " + git_branch + "\nCommit: " + git_commit
else:
aboutmessage = "Khaganat client test\nVersion: " + tag_release
$AboutMessage.set_text(aboutmessage)
$AboutMessage.popup_centered()
$AboutMessage.visible = true
func _on_music_pressed():
$MusicManager.show_config()