From: Eduardo Fernandez Date: Sat, 22 Jun 2024 00:35:09 +0000 (+0200) Subject: starting work to populate miniatures X-Git-Url: http://git.edufdez.es/?a=commitdiff_plain;h=5feaf328c5e312413658a3857853ed987547c90d;p=local-picrew.git starting work to populate miniatures --- diff --git a/scenes/interface.gd b/scenes/interface.gd index 1d493e2..50e1ae8 100644 --- a/scenes/interface.gd +++ b/scenes/interface.gd @@ -40,6 +40,7 @@ func _init(): func _ready(): _on_section_list(Globals.sections) + _on_section_content(Globals.sections) #endregion @@ -210,6 +211,11 @@ func add_timer_with_timeout(function: Callable, seconds: float = 2): #region signal callbacks +#endregion + +#region initial content drawing + + func _on_section_list(sections: Array[Globals.Section]): # TODO: remove: debug only for child in sections_tabs.get_children(): @@ -223,4 +229,25 @@ func _on_section_list(sections: Array[Globals.Section]): sections_tabs.add_child(container) +func _on_section_content(sections: Array[Globals.Section]): + for section in sections: + for file_path in section.image_paths: + var file_name := file_path.split("/")[-1] + var miniature_file_path := file_path.trim_suffix(file_name) + ".thumb/" + file_name + + var texture_button := TextureButton.new() + texture_button.set_meta("file_path", file_path) + texture_button.stretch_mode = TextureButton.StretchMode.STRETCH_KEEP_ASPECT + texture_button.ignore_texture_size = true + texture_button.custom_minimum_size = Vector2(100, 100) + + var image = Image.load_from_file(miniature_file_path) + var texture = ImageTexture.create_from_image(image) + texture_button.texture_normal = texture + + for child in sections_tabs.get_children(): + if child.name == section.name: + child.add_child(texture_button) + + #endregion diff --git a/scripts/globals.gd b/scripts/globals.gd index 071758d..e18f1c1 100644 --- a/scripts/globals.gd +++ b/scripts/globals.gd @@ -3,6 +3,7 @@ extends Node class Section: var name: String + var color_placeholder: Color var colors: Array[Color] var image_paths: Array[String] @@ -75,10 +76,11 @@ func _load_texture(image_file_path: String): #region utils -func get_section_index(section_name: String): +func get_section_index(section_name: String) -> int: for section in sections: if section.name == section_name: return sections.find(section) - + + return -1 #endregion diff --git a/scripts/splash_screen.gd b/scripts/splash_screen.gd index ff75821..3bf20f0 100644 --- a/scripts/splash_screen.gd +++ b/scripts/splash_screen.gd @@ -60,6 +60,7 @@ func _ready(): for section in Globals.sections: load_options(section.name) + load_colors(section.name) var new_scene = load("res://scenes/interface.tscn") var timer = Timer.new() @@ -124,5 +125,24 @@ func load_options(section: String): Globals.files_to_process.append(file_path) -func load_colors(): - pass +func load_colors(section: String): + var dir := DirAccess.open("./assets/" + section) + if not dir.file_exists("config.txt"): + return + + var s_index: int = Globals.get_section_index(section) + + var config = ConfigFile.new() + var err = config.load("./assets/" + section + "/config.txt") + + if not err == OK: + print(err) + return + + if config.get_value("", "color_placeholder") is String: + var color_placeholder: Color = config.get_value("", "color_placeholder") + Globals.sections[s_index].color_placeholder = color_placeholder + + if config.get_value("", "colors") is Array: + var colors = config.get_value("", "colors") as Array[Color] + Globals.sections[s_index].colors.append_array(colors)