Skip to content

Commit

Permalink
Numerous interface improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Dec 28, 2023
1 parent e39f500 commit d04fd5c
Show file tree
Hide file tree
Showing 37 changed files with 785 additions and 780 deletions.
75 changes: 75 additions & 0 deletions megameklab/mmconf/megameklab.save
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#Client Config
#Thu Dec 28 11:44:58 CET 2023
ASWindow=643;165;1250;1127
Save_File_9=C\:\\Users\\Simon\\Desktop\\Arctic Fox AF1D.mtf
rs_condensed_reference=false
techUnofficialNoYear=false
Save_File_2=D\:\\BattleTech\\FOR ALL\\Anvil ANV-TESt234.mtf
Systems-Background=-13421773
Save_File_1=data\\mechfiles\\fighters\\TRO3075\\Vulcan VLC-8N.blk
Save_File_4=data\\mechfiles\\fighters\\Golden Century\\Tomahawk THK-63-EC.blk
Save_File_3=data\\mechfiles\\mechs\\3085u\\Phoenix\\Rifleman IIC 3.mtf
Save_File_6=data\\mechfiles\\fighters\\XTRs\\Liao\\Transit TR-13 Glare.blk
useTROFormat=true
Save_File_5=data\\mechfiles\\fighters\\TRO3039u\\Transit TR-11.blk
rs_scale_units=HEXES
Save_File_8=data\\mechfiles\\mechs\\3145\\Steiner\\Zeus X ZEU-X3.mtf
mekAutocompact=false
WINDOWLEFT=0
WINDOWSTATE=0
Save_File_7=D\:\\BattleTech\\FOR ALL\\test.mtf
rs_color=false
Save_File_Three=
nag_equipment_ctrlclick=false
lookAndFeel=com.formdev.flatlaf.FlatDarculaLaf
MekWindow=610;168;1340;1065
Weapons-Background=-13434880
techUseYear=true
File_Chooser_Window=
Save_File_One=D\:\\BattleTech\\FOR ALL\\Anvil ANV-TEST.mtf
Ammo-Background=-13421773
Equipment-Foreground=-256
Systems-Foreground=-16750900
rs_font=Exo
rs_show_quirks=true
BMWindow=633;171;1340;1067
mekAutofill=true
Save_File_Four=D\:\\BattleTech\\FOR ALL\\Anvil ANV-5M_TES2.mtf
rs_reference=false
techShowExtinct=false
DSWindow=
FullScreen=0
WINDOWHEIGHT=600
techYear=3145
PMWindow=
rs_heat_profile=true
rs_tac_ops_heat=false
Nonhittable-Background=-13421773
techShowFaction=true
Empty-Background=-16764160
Weapons-Foreground=-26215
techProgression=false
mekAutosort=false
rs_show_era=true
Equipment-Background=-13421773
StartupGui=SPLASH_SCREEN
rs_show_role=true
rs_scale_factor=1
Ammo-Foreground=-26215
rs_show_pilot_data=true
Nonhittable-Foreground=-10066330
Last_directory=D\:\\BattleTech\\FOR ALL
Empty-Foreground=-16738048
WINDOWTOP=0
Save_File_10=data\\mechfiles\\vehicles\\3050U\\Zephyr Hovertank (LRM).blk
Save_File_Two=D\:\\BattleTech\\FOR ALL
WSWindow=
CIWindow=
rs_paper_size=US_LETTER
CVWindow=
skipSafetyPrompts=true
WINDOWWIDTH=800
SVWindow=704;211;1152;1006
Save-Location-Default=D\:\\BattleTech\\FOR ALL
BAWindow=
rs_progress_bar=true
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ConfigurationDialog.techProgression.title=Tech Progression
ConfigurationDialog.printing.title=Record Sheets and Export
ConfigurationDialog.misc.title=General
ConfigurationDialog.chkTechProgression.text=Use Variable Tech Level
ConfigurationDialog.chkTechProgression.tooltip=Tech Level changes from Experimental to Advanced to Standard based on the year
ConfigurationDialog.chkTechProgression.tooltip=When this is checked, the tech level of equipment and therefore of the unit changes from Experimental to Advanced to Standard based on the year. If it is unchecked, all equipment and the unit keeps its tech level regardless of the year.
ConfigurationDialog.chkTechYear.text=Use game year
ConfigurationDialog.chkTechYear.tooltip=Use this year to determine the Tech Level if later than the introduction year.
ConfigurationDialog.chkTechShowFaction.text=Allow setting a unit's Faction
Expand Down
5 changes: 3 additions & 2 deletions megameklab/resources/megameklab/resources/Menu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ refreshMenu.text=Refresh
miRefreshUnitCache.text=Refresh Unit Cache
## Options Menu
optionsMenu.text=Options
miImport.text=Import MML Settings...
miConfiguration.text=Configuration...
## Themes Menu
themesMenu.text=Themes
Expand All @@ -72,6 +73,7 @@ unitCostBreakdownMenu.text=Unit Cost Breakdown
unitWeightBreakdownMenu.text=Unit Weight Breakdown
### Help Menu
helpMenu.text=Help
miResetWindow.text=Reset Window Positions
miAbout.text=About...
miRecordSheetImages.text=Record Sheet Images...

Expand All @@ -93,13 +95,12 @@ dialog.imagePath.title=Image Path
dialog.saveAs.title=Save As
dialog.saveAs.message.format=%s %s saved to %s
dialog.filter.unitFiles=Unit Files (*.mtf; *.blk; *.hmp)
dialog.importSettings=Import Settings From...

message.invalidUnit.format=Warning: Invalid unit, it might load incorrectly!\n%1$s
message.invalidUnit.text=Warning: Invalid unit, it might load incorrectly!
message.savingInvalidUnit.text=Warning: Saving an invalid unit, it might load incorrectly!
message.exportingInvalidUnit.text=Warning: Exporting an invalid unit!
message.abortUnitLoad.text=Warning: Could not create new UI, aborting unit load!\
Probable cause: Unsupported unit type.

# The following values are used programatically by MMLStartUp
MMLStartUp.SPLASH_SCREEN=MML Main UI
Expand Down
12 changes: 12 additions & 0 deletions megameklab/resources/megameklab/resources/PopupMessages.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mostRecentNotFound=The most recent unit file could not be opened. Starting in MML's main UI instead.
noMostRecentUnit=There is no most recent unit. Starting in MML's main UI instead.
fileReadError=An error occurred while trying to read the file %s. This can happen for various reasons. The file may not exist, MML may lack the rights to read the file or the file may be malformed or not conform to its file extension. The error message is:\n\n%s
invalidUnit=The unit is invalid for the reasons listed below and may load incorrectly!\n\n%s
validUnit=Validation Passed.
fileWriteError=A problem occurred while trying to write the file. The error message is:\n\n%s
unitSaved=%s %s saved to %s
lookAndFeelError=A problem occurred while trying to change the Java Look-and-Feel. The error message is:\n\n%s
uncaughtException=Uncaught %s detected. Please open up an issue containing all logs and the current unit file at https://github.com/MegaMek/megameklab/issues
loadUiError=A problem occurred while trying to create the unit UI, reverting to a new Mek!
locationFull=Could not add %s because the chosen location is full!
invalidLocation=%s can't be placed in %s!
5 changes: 1 addition & 4 deletions megameklab/resources/megameklab/resources/Splash.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@ btnNewAero.text=New Aero Fighter
btnNewDropper.text=New Dropship/Small Craft
btnNewLargeCraft.text=New Capital-Scale Craft
btnQuit.text=Quit
version.text=MegaMekLab Version
message.invalidUnit.format=Warning: Invalid unit, it might load incorrectly!\n%1$s
message.abortUnitLoad.text=Warning: Could not create new UI, aborting unit load!\
Probable cause: Unsupported unit type.
version.text=MegaMekLab Version
59 changes: 29 additions & 30 deletions megameklab/src/megameklab/MegaMekLab.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import megamek.MegaMek;
import megamek.client.ui.preferences.SuitePreferences;
import megamek.common.*;
import megameklab.ui.MenuBar;
import megameklab.ui.PopupMessages;
import megameklab.ui.StartupGUI;
import megameklab.ui.dialog.UiLoader;
import megameklab.util.CConfig;
Expand All @@ -29,7 +29,6 @@
import javax.swing.*;
import java.io.File;
import java.util.Locale;
import java.util.ResourceBundle;

public class MegaMekLab {
private static final SuitePreferences mmlPreferences = new SuitePreferences();
Expand All @@ -39,20 +38,14 @@ public static void main(String... args) {
// First, create a global default exception handler
Thread.setDefaultUncaughtExceptionHandler((thread, t) -> {
LogManager.getLogger().error("Uncaught Exception Detected", t);
final String name = t.getClass().getName();
JOptionPane.showMessageDialog(null,
String.format("Uncaught %s detected. Please open up an issue containing all logs and the current unit file at https://github.com/MegaMek/megameklab/issues", name),
"Uncaught " + name, JOptionPane.ERROR_MESSAGE);
PopupMessages.showUncaughtException(null, t);
});

// Second, let's handle logging
MegaMek.initializeLogging(MMLConstants.PROJECT_NAME);
MegaMekLab.initializeLogging(MMLConstants.PROJECT_NAME);

// Third, let's handle suite graphical setup initialization
MegaMek.initializeSuiteGraphicalSetups(MMLConstants.PROJECT_NAME);

// Finally, let's handle startup
ToolTipManager.sharedInstance().setDismissDelay(1000000);
ToolTipManager.sharedInstance().setReshowDelay(50);
startup();
}

Expand Down Expand Up @@ -112,7 +105,7 @@ private static void startup() {
UiLoader.loadUi(Entity.ETYPE_INFANTRY, false, false);
break;
case RECENT_UNIT:
if (loadRecentUnit()) {
if (loadMostRecentUnit()) {
return;
}
// intentional fall through when loading the most recent unit doesn't work
Expand All @@ -125,7 +118,7 @@ private static void startup() {

private static void setLookAndFeel() {
try {
String plaf = CConfig.getParam(CConfig.CONFIG_PLAF, UIManager.getSystemLookAndFeelClassName());
String plaf = CConfig.getParam(CConfig.GUI_PLAF, UIManager.getSystemLookAndFeelClassName());
UIManager.setLookAndFeel(plaf);
} catch (Exception ex) {
LogManager.getLogger().error("", ex);
Expand All @@ -140,34 +133,40 @@ public static MMLOptions getMMLOptions() {
return mmlOptions;
}

private static boolean loadRecentUnit() {
String filePathName = CConfig.getParam(CConfig.CONFIG_SAVE_FILE_1);
/**
* Tries loading the most recent unit. Returns true when successful, false when no such
* unit could be found or the unit doesn't load.
*
* @return True when the most recent unit is successfully loaded
*/
private static boolean loadMostRecentUnit() {
String mostRecentName = CConfig.getRecentFile(1);
if (mostRecentName.isBlank()) {
PopupMessages.showNoMostRecentUnitError(null);
return false;
}

File unitFile = new File(filePathName);
if (!(unitFile.isFile())) {
File unitFile = new File(mostRecentName);
if (!unitFile.isFile()) {
PopupMessages.showMostRecentUnitMissingError(null);
return false;
}
ResourceBundle resources = ResourceBundle.getBundle("megameklab.resources.Menu");

try {
Entity tempEntity = new MechFileParser(unitFile).getEntity();
if (tempEntity == null) {
Entity recentUnit = new MechFileParser(unitFile).getEntity();
if (recentUnit == null) {
return false;
} else if (!UnitUtil.validateUnit(recentUnit).isBlank()) {
PopupMessages.showUnitInvalidWarning(null, UnitUtil.validateUnit(recentUnit));
}

if (!UnitUtil.validateUnit(tempEntity).isBlank()) {
JOptionPane.showMessageDialog(null, String.format(
resources.getString("message.invalidUnit.format"),
UnitUtil.validateUnit(tempEntity)));
}

UiLoader.loadUi(tempEntity);
UiLoader.loadUi(recentUnit, unitFile.toString());
return true;
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, String.format(
resources.getString("message.invalidUnit.format"),
ex.getMessage()));
PopupMessages.showFileReadError(null, unitFile.toString(), ex.getMessage());
return false;
}
}

private MegaMekLab() { }
}
71 changes: 49 additions & 22 deletions megameklab/src/megameklab/ui/MegaMekLabMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,49 @@

public abstract class MegaMekLabMainUI extends JFrame implements RefreshListener, EntitySource, MenuBarOwner {
private Entity entity = null;
private String fileName = "";
protected MenuBar mmlMenuBar;
protected boolean refreshRequired = false;

public MegaMekLabMainUI() {
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(new ExitOnWindowClosingListener(this));
setResizable(true);
setExtendedState(CConfig.getIntParam("WINDOWSTATE"));
setExtendedState(CConfig.getIntParam(CConfig.GUI_FULLSCREEN));
}

protected void finishSetup() {
mmlMenuBar = new MenuBar(this);
setJMenuBar(mmlMenuBar);
reloadTabs();
setSizeAndLocation();
refreshAll();
}

protected void setSizeAndLocation() {
pack();
restrictToScrenSize();
CConfig.getMainUiWindowSize(this).ifPresent(this::setSize);
CConfig.getMainUiWindowPosition(this).ifPresent(this::setLocation);
setLocationRelativeTo(null);
}

private void restrictToScrenSize() {
DisplayMode currentMonitor = getGraphicsConfiguration().getDevice().getDisplayMode();
int scaledMonitorW = UIUtil.getScaledScreenWidth(currentMonitor);
int scaledMonitorH = UIUtil.getScaledScreenHeight(currentMonitor);
int w = Math.min(getSize().width, scaledMonitorW);
int h = Math.min(getSize().height, scaledMonitorH);
setSize(new Dimension(w, h));
}

// figure out size dimensions
pack();
setLocationRelativeTo(null);
int w = getSize().width;
int h = getSize().height;

if (scaledMonitorW < w) {
w = scaledMonitorW;
@Override
public void setVisible(boolean b) {
if (b) {
setSizeAndLocation();
}
if (scaledMonitorH < h) {
h = scaledMonitorH;
super.setVisible(b);
if (!b && (getFloatingEquipmentDatabase() != null)) {
getFloatingEquipmentDatabase().setVisible(false);
}
Dimension size = new Dimension(w, h);
setSize(size);
setPreferredSize(size);
setLocationRelativeTo(null);
}

@Override
Expand All @@ -83,7 +87,7 @@ public boolean safetyPrompt() {
JOptionPane.WARNING_MESSAGE);
// When the user did not actually save the unit, return as if CANCEL was pressed
return (savePrompt == JOptionPane.NO_OPTION)
|| ((savePrompt == JOptionPane.YES_OPTION) && mmlMenuBar.saveEntity(entity));
|| ((savePrompt == JOptionPane.YES_OPTION) && mmlMenuBar.saveUnit());
}
}

Expand All @@ -93,8 +97,9 @@ public boolean exit() {
return false;
}

CConfig.setParam("WINDOWSTATE", Integer.toString(getExtendedState()));
CConfig.setParam(CConfig.CONFIG_PLAF, UIManager.getLookAndFeel().getClass().getName());
CConfig.setParam(CConfig.GUI_FULLSCREEN, Integer.toString(getExtendedState()));
CConfig.setParam(CConfig.GUI_PLAF, UIManager.getLookAndFeel().getClass().getName());
CConfig.writeMainUiWindowSettings(this);
CConfig.saveConfig();
PreferenceManager.getInstance().save();
MegaMek.getMMPreferences().saveToFile(MMLConstants.MM_PREFERENCES_FILE);
Expand All @@ -117,7 +122,10 @@ public boolean exit() {
public abstract void refreshEquipment();

@Override
public abstract void refreshHeader();
public void refreshHeader() {
String fileInfo = fileName.isBlank() ? "" : " (" + fileName + ")";
setTitle(getEntity().getChassis() + " " + getEntity().getModel() + fileInfo);
}

@Override
public abstract void refreshStatus();
Expand All @@ -132,14 +140,18 @@ public boolean exit() {
public abstract void refreshPreview();

public void setEntity(Entity en) {
entity = en;
setEntity(en, "");
}

@Override
public Entity getEntity() {
return entity;
}

public void setEntity(Entity entity, String currentEntityFilename) {
this.entity = entity;
setFileName(currentEntityFilename);
}

@Override
public void scheduleRefresh() {
Expand All @@ -160,4 +172,19 @@ private void performRefresh() {
public JFrame getFrame() {
return this;
}

@Override
public String getFileName() {
return fileName;
}

public void setFileName(String fileName) {
this.fileName = fileName;
refreshHeader();
}

@Override
public void refreshMenuBar() {
mmlMenuBar.refreshMenuBar();
}
}
Loading

0 comments on commit d04fd5c

Please sign in to comment.