summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorrom <romangraef@gmail.com>2021-04-25 00:48:50 +0200
committerrom <romangraef@gmail.com>2021-04-25 00:49:01 +0200
commite1f67cda480d596c8d52d6c0d666e40297cc70fa (patch)
tree8c3159afb42c8cdfd956514dc728ebee340d68f2 /components
parent66a83b84af05256c468f4cc47545ce592a9353fc (diff)
downloadldjam48-e1f67cda480d596c8d52d6c0d666e40297cc70fa.tar.gz
ldjam48-e1f67cda480d596c8d52d6c0d666e40297cc70fa.tar.bz2
ldjam48-e1f67cda480d596c8d52d6c0d666e40297cc70fa.zip
centralize fonts and make textreveal a node
Diffstat (limited to 'components')
-rw-r--r--components/button.gd4
-rw-r--r--components/button.tscn27
-rw-r--r--components/textreveal.gd24
-rw-r--r--components/textreveal.tscn18
4 files changed, 16 insertions, 57 deletions
diff --git a/components/button.gd b/components/button.gd
index 1171cbd..f5f1606 100644
--- a/components/button.gd
+++ b/components/button.gd
@@ -15,11 +15,11 @@ var is_hovered = false
onready var stretcher : Node2D = $Middle
onready var left : Node2D = $Left
onready var right : Node2D = $Right
-onready var font_source : RichTextLabel = $FontSource
onready var hitbox : CollisionShape2D = $Hitbox
const BASE_WIDTH = 6
const BASE_HEIGHT = 16
+const theme : Theme = preload("res://fonts/Flipps_Theme.tres")
const left_nohover = preload("res://textures/components/button/left.png")
const left_hover = preload("res://textures/components/button/left_hover.png")
const left_press = preload("res://textures/components/button/left_press.png")
@@ -35,7 +35,7 @@ var label
func _ready():
label = Label.new()
label.text = text
- label.theme = font_source.theme
+ label.theme = theme
add_child(label)
label.rect_position = -label.rect_size / 2
var width = label.rect_size.x
diff --git a/components/button.tscn b/components/button.tscn
index 6248b45..0fda370 100644
--- a/components/button.tscn
+++ b/components/button.tscn
@@ -1,19 +1,11 @@
-[gd_scene load_steps=9 format=2]
+[gd_scene load_steps=6 format=2]
[ext_resource path="res://textures/components/button/middle.png" type="Texture" id=1]
[ext_resource path="res://textures/components/button/right.png" type="Texture" id=2]
-[ext_resource path="res://fonts/Fipps-Regular.otf" type="DynamicFontData" id=3]
[ext_resource path="res://textures/components/button/left.png" type="Texture" id=4]
[ext_resource path="res://components/button.gd" type="Script" id=5]
-[sub_resource type="DynamicFont" id=1]
-outline_color = Color( 0, 0, 0, 1 )
-font_data = ExtResource( 3 )
-
-[sub_resource type="Theme" id=2]
-default_font = SubResource( 1 )
-
-[sub_resource type="RectangleShape2D" id=3]
+[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 10, 32 )
[node name="Button" type="Area2D"]
@@ -34,20 +26,9 @@ position = Vector2( -0.5, 0 )
scale = Vector2( 30.321, 4 )
texture = ExtResource( 1 )
-[node name="FontSource" type="RichTextLabel" parent="."]
-grow_horizontal = 2
-grow_vertical = 2
-rect_clip_content = false
-size_flags_horizontal = 3
-theme = SubResource( 2 )
-text = "Menu"
-scroll_active = false
-__meta__ = {
-"_edit_use_anchors_": false
-}
-
[node name="Hitbox" type="CollisionShape2D" parent="."]
-shape = SubResource( 3 )
+shape = SubResource( 1 )
+
[connection signal="input_event" from="." to="." method="_on_ButtonTest_input_event"]
[connection signal="mouse_entered" from="." to="." method="_on_ButtonTest_mouse_entered"]
[connection signal="mouse_exited" from="." to="." method="_on_ButtonTest_mouse_exited"]
diff --git a/components/textreveal.gd b/components/textreveal.gd
index 1685a8d..d76282a 100644
--- a/components/textreveal.gd
+++ b/components/textreveal.gd
@@ -1,8 +1,9 @@
-extends Node2D
+extends Label
+class_name TextReveal
signal finished_reveal()
-export(String, MULTILINE) var text = "Text"
+export(String, MULTILINE) var to_render = "Text"
export var speed = 100.0
############
@@ -10,23 +11,15 @@ export var speed = 100.0
############
-onready var font_source : RichTextLabel = $FontSource
var revealed = 0
var started = false
var finished = false
var t = 0
-onready var label = Label.new()
# Called when the node enters the scene tree for the first time.
func _ready():
- label.theme = font_source.theme
- label.align = Label.ALIGN_CENTER
- add_child(label)
-
-
-func _show_text(text):
- label.text = text
- label.rect_position = -label.rect_size / 2
+ theme = preload("res://fonts/Flipps_Theme.tres")
+ align = Label.ALIGN_CENTER
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
@@ -36,15 +29,16 @@ func _process(delta):
var additional = int(t)
t -= additional
revealed += additional
- _show_text(text.substr(0, revealed))
- if text.length() == revealed:
+ text = to_render.substr(0, revealed)
+ rect_position = -rect_size / 2
+ if to_render.length() == revealed:
started = false
finished = true
emit_signal("finished_reveal")
func start():
started = true
- label.text = ""
+ text = ""
revealed = 0
t = 0
finished = false
diff --git a/components/textreveal.tscn b/components/textreveal.tscn
index a6d9cbb..455bb49 100644
--- a/components/textreveal.tscn
+++ b/components/textreveal.tscn
@@ -1,22 +1,6 @@
-[gd_scene load_steps=5 format=2]
+[gd_scene load_steps=2 format=2]
[ext_resource path="res://components/textreveal.gd" type="Script" id=1]
-[ext_resource path="res://fonts/Fipps-Regular.otf" type="DynamicFontData" id=2]
-
-[sub_resource type="DynamicFont" id=1]
-font_data = ExtResource( 2 )
-
-[sub_resource type="Theme" id=2]
-default_font = SubResource( 1 )
[node name="Node2D" type="Node2D"]
script = ExtResource( 1 )
-
-[node name="FontSource" type="RichTextLabel" parent="."]
-grow_horizontal = 2
-grow_vertical = 2
-theme = SubResource( 2 )
-text = "AAAAAAAAAAAAAAAAAAAAAAA"
-__meta__ = {
-"_edit_use_anchors_": false
-}