Skip to content
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

Bug fix custom shortcut setting does not work #20

Merged
merged 1 commit into from
Aug 11, 2024
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
2 changes: 2 additions & 0 deletions project/addons/net.yarvis.pixel_pen/classes/editor_shorcut.gd
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,5 @@ extends Resource

@export_category("Other")
@export var confirm : Shortcut
@export var zoom_in : Shortcut
@export var zoom_out : Shortcut
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ func update_background_shader_state():
background_canvas.visible = true


func zoom_input(event: InputEvent) -> bool:
if not PixelPen.state or not PixelPen.state.userconfig:
return false
var shorcut := (PixelPen.state.userconfig as UserConfig).shorcuts
if shorcut.zoom_in and shorcut.zoom_in.matches_event(event):
zoom(1.1)
return true
if shorcut.zoom_out and shorcut.zoom_out.matches_event(event):
zoom(0.9)
return true
return false


func _input(event: InputEvent):
PixelPen.state.debug_log.emit("Input", event)
if PixelPen.state.current_project == null:
Expand All @@ -220,7 +233,8 @@ func _input(event: InputEvent):
if event is InputEventKey:
if event.keycode == KEY_SHIFT:
canvas_paint.on_shift_pressed(event.is_pressed())

if zoom_input(event):
return
if event and event is InputEventMagnifyGesture:
zoom(event.factor)
elif event and event is InputEventPanGesture:
Expand Down
17 changes: 10 additions & 7 deletions project/addons/net.yarvis.pixel_pen/editor/preferences.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[ext_resource type="Script" path="res://addons/net.yarvis.pixel_pen/ui/tree_properties/tree_row.gd" id="4_6utim"]
[ext_resource type="Script" path="res://addons/net.yarvis.pixel_pen/editor/preferences/shorcuts_preferences.gd" id="6_dsxs8"]

[sub_resource type="Resource" id="Resource_h5vb2"]
[sub_resource type="Resource" id="Resource_nqfg7"]
script = ExtResource("4_6utim")
label = "Grid line repeat"
field = 5
Expand Down Expand Up @@ -41,8 +41,10 @@ enum_option = Array[String]([])
file_value = ""
file_mode = 4
file_dialog_filters = PackedStringArray("*.png, *.jpg, *.jpeg ; Supported Images")
color_value = Color(1, 1, 1, 1)
color_alpha = true

[sub_resource type="Resource" id="Resource_gogf3"]
[sub_resource type="Resource" id="Resource_u6eg1"]
script = ExtResource("4_6utim")
label = "Checker size"
field = 5
Expand Down Expand Up @@ -76,11 +78,13 @@ enum_option = Array[String]([])
file_value = ""
file_mode = 4
file_dialog_filters = PackedStringArray("*.png, *.jpg, *.jpeg ; Supported Images")
color_value = Color(1, 1, 1, 1)
color_alpha = true

[node name="Preferences" type="AcceptDialog" node_paths=PackedStringArray("tab_container")]
title = "Preferences"
initial_position = 1
size = Vector2i(861, 574)
size = Vector2i(1146, 764)
visible = true
theme = ExtResource("1_mhedo")
ok_button_text = "Close"
Expand All @@ -93,15 +97,13 @@ anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 3.6
offset_top = 3.6
offset_right = -3.60004
offset_right = -3.59998
offset_bottom = -37.6
grow_horizontal = 2
grow_vertical = 2
current_tab = 1
tab_focus_mode = 0

[node name="General" type="HBoxContainer" parent="TabContainer" node_paths=PackedStringArray("tree", "tree_properties")]
visible = false
layout_mode = 2
theme_override_constants/separation = 16
script = ExtResource("3_k57uy")
Expand All @@ -120,9 +122,10 @@ layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 3.0
script = ExtResource("3_74jry")
structure = Array[ExtResource("4_6utim")]([SubResource("Resource_h5vb2"), SubResource("Resource_gogf3")])
structure = Array[ExtResource("4_6utim")]([SubResource("Resource_nqfg7"), SubResource("Resource_u6eg1")])

[node name="Shorcuts" type="HBoxContainer" parent="TabContainer" node_paths=PackedStringArray("shorcuts_tree", "edit_button", "reset_button", "clear_button")]
visible = false
layout_mode = 2
script = ExtResource("6_dsxs8")
shorcuts_tree = NodePath("ShorcutsTree")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ var shorcuts_tree_structure : Dictionary = {
"Fill.tool_fill" : [],
"Color Picker.tool_color_picker" : [],
"Zoom.tool_zoom" : []
},
"Navigation" : {
"Zoom in.zoom_in" : [],
"Zoom out.zoom_out" : [],
}
}

Expand Down Expand Up @@ -155,7 +159,7 @@ func _on_edit_pressed():
var line_edit : LineEdit = LineEdit.new()
line_edit.set_anchors_and_offsets_preset(Control.PRESET_HCENTER_WIDE)
line_edit.placeholder_text = "Linstening for input..."
line_edit.set_script(load("shorcut_listener.gd"))
line_edit.set_script(load("res://addons/net.yarvis.pixel_pen/editor/preferences/shorcut_listener.gd"))
wrapper.add_child(line_edit)
window.confirmed.connect(func ():
if line_edit.record_shorcut.has_valid_event():
Expand Down