From adfc8000b2c15faf24cb5ef883645dff5b6f2eab Mon Sep 17 00:00:00 2001 From: Noah Date: Mon, 10 Oct 2022 20:59:43 -0500 Subject: [PATCH] Added versions selector --- Main_menu.gd | 9 +++++- Main_menu.tscn | 53 ++++++++++++++++++------------ Store.gd | 72 +++++++++++++++++++++++++++++++++++++++++ Versions.gd | 24 ++++++++++++++ fonts/retro_gaming.tres | 1 - project.godot | 7 +++- themes/Base_theme.tres | 4 ++- 7 files changed, 146 insertions(+), 24 deletions(-) create mode 100644 Store.gd create mode 100644 Versions.gd diff --git a/Main_menu.gd b/Main_menu.gd index 22f638a..6a22059 100644 --- a/Main_menu.gd +++ b/Main_menu.gd @@ -1,4 +1,11 @@ extends Control +onready var Version_menu = $Panel/Version_menu + func _ready(): - pass + for version in Versions.get_versions(): + $Panel/Version_menu.add_item(version) + + +func _on_Play_button_pressed(): + var version = Version_menu.get_item_text(Version_menu.selected) diff --git a/Main_menu.tscn b/Main_menu.tscn index 1fe93c6..735b87c 100644 --- a/Main_menu.tscn +++ b/Main_menu.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://textures/Title-Background.png" type="Texture" id=1] [ext_resource path="res://fonts/SPACEBAR.ttf" type="DynamicFontData" id=2] [ext_resource path="res://Main_menu.gd" type="Script" id=3] [ext_resource path="res://fonts/Title-font.tres" type="DynamicFont" id=4] [ext_resource path="res://themes/Base_theme.tres" type="Theme" id=5] +[ext_resource path="res://fonts/retro_gaming.tres" type="DynamicFont" id=7] [sub_resource type="Theme" id=1] default_font = ExtResource( 4 ) @@ -13,7 +14,18 @@ default_font = ExtResource( 4 ) size = 40 font_data = ExtResource( 2 ) -[sub_resource type="DynamicFont" id=3] +[sub_resource type="StyleBoxFlat" id=4] +bg_color = Color( 0.0823529, 0.0745098, 0.117647, 1 ) +border_width_left = 10 +border_width_right = 5 +border_color = Color( 0.0823529, 0.0745098, 0.117647, 1 ) +corner_radius_top_left = 16 +corner_radius_top_right = 16 +corner_radius_bottom_right = 16 +corner_radius_bottom_left = 16 +corner_detail = 16 + +[sub_resource type="DynamicFont" id=5] size = 32 font_data = ExtResource( 2 ) @@ -22,21 +34,12 @@ anchor_right = 1.0 anchor_bottom = 1.0 theme = ExtResource( 5 ) script = ExtResource( 3 ) -__meta__ = { -"_edit_lock_": true -} - -[node name="HTTPRequest" type="HTTPRequest" parent="."] [node name="Background" type="TextureRect" parent="."] margin_right = 2000.0 margin_bottom = 2000.0 rect_scale = Vector2( 0.722402, 0.558973 ) texture = ExtResource( 1 ) -__meta__ = { -"_edit_group_": true, -"_edit_lock_": true -} [node name="Header" type="Label" parent="."] anchor_right = 1.0 @@ -51,18 +54,28 @@ valign = 1 anchor_top = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 -margin_left = 40.0 -margin_top = -112.0 -margin_right = -40.0 +margin_left = 64.0 +margin_top = -120.0 +margin_right = -64.0 +margin_bottom = -24.0 theme = ExtResource( 5 ) +custom_styles/panel = SubResource( 4 ) + +[node name="Version_menu" type="OptionButton" parent="Panel"] +margin_left = 304.0 +margin_top = 64.0 +margin_right = 432.0 +margin_bottom = 91.0 +theme = ExtResource( 5 ) +custom_fonts/font = ExtResource( 7 ) [node name="Play_button" type="Button" parent="Panel"] -margin_left = 344.0 -margin_top = 24.0 -margin_right = 610.0 -margin_bottom = 96.0 +margin_left = 288.0 +margin_top = 8.0 +margin_right = 612.0 +margin_bottom = 61.0 rect_scale = Vector2( 0.962016, 0.91427 ) -custom_fonts/font = SubResource( 3 ) +custom_fonts/font = SubResource( 5 ) text = "play" -[connection signal="request_completed" from="HTTPRequest" to="." method="_on_HTTPRequest_request_completed"] +[connection signal="pressed" from="Panel/Play_button" to="." method="_on_Play_button_pressed"] diff --git a/Store.gd b/Store.gd new file mode 100644 index 0000000..7b97e8c --- /dev/null +++ b/Store.gd @@ -0,0 +1,72 @@ +# UltraFlare +# Store.gd is a set of functions for storing settings/data using JSON files + +extends Node + +# Create a new file object for the config +var store_dir = Directory.new() +var store_file = File.new() + +# Define a place to store places to look for the date +var store_paths = [OS.get_config_dir()+"/UltraFlare/"] +var store_path = null + + +# When script/game is loaded, +func _ready(): + # For each path, + for path in store_paths: + # If the path exists, + if store_dir.dir_exists(path): + if store_file.file_exists(path): + # Set the data_path to that path + store_path = path + # Break out of the loop + break + + # If the for loop finished with no results, + if store_path == null: + # Set the data path to the first entry in the data_paths array + store_path = store_paths[0] + store_dir.make_dir_recursive(store_path) + store_file.open(store_path+"/store.json", 3) + +# get_store() +# Used for getting all data in storage +func get_store(): + var data = JSONParseResult.new() + store_file.open(store_path+"/store.json", 1) + + # Read the data from the stores + if store_file.get_as_text() != "": + data = JSON.parse(store_file.get_as_text()) + + store_file.close() + + # If no data was found, + if data.error or data == null or data.result == null: + return {} + # If data was found, + return data.result + + +# store() +# Used for storing data to the storage +func write_store(key, value): + # Read the data from the store + var data = get_store() + + # If the value is null, + if value == null: + # Remove the key-value pair from the dictionary + data.erase(key) + else: + # Store the key-value pair + data[key] = value + + store_file.open(store_path+"/store.json", 2) + + # Translate the dictionary back to JSON and store it + store_file.store_string(JSON.print(data, " ")) + # Close the file + store_file.close() diff --git a/Versions.gd b/Versions.gd new file mode 100644 index 0000000..7265076 --- /dev/null +++ b/Versions.gd @@ -0,0 +1,24 @@ +extends Node + +var versions_dir_path = OS.get_config_dir()+"/UltraFlare/versions/" +var versions_dir = Directory.new() + +func get_versions(): + var versions = [] + versions_dir.open(versions_dir_path) + versions_dir.list_dir_begin(true) + + var file_name = versions_dir.get_next() + while file_name != "": + versions.append(file_name) + file_name = versions_dir.get_next() + + versions_dir.list_dir_end() + + return versions + + +func _ready(): + if not versions_dir.dir_exists(versions_dir_path): + versions_dir.make_dir_recursive(versions_dir_path) + diff --git a/fonts/retro_gaming.tres b/fonts/retro_gaming.tres index 136530e..180bb44 100644 --- a/fonts/retro_gaming.tres +++ b/fonts/retro_gaming.tres @@ -3,5 +3,4 @@ [ext_resource path="res://fonts/Retro Gaming.ttf" type="DynamicFontData" id=1] [resource] -outline_color = Color( 0.0823529, 0.0745098, 0.117647, 1 ) font_data = ExtResource( 1 ) diff --git a/project.godot b/project.godot index 36045c4..d3b110a 100644 --- a/project.godot +++ b/project.godot @@ -14,10 +14,15 @@ config/name="UltraFlare Launcher" run/main_scene="res://Main_menu.tscn" config/icon="res://icon.png" +[autoload] + +Store="*res://Store.gd" +Versions="*res://Versions.gd" + [display] window/stretch/mode="2d" -window/stretch/aspect="keep" +window/stretch/aspect="expand" [editor] diff --git a/themes/Base_theme.tres b/themes/Base_theme.tres index bc84a19..d5572f4 100644 --- a/themes/Base_theme.tres +++ b/themes/Base_theme.tres @@ -1,8 +1,10 @@ -[gd_resource type="Theme" load_steps=3 format=2] +[gd_resource type="Theme" load_steps=4 format=2] [ext_resource path="res://fonts/Title-font.tres" type="DynamicFont" id=1] [ext_resource path="res://themes/Base_panel.tres" type="StyleBox" id=2] +[ext_resource path="res://fonts/retro_gaming.tres" type="DynamicFont" id=3] [resource] default_font = ExtResource( 1 ) Panel/styles/panel = ExtResource( 2 ) +PopupMenu/fonts/font = ExtResource( 3 )