-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from ligen131/feat-20240218-table-cloth-scroll
feat(scroll_area, base_level): 添加 scroll_area
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
extends Area2D | ||
|
||
|
||
const WIDTH := 1920 / 4 | ||
const PADDING := 32 | ||
const SPEED := 300 | ||
|
||
|
||
@export var is_on_left := true | ||
|
||
var is_mouse_on = false | ||
|
||
|
||
|
||
func _process(delta: float): | ||
if self.is_mouse_on: | ||
if get_tree().root.has_node("BaseLevel/HUDs/TableCloth"): | ||
var table_cloth_node = get_tree().root.get_node("BaseLevel/HUDs/TableCloth") | ||
var offset := 0 | ||
|
||
if table_cloth_node.size.x < WIDTH: | ||
return | ||
|
||
if self.is_on_left and table_cloth_node.position.x < PADDING: | ||
offset = min(PADDING - table_cloth_node.position.x, int(delta * SPEED + 0.5)) | ||
elif not self.is_on_left and table_cloth_node.position.x + table_cloth_node.size.x > WIDTH - PADDING: | ||
offset = -min(table_cloth_node.position.x + table_cloth_node.size.x - (WIDTH - PADDING), int(delta * SPEED + 0.5)) | ||
|
||
if offset != 0: | ||
table_cloth_node.position.x += offset | ||
for block: Block in get_tree().root.get_node("BaseLevel/Blocks").get_children(): | ||
block.position.x += offset | ||
if block.occupied_card != null: | ||
block.occupied_card.position.x += offset | ||
|
||
|
||
func _on_mouse_exited(): | ||
self.is_mouse_on = false | ||
|
||
func _on_mouse_entered(): | ||
self.is_mouse_on = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://csl5lwjicxroy"] | ||
|
||
[ext_resource type="Script" path="res://levels/base_level/scroll_area/scroll_area.gd" id="1_j4m6q"] | ||
|
||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_dbovb"] | ||
size = Vector2(64, 200) | ||
|
||
[node name="ScrollArea" type="Area2D"] | ||
script = ExtResource("1_j4m6q") | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
shape = SubResource("RectangleShape2D_dbovb") | ||
debug_color = Color(0, 0.6, 0.701961, 0.419608) | ||
|
||
[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] | ||
[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"] |