Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
fix mouse position scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Nordup committed Mar 25, 2024
1 parent 75d6ee0 commit baa9c03
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 18 deletions.
4 changes: 2 additions & 2 deletions project/scenes/components/search.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
[ext_resource type="Texture2D" uid="uid://btn6ytky782a2" path="res://textures/star.svg" id="8_b00p6"]
[ext_resource type="Texture2D" uid="uid://lxx36xkotvh1" path="res://textures/star_filled.svg" id="9_2en0l"]
[ext_resource type="Script" path="res://scripts/ui/search/prompt_results.gd" id="14_0lofv"]
[ext_resource type="Script" path="res://scripts/ui/top_level.gd" id="14_5k27g"]
[ext_resource type="Script" path="res://scripts/ui/search/prompt_navigation.gd" id="14_h86vl"]
[ext_resource type="Script" path="res://scripts/ui/search/fix_promt_position.gd" id="15_35wcy"]
[ext_resource type="Resource" uid="uid://cjcdum6fm4ta0" path="res://resources/api_settings.tres" id="15_uafyh"]
[ext_resource type="PackedScene" uid="uid://b57n6cvtqn5b7" path="res://scenes/components/prompt.tscn" id="16_lbcsd"]

Expand Down Expand Up @@ -432,7 +432,7 @@ offset_right = 500.0
offset_bottom = 860.0
grow_horizontal = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_mh73y")
script = ExtResource("14_5k27g")
script = ExtResource("15_35wcy")

[node name="VBoxContainer" type="VBoxContainer" parent="Prompt/Panel" node_paths=PackedStringArray("panel")]
layout_mode = 1
Expand Down
5 changes: 4 additions & 1 deletion project/scenes/menu.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=18 format=3 uid="uid://5btb7nvgmfhl"]
[gd_scene load_steps=19 format=3 uid="uid://5btb7nvgmfhl"]

[ext_resource type="Script" path="res://scripts/ui/menu/menu_navigation.gd" id="1_7anvm"]
[ext_resource type="Texture2D" uid="uid://8wvea7j0v0rx" path="res://textures/Reload.svg" id="1_d6dhb"]
[ext_resource type="Script" path="res://scripts/ui/menu/menu.gd" id="1_o6vga"]
[ext_resource type="Texture2D" uid="uid://byvigfpu44dnu" path="res://textures/arrow.svg" id="1_wkgtd"]
[ext_resource type="Texture2D" uid="uid://dystd8vvbqwo2" path="res://textures/exit.svg" id="3_1a6fk"]
[ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://resources/gate_events.res" id="3_m632k"]
Expand Down Expand Up @@ -153,6 +154,8 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_o6vga")
ui_events = ExtResource("8_8dnbq")

[node name="Background" type="Panel" parent="."]
layout_mode = 0
Expand Down
1 change: 1 addition & 0 deletions project/scenes/menu_body/world.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ custom_minimum_size = Vector2(1300, 0)
layout_mode = 2
size_flags_horizontal = 0
script = ExtResource("9_ncfxj")
ui_events = ExtResource("9_ir58h")

[node name="RenderResult" type="TextureRect" parent="HBoxContainer/WorldCanvas"]
layout_mode = 1
Expand Down
14 changes: 11 additions & 3 deletions project/scripts/resources/ui_events.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
extends Resource
class_name UiEvents

signal visibility_changed(visible: bool)
signal ui_visibility_changed(visible: bool)
signal ui_size_changed(size: Vector2)

var current_ui_size: Vector2

func visibility_changed_emit(visible: bool) -> void:
visibility_changed.emit(visible)

func ui_visibility_changed_emit(visible: bool) -> void:
ui_visibility_changed.emit(visible)


func ui_size_changed_emit(size: Vector2) -> void:
current_ui_size = size
ui_size_changed.emit(size)
9 changes: 3 additions & 6 deletions project/scripts/sandbox/input_sync.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ var should_send := false

func _ready() -> void:
gate_events.gate_entered.connect(start_server)
ui_events.visibility_changed.connect(on_ui_visibility_changed)
ui_events.ui_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
scale_width = float(render_result.width) / ui_events.current_ui_size.x
scale_height = float(render_result.height) / ui_events.current_ui_size.y
Debug.logclr("Mouse position scale: %.2fx%.2f" % [scale_width, scale_height], Color.DIM_GRAY)


Expand Down
6 changes: 3 additions & 3 deletions project/scripts/ui/fullscreen_animation.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ var fullscreen := false


func _ready() -> void:
ui_events.visibility_changed.connect(on_visibility_changed)
gate_events.open_gate.connect(func(_url): on_visibility_changed(true))
ui_events.ui_visibility_changed.connect(on_ui_visibility_changed)
gate_events.open_gate.connect(func(_url): on_ui_visibility_changed(true))


func on_visibility_changed(visible: bool) -> void:
func on_ui_visibility_changed(visible: bool) -> void:
if visible and fullscreen:
fullscreen = false
play(INITIAL)
Expand Down
12 changes: 12 additions & 0 deletions project/scripts/ui/menu/menu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
extends Control

@export var ui_events: UiEvents


func _ready() -> void:
resized.connect(on_resized)
on_resized()


func on_resized() -> void:
ui_events.ui_size_changed_emit(size)
3 changes: 2 additions & 1 deletion project/scripts/ui/world/world_canvas.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extends Control

@export var ui_events: UiEvents
@export var interpolate: float:
set(value):
interpolate = value
Expand All @@ -13,7 +14,7 @@ func _ready() -> void:
var viewport_width = ProjectSettings.get_setting("display/window/size/viewport_width", 1152)
var scale_width = float(custom_minimum_size.x) / viewport_width

full_screen = int(get_parent_control().size.x)
full_screen = int(ui_events.current_ui_size.x)
initial = int(full_screen * scale_width)
custom_minimum_size.x = initial
Debug.logclr("WorldCanvas initial: %d full_screen: %d" % [initial, full_screen], Color.DIM_GRAY)
Expand Down
4 changes: 2 additions & 2 deletions project/scripts/ui/world/world_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func show_ui() -> void:
_visible = true

Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
ui_events.visibility_changed_emit(true)
ui_events.ui_visibility_changed_emit(true)


func hide_ui() -> void:
if not _visible: return
_visible = false

Input.set_mouse_mode(mouse_mode)
ui_events.visibility_changed_emit(false)
ui_events.ui_visibility_changed_emit(false)

0 comments on commit baa9c03

Please sign in to comment.