divers test.

This commit is contained in:
osquallo 2018-07-29 18:00:08 +02:00
parent a331edd6b6
commit 561877739f
13 changed files with 402 additions and 232 deletions

71
JukeboxPannel.gd Normal file
View file

@ -0,0 +1,71 @@
extends Spatial
# Member variables
var prev_pos = null
var last_click_pos = null
var viewport = null
func _input(event):
# Check if the event is a non-mouse event
var is_mouse_event = false
var mouse_events = [InputEventMouseButton, InputEventMouseMotion, InputEventScreenDrag, InputEventScreenTouch]
for mouse_event in mouse_events:
if (event is mouse_event):
is_mouse_event = true
break
# If it is, then pass the event to the viewport
if (is_mouse_event == false):
viewport.input(event)
# Mouse events for Area
func _on_area_input_event(camera, event, click_pos, click_normal, shape_idx):
# Use click pos (click in 3d space, convert to area space)
var pos = get_node("Area").get_global_transform().affine_inverse()
# the click pos is not zero, then use it to convert from 3D space to area space
if (click_pos.x != 0 or click_pos.y != 0 or click_pos.z != 0):
pos *= click_pos
last_click_pos = click_pos
else:
# Otherwise, we have a motion event and need to use our last click pos
# and move it according to the relative position of the event.
# NOTE: this is not an exact 1-1 conversion, but it's pretty close
pos *= last_click_pos
if (event is InputEventMouseMotion or event is InputEventScreenDrag):
pos.x += event.relative.x / viewport.size.x
pos.y += event.relative.y / viewport.size.y
last_click_pos = pos
# Convert to 2D
pos = Vector2(pos.x, pos.y)
# Convert to viewport coordinate system
# Convert pos to a range from (0 - 1)
pos.y *= -1
pos += Vector2(1, 1)
pos = pos / 2
# Convert pos to be in range of the viewport
pos.x *= viewport.size.x
pos.y *= viewport.size.y
# Set the position in event
event.position = pos
event.global_position = pos
if (prev_pos == null):
prev_pos = pos
if (event is InputEventMouseMotion):
event.relative = pos - prev_pos
prev_pos = pos
# Send the event to the viewport
viewport.input(event)
func _ready():
viewport = get_node("Viewport")
get_node("Area").connect("input_event", self, "_on_area_input_event")

View file

@ -46,6 +46,7 @@ margin_left = 4.0
margin_top = 4.0 margin_top = 4.0
margin_right = 1020.0 margin_right = 1020.0
margin_bottom = 596.0 margin_bottom = 596.0
mouse_filter = 1
theme = SubResource( 2 ) theme = SubResource( 2 )
_sections_unfolded = [ "Focus", "Margin", "Mouse", "Rect", "Size Flags", "Theme", "Visibility", "custom_constants" ] _sections_unfolded = [ "Focus", "Margin", "Mouse", "Rect", "Size Flags", "Theme", "Visibility", "custom_constants" ]

View file

@ -31,15 +31,11 @@ func _on_SaveHUD_pressed():
func _on_Windows_gui_input( event ): func _on_Windows_gui_input( event ):
if event is InputEventMouseButton \ if event is InputEventMouseButton \
and event.button_index == BUTTON_RIGHT \
and Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE \ and Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE \
and not event.is_echo() \ and event.is_action_pressed( "ui_free_cursor" ):
and not event.pressed:
Input.set_mouse_mode( Input.MOUSE_MODE_CAPTURED ) Input.set_mouse_mode( Input.MOUSE_MODE_CAPTURED )
elif event is InputEventMouseButton \ elif event is InputEventMouseButton \
and event.button_index == BUTTON_RIGHT \
and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED \ and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED \
and not event.is_echo() \ and event.is_action_pressed( "ui_free_cursor" ):
and not event.pressed:
Input.set_mouse_mode( Input.MOUSE_MODE_VISIBLE ) Input.set_mouse_mode( Input.MOUSE_MODE_VISIBLE )

View file

@ -42,14 +42,15 @@ margin_right = 1024.0
margin_bottom = 600.0 margin_bottom = 600.0
rect_pivot_offset = Vector2( 0, 0 ) rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false rect_clip_content = false
mouse_filter = 0 mouse_filter = 2
mouse_default_cursor_shape = 0 mouse_default_cursor_shape = 0
size_flags_horizontal = 1 size_flags_horizontal = 1
size_flags_vertical = 1 size_flags_vertical = 1
_sections_unfolded = [ "Visibility" ] _sections_unfolded = [ "Mouse", "Visibility" ]
[node name="overlay_douleur" type="Panel" parent="." index="1"] [node name="overlay_douleur" type="Panel" parent="." index="1"]
visible = false
modulate = Color( 1, 0, 0, 0 ) modulate = Color( 1, 0, 0, 0 )
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -59,11 +60,11 @@ margin_right = 1024.0
margin_bottom = 600.0 margin_bottom = 600.0
rect_pivot_offset = Vector2( 0, 0 ) rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false rect_clip_content = false
mouse_filter = 0 mouse_filter = 2
mouse_default_cursor_shape = 0 mouse_default_cursor_shape = 0
size_flags_horizontal = 1 size_flags_horizontal = 1
size_flags_vertical = 1 size_flags_vertical = 1
_sections_unfolded = [ "Visibility" ] _sections_unfolded = [ "Mouse", "Visibility" ]
[node name="Windows" type="ReferenceRect" parent="." index="2"] [node name="Windows" type="ReferenceRect" parent="." index="2"]

View file

@ -1,6 +1,5 @@
extends VBoxContainer extends VBoxContainer
#var songs_list = [ "Sangakanat", "pre-mix_khanat_main_theme" ]
var songs_list = [] var songs_list = []
var current_song = "" var current_song = ""
var current_position = 0.0 var current_position = 0.0

View file

@ -15,13 +15,13 @@ margin_right = 256.0
margin_bottom = 86.0 margin_bottom = 86.0
rect_pivot_offset = Vector2( 0, 0 ) rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false rect_clip_content = false
mouse_filter = 0 mouse_filter = 1
mouse_default_cursor_shape = 0 mouse_default_cursor_shape = 2
size_flags_horizontal = 1 size_flags_horizontal = 1
size_flags_vertical = 1 size_flags_vertical = 1
alignment = 0 alignment = 0
script = ExtResource( 1 ) script = ExtResource( 1 )
_sections_unfolded = [ "Rect", "Size Flags" ] _sections_unfolded = [ "Mouse", "Rect", "Size Flags" ]
[node name="Songs" type="Container" parent="." index="0"] [node name="Songs" type="Container" parent="." index="0"]
@ -32,10 +32,11 @@ anchor_bottom = 0.0
margin_right = 256.0 margin_right = 256.0
rect_pivot_offset = Vector2( 0, 0 ) rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false rect_clip_content = false
mouse_filter = 0 mouse_filter = 1
mouse_default_cursor_shape = 0 mouse_default_cursor_shape = 0
size_flags_horizontal = 1 size_flags_horizontal = 1
size_flags_vertical = 1 size_flags_vertical = 1
_sections_unfolded = [ "Mouse" ]
[node name="pre-mix_khanat_main_theme" type="AudioStreamPlayer" parent="Songs" index="0"] [node name="pre-mix_khanat_main_theme" type="AudioStreamPlayer" parent="Songs" index="0"]
@ -102,7 +103,7 @@ rect_clip_content = false
focus_mode = 2 focus_mode = 2
mouse_filter = 0 mouse_filter = 0
mouse_default_cursor_shape = 0 mouse_default_cursor_shape = 0
size_flags_horizontal = 1 size_flags_horizontal = 3
size_flags_vertical = 1 size_flags_vertical = 1
toggle_mode = false toggle_mode = false
action_mode = 0 action_mode = 0
@ -113,6 +114,7 @@ flat = false
align = 0 align = 0
items = [ ] items = [ ]
selected = -1 selected = -1
_sections_unfolded = [ "Grow Direction", "Margin", "Rect", "Size Flags" ]
[node name="Buttons" type="HBoxContainer" parent="." index="3"] [node name="Buttons" type="HBoxContainer" parent="." index="3"]
@ -130,7 +132,7 @@ mouse_default_cursor_shape = 0
size_flags_horizontal = 1 size_flags_horizontal = 1
size_flags_vertical = 1 size_flags_vertical = 1
alignment = 0 alignment = 0
_sections_unfolded = [ "Rect" ] _sections_unfolded = [ "Mouse", "Rect" ]
[node name="Pause" type="Button" parent="Buttons" index="0"] [node name="Pause" type="Button" parent="Buttons" index="0"]

View file

@ -139,4 +139,3 @@ func _input(event):
if Input.is_action_pressed( "hide_char" ): if Input.is_action_pressed( "hide_char" ):
$MeshInstance.visible = not $MeshInstance.visible $MeshInstance.visible = not $MeshInstance.visible

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=46 format=2] [gd_scene load_steps=41 format=2]
[ext_resource path="res://scenes/Game/Character/Character.tscn" type="PackedScene" id=1] [ext_resource path="res://scenes/Game/Character/Character.tscn" type="PackedScene" id=1]
[ext_resource path="res://scenes/Game/Terrain/Terrain.tscn" type="PackedScene" id=2] [ext_resource path="res://scenes/Game/Terrain/Terrain.tscn" type="PackedScene" id=2]
@ -13,7 +13,6 @@
[ext_resource path="res://assets/Game/textures/fire_01.png" type="Texture" id=11] [ext_resource path="res://assets/Game/textures/fire_01.png" type="Texture" id=11]
[ext_resource path="res://assets/Game/textures/fire_02.png" type="Texture" id=12] [ext_resource path="res://assets/Game/textures/fire_02.png" type="Texture" id=12]
[ext_resource path="res://scenes/Game/jukebox/jukebox.tscn" type="PackedScene" id=13] [ext_resource path="res://scenes/Game/jukebox/jukebox.tscn" type="PackedScene" id=13]
[ext_resource path="res://scenes/GUI/MusicControls/MusicControls.tscn" type="PackedScene" id=14]
[sub_resource type="GDScript" id=1] [sub_resource type="GDScript" id=1]
@ -777,75 +776,6 @@ material = SubResource( 26 )
custom_aabb = AABB( 0, 0, 0, 0, 0, 0 ) custom_aabb = AABB( 0, 0, 0, 0, 0, 0 )
size = Vector2( 0.4, 0.4 ) size = Vector2( 0.4, 0.4 )
[sub_resource type="QuadMesh" id=28]
custom_aabb = AABB( 0, 0, 0, 0, 0, 0 )
size = Vector2( 2, 2 )
[sub_resource type="ViewportTexture" id=29]
resource_local_to_scene = true
flags = 0
viewport_path = NodePath("jukebox/Viewport")
[sub_resource type="SpatialMaterial" id=30]
resource_local_to_scene = true
render_priority = 0
flags_transparent = true
flags_unshaded = true
flags_vertex_lighting = false
flags_no_depth_test = false
flags_use_point_size = false
flags_world_triplanar = false
flags_fixed_size = false
flags_albedo_tex_force_srgb = true
vertex_color_use_as_albedo = false
vertex_color_is_srgb = false
params_diffuse_mode = 0
params_specular_mode = 0
params_blend_mode = 0
params_cull_mode = 2
params_depth_draw_mode = 0
params_line_width = 1.0
params_point_size = 1.0
params_billboard_mode = 0
params_grow = false
params_use_alpha_scissor = false
albedo_color = Color( 1, 1, 1, 1 )
albedo_texture = SubResource( 29 )
metallic = 0.0
metallic_specular = 0.5
metallic_texture_channel = 0
roughness = 0.0
roughness_texture_channel = 0
emission_enabled = false
normal_enabled = false
rim_enabled = false
clearcoat_enabled = false
anisotropy_enabled = false
ao_enabled = false
depth_enabled = false
subsurf_scatter_enabled = false
transmission_enabled = false
refraction_enabled = false
detail_enabled = false
uv1_scale = Vector3( 1, 1, 1 )
uv1_offset = Vector3( 0, 0, 0 )
uv1_triplanar = false
uv1_triplanar_sharpness = 1.0
uv2_scale = Vector3( 1, 1, 1 )
uv2_offset = Vector3( 0, 0, 0 )
uv2_triplanar = false
uv2_triplanar_sharpness = 1.0
proximity_fade_enable = false
distance_fade_enable = false
_sections_unfolded = [ "Albedo", "Flags", "Metallic", "Parameters", "Resource" ]
[sub_resource type="ConvexPolygonShape" id=31]
points = PoolVector3Array( -0.5, -0.5, 0, -0.5, 0.5, 0, 0.5, 0.5, 0, 0.5, -0.5, 0 )
[node name="Game" type="Spatial" index="0"] [node name="Game" type="Spatial" index="0"]
_sections_unfolded = [ "Transform" ] _sections_unfolded = [ "Transform" ]
@ -1205,91 +1135,9 @@ draw_passes = 2
draw_pass_1 = SubResource( 25 ) draw_pass_1 = SubResource( 25 )
draw_pass_2 = SubResource( 27 ) draw_pass_2 = SubResource( 27 )
[node name="jukebox" parent="." index="2" instance=ExtResource( 13 )] [node name="jukebox" parent="World" index="8" instance=ExtResource( 13 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -7.67816, 0, 0 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -7.67816, 0, 0 )
_sections_unfolded = [ "Transform" ]
[node name="JukeBoxArea" type="Area" parent="jukebox" index="3"]
transform = Transform( -4.96064e-008, -0.173067, 0.981514, 3.42613e-008, 0.981514, 0.173067, -0.996655, 4.23548e-008, -4.29033e-008, 0.5, 2.5, 0 )
input_ray_pickable = true
input_capture_on_drag = true
space_override = 0
gravity_point = false
gravity_distance_scale = 0.0
gravity_vec = Vector3( 0, -1, 0 )
gravity = 9.8
linear_damp = 0.1
angular_damp = 1.0
priority = 0.0
monitoring = true
monitorable = true
collision_layer = 1
collision_mask = 1
audio_bus_override = false
audio_bus_name = "Master"
reverb_bus_enable = false
reverb_bus_name = "Master"
reverb_bus_amount = 0.0
reverb_bus_uniformity = 0.0
_sections_unfolded = [ "Collision", "Transform" ]
[node name="MeshInstance" type="MeshInstance" parent="jukebox/JukeBoxArea" index="0"]
transform = Transform( 1, 0, 0, -7.10543e-015, 1, -9.55343e-016, 7.10543e-015, -9.55343e-016, 1, 0, 0, 0 )
layers = 1
material_override = null
cast_shadow = 1
extra_cull_margin = 0.0
use_in_baked_light = false
lod_min_distance = 0.0
lod_min_hysteresis = 0.0
lod_max_distance = 0.0
lod_max_hysteresis = 0.0
mesh = SubResource( 28 )
skeleton = NodePath("..")
material/0 = SubResource( 30 )
_sections_unfolded = [ "Geometry", "Transform", "material" ]
[node name="CollisionShape" type="CollisionShape" parent="jukebox/JukeBoxArea" index="1"]
shape = SubResource( 31 )
disabled = false
_sections_unfolded = [ "Transform" ]
[node name="Viewport" type="Viewport" parent="jukebox" index="4"]
arvr = false
size = Vector2( 256, 256 )
own_world = false
world = null
transparent_bg = true
msaa = 0
hdr = false
disable_3d = false
usage = 0
debug_draw = 0
render_target_v_flip = true
render_target_clear_mode = 0
render_target_update_mode = 2
audio_listener_enable_2d = false
audio_listener_enable_3d = false
physics_object_picking = false
gui_disable_input = false
gui_snap_controls_to_pixels = true
shadow_atlas_size = 0
shadow_atlas_quad_0 = 2
shadow_atlas_quad_1 = 2
shadow_atlas_quad_2 = 3
shadow_atlas_quad_3 = 4
_sections_unfolded = [ "Audio Listener", "GUI", "Physics", "Render Target", "Rendering", "Shadow Atlas" ]
[node name="Music" parent="jukebox/Viewport" index="0" instance=ExtResource( 14 )]
mouse_filter = 1
mouse_default_cursor_shape = 2
_sections_unfolded = [ "Mouse", "Rect", "Size Flags", "custom_constants" ]
[connection signal="sleeping_state_changed" from="World/Box" to="World/Box" method="_on_Box_sleeping_state_changed"] [connection signal="sleeping_state_changed" from="World/Box" to="World/Box" method="_on_Box_sleeping_state_changed"]

View file

@ -0,0 +1,188 @@
[gd_scene load_steps=8 format=2]
[ext_resource path="res://scenes/Game/jukebox/gui_3d.gd" type="Script" id=1]
[ext_resource path="res://scenes/GUI/MusicControls/MusicControls.tscn" type="PackedScene" id=2]
[sub_resource type="PlaneMesh" id=1]
custom_aabb = AABB( 0, 0, 0, 0, 0, 0 )
size = Vector2( 2, 2 )
subdivide_width = 0
subdivide_depth = 0
[sub_resource type="ViewportTexture" id=2]
resource_local_to_scene = true
flags = 0
viewport_path = NodePath("Viewport")
_sections_unfolded = [ "Resource" ]
[sub_resource type="SpatialMaterial" id=3]
resource_local_to_scene = true
render_priority = 0
flags_transparent = true
flags_unshaded = true
flags_vertex_lighting = false
flags_no_depth_test = false
flags_use_point_size = false
flags_world_triplanar = false
flags_fixed_size = false
flags_albedo_tex_force_srgb = true
vertex_color_use_as_albedo = false
vertex_color_is_srgb = false
params_diffuse_mode = 1
params_specular_mode = 0
params_blend_mode = 0
params_cull_mode = 2
params_depth_draw_mode = 0
params_line_width = 1.0
params_point_size = 1.0
params_billboard_mode = 0
params_grow = false
params_use_alpha_scissor = false
albedo_color = Color( 1, 1, 1, 1 )
albedo_texture = SubResource( 2 )
metallic = 0.0
metallic_specular = 0.5
metallic_texture_channel = 0
roughness = 0.0
roughness_texture_channel = 0
emission_enabled = true
emission = Color( 0, 0, 0, 1 )
emission_energy = 1.0
emission_operator = 0
emission_on_uv2 = false
normal_enabled = false
rim_enabled = false
clearcoat_enabled = false
anisotropy_enabled = false
ao_enabled = false
depth_enabled = false
subsurf_scatter_enabled = false
transmission_enabled = false
refraction_enabled = false
detail_enabled = false
uv1_scale = Vector3( 1, 1, 1 )
uv1_offset = Vector3( 0, 0, 0 )
uv1_triplanar = false
uv1_triplanar_sharpness = 1.0
uv2_scale = Vector3( 1, 1, 1 )
uv2_offset = Vector3( 0, 0, 0 )
uv2_triplanar = false
uv2_triplanar_sharpness = 1.0
proximity_fade_enable = false
distance_fade_enable = false
_sections_unfolded = [ "Albedo", "Flags", "Metallic", "Parameters" ]
[sub_resource type="GDScript" id=4]
script/source = "tool
extends Object
func e():
return 0.01
"
[sub_resource type="BoxShape" id=5]
extents = Vector3( 1, 1, 0.01 )
script = SubResource( 4 )
[node name="Gui_in_3D" type="Spatial"]
script = ExtResource( 1 )
_sections_unfolded = [ "Transform" ]
[node name="Viewport" type="Viewport" parent="." index="0"]
arvr = false
size = Vector2( 256, 256 )
own_world = false
world = null
transparent_bg = true
msaa = 0
hdr = false
disable_3d = false
usage = 0
debug_draw = 0
render_target_v_flip = true
render_target_clear_mode = 0
render_target_update_mode = 2
audio_listener_enable_2d = false
audio_listener_enable_3d = false
physics_object_picking = false
gui_disable_input = false
gui_snap_controls_to_pixels = true
shadow_atlas_size = 0
shadow_atlas_quad_0 = 2
shadow_atlas_quad_1 = 2
shadow_atlas_quad_2 = 3
shadow_atlas_quad_3 = 4
_sections_unfolded = [ "Audio Listener", "GUI", "Physics", "Render Target", "Rendering", "Shadow Atlas" ]
[node name="GUI" type="Control" parent="Viewport" index="0"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 40.0
margin_bottom = 40.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
_sections_unfolded = [ "Mouse", "Rect" ]
[node name="Music" parent="Viewport/GUI" index="0" instance=ExtResource( 2 )]
[node name="Area" type="Area" parent="." index="1"]
input_ray_pickable = true
input_capture_on_drag = true
space_override = 0
gravity_point = false
gravity_distance_scale = 0.0
gravity_vec = Vector3( 0, -1, 0 )
gravity = 9.8
linear_damp = 0.1
angular_damp = 1.0
priority = 0.0
monitoring = true
monitorable = true
collision_layer = 1
collision_mask = 1
audio_bus_override = false
audio_bus_name = "Master"
reverb_bus_enable = false
reverb_bus_name = "Master"
reverb_bus_amount = 0.0
reverb_bus_uniformity = 0.0
_sections_unfolded = [ "Transform" ]
[node name="Quad" type="MeshInstance" parent="Area" index="0"]
transform = Transform( -1, 8.74228e-008, -4.37114e-008, -4.37114e-008, 1.91069e-015, 1, 8.74228e-008, 1, 1.91069e-015, 0, 0, 0 )
layers = 1
material_override = null
cast_shadow = 1
extra_cull_margin = 0.0
use_in_baked_light = false
lod_min_distance = 0.0
lod_min_hysteresis = 0.0
lod_max_distance = 0.0
lod_max_hysteresis = 0.0
mesh = SubResource( 1 )
skeleton = NodePath("..")
material/0 = SubResource( 3 )
_sections_unfolded = [ "Geometry", "Transform", "material" ]
[node name="CollisionShape" type="CollisionShape" parent="Area" index="1"]
shape = SubResource( 5 )
disabled = false
_sections_unfolded = [ "Transform" ]

View file

@ -0,0 +1,25 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scenes/Game/jukebox/Gui_in_3D.tscn" type="PackedScene" id=1]
[node name="JukeboxPannel" type="Spatial"]
[node name="Gui_in_3D" parent="." index="0" instance=ExtResource( 1 )]
[node name="Camera" type="Camera" parent="." index="1"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 2.01693 )
keep_aspect = 1
cull_mask = 1048575
environment = null
h_offset = 0.0
v_offset = 0.0
doppler_tracking = 0
projection = 0
current = false
fov = 70.0
size = 1.0
near = 0.05
far = 100.0

View file

@ -0,0 +1,72 @@
extends Spatial
# Member variables
var prev_pos = null
var last_click_pos = null
var viewport = null
func _input(event):
# Check if the event is a non-mouse event
var is_mouse_event = false
var mouse_events = [InputEventMouseButton, InputEventMouseMotion, InputEventScreenDrag, InputEventScreenTouch]
for mouse_event in mouse_events:
if (event is mouse_event):
is_mouse_event = true
break
# If it is, then pass the event to the viewport
if (is_mouse_event == false):
viewport.input(event)
# Mouse events for Area
func _on_area_input_event(camera, event, click_pos, click_normal, shape_idx):
print("AREA")
# Use click pos (click in 3d space, convert to area space)
var pos = get_node("Area").get_global_transform().affine_inverse()
# the click pos is not zero, then use it to convert from 3D space to area space
if (click_pos.x != 0 or click_pos.y != 0 or click_pos.z != 0):
pos *= click_pos
last_click_pos = click_pos
else:
# Otherwise, we have a motion event and need to use our last click pos
# and move it according to the relative position of the event.
# NOTE: this is not an exact 1-1 conversion, but it's pretty close
pos *= last_click_pos
if (event is InputEventMouseMotion or event is InputEventScreenDrag):
pos.x += event.relative.x / viewport.size.x
pos.y += event.relative.y / viewport.size.y
last_click_pos = pos
# Convert to 2D
pos = Vector2(pos.x, pos.y)
# Convert to viewport coordinate system
# Convert pos to a range from (0 - 1)
pos.y *= -1
pos += Vector2(1, 1)
pos = pos / 2
# Convert pos to be in range of the viewport
pos.x *= viewport.size.x
pos.y *= viewport.size.y
# Set the position in event
event.position = pos
event.global_position = pos
if (prev_pos == null):
prev_pos = pos
if (event is InputEventMouseMotion):
event.relative = pos - prev_pos
prev_pos = pos
# Send the event to the viewport
viewport.input(event)
func _ready():
viewport = get_node("Viewport")
get_node("Area").connect("input_event", self, "_on_area_input_event")

View file

@ -8,7 +8,7 @@ var viewport = null
func _ready(): func _ready():
viewport = get_node("Viewport") viewport = get_node("Viewport")
get_node("JukeBoxArea").connect("input_event", self, "_on_area_input_event") get_node("Area").connect("input_event", self, "_on_area_input_event")
func _input(event): func _input(event):
# Check if the event is a non-mouse event # Check if the event is a non-mouse event
@ -26,9 +26,10 @@ func _input(event):
# Mouse events for Area # Mouse events for Area
func _on_area_input_event(camera, event, click_pos, click_normal, shape_idx): func _on_area_input_event(camera, event, click_pos, click_normal, shape_idx):
print("area")
# Use click pos (click in 3d space, convert to area space) # Use click pos (click in 3d space, convert to area space)
var pos = get_node("JukeBoxArea").get_global_transform().affine_inverse() var pos = get_node("Area").get_global_transform().affine_inverse()
# the click pos is not zero, then use it to convert from 3D space to area space # the click pos is not zero, then use it to convert from 3D space to area space
if (click_pos.x != 0 or click_pos.y != 0 or click_pos.z != 0): if (click_pos.x != 0 or click_pos.y != 0 or click_pos.z != 0):
pos *= click_pos pos *= click_pos
@ -70,9 +71,10 @@ func _on_area_input_event(camera, event, click_pos, click_normal, shape_idx):
func _on_Area_body_entered(body): func _on_Area_body_entered(body):
if get_node( "JukeBoxArea" ) and body.name == "Character": if get_node( "Area" ) and body.name == "Character":
get_node( "JukeBoxArea" ).show() get_node( "Area" ).show()
func _on_Area_body_exited(body): func _on_Area_body_exited(body):
if get_node( "JukeBoxArea" ) and body.name == "Character": if get_node( "Area" ) and body.name == "Character":
get_node( "JukeBoxArea" ).hide() get_node( "Area" ).hide()

File diff suppressed because one or more lines are too long