Browse Source

modified menu to be inside a popup so it will close on both right click and left click

Jonathan Higgins 7 months ago
parent
commit
682f4f92f1
4 changed files with 196 additions and 195 deletions
  1. 1 0
      project.godot
  2. 25 23
      scenes/main/control.gd
  3. 2 11
      scenes/main/control.tscn
  4. 168 161
      scenes/menu/menu.tscn

+ 1 - 0
project.godot

@@ -32,6 +32,7 @@ window/size/viewport_height=720
 window/size/mode=2
 window/size/mode=2
 window/subwindows/embed_subwindows=false
 window/subwindows/embed_subwindows=false
 window/stretch/aspect="ignore"
 window/stretch/aspect="ignore"
+window/per_pixel_transparency/allowed=true
 
 
 [global_group]
 [global_group]
 
 

+ 25 - 23
scenes/main/control.gd

@@ -30,9 +30,9 @@ var uiscale = 1.0 #tracks scaling for retina screens
 func _ready() -> void:
 func _ready() -> void:
 	Nodes.hide()
 	Nodes.hide()
 	$mainmenu.hide()
 	$mainmenu.hide()
-	$"mainmenu/select_effect/Time Domain".show()
-	$"mainmenu/select_effect/Time Domain/Distort".show()
-	$"mainmenu/select_effect/Frequency Domain/Convert".show()
+	#$"mainmenu/select_effect/Time Domain".show()
+	#$"mainmenu/select_effect/Time Domain/Distort".show()
+	#$"mainmenu/select_effect/Frequency Domain/Convert".show()
 	$NoLocationPopup.hide()
 	$NoLocationPopup.hide()
 	$Console.hide()
 	$Console.hide()
 	$NoInputPopup.hide()
 	$NoInputPopup.hide()
@@ -1708,20 +1708,25 @@ func _on_rich_text_label_meta_clicked(meta: Variant) -> void:
 
 
 
 
 func _on_graph_edit_popup_request(at_position: Vector2) -> void:
 func _on_graph_edit_popup_request(at_position: Vector2) -> void:
-	if mainmenu_visible == false:
-		effect_position = graph_edit.get_local_mouse_position()
-		#$mainmenu.position.x = min(effect_position.x, get_viewport().get_visible_rect().size.x - $mainmenu.size.x)
-		#$mainmenu.position.y = min(effect_position.y, get_viewport().get_visible_rect().size.y - $mainmenu.size.y)
-		$mainmenu.position.x = clamp(get_viewport().get_mouse_position().x, $mainmenu/select_effect.size.x / 2, get_viewport().get_visible_rect().size.x - ($mainmenu/select_effect.size.x / 2))
-		$mainmenu.position.y = clamp(get_viewport().get_mouse_position().y, ($mainmenu/select_effect.size.y / 2) + $ColorRect.size.y, get_viewport().get_visible_rect().size.y - ($mainmenu/select_effect.size.y / 2))
-		print($GraphEdit.scroll_offset)
-		#print(DisplayServer.window_get_size()) #actual window size
-		#print(get_viewport().get_visible_rect().size) # window size asjusted for retina scaling
-		$mainmenu.show()
-		mainmenu_visible = true
-	else:
-		$mainmenu.hide()
-		mainmenu_visible = false
+	effect_position = graph_edit.get_local_mouse_position()
+	
+	#get the mouse position in screen coordinates
+	var mouse_screen_pos = DisplayServer.mouse_get_position()  
+	#get the window position in screen coordinates
+	var window_screen_pos = get_window().position
+	#get the window size relative to its scaling for retina displays
+	var window_size = get_window().size * DisplayServer.screen_get_scale()
+	#get the size of the popup menu
+	var popup_size = $mainmenu.size
+
+	#calculate the xy position of the mouse clamped to the size of the window and menu so it doesn't go off the screen
+	var clamped_x = clamp(mouse_screen_pos.x, window_screen_pos.x, window_screen_pos.x + window_size.x - popup_size.x)
+	var clamped_y = clamp(mouse_screen_pos.y, window_screen_pos.y, window_screen_pos.y + window_size.y - popup_size.y)
+	
+	#position and show the menu
+	$mainmenu.position = Vector2(clamped_x, clamped_y)
+	$mainmenu.popup()
+
 
 
 func _on_audio_settings_close_requested() -> void:
 func _on_audio_settings_close_requested() -> void:
 	$AudioSettings.hide()
 	$AudioSettings.hide()
@@ -1735,9 +1740,6 @@ func _on_open_audio_settings_button_down() -> void:
 func _on_audio_device_popup_close_requested() -> void:
 func _on_audio_device_popup_close_requested() -> void:
 	$AudioDevicePopup.hide()
 	$AudioDevicePopup.hide()
 
 
-
-#func _unhandled_input(event: InputEvent) -> void:
-	#if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
-		#if mainmenu_visible and !$mainmenu.get_global_rect().has_point(get_global_mouse_position()):
-			#mainmenu_visible = false
-			#$mainmenu.hide()
+func _on_mainmenu_close_requested() -> void:
+	#closes menu if click is anywhere other than the menu as it is a window with popup set to true
+	$mainmenu.hide()

+ 2 - 11
scenes/main/control.tscn

@@ -31,18 +31,8 @@ file_mode = 2
 access = 2
 access = 2
 use_native_dialog = true
 use_native_dialog = true
 
 
-[node name="mainmenu" parent="." instance=ExtResource("3_dtf4o")]
+[node name="mainmenu" parent="." groups=["popup_windows"] instance=ExtResource("3_dtf4o")]
 visible = false
 visible = false
-layout_mode = 0
-anchors_preset = 0
-anchor_right = 0.0
-anchor_bottom = 0.0
-offset_left = 600.0
-offset_top = 456.0
-offset_right = 600.0
-offset_bottom = 456.0
-grow_horizontal = 1
-grow_vertical = 1
 
 
 [node name="NoLocationPopup" type="Window" parent="." groups=["popup_windows"]]
 [node name="NoLocationPopup" type="Window" parent="." groups=["popup_windows"]]
 auto_translate_mode = 1
 auto_translate_mode = 1
@@ -359,6 +349,7 @@ visible = false
 [connection signal="node_selected" from="GraphEdit" to="." method="_on_graph_edit_node_selected"]
 [connection signal="node_selected" from="GraphEdit" to="." method="_on_graph_edit_node_selected"]
 [connection signal="popup_request" from="GraphEdit" to="." method="_on_graph_edit_popup_request"]
 [connection signal="popup_request" from="GraphEdit" to="." method="_on_graph_edit_popup_request"]
 [connection signal="dir_selected" from="FileDialog" to="." method="_on_file_dialog_dir_selected"]
 [connection signal="dir_selected" from="FileDialog" to="." method="_on_file_dialog_dir_selected"]
+[connection signal="close_requested" from="mainmenu" to="." method="_on_mainmenu_close_requested"]
 [connection signal="meta_clicked" from="NoLocationPopup/RichTextLabel" to="." method="_on_rich_text_label_meta_clicked"]
 [connection signal="meta_clicked" from="NoLocationPopup/RichTextLabel" to="." method="_on_rich_text_label_meta_clicked"]
 [connection signal="button_down" from="NoLocationPopup/OkButton" to="." method="_on_ok_button_button_down"]
 [connection signal="button_down" from="NoLocationPopup/OkButton" to="." method="_on_ok_button_button_down"]
 [connection signal="button_down" from="NoInputPopup/OkButton2" to="." method="_on_ok_button_2_button_down"]
 [connection signal="button_down" from="NoInputPopup/OkButton2" to="." method="_on_ok_button_2_button_down"]

File diff suppressed because it is too large
+ 168 - 161
scenes/menu/menu.tscn


Some files were not shown because too many files changed in this diff