diff --git a/assets/icons/locked.png b/assets/icons/locked.png new file mode 100644 index 0000000..346690e Binary files /dev/null and b/assets/icons/locked.png differ diff --git a/assets/icons/locked.png.import b/assets/icons/locked.png.import new file mode 100644 index 0000000..4124a84 --- /dev/null +++ b/assets/icons/locked.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dcd26ajdxnv5s" +path="res://.godot/imported/locked.png-0e485415f5c3174bad8abf5ae073d9e6.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/icons/locked.png" +dest_files=["res://.godot/imported/locked.png-0e485415f5c3174bad8abf5ae073d9e6.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/scenes/ui/select_stage.tscn b/scenes/ui/select_stage.tscn index aa22043..b01b7da 100644 --- a/scenes/ui/select_stage.tscn +++ b/scenes/ui/select_stage.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=3 uid="uid://cwf2fhvjfq7xg"] +[gd_scene load_steps=3 format=3 uid="uid://cwf2fhvjfq7xg"] [ext_resource type="Script" path="res://scripts/ui/select_stage.gd" id="1_t86bq"] +[ext_resource type="Texture2D" uid="uid://dcd26ajdxnv5s" path="res://assets/icons/locked.png" id="2_ppj84"] [node name="SelectStage" type="Control"] layout_mode = 3 @@ -62,6 +63,12 @@ theme_override_constants/margin_top = 10 theme_override_constants/margin_right = 10 theme_override_constants/margin_bottom = 10 +[node name="Locked" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer"] +layout_mode = 2 +texture = ExtResource("2_ppj84") +expand_mode = 2 +stretch_mode = 5 + [node name="Stage 1" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer"] layout_mode = 2 text = "1" @@ -74,6 +81,12 @@ theme_override_constants/margin_top = 10 theme_override_constants/margin_right = 10 theme_override_constants/margin_bottom = 10 +[node name="Locked" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2"] +layout_mode = 2 +texture = ExtResource("2_ppj84") +expand_mode = 2 +stretch_mode = 5 + [node name="Stage 2" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2"] layout_mode = 2 text = "2" @@ -86,6 +99,12 @@ theme_override_constants/margin_top = 10 theme_override_constants/margin_right = 20 theme_override_constants/margin_bottom = 10 +[node name="Locked" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer3"] +layout_mode = 2 +texture = ExtResource("2_ppj84") +expand_mode = 2 +stretch_mode = 5 + [node name="Stage 3" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer3"] layout_mode = 2 text = "3" @@ -102,6 +121,12 @@ theme_override_constants/margin_top = 10 theme_override_constants/margin_right = 10 theme_override_constants/margin_bottom = 20 +[node name="Locked" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer"] +layout_mode = 2 +texture = ExtResource("2_ppj84") +expand_mode = 2 +stretch_mode = 5 + [node name="Stage 4" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer"] layout_mode = 2 text = "4" @@ -114,6 +139,12 @@ theme_override_constants/margin_top = 10 theme_override_constants/margin_right = 10 theme_override_constants/margin_bottom = 20 +[node name="Locked" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer2"] +layout_mode = 2 +texture = ExtResource("2_ppj84") +expand_mode = 2 +stretch_mode = 5 + [node name="Stage 5" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer2"] layout_mode = 2 text = "5" @@ -126,6 +157,12 @@ theme_override_constants/margin_top = 10 theme_override_constants/margin_right = 20 theme_override_constants/margin_bottom = 20 +[node name="Locked" type="TextureRect" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer3"] +layout_mode = 2 +texture = ExtResource("2_ppj84") +expand_mode = 2 +stretch_mode = 5 + [node name="Stage 6" type="Button" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer3"] layout_mode = 2 text = "6" diff --git a/scripts/data/data.gd b/scripts/data/data.gd new file mode 100644 index 0000000..dcb7dda --- /dev/null +++ b/scripts/data/data.gd @@ -0,0 +1,31 @@ +extends Node + + +const FILE_NAME = "user://data.foh" +const KEY = "NO_OPPAI_NO_LIFE" + +func save_data(data): + var file = FileAccess.open_encrypted_with_pass(FILE_NAME, FileAccess.WRITE, KEY) + if file == null: + print(FileAccess.get_open_error()) + return + + var json_string = JSON.stringify(data, "\t") + file.store_string(json_string) + file.close() + +func load_data(): + if FileAccess.file_exists(FILE_NAME): + var file = FileAccess.open_encrypted_with_pass(FILE_NAME, FileAccess.READ, KEY) + if file == null: + print(FileAccess.get_open_error()) + return + + var content = file.get_as_text() + file.close() + + var data = JSON.parse_string(content) + + return data + else: + return null \ No newline at end of file diff --git a/scripts/stages/1/game_manager.gd b/scripts/stages/1/game_manager.gd index 8a725bd..5798749 100644 --- a/scripts/stages/1/game_manager.gd +++ b/scripts/stages/1/game_manager.gd @@ -113,4 +113,5 @@ func on_enemy_reward(value: int): func _on_duration_timeout(): get_tree().paused = true + $CanvasLayer/Victory.unlock_next_stage() $CanvasLayer/Victory.show() diff --git a/scripts/stages/2/game_manager.gd b/scripts/stages/2/game_manager.gd index b570456..092f92c 100644 --- a/scripts/stages/2/game_manager.gd +++ b/scripts/stages/2/game_manager.gd @@ -112,4 +112,5 @@ func on_enemy_reward(value: int): func _on_duration_timeout(): get_tree().paused = true + $CanvasLayer/Victory.unlock_next_stage() $CanvasLayer/Victory.show() \ No newline at end of file diff --git a/scripts/stages/3/game_manager.gd b/scripts/stages/3/game_manager.gd index 0b8cdbe..40baf47 100644 --- a/scripts/stages/3/game_manager.gd +++ b/scripts/stages/3/game_manager.gd @@ -112,4 +112,5 @@ func on_enemy_reward(value: int): func _on_duration_timeout(): get_tree().paused = true + $CanvasLayer/Victory.unlock_next_stage() $CanvasLayer/Victory.show() diff --git a/scripts/stages/4/game_manager.gd b/scripts/stages/4/game_manager.gd index 9923d68..30a4bf8 100644 --- a/scripts/stages/4/game_manager.gd +++ b/scripts/stages/4/game_manager.gd @@ -112,4 +112,5 @@ func on_enemy_reward(value: int): func _on_duration_timeout(): get_tree().paused = true + $CanvasLayer/Victory.unlock_next_stage() $CanvasLayer/Victory.show() \ No newline at end of file diff --git a/scripts/stages/5/game_manager.gd b/scripts/stages/5/game_manager.gd index a74c994..14d183f 100644 --- a/scripts/stages/5/game_manager.gd +++ b/scripts/stages/5/game_manager.gd @@ -112,4 +112,5 @@ func on_enemy_reward(value: int): func _on_duration_timeout(): get_tree().paused = true + $CanvasLayer/Victory.unlock_next_stage() $CanvasLayer/Victory.show() \ No newline at end of file diff --git a/scripts/stages/6/game_manager.gd b/scripts/stages/6/game_manager.gd index c694067..157565b 100644 --- a/scripts/stages/6/game_manager.gd +++ b/scripts/stages/6/game_manager.gd @@ -112,4 +112,5 @@ func on_enemy_reward(value: int): func _on_duration_timeout(): get_tree().paused = true + $CanvasLayer/Victory.unlock_next_stage() $CanvasLayer/Victory.show() \ No newline at end of file diff --git a/scripts/ui/main_menu.gd b/scripts/ui/main_menu.gd index 46f59d2..ca85620 100644 --- a/scripts/ui/main_menu.gd +++ b/scripts/ui/main_menu.gd @@ -1,6 +1,16 @@ extends Control +var game_data = load("res://scripts/data/data.gd").new() + +func _ready(): + var data = game_data.load_data() + if data == null: + game_data.save_data({ + "debug": false, + "unlocked_stage": 1 + }) + func _on_start_game_pressed(): get_tree().change_scene_to_file("res://scenes/ui/select_stage.tscn") diff --git a/scripts/ui/select_stage.gd b/scripts/ui/select_stage.gd index 76a5142..d5548ca 100644 --- a/scripts/ui/select_stage.gd +++ b/scripts/ui/select_stage.gd @@ -1,23 +1,63 @@ extends Control +var game_data = load("res://scripts/data/data.gd").new() +var data = game_data.load_data() + +func _ready(): + match int(data['unlocked_stage']): + 1: + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer/Locked.hide() + 2: + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2/Locked.hide() + 3: + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer3/Locked.hide() + 4: + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer3/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer/Locked.hide() + 5: + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer3/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer2/Locked.hide() + 6: + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer2/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer2/MarginContainer3/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer2/Locked.hide() + $Panel/MarginContainer/VBoxContainer/HBoxContainer3/MarginContainer3/Locked.hide() + _: + pass + func _on_back_pressed(): get_tree().change_scene_to_file("res://scenes/ui/main_menu.tscn") func _on_stage_1_pressed(): - get_tree().change_scene_to_file("res://scenes/stages/stage_1.tscn") + verify_selected_stage(1) func _on_stage_2_pressed(): - get_tree().change_scene_to_file("res://scenes/stages/stage_2.tscn") + verify_selected_stage(2) func _on_stage_3_pressed(): - get_tree().change_scene_to_file("res://scenes/stages/stage_3.tscn") + verify_selected_stage(3) func _on_stage_4_pressed(): - get_tree().change_scene_to_file("res://scenes/stages/stage_4.tscn") + verify_selected_stage(4) func _on_stage_5_pressed(): - get_tree().change_scene_to_file("res://scenes/stages/stage_5.tscn") + verify_selected_stage(5) func _on_stage_6_pressed(): - get_tree().change_scene_to_file("res://scenes/stages/stage_6.tscn") \ No newline at end of file + verify_selected_stage(6) + +func verify_selected_stage(stage_id: int): + if int(data['unlocked_stage']) >= stage_id: + get_tree().change_scene_to_file("res://scenes/stages/stage_{stage_id}.tscn".format({"stage_id": str(stage_id)})) + pass \ No newline at end of file diff --git a/scripts/ui/victory.gd b/scripts/ui/victory.gd index 7baa39e..95ed736 100644 --- a/scripts/ui/victory.gd +++ b/scripts/ui/victory.gd @@ -1,6 +1,9 @@ extends Control +var game_data = load("res://scripts/data/data.gd").new() +var data = game_data.load_data() + var next_stage: int = 0 func set_next_stage(value: int): @@ -9,6 +12,11 @@ func set_next_stage(value: int): else: $Panel/MarginContainer/VBoxContainer/NextStage.text = "Main Menu" +func unlock_next_stage(): + if next_stage != 0: + data['unlocked_stage'] = next_stage + game_data.save_data(data) + func _on_next_stage_pressed(): get_tree().paused = false