Skip to content

Commit d575f15

Browse files
committed
feat: ✨ apply config to material params
1 parent d2d2403 commit d575f15

File tree

6 files changed

+79
-43
lines changed

6 files changed

+79
-43
lines changed

root/mods-unpacked/GodotModding-UserProfile/content/ModList.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func generate_grid(user_profile: ModLoaderUserProfile.Profile) -> void:
1717
for mod_id in user_profile.mod_list.keys():
1818
_generate_mod_name(mod_id)
1919
_generate_mod_active_state(mod_id, user_profile)
20-
if not ModLoaderStore.mod_data[mod_id].configs.empty():
20+
if ModLoaderStore.mod_data.has(mod_id) and not ModLoaderStore.mod_data[mod_id].configs.empty():
2121
_generate_mod_current_config(mod_id, user_profile)
2222
else:
2323
grid.add_child(grid_placeholder.new())
@@ -68,7 +68,7 @@ func clear_grid() -> void:
6868
for child in grid.get_children():
6969
if not child is Label or child is ModIdLabel:
7070
grid.remove_child(child)
71-
child.free()
71+
child.queue_free()
7272

7373

7474
func _on_mod_is_active_toggled(mod_id: String, is_active: bool) -> void:

root/mods-unpacked/GodotModding-UserProfile/content/UserProfiles.gd

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ extends WindowDialog
22

33

44
export(PackedScene) var user_profile_section: PackedScene
5+
export(String) var text_select_profile := "Select Profile"
56
export(String) var text_restart := "A game restart is required to apply the settings"
67
export(String) var text_profile_create_error := "There was an error creating the profile - check logs"
78
export(String) var text_profile_select_error := "There was an error selecting the profile - check logs"
@@ -11,34 +12,49 @@ export(String) var text_mod_disable_error := "There was an error disabling the m
1112
export(String) var text_mod_current_config_change_error := "There was an error changing the config - check logs"
1213
export(String) var text_current_profile := " (Current Profile)"
1314

15+
onready var label_select_profile: Label = $"%LabelSelectProfile"
1416
onready var user_profile_sections := $"%UserProfileSections"
1517
onready var profile_select = $"%ProfileSelect"
1618
onready var popup_new_profile = $"%PopupNewProfile"
1719
onready var input_profile_name = $"%InputProfileName"
1820
onready var button_profile_name_submit = $"%ButtonProfileNameSubmit"
1921
onready var button_new_profile = $"%ButtonNewProfile"
20-
onready var mod_list = $"%ModList"
2122
onready var info_text = $"%InfoText"
2223

2324

2425
func _ready() -> void:
2526
_populate_profile_select()
2627
_generate_user_profile_section()
2728

29+
ModLoader.connect("current_config_changed", self, "_on_ModLoader_current_config_changed")
30+
2831

2932
func _input(event) -> void:
3033
if event is InputEventKey:
3134
if event.pressed and event.scancode == KEY_U:
3235
popup_centered() if not visible else hide()
3336

3437

38+
func apply_config(config: ModConfig) -> void:
39+
label_select_profile.text = config.data.select_profile_text
40+
41+
var material_settings: Dictionary = config.data.material_settings
42+
43+
material.set_shader_param("animate", material_settings.animate)
44+
material.set_shader_param("square_scale", material_settings.square_scale)
45+
material.set_shader_param("blur_amount", material_settings.blur_amount)
46+
material.set_shader_param("mix_amount", material_settings.mix_amount)
47+
material.set_shader_param("color_over", Color(material_settings.color))
48+
49+
3550
func _update_ui() -> void:
3651
# Update the profile select list
3752
_populate_profile_select()
3853

3954
# Update the Setting list
4055
_generate_user_profile_section()
4156

57+
4258
func _populate_profile_select() -> void:
4359
var index_current_profile: int
4460

@@ -69,7 +85,7 @@ func _on_ButtonNewProfile_pressed() -> void:
6985
func _on_ButtonDeleteProfile_pressed():
7086
var profile_to_delete := ModLoaderStore.current_user_profile
7187
# Switch to default profile
72-
if not ModLoaderUserProfile.set_profile("default"):
88+
if not ModLoaderUserProfile.set_profile(ModLoaderConfig.DEFAULT_CONFIG_NAME):
7389
info_text.text = text_profile_select_error
7490
return
7591
# Delete the profile
@@ -119,7 +135,13 @@ func _on_ModList_mod_is_active_changed(mod_id: String, is_active: bool) -> void
119135

120136

121137
func _on_ModList_mod_current_config_changed(mod_id: String, current_config_name: String):
122-
var is_success := ModLoaderConfig.set_current_mod_config(mod_id, current_config_name)
138+
var config := ModLoaderConfig.get_config(mod_id, current_config_name)
123139

124-
if not is_success:
140+
if not config:
125141
info_text.text = text_mod_current_config_change_error
142+
143+
ModLoaderConfig.set_current_config(config)
144+
145+
146+
func _on_ModLoader_current_config_changed(config: ModConfig) -> void:
147+
_update_ui()

root/mods-unpacked/GodotModding-UserProfile/content/UserProfiles.tscn

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ shader_param/animate = false
1313
shader_param/square_scale = 0.1
1414
shader_param/blur_amount = 5.061
1515
shader_param/mix_amount = 0.705
16-
shader_param/color_over = Color( 0, 0, 0, 1 )
16+
shader_param/color_over = Color( 0, 0, 0, 0.968627 )
1717

1818
[sub_resource type="ImageTexture" id=4]
1919

@@ -59,78 +59,83 @@ margin_right = 730.0
5959
margin_bottom = 580.0
6060

6161
[node name="LabelSelectProfile" type="Label" parent="MarginContainer/VBoxContainer"]
62-
margin_right = 460.0
62+
unique_name_in_owner = true
63+
margin_right = 710.0
6364
margin_bottom = 19.0
6465
custom_fonts/font = ExtResource( 4 )
6566
text = "Select Profile"
6667

6768
[node name="ProfileSelection" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
6869
margin_top = 23.0
69-
margin_right = 460.0
70+
margin_right = 710.0
7071
margin_bottom = 46.0
7172

7273
[node name="ProfileSelect" type="OptionButton" parent="MarginContainer/VBoxContainer/ProfileSelection"]
7374
unique_name_in_owner = true
74-
margin_right = 380.0
75+
margin_right = 630.0
7576
margin_bottom = 23.0
7677
size_flags_horizontal = 3
7778
custom_fonts/font = ExtResource( 5 )
7879

7980
[node name="ButtonNewProfile" type="Button" parent="MarginContainer/VBoxContainer/ProfileSelection"]
8081
unique_name_in_owner = true
81-
margin_left = 384.0
82-
margin_right = 420.0
82+
margin_left = 634.0
83+
margin_right = 670.0
8384
margin_bottom = 23.0
8485
custom_fonts/font = ExtResource( 5 )
8586
text = " + "
8687

8788
[node name="ButtonDeleteProfile" type="Button" parent="MarginContainer/VBoxContainer/ProfileSelection"]
8889
unique_name_in_owner = true
89-
margin_left = 424.0
90-
margin_right = 460.0
90+
margin_left = 674.0
91+
margin_right = 710.0
9192
margin_bottom = 23.0
9293
custom_fonts/font = ExtResource( 5 )
9394
text = " - "
9495

9596
[node name="ProfileSettings" type="MarginContainer" parent="MarginContainer/VBoxContainer"]
9697
margin_top = 50.0
97-
margin_right = 460.0
98+
margin_right = 710.0
9899
margin_bottom = 539.0
99100
size_flags_vertical = 3
100101
custom_constants/margin_top = 25
101102
custom_constants/margin_bottom = 20
102103

103104
[node name="ScrollContainer" type="ScrollContainer" parent="MarginContainer/VBoxContainer/ProfileSettings"]
104105
margin_top = 25.0
105-
margin_right = 460.0
106+
margin_right = 710.0
106107
margin_bottom = 469.0
107108

108109
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/ProfileSettings/ScrollContainer"]
109-
margin_right = 460.0
110+
margin_right = 710.0
110111
margin_bottom = 444.0
111112
size_flags_horizontal = 3
112113
size_flags_vertical = 3
113114

114115
[node name="LabelProfileSettings" type="Label" parent="MarginContainer/VBoxContainer/ProfileSettings/ScrollContainer/VBoxContainer"]
115-
margin_right = 460.0
116+
margin_right = 710.0
116117
margin_bottom = 19.0
117118
custom_fonts/font = ExtResource( 4 )
118119
text = "Profile Settings"
119120

120121
[node name="UserProfileSections" type="VBoxContainer" parent="MarginContainer/VBoxContainer/ProfileSettings/ScrollContainer/VBoxContainer"]
121122
unique_name_in_owner = true
122123
margin_top = 23.0
123-
margin_right = 460.0
124+
margin_right = 710.0
124125
margin_bottom = 444.0
125126
size_flags_horizontal = 3
126127
size_flags_vertical = 3
127128

128129
[node name="ModList" parent="MarginContainer/VBoxContainer/ProfileSettings/ScrollContainer/VBoxContainer/UserProfileSections" instance=ExtResource( 3 )]
130+
margin_left = 0.0
131+
margin_top = 0.0
132+
margin_right = 710.0
133+
margin_bottom = 39.0
129134

130135
[node name="InfoText" type="Label" parent="MarginContainer/VBoxContainer"]
131136
unique_name_in_owner = true
132137
margin_top = 543.0
133-
margin_right = 460.0
138+
margin_right = 710.0
134139
margin_bottom = 560.0
135140
custom_fonts/font = ExtResource( 5 )
136141
align = 1

root/mods-unpacked/GodotModding-UserProfile/content/components/CurrentConfigSelect.gd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ var mod_id: String
88
var config_names := {}
99

1010

11-
func add_mod_configs(mod_configs: Array) -> void:
11+
func add_mod_configs(mod_configs: Dictionary) -> void:
1212
var index := 0
13-
for config in mod_configs:
14-
config_names[config.name] = index
15-
self.add_item(config.name)
13+
for config_name in mod_configs.keys():
14+
config_names[config_name] = index
15+
add_item(config_name)
1616
index = index + 1
1717

1818

1919
func select_item(item_text: String) -> void:
20-
self.select(config_names[item_text])
20+
select(config_names[item_text])
2121

2222

2323
func _on_CurrentConfigSelect_item_selected(index) -> void:
24-
emit_signal("current_config_selected", mod_id, self.get_item_text(index))
24+
emit_signal("current_config_selected", mod_id, get_item_text(index))

root/mods-unpacked/GodotModding-UserProfile/manifest.json

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "UserProfile",
33
"namespace": "GodotModding",
4-
"version_number": "0.1.0",
4+
"version_number": "0.2.0",
55
"description": "Example Mod for User Profiles",
66
"website_url": "https://github.com/GodotModding",
77
"dependencies": [],
@@ -19,10 +19,16 @@
1919
"load_before": [],
2020
"tags": [],
2121
"config_schema": {
22+
"$schema": "https://json-schema.org/draft/2020-12/schema",
2223
"title": "Config",
2324
"description": "Config for this Mod",
2425
"type": "object",
2526
"properties": {
27+
"select_profile_text": {
28+
"title": "Select profile text:",
29+
"type": "string",
30+
"default": "Select Profile"
31+
},
2632
"material_settings": {
2733
"title": "Material Settings",
2834
"type": "object",
@@ -40,9 +46,9 @@
4046
"title": "Animate",
4147
"default": false
4248
},
43-
"bluer_amount": {
49+
"blur_amount": {
4450
"type": "number",
45-
"title": "Bluer Amount",
51+
"title": "Blur Amount",
4652
"minimum": 0.0,
4753
"maximum": 10.0,
4854
"multipleOf": 0.1,
@@ -57,18 +63,10 @@
5763
"default": 0.71
5864
},
5965
"color": {
60-
"type": "array",
66+
"type": "string",
6167
"title": "Color Over",
62-
"prefixItems": [
63-
{ "type": "number", "minimum": 0, "maximum": 255 },
64-
{ "type": "number", "minimum": 0, "maximum": 255 },
65-
{ "type": "number", "minimum": 0, "maximum": 255 },
66-
{ "type": "number", "minimum": 0, "maximum": 255 }
67-
],
68-
"items": false,
69-
"minItems": 3,
70-
"maxItems": 4,
71-
"default": [0, 0, 0, 255]
68+
"format": "color",
69+
"default": "#f7000000"
7270
}
7371
}
7472
}

root/mods-unpacked/GodotModding-UserProfile/mod_main.gd

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ var mod_dir_path := ""
88
var extensions_dir_path := ""
99
var translations_dir_path := ""
1010

11+
onready var user_profile_dialog = load("res://mods-unpacked/GodotModding-UserProfile/content/UserProfiles.tscn").instance()
12+
1113

1214
func _init(modLoader = ModLoader) -> void:
1315
ModLoaderLog.info("Init", GodotModding_User_Profile_LOG_NAME)
@@ -29,14 +31,23 @@ func add_translations(modLoader) -> void:
2931

3032

3133
func _ready():
32-
var user_profile_dialog = load("res://mods-unpacked/GodotModding-UserProfile/content/UserProfiles.tscn").instance()
3334
get_tree().root.call_deferred("add_child", user_profile_dialog)
3435

35-
# handle_config()
36+
handle_config()
3637

3738

3839
func handle_config() -> void:
3940
# Get the mod config
4041
var config := ModLoaderConfig.get_current_config(GodotModding_User_Profile_MOD_DIR)
41-
print(JSON.print(config, '\t'))
42+
ModLoader.connect("current_config_changed", self, "_on_current_config_changed")
43+
apply_config(config)
44+
45+
46+
func apply_config(config: ModConfig) -> void:
47+
user_profile_dialog.call_deferred("apply_config", config)
48+
4249

50+
func _on_current_config_changed(config: ModConfig) -> void:
51+
if config.mod_id == GodotModding_User_Profile_MOD_DIR:
52+
ModLoaderLog.debug("HHHHHEEEEEEEEYYYY - My config changed to %s" % config.name, GodotModding_User_Profile_LOG_NAME)
53+
apply_config(config)

0 commit comments

Comments
 (0)