Skip to content

Commit

Permalink
feat: small improvements on internationalization
Browse files Browse the repository at this point in the history
  • Loading branch information
Scoppio committed Dec 31, 2024
1 parent ae16e42 commit 448b792
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 79 deletions.
13 changes: 13 additions & 0 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4860,3 +4860,16 @@ aiEditor.import.title=Import AI configurations

aiEditor.import.error.title=Error importing AI configuration
aiEditor.import.error.message=An error occurred while importing the AI configuration.
aiEditor.new.profile=New Profile
aiEditor.new.decision=New Decision
aiEditor.new.consideration=New Consideration
aiEditor.new.dse=New Decision Score Evaluator

aiEditor.add.to.profile=Add to Profile
aiEditor.copy.profile=Copy Profile
aiEditor.item.copy=(copy)
aiEditor.contextualMenu.delete=Delete
aiEditor.add.to.dse=Add to Decision Score Evaluator
aiEditor.add.to.decision=Add to Decision
aiEditor.save.error.title=Error saving data
aiEditor.save.error.message=One or more mandatory fields are empty or invalid. Please correct the errors and try again.
4 changes: 2 additions & 2 deletions megamek/src/megamek/client/ui/swing/MegaMekGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ private void showMainMenu() {
// c.gridy++;
// addBag(connectSBF, gridbag, c);

c.gridy++;
addBag(editAi, gridbag, c);
}

c.gridy++;
addBag(editAi, gridbag, c);
c.gridy++;
c.insets = new Insets(4, 4, 15, 12);
addBag(quitB, gridbag, c);
Expand Down
162 changes: 85 additions & 77 deletions megamek/src/megamek/client/ui/swing/ai/editor/AiProfileEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,6 @@ public void keyPressed(KeyEvent e) {
}
});

// repositoryViewer.addTreeSelectionListener(e -> {
// TreePath path = e.getPath();
// if (path != null) {
// DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
// if (node.isLeaf()) {
// handleOpenNodeAction(node);
// }
// }
// });
getFrame().setJMenuBar(menuBar);
menuBar.addActionListener(this);
saveProfileButton.addActionListener(e -> {
Expand Down Expand Up @@ -249,86 +240,103 @@ private JPopupMenu createContextMenu(DefaultMutableTreeNode node) {
JPopupMenu contextMenu = new JPopupMenu();
var obj = node.getUserObject();
if (obj instanceof String) {
JMenuItem menuItemAction = new JMenuItem("New " + obj);
if (obj.equals(Messages.getString("aiEditor.Profiles"))) {
JMenuItem menuItemAction = new JMenuItem(Messages.getString("aiEditor.new.profile"));
menuItemAction.addActionListener(evt -> {
createNewProfile();
});
contextMenu.add(menuItemAction);
} else if (obj.equals(Messages.getString("aiEditor.Decisions"))) {
JMenuItem menuItemAction = new JMenuItem(Messages.getString("aiEditor.new.decision"));
menuItemAction.addActionListener(evt -> {
createNewDecision();
});
contextMenu.add(menuItemAction);
} else if (obj.equals(Messages.getString("aiEditor.DecisionScoreEvaluators"))) {
JMenuItem menuItemAction = new JMenuItem(Messages.getString("aiEditor.new.dse"));
menuItemAction.addActionListener(evt -> {
createNewDecisionScoreEvaluator();
});
contextMenu.add(menuItemAction);
} else if (obj.equals(Messages.getString("aiEditor.Considerations"))) {
JMenuItem menuItemAction = new JMenuItem(Messages.getString("aiEditor.new.consideration"));
menuItemAction.addActionListener(evt -> {
addNewConsideration();
});
contextMenu.add(menuItemAction);
}
} else {
JMenuItem menuItemAction = new JMenuItem("Open");
menuItemAction.addActionListener(evt -> {
handleOpenNodeAction(node);
});
contextMenu.add(menuItemAction);
}

// Example menu item #1
JMenuItem menuItemAction = new JMenuItem("Open");
menuItemAction.addActionListener(evt -> {
handleOpenNodeAction(node);
});
contextMenu.add(menuItemAction);

if (obj instanceof TWDecision twDecision) {
var action = new JMenuItem("Add to current Profile");
action.addActionListener(evt -> {
var model = profileDecisionTable.getModel();
//noinspection unchecked
((DecisionTableModel<TWDecision>) model).addRow(twDecision);
});
contextMenu.add(action);
} else if (obj instanceof TWProfile) {
var action = getCopyProfileMenuItem((TWProfile) obj);
contextMenu.add(action);
} else if (obj instanceof TWDecisionScoreEvaluator twDse) {
var action = new JMenuItem("New Decision Score Evaluator");
action.addActionListener(evt -> {
createNewDecisionScoreEvaluator();
});
contextMenu.add(action);
} else if (obj instanceof TWConsideration twConsideration) {
var action = new JMenuItem("New Consideration");
action.addActionListener(evt -> {
addNewConsideration();
});
contextMenu.add(action);
// if the tab is a DSE, add the consideration to the DSE
if (mainEditorTabbedPane.getSelectedComponent() == dseTabPane) {
var action1 = new JMenuItem("Add to current Decision Score Evaluator");
action1.addActionListener(evt -> {
var dse = ((DecisionScoreEvaluatorPane) dsePane).getDecisionScoreEvaluator();
dse.addConsideration(twConsideration);
((DecisionScoreEvaluatorPane) dsePane).setDecisionScoreEvaluator(dse);
if (obj instanceof TWDecision twDecision) {
var action = new JMenuItem(Messages.getString("aiEditor.add.to.profile"));
action.addActionListener(evt -> {
var model = profileDecisionTable.getModel();
//noinspection unchecked
((DecisionTableModel<TWDecision>) model).addRow(twDecision);
});
contextMenu.add(action1);
} else if (mainEditorTabbedPane.getSelectedComponent() == decisionTabPane) {
var action1 = new JMenuItem("Add to current Decision");
action1.addActionListener(evt -> {
var dse = ((DecisionScoreEvaluatorPane)decisionTabDsePanel).getDecisionScoreEvaluator();
dse.addConsideration(twConsideration);
((DecisionScoreEvaluatorPane) decisionTabDsePanel).setDecisionScoreEvaluator(dse);
contextMenu.add(action);
} else if (obj instanceof TWProfile) {
var action = getCopyProfileMenuItem((TWProfile) obj);
contextMenu.add(action);
} else if (obj instanceof TWDecisionScoreEvaluator) {
var action = new JMenuItem(Messages.getString("aiEditor.new.dse"));
action.addActionListener(evt -> {
createNewDecisionScoreEvaluator();
});
contextMenu.add(action1);
}
}

// Example menu item #2
JMenuItem menuItemOther = new JMenuItem("Delete");
menuItemOther.addActionListener(evt -> {
// Another action
int deletePrompt = JOptionPane.showConfirmDialog(null,
Messages.getString("aiEditor.deleteNodePrompt"),
Messages.getString("BoardEditor.deleteNodeTitle"),
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
if (deletePrompt == JOptionPane.YES_OPTION) {
handleDeleteNodeAction(node);
contextMenu.add(action);
} else if (obj instanceof TWConsideration twConsideration) {
var action = new JMenuItem(Messages.getString("aiEditor.new.consideration"));
action.addActionListener(evt -> {
addNewConsideration();
});
contextMenu.add(action);
// if the tab is a DSE, add the consideration to the DSE
if (mainEditorTabbedPane.getSelectedComponent() == dseTabPane) {
var action1 = new JMenuItem(Messages.getString("aiEditor.add.to.dse"));
action1.addActionListener(evt -> {
var dse = ((DecisionScoreEvaluatorPane) dsePane).getDecisionScoreEvaluator();
dse.addConsideration(twConsideration);
((DecisionScoreEvaluatorPane) dsePane).setDecisionScoreEvaluator(dse);
});
contextMenu.add(action1);
} else if (mainEditorTabbedPane.getSelectedComponent() == decisionTabPane) {
var action1 = new JMenuItem(Messages.getString("aiEditor.add.to.decision"));
action1.addActionListener(evt -> {
var dse = ((DecisionScoreEvaluatorPane) decisionTabDsePanel).getDecisionScoreEvaluator();
dse.addConsideration(twConsideration);
((DecisionScoreEvaluatorPane) decisionTabDsePanel).setDecisionScoreEvaluator(dse);
});
contextMenu.add(action1);
}
}
});
contextMenu.add(menuItemOther);

JMenuItem menuItemOther = new JMenuItem(Messages.getString("aiEditor.contextualMenu.delete"));
menuItemOther.addActionListener(evt -> {
// Another action
int deletePrompt = JOptionPane.showConfirmDialog(null,
Messages.getString("aiEditor.deleteNodePrompt"),
Messages.getString("aiEditor.deleteNode.title"),
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
if (deletePrompt == JOptionPane.YES_OPTION) {
handleDeleteNodeAction(node);
}
});
contextMenu.add(menuItemOther);
}
return contextMenu;
}

private JMenuItem getCopyProfileMenuItem(TWProfile obj) {
var action = new JMenuItem("Copy Profile");
var action = new JMenuItem(Messages.getString("aiEditor.copy.profile"));
action.addActionListener(evt -> {
profileId = -1;
profileNameTextField.setText(obj.getName() + " (Copy)");
profileNameTextField.setText(obj.getName() + " " + Messages.getString("aiEditor.item.copy"));
descriptionTextField.setText(obj.getDescription());
profileDecisionTable.setModel(new DecisionTableModel<>(obj.getDecisions()));
mainEditorTabbedPane.setSelectedComponent(profileTabPane);
Expand Down Expand Up @@ -439,8 +447,8 @@ private boolean saveEverything() {
}
return true;
} catch (IllegalArgumentException ex) {
logger.formattedErrorDialog("Error saving data",
"One or more fields are empty or invalid. Please correct the errors and try again.");
logger.formattedErrorDialog(Messages.getString("aiEditor.save.error.title"),
Messages.getString("aiEditor.save.error.message") + ": " + ex.getMessage());
}
return false;
}
Expand Down Expand Up @@ -564,7 +572,7 @@ public void actionPerformed(ActionEvent e) {

private void createNewProfile() {
profileId = -1;
profileNameTextField.setText("New Profile");
profileNameTextField.setText(Messages.getString("aiEditor.new.profile"));
descriptionTextField.setText("");
initializeProfileUI();
mainEditorTabbedPane.setSelectedComponent(profileTabPane);
Expand Down

0 comments on commit 448b792

Please sign in to comment.