fixed camera script and restructured ui folder
This commit is contained in:
parent
877ebafc74
commit
5748d34b34
32 changed files with 781 additions and 162 deletions
41
ui/ingame_controls/camera_controls.gd
Normal file
41
ui/ingame_controls/camera_controls.gd
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
extends Control
|
||||
|
||||
var pressed: bool = false
|
||||
var previous_position : Vector2 = Vector2.ZERO
|
||||
var speed : float = 0.5
|
||||
var delta_position: Vector2 = Vector2.ZERO
|
||||
var damping_factor: float = 0.08
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
simulate_joystick_motion(JOY_AXIS_RIGHT_X, delta_position.x * delta * speed, 0)
|
||||
print(delta_position)
|
||||
#delta_position *= 0.92
|
||||
delta_position *= (1 - damping_factor)
|
||||
|
||||
func _gui_input(event: InputEvent) -> void:
|
||||
# Filter touch or drag events only.
|
||||
if event is not InputEventScreenTouch and event is not InputEventScreenDrag:
|
||||
return
|
||||
|
||||
if event is InputEventScreenTouch:
|
||||
if event.is_pressed():
|
||||
previous_position = event.position
|
||||
pressed = true
|
||||
else:
|
||||
pressed = false
|
||||
simulate_joystick_motion(JOY_AXIS_RIGHT_X, 0, 0)
|
||||
previous_position = Vector2.ZERO
|
||||
|
||||
if pressed and event is InputEventScreenDrag:
|
||||
delta_position = clamp(previous_position - event.position, Vector2(-10, -10), Vector2(10, 10))
|
||||
|
||||
# finally update the previous position
|
||||
previous_position = event.position
|
||||
|
||||
func simulate_joystick_motion(axis: int, value: float, device_id: int = 0) -> void:
|
||||
var joystick_event = InputEventJoypadMotion.new()
|
||||
joystick_event.device = device_id
|
||||
joystick_event.axis = axis # Axis index (e.g., 0 for X-axis, 1 for Y-axis)
|
||||
joystick_event.axis_value = value # Value of the axis, typically between -1 and 1
|
||||
|
||||
Input.parse_input_event(joystick_event) # Process the event
|
||||
53
ui/ingame_controls/ingame_controls.gd
Normal file
53
ui/ingame_controls/ingame_controls.gd
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
extends Control
|
||||
class_name IngameControls
|
||||
|
||||
signal menu_button_clicked
|
||||
signal settings_button_clicked
|
||||
signal save_button_clicked
|
||||
signal save_button_released
|
||||
signal save_timer_incremented(value: int)
|
||||
signal save_timer_reached
|
||||
|
||||
var save_button_held_down: bool = false
|
||||
var save_timer: float = 0.0
|
||||
var time_to_save: float = 0.8 # second
|
||||
|
||||
func _process(delta) -> void:
|
||||
if save_button_held_down:
|
||||
if save_timer >= time_to_save:
|
||||
save_timer_reached.emit()
|
||||
save_timer = 0.0
|
||||
|
||||
# Save the game
|
||||
SaveManager.save_game()
|
||||
|
||||
save_button_held_down = false
|
||||
else:
|
||||
save_timer_incremented.emit(ceili((save_timer / time_to_save) * 100))
|
||||
save_timer += delta
|
||||
|
||||
func _on_menu_button_pressed() -> void:
|
||||
menu_button_clicked.emit()
|
||||
|
||||
func _on_settings_button_pressed() -> void:
|
||||
settings_button_clicked.emit()
|
||||
|
||||
# the save function should work as follows:
|
||||
# a percentage sign with 0% should be shown
|
||||
# the player has to hold down the save button
|
||||
# during holding down, the percentage increases until 100%
|
||||
# a finishing animation plays, the game is saved and the countdown disappears again
|
||||
func _on_save_button_button_down() -> void:
|
||||
save_button_held_down = true
|
||||
save_button_clicked.emit()
|
||||
|
||||
func _on_save_button_button_up() -> void:
|
||||
save_button_held_down = false
|
||||
save_button_released.emit()
|
||||
save_timer = 0.0
|
||||
|
||||
func disable_save_button() -> void:
|
||||
%SaveButton.disabled = true
|
||||
|
||||
func enable_save_button() -> void:
|
||||
%SaveButton.disabled = false
|
||||
128
ui/ingame_controls/ingame_controls.tscn
Normal file
128
ui/ingame_controls/ingame_controls.tscn
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
[gd_scene load_steps=11 format=3 uid="uid://1anjhvi173g3"]
|
||||
|
||||
[ext_resource type="Script" path="res://ui/ingame_controls/ingame_controls.gd" id="1_iw1sp"]
|
||||
[ext_resource type="Texture2D" uid="uid://2vxx2waofxpw" path="res://assets/textures/Xbox Series/Vector/xbox_button_menu_outline.svg" id="1_wr5sh"]
|
||||
[ext_resource type="Script" path="res://ui/ingame_controls/joystick.gd" id="2_pyri2"]
|
||||
[ext_resource type="Texture2D" uid="uid://8anyvhkcy4ng" path="res://assets/textures/Xbox Series/Vector/xbox_button_a.svg" id="3_lgi8v"]
|
||||
[ext_resource type="Texture2D" uid="uid://cbep021ykpb23" path="res://assets/textures/Game Icons/Vector/2x/save.png" id="5_2pil1"]
|
||||
[ext_resource type="Texture2D" uid="uid://bwyoxxotdisyp" path="res://assets/textures/Game Icons/Vector/2x/gear.png" id="5_nwwsc"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_uoef2"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_nfkty"]
|
||||
bg_color = Color(0, 0, 0, 0.196078)
|
||||
corner_radius_top_left = 999
|
||||
corner_radius_top_right = 999
|
||||
corner_radius_bottom_right = 999
|
||||
corner_radius_bottom_left = 999
|
||||
corner_detail = 12
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_hfsbq"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_x4icw"]
|
||||
|
||||
[node name="IngameControls" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 12
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("1_iw1sp")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 12
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -338.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
theme_override_constants/margin_left = 30
|
||||
theme_override_constants/margin_right = 30
|
||||
theme_override_constants/margin_bottom = 30
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 8
|
||||
alignment = 2
|
||||
|
||||
[node name="Left" type="VBoxContainer" parent="MarginContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/separation = 8
|
||||
alignment = 2
|
||||
|
||||
[node name="MenuButton" type="Button" parent="MarginContainer/HBoxContainer/Left"]
|
||||
self_modulate = Color(0, 0, 0, 0.392157)
|
||||
custom_minimum_size = Vector2(120, 120)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
theme_override_styles/focus = SubResource("StyleBoxEmpty_uoef2")
|
||||
icon = ExtResource("1_wr5sh")
|
||||
flat = true
|
||||
expand_icon = true
|
||||
|
||||
[node name="JoystickPanel" type="Panel" parent="MarginContainer/HBoxContainer/Left"]
|
||||
custom_minimum_size = Vector2(180, 180)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 0
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_nfkty")
|
||||
script = ExtResource("2_pyri2")
|
||||
|
||||
[node name="Thumbstick" type="TextureRect" parent="MarginContainer/HBoxContainer/Left/JoystickPanel"]
|
||||
self_modulate = Color(0, 0, 0, 0.392157)
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -65.0
|
||||
offset_top = -65.0
|
||||
offset_right = 65.0
|
||||
offset_bottom = 65.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("3_lgi8v")
|
||||
expand_mode = 3
|
||||
stretch_mode = 5
|
||||
|
||||
[node name="Right" type="VBoxContainer" parent="MarginContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 8
|
||||
theme_override_constants/separation = 0
|
||||
alignment = 2
|
||||
|
||||
[node name="SaveButton" type="Button" parent="MarginContainer/HBoxContainer/Right"]
|
||||
unique_name_in_owner = true
|
||||
self_modulate = Color(0, 0, 0, 0.392157)
|
||||
custom_minimum_size = Vector2(120, 120)
|
||||
layout_mode = 2
|
||||
theme_override_styles/focus = SubResource("StyleBoxEmpty_hfsbq")
|
||||
icon = ExtResource("5_2pil1")
|
||||
flat = true
|
||||
icon_alignment = 1
|
||||
expand_icon = true
|
||||
|
||||
[node name="SettingsButton" type="Button" parent="MarginContainer/HBoxContainer/Right"]
|
||||
self_modulate = Color(0, 0, 0, 0.392157)
|
||||
custom_minimum_size = Vector2(120, 120)
|
||||
layout_mode = 2
|
||||
theme_override_styles/focus = SubResource("StyleBoxEmpty_x4icw")
|
||||
icon = ExtResource("5_nwwsc")
|
||||
flat = true
|
||||
icon_alignment = 1
|
||||
expand_icon = true
|
||||
|
||||
[connection signal="pressed" from="MarginContainer/HBoxContainer/Left/MenuButton" to="." method="_on_menu_button_pressed"]
|
||||
[connection signal="gui_input" from="MarginContainer/HBoxContainer/Left/JoystickPanel" to="MarginContainer/HBoxContainer/Left/JoystickPanel" method="_on_gui_input"]
|
||||
[connection signal="resized" from="MarginContainer/HBoxContainer/Left/JoystickPanel" to="MarginContainer/HBoxContainer/Left/JoystickPanel" method="_on_resized"]
|
||||
[connection signal="button_down" from="MarginContainer/HBoxContainer/Right/SaveButton" to="." method="_on_save_button_button_down"]
|
||||
[connection signal="button_up" from="MarginContainer/HBoxContainer/Right/SaveButton" to="." method="_on_save_button_button_up"]
|
||||
[connection signal="pressed" from="MarginContainer/HBoxContainer/Right/SettingsButton" to="." method="_on_settings_button_pressed"]
|
||||
69
ui/ingame_controls/joystick.gd
Normal file
69
ui/ingame_controls/joystick.gd
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
extends Panel
|
||||
|
||||
@onready var talk_a_texture = preload("res://assets/textures/Xbox Series/Vector/xbox_button_a.svg")
|
||||
@onready var drag_texture = preload("res://assets/textures/Generic/Vector/generic_button_circle.svg")
|
||||
@onready var thumbstick = $Thumbstick
|
||||
var thumbstick_size_factor = 0.5
|
||||
|
||||
|
||||
var middle: Vector2 = Vector2(100, 100)
|
||||
var touch_start: Vector2 = Vector2(0, 0)
|
||||
var jump_threshold: float = 10.0
|
||||
var delta: float = 0.0
|
||||
var pressed: bool = false
|
||||
|
||||
# debug rotation
|
||||
var rotation_delta: Vector2 = Vector2(0, 0)
|
||||
|
||||
func _ready() -> void:
|
||||
#thumbstick.custom_minimum_size = Vector2(size.x, size.x) * thumbstick_size_factor
|
||||
thumbstick.position = middle - thumbstick.size / 2.0
|
||||
|
||||
func _on_gui_input(event: InputEvent) -> void:
|
||||
if event is not InputEventScreenTouch and event is not InputEventScreenDrag:
|
||||
return
|
||||
|
||||
if event.is_pressed() == false:
|
||||
simulate_joystick_motion(JOY_AXIS_LEFT_X, Vector2.ZERO.x)
|
||||
simulate_joystick_motion(JOY_AXIS_LEFT_Y, Vector2.ZERO.y)
|
||||
thumbstick.position = middle - thumbstick.size / 2.0
|
||||
thumbstick.texture = talk_a_texture
|
||||
|
||||
if event is InputEventScreenTouch and pressed == true:
|
||||
Input.action_press("ui_select")
|
||||
pressed = false
|
||||
|
||||
if event is InputEventScreenTouch and event.is_pressed():
|
||||
pressed = true
|
||||
|
||||
if event is InputEventScreenDrag:
|
||||
# cancel the talking action
|
||||
pressed = false
|
||||
# swap to drag texture
|
||||
thumbstick.texture = drag_texture
|
||||
|
||||
var touch_position = event.position
|
||||
|
||||
# visual thumbstick movement
|
||||
var thumbstick_position = touch_position - thumbstick.size / 2.0
|
||||
#var clamped_thumbstick_position = thumbstick_position.clampf(-40.0, 40.0)
|
||||
thumbstick.position = thumbstick_position
|
||||
|
||||
# actual value
|
||||
var _delta = middle - touch_position
|
||||
var direction = _delta.normalized()
|
||||
simulate_joystick_motion(JOY_AXIS_LEFT_X, -direction.x)
|
||||
simulate_joystick_motion(JOY_AXIS_LEFT_Y, -direction.y)
|
||||
|
||||
func simulate_joystick_motion(axis: int, value: float, device_id: int = 0) -> void:
|
||||
var joystick_event = InputEventJoypadMotion.new()
|
||||
joystick_event.device = device_id
|
||||
joystick_event.axis = axis # Axis index (e.g., 0 for X-axis, 1 for Y-axis)
|
||||
joystick_event.axis_value = value # Value of the axis, typically between -1 and 1
|
||||
|
||||
Input.parse_input_event(joystick_event) # Process the event
|
||||
|
||||
func _on_resized() -> void:
|
||||
middle = size / 2.0
|
||||
thumbstick = get_node("Thumbstick")
|
||||
thumbstick.position = middle - thumbstick.size / 2.0
|
||||
Loading…
Add table
Add a link
Reference in a new issue