Start to add building info

This commit is contained in:
Ategon 2024-09-13 21:02:26 -04:00
parent 586b3f55dc
commit 4cada48a71
6 changed files with 58 additions and 5 deletions

View file

@ -60,9 +60,9 @@ layout_mode = 1
anchors_preset = 5 anchors_preset = 5
anchor_left = 0.5 anchor_left = 0.5
anchor_right = 0.5 anchor_right = 0.5
offset_left = -93.5 offset_left = -119.5
offset_top = 53.0 offset_top = 53.0
offset_right = 103.5 offset_right = 120.5
offset_bottom = 83.0 offset_bottom = 83.0
grow_horizontal = 2 grow_horizontal = 2
theme_override_font_sizes/normal_font_size = 16 theme_override_font_sizes/normal_font_size = 16

View file

@ -60,6 +60,10 @@ func _on_click():
if current_node.modulate.a < 1: if current_node.modulate.a < 1:
hidden = true hidden = true
break break
if "visible" in current_node:
if not current_node.visible:
hidden = true
break
current_node = current_node.get_parent() current_node = current_node.get_parent()
if hidden: if hidden:
@ -83,6 +87,10 @@ func _on_rclick():
if current_node.modulate.a < 1: if current_node.modulate.a < 1:
hidden = true hidden = true
break break
if "visible" in current_node:
if not current_node.visible:
hidden = true
break
current_node = current_node.get_parent() current_node = current_node.get_parent()
if hidden: if hidden:
@ -105,9 +113,29 @@ func _process(delta):
func _on_mouse_control_area_entered(area): func _on_mouse_control_area_entered(area):
if area.has_method("_on_hovered"): if area.has_method("_on_hovered"):
area._on_hovered() var current_node = area
var hidden = false
while current_node:
if "visible" in current_node:
if not current_node.visible:
hidden = true
break
current_node = current_node.get_parent()
if not hidden:
area._on_hovered()
func _on_mouse_control_area_exited(area): func _on_mouse_control_area_exited(area):
if area.has_method("_on_unhovered"): if area.has_method("_on_unhovered"):
area._on_unhovered() var current_node = area
var hidden = false
while current_node:
if "visible" in current_node:
if not current_node.visible:
hidden = true
break
current_node = current_node.get_parent()
if not hidden:
area._on_unhovered()

View file

@ -2,6 +2,11 @@ extends Control
var window_tween var window_tween
@onready var icon: TextureRect = $Icon
@onready var title: RichTextLabel = $Title
@onready var subtitle: RichTextLabel = $Subtitle
@onready var description: RichTextLabel = $Description
func _ready() -> void: func _ready() -> void:
Triggerer.listen("show_info", _show_info_window) Triggerer.listen("show_info", _show_info_window)
@ -12,10 +17,19 @@ func _ready() -> void:
func _show_info_window(data): func _show_info_window(data):
visible = true visible = true
var building_data = Data.data.buildings[data.Key]
if window_tween: if window_tween:
window_tween.kill() window_tween.kill()
window_tween = create_tween() window_tween = create_tween()
window_tween.set_ease(Tween.EASE_IN)
window_tween.set_trans(Tween.TRANS_QUAD)
window_tween.tween_property(self, "scale", Vector2.ZERO, 0.25)
window_tween.tween_callback(func():
title.text = "[center]%s" % [building_data.name]
)
window_tween.set_ease(Tween.EASE_OUT) window_tween.set_ease(Tween.EASE_OUT)
window_tween.set_trans(Tween.TRANS_BACK) window_tween.set_trans(Tween.TRANS_BACK)
window_tween.tween_property(self, "scale", Vector2.ONE, 0.5) window_tween.tween_property(self, "scale", Vector2.ONE, 0.5)

View file

@ -4,6 +4,7 @@ var GridSize = 33
var Dic = {} var Dic = {}
var Building_Mode := false var Building_Mode := false
var Drag_Mode := false var Drag_Mode := false
var building_key
func generate_percentage(percentages: Array): func generate_percentage(percentages: Array):
var array_length = 0 var array_length = 0
@ -105,6 +106,7 @@ func show_info_building():
func select_building(data): func select_building(data):
Building_Mode = true Building_Mode = true
building_key = data.key
for x in GridSize: for x in GridSize:
for y in GridSize: for y in GridSize:
if !Dic[str(Vector2(x,y))].get("Placed"): if !Dic[str(Vector2(x,y))].get("Placed"):
@ -114,17 +116,20 @@ func select_building(data):
func drag_building(data): func drag_building(data):
Building_Mode = true Building_Mode = true
Drag_Mode = true Drag_Mode = true
building_key = data.key
func release_mouse(): func release_mouse():
if Drag_Mode and Building_Mode: if Drag_Mode and Building_Mode:
place_building() place_building()
Building_Mode = false
func place_building(): func place_building():
var tile = local_to_map(get_global_mouse_position()) var tile = local_to_map(get_global_mouse_position())
if Dic.has(str(tile)): if Dic.has(str(tile)):
Building_Mode = false Building_Mode = false
Dic[str(tile)]["Key"] = building_key
Dic[str(tile)]["Placed"] = true Dic[str(tile)]["Placed"] = true
Drag_Mode = false Drag_Mode = false

View file

@ -3,7 +3,6 @@ extends ColorRect
var key var key
var clicked = false var clicked = false
@onready var texture_rect: TextureRect = $TextureRect @onready var texture_rect: TextureRect = $TextureRect
@ -17,12 +16,17 @@ func _on_mouse_handler_hovered() -> void:
func _on_mouse_handler_unhovered() -> void: func _on_mouse_handler_unhovered() -> void:
print(key)
print("DRAG 1")
if clicked: if clicked:
print("DRAG")
Triggerer.trigger("drag_building", { "key": key }) Triggerer.trigger("drag_building", { "key": key })
clicked = false clicked = false
func _on_mouse_handler_released() -> void: func _on_mouse_handler_released() -> void:
print("SELECT 1")
if clicked: if clicked:
print("SELECT")
Triggerer.trigger("select_building", { "key": key }) Triggerer.trigger("select_building", { "key": key })
clicked = false clicked = false

View file

@ -51,6 +51,8 @@ func swap_to_tab(index):
if i > 0: if i > 0:
spacers[i - 1].visible = false spacers[i - 1].visible = false
print(icons.map(func(icon): return icon.key))
func _on_building_tab_clicked() -> void: func _on_building_tab_clicked() -> void:
swap_to_tab(0) swap_to_tab(0)