From bb84f323d893fbe9bbca6ca26532bf76b48e1379 Mon Sep 17 00:00:00 2001 From: IllianiCBT Date: Thu, 26 Sep 2024 14:42:34 -0500 Subject: [PATCH] Added Display for Original Unit to Person View Panel Enhanced `PersonViewPanel` to display the original unit of a person if applicable. If the original unit is no longer available, the original unit's weight and tech level are displayed instead. --- .../resources/PersonViewPanel.properties | 1 + MekHQ/src/mekhq/gui/view/PersonViewPanel.java | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/MekHQ/resources/mekhq/resources/PersonViewPanel.properties b/MekHQ/resources/mekhq/resources/PersonViewPanel.properties index 5fdd4b6f46..465b2e4187 100644 --- a/MekHQ/resources/mekhq/resources/PersonViewPanel.properties +++ b/MekHQ/resources/mekhq/resources/PersonViewPanel.properties @@ -7,6 +7,7 @@ lblAge1.text=Age:; lblGender1.text=Gender:; lblStatus1.text=Status:; lblOrigin1.text=Origin:; +lblOriginalUnit1.text=Original Unit:; lblDueDate1.text=Due Date:; lblRetirement1.text=Retired:; lblTotalEarnings1.text=Total Earnings:; diff --git a/MekHQ/src/mekhq/gui/view/PersonViewPanel.java b/MekHQ/src/mekhq/gui/view/PersonViewPanel.java index e15e8115f8..4f7ae447e6 100644 --- a/MekHQ/src/mekhq/gui/view/PersonViewPanel.java +++ b/MekHQ/src/mekhq/gui/view/PersonViewPanel.java @@ -58,6 +58,7 @@ import java.util.stream.Collectors; import static megamek.client.ui.WrapLayout.wordWrap; +import static megamek.common.EntityWeightClass.WEIGHT_ULTRA_LIGHT; import static mekhq.campaign.personnel.Person.getLoyaltyName; /** @@ -574,6 +575,8 @@ private JPanel fillInfo() { JLabel lblAge2 = new JLabel(); JLabel lblGender1 = new JLabel(); JLabel lblGender2 = new JLabel(); + JLabel lblOriginalUnit1 = new JLabel(); + JLabel lblOriginalUnit2 = new JLabel(); JLabel lblDueDate1 = new JLabel(); JLabel lblDueDate2 = new JLabel(); JLabel lblRecruited1 = new JLabel(); @@ -736,6 +739,45 @@ public void mouseClicked(MouseEvent e) { pnlInfo.add(lblGender2, gridBagConstraints); y++; + boolean displayOriginalUnit = person.getOriginalUnitId() != null + || person.getOriginalUnitWeight() != WEIGHT_ULTRA_LIGHT; + + if (displayOriginalUnit) { + lblOriginalUnit1.setName("lblOriginalUnit1"); + lblOriginalUnit1.setText(resourceMap.getString("lblOriginalUnit1.text")); + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = y; + gridBagConstraints.fill = GridBagConstraints.NONE; + gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; + pnlInfo.add(lblOriginalUnit1, gridBagConstraints); + + lblOriginalUnit2.setName("lblOriginalUnit2"); + + if (campaign.getUnit(person.getOriginalUnitId()) != null) { + lblOriginalUnit2.setText(campaign.getUnit(person.getOriginalUnitId()).getName()); + } else { + List originalUnitWeight = List.of("None", "Light", "Medium", "Heavy", "Assault"); + int originalUnitWeightIndex = person.getOriginalUnitWeight(); + + List originalUnitTech = List.of("IS1", "IS2", "Clan"); + int originalUnitTechIndex = person.getOriginalUnitTech(); + + lblOriginalUnit2.setText(originalUnitWeight.get(originalUnitWeightIndex) + + " (" + originalUnitTech.get(originalUnitTechIndex) + ')'); + } + lblOriginalUnit1.setLabelFor(lblOriginalUnit2); + gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = y; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new Insets(0, 10, 0, 0); + gridBagConstraints.fill = GridBagConstraints.NONE; + gridBagConstraints.anchor = GridBagConstraints.NORTHWEST; + pnlInfo.add(lblOriginalUnit2, gridBagConstraints); + y++; + } + if (person.isPregnant()) { lblDueDate1.setName("lblDueDate1"); lblDueDate1.setText(resourceMap.getString("lblDueDate1.text"));