Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tip of the Day #1821

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
17 changes: 17 additions & 0 deletions megameklab/resources/megameklab/resources/TipOfTheDay.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
TipOfTheDay.title.text=Tip of the Day:
TipOfTheDay.tip.1=You can copy a Record Sheet as image by doing right click and "Copy to clipboard" on it. You can then paste it in any image editor or even Discord.
TipOfTheDay.tip.2=Press CTRL+S to quickly save your current unit.
TipOfTheDay.tip.3=Use CTRL+Z to undo and CTRL+Y to redo recent changes to your unit design.
TipOfTheDay.tip.4=Customize your workspace by dragging tabs to reorder or separate them from the main window.
TipOfTheDay.tip.5=Right-click on equipment in the "Assign Criticals" tab for additional options.
TipOfTheDay.tip.6=The status bar shows any validation problems with your design.
TipOfTheDay.tip.7=Use "Unit Validation" to check if your design has any errors.
TipOfTheDay.tip.8=You can drag and drop MUL files onto the start screen to open them directly.
TipOfTheDay.tip.9=Use the BV Calculator to see how battle value is calculated for your unit.
TipOfTheDay.tip.10=MegaMekLab supports many rule levels and technology bases.
TipOfTheDay.tip.11=Double-check your heat sinks when designing 'Mechs.
TipOfTheDay.tip.12=Zoom in or out on Record Sheets using the mouse wheel, and click-drag to pan the view.
TipOfTheDay.tip.13=In the unit selection screen, you can select multiple units by holding down the CTRL key. SHIFT to select a range.
TipOfTheDay.tip.14=In the status bar, you can click on Weight, BV and Dry Cost for additional information.
TipOfTheDay.tip.15=To view several Record Sheets simultaneously, detach their tabs from the main window.
TipOfTheDay.tip.16=To examine multiple Record Sheets simultaneously, select several units at once in the unit selection screen.
75 changes: 56 additions & 19 deletions megameklab/src/megameklab/ui/StartupGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import megameklab.ui.util.ExitOnWindowClosingListener;
import megameklab.ui.util.MegaMekLabFileSaver;
import megameklab.ui.util.TabUtil;
import megamek.common.util.TipOfTheDay;
import megameklab.util.CConfig;
import megameklab.util.MMLFileDropTransferHandler;
import org.apache.commons.collections4.CollectionUtils;
Expand All @@ -43,11 +44,13 @@

/**
* A startup splash screen for MegaMekLab
*
* @author Taharqa
*/
public class StartupGUI extends SkinnedJPanel implements MenuBarOwner {
JFrame frame;
MenuBar mmlMenuBar;
JLabel splash;

/** A map of resolution widths to file names for the startup screen */
private final TreeMap<Integer, String> startupScreenImages = new TreeMap<>();
Expand All @@ -58,6 +61,8 @@ public class StartupGUI extends SkinnedJPanel implements MenuBarOwner {
}

private final ResourceBundle resourceMap = ResourceBundle.getBundle("megameklab.resources.Splash");
private final TipOfTheDay tipOfTheDay = new TipOfTheDay("megameklab.resources.TipOfTheDay");


public StartupGUI() {
super(UIComponents.MainMenuBorder, 1);
Expand All @@ -76,7 +81,8 @@ private void showImportSettingsDialog() {
CConfig.setParam(CConfig.NAG_IMPORT_SETTINGS, Boolean.toString(false));
int choice = JOptionPane.showConfirmDialog(this,
"Do you wish to import settings from another MML" +
"? You can also do this later from the main menu.", "Import Settings?", YES_NO_OPTION);
"? You can also do this later from the main menu.",
"Import Settings?", YES_NO_OPTION);
if (choice == JOptionPane.YES_OPTION) {
mmlMenuBar.importSettings();
}
Expand All @@ -91,11 +97,12 @@ private void initComponents() {
frame.setJMenuBar(mmlMenuBar);

Dimension scaledMonitorSize = UIUtil.getScaledScreenSize(frame);
JLabel splash = UIUtil.createSplashComponent(startupScreenImages, frame);
splash = UIUtil.createSplashComponent(startupScreenImages, frame);
splash.setOpaque(false);
add(splash, BorderLayout.CENTER);

JLabel labVersion = new JLabel(resourceMap.getString("version.text") + MMLConstants.VERSION, JLabel.CENTER);
labVersion.setPreferredSize(new Dimension(250,15));
labVersion.setPreferredSize(new Dimension(250, 15));
if (!skinSpec.fontColors.isEmpty()) {
labVersion.setForeground(skinSpec.fontColors.get(0));
}
Expand Down Expand Up @@ -153,12 +160,12 @@ private void initComponents() {
// the button width "look" reasonable.
int maximumWidth = (int) (0.9 * scaledMonitorSize.width) - splash.getPreferredSize().width;

//no more than 50% of image width
// no more than 50% of image width
if (maximumWidth > (int) (0.5 * splash.getPreferredSize().width)) {
maximumWidth = (int) (0.5 * splash.getPreferredSize().width);
}

Dimension minButtonDim = new Dimension((int)(maximumWidth / 1.618), 25);
Dimension minButtonDim = new Dimension((int) (maximumWidth / 1.618), 25);
if (textDim.getWidth() > minButtonDim.getWidth()) {
minButtonDim = textDim;
}
Expand Down Expand Up @@ -189,24 +196,32 @@ private void initComponents() {
// layout
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
// Left Column
// Left Column (Splash Image)
c.anchor = GridBagConstraints.WEST;
c.insets = new Insets(10, 5, 10, 10);
c.ipadx = 10; c.ipady = 5;
c.gridx = 0; c.gridy = 0;
c.ipadx = 10;
c.ipady = 5;
c.gridx = 0;
c.gridy = 0;
c.fill = GridBagConstraints.NONE;
c.weightx = 0.0; c.weighty = 0.0;
c.weightx = 0.0;
c.weighty = 0.0;
c.gridwidth = 1;
c.gridheight = 12;
add(splash, c);
// Right Column

// Right Column (Buttons)
c.insets = new Insets(2, 2, 2, 10);
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0; c.weighty = 1.0;
c.ipadx = 0; c.ipady = 0;
c.weightx = 1.0;
c.weighty = 1.0;
c.ipadx = 0;
c.ipady = 0;
c.gridheight = 1;
c.gridx = 1; c.gridy = 0;
c.gridx = 1;
c.gridy = 0;
add(labVersion, c);

c.gridy++;
add(btnLoadUnit, c);
c.gridy++;
Expand All @@ -230,6 +245,8 @@ private void initComponents() {
c.gridy++;
add(btnQuit, c);

setOpaque(false);

frame.setResizable(false);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(this, BorderLayout.CENTER);
Expand All @@ -241,6 +258,19 @@ private void initComponents() {
this.setTransferHandler(new MMLFileDropTransferHandler(this));
}

/**
* Override paint to draw the tip *after* children are painted.
*/
@Override
public void paint(Graphics g) {
super.paint(g); // Draw background, border, and children first

// Now draw the tip on top
if (splash != null && splash.isVisible() && splash.getWidth() > 0 && splash.getHeight() > 0) {
tipOfTheDay.drawTipOfTheDay((Graphics2D) g, splash.getBounds(), TipOfTheDay.Position.BOTTOM_BORDER);
}
}

private static String processFileName(File file, Entity newUnit) {
String fileName = file.toString();
if (fileName.toLowerCase().endsWith(".zip")) {
Expand All @@ -262,20 +292,25 @@ private static void addUnits(MegaMekLabUnitSelectorDialog viewer, MenuBarOwner o
}

/**
* Shows the Unit Selector Window and loads the unit if the user selects one. When the chosen
* unit fits the MageMekLabMainUI given as previousFrame this frame will be kept and updated
* to the chosen unit, otherwise, a new UI will be created for the unit and previousFrame will
* Shows the Unit Selector Window and loads the unit if the user selects one.
* When the chosen
* unit fits the MageMekLabMainUI given as previousFrame this frame will be kept
* and updated
* to the chosen unit, otherwise, a new UI will be created for the unit and
* previousFrame will
* be closed and disposed.
*
* @param previousFrame The active frame before loading a new unit; can be the StartupGUI or any
* @param previousFrame The active frame before loading a new unit; can be the
* StartupGUI or any
* MegaMekLabMainUI.
*/
public static void selectAndLoadUnitFromCache(MenuBarOwner previousFrame) {
UnitLoadingDialog unitLoadingDialog = new UnitLoadingDialog(previousFrame.getFrame());
unitLoadingDialog.setVisible(true);
MegaMekLabUnitSelectorDialog viewer;
if (previousFrame instanceof MegaMekLabTabbedUI tabbedUI) {
viewer = new MegaMekLabUnitSelectorDialog(previousFrame.getFrame(), unitLoadingDialog, dialog -> addUnits(dialog, tabbedUI));
viewer = new MegaMekLabUnitSelectorDialog(previousFrame.getFrame(), unitLoadingDialog,
dialog -> addUnits(dialog, tabbedUI));
} else {
viewer = new MegaMekLabUnitSelectorDialog(previousFrame.getFrame(), unitLoadingDialog, true);
}
Expand Down Expand Up @@ -309,7 +344,9 @@ public boolean hasEntityNameChanged() {

@Override
public void refreshMenuBar() {
mmlMenuBar.refreshMenuBar();
if (mmlMenuBar != null) {
mmlMenuBar.refreshMenuBar();
}
}

@Override
Expand Down
Loading