Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
Argent77 committed Apr 19, 2020
2 parents 2687ea6 + 60ab963 commit 600dea3
Show file tree
Hide file tree
Showing 40 changed files with 5,060 additions and 251 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="lib/jorbis/jorbis.jar" sourcepath="lib/jorbis/jorbis-0.0.17.zip"/>
<classpathentry exported="true" kind="lib" path="lib/rsyntaxtextarea/rsyntaxtextarea.jar" sourcepath="lib/rsyntaxtextarea/RSyntaxTextArea-2.6.0-light.zip"/>
<classpathentry exported="true" kind="lib" path="lib/jhexview/jhexview.jar" sourcepath="lib/jhexview/jhexview-current.zip"/>
<classpathentry exported="true" kind="lib" path="lib/montemedia/montemedia.jar" sourcepath="lib/montemedia/MonteMedia-0.7.7.zip"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 1 addition & 1 deletion src/org/infinity/check/StructChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public final class StructChecker extends AbstractChecker implements ListSelectio
fileInfo.put("PRO", new StructInfo("PRO ", new String[]{"V1.0"}));
fileInfo.put("SPL", new StructInfo("SPL ", new String[]{"V1 ", "V2.0"}));
fileInfo.put("STO", new StructInfo("STOR", new String[]{"V1.0", "V1.1", "V9.0"}));
fileInfo.put("VEF", new StructInfo("VEF ", new String[]{"V1.0"}));
fileInfo.put("VEF", new StructInfo("VEF ", new String[]{"V1.0", ""}));
fileInfo.put("VVC", new StructInfo("VVC ", new String[]{"V1.0"}));
fileInfo.put("WED", new StructInfo("WED ", new String[]{"V1.3"}));
fileInfo.put("WMP", new StructInfo("WMAP", new String[]{"V1.0"}));
Expand Down
24 changes: 16 additions & 8 deletions src/org/infinity/datatype/Bitmap.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ public class Bitmap extends Datatype implements Editable, IsNumeric
private final String[] table;

private TextListPanel<String> list;
private int base; // numeric value of first item index
private int value;

public Bitmap(ByteBuffer buffer, int offset, int length, String name, String[] table)
{
super(offset, length, name);
this.base = 0;
this.table = table;
read(buffer, offset);
}
Expand All @@ -58,9 +60,17 @@ public Bitmap(ByteBuffer buffer, int offset, int length, String name, String[] t
@Override
public JComponent edit(final ActionListener container)
{
final List<String> values = new ArrayList<>(Math.max(table.length, value + 1));
for (int i = 0; i < Math.max(table.length, value + 1); i++) {
values.add(toString(i));
base = 0;
int capacity = table.length;
if (value < 0) {
capacity += Math.abs(value);
base = value;
} else if (value >= table.length) {
capacity = value + 1;
}
final List<String> values = new ArrayList<>(capacity);
for (int i = 0; i < capacity; i++) {
values.add(toString(base + i));
}
list = new TextListPanel<>(values, false);
list.addMouseListener(new MouseAdapter()
Expand All @@ -73,7 +83,7 @@ public void mouseClicked(MouseEvent event)
}
}
});
if (value >= 0 && value < list.getModel().getSize()) {
if (value >= base && value < list.getModel().getSize() + base) {
int index = 0;
while (!list.getModel().getElementAt(index).equals(toString(value))) {
index++;
Expand Down Expand Up @@ -187,10 +197,8 @@ protected String getString(int nr)
/** Returns a formatted description of the specified value. */
private String toString(int nr)
{
if (nr >= table.length) {
if (nr < 0 || nr >= table.length) {
return "Unknown (" + nr + ')';
} else if (nr < 0) {
return "Error (" + nr + ')';
} else if (table[nr] == null || table[nr].isEmpty()) {
return "Unknown (" + nr + ')';
} else {
Expand All @@ -210,7 +218,7 @@ private void setValue(int newValue)
private int calcValue()
{
final String svalue = list.getSelectedValue();
int val = 0;
int val = base;
//FIXME: Ineffective code
while (!svalue.equals(toString(val))) {
val++;
Expand Down
47 changes: 40 additions & 7 deletions src/org/infinity/gui/BrowserMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.infinity.icon.Icons;
import org.infinity.resource.AbstractStruct;
import org.infinity.resource.Profile;
import org.infinity.resource.Referenceable;
import org.infinity.resource.Resource;
import org.infinity.resource.ResourceFactory;
import org.infinity.resource.StructEntry;
Expand All @@ -90,6 +91,7 @@
import org.infinity.search.SearchFrame;
import org.infinity.search.SearchResource;
import org.infinity.search.TextResourceSearcher;
import org.infinity.search.advanced.AdvancedSearch;
import org.infinity.updater.UpdateCheck;
import org.infinity.updater.UpdateInfo;
import org.infinity.updater.Updater;
Expand All @@ -104,7 +106,7 @@

public final class BrowserMenuBar extends JMenuBar implements KeyEventDispatcher
{
public static final String VERSION = "v2.1-20200401";
public static final String VERSION = "v2.1-20200419";
public static final LookAndFeelInfo DEFAULT_LOOKFEEL =
new LookAndFeelInfo("Metal", "javax.swing.plaf.metal.MetalLookAndFeel");

Expand Down Expand Up @@ -1161,7 +1163,7 @@ public boolean gameSupported(Profile.Game game)
};

private final JMenu newFileMenu;
private final JMenuItem fileOpenNew, fileExport, fileAddCopy, fileRename, fileDelete, fileRestore;
private final JMenuItem fileOpenNew, fileReference, fileExport, fileAddCopy, fileRename, fileDelete, fileRestore;

private FileMenu()
{
Expand All @@ -1175,6 +1177,9 @@ private FileMenu()
fileOpenNew = makeMenuItem("Open in New Window", KeyEvent.VK_W, Icons.getIcon(Icons.ICON_OPEN_16), -1, this);
fileOpenNew.setEnabled(false);
add(fileOpenNew);
fileReference = makeMenuItem("Find references...", KeyEvent.VK_F, Icons.getIcon(Icons.ICON_FIND_16), -1, this);
fileReference.setEnabled(false);
add(fileReference);
fileExport = makeMenuItem("Export...", KeyEvent.VK_E, Icons.getIcon(Icons.ICON_EXPORT_16), -1, this);
fileExport.setEnabled(false);
add(fileExport);
Expand Down Expand Up @@ -1214,10 +1219,21 @@ private void gameLoaded()
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == fileOpenNew) {
Resource res = ResourceFactory.getResource(
NearInfinity.getInstance().getResourceTree().getSelected());
Resource res = ResourceFactory.getResource(NearInfinity.getInstance().getResourceTree().getSelected());
if (res != null)
new ViewFrame(NearInfinity.getInstance(), res);
} else if (event.getSource() == fileReference) {
Resource res = ResourceFactory.getResource(NearInfinity.getInstance().getResourceTree().getSelected());
if (res instanceof Referenceable) {
if (((Referenceable)res).isReferenceable()) {
((Referenceable)res).searchReferences(NearInfinity.getInstance());
} else {
JOptionPane.showMessageDialog(NearInfinity.getInstance(),
"Finding references is not supported for " +
NearInfinity.getInstance().getResourceTree().getSelected() + ".",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
} else if (event.getSource() == fileExport) {
ResourceFactory.exportResource(NearInfinity.getInstance().getResourceTree().getSelected(),
NearInfinity.getInstance());
Expand All @@ -1243,6 +1259,8 @@ public void actionPerformed(ActionEvent event)
private void resourceEntrySelected(ResourceEntry entry)
{
fileOpenNew.setEnabled(entry != null);
Class<? extends Resource> cls = ResourceFactory.getResourceType(entry);
fileReference.setEnabled(cls != null && Referenceable.class.isAssignableFrom(cls));
fileExport.setEnabled(entry != null);
fileAddCopy.setEnabled(entry != null);
fileRename.setEnabled(entry instanceof FileResourceEntry);
Expand Down Expand Up @@ -1298,7 +1316,7 @@ else if (event.getSource() == editBIFF) {
private static final class SearchMenu extends JMenu implements ActionListener
{
private final String TEXTSEARCH[] = {"2DA", "BCS", "DLG", "IDS", "INI", "LUA"};
private final JMenuItem searchString, searchFile, searchResource;
private final JMenuItem searchString, searchFile, searchResource, advancedSearch;
private final JMenu textSearchMenu;

private SearchMenu()
Expand All @@ -1312,10 +1330,22 @@ private SearchMenu()
searchFile =
makeMenuItem("CRE/ITM/SPL/STO...", KeyEvent.VK_C, Icons.getIcon(Icons.ICON_FIND_16), KeyEvent.VK_F, this);
add(searchFile);

JMenu menuAdvanced = new JMenu("Advanced Search");
menuAdvanced.setIcon(Icons.getIcon(Icons.ICON_FIND_16));
menuAdvanced.setMnemonic('a');
add(menuAdvanced);

advancedSearch =
makeMenuItem("Advanced search...", KeyEvent.VK_A, Icons.getIcon(Icons.ICON_FIND_16), -1, this);
advancedSearch.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, CTRL_MASK | ALT_MASK));
advancedSearch.setToolTipText("A powerful and highly flexible search for structured resources of all kinds.");
menuAdvanced.add(advancedSearch);
searchResource =
makeMenuItem("Extended search...", KeyEvent.VK_X, Icons.getIcon(Icons.ICON_FIND_16), -1, this);
makeMenuItem("Legacy extended search...", KeyEvent.VK_X, Icons.getIcon(Icons.ICON_FIND_16), -1, this);
searchResource.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, CTRL_MASK | ALT_MASK));
add(searchResource);
searchResource.setToolTipText("The original \"Extended Search\".");
menuAdvanced.add(searchResource);

textSearchMenu = new JMenu("Text Search");
textSearchMenu.setIcon(Icons.getIcon(Icons.ICON_EDIT_16));
Expand Down Expand Up @@ -1355,6 +1385,9 @@ else if (event.getSource() == searchFile) {
else if (event.getSource() == searchResource) {
ChildFrame.show(SearchResource.class, () -> new SearchResource());
}
else if (event.getSource() == advancedSearch) {
ChildFrame.show(AdvancedSearch.class, () -> new AdvancedSearch());
}
else {
for (final String type : TEXTSEARCH) {
if (event.getActionCommand().equals(type)) {
Expand Down
115 changes: 64 additions & 51 deletions src/org/infinity/gui/ResourceTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import javax.swing.JTree;
import javax.swing.SwingConstants;
import javax.swing.Timer;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileNameExtensionFilter;
Expand All @@ -44,6 +46,7 @@
import org.infinity.gui.BrowserMenuBar.OverrideMode;
import org.infinity.icon.Icons;
import org.infinity.resource.Profile;
import org.infinity.resource.Referenceable;
import org.infinity.resource.Resource;
import org.infinity.resource.ResourceFactory;
import org.infinity.resource.key.BIFFResourceEntry;
Expand Down Expand Up @@ -617,10 +620,11 @@ private void maybeShowPopup(MouseEvent e)
}
}

private final class TreePopupMenu extends JPopupMenu implements ActionListener
private final class TreePopupMenu extends JPopupMenu implements ActionListener, PopupMenuListener
{
private final JMenuItem mi_open = new JMenuItem("Open");
private final JMenuItem mi_opennew = new JMenuItem("Open in new window");
private final JMenuItem mi_reference = new JMenuItem("Find references");
private final JMenuItem mi_export = new JMenuItem("Export");
private final JMenuItem mi_addcopy = new JMenuItem("Add copy of");
private final JMenuItem mi_rename = new JMenuItem("Rename");
Expand All @@ -630,68 +634,32 @@ private final class TreePopupMenu extends JPopupMenu implements ActionListener

TreePopupMenu()
{
add(mi_open);
add(mi_opennew);
add(mi_export);
mi_reference.setEnabled(false);
mi_zip.setToolTipText("Create a zip archive out of the selected saved game.");
add(mi_zip);
add(mi_addcopy);
add(mi_rename);
add(mi_delete);
add(mi_restore);
mi_open.addActionListener(this);
mi_opennew.addActionListener(this);
mi_export.addActionListener(this);
mi_zip.addActionListener(this);
mi_addcopy.addActionListener(this);
mi_rename.addActionListener(this);
mi_delete.addActionListener(this);
mi_restore.addActionListener(this);
mi_opennew.setFont(mi_opennew.getFont().deriveFont(Font.PLAIN));
mi_export.setFont(mi_opennew.getFont());
mi_addcopy.setFont(mi_opennew.getFont());
mi_rename.setFont(mi_opennew.getFont());
mi_delete.setFont(mi_opennew.getFont());
mi_restore.setFont(mi_opennew.getFont());
mi_zip.setFont(mi_opennew.getFont());
Font fnt = mi_open.getFont().deriveFont(Font.PLAIN);
for (JMenuItem mi : new JMenuItem[] {mi_open, mi_opennew, mi_reference, mi_export,
mi_zip, mi_addcopy, mi_rename, mi_delete, mi_restore}) {
add(mi);
mi.addActionListener(this);
mi.setFont(fnt);
}
addPopupMenuListener(this);
}

@Override
public void show(Component invoker, int x, int y)
private ResourceEntry getResourceEntry()
{
super.show(invoker, x, y);
mi_rename.setEnabled(tree.getLastSelectedPathComponent() instanceof FileResourceEntry);
ResourceEntry entry = null;
if (tree.getLastSelectedPathComponent() instanceof ResourceEntry) {
ResourceEntry entry = (ResourceEntry)tree.getLastSelectedPathComponent();
mi_delete.setEnabled(entry != null && entry.hasOverride() || entry instanceof FileResourceEntry);
mi_restore.setEnabled(isBackupAvailable(entry));
mi_zip.setEnabled(entry instanceof FileResourceEntry && Profile.isSaveGame(entry.getActualPath()));
}
else {
mi_delete.setEnabled(false);
mi_restore.setEnabled(false);
if (tree.getLastSelectedPathComponent() instanceof ResourceTreeFolder) {
ResourceTreeFolder folder = (ResourceTreeFolder)tree.getLastSelectedPathComponent();
String path = "";
while (folder != null && !folder.folderName().isEmpty()) {
path = folder.folderName() + "/" + path;
folder = folder.getParentFolder();
}
mi_zip.setEnabled(Profile.isSaveGame(FileManager.resolve(path)));
} else {
mi_zip.setEnabled(false);
}
entry = (ResourceEntry)tree.getLastSelectedPathComponent();
}
return entry;
}

@Override
public void actionPerformed(ActionEvent event)
{
showresource = true;
ResourceEntry node = null;
if (tree.getLastSelectedPathComponent() instanceof ResourceEntry) {
node = (ResourceEntry)tree.getLastSelectedPathComponent();
}
ResourceEntry node = getResourceEntry();
if (event.getSource() == mi_open && node != null) {
if (prevnextnode != null)
prevstack.push(prevnextnode);
Expand All @@ -707,6 +675,18 @@ else if (event.getSource() == mi_opennew && node != null) {
if (res != null)
new ViewFrame(NearInfinity.getInstance(), res);
}
else if (event.getSource() == mi_reference && node != null) {
Resource res = ResourceFactory.getResource(node);
if (res != null && res instanceof Referenceable) {
if (((Referenceable)res).isReferenceable()) {
((Referenceable)res).searchReferences(NearInfinity.getInstance());
} else {
JOptionPane.showMessageDialog(NearInfinity.getInstance(),
"Finding references is not supported for " + node + ".",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
}
else if (event.getSource() == mi_export && node != null) {
ResourceFactory.exportResource(node, NearInfinity.getInstance());
}
Expand Down Expand Up @@ -747,6 +727,39 @@ else if (o instanceof ResourceTreeFolder) {
}
}
}

@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent event)
{
ResourceEntry entry = getResourceEntry();
Class<? extends Resource> cls = ResourceFactory.getResourceType(entry);
mi_reference.setEnabled(cls != null && Referenceable.class.isAssignableFrom(cls));
mi_rename.setEnabled(entry instanceof FileResourceEntry);

mi_delete.setEnabled(entry != null && entry.hasOverride() || entry instanceof FileResourceEntry);
mi_restore.setEnabled(isBackupAvailable(entry));
mi_zip.setEnabled(entry instanceof FileResourceEntry && Profile.isSaveGame(entry.getActualPath()));

String path = "";
if (tree.getLastSelectedPathComponent() instanceof ResourceTreeFolder) {
ResourceTreeFolder folder = (ResourceTreeFolder)tree.getLastSelectedPathComponent();
while (folder != null && !folder.folderName().isEmpty()) {
path = folder.folderName() + "/" + path;
folder = folder.getParentFolder();
}
}
mi_zip.setEnabled(!path.isEmpty() && Profile.isSaveGame(FileManager.resolve(path)));
}

@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent event)
{
}

@Override
public void popupMenuCanceled(PopupMenuEvent event)
{
}
}

private static final class ResourceTreeRenderer extends DefaultTreeCellRenderer
Expand Down
Loading

0 comments on commit 600dea3

Please sign in to comment.