From 4cc6e938fc6f53bb7891dd573bda59c2a8a67a34 Mon Sep 17 00:00:00 2001 From: JHDev2006 Date: Sat, 20 Sep 2025 19:09:34 +0100 Subject: [PATCH] made sub level transitions a bit smoother --- Assets/Sprites/UI/LSSRatingStars.png | Bin 0 -> 179 bytes Assets/Sprites/UI/LSSRatingStars.png.import | 40 + Scenes/Levels/SMB1/World1/1-2.tscn | 5394 +++++++++---------- Scenes/Prefabs/UI/CustomLevelContainer.tscn | 9 + Scenes/Prefabs/UI/OnlineLevelContainer.tscn | 53 +- Scripts/Classes/Editor/LevelEditor.gd | 1 + Scripts/Classes/Singletons/Global.gd | 6 +- Scripts/UI/CustomLevelContainer.gd | 10 +- Scripts/UI/CustomLevelList.gd | 9 +- Scripts/UI/LssBrowser.gd | 1 + Scripts/UI/OnlineLevelContainer.gd | 24 +- 11 files changed, 2839 insertions(+), 2708 deletions(-) create mode 100644 Assets/Sprites/UI/LSSRatingStars.png create mode 100644 Assets/Sprites/UI/LSSRatingStars.png.import diff --git a/Assets/Sprites/UI/LSSRatingStars.png b/Assets/Sprites/UI/LSSRatingStars.png new file mode 100644 index 0000000000000000000000000000000000000000..010bffecfe0f138f3a1093749a3a6e0aaf419b9a GIT binary patch literal 179 zcmeAS@N?(olHy`uVBq!ia0vp^5A|QV^pr%HRZOMsd$rd@C7oT1nWO{s<=NN}s4BMkek2f)h b&tJyCpseG~rS$tf$axH&u6{1-oD!M void: LevelPersistance.reset_states() sub_level_id = sub_lvl_idx $LevelLoader.load_level(sub_lvl_idx) + Global.do_fake_transition(0.1) await get_tree().physics_frame if (play_pipe_transition or play_door_transition) and play_transition: parse_tiles() diff --git a/Scripts/Classes/Singletons/Global.gd b/Scripts/Classes/Singletons/Global.gd index 9884bd9..7a19109 100644 --- a/Scripts/Classes/Singletons/Global.gd +++ b/Scripts/Classes/Singletons/Global.gd @@ -304,16 +304,16 @@ func transition_to_scene(scene_path := "") -> void: -func do_fake_transition() -> void: +func do_fake_transition(duration := 0.2) -> void: if fade_transition: $Transition/AnimationPlayer.play("FadeIn") await $Transition/AnimationPlayer.animation_finished - await get_tree().create_timer(0.2, false).timeout + await get_tree().create_timer(duration, false).timeout $Transition/AnimationPlayer.play_backwards("FadeIn") else: %TransitionBlock.modulate.a = 1 $Transition.show() - await get_tree().create_timer(0.25, false).timeout + await get_tree().create_timer(duration + 0.05, false).timeout $Transition.hide() func freeze_screen() -> void: diff --git a/Scripts/UI/CustomLevelContainer.gd b/Scripts/UI/CustomLevelContainer.gd index 9b62e1e..29eee26 100644 --- a/Scripts/UI/CustomLevelContainer.gd +++ b/Scripts/UI/CustomLevelContainer.gd @@ -12,6 +12,7 @@ var game_style := "SMBLL" var difficulty := 0 var file_path := "" var is_downloaded := false +var thumbnail: Texture = null var level_id := "" var idx := 0 @@ -55,9 +56,14 @@ func _ready() -> void: update_visuals() func update_visuals() -> void: - if is_downloaded: - %LevelIcon.texture = ImageTexture.create_from_image(Image.load_from_file("user://custom_levels/downloaded/thumbnails/" + level_id + ".png")) + if is_downloaded and FileAccess.file_exists("user://custom_levels/downloaded/thumbnails/" + level_id + ".png"): + thumbnail = ImageTexture.create_from_image(Image.load_from_file("user://custom_levels/downloaded/thumbnails/" + level_id + ".png")) + %Thumbnail.texture = thumbnail + %LevelIcon.hide() + %Thumbnail.show() else: + %Thumbnail.hide() + %LevelIcon.show() %LevelIcon.texture = ResourceSetter.get_resource(ICON_TEXTURES[level_time]) %LevelIcon.region_rect = THEME_RECTS[level_theme] diff --git a/Scripts/UI/CustomLevelList.gd b/Scripts/UI/CustomLevelList.gd index eceed53..77ba07d 100644 --- a/Scripts/UI/CustomLevelList.gd +++ b/Scripts/UI/CustomLevelList.gd @@ -52,19 +52,20 @@ func get_levels(path := "user://custom_levels") -> void: continue %LevelContainers.get_node("Label").hide() var container = CUSTOM_LEVEL_CONTAINER.instantiate() - var file = FileAccess.open(path + "/" + i, FileAccess.READ) + var file_path = path + "/" + i + var file = FileAccess.open(file_path, FileAccess.READ) var json = JSON.parse_string(file.get_as_text()) file.close() var data = json["Levels"][0]["Data"].split("=") var info = json["Info"] - container.is_downloaded = path.contains("/downloaded/") + container.is_downloaded = path.contains("downloaded") if container.is_downloaded: - container.level_id = path.get_file().replace(".lvl", "") + container.level_id = file_path.get_file().replace(".lvl", "") container.level_name = info["Name"] container.level_author = info["Author"] container.level_desc = info["Description"] container.idx = idx - container.file_path = path + "/" + i + container.file_path = file_path container.level_theme = Level.THEME_IDXS[base64_charset.find(data[0])] container.level_time = base64_charset.find(data[1]) container.game_style = Global.CAMPAIGNS[base64_charset.find(data[3])] diff --git a/Scripts/UI/LssBrowser.gd b/Scripts/UI/LssBrowser.gd index 23e66da..c2f4b5c 100644 --- a/Scripts/UI/LssBrowser.gd +++ b/Scripts/UI/LssBrowser.gd @@ -79,6 +79,7 @@ func spawn_containers() -> void: container.level_author = i.author.username container.difficulty = i.difficulty container.level_id = i._id + container.ratings = i.rates container.level_selected.connect(show_info) if i.has("thumbnail"): if i.thumbnail != null: diff --git a/Scripts/UI/OnlineLevelContainer.gd b/Scripts/UI/OnlineLevelContainer.gd index 25e9733..ecb882b 100644 --- a/Scripts/UI/OnlineLevelContainer.gd +++ b/Scripts/UI/OnlineLevelContainer.gd @@ -7,6 +7,8 @@ var level_thumbnail = null var level_id := "" var thumbnail_url := "" +var ratings := [] + var difficulty := "Easy" var featured = false @@ -38,10 +40,19 @@ func setup_visuals() -> void: print(difficulty) var difficulty_int = DIFFICULTY_TO_STAR_TRANSLATION[difficulty] for i in %DifficultyStars.get_children(): - i.region_rect.position.x = 24 if idx > difficulty_int else [0, 0, 8, 8, 16][difficulty_int] + i.region_rect.position.x = 32 if idx > difficulty_int else [0, 8, 8, 16, 24][difficulty_int] idx += 1 + setup_rating_stars() get_thumbnail() +func setup_rating_stars() -> void: + var rating = calculate_rating() + + var idx := 0 + for i in %RatingStars.get_children(): + i.region_rect.position.x = 16 if idx > rating else (0 if abs(idx - rating) >= 0.5 else 8) + idx += 1 + func get_thumbnail() -> void: if cached_thumbnails.has(level_id): %LevelIcon.texture = cached_thumbnails[level_id] @@ -53,6 +64,17 @@ func get_thumbnail() -> void: return $ThumbnailDownloader.request(thumbnail_url, [], HTTPClient.METHOD_GET) +func calculate_rating() -> int: + var rating := -1.0 + var total := 0 + if ratings.is_empty(): + return 0 + for i in ratings: + total += i + rating = total / float(ratings.size()) + print(rating) + return rating + func on_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray) -> void: var image = Image.new() if thumbnail_url.contains(".webp"):