Skip to content

Commit 8decc49

Browse files
committed
-Initialize
1 parent 773ce09 commit 8decc49

File tree

8 files changed

+263
-0
lines changed

8 files changed

+263
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Normalize EOL for all files that Git considers text files.
2+
* text=auto eol=lf

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Godot 4+ specific ignores
2+
.godot/

Jungleprog/Node/UIControl.tscn

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[gd_scene load_steps=3 format=3 uid="uid://do2o8idv54r2q"]
2+
3+
[ext_resource type="Script" path="res://Jungleprog/Script/InfiniteScrollContainer.gd" id="1_a8e4e"]
4+
[ext_resource type="Script" path="res://Jungleprog/Script/Item.gd" id="2_hmj7c"]
5+
6+
[node name="Control" type="Control"]
7+
layout_mode = 3
8+
anchors_preset = 15
9+
anchor_right = 1.0
10+
anchor_bottom = 1.0
11+
grow_horizontal = 2
12+
grow_vertical = 2
13+
14+
[node name="ScrollContainer" type="ScrollContainer" parent="."]
15+
layout_mode = 1
16+
anchors_preset = 15
17+
anchor_right = 1.0
18+
anchor_bottom = 1.0
19+
grow_horizontal = 2
20+
grow_vertical = 2
21+
horizontal_scroll_mode = 0
22+
vertical_scroll_mode = 3
23+
script = ExtResource("1_a8e4e")
24+
25+
[node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer"]
26+
layout_mode = 2
27+
size_flags_horizontal = 3
28+
size_flags_vertical = 3
29+
theme_override_constants/separation = 2
30+
31+
[node name="TemplateItem" type="Control" parent="ScrollContainer/VBoxContainer"]
32+
custom_minimum_size = Vector2(2.08165e-12, 100)
33+
layout_mode = 2
34+
mouse_filter = 1
35+
script = ExtResource("2_hmj7c")
36+
37+
[node name="Button" type="Button" parent="ScrollContainer/VBoxContainer/TemplateItem"]
38+
layout_mode = 1
39+
anchors_preset = 15
40+
anchor_right = 1.0
41+
anchor_bottom = 1.0
42+
grow_horizontal = 2
43+
grow_vertical = 2
44+
mouse_filter = 1
45+
46+
[connection signal="gui_input" from="ScrollContainer" to="ScrollContainer" method="_on_gui_input"]
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
extends ScrollContainer
2+
3+
@onready var vBoxContainer = $VBoxContainer
4+
@onready var templateItem = $VBoxContainer/TemplateItem
5+
6+
var is_pressed : bool = false
7+
var is_set_scolle_size : bool = false
8+
var scroll_min : int = -1
9+
var scroll_max : int = -1
10+
11+
var data_list = []
12+
var box_container_list = []
13+
14+
var is_flash = false
15+
var vertical_value = 0
16+
var container_index = 0
17+
var end_line = 0 #520
18+
var data_index = 0 #8 max scroll
19+
var max_container = 12
20+
var v_item_size = 0
21+
var v_item_last_size = 0
22+
23+
var delay_release : float = 0
24+
var is_delay : bool = false
25+
26+
# Called when the node enters the scene tree for the first time.
27+
func _ready():
28+
29+
# create data
30+
for i in 50:
31+
data_list.append(i)
32+
33+
templateItem.hide()
34+
data_index = max_container
35+
for i in max_container:
36+
if templateItem:
37+
var newBoxContainer = templateItem.duplicate()
38+
box_container_list.append(newBoxContainer)
39+
vBoxContainer.add_child(newBoxContainer)
40+
(newBoxContainer as Control).visible = true
41+
newBoxContainer.connect("on_button_event", on_select_index)
42+
newBoxContainer.set_data(i)
43+
newBoxContainer.name = "Box%d" % i
44+
45+
# Called every frame. 'delta' is the elapsed time since the previous frame.
46+
func _process(delta):
47+
if is_delay:
48+
delay_release += delta
49+
if delay_release >= 0.3:
50+
is_delay = false
51+
is_pressed = false
52+
pass
53+
54+
55+
func on_select_index(index):
56+
if !is_pressed:
57+
print("select button %d" % index)
58+
59+
func _on_gui_input(event):
60+
61+
if is_pressed:
62+
if event is InputEventScreenTouch and event.is_pressed() == false:
63+
is_delay = true
64+
delay_release = 0
65+
66+
if event is InputEventScreenDrag:
67+
init_scroll()
68+
# Scrolling
69+
is_pressed = true
70+
71+
vertical_value += -event.relative.y
72+
if vertical_value <= 0:
73+
vertical_value = 0
74+
elif vertical_value >= end_line:
75+
vertical_value = end_line
76+
77+
scroll_vertical = vertical_value
78+
# Down Scroll
79+
if scroll_vertical >= end_line and data_index < data_list.size():
80+
scroll_vertical = v_item_last_size
81+
vertical_value = v_item_last_size
82+
83+
var box = box_container_list[container_index]
84+
box.set_data(data_index)
85+
vBoxContainer.move_child(box, max_container)
86+
87+
data_index += 1
88+
container_index += 1
89+
if container_index >= box_container_list.size():
90+
container_index = 0
91+
92+
# UP Scroll
93+
if scroll_vertical <= 0 and data_index > max_container:
94+
data_index -= 1
95+
container_index -= 1
96+
if container_index < 0:
97+
container_index = box_container_list.size() - 1
98+
99+
scroll_vertical = v_item_size
100+
vertical_value = v_item_size
101+
102+
var new_index = data_index - max_container
103+
var box = box_container_list[container_index]
104+
box.set_data(new_index)
105+
vBoxContainer.move_child(box, 0)
106+
107+
func init_scroll():
108+
if !is_set_scolle_size:
109+
110+
is_set_scolle_size = true
111+
var bar = self.get_v_scroll_bar()
112+
scroll_min = bar.min_value
113+
scroll_max = bar.max_value
114+
end_line = bar.max_value - get_rect().size.y
115+
v_item_size = templateItem.get_rect().size.y
116+
117+
var rest_item_size = int(v_item_size) - int(get_rect().size.y) % int(v_item_size)
118+
v_item_last_size = v_item_size * 2 + rest_item_size
119+
120+
121+
print(get_rect().size.y)
122+
print(v_item_last_size)
123+
print(v_item_size)
124+
print("min = %d" % bar.min_value)
125+
print("max = %d" % bar.max_value)
126+
print(end_line)

Jungleprog/Script/Item.gd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extends Control
2+
3+
#signal for event
4+
signal on_button_event(index : int)
5+
6+
func on_item_button_event(index):
7+
emit_signal("on_button_event", index)
8+
9+
func set_data(parent_index):
10+
var count = get_child_count()
11+
for i in range(count):
12+
var button = get_child(i) as Button
13+
button.text = "index : %d" % (parent_index)
14+
button.disconnect("button_up",on_item_button_event.bind(parent_index))
15+
button.connect("button_up", on_item_button_event.bind(parent_index))
16+
pass

icon.svg

Lines changed: 1 addition & 0 deletions
Loading

icon.svg.import

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://c05atarl32wyc"
6+
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://icon.svg"
14+
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1
35+
svg/scale=1.0
36+
editor/scale_with_editor_scale=false
37+
editor/convert_colors_with_editor_theme=false

project.godot

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; Engine configuration file.
2+
; It's best edited using the editor UI and not directly,
3+
; since the parameters that go here are not all obvious.
4+
;
5+
; Format:
6+
; [section] ; section goes between []
7+
; param=value ; assign values to parameters
8+
9+
config_version=5
10+
11+
[application]
12+
13+
config/name="Infinite Scroll"
14+
run/main_scene="res://Jungleprog/Node/UIControl.tscn"
15+
config/features=PackedStringArray("4.2", "Mobile")
16+
config/icon="res://icon.svg"
17+
18+
[display]
19+
20+
window/size/viewport_width=600
21+
window/size/viewport_height=800
22+
23+
[dotnet]
24+
25+
project/assembly_name="Infinite Scroll"
26+
27+
[input_devices]
28+
29+
pointing/emulate_touch_from_mouse=true
30+
31+
[rendering]
32+
33+
renderer/rendering_method="mobile"

0 commit comments

Comments
 (0)