Skip to content

Commit

Permalink
Add comments for bomb picker dialog, make XML writer aware of two bom…
Browse files Browse the repository at this point in the history
…b types
  • Loading branch information
Sleet01 committed Dec 29, 2023
1 parent 4f5c173 commit 96b49f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions MekHQ/src/mekhq/gui/dialog/BombsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private void initGUI() {
typeMax[type] = availBombs[type] + bombChoices[type];
}

// BombChoicePanel takes care of managing internal and external stores, so we don't need to here.
bombPanel = new BombChoicePanel(bomber, campaign.getGameOptions().booleanOption("at2_nukes"),
true, typeMax);

Expand Down Expand Up @@ -127,6 +128,7 @@ private void setUserPreferences() {
@Override
public void actionPerformed(ActionEvent e) {
if (okayButton.equals(e.getSource())) {
// internal and external choices are applied by bombPanel; here we only care about the totals.
bombPanel.applyChoice();
int[] newLoadout = bombPanel.getChoice();

Expand Down
15 changes: 11 additions & 4 deletions MekHQ/src/mekhq/utilities/MHQXMLUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,7 @@ public static String writeEntityToXmlString(Entity tgtEnt, int indentLvl, List<E
return retVal.toString();
}

private static String getBombChoiceString(IBomber bomber, int indentLvl) {
StringBuilder retVal = new StringBuilder();

int[] bombChoices = bomber.getBombChoices();
private static void compileBombChoices(int[] bombChoices, StringBuilder retVal, int indentLvl, boolean isInternal) {
if (bombChoices.length > 0) {
retVal.append(MHQXMLUtility.indentStr(indentLvl + 1)).append("<bombs>\n");
for (int type = 0; type < BombType.B_NUM; type++) {
Expand All @@ -267,12 +264,22 @@ private static String getBombChoiceString(IBomber bomber, int indentLvl) {
retVal.append(typeName);
retVal.append("\" load=\"");
retVal.append(bombChoices[type]);
retVal.append((isInternal) ? "\" Internal=\"true" : "\" Internal=\"false");
retVal.append("\"/>\n");
}
}
retVal.append(MHQXMLUtility.indentStr(indentLvl + 1)).append("</bombs>\n");
}

}
private static String getBombChoiceString(IBomber bomber, int indentLvl) {
StringBuilder retVal = new StringBuilder();

int[] bombChoices = bomber.getIntBombChoices();
compileBombChoices(bombChoices, retVal, indentLvl, true);
bombChoices = bomber.getExtBombChoices();
compileBombChoices(bombChoices, retVal, indentLvl, false);

return retVal.toString();
}

Expand Down

0 comments on commit 96b49f0

Please sign in to comment.