Skip to content

Commit

Permalink
A little gimmick for NI ;)
Browse files Browse the repository at this point in the history
Adds an option to progressively populate the (empty) main panel of NI
with various creatures from the currently opened game over time which
perform random actions. Feature can be enabled or disabled in the
Preferences.
  • Loading branch information
Argent77 committed Nov 21, 2024
1 parent ba0d55f commit 671d41a
Show file tree
Hide file tree
Showing 5 changed files with 1,954 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/org/infinity/AppOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public class AppOption {
/** Menu Options: RememberChildFrameRect (Boolean, Default: false) */
public static final AppOption REMEMBER_CHILD_FRAME_RECT = new AppOption(OptionsMenuItem.OPTION_REMEMBER_CHILDFRAME_RECT,
"Remember Last Child Frame Size and Position", false);
/** Menu Options: ShowCreaturesOnPanel (Boolean, Default: false) */
public static final AppOption SHOW_CREATURES_ON_PANEL = new AppOption(OptionsMenuItem.OPTION_SHOW_CREATURES_ON_PANEL,
"Show creatures on main panel", false);
/**
* Menu Options: OptionFixedInternal (Integer, Default: 0).
* Note: Used internally to fix incorrect default values after the public release.
Expand Down
39 changes: 37 additions & 2 deletions src/org/infinity/NearInfinity.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
import org.infinity.gui.PopupWindowListener;
import org.infinity.gui.QuickSearch;
import org.infinity.gui.ResourceTree;
import org.infinity.gui.SpriteAnimationPanel;
import org.infinity.gui.StatusBar;
import org.infinity.gui.StringEditor;
import org.infinity.gui.StructViewer;
Expand Down Expand Up @@ -232,7 +233,7 @@ public final class NearInfinity extends JFrame implements ActionListener, Viewab

private static NearInfinity browser;

private final JPanel containerpanel;
private final SpriteAnimationPanel containerpanel;
private final JSplitPane spSplitter;
private final ResourceTree tree;
private final StatusBar statusBar;
Expand Down Expand Up @@ -594,7 +595,7 @@ public void actionPerformed(ActionEvent e) {
leftPanel.add(tree, BorderLayout.CENTER);
leftPanel.add(toolBar, BorderLayout.NORTH);

containerpanel = new JPanel(new BorderLayout());
containerpanel = new SpriteAnimationPanel(new BorderLayout());
containerpanel.add(createJavaInfoPanel(), BorderLayout.CENTER);
spSplitter = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, containerpanel);
spSplitter.setBorder(BorderFactory.createEmptyBorder());
Expand All @@ -613,6 +614,8 @@ public void actionPerformed(ActionEvent e) {
setVisible(true);
setExtendedState(AppOption.APP_WINDOW_STATE.getIntValue());

setSpriteAnimationPanelEnabled(true);

// XXX: Workaround to trigger standard window closing callback on OSX when using command-Q
if (Platform.IS_MACOS) {
enableOSXQuitStrategy();
Expand Down Expand Up @@ -689,6 +692,7 @@ public void actionPerformed(ActionEvent event) {
BrowserMenuBar.getInstance().gameLoaded(oldGame, oldFile);
tree.setModel(treemodel);
ChildFrame.fireGameReset(false);
resetSpriteAnimationPanel();
containerpanel.removeAll();
containerpanel.add(createJavaInfoPanel(), BorderLayout.CENTER);
containerpanel.revalidate();
Expand Down Expand Up @@ -835,6 +839,7 @@ public void setViewable(Viewable newViewable) {
statusBar.setMessage(resource.getResourceEntry().getActualPath().toString());
containerpanel.removeAll();
containerpanel.add(viewable.makeViewer(this), BorderLayout.CENTER);
setSpriteAnimationPanelEnabled(false);
containerpanel.revalidate();
containerpanel.repaint();
toFront();
Expand Down Expand Up @@ -882,6 +887,7 @@ public void openGame(Path keyFile) {
BrowserMenuBar.getInstance().gameLoaded(oldGame, Objects.requireNonNull(oldKeyFile).toString());
tree.setModel(treemodel);
ChildFrame.fireGameReset(false);
resetSpriteAnimationPanel();
containerpanel.removeAll();
containerpanel.add(createJavaInfoPanel(), BorderLayout.CENTER);
containerpanel.revalidate();
Expand All @@ -903,6 +909,7 @@ public boolean removeViewable() {
tree.select(null);
containerpanel.removeAll();
containerpanel.add(createJavaInfoPanel(), BorderLayout.CENTER);
setSpriteAnimationPanelEnabled(true);
containerpanel.revalidate();
containerpanel.repaint();
return true;
Expand All @@ -919,6 +926,7 @@ public void showResourceEntry(ResourceEntry resourceEntry, Operation doneOperati
public void quit() {
if (removeViewable()) {
ChildFrame.closeWindows(true);
try { containerpanel.close(); } catch (Exception e) {}
storePreferences();
clearCache(false);
System.exit(0);
Expand Down Expand Up @@ -948,6 +956,7 @@ public void refreshGame() {
}
cacheResourceIcons(true);
ChildFrame.fireGameReset(true);
resetSpriteAnimationPanel();
} finally {
blocker.setBlocked(false);
}
Expand Down Expand Up @@ -1349,6 +1358,32 @@ private void checkFileAccess(Path path) throws IOException {
}
}

/** Controls enabled state of the creature animation panel. */
public void setSpriteAnimationPanelEnabled(boolean enable) {
if (BrowserMenuBar.getInstance().getOptions().showCreaturesOnPanel()) {
if (enable && !containerpanel.isRunning()) {
Logger.trace("Starting creature animation panel");
containerpanel.start();
} else if (!enable && containerpanel.isRunning()) {
Logger.trace("Stopping creature animation panel");
containerpanel.stop();
}
} else {
if (containerpanel.isRunning()) {
containerpanel.stop();
}
}
}

/** Resets the animation panel in a controlled manner. */
public void resetSpriteAnimationPanel() {
if (BrowserMenuBar.getInstance().getOptions().showCreaturesOnPanel()) {
Logger.trace("Resetting creature animation panel");
containerpanel.reset();
}
setSpriteAnimationPanelEnabled(true);
}

/**
* Shows Java Runtime information when there are no components attached to the main view.
*/
Expand Down
8 changes: 7 additions & 1 deletion src/org/infinity/gui/PreferencesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,13 @@ public String toString() {
"With this option enabled Near Infinity remembers current size and position of child windows on the screen.<br/>"
+ "This information is only remembered across the current session and will be discarded whenever "
+ "Near Infinity is closed.",
AppOption.REMEMBER_CHILD_FRAME_RECT)
AppOption.REMEMBER_CHILD_FRAME_RECT),
OptionCheckBox.create(AppOption.SHOW_CREATURES_ON_PANEL.getName(), AppOption.SHOW_CREATURES_ON_PANEL.getLabel(),
"With this option enabled creatures from the currently opened game will progressively populate the "
+ "main panel and perform all kinds of random actions. This option is primarily meant as a gimmick. ;)"
+ "<p><strong>Note:</strong> Changing this option requires to open a new game or use the command "
+ "\"Refresh Tree\" (Shortcut: <code>F5</code>)</p>",
AppOption.SHOW_CREATURES_ON_PANEL)
)
),
OptionCategory.create(Category.SCRIPT_COMPILER,
Expand Down
Loading

0 comments on commit 671d41a

Please sign in to comment.