divres tests et correction du probleme de focus permanent du hud.

This commit is contained in:
osquallo 2018-07-30 09:08:39 +02:00
parent 561877739f
commit 4ac8000762
14 changed files with 230 additions and 54 deletions

View file

@ -22,8 +22,7 @@ func _on_Home_play_pressed():
play()
func _input(event):
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED and event is InputEventKey:
accept_event()
if event.is_action_pressed("ui_test"):
print( "Event: ui_test" )
@ -48,7 +47,20 @@ func _input(event):
# else:
# Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
# ----------------------------------
# Si on est en mode "deplacement", on desative le focus sur l'interface
# afin de ne pas naviguer dedans en même temps que l'on agit en jeu.
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
recursive_release_focus( self )
func recursive_release_focus( control ):
if control is Control:
if len(control.get_children()) > 0:
for child in control.get_children():
recursive_release_focus( child )
# if control.has_method( "release_focus" ):
control.release_focus()
func pause():
get_tree().paused = true
show_menu()

View file

@ -19,7 +19,7 @@ _sections_unfolded = [ "Font", "Settings" ]
default_font = SubResource( 1 )
[node name="GUI" type="MarginContainer"]
[node name="GUI" type="MarginContainer" index="0"]
anchor_left = 0.0
anchor_top = 0.0
@ -27,7 +27,7 @@ anchor_right = 1.0
anchor_bottom = 1.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 0
mouse_filter = 1
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
@ -36,7 +36,7 @@ custom_constants/margin_top = 4
custom_constants/margin_left = 4
custom_constants/margin_bottom = 4
script = ExtResource( 1 )
_sections_unfolded = [ "Margin", "Size Flags", "Theme", "custom_constants" ]
_sections_unfolded = [ "Margin", "Mouse", "Size Flags", "Theme", "custom_constants" ]
[node name="HUD" parent="." index="0" instance=ExtResource( 2 )]
@ -59,7 +59,8 @@ margin_left = 4.0
margin_top = 4.0
margin_right = 1020.0
margin_bottom = 596.0
_sections_unfolded = [ "Margin", "Size Flags", "Visibility", "custom_constants" ]
mouse_filter = 1
_sections_unfolded = [ "Margin", "Mouse", "Size Flags", "Visibility", "custom_constants" ]
[node name="Settings" parent="." index="2" instance=ExtResource( 5 )]
@ -70,7 +71,8 @@ margin_left = 4.0
margin_top = 4.0
margin_right = 1020.0
margin_bottom = 596.0
_sections_unfolded = [ "Margin", "Size Flags", "Theme", "custom_constants" ]
mouse_filter = 1
_sections_unfolded = [ "Margin", "Mouse", "Size Flags", "Theme", "custom_constants" ]
[node name="Help" parent="." index="3" instance=ExtResource( 6 )]
@ -78,6 +80,7 @@ margin_left = 4.0
margin_top = 4.0
margin_right = 89.0
margin_bottom = 86.0
_sections_unfolded = [ "Margin", "Mouse", "Size Flags", "custom_constants" ]
[connection signal="play_pressed" from="Home" to="." method="_on_Home_play_pressed"]

View file

@ -29,11 +29,13 @@ func _on_SaveHUD_pressed():
config_file.save( HUD_config_file )
func _on_Windows_gui_input( event ):
if event is InputEventMouseButton \
and Input.get_mouse_mode() == Input.MOUSE_MODE_VISIBLE \
and event.is_action_pressed( "ui_free_cursor" ):
Input.set_mouse_mode( Input.MOUSE_MODE_CAPTURED )
elif event is InputEventMouseButton \
and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED \

View file

@ -33,6 +33,7 @@ _sections_unfolded = [ "Margin", "Mouse", "Rect", "Size Flags", "Theme", "Visibi
[node name="overlay_oubli" type="Panel" parent="." index="0"]
visible = false
modulate = Color( 0, 0, 0, 0 )
anchor_left = 0.0
anchor_top = 0.0

View file

@ -16,7 +16,7 @@ margin_bottom = 86.0
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false
mouse_filter = 1
mouse_default_cursor_shape = 2
mouse_default_cursor_shape = 0
size_flags_horizontal = 1
size_flags_vertical = 1
alignment = 0

View file

@ -22,7 +22,7 @@ func _ready():
camera = $Camera_rotation_helper/Camera
camera.make_current()
flashlight = $MeshInstance/Flashlight
func _process(delta):
process_input(delta)
process_movement(delta)
@ -34,10 +34,10 @@ func process_input(delta):
# Walking
dir = Vector3()
var cam_xform = camera.get_global_transform()
var input_movement_vector = Vector3()
var cam_scroll = 0.0
if Input.is_action_pressed("move_up"):
input_movement_vector.z += 1
if Input.is_action_pressed("move_down"):
@ -46,12 +46,12 @@ func process_input(delta):
input_movement_vector.x -= 1
if Input.is_action_pressed("move_right"):
input_movement_vector.x += 1
input_movement_vector = input_movement_vector.normalized()
dir += -cam_xform.basis.z.normalized() * input_movement_vector.z
dir += cam_xform.basis.x.normalized() * input_movement_vector.x
if Input.is_action_pressed("fly_up"):
vel.y = FLY_SPEED
elif Input.is_action_pressed("fly_down"):
@ -60,27 +60,27 @@ func process_input(delta):
vel.y = 0
func process_movement(delta):
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
dir.y = 0
dir = dir.normalized()
# vel.y += delta*GRAVITY
var hvel = vel
hvel.y = 0
var target = dir
target *= MAX_SPEED
var accel
if dir.dot(hvel) > 0:
accel = ACCEL
else:
accel = DEACCEL
hvel = hvel.linear_interpolate(target, accel*delta)
vel.x = hvel.x
vel.z = hvel.z
@ -99,39 +99,41 @@ func process_movement(delta):
get_node( "../../GUI/HUD/Jauges/trauma/ProgressBar" ).value += 0.25
if get_node( "../../GUI/HUD/Jauges/trauma/ProgressBar" ).value >= 100:
get_node( "../../GUI/HUD/Jauges/oubli/ProgressBar" ).value += 0.25
func _input(event):
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
if event is InputEventMouseMotion :
camera_rotation.rotate_x(deg2rad(event.relative.y * MOUSE_SENSITIVITY * -1))
self.rotate_y(deg2rad(event.relative.x * MOUSE_SENSITIVITY * -1))
var camera_rot = camera_rotation.rotation_degrees
camera_rot.x = clamp(camera_rot.x, -30, 30)
camera_rotation.rotation_degrees = camera_rot
if event is InputEventMouseButton:
# to prevent the cam sliding effect when clamp limit reached.
var old_x_translation = camera.translation.x
var old_y_translation = camera.translation.y
var cam_scroll = Vector3( 0.0, 0.0, 0.0 )
if event.button_index == BUTTON_WHEEL_UP:
cam_scroll.z = -1.0 * MOUSE_SENSITIVITY
if event.button_index == BUTTON_WHEEL_DOWN:
cam_scroll.z = 1.0 * MOUSE_SENSITIVITY
camera.translate( cam_scroll )
camera.translation.x = old_x_translation
camera.translation.y = old_y_translation
camera.translation.z = clamp(camera.translation.z, 0, 5)
# TODO trouver pourquoi cela ne se fait plus:
if Input.is_action_just_pressed("game_flashlight"):
# flashlight.visible = not flashlight.visible
if flashlight.is_visible_in_tree():
flashlight.hide()
else:
@ -139,3 +141,4 @@ func _input(event):
if Input.is_action_pressed( "hide_char" ):
$MeshInstance.visible = not $MeshInstance.visible

View file

@ -79,7 +79,6 @@ material/0 = null
[node name="Flashlight" type="SpotLight" parent="MeshInstance" index="0"]
transform = Transform( 1.74358, 0, 0, 0, 0.999973, 0.0124571, 0, -0.00792279, 1.83077, -0.0756186, 0.00765181, -1.31515 )
visible = false
layers = 1
light_color = Color( 1, 1, 1, 1 )
light_energy = 2.0

143
scenes/Game/Game.gd Normal file
View file

@ -0,0 +1,143 @@
extends Spatial
var dir = Vector3()
const GRAVITY = -24.8
var vel = Vector3()
const MAX_SPEED = 20
const ACCEL= 4.5
const FLY_SPEED = 7
const DEACCEL= 16
const MAX_SLOPE_ANGLE = 40
var camera_rotation
var camera
var flashlight
var MOUSE_SENSITIVITY = 0.05
func _ready():
camera_rotation = $Character/Camera_rotation_helper
camera = $Character/Camera_rotation_helper/Camera
camera.make_current()
flashlight = $Character/MeshInstance/Flashlight
func _process(delta):
process_input(delta)
process_movement(delta)
func process_input(delta):
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
# ----------------------------------
# Walking
dir = Vector3()
var cam_xform = camera.get_global_transform()
var input_movement_vector = Vector3()
var cam_scroll = 0.0
if Input.is_action_pressed("move_up"):
input_movement_vector.z += 1
if Input.is_action_pressed("move_down"):
input_movement_vector.z -= 1
if Input.is_action_pressed("move_left"):
input_movement_vector.x -= 1
if Input.is_action_pressed("move_right"):
input_movement_vector.x += 1
input_movement_vector = input_movement_vector.normalized()
dir += -cam_xform.basis.z.normalized() * input_movement_vector.z
dir += cam_xform.basis.x.normalized() * input_movement_vector.x
if Input.is_action_pressed("fly_up"):
vel.y = FLY_SPEED
elif Input.is_action_pressed("fly_down"):
vel.y = -FLY_SPEED
else:
vel.y = 0
func process_movement(delta):
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
dir.y = 0
dir = dir.normalized()
# vel.y += delta*GRAVITY
var hvel = vel
hvel.y = 0
var target = dir
target *= MAX_SPEED
var accel
if dir.dot(hvel) > 0:
accel = ACCEL
else:
accel = DEACCEL
hvel = hvel.linear_interpolate(target, accel*delta)
vel.x = hvel.x
vel.z = hvel.z
var collision_info = $Character.move_and_collide(vel * delta)
if collision_info:
vel = vel.bounce(collision_info.normal)
var obj = collision_info.collider
if obj.is_class( "RigidBody" ):
obj.sleeping = false
obj.apply_impulse( collision_info.position, -collision_info.normal*delta )
if not obj.get_node( "MeshInstance" ).get_surface_material(0).get("albedo_color") == null:
obj.get_node( "MeshInstance" ).get_surface_material(0).albedo_color = Color( 1, 0, 1, 1 )
$Character.get_node( "../../GUI/HUD/Jauges/douleur/ProgressBar" ).value += 0.25
if $Character.get_node( "../../GUI/HUD/Jauges/douleur/ProgressBar" ).value >= 100:
$Character.get_node( "../../GUI/HUD/Jauges/trauma/ProgressBar" ).value += 0.25
if $Character.get_node( "../../GUI/HUD/Jauges/trauma/ProgressBar" ).value >= 100:
$Character.get_node( "../../GUI/HUD/Jauges/oubli/ProgressBar" ).value += 0.25
func _input(event):
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
if event is InputEventMouseMotion :
camera_rotation.rotate_x(deg2rad(event.relative.y * MOUSE_SENSITIVITY * -1))
$Character.rotate_y(deg2rad(event.relative.x * MOUSE_SENSITIVITY * -1))
var camera_rot = camera_rotation.rotation_degrees
camera_rot.x = clamp(camera_rot.x, -30, 30)
camera_rotation.rotation_degrees = camera_rot
if event is InputEventMouseButton:
# to prevent the cam sliding effect when clamp limit reached.
var old_x_translation = camera.translation.x
var old_y_translation = camera.translation.y
var cam_scroll = Vector3( 0.0, 0.0, 0.0 )
if event.button_index == BUTTON_WHEEL_UP:
cam_scroll.z = -1.0 * MOUSE_SENSITIVITY
if event.button_index == BUTTON_WHEEL_DOWN:
cam_scroll.z = 1.0 * MOUSE_SENSITIVITY
camera.translate( cam_scroll )
camera.translation.x = old_x_translation
camera.translation.y = old_y_translation
camera.translation.z = clamp(camera.translation.z, 0, 5)
# TODO trouver pourquoi cela ne se fait plus:
if Input.is_action_just_pressed("game_flashlight"):
# flashlight.visible = not flashlight.visible
if flashlight.is_visible_in_tree():
flashlight.hide()
else:
flashlight.show()
if Input.is_action_pressed( "hide_char" ):
$MeshInstance.visible = not $MeshInstance.visible

View file

@ -776,7 +776,7 @@ material = SubResource( 26 )
custom_aabb = AABB( 0, 0, 0, 0, 0, 0 )
size = Vector2( 0.4, 0.4 )
[node name="Game" type="Spatial" index="0"]
[node name="Game" type="Spatial"]
_sections_unfolded = [ "Transform" ]
@ -784,6 +784,7 @@ _sections_unfolded = [ "Transform" ]
[node name="World" type="Spatial" parent="." index="1"]
editor/display_folded = true
_sections_unfolded = [ "Transform", "Visibility" ]
[node name="Terrain" parent="World" index="0" instance=ExtResource( 2 )]

View file

@ -138,6 +138,7 @@ _sections_unfolded = [ "Albedo", "Flags" ]
[node name="Floor" type="StaticBody" parent="." index="0"]
editor/display_folded = true
input_ray_pickable = true
input_capture_on_drag = false
collision_layer = 1
@ -172,6 +173,7 @@ disabled = false
[node name="Ceilling" type="StaticBody" parent="." index="1"]
editor/display_folded = true
transform = Transform( 1, 0, 0, 0, -0.984809, -0.173641, 0, 0.173641, -0.984809, 0, 20, 0 )
input_ray_pickable = true
input_capture_on_drag = false
@ -208,6 +210,7 @@ disabled = false
[node name="Wall1" type="StaticBody" parent="." index="2"]
editor/display_folded = true
transform = Transform( -4.37114e-008, 1, 0, -1, -4.37114e-008, 0, 0, 0, 1, -10, 10, 0 )
input_ray_pickable = true
input_capture_on_drag = false
@ -245,6 +248,7 @@ _sections_unfolded = [ "Transform" ]
[node name="Wall2" type="StaticBody" parent="." index="3"]
editor/display_folded = true
transform = Transform( -4.37114e-008, -1, 0, 1, -4.37114e-008, 0, 0, 0, 1, 10, 10, 0 )
input_ray_pickable = true
input_capture_on_drag = false
@ -281,6 +285,7 @@ disabled = false
[node name="Wall3" type="StaticBody" parent="." index="4"]
editor/display_folded = true
transform = Transform( 1.91069e-015, 4.37114e-008, 1, 1, -4.37114e-008, 0, 4.37114e-008, 1, -4.37114e-008, 0, 10, -10 )
input_ray_pickable = true
input_capture_on_drag = false
@ -317,6 +322,7 @@ disabled = false
[node name="Wall4" type="StaticBody" parent="." index="5"]
editor/display_folded = true
transform = Transform( 1.91069e-015, 4.37114e-008, -1, 1, -4.37114e-008, 0, -4.37114e-008, -1, -4.37114e-008, 0, 10, 10 )
input_ray_pickable = true
input_capture_on_drag = false

View file

@ -138,6 +138,8 @@ _sections_unfolded = [ "Mouse", "Rect" ]
[node name="Music" parent="Viewport/GUI" index="0" instance=ExtResource( 2 )]
mouse_default_cursor_shape = 0
[node name="Area" type="Area" parent="." index="1"]
input_ray_pickable = true

View file

@ -6,20 +6,4 @@
[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

@ -96,12 +96,16 @@ params_grow = false
params_use_alpha_scissor = false
albedo_color = Color( 1, 1, 1, 1 )
albedo_texture = ExtResource( 1 )
metallic = 0.5
metallic_specular = 0.5
metallic = 1.0
metallic_specular = 1.0
metallic_texture_channel = 0
roughness = 0.0
roughness_texture_channel = 0
emission_enabled = false
emission_enabled = true
emission = Color( 0.742188, 0.400085, 0, 1 )
emission_energy = 1.0
emission_operator = 0
emission_on_uv2 = false
normal_enabled = false
rim_enabled = false
clearcoat_enabled = false
@ -122,7 +126,7 @@ uv2_triplanar = false
uv2_triplanar_sharpness = 1.0
proximity_fade_enable = false
distance_fade_enable = false
_sections_unfolded = [ "Albedo", "Metallic" ]
_sections_unfolded = [ "Albedo", "Emission", "Flags", "Metallic", "Roughness", "Vertex Color" ]
[sub_resource type="ConvexPolygonShape" id=4]
@ -328,4 +332,20 @@ disabled = false
transform = Transform( 0.038434, -0.172056, 0.984337, 0.00671291, 0.985087, 0.171925, -0.999239, 0, 0.0390158, 0.536377, 2.51347, 0 )
[node name="Camera" type="Camera" parent="." index="3"]
transform = Transform( 0.718383, 0, 0.695648, 0, 1, 0, -0.695648, 0, 0.718383, 2.63256, 2.80749, 1.31678 )
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

@ -14,6 +14,6 @@ _sections_unfolded = [ "Pause" ]
[node name="GUI" parent="." index="1" instance=ExtResource( 3 )]
pause_mode = 2
_sections_unfolded = [ "Margin", "Pause", "Rect", "Size Flags", "Theme", "custom_constants" ]
_sections_unfolded = [ "Margin", "Mouse", "Pause", "Rect", "Size Flags", "Theme", "custom_constants" ]