Skip to content

Commit

Permalink
show player avatars in the selector
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaruth committed Apr 17, 2024
1 parent 159c787 commit 66a23e6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/main/kotlin/dartzee/bean/GameSetupPlayerSelector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import dartzee.core.bean.ScrollTableOrdered
import dartzee.core.util.DialogUtil
import dartzee.core.util.setMargins
import dartzee.db.MAX_PLAYERS
import dartzee.utils.InjectedThings
import dartzee.utils.ResourceCache
import java.awt.Font
import java.awt.event.ActionEvent
import javax.swing.ImageIcon
import javax.swing.JToggleButton
Expand All @@ -15,6 +18,13 @@ class GameSetupPlayerSelector : AbstractPlayerSelector<ScrollTableOrdered>() {
init {
super.render()

if (InjectedThings.partyMode) {
val font = ResourceCache.BASE_FONT.deriveFont(Font.PLAIN, 24f)
tablePlayersToSelectFrom.setTableFont(font)
tablePlayersSelected.setTableFont(font)
}


btnPairs.icon = ImageIcon(javaClass.getResource("/buttons/teams.png"))
btnPairs.toolTipText = "Play in pairs"
tablePlayersSelected.addButtonToOrderingPanel(btnPairs, 3)
Expand Down
16 changes: 13 additions & 3 deletions src/main/kotlin/dartzee/bean/ScrollTablePlayers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package dartzee.bean
import dartzee.core.bean.ScrollTable
import dartzee.core.util.TableUtil
import dartzee.db.PlayerEntity
import dartzee.utils.InjectedThings
import dartzee.utils.getAvatarImage
import dartzee.utils.resize
import javax.swing.ImageIcon

fun ScrollTable.getSelectedPlayer(): PlayerEntity? {
val row = table.selectedRow
Expand All @@ -22,8 +26,14 @@ fun ScrollTable.initPlayerTableModel(players: List<PlayerEntity> = listOf()) {

this.model = model

setRowHeight(23)
setColumnWidths("25")
if (InjectedThings.partyMode) {
setRowHeight(50)
setColumnWidths("50")
} else {
setRowHeight(23)
setColumnWidths("25")
}


addPlayers(players)

Expand All @@ -34,7 +44,7 @@ fun ScrollTable.initPlayerTableModel(players: List<PlayerEntity> = listOf()) {
fun ScrollTable.addPlayers(players: List<PlayerEntity>) = players.forEach(::addPlayer)

private fun ScrollTable.addPlayer(player: PlayerEntity) {
val flag = player.getFlag()
val flag = if (InjectedThings.partyMode) ImageIcon(player.getAvatarImage().resize(50, 50)) else player.getFlag()
val row = arrayOf(flag, player)

addRow(row)
Expand Down
9 changes: 5 additions & 4 deletions src/main/kotlin/dartzee/utils/PlayerImageUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun splitAvatar(
return ImageIcon(newImage)
}

private fun PlayerEntity.getAvatarImage() = getAvatar().toBufferedImage(BufferedImage.TYPE_INT_RGB)
fun PlayerEntity.getAvatarImage() = getAvatar().toBufferedImage(BufferedImage.TYPE_INT_RGB)

fun combinePlayerFlags(flagOne: ImageIcon, flagTwo: ImageIcon): ImageIcon {
val imageOne = flagOne.toBufferedImage(BufferedImage.TYPE_INT_ARGB)
Expand Down Expand Up @@ -121,11 +121,12 @@ fun convertImageToAvatarDimensions(imageBytes: ByteArray): ByteArray {

val croppedImage = image.getSubimage(xc, yc, minDimension, minDimension)
val resizedImage =
croppedImage
.getScaledInstance(PLAYER_IMAGE_WIDTH, PLAYER_IMAGE_HEIGHT, BufferedImage.SCALE_SMOOTH)
.toBufferedImage(PLAYER_IMAGE_WIDTH, PLAYER_IMAGE_HEIGHT)
croppedImage.resize(PLAYER_IMAGE_WIDTH, PLAYER_IMAGE_HEIGHT)

val baos = ByteArrayOutputStream()
ImageIO.write(resizedImage, "jpg", baos)
return baos.toByteArray()
}

fun BufferedImage.resize(width: Int, height: Int = width) =
getScaledInstance(width, height, BufferedImage.SCALE_SMOOTH).toBufferedImage(width, height)

0 comments on commit 66a23e6

Please sign in to comment.