Skip to content

Commit

Permalink
Merge pull request #1342 from SJuliez/QuirksTab
Browse files Browse the repository at this point in the history
Quirk editing in MML
  • Loading branch information
SJuliez authored Dec 13, 2023
2 parents aec7d0a + f39b23b commit 1a429bd
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 19,223 deletions.
19,142 changes: 0 additions & 19,142 deletions megameklab/data/canonUnitQuirks.xml

This file was deleted.

62 changes: 0 additions & 62 deletions megameklab/data/unitQuirksSchema.xsd

This file was deleted.

6 changes: 0 additions & 6 deletions megameklab/src/megameklab/MegaMekLab.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import megamek.client.ui.preferences.SuitePreferences;
import megamek.common.EquipmentType;
import megamek.common.MechSummaryCache;
import megamek.common.QuirksHandler;
import megameklab.ui.StartupGUI;
import megameklab.util.CConfig;
import megameklab.util.UnitUtil;
Expand Down Expand Up @@ -69,11 +68,6 @@ public static String getUnderlyingInformation(final String originProject) {
private static void startup() {
EquipmentType.initializeTypes();
MechSummaryCache.getInstance();
try {
QuirksHandler.initQuirksList();
} catch (Exception ex) {
LogManager.getLogger().warn("Could not load quirks", ex);
}
CConfig.load();
UnitUtil.loadFonts();

Expand Down
5 changes: 4 additions & 1 deletion megameklab/src/megameklab/ui/battleArmor/BAMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import megameklab.ui.MegaMekLabMainUI;
import megameklab.ui.dialog.FloatingEquipmentDatabaseDialog;
import megameklab.ui.generalUnit.FluffTab;
import megameklab.ui.generalUnit.QuirksTab;
import megameklab.ui.util.TabScrollPane;

import javax.swing.*;
Expand All @@ -33,6 +34,7 @@ public class BAMainUI extends MegaMekLabMainUI {
private BAEquipmentTab equipTab;
private FluffTab fluffTab;
private BAStatusBar statusbar;
private QuirksTab quirksTab;
private FloatingEquipmentDatabaseDialog floatingEquipmentDatabase;

public BAMainUI() {
Expand All @@ -51,7 +53,7 @@ public void reloadTabs() {
structureTab = new BAStructureTab(this);
equipTab = new BAEquipmentTab(this);
fluffTab = new FluffTab(this);

quirksTab = new QuirksTab(this);
statusbar = new BAStatusBar(this);
buildTab = new BABuildTab(this);
structureTab.addRefreshedListener(this);
Expand All @@ -63,6 +65,7 @@ public void reloadTabs() {
configPane.addTab("Equipment", equipTab);
configPane.addTab("Assign Criticals", new TabScrollPane(buildTab));
configPane.addTab("Fluff", new TabScrollPane(fluffTab));
configPane.addTab("Quirks", new TabScrollPane(quirksTab, quirksTab.refreshOnShow));

add(configPane, BorderLayout.CENTER);
add(statusbar, BorderLayout.SOUTH);
Expand Down
4 changes: 4 additions & 0 deletions megameklab/src/megameklab/ui/combatVehicle/CVMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import megameklab.ui.generalUnit.AbstractEquipmentTab;
import megameklab.ui.generalUnit.FluffTab;
import megameklab.ui.generalUnit.PreviewTab;
import megameklab.ui.generalUnit.QuirksTab;
import megameklab.ui.util.TabScrollPane;

import javax.swing.*;
Expand All @@ -37,6 +38,7 @@ public class CVMainUI extends MegaMekLabMainUI {
private CVBuildTab buildTab;
private FluffTab fluffTab;
private CVStatusBar statusbar;
private QuirksTab quirksTab;
private FloatingEquipmentDatabaseDialog floatingEquipmentDatabase;

public CVMainUI() {
Expand All @@ -56,6 +58,7 @@ public void reloadTabs() {
equipmentTab = new CVEquipmentTab(this);
buildTab = new CVBuildTab(this);
fluffTab = new FluffTab(this);
quirksTab = new QuirksTab(this);
structureTab.addRefreshedListener(this);
equipmentTab.addRefreshedListener(this);
buildTab.addRefreshedListener(this);
Expand All @@ -68,6 +71,7 @@ public void reloadTabs() {
configPane.addTab("Equipment", equipmentTab);
configPane.addTab("Assign Criticals", new TabScrollPane(buildTab));
configPane.addTab("Fluff", new TabScrollPane(fluffTab));
configPane.addTab("Quirks", new TabScrollPane(quirksTab, quirksTab.refreshOnShow));
configPane.addTab("Preview", previewTab);

add(configPane, BorderLayout.CENTER);
Expand Down
4 changes: 4 additions & 0 deletions megameklab/src/megameklab/ui/fighterAero/ASMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import megameklab.ui.generalUnit.AbstractEquipmentTab;
import megameklab.ui.generalUnit.FluffTab;
import megameklab.ui.generalUnit.PreviewTab;
import megameklab.ui.generalUnit.QuirksTab;
import megameklab.ui.util.TabScrollPane;
import org.apache.logging.log4j.LogManager;

Expand All @@ -37,6 +38,7 @@ public class ASMainUI extends MegaMekLabMainUI {
private ASBuildTab buildTab;
private FluffTab fluffTab;
private ASStatusBar statusbar;
private QuirksTab quirksTab;
private FloatingEquipmentDatabaseDialog floatingEquipmentDatabase;

public ASMainUI(boolean primitive) {
Expand All @@ -58,6 +60,7 @@ public void reloadTabs() {
equipmentTab = new ASEquipmentTab(this);
buildTab = new ASBuildTab(this);
fluffTab = new FluffTab(this);
quirksTab = new QuirksTab(this);
structureTab.addRefreshedListener(this);
equipmentTab.addRefreshedListener(this);
buildTab.addRefreshedListener(this);
Expand All @@ -68,6 +71,7 @@ public void reloadTabs() {
configPane.addTab("Equipment", equipmentTab);
configPane.addTab("Assign Criticals", new TabScrollPane(buildTab));
configPane.addTab("Fluff", new TabScrollPane(fluffTab));
configPane.addTab("Quirks", new TabScrollPane(quirksTab, quirksTab.refreshOnShow));
configPane.addTab("Preview", previewTab);

add(configPane, BorderLayout.CENTER);
Expand Down
127 changes: 127 additions & 0 deletions megameklab/src/megameklab/ui/generalUnit/QuirksTab.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* Copyright (c) 2023 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMekLab.
*
* MegaMek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MegaMek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/
package megameklab.ui.generalUnit;

import megamek.client.ui.GBC;
import megamek.client.ui.swing.DialogOptionComponent;
import megamek.client.ui.swing.DialogOptionListener;
import megamek.common.MiscType;
import megamek.common.Mounted;
import megamek.common.options.IOption;
import megamek.common.options.IOptionGroup;
import megamek.common.options.Quirks;
import megamek.common.options.WeaponQuirks;
import megameklab.ui.EntitySource;
import megameklab.ui.util.ITab;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;

public class QuirksTab extends ITab implements DialogOptionListener {

private final HashMap<Integer, ArrayList<DialogOptionComponent>> wpnQuirkComps = new HashMap<>();
private final HashMap<Integer, WeaponQuirks> wpnQuirks = new HashMap<>();

public QuirksTab(EntitySource eSource) {
super(eSource);
setLayout(new GridBagLayout());
refreshQuirks();
}

public void refreshQuirks() {
wpnQuirks.clear();
for (Mounted m : getEntity().getWeaponList()) {
wpnQuirks.put(getEntity().getEquipmentNum(m), m.getQuirks());
}
// Also need to consider melee weapons
for (Mounted m : getEntity().getMisc()) {
if (m.getType().hasFlag(MiscType.F_CLUB)) {
wpnQuirks.put(getEntity().getEquipmentNum(m), m.getQuirks());
}
}
removeAll();
for (Integer eqNum : wpnQuirks.keySet()) {
wpnQuirkComps.put(eqNum, new ArrayList<>());
}

for (Enumeration<IOptionGroup> i = getEntity().getQuirks().getGroups(); i.hasMoreElements(); ) {
IOptionGroup group = i.nextElement();
add(new JLabel(group.getDisplayableName()), GBC.eol());

for (Enumeration<IOption> j = group.getSortedOptions(); j.hasMoreElements(); ) {
IOption option = j.nextElement();

if (null == option || !Quirks.isQuirkLegalFor(option, getEntity())) {
continue;
}

addQuirk(option);
}
}

// now for weapon quirks
for (int key : wpnQuirks.keySet()) {
Mounted m = getEntity().getEquipment(key);
WeaponQuirks wpnQuirks = m.getQuirks();
JLabel labWpn = new JLabel(m.getName() + " ("
+ getEntity().getLocationName(m.getLocation()) + ")");
add(labWpn, GBC.eol());
for (Enumeration<IOptionGroup> i = wpnQuirks.getGroups(); i.hasMoreElements(); ) {
IOptionGroup group = i.nextElement();
for (Enumeration<IOption> j = group.getSortedOptions(); j.hasMoreElements(); ) {
IOption option = j.nextElement();
if (!WeaponQuirks.isQuirkLegalFor(option, getEntity(), m.getType())) {
continue;
}
addWeaponQuirk(key, option);
}
}
}
validate();
}

private void addQuirk(IOption option) {
DialogOptionComponent optionComp = new DialogOptionComponent(this, option, true);
add(optionComp, GBC.eol());
}

private void addWeaponQuirk(int key, IOption option) {
DialogOptionComponent optionComp = new DialogOptionComponent(this, option, true);
add(optionComp, GBC.eol());
wpnQuirkComps.get(key).add(optionComp);
}

@Override
public void optionClicked(DialogOptionComponent comp, IOption option, boolean state) {
option.setValue(state);
}

public ComponentListener refreshOnShow = new ComponentAdapter() {
@Override
public void componentShown(ComponentEvent e) {
refreshQuirks();
}
};
}
8 changes: 4 additions & 4 deletions megameklab/src/megameklab/ui/largeAero/DSMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
import megamek.common.*;
import megameklab.ui.MegaMekLabMainUI;
import megameklab.ui.dialog.FloatingEquipmentDatabaseDialog;
import megameklab.ui.generalUnit.AbstractEquipmentTab;
import megameklab.ui.generalUnit.FluffTab;
import megameklab.ui.generalUnit.PreviewTab;
import megameklab.ui.generalUnit.TransportTab;
import megameklab.ui.generalUnit.*;
import megameklab.ui.util.TabScrollPane;
import org.apache.logging.log4j.LogManager;

Expand All @@ -40,6 +37,7 @@ public class DSMainUI extends MegaMekLabMainUI {
private LABuildTab buildTab;
private TransportTab transportTab;
private DSStatusBar statusbar;
private QuirksTab quirksTab;
private FloatingEquipmentDatabaseDialog floatingEquipmentDatabase;

public DSMainUI(boolean primitive) {
Expand Down Expand Up @@ -150,6 +148,7 @@ public void reloadTabs() {
equipmentTab = new LAEquipmentTab(this);
buildTab = new LABuildTab(this);
transportTab = new TransportTab(this);
quirksTab = new QuirksTab(this);
FluffTab fluffTab = new FluffTab(this);
structureTab.addRefreshedListener(this);
equipmentTab.addRefreshedListener(this);
Expand All @@ -163,6 +162,7 @@ public void reloadTabs() {
configPane.addTab("Assign Criticals", new TabScrollPane(buildTab));
configPane.addTab("Transport Bays", new TabScrollPane(transportTab));
configPane.addTab("Fluff", new TabScrollPane(fluffTab));
configPane.addTab("Quirks", new TabScrollPane(quirksTab, quirksTab.refreshOnShow));
configPane.addTab("Preview", previewTab);

add(configPane, BorderLayout.CENTER);
Expand Down
8 changes: 4 additions & 4 deletions megameklab/src/megameklab/ui/largeAero/WSMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
import megamek.common.verifier.TestAdvancedAerospace;
import megameklab.ui.MegaMekLabMainUI;
import megameklab.ui.dialog.FloatingEquipmentDatabaseDialog;
import megameklab.ui.generalUnit.AbstractEquipmentTab;
import megameklab.ui.generalUnit.FluffTab;
import megameklab.ui.generalUnit.PreviewTab;
import megameklab.ui.generalUnit.TransportTab;
import megameklab.ui.generalUnit.*;
import megameklab.ui.util.TabScrollPane;
import org.apache.logging.log4j.LogManager;

Expand All @@ -40,6 +37,7 @@ public class WSMainUI extends MegaMekLabMainUI {
private LABuildTab buildTab;
private TransportTab transportTab;
private FluffTab fluffTab;
private QuirksTab quirksTab;
private WSStatusBar statusbar;
private FloatingEquipmentDatabaseDialog floatingEquipmentDatabase;

Expand Down Expand Up @@ -167,6 +165,7 @@ public void reloadTabs() {
buildTab = new LABuildTab(this);
fluffTab = new FluffTab(this);
transportTab = new TransportTab(this);
quirksTab = new QuirksTab(this);
structureTab.addRefreshedListener(this);
equipmentTab.addRefreshedListener(this);
buildTab.addRefreshedListener(this);
Expand All @@ -179,6 +178,7 @@ public void reloadTabs() {
configPane.addTab("Assign Criticals", new TabScrollPane(buildTab));
configPane.addTab("Transport Bays", new TabScrollPane(transportTab));
configPane.addTab("Fluff", new TabScrollPane(fluffTab));
configPane.addTab("Quirks", new TabScrollPane(quirksTab, quirksTab.refreshOnShow));
configPane.addTab("Preview", previewTab);

add(configPane, BorderLayout.CENTER);
Expand Down
Loading

0 comments on commit 1a429bd

Please sign in to comment.