From 54c3143fcf75c9fd9d778c24802022d7b3ba5696 Mon Sep 17 00:00:00 2001 From: KartikWatts Date: Wed, 17 Jan 2024 18:39:14 +0530 Subject: [PATCH] custom theme and font with damage text creating custom theme resource and project wide theme usage using tween effects for floating damage text scene effect on hurtbox component with dynamic text based on hitbox damage dealt on enemy --- 2d-survivors-course/project.godot | 4 ++ .../resources/theme/Rockboxcond12.ttf | Bin 0 -> 11212 bytes .../resources/theme/Rockboxcond12.ttf.import | 38 ++++++++++++++++++ .../resources/theme/theme.tres | 7 ++++ .../scenes/components/hurt_box_component.gd | 7 ++++ .../scenes/ui/arena_time_ui.tscn | 5 +++ .../scenes/ui/floating_text.gd | 27 +++++++++++++ .../scenes/ui/floating_text.tscn | 21 ++++++++++ 8 files changed, 109 insertions(+) create mode 100644 2d-survivors-course/resources/theme/Rockboxcond12.ttf create mode 100644 2d-survivors-course/resources/theme/Rockboxcond12.ttf.import create mode 100644 2d-survivors-course/resources/theme/theme.tres create mode 100644 2d-survivors-course/scenes/ui/floating_text.gd create mode 100644 2d-survivors-course/scenes/ui/floating_text.tscn diff --git a/2d-survivors-course/project.godot b/2d-survivors-course/project.godot index 4153b021..cbc24668 100644 --- a/2d-survivors-course/project.godot +++ b/2d-survivors-course/project.godot @@ -27,6 +27,10 @@ window/size/window_width_override=1920 window/size/window_height_override=1080 window/stretch/mode="viewport" +[gui] + +theme/custom="res://resources/theme/theme.tres" + [input] move_left={ diff --git a/2d-survivors-course/resources/theme/Rockboxcond12.ttf b/2d-survivors-course/resources/theme/Rockboxcond12.ttf new file mode 100644 index 0000000000000000000000000000000000000000..ac8aaa54696985b6e2cf507c2b5ea5e28f7d1a2e GIT binary patch literal 11212 zcmbtaU2GiH6+UxkcGv6mZ_FkTvWcCIaj;3^cyR);7bXxw2mwM841_>1c0vq^ojM6} z^MFQeQ$=b;d1}=PRTbr>6j2hj5|!F&gsPT@v_&ZWQ9*!OgeppSYI&%D?RU<-cX#&B z-Z*3L+&lN@{GW5ry))zxQ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zxiLFKzP@irE%-`i6sOv^V29!3dzsr1LAKEyw4Lsx9dsA%q`PSs^mH%X zN4x2MaJ-lH(E~I_57I;QFzu&DV4087V|0)nr*TKokLeq9hJH=orGL>k={fqA<2qjA z)b!Ng;MPI!j#INU{E&kHSqKik@WWAxkw=@@Dn|lD5NWkNQvUwS*WTxmZ_W*D<&wW) F{Xb^vdtd+n literal 0 HcmV?d00001 diff --git a/2d-survivors-course/resources/theme/Rockboxcond12.ttf.import b/2d-survivors-course/resources/theme/Rockboxcond12.ttf.import new file mode 100644 index 00000000..8934a62b --- /dev/null +++ b/2d-survivors-course/resources/theme/Rockboxcond12.ttf.import @@ -0,0 +1,38 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://b7708ebmlmygw" +path="res://.godot/imported/Rockboxcond12.ttf-6ec46e755c0cb4bc7bf74c19c1d5cac8.fontdata" + +[deps] + +source_file="res://resources/theme/Rockboxcond12.ttf" +dest_files=["res://.godot/imported/Rockboxcond12.ttf-6ec46e755c0cb4bc7bf74c19c1d5cac8.fontdata"] + +[params] + +Rendering=null +antialiasing=0 +generate_mipmaps=false +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +hinting=0 +subpixel_positioning=0 +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[{ +"chars": [], +"glyphs": [], +"name": "New Configuration", +"size": Vector2i(16, 0) +}] +language_support={} +script_support={} +opentype_features={} diff --git a/2d-survivors-course/resources/theme/theme.tres b/2d-survivors-course/resources/theme/theme.tres new file mode 100644 index 00000000..885ab466 --- /dev/null +++ b/2d-survivors-course/resources/theme/theme.tres @@ -0,0 +1,7 @@ +[gd_resource type="Theme" load_steps=2 format=3 uid="uid://dppehnirbmmb0"] + +[ext_resource type="FontFile" uid="uid://b7708ebmlmygw" path="res://resources/theme/Rockboxcond12.ttf" id="1_8cegc"] + +[resource] +default_font = ExtResource("1_8cegc") +default_font_size = 16 diff --git a/2d-survivors-course/scenes/components/hurt_box_component.gd b/2d-survivors-course/scenes/components/hurt_box_component.gd index f14eefdc..9241cda3 100644 --- a/2d-survivors-course/scenes/components/hurt_box_component.gd +++ b/2d-survivors-course/scenes/components/hurt_box_component.gd @@ -3,6 +3,7 @@ class_name HurtBoxComponent @export var health_component: HealthComponent +var floating_text_scence = preload("res://scenes/ui/floating_text.tscn") func _ready(): area_entered.connect(on_area_entered) @@ -17,3 +18,9 @@ func on_area_entered(other_area: Area2D): var hitbox_component = other_area as HitBoxComponent health_component.damage(hitbox_component.damage) + + var floating_text = floating_text_scence.instantiate() as FloatingText + get_tree().get_first_node_in_group("foreground_layer").add_child(floating_text) + + floating_text.global_position = global_position + (Vector2.UP * 16) + floating_text.start(str(hitbox_component.damage)) diff --git a/2d-survivors-course/scenes/ui/arena_time_ui.tscn b/2d-survivors-course/scenes/ui/arena_time_ui.tscn index 0a1ed102..6b407b10 100644 --- a/2d-survivors-course/scenes/ui/arena_time_ui.tscn +++ b/2d-survivors-course/scenes/ui/arena_time_ui.tscn @@ -19,4 +19,9 @@ unique_name_in_owner = true layout_mode = 2 size_flags_horizontal = 4 size_flags_vertical = 0 +theme_override_colors/font_shadow_color = Color(0.247059, 0.14902, 0.192157, 1) +theme_override_colors/font_outline_color = Color(0.247059, 0.14902, 0.192157, 1) +theme_override_constants/shadow_offset_x = 0 +theme_override_constants/shadow_offset_y = 0 +theme_override_constants/outline_size = 6 text = "test" diff --git a/2d-survivors-course/scenes/ui/floating_text.gd b/2d-survivors-course/scenes/ui/floating_text.gd new file mode 100644 index 00000000..bb4e2974 --- /dev/null +++ b/2d-survivors-course/scenes/ui/floating_text.gd @@ -0,0 +1,27 @@ +extends Node2D +class_name FloatingText + +func _ready(): + pass + + +func start(text: String): + $Label.text = text + + var tween = create_tween() + tween.set_parallel() + + tween.tween_property(self, "global_position", global_position + (Vector2.UP * 16), .3)\ + .set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_CUBIC) + tween.chain() + + tween.tween_property(self, "global_position", global_position + (Vector2.UP * 16), .5)\ + .set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_CUBIC) + tween.tween_property(self, "scale", Vector2.ONE, .5).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_CUBIC) + tween.chain() + + tween.tween_callback(queue_free) + + var scale_tween = create_tween() + scale_tween.tween_property(self, "scale", Vector2.ONE * 1.5, .15).set_ease(Tween.EASE_OUT).set_trans(Tween.TRANS_CUBIC) + scale_tween.tween_property(self, "scale", Vector2.ONE, .15).set_ease(Tween.EASE_IN).set_trans(Tween.TRANS_CUBIC) diff --git a/2d-survivors-course/scenes/ui/floating_text.tscn b/2d-survivors-course/scenes/ui/floating_text.tscn new file mode 100644 index 00000000..192db87a --- /dev/null +++ b/2d-survivors-course/scenes/ui/floating_text.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=2 format=3 uid="uid://l5bn3rnkbcgi"] + +[ext_resource type="Script" path="res://scenes/ui/floating_text.gd" id="1_ets41"] + +[node name="FloatingText" type="Node2D"] +script = ExtResource("1_ets41") + +[node name="Label" type="Label" parent="."] +custom_minimum_size = Vector2(100, 32) +offset_left = -50.0 +offset_top = -14.0 +offset_right = 50.0 +offset_bottom = 18.0 +theme_override_colors/font_shadow_color = Color(0.247059, 0.14902, 0.192157, 1) +theme_override_colors/font_outline_color = Color(0.247059, 0.14902, 0.192157, 1) +theme_override_constants/shadow_offset_x = 0 +theme_override_constants/shadow_offset_y = 0 +theme_override_constants/outline_size = 6 +text = "108" +horizontal_alignment = 1 +vertical_alignment = 1