feat: connect loadout selection to session cost tracking
- start_session now uses _session_loadout_name for HUD display - Added _setup_session_cost_tracker to initialize SessionCostTracker - Added _on_cost_update callback to update HUD with live costs - Loadout name now appears in HUD instead of 'Default'
This commit is contained in:
parent
43657eaf1e
commit
d7f1e61533
|
|
@ -940,13 +940,22 @@ class MainWindow(QMainWindow):
|
|||
weapon_dpp = Decimal(str(weapon_stats.get('dpp', 0)))
|
||||
weapon_cost_per_hour = Decimal(str(weapon_stats.get('cost_per_hour', 0)))
|
||||
|
||||
# Get loadout name from session selection
|
||||
loadout_name = getattr(self, '_session_loadout_name', None) or "Default"
|
||||
loadout_id = getattr(self, '_session_loadout_id', None)
|
||||
|
||||
self.hud.start_session(
|
||||
weapon=weapon_name,
|
||||
loadout="Default",
|
||||
loadout=loadout_name,
|
||||
weapon_dpp=weapon_dpp,
|
||||
weapon_cost_per_hour=weapon_cost_per_hour
|
||||
)
|
||||
self.log_info("HUD", f"HUD shown - Weapon: {weapon_name} (DPP: {weapon_dpp:.2f}, Cost/h: {weapon_cost_per_hour:.2f} PED)")
|
||||
|
||||
# Set up cost tracker if loadout selected
|
||||
if loadout_id:
|
||||
self._setup_session_cost_tracker(loadout_id)
|
||||
|
||||
self.log_info("HUD", f"HUD shown - Weapon: {weapon_name}, Loadout: {loadout_name} (DPP: {weapon_dpp:.2f}, Cost/h: {weapon_cost_per_hour:.2f} PED)")
|
||||
|
||||
def _setup_log_watcher_callbacks(self):
|
||||
"""Setup LogWatcher event callbacks."""
|
||||
|
|
@ -1136,6 +1145,40 @@ class MainWindow(QMainWindow):
|
|||
self._log_watcher_thread = None
|
||||
self.log_info("LogWatcher", "Stopped")
|
||||
|
||||
def _setup_session_cost_tracker(self, loadout_id: int):
|
||||
"""Set up session cost tracker with selected loadout."""
|
||||
from core.session_cost_tracker import SessionCostTracker
|
||||
from core.database import DatabaseManager
|
||||
|
||||
try:
|
||||
db = DatabaseManager()
|
||||
self._cost_tracker = SessionCostTracker(
|
||||
session_id=self._current_db_session_id,
|
||||
loadout_id=loadout_id,
|
||||
db_manager=db
|
||||
)
|
||||
self._cost_tracker.register_callback(self._on_cost_update)
|
||||
self.log_info("CostTracker", f"Cost tracking enabled for loadout ID: {loadout_id}")
|
||||
except Exception as e:
|
||||
self.log_error("CostTracker", f"Failed to set up cost tracker: {e}")
|
||||
|
||||
def _on_cost_update(self, state):
|
||||
"""Handle cost update from SessionCostTracker."""
|
||||
# Update HUD with new cost state
|
||||
if hasattr(self, 'hud') and self.hud:
|
||||
summary = {
|
||||
'weapon_cost': state.weapon_cost,
|
||||
'armor_cost': state.armor_cost,
|
||||
'healing_cost': state.healing_cost,
|
||||
'enhancer_cost': state.enhancer_cost,
|
||||
'mindforce_cost': state.mindforce_cost,
|
||||
'shots_fired': state.shots_fired,
|
||||
'hits_taken': state.hits_taken,
|
||||
'heals_used': state.heals_used,
|
||||
}
|
||||
self.hud._stats.update_from_cost_tracker(summary)
|
||||
self.hud._refresh_display()
|
||||
|
||||
def _process_queued_events(self):
|
||||
"""Process events from the queue in the main thread (SQLite thread safety)."""
|
||||
from core.project_manager import LootEvent
|
||||
|
|
|
|||
Loading…
Reference in New Issue