fuzzyworld

godot-shooter / commit

Added an optional setting to show all items on the radar. This is off by default.

e96078c12d29f68873ff09729eb9caf73b5601a6 · Pavel Safronov · 2023-11-17 12:14:17 -0800 · parents 5be558de3376

Added an optional setting to show all items on the radar. This is off by default.
 actors/Player.gd   |  7 +++++++
 actors/Player.tscn | 21 ++++++++++++++-------
 scenes/World.gd    |  7 ++++++-
 utils/Settings.gd  |  5 +++--
 utils/Utils.gd     |  1 +
 5 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/actors/Player.gd b/actors/Player.gd
index 6995f82..f55e7e8 100644
--- a/actors/Player.gd
+++ b/actors/Player.gd
@@ -27,6 +27,7 @@ onready var scores_list = $UI/PauseMenu/CenterContainer/PanelContainer/VBoxConta
 onready var intro_menu = $UI/IntroMenu
 onready var intro_always_show_intro_check = $UI/IntroMenu/CenterContainer/PanelContainer/VBoxContainer/AlwaysShowIntroCheckBox
 onready var pause_always_show_intro_check = $UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/TabContainer/Pref/AlwaysShowIntroCheckBox
+onready var pause_show_items_in_radar_check = $UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/TabContainer/Pref/ShowItemsInRadarCheckBox
 onready var health_label = $Graphics/Alive/StaticControls/HealthLabel
 onready var trails = $Graphics/Alive/Trails
 onready var shot_timer = $ShotTimer
@@ -51,6 +52,7 @@ func _ready() -> void:
 	settings = Utils.load_user_settings()
 	settings.save_user_settings()
 	pause_always_show_intro_check.pressed = settings.show_intro
+	pause_show_items_in_radar_check.pressed = settings.show_items
 	if settings.show_intro:
 		show_intro()
 
@@ -190,6 +192,11 @@ func _on_PauseAlwaysShowIntroCheckBox_pressed() -> void:
 	var show_intro = pause_always_show_intro_check.pressed
 	set_intro_dialog(show_intro)
 
+func _on_ShowItemsInRadarCheckBox_pressed() -> void:
+	var show_items = pause_show_items_in_radar_check.pressed
+	settings.show_items = show_items
+	settings.save_user_settings()
+
 func add_high_score(new_score: int) -> void:
 	var hs = Settings.HighScore.new(new_score, Time.get_datetime_dict_from_system())
 	var hss = settings.high_scores
diff --git a/actors/Player.tscn b/actors/Player.tscn
index cee98a5..49be807 100644
--- a/actors/Player.tscn
+++ b/actors/Player.tscn
@@ -224,7 +224,7 @@ rect_min_size = Vector2( 450, 235 )
 margin_left = 14.0
 margin_top = 14.0
 margin_right = 436.0
-margin_bottom = 233.0
+margin_bottom = 277.0
 
 [node name="Label" type="Label" parent="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer"]
 margin_right = 422.0
@@ -236,9 +236,10 @@ align = 1
 [node name="TabContainer" type="TabContainer" parent="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer"]
 margin_top = 45.0
 margin_right = 422.0
-margin_bottom = 174.0
+margin_bottom = 218.0
 
 [node name="Scores" type="VBoxContainer" parent="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/TabContainer"]
+visible = false
 anchor_right = 1.0
 anchor_bottom = 1.0
 margin_left = 8.0
@@ -254,15 +255,14 @@ text = "High scores:"
 [node name="ScoresList" type="VBoxContainer" parent="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/TabContainer/Scores"]
 margin_top = 33.0
 margin_right = 406.0
-margin_bottom = 33.0
+margin_bottom = 58.0
 
 [node name="Label" type="Label" parent="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/TabContainer/Scores/ScoresList"]
-margin_right = 40.0
+margin_right = 406.0
 margin_bottom = 25.0
 text = "No high scores yet!"
 
 [node name="Pref" type="VBoxContainer" parent="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/TabContainer"]
-visible = false
 anchor_right = 1.0
 anchor_bottom = 1.0
 margin_left = 8.0
@@ -275,6 +275,12 @@ margin_right = 406.0
 margin_bottom = 48.0
 text = "Show intro dialog"
 
+[node name="ShowItemsInRadarCheckBox" type="CheckBox" parent="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/TabContainer/Pref"]
+margin_top = 56.0
+margin_right = 406.0
+margin_bottom = 104.0
+text = "Show items in radar"
+
 [node name="About" type="VBoxContainer" parent="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/TabContainer"]
 visible = false
 anchor_right = 1.0
@@ -299,9 +305,9 @@ focus_mode = 2
 text = "Source code"
 
 [node name="ResumeButton" type="Button" parent="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer"]
-margin_top = 182.0
+margin_top = 226.0
 margin_right = 422.0
-margin_bottom = 219.0
+margin_bottom = 263.0
 theme = ExtResource( 5 )
 text = "Resume"
 
@@ -364,6 +370,7 @@ __meta__ = {
 [connection signal="pressed" from="UI/DeathScreen/CenterContainer/PanelContainer/VBoxContainer/StartNewGameButton" to="." method="_on_StartNewGameButton_pressed"]
 [connection signal="pressed" from="UI/IntroMenu/CenterContainer/PanelContainer/VBoxContainer/StartButton" to="." method="_on_StartButton_pressed"]
 [connection signal="pressed" from="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/TabContainer/Pref/AlwaysShowIntroCheckBox" to="." method="_on_PauseAlwaysShowIntroCheckBox_pressed"]
+[connection signal="pressed" from="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/TabContainer/Pref/ShowItemsInRadarCheckBox" to="." method="_on_ShowItemsInRadarCheckBox_pressed"]
 [connection signal="pressed" from="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/TabContainer/About/LinkButton" to="." method="_on_LinkButton_pressed"]
 [connection signal="pressed" from="UI/PauseMenu/CenterContainer/PanelContainer/VBoxContainer/ResumeButton" to="." method="_on_ResumeButton_pressed"]
 [connection signal="timeout" from="ShotTimer" to="." method="allow_fire"]
diff --git a/scenes/World.gd b/scenes/World.gd
index 52375b3..4ec89b9 100644
--- a/scenes/World.gd
+++ b/scenes/World.gd
@@ -139,7 +139,12 @@ func _process(_delta: float) -> void:
 			enemy.teleport(new_pos)
 
 	player.clear_radar()
-	player.update_radar(get_tree().get_nodes_in_group("gold"), Color.yellow)
+	
+	if player.settings.show_items:
+		player.update_radar(get_tree().get_nodes_in_group("health"), Color.gray)
+		player.update_radar(get_tree().get_nodes_in_group("weapons"), Color.white)
+
+	player.update_radar(get_tree().get_nodes_in_group("gold"), Color.gold)
 	player.update_radar(filteredEnemies, Color.red)
 
 func _on_Destination_body_entered(body: Node) -> void:
diff --git a/utils/Settings.gd b/utils/Settings.gd
index 3fc05a2..8df69a2 100644
--- a/utils/Settings.gd
+++ b/utils/Settings.gd
@@ -1,8 +1,8 @@
 class_name Settings
 
 var show_intro = true
-var high_scores: Array = [
-]
+var show_items = false
+var high_scores: Array = []
 
 class HighScore:
 	var score: int
@@ -26,6 +26,7 @@ func to_json() -> Dictionary:
 		scores.push_back(json)
 	var final_obj = {
 		"show_intro": show_intro,
+		"show_items": show_items,
 		"high_scores": scores
 	}
 	return final_obj
diff --git a/utils/Utils.gd b/utils/Utils.gd
index cf32600..3ce4ebf 100644
--- a/utils/Utils.gd
+++ b/utils/Utils.gd
@@ -17,6 +17,7 @@ static func load_user_settings(path = SettingsClass.settings_path) -> Settings:
 			var json = parse_json(text)
 			var data: Settings = Settings.new()
 			data.show_intro = json["show_intro"]
+			data.show_items = json["show_items"]
 			if json.has("high_scores"):
 				data.high_scores = []
 #				print("high scores", high_scores)