variable wire cutter uisng right click (no sprite change yet)

This commit is contained in:
minjaesong
2024-03-14 21:14:30 +09:00
parent 336dfad207
commit c0a8118717
9 changed files with 195 additions and 19 deletions

View File

@@ -4,8 +4,6 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.ItemCodex
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.toInt
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -32,13 +30,13 @@ object ItemSlotImageFactory {
val slotImage = TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slots_atlas2.tga"), TILE_WIDTH, TILE_HEIGHT) // must have same w/h as slotLarge
fun produce(isBlack: Boolean, number: Int = 10, item: GameItem?): ItemSlotImage {
return ItemSlotImage(slotImage.get(number, 0 or isBlack.toInt().shl(1)), ItemCodex.getItemImage(item))
fun produce(isBlack: Boolean, number: Int?, sprite: TextureRegion?): ItemSlotImage {
return ItemSlotImage(slotImage.get(number ?: 10, 0 or isBlack.toInt().shl(1)), sprite)
}
fun produceLarge(isBlack: Boolean, number: Int = 10, item: GameItem?, hasGauge: Boolean): ItemSlotImage {
fun produceLarge(isBlack: Boolean, number: Int?, sprite: TextureRegion?, hasGauge: Boolean): ItemSlotImage {
val y = if (hasGauge && isBlack) 9 else if (hasGauge && !isBlack) 8 else if (!hasGauge && isBlack) 3 else 1
return ItemSlotImage(slotImage.get(number, y), ItemCodex.getItemImage(item))
return ItemSlotImage(slotImage.get(number ?: 10, y), sprite)
}

View File

@@ -109,9 +109,9 @@ class UIQuickslotBar : UICanvas() {
val itemHasGauge = ((item?.maxDurability ?: 0) > 0.0) || item?.stackable == true
val image = if (i == selection)
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, item, itemHasGauge)
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, ItemCodex.getItemImage(item), itemHasGauge)
else
ItemSlotImageFactory.produce(true, (i + 1) % SLOT_COUNT, item)
ItemSlotImageFactory.produce(true, (i + 1) % SLOT_COUNT, ItemCodex.getItemImage(item))
val slotX = cellSize / 2 + (cellSize + gutter) * i
val slotY = cellSize / 2

View File

@@ -82,9 +82,9 @@ class UIQuickslotPie : UICanvas() {
// draw cells
val image = if (i == selection)
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, item, itemHasGauge)
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, ItemCodex.getItemImage(item), itemHasGauge)
else
ItemSlotImageFactory.produce(true, (i + 1) % SLOT_COUNT, item)
ItemSlotImageFactory.produce(true, (i + 1) % SLOT_COUNT, ItemCodex.getItemImage(item))
val slotX = slotCentrePoint.x.toInt()
val slotY = slotCentrePoint.y.toInt()

View File

@@ -0,0 +1,140 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.jme3.math.FastMath
import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText
import net.torvald.terrarum.ui.Toolkit
import net.torvald.terrarum.ui.UICanvas
import org.dyn4j.geometry.Vector2
import kotlin.math.roundToInt
/**
* Created by minjaesong on 2024-03-14.
*/
class UIWireCutterPie : UICanvas() {
init {
handler.allowESCtoClose = false
}
private val cellSize = ItemSlotImageFactory.slotImage.tileW
private val slotCount = 6
private val slotDistanceFromCentre: Double
get() = cellSize * 2.666 * handler.scale
override var width: Int = cellSize * 7
override var height: Int = width
/**
* In milliseconds
*/
override var openCloseTime: Second = UIQuickslotBar.COMMON_OPEN_CLOSE
private val smallenSize = 0.92f
var selection: Int = -1
override fun updateImpl(delta: Float) {
if (selection >= 0 && (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying != null)
(Terrarum.ingame!! as TerrarumIngame).actorNowPlaying!!.actorValue[AVKey.__PLAYER_WIRECUTTERSEL] =
selection % slotCount
// update controls
if (handler.isOpened || handler.isOpening) {
val cursorPos = Vector2(Terrarum.mouseScreenX.toDouble(), Terrarum.mouseScreenY.toDouble())
val centre = Vector2(Toolkit.hdrawWidth.toDouble(), App.scr.halfh.toDouble())
val deg = -(centre - cursorPos).direction.toFloat()
selection = Math.round(deg * slotCount / FastMath.TWO_PI)
if (selection < 0) selection += slotCount
// TODO add gamepad support
}
}
private val drawColor = Color(1f, 1f, 1f, 1f)
private fun getSprite(index: Int): TextureRegion {
val (x, y) = when (index) {
0 -> 1 to 3
1 -> 11 to 2
2 -> 12 to 2
3 -> 13 to 2
4 -> 14 to 2
5 -> 15 to 2
else -> throw IllegalArgumentException()
}
return CommonResourcePool.getAsItemSheet("basegame.items").get(x, y)
}
companion object {
fun getWireItemID(index: Int): String {
return when (index) {
0 -> "__all__"
1 -> "wire@basegame:8192"
2 -> "wire@basegame:8193"
3 -> "wire@basegame:8194"
4 -> "wire@basegame:8195"
5 -> "wire@basegame:8196"
else -> throw IllegalArgumentException()
}
}
}
override fun renderImpl(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) {
// draw radial thingies
for (i in 0 until slotCount) {
val sprite = getSprite(i)
// set position
val angle = Math.PI * 2.0 * (i.toDouble() / slotCount) + Math.PI // 180 deg monitor-wise
val slotCentrePoint = Vector2(0.0, slotDistanceFromCentre).setDirection(-angle) // NOTE: NOT a center of circle!
// draw cells
val image = if (i == selection)
ItemSlotImageFactory.produceLarge(false, null, sprite, false)
else
ItemSlotImageFactory.produce(true, null, sprite)
val slotX = slotCentrePoint.x.toInt()
val slotY = slotCentrePoint.y.toInt()
drawColor.a = UIQuickslotBar.DISPLAY_OPACITY
batch.color = drawColor
image.draw(batch, slotX, slotY)
}
}
override fun doOpening(delta: Float) {
doOpeningFade(this, openCloseTime)
handler.scale = smallenSize + (1f.minus(smallenSize) * handler.opacity)
}
override fun doClosing(delta: Float) {
doClosingFade(this, openCloseTime)
handler.scale = smallenSize + (1f.minus(smallenSize) * handler.opacity)
}
override fun endOpening(delta: Float) {
endOpeningFade(this)
handler.scale = 1f
}
override fun endClosing(delta: Float) {
endClosingFade(this)
handler.scale = 1f
}
override fun dispose() {
}
}