Skip to content

Commit

Permalink
Merge pull request #46 from the-furry-hubofeverything/fileDialog
Browse files Browse the repository at this point in the history
Add filedialog option to lineEdit in mods
  • Loading branch information
ExpiredPopsicle authored Nov 29, 2024
2 parents 1b68f61 + 096d899 commit cc29b36
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Core/UI/UI_Root.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ file_mode = 0
access = 2
filters = PackedStringArray("*.vrm")

[node name="LineEditFileDialog" type="FileDialog" parent="."]
title = "Open a File"
ok_button_text = "Open"
file_mode = 0
access = 2

[node name="ModsWindow" parent="." instance=ExtResource("2_v48gv")]
visible = false
offset_left = 247.0
Expand Down
29 changes: 26 additions & 3 deletions Mods/Base/Mod_Base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ func add_tracked_setting(setting_name, label_text, extra_args={}):
if prop_val is String:
settings_window_add_lineedit(
new_setting_prop["label"], new_setting_prop["name"],
new_setting_prop["args"].get("is_redeem", false))
new_setting_prop["args"].get("is_redeem", false),
new_setting_prop["args"].get("is_fileaccess", false))

elif prop_val is bool:
settings_window_add_boolean(new_setting_prop["label"], new_setting_prop["name"])
Expand Down Expand Up @@ -178,6 +179,21 @@ func _test_redeem_with_settings_value(prop_name, local=true):
get_app()._on_handle_channel_points_redeem(
"testuser", "TestUser", prop_val, "Test input")

func _get_file_path(prop_name, widget: LineEdit, filter: PackedStringArray):
var prop_val = get(prop_name)
var file_dialog = get_app()._get_ui_root().get_node("LineEditFileDialog")

# Set the file format filter
file_dialog.set_filters(filter)
file_dialog.popup()

prop_val = await file_dialog.file_selected
modify_setting(prop_name, prop_val)
widget.set_text(prop_val)

# clear filter
file_dialog.clear_filters()

# Pull settings from app and update UI widgets to reflect them.
#
# Default version here. Can be overridden.
Expand Down Expand Up @@ -408,7 +424,7 @@ func settings_window_add_spinbox(
window.add_child(spinbox_widget)
_settings_widgets_by_setting_name[setting_name] = spinbox_widget

func settings_window_add_lineedit(setting_label, setting_name, is_redeem=false):
func settings_window_add_lineedit(setting_label, setting_name, is_redeem=false, is_fileaccess=false, file_filters: PackedStringArray = []):

# This only works with the default-created settings window widget.
var window : GridContainer = get_settings_window()
Expand All @@ -429,7 +445,14 @@ func settings_window_add_lineedit(setting_label, setting_name, is_redeem=false):
setting_name,
new_text))
group_widget.add_child(lineedit_widget)


if is_fileaccess:
var dialog_button : Button = Button.new()
dialog_button.text = "..."
dialog_button.tooltip_text = "Open File"
group_widget.add_child(dialog_button)
dialog_button.button_down.connect(_get_file_path.bind(setting_name, lineedit_widget, file_filters))

if is_redeem:
var test_button : Button = Button.new()
test_button.text = "Test This"
Expand Down

0 comments on commit cc29b36

Please sign in to comment.