1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-22 23:54:21 +00:00
swear-jar/interface/custom_ui.gd

33 lines
1 KiB
GDScript3
Raw Normal View History

2023-10-01 21:40:48 +00:00
extends Control
2023-10-02 00:53:12 +00:00
class_name CustomUI
2023-10-01 21:40:48 +00:00
@onready var window: Window = get_window()
@onready var viewport: Viewport = window.get_viewport()
2023-10-02 13:12:08 +00:00
@onready var game_safe_ui: MarginContainer = $GameSafeUI
@onready var shop_safe_ui: MarginContainer = $ShopSafeUI
2023-10-03 23:01:36 +00:00
@onready var score_safe_ui: MarginContainer = $ScoreSafeUI
2023-10-02 13:12:08 +00:00
@onready var game_camera: GameCamera = $GameViewport/Viewport/GameCamera
2023-10-01 21:40:48 +00:00
func _ready():
viewport.size_changed.connect(_on_viewport_size_changed)
2023-10-02 00:53:12 +00:00
_on_viewport_size_changed()
2023-10-01 21:40:48 +00:00
func _on_viewport_size_changed():
var window_size: Vector2i = DisplayServer.window_get_size()
print("[View] Window size is: ", window_size)
var scaling_factor
if window_size.x < window_size.y:
scaling_factor = window_size.x / 270.0
2023-10-01 21:40:48 +00:00
else:
scaling_factor = window_size.y / 480.0
2023-10-01 21:40:48 +00:00
print("[View] Scaling factor is: ", scaling_factor)
get_window().set_content_scale_factor(scaling_factor)
2023-10-02 13:12:08 +00:00
game_safe_ui.set_safe_margins(scaling_factor)
shop_safe_ui.set_safe_margins(scaling_factor)
2023-10-03 23:01:36 +00:00
score_safe_ui.set_safe_margins(scaling_factor)
2023-10-02 13:12:08 +00:00
game_camera.set_camera_position(scaling_factor)