Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Unused "Middle Button Panel" Code #12

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 46 additions & 108 deletions src/main/kotlin/org/rowlandhall/meepmeep/MeepMeep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
)
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
DragonDev07 marked this conversation as resolved.
Show resolved Hide resolved
if (e.keyCode == KeyEvent.VK_C || e.keyCode == KeyEvent.VK_COPY) { // Convert mouse coordinates from screen to field coordinates
DragonDev07 marked this conversation as resolved.
Show resolved Hide resolved
val mouseToFieldCoords = FieldUtil.screenCoordsToFieldCoords(
Vector2d(
canvasMouseX.toDouble(), canvasMouseY.toDouble()
Expand Down Expand Up @@ -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
DragonDev07 marked this conversation as resolved.
Show resolved Hide resolved
val g = canvas.bufferStrat.drawGraphics as Graphics2D

// Enable anti-aliasing for smoother visuals
Expand All @@ -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
DragonDev07 marked this conversation as resolved.
Show resolved Hide resolved
val resetComposite = g.composite
val alphaComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, bgAlpha)

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -575,23 +531,14 @@ 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)
}

// 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
}
}

/**
Expand All @@ -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
Expand All @@ -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()

Expand All @@ -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)
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading