Skip to content

Commit

Permalink
feat: new log file, rolled back option initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Scoppio committed Dec 11, 2024
1 parent b23ad42 commit d778437
Show file tree
Hide file tree
Showing 15 changed files with 748 additions and 986 deletions.
128 changes: 58 additions & 70 deletions megamek/src/megamek/client/ui/swing/CommonSettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,7 @@
*/
package megamek.client.ui.swing;

import static java.util.stream.Collectors.toList;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.stream.Stream;

import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.MouseInputAdapter;

import com.formdev.flatlaf.icons.FlatHelpButtonIcon;

import megamek.MMConstants;
import megamek.client.ui.Messages;
import megamek.client.ui.baseComponents.AbstractButtonDialog;
Expand All @@ -70,6 +40,24 @@
import megamek.common.preference.PreferenceManager;
import megamek.logging.MMLogger;

import javax.swing.*;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.border.EmptyBorder;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.*;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toList;

/**
* The Client Settings Dialog offering GUI options concerning tooltips, map
* display, keybinds etc.
Expand Down Expand Up @@ -470,7 +458,7 @@ private <T> void moveElement(DefaultListModel<T> srcModel, int srcIndex, int trg
private ClientGUI clientgui = null;

private static final GUIPreferences GUIP = GUIPreferences.getInstance();
private static final ClientPreferences CP = PreferenceManager.getClientPreferences();
private static final ClientPreferences CLIENT_PREFERENCES = PreferenceManager.getClientPreferences();
private static final UnitDisplayOrderPreferences UDOP = UnitDisplayOrderPreferences.getInstance();
private static final ButtonOrderPreferences BOP = ButtonOrderPreferences.getInstance();

Expand Down Expand Up @@ -1942,7 +1930,7 @@ public void setVisible(boolean visible) {
// Select the correct char set (give a nice default to start).
unitStartChar.setSelectedIndex(0);
for (int loop = 0; loop < unitStartChar.getItemCount(); loop++) {
if (unitStartChar.getItemAt(loop).charAt(0) == CP.getUnitStartChar()) {
if (unitStartChar.getItemAt(loop).charAt(0) == CLIENT_PREFERENCES.getUnitStartChar()) {
unitStartChar.setSelectedIndex(loop);
break;
}
Expand All @@ -1956,31 +1944,31 @@ public void setVisible(boolean visible) {
tfSoundMuteMyTurnFileName.setText(GUIP.getSoundBingFilenameMyTurn());
tfSoundMuteOthersFileName.setText(GUIP.getSoundBingFilenameOthersTurn());

maxPathfinderTime.setText(Integer.toString(CP.getMaxPathfinderTime()));
maxPathfinderTime.setText(Integer.toString(CLIENT_PREFERENCES.getMaxPathfinderTime()));

keepGameLog.setSelected(CP.keepGameLog());
keepGameLog.setSelected(CLIENT_PREFERENCES.keepGameLog());
gameLogFilename.setEnabled(keepGameLog.isSelected());
gameLogFilename.setText(CP.getGameLogFilename());
userDir.setText(CP.getUserDir());
mmlPath.setText(CP.getMmlPath());
stampFilenames.setSelected(CP.stampFilenames());
gameLogFilename.setText(CLIENT_PREFERENCES.getGameLogFilename());
userDir.setText(CLIENT_PREFERENCES.getUserDir());
mmlPath.setText(CLIENT_PREFERENCES.getMmlPath());
stampFilenames.setSelected(CLIENT_PREFERENCES.stampFilenames());
stampFormat.setEnabled(stampFilenames.isSelected());
stampFormat.setText(CP.getStampFormat());
reportKeywordsTextPane.setText(CP.getReportKeywords());
showIPAddressesInChat.setSelected(CP.getShowIPAddressesInChat());
startSearchlightsOn.setSelected(CP.getStartSearchlightsOn());
stampFormat.setText(CLIENT_PREFERENCES.getStampFormat());
reportKeywordsTextPane.setText(CLIENT_PREFERENCES.getReportKeywords());
showIPAddressesInChat.setSelected(CLIENT_PREFERENCES.getShowIPAddressesInChat());
startSearchlightsOn.setSelected(CLIENT_PREFERENCES.getStartSearchlightsOn());

defaultAutoejectDisabled.setSelected(CP.defaultAutoejectDisabled());
useAverageSkills.setSelected(CP.useAverageSkills());
useGPinUnitSelection.setSelected(CP.useGPinUnitSelection());
generateNames.setSelected(CP.generateNames());
showUnitId.setSelected(CP.getShowUnitId());
defaultAutoejectDisabled.setSelected(CLIENT_PREFERENCES.defaultAutoejectDisabled());
useAverageSkills.setSelected(CLIENT_PREFERENCES.useAverageSkills());
useGPinUnitSelection.setSelected(CLIENT_PREFERENCES.useGPinUnitSelection());
generateNames.setSelected(CLIENT_PREFERENCES.generateNames());
showUnitId.setSelected(CLIENT_PREFERENCES.getShowUnitId());

int index = 0;
if (CP.getLocaleString().startsWith("de")) {
if (CLIENT_PREFERENCES.getLocaleString().startsWith("de")) {
index = 1;
}
if (CP.getLocaleString().startsWith("ru")) {
if (CLIENT_PREFERENCES.getLocaleString().startsWith("ru")) {
index = 2;
}
displayLocale.setSelectedIndex(index);
Expand Down Expand Up @@ -2008,7 +1996,7 @@ public void setVisible(boolean visible) {
for (int i = 0; i < tileSets.size(); i++) {
String name = tileSets.get(i);
tileSetChoice.addItem(name.substring(0, name.length() - 8));
if (name.equals(CP.getMapTileset())) {
if (name.equals(CLIENT_PREFERENCES.getMapTileset())) {
tileSetChoice.setSelectedIndex(i);
}
}
Expand Down Expand Up @@ -2413,7 +2401,7 @@ protected void okAction() {
logger.error(ex, "okAction");
}
GUIP.setValue(GUIPreferences.GUI_SCALE, (float) (guiScale.getValue()) / 10);
CP.setUnitStartChar(((String) unitStartChar.getSelectedItem()).charAt(0));
CLIENT_PREFERENCES.setUnitStartChar(((String) unitStartChar.getSelectedItem()).charAt(0));

GUIP.setMouseWheelZoom(mouseWheelZoom.isSelected());
GUIP.setMouseWheelZoomFlip(mouseWheelZoomFlip.isSelected());
Expand All @@ -2430,33 +2418,33 @@ protected void okAction() {
GUIP.setSoundBingFilenameOthersTurn(tfSoundMuteOthersFileName.getText());

try {
CP.setMaxPathfinderTime(Integer.parseInt(maxPathfinderTime.getText()));
CLIENT_PREFERENCES.setMaxPathfinderTime(Integer.parseInt(maxPathfinderTime.getText()));
} catch (Exception ex) {
logger.error(ex, "okAction");
}

GUIP.setGetFocus(getFocus.isSelected());

CP.setKeepGameLog(keepGameLog.isSelected());
CP.setGameLogFilename(gameLogFilename.getText());
CP.setUserDir(userDir.getText());
CP.setMmlPath(mmlPath.getText());
CP.setStampFilenames(stampFilenames.isSelected());
CP.setStampFormat(stampFormat.getText());
CP.setReportKeywords(reportKeywordsTextPane.getText());
CP.setShowIPAddressesInChat(showIPAddressesInChat.isSelected());
CP.setStartSearchlightsOn(startSearchlightsOn.isSelected());

CP.setDefaultAutoejectDisabled(defaultAutoejectDisabled.isSelected());
CP.setUseAverageSkills(useAverageSkills.isSelected());
CP.setUseGpInUnitSelection(useGPinUnitSelection.isSelected());
CP.setGenerateNames(generateNames.isSelected());
CP.setShowUnitId(showUnitId.isSelected());
CLIENT_PREFERENCES.setKeepGameLog(keepGameLog.isSelected());
CLIENT_PREFERENCES.setGameLogFilename(gameLogFilename.getText());
CLIENT_PREFERENCES.setUserDir(userDir.getText());
CLIENT_PREFERENCES.setMmlPath(mmlPath.getText());
CLIENT_PREFERENCES.setStampFilenames(stampFilenames.isSelected());
CLIENT_PREFERENCES.setStampFormat(stampFormat.getText());
CLIENT_PREFERENCES.setReportKeywords(reportKeywordsTextPane.getText());
CLIENT_PREFERENCES.setShowIPAddressesInChat(showIPAddressesInChat.isSelected());
CLIENT_PREFERENCES.setStartSearchlightsOn(startSearchlightsOn.isSelected());

CLIENT_PREFERENCES.setDefaultAutoejectDisabled(defaultAutoejectDisabled.isSelected());
CLIENT_PREFERENCES.setUseAverageSkills(useAverageSkills.isSelected());
CLIENT_PREFERENCES.setUseGpInUnitSelection(useGPinUnitSelection.isSelected());
CLIENT_PREFERENCES.setGenerateNames(generateNames.isSelected());
CLIENT_PREFERENCES.setShowUnitId(showUnitId.isSelected());
if ((clientgui != null) && (clientgui.getBoardView() != null)) {
clientgui.getBoardView().updateEntityLabels();
}

CP.setLocale(CommonSettingsDialog.LOCALE_CHOICES[displayLocale.getSelectedIndex()]);
CLIENT_PREFERENCES.setLocale(CommonSettingsDialog.LOCALE_CHOICES[displayLocale.getSelectedIndex()]);

GUIP.setShowMapsheets(showMapsheets.isSelected());
GUIP.setAOHexShadows(aOHexShadows.isSelected());
Expand Down Expand Up @@ -2493,11 +2481,11 @@ protected void okAction() {

if (tileSetChoice.getSelectedIndex() >= 0) {
String tileSetFileName = tileSets.get(tileSetChoice.getSelectedIndex());
if (!CP.getMapTileset().equals(tileSetFileName) &&
if (!CLIENT_PREFERENCES.getMapTileset().equals(tileSetFileName) &&
(clientgui != null) && (clientgui.getBoardView() != null)) {
clientgui.getBoardView().clearShadowMap();
}
CP.setMapTileset(tileSetFileName);
CLIENT_PREFERENCES.setMapTileset(tileSetFileName);
}

ToolTipManager.sharedInstance().setInitialDelay(GUIP.getTooltipDelay());
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/QuirksPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void refreshQuirks() {
IOptionGroup group = i.nextElement();
for (Enumeration<IOption> j = group.getSortedOptions(); j.hasMoreElements();) {
IOption option = j.nextElement();
if (!WeaponQuirks.isQuirkLegalFor(option, entity, m.getType())) {
if (WeaponQuirks.isQuirkLegalFor(option, entity, m.getType())) {
continue;
}
addWeaponQuirk(key, option, editable);
Expand Down
22 changes: 22 additions & 0 deletions megamek/src/megamek/common/Roll.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ public boolean isTargetRollSuccess(TargetRoll targetRoll) {
return getIntValue() > 2 && getIntValue() >= targetRoll.getValue();
}

/**
* Determines if the roll is a success based on the target number
* A 2 is always a failure
*
* @param targetRoll the target roll to compare against
* @return true if the roll's value is greater than the target roll's value, false otherwise
*/
public boolean isTargetRollSuccess(int targetRoll) {
return getIntValue() > 2 && getIntValue() >= targetRoll;
}

/**
* Determines if the roll is a success based on the target roll.
*
Expand All @@ -143,6 +154,17 @@ public boolean isTargetRollSuccessWithoutSimpleFailure(TargetRoll targetRoll) {
return getIntValue() >= targetRoll.getValue();
}

/**
* Determines if the roll is a success based on the target number
* A 2 is always a failure
*
* @param targetRoll the target roll to compare against
* @return true if the roll's value is greater than the target roll's value, false otherwise
*/
public boolean isTargetRollSuccessWithoutSimpleFailure(int targetRoll) {
return getIntValue() >= targetRoll;
}

/**
* Returns the margin of success/failure of the roll compared to the target roll.
* @param targetRoll the target roll to compare against
Expand Down
Loading

0 comments on commit d778437

Please sign in to comment.