From 437f6b3027fba5d6fc909d62ee26b9a2bcc17424 Mon Sep 17 00:00:00 2001 From: LemonNexus Date: Mon, 9 Feb 2026 19:08:35 +0000 Subject: [PATCH] fix(ui): properly update ArmorSlotWidget UI when setting piece from API - Fixed set_piece() to use protection_label instead of non-existent piece_name_label - Now updates protection display when piece is set - Adds piece to combo if not already present - Properly stores current_piece and calls _update_total() --- ui/loadout_manager.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/ui/loadout_manager.py b/ui/loadout_manager.py index a5db499..f965185 100644 --- a/ui/loadout_manager.py +++ b/ui/loadout_manager.py @@ -651,16 +651,37 @@ class ArmorSlotWidget(QWidget): """Set selected armor piece.""" if piece is None: self.piece_combo.setCurrentIndex(0) + self.current_piece = None + self.protection_label.setText("-") + self._update_total() return - # Find and select the piece + # Store the piece + self.current_piece = piece + + # Update protection display + prot_parts = [] + if piece.protection.impact > 0: + prot_parts.append(f"Imp:{piece.protection.impact}") + if piece.protection.cut > 0: + prot_parts.append(f"Cut:{piece.protection.cut}") + if piece.protection.stab > 0: + prot_parts.append(f"Stab:{piece.protection.stab}") + self.protection_label.setText(", ".join(prot_parts) if prot_parts else "-") + + # Try to find and select the piece in combo for i in range(self.piece_combo.count()): data = self.piece_combo.itemData(i) - if data and data.item_id == piece.item_id: + if data and hasattr(data, 'item_id') and data.item_id == piece.item_id: self.piece_combo.setCurrentIndex(i) + self._update_total() return - - self.piece_combo.setCurrentIndex(0) + + # Piece not in combo - add it + display = f"{piece.name} (API)" + self.piece_combo.addItem(display, piece) + self.piece_combo.setCurrentIndex(self.piece_combo.count() - 1) + self._update_total() def set_plate(self, plate: Optional[ArmorPlate]): """Set selected plate."""