fix: add error handling to prevent stylesheet crash in _refresh_display
- Wrap entire _refresh_display in try/except - Check widget exists before setting stylesheet - Log errors instead of crashing
This commit is contained in:
parent
e17f7e3565
commit
b8bd462d09
|
|
@ -754,39 +754,63 @@ class HUDOverlay(QWidget):
|
||||||
|
|
||||||
def _refresh_display(self):
|
def _refresh_display(self):
|
||||||
"""Refresh all display labels."""
|
"""Refresh all display labels."""
|
||||||
# Profit/Loss
|
try:
|
||||||
profit = self._stats.profit_loss
|
# Profit/Loss
|
||||||
color = "#7FFF7F" if profit >= 0 else "#FF7F7F"
|
if hasattr(self, 'profit_label') and self.profit_label is not None:
|
||||||
self._safe_set_text('profit_label', f"{profit:+.2f} PED")
|
try:
|
||||||
if hasattr(self, 'profit_label') and self.profit_label is not None:
|
profit = self._stats.profit_loss
|
||||||
try:
|
color = "#7FFF7F" if profit >= 0 else "#FF7F7F"
|
||||||
self.profit_label.setStyleSheet(f"font-size: 18px; font-weight: bold; color: {color};")
|
self.profit_label.setText(f"{profit:+.2f} PED")
|
||||||
except RuntimeError:
|
self.profit_label.setStyleSheet(f"font-size: 18px; font-weight: bold; color: {color};")
|
||||||
pass
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Return %
|
# Return %
|
||||||
ret = self._stats.return_percentage
|
if hasattr(self, 'return_label') and self.return_label is not None:
|
||||||
if ret >= 100:
|
try:
|
||||||
color = "#7FFF7F"
|
ret = self._stats.return_percentage
|
||||||
elif ret >= 90:
|
if ret >= 100:
|
||||||
color = "#FFFF7F"
|
color = "#7FFF7F"
|
||||||
else:
|
elif ret >= 90:
|
||||||
color = "#FF7F7F"
|
color = "#FFFF7F"
|
||||||
self._safe_set_text('return_label', f"{ret:.1f}%")
|
else:
|
||||||
if hasattr(self, 'return_label') and self.return_label is not None:
|
color = "#FF7F7F"
|
||||||
try:
|
self.return_label.setText(f"{ret:.1f}%")
|
||||||
self.return_label.setStyleSheet(f"font-size: 16px; font-weight: bold; color: {color};")
|
self.return_label.setStyleSheet(f"font-size: 16px; font-weight: bold; color: {color};")
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Total Cost + Loot breakdown + Highest
|
# Total Cost + Loot breakdown + Highest
|
||||||
self._safe_set_text('total_cost_label', f"Cost: {self._stats.cost_total:.2f}")
|
self._safe_set_text('total_cost_label', f"Cost: {self._stats.cost_total:.2f}")
|
||||||
self._safe_set_text('total_loot_label', f"Total: {self._stats.loot_total:.2f}")
|
self._safe_set_text('total_loot_label', f"Total: {self._stats.loot_total:.2f}")
|
||||||
self._safe_set_text('shrapnel_value_label', f"S: {self._stats.shrapnel_total:.2f}")
|
self._safe_set_text('shrapnel_value_label', f"S: {self._stats.shrapnel_total:.2f}")
|
||||||
self._safe_set_text('regular_loot_label', f"R: {self._stats.loot_other:.2f}")
|
self._safe_set_text('regular_loot_label', f"R: {self._stats.loot_other:.2f}")
|
||||||
self._safe_set_text('highest_loot_label', f"Highest: {self._stats.highest_loot:.2f}")
|
self._safe_set_text('highest_loot_label', f"Highest: {self._stats.highest_loot:.2f}")
|
||||||
|
|
||||||
# Cost metrics
|
# Cost metrics
|
||||||
|
self._safe_set_text('cps_label', f"Shot: {self._stats.cost_per_shot:.4f}")
|
||||||
|
self._safe_set_text('cph_label', f"Hit: {self._stats.cost_per_hit:.4f}")
|
||||||
|
self._safe_set_text('cphl_label', f"Heal: {self._stats.cost_per_heal:.4f}")
|
||||||
|
|
||||||
|
# Gear
|
||||||
|
self._safe_set_text('weapon_label', f"W: {self._stats.current_weapon[:20]}")
|
||||||
|
self._safe_set_text('armor_label', f"A: {self._stats.current_armor[:20]}")
|
||||||
|
self._safe_set_text('loadout_label', f"L: {self._stats.current_loadout[:20]}")
|
||||||
|
|
||||||
|
# Cost breakdown
|
||||||
|
self._safe_set_text('wep_cost_label', f"{self._stats.weapon_cost_total:.2f}")
|
||||||
|
self._safe_set_text('arm_cost_label', f"{self._stats.armor_cost_total:.2f}")
|
||||||
|
self._safe_set_text('heal_cost_label', f"{self._stats.healing_cost_total:.2f}")
|
||||||
|
|
||||||
|
# Combat
|
||||||
|
self._safe_set_text('kills_label', f"Kills: {self._stats.kills}")
|
||||||
|
self._safe_set_text('globals_label', f"Globals: {self._stats.globals_count}")
|
||||||
|
|
||||||
|
# Damage stats
|
||||||
|
self._safe_set_text('damage_dealt_label', f"Dealt: {int(self._stats.damage_dealt)}")
|
||||||
|
self._safe_set_text('damage_taken_label', f"Taken: {int(self._stats.damage_taken)}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error in _refresh_display: {e}")
|
||||||
self._safe_set_text('cps_label', f"Shot: {self._stats.cost_per_shot:.4f}")
|
self._safe_set_text('cps_label', f"Shot: {self._stats.cost_per_shot:.4f}")
|
||||||
self._safe_set_text('cph_label', f"Hit: {self._stats.cost_per_hit:.4f}")
|
self._safe_set_text('cph_label', f"Hit: {self._stats.cost_per_hit:.4f}")
|
||||||
self._safe_set_text('cphl_label', f"Heal: {self._stats.cost_per_heal:.4f}")
|
self._safe_set_text('cphl_label', f"Heal: {self._stats.cost_per_heal:.4f}")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue