mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-14 23:56:07 +09:00
portrait on equippedview
This commit is contained in:
@@ -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) {
|
val tx = (parentActor.hitboxTranslateX) * scale
|
||||||
if (parentActor.isVisible) {
|
val txFlp = -(parentActor.hitboxTranslateX) * scale
|
||||||
|
// flipping will not be symmetrical if baseHitboxWidth is odd number
|
||||||
val tx = (parentActor.hitboxTranslateX) * scale
|
val ty = (parentActor.hitboxTranslateY - parentActor.baseHitboxH) * scale
|
||||||
val txFlp = -(parentActor.hitboxTranslateX) * scale
|
val tyFlp = (parentActor.hitboxTranslateY) * 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 ->
|
adp.animations[animNameRoot]!!.let { theAnim ->
|
||||||
val skeleton = theAnim.skeleton.joints.reversed()
|
val skeleton = theAnim.skeleton.joints.reversed()
|
||||||
val transforms = adp.getTransform("${currentAnimation}_${1+currentFrame}")
|
val transforms = adp.getTransform(animName)
|
||||||
val bodypartOrigins = adp.bodypartJoints
|
val bodypartOrigins = adp.bodypartJoints
|
||||||
|
|
||||||
AssembleFrameBase.makeTransformList(skeleton, transforms).forEach { (name, bodypartPos0) ->
|
AssembleFrameBase.makeTransformList(skeleton, transforms).forEach { (name, bodypartPos0) ->
|
||||||
var bodypartPos = bodypartPos0.invertY()
|
var bodypartPos = bodypartPos0.invertY()
|
||||||
if (flipVertical) bodypartPos = bodypartPos.invertY()
|
if (flipVertical) bodypartPos = bodypartPos.invertY()
|
||||||
if (flipHorizontal) bodypartPos = bodypartPos.invertX()
|
if (flipHorizontal) bodypartPos = bodypartPos.invertX()
|
||||||
bodypartPos += ADPropertyObject.Vector2i(1,0)
|
bodypartPos += ADPropertyObject.Vector2i(1,0)
|
||||||
|
|
||||||
if (name in jointNameToEquipPos) {
|
if (name in jointNameToEquipPos) {
|
||||||
ItemCodex[(parentActor as? Pocketed)?.inventory?.itemEquipped?.get(jointNameToEquipPos[name]!!)]?.let { item ->
|
ItemCodex[(parentActor as? Pocketed)?.inventory?.itemEquipped?.get(jointNameToEquipPos[name]!!)]?.let { item ->
|
||||||
ItemCodex.getItemImage(item)?.let { image ->
|
ItemCodex.getItemImage(item)?.let { image ->
|
||||||
val drawPos = adp.origin + bodypartPos // imgCentre for held items are (0,0)
|
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
|
|
||||||
val w = image.regionWidth * scale
|
val w = image.regionWidth * scale
|
||||||
val h = image.regionHeight * scale
|
val h = image.regionHeight * scale
|
||||||
val fposX = posX.floor() + drawPos.x * 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)
|
if (flipHorizontal && flipVertical)
|
||||||
batch.draw(image, fposX + txFlp, fposY + tyFlp, -w, -h)
|
batch.draw(image, fposX + txFlp, fposY + tyFlp, -w, -h)
|
||||||
else if (flipHorizontal && !flipVertical)
|
else if (flipHorizontal && !flipVertical)
|
||||||
@@ -153,14 +129,39 @@ class AssembledSpriteAnimation(
|
|||||||
batch.draw(image, fposX - tx, fposY + tyFlp, w, -h)
|
batch.draw(image, fposX - tx, fposY + tyFlp, w, -h)
|
||||||
else
|
else
|
||||||
batch.draw(image, fposX - tx, fposY - ty, w, h)
|
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}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,23 +82,28 @@ class UIItemInventoryEquippedView(
|
|||||||
|
|
||||||
|
|
||||||
// sprite
|
// sprite
|
||||||
val sprite = INGAME.actorNowPlaying?.sprite
|
INGAME.actorNowPlaying?.let { actor ->
|
||||||
sprite?.let {
|
actor.sprite?.let {
|
||||||
blendNormal(batch)
|
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
|
// slot image on each cells
|
||||||
|
|||||||
Reference in New Issue
Block a user