mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-23 17:17:31 -04:00
Scale mouse position, disable emulate_touch_from_mouse
This commit is contained in:
parent
a6a0ba6441
commit
2b652faf54
3 changed files with 23 additions and 6 deletions
|
@ -54,10 +54,6 @@ open_debug={
|
|||
]
|
||||
}
|
||||
|
||||
[input_devices]
|
||||
|
||||
pointing/emulate_touch_from_mouse=true
|
||||
|
||||
[physics]
|
||||
|
||||
2d/physics_engine="GodotPhysics2D"
|
||||
|
|
|
@ -331,10 +331,11 @@ grow_horizontal = 2
|
|||
grow_vertical = 2
|
||||
focus_mode = 0
|
||||
|
||||
[node name="InputSync" type="Node" parent="HBoxContainer/WorldCanvas"]
|
||||
[node name="InputSync" type="Node" parent="HBoxContainer/WorldCanvas" node_paths=PackedStringArray("render_result")]
|
||||
script = ExtResource("8_1blsi")
|
||||
gate_events = ExtResource("2_q7cvi")
|
||||
ui_events = ExtResource("9_ir58h")
|
||||
render_result = NodePath("../RenderResult")
|
||||
|
||||
[node name="CommandSync" type="CommandSync" parent="HBoxContainer/WorldCanvas"]
|
||||
script = ExtResource("10_cqo55")
|
||||
|
|
|
@ -2,6 +2,10 @@ extends Node
|
|||
|
||||
@export var gate_events: GateEvents
|
||||
@export var ui_events: UiEvents
|
||||
@export var render_result: RenderResult
|
||||
|
||||
var scale_width: float
|
||||
var scale_height: float
|
||||
|
||||
var input_sync: InputSync
|
||||
var should_send := false
|
||||
|
@ -10,6 +14,13 @@ var should_send := false
|
|||
func _ready() -> void:
|
||||
gate_events.gate_entered.connect(start_server)
|
||||
ui_events.visibility_changed.connect(on_ui_visibility_changed)
|
||||
|
||||
# Scale mouse position for resolutions other than 1920x1080
|
||||
var viewport_width = ProjectSettings.get_setting("display/window/size/viewport_width", 1152)
|
||||
var viewport_height = ProjectSettings.get_setting("display/window/size/viewport_height", 648)
|
||||
scale_width = float(render_result.width) / viewport_width
|
||||
scale_height = float(render_result.height) / viewport_height
|
||||
Debug.logclr("Mouse position scale: %fx%f" % [scale_width, scale_height], Color.DIM_GRAY)
|
||||
|
||||
|
||||
func start_server() -> void:
|
||||
|
@ -23,6 +34,15 @@ func on_ui_visibility_changed(visible: bool) -> void:
|
|||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if input_sync == null or not should_send: return
|
||||
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT: return
|
||||
|
||||
if event is InputEventMouse:
|
||||
event.position = get_scaled_mouse_pos(event.position)
|
||||
event.global_position = get_scaled_mouse_pos(event.global_position)
|
||||
|
||||
input_sync.send_input_event(event)
|
||||
|
||||
|
||||
func get_scaled_mouse_pos(position : Vector2) -> Vector2:
|
||||
position.x *= scale_width
|
||||
position.y *= scale_height
|
||||
return position
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue