Add hold and drag building

This commit is contained in:
Ategon 2024-09-13 20:09:38 -04:00
parent e1753a1587
commit c30cc68db8
13 changed files with 268 additions and 45 deletions

View file

@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=3 uid="uid://byyyhq3x8t2d8"]
[gd_scene load_steps=5 format=3 uid="uid://byyyhq3x8t2d8"]
[ext_resource type="Theme" uid="uid://d035h7upxrw3h" path="res://theme.tres" id="1_emusj"]
[ext_resource type="Script" path="res://info_window.gd" id="1_oy31s"]
[ext_resource type="PackedScene" uid="uid://bsj3th0rsn7a8" path="res://ResourceAllocation.tscn" id="3_r3oy0"]
[ext_resource type="Texture2D" uid="uid://brrrxrf3phkqv" path="res://ui/buildingmeny.png" id="3_wsa04"]
[node name="InfoWindow" type="Control"]
layout_mode = 3
@ -20,38 +21,75 @@ grow_vertical = 2
theme = ExtResource("1_emusj")
script = ExtResource("1_oy31s")
[node name="ColorRect" type="ColorRect" parent="."]
[node name="ColorRect" type="TextureRect" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0.0605303, 0.0605303, 0.0605303, 1)
texture = ExtResource("3_wsa04")
[node name="RichTextLabel" type="RichTextLabel" parent="."]
[node name="ColorRect2" type="ColorRect" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 2.0
offset_top = 2.0
offset_right = -2.0
offset_bottom = -2.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 0.662745)
[node name="Icon" type="TextureRect" parent="."]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -16.0
offset_top = 14.0
offset_right = 16.0
offset_bottom = 46.0
grow_horizontal = 2
[node name="Title" type="RichTextLabel" parent="."]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -93.5
offset_top = 14.0
offset_top = 53.0
offset_right = 103.5
offset_bottom = 44.0
offset_bottom = 83.0
grow_horizontal = 2
theme_override_font_sizes/normal_font_size = 16
bbcode_enabled = true
text = "[center]Test Title"
[node name="RichTextLabel2" type="RichTextLabel" parent="."]
[node name="Subtitle" type="RichTextLabel" parent="."]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -83.5
offset_top = 36.0
offset_top = 75.0
offset_right = 83.5
offset_bottom = 66.0
offset_bottom = 105.0
grow_horizontal = 2
bbcode_enabled = true
text = "[center]Test Title"
[node name="Description" type="RichTextLabel" parent="."]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -83.5
offset_top = 90.0
offset_right = 83.5
offset_bottom = 162.0
grow_horizontal = 2
bbcode_enabled = true
text = "[center]Test Title"

View file

@ -41,8 +41,8 @@ sources/0 = SubResource("TileSetAtlasSource_dxrqb")
sources/1 = SubResource("TileSetAtlasSource_j7eew")
sources/2 = SubResource("TileSetAtlasSource_w6tof")
[sub_resource type="CircleShape2D" id="CircleShape2D_s8q4l"]
radius = 150.083
[sub_resource type="RectangleShape2D" id="RectangleShape2D_57goo"]
size = Vector2(324, 314)
[node name="Main" type="Node2D"]
@ -68,7 +68,8 @@ script = ExtResource("5_v47eg")
position = Vector2(319, 177)
[node name="CollisionShape2D" type="CollisionShape2D" parent="TileMap/MouseHandler"]
shape = SubResource("CircleShape2D_s8q4l")
rotation = 0.750492
shape = SubResource("RectangleShape2D_57goo")
[node name="Camera2D" type="Camera2D" parent="."]
position = Vector2(-48, -46)
@ -77,6 +78,8 @@ offset = Vector2(50, 150)
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="InfoWindow" parent="CanvasLayer" instance=ExtResource("7_f4xfy")]
visible = false
pivot_offset = Vector2(170, 129)
[node name="BuildingMenu" parent="CanvasLayer" instance=ExtResource("7_hnxcf")]

View file

@ -10,9 +10,9 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -54.5
offset_left = -33.0
offset_top = 30.0
offset_right = 54.5
offset_right = 33.0
offset_bottom = 70.0
grow_horizontal = 2
grow_vertical = 2
@ -20,15 +20,57 @@ theme = ExtResource("1_5kjyf")
script = ExtResource("2_d6ufs")
[node name="ColorRect2" type="ColorRect" parent="."]
self_modulate = Color(1, 1, 1, 0.647059)
layout_mode = 1
anchors_preset = 4
anchor_top = 0.5
anchor_bottom = 0.5
offset_top = -10.0
offset_right = 20.0
offset_bottom = 10.0
offset_top = -8.0
offset_right = 16.0
offset_bottom = 8.0
grow_vertical = 2
color = Color(1, 0.419608, 0.447059, 1)
color = Color(0, 0, 0, 1)
[node name="RichTextLabel" type="RichTextLabel" parent="ColorRect2"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 2.0
offset_top = 6.0
offset_bottom = 2.0
grow_horizontal = 2
grow_vertical = 2
bbcode_enabled = true
text = "[center]-"
[node name="ColorRect3" type="ColorRect" parent="."]
self_modulate = Color(1, 1, 1, 0.647059)
layout_mode = 1
anchors_preset = 6
anchor_left = 1.0
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
offset_left = -16.0
offset_top = -8.0
offset_bottom = 8.0
grow_horizontal = 0
grow_vertical = 2
color = Color(0, 0, 0, 1)
[node name="RichTextLabel" type="RichTextLabel" parent="ColorRect3"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 2.0
offset_top = 6.0
offset_bottom = 2.0
grow_horizontal = 2
grow_vertical = 2
bbcode_enabled = true
text = "[center]+"
[node name="RichTextLabel" type="RichTextLabel" parent="."]
layout_mode = 1
@ -38,24 +80,10 @@ anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -36.0
offset_top = -4.0
offset_top = -3.0
offset_right = 36.0
offset_bottom = 20.0
offset_bottom = 21.0
grow_horizontal = 2
grow_vertical = 2
bbcode_enabled = true
text = "[center]X/X"
[node name="ColorRect3" type="ColorRect" parent="."]
layout_mode = 1
anchors_preset = 6
anchor_left = 1.0
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
offset_left = -20.0
offset_top = -10.0
offset_bottom = 10.0
grow_horizontal = 0
grow_vertical = 2
color = Color(0.168627, 0.745098, 0.313726, 1)

BIN
button.aseprite Normal file

Binary file not shown.

BIN
button.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

34
button.png.import Normal file
View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cpawfy44acsxc"
path="res://.godot/imported/button.png-234620e182281afdeb4aab4d2ed4f8a7.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://button.png"
dest_files=["res://.godot/imported/button.png-234620e182281afdeb4aab4d2ed4f8a7.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -21,6 +21,30 @@ func _on_fire(_data):
sprite_2d.scale = Vector2.ONE * 1.25 * 0.156
func _on_release():
var overlapping_areas = mouse_control.get_overlapping_areas()
overlapping_areas.sort_custom(func(a, b):
return a.z_index > b.z_index
)
for area in overlapping_areas:
if area.has_method("_on_released"):
var current_node = area
var hidden = false
while current_node:
if "modulate" in current_node:
if current_node.modulate.a < 1:
hidden = true
break
current_node = current_node.get_parent()
if hidden:
continue
if not area._on_released():
break
func _on_click():
var overlapping_areas = mouse_control.get_overlapping_areas()
overlapping_areas.sort_custom(func(a, b):
@ -69,6 +93,8 @@ func _on_rclick():
func _process(delta):
if Input.is_action_just_released("lclick"):
_on_release()
if Input.is_action_just_pressed("lclick"):
_on_click()
if Input.is_action_just_pressed("rclick"):

View file

@ -5,6 +5,7 @@ signal clicked
signal hovered
signal unhovered
signal rclicked
signal released
@export var passthrough = false
@ -18,6 +19,10 @@ func _on_clicked():
clicked.emit()
return passthrough
func _on_released():
released.emit()
return passthrough
func _on_rclicked():
rclicked.emit()
return passthrough

View file

@ -1,11 +1,28 @@
extends Control
var window_tween
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
Triggerer.listen("show_info", _show_info_window)
Triggerer.listen("hide_info", _hide_info_window)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _show_info_window(data):
visible = true
if window_tween:
window_tween.kill()
window_tween = create_tween()
window_tween.set_ease(Tween.EASE_OUT)
window_tween.set_trans(Tween.TRANS_BACK)
window_tween.tween_property(self, "scale", Vector2.ONE, 1)
func _hide_info_window(_data):
if window_tween:
window_tween.kill()
window_tween = create_tween()
window_tween.tween_property(self, "scale", Vector2.ZERO, 1)

View file

@ -2,7 +2,8 @@ extends TileMap
var GridSize = 33
var Dic = {}
var Building_Mode: bool = false
var Building_Mode := false
var Drag_Mode := false
func generate_percentage(percentages: Array):
var array_length = 0
@ -26,6 +27,9 @@ func abs(num: int):
return num
func _ready():
Triggerer.listen("select_building", select_building)
Triggerer.listen("drag_building", drag_building)
for x in GridSize:
for y in GridSize:
var layer_number: int
@ -72,6 +76,9 @@ func _ready():
}
func _process(delta):
if Input.is_action_just_released("lclick"):
release_mouse()
if Building_Mode:
var tile = local_to_map(get_global_mouse_position())
@ -85,13 +92,38 @@ func _process(delta):
func _on_mouse_handler_clicked():
print("TEST")
if Building_Mode:
var tile = local_to_map(get_global_mouse_position())
Dic[str(tile)]["Placed"] = true
place_building()
func _on_mouse_handler_rclicked():
Building_Mode = !Building_Mode
func select_building(data):
Building_Mode = true
for x in GridSize:
for y in GridSize:
if !Dic[str(Vector2(x,y))].get("Placed"):
erase_cell(Dic[str(Vector2(x,y))].get("Layer"), Vector2(x,y))
func drag_building(data):
Building_Mode = true
Drag_Mode = true
func release_mouse():
if Drag_Mode and Building_Mode:
place_building()
Drag_Mode = false
func place_building():
var tile = local_to_map(get_global_mouse_position())
Building_Mode = false
Dic[str(tile)]["Placed"] = true
func _on_mouse_handler_rclicked():
Building_Mode = false
for x in GridSize:
for y in GridSize:
if !Dic[str(Vector2(x,y))].get("Placed"):

View file

@ -1,7 +1,10 @@
[gd_scene load_steps=3 format=3 uid="uid://b7o2i7tgirg64"]
[gd_scene load_steps=5 format=3 uid="uid://b7o2i7tgirg64"]
[ext_resource type="Script" path="res://ui/building_icon.gd" id="1_6qgij"]
[ext_resource type="Texture2D" uid="uid://c3t66sxwk078m" path="res://parts/buildings/images/essencecompressor.png" id="1_62uie"]
[ext_resource type="PackedScene" uid="uid://dykc1mgg5uopw" path="res://components/Cursor/MouseHandler.tscn" id="3_tf3sl"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_0bdxp"]
[node name="BuildingIcon" type="ColorRect"]
custom_minimum_size = Vector2(32, 32)
@ -21,3 +24,14 @@ offset_bottom = 24.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("1_62uie")
[node name="MouseHandler" parent="." instance=ExtResource("3_tf3sl")]
position = Vector2(16, 17)
[node name="CollisionShape2D" type="CollisionShape2D" parent="MouseHandler"]
shape = SubResource("RectangleShape2D_0bdxp")
[connection signal="clicked" from="MouseHandler" to="." method="_on_mouse_handler_clicked"]
[connection signal="hovered" from="MouseHandler" to="." method="_on_mouse_handler_hovered"]
[connection signal="released" from="MouseHandler" to="." method="_on_mouse_handler_released"]
[connection signal="unhovered" from="MouseHandler" to="." method="_on_mouse_handler_unhovered"]

View file

@ -1,3 +1,28 @@
extends ColorRect
var key
var clicked = false
@onready var texture_rect: TextureRect = $TextureRect
func _on_mouse_handler_clicked() -> void:
clicked = true
func _on_mouse_handler_hovered() -> void:
pass # Replace with function body.
func _on_mouse_handler_unhovered() -> void:
if clicked:
Triggerer.trigger("drag_building", { "key": key })
clicked = false
func _on_mouse_handler_released() -> void:
if clicked:
Triggerer.trigger("select_building", { "key": key })
clicked = false

View file

@ -40,6 +40,7 @@ func swap_to_tab(index):
for i in range(0, icons.size()):
if i < filtered_buildings.size():
icons[i].visible = true
icons[i].key = filtered_buildings[i]
icons[i].texture_rect.texture = Data.data.images[filtered_buildings[i]]
if i > 0: