Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
Argent77 committed Jul 14, 2023
2 parents be795eb + 128d743 commit 9d1d11e
Show file tree
Hide file tree
Showing 169 changed files with 2,852 additions and 888 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/ant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Java CI with Apache Ant

on:
push:
branches: [ devel, master ]
branches: [ devel ]
pull_request:
branches: [ devel, master ]
branches: [ devel ]

jobs:
build:
Expand All @@ -17,4 +17,15 @@ jobs:
distribution: 'temurin'
java-version: '8'
- name: Build with Ant
run: ant -noinput -buildfile build.xml
run: |
hash=$(echo "${{ github.sha }}" | sed -e 's/\(.\{7\}\).*/\1/')
sed -i "s/\(VERSION *= *\"v\?[0-9]\+\.[0-9]\+\(\.[0-9]\+\)\?\)[^\"]*\"/\1-$(date +%Y%m%d) (${hash})\"/" src/org/infinity/NearInfinity.java
sed -i 's/debug="false"/debug="true"/' build.xml
ant -noinput -buildfile build.xml
- name: Upload artifact
uses: pyTooling/Actions/releaser@r0
with:
tag: nightly
rm: true
token: ${{ secrets.GITHUB_TOKEN }}
files: NearInfinity.jar
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/Argent77/NearInfinity?color=darkred&include_prereleases&label=latest%20release)](https://GitHub.com/Argent77/NearInfinity/releases/latest)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/Argent77/NearInfinity?color=darkred&label=latest%20release)](https://GitHub.com/Argent77/NearInfinity/releases/latest)
[![GitHub release date (latest by date)](https://img.shields.io/github/release-date/Argent77/NearInfinity?color=gold)](https://GitHub.com/Argent77/NearInfinity/releases/latest)
[![Github downloads (total)](https://img.shields.io/github/downloads/Argent77/NearInfinity/total.svg?color=blueviolet)](https://GitHub.com/Argent77/NearInfinity/releases)

# Near Infinity

A file browser and editor for the Infinity Engine. You can find out more in
the [Near Infinity Wiki](https://github.com/NearInfinityBrowser/NearInfinity/wiki), or download it directly from the
[Releases section](https://github.com/Argent77/NearInfinity/releases).
A file browser and editor for the Infinity Engine.

Find out more in the [Near Infinity Wiki](https://github.com/NearInfinityBrowser/NearInfinity/wiki).

Download Near Infinity directly from the [Releases section](https://github.com/Argent77/NearInfinity/releases)
or use [Nightly Releases](https://github.com/Argent77/NearInfinity/releases/tag/nightly) for the latest features
and bugfixes.

**Discuss Near Infinity on:**
- [GitHub Discussions](https://github.com/NearInfinityBrowser/NearInfinity/discussions)
Expand Down
18 changes: 12 additions & 6 deletions src/org/infinity/AppOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public class AppOption {
/** Menu Options: ShowTreeSearchNames (Boolean, Default: true) */
public static final AppOption SHOW_TREE_SEARCH_NAMES = new AppOption(OptionsMenuItem.OPTION_SHOWTREESEARCHNAMES,
"Show Search Names in Resource Tree", true);
/** Menu Options: Show Icons in Resource List (Boolean, Default: false) */
public static final AppOption SHOW_RESOURCE_LIST_ICONS = new AppOption(OptionsMenuItem.OPTION_SHOW_RESOURCE_LIST_ICONS,
"Show Icons in Resource List", false);
/** Menu Options: Show Icons in Resource Tree (Boolean, Default: false) */
public static final AppOption SHOW_RESOURCE_TREE_ICONS = new AppOption(OptionsMenuItem.OPTION_SHOW_RESOURCE_TREE_ICONS,
"Show Icons in Resource Tree", false);
/** Menu Options: HighlightOverridden (Boolean, Default: true) */
public static final AppOption HIGHLIGHT_OVERRIDDEN = new AppOption(OptionsMenuItem.OPTION_HIGHLIGHT_OVERRIDDEN,
"Show Overridden Files in Bold in Resource Tree", true);
Expand Down Expand Up @@ -757,31 +763,31 @@ public Object loadValue() throws ClassCastException {
final Preferences prefs = getPrefs();
if (Boolean.class.isAssignableFrom(valueType)) {
if (prefs != null) {
initialValue = (Boolean) prefs.getBoolean(getName(), (Boolean) getDefault());
initialValue = prefs.getBoolean(getName(), (Boolean) getDefault());
} else {
initialValue = getDefault();
}
} else if (Integer.class.isAssignableFrom(valueType)) {
if (prefs != null) {
initialValue = (Integer) prefs.getInt(getName(), (Integer) getDefault());
initialValue = prefs.getInt(getName(), (Integer) getDefault());
} else {
initialValue = getDefault();
}
} else if (Long.class.isAssignableFrom(valueType)) {
if (prefs != null) {
initialValue = (Long) prefs.getLong(getName(), (Long) getDefault());
initialValue = prefs.getLong(getName(), (Long) getDefault());
} else {
initialValue = getDefault();
}
} else if (Float.class.isAssignableFrom(valueType)) {
if (prefs != null) {
initialValue = (Float) prefs.getFloat(getName(), (Float) getDefault());
initialValue = prefs.getFloat(getName(), (Float) getDefault());
} else {
initialValue = getDefault();
}
} else if (Double.class.isAssignableFrom(valueType)) {
if (prefs != null) {
initialValue = (Double) prefs.getDouble(getName(), (Double) getDefault());
initialValue = prefs.getDouble(getName(), (Double) getDefault());
} else {
initialValue = getDefault();
}
Expand Down Expand Up @@ -863,7 +869,7 @@ public boolean equals(Object obj) {
private Object validate(Object value) throws ClassCastException {
value = validator.apply(value);
if ((value == null && validateType(valueType) == valueType) ||
valueType.isAssignableFrom(validateType(value.getClass()))) {
(value != null && valueType.isAssignableFrom(validateType(value.getClass())))) {
// pass
return value;
}
Expand Down
110 changes: 99 additions & 11 deletions src/org/infinity/NearInfinity.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@
import org.infinity.util.CharsetDetector;
import org.infinity.util.CreMapCache;
import org.infinity.util.FileDeletionHook;
import org.infinity.util.IconCache;
import org.infinity.util.IdsMapCache;
import org.infinity.util.IniMapCache;
import org.infinity.util.LauncherUtils;
import org.infinity.util.Misc;
import org.infinity.util.Operation;
import org.infinity.util.Platform;
import org.infinity.util.StringTable;
import org.infinity.util.Table2daCache;
Expand All @@ -133,7 +135,7 @@

public final class NearInfinity extends JFrame implements ActionListener, ViewableContainer {
// the current Near Infinity version
private static final String VERSION = "v2.4-20230625";
private static final String VERSION = "v2.4-20230714";

// the minimum supported Java version
private static final int JAVA_VERSION_MIN = 8;
Expand Down Expand Up @@ -235,6 +237,7 @@ public final class NearInfinity extends JFrame implements ActionListener, Viewab
private int tablePanelHeight;
private ProgressMonitor pmProgress;
private int progressIndex;
private SwingWorker<Void, Void> iconCacheWorker;

private static Path findKeyfile() {
JFileChooser chooser;
Expand Down Expand Up @@ -475,6 +478,7 @@ public void windowClosing(WindowEvent event) {
quit();
}
});

try {
LookAndFeelInfo info = BrowserMenuBar.getInstance().getOptions().getLookAndFeel();
UIManager.setLookAndFeel(info.getClassName());
Expand All @@ -483,6 +487,8 @@ public void windowClosing(WindowEvent event) {
e.printStackTrace();
}

cacheResourceIcons(true);

statusBar = new StatusBar();
ResourceTreeModel treemodel = ResourceFactory.getResourceTreeModel();
updateWindowTitle();
Expand Down Expand Up @@ -827,7 +833,6 @@ public void openGame(Path keyFile) {
Path oldKeyFile = Profile.getChitinKey();
ChildFrame.closeWindows();
clearCache(false);
BaseOpcode.reset();
Profile.openGame(keyFile, BrowserMenuBar.getInstance().getGameMenu().getBookmarkName(keyFile));

// making sure vital game resources are accessible
Expand Down Expand Up @@ -916,6 +921,7 @@ public void refreshGame() {
containerpanel.revalidate();
containerpanel.repaint();
}
cacheResourceIcons(true);
} finally {
blocker.setBlocked(false);
}
Expand Down Expand Up @@ -1109,15 +1115,15 @@ public boolean isDarkMode() {
final Color bg = Misc.getDefaultColor("TextField.background", Color.WHITE);
final double bgIntensity;
if (bg != null) {
bgIntensity = (double) bg.getRed() * 0.299 + (double) bg.getGreen() * 0.587 + (double) bg.getBlue() * 0.114;
bgIntensity = bg.getRed() * 0.299 + bg.getGreen() * 0.587 + bg.getBlue() * 0.114;
} else {
bgIntensity = 0.0;
}

final Color fg = Misc.getDefaultColor("TextField.foreground", Color.BLACK);
final double fgIntensity;
if (fg != null) {
fgIntensity = (double) fg.getRed() * 0.299 + (double) fg.getGreen() * 0.587 + (double) fg.getBlue() * 0.114;
fgIntensity = fg.getRed() * 0.299 + fg.getGreen() * 0.587 + fg.getBlue() * 0.114;
} else {
fgIntensity = 255.0;
}
Expand Down Expand Up @@ -1160,6 +1166,7 @@ private static boolean reloadFactory(boolean refreshOnly) {

// Central method for clearing cached data
private static void clearCache(boolean refreshOnly) {
NearInfinity.getInstance().cancelCacheResourceIcons();
if (ResourceFactory.getKeyfile() != null) {
ResourceFactory.getKeyfile().closeBIFFFiles();
}
Expand All @@ -1168,6 +1175,7 @@ private static void clearCache(boolean refreshOnly) {
}
DlcManager.close();
FileManager.reset();
IconCache.clearCache();
IdsMapCache.clearCache();
IniMapCache.clearCache();
Table2daCache.clearCache();
Expand Down Expand Up @@ -1387,30 +1395,30 @@ private JPanel createJavaInfoPanel() {
}

final List<Couple<String, String>> entries = new ArrayList<>();
entries.add(new Couple<String, String>("Near Infinity", getVersion()));
entries.add(new Couple<String, String>("Java Runtime", System.getProperty("java.runtime.name")));
entries.add(new Couple<>("Near Infinity", getVersion()));
entries.add(new Couple<>("Java Runtime", System.getProperty("java.runtime.name")));

String s1 = System.getProperty("java.version", "n/a");
String s2 = System.getProperty("java.version.date", "");
String value = s2.isEmpty() ? s1 : String.format("%s (%s)", s1, s2);
entries.add(new Couple<String, String>("Java Version", value));
entries.add(new Couple<>("Java Version", value));

value = System.getProperty("java.vm.name", "n/a") + " (" + System.getProperty("java.vm.version", "n/a");
s1 = System.getProperty("java.vm.info", "");
if (!s1.isEmpty()) {
value += ", " + s1;
}
value += ")";
entries.add(new Couple<String, String>("Java VM", value));
entries.add(new Couple<>("Java VM", value));

entries.add(new Couple<String, String>("Java VM Architecture", System.getProperty("os.arch", "n/a")));
entries.add(new Couple<>("Java VM Architecture", System.getProperty("os.arch", "n/a")));

long memoryMax = Runtime.getRuntime().maxMemory();
if (memoryMax != Long.MAX_VALUE) {
memoryMax /= 1024L * 1024L;
entries.add(new Couple<String, String>("Available Memory", String.format("%d MB", memoryMax)));
entries.add(new Couple<>("Available Memory", String.format("%d MB", memoryMax)));
} else {
entries.add(new Couple<String, String>("Available Memory", "n/a"));
entries.add(new Couple<>("Available Memory", "n/a"));
}

JPanel infoPanel = new JPanel(new GridBagLayout());
Expand Down Expand Up @@ -1459,6 +1467,86 @@ private JPanel createJavaInfoPanel() {
return infoPanel;
}

/**
* Cancels an ongoing resource icon cache operation.
*
* The method returns only after the operation has been successfully cancelled.
*/
private void cancelCacheResourceIcons() {
if (iconCacheWorker != null) {
iconCacheWorker.cancel(false);
for (int i = 0; i < 100 && iconCacheWorker.getProgress() < 100; i++) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
}
iconCacheWorker = null;
}
}

/**
* Preloads icons for all ITM and SPL resources into the cache.
*
* @param threaded Whether to perform the operation in a separate thread.
*/
private void cacheResourceIcons(boolean threaded) {
// Operation for caching resource icons
final Operation operation = () -> {
try {
IconCache.clearCache();
final List<Integer> sizeList = new ArrayList<>();
if (BrowserMenuBar.getInstance().getOptions().showResourceTreeIcons()) {
sizeList.add(IconCache.getDefaultTreeIconSize());
}
if (BrowserMenuBar.getInstance().getOptions().showResourceListIcons()) {
sizeList.add(IconCache.getDefaultListIconSize());
}
if (!sizeList.isEmpty()) {
final String[] types = { "ITM", "SPL" };
int[] sizes = sizeList.stream().mapToInt(Integer::intValue).toArray();
for (final String type : types) {
final List<ResourceEntry> resources = ResourceFactory.getResources(type);
if (resources != null) {
for (final ResourceEntry e : resources) {
for (final int size : sizes) {
if (iconCacheWorker != null && iconCacheWorker.isCancelled()) {
return;
}
IconCache.get(e, size);
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
};

// ensure that ongoing operations have ended before starting a new operation
cancelCacheResourceIcons();

if (threaded) {
iconCacheWorker = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
setProgress(0);
try {
operation.perform();
} catch (Exception e) {
e.printStackTrace();
}
setProgress(100);
return null;
}
};
iconCacheWorker.execute();
} else {
operation.perform();
}
}

// -------------------------- INNER CLASSES --------------------------

private static final class Options {
Expand Down
2 changes: 1 addition & 1 deletion src/org/infinity/check/StringSoundsChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private ChildFrame getResultFrame() {
buttonPanel.add(openStringTableButton);
buttonPanel.add(saveButton);

tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane = new JTabbedPane(SwingConstants.TOP);

// Male string table
JScrollPane scrollTable = new JScrollPane(table);
Expand Down
15 changes: 11 additions & 4 deletions src/org/infinity/datatype/AbstractBitmap.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.infinity.gui.StructViewer;
import org.infinity.gui.TextListPanel;
import org.infinity.gui.ViewerUtil;
import org.infinity.gui.menu.BrowserMenuBar;
import org.infinity.icon.Icons;
import org.infinity.resource.AbstractStruct;
import org.infinity.util.Misc;
Expand Down Expand Up @@ -205,14 +206,14 @@ public JComponent edit(ActionListener container) {
FormattedData<T> selected = null;
final List<FormattedData<T>> items = new ArrayList<>(itemMap.size());
for (final Long key : itemMap.keySet()) {
FormattedData<T> item = new FormattedData<>(key, itemMap.get(key), formatter);
FormattedData<T> item = new FormattedData<>(this, key, itemMap.get(key), formatter);
items.add(item);
if (key.intValue() == value) {
selected = item;
}
}

list = new TextListPanel<>(items, sortByName);
list = new TextListPanel<>(items, sortByName, BrowserMenuBar.getInstance().getOptions().showResourceListIcons());
list.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
Expand Down Expand Up @@ -494,17 +495,23 @@ protected String getHexValue(long value) {
/**
* A helper class used to encapsulate the formatter function object.
*/
protected static class FormattedData<T> {
public static class FormattedData<T> {
private final AbstractBitmap<T> parent;
private final Long value;
private final T data;
private final BiFunction<Long, T, String> formatter;

public FormattedData(long value, T data, BiFunction<Long, T, String> formatter) {
public FormattedData(AbstractBitmap<T> parent, long value, T data, BiFunction<Long, T, String> formatter) {
this.parent = parent;
this.value = value;
this.data = data;
this.formatter = formatter;
}

public AbstractBitmap<T> getParent() {
return parent;
}

public Long getValue() {
return value;
}
Expand Down
Loading

0 comments on commit 9d1d11e

Please sign in to comment.