Edge scroll cursor change
This commit is contained in:
parent
30e7ebc927
commit
f8ba9b5727
5 changed files with 123 additions and 41 deletions
|
@ -1,30 +1,24 @@
|
||||||
extends Node
|
extends Node
|
||||||
## Handle all the cursor appareance related stuff.
|
## 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")
|
|
||||||
|
|
||||||
|
# Mapping 8 primary directions to custom cursor images
|
||||||
# Called when the node enters the scene tree for the first time.
|
const DIRECTION_CURSOR_MAP = {
|
||||||
func _ready() -> void:
|
Vector2(-1, -1): preload("uid://bnwb6728ln3ae"),
|
||||||
pass # Replace with function body.
|
Vector2(0, -1): preload("uid://cgx332aowj6dn"),
|
||||||
|
Vector2(1, -1): preload("uid://dmn7dlir4ohff"),
|
||||||
|
Vector2(1, 0): preload("uid://bwfy3euyxmi7j"),
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
Vector2(1, 1): preload("uid://cpklilc6jmw0d"),
|
||||||
func _process(delta: float) -> void:
|
Vector2(0, 1): preload("uid://cbr6j5g1ipdi4"),
|
||||||
pass
|
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:
|
func _on_player_root_cursor_edge_scrolling(direction: Vector2) -> void:
|
||||||
print("panning vector", direction)
|
if direction.length() > 0 or edge_scroll_vector.length() != 0:
|
||||||
return
|
#print("direction lenght = ",direction.length()," and stored vector is ", edge_scroll_vector.length())
|
||||||
if direction.length() > 0:
|
edge_scroll_vector = direction
|
||||||
if direction.x > 0:
|
Input.set_custom_mouse_cursor(DIRECTION_CURSOR_MAP.get(direction))
|
||||||
Input.set_custom_mouse_cursor(nav_e)
|
print(direction)
|
||||||
else:
|
|
||||||
Input.set_custom_mouse_cursor(nav_ne)
|
|
||||||
|
|
|
@ -31,6 +31,9 @@ signal cursor_edge_scrolling(direction:Vector2)
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
###### DEBUG
|
||||||
|
const quit_screen_load = preload("uid://hne6njnc23ur")
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
Input.mouse_mode = Input.MOUSE_MODE_CONFINED # Maybe should be moved in a better script
|
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:
|
func quit_game() -> void:
|
||||||
var quit_label = Label.new()
|
var quit_screen = quit_screen_load.instantiate()
|
||||||
quit_label.text = "Quitting game ..."
|
get_tree().current_scene.add_child(quit_screen)
|
||||||
quit_label.uppercase = true
|
|
||||||
quit_label.add_child(get_tree().current_scene)
|
|
||||||
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
|
Input.mouse_mode = Input.MOUSE_MODE_HIDDEN
|
||||||
get_tree().root.propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)
|
get_tree().root.propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)
|
||||||
get_tree().quit()
|
get_tree().call_deferred("quit")
|
||||||
|
|
||||||
|
|
||||||
#region Getter
|
#region Getter
|
||||||
|
@ -138,28 +139,35 @@ func cam_zoom(delta:float) -> void:
|
||||||
zoom_direction *= zoom_speed_damp #Smooth the deceleration
|
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
|
if edge_scroll_disabled:return
|
||||||
|
|
||||||
var current_viewport = get_viewport()
|
var current_viewport = get_viewport()
|
||||||
var pan_direction := Vector2(0,0) #Edge scrolling to bottom left by default, changing that if needed
|
var pan_direction := Vector2.ZERO
|
||||||
var viewport_rectange := Rect2i(current_viewport.get_visible_rect())
|
var viewport_rect := current_viewport.get_visible_rect()
|
||||||
var viewport_size := viewport_rectange.size
|
var viewport_size := viewport_rect.size
|
||||||
var mouse_position = get_mouse_position()
|
var mouse_position = get_mouse_position()
|
||||||
|
|
||||||
|
# TODO: Clamp mouse to edge ?
|
||||||
# X PAN
|
# X PAN
|
||||||
if (mouse_position.x < edge_scrolling_margin or (mouse_position.x > viewport_size.x - edge_scrolling_margin)):
|
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
|
# Y PAN
|
||||||
if (mouse_position.y < edge_scrolling_margin or (mouse_position.y > viewport_size.y - edge_scrolling_margin)):
|
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:
|
if pan_vector.length() > 0:
|
||||||
translate_object_local(Vector3(pan_vector.y,0,pan_vector.x))
|
translate_object_local(Vector3(pan_vector.y, 0, pan_vector.x))
|
||||||
#print("panning", pan_vector)
|
|
||||||
|
|
||||||
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:
|
func cam_rotation(mouse_relative:Vector2) -> void:
|
||||||
|
|
21
UI/Loading.tres
Normal file
21
UI/Loading.tres
Normal file
|
@ -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
|
58
UI/Quit Screen.tscn
Normal file
58
UI/Quit Screen.tscn
Normal file
|
@ -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")
|
|
@ -21,6 +21,7 @@ config/icon="res://icon.svg"
|
||||||
[display]
|
[display]
|
||||||
|
|
||||||
mouse_cursor/custom_image="uid://dp4ed16rb1754"
|
mouse_cursor/custom_image="uid://dp4ed16rb1754"
|
||||||
|
mouse_cursor/custom_image_hotspot=Vector2(14, 2)
|
||||||
|
|
||||||
[editor_plugins]
|
[editor_plugins]
|
||||||
|
|
||||||
|
@ -37,8 +38,8 @@ folder_colors={
|
||||||
|
|
||||||
controls/camera_zoom_speed=20.0
|
controls/camera_zoom_speed=20.0
|
||||||
controls/camera_move_speed=20.0
|
controls/camera_move_speed=20.0
|
||||||
controls/cam_rotation_speed_x=0.19999999999708962
|
controls/cam_rotation_speed_x=0.1999999999970896
|
||||||
controls/cam_rotation_speed_y=0.19999999999708962
|
controls/cam_rotation_speed_y=0.1999999999970896
|
||||||
controls/invert_cam_rotation_x=false
|
controls/invert_cam_rotation_x=false
|
||||||
controls/invert_cam_rotation_y=true
|
controls/invert_cam_rotation_y=true
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue