Skip to content

Commit

Permalink
Move custom settings away from Keychain.gd
Browse files Browse the repository at this point in the history
To keep it the same as the upstream plugin
  • Loading branch information
OverloadedOrama committed May 12, 2022
1 parent 464e459 commit 37e0d38
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 81 deletions.
86 changes: 5 additions & 81 deletions addons/keychain/Keychain.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,82 +6,15 @@ var selected_preset: Preset = presets[0]
var preset_index := 0
# Syntax: "action_name": InputAction.new("Action Display Name", "Group", true)
# Note that "action_name" must already exist in the Project's Input Map.
var actions := {
"new_file": MenuInputAction.new("", "File Menu", true, "FileMenu", Global.FileMenuId.NEW),
"open_file": MenuInputAction.new("", "File Menu", true, "FileMenu", Global.FileMenuId.OPEN),
"save_file": MenuInputAction.new("", "File Menu", true, "FileMenu", Global.FileMenuId.SAVE),
"save_file_as":
MenuInputAction.new("", "File Menu", true, "FileMenu", Global.FileMenuId.SAVE_AS),
"export_file": MenuInputAction.new("", "File Menu", true, "FileMenu", Global.FileMenuId.EXPORT),
"export_file_as":
MenuInputAction.new("", "File Menu", true, "FileMenu", Global.FileMenuId.EXPORT_AS),
"quit": MenuInputAction.new("", "File Menu", true, "FileMenu", Global.FileMenuId.QUIT),
"redo": MenuInputAction.new("", "Edit Menu", true, "EditMenu", Global.EditMenuId.REDO, true),
"undo": MenuInputAction.new("", "Edit Menu", true, "EditMenu", Global.EditMenuId.UNDO, true),
"cut": MenuInputAction.new("", "Edit Menu", true, "EditMenu", Global.EditMenuId.CUT),
"copy": MenuInputAction.new("", "Edit Menu", true, "EditMenu", Global.EditMenuId.COPY),
"paste": MenuInputAction.new("", "Edit Menu", true, "EditMenu", Global.EditMenuId.PASTE),
"delete": MenuInputAction.new("", "Edit Menu", true, "EditMenu", Global.EditMenuId.DELETE),
"new_brush":
MenuInputAction.new("", "Edit Menu", true, "EditMenu", Global.EditMenuId.NEW_BRUSH),
"mirror_view":
MenuInputAction.new("", "View Menu", true, "ViewMenu", Global.ViewMenuId.MIRROR_VIEW),
"show_grid":
MenuInputAction.new("", "View Menu", true, "ViewMenu", Global.ViewMenuId.SHOW_GRID),
"show_pixel_grid":
MenuInputAction.new("", "View Menu", true, "ViewMenu", Global.ViewMenuId.SHOW_PIXEL_GRID),
"show_guides":
MenuInputAction.new("", "View Menu", true, "ViewMenu", Global.ViewMenuId.SHOW_GUIDES),
"show_rulers":
MenuInputAction.new("", "View Menu", true, "ViewMenu", Global.ViewMenuId.SHOW_RULERS),
"zen_mode":
MenuInputAction.new("", "Window Menu", true, "WindowMenu", Global.WindowMenuId.ZEN_MODE),
"toggle_fullscreen":
MenuInputAction.new("", "Window Menu", true, "WindowMenu", Global.WindowMenuId.FULLSCREEN_MODE),
"clear_selection":
MenuInputAction.new("", "Select Menu", true, "SelectMenu", Global.SelectMenuId.CLEAR_SELECTION),
"select_all":
MenuInputAction.new("", "Select Menu", true, "SelectMenu", Global.SelectMenuId.SELECT_ALL),
"invert_selection":
MenuInputAction.new("", "Select Menu", true, "SelectMenu", Global.SelectMenuId.INVERT),
"open_docs":
MenuInputAction.new("", "Help Menu", true, "HelpMenu", Global.HelpMenuId.ONLINE_DOCS),
"edit_mode": InputAction.new("Moveable Panels", "Window Menu"),
"zoom_in": InputAction.new("", "General"),
"zoom_out": InputAction.new("", "General"),
"pan": InputAction.new("", "General"),
"confirm": InputAction.new("", "General"),
"cancel": InputAction.new("", "General"),
"switch_colors": InputAction.new("", "Buttons"),
"go_to_first_frame": InputAction.new("", "Buttons"),
"go_to_last_frame": InputAction.new("", "Buttons"),
"go_to_previous_frame": InputAction.new("", "Buttons"),
"go_to_next_frame": InputAction.new("", "Buttons"),
"play_backwards": InputAction.new("", "Buttons"),
"play_forward": InputAction.new("", "Buttons"),
}
var actions := {}
# Syntax: "Group Name": InputGroup.new("Parent Group Name")
var groups := {
"General": InputGroup.new("", false),
"Buttons": InputGroup.new(),
"Tools": InputGroup.new(),
"Left": InputGroup.new("Tools"),
"Right": InputGroup.new("Tools"),
"Menu": InputGroup.new(),
"File Menu": InputGroup.new("Menu"),
"Edit Menu": InputGroup.new("Menu"),
"View Menu": InputGroup.new("Menu"),
"Select Menu": InputGroup.new("Menu"),
"Image Menu": InputGroup.new("Menu"),
"Window Menu": InputGroup.new("Menu"),
"Help Menu": InputGroup.new("Menu"),
}
var ignore_actions := ["left_mouse", "right_mouse", "middle_mouse", "shift", "ctrl", "alt"]
var groups := {}
var ignore_actions := []
var ignore_ui_actions := true
var changeable_types := [true, true, true, false]
var multiple_menu_accelerators := true
var config_path := "user://cache.ini"
var config_file: ConfigFile = Global.config_cache
var config_file: ConfigFile


class Preset:
Expand Down Expand Up @@ -208,14 +141,12 @@ class InputGroup:
folded = _folded


func _init() -> void:
func _ready() -> void:
if !config_file:
config_file = ConfigFile.new()
if !config_path.empty():
config_file.load(config_path)


func _ready() -> void:
set_process_input(multiple_menu_accelerators)
for preset in presets:
preset.load_from_file()
Expand All @@ -227,13 +158,6 @@ func _ready() -> void:
if input_action is MenuInputAction:
input_action.get_node(Global.top_menu_container.get_node("MenuItems"))

for t in Tools.tools: # Code not in the original plugin
var tool_shortcut: String = Tools.tools[t].shortcut
var left_tool_shortcut := "left_%s_tool" % tool_shortcut
var right_tool_shortcut := "right_%s_tool" % tool_shortcut
actions[left_tool_shortcut] = InputAction.new("", "Left")
actions[right_tool_shortcut] = InputAction.new("", "Right")


func _input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
Expand Down
85 changes: 85 additions & 0 deletions src/Autoload/Global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,91 @@ onready var current_version: String = ProjectSettings.get_setting("application/c


func _ready() -> void:
Keychain.config_file = config_cache
Keychain.actions = {
"new_file": Keychain.MenuInputAction.new("", "File Menu", true, "FileMenu", FileMenuId.NEW),
"open_file":
Keychain.MenuInputAction.new("", "File Menu", true, "FileMenu", FileMenuId.OPEN),
"save_file":
Keychain.MenuInputAction.new("", "File Menu", true, "FileMenu", FileMenuId.SAVE),
"save_file_as":
Keychain.MenuInputAction.new("", "File Menu", true, "FileMenu", FileMenuId.SAVE_AS),
"export_file":
Keychain.MenuInputAction.new("", "File Menu", true, "FileMenu", FileMenuId.EXPORT),
"export_file_as":
Keychain.MenuInputAction.new("", "File Menu", true, "FileMenu", FileMenuId.EXPORT_AS),
"quit": Keychain.MenuInputAction.new("", "File Menu", true, "FileMenu", FileMenuId.QUIT),
"redo":
Keychain.MenuInputAction.new("", "Edit Menu", true, "EditMenu", EditMenuId.REDO, true),
"undo":
Keychain.MenuInputAction.new("", "Edit Menu", true, "EditMenu", EditMenuId.UNDO, true),
"cut": Keychain.MenuInputAction.new("", "Edit Menu", true, "EditMenu", EditMenuId.CUT),
"copy": Keychain.MenuInputAction.new("", "Edit Menu", true, "EditMenu", EditMenuId.COPY),
"paste": Keychain.MenuInputAction.new("", "Edit Menu", true, "EditMenu", EditMenuId.PASTE),
"delete":
Keychain.MenuInputAction.new("", "Edit Menu", true, "EditMenu", EditMenuId.DELETE),
"new_brush":
Keychain.MenuInputAction.new("", "Edit Menu", true, "EditMenu", EditMenuId.NEW_BRUSH),
"mirror_view":
Keychain.MenuInputAction.new("", "View Menu", true, "ViewMenu", ViewMenuId.MIRROR_VIEW),
"show_grid":
Keychain.MenuInputAction.new("", "View Menu", true, "ViewMenu", ViewMenuId.SHOW_GRID),
"show_pixel_grid":
Keychain.MenuInputAction.new("", "View Menu", true, "ViewMenu", ViewMenuId.SHOW_PIXEL_GRID),
"show_guides":
Keychain.MenuInputAction.new("", "View Menu", true, "ViewMenu", ViewMenuId.SHOW_GUIDES),
"show_rulers":
Keychain.MenuInputAction.new("", "View Menu", true, "ViewMenu", ViewMenuId.SHOW_RULERS),
"zen_mode":
Keychain.MenuInputAction.new("", "Window Menu", true, "WindowMenu", WindowMenuId.ZEN_MODE),
"toggle_fullscreen":
Keychain.MenuInputAction.new(
"", "Window Menu", true, "WindowMenu", WindowMenuId.FULLSCREEN_MODE
),
"clear_selection":
Keychain.MenuInputAction.new(
"", "Select Menu", true, "SelectMenu", SelectMenuId.CLEAR_SELECTION
),
"select_all":
Keychain.MenuInputAction.new(
"", "Select Menu", true, "SelectMenu", SelectMenuId.SELECT_ALL
),
"invert_selection":
Keychain.MenuInputAction.new("", "Select Menu", true, "SelectMenu", SelectMenuId.INVERT),
"open_docs":
Keychain.MenuInputAction.new("", "Help Menu", true, "HelpMenu", HelpMenuId.ONLINE_DOCS),
"edit_mode": Keychain.InputAction.new("Moveable Panels", "Window Menu"),
"zoom_in": Keychain.InputAction.new("", "General"),
"zoom_out": Keychain.InputAction.new("", "General"),
"pan": Keychain.InputAction.new("", "General"),
"confirm": Keychain.InputAction.new("", "General"),
"cancel": Keychain.InputAction.new("", "General"),
"switch_colors": Keychain.InputAction.new("", "Buttons"),
"go_to_first_frame": Keychain.InputAction.new("", "Buttons"),
"go_to_last_frame": Keychain.InputAction.new("", "Buttons"),
"go_to_previous_frame": Keychain.InputAction.new("", "Buttons"),
"go_to_next_frame": Keychain.InputAction.new("", "Buttons"),
"play_backwards": Keychain.InputAction.new("", "Buttons"),
"play_forward": Keychain.InputAction.new("", "Buttons"),
}

Keychain.groups = {
"General": Keychain.InputGroup.new("", false),
"Buttons": Keychain.InputGroup.new(),
"Tools": Keychain.InputGroup.new(),
"Left": Keychain.InputGroup.new("Tools"),
"Right": Keychain.InputGroup.new("Tools"),
"Menu": Keychain.InputGroup.new(),
"File Menu": Keychain.InputGroup.new("Menu"),
"Edit Menu": Keychain.InputGroup.new("Menu"),
"View Menu": Keychain.InputGroup.new("Menu"),
"Select Menu": Keychain.InputGroup.new("Menu"),
"Image Menu": Keychain.InputGroup.new("Menu"),
"Window Menu": Keychain.InputGroup.new("Menu"),
"Help Menu": Keychain.InputGroup.new("Menu"),
}
Keychain.ignore_actions = ["left_mouse", "right_mouse", "middle_mouse", "shift", "ctrl", "alt"]

if OS.has_feature("standalone"):
root_directory = OS.get_executable_path().get_base_dir()
# root_directory must be set earlier than this is because XDGDataDirs depends on it
Expand Down
6 changes: 6 additions & 0 deletions src/Autoload/Tools.gd
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ func _ready() -> void:
_tool_buttons = Global.control.find_node("ToolButtons")
for t in tools:
add_tool_button(tools[t])
var tool_shortcut: String = Tools.tools[t].shortcut
var left_tool_shortcut := "left_%s_tool" % tool_shortcut
var right_tool_shortcut := "right_%s_tool" % tool_shortcut
Keychain.actions[left_tool_shortcut] = Keychain.InputAction.new("", "Left")
Keychain.actions[right_tool_shortcut] = Keychain.InputAction.new("", "Right")

_slots[BUTTON_LEFT] = Slot.new("Left tool")
_slots[BUTTON_RIGHT] = Slot.new("Right tool")
_panels[BUTTON_LEFT] = Global.control.find_node("LeftPanelContainer", true, false)
Expand Down

0 comments on commit 37e0d38

Please sign in to comment.