Added "better" implementation for camp UI

CampAndInventoryUI
Yan Wittmann 2025-01-14 21:37:13 +01:00
parent f3f4cef1bf
commit 3d716ed06d
3 changed files with 312 additions and 436 deletions

File diff suppressed because one or more lines are too long

View File

@ -15,7 +15,6 @@ var tilemap_types: TileMapTileTypes = TileMapTileTypes.new()
@onready var time_of_day_bar: ProgressBar = %TimeOfDayBar
var tilemap_navigation: TilemapNavigation = TilemapNavigation.new()
var camp: CampManager = CampManager.new()
@onready var tree_visualizer: BehaviorTreeVisualizer = %TreeVisualizer
@ -32,11 +31,7 @@ func _ready() -> void:
world.camp_manager.game_manager = self
world.step_visualizer.game_manager = self
world.step_visualizer.world = world
camp.camp_add_item(tilemap_types.OBJECT_I_BERRY)
camp.camp_add_item(tilemap_types.OBJECT_I_STICK)
update_bars()
update_camp_ui()
update_boat_progress()
call_deferred("defer_ready")
@ -50,8 +45,6 @@ func defer_ready() -> void:
get_tree().create_tween().tween_method(set_instructions_opacity, 0.0, 1.0, 1.0)
# game_ticker.start()
func _process(delta: float) -> void:
if Input.is_action_just_pressed("force_game_tick"):
Task.print_behavior_tree_evaluation = true
@ -128,7 +121,7 @@ func _on_game_tick_timeout() -> void:
EventsTracker.populate_visual_log(%RecentEventsLog, self)
update_bars()
update_boat_progress()
world.camp_manager.populate_camp_visualization(%BoatProcessUI, %CampItemUI)
handle_result_game_state(player.behavior_tree.blackboard)
if not game_ticker.is_stopped():
@ -180,10 +173,8 @@ func handle_result_game_state(blackboard: Dictionary) -> void:
get_tree().create_tween().tween_method(set_outro_opacity, 0.0, 1.0, 1.0)
func update_boat_progress() -> void:
# Dictionary zur Zählung der Bootsteile
var part_counts = {
func update_boat_progress_old() -> void:
var part_counts: Dictionary = { # @formatter:off
tilemap_types.OBJECT_I_BOAT_PART_ENGINE: 0,
tilemap_types.OBJECT_I_BOAT_PART_FUEL: 0,
tilemap_types.OBJECT_I_BOAT_PART_ANCHOR: 0,
@ -192,14 +183,12 @@ func update_boat_progress() -> void:
tilemap_types.OBJECT_I_BOAT_PART_MEDIKIT: 0,
tilemap_types.OBJECT_I_BOAT_PART_PADDLE: 0,
tilemap_types.OBJECT_I_BOAT_PART_GAS_STOVE: 0
}
} # @formatter:on
# Teile in boat_items zählen
for boat_part in world.camp_manager.boat_items:
if part_counts.has(boat_part):
part_counts[boat_part] += 1
# Aktualisiere die UI basierend auf den gezählten Teilen
for part in part_counts.keys():
var count = part_counts[part]
if count > 0:
@ -239,23 +228,6 @@ func update_boat_progress() -> void:
push_error("Unknown boat part: " + str(part))
func update_camp_ui() -> void:
# Get the count of berries and sticks from the camp inventory
var berry_count_value = camp.camp_item_count(tilemap_types.OBJECT_I_BERRY)
var stick_count_value = camp.camp_item_count(tilemap_types.OBJECT_I_STICK)
# Update Berry UI
%BerryCount.text = str(berry_count_value) # Update the count label
%BerryTexture.visible = berry_count_value > 0 # Show texture only if count > 0
if berry_count_value > 0:
%BerryTexture.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_BERRY)
# Update Stick UI
%StickCount.text = str(stick_count_value) # Update the count label
%StickTexture.visible = stick_count_value > 0 # Show texture only if count > 0
if stick_count_value > 0:
%StickTexture.texture = world.tilemap_interactive.get_cell_texture(tilemap_types.OBJECT_I_STICK)
func update_bars() -> void:
if health_bar != null:
health_bar.max_value = player.max_health

View File

@ -16,7 +16,7 @@ var boat_leave_location: Vector2i = tilemap_types.EMPTY
var time_of_day: int = 0
var day_length: int = 1000
@export var required_boat_parts: int = 6
@export var required_boat_parts: int = 8
func setup() -> void:
@ -110,20 +110,12 @@ func camp_take_item(item: Vector2i, count: int = 1) -> bool:
break
EventsTracker.track(EventsTracker.Event.CAMP_TAKEN_ITEM, {"item": item, "count": count})
if game_manager:
game_manager.update_camp_ui()
return true
func camp_add_item(item: Vector2i) -> void:
camp_items.append(item)
if tilemap_types.is_part_of_collection(tilemap_types.OBJECT_COLLECTION_BOAT_PARTS, item):
if not boat_items.has(item):
boat_items.append(item)
EventsTracker.track(EventsTracker.Event.CAMP_ADDED_ITEM, {"item": item, "count": 1, "new_count": camp_item_count(item)})
if game_manager:
game_manager.update_camp_ui()
func campfire_light() -> bool:
@ -161,3 +153,32 @@ func sleep_effect() -> void:
print("Sleep effect done")
is_sleep_active = false
time_of_day = 0
func populate_camp_visualization(boat_ui: HBoxContainer, camp_ui: HBoxContainer) -> void:
for child in boat_ui.get_children():
if child.name != "HeightLabel":
boat_ui.remove_child(child)
for boat_part in boat_items:
var texture: TextureRect = create_item_texture(boat_part)
boat_ui.add_child(texture)
for child in camp_ui.get_children():
if child.name != "HeightLabel":
camp_ui.remove_child(child)
for boat_part in camp_items:
var texture: TextureRect = create_item_texture(boat_part)
camp_ui.add_child(texture)
func create_item_texture(item: Vector2i) -> TextureRect:
var item_texture: Texture = game_manager.world.tilemap_interactive.get_cell_texture(item)
if item_texture:
var item_texture_rect: TextureRect = TextureRect.new()
item_texture_rect.texture = item_texture
item_texture_rect.set_expand_mode(TextureRect.EXPAND_FIT_WIDTH)
item_texture_rect.set_stretch_mode(TextureRect.STRETCH_KEEP_ASPECT_CENTERED)
return item_texture_rect
return null