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

Tabbed UI Improvements #1679

Merged
merged 2 commits into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions megameklab/src/megameklab/ui/MegaMekLabMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import megamek.MegaMek;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.Entity;
import megamek.common.Mounted;
import megamek.common.preference.PreferenceManager;
import megameklab.MMLConstants;
import megameklab.MegaMekLab;
Expand Down Expand Up @@ -212,4 +213,12 @@ public MenuBar getMMLMenuBar() {
public void setOwner(MegaMekLabTabbedUI owner) {
this.owner = owner;
}

/**
* Retrieves a list of mounted components that are currently not assigned to a location.
* Such equipment would be deleted on save and reload.
*
* @return a List containing unallocated Mounted objects.
*/
public abstract java.util.List<Mounted<?>> getUnallocatedMounted();
}
101 changes: 94 additions & 7 deletions megameklab/src/megameklab/ui/MegaMekLabTabbedUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,104 @@ public MenuBar getMMLMenuBar() {
private class NewTabButton extends JPanel {
public NewTabButton() {
setOpaque(false);
var button = new JButton("➕");
button.setForeground(Color.GREEN);
button.setFont(Font.getFont("Symbola"));
button.setFocusable(false);
button.setBorder(BorderFactory.createEmptyBorder());
var newUnitButton = new JButton("➕");
newUnitButton.setForeground(Color.GREEN);
newUnitButton.setFont(Font.getFont("Symbola"));
newUnitButton.setFocusable(false);
newUnitButton.setBorder(BorderFactory.createEmptyBorder());
newUnitButton.setToolTipText("<html>New Blank Mek<br>Right Click: Select Unit Type");

newUnitButton.addActionListener(e -> newTab());
newUnitButton.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
Fixed Show fixed Hide fixed
if (e.isPopupTrigger()) {
newUnitPopupMenu().show(e.getComponent(), e.getX(), e.getY());
}
}

@Override
public void mouseReleased(MouseEvent e) {
Fixed Show fixed Hide fixed
if (e.isPopupTrigger()) {
newUnitPopupMenu().show(e.getComponent(), e.getX(), e.getY());
}
}
});

add(newUnitButton);

var loadUnitButton = new JButton("⌸");
loadUnitButton.setFont(Font.getFont("Symbola"));
loadUnitButton.setForeground(Color.CYAN);
loadUnitButton.setFocusable(false);
loadUnitButton.setBorder(BorderFactory.createEmptyBorder());
loadUnitButton.setToolTipText("<html>Load unit from cache<br>Right Click: Load Unit Menu");

loadUnitButton.addActionListener(e -> StartupGUI.selectAndLoadUnitFromCache(MegaMekLabTabbedUI.this));
loadUnitButton.addMouseListener(new MouseAdapter() {

@Override
public void mousePressed(MouseEvent e) {
Fixed Show fixed Hide fixed
if (e.isPopupTrigger()) {
loadUnitMenu().show(e.getComponent(), e.getX(), e.getY());
}
}

@Override
public void mouseReleased(MouseEvent e) {
Fixed Show fixed Hide fixed
if (e.isPopupTrigger()) {
loadUnitMenu().show(e.getComponent(), e.getX(), e.getY());
}
}
});

add(loadUnitButton);
}

private JPopupMenu newUnitPopupMenu() {
var menu = new JPopupMenu();
menu.add(newUnitItem("New Mek", Entity.ETYPE_MEK, false));
menu.add(newUnitItem("New Fighter", Entity.ETYPE_AERO, false));
menu.add(newUnitItem("New DropShip/Small Craft", Entity.ETYPE_DROPSHIP, false));
menu.add(newUnitItem("New Advanced Aerospace", Entity.ETYPE_JUMPSHIP, false));
menu.add(newUnitItem("New Tank", Entity.ETYPE_TANK, false));
menu.add(newUnitItem("New Support Vehicle", Entity.ETYPE_SUPPORT_TANK, false));
menu.add(newUnitItem("New Battle Armor", Entity.ETYPE_BATTLEARMOR, false));
menu.add(newUnitItem("New Conventional Infantry", Entity.ETYPE_INFANTRY, false));
menu.add(newUnitItem("New ProtoMek", Entity.ETYPE_PROTOMEK, false));

var primitive = new JMenu("New Primitive...");
primitive.add(newUnitItem("New Mek", Entity.ETYPE_MEK, true));
primitive.add(newUnitItem("New Fighter", Entity.ETYPE_AERO, true));
primitive.add(newUnitItem("New DropShip/Small Craft", Entity.ETYPE_DROPSHIP, true));
primitive.add(newUnitItem("New JumpShip", Entity.ETYPE_JUMPSHIP, true));

menu.add(primitive);

return menu;
}

button.addActionListener(e -> {
private JMenuItem newUnitItem(String name, long entityType, boolean primitive) {
var item = new JMenuItem(name);
item.addActionListener(e -> {
newTab();
newUnit(entityType, primitive);
});
return item;
}

private JPopupMenu loadUnitMenu() {
var menu = new JPopupMenu();

var fromCache = new JMenuItem("Load from cache");
fromCache.addActionListener(e -> StartupGUI.selectAndLoadUnitFromCache(MegaMekLabTabbedUI.this));
menu.add(fromCache);

var fromFile = new JMenuItem("Load from file");
fromFile.addActionListener(e -> getMMLMenuBar().loadUnitFromFile(-1));
menu.add(fromFile);

add(button);
return menu;
}
}

Expand Down
2 changes: 1 addition & 1 deletion megameklab/src/megameklab/ui/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ private void exportSummary(ViewFormatting formatting) {
}
}

private void loadUnitFromFile(int fileNumber) {
public void loadUnitFromFile(int fileNumber) {
File unitFile;
if (fileNumber > 0) {
String recentFileName = CConfig.getRecentFile(fileNumber);
Expand Down
5 changes: 5 additions & 0 deletions megameklab/src/megameklab/ui/battleArmor/BABuildTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public class BABuildTab extends ITab {

private RefreshListener refresh = null;
private final ArrayList<BACriticalView> critViews = new ArrayList<>();

public BABuildView getBuildView() {
return buildView;
}

private final BABuildView buildView;

/** Panel for displaying the critical trees for each trooper in the squad. */
Expand Down
6 changes: 6 additions & 0 deletions megameklab/src/megameklab/ui/battleArmor/BABuildView.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.BorderFactory;
Expand Down Expand Up @@ -66,6 +67,11 @@ public class BABuildView extends IView implements ActionListener, MouseListener
private JPanel mainPanel = new JPanel();

private CriticalTableModel equipmentList;

public List<Mounted<?>> getEquipment() {
return equipmentList.getCrits();
}

private Vector<Mounted<?>> masterEquipmentList = new Vector<>(10, 1);
private JTable equipmentTable = new JTable();
private JScrollPane equipmentScroll = new JScrollPane();
Expand Down
14 changes: 10 additions & 4 deletions megameklab/src/megameklab/ui/battleArmor/BAMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import javax.swing.*;
import java.awt.*;
import java.util.List;

public class BAMainUI extends MegaMekLabMainUI {

Expand Down Expand Up @@ -123,7 +124,7 @@ public void refreshBuild() {
public void refreshEquipment() {
equipTab.refresh();
}

@Override
public void refreshTransport() {
// not used for ba
Expand All @@ -146,10 +147,10 @@ public void refreshWeapons() { }
public void refreshPreview() {
structureTab.refreshPreview();
}

@Override
public void refreshSummary() { }

@Override
public void refreshEquipmentTable() {
equipTab.refreshTable();
Expand All @@ -164,4 +165,9 @@ public ITechManager getTechManager() {
public JDialog getFloatingEquipmentDatabase() {
return floatingEquipmentDatabase;
}
}

@Override
public List<Mounted<?>> getUnallocatedMounted() {
return buildTab.getBuildView().getEquipment();
}
}
5 changes: 5 additions & 0 deletions megameklab/src/megameklab/ui/combatVehicle/CVBuildTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public class CVBuildTab extends ITab implements ActionListener {

private RefreshListener refresh = null;
private CVCriticalView critView;

public UnallocatedView getUnallocatedView() {
return unallocatedView;
}

private UnallocatedView unallocatedView;

private JButton autoFillButton = new JButton("Auto Fill");
Expand Down
10 changes: 8 additions & 2 deletions megameklab/src/megameklab/ui/combatVehicle/CVMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import javax.swing.*;
import java.awt.*;
import java.util.List;

public class CVMainUI extends MegaMekLabMainUI {

Expand Down Expand Up @@ -63,7 +64,7 @@ public void reloadTabs() {
buildTab.addRefreshedListener(this);
fluffTab.setRefreshedListener(this);
statusbar.addRefreshedListener(this);

previewTab = new PreviewTab(this);

configPane.addTab("Structure/Armor", new TabScrollPane(structureTab));
Expand Down Expand Up @@ -217,4 +218,9 @@ public ITechManager getTechManager() {
public JDialog getFloatingEquipmentDatabase() {
return floatingEquipmentDatabase;
}
}

@Override
public List<Mounted<?>> getUnallocatedMounted() {
return buildTab.getUnallocatedView().getEquipment();
}
}
5 changes: 5 additions & 0 deletions megameklab/src/megameklab/ui/fighterAero/ASBuildTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
public class ASBuildTab extends ITab implements ActionListener {
private RefreshListener refresh = null;
private ASCriticalView critView = null;

public ASBuildView getBuildView() {
return buildView;
}

private ASBuildView buildView = null;
private JPanel buttonPanel = new JPanel();
private JPanel mainPanel = new JPanel();
Expand Down
6 changes: 6 additions & 0 deletions megameklab/src/megameklab/ui/fighterAero/ASBuildView.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.BorderFactory;
Expand Down Expand Up @@ -60,6 +61,11 @@ public class ASBuildView extends IView implements ActionListener, MouseListener
private static final MMLogger logger = MMLogger.create(ASBuildView.class);

private CriticalTableModel equipmentList;

public List<Mounted<?>> getEquipment() {
return equipmentList.getCrits();
}

private Vector<Mounted<?>> masterEquipmentList = new Vector<>(10, 1);
private JTable equipmentTable = new JTable();
private JScrollPane equipmentScroll = new JScrollPane();
Expand Down
16 changes: 7 additions & 9 deletions megameklab/src/megameklab/ui/fighterAero/ASMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,13 @@
package megameklab.ui.fighterAero;

import java.awt.BorderLayout;
import java.util.List;

import javax.swing.JDialog;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;

import megamek.common.Aero;
import megamek.common.AeroSpaceFighter;
import megamek.common.ConvFighter;
import megamek.common.Engine;
import megamek.common.Entity;
import megamek.common.EquipmentType;
import megamek.common.ITechManager;
import megamek.common.SimpleTechLevel;
import megamek.common.TechConstants;
import megamek.common.*;
import megamek.logging.MMLogger;
import megameklab.ui.MegaMekLabMainUI;
import megameklab.ui.dialog.FloatingEquipmentDatabaseDialog;
Expand Down Expand Up @@ -219,4 +212,9 @@ public ITechManager getTechManager() {
public JDialog getFloatingEquipmentDatabase() {
return floatingEquipmentDatabase;
}

@Override
public List<Mounted<?>> getUnallocatedMounted() {
return buildTab.getBuildView().getEquipment();
}
}
6 changes: 6 additions & 0 deletions megameklab/src/megameklab/ui/generalUnit/UnallocatedView.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import java.util.Vector;
import java.util.function.Supplier;

Expand Down Expand Up @@ -52,6 +53,11 @@ public class UnallocatedView extends IView implements ActionListener, MouseListe
private static final MMLogger logger = MMLogger.create(UnallocatedView.class);

private CriticalTableModel equipmentList;

public List<Mounted<?>> getEquipment() {
return equipmentList.getCrits();
}

private Vector<Mounted<?>> masterEquipmentList = new Vector<>(10, 1);
private JTable equipmentTable = new JTable();

Expand Down
8 changes: 7 additions & 1 deletion megameklab/src/megameklab/ui/infantry/CIMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package megameklab.ui.infantry;

import java.awt.BorderLayout;
import java.util.List;

import javax.swing.*;

Expand Down Expand Up @@ -129,6 +130,11 @@ public JDialog getFloatingEquipmentDatabase() {
return null;
}

@Override
public List<Mounted<?>> getUnallocatedMounted() {
return List.of();
}

@Override
public void refreshSummary() { }

Expand All @@ -144,4 +150,4 @@ public ITechManager getTechManager() {
}
return null;
}
}
}
6 changes: 6 additions & 0 deletions megameklab/src/megameklab/ui/largeAero/DSMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package megameklab.ui.largeAero;

import java.awt.BorderLayout;
import java.util.List;

import javax.swing.JDialog;
import javax.swing.JTabbedPane;
Expand Down Expand Up @@ -233,4 +234,9 @@ public void refreshPreview() {
public JDialog getFloatingEquipmentDatabase() {
return floatingEquipmentDatabase;
}

@Override
public List<Mounted<?>> getUnallocatedMounted() {
return buildTab.getBuildView().getEquipment();
}
}
5 changes: 5 additions & 0 deletions megameklab/src/megameklab/ui/largeAero/LABuildTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
public class LABuildTab extends ITab implements ActionListener {
private RefreshListener refresh = null;
private LACriticalView critView = null;

public LABuildView getBuildView() {
return buildView;
}

private LABuildView buildView = null;
private JPanel buttonPanel = new JPanel();
private JPanel mainPanel = new JPanel();
Expand Down
Loading
Loading