Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Godot 4 #1

Merged
merged 17 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.import/
.godot/
.idea/
.DS_Store
exports/
Expand Down
17 changes: 4 additions & 13 deletions ATTRIBUTION.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
# Attribution
## Collaborators

### Role
Person 1
Person 2
[Person w/ Link]()


## Sourced / Unaffiliated
### Asset Type
#### Use Case
Author: [Name]()
Source: [Domain : webpage.html]()
License: [License]()

### Godot Game Template
Author: [Marek](https://github.com/Maaack)
Source: [github: Godot-Game-Template](https://github.com/Maaack/Godot-Game-Template)
License: [MIT License](LICENSE.txt)

## Tools
#### Godot
Expand Down
27 changes: 27 additions & 0 deletions ATTRIBUTION_example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Attribution
## Collaborators

### Role
Person 1
Person 2
[Person w/ Link]()


## Sourced / Unaffiliated
### Asset Type
#### Use Case
Author: [Name]()
Source: [Domain : webpage.html]()
License: [License]()


## Tools
#### Godot
Author: [Juan Linietsky, Ariel Manzur, and contributors](https://godotengine.org/contact)
Source: [godotengine.org](https://godotengine.org/)
License: [MIT License](https://github.com/godotengine/godot/blob/master/LICENSE.txt)

#### Git
Author: [Linus Torvalds](https://github.com/torvalds)
Source: [git-scm.com](https://git-scm.com/downloads)
License: [GNU General Public License version 2](https://opensource.org/licenses/GPL-2.0)
19 changes: 19 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2022-present Marek Belski.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Project Name
Made in Godot 3.5.0
# Godot Game Template
For Godot 4.1.2

This template has a dynamic main menu, pause menu, and credits scene. Multiple options menus to choose from with key rebinding and persistent config settings.

## Links
[Attribution](ATTRIBUTION.md)
[License](LICENSE.txt)
83 changes: 43 additions & 40 deletions Scenes/Credits/Credits.gd
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
@tool
extends Control


signal end_reached

onready var scroll_container = $ScrollContainer
onready var rich_text_label = $ScrollContainer/VBoxContainer/RichTextLabel
@onready var scroll_container = $ScrollContainer
@onready var rich_text_label = $ScrollContainer/VBoxContainer/RichTextLabel

export(String) var attribution_file_path : String = "res://ATTRIBUTION.md" setget set_file_path
export(DynamicFont) var h1_font
export(DynamicFont) var h2_font
export(DynamicFont) var h3_font
export(DynamicFont) var h4_font
export(float) var current_speed : float = 1.0
export var scroll_active : bool = true
@export_file("*.md") var attribution_file_path: String = "res://ATTRIBUTION.md": set = set_file_path
@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 var current_speed: float = 1.0
@export var scroll_active : bool = true

var scroll_paused : bool = false

func load_file(file_path):
var file : File = File.new()
var open_error : int = file.open(file_path, File.READ)
if open_error:
print("load file failed with error %d" % open_error)
var text : String = file.get_as_text()
file.close()
return text
var file_string = FileAccess.get_file_as_string(file_path)
if file_string == null:
print("File open error: %s" % FileAccess.get_open_error())
return file_string

func regex_replace_urls(credits:String):
var regex = RegEx.new()
Expand All @@ -34,30 +31,30 @@ func regex_replace_urls(credits:String):

func regex_replace_titles(credits:String):
var iter = 0
var heading_fonts : Array = [h1_font, h2_font, h3_font, h4_font]
for heading_font in heading_fonts:
if heading_font is DynamicFont:
iter += 1
var regex = RegEx.new()
var match_string : String = "([^#])#{%d}\\s([^\n]*)" % iter
var replace_string : String = "$1[font=%s]$2[/font]" % [heading_font.resource_path]
regex.compile(match_string)
credits = regex.sub(credits, replace_string, true)
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 : String = "([^#])#{%d}\\s([^\n]*)" % iter
var replace_string : 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 set_file_path(value:String):
var text : String = load_file(value)
func set_file_path(file_path:String):
attribution_file_path = file_path
var text : String = load_file(attribution_file_path)
if text == "":
return
text = text.right(text.find("\n")) # Trims first line "ATTRIBUTION"
text = text.right(-text.find("\n")) # Trims first line "ATTRIBUTION"
text = regex_replace_urls(text)
text = regex_replace_titles(text)
$ScrollContainer/VBoxContainer/RichTextLabel.bbcode_text = "[center]%s[/center]" % [text]
$ScrollContainer/VBoxContainer/RichTextLabel.text = "[center]%s[/center]" % [text]

func set_header_and_footer():
$ScrollContainer/VBoxContainer/HeaderSpace.rect_min_size.y = rect_size.y
$ScrollContainer/VBoxContainer/FooterSpace.rect_min_size.y = rect_size.y
$ScrollContainer/VBoxContainer/RichTextLabel.rect_min_size.x = rect_size.x
$ScrollContainer/VBoxContainer/HeaderSpace.custom_minimum_size.y = size.y
$ScrollContainer/VBoxContainer/FooterSpace.custom_minimum_size.y = size.y
$ScrollContainer/VBoxContainer/RichTextLabel.custom_minimum_size.x = size.x

func reset():
$ScrollContainer.scroll_vertical = 0
Expand All @@ -68,24 +65,30 @@ func _ready():
set_file_path(attribution_file_path)
set_header_and_footer()

func end_reached():
func _end_reached():
scroll_active = false
emit_signal("end_reached")

func _check_end_reached(previous_scroll):
if previous_scroll != $ScrollContainer.scroll_vertical:
return
end_reached()
_end_reached()

func _scroll_container() -> void:
if not scroll_active or scroll_paused or round(current_speed) == 0:
func _scroll_container(amount : float) -> void:
if not scroll_active or scroll_paused or round(amount) == 0:
return
var previous_scroll = $ScrollContainer.scroll_vertical
$ScrollContainer.scroll_vertical += round(current_speed)
$ScrollContainer.scroll_vertical += round(amount)
_check_end_reached(previous_scroll)

func _process(_delta):
_scroll_container()
if Engine.is_editor_hint():
return
var input_axis = Input.get_axis("move_up", "move_down")
if input_axis != 0:
_scroll_container(10 * input_axis)
else:
_scroll_container(current_speed)

func _on_RichTextLabel_gui_input(event):
if event is InputEventMouseButton:
Expand All @@ -94,7 +97,7 @@ func _on_RichTextLabel_gui_input(event):

func _start_scroll_timer():
var timer = get_tree().create_timer(1.5)
yield(timer, "timeout")
await timer.timeout
set_header_and_footer()
scroll_paused = false

Expand Down
64 changes: 42 additions & 22 deletions Scenes/Credits/Credits.tscn
Original file line number Diff line number Diff line change
@@ -1,47 +1,67 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=2 format=3 uid="uid://t2dui8ppm3a4"]

[ext_resource path="res://Scenes/Credits/Credits.gd" type="Script" id=4]
[ext_resource path="res://Scenes/Credits/HiddenScrollBar.tres" type="Theme" id=6]
[ext_resource type="Script" path="res://Scenes/Credits/Credits.gd" id="4"]

[node name="Credits" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 4 )
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("4")
h1_font_size = 64
h2_font_size = 48
h3_font_size = 32
h4_font_size = 24
scroll_active = false

[node name="ScrollContainer" type="ScrollContainer" parent="."]
layout_mode = 0
anchor_right = 1.0
anchor_bottom = 1.0
theme = ExtResource( 6 )
scroll_horizontal_enabled = false
scroll_vertical = 100
horizontal_scroll_mode = 0
vertical_scroll_mode = 3

[node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer"]
margin_right = 1024.0
margin_bottom = 2071.0
layout_mode = 2
size_flags_horizontal = 3

[node name="HeaderSpace" type="Control" parent="ScrollContainer/VBoxContainer"]
margin_right = 1024.0
margin_bottom = 1024.0
rect_min_size = Vector2( 0, 1024 )
custom_minimum_size = Vector2(0, 648)
layout_mode = 2

[node name="RichTextLabel" type="RichTextLabel" parent="ScrollContainer/VBoxContainer"]
margin_top = 1028.0
margin_right = 1024.0
margin_bottom = 1043.0
rect_min_size = Vector2( 1024, 0 )
focus_mode = 2
custom_minimum_size = Vector2(1152, 0)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 5
bbcode_enabled = true
fit_content_height = true
text = "[center]
[font_size=48]Collaborators[/font_size]

[font_size=32]Godot Game Template[/font_size]
Author: [url=https://github.com/Maaack]Marek[/url]
Source: [url=https://github.com/Maaack/Godot-Game-Template]github: Godot-Game-Template[/url]
License: [url=LICENSE.txt]MIT License[/url]

[font_size=48]Tools[/font_size]
[font_size=24]Godot[/font_size]
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]Git[/font_size]
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][/center]"
fit_content = true
scroll_active = false
selection_enabled = true

[node name="FooterSpace" type="Control" parent="ScrollContainer/VBoxContainer"]
margin_top = 1047.0
margin_right = 1024.0
margin_bottom = 2071.0
rect_min_size = Vector2( 0, 1024 )
custom_minimum_size = Vector2(0, 648)
layout_mode = 2

[node name="ScrollResetTimer" type="Timer" parent="."]
wait_time = 1.5
Expand Down
2 changes: 1 addition & 1 deletion Scenes/Credits/EndCredits.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ func end_reached():
node.show()

func _on_MenuButton_pressed():
get_tree().change_scene("res://Scenes/MainMenu/MainMenu.tscn")
get_tree().change_scene_to_file("res://Scenes/MainMenu/MainMenu.tscn")


func _on_ExitButton_pressed():
Expand Down
Loading