Skip to content

Commit d2d2403

Browse files
committed
feat: ✨ added current_config
1 parent dfa01bb commit d2d2403

File tree

12 files changed

+203
-171
lines changed

12 files changed

+203
-171
lines changed

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

Lines changed: 60 additions & 29 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(String) var section_name := "" setget _set_section_name
7+
export(PackedScene) var mod_id_label_scene
8+
export(PackedScene) var is_active_toggle_scene
9+
export(PackedScene) var current_config_select_scene
810

9-
onready var label_section_name := $"%SectionName"
10-
onready var mod_list = $"%ModLists"
11+
var grid_placeholder := Control
1112

13+
onready var grid = $"%Grid"
1214

13-
func _set_section_name(new_name: String) -> void:
14-
section_name = new_name
15-
if label_section_name:
16-
label_section_name.text = new_name
1715

18-
19-
func generate_mod_list(user_profile: ModLoaderUserProfile.Profile) -> void:
16+
func generate_grid(user_profile: ModLoaderUserProfile.Profile) -> void:
2017
for mod_id in user_profile.mod_list.keys():
21-
var new_mod_list_mod: HBoxContainer = mod_list_mod.instance()
18+
_generate_mod_name(mod_id)
19+
_generate_mod_active_state(mod_id, user_profile)
20+
if 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())
24+
25+
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()
2237

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].is_active
38+
# Check if the mod is loadable
39+
if not mod.is_loadable:
40+
label_mod_id.set_error_color()
2741

28-
if ModLoaderStore.mod_data.has(mod_id):
29-
var mod: ModData = ModLoaderStore.mod_data[mod_id]
3042

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()
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")
3649

37-
# Check if the mod is loadable
38-
if not mod.is_loadable:
39-
new_mod_list_mod.set_error_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
4056

4157

42-
func clear_mod_list() -> void:
43-
for child in mod_list.get_children():
44-
mod_list.remove_child(child)
45-
child.free()
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.free()
72+
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="ModLists" 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 & 59 deletions
This file was deleted.

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

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

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export(String) var text_profile_select_error := "There was an error selecting th
88
export(String) var text_profile_delete_error := "There was an error deleting the profile - check logs"
99
export(String) var text_mod_enable_error := "There was an error enabling the mod - check logs"
1010
export(String) var text_mod_disable_error := "There was an error disabling the mod - check logs"
11+
export(String) var text_mod_current_config_change_error := "There was an error changing the config - check logs"
1112
export(String) var text_current_profile := " (Current Profile)"
1213

1314
onready var user_profile_sections := $"%UserProfileSections"
@@ -57,9 +58,8 @@ func _populate_profile_select() -> void:
5758

5859
func _generate_user_profile_section() -> void:
5960
for section in user_profile_sections.get_children():
60-
section.section_name = section.section_name
61-
section.clear_mod_list()
62-
section.generate_mod_list(ModLoaderUserProfile.get_current())
61+
section.clear_grid()
62+
section.generate_grid(ModLoaderUserProfile.get_current())
6363

6464

6565
func _on_ButtonNewProfile_pressed() -> void:
@@ -95,7 +95,17 @@ func _on_ButtonProfileNameSubmit_pressed() -> void:
9595
popup_new_profile.hide()
9696

9797

98-
func _mod_is_active_changed(mod_id: String, is_active: bool) -> void:
98+
func _on_ProfileSelect_item_selected(index: int) -> void:
99+
if not ModLoaderUserProfile.set_profile(profile_select.get_item_text(index)):
100+
info_text.text = text_profile_select_error
101+
return
102+
103+
_update_ui()
104+
105+
info_text.text = text_restart
106+
107+
108+
func _on_ModList_mod_is_active_changed(mod_id: String, is_active: bool) -> void:
99109
if is_active:
100110
if not ModLoaderUserProfile.enable_mod(mod_id):
101111
info_text.text = text_mod_enable_error
@@ -108,11 +118,8 @@ func _mod_is_active_changed(mod_id: String, is_active: bool) -> void:
108118
info_text.text = text_restart
109119

110120

111-
func _on_ProfileSelect_item_selected(index: int) -> void:
112-
if not ModLoaderUserProfile.set_profile(profile_select.get_item_text(index)):
113-
info_text.text = text_profile_select_error
114-
return
115-
116-
_update_ui()
121+
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)
117123

118-
info_text.text = text_restart
124+
if not is_success:
125+
info_text.text = text_mod_current_config_change_error

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

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ anchor_right = 0.5
3636
anchor_bottom = 0.5
3737
margin_left = -350.0
3838
margin_top = -400.0
39-
margin_right = 150.0
39+
margin_right = 400.0
4040
margin_bottom = 200.0
4141
custom_icons/close_highlight = SubResource( 4 )
4242
custom_icons/close = SubResource( 3 )
@@ -55,7 +55,7 @@ custom_constants/margin_bottom = 20
5555
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
5656
margin_left = 20.0
5757
margin_top = 20.0
58-
margin_right = 480.0
58+
margin_right = 730.0
5959
margin_bottom = 580.0
6060

6161
[node name="LabelSelectProfile" type="Label" parent="MarginContainer/VBoxContainer"]
@@ -126,24 +126,6 @@ size_flags_horizontal = 3
126126
size_flags_vertical = 3
127127

128128
[node name="ModList" parent="MarginContainer/VBoxContainer/ProfileSettings/ScrollContainer/VBoxContainer/UserProfileSections" instance=ExtResource( 3 )]
129-
unique_name_in_owner = true
130-
margin_left = 0.0
131-
margin_top = 0.0
132-
margin_right = 460.0
133-
margin_bottom = 43.0
134-
section_name = "Active Mods"
135-
136-
[node name="VBoxContainer" parent="MarginContainer/VBoxContainer/ProfileSettings/ScrollContainer/VBoxContainer/UserProfileSections/ModList" index="0"]
137-
margin_right = 460.0
138-
margin_bottom = 33.0
139-
140-
[node name="ModList2" parent="MarginContainer/VBoxContainer/ProfileSettings/ScrollContainer/VBoxContainer/UserProfileSections" instance=ExtResource( 3 )]
141-
unique_name_in_owner = true
142-
margin_left = 0.0
143-
margin_top = 0.0
144-
margin_right = 460.0
145-
margin_bottom = 43.0
146-
section_name = "Mod Configs"
147129

148130
[node name="InfoText" type="Label" parent="MarginContainer/VBoxContainer"]
149131
unique_name_in_owner = true
@@ -216,6 +198,6 @@ text = "OK"
216198
[connection signal="item_selected" from="MarginContainer/VBoxContainer/ProfileSelection/ProfileSelect" to="." method="_on_ProfileSelect_item_selected"]
217199
[connection signal="pressed" from="MarginContainer/VBoxContainer/ProfileSelection/ButtonNewProfile" to="." method="_on_ButtonNewProfile_pressed"]
218200
[connection signal="pressed" from="MarginContainer/VBoxContainer/ProfileSelection/ButtonDeleteProfile" to="." method="_on_ButtonDeleteProfile_pressed"]
201+
[connection signal="mod_current_config_changed" from="MarginContainer/VBoxContainer/ProfileSettings/ScrollContainer/VBoxContainer/UserProfileSections/ModList" to="." method="_on_ModList_mod_current_config_changed"]
202+
[connection signal="mod_is_active_changed" from="MarginContainer/VBoxContainer/ProfileSettings/ScrollContainer/VBoxContainer/UserProfileSections/ModList" to="." method="_on_ModList_mod_is_active_changed"]
219203
[connection signal="pressed" from="PopupNewProfile/MarginContainer/VBoxContainer/VBoxContainer/ButtonProfileNameSubmit" to="." method="_on_ButtonProfileNameSubmit_pressed"]
220-
221-
[editable path="MarginContainer/VBoxContainer/ProfileSettings/ScrollContainer/VBoxContainer/UserProfileSections/ModList"]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class_name CurrentConfigSelect
2+
extends OptionButton
3+
4+
5+
signal current_config_selected(mod_id, config_name)
6+
7+
var mod_id: String
8+
var config_names := {}
9+
10+
11+
func add_mod_configs(mod_configs: Array) -> void:
12+
var index := 0
13+
for config in mod_configs:
14+
config_names[config.name] = index
15+
self.add_item(config.name)
16+
index = index + 1
17+
18+
19+
func select_item(item_text: String) -> void:
20+
self.select(config_names[item_text])
21+
22+
23+
func _on_CurrentConfigSelect_item_selected(index) -> void:
24+
emit_signal("current_config_selected", mod_id, self.get_item_text(index))

0 commit comments

Comments
 (0)