From 1045bf2f9e903c9abbd5d6da4828c3b445aa7f2b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 2 Sep 2023 14:05:41 +0200 Subject: [PATCH] Fixed auto scrolling to inspiration. Fixed show answer changes song list. Started working on some colors --- InsperationScrollContainer.gd | 36 ++++++++++++++ LightGrayTheme.tres | 7 +++ MainWindow.gd | 30 +++++++----- MainWindow.tscn | 48 +++++++++++++------ ...ontainer.gd => MusicListScrollContainer.gd | 2 - neutral_gray.tres | 4 ++ 6 files changed, 99 insertions(+), 28 deletions(-) create mode 100644 InsperationScrollContainer.gd create mode 100644 LightGrayTheme.tres rename ScrollContainer.gd => MusicListScrollContainer.gd (97%) create mode 100644 neutral_gray.tres diff --git a/InsperationScrollContainer.gd b/InsperationScrollContainer.gd new file mode 100644 index 0000000..3e4368a --- /dev/null +++ b/InsperationScrollContainer.gd @@ -0,0 +1,36 @@ +extends ScrollContainer + +var SCROLL = 0 +var delay = 0.02 #seconds +var wait = 0 + +var SPEED: int = 1 + +# Called when the node enters the scene tree for the first time. +func _ready(): + wait = delay + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + wait -= delta + if wait < 0: + wait = delay + #SCROLL DOWN + if SCROLL == 1: + if (scroll_vertical + get_v_scroll_bar().page) < get_v_scroll_bar().max_value: + scroll_vertical += SPEED + else: + scroll_back_up() + #SCROLL UP + elif SCROLL == -1: + if scroll_vertical != 0: + scroll_vertical -= SPEED + else: + scroll_to_bottom() + +func scroll_back_up(): + SCROLL = -1 + +func scroll_to_bottom(): + scroll_vertical = 0 #Reset to top first. + SCROLL = 1 diff --git a/LightGrayTheme.tres b/LightGrayTheme.tres new file mode 100644 index 0000000..c48b64e --- /dev/null +++ b/LightGrayTheme.tres @@ -0,0 +1,7 @@ +[gd_resource type="Theme" load_steps=2 format=3 uid="uid://rxexo3ur85as"] + +[ext_resource type="StyleBox" uid="uid://blf3g88mugovr" path="res://neutral_gray.tres" id="1_alhp2"] + +[resource] +Label/styles/normal = ExtResource("1_alhp2") +PanelContainer/styles/panel = ExtResource("1_alhp2") diff --git a/MainWindow.gd b/MainWindow.gd index 58be910..65479de 100644 --- a/MainWindow.gd +++ b/MainWindow.gd @@ -7,7 +7,10 @@ var open_button := $Open var fileDialog := $FileDialog @onready -var list := $ScrollContainer/VBoxContainer +var insperation_scroll := $ScrollContainer + +@onready +var insperation_list := $ScrollContainer/VBoxContainer @onready var game_label := $VBoxContainer/GameLabel @@ -111,6 +114,7 @@ func fetched(): push_error("An error occurred in the HTTP request.") +var next_label: Label func show_fetched(result, response_code, headers, body) -> void: var json = JSON.new() var error = json.parse(body.get_string_from_utf8()) @@ -120,6 +124,9 @@ func show_fetched(result, response_code, headers, body) -> void: print("data_received: ", data_received) game_label.text = data_received.Game song_label.text = data_received.Song + var format_string = "%d. %s - %s" + var actual_string = format_string % [(data_received.SongNo+1), data_received.Game, data_received.Song] + next_label.text = actual_string var song_list = [] func show_fetched_list(result, response_code, headers, body) -> void: @@ -142,17 +149,17 @@ func show_fetched_list(result, response_code, headers, body) -> void: label.gui_input.connect(song_clicked.bind(song.SongNo)) music_list.add_child(label) - var label := Label.new() - label.text = "??? - ???" - label.mouse_filter = Control.MOUSE_FILTER_PASS - label.gui_input.connect(show_fetched) - music_list.add_child(label) + next_label = Label.new() + next_label.text = "??? - ???" + next_label.mouse_filter = Control.MOUSE_FILTER_PASS + next_label.gui_input.connect(show_fetched) + music_list.add_child(next_label) else: print("Unexpected data") func song_clicked(event, song_no): - if (event is InputEventMouseButton && event.pressed && event.button_index == 1): + if (event is InputEventMouseButton && event.pressed && event.button_index == MOUSE_BUTTON_LEFT): print("Clicked: " + str(song_no)) # Called when the HTTP request is completed. @@ -167,8 +174,9 @@ func _http_request_completed(result, response_code, headers, body): for game in games: var label := Label.new() label.text = game - list.add_child(label) - #print(data_received) # Prints array + label.autowrap_mode = TextServer.AUTOWRAP_WORD + insperation_list.add_child(label) + insperation_scroll.scroll_to_bottom() else: print("Unexpected data") @@ -185,7 +193,7 @@ func open(): func _process(delta): if audio.has_stream_playback() && !is_changing && !audio.stream_paused: progress.value = audio.get_playback_position() - label.text = format_text(progress.value, stream.get_length()) + label.text = format_text(progress.value, stream.get_length()) func _on_file_dialog_dir_selected(path): print(path) @@ -217,7 +225,7 @@ func dir_contents(path: String) -> void: for game in games: var label := Label.new() label.text = game - list.add_child(label) + insperation_list.add_child(label) diff --git a/MainWindow.tscn b/MainWindow.tscn index 11a9521..fd22513 100644 --- a/MainWindow.tscn +++ b/MainWindow.tscn @@ -1,23 +1,38 @@ -[gd_scene load_steps=9 format=3 uid="uid://xwq863o6uvsu"] +[gd_scene load_steps=11 format=3 uid="uid://xwq863o6uvsu"] [ext_resource type="Script" path="res://MainWindow.gd" id="1_eu0t5"] [ext_resource type="PackedScene" uid="uid://b16on0oscg1bv" path="res://CharacterSelect.tscn" id="2_76kf4"] +[ext_resource type="Script" path="res://InsperationScrollContainer.gd" id="2_gxtxm"] [ext_resource type="PackedScene" uid="uid://w400rnew7453" path="res://volume_slider.tscn" id="3_rxhba"] [ext_resource type="AudioStream" uid="uid://n2g8jddr85h2" path="res://01. Opening.mp3" id="4_5kvsq"] [ext_resource type="Texture2D" uid="uid://o5go6smk7hm1" path="res://person_add_alt_1-black-36dp.svg" id="4_op458"] -[ext_resource type="Script" path="res://ScrollContainer.gd" id="6_7b4jh"] +[ext_resource type="Script" path="res://MusicListScrollContainer.gd" id="7_dj026"] +[ext_resource type="Theme" uid="uid://rxexo3ur85as" path="res://LightGrayTheme.tres" id="7_wxbv6"] [sub_resource type="LabelSettings" id="LabelSettings_qspbu"] -font_size = 70 +font_size = 50 [sub_resource type="LabelSettings" id="LabelSettings_3m52w"] -font_size = 50 +font_size = 35 [node name="Control" type="Control"] layout_mode = 3 anchors_preset = 0 script = ExtResource("1_eu0t5") +[node name="TopPanelContainer" type="PanelContainer" parent="."] +layout_mode = 0 +offset_right = 1920.0 +offset_bottom = 52.0 + +[node name="HBoxContainer" type="HBoxContainer" parent="TopPanelContainer"] +layout_mode = 2 + +[node name="Label" type="Label" parent="TopPanelContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 0 +text = "Music Player Randomizer" + [node name="Open" type="Button" parent="."] layout_mode = 2 offset_left = 65.0 @@ -38,12 +53,16 @@ show_hidden_files = true [node name="ScrollContainer" type="ScrollContainer" parent="."] layout_mode = 0 offset_left = 1204.0 -offset_top = 17.0 -offset_right = 1771.0 +offset_top = 95.0 +offset_right = 1845.0 offset_bottom = 465.0 +horizontal_scroll_mode = 0 +script = ExtResource("2_gxtxm") [node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer"] layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 [node name="Label" type="Label" parent="ScrollContainer/VBoxContainer"] layout_mode = 2 @@ -57,7 +76,7 @@ text = "Test2" [node name="VBoxContainer" type="VBoxContainer" parent="."] layout_mode = 0 offset_left = 52.0 -offset_top = 64.0 +offset_top = 81.0 offset_right = 977.0 offset_bottom = 368.0 @@ -82,7 +101,7 @@ visible = false layout_mode = 0 offset_left = 69.0 offset_top = 924.0 -offset_right = 955.0 +offset_right = 1057.0 offset_bottom = 964.0 [node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer"] @@ -111,12 +130,10 @@ scrollable = false layout_mode = 2 text = "1:00 / 3:00" -[node name="VolumeSlider" parent="." instance=ExtResource("3_rxhba")] -layout_mode = 0 -offset_left = 983.0 -offset_top = 916.0 -offset_right = 1214.0 -offset_bottom = 955.0 +[node name="VolumeSlider" parent="PanelContainer/HBoxContainer" instance=ExtResource("3_rxhba")] +custom_minimum_size = Vector2(100, 0) +layout_mode = 2 +size_flags_vertical = 4 [node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] stream = ExtResource("4_5kvsq") @@ -200,11 +217,12 @@ offset_left = 136.0 offset_top = 388.0 offset_right = 1009.0 offset_bottom = 845.0 +theme = ExtResource("7_wxbv6") [node name="ScrollContainer" type="ScrollContainer" parent="MusicListPanel"] layout_mode = 2 follow_focus = true -script = ExtResource("6_7b4jh") +script = ExtResource("7_dj026") [node name="MusicList" type="VBoxContainer" parent="MusicListPanel/ScrollContainer"] layout_mode = 2 diff --git a/ScrollContainer.gd b/MusicListScrollContainer.gd similarity index 97% rename from ScrollContainer.gd rename to MusicListScrollContainer.gd index bc95426..6115b09 100644 --- a/ScrollContainer.gd +++ b/MusicListScrollContainer.gd @@ -10,8 +10,6 @@ func _draw(): if max != self.get_v_scroll_bar().max_value: max = self.get_v_scroll_bar().max_value self.scroll_vertical = max - - pass # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): diff --git a/neutral_gray.tres b/neutral_gray.tres new file mode 100644 index 0000000..ae64844 --- /dev/null +++ b/neutral_gray.tres @@ -0,0 +1,4 @@ +[gd_resource type="StyleBoxFlat" format=3 uid="uid://blf3g88mugovr"] + +[resource] +bg_color = Color(0.257813, 0.257813, 0.257813, 1)