Loot change
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -114,17 +114,13 @@ func update_data(data: Dictionary):
|
||||
|
||||
_initialized = true
|
||||
|
||||
# Update visual state
|
||||
#var state = data.get("state", data.get("State", "idle")).to_lower()
|
||||
#var rotation = data.get("rotation", data.get("Rotation", 0.0))
|
||||
#
|
||||
#_update_animation_state(state, rotation)
|
||||
|
||||
var raw_state = data.get("state", data.get("State", "idle")).to_lower()
|
||||
var animation_state := _state_to_animation(raw_state)
|
||||
var rotation = data.get("rotation", data.get("Rotation", 0.0))
|
||||
# Update visual state (skip for dead mobs to preserve death animation)
|
||||
if _current_state != "dead":
|
||||
var raw_state = data.get("state", data.get("State", "idle")).to_lower()
|
||||
var animation_state := _state_to_animation(raw_state)
|
||||
var rotation = data.get("rotation", data.get("Rotation", 0.0))
|
||||
|
||||
_update_animation_state(animation_state, rotation)
|
||||
_update_animation_state(animation_state, rotation)
|
||||
|
||||
|
||||
# Apply scale
|
||||
@@ -536,15 +532,13 @@ func play_death_animation():
|
||||
break
|
||||
|
||||
if death_anim_name != "":
|
||||
# Disable looping for death animation BEFORE playing
|
||||
_animated_sprite.sprite_frames.set_animation_loop(death_anim_name, false)
|
||||
|
||||
# Play the death animation
|
||||
_last_animation = death_anim_name
|
||||
_animated_sprite.play(death_anim_name)
|
||||
|
||||
# Wait for animation to finish
|
||||
if _animated_sprite.sprite_frames.get_animation_loop(death_anim_name):
|
||||
# If it loops, disable looping temporarily
|
||||
_animated_sprite.sprite_frames.set_animation_loop(death_anim_name, false)
|
||||
|
||||
# Wait for animation to complete
|
||||
await _animated_sprite.animation_finished
|
||||
|
||||
|
||||
Reference in New Issue
Block a user