fixed interaction bar

tweaking resource_manager.gd
This commit is contained in:
2024-03-07 09:46:41 -06:00
parent ca8cfee1e8
commit 856b6a0400
11 changed files with 59 additions and 34 deletions

View File

@@ -1,9 +1,6 @@
extends Node2D
signal changed_resource
@onready var world: World = $".."
@export var resources := {}
func _on_gained_resource(res: GameResource) -> void:

View File

@@ -20,6 +20,7 @@ const BASIC_BUILDING_GROUP = preload("res://data/buildings/basic/basic_building_
func _ready() -> void:
_add_building_group(BASIC_BUILDING_GROUP)
_add_building_group(ADVANCED_BUILDING_GROUP)
building_groups.set_focus()
func _add_building_group(group: BuildingGroup) -> void:
building_groups.add_item(group.name, group.atlas_texture)

View File

@@ -4,11 +4,11 @@ extends Node2D
var base = preload("res://scene/base.tscn")
var building = preload("res://data/buildings/hub.tres")
func _unhandled_input(event):
if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT:
var build: Base = base.instantiate()
build.position = get_global_mouse_position()
build.world = world
build.building_data = building.duplicate(true)
add_child(build)
#func _unhandled_input(event):
#if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT:
#var build: Base = base.instantiate()
#build.position = get_global_mouse_position()
#build.world = world
#build.building_data = building.duplicate(true)
#add_child(build)
#world_grid.set_cell(2, world_grid.local_to_map(get_global_mouse_position()), 0, Vector2i(16,2))

View File

@@ -17,11 +17,11 @@ func _on_resource_manager_changed_resource(changed: ResourceChangedSignal) -> vo
img.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL
resource_container.add_child(img)
var label = Label.new()
var label := Label.new()
label.text = str(changed.changed_resources[resource])
resource_container.add_child(label)
var data = ResourceData.new()
var data := ResourceData.new()
data.image = img
data.label = label
data.value = changed.changed_resources[resource]

View File

@@ -3,11 +3,17 @@ class_name InteractionBar
signal interaction_finished
var grid_position: Vector2i
func _ready() -> void:
position = Grid.grid_to_world_center(grid_position) - Vector2(30,10)
var tween = get_tree().create_tween()
tween.tween_property(self, "value", 100, 3)
tween.tween_callback(_cleanup_gather)
func _cleanup_gather() -> void:
interaction_finished.emit()
var res: GameResource = Grid.get_location_data(grid_position).get_resource()
res.gained_resource.emit(res)
self.queue_free()

View File

@@ -42,9 +42,10 @@ func _input(event: InputEvent) -> void:
var build: BuildingBase = BUILDING_BASE.instantiate()
build.initialize(_attempting_build, interaction_location)
add_sibling(build)
if not _interacting and Grid.get_location_data(interaction_location).is_interactable():
elif not _interacting and Grid.get_location_data(interaction_location).is_interactable():
var interaction = INTERACTION_BAR.instantiate()
interaction.position = Grid.grid_to_world_center(interaction_location) - Vector2(30,10)
interaction.interaction_finished.connect(_on_interaction_finished)
interaction.grid_position = interaction_location
_interacting = true
add_sibling(interaction)
if event.is_action_pressed("build"):
@@ -52,6 +53,9 @@ func _input(event: InputEvent) -> void:
build_menu.build.connect(_on_build_menu_build)
add_sibling(build_menu)
func _on_interaction_finished() -> void:
_interacting = false
func _on_build_menu_build(building: Building) -> void:
print("Building: %s" % building.name)
_attempting_build = building