Kaynağa Gözat

Started implementing invert theme option and fixed bug with custom theme colour not updating the menu option until after the window is closed and reopened

Jonathan Higgins 3 ay önce
ebeveyn
işleme
6c3ca82efd

+ 1 - 0
Global/config_handler.gd

@@ -17,6 +17,7 @@ func _ready():
 	ensure_setting("interface_settings", "console_on_top", true)
 	ensure_setting("interface_settings", "theme", 0)
 	ensure_setting("interface_settings", "theme_custom_colour", "#865699")
+	ensure_setting("interface_settings", "invert_theme", false)
 	ensure_setting("interface_settings", "delete_intermediate", true)
 	ensure_setting("interface_settings", "reuse_output_folder", true)
 	ensure_setting("interface_settings", "autoplay", true)

+ 0 - 1
project.godot

@@ -43,7 +43,6 @@ inputnode="input file controls"
 
 [gui]
 
-theme/custom="uid://cefwkdcoxihro"
 theme/custom_font="uid://cc7mj053bhfvh"
 
 [input]

+ 10 - 0
scenes/main/scripts/control.gd

@@ -18,6 +18,7 @@ var foldertoggle #links to the reuse folder button
 var lastoutputfolder = "none" #tracks last output folder, this can in future be used to replace global.outfile but i cba right now
 var uiscale = 1.0 #tracks scaling for retina screens
 var use_anyway #used to store the folder selected for cdprogs when it appears the wrong folder is selected but the user wants to use it anyway
+var main_theme = preload("res://theme/main_theme.tres") #load the theme
 
 
 #scripts
@@ -51,6 +52,7 @@ func _ready() -> void:
 	
 	get_tree().set_auto_accept_quit(false) #disable closing the app with the x and instead handle it internally
 	
+	
 	load_scripts()
 	make_signal_connections()
 	check_user_preferences()
@@ -179,6 +181,14 @@ func check_user_preferences():
 			RenderingServer.set_default_clear_color(Color("#98d4d2"))
 		3:
 			RenderingServer.set_default_clear_color(Color(interface_settings.theme_custom_colour))
+			
+	#set the theme to either the main theme or inverted theme depending on user preferences
+	if interface_settings.invert_theme:
+		var inverted = $Settings.invert_theme(main_theme)
+		get_tree().root.theme = inverted
+	else:
+		get_tree().root.theme = main_theme
+		
 func show_cdp_location():
 	$CdpLocationDialog.show()
 	

+ 38 - 0
scenes/main/scripts/settings.gd

@@ -2,6 +2,7 @@ extends Window
 signal open_cdp_location
 signal console_on_top
 var interface_settings
+var main_theme = preload("res://theme/main_theme.tres")
 
 # Called when the node enters the scene tree for the first time.
 func _ready() -> void:
@@ -21,6 +22,7 @@ func _on_about_to_popup() -> void:
 	interface_settings = ConfigHandler.load_interface_settings()
 	$VBoxContainer/HBoxContainer5/ThemeList.select(interface_settings.theme, true)
 	$VBoxContainer/HBoxContainer/CustomColourPicker.color = Color(interface_settings.theme_custom_colour)
+	$VBoxContainer/invert_ui_container/InvertUI.button_pressed = interface_settings.invert_theme
 	$VBoxContainer/HBoxContainer2/PvocWarning.button_pressed = interface_settings.disable_pvoc_warning
 	$VBoxContainer/HBoxContainer6/ProgressBar.button_pressed = interface_settings.disable_progress_bar
 	$VBoxContainer/HBoxContainer3/AutoCloseConsole.button_pressed = interface_settings.auto_close_console
@@ -45,6 +47,7 @@ func _on_console_always_on_top_toggled(toggled_on: bool) -> void:
 
 
 func _on_theme_list_item_selected(index: int) -> void:
+	interface_settings = ConfigHandler.load_interface_settings()
 	ConfigHandler.save_interface_settings("theme", index)
 	match index:
 		0:
@@ -61,3 +64,38 @@ func _on_custom_colour_picker_color_changed(color: Color) -> void:
 	ConfigHandler.save_interface_settings("theme_custom_colour", color.to_html(false))
 	if $VBoxContainer/HBoxContainer5/ThemeList.is_selected(3):
 		RenderingServer.set_default_clear_color(color)
+		
+func invert_theme(theme: Theme) -> Theme:
+	var inverted_theme = theme.duplicate(true) # deep copy
+
+	# Check all types and color names in the theme
+	var types = inverted_theme.get_type_list()
+	for type in types:
+		var color_names = inverted_theme.get_color_list(type)
+		for cname in color_names:
+			var col = inverted_theme.get_color(cname, type)
+			var inverted = Color(1.0 - col.r, 1.0 - col.g, 1.0 - col.b, col.a)
+			inverted_theme.set_color(cname, type, inverted)
+
+		var style_names = inverted_theme.get_stylebox_list(type)
+		for sname in style_names:
+			if type == "GraphEdit" and sname == "panel":
+				continue
+			var sb = inverted_theme.get_stylebox(sname, type)
+			var new_sb = sb.duplicate()
+			if new_sb is StyleBoxFlat:
+				var col = new_sb.bg_color
+				new_sb.bg_color = Color(1.0 - col.r, 1.0 - col.g, 1.0 - col.b, col.a)
+			inverted_theme.set_stylebox(sname, type, new_sb)
+	
+	return inverted_theme
+	
+
+func _on_invert_ui_toggled(toggled_on: bool) -> void:
+	ConfigHandler.save_interface_settings("invert_theme", toggled_on)
+	if toggled_on:
+		print("invert toggled on")
+		var inverted = invert_theme(main_theme)
+		get_tree().root.theme = inverted # force refresh
+	else:
+		get_tree().root.theme = main_theme # force refresheme = main_theme

+ 12 - 0
scenes/main/settings.tscn

@@ -82,6 +82,17 @@ size_flags_horizontal = 3
 color = Color(0.184314, 0.309804, 0.305882, 1)
 edit_alpha = false
 
+[node name="invert_ui_container" type="HBoxContainer" parent="VBoxContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="VBoxContainer/invert_ui_container"]
+layout_mode = 2
+text = "Invert UI colours:"
+
+[node name="InvertUI" type="CheckButton" parent="VBoxContainer/invert_ui_container"]
+layout_mode = 2
+size_flags_horizontal = 3
+
 [node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
 layout_mode = 2
 
@@ -131,6 +142,7 @@ size_flags_horizontal = 3
 [connection signal="button_down" from="VBoxContainer/ChangeCDP" to="." method="_on_change_cdp_button_down"]
 [connection signal="item_selected" from="VBoxContainer/HBoxContainer5/ThemeList" to="." method="_on_theme_list_item_selected"]
 [connection signal="color_changed" from="VBoxContainer/HBoxContainer/CustomColourPicker" to="." method="_on_custom_colour_picker_color_changed"]
+[connection signal="toggled" from="VBoxContainer/invert_ui_container/InvertUI" to="." method="_on_invert_ui_toggled"]
 [connection signal="toggled" from="VBoxContainer/HBoxContainer2/PvocWarning" to="." method="_on_pvoc_warning_toggled"]
 [connection signal="toggled" from="VBoxContainer/HBoxContainer6/ProgressBar" to="." method="_on_progress_bar_toggled"]
 [connection signal="toggled" from="VBoxContainer/HBoxContainer3/AutoCloseConsole" to="." method="_on_auto_close_console_toggled"]

Dosya farkı çok büyük olduğundan ihmal edildi
+ 4 - 1
theme/main_theme.tres


Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor