Skip to content

Commit

Permalink
Re-implemented the Ability Scores component in JavaFX
Browse files Browse the repository at this point in the history
  • Loading branch information
Lichtblitz committed Nov 2, 2023
1 parent e1da8f3 commit 4db9747
Show file tree
Hide file tree
Showing 17 changed files with 624 additions and 37 deletions.
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ plugins {
id "com.dorongold.task-tree" version '2.1.1' // Prints the task dependency tree
id 'org.openjfx.javafxplugin' version '0.1.0' // JavaFX support
id 'org.beryx.runtime' version '1.13.0' // Creates custom runtimes
id "io.freefair.lombok" version '8.4' // Adding Lombok support
}

/**
* Set the version and the modules we want from JavaFX (not everything)
*/
javafx {
version = "17"
version = "21"
modules = [ 'javafx.controls', 'javafx.web', 'javafx.swing', 'javafx.fxml', 'javafx.graphics' ]

/*
Expand Down Expand Up @@ -271,9 +272,9 @@ dependencies {
// https://github.com/TestFX/Monocle/issues/79
testImplementation group: 'org.testfx', name: 'openjfx-monocle', version: 'jdk-12.0.1+2'
constraints {
implementation('org.openjfx:javafx-base:17')
implementation('org.openjfx:javafx-controls:17')
implementation('org.openjfx:javafx-graphics:17') {
implementation('org.openjfx:javafx-base:21')
implementation('org.openjfx:javafx-controls:21')
implementation('org.openjfx:javafx-graphics:21') {
because 'Monocle uses 12.0.1+2 that does not support Mac`s ARM'
}
}
Expand Down
6 changes: 5 additions & 1 deletion code/src/java/pcgen/facade/core/CharacterFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.File;
import java.math.BigDecimal;
import java.util.List;

import pcgen.cdom.enumeration.CharID;
import pcgen.cdom.enumeration.Gender;
import pcgen.cdom.enumeration.Handed;
Expand All @@ -48,6 +47,7 @@
import pcgen.facade.util.ListFacade;
import pcgen.facade.util.ReferenceFacade;
import pcgen.facade.util.event.ChangeListener;
import pcgen.facade.util.event.ReferenceListener;
import pcgen.io.ExportException;
import pcgen.io.ExportHandler;

Expand Down Expand Up @@ -852,4 +852,8 @@ public interface CharacterFacade extends CompanionFacade
public String getPreviewSheetVar(String key);

public void addPreviewSheetVar(String key, String value);

public void addStatsBonusesChangedListener(ReferenceListener<Integer> listener);

public void removeStatsBonusesChangedListener(ReferenceListener<Integer> listener);
}
2 changes: 1 addition & 1 deletion code/src/java/pcgen/gui2/PCGenFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@
import pcgen.gui3.GuiUtility;
import pcgen.gui3.JFXPanelFromResource;
import pcgen.gui3.component.PCGenToolBar;
import pcgen.gui3.dialog.AboutDialog;
import pcgen.gui3.dialog.RememberingChoiceDialog;
import pcgen.gui3.dialog.TipOfTheDayController;
import pcgen.gui3.dialog.about.AboutDialog;
import pcgen.io.PCGFile;
import pcgen.persistence.SourceFileLoader;
import pcgen.system.CharacterManager;
Expand Down
20 changes: 17 additions & 3 deletions code/src/java/pcgen/gui2/facade/CharacterFacadeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import pcgen.cdom.base.AssociatedPrereqObject;
import pcgen.cdom.base.CDOMObject;
import pcgen.cdom.base.CDOMReference;
Expand Down Expand Up @@ -149,6 +149,7 @@
import pcgen.facade.util.event.ChangeListener;
import pcgen.facade.util.event.ListEvent;
import pcgen.facade.util.event.ListListener;
import pcgen.facade.util.event.ReferenceListener;
import pcgen.gui2.UIPropertyContext;
import pcgen.gui2.util.CoreInterfaceUtilities;
import pcgen.io.ExportException;
Expand All @@ -169,8 +170,6 @@
import pcgen.util.enumeration.Tab;
import pcgen.util.enumeration.View;

import org.apache.commons.lang3.StringUtils;

/**
* The Class {@code CharacterFacadeImpl} is an implementation of
* the {@link CharacterFacade} interface for the new user interface. It is
Expand Down Expand Up @@ -262,6 +261,7 @@ public class CharacterFacadeImpl
private TemplateListener templateListener;
private XPListener xpListener;
private AutoEquipListener autoEquipListener;
private DefaultReferenceFacade<Integer> statsBonusesChanged = new DefaultReferenceFacade<>(0);

/**
* Create a new character facade for an existing character.
Expand Down Expand Up @@ -460,6 +460,18 @@ private WriteableReferenceFacade<Number> getStatReferenceFacade(PCStat stat)
return ChannelCompatibility.getStatScore(theCharacter.getCharID(), stat);
}

@Override
public void addStatsBonusesChangedListener(ReferenceListener<Integer> listener)
{
statsBonusesChanged.addReferenceListener(listener);
}

@Override
public void removeStatsBonusesChangedListener(ReferenceListener<Integer> listener)
{
statsBonusesChanged.removeReferenceListener(listener);
}

/**
* Build up the list of kits that the character has.
*/
Expand Down Expand Up @@ -1598,6 +1610,8 @@ private void refreshStatScores()
charLevelsFacade.fireSkillBonusEvent(this, 0, true);
charLevelsFacade.updateSkillsTodo();
}

statsBonusesChanged.set(statsBonusesChanged.get() + 1);
}

@Override
Expand Down
60 changes: 50 additions & 10 deletions code/src/java/pcgen/gui2/tabs/SummaryInfoTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.net.URL;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.TreeSet;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Box;
Expand All @@ -61,7 +62,7 @@
import javax.swing.border.TitledBorder;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

import org.apache.commons.lang3.StringUtils;
import pcgen.cdom.enumeration.Gender;
import pcgen.cdom.enumeration.Handed;
import pcgen.cdom.util.CControl;
Expand Down Expand Up @@ -103,11 +104,16 @@
import pcgen.gui2.util.SimpleTextIcon;
import pcgen.gui3.JFXPanelFromResource;
import pcgen.gui3.SimpleHtmlPanelController;
import pcgen.gui3.tabs.summary.AbilityScores;
import pcgen.gui3.tabs.summary.AbilityScoresModel;
import pcgen.gui3.utilty.ColorUtilty;
import pcgen.system.LanguageBundle;
import pcgen.util.enumeration.Tab;

import org.apache.commons.lang3.StringUtils;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;

/**
* This component displays a basic summary of a character such as name,
Expand All @@ -120,7 +126,8 @@ public class SummaryInfoTab extends JPanel implements CharacterInfoTab, TodoHand
private final TabTitle tabTitle;
private final JPanel basicsPanel;
private final JPanel todoPanel;
private final JPanel scoresPanel;
private final JFXPanel scoresPanel;
private AbilityScores abilityScores;
private final JPanel racePanel;
private final JPanel classPanel;
private final JTextField characterNameField;
Expand Down Expand Up @@ -169,7 +176,7 @@ public class SummaryInfoTab extends JPanel implements CharacterInfoTab, TodoHand
this.tabTitle = new TabTitle(Tab.SUMMARY);
this.basicsPanel = new JPanel();
this.todoPanel = new JPanel();
this.scoresPanel = new JPanel();
this.scoresPanel = new JFXPanel();
this.racePanel = new JPanel();
this.classPanel = new JPanel();
this.characterNameField = new JTextField();
Expand Down Expand Up @@ -245,7 +252,8 @@ private void initComponents()
gbc.gridheight = GridBagConstraints.REMAINDER;
add(todoPanel, gbc);

initMiddlePanel(scoresPanel);
Platform.runLater(() -> initMiddlePanel(scoresPanel));

gbc.gridy = GridBagConstraints.RELATIVE;
gbc.weightx = 1;
add(scoresPanel, gbc);
Expand All @@ -257,6 +265,8 @@ private void initComponents()
gbc.weightx = 0.1;
gbc.weighty = 1;
add(rightPanel, gbc);


}

private static void setPanelTitle(JComponent panel, String title)
Expand Down Expand Up @@ -284,15 +294,34 @@ private void initTodoPanel(JPanel panel)
panel.add(scroll, BorderLayout.CENTER);
}

private void initMiddlePanel(JPanel middlePanel)
private void initMiddlePanel(JFXPanel middlePanel)
{
URL resource = AbilityScores.class.getResource(AbilityScores.class.getSimpleName() + ".fxml");
FXMLLoader loader = new FXMLLoader(resource, LanguageBundle.getBundle());

Scene scene = null;
try
{
scene = loader.load();
abilityScores = loader.getController();
}
catch (IOException e)
{
throw new RuntimeException(e);
}

middlePanel.setScene(scene);

StatTableModel.initializeTable(statsTable);


middlePanel.setLayout(new GridLayout(2, 1));

JPanel statsPanel = new JPanel();
setPanelTitle(statsPanel, LanguageBundle.getString("in_sumAbilityScores")); //$NON-NLS-1$
statsPanel.setLayout(new BoxLayout(statsPanel, BoxLayout.Y_AXIS));

StatTableModel.initializeTable(statsTable);

JScrollPane pane = new JScrollPane(statsTable, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER)
{
Expand Down Expand Up @@ -333,11 +362,12 @@ public Dimension getMaximumSize()
statTotalPanel.add(Box.createHorizontalGlue());
statsPanel.add(statTotalPanel);

middlePanel.add(statsPanel);
//middlePanel.add(statsPanel);

pane = new JScrollPane(infoPane);
setPanelTitle(pane, LanguageBundle.getString("in_sumStats")); //$NON-NLS-1$
middlePanel.add(pane);
//middlePanel.add(pane);

}

private void initRightPanel(JPanel rightPanel)
Expand Down Expand Up @@ -665,6 +695,8 @@ public ModelMap createModels(final CharacterFacade character)
models.put(ExpSubtractAction.class, new ExpSubtractAction(character));
models.put(TodoListHandler.class, new TodoListHandler(character));
models.put(HPHandler.class, new HPHandler(character));
//TODO: new
models.put(AbilityScoresModel.class, new AbilityScoresModel(character));
return models;
}

Expand All @@ -689,6 +721,9 @@ public void storeModels(ModelMap models)
models.get(HPHandler.class).uninstall();

models.get(ComboBoxRendererHandler.class).uninstall();

//TODO: new
models.get(AbilityScoresModel.class).uninstall();
}

@Override
Expand Down Expand Up @@ -722,6 +757,11 @@ public void restoreModels(ModelMap models)
expsubtractButton.setAction(models.get(ExpSubtractAction.class));
addLevelsAction.install();

//TODO: new
AbilityScoresModel abilityScoresModel = models.get(AbilityScoresModel.class);
abilityScoresModel.install();
abilityScores.getAbilityScoresModelProperty().set(abilityScoresModel);

resetBasicsPanel();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

package pcgen.gui3.dialog;
package pcgen.gui3.dialog.about;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;

import pcgen.gui3.Controllable;
import pcgen.gui3.GuiAssertions;
import pcgen.system.LanguageBundle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

package pcgen.gui3.dialog;
package pcgen.gui3.dialog.about;

import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;

import org.apache.commons.lang3.StringUtils;
import pcgen.gui2.tools.DesktopBrowserLauncher;
import pcgen.system.LanguageBundle;
import pcgen.system.PCGenPropBundle;
Expand All @@ -34,7 +34,6 @@
import javafx.scene.control.Labeled;
import javafx.scene.control.TextArea;
import javafx.scene.text.Text;
import org.apache.commons.lang3.StringUtils;

/**
* Controller for about panel.
Expand Down
Loading

0 comments on commit 4db9747

Please sign in to comment.