Loot change

This commit is contained in:
dingo
2026-01-21 08:43:18 -05:00
parent 5aa92abce8
commit 85c95e9f6a
3 changed files with 83 additions and 16 deletions
+74
View File
@@ -27,6 +27,10 @@ const WORLD_TILE_SIZE := TILE_SIZE * TILE_SCALE # 32 pixels per tile in world
var crafting_panel = null
var mob_loot_ui = null
# Loot popup prompt
var loot_popup: Button = null
var nearby_lootable_mob: Node = null
# Visual tile renderer (for V2 dungeons)
var visual_renderer: VisualTileMapRenderer = null
@@ -83,6 +87,9 @@ func _ready():
mob_loot_ui.visible = false
add_child(mob_loot_ui)
# Create loot popup prompt
_create_loot_popup()
# Create visual tile renderer
visual_renderer = VisualTileMapRenderer.new()
visual_renderer.name = "VisualTileRenderer"
@@ -238,6 +245,7 @@ func _process(delta):
_handle_input()
_update_camera(delta)
_update_loot_popup()
func _physics_process(_delta):
if not GameState or GameState.current_state != GameState.STATE_PLAYING:
@@ -719,3 +727,69 @@ func _on_damage_number(data: Dictionary):
color = Color(1.0, 0.5, 0.0) # Orange for weakness
dmg_number.initialize(damage, color)
func _create_loot_popup():
"""Create the loot popup prompt that appears when near corpses"""
# Create a button instead of label so it's clickable
var button = Button.new()
button.text = "[E]"
button.add_theme_font_size_override("font_size", 14)
button.add_theme_color_override("font_color", Color.WHITE)
button.visible = false
button.z_index = 100
button.custom_minimum_size = Vector2(30, 30)
# Make it styled
var style_normal = StyleBoxFlat.new()
style_normal.bg_color = Color(0, 0, 0, 0.8)
style_normal.set_border_width_all(2)
style_normal.border_color = Color(0.8, 0.8, 0.3)
style_normal.set_corner_radius_all(4)
button.add_theme_stylebox_override("normal", style_normal)
var style_hover = StyleBoxFlat.new()
style_hover.bg_color = Color(0.2, 0.2, 0, 0.9)
style_hover.set_border_width_all(2)
style_hover.border_color = Color(1.0, 1.0, 0.5)
style_hover.set_corner_radius_all(4)
button.add_theme_stylebox_override("hover", style_hover)
button.pressed.connect(_on_loot_popup_clicked)
add_child(button)
loot_popup = button
func _update_loot_popup():
"""Update loot popup position and visibility based on nearby corpses"""
if not loot_popup or not player_node or not mobs_container:
return
var player_pos = player_node.position
var loot_range = 50.0 # Pixels
# Find nearest dead mob within range
var nearest_mob = null
var nearest_distance = loot_range
for child in mobs_container.get_children():
if child.get_meta("is_dead", false):
var distance = player_pos.distance_to(child.position)
if distance < nearest_distance:
nearest_distance = distance
nearest_mob = child
if nearest_mob:
# Show popup above the corpse
nearby_lootable_mob = nearest_mob
loot_popup.visible = true
loot_popup.global_position = nearest_mob.global_position + Vector2(-40, -40)
else:
nearby_lootable_mob = null
loot_popup.visible = false
func _on_loot_popup_clicked():
"""Handle click on loot popup"""
if nearby_lootable_mob:
var mob_id = nearby_lootable_mob.get_meta("entity_id", -1)
if mob_id >= 0:
GameState.request_mob_loot(mob_id)
print("[DungeonManager] Loot popup clicked - requesting loot from mob ID: %d" % mob_id)