Skip to content

Commit b0b8abe

Browse files
authored
Merge pull request #1 from GodotModding/Mod_Config_Update
feat: ✨ added `current_config`
2 parents ccf3b23 + ceb70cd commit b0b8abe

File tree

14 files changed

+325
-174
lines changed

14 files changed

+325
-174
lines changed

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

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,78 @@ extends MarginContainer
22

33

44
signal mod_is_active_changed(mod_id, is_active)
5+
signal mod_current_config_changed(mod_id, current_config)
56

6-
export(PackedScene) var mod_list_mod
7+
export(PackedScene) var mod_id_label_scene
8+
export(PackedScene) var is_active_toggle_scene
9+
export(PackedScene) var current_config_select_scene
710

8-
var section_name := "" setget _set_section_name
11+
var grid_placeholder := Control
912

10-
onready var user_profile_name := $"%SectionName"
11-
onready var mod_list = $"%ModList"
13+
onready var grid = $"%Grid"
1214

1315

14-
func _set_section_name(new_name: String) -> void:
15-
section_name = new_name
16-
user_profile_name.text = new_name
16+
func generate_grid(user_profile: ModLoaderUserProfile.Profile) -> void:
17+
for mod_id in user_profile.mod_list.keys():
18+
_generate_mod_name(mod_id)
19+
_generate_mod_active_state(mod_id, user_profile)
20+
if ModLoaderStore.mod_data.has(mod_id) and not ModLoaderStore.mod_data[mod_id].configs.empty():
21+
_generate_mod_current_config(mod_id, user_profile)
22+
else:
23+
grid.add_child(grid_placeholder.new())
1724

1825

19-
func generate_mod_list(user_profile: ModLoaderUserProfile.Profile) -> void:
20-
for mod_id in user_profile.mod_list.keys():
21-
var new_mod_list_mod: HBoxContainer = mod_list_mod.instance()
26+
func _generate_mod_name(mod_id: String) -> void:
27+
var label_mod_id: ModIdLabel = mod_id_label_scene.instance()
28+
grid.add_child(label_mod_id)
29+
label_mod_id.text = mod_id
30+
31+
if ModLoaderStore.mod_data.has(mod_id):
32+
var mod: ModData = ModLoaderStore.mod_data[mod_id]
33+
34+
# Check if mod is locked
35+
if mod.is_locked:
36+
label_mod_id.set_mandatory_color()
37+
38+
# Check if the mod is loadable
39+
if not mod.is_loadable:
40+
label_mod_id.set_error_color()
2241

23-
new_mod_list_mod.connect("is_active_toggled", self, "_on_mod_is_active_toggled")
24-
mod_list.add_child(new_mod_list_mod)
25-
new_mod_list_mod.mod_id = mod_id
26-
new_mod_list_mod.is_active = user_profile.mod_list[mod_id]
2742

28-
if ModLoaderStore.mod_data.has(mod_id):
29-
var mod: ModData = ModLoaderStore.mod_data[mod_id]
43+
func _generate_mod_active_state(mod_id: String, user_profile: ModLoaderUserProfile.Profile) -> void:
44+
var is_active_toggle: IsActiveToggle = is_active_toggle_scene.instance()
45+
grid.add_child(is_active_toggle)
46+
is_active_toggle.mod_id = mod_id
47+
is_active_toggle.is_active = user_profile.mod_list[mod_id].is_active
48+
is_active_toggle.connect("is_active_toggled", self, "_on_mod_is_active_toggled")
3049

31-
# Check if mod is locked
32-
if mod.is_locked:
33-
# Disable the checkbox if it is
34-
new_mod_list_mod.is_disabled = true
35-
new_mod_list_mod.set_mandatory_color()
50+
if ModLoaderStore.mod_data.has(mod_id):
51+
var mod: ModData = ModLoaderStore.mod_data[mod_id]
52+
# Check if mod is locked
53+
if mod.is_locked:
54+
# Disable the checkbox if it is
55+
is_active_toggle.disabled = true
3656

37-
# Check if the mod is loadable
38-
if not mod.is_loadable:
39-
new_mod_list_mod.set_error_color()
4057

58+
func _generate_mod_current_config(mod_id: String, user_profile: ModLoaderUserProfile.Profile) -> void:
59+
var current_config_select: CurrentConfigSelect = current_config_select_scene.instance()
60+
grid.add_child(current_config_select)
61+
current_config_select.mod_id = mod_id
62+
current_config_select.add_mod_configs(ModLoaderStore.mod_data[mod_id].configs)
63+
current_config_select.select_item(user_profile.mod_list[mod_id].current_config)
64+
current_config_select.connect("current_config_selected", self, "_on_current_config_selected")
65+
66+
67+
func clear_grid() -> void:
68+
for child in grid.get_children():
69+
if not child is Label or child is ModIdLabel:
70+
grid.remove_child(child)
71+
child.queue_free()
4172

42-
func clear_mod_list() -> void:
43-
for child in mod_list.get_children():
44-
mod_list.remove_child(child)
45-
child.free()
4673

4774
func _on_mod_is_active_toggled(mod_id: String, is_active: bool) -> void:
4875
emit_signal("mod_is_active_changed", mod_id, is_active)
76+
77+
78+
func _on_current_config_selected(mod_id: String, config_name: String) -> void:
79+
emit_signal("mod_current_config_changed", mod_id, config_name)
Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
[gd_scene load_steps=4 format=2]
1+
[gd_scene load_steps=6 format=2]
22

33
[ext_resource path="res://mods-unpacked/GodotModding-UserProfile/content/ModList.gd" type="Script" id=1]
4-
[ext_resource path="res://mods-unpacked/GodotModding-UserProfile/content/ModListMod.tscn" type="PackedScene" id=2]
4+
[ext_resource path="res://mods-unpacked/GodotModding-UserProfile/content/components/IsActiveToggle.tscn" type="PackedScene" id=2]
55
[ext_resource path="res://mods-unpacked/GodotModding-UserProfile/assets/fonts/Heading.tres" type="DynamicFont" id=3]
6+
[ext_resource path="res://mods-unpacked/GodotModding-UserProfile/content/components/CurrentConfigSelect.tscn" type="PackedScene" id=4]
7+
[ext_resource path="res://mods-unpacked/GodotModding-UserProfile/content/components/ModIdLabel.tscn" type="PackedScene" id=5]
68

79
[node name="ModList" type="MarginContainer"]
810
margin_left = 20.0
@@ -12,23 +14,37 @@ margin_bottom = 1060.0
1214
custom_constants/margin_top = 10
1315
custom_constants/margin_bottom = 10
1416
script = ExtResource( 1 )
15-
mod_list_mod = ExtResource( 2 )
17+
mod_id_label_scene = ExtResource( 5 )
18+
is_active_toggle_scene = ExtResource( 2 )
19+
current_config_select_scene = ExtResource( 4 )
1620

17-
[node name="VBoxContainer" type="VBoxContainer" parent="."]
21+
[node name="Grid" type="GridContainer" parent="."]
22+
unique_name_in_owner = true
1823
margin_top = 10.0
1924
margin_right = 1880.0
2025
margin_bottom = 1030.0
26+
custom_constants/hseparation = 50
27+
columns = 3
2128

22-
[node name="SectionName" type="Label" parent="VBoxContainer"]
29+
[node name="LabelModName" type="Label" parent="Grid"]
2330
unique_name_in_owner = true
24-
margin_right = 1880.0
31+
margin_right = 72.0
2532
margin_bottom = 19.0
2633
custom_fonts/font = ExtResource( 3 )
27-
text = "Active Mods"
34+
text = "Mod Name"
2835

29-
[node name="ModList" type="VBoxContainer" parent="VBoxContainer"]
36+
[node name="LabelActiveState" type="Label" parent="Grid"]
3037
unique_name_in_owner = true
31-
margin_top = 23.0
32-
margin_right = 1880.0
33-
margin_bottom = 23.0
34-
size_flags_horizontal = 3
38+
margin_left = 122.0
39+
margin_right = 176.0
40+
margin_bottom = 19.0
41+
custom_fonts/font = ExtResource( 3 )
42+
text = "active"
43+
44+
[node name="LabelCurrentConfig" type="Label" parent="Grid"]
45+
unique_name_in_owner = true
46+
margin_left = 226.0
47+
margin_right = 352.0
48+
margin_bottom = 19.0
49+
custom_fonts/font = ExtResource( 3 )
50+
text = "current config"

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

Lines changed: 0 additions & 49 deletions
This file was deleted.

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

Lines changed: 0 additions & 30 deletions
This file was deleted.

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

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,59 @@ 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"
89
export(String) var text_profile_delete_error := "There was an error deleting the profile - check logs"
910
export(String) var text_mod_enable_error := "There was an error enabling the mod - check logs"
1011
export(String) var text_mod_disable_error := "There was an error disabling the mod - check logs"
12+
export(String) var text_mod_current_config_change_error := "There was an error changing the config - check logs"
1113
export(String) var text_current_profile := " (Current Profile)"
1214

15+
onready var label_select_profile: Label = $"%LabelSelectProfile"
1316
onready var user_profile_sections := $"%UserProfileSections"
1417
onready var profile_select = $"%ProfileSelect"
1518
onready var popup_new_profile = $"%PopupNewProfile"
1619
onready var input_profile_name = $"%InputProfileName"
1720
onready var button_profile_name_submit = $"%ButtonProfileNameSubmit"
1821
onready var button_new_profile = $"%ButtonNewProfile"
19-
onready var mod_list = $"%ModList"
2022
onready var info_text = $"%InfoText"
2123

2224

2325
func _ready() -> void:
2426
_populate_profile_select()
2527
_generate_user_profile_section()
2628

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

2832
func _input(event) -> void:
2933
if event is InputEventKey:
3034
if event.pressed and event.scancode == KEY_U:
3135
popup_centered() if not visible else hide()
3236

3337

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+
3450
func _update_ui() -> void:
3551
# Update the profile select list
3652
_populate_profile_select()
3753

3854
# Update the Setting list
3955
_generate_user_profile_section()
4056

57+
4158
func _populate_profile_select() -> void:
4259
var index_current_profile: int
4360

@@ -56,8 +73,9 @@ func _populate_profile_select() -> void:
5673

5774

5875
func _generate_user_profile_section() -> void:
59-
mod_list.clear_mod_list()
60-
mod_list.generate_mod_list(ModLoaderUserProfile.get_current())
76+
for section in user_profile_sections.get_children():
77+
section.clear_grid()
78+
section.generate_grid(ModLoaderUserProfile.get_current())
6179

6280

6381
func _on_ButtonNewProfile_pressed() -> void:
@@ -67,7 +85,7 @@ func _on_ButtonNewProfile_pressed() -> void:
6785
func _on_ButtonDeleteProfile_pressed():
6886
var profile_to_delete := ModLoaderStore.current_user_profile
6987
# Switch to default profile
70-
if not ModLoaderUserProfile.set_profile("default"):
88+
if not ModLoaderUserProfile.set_profile(ModLoaderConfig.DEFAULT_CONFIG_NAME):
7189
info_text.text = text_profile_select_error
7290
return
7391
# Delete the profile
@@ -93,7 +111,17 @@ func _on_ButtonProfileNameSubmit_pressed() -> void:
93111
popup_new_profile.hide()
94112

95113

96-
func _mod_is_active_changed(mod_id: String, is_active: bool) -> void:
114+
func _on_ProfileSelect_item_selected(index: int) -> void:
115+
if not ModLoaderUserProfile.set_profile(profile_select.get_item_text(index)):
116+
info_text.text = text_profile_select_error
117+
return
118+
119+
_update_ui()
120+
121+
info_text.text = text_restart
122+
123+
124+
func _on_ModList_mod_is_active_changed(mod_id: String, is_active: bool) -> void:
97125
if is_active:
98126
if not ModLoaderUserProfile.enable_mod(mod_id):
99127
info_text.text = text_mod_enable_error
@@ -106,11 +134,14 @@ func _mod_is_active_changed(mod_id: String, is_active: bool) -> void:
106134
info_text.text = text_restart
107135

108136

109-
func _on_ProfileSelect_item_selected(index: int) -> void:
110-
if not ModLoaderUserProfile.set_profile(profile_select.get_item_text(index)):
111-
info_text.text = text_profile_select_error
112-
return
137+
func _on_ModList_mod_current_config_changed(mod_id: String, current_config_name: String):
138+
var config := ModLoaderConfig.get_config(mod_id, current_config_name)
113139

114-
_update_ui()
140+
if not config:
141+
info_text.text = text_mod_current_config_change_error
115142

116-
info_text.text = text_restart
143+
ModLoaderConfig.set_current_config(config)
144+
145+
146+
func _on_ModLoader_current_config_changed(config: ModConfig) -> void:
147+
_update_ui()

0 commit comments

Comments
 (0)