From e17f7e35653acc868ce89bebe3d001bec7cac93a Mon Sep 17 00:00:00 2001 From: LemonNexus Date: Tue, 10 Feb 2026 13:57:41 +0000 Subject: [PATCH] fix: properly wire cost tracking and loot tracking to new HUD - Add weapon cost tracking on damage_dealt using session_costs - Add armor cost tracking on damage_taken using session_costs - Fix on_loot to use update_kills() and update_loot() with proper params - Fix on_heal to use update_healing_cost() and on_heal_event() with proper params - All cost tracking now uses _session_costs from loadout selection --- ui/main_window.py | 48 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/ui/main_window.py b/ui/main_window.py index c6e9c05..42a796e 100644 --- a/ui/main_window.py +++ b/ui/main_window.py @@ -1020,13 +1020,25 @@ class MainWindow(QMainWindow): decay_cost = Decimal('0.02') # Update HUD with heal event - self.hud.on_heal_event(heal_amount, decay_cost) + try: + # Track healing cost + if self._session_costs: + cost_per_heal = self._session_costs.get('cost_per_heal', Decimal('0')) + if cost_per_heal > 0: + self.hud.update_healing_cost(cost_per_heal) + + # Track heal amount (as event dict for new HUD) + self.hud.on_heal_event({'heal_amount': heal_amount}) + except Exception as e: + logger.error(f"Error updating HUD heal: {e}") # Log to UI self.log_info("Heal", f"Healed {heal_amount} HP (Cost: {decay_cost:.4f} PED)") def on_loot(event): """Handle loot events.""" + from decimal import Decimal + item_name = event.data.get('item_name', 'Unknown') value_ped = event.data.get('value_ped', Decimal('0.0')) quantity = event.data.get('quantity', 1) @@ -1035,8 +1047,15 @@ class MainWindow(QMainWindow): if item_name == 'Universal Ammo': return - # Estimated Kills: Every loot event = 1 mob killed - self.hud.update_stats({'kills_add': 1}) + try: + # Update kill count (each loot event = 1 kill) + self.hud.update_kills(1) + + # Update loot value + is_shrapnel = 'shrapnel' in item_name.lower() + self.hud.update_loot(value_ped, is_shrapnel=is_shrapnel) + except Exception as e: + logger.error(f"Error updating HUD loot: {e}") # Queue database write for main thread (SQLite thread safety) if self._current_db_session_id: @@ -1049,9 +1068,6 @@ class MainWindow(QMainWindow): 'raw_line': event.raw_line }) - # Update HUD (thread-safe) - self.hud.on_loot_event(item_name, value_ped) - # Log to UI (main thread only - use signal/slot or queue) # We'll log this in _process_queued_events instead @@ -1094,13 +1110,19 @@ class MainWindow(QMainWindow): self.log_info("Skill", f"{skill_name} +{gained}") def on_damage_dealt(event): - """Handle damage dealt - track damage stats.""" + """Handle damage dealt - track damage stats and weapon cost.""" from decimal import Decimal try: damage = event.data.get('damage', 0) if damage: - # Pass as Decimal to avoid type errors + # Track damage amount self.hud.on_damage_dealt(Decimal(str(damage))) + + # Track weapon cost per shot + if self._session_costs: + cost_per_shot = self._session_costs.get('cost_per_shot', Decimal('0')) + if cost_per_shot > 0: + self.hud.update_weapon_cost(cost_per_shot) except Exception as e: logger.error(f"Error in on_damage_dealt: {e}") @@ -1112,13 +1134,19 @@ class MainWindow(QMainWindow): logger.error(f"Error in on_critical_hit: {e}") def on_damage_taken(event): - """Handle damage taken - track armor decay cost.""" + """Handle damage taken - track damage stats and armor cost.""" from decimal import Decimal try: damage = event.data.get('damage', 0) if damage: - # Pass as Decimal to avoid type errors + # Track damage amount self.hud.on_damage_taken(Decimal(str(damage))) + + # Track armor cost per hit + if self._session_costs: + cost_per_hit = self._session_costs.get('cost_per_hit', Decimal('0')) + if cost_per_hit > 0: + self.hud.update_armor_cost(cost_per_hit) except Exception as e: logger.error(f"Error in on_damage_taken: {e}")