Basic game template addon
This commit is contained in:
56
menus/scenes/credits/credits_label.tscn
Normal file
56
menus/scenes/credits/credits_label.tscn
Normal file
@@ -0,0 +1,56 @@
|
||||
[gd_scene format=3 uid="uid://coug8dvtetdu6"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/maaacks_game_template/base/nodes/labels/credits_label.gd" id="1_ao6uf"]
|
||||
|
||||
[node name="CreditsLabel" type="RichTextLabel"]
|
||||
custom_minimum_size = Vector2(1280, 0)
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 5
|
||||
bbcode_enabled = true
|
||||
text = "[font_size=48]Collaborators[/font_size]
|
||||
|
||||
[font_size=32]Role[/font_size]
|
||||
Person 1
|
||||
Person 2
|
||||
[url=]Person w/ Link[/url]
|
||||
|
||||
[font_size=48]Sourced[/font_size]
|
||||
[font_size=32]Asset Type[/font_size]
|
||||
[font_size=24]Use Case[/font_size]
|
||||
Author: [url=]Name[/url]
|
||||
Source: [url=]Domain : webpage.html[/url]
|
||||
License: [url=]License[/url]
|
||||
|
||||
[font_size=24]Godot Engine Logo[/font_size]
|
||||
Author: Andrea Calabró
|
||||
Source: [url=https://godotengine.org/press/]godotengine.org : press[/url]
|
||||
License: [url=https://github.com/godotengine/godot/blob/master/LOGO_LICENSE.txt]CC BY 4.0 International[/url]
|
||||
|
||||
[font_size=48]Tools[/font_size]
|
||||
[font_size=24]Godot[/font_size]
|
||||
[img=80]res:///menus/assets/godot_engine_logo/logo_vertical_color_dark.png[/img]
|
||||
Author: [url=https://godotengine.org/contact]Juan Linietsky, Ariel Manzur, and contributors[/url]
|
||||
Source: [url=https://godotengine.org/]godotengine.org[/url]
|
||||
License: [url=https://github.com/godotengine/godot/blob/master/LICENSE.txt]MIT License[/url]
|
||||
|
||||
[font_size=24]Godot Minimal Game Template[/font_size]
|
||||
[img=80]res:///menus/assets/plugin_logo/logo.png[/img]
|
||||
Author: [url=https://github.com/Maaack/Godot-Minimal-Game-Template/graphs/contributors]Marek Belski and contributors[/url]
|
||||
Source: [url=https://github.com/Maaack/Godot-Minimal-Game-Template]github: Godot-Minimal-Game-Template[/url]
|
||||
License: [url=LICENSE.txt]MIT License[/url]
|
||||
|
||||
[font_size=24]Git[/font_size]
|
||||
[img=80]res:///menus/assets/git_logo/Git-Logo-2Color.png[/img]
|
||||
Author: [url=https://github.com/torvalds]Linus Torvalds[/url]
|
||||
Source: [url=https://git-scm.com/downloads]git-scm.com[/url]
|
||||
License: [url=https://opensource.org/licenses/GPL-2.0]GNU General Public License version 2[/url]
|
||||
"
|
||||
fit_content = true
|
||||
scroll_active = false
|
||||
horizontal_alignment = 1
|
||||
script = ExtResource("1_ao6uf")
|
||||
29
menus/scenes/credits/scrollable_credits.gd
Normal file
29
menus/scenes/credits/scrollable_credits.gd
Normal file
@@ -0,0 +1,29 @@
|
||||
@tool
|
||||
extends Control
|
||||
|
||||
@onready var credits_label : RichTextLabel = %CreditsLabel
|
||||
|
||||
@export var input_scroll_speed : float = 10.0
|
||||
|
||||
var _line_number : float = 0
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if visible:
|
||||
credits_label.scroll_to_line(0)
|
||||
credits_label.grab_focus()
|
||||
|
||||
func _ready() -> void:
|
||||
visibility_changed.connect(_on_visibility_changed)
|
||||
|
||||
func _process(delta : float) -> void:
|
||||
if Engine.is_editor_hint() or not visible:
|
||||
return
|
||||
var input_axis = Input.get_axis("ui_up", "ui_down")
|
||||
if abs(input_axis) > 0.5:
|
||||
_line_number += input_axis * delta * input_scroll_speed
|
||||
var max_lines = credits_label.get_line_count() - credits_label.get_visible_line_count()
|
||||
if _line_number < 0:
|
||||
_line_number = 0
|
||||
if _line_number > max_lines:
|
||||
_line_number = max_lines
|
||||
credits_label.scroll_to_line(round(_line_number))
|
||||
1
menus/scenes/credits/scrollable_credits.gd.uid
Normal file
1
menus/scenes/credits/scrollable_credits.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dyf426wsn270l
|
||||
19
menus/scenes/credits/scrollable_credits.tscn
Normal file
19
menus/scenes/credits/scrollable_credits.tscn
Normal file
@@ -0,0 +1,19 @@
|
||||
[gd_scene format=3 uid="uid://1y3twyudd5l8"]
|
||||
|
||||
[ext_resource type="Script" path="res://menus/scenes/credits/scrollable_credits.gd" id="1_gcb84"]
|
||||
[ext_resource type="PackedScene" path="res://menus/scenes/credits/credits_label.tscn" id="2_nuv7p"]
|
||||
|
||||
[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_gcb84")
|
||||
|
||||
[node name="CreditsLabel" parent="." instance=ExtResource("2_nuv7p")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 1
|
||||
fit_content = false
|
||||
scroll_active = true
|
||||
92
menus/scenes/credits/scrolling_credits.gd
Normal file
92
menus/scenes/credits/scrolling_credits.gd
Normal file
@@ -0,0 +1,92 @@
|
||||
@tool
|
||||
extends Control
|
||||
|
||||
signal end_reached
|
||||
|
||||
@export var auto_scroll_speed: float = 60.0
|
||||
@export var input_scroll_speed : float = 400.0
|
||||
@export var scroll_restart_delay : float = 1.5
|
||||
@export var scroll_paused : bool = false
|
||||
|
||||
var timer : Timer = Timer.new()
|
||||
var _current_scroll_position : float = 0.0
|
||||
|
||||
@onready var header_space : Control = %HeaderSpace
|
||||
@onready var footer_space : Control = %FooterSpace
|
||||
@onready var credits_label : Control = %CreditsLabel
|
||||
@onready var scroll_container : ScrollContainer = %ScrollContainer
|
||||
|
||||
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_resized() -> void:
|
||||
set_header_and_footer()
|
||||
_current_scroll_position = scroll_container.scroll_vertical
|
||||
|
||||
func _end_reached() -> void:
|
||||
scroll_paused = true
|
||||
end_reached.emit()
|
||||
|
||||
func is_end_reached() -> bool:
|
||||
var _end_of_credits_vertical = credits_label.size.y + header_space.size.y
|
||||
return scroll_container.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_container.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_container.scroll_vertical
|
||||
scroll_paused = false
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if visible:
|
||||
scroll_container.scroll_vertical = 0
|
||||
_current_scroll_position = scroll_container.scroll_vertical
|
||||
scroll_paused = false
|
||||
|
||||
func _ready() -> void:
|
||||
scroll_container.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)
|
||||
set_header_and_footer()
|
||||
add_child(timer)
|
||||
scroll_paused = false
|
||||
|
||||
|
||||
func _process(delta : float) -> void:
|
||||
var input_axis = Input.get_axis("ui_up", "ui_down")
|
||||
if input_axis != 0:
|
||||
_scroll_container(input_axis * input_scroll_speed * delta)
|
||||
else:
|
||||
_scroll_container(auto_scroll_speed * delta)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
_current_scroll_position = scroll_container.scroll_vertical
|
||||
1
menus/scenes/credits/scrolling_credits.gd.uid
Normal file
1
menus/scenes/credits/scrolling_credits.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://c1ac47rxkskux
|
||||
40
menus/scenes/credits/scrolling_credits.tscn
Normal file
40
menus/scenes/credits/scrolling_credits.tscn
Normal file
@@ -0,0 +1,40 @@
|
||||
[gd_scene format=3 uid="uid://c6r0n1kinvqj7"]
|
||||
|
||||
[ext_resource type="Script" path="res://menus/scenes/credits/scrolling_credits.gd" id="1_hy305"]
|
||||
[ext_resource type="PackedScene" path="res://menus/scenes/credits/credits_label.tscn" id="2_ymsg3"]
|
||||
|
||||
[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("1_hy305")
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
scroll_vertical = 0
|
||||
horizontal_scroll_mode = 0
|
||||
vertical_scroll_mode = 3
|
||||
|
||||
[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" parent="ScrollContainer/VBoxContainer" instance=ExtResource("2_ymsg3")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[node name="FooterSpace" type="Control" parent="ScrollContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(0, 720)
|
||||
layout_mode = 2
|
||||
Reference in New Issue
Block a user