Skip to content

Commit

Permalink
feat: godot demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna committed Dec 21, 2024
1 parent 7565bf7 commit af8391b
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Godot/godotdemo/Controls/CustomMenuButton.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
extends MenuButton
class_name CustomMenuButton

func _ready():
# 连接 popup 关信号
connect("popup", _on_popup)

func _on_popup():
# todo 没有走到这里
# 获取菜单
var menu = get_popup()

# 计算菜单的新位置
var position = get_global_rect().position
var size = get_global_rect().size
var menu_size = menu.get_size()

# 计算新的 y 位置,使菜单向上展开
var new_y = position.y - menu_size.y

# 设置菜单的新位置
menu.popup(Rect2(position.x, new_y, menu_size.x, menu_size.y))
Binary file not shown.
57 changes: 56 additions & 1 deletion Godot/godotdemo/Scene/ControlScene.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[gd_scene load_steps=12 format=3 uid="uid://b41nglb6ngydo"]
[gd_scene load_steps=13 format=3 uid="uid://b41nglb6ngydo"]

[ext_resource type="Texture2D" uid="uid://bt8safuv6fw0o" path="res://Resources/00455tql.png" id="1_2s3an"]
[ext_resource type="Texture2D" uid="uid://do0t1ajaajywi" path="res://icon.svg" id="1_igce7"]
[ext_resource type="Texture2D" uid="uid://8f8upw43mnjj" path="res://Resources/enemyFloating_1.png" id="2_rgksf"]
[ext_resource type="LabelSettings" uid="uid://bv1u5ofn4jwb" path="res://new_label_settings.tres" id="4_ai2n2"]
[ext_resource type="Script" path="res://Scripts/ControlScene/TextEditScript.gd" id="5_880mr"]
[ext_resource type="Script" path="res://Scripts/ControlScene/Label4Script.gd" id="6_4bi2e"]
[ext_resource type="Script" path="res://Controls/CustomMenuButton.gd" id="7_f8j5s"]

[sub_resource type="InputEventKey" id="InputEventKey_64aye"]
device = -1
Expand Down Expand Up @@ -237,4 +238,58 @@ offset_bottom = 408.0
text = "Title"
script = ExtResource("6_4bi2e")

[node name="MenuButton" type="MenuButton" parent="."]
layout_mode = 0
offset_left = 1400.0
offset_top = 472.0
offset_right = 1568.0
offset_bottom = 528.0
text = "test"
icon = ExtResource("1_igce7")
flat = false
item_count = 2
popup/item_0/text = "1"
popup/item_1/text = "2"
popup/item_1/id = 1

[node name="OptionButton" type="OptionButton" parent="."]
layout_mode = 0
offset_left = 1600.0
offset_top = 480.0
offset_right = 1768.0
offset_bottom = 512.0
item_count = 2
popup/item_0/text = "1"
popup/item_1/text = "2"
popup/item_1/id = 1

[node name="CustomMenuButton" type="MenuButton" parent="."]
layout_mode = 0
offset_left = 1328.0
offset_top = 672.0
offset_right = 1480.0
offset_bottom = 712.0
text = "test"
icon = ExtResource("1_igce7")
item_count = 2
popup/item_0/text = "1"
popup/item_1/text = "2"
popup/item_1/id = 1
script = ExtResource("7_f8j5s")

[node name="MenuButton2" type="MenuButton" parent="."]
layout_mode = 0
offset_left = 1192.0
offset_top = 512.0
offset_right = 1362.0
offset_bottom = 584.0
text = "test"
icon = ExtResource("1_igce7")
flat = false
expand_icon = true
item_count = 2
popup/item_0/text = "1"
popup/item_1/text = "2"
popup/item_1/id = 1

[connection signal="text_changed" from="TextEdit" to="TextEdit" method="_on_text_changed"]
23 changes: 23 additions & 0 deletions Godot/godotdemo/Scene/ItemListScene.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[gd_scene format=3 uid="uid://bqa34s808mgg"]

[node name="ItemListScene" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="ItemList" type="ItemList" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
item_count = 4
max_columns = 2
item_0/text = "test1"
item_1/text = "test2"
item_2/text = "item3"
item_3/text = "item4"
22 changes: 22 additions & 0 deletions Godot/godotdemo/Scene/VideoTest.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[gd_scene load_steps=2 format=3 uid="uid://bd0qmo4dtfqmh"]

[ext_resource type="VideoStream" path="res://Resources/startRoomBackgroundVideo.ogv" id="1_vlprb"]

[node name="VideoTest" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="VideoStreamPlayer" type="VideoStreamPlayer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
stream = ExtResource("1_vlprb")
autoplay = true
loop = true

0 comments on commit af8391b

Please sign in to comment.