Skip to content

Commit

Permalink
Failed attempt to fix text alpha
Browse files Browse the repository at this point in the history
I tried to create an OutlineLabelConvert that automatically changes a
label to a CanvasGroup and sets the correct stuff.
There are several shortcomings:
1.This fucks up the node paths and creates crashes
2.CanvasGroup doesn't work well when parents have modulate, so to fix
  that I had to use top_level and recalculate self_modulate everytime on
  process, which is a bad solution. (possibly very inefficient)
3.Even with the (2) hacked around, if you manually change the CanvasGroup
  you have to be careful to change the self_modulate and not modulate,
  creating many other changes necessary in the code.

Using a OutlineLabelConvert is clearly a bad idea. Just changing the
labels to a instance of OutlineLabel is better, but (3) would still be a
problem and we would need to change everything that changes modulate.
  • Loading branch information
yancouto committed Jan 19, 2024
1 parent e071eb9 commit 64c4efc
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
9 changes: 7 additions & 2 deletions project/game/level/Level.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=31 format=3 uid="uid://dlcfb4y7xjjl3"]
[gd_scene load_steps=32 format=3 uid="uid://dlcfb4y7xjjl3"]

[ext_resource type="Script" path="res://game/level/Level.gd" id="2_wvis2"]
[ext_resource type="PackedScene" uid="uid://qm8ijblbhiyt" path="res://game/level/GridView.tscn" id="2_yywdk"]
Expand All @@ -20,6 +20,7 @@
[ext_resource type="PackedScene" uid="uid://8wk0fsy5tc5" path="res://database/tutorials/TogetherSeparate.tscn" id="13_kx7dw"]
[ext_resource type="PackedScene" uid="uid://cqxcsefprpluj" path="res://game/level/TutorialDisplay.tscn" id="15_nwo8g"]
[ext_resource type="PackedScene" uid="uid://cvc05fffw42ma" path="res://game/steam/SteamPlaytimeTracker.tscn" id="16_78sh5"]
[ext_resource type="Script" path="res://game/ui/OutlineLabelConvert.gd" id="17_oqjtt"]

[sub_resource type="FontVariation" id="FontVariation_hmnss"]
base_font = ExtResource("5_2usht")
Expand Down Expand Up @@ -273,7 +274,7 @@ tracks/3/keys = {
"times": PackedFloat32Array(0, 1, 1.3, 3.2, 3.5),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
"update": 0,
"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 1), Color(1, 1, 1, 0)]
"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 0), Color(1, 1, 1, 0.670588), Color(1, 1, 1, 1), Color(1, 1, 1, 0)]
}
tracks/4/type = "value"
tracks/4/imported = false
Expand Down Expand Up @@ -338,6 +339,7 @@ theme_override_colors/font_outline_color = Color(0, 0.0352941, 0.141176, 1)
theme_override_constants/outline_size = 36
theme_override_font_sizes/font_size = 70
text = "0 - 0"
script = ExtResource("17_oqjtt")

[node name="LevelLabel" type="Label" parent="TopInfo/LevelNameContainer"]
unique_name_in_owner = true
Expand All @@ -348,6 +350,7 @@ theme_override_constants/outline_size = 54
theme_override_font_sizes/font_size = 90
text = "LEVELNAM"
autowrap_mode = 3
script = ExtResource("17_oqjtt")

[node name="VBoxContainer" type="VBoxContainer" parent="TopInfo"]
layout_mode = 0
Expand Down Expand Up @@ -724,6 +727,7 @@ theme_override_font_sizes/font_size = 120
text = "Level title"
horizontal_alignment = 1
text_overrun_behavior = 3
script = ExtResource("17_oqjtt")

[node name="Edit" type="LineEdit" parent="Title"]
visible = false
Expand Down Expand Up @@ -807,6 +811,7 @@ layer = 3
libraries = {
"": SubResource("AnimationLibrary_b8al2")
}
speed_scale = 0.3

[node name="Autosaver" type="Timer" parent="."]
wait_time = 30.0
Expand Down
7 changes: 6 additions & 1 deletion project/game/levelhub/LevelSection.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=20 format=3 uid="uid://dns62u0n4j1k3"]
[gd_scene load_steps=21 format=3 uid="uid://dns62u0n4j1k3"]

[ext_resource type="Theme" uid="uid://c6108lc3jg2cv" path="res://assets/ui/GeneralTheme.tres" id="1_8nqmb"]
[ext_resource type="Script" path="res://game/levelhub/LevelSection.gd" id="2_5vo2a"]
Expand All @@ -8,6 +8,7 @@
[ext_resource type="StyleBox" uid="uid://dw5db25mri8oa" path="res://assets/ui/SectionButton/CompletedHoverStyle.tres" id="4_ej3iu"]
[ext_resource type="PackedScene" uid="uid://d3tmba0xubh11" path="res://game/levelhub/OngoingSolution.tscn" id="4_wvh0b"]
[ext_resource type="StyleBox" uid="uid://cskgyvxp485ui" path="res://assets/ui/SectionButton/DisabledStyle.tres" id="6_lf75c"]
[ext_resource type="Script" path="res://game/ui/OutlineLabelConvert.gd" id="8_lakdo"]
[ext_resource type="Texture2D" uid="uid://dd04btxtr18wg" path="res://assets/images/ui/bg/bubble.png" id="8_xte08"]
[ext_resource type="Theme" uid="uid://cjvm0hkahhs31" path="res://assets/ui/MobileTheme.tres" id="10_lt5bs"]

Expand Down Expand Up @@ -351,6 +352,7 @@ text = "Level Name That is Very Big"
horizontal_alignment = 1
vertical_alignment = 1
autowrap_mode = 3
script = ExtResource("8_lakdo")

[node name="Completed" type="Label" parent="Button/LevelInfoContainer/VBoxContainer"]
unique_name_in_owner = true
Expand All @@ -361,6 +363,7 @@ theme_override_constants/outline_size = 30
theme_override_font_sizes/font_size = 30
text = "COMPLETED_LEVEL"
horizontal_alignment = 1
script = ExtResource("8_lakdo")

[node name="Spacer" type="Control" parent="Button/LevelInfoContainer/VBoxContainer"]
custom_minimum_size = Vector2(0, 10)
Expand All @@ -376,6 +379,7 @@ theme_override_constants/outline_size = 20
theme_override_font_sizes/font_size = 20
text = "BEST_TIME"
horizontal_alignment = 1
script = ExtResource("8_lakdo")

[node name="BestMistakes" type="Label" parent="Button/LevelInfoContainer/VBoxContainer"]
unique_name_in_owner = true
Expand All @@ -386,6 +390,7 @@ theme_override_constants/outline_size = 20
theme_override_font_sizes/font_size = 20
text = "BEST_MISTAKES"
horizontal_alignment = 1
script = ExtResource("8_lakdo")

[node name="UnlockParticles" type="GPUParticles2D" parent="Button"]
position = Vector2(91, 130)
Expand Down
19 changes: 19 additions & 0 deletions project/game/ui/OutlineLabel.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
extends CanvasGroup

var text: String :
get:
return $Label.text
set(x):
$Label.text = x


func _process(dt):
var a := 1.0
var n := get_parent()
while n != null:
if n.get("modulate") != null:
a *= n.modulate.a
else:
break
n = n.get_parent()
self_modulate.a = a
6 changes: 6 additions & 0 deletions project/game/ui/OutlineLabel.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://dexpbx7tera5u"]

[ext_resource type="Script" path="res://game/ui/OutlineLabel.gd" id="1_i8vuh"]

[node name="OutlineLabel" type="CanvasGroup"]
script = ExtResource("1_i8vuh")
13 changes: 13 additions & 0 deletions project/game/ui/OutlineLabelConvert.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class_name OutlineLabelConvert
extends Label

func _ready() -> void:
call_deferred("put_inside_group")

func put_inside_group() -> void:
var had_uniq := unique_name_in_owner
var group := preload("res://game/ui/OutlineLabel.tscn").instantiate()
add_sibling(group)
reparent(group)
if had_uniq:
unique_name_in_owner = true

0 comments on commit 64c4efc

Please sign in to comment.