diff --git a/src/main/java/com/parafield/storming/Icons.java b/src/main/java/com/parafield/storming/Icons.java index f333b1d..2a41823 100644 --- a/src/main/java/com/parafield/storming/Icons.java +++ b/src/main/java/com/parafield/storming/Icons.java @@ -1,5 +1,6 @@ package com.parafield.storming; +import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.extras.FlatSVGIcon; import javax.swing.ImageIcon; import java.awt.*; @@ -9,6 +10,7 @@ /** * Provides access to SVG and PNG icon resources used throughout the Storming Engine Editor. * Automatically handles SVG loading (using FlatLaf) and PNG fallbacks. + * SVGs are automatically tinted to match the current theme (light/dark). */ public class Icons { /** The main window icon for the application. */ @@ -17,6 +19,7 @@ public class Icons { /** * Loads an icon from resources by name. * Attempts to find a .svg file in icons/svg first, falling back to .png in icons/png if not found. + * SVGs are configured with a theme-aware color filter. * * @param name The base name of the icon file. * @param width The target width to scale to (set to 0 for default). @@ -29,6 +32,19 @@ private static ImageIcon loadIcon(String name, int width, int height) { if (svgUrl != null) { FlatSVGIcon svgIcon = new FlatSVGIcon(svgUrl); + + // Apply dynamic theme-aware color filter for all icons except brand icons + if (!name.equalsIgnoreCase("icon") && !name.equalsIgnoreCase("exe-icon")) { + svgIcon.setColorFilter(new FlatSVGIcon.ColorFilter(color -> { + // If the current theme is light, map white icons to dark gray + if (!FlatLaf.isLafDark()) { + return new Color(60, 60, 60); + } + // Otherwise keep original (white) + return color; + })); + } + if (width > 0 && height > 0) { return svgIcon.derive(width, height); } @@ -39,7 +55,12 @@ private static ImageIcon loadIcon(String name, int width, int height) { if (pngUrl == null) { return null; } + ImageIcon icon = new ImageIcon(pngUrl); + + // Note: PNG inversion/tinting is more complex and usually handled via separate assets + // or specific ImageFilters if needed. For now, we prioritize SVG scaling and tinting. + if (width > 0 && height > 0) { icon = new ImageIcon(icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH)); } @@ -84,6 +105,6 @@ private static ImageIcon loadIcon(String name, int width, int height) { public static final ImageIcon PLUS = loadIcon("plus", 16, 16); public static final ImageIcon BRUSH = loadIcon("brush", 16, 16); public static final ImageIcon CLIPBOARD = loadIcon("clipboard", 16, 16); - public static final ImageIcon RESTART = loadIcon("restart", 18, 18); - public static final ImageIcon PAUSE = loadIcon("pause", 18, 18); + public static final ImageIcon RESTART = loadIcon("restart", 23, 23); + public static final ImageIcon PAUSE = loadIcon("pause", 23, 23); } diff --git a/src/main/java/com/parafield/storming/ui/panels/SceneViewPanel.java b/src/main/java/com/parafield/storming/ui/panels/SceneViewPanel.java index 7b4f897..df2cceb 100644 --- a/src/main/java/com/parafield/storming/ui/panels/SceneViewPanel.java +++ b/src/main/java/com/parafield/storming/ui/panels/SceneViewPanel.java @@ -44,6 +44,7 @@ public interface LibC extends Library { // 2D Overlays private boolean showGrid = true; private boolean showCollisions = false; + private final JPanel overlayToolbar; /** * Constructs a SceneViewPanel, initializing the image buffer and floating toolbar. @@ -56,7 +57,7 @@ public SceneViewPanel() { image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); // --- Floating Scene Toolbar --- - JPanel overlayToolbar = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 2)); + overlayToolbar = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 2)); overlayToolbar.setOpaque(true); overlayToolbar.setBackground(new Color(40, 40, 45, 180)); overlayToolbar.setBorder(BorderFactory.createLineBorder(new Color(100, 100, 100, 50))); @@ -89,6 +90,14 @@ public SceneViewPanel() { timer.start(); } + /** + * Toggles the visibility of the floating scene toolbar. + * @param visible true to show the toolbar, false to hide it. + */ + public void setToolbarVisible(boolean visible) { + overlayToolbar.setVisible(visible); + } + /** * Utility method to create a stylized toggle button for scene overlays. * @param tip The tooltip text. @@ -155,8 +164,8 @@ protected void paintComponent(Graphics g) { // Draw image centered and scaled g.drawImage(image, 0, 0, getWidth(), getHeight(), null); - // Draw custom grid if enabled - if (showGrid) { + // Draw custom grid if enabled (only if toolbar/overlays would be visible) + if (showGrid && overlayToolbar.isVisible()) { drawGrid(g); } } diff --git a/src/main/java/com/parafield/storming/ui/widgets/StormingMenuBar.java b/src/main/java/com/parafield/storming/ui/widgets/StormingMenuBar.java index 0a0ee9c..3ecd373 100644 --- a/src/main/java/com/parafield/storming/ui/widgets/StormingMenuBar.java +++ b/src/main/java/com/parafield/storming/ui/widgets/StormingMenuBar.java @@ -3,6 +3,7 @@ import com.formdev.flatlaf.FlatClientProperties; import com.parafield.storming.Icons; import com.parafield.storming.ui.utils.UIUtils; +import com.parafield.storming.ui.windows.SettingsWindow; import javax.swing.*; import java.awt.*; import java.awt.event.AWTEventListener; @@ -184,6 +185,12 @@ public void paintIcon(Component c, Graphics g, int x, int y) { JButton settingsBtn = new JButton(Icons.SETTINGS); settingsBtn.setToolTipText("Settings"); settingsBtn.putClientProperty(FlatClientProperties.BUTTON_TYPE, FlatClientProperties.BUTTON_TYPE_TOOLBAR_BUTTON); + settingsBtn.addActionListener(e -> { + Window parent = SwingUtilities.getWindowAncestor(this); + if (parent instanceof Frame) { + new SettingsWindow((Frame) parent).setVisible(true); + } + }); add(settingsBtn); } @@ -198,7 +205,16 @@ private JMenu createFileMenu() { menu.addSeparator(); menu.add(new JMenuItem("Save Scene", Icons.CLIPBOARD)); menu.addSeparator(); - menu.add(new JMenuItem("Settings...", Icons.SETTINGS)); + + JMenuItem settingsItem = new JMenuItem("Settings...", Icons.SETTINGS); + settingsItem.addActionListener(e -> { + Window parent = SwingUtilities.getWindowAncestor(this); + if (parent instanceof Frame) { + new SettingsWindow((Frame) parent).setVisible(true); + } + }); + menu.add(settingsItem); + menu.add(new JMenuItem("Exit")); return menu; } diff --git a/src/main/java/com/parafield/storming/ui/windows/ProjectSelectorWindow.java b/src/main/java/com/parafield/storming/ui/windows/ProjectSelectorWindow.java index be91a93..2a1a798 100644 --- a/src/main/java/com/parafield/storming/ui/windows/ProjectSelectorWindow.java +++ b/src/main/java/com/parafield/storming/ui/windows/ProjectSelectorWindow.java @@ -95,7 +95,7 @@ public void mouseExited(java.awt.event.MouseEvent e) { JButton settingsBtn = new JButton(" Settings", Icons.SETTINGS); settingsBtn.putClientProperty(FlatClientProperties.BUTTON_TYPE, FlatClientProperties.BUTTON_TYPE_TOOLBAR_BUTTON); - settingsBtn.addActionListener(e -> JOptionPane.showMessageDialog(this, "Settings coming soon!")); + settingsBtn.addActionListener(e -> new SettingsWindow(this).setVisible(true)); sidebarFooter.add(settingsBtn, BorderLayout.WEST); sidebar.add(sidebarFooter, BorderLayout.SOUTH); diff --git a/src/main/java/com/parafield/storming/ui/windows/SettingsWindow.java b/src/main/java/com/parafield/storming/ui/windows/SettingsWindow.java new file mode 100644 index 0000000..c861de8 --- /dev/null +++ b/src/main/java/com/parafield/storming/ui/windows/SettingsWindow.java @@ -0,0 +1,419 @@ +package com.parafield.storming.ui.windows; + +import com.formdev.flatlaf.FlatClientProperties; +import com.formdev.flatlaf.FlatDarkLaf; +import com.formdev.flatlaf.FlatLaf; +import com.formdev.flatlaf.FlatLightLaf; +import com.formdev.flatlaf.themes.FlatMacDarkLaf; +import com.formdev.flatlaf.themes.FlatMacLightLaf; +import com.parafield.storming.Icons; +import com.parafield.storming.ui.utils.UIAnimator; +import com.parafield.storming.ui.utils.UIUtils; +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; + +/** + * The Settings window for the Storming Engine Editor. + * Provides a categorized interface for application and engine configuration, + * featuring a searchable category list and dynamic content panels with smooth transitions. + */ +public class SettingsWindow extends JDialog { + + private final CardLayout cardLayout; + private final JPanel contentPanel; + private final JList categoryList; + private final JLabel headerLabel; + + private float contentAlpha = 0.0f; + private int contentYOffset = 20; + + /** + * Constructs a SettingsWindow. + * @param owner The parent frame for this dialog. + */ + public SettingsWindow(Window owner) { + super(owner, "Settings", ModalityType.APPLICATION_MODAL); + setSize(900, 650); + setLocationRelativeTo(owner); + + rootPane.putClientProperty("apple.awt.fullWindowContent", true); + rootPane.putClientProperty("apple.awt.transparentTitleBar", true); + + setLayout(new BorderLayout()); + + // --- 1. Sidebar (Search + Categories) --- + JPanel sidebar = new JPanel(new BorderLayout()); + sidebar.setPreferredSize(new Dimension(240, 0)); + sidebar.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, UIManager.getColor("Component.borderColor"))); + sidebar.putClientProperty(FlatClientProperties.STYLE, "background: darken($Panel.background, 2%)"); + + // Search Field + JPanel searchPanel = new JPanel(new BorderLayout()); + searchPanel.setOpaque(false); + searchPanel.setBorder(new EmptyBorder(35, 15, 10, 15)); + + JTextField searchField = new JTextField(); + searchField.putClientProperty(FlatClientProperties.PLACEHOLDER_TEXT, "Search settings..."); + searchField.putClientProperty(FlatClientProperties.TEXT_FIELD_LEADING_ICON, Icons.SEARCH); + searchField.putClientProperty(FlatClientProperties.STYLE, "arc: 8; background: darken($Panel.background, 4%); borderWidth: 0; focusWidth: 0;"); + searchPanel.add(searchField, BorderLayout.CENTER); + sidebar.add(searchPanel, BorderLayout.NORTH); + + DefaultListModel model = new DefaultListModel<>(); + model.addElement(new CategoryItem("Appearance", Icons.BRUSH)); + model.addElement(new CategoryItem("Engine", Icons.LOGO_80)); + model.addElement(new CategoryItem("Editor", Icons.SETTINGS)); + model.addElement(new CategoryItem("Git", Icons.GIT)); + model.addElement(new CategoryItem("Terminal", Icons.CONSOLE)); + + categoryList = new JList<>(model); + categoryList.setCellRenderer(new CategoryRenderer()); + categoryList.setFixedCellHeight(36); + categoryList.setOpaque(false); + categoryList.setSelectedIndex(0); + categoryList.setBorder(new EmptyBorder(0, 8, 0, 8)); + + JScrollPane scrollPane = new JScrollPane(categoryList); + scrollPane.setBorder(null); + scrollPane.setOpaque(false); + scrollPane.getViewport().setOpaque(false); + sidebar.add(scrollPane, BorderLayout.CENTER); + + // --- 2. Content Area --- + JPanel rightPanel = new JPanel(new BorderLayout()) { + @Override + public void paint(Graphics g) { + Graphics2D g2 = (Graphics2D) g.create(); + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, contentAlpha)); + g2.translate(0, contentYOffset); + super.paint(g2); + g2.dispose(); + } + }; + + // Header + JPanel header = new JPanel(new BorderLayout()); + header.setPreferredSize(new Dimension(0, 60)); + header.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, UIManager.getColor("Component.borderColor"))); + header.setOpaque(false); + + headerLabel = new JLabel("Appearance"); + headerLabel.setFont(UIUtils.getFont(Font.BOLD, 20f)); + headerLabel.setBorder(new EmptyBorder(25, 30, 0, 0)); + header.add(headerLabel, BorderLayout.WEST); + rightPanel.add(header, BorderLayout.NORTH); + + cardLayout = new CardLayout(); + contentPanel = new JPanel(cardLayout); + contentPanel.setBorder(new EmptyBorder(20, 30, 20, 30)); + contentPanel.setOpaque(false); + + contentPanel.add(createAppearancePanel(), "Appearance"); + contentPanel.add(createEnginePanel(), "Engine"); + contentPanel.add(createEditorPanel(), "Editor"); + contentPanel.add(createPlaceholderPanel("Version Control (Git)"), "Git"); + contentPanel.add(createPlaceholderPanel("Terminal Emulator Settings"), "Terminal"); + + categoryList.addListSelectionListener(e -> { + if (!e.getValueIsAdjusting()) { + CategoryItem selected = categoryList.getSelectedValue(); + if (selected != null) { + animateCategoryTransition(selected.name); + } + } + }); + + rightPanel.add(contentPanel, BorderLayout.CENTER); + + // --- 3. Footer --- + JPanel footer = new JPanel(new FlowLayout(FlowLayout.RIGHT, 12, 12)); + footer.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, UIManager.getColor("Component.borderColor"))); + + JButton cancelBtn = new JButton("Cancel"); + cancelBtn.addActionListener(e -> dispose()); + + JButton applyBtn = new JButton("Apply"); + applyBtn.setEnabled(false); + + JButton okBtn = new JButton("OK"); + okBtn.putClientProperty(FlatClientProperties.STYLE, "background: #3498db; foreground: #ffffff;"); + okBtn.addActionListener(e -> dispose()); + + footer.add(cancelBtn); + footer.add(applyBtn); + footer.add(okBtn); + + add(sidebar, BorderLayout.WEST); + add(rightPanel, BorderLayout.CENTER); + add(footer, BorderLayout.SOUTH); + + // Start entrance animation + SwingUtilities.invokeLater(this::animateEntrance); + } + + /** + * Performs an entrance animation for the content area. + */ + private void animateEntrance() { + UIAnimator.animate(0.0f, 1.0f, 500, a -> { + contentAlpha = a; + contentYOffset = (int)(20 * (1.0f - a)); + repaint(); + }, null); + } + + /** + * Animates the transition between setting categories. + * @param targetName The name of the category to transition to. + */ + private void animateCategoryTransition(String targetName) { + // Fade out current + UIAnimator.animate(1.0f, 0.0f, 150, a -> { + contentAlpha = a; + repaint(); + }, () -> { + // Switch card + cardLayout.show(contentPanel, targetName); + headerLabel.setText(targetName); + // Fade in new + UIAnimator.animate(0.0f, 1.0f, 200, a -> { + contentAlpha = a; + repaint(); + }, null); + }); + } + + /** + * Creates the panel for Editor-specific preferences. + * @return A JPanel containing autosave, keymap, and editor behavior settings. + */ + private JPanel createEditorPanel() { + JPanel p = new JPanel(); + p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); + p.setOpaque(false); + + p.add(createSectionHeader("General")); + p.add(Box.createVerticalStrut(10)); + + JCheckBox autoSave = new JCheckBox("Autosave files on window focus loss"); + autoSave.setSelected(true); + autoSave.setOpaque(false); + p.add(createSettingRow("Autosave:", autoSave)); + + p.add(Box.createVerticalStrut(8)); + p.add(createSettingRow("Keymap:", new JComboBox<>(new String[]{"Default", "IntelliJ IDEA", "Visual Studio", "Sublime Text"}))); + + p.add(Box.createVerticalStrut(30)); + + p.add(createSectionHeader("Code Style")); + p.add(Box.createVerticalStrut(10)); + + p.add(createSettingRow("Tab Size:", new JSpinner(new SpinnerNumberModel(4, 1, 8, 1)))); + p.add(Box.createVerticalStrut(8)); + + JCheckBox useSpaces = new JCheckBox("Insert spaces instead of tabs"); + useSpaces.setSelected(true); + useSpaces.setOpaque(false); + p.add(createSettingRow("Indentation:", useSpaces)); + + p.add(Box.createVerticalGlue()); + return p; + } + + /** + * Creates the panel for Engine-specific settings. + * @return A JPanel containing engine path, graphics API, and logging configuration. + */ + private JPanel createEnginePanel() { + JPanel p = new JPanel(); + p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); + p.setOpaque(false); + + // Core Engine Section + p.add(createSectionHeader("Runtime Environment")); + p.add(Box.createVerticalStrut(10)); + + JPanel pathPanel = new JPanel(new BorderLayout(5, 0)); + pathPanel.setOpaque(false); + JTextField pathField = new JTextField("Engine/2D/build/bin/StormingEngine"); + JButton browseBtn = new JButton("Browse..."); + pathPanel.add(pathField, BorderLayout.CENTER); + pathPanel.add(browseBtn, BorderLayout.EAST); + + p.add(createSettingRow("Engine Path:", pathPanel)); + p.add(Box.createVerticalStrut(8)); + + p.add(createSettingRow("Graphics API:", new JComboBox<>(new String[]{"OpenGL 4.5 Core (Default)", "Vulkan 1.3 (Experimental)", "DirectX 12 (Windows Only)"}))); + p.add(Box.createVerticalStrut(8)); + + p.add(createSettingRow("Log Level:", new JComboBox<>(new String[]{"Debug", "Info", "Warning", "Error", "Critical"}))); + + p.add(Box.createVerticalStrut(30)); + + // Shared Memory Section + p.add(createSectionHeader("Performance & IPC")); + p.add(Box.createVerticalStrut(10)); + + JCheckBox shmCheck = new JCheckBox("Use Shared Memory for Real-time Streaming"); + shmCheck.setSelected(true); + shmCheck.setOpaque(false); + p.add(createSettingRow("Streaming:", shmCheck)); + + p.add(Box.createVerticalStrut(8)); + p.add(createSettingRow("Buffer Size:", new JComboBox<>(new String[]{"Double Buffered", "Triple Buffered"}))); + + p.add(Box.createVerticalGlue()); + return p; + } + + /** + * Creates the panel for Appearance settings. + * @return A JPanel containing appearance-related configuration components. + */ + private JPanel createAppearancePanel() { + JPanel p = new JPanel(); + p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); + p.setOpaque(false); + + // UI Theme Section + p.add(createSectionHeader("User Interface")); + p.add(Box.createVerticalStrut(10)); + + String[] themes = {"Mac Dark", "Mac Light", "Flat Dark", "Flat Light"}; + JComboBox themeCombo = new JComboBox<>(themes); + + // Set initial selection based on current Look and Feel + String currentLaf = UIManager.getLookAndFeel().getClass().getSimpleName(); + if (currentLaf.contains("MacDark")) themeCombo.setSelectedIndex(0); + else if (currentLaf.contains("MacLight")) themeCombo.setSelectedIndex(1); + else if (currentLaf.contains("FlatDark")) themeCombo.setSelectedIndex(2); + else if (currentLaf.contains("FlatLight")) themeCombo.setSelectedIndex(3); + + themeCombo.addActionListener(e -> { + String selected = (String) themeCombo.getSelectedItem(); + try { + if ("Mac Dark".equals(selected)) UIManager.setLookAndFeel(new FlatMacDarkLaf()); + else if ("Mac Light".equals(selected)) UIManager.setLookAndFeel(new FlatMacLightLaf()); + else if ("Flat Dark".equals(selected)) UIManager.setLookAndFeel(new FlatDarkLaf()); + else if ("Flat Light".equals(selected)) UIManager.setLookAndFeel(new FlatLightLaf()); + + FlatLaf.updateUI(); + } catch (Exception ex) { + ex.printStackTrace(); + } + }); + + p.add(createSettingRow("Theme:", themeCombo)); + p.add(Box.createVerticalStrut(8)); + p.add(createSettingRow("Zoom Level:", new JComboBox<>(new String[]{"100%", "125%", "150%", "200%"}))); + + p.add(Box.createVerticalStrut(30)); + + // Editor Section + p.add(createSectionHeader("Editor Font")); + p.add(Box.createVerticalStrut(10)); + + JPanel fontControls = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); + fontControls.setOpaque(false); + JComboBox fontCombo = new JComboBox<>(new String[]{"JetBrains Mono", "Fira Code", "Consolas"}); + fontCombo.setPreferredSize(new Dimension(200, 30)); + JSpinner sizeSpinner = new JSpinner(new SpinnerNumberModel(13, 8, 72, 1)); + sizeSpinner.setPreferredSize(new Dimension(65, 30)); + fontControls.add(fontCombo); + fontControls.add(Box.createHorizontalStrut(10)); + fontControls.add(sizeSpinner); + + p.add(createSettingRow("Font Family:", fontControls)); + p.add(Box.createVerticalStrut(8)); + p.add(createSettingRow("Line Spacing:", new JSpinner(new SpinnerNumberModel(1.2, 0.5, 3.0, 0.1)))); + + p.add(Box.createVerticalGlue()); + return p; + } + + /** + * Creates a standardized row for a setting. + * @param label The name of the setting. + * @param component The interactive component for the setting. + * @return A JPanel representing one setting row. + */ + private JPanel createSettingRow(String label, JComponent component) { + JPanel row = new JPanel(new BorderLayout()); + row.setOpaque(false); + row.setMaximumSize(new Dimension(600, 30)); + row.setAlignmentX(Component.LEFT_ALIGNMENT); + + JLabel l = new JLabel(label); + l.setPreferredSize(new Dimension(120, 30)); + l.setFont(UIUtils.getFont(Font.PLAIN, 12f)); + + component.setMaximumSize(new Dimension(300, 30)); + + row.add(l, BorderLayout.WEST); + row.add(component, BorderLayout.CENTER); + return row; + } + + /** + * Creates a stylized header for a setting section. + * @param text The header text. + * @return A JLabel configured as a section header. + */ + private JLabel createSectionHeader(String text) { + JLabel l = new JLabel(text); + l.setFont(UIUtils.getFont(Font.BOLD, 14f)); + l.setForeground(UIManager.getColor("Label.disabledForeground")); + l.setAlignmentX(Component.LEFT_ALIGNMENT); + return l; + } + + /** + * Creates a placeholder panel for categories that are not yet fully implemented. + * @param text The text to display in the placeholder. + * @return A JPanel with a centered placeholder label. + */ + private JPanel createPlaceholderPanel(String text) { + JPanel p = new JPanel(new BorderLayout()); + p.setOpaque(false); + JLabel l = new JLabel("
" + text + "
Configure " + text.toLowerCase() + " options here.
", SwingConstants.CENTER); + l.setFont(UIUtils.getFont(Font.PLAIN, 15f)); + p.add(l, BorderLayout.CENTER); + return p; + } + + /** Represents a category entry in the settings sidebar. */ + private record CategoryItem(String name, Icon icon) {} + + /** Custom renderer for settings categories with JetBrains-style selection. */ + private static class CategoryRenderer extends DefaultListCellRenderer { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + CategoryItem item = (CategoryItem) value; + JPanel p = new JPanel(new BorderLayout(10, 0)) { + @Override + protected void paintComponent(Graphics g) { + if (isSelected) { + Graphics2D g2 = (Graphics2D) g.create(); + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2.setColor(UIManager.getColor("List.selectionBackground")); + g2.fillRoundRect(0, 2, getWidth(), getHeight() - 4, 6, 6); + g2.dispose(); + } + } + }; + p.setOpaque(false); + p.setBorder(new EmptyBorder(0, 10, 0, 10)); + + JLabel iconLabel = new JLabel(item.icon); + JLabel textLabel = new JLabel(item.name); + textLabel.setFont(UIUtils.getFont(isSelected ? Font.BOLD : Font.PLAIN, 13f)); + textLabel.setForeground(isSelected ? UIManager.getColor("List.selectionForeground") : UIManager.getColor("Label.foreground")); + + p.add(iconLabel, BorderLayout.WEST); + p.add(textLabel, BorderLayout.CENTER); + return p; + } + } +} diff --git a/src/main/java/com/parafield/storming/ui/windows/SimulationWindow.java b/src/main/java/com/parafield/storming/ui/windows/SimulationWindow.java index 8a4bbec..cff2200 100644 --- a/src/main/java/com/parafield/storming/ui/windows/SimulationWindow.java +++ b/src/main/java/com/parafield/storming/ui/windows/SimulationWindow.java @@ -4,60 +4,55 @@ import com.parafield.storming.Icons; import com.parafield.storming.core.EngineLauncher; import com.parafield.storming.ui.panels.SceneViewPanel; +import com.parafield.storming.ui.utils.UIAnimator; import com.parafield.storming.ui.utils.UIUtils; import javax.swing.*; +import javax.swing.border.EmptyBorder; import java.awt.*; /** - * A dedicated window for running and debugging engine simulations. - * Provides a clean viewport for the game/application and playback controls. - * Integrates with the {@link EngineLauncher} to manage the engine process. + * An advanced simulation window with a Godot-inspired aesthetic. + * Features a pulsating "LIVE" indicator, real-time resource tracking, + * and smooth entrance animations for a high-end feel. */ public class SimulationWindow extends JFrame { private final SceneViewPanel viewport; private final EngineLauncher launcher; + + private AlphaPanel header; + private AlphaPanel footer; + private JLabel liveIndicator; + private JLabel memLabel; + private JProgressBar memBar; + + private boolean isPaused = false; - /** - * Constructs a SimulationWindow. - * @param launcher The EngineLauncher instance to use for starting/stopping the engine. - */ public SimulationWindow(EngineLauncher launcher) { this.launcher = launcher; - setTitle("New Adventure (DEBUG) - Storming Engine"); - setSize(1200, 800); + setTitle("Storming Engine - Simulation (DEBUG)"); + setSize(1280, 720); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - // Integrated Title Bar setup rootPane.putClientProperty("apple.awt.fullWindowContent", true); rootPane.putClientProperty("apple.awt.transparentTitleBar", true); rootPane.putClientProperty("flatlaf.showWindowIcon", false); - initMenuBar(); - JPanel root = new JPanel(new BorderLayout()); setContentPane(root); - // 1. The Viewport (Godot style: pure game focus) + header = createHeader(); + root.add(header, BorderLayout.NORTH); + viewport = new SceneViewPanel(); + viewport.setToolbarVisible(false); root.add(viewport, BorderLayout.CENTER); - // 2. Minimal Footer (Optional, can be removed for full clean look) - JPanel footer = new JPanel(new BorderLayout()); - footer.setPreferredSize(new Dimension(0, 22)); - footer.setBackground(new Color(20, 20, 25)); - footer.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(100, 100, 100, 30))); - - JLabel stats = new JLabel(" ● Live | 60 FPS | OpenGL 4.5 Core"); - stats.setFont(UIUtils.getFont(Font.PLAIN, 10f)); - stats.setForeground(new Color(150, 150, 150)); - footer.add(stats, BorderLayout.WEST); - + footer = createFooter(); root.add(footer, BorderLayout.SOUTH); - // ESC to stop root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "stopSim"); root.getActionMap().put("stopSim", new AbstractAction() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { closeAndStop(); } @@ -66,88 +61,175 @@ public SimulationWindow(EngineLauncher launcher) { addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { closeAndStop(); } }); + + startLivePulse(); + startResourceMonitor(); } - /** - * Initializes the menu bar with simulation playback controls (Restart, Pause, Stop). - */ - private void initMenuBar() { - JMenuBar menuBar = new JMenuBar(); - menuBar.setPreferredSize(new Dimension(0, 40)); - menuBar.setBackground(new Color(25, 25, 30)); - - // Left: Title - JLabel titleLabel = new JLabel(" New Adventure (DEBUG)"); - titleLabel.setFont(UIUtils.getFont(Font.BOLD, 12f)); - titleLabel.setForeground(new Color(200, 200, 200)); - menuBar.add(titleLabel); + private AlphaPanel createHeader() { + AlphaPanel p = new AlphaPanel(new BorderLayout()); + p.setPreferredSize(new Dimension(0, 42)); + p.setBackground(new Color(30, 30, 35)); + p.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(60, 60, 65))); - menuBar.add(Box.createHorizontalGlue()); + JPanel left = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 8)); + left.setOpaque(false); + + liveIndicator = new JLabel("●"); + liveIndicator.setFont(UIUtils.getFont(Font.BOLD, 11f)); + liveIndicator.setForeground(new Color(46, 204, 113)); + + JLabel title = new JLabel("New Adventure"); + title.setFont(UIUtils.getFont(Font.BOLD, 12f)); + title.setForeground(new Color(220, 220, 220)); + + JLabel badge = new JLabel(" DEBUG "); + badge.setFont(UIUtils.getFont(Font.BOLD, 9f)); + badge.setForeground(new Color(231, 76, 60)); + badge.setBorder(BorderFactory.createLineBorder(new Color(231, 76, 60, 100))); + + left.add(liveIndicator); + left.add(title); + left.add(badge); + p.add(left, BorderLayout.WEST); - // Center: Godot-style Playback Controls - JPanel centerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0)); - centerPanel.setOpaque(false); + JPanel center = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 4)); + center.setOpaque(false); - JButton restartBtn = createControlBtn(Icons.RESTART, "Restart (F5)"); + JButton restartBtn = createHeaderBtn(Icons.RESTART, "Restart Simulation (F5)"); restartBtn.addActionListener(e -> restartSimulation()); - JButton pauseBtn = createControlBtn(Icons.PAUSE, "Pause"); + JButton pauseBtn = createHeaderBtn(Icons.PAUSE, "Pause Simulation"); + pauseBtn.addActionListener(e -> togglePause()); - JButton stopBtn = createControlBtn(Icons.STOP, "Stop (Esc)"); + JButton stopBtn = createHeaderBtn(Icons.STOP, "Stop Simulation (Esc)"); stopBtn.addActionListener(e -> closeAndStop()); - centerPanel.add(restartBtn); - centerPanel.add(pauseBtn); - centerPanel.add(stopBtn); + center.add(restartBtn); + center.add(pauseBtn); + center.add(stopBtn); + p.add(center, BorderLayout.CENTER); + + p.add(Box.createHorizontalStrut(150), BorderLayout.EAST); + return p; + } + + private AlphaPanel createFooter() { + AlphaPanel p = new AlphaPanel(new BorderLayout()); + p.setPreferredSize(new Dimension(0, 26)); + p.setBackground(new Color(25, 25, 30)); + p.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(50, 50, 55))); + + JPanel left = new JPanel(new FlowLayout(FlowLayout.LEFT, 12, 4)); + left.setOpaque(false); + JLabel stats = new JLabel("60 FPS | 16.6ms | OpenGL 4.5 Core"); + stats.setFont(UIUtils.getFont(Font.PLAIN, 10f)); + stats.setForeground(new Color(150, 150, 150)); + left.add(stats); + p.add(left, BorderLayout.WEST); + + JPanel right = new JPanel(new FlowLayout(FlowLayout.RIGHT, 10, 4)); + right.setOpaque(false); + + memLabel = new JLabel("0 / 0 MB"); + memLabel.setFont(UIUtils.getFont(Font.PLAIN, 10f)); + memLabel.setForeground(new Color(150, 150, 150)); - menuBar.add(centerPanel); - menuBar.add(Box.createHorizontalGlue()); + memBar = new JProgressBar(0, 100); + memBar.setPreferredSize(new Dimension(80, 6)); + memBar.setForeground(new Color(52, 152, 219)); + memBar.setBackground(new Color(40, 40, 45)); + memBar.setBorder(null); - // Right: Window controls space - menuBar.add(Box.createHorizontalStrut(120)); + right.add(memLabel); + right.add(memBar); + right.add(Box.createHorizontalStrut(5)); + p.add(right, BorderLayout.EAST); + + return p; + } + + private void togglePause() { + isPaused = !isPaused; + liveIndicator.setText(isPaused ? "● PAUSED" : "●"); + liveIndicator.setForeground(isPaused ? new Color(241, 196, 15) : new Color(46, 204, 113)); + } - setJMenuBar(menuBar); + private void startLivePulse() { + Timer pulse = new Timer(1500, e -> { + if (!isPaused && isShowing()) { + UIAnimator.animate(1.0f, 0.2f, 600, a -> { + Color c = liveIndicator.getForeground(); + liveIndicator.setForeground(new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(a * 255))); + }, () -> { + UIAnimator.animate(0.2f, 1.0f, 600, a -> { + Color c = liveIndicator.getForeground(); + liveIndicator.setForeground(new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(a * 255))); + }, null); + }); + } + }); + pulse.start(); + } + + private void startResourceMonitor() { + Timer monitor = new Timer(2000, e -> { + if (isShowing()) { + Runtime r = Runtime.getRuntime(); + long total = r.totalMemory() / 1024 / 1024; + long used = (r.totalMemory() - r.freeMemory()) / 1024 / 1024; + memLabel.setText(String.format("%d / %d MB", used, total)); + memBar.setValue((int)((double)used / total * 100)); + } + }); + monitor.start(); } - /** - * Creates a stylized toolbar button for simulation control. - * @param icon The icon to display on the button. - * @param tip The tooltip text for the button. - * @return A configured JButton. - */ - private JButton createControlBtn(Icon icon, String tip) { + private JButton createHeaderBtn(Icon icon, String tip) { JButton btn = new JButton(icon); btn.setToolTipText(tip); btn.putClientProperty(FlatClientProperties.BUTTON_TYPE, FlatClientProperties.BUTTON_TYPE_TOOLBAR_BUTTON); - btn.setPreferredSize(new Dimension(34, 34)); + btn.setPreferredSize(new Dimension(32, 32)); + btn.setFocusable(false); return btn; } - /** - * Restarts the engine simulation by stopping the current process and launching a new one. - */ private void restartSimulation() { launcher.stop(); Timer t = new Timer(500, e -> startSimulation()); t.setRepeats(false); t.start(); } - /** - * Stops the simulation and closes the window. - */ private void closeAndStop() { launcher.stop(); dispose(); } - /** - * Starts the engine simulation. - * Makes the window visible and initiates engine launch with shared memory. - */ public void startSimulation() { + header.setAlpha(0.0f); + footer.setAlpha(0.0f); setVisible(true); + + UIAnimator.animate(0.0f, 1.0f, 500, a -> { + header.setAlpha(a); + footer.setAlpha(a); + }, null); + String shmName = "/storming_shm_" + System.currentTimeMillis(); launcher.launch(shmName); viewport.startStreaming(shmName); } + + private static class AlphaPanel extends JPanel { + private float alpha = 1.0f; + public AlphaPanel(LayoutManager layout) { super(layout); } + public void setAlpha(float a) { this.alpha = a; repaint(); } + @Override + public void paint(Graphics g) { + Graphics2D g2 = (Graphics2D) g.create(); + g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); + super.paint(g2); + g2.dispose(); + } + } } diff --git a/src/main/resources/com/parafield/storming/icons/png/pause.png b/src/main/resources/com/parafield/storming/icons/png/pause.png new file mode 100644 index 0000000..21faa7d Binary files /dev/null and b/src/main/resources/com/parafield/storming/icons/png/pause.png differ diff --git a/src/main/resources/com/parafield/storming/icons/png/restart.png b/src/main/resources/com/parafield/storming/icons/png/restart.png new file mode 100644 index 0000000..6661f10 Binary files /dev/null and b/src/main/resources/com/parafield/storming/icons/png/restart.png differ diff --git a/src/main/resources/com/parafield/storming/icons/svg/pause.svg b/src/main/resources/com/parafield/storming/icons/svg/pause.svg new file mode 100644 index 0000000..3ce93d9 --- /dev/null +++ b/src/main/resources/com/parafield/storming/icons/svg/pause.svg @@ -0,0 +1,7 @@ + + + + + + pause [#ffffff] Created with Sketch. + \ No newline at end of file diff --git a/src/main/resources/com/parafield/storming/icons/svg/restart.svg b/src/main/resources/com/parafield/storming/icons/svg/restart.svg new file mode 100644 index 0000000..7ab9246 --- /dev/null +++ b/src/main/resources/com/parafield/storming/icons/svg/restart.svg @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file