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

Cursor is still blinking after modal is closed #266

Open
coldwarrl opened this issue Dec 24, 2019 · 0 comments
Open

Cursor is still blinking after modal is closed #266

coldwarrl opened this issue Dec 24, 2019 · 0 comments
Labels
bug Bugs within the program

Comments

@coldwarrl
Copy link
Member

coldwarrl commented Dec 24, 2019

Cursor is still blinking on the screen after modal is closed

Run example, enter sth in the text area and press ESCAPE . The dialog is closed but the cursor is still blinking

Steps to reproduce the bug

package org.hexworks.zircon.examples


import org.hexworks.zircon.api.ColorThemes
import org.hexworks.zircon.api.Components
import org.hexworks.zircon.api.GameComponents
import org.hexworks.zircon.api.SwingApplications
import org.hexworks.zircon.api.application.AppConfig
import org.hexworks.zircon.api.builder.component.ModalBuilder
import org.hexworks.zircon.api.color.ANSITileColor
import org.hexworks.zircon.api.color.TileColor
import org.hexworks.zircon.api.component.ComponentAlignment
import org.hexworks.zircon.api.data.*
import org.hexworks.zircon.api.extensions.alignmentWithin
import org.hexworks.zircon.api.extensions.box
import org.hexworks.zircon.api.extensions.shadow
import org.hexworks.zircon.api.game.GameArea
import org.hexworks.zircon.api.game.base.BaseGameArea
import org.hexworks.zircon.api.graphics.Symbols
import org.hexworks.zircon.api.screen.Screen
import org.hexworks.zircon.api.uievent.*
import org.hexworks.zircon.internal.component.modal.EmptyModalResult

object CustomGameAreaExample {

    val theme = ColorThemes.adriftInDreams()

    class CustomGameArea(visibleSize: Size3D,
                         actualSize: Size3D) : BaseGameArea<Tile, Block<Tile>>(
            initialVisibleSize = visibleSize,
            initialActualSize = actualSize)

    @JvmStatic
    fun main(args: Array<String>) {

        val gameArea = CustomGameArea(VISIBLE_SIZE, ACTUAL_SIZE)
        val theme = ColorThemes.amigaOs()

        makeCaves(gameArea)

        val tileGrid = SwingApplications.startTileGrid(AppConfig.newBuilder()
                .withSize(VISIBLE_SIZE.to2DSize())
                .enableBetaFeatures()
                .build())

        val screen = Screen.create(tileGrid)

        screen.addComponent(GameComponents.newGameComponentBuilder<Tile, Block<Tile>>()
                .withSize(VISIBLE_SIZE.to2DSize())
                .withGameArea(gameArea)
                .build())

        screen.display()

        Thread.sleep(500)
        openModal(screen)

    }

    private fun openModal(screen: Screen, level: Int = 1) {

        val modalPanel = Components.panel()
                .withSize(Size.create(30, 20))
                .withDecorations(box(title = "Modal level: $level"), shadow())
                .build()

        val modal = ModalBuilder.newBuilder<EmptyModalResult>()
                .withComponent(modalPanel)
                .withParentSize(screen.size)
                .withColorTheme(theme)
                .build().apply {
                    handleKeyboardEvents(KeyboardEventType.KEY_PRESSED) { event, _ ->
                        if (event.code == KeyCode.KEY_C) {
                            close(EmptyModalResult)
                            Processed
                        } else Pass
                    }
                }

        val closeButton = Components.button()
                .withText("Close")
                .withAlignment(alignmentWithin(modalPanel, ComponentAlignment.BOTTOM_RIGHT))
                .build().apply {
                    handleComponentEvents(ComponentEventType.ACTIVATED) {
                        modal.close(EmptyModalResult)
                        Processed
                    }
                }

        val inputArea = Components.textArea()
                .withText("Enter Text here")
                .withAlignment(alignmentWithin(modalPanel, ComponentAlignment.CENTER))
                .build().apply {
                    handleKeyboardEvents(KeyboardEventType.KEY_PRESSED) { event, phase ->
                        if (event.code == KeyCode.ESCAPE)
                            modal.close(EmptyModalResult)
                        Processed
                    }
                }


        modalPanel.addComponent(closeButton)
        modalPanel.addComponent(inputArea)

        screen.openModal(modal)

    }

    private fun makeCaves(gameArea: GameArea<Tile, Block<Tile>>, smoothTimes: Int = 8) {
        val width = gameArea.actualSize.xLength
        val height = gameArea.actualSize.yLength
        var tiles: MutableMap<Position, Tile> = mutableMapOf()
        gameArea.actualSize.to2DSize().fetchPositions().forEach { pos ->
            tiles[pos] = if (Math.random() < 0.5) FLOOR else WALL
        }
        val newTiles: MutableMap<Position, Tile> = mutableMapOf()
        for (time in 0 until smoothTimes) {

            for (x in 0 until width) {
                for (y in 0 until height) {
                    var floors = 0
                    var rocks = 0

                    for (ox in -1..1) {
                        for (oy in -1..1) {
                            if (x + ox < 0 || x + ox >= width || y + oy < 0
                                    || y + oy >= height)
                                continue

                            if (tiles[Position.create(x + ox, y + oy)] === FLOOR)
                                floors++
                            else
                                rocks++
                        }
                    }
                    newTiles[Position.create(x, y)] = if (floors >= rocks) FLOOR else WALL
                }
            }
            tiles = newTiles
        }
        tiles.forEach { pos, tile ->
            val pos3D = pos.to3DPosition(0)
            gameArea.setBlockAt(pos3D, Block.newBuilder<Tile>()
                    .withContent(tile)
                    .withEmptyTile(Tile.empty())
                    .build())
        }
    }

    private val FLOOR = Tile.newBuilder()
            .withCharacter(Symbols.INTERPUNCT)
            .withForegroundColor(ANSITileColor.YELLOW)
            .buildCharacterTile()

    private val WALL = Tile.newBuilder()
            .withCharacter('#')
            .withForegroundColor(TileColor.fromString("#999999"))
            .buildCharacterTile()

    private val VISIBLE_SIZE = Size3D.create(60, 30, 10)
    private val ACTUAL_SIZE = Size3D.create(100, 100, 200)


}
@coldwarrl coldwarrl added the bug Bugs within the program label Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs within the program
Projects
None yet
Development

No branches or pull requests

1 participant