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

Added MHQDialogImmersive for Immersive Dialog Functionality that Immersively Improves Immersion #5709

Merged
merged 7 commits into from
Jan 9, 2025
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
/*
* Copyright (c) 2021 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MekHQ.
*
* MekHQ 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.
*
* MekHQ 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 MekHQ. If not, see <http://www.gnu.org/licenses/>.
*/
package mekhq.gui.baseComponents;
import megamek.client.ui.baseComponents.AbstractDialog;
import mekhq.MekHQ;
import javax.swing.*;
import java.util.ResourceBundle;
/**
* This is the base class for dialogs in MegaMek. This class handles setting the UI, managing the X
* button, managing the escape key, and saving the dialog preferences.
*
* Inheriting classes must call initialize() in their constructors and override createCenterPane()
*/
public abstract class AbstractMHQDialog extends AbstractDialog {
//region Constructors
/**
* This creates a non-modal AbstractMHQDialog using the default MHQ resource bundle. This is
* the normal constructor to use for an AbstractMHQDialog.
*/
protected AbstractMHQDialog(final JFrame frame, final String name, final String title) {
this(frame, false, name, title);
}
/**
* This creates an AbstractMHQDialog using the default MHQ resource bundle. It allows one
* to create modal dialogs.
*/
protected AbstractMHQDialog(final JFrame frame, final boolean modal, final String name, final String title) {
this(frame, modal, ResourceBundle.getBundle("mekhq.resources.GUI",
MekHQ.getMHQOptions().getLocale()), name, title);
}
/**
* This creates an AbstractMHQDialog using the specified resource bundle. This is not recommended
* by default.
*/
protected AbstractMHQDialog(final JFrame frame, final boolean modal, final ResourceBundle resources,
final String name, final String title) {
super(frame, modal, resources, name, title);
}
//endregion Constructors
/**
* This override forces the preferences for this class to be tracked in MekHQ instead of MegaMek.
* @throws Exception if there's an issue initializing the preferences. Normally this means
* a component has <strong>not</strong> had its name value set.
*/
@Override
protected void setPreferences() throws Exception {
setPreferences(MekHQ.getMHQPreferences().forClass(getClass()));
}
}
/*
* Copyright (c) 2021-2025 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MekHQ.
*
* MekHQ 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.
*
* MekHQ 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 MekHQ. If not, see <http://www.gnu.org/licenses/>.
*/
package mekhq.gui.baseComponents;

import megamek.client.ui.baseComponents.AbstractDialog;
import mekhq.MekHQ;

import javax.swing.*;
import java.util.ResourceBundle;

/**
* This is the base class for dialogs in MegaMek. This class handles setting the UI, managing the X
* button, managing the escape key, and saving the dialog preferences.
* <p>
* Inheriting classes must call initialize() in their constructors and override createCenterPane()
*/
public abstract class AbstractMHQDialogBasic extends AbstractDialog {
//region Constructors
/**
* This creates a non-modal AbstractMHQDialog using the default MHQ resource bundle. This is
* the normal constructor to use for an AbstractMHQDialog.
*/
protected AbstractMHQDialogBasic(final JFrame frame, final String name, final String title) {
this(frame, false, name, title);
}

/**
* This creates an AbstractMHQDialog using the default MHQ resource bundle. It allows one
* to create modal dialogs.
*/
protected AbstractMHQDialogBasic(final JFrame frame, final boolean modal, final String name, final String title) {
this(frame, modal, ResourceBundle.getBundle("mekhq.resources.GUI",
MekHQ.getMHQOptions().getLocale()), name, title);
}

/**
* This creates an AbstractMHQDialog using the specified resource bundle. This is not recommended
* by default.
*/
protected AbstractMHQDialogBasic(final JFrame frame, final boolean modal, final ResourceBundle resources,
final String name, final String title) {
super(frame, modal, resources, name, title);
}
//endregion Constructors

/**
* This override forces the preferences for this class to be tracked in MekHQ instead of MegaMek.
* @throws Exception if there's an issue initializing the preferences. Normally this means
* a component has <strong>not</strong> had its name value set.
*/
@Override
protected void setPreferences() throws Exception {
setPreferences(MekHQ.getMHQPreferences().forClass(getClass()));
}
}
59 changes: 2 additions & 57 deletions MekHQ/src/mekhq/gui/baseComponents/AbstractMHQNagDialog.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 The MegaMek Team. All Rights Reserved.
* Copyright (c) 2024-2025 The MegaMek Team. All Rights Reserved.
*
* This file is part of MekHQ.
*
Expand All @@ -22,16 +22,13 @@
import mekhq.MekHQ;
import mekhq.campaign.Campaign;
import mekhq.campaign.Campaign.AdministratorSpecialization;
import mekhq.campaign.force.Force;
import mekhq.campaign.personnel.Person;
import mekhq.campaign.personnel.enums.PersonnelRole;
import mekhq.campaign.unit.Unit;

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

import static mekhq.campaign.force.Force.FORCE_NONE;
import static mekhq.gui.baseComponents.MHQDialogImmersive.getSpeakerDescription;
import static mekhq.gui.dialog.resupplyAndCaches.ResupplyDialogUtilities.getSpeakerIcon;
import static mekhq.utilities.ImageUtilities.scaleImageIconToWidth;

Expand Down Expand Up @@ -223,58 +220,6 @@ public void setRightDescriptionMessage(String rightDescriptionMessage) {
pack();
}

/**
* Assembles the speaker description based on the provided speaker and campaign details.
*
* <p>
* The description includes:
* <ul>
* <li>The speaker's title and roles (both primary and secondary, if applicable).</li>
* <li>The force associated with the speaker.</li>
* <li>A fallback to the campaign name if the speaker is not available.</li>
* </ul>
*
* @param campaign The current campaign.
* @param speaker The {@link Person} representing the speaker, or {@code null} to use fallback data.
* @param speakerName The name/title to use for the speaker if one exists.
* @return A {@link StringBuilder} containing the formatted HTML description of the speaker.
*/
public static StringBuilder getSpeakerDescription(Campaign campaign, Person speaker, String speakerName) {
StringBuilder speakerDescription = new StringBuilder();

if (speaker != null) {
speakerDescription.append("<b>").append(speakerName).append("</b>");

boolean isClan = campaign.getFaction().isClan();

PersonnelRole primaryRole = speaker.getPrimaryRole();
if (!primaryRole.isNone()) {
speakerDescription.append("<br>").append(primaryRole.getName(isClan));
}

PersonnelRole secondaryRole = speaker.getSecondaryRole();
if (!secondaryRole.isNone()) {
speakerDescription.append("<br>").append(secondaryRole.getName(isClan));
}

Unit assignedUnit = speaker.getUnit();
if (assignedUnit != null) {
int forceId = assignedUnit.getForceId();

if (forceId != FORCE_NONE) {
Force force = campaign.getForce(forceId);

if (force != null) {
speakerDescription.append("<br>").append(force.getName());
}
}
}
} else {
speakerDescription.append("<b>").append(campaign.getName()).append("</b>");
}
return speakerDescription;
}

/**
* Checks if the user selected the "Advance Day" action.
*
Expand Down
Loading
Loading