Skip to content

feat: ✨ added current_config #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 59 additions & 28 deletions root/mods-unpacked/GodotModding-UserProfile/content/ModList.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,78 @@ extends MarginContainer


signal mod_is_active_changed(mod_id, is_active)
signal mod_current_config_changed(mod_id, current_config)

export(PackedScene) var mod_list_mod
export(PackedScene) var mod_id_label_scene
export(PackedScene) var is_active_toggle_scene
export(PackedScene) var current_config_select_scene

var section_name := "" setget _set_section_name
var grid_placeholder := Control

onready var user_profile_name := $"%SectionName"
onready var mod_list = $"%ModList"
onready var grid = $"%Grid"


func _set_section_name(new_name: String) -> void:
section_name = new_name
user_profile_name.text = new_name
func generate_grid(user_profile: ModLoaderUserProfile.Profile) -> void:
for mod_id in user_profile.mod_list.keys():
_generate_mod_name(mod_id)
_generate_mod_active_state(mod_id, user_profile)
if ModLoaderStore.mod_data.has(mod_id) and not ModLoaderStore.mod_data[mod_id].configs.empty():
_generate_mod_current_config(mod_id, user_profile)
else:
grid.add_child(grid_placeholder.new())


func generate_mod_list(user_profile: ModLoaderUserProfile.Profile) -> void:
for mod_id in user_profile.mod_list.keys():
var new_mod_list_mod: HBoxContainer = mod_list_mod.instance()
func _generate_mod_name(mod_id: String) -> void:
var label_mod_id: ModIdLabel = mod_id_label_scene.instance()
grid.add_child(label_mod_id)
label_mod_id.text = mod_id

if ModLoaderStore.mod_data.has(mod_id):
var mod: ModData = ModLoaderStore.mod_data[mod_id]

# Check if mod is locked
if mod.is_locked:
label_mod_id.set_mandatory_color()

# Check if the mod is loadable
if not mod.is_loadable:
label_mod_id.set_error_color()

new_mod_list_mod.connect("is_active_toggled", self, "_on_mod_is_active_toggled")
mod_list.add_child(new_mod_list_mod)
new_mod_list_mod.mod_id = mod_id
new_mod_list_mod.is_active = user_profile.mod_list[mod_id]

if ModLoaderStore.mod_data.has(mod_id):
var mod: ModData = ModLoaderStore.mod_data[mod_id]
func _generate_mod_active_state(mod_id: String, user_profile: ModLoaderUserProfile.Profile) -> void:
var is_active_toggle: IsActiveToggle = is_active_toggle_scene.instance()
grid.add_child(is_active_toggle)
is_active_toggle.mod_id = mod_id
is_active_toggle.is_active = user_profile.mod_list[mod_id].is_active
is_active_toggle.connect("is_active_toggled", self, "_on_mod_is_active_toggled")

# Check if mod is locked
if mod.is_locked:
# Disable the checkbox if it is
new_mod_list_mod.is_disabled = true
new_mod_list_mod.set_mandatory_color()
if ModLoaderStore.mod_data.has(mod_id):
var mod: ModData = ModLoaderStore.mod_data[mod_id]
# Check if mod is locked
if mod.is_locked:
# Disable the checkbox if it is
is_active_toggle.disabled = true

# Check if the mod is loadable
if not mod.is_loadable:
new_mod_list_mod.set_error_color()

func _generate_mod_current_config(mod_id: String, user_profile: ModLoaderUserProfile.Profile) -> void:
var current_config_select: CurrentConfigSelect = current_config_select_scene.instance()
grid.add_child(current_config_select)
current_config_select.mod_id = mod_id
current_config_select.add_mod_configs(ModLoaderStore.mod_data[mod_id].configs)
current_config_select.select_item(user_profile.mod_list[mod_id].current_config)
current_config_select.connect("current_config_selected", self, "_on_current_config_selected")


func clear_grid() -> void:
for child in grid.get_children():
if not child is Label or child is ModIdLabel:
grid.remove_child(child)
child.queue_free()

func clear_mod_list() -> void:
for child in mod_list.get_children():
mod_list.remove_child(child)
child.free()

func _on_mod_is_active_toggled(mod_id: String, is_active: bool) -> void:
emit_signal("mod_is_active_changed", mod_id, is_active)


func _on_current_config_selected(mod_id: String, config_name: String) -> void:
emit_signal("mod_current_config_changed", mod_id, config_name)
40 changes: 28 additions & 12 deletions root/mods-unpacked/GodotModding-UserProfile/content/ModList.tscn
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=6 format=2]

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

[node name="ModList" type="MarginContainer"]
margin_left = 20.0
Expand All @@ -12,23 +14,37 @@ margin_bottom = 1060.0
custom_constants/margin_top = 10
custom_constants/margin_bottom = 10
script = ExtResource( 1 )
mod_list_mod = ExtResource( 2 )
mod_id_label_scene = ExtResource( 5 )
is_active_toggle_scene = ExtResource( 2 )
current_config_select_scene = ExtResource( 4 )

[node name="VBoxContainer" type="VBoxContainer" parent="."]
[node name="Grid" type="GridContainer" parent="."]
unique_name_in_owner = true
margin_top = 10.0
margin_right = 1880.0
margin_bottom = 1030.0
custom_constants/hseparation = 50
columns = 3

[node name="SectionName" type="Label" parent="VBoxContainer"]
[node name="LabelModName" type="Label" parent="Grid"]
unique_name_in_owner = true
margin_right = 1880.0
margin_right = 72.0
margin_bottom = 19.0
custom_fonts/font = ExtResource( 3 )
text = "Active Mods"
text = "Mod Name"

[node name="ModList" type="VBoxContainer" parent="VBoxContainer"]
[node name="LabelActiveState" type="Label" parent="Grid"]
unique_name_in_owner = true
margin_top = 23.0
margin_right = 1880.0
margin_bottom = 23.0
size_flags_horizontal = 3
margin_left = 122.0
margin_right = 176.0
margin_bottom = 19.0
custom_fonts/font = ExtResource( 3 )
text = "active"

[node name="LabelCurrentConfig" type="Label" parent="Grid"]
unique_name_in_owner = true
margin_left = 226.0
margin_right = 352.0
margin_bottom = 19.0
custom_fonts/font = ExtResource( 3 )
text = "current config"
49 changes: 0 additions & 49 deletions root/mods-unpacked/GodotModding-UserProfile/content/ModListMod.gd

This file was deleted.

This file was deleted.

53 changes: 42 additions & 11 deletions root/mods-unpacked/GodotModding-UserProfile/content/UserProfiles.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,59 @@ extends WindowDialog


export(PackedScene) var user_profile_section: PackedScene
export(String) var text_select_profile := "Select Profile"
export(String) var text_restart := "A game restart is required to apply the settings"
export(String) var text_profile_create_error := "There was an error creating the profile - check logs"
export(String) var text_profile_select_error := "There was an error selecting the profile - check logs"
export(String) var text_profile_delete_error := "There was an error deleting the profile - check logs"
export(String) var text_mod_enable_error := "There was an error enabling the mod - check logs"
export(String) var text_mod_disable_error := "There was an error disabling the mod - check logs"
export(String) var text_mod_current_config_change_error := "There was an error changing the config - check logs"
export(String) var text_current_profile := " (Current Profile)"

onready var label_select_profile: Label = $"%LabelSelectProfile"
onready var user_profile_sections := $"%UserProfileSections"
onready var profile_select = $"%ProfileSelect"
onready var popup_new_profile = $"%PopupNewProfile"
onready var input_profile_name = $"%InputProfileName"
onready var button_profile_name_submit = $"%ButtonProfileNameSubmit"
onready var button_new_profile = $"%ButtonNewProfile"
onready var mod_list = $"%ModList"
onready var info_text = $"%InfoText"


func _ready() -> void:
_populate_profile_select()
_generate_user_profile_section()

ModLoader.connect("current_config_changed", self, "_on_ModLoader_current_config_changed")


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


func apply_config(config: ModConfig) -> void:
label_select_profile.text = config.data.select_profile_text

var material_settings: Dictionary = config.data.material_settings

material.set_shader_param("animate", material_settings.animate)
material.set_shader_param("square_scale", material_settings.square_scale)
material.set_shader_param("blur_amount", material_settings.blur_amount)
material.set_shader_param("mix_amount", material_settings.mix_amount)
material.set_shader_param("color_over", Color(material_settings.color))


func _update_ui() -> void:
# Update the profile select list
_populate_profile_select()

# Update the Setting list
_generate_user_profile_section()


func _populate_profile_select() -> void:
var index_current_profile: int

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


func _generate_user_profile_section() -> void:
mod_list.clear_mod_list()
mod_list.generate_mod_list(ModLoaderUserProfile.get_current())
for section in user_profile_sections.get_children():
section.clear_grid()
section.generate_grid(ModLoaderUserProfile.get_current())


func _on_ButtonNewProfile_pressed() -> void:
Expand All @@ -67,7 +85,7 @@ func _on_ButtonNewProfile_pressed() -> void:
func _on_ButtonDeleteProfile_pressed():
var profile_to_delete := ModLoaderStore.current_user_profile
# Switch to default profile
if not ModLoaderUserProfile.set_profile("default"):
if not ModLoaderUserProfile.set_profile(ModLoaderConfig.DEFAULT_CONFIG_NAME):
info_text.text = text_profile_select_error
return
# Delete the profile
Expand All @@ -93,7 +111,17 @@ func _on_ButtonProfileNameSubmit_pressed() -> void:
popup_new_profile.hide()


func _mod_is_active_changed(mod_id: String, is_active: bool) -> void:
func _on_ProfileSelect_item_selected(index: int) -> void:
if not ModLoaderUserProfile.set_profile(profile_select.get_item_text(index)):
info_text.text = text_profile_select_error
return

_update_ui()

info_text.text = text_restart


func _on_ModList_mod_is_active_changed(mod_id: String, is_active: bool) -> void:
if is_active:
if not ModLoaderUserProfile.enable_mod(mod_id):
info_text.text = text_mod_enable_error
Expand All @@ -106,11 +134,14 @@ func _mod_is_active_changed(mod_id: String, is_active: bool) -> void:
info_text.text = text_restart


func _on_ProfileSelect_item_selected(index: int) -> void:
if not ModLoaderUserProfile.set_profile(profile_select.get_item_text(index)):
info_text.text = text_profile_select_error
return
func _on_ModList_mod_current_config_changed(mod_id: String, current_config_name: String):
var config := ModLoaderConfig.get_config(mod_id, current_config_name)

_update_ui()
if not config:
info_text.text = text_mod_current_config_change_error

info_text.text = text_restart
ModLoaderConfig.set_current_config(config)


func _on_ModLoader_current_config_changed(config: ModConfig) -> void:
_update_ui()
Loading