gd: added menu template

This commit is contained in:
2025-06-10 18:46:20 +02:00
parent f9a6c42b14
commit c554e24b01
421 changed files with 12371 additions and 2 deletions

View File

@ -0,0 +1,79 @@
extends ScrollContainer
signal end_reached
@onready var header_space : Control = %HeaderSpace
@onready var footer_space : Control = %FooterSpace
@onready var credits_label : Control = %CreditsLabel
var timer : Timer = Timer.new()
@export var current_speed: float = 1.0
@export var scroll_restart_delay : float = 1.5
var _current_scroll_position : float = 0.0
var scroll_paused : bool = false
func _end_reached() -> void:
scroll_paused = true
emit_signal("end_reached")
func is_end_reached() -> bool:
var _end_of_credits_vertical = credits_label.size.y + header_space.size.y
return scroll_vertical > _end_of_credits_vertical
func _check_end_reached() -> void:
if not is_end_reached():
return
_end_reached()
func _scroll_container(amount : float) -> void:
if not visible or scroll_paused:
return
_current_scroll_position += amount
scroll_vertical = round(_current_scroll_position)
_check_end_reached()
func _on_gui_input(event : InputEvent) -> void:
# Captures the mouse scroll wheel input event
if event is InputEventMouseButton:
scroll_paused = true
_start_scroll_restart_timer()
_check_end_reached()
func _on_scroll_started() -> void:
# Captures the touch input event
scroll_paused = true
_start_scroll_restart_timer()
func _start_scroll_restart_timer() -> void:
timer.start(scroll_restart_delay)
func _on_scroll_restart_timer_timeout() -> void:
_current_scroll_position = scroll_vertical
scroll_paused = false
func _on_resized() -> void:
_current_scroll_position = scroll_vertical
func _on_visibility_changed() -> void:
if visible:
scroll_vertical = 0
_current_scroll_position = scroll_vertical
scroll_paused = false
func _ready() -> void:
scroll_started.connect(_on_scroll_started)
gui_input.connect(_on_gui_input)
resized.connect(_on_resized)
visibility_changed.connect(_on_visibility_changed)
timer.timeout.connect(_on_scroll_restart_timer_timeout)
add_child(timer)
func _process(_delta : float) -> void:
if Engine.is_editor_hint():
return
var input_axis = Input.get_axis("ui_up", "ui_down")
if input_axis != 0:
_scroll_container(10 * input_axis)
else:
_scroll_container(current_speed)

View File

@ -0,0 +1 @@
uid://gmrv6pgchkwc

View File

@ -0,0 +1,4 @@
class_name Credits
extends Control
signal end_reached

View File

@ -0,0 +1 @@
uid://xc4ebbm5dxnh

View File

@ -0,0 +1,87 @@
@tool
class_name CreditsLabel
extends RichTextLabel
@export_file("*.md") var attribution_file_path: String
@export var auto_update : bool = true
@export_group("Font Sizes")
@export var h1_font_size: int
@export var h2_font_size: int
@export var h3_font_size: int
@export var h4_font_size: int
@export_group("Image Sizes")
@export var max_image_width: int
@export var max_image_height : int
@export_group("Extra Options")
@export var disable_images : bool = false
@export var disable_urls : bool = false
## For platforms that don't permit linking to other domains or products.
@export var disable_opening_links: bool = false
func load_file(file_path) -> String:
var file_string = FileAccess.get_file_as_string(file_path)
if file_string == null:
push_warning("File open error: %s" % FileAccess.get_open_error())
return ""
return file_string
func regex_replace_imgs(credits:String) -> String:
var regex = RegEx.new()
var match_string := "!\\[([^\\]]*)\\]\\(([^\\)]*)\\)"
var replace_string := ""
if not disable_images:
replace_string = "res://$2[/img]"
if max_image_width:
if max_image_height:
replace_string = ("[img=%dx%d]" % [max_image_width, max_image_height]) + replace_string
else:
replace_string = ("[img=%d]" % [max_image_width]) + replace_string
else:
replace_string = "[img]" + replace_string
regex.compile(match_string)
regex.get_group_count()
return regex.sub(credits, replace_string, true)
func regex_replace_urls(credits:String) -> String:
var regex = RegEx.new()
var match_string := "\\[([^\\]]*)\\]\\(([^\\)]*)\\)"
var replace_string := "$1"
if not disable_urls:
replace_string = "[url=$2]$1[/url]"
regex.compile(match_string)
return regex.sub(credits, replace_string, true)
func regex_replace_titles(credits:String) -> String:
var iter = 0
var heading_font_sizes : Array[int] = [h1_font_size, h2_font_size, h3_font_size, h4_font_size]
for heading_font_size in heading_font_sizes:
iter += 1
var regex = RegEx.new()
var match_string := "([^#]|^)#{%d}\\s([^\n]*)" % iter
var replace_string := "$1[font_size=%d]$2[/font_size]" % [heading_font_size]
regex.compile(match_string)
credits = regex.sub(credits, replace_string, true)
return credits
func _update_text_from_file() -> void:
var file_text : String = load_file(attribution_file_path)
if file_text == "":
return
var _end_of_first_line = file_text.find("\n") + 1
file_text = file_text.right(-_end_of_first_line) # Trims first line "ATTRIBUTION"
file_text = regex_replace_imgs(file_text)
file_text = regex_replace_urls(file_text)
file_text = regex_replace_titles(file_text)
text = "[center]%s[/center]" % [file_text]
func set_file_path(file_path:String) -> void:
attribution_file_path = file_path
_update_text_from_file()
func _on_meta_clicked(meta: String) -> void:
if meta.begins_with("https://") and not disable_opening_links:
var _err = OS.shell_open(meta)
func _ready() -> void:
if not auto_update: return
set_file_path(attribution_file_path)

View File

@ -0,0 +1 @@
uid://cc2wtqasev7le

View File

@ -0,0 +1,12 @@
@tool
class_name ScrollableCredits
extends Credits
@onready var credits_label : RichTextLabel = %CreditsLabel
func _on_visibility_changed() -> void:
if visible:
credits_label.scroll_to_line(0)
func _ready() -> void:
visibility_changed.connect(_on_visibility_changed)

View File

@ -0,0 +1 @@
uid://c5wuso5r3dwpw

View File

@ -0,0 +1,29 @@
[gd_scene load_steps=3 format=3 uid="uid://osxulxw2oas3"]
[ext_resource type="Script" uid="uid://c5wuso5r3dwpw" path="res://addons/maaacks_game_template/base/scenes/credits/scrollable_credits.gd" id="1_hny8b"]
[ext_resource type="Script" uid="uid://cc2wtqasev7le" path="res://addons/maaacks_game_template/base/scenes/credits/credits_label.gd" id="2_g23vg"]
[node name="ScrollableCredits" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_hny8b")
[node name="CreditsLabel" type="RichTextLabel" parent="."]
unique_name_in_owner = true
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
bbcode_enabled = true
script = ExtResource("2_g23vg")
h1_font_size = 64
h2_font_size = 48
h3_font_size = 32
h4_font_size = 24
max_image_width = 80

View File

@ -0,0 +1,20 @@
class_name ScrollingCredits
extends Credits
@onready var header_space : Control = %HeaderSpace
@onready var footer_space : Control = %FooterSpace
@onready var credits_label : Control = %CreditsLabel
func set_header_and_footer() -> void:
header_space.custom_minimum_size.y = size.y
footer_space.custom_minimum_size.y = size.y
credits_label.custom_minimum_size.x = size.x
func _on_scroll_container_end_reached() -> void:
end_reached.emit()
func _on_resized() -> void:
set_header_and_footer()
func _ready() -> void:
resized.connect(_on_resized)

View File

@ -0,0 +1 @@
uid://bnub0cq2y0deh

View File

@ -0,0 +1,55 @@
[gd_scene load_steps=4 format=3 uid="uid://t2dui8ppm3a4"]
[ext_resource type="Script" uid="uid://gmrv6pgchkwc" path="res://addons/maaacks_game_template/base/scenes/credits/auto_scroll_container.gd" id="2_ak7hi"]
[ext_resource type="Script" uid="uid://cc2wtqasev7le" path="res://addons/maaacks_game_template/base/scenes/credits/credits_label.gd" id="3_kngql"]
[ext_resource type="Script" uid="uid://bnub0cq2y0deh" path="res://addons/maaacks_game_template/base/scenes/credits/scrolling_credits.gd" id="4"]
[node name="ScrollingCredits" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("4")
[node name="ScrollContainer" type="ScrollContainer" parent="."]
layout_mode = 0
anchor_right = 1.0
anchor_bottom = 1.0
scroll_vertical = 100
horizontal_scroll_mode = 0
vertical_scroll_mode = 3
script = ExtResource("2_ak7hi")
[node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
[node name="HeaderSpace" type="Control" parent="ScrollContainer/VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 720)
layout_mode = 2
[node name="CreditsLabel" type="RichTextLabel" parent="ScrollContainer/VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(1280, 0)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 5
bbcode_enabled = true
fit_content = true
scroll_active = false
script = ExtResource("3_kngql")
h1_font_size = 64
h2_font_size = 48
h3_font_size = 32
h4_font_size = 24
max_image_width = 80
[node name="FooterSpace" type="Control" parent="ScrollContainer/VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 720)
layout_mode = 2
[connection signal="end_reached" from="ScrollContainer" to="." method="_on_scroll_container_end_reached"]