From 8c8e41871a94d170f4eecbb910c9a343695d7dcc Mon Sep 17 00:00:00 2001 From: minjaesong Date: Fri, 25 Mar 2022 16:22:35 +0900 Subject: [PATCH] portrait on equippedview --- .../AssembledSpriteAnimation.kt | 95 ++++++++++--------- .../ui/UIItemInventoryEquippedView.kt | 33 ++++--- 2 files changed, 67 insertions(+), 61 deletions(-) diff --git a/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt b/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt index 1d19cab05..d0fab25d9 100644 --- a/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt +++ b/src/net/torvald/spriteanimation/AssembledSpriteAnimation.kt @@ -90,61 +90,37 @@ class AssembledSpriteAnimation( } } + fun renderThisAnimation(batch: SpriteBatch, posX: Float, posY: Float, scale: Float, animName: String) { + val animNameRoot = animName.substring(0, animName.indexOfLast { it == '_' }) - override fun render(batch: SpriteBatch, posX: Float, posY: Float, scale: Float) { - if (parentActor.isVisible) { - - val tx = (parentActor.hitboxTranslateX) * scale - val txFlp = -(parentActor.hitboxTranslateX) * scale - // flipping will not be symmetrical if baseHitboxWidth is odd number - val ty = (parentActor.hitboxTranslateY - parentActor.baseHitboxH) * scale - val tyFlp = (parentActor.hitboxTranslateY) * scale + val tx = (parentActor.hitboxTranslateX) * scale + val txFlp = -(parentActor.hitboxTranslateX) * scale + // flipping will not be symmetrical if baseHitboxWidth is odd number + val ty = (parentActor.hitboxTranslateY - parentActor.baseHitboxH) * scale + val tyFlp = (parentActor.hitboxTranslateY) * scale - adp.animations[currentAnimation]!!.let { theAnim -> - val skeleton = theAnim.skeleton.joints.reversed() - val transforms = adp.getTransform("${currentAnimation}_${1+currentFrame}") - val bodypartOrigins = adp.bodypartJoints + adp.animations[animNameRoot]!!.let { theAnim -> + val skeleton = theAnim.skeleton.joints.reversed() + val transforms = adp.getTransform(animName) + val bodypartOrigins = adp.bodypartJoints - AssembleFrameBase.makeTransformList(skeleton, transforms).forEach { (name, bodypartPos0) -> - var bodypartPos = bodypartPos0.invertY() - if (flipVertical) bodypartPos = bodypartPos.invertY() - if (flipHorizontal) bodypartPos = bodypartPos.invertX() - bodypartPos += ADPropertyObject.Vector2i(1,0) + AssembleFrameBase.makeTransformList(skeleton, transforms).forEach { (name, bodypartPos0) -> + var bodypartPos = bodypartPos0.invertY() + if (flipVertical) bodypartPos = bodypartPos.invertY() + if (flipHorizontal) bodypartPos = bodypartPos.invertX() + bodypartPos += ADPropertyObject.Vector2i(1,0) - if (name in jointNameToEquipPos) { - ItemCodex[(parentActor as? Pocketed)?.inventory?.itemEquipped?.get(jointNameToEquipPos[name]!!)]?.let { item -> - ItemCodex.getItemImage(item)?.let { image -> - val drawPos = adp.origin + bodypartPos // imgCentre for held items are (0,0) - val w = image.regionWidth * scale - val h = image.regionHeight * scale - val fposX = posX.floor() + drawPos.x * scale - val fposY = posY.floor() + drawPos.y * scale - h - - // draw - if (flipHorizontal && flipVertical) - batch.draw(image, fposX + txFlp, fposY + tyFlp, -w, -h) - else if (flipHorizontal && !flipVertical) - batch.draw(image, fposX + txFlp, fposY - ty, -w, h) - else if (!flipHorizontal && flipVertical) - batch.draw(image, fposX - tx, fposY + tyFlp, w, -h) - else - batch.draw(image, fposX - tx, fposY - ty, w, h) - } - } - } - else { - res[name]?.let { image -> - var imgCentre = bodypartOrigins[name]!! - if (flipVertical) imgCentre = imgCentre.invertY() - if (flipHorizontal) imgCentre = imgCentre.invertX() - - val drawPos = adp.origin + bodypartPos - imgCentre + if (name in jointNameToEquipPos) { + ItemCodex[(parentActor as? Pocketed)?.inventory?.itemEquipped?.get(jointNameToEquipPos[name]!!)]?.let { item -> + ItemCodex.getItemImage(item)?.let { image -> + val drawPos = adp.origin + bodypartPos // imgCentre for held items are (0,0) val w = image.regionWidth * scale val h = image.regionHeight * scale val fposX = posX.floor() + drawPos.x * scale - val fposY = posY.floor() + drawPos.y * scale + val fposY = posY.floor() + drawPos.y * scale - h + // draw if (flipHorizontal && flipVertical) batch.draw(image, fposX + txFlp, fposY + tyFlp, -w, -h) else if (flipHorizontal && !flipVertical) @@ -153,14 +129,39 @@ class AssembledSpriteAnimation( batch.draw(image, fposX - tx, fposY + tyFlp, w, -h) else batch.draw(image, fposX - tx, fposY - ty, w, h) - } } } + else { + res[name]?.let { image -> + var imgCentre = bodypartOrigins[name]!! + if (flipVertical) imgCentre = imgCentre.invertY() + if (flipHorizontal) imgCentre = imgCentre.invertX() + val drawPos = adp.origin + bodypartPos - imgCentre + val w = image.regionWidth * scale + val h = image.regionHeight * scale + val fposX = posX.floor() + drawPos.x * scale + val fposY = posY.floor() + drawPos.y * scale + if (flipHorizontal && flipVertical) + batch.draw(image, fposX + txFlp, fposY + tyFlp, -w, -h) + else if (flipHorizontal && !flipVertical) + batch.draw(image, fposX + txFlp, fposY - ty, -w, h) + else if (!flipHorizontal && flipVertical) + batch.draw(image, fposX - tx, fposY + tyFlp, w, -h) + else + batch.draw(image, fposX - tx, fposY - ty, w, h) + + } + } } + } + } + override fun render(batch: SpriteBatch, posX: Float, posY: Float, scale: Float) { + if (parentActor.isVisible) { + renderThisAnimation(batch, posX, posY, scale, "${currentAnimation}_${1+currentFrame}") } } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt index 4abc32b83..6de020627 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt @@ -82,23 +82,28 @@ class UIItemInventoryEquippedView( // sprite - val sprite = INGAME.actorNowPlaying?.sprite - sprite?.let { - blendNormal(batch) + INGAME.actorNowPlaying?.let { actor -> + actor.sprite?.let { + blendNormal(batch) - batch.color = SPRITE_DRAW_COL + batch.color = SPRITE_DRAW_COL + + if (it is SheetSpriteAnimation) { + batch.draw( + it.textureRegion.get(0, 0), + posX + (width - it.cellWidth + EXTRA_HEADROOM_X).div(2).toFloat(), + posY + (width - it.cellHeight - EXTRA_HEADROOM_Y).div(2).toFloat() + ) + } + else if (it is AssembledSpriteAnimation) { + it.renderThisAnimation(batch, + posX + ((width - actor.baseHitboxW) / 2).toFloat(), + posY + ((width - actor.baseHitboxH) / 2).toFloat(), + 1f, "ANIM_IDLE_1" + ) + } - if (it is SheetSpriteAnimation) { - batch.draw( - it.textureRegion.get(0, 0), - posX + (width - it.cellWidth + EXTRA_HEADROOM_X).div(2).toFloat(), - posY + (width - it.cellHeight - EXTRA_HEADROOM_Y).div(2).toFloat() - ) } - else if (it is AssembledSpriteAnimation) { - // TODO - } - } // slot image on each cells