From 9f75f9c63db4a7845912d9cb92e0a64a971b218e Mon Sep 17 00:00:00 2001 From: Holly Date: Tue, 4 Feb 2025 10:52:15 +0000 Subject: [PATCH] SelectionList works, make FPSfactor match game better --- scenes/gui/OutlineRect.tscn | 1 + scenes/gui/OutlineRect2.tscn | 1 + scenes/gui/SelectionList.tscn | 6 ++--- src/Global.gd | 20 +++++++++++++- src/Launcher.gd | 19 ++++++++------ src/Player.gd | 13 +++++----- src/SelectionList.gd | 49 ++++++++++++++++++++++++++++++++++- 7 files changed, 89 insertions(+), 20 deletions(-) diff --git a/scenes/gui/OutlineRect.tscn b/scenes/gui/OutlineRect.tscn index 4abca03..f2c9be3 100644 --- a/scenes/gui/OutlineRect.tscn +++ b/scenes/gui/OutlineRect.tscn @@ -7,6 +7,7 @@ layout_mode = 3 anchors_preset = 0 offset_right = 100.0 offset_bottom = 20.0 +mouse_filter = 2 script = ExtResource("1_2f5i4") [node name="ColorRect" type="ColorRect" parent="."] diff --git a/scenes/gui/OutlineRect2.tscn b/scenes/gui/OutlineRect2.tscn index b2dbb41..055d937 100644 --- a/scenes/gui/OutlineRect2.tscn +++ b/scenes/gui/OutlineRect2.tscn @@ -7,6 +7,7 @@ layout_mode = 3 anchors_preset = 0 offset_right = 100.0 offset_bottom = 20.0 +mouse_filter = 2 script = ExtResource("1_s8wxs") [node name="ColorRect" type="ColorRect" parent="."] diff --git a/scenes/gui/SelectionList.tscn b/scenes/gui/SelectionList.tscn index 1658ecf..66185ff 100644 --- a/scenes/gui/SelectionList.tscn +++ b/scenes/gui/SelectionList.tscn @@ -9,8 +9,8 @@ layout_mode = 3 anchors_preset = 0 script = ExtResource("1_bao2f") -[node name="Selection" parent="." instance=ExtResource("2_v4kkt")] -color = Color(0, 0, 0, 1) - [node name="Hover" parent="." instance=ExtResource("2_v4kkt")] color = Color(0.392157, 0.392157, 0.392157, 1) + +[node name="Selection" parent="." instance=ExtResource("2_v4kkt")] +color = Color(0, 0, 0, 1) diff --git a/src/Global.gd b/src/Global.gd index e9e044a..9fe1f6a 100644 --- a/src/Global.gd +++ b/src/Global.gd @@ -59,6 +59,24 @@ func _ready(): LoadTexture("GFX/BlinkMeter.jpg") +func getMsec(): + return Time.get_ticks_msec() + +var CurTime = 0 +var ElapsedTime = 0 +var PrevTime = 0 + func _process(delta): - FPSfactor = delta * 1000 + #FPSfactor = delta * 1000 + #FPSfactor = max(min(delta * 70, 5.0), 0.2) + #print(max(min(delta * 70, 5.0), 0.2)) + CurTime = getMsec() + ElapsedTime = (CurTime - PrevTime) / 1000.0 + PrevTime = CurTime + FPSfactor = max(min(ElapsedTime * 70, 5.0), 0.2) + + if Engine.time_scale == 0: + FPSfactor = 0 + + #print(FPSfactor) diff --git a/src/Launcher.gd b/src/Launcher.gd index 19ffa8b..fa58146 100644 --- a/src/Launcher.gd +++ b/src/Launcher.gd @@ -3,11 +3,14 @@ extends Control func _ready() -> void: DisplayServer.window_set_title("SCP - Containment Breach Launcher") - $Launch.connect("clicked", launch) - $Exit.connect("clicked", exit) - -func launch(): - get_tree().change_scene_to_file("res://scenes/screens/GameStartup.tscn") - -func exit(): - get_tree().quit.call_deferred() + $SelectionList.connect("selection_changed", func(resolutionRaw: String): + var resSplit = resolutionRaw.split("x") + Main.options.get("options")["width"] = resSplit[0] + Main.options.get("options")["height"] = resSplit[1] + ) + $Launch.connect("clicked", func(): + get_tree().change_scene_to_file("res://scenes/screens/GameStartup.tscn") + ) + $Exit.connect("clicked", func(): + get_tree().quit.call_deferred() + ) diff --git a/src/Player.gd b/src/Player.gd index 895f923..713a44b 100644 --- a/src/Player.gd +++ b/src/Player.gd @@ -85,7 +85,6 @@ func _process(delta: float) -> void: for i in range(barAmount, 20): blinkBar.get_child(i).visible = false -func _physics_process(delta: float) -> void: var Sprint = 1.0 var Speed = 0.018 @@ -191,14 +190,14 @@ func _physics_process(delta: float) -> void: movementSpeed = movementSpeed * NoClipSpeed if Input.is_action_pressed("player_backwards"): - position.z += -movementSpeed * Global.FPSfactor + position.z += -movementSpeed * delta if Input.is_action_pressed("player_forwards"): - position.z += movementSpeed * Global.FPSfactor + position.z += movementSpeed * delta if Input.is_action_pressed("player_left"): - position.x += -movementSpeed * Global.FPSfactor + position.x += -movementSpeed * delta if Input.is_action_pressed("ui_right"): - position.x += movementSpeed * Global.FPSfactor + position.x += movementSpeed * delta else: movementSpeed = movementSpeed / max((Injuries + 3.0) / 3.0, 1.0) if Injuries > 0.5: @@ -240,8 +239,8 @@ func _physics_process(delta: float) -> void: #print(str(cos(angle) * CurrSpeed * 100000 * Global.FPSfactor), " ", str(sin(angle) * CurrSpeed * 100000 * Global.FPSfactor)) #position.x += cos(angle) * CurrSpeed * 100000 * Global.FPSfactor #position.z += sin(angle) * CurrSpeed * 100000 * Global.FPSfactor - var movementX = (direction.x * CurrSpeed) * 40 * Global.FPSfactor - var movementZ = (direction.z * CurrSpeed) * 40 * Global.FPSfactor + var movementX = (direction.x * CurrSpeed) * 160 * Global.FPSfactor + var movementZ = (direction.z * CurrSpeed) * 160 * Global.FPSfactor #print(CurrSpeed, " ", direction.x, " ", direction.z, " ", str(movementX), " ", str(movementZ)) velocity.x = movementX velocity.z = movementZ diff --git a/src/SelectionList.gd b/src/SelectionList.gd index 005a89f..4912a83 100644 --- a/src/SelectionList.gd +++ b/src/SelectionList.gd @@ -1,12 +1,16 @@ extends Control +class_name SelectionList @export var selectionList: Array var options: Array var selection: OutlineRect var hover: OutlineRect +var selectedOption: Variant +var selectedIndex: int + +signal selection_changed -# Called when the node enters the scene tree for the first time. func _ready() -> void: var font = load("res://GFX/font/cour/Courier New.ttf") @@ -34,3 +38,46 @@ func _ready() -> void: option.add_child(label) add_child(option) why += 1 + + selection.position.x = 10 + selection.position.y = 10 + selectedOption = selectionList[selectedIndex] + selection_changed.emit.call_deferred(selectedOption) + +var mousePos = Vector2i() +func _gui_input(event: InputEvent) -> void: + if event is InputEventMouseMotion: + mousePos.x = event.position.x + mousePos.y = event.position.y + + updateSelection(false) + if event is InputEventMouseButton: + if event.button_index == 1 and event.pressed: + updateSelection(true) + +func updateSelection(pressed: bool): + var col = ((mousePos.x + 10) / 100) + var row = ((mousePos.y + 10) / 20) - 1 + var index = row + col * 6 + if index > selectionList.size() - 1 or row > 5 or col > 3 or row < 0 or col < 0: + hover.visible = false + return + + if mousePos.x >= 10 + (100 * col) and mousePos.x < 10 + (100 * col) + 100 and mousePos.y >= 10 + (20 * row) and mousePos.y < 10 + (20 * row) + 20: + if pressed: + selectedIndex = index + selectedOption = selectionList[index] + selection.position.x = 10 + (100 * col) + selection.position.y = 10 + (20 * row) + selection_changed.emit(selectedOption) + + hover.visible = true + else: + hover.visible = false + + hover.position.x = 10 + (100 * col) + hover.position.y = 10 + (20 * row) + + if mousePos.x == 0 and mousePos.y == 0: + selection.position.x = 10 + (100 * col) + selection.position.y = 10 + (20 * row)