Skip to content

Commit

Permalink
Fix many bugs (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
MewPurPur authored Aug 20, 2024
1 parent b8697d2 commit fe7d43b
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 24 deletions.
5 changes: 5 additions & 0 deletions src/autoload/GlobalSettings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ func save() -> void:
ResourceSaver.save(savedata, savedata_path)


var default_keybinds := {}

func _enter_tree() -> void:
for action in InputMap.get_actions():
if action in ShortcutUtils.get_all_keybinds():
default_keybinds[action] = InputMap.action_get_events(action)
load_config()
load_svg_text()
ThemeGenerator.generate_and_apply_theme()
Expand Down
5 changes: 0 additions & 5 deletions src/config_classes/SaveData.gd
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,3 @@ const GoodColorPicker = preload("res://src/ui_widgets/good_color_picker.gd")
@export var formatters: Array[Formatter] = []
@export var editor_formatter: Formatter = null
@export var export_formatter: Formatter = null

func _init() -> void:
for action in InputMap.get_actions():
if action in ShortcutUtils.get_all_keybinds():
keybinds[action] = InputMap.action_get_events(action)
6 changes: 3 additions & 3 deletions src/ui_parts/display.gd
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ func set_snap_amount(snap_value: float) -> void:
snapper.set_value(snap_value)

func _on_snap_button_toggled(toggled_on: bool) -> void:
GlobalSettings.savedata.snap = absf(GlobalSettings.savedata.snap) if toggled_on\
else -absf(GlobalSettings.savedata.snap)
GlobalSettings.modify_setting("snap", absf(GlobalSettings.savedata.snap) if toggled_on\
else -absf(GlobalSettings.savedata.snap))

func _on_snap_number_edit_value_changed(new_value: float) -> void:
GlobalSettings.savedata.snap = new_value * signf(GlobalSettings.savedata.snap)
GlobalSettings.modify_setting("snap", new_value * signf(GlobalSettings.savedata.snap))

# The strings here are intentionally not localized.
func update_debug() -> void:
Expand Down
2 changes: 1 addition & 1 deletion src/ui_parts/good_file_dialog.gd
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func _on_drives_list_item_selected(index: int) -> void:
call_selection_action(drives_list.get_item_metadata(index))

func _on_show_hidden_button_toggled(toggled_on: bool) -> void:
GlobalSettings.savedata.file_dialog_show_hidden = toggled_on
GlobalSettings.modify_setting("file_dialog_show_hidden", toggled_on)
refresh_dir()

func _on_search_button_toggled(toggled_on: bool) -> void:
Expand Down
5 changes: 3 additions & 2 deletions src/ui_widgets/ContextPopup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ start_pressed: bool, shortcut := "") -> CheckBox:
ret_button.focus_mode = Control.FOCUS_NONE
ret_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
ret_button.shortcut_in_tooltip = false
checkbox.add_theme_stylebox_override("normal",
checkbox.get_theme_stylebox("normal", "ContextButton"))
for theme_stylebox in ["normal", "pressed"]:
checkbox.add_theme_stylebox_override(theme_stylebox,
checkbox.get_theme_stylebox("normal", "ContextButton"))
var internal_hbox := HBoxContainer.new()
checkbox.mouse_filter = Control.MOUSE_FILTER_IGNORE # Unpressable.
internal_hbox.add_theme_constant_override("separation", 6)
Expand Down
2 changes: 1 addition & 1 deletion src/ui_widgets/good_color_picker.gd
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func _on_hsv_pressed() -> void:

func change_slider_mode(new_slider_mode: SliderMode) -> void:
slider_mode = new_slider_mode
GlobalSettings.savedata.color_picker_slider_mode = new_slider_mode
GlobalSettings.modify_setting("color_picker_slider_mode", new_slider_mode)


# Gray out the start color rect if it's not actually a color.
Expand Down
2 changes: 1 addition & 1 deletion src/ui_widgets/path_popup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func emit_picked(cmd_char: String) -> void:
queue_free()

func _on_relative_toggle_toggled(toggled_on: bool) -> void:
GlobalSettings.savedata.path_command_relative = toggled_on
GlobalSettings.savedata.modify_setting("path_command_relative", toggled_on)
for command_button in command_container.get_children():
command_button.command_char = command_button.command_char.to_lower() if toggled_on\
else command_button.command_char.to_upper()
Expand Down
10 changes: 7 additions & 3 deletions src/ui_widgets/setting_shortcut.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ var events: Array[InputEvent] = []

var listening_idx := -1

func _ready() -> void:
func update_translation() -> void:
reset_button.tooltip_text = TranslationServer.translate("Reset to default")

func _ready() -> void:
GlobalSettings.language_changed.connect(update_translation)
update_translation()

func setup(new_action: String) -> void:
action = new_action
events = InputMap.action_get_events(action)
Expand All @@ -23,7 +27,7 @@ func setup(new_action: String) -> void:
# Syncs based on current events.
func sync() -> void:
# Show the reset button if any of the actions don't match.
var action_defaults: Array[InputEvent] = GlobalSettings.savedata.keybinds[action]
var action_defaults: Array[InputEvent] = GlobalSettings.default_keybinds[action]
if events.size() != action_defaults.size():
reset_button.show()
else:
Expand Down Expand Up @@ -146,6 +150,6 @@ func _input(event: InputEvent) -> void:
listening_idx = -1

func _on_reset_button_pressed() -> void:
events = GlobalSettings.savedata.keybinds[action].duplicate(true)
events = GlobalSettings.default_keybinds[action].duplicate(true)
update_shortcut()
sync()
12 changes: 6 additions & 6 deletions src/utils/FileUtils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ static func does_svg_data_match_disk_contents() -> bool:


static func finish_import(svg_text: String, file_path: String) -> void:
GlobalSettings.savedata.current_file_path = file_path
GlobalSettings.modify_setting("current_file_path", file_path)
SVG.apply_svg_text(svg_text)

static func finish_export(file_path: String, extension: String, upscale_amount := 1.0,
quality := 0.8, lossless := true) -> void:
if file_path.get_extension().is_empty():
file_path += "." + extension

GlobalSettings.savedata.last_used_dir = file_path.get_base_dir()
GlobalSettings.modify_setting("last_used_dir", file_path.get_base_dir())

match extension:
"png": generate_image_from_elements(upscale_amount).save_png(file_path)
Expand All @@ -37,7 +37,7 @@ quality := 0.8, lossless := true) -> void:
quality)
_:
# SVG / fallback.
GlobalSettings.savedata.current_file_path = file_path
GlobalSettings.modify_setting("current_file_path", file_path)
save_svg_to_file(file_path)
HandlerGUI.remove_overlay()

Expand Down Expand Up @@ -90,8 +90,8 @@ _filter_idx: int, extension: String, upscale_amount := 1.0) -> void:
static func native_file_save(has_selected: bool, files: PackedStringArray,
_filter_idx: int) -> void:
if has_selected:
GlobalSettings.savedata.current_file_path = files[0]
GlobalSettings.savedata.last_used_dir = files[0].get_base_dir()
GlobalSettings.modify_setting("current_file_path", files[0])
GlobalSettings.modify_setting("last_used_dir", files[0].get_base_dir())
save_svg_to_file(files[0])


Expand Down Expand Up @@ -152,7 +152,7 @@ static func apply_svg_from_path(path: String) -> int:
var error := ""
var extension := path.get_extension()

GlobalSettings.savedata.last_used_dir = path.get_base_dir()
GlobalSettings.modify_setting("last_used_dir", path.get_base_dir())

if extension.is_empty():
error = TranslationServer.translate(
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ShortcutUtils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static func fn(shortcut: String) -> Callable:
"clear_svg": return SVG.apply_svg_text.bind(SVG.DEFAULT)
"optimize": return SVG.optimize
"clear_file_path": return GlobalSettings.modify_setting.bind(
"session", "current_file_path", "")
"current_file_path", "")
"reset_svg": return FileUtils.apply_svg_from_path.bind(
GlobalSettings.savedata.current_file_path)
"redo": return SVG.redo
Expand Down
2 changes: 1 addition & 1 deletion visual/icons/element/radialGradient.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fe7d43b

Please sign in to comment.