From f8ba9b5727300047319dfd039cb221e468cea3cf Mon Sep 17 00:00:00 2001 From: lucastucious Date: Mon, 21 Jul 2025 19:07:26 +0200 Subject: [PATCH] Edge scroll cursor change --- Core/cursor_behaviour.gd | 42 +++++++++++++---------------- Core/player.gd | 38 +++++++++++++++----------- UI/Loading.tres | 21 +++++++++++++++ UI/Quit Screen.tscn | 58 ++++++++++++++++++++++++++++++++++++++++ project.godot | 5 ++-- 5 files changed, 123 insertions(+), 41 deletions(-) create mode 100644 UI/Loading.tres create mode 100644 UI/Quit Screen.tscn diff --git a/Core/cursor_behaviour.gd b/Core/cursor_behaviour.gd index f6bf98c..208f544 100644 --- a/Core/cursor_behaviour.gd +++ b/Core/cursor_behaviour.gd @@ -1,30 +1,24 @@ extends Node ## Handle all the cursor appareance related stuff. -const nav_e = preload("res://Packs/Kenney-cursors/Outline/navigation_e.svg") -const nav_n = preload("res://Packs/Kenney-cursors/Outline/navigation_n.svg") -const nav_ne = preload("res://Packs/Kenney-cursors/Outline/navigation_ne.svg") -const nav_nw = preload("res://Packs/Kenney-cursors/Outline/navigation_nw.svg") -const nav_s = preload("res://Packs/Kenney-cursors/Outline/navigation_s.svg") -const nav_se = preload("res://Packs/Kenney-cursors/Outline/navigation_se.svg") -const nav_sw = preload("res://Packs/Kenney-cursors/Outline/navigation_sw.svg") -const nav_w = preload("res://Packs/Kenney-cursors/Outline/navigation_w.svg") - -# Called when the node enters the scene tree for the first time. -func _ready() -> void: - pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta: float) -> void: - pass +# Mapping 8 primary directions to custom cursor images +const DIRECTION_CURSOR_MAP = { + Vector2(-1, -1): preload("uid://bnwb6728ln3ae"), + Vector2(0, -1): preload("uid://cgx332aowj6dn"), + Vector2(1, -1): preload("uid://dmn7dlir4ohff"), + Vector2(1, 0): preload("uid://bwfy3euyxmi7j"), + Vector2(1, 1): preload("uid://cpklilc6jmw0d"), + Vector2(0, 1): preload("uid://cbr6j5g1ipdi4"), + Vector2(-1, 1): preload("uid://doia8nobwmv4n"), + Vector2(-1, 0): preload("uid://bqg7s8lukudkc"), + Vector2(0, 0): preload("uid://dp4ed16rb1754"), +} +var edge_scroll_vector = Vector2(1,1) func _on_player_root_cursor_edge_scrolling(direction: Vector2) -> void: - print("panning vector", direction) - return - if direction.length() > 0: - if direction.x > 0: - Input.set_custom_mouse_cursor(nav_e) - else: - Input.set_custom_mouse_cursor(nav_ne) + if direction.length() > 0 or edge_scroll_vector.length() != 0: + #print("direction lenght = ",direction.length()," and stored vector is ", edge_scroll_vector.length()) + edge_scroll_vector = direction + Input.set_custom_mouse_cursor(DIRECTION_CURSOR_MAP.get(direction)) + print(direction) diff --git a/Core/player.gd b/Core/player.gd index 27129f7..a65f631 100644 --- a/Core/player.gd +++ b/Core/player.gd @@ -31,6 +31,9 @@ signal cursor_edge_scrolling(direction:Vector2) #endregion +###### DEBUG +const quit_screen_load = preload("uid://hne6njnc23ur") + func _ready(): Input.mouse_mode = Input.MOUSE_MODE_CONFINED # Maybe should be moved in a better script @@ -86,13 +89,11 @@ func _unhandled_input(event: InputEvent) -> void: func quit_game() -> void: - var quit_label = Label.new() - quit_label.text = "Quitting game ..." - quit_label.uppercase = true - quit_label.add_child(get_tree().current_scene) + var quit_screen = quit_screen_load.instantiate() + get_tree().current_scene.add_child(quit_screen) Input.mouse_mode = Input.MOUSE_MODE_HIDDEN get_tree().root.propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST) - get_tree().quit() + get_tree().call_deferred("quit") #region Getter @@ -138,28 +139,35 @@ func cam_zoom(delta:float) -> void: zoom_direction *= zoom_speed_damp #Smooth the deceleration -func cam_edge_scroll(delta:float) -> void: +func cam_edge_scroll(delta: float) -> void: if edge_scroll_disabled:return + var current_viewport = get_viewport() - var pan_direction := Vector2(0,0) #Edge scrolling to bottom left by default, changing that if needed - var viewport_rectange := Rect2i(current_viewport.get_visible_rect()) - var viewport_size := viewport_rectange.size + var pan_direction := Vector2.ZERO + var viewport_rect := current_viewport.get_visible_rect() + var viewport_size := viewport_rect.size var mouse_position = get_mouse_position() + # TODO: Clamp mouse to edge ? # X PAN if (mouse_position.x < edge_scrolling_margin or (mouse_position.x > viewport_size.x - edge_scrolling_margin)): - pan_direction.x = 1 if (mouse_position.x > viewport_size.x/2) else -1 # detect if we are in the half of the screen or not + pan_direction.x = 1 if (mouse_position.x > viewport_size.x / 2) else -1 # detect if we are in the half of the screen or not # Y PAN if (mouse_position.y < edge_scrolling_margin or (mouse_position.y > viewport_size.y - edge_scrolling_margin)): - pan_direction.y = 1 if (mouse_position.y < viewport_size.y/2) else -1 # detect if we are in the half of the screen or not + pan_direction.y = 1 if (mouse_position.y < viewport_size.y / 2) else -1 # detect if we are in the half of the screen or not - var pan_vector:= Vector2(pan_direction.x,pan_direction.y) * delta * edge_scrolling_speed * get_zoom_factor() + # actual camera movement vector + var pan_vector := pan_direction * delta * edge_scrolling_speed * get_zoom_factor() if pan_vector.length() > 0: - translate_object_local(Vector3(pan_vector.y,0,pan_vector.x)) - #print("panning", pan_vector) + translate_object_local(Vector3(pan_vector.y, 0, pan_vector.x)) - cursor_edge_scrolling.emit(pan_direction.normalized()) + # Emit a normalized version just for the cursor + var quantized_direction := Vector2( + sign(pan_direction.x) if pan_direction.x != 0 else 0, + sign(pan_direction.y) if pan_direction.y != 0 else 0 + ) + cursor_edge_scrolling.emit(quantized_direction) func cam_rotation(mouse_relative:Vector2) -> void: diff --git a/UI/Loading.tres b/UI/Loading.tres new file mode 100644 index 0000000..2881a7a --- /dev/null +++ b/UI/Loading.tres @@ -0,0 +1,21 @@ +[gd_resource type="AnimatedTexture" load_steps=6 format=3 uid="uid://b6qj8shryxmio"] + +[ext_resource type="Texture2D" uid="uid://by55p63om2xkq" path="res://Packs/Kenney-cursors/Outline/progress_empty.svg" id="1_odma8"] +[ext_resource type="Texture2D" uid="uid://bafvx06uvfc3o" path="res://Packs/Kenney-cursors/Outline/progress_CCW_25.svg" id="2_ntwnl"] +[ext_resource type="Texture2D" uid="uid://bmf66p02xiadn" path="res://Packs/Kenney-cursors/Outline/progress_CCW_50.svg" id="3_4r667"] +[ext_resource type="Texture2D" uid="uid://drxmle35rtqfb" path="res://Packs/Kenney-cursors/Outline/progress_CCW_75.svg" id="4_c8cdf"] +[ext_resource type="Texture2D" uid="uid://5qort3ndttur" path="res://Packs/Kenney-cursors/Outline/progress_full.svg" id="5_ci2dw"] + +[resource] +frames = 5 +speed_scale = 1.5 +frame_0/texture = ExtResource("1_odma8") +frame_0/duration = 0.3 +frame_1/texture = ExtResource("2_ntwnl") +frame_1/duration = 0.3 +frame_2/texture = ExtResource("3_4r667") +frame_2/duration = 0.3 +frame_3/texture = ExtResource("4_c8cdf") +frame_3/duration = 0.3 +frame_4/texture = ExtResource("5_ci2dw") +frame_4/duration = 0.3 diff --git a/UI/Quit Screen.tscn b/UI/Quit Screen.tscn new file mode 100644 index 0000000..9715007 --- /dev/null +++ b/UI/Quit Screen.tscn @@ -0,0 +1,58 @@ +[gd_scene load_steps=3 format=3 uid="uid://hne6njnc23ur"] + +[ext_resource type="Texture2D" uid="uid://b6qj8shryxmio" path="res://UI/Loading.tres" id="1_wg051"] + +[sub_resource type="LabelSettings" id="LabelSettings_71lkv"] +outline_size = 6 +outline_color = Color(0, 0, 0, 1) + +[node name="QuitScreen" type="Control"] +process_mode = 3 +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 +accessibility_name = "Quit Screen" + +[node name="Label" type="Label" parent="."] +process_mode = 3 +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -87.5 +offset_top = -25.0 +offset_right = 87.5 +offset_bottom = 25.0 +grow_horizontal = 2 +grow_vertical = 2 +pivot_offset = Vector2(87.5, 25) +accessibility_name = "Quit game in progress" +text = "Quitting Game" +label_settings = SubResource("LabelSettings_71lkv") +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Loading" type="TextureRect" parent="Label"] +process_mode = 3 +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -20.0 +offset_top = 25.0 +offset_right = 20.0 +offset_bottom = 64.99997 +grow_horizontal = 2 +grow_vertical = 2 +pivot_offset = Vector2(20, 20) +accessibility_name = "Loading spin image" +texture = ExtResource("1_wg051") diff --git a/project.godot b/project.godot index 02de14b..d301fa4 100644 --- a/project.godot +++ b/project.godot @@ -21,6 +21,7 @@ config/icon="res://icon.svg" [display] mouse_cursor/custom_image="uid://dp4ed16rb1754" +mouse_cursor/custom_image_hotspot=Vector2(14, 2) [editor_plugins] @@ -37,8 +38,8 @@ folder_colors={ controls/camera_zoom_speed=20.0 controls/camera_move_speed=20.0 -controls/cam_rotation_speed_x=0.19999999999708962 -controls/cam_rotation_speed_y=0.19999999999708962 +controls/cam_rotation_speed_x=0.1999999999970896 +controls/cam_rotation_speed_y=0.1999999999970896 controls/invert_cam_rotation_x=false controls/invert_cam_rotation_y=true