From 31a2183f7870220f4421706db1581ae73d8d84c6 Mon Sep 17 00:00:00 2001 From: "A. Teo Welton" <76081718+DragonDev07@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:39:59 -0600 Subject: [PATCH 1/2] Remove unused middle button panel code --- .../org/rowlandhall/meepmeep/MeepMeep.kt | 154 ++++++------------ 1 file changed, 46 insertions(+), 108 deletions(-) diff --git a/src/main/kotlin/org/rowlandhall/meepmeep/MeepMeep.kt b/src/main/kotlin/org/rowlandhall/meepmeep/MeepMeep.kt index f208275..77c3aab 100644 --- a/src/main/kotlin/org/rowlandhall/meepmeep/MeepMeep.kt +++ b/src/main/kotlin/org/rowlandhall/meepmeep/MeepMeep.kt @@ -27,13 +27,7 @@ import java.awt.event.MouseEvent import java.awt.event.MouseListener import java.awt.event.MouseMotionListener import javax.imageio.ImageIO -import javax.swing.BorderFactory -import javax.swing.Box -import javax.swing.BoxLayout -import javax.swing.JButton -import javax.swing.JPanel import javax.swing.UIManager -import javax.swing.border.EtchedBorder /** * The [MeepMeep] class is the main entry point for the Meep Meep @@ -106,18 +100,6 @@ class MeepMeep @JvmOverloads constructor( /** Manages the z-index of entities for rendering order. */ private val zIndexManager = ZIndexManager() - /** Panel containing the middle buttons. */ - private var middleButtonPanel = JPanel() - - /** Button for standard cursor mode. */ - private val standardCursorButton = JButton("test") - - /** Button for path selection mode. */ - private val pathSelectionButton = JButton("test 2") - - /** List of buttons in the middle panel. */ - private val middleButtonList = mutableListOf(standardCursorButton, pathSelectionButton) - /** The x-coordinate for displaying mouse coordinates. */ private var mouseCoordinateDisplayX = 10 @@ -149,8 +131,7 @@ class MeepMeep @JvmOverloads constructor( * @see [TrajectoryProgressSliderMaster] * @see [FieldUtil.CANVAS_WIDTH] */ - private val progressSliderMasterPanel: TrajectoryProgressSliderMaster by lazy { - // Create a new instance of TrajectoryProgressSliderMaster + private val progressSliderMasterPanel: TrajectoryProgressSliderMaster by lazy { // Create a new instance of TrajectoryProgressSliderMaster TrajectoryProgressSliderMaster( this, FieldUtil.CANVAS_WIDTH.toInt(), 20 ) @@ -160,8 +141,7 @@ class MeepMeep @JvmOverloads constructor( // Returns true if entity list needs to be sorted private var entityListDirty = false - init { - // Create class loader to load resources + init { // Create class loader to load resources val classLoader = Thread.currentThread().contextClassLoader // Load Roboto Regular font from file @@ -202,27 +182,8 @@ class MeepMeep @JvmOverloads constructor( this, colorManager.theme, 30.0, 30.0, Vector2d(-54.0, 54.0) ) - // Set alignment and background color for each button in the middle button list - middleButtonList.forEach { - it.alignmentX = 0.5f - it.background = colorManager.theme.uiMainBG - } - - // Set background color and border for the middle button panel - middleButtonPanel.background = colorManager.theme.uiMainBG - middleButtonPanel.border = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED) - - // Set layout for the middle button panel - middleButtonPanel.layout = BoxLayout(middleButtonPanel, BoxLayout.Y_AXIS) - - // Add vertical glue and buttons to the middle button panel - middleButtonPanel.add(Box.createVerticalGlue()) - middleButtonPanel.add(standardCursorButton) - middleButtonPanel.add(pathSelectionButton) - middleButtonPanel.add(Box.createVerticalGlue()) - // Add the progress slider panel to the canvas panel - windowFrame.canvasPanel.add(progressSliderMasterPanel) // windowFrame.contentPane.add(middleButtonPanel) + windowFrame.canvasPanel.add(progressSliderMasterPanel) // Pack the window frame to fit the preferred sizes of its components windowFrame.pack() @@ -253,10 +214,8 @@ class MeepMeep @JvmOverloads constructor( * * @param e The KeyEvent that triggered this method. */ - override fun keyPressed(e: KeyEvent) { - // Check if the 'C' or 'COPY' (Often `Ctrl/CMD + C`) key is pressed - if (e.keyCode == KeyEvent.VK_C || e.keyCode == KeyEvent.VK_COPY) { - // Convert mouse coordinates from screen to field coordinates + override fun keyPressed(e: KeyEvent) { // Check if the 'C' or 'COPY' (Often `Ctrl/CMD + C`) key is pressed + if (e.keyCode == KeyEvent.VK_C || e.keyCode == KeyEvent.VK_COPY) { // Convert mouse coordinates from screen to field coordinates val mouseToFieldCoords = FieldUtil.screenCoordsToFieldCoords( Vector2d( canvasMouseX.toDouble(), canvasMouseY.toDouble() @@ -314,8 +273,7 @@ class MeepMeep @JvmOverloads constructor( * @see [FieldUtil] * @see [LoopManager] */ - private val render: () -> Unit = { - // Get the graphics context from the canvas buffer strategy + private val render: () -> Unit = { // Get the graphics context from the canvas buffer strategy val g = canvas.bufferStrat.drawGraphics as Graphics2D // Enable anti-aliasing for smoother visuals @@ -326,8 +284,7 @@ class MeepMeep @JvmOverloads constructor( // Render the background image if it exists bg?.let { - if (bgAlpha < 1.0f) { - // Apply alpha transparency to the background image + if (bgAlpha < 1.0f) { // Apply alpha transparency to the background image val resetComposite = g.composite val alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, bgAlpha) @@ -381,25 +338,24 @@ class MeepMeep @JvmOverloads constructor( * @see [Entity] * @see [ZIndexManager] */ - private val update: (deltaTime: Long) -> Unit = { deltaTime -> - // Check if the entity list needs to be updated - if (entityListDirty) { - // Remove entities that are requested to be removed - entityList.removeAll(requestedRemoveEntityList) - requestedRemoveEntityList.clear() - - // Add entities that are requested to be added - entityList.addAll(requestedAddEntityList) - requestedAddEntityList.clear() - - // Sort the entity list by their z-index - entityList.sortBy { it.zIndex } - entityListDirty = false - } + private val update: (deltaTime: Long) -> Unit = + { deltaTime -> // Check if the entity list needs to be updated + if (entityListDirty) { // Remove entities that are requested to be removed + entityList.removeAll(requestedRemoveEntityList) + requestedRemoveEntityList.clear() + + // Add entities that are requested to be added + entityList.addAll(requestedAddEntityList) + requestedAddEntityList.clear() + + // Sort the entity list by their z-index + entityList.sortBy { it.zIndex } + entityListDirty = false + } - // Update each entity in the entity list - entityList.forEach { it.update(deltaTime) } - } + // Update each entity in the entity list + entityList.forEach { it.update(deltaTime) } + } /** * Manages the application loop with the specified fps and update and @@ -416,8 +372,7 @@ class MeepMeep @JvmOverloads constructor( * * @return The [MeepMeep] instance. */ - fun start(): MeepMeep { - // Set the default background if none is set + fun start(): MeepMeep { // Set the default background if none is set if (bg == null) setBackground(Background.GRID_BLUE) windowFrame.isVisible = true @@ -479,8 +434,9 @@ class MeepMeep @JvmOverloads constructor( // Get the path and dark mode boolean from the background map val (path, isDarkMode) = backgroundMap[background]!! colorManager.isDarkMode = isDarkMode - bg = ImageIO.read(classLoader.getResourceAsStream(path)) - .getScaledInstance(windowX, windowY, Image.SCALE_SMOOTH) + bg = + ImageIO.read(classLoader.getResourceAsStream(path)) + .getScaledInstance(windowX, windowY, Image.SCALE_SMOOTH) // Refresh the theme for all entities refreshTheme() @@ -498,8 +454,7 @@ class MeepMeep @JvmOverloads constructor( * @param image The [Image] to be set as the background. * @return The [MeepMeep] instance for method chaining. */ - fun setBackground(image: Image): MeepMeep { - // Scale the provided image to fit the window dimensions + fun setBackground(image: Image): MeepMeep { // Scale the provided image to fit the window dimensions bg = image.getScaledInstance(windowX, windowY, Image.SCALE_SMOOTH) // Return the current instance for method chaining @@ -516,8 +471,9 @@ class MeepMeep @JvmOverloads constructor( * @param x The x-coordinate for displaying the mouse coordinates. * @param y The y-coordinate for displaying the mouse coordinates. */ - fun setMouseCoordinateDisplayPosition(x: Int, y: Int) { - // Update the x-coordinate for the mouse coordinate display + fun setMouseCoordinateDisplayPosition( + x: Int, y: Int + ) { // Update the x-coordinate for the mouse coordinate display mouseCoordinateDisplayX = x // Update the y-coordinate for the mouse coordinate display @@ -531,8 +487,7 @@ class MeepMeep @JvmOverloads constructor( * shown. * @return The [MeepMeep] instance for method chaining. */ - fun setShowFPS(showFPS: Boolean): MeepMeep { - // Update the showFPS property + fun setShowFPS(showFPS: Boolean): MeepMeep { // Update the showFPS property this.showFPS = showFPS return this @@ -553,8 +508,9 @@ class MeepMeep @JvmOverloads constructor( * @see [refreshTheme] */ @JvmOverloads - fun setTheme(schemeLight: ColorScheme, schemeDark: ColorScheme = schemeLight): MeepMeep { - // Set the light and dark themes in the ColorManager + fun setTheme( + schemeLight: ColorScheme, schemeDark: ColorScheme = schemeLight + ): MeepMeep { // Set the light and dark themes in the ColorManager colorManager.setTheme(schemeLight, schemeDark) // Refresh the theme for all entities and UI components @@ -575,8 +531,7 @@ class MeepMeep @JvmOverloads constructor( * @see [ColorManager] * @see [ThemedEntity] */ - private fun refreshTheme() { - // Core Refresh: Update the theme for all entities that implement ThemedEntity + private fun refreshTheme() { // Core Refresh: Update the theme for all entities that implement ThemedEntity entityList.forEach { if (it is ThemedEntity) it.switchScheme(colorManager.theme) } @@ -584,14 +539,6 @@ class MeepMeep @JvmOverloads constructor( // Update the background color of the main content pane and canvas panel windowFrame.contentPane.background = colorManager.theme.uiMainBG windowFrame.canvasPanel.background = colorManager.theme.uiMainBG - - // Road Runner Refresh: Update the background color of the middle button panel - middleButtonPanel.background = colorManager.theme.uiMainBG - - // Update the background color of each button in the middle button list - middleButtonList.forEach { - it.background = colorManager.theme.uiMainBG - } } /** @@ -606,8 +553,7 @@ class MeepMeep @JvmOverloads constructor( * @return The [MeepMeep] instance for method chaining. * @see [ColorManager] */ - fun setDarkMode(isDarkMode: Boolean): MeepMeep { - // Update the dark mode setting in the ColorManager + fun setDarkMode(isDarkMode: Boolean): MeepMeep { // Update the dark mode setting in the ColorManager colorManager.isDarkMode = isDarkMode // Return the current instance for method chaining @@ -626,8 +572,7 @@ class MeepMeep @JvmOverloads constructor( * @see FieldUtil * @see Entity.setCanvasDimensions */ - private fun onCanvasResize() { - // Set the canvas width and height in FieldUtil to the current window dimensions + private fun onCanvasResize() { // Set the canvas width and height in FieldUtil to the current window dimensions FieldUtil.CANVAS_WIDTH = windowX.toDouble() FieldUtil.CANVAS_HEIGHT = windowY.toDouble() @@ -647,10 +592,8 @@ class MeepMeep @JvmOverloads constructor( * @param interval The interval to set for the [AxesEntity]. * @return The [MeepMeep] instance for method chaining. */ - fun setAxesInterval(interval: Int): MeepMeep { - // Check if the default [AxesEntity] is in the [entityList] - if (DEFAULT_AXES_ENTITY in entityList) { - // Set the interval for the default [AxesEntity] + fun setAxesInterval(interval: Int): MeepMeep { // Check if the default [AxesEntity] is in the [entityList] + if (DEFAULT_AXES_ENTITY in entityList) { // Set the interval for the default [AxesEntity] DEFAULT_AXES_ENTITY.setInterval(interval) } @@ -671,8 +614,7 @@ class MeepMeep @JvmOverloads constructor( * @param entity The [Entity] to be added to the application. * @return The [MeepMeep] instance for method chaining. */ - fun addEntity(entity: Entity): MeepMeep { - // Add the entity to the z-index manager + fun addEntity(entity: Entity): MeepMeep { // Add the entity to the z-index manager zIndexManager.addEntity(entity) // Add the entity to the entity list and mark the list as dirty @@ -707,8 +649,7 @@ class MeepMeep @JvmOverloads constructor( * @param entity The [Entity] to be removed from the application. * @return The [MeepMeep] instance for method chaining. */ - fun removeEntity(entity: Entity): MeepMeep { - // Remove the entity from the entity list + fun removeEntity(entity: Entity): MeepMeep { // Remove the entity from the entity list entityList.remove(entity) // Remove the entity from the requested add entity list @@ -743,8 +684,7 @@ class MeepMeep @JvmOverloads constructor( * @param entity The [Entity] to be added to the application. * @return The [MeepMeep] instance for method chaining. */ - fun requestToAddEntity(entity: Entity): MeepMeep { - // Add the entity to the requested add entity list + fun requestToAddEntity(entity: Entity): MeepMeep { // Add the entity to the requested add entity list requestedAddEntityList.add(entity) // Mark the entity list as dirty to indicate it needs to be sorted @@ -767,8 +707,7 @@ class MeepMeep @JvmOverloads constructor( * @see [requestToAddEntity] * @see [removeEntity] */ - fun requestToRemoveEntity(entity: Entity): MeepMeep { - // Add the entity to the requested remove entity list + fun requestToRemoveEntity(entity: Entity): MeepMeep { // Add the entity to the requested remove entity list requestedRemoveEntityList.add(entity) // Mark the entity list as dirty to indicate it needs to be sorted @@ -790,8 +729,7 @@ class MeepMeep @JvmOverloads constructor( * @return The [MeepMeep] instance for method chaining. * @see [MeepMeep.setBackground] */ - fun setBackgroundAlpha(alpha: Float): MeepMeep { - // Set the alpha transparency level for the background image + fun setBackgroundAlpha(alpha: Float): MeepMeep { // Set the alpha transparency level for the background image bgAlpha = alpha // Return the current instance for method chaining From 90b2950e1315e261395869f433a571e79baebb74 Mon Sep 17 00:00:00 2001 From: "A. Teo Welton" <76081718+DragonDev07@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:44:17 -0600 Subject: [PATCH 2/2] Formatting --- .../org/rowlandhall/meepmeep/MeepMeep.kt | 89 +++++++++++-------- 1 file changed, 54 insertions(+), 35 deletions(-) diff --git a/src/main/kotlin/org/rowlandhall/meepmeep/MeepMeep.kt b/src/main/kotlin/org/rowlandhall/meepmeep/MeepMeep.kt index 77c3aab..cb98f9f 100644 --- a/src/main/kotlin/org/rowlandhall/meepmeep/MeepMeep.kt +++ b/src/main/kotlin/org/rowlandhall/meepmeep/MeepMeep.kt @@ -131,7 +131,8 @@ class MeepMeep @JvmOverloads constructor( * @see [TrajectoryProgressSliderMaster] * @see [FieldUtil.CANVAS_WIDTH] */ - private val progressSliderMasterPanel: TrajectoryProgressSliderMaster by lazy { // Create a new instance of TrajectoryProgressSliderMaster + private val progressSliderMasterPanel: TrajectoryProgressSliderMaster by lazy { + // Create a new instance of TrajectoryProgressSliderMaster TrajectoryProgressSliderMaster( this, FieldUtil.CANVAS_WIDTH.toInt(), 20 ) @@ -141,7 +142,8 @@ class MeepMeep @JvmOverloads constructor( // Returns true if entity list needs to be sorted private var entityListDirty = false - init { // Create class loader to load resources + init { + // Create class loader to load resources val classLoader = Thread.currentThread().contextClassLoader // Load Roboto Regular font from file @@ -273,7 +275,8 @@ class MeepMeep @JvmOverloads constructor( * @see [FieldUtil] * @see [LoopManager] */ - private val render: () -> Unit = { // Get the graphics context from the canvas buffer strategy + private val render: () -> Unit = { + // Get the graphics context from the canvas buffer strategy val g = canvas.bufferStrat.drawGraphics as Graphics2D // Enable anti-aliasing for smoother visuals @@ -338,24 +341,25 @@ class MeepMeep @JvmOverloads constructor( * @see [Entity] * @see [ZIndexManager] */ - private val update: (deltaTime: Long) -> Unit = - { deltaTime -> // Check if the entity list needs to be updated - if (entityListDirty) { // Remove entities that are requested to be removed - entityList.removeAll(requestedRemoveEntityList) - requestedRemoveEntityList.clear() - - // Add entities that are requested to be added - entityList.addAll(requestedAddEntityList) - requestedAddEntityList.clear() - - // Sort the entity list by their z-index - entityList.sortBy { it.zIndex } - entityListDirty = false - } + private val update: (deltaTime: Long) -> Unit = { deltaTime -> + // Check if the entity list needs to be updated + if (entityListDirty) { + // Remove entities that are requested to be removed + entityList.removeAll(requestedRemoveEntityList) + requestedRemoveEntityList.clear() + + // Add entities that are requested to be added + entityList.addAll(requestedAddEntityList) + requestedAddEntityList.clear() + + // Sort the entity list by their z-index + entityList.sortBy { it.zIndex } + entityListDirty = false + } - // Update each entity in the entity list - entityList.forEach { it.update(deltaTime) } - } + // Update each entity in the entity list + entityList.forEach { it.update(deltaTime) } + } /** * Manages the application loop with the specified fps and update and @@ -372,7 +376,8 @@ class MeepMeep @JvmOverloads constructor( * * @return The [MeepMeep] instance. */ - fun start(): MeepMeep { // Set the default background if none is set + fun start(): MeepMeep { + // Set the default background if none is set if (bg == null) setBackground(Background.GRID_BLUE) windowFrame.isVisible = true @@ -454,7 +459,8 @@ class MeepMeep @JvmOverloads constructor( * @param image The [Image] to be set as the background. * @return The [MeepMeep] instance for method chaining. */ - fun setBackground(image: Image): MeepMeep { // Scale the provided image to fit the window dimensions + fun setBackground(image: Image): MeepMeep { + // Scale the provided image to fit the window dimensions bg = image.getScaledInstance(windowX, windowY, Image.SCALE_SMOOTH) // Return the current instance for method chaining @@ -473,7 +479,8 @@ class MeepMeep @JvmOverloads constructor( */ fun setMouseCoordinateDisplayPosition( x: Int, y: Int - ) { // Update the x-coordinate for the mouse coordinate display + ) { + // Update the x-coordinate for the mouse coordinate display mouseCoordinateDisplayX = x // Update the y-coordinate for the mouse coordinate display @@ -487,7 +494,8 @@ class MeepMeep @JvmOverloads constructor( * shown. * @return The [MeepMeep] instance for method chaining. */ - fun setShowFPS(showFPS: Boolean): MeepMeep { // Update the showFPS property + fun setShowFPS(showFPS: Boolean): MeepMeep { + // Update the showFPS property this.showFPS = showFPS return this @@ -510,7 +518,8 @@ class MeepMeep @JvmOverloads constructor( @JvmOverloads fun setTheme( schemeLight: ColorScheme, schemeDark: ColorScheme = schemeLight - ): MeepMeep { // Set the light and dark themes in the ColorManager + ): MeepMeep { + // Set the light and dark themes in the ColorManager colorManager.setTheme(schemeLight, schemeDark) // Refresh the theme for all entities and UI components @@ -531,7 +540,8 @@ class MeepMeep @JvmOverloads constructor( * @see [ColorManager] * @see [ThemedEntity] */ - private fun refreshTheme() { // Core Refresh: Update the theme for all entities that implement ThemedEntity + private fun refreshTheme() { + // Core Refresh: Update the theme for all entities that implement ThemedEntity entityList.forEach { if (it is ThemedEntity) it.switchScheme(colorManager.theme) } @@ -553,7 +563,8 @@ class MeepMeep @JvmOverloads constructor( * @return The [MeepMeep] instance for method chaining. * @see [ColorManager] */ - fun setDarkMode(isDarkMode: Boolean): MeepMeep { // Update the dark mode setting in the ColorManager + fun setDarkMode(isDarkMode: Boolean): MeepMeep { + // Update the dark mode setting in the ColorManager colorManager.isDarkMode = isDarkMode // Return the current instance for method chaining @@ -572,7 +583,8 @@ class MeepMeep @JvmOverloads constructor( * @see FieldUtil * @see Entity.setCanvasDimensions */ - private fun onCanvasResize() { // Set the canvas width and height in FieldUtil to the current window dimensions + private fun onCanvasResize() { + // Set the canvas width and height in FieldUtil to the current window dimensions FieldUtil.CANVAS_WIDTH = windowX.toDouble() FieldUtil.CANVAS_HEIGHT = windowY.toDouble() @@ -592,8 +604,10 @@ class MeepMeep @JvmOverloads constructor( * @param interval The interval to set for the [AxesEntity]. * @return The [MeepMeep] instance for method chaining. */ - fun setAxesInterval(interval: Int): MeepMeep { // Check if the default [AxesEntity] is in the [entityList] - if (DEFAULT_AXES_ENTITY in entityList) { // Set the interval for the default [AxesEntity] + fun setAxesInterval(interval: Int): MeepMeep { + // Check if the default [AxesEntity] is in the [entityList] + if (DEFAULT_AXES_ENTITY in entityList) { + // Set the interval for the default [AxesEntity] DEFAULT_AXES_ENTITY.setInterval(interval) } @@ -614,7 +628,8 @@ class MeepMeep @JvmOverloads constructor( * @param entity The [Entity] to be added to the application. * @return The [MeepMeep] instance for method chaining. */ - fun addEntity(entity: Entity): MeepMeep { // Add the entity to the z-index manager + fun addEntity(entity: Entity): MeepMeep { + // Add the entity to the z-index manager zIndexManager.addEntity(entity) // Add the entity to the entity list and mark the list as dirty @@ -649,7 +664,8 @@ class MeepMeep @JvmOverloads constructor( * @param entity The [Entity] to be removed from the application. * @return The [MeepMeep] instance for method chaining. */ - fun removeEntity(entity: Entity): MeepMeep { // Remove the entity from the entity list + fun removeEntity(entity: Entity): MeepMeep { + // Remove the entity from the entity list entityList.remove(entity) // Remove the entity from the requested add entity list @@ -684,7 +700,8 @@ class MeepMeep @JvmOverloads constructor( * @param entity The [Entity] to be added to the application. * @return The [MeepMeep] instance for method chaining. */ - fun requestToAddEntity(entity: Entity): MeepMeep { // Add the entity to the requested add entity list + fun requestToAddEntity(entity: Entity): MeepMeep { + // Add the entity to the requested add entity list requestedAddEntityList.add(entity) // Mark the entity list as dirty to indicate it needs to be sorted @@ -707,7 +724,8 @@ class MeepMeep @JvmOverloads constructor( * @see [requestToAddEntity] * @see [removeEntity] */ - fun requestToRemoveEntity(entity: Entity): MeepMeep { // Add the entity to the requested remove entity list + fun requestToRemoveEntity(entity: Entity): MeepMeep { + // Add the entity to the requested remove entity list requestedRemoveEntityList.add(entity) // Mark the entity list as dirty to indicate it needs to be sorted @@ -729,7 +747,8 @@ class MeepMeep @JvmOverloads constructor( * @return The [MeepMeep] instance for method chaining. * @see [MeepMeep.setBackground] */ - fun setBackgroundAlpha(alpha: Float): MeepMeep { // Set the alpha transparency level for the background image + fun setBackgroundAlpha(alpha: Float): MeepMeep { + // Set the alpha transparency level for the background image bgAlpha = alpha // Return the current instance for method chaining