Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion CogsPartyLauncher/scenes/main.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=28 format=3 uid="uid://k31chn02rvs2"]
[gd_scene load_steps=32 format=3 uid="uid://k31chn02rvs2"]

[ext_resource type="Theme" uid="uid://036n6qd3ik2g" path="res://assets/theme.tres" id="1_erdau"]
[ext_resource type="Script" uid="uid://du6vnjc42pp0f" path="res://scripts/main_menu.gd" id="2_6njpl"]
Expand Down Expand Up @@ -94,6 +94,14 @@ corner_radius_top_right = 4
corner_radius_bottom_right = 4
corner_radius_bottom_left = 4

[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_yc10j"]

[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_jscy8"]

[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_pm3ni"]

[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_y6deb"]

[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_muem4"]

[sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_dp3eg"]
Expand Down Expand Up @@ -435,11 +443,40 @@ layout_mode = 2
text = "E D I T"

[node name="GamesFolderSelectFileDialog" type="FileDialog" parent="Menus/MainMenu/VBoxContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/MarginContainer/GamesFolderSelectButton"]
oversampling_override = 1.0
title = "Open a Directory"
ok_button_text = "Select Current Folder"
file_mode = 2
access = 2

[node name="BottomBorder" type="StaticBody2D" parent="Menus/MainMenu/VBoxContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/MarginContainer/GamesFolderSelectButton/GamesFolderSelectFileDialog"]
position = Vector2(599, 638)

[node name="CollisionShape2D" type="CollisionShape2D" parent="Menus/MainMenu/VBoxContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/MarginContainer/GamesFolderSelectButton/GamesFolderSelectFileDialog/BottomBorder"]
shape = SubResource("WorldBoundaryShape2D_yc10j")

[node name="TopBorder" type="StaticBody2D" parent="Menus/MainMenu/VBoxContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/MarginContainer/GamesFolderSelectButton/GamesFolderSelectFileDialog"]
position = Vector2(613, 514)

[node name="CollisionShape2D" type="CollisionShape2D" parent="Menus/MainMenu/VBoxContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/MarginContainer/GamesFolderSelectButton/GamesFolderSelectFileDialog/TopBorder"]
position = Vector2(1, -533)
rotation = 3.1415927
shape = SubResource("WorldBoundaryShape2D_jscy8")

[node name="RightBorder" type="StaticBody2D" parent="Menus/MainMenu/VBoxContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/MarginContainer/GamesFolderSelectButton/GamesFolderSelectFileDialog"]
position = Vector2(1115, 288)
rotation = -1.5707964

[node name="CollisionShape2D" type="CollisionShape2D" parent="Menus/MainMenu/VBoxContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/MarginContainer/GamesFolderSelectButton/GamesFolderSelectFileDialog/RightBorder"]
shape = SubResource("WorldBoundaryShape2D_pm3ni")

[node name="LeftBorder" type="StaticBody2D" parent="Menus/MainMenu/VBoxContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/MarginContainer/GamesFolderSelectButton/GamesFolderSelectFileDialog"]
position = Vector2(-23, 282)
rotation = 1.5707964

[node name="CollisionShape2D" type="CollisionShape2D" parent="Menus/MainMenu/VBoxContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/MarginContainer/GamesFolderSelectButton/GamesFolderSelectFileDialog/LeftBorder"]
shape = SubResource("WorldBoundaryShape2D_y6deb")

[node name="GamesFolderLabel" type="Label" parent="Menus/MainMenu/VBoxContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/MarginContainer"]
layout_mode = 2
size_flags_horizontal = 3
Expand Down
4 changes: 3 additions & 1 deletion CogsPartyLauncher/scripts/main_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ func _on_refresh_games_button_pressed():


func _on_games_folder_select_pressed():
games_folder_select_file_dialog.popup_centered_ratio()
# NOTE: if you change this, you will also need to adjust the WorldBorders containing the cursors
# under the GamesFolderSelectFileDialog
games_folder_select_file_dialog.popup_centered_ratio(0.93)


func _on_games_folder_selected(folder: String):
Expand Down
38 changes: 32 additions & 6 deletions CogsPartyLauncher/scripts/player_cursor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,38 @@ extends CharacterBody2D
@export var speed: float = 30000.0
@export var player_name_label: Label

# unlinked cursors have an ID of -1
var controller_id: int = 0
const DOUBLE_CLICK_THRESHOLD: float = 0.5

var controller_id: int = 0 # unlinked cursors have an id of -1
var file_dialog_cursor: CharacterBody2D # reference to matching cursor in main menus file dialog
var last_click: float # last time the player clicked (double click detection)
var elapsed_time: float = 0.0


func construct(cursor_position: Vector2, id: int):
position = cursor_position
controller_id = id


func get_id() -> int:
return controller_id


func _physics_process(delta):
elapsed_time += delta

if controller_id != -1:
var direction = Input.get_vector(
"left%s" % [controller_id],
"right%s" % [controller_id],
"up%s" % [controller_id],
"down%s" % [controller_id]
)

var rs_strength = abs(Input.get_axis("scroll_down", "scroll_up"))

velocity = direction * speed * delta
move_and_slide()

if Input.is_action_pressed("scroll_up%s" % [controller_id]):
_simulate_scroll(MOUSE_BUTTON_WHEEL_UP, rs_strength)
elif Input.is_action_pressed("scroll_down%s" % [controller_id]):
Expand All @@ -38,20 +47,27 @@ func _physics_process(delta):
func _input(event: InputEvent) -> void:
if controller_id != -1:
if event.is_action_pressed("select%s" % [controller_id]):
_simulate_mouse_click()
if elapsed_time - last_click <= DOUBLE_CLICK_THRESHOLD:
_simulate_mouse_click(true)
last_click = 0
else:
_simulate_mouse_click(false)
last_click = elapsed_time


func _simulate_mouse_click():
func _simulate_mouse_click(double_click: bool):
var click_pos = get_viewport().get_screen_transform() * position

var press = InputEventMouseButton.new()
press.button_index = MOUSE_BUTTON_LEFT
press.double_click = double_click
press.position = click_pos
press.pressed = true
Input.parse_input_event(press)

var release = InputEventMouseButton.new()
release.button_index = MOUSE_BUTTON_LEFT
release.double_click = double_click
release.position = click_pos
release.pressed = false
Input.parse_input_event(release)
Expand All @@ -77,7 +93,17 @@ func _simulate_stop_scroll(direction: MouseButton):

func update_player_label(player_number: int):
player_name_label.text = "P%d" % player_number
if file_dialog_cursor != null:
file_dialog_cursor.update_player_label(player_number)


func update_color(color: Color):
$Sprite2D.modulate = color
if file_dialog_cursor != null:
file_dialog_cursor.update_color(color)


func update_id(id: int):
controller_id = id
if file_dialog_cursor != null:
file_dialog_cursor.update_id(id)
53 changes: 38 additions & 15 deletions CogsPartyLauncher/scripts/player_select_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func _ready():
_update_add_player_button()
_get_non_ui_controls()


for device in Input.get_connected_joypads():
_add_controls(device)
_on_add_player_button_pressed()
Expand Down Expand Up @@ -155,17 +156,7 @@ func _on_player_count_changed():


func _on_add_player_button_pressed():
var main = get_tree().current_scene
var player_cursor = player_cursor_prefab.instantiate() as CharacterBody2D
var id = _get_next_id()
_add_taken_id(id)
player_cursor.construct(
Vector2(randi_range(476,676), randi_range(224,424)),
id
)
player_cursors.append(player_cursor)
main.add_child.call_deferred(player_cursor)

var player_cursor = _create_new_cursor()

var inst = player_setting_prefab.instantiate() as PlayerSetting
player_setting_container.add_child(inst)
Expand All @@ -178,6 +169,7 @@ func _on_add_player_button_pressed():
_get_next_available_color_or_self()
)
player_settings.append(inst)
_create_file_dialog_cursor(player_cursor)
_on_player_count_changed()


Expand All @@ -191,10 +183,12 @@ func _on_player_setting_removed(player_setting: PlayerSetting):
else:
pass # next_focus_control.grab_focus()

# delete cursor
_remove_taken_id(player_setting.player_cursor.controller_id)
# delete cursor and its file dialog duplicate
_remove_taken_id(player_setting.player_cursor.get_id())
player_cursors.erase(player_setting.player_cursor)
player_setting.player_cursor.file_dialog_cursor.queue_free()
player_setting.player_cursor.queue_free()


player_setting_container.remove_child(player_setting)
player_setting.queue_free()
Expand All @@ -203,6 +197,35 @@ func _on_player_setting_removed(player_setting: PlayerSetting):
_on_player_count_changed()


func _create_new_cursor() -> CharacterBody2D:
var player_cursor = player_cursor_prefab.instantiate() as CharacterBody2D
var id = _get_next_id()
_add_taken_id(id)

player_cursor.construct(
Vector2(randi_range(476,676), randi_range(224,424)),
id
)
player_cursors.append(player_cursor)
get_tree().current_scene.add_child.call_deferred(player_cursor)
return player_cursor


func _create_file_dialog_cursor(player_cursor: CharacterBody2D):
var file_dialog_cursor = player_cursor.duplicate()
var main_menu = get_tree().current_scene.find_child("Menus").find_child("MainMenu")

# gives the original player cursor a reference to the duplicate used in the file dialog
player_cursor.file_dialog_cursor = file_dialog_cursor

file_dialog_cursor.construct(
Vector2(randi_range(476,676), randi_range(224,424)),
player_cursor.get_id()
)
if main_menu != null:
main_menu.games_folder_select_file_dialog.add_child(file_dialog_cursor)


func _on_joy_connection_changed(device_id: int, connected: bool):
if connected:
_add_controls(device_id)
Expand All @@ -222,11 +245,11 @@ func _reset_controller_ids():

taken_ids.clear()
for cursor in player_cursors:
cursor.controller_id = -1
cursor.update_id(-1)
for device in devices:
if not taken_ids.has(device):
taken_ids[device] = null
cursor.controller_id = device
cursor.update_id(device)
break


Expand Down