Update input actions and UI layout

Added new input actions for movement and actions in project.godot. Adjusted UI element positions, visibility, and sizing in main.tscn. Added a temporary scene file and updated player.gd.
This commit is contained in:
2025-11-04 11:33:54 +08:00
parent cd22925449
commit b27b612989
4 changed files with 10171 additions and 15 deletions
+51
View File
@@ -44,3 +44,54 @@ put_item={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194326,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
move_northwest={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":81,"location":0,"echo":false,"script":null)
]
}
move_north={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":87,"location":0,"echo":false,"script":null)
]
}
move_northeast={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
]
}
move_west={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
]
}
move_east={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
]
}
move_southwest={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null)
]
}
move_south={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null)
]
}
move_southeast={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":67,"key_label":0,"unicode":99,"location":0,"echo":false,"script":null)
]
}
action_grab={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
]
}
action_put={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":83,"location":0,"echo":false,"script":null)
]
}
+20 -14
View File
@@ -55,7 +55,7 @@ current = true
fov = 35.5
[node name="Camera3D200" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 7, 15, 7)
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 7, 15, 6.35926)
environment = ExtResource("4_ky38j")
projection = 1
current = true
@@ -66,10 +66,10 @@ size = 23.0
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
offset_left = 47.0
offset_top = -137.0
offset_right = 183.0
offset_bottom = -84.0
offset_left = 1208.0
offset_top = 280.0
offset_right = 1344.0
offset_bottom = 333.0
grow_vertical = 2
theme_override_styles/panel = ExtResource("5_dvx6y")
@@ -92,14 +92,14 @@ vertical_alignment = 1
[node name="PlayerboardUI" type="GridContainer" parent="."]
clip_contents = true
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_left = 40.0
offset_top = -232.0
offset_right = 236.0
offset_bottom = -36.0
grow_vertical = 0
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
offset_left = 32.0
offset_top = -104.0
offset_right = 228.0
offset_bottom = 92.0
grow_vertical = 2
size_flags_horizontal = 3
columns = 5
@@ -960,7 +960,7 @@ anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = -160.0
offset_left = -323.0
offset_top = -384.0
grow_horizontal = 0
grow_vertical = 0
@@ -971,22 +971,27 @@ offset_right = 40.0
offset_bottom = 40.0
[node name="MoveButton" type="Button" parent="ActionMenu/ActionButtonContainer"]
visible = false
layout_mode = 2
text = "Move"
[node name="GrabButton" type="Button" parent="ActionMenu/ActionButtonContainer"]
custom_minimum_size = Vector2(100, 100)
layout_mode = 2
text = "Grab"
[node name="PutButton" type="Button" parent="ActionMenu/ActionButtonContainer"]
custom_minimum_size = Vector2(100, 100)
layout_mode = 2
text = "Put"
[node name="RandomizeButton" type="Button" parent="ActionMenu/ActionButtonContainer"]
visible = false
layout_mode = 2
text = "Randomize"
[node name="ArrangeButton" type="Button" parent="ActionMenu/ActionButtonContainer"]
visible = false
layout_mode = 2
text = "Arrange"
@@ -1035,6 +1040,7 @@ theme_override_styles/normal = ExtResource("5_dvx6y")
text = "Join"
[node name="MessageInput" type="LineEdit" parent="."]
visible = false
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
File diff suppressed because it is too large Load Diff
+91 -1
View File
@@ -464,12 +464,54 @@ func _physics_process(delta):
if current_position in finish_locations and can_finish and not is_player_moving:
start_new_lap()
# --------------------------------------------------------------------
# Input
# --------------------------------------------------------------------
func _unhandled_input(event):
# Early return if not authorized human player
if not is_multiplayer_authority() or is_bot or is_in_group("Bots"):
set_process_unhandled_input(false)
return
var main = get_node("/root/Main")
# --- Real-time Keyboard/Touch Input ---
if not main.turn_based_mode and not is_player_moving:
var target_position = current_position
var input_handled = true
if Input.is_action_just_pressed("move_north"):
target_position += Vector2i(0, -1)
elif Input.is_action_just_pressed("move_northeast"):
target_position += Vector2i(1, -1)
elif Input.is_action_just_pressed("move_east"):
target_position += Vector2i(1, 0)
elif Input.is_action_just_pressed("move_southeast"):
target_position += Vector2i(1, 1)
elif Input.is_action_just_pressed("move_south"):
target_position += Vector2i(0, 1)
elif Input.is_action_just_pressed("move_southwest"):
target_position += Vector2i(-1, 1)
elif Input.is_action_just_pressed("move_west"):
target_position += Vector2i(-1, 0)
elif Input.is_action_just_pressed("move_northwest"):
target_position += Vector2i(-1, -1)
elif Input.is_action_just_pressed("action_grab"):
grab_item(current_position) # Try to grab from current position [cite: 59]
elif Input.is_action_just_pressed("action_put"):
auto_put_item()
else:
input_handled = false # No relevant key was pressed
if target_position != current_position:
simple_move_to(target_position)
if input_handled:
get_viewport().set_input_as_handled() # Consume the event
return # Don't process turn-based or spawn logic
# --- End Real-time Input ---
# Handle spawn point selection if not yet selected
if not spawn_point_selected and highlighted_spawn_points.size() > 0:
if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
@@ -483,10 +525,10 @@ func _unhandled_input(event):
return # Spawn point selected successfully
# Use get_node_or_null for safer node access
var main = get_tree().get_root().get_node_or_null("Main")
if not main:
return
# Turn-based mouse input
if not is_multiplayer_authority() or (main.turn_based_mode and (not is_my_turn or is_player_moving)):
return
@@ -695,6 +737,54 @@ func is_within_movement_range(target_position: Vector2i) -> bool:
distance = abs(target_position.x - current_position.x) + abs(target_position.y - current_position.y)
return distance <= movement_range
# -----------------------------------------------------------------
# Movement
# -----------------------------------------------------------------
func simple_move_to(grid_position: Vector2i):
if not is_multiplayer_authority() or is_player_moving:
return
# Check if target is within 1-tile range
var distance: int
if use_diagonal_movement:
distance = max(abs(grid_position.x - current_position.x), abs(grid_position.y - current_position.y))
else:
distance = abs(grid_position.x - current_position.x) + abs(grid_position.y - current_position.y)
if distance != 1:
return # Only single-step moves allowed
# Check for finish line
if grid_position in finish_locations:
if not can_finish:
can_finish = check_pattern_match()
if not can_finish:
return # Cannot move to finish line
var is_valid_finish = grid_position in finish_locations if current_lap == 0 else grid_position in spawn_locations
# Check walkability and obstacles
var cell_item = enhanced_gridmap.get_cell_item(Vector3i(grid_position.x, 0, grid_position.y))
if cell_item in enhanced_gridmap.non_walkable_items or is_position_occupied(grid_position):
return
if enhanced_gridmap.is_blocked_by_obstacle(current_position, grid_position, 3):
return
# All checks passed, perform move
rotate_towards_target(grid_position)
var path = [Vector2(current_position.x, current_position.y), Vector2(grid_position.x, grid_position.y)]
path.pop_front()
# Use the existing RPC to move
rpc("start_movement_along_path", path, not (is_bot or is_in_group("Bots")))
# Handle finish line crossing
if is_valid_finish and can_finish:
rpc("finish_race")
func move_player_to_clicked_position(grid_position: Vector2i):
if not is_multiplayer_authority() or is_player_moving or action_points <= 0: