Skip to content

Commit

Permalink
ReadableComponent gamepad scrolling support added.
Browse files Browse the repository at this point in the history
ReadableComponent:
- added support to scroll readables with the gamepad right thumbstick.
  • Loading branch information
Phazorknight committed Jul 9, 2024
1 parent d6204aa commit 10c71a7
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 95 deletions.
2 changes: 2 additions & 0 deletions COGITO/Components/Interactions/ReadableComponent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ signal has_been_read

var is_open : bool


func _ready():
readable_ui.hide()
is_open = false
Expand All @@ -38,6 +39,7 @@ func open(_player_interaction_component: PlayerInteractionComponent):
has_been_read.emit()
is_open = true


func close(_player_interaction_component: PlayerInteractionComponent):
readable_ui.hide()
_player_interaction_component.get_parent().menu_pressed.disconnect(close)
Expand Down
18 changes: 15 additions & 3 deletions COGITO/Components/Interactions/ReadableComponent.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

[node name="ReadableComponent" type="Node3D"]
script = ExtResource("1_6uwtb")
readable_title = "Testomania"
readable_content = "COGITO is a first Person Immersive Sim Template Project for Godot Engine 4. In comparison to other first person assets out there, which focus mostly on shooter mechanics, COGITO focuses more on providing a framework for creating interactable objects and items."
readable_title = "Test Readable Example"
readable_content = "COGITO is a first Person Immersive Sim Template Project for Godot Engine 4. In comparison to other first person assets out there, which focus mostly on shooter mechanics, COGITO focuses more on providing a framework for creating interactable objects and items.
This text is a placeholder, showing how a readable object would work. It is recommended to make a copy of the readable component and then modify the copy to your liking.
This UI is included and makes use of the COGITO theme. You can also make several different ReadableComponents for different document types, each with their own theme applied, for example: letters, text messages on phone displays, computer screens, tablets, signs, etc."
input_map_action = "interact"
interaction_text = "Read"

Expand Down Expand Up @@ -58,6 +62,8 @@ theme_override_constants/margin_bottom = 25
custom_minimum_size = Vector2(450, 0)
layout_mode = 2
size_flags_horizontal = 4
follow_focus = true
horizontal_scroll_mode = 0
script = ExtResource("3_aj2s3")
transition_time = 0.15

Expand All @@ -69,6 +75,8 @@ theme_override_constants/separation = 15
[node name="ReadableTitle" type="Label" parent="ReadableUi/Bindings/ScrollContainer/VBoxContainer"]
custom_minimum_size = Vector2(450, 0)
layout_mode = 2
focus_neighbor_bottom = NodePath("../ReadableContent")
focus_mode = 2
theme_override_font_sizes/font_size = 35
text = "This is a readable. Title can even be longer."
horizontal_alignment = 1
Expand All @@ -80,5 +88,9 @@ theme_override_constants/separation = 10

[node name="ReadableContent" type="RichTextLabel" parent="ReadableUi/Bindings/ScrollContainer/VBoxContainer"]
layout_mode = 2
text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
focus_neighbor_top = NodePath("../ReadableTitle")
focus_mode = 2
text = "This text is a placeholder, showing how a readable object would work. It is recommended to make a copy of the readable component and then modify the copy to your liking.
This UI is included and makes use of the COGITO theme. You can also make several different ReadableComponents for different document types, each with their own theme applied, for example: letters, text messages on phone displays, computer screens, tablets, signs, etc."
fit_content = true
8 changes: 7 additions & 1 deletion COGITO/DemoScenes/DemoPrefabs/note_welcome.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ shape = SubResource("BoxShape3D_mqvc0")
[node name="ReadableComponent" parent="." instance=ExtResource("2_cwsfv")]
interact_sound = ExtResource("3_lxhi0")
readable_title = "Welcome to the LOBBY"
readable_content = "This scene is still under construction, but feel free to explore what's there."
readable_content = "This scene is still under construction, but feel free to explore what's there.
COGITO is a first Person Immersive Sim Template Project for Godot Engine 4. In comparison to other first person assets out there, which focus mostly on shooter mechanics, COGITO focuses more on providing a framework for creating interactable objects and items.
This text is a placeholder, showing how a readable object would work. It is recommended to make a copy of the readable component and then modify the copy to your liking.
This UI is included and makes use of the COGITO theme. You can also make several different ReadableComponents for different document types, each with their own theme applied, for example: letters, text messages on phone displays, computer screens, tablets, signs, etc."
17 changes: 16 additions & 1 deletion COGITO/EasyMenus/Scripts/follow_focus_center.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ extends ScrollContainer
var scrollable : Control
@export var animate = true
@export var transition_time = 0.2

@export var gamepad_scroll_speed : int = 5
@export var gamepad_scroll_deadzone : float = 0.1
var _last_input_event
var gamepad_scroll : float = 0


func _ready():
scrollable = get_child(0)
get_viewport().gui_focus_changed.connect(focus_changed)


func _get_position_relative_to_control(a: Control, b: Control) -> Vector2:
return b.get_global_rect().position - a.get_global_rect().position


func focus_changed(focus: Control):
if _last_input_event is InputEventMouseButton:
return
Expand All @@ -26,3 +31,13 @@ func focus_changed(focus: Control):

func _input(event):
_last_input_event = event

# Checking Analog stick input for mouse look
if event is InputEventJoypadMotion:
if event.get_axis() == 3:
gamepad_scroll = event.get_axis_value()


func _process(delta: float) -> void:
if abs(gamepad_scroll) > abs(gamepad_scroll_deadzone):
scroll_vertical = scroll_vertical + gamepad_scroll_speed * gamepad_scroll
Loading

0 comments on commit 10c71a7

Please sign in to comment.