small racing game im working on
add settings tab
| -rw-r--r-- | cam.gd | 1 | ||||
| -rw-r--r-- | globals.gd | 2 | ||||
| -rw-r--r-- | scenes/race_highlevel.gd | 4 | ||||
| -rw-r--r-- | start.tscn | 7 | ||||
| -rw-r--r-- | ui/countdown.tscn | 79 | ||||
| -rw-r--r-- | ui/editor/cam.gd | 3 | ||||
| -rw-r--r-- | ui/tabs/settings.gd | 62 | ||||
| -rw-r--r-- | ui/tabs/settings.tscn | 101 | ||||
| -rw-r--r-- | ui/theme.tres | 2 |
9 files changed, 196 insertions, 65 deletions
@@ -11,6 +11,7 @@ func _ready(): reset() far = 2000 near = .2 + fov = Globals.cfg.get_value(SettingsSaver.GRAPHIC, "camera_fov") func reset(): global_position = follow_this.global_position + (follow_this.global_transform.basis.z * target_distance) @@ -5,9 +5,11 @@ var playing: TrackResource var editing: TrackResource var ghost: GhostData var track_select: BuiltinTrackSelect +var cfg: ConfigFile const SAVES := "user://ghosts/%s.ghost" const TRACKS := "user://player data/tracks/%s.track" const THUMBS := "user://thumbs/%s.thumb" +const SETTINGS := "user://settings.cfg" const DEFAULT_EDITOR_LAYER := 0x80000000 const GIZMO_LAYER := 0x40000000 const GIZMO_LAYER_I := 31 diff --git a/scenes/race_highlevel.gd b/scenes/race_highlevel.gd index 2524f11..79ac020 100644 --- a/scenes/race_highlevel.gd +++ b/scenes/race_highlevel.gd @@ -14,6 +14,7 @@ var race: Race var huds: Array[HUD] func _ready() -> void: + scale = Globals.cfg.get_value(SettingsSaver.GRAPHIC, "viewport_scale") / 100 race = Race.new(Globals.playing, Globals.ghost, car_scene, ghost_scene, track_loader_scene) race.did_reset.connect(count_in) add_child(race) @@ -50,6 +51,9 @@ func add_player() -> void: ) func count_in(): + if Globals.cfg.get_value(SettingsSaver.UTIL, "countdown_step_length") == 0: + race.start() + return var countdown := countdown_scene.instantiate() huds[0].add_child(countdown) countdown.finished.connect(race.start) @@ -1,8 +1,9 @@ -[gd_scene load_steps=5 format=3 uid="uid://co11ood2nmady"] +[gd_scene load_steps=6 format=3 uid="uid://co11ood2nmady"] [ext_resource type="Theme" uid="uid://d3ywcokn5ddy8" path="res://ui/theme.tres" id="1_gm0ws"] [ext_resource type="PackedScene" uid="uid://oq2hhcxu57xx" path="res://ui/tabs/create.tscn" id="2_sm0m7"] [ext_resource type="PackedScene" uid="uid://6p50mntqmyvq" path="res://ui/tabs/play.tscn" id="3_4rfac"] +[ext_resource type="PackedScene" uid="uid://difst0fhw1538" path="res://ui/tabs/settings.tscn" id="4_r4bcq"] [ext_resource type="AudioStream" uid="uid://bwiyphl31lwu6" path="res://assets/sounds/music.ogg" id="9_ma7kx"] [node name="start" type="Control"] @@ -37,6 +38,10 @@ layout_mode = 2 visible = false layout_mode = 2 +[node name="settings" parent="margin/tabs" instance=ExtResource("4_r4bcq")] +visible = false +layout_mode = 2 + [node name="music" type="AudioStreamPlayer" parent="."] stream = ExtResource("9_ma7kx") volume_db = -25.0 diff --git a/ui/countdown.tscn b/ui/countdown.tscn index 1ac3f00..65982eb 100644 --- a/ui/countdown.tscn +++ b/ui/countdown.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=5 format=3 uid="uid://clpo7rt0vkudy"] +[gd_scene load_steps=2 format=3 uid="uid://clpo7rt0vkudy"] [sub_resource type="GDScript" id="GDScript_4shhd"] resource_name = "countdown" @@ -6,72 +6,26 @@ script/source = "extends CanvasLayer signal finished -func finished_anim() -> void: - finished.emit() -" +@onready var counter: RichTextLabel = $Counter -[sub_resource type="Animation" id="Animation_2si4r"] -length = 0.001 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath("Counter:text") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [" -"] -} +func _ready() -> void: + var tween := get_tree().create_tween().bind_node(counter) + var duration: float = Globals.cfg.get_value(SettingsSaver.UTIL, \"countdown_step_length\") + tween.tween_property(counter, ^\"text\", \"[center][b]3[/b][/center]\", duration) + tween.tween_property(counter, ^\"text\", \"[center][b]2[/b][/center]\", duration) + tween.tween_property(counter, ^\"text\", \"[center][b]1[/b][/center]\", duration) + tween.tween_property(counter, ^\"text\", \"\", duration) -[sub_resource type="Animation" id="Animation_uaks0"] -resource_name = "count_in" -length = 3.0 -step = 0.5 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath("Counter:text") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0, 1, 2, 3), -"transitions": PackedFloat32Array(1, 1, 1, 1), -"update": 1, -"values": ["[center][b]3[/b][/center]", "[center][b]2[/b][/center] -", "[center][b]1[/b][/center] -", ""] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath("Counter:theme_override_colors/default_color") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0, 3), -"transitions": PackedFloat32Array(1, 1), -"update": 0, -"values": [Color(1, 0.360784, 0.227451, 1), Color(0.980392, 0.737255, 0, 1)] -} + var color_tween := get_tree().create_tween().bind_node(counter) + counter.add_theme_color_override(&\"default_color\", Color(\"ff5c3a\")) + color_tween.tween_property(counter, ^\"theme_override_colors/default_color\", Color(\"fabc00\"), duration*4) -[sub_resource type="AnimationLibrary" id="AnimationLibrary_hplnw"] -_data = { -"RESET": SubResource("Animation_2si4r"), -"count_in": SubResource("Animation_uaks0") -} + tween.finished.connect(emit_signal.bind(&\"finished\")) +" [node name="Countdown" type="CanvasLayer"] script = SubResource("GDScript_4shhd") -[node name="CountPlayer" type="AnimationPlayer" parent="."] -autoplay = "count_in" -libraries = { -"": SubResource("AnimationLibrary_hplnw") -} - [node name="Counter" type="RichTextLabel" parent="."] custom_minimum_size = Vector2(1400, 0) anchors_preset = 8 @@ -90,8 +44,5 @@ theme_override_colors/font_outline_color = Color(0, 0, 0, 1) theme_override_constants/outline_size = 50 theme_override_font_sizes/bold_font_size = 800 bbcode_enabled = true -text = " -" +text = "[center][b]3[/b][/center]" fit_content = true - -[connection signal="animation_finished" from="CountPlayer" to="." method="finished_anim" unbinds=1] diff --git a/ui/editor/cam.gd b/ui/editor/cam.gd index 30e5ba7..09db951 100644 --- a/ui/editor/cam.gd +++ b/ui/editor/cam.gd @@ -11,6 +11,9 @@ const CAMERA_MAX_ROTATION_ANGLE = deg_to_rad(70); var m_vel := Vector2.ZERO @onready var last_m_pos := get_viewport().get_mouse_position() +func _ready() -> void: + fov = Globals.cfg.get_value(SettingsSaver.GRAPHIC, "camera_fov") + func _process(_delta): m_vel = get_viewport().get_mouse_position() - last_m_pos last_m_pos = get_viewport().get_mouse_position() diff --git a/ui/tabs/settings.gd b/ui/tabs/settings.gd new file mode 100644 index 0000000..88b2cbd --- /dev/null +++ b/ui/tabs/settings.gd @@ -0,0 +1,62 @@ +extends Control +class_name SettingsSaver + +# utility +const UTIL = "utility" +var countdown_step_length: float = 1.0 + +# graphical +const GRAPHIC = "graphics" +var viewport_scale: float = 100.0 +var camera_fov: float = 75.0 + + +# trying the [ConfigFile] class out instead of the usual var2str/str2var with dict +var cfg := ConfigFile.new() + +@onready var nodes := { + "countdown_step_length" = %countdown_step, + "camera_fov" = %camera_fov, + "viewport_scale" = %viewport_scale +} + +func _load(): + var err := cfg.load(Globals.SETTINGS) + if err != OK: # no file + _save() # make it + return + getv(UTIL, "countdown_step_length", 0.05, 30) + getv(GRAPHIC, "camera_fov", 1, 179) + getv(GRAPHIC, "viewport_scale", 1, 100) + +func getv(section: String, variable: String, p_min: float, p_max: float): + if cfg.has_section_key(section, variable): + # i can use self[variable] but i think set() and get() is more readable + var value := clampf(cfg.get_value(section, variable, get(variable)), p_min, p_max) + set(variable, value) + if nodes[variable] is SpinBox: + nodes[variable].value = value + else: + cfg.set_value(section, variable, get(variable)) + +func setv(section: String, variable: String): + cfg.set_value(section, variable, get(variable)) + +func _save(): + setv(UTIL, "countdown_step_length") + setv(GRAPHIC, "camera_fov") + setv(GRAPHIC, "viewport_scale") + cfg.save(Globals.SETTINGS) + +func _connect(): + for variable in nodes: + (nodes[variable] as SpinBox).value_changed.connect(_spinner_change.bind(variable)) + +func _ready() -> void: + _load() + _connect() + Globals.cfg = cfg + +func _spinner_change(value: float, variable: String) -> void: + set(variable, value) + _save() diff --git a/ui/tabs/settings.tscn b/ui/tabs/settings.tscn new file mode 100644 index 0000000..1c99dad --- /dev/null +++ b/ui/tabs/settings.tscn @@ -0,0 +1,101 @@ +[gd_scene load_steps=3 format=3 uid="uid://difst0fhw1538"] + +[ext_resource type="Script" path="res://ui/tabs/settings.gd" id="1_8637a"] +[ext_resource type="Theme" uid="uid://d3ywcokn5ddy8" path="res://ui/theme.tres" id="2_vwoli"] + +[node name="settings" type="ScrollContainer"] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme = ExtResource("2_vwoli") +horizontal_scroll_mode = 0 +script = ExtResource("1_8637a") + +[node name="vbox" type="VBoxContainer" parent="."] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="label" type="Label" parent="vbox"] +layout_mode = 2 +text = "utility" + +[node name="utility" type="HFlowContainer" parent="vbox"] +layout_mode = 2 +theme_override_constants/h_separation = 15 + +[node name="panel" type="PanelContainer" parent="vbox/utility"] +layout_mode = 2 +size_flags_vertical = 0 +tooltip_text = "The countdown length (set to 0 to disable countdown)." +theme_type_variation = &"ui_light_panel" + +[node name="countdown_step" type="HBoxContainer" parent="vbox/utility/panel"] +layout_mode = 2 +tooltip_text = "The countdown length (set to 0 to disable countdown)." + +[node name="label" type="Label" parent="vbox/utility/panel/countdown_step"] +layout_mode = 2 +text = "countdown step length:" + +[node name="countdown_step" type="SpinBox" parent="vbox/utility/panel/countdown_step"] +unique_name_in_owner = true +layout_mode = 2 +tooltip_text = "The countdown length (set to 0 to disable countdown)." +max_value = 30.0 +step = 0.1 +suffix = "s" +custom_arrow_step = 0.5 + +[node name="label2" type="Label" parent="vbox"] +layout_mode = 2 +text = "graphical" + +[node name="graphical" type="HFlowContainer" parent="vbox"] +layout_mode = 2 + +[node name="panel" type="PanelContainer" parent="vbox/graphical"] +layout_mode = 2 +tooltip_text = "Viewport scale" +theme_type_variation = &"ui_light_panel" + +[node name="viewport_scale" type="HBoxContainer" parent="vbox/graphical/panel"] +layout_mode = 2 +tooltip_text = "Viewport scale" + +[node name="label" type="Label" parent="vbox/graphical/panel/viewport_scale"] +layout_mode = 2 +text = "viewport scale:" + +[node name="viewport_scale" type="SpinBox" parent="vbox/graphical/panel/viewport_scale"] +unique_name_in_owner = true +custom_minimum_size = Vector2(100, 0) +layout_mode = 2 +tooltip_text = "Viewport scale" +value = 100.0 +suffix = "%" + +[node name="panel2" type="PanelContainer" parent="vbox/graphical"] +layout_mode = 2 +tooltip_text = "Camera FOV." +theme_type_variation = &"ui_light_panel" + +[node name="camera_fov" type="HBoxContainer" parent="vbox/graphical/panel2"] +layout_mode = 2 +tooltip_text = "Camera FOV." + +[node name="label" type="Label" parent="vbox/graphical/panel2/camera_fov"] +layout_mode = 2 +text = "camera field of view:" + +[node name="camera_fov" type="SpinBox" parent="vbox/graphical/panel2/camera_fov"] +unique_name_in_owner = true +custom_minimum_size = Vector2(120, 0) +layout_mode = 2 +tooltip_text = "Camera FOV." +min_value = 1.0 +max_value = 179.0 +value = 75.0 +suffix = "deg" diff --git a/ui/theme.tres b/ui/theme.tres index a545b32..6742c0e 100644 --- a/ui/theme.tres +++ b/ui/theme.tres @@ -185,5 +185,7 @@ Tree/icons/arrow_collapsed = ExtResource("7_raqbt") Tree/styles/panel = ExtResource("2_0o40a") VSeparator/constants/separation = 0 VSeparator/styles/separator = SubResource("StyleBoxLine_vr8fs") +ui_light_panel/base_type = &"PanelContainer" +ui_light_panel/styles/panel = ExtResource("2_0o40a") ui_panel/base_type = &"PanelContainer" ui_panel/styles/panel = ExtResource("4_mx083") |