Skip to content

Commit ca2be8d

Browse files
authored
feat: ✨ added rename button (#5)
1 parent 1e4fcb7 commit ca2be8d

File tree

1 file changed

+45
-14
lines changed

1 file changed

+45
-14
lines changed

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

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
extends WindowDialog
22

3-
43
export(PackedScene) var user_profile_section: PackedScene
54
export(String) var text_select_profile := "Select Profile"
65
export(String) var text_restart := "A game restart is required to apply the settings"
76
export(String) var text_profile_create_error := "There was an error creating the profile - check logs"
7+
export(String) var text_profile_rename_error := "There was an error renaming the profile - check logs"
88
export(String) var text_profile_select_error := "There was an error selecting the profile - check logs"
99
export(String) var text_profile_delete_error := "There was an error deleting the profile - check logs"
1010
export(String) var text_mod_enable_error := "There was an error enabling the mod - check logs"
@@ -16,16 +16,22 @@ onready var label_select_profile: Label = $"%LabelSelectProfile"
1616
onready var user_profile_sections := $"%UserProfileSections"
1717
onready var profile_select = $"%ProfileSelect"
1818
onready var popup_new_profile = $"%PopupNewProfile"
19+
onready var popup_rename_profile: WindowDialog = $"%PopupRenameProfile"
1920
onready var input_profile_name = $"%InputProfileName"
2021
onready var button_profile_name_submit = $"%ButtonProfileNameSubmit"
2122
onready var button_new_profile = $"%ButtonNewProfile"
2223
onready var info_text = $"%InfoText"
24+
onready var input_rename_profile_name: LineEdit = $"%InputRenameProfileName"
25+
26+
var profile_selected: ModUserProfile
2327

2428

2529
func _ready() -> void:
2630
_populate_profile_select()
2731
_generate_user_profile_section()
2832

33+
profile_selected = ModLoaderUserProfile.get_current()
34+
2935
ModLoader.connect("current_config_changed", self, "_on_ModLoader_current_config_changed")
3036

3137

@@ -61,8 +67,14 @@ func _populate_profile_select() -> void:
6167
profile_select.clear()
6268

6369
for user_profile in ModLoaderUserProfile.get_all_as_array():
64-
var is_current_profile := true if ModLoaderUserProfile.get_current().name == user_profile.name else false
65-
profile_select.add_item(user_profile.name + text_current_profile if is_current_profile else user_profile.name)
70+
var is_current_profile := (
71+
true
72+
if ModLoaderUserProfile.get_current().name == user_profile.name
73+
else false
74+
)
75+
profile_select.add_item(
76+
user_profile.name + text_current_profile if is_current_profile else user_profile.name
77+
)
6678

6779
# Get the item index of the current profile
6880
if is_current_profile:
@@ -95,20 +107,37 @@ func _on_ButtonDeleteProfile_pressed():
95107

96108
_update_ui()
97109

110+
profile_selected = ModLoaderUserProfile.get_current()
111+
112+
113+
func _on_ButtonRename_pressed() -> void:
114+
popup_rename_profile.popup_centered()
98115

99-
func _on_ButtonProfileNameSubmit_pressed() -> void:
100-
# Create new User Profile
101-
if not ModLoaderUserProfile.create_profile(input_profile_name.text):
102-
# If there was an error creating the profile
103-
# Add error message to the info text label
104-
info_text.text = text_profile_create_error
105-
# And return early
106-
return
116+
117+
func _on_ButtonProfileNameSubmit_pressed(is_rename: bool) -> void:
118+
if is_rename:
119+
var success := ModLoaderUserProfile.rename_profile(
120+
profile_selected.name, input_rename_profile_name.text
121+
)
122+
if not success:
123+
info_text.text = text_profile_rename_error
124+
return
125+
# Close popup
126+
popup_rename_profile.hide()
127+
else:
128+
# Create new User Profile
129+
if not ModLoaderUserProfile.create_profile(input_profile_name.text):
130+
# If there was an error creating the profile
131+
# Add error message to the info text label
132+
info_text.text = text_profile_create_error
133+
# And return early
134+
return
135+
# Close popup
136+
popup_new_profile.hide()
107137

108138
_update_ui()
109139

110-
# Close popup
111-
popup_new_profile.hide()
140+
profile_selected = ModLoaderUserProfile.get_current()
112141

113142

114143
func _on_ProfileSelect_item_selected(index: int) -> void:
@@ -117,12 +146,14 @@ func _on_ProfileSelect_item_selected(index: int) -> void:
117146
info_text.text = text_profile_select_error
118147
return
119148

149+
profile_selected = user_profile
150+
120151
_update_ui()
121152

122153
info_text.text = text_restart
123154

124155

125-
func _on_ModList_mod_is_active_changed(mod_id: String, is_active: bool) -> void:
156+
func _on_ModList_mod_is_active_changed(mod_id: String, is_active: bool) -> void:
126157
if is_active:
127158
if not ModLoaderUserProfile.enable_mod(mod_id):
128159
info_text.text = text_mod_enable_error

0 commit comments

Comments
 (0)