mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 10:34:06 +09:00
fixed various quirks and removed dirty hacks on quickslot bar/pie
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.gameactors.ai.toInt
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
|
||||
/**
|
||||
* Make item slot image with number on bottom-right
|
||||
*
|
||||
* Created by minjaesong on 2016-07-20.
|
||||
*/
|
||||
object ItemSlotImageBuilder {
|
||||
|
||||
// FIXME it leaks mem waaaaagh
|
||||
|
||||
val colourBlack = Color(0x404040_FF)
|
||||
val colourWhite = Color(0xC0C0C0_FF.toInt())
|
||||
|
||||
val slotImage = TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slots_atlas.tga"), 38, 38) // must have same w/h as slotLarge
|
||||
|
||||
|
||||
private val imageDict = HashMap<Long, Texture>()
|
||||
|
||||
|
||||
fun produce(isBlack: Boolean, number: Int = 10): TextureRegion {
|
||||
return slotImage.get(number, 0 or isBlack.toInt().shl(1))
|
||||
}
|
||||
|
||||
fun produceLarge(isBlack: Boolean, number: Int = 10): TextureRegion {
|
||||
return slotImage.get(number, 1 or isBlack.toInt().shl(1))
|
||||
}
|
||||
|
||||
|
||||
fun dispose() {
|
||||
slotImage.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
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.gameactors.ai.toInt
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
|
||||
/**
|
||||
* Make item slot image with number on bottom-right
|
||||
*
|
||||
* Created by minjaesong on 2016-07-20.
|
||||
*/
|
||||
object ItemSlotImageFactory {
|
||||
|
||||
val colourBlack = Color(0x404040_FF)
|
||||
val colourWhite = Color(0xC0C0C0_FF.toInt())
|
||||
|
||||
val slotImage = TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slots_atlas.tga"), 38, 38) // 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 produceLarge(isBlack: Boolean, number: Int = 10, item: GameItem?): ItemSlotImage {
|
||||
return ItemSlotImage(slotImage.get(number, 1 or isBlack.toInt().shl(1)), ItemCodex.getItemImage(item))
|
||||
}
|
||||
|
||||
|
||||
fun dispose() {
|
||||
slotImage.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data class ItemSlotImage(val baseTex: TextureRegion, val itemTex: TextureRegion?) {
|
||||
/**
|
||||
* batch.begin() must be called beforehand.
|
||||
*
|
||||
* @param batch a spritebatch
|
||||
* @param cx centre-x position of the draw
|
||||
* @param cy centre-y position of the draw
|
||||
*/
|
||||
fun draw(batch: SpriteBatch, cx: Int, cy: Int) {
|
||||
// just draws two image on the centre
|
||||
|
||||
batch.draw(baseTex, cx - (baseTex.regionWidth).div(2).toFloat(), cy - (baseTex.regionHeight).div(2).toFloat())
|
||||
if (itemTex != null)
|
||||
batch.draw(itemTex, cx - (itemTex.regionWidth).div(2).toFloat(), cy - (itemTex.regionHeight).div(2).toFloat())
|
||||
|
||||
}
|
||||
}
|
||||
@@ -316,8 +316,8 @@ package net.torvald.terrarum.modulebasegame.ui
|
||||
items[k].itemImage = ItemCodex.getItemImage(sortListItem.item)
|
||||
|
||||
// set quickslot number
|
||||
for (qs in 1..UIQuickBar.SLOT_COUNT) {
|
||||
if (sortListItem.item == actor?.inventory?.getQuickBar(qs - 1)?.item) {
|
||||
for (qs in 1..UIQuickslotBar.SLOT_COUNT) {
|
||||
if (sortListItem.item == actor?.inventory?.getQuickslot(qs - 1)?.item) {
|
||||
items[k].quickslot = qs % 10 // 10 -> 0, 1..9 -> 1..9
|
||||
break
|
||||
}
|
||||
|
||||
@@ -3,20 +3,16 @@ package net.torvald.terrarum.modulebasegame.ui
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.BlendMode
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.UIItemInventoryElem
|
||||
import net.torvald.terrarum.UIItemInventoryElemSimple
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
||||
import net.torvald.terrarum.ceilInt
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
import net.torvald.terrarum.ui.UIItemImageButton
|
||||
import java.util.ArrayList
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Display either extended or compact list
|
||||
@@ -75,8 +71,7 @@ class UIItemInventoryDynamicList(
|
||||
val defaultTextColour = Color(0xeaeaea_ff.toInt())
|
||||
|
||||
private val listGap = 8
|
||||
private val itemList = Array<UIItemInventoryCellBase>(
|
||||
7 * 2, {
|
||||
private val itemList = Array<UIItemInventoryCellBase>(7 * 2) {
|
||||
UIItemInventoryElem(
|
||||
parentUI = inventoryUI,
|
||||
posX = this.posX + (272 + listGap) * (it % 2),
|
||||
@@ -91,9 +86,9 @@ class UIItemInventoryDynamicList(
|
||||
backBlendMode = BlendMode.NORMAL,
|
||||
drawBackOnNull = true,
|
||||
inactiveTextCol = defaultTextColour
|
||||
) })
|
||||
private val itemGrid = Array<UIItemInventoryCellBase>(
|
||||
7 * 10, {
|
||||
)
|
||||
}
|
||||
private val itemGrid = Array<UIItemInventoryCellBase>(7 * 10) {
|
||||
UIItemInventoryElemSimple(
|
||||
parentUI = inventoryUI,
|
||||
posX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % 10),
|
||||
@@ -109,17 +104,13 @@ class UIItemInventoryDynamicList(
|
||||
inactiveTextCol = defaultTextColour
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
private var items: Array<UIItemInventoryCellBase>
|
||||
= if (catArrangement[selection] in compactViewCat) itemGrid else itemList // this is INIT code
|
||||
private var items: Array<UIItemInventoryCellBase> = itemList
|
||||
|
||||
var isCompactMode = (catArrangement[selection] in compactViewCat) // this is INIT code
|
||||
var isCompactMode = false // this is INIT code
|
||||
set(value) {
|
||||
items = if (value) itemGrid else itemList
|
||||
|
||||
rebuild()
|
||||
|
||||
field = value
|
||||
}
|
||||
|
||||
@@ -129,7 +120,7 @@ class UIItemInventoryDynamicList(
|
||||
posY - 2 + (4 + UIItemInventoryElem.height - (parentUI as UIInventoryFull).catIcons.tileH) * index
|
||||
|
||||
/** Long/compact mode buttons */
|
||||
private val gridModeButtons = Array<UIItemImageButton>(2, { index ->
|
||||
private val gridModeButtons = Array<UIItemImageButton>(2) { index ->
|
||||
UIItemImageButton(
|
||||
parentUI,
|
||||
parentUI.catIcons.get(index + 14, 0),
|
||||
@@ -139,7 +130,7 @@ class UIItemInventoryDynamicList(
|
||||
posY = getIconPosY(index),
|
||||
highlightable = true
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
private val scrollUpButton = UIItemImageButton(
|
||||
parentUI,
|
||||
@@ -288,8 +279,8 @@ class UIItemInventoryDynamicList(
|
||||
items[k].itemImage = ItemCodex.getItemImage(sortListItem.item)
|
||||
|
||||
// set quickslot number
|
||||
for (qs in 1..UIQuickBar.SLOT_COUNT) {
|
||||
if (sortListItem.item == inventory.getQuickBar(qs - 1)?.item) {
|
||||
for (qs in 1..UIQuickslotBar.SLOT_COUNT) {
|
||||
if (sortListItem.item == inventory.getQuickslot(qs - 1)?.item) {
|
||||
items[k].quickslot = qs % 10 // 10 -> 0, 1..9 -> 1..9
|
||||
break
|
||||
}
|
||||
|
||||
@@ -4,74 +4,61 @@ import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
|
||||
/**
|
||||
* A bar-shaped representation of the Quickslot.
|
||||
*
|
||||
* Created by minjaesong on 2016-07-20.
|
||||
*/
|
||||
class UIQuickBar : UICanvas() {
|
||||
private val gutter = 8
|
||||
override var width: Int = (ItemSlotImageBuilder.slotImage.tileW + gutter) * SLOT_COUNT
|
||||
override var height: Int = ItemSlotImageBuilder.slotImage.tileH + 4 + Terrarum.fontGame.lineHeight.toInt()
|
||||
class UIQuickslotBar : UICanvas() {
|
||||
private val cellSize = ItemSlotImageFactory.slotImage.tileW // 38
|
||||
|
||||
private val gutter = 10 - 6 // do -6 to get a gutter size of not-enlarged cells
|
||||
override var width: Int = cellSize * SLOT_COUNT + gutter * (SLOT_COUNT - 1) // 452
|
||||
override var height: Int = ItemSlotImageFactory.slotImage.tileH + 4 + Terrarum.fontGame.lineHeight.toInt()
|
||||
/**
|
||||
* In milliseconds
|
||||
*/
|
||||
override var openCloseTime: Second = 0.16f
|
||||
|
||||
private val startPointX = ItemSlotImageBuilder.slotImage.tileW / 2
|
||||
private val startPointY = ItemSlotImageBuilder.slotImage.tileH / 2
|
||||
override var openCloseTime: Second = COMMON_OPEN_CLOSE
|
||||
|
||||
private var selection: Int
|
||||
get() = (Terrarum.ingame!! as Ingame).actorNowPlaying?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
|
||||
set(value) { (Terrarum.ingame!! as Ingame).actorNowPlaying?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
|
||||
|
||||
|
||||
|
||||
companion object {
|
||||
const val SLOT_COUNT = 10
|
||||
const val DISPLAY_OPACITY = 0.8f
|
||||
const val COMMON_OPEN_CLOSE = 0.12f
|
||||
}
|
||||
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
for (i in 0..SLOT_COUNT - 1) {
|
||||
val image = if (i == selection)
|
||||
ItemSlotImageBuilder.produceLarge(false, (i + 1) % SLOT_COUNT)
|
||||
else
|
||||
ItemSlotImageBuilder.produce(true, (i + 1) % SLOT_COUNT)
|
||||
val item = (Terrarum.ingame!! as Ingame).actorNowPlaying?.inventory?.getQuickslot(i)?.item
|
||||
|
||||
val slotX = startPointX + (CELL_SIZE + gutter).times(i).toFloat()
|
||||
val slotY = startPointY.toFloat()
|
||||
val image = if (i == selection)
|
||||
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, item)
|
||||
else
|
||||
ItemSlotImageFactory.produce(true, (i + 1) % SLOT_COUNT, item)
|
||||
|
||||
val slotX = cellSize / 2 + (cellSize + gutter) * i
|
||||
val slotY = cellSize / 2
|
||||
|
||||
// draw slots
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity * finalOpacity)
|
||||
batch.draw(
|
||||
image,
|
||||
slotX,
|
||||
slotY
|
||||
)
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity * DISPLAY_OPACITY)
|
||||
image.draw(batch, slotX, slotY)
|
||||
|
||||
// draw item
|
||||
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
|
||||
if (player == null) return // if player is null, don't draw actual items
|
||||
|
||||
|
||||
val itemPair = player.inventory.getQuickBar(i)
|
||||
|
||||
if (itemPair != null) {
|
||||
val itemImage = ItemCodex.getItemImage(itemPair.item)
|
||||
val itemW = itemImage.regionWidth
|
||||
val itemH = itemImage.regionHeight
|
||||
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity)
|
||||
batch.draw(
|
||||
itemImage, // using fixed CELL_SIZE for reasons
|
||||
slotX + (CELL_SIZE - itemW) / 2f,
|
||||
slotY + (CELL_SIZE - itemH) / 2f
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,11 +108,4 @@ class UIQuickBar : UICanvas() {
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
val finalOpacity = 0.8f
|
||||
|
||||
const val SLOT_COUNT = 10
|
||||
const val CELL_SIZE = 32
|
||||
}
|
||||
}
|
||||
@@ -4,26 +4,27 @@ import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickBar.Companion.CELL_SIZE
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickBar.Companion.SLOT_COUNT
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.COMMON_OPEN_CLOSE
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.SLOT_COUNT
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import org.dyn4j.geometry.Vector2
|
||||
|
||||
/**
|
||||
* The Sims styled pie representation of the Quickslot.
|
||||
*
|
||||
* Created by minjaesong on 2016-07-20.
|
||||
*/
|
||||
class UIPieMenu : UICanvas() {
|
||||
private val cellSize = UIQuickBar.CELL_SIZE
|
||||
class uiQuickslotPie : UICanvas() {
|
||||
private val cellSize = ItemSlotImageFactory.slotImage.tileW
|
||||
|
||||
private val slotCount = UIQuickBar.SLOT_COUNT
|
||||
private val slotCount = UIQuickslotBar.SLOT_COUNT
|
||||
|
||||
private val slotDistanceFromCentre: Double
|
||||
get() = cellSize * 2.8 * handler.scale
|
||||
get() = cellSize * 2.5 * handler.scale
|
||||
override var width: Int = cellSize * 7
|
||||
override var height: Int = width
|
||||
|
||||
@@ -31,7 +32,7 @@ class UIPieMenu : UICanvas() {
|
||||
/**
|
||||
* In milliseconds
|
||||
*/
|
||||
override var openCloseTime: Second = 0.16f
|
||||
override var openCloseTime: Second = COMMON_OPEN_CLOSE
|
||||
|
||||
private val smallenSize = 0.93f
|
||||
|
||||
@@ -59,48 +60,24 @@ class UIPieMenu : UICanvas() {
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
// draw radial thingies
|
||||
for (i in 0..slotCount - 1) {
|
||||
val item = (Terrarum.ingame!! as Ingame).actorNowPlaying?.inventory?.getQuickslot(i)?.item
|
||||
|
||||
// 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)
|
||||
ItemSlotImageBuilder.produceLarge(false, (i + 1) % SLOT_COUNT)
|
||||
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, item)
|
||||
else
|
||||
ItemSlotImageBuilder.produce(true, (i + 1) % SLOT_COUNT)
|
||||
ItemSlotImageFactory.produce(true, (i + 1) % SLOT_COUNT, item)
|
||||
|
||||
val slotSize = image.regionWidth
|
||||
val slotX = slotCentrePoint.x.toInt()
|
||||
val slotY = slotCentrePoint.y.toInt()
|
||||
|
||||
val slotX = slotCentrePoint.x.toFloat() - (slotSize / 2)
|
||||
val slotY = slotCentrePoint.y.toFloat() - (slotSize / 2)
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity * UIQuickslotBar.DISPLAY_OPACITY)
|
||||
image.draw(batch, slotX, slotY)
|
||||
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity * UIQuickBar.finalOpacity)
|
||||
batch.draw(
|
||||
image,
|
||||
slotX,
|
||||
slotY
|
||||
)
|
||||
|
||||
|
||||
// draw item
|
||||
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
|
||||
if (player == null) return // don't draw actual items
|
||||
|
||||
|
||||
val itemPair = player.inventory.getQuickBar(i)
|
||||
|
||||
if (itemPair != null) {
|
||||
val itemImage = ItemCodex.getItemImage(itemPair.item)
|
||||
val itemW = itemImage.regionWidth
|
||||
val itemH = itemImage.regionHeight
|
||||
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity)
|
||||
batch.draw(
|
||||
itemImage, // using fixed CELL_SIZE for reasons
|
||||
slotX + (CELL_SIZE - itemW) / 2f,
|
||||
slotY + (CELL_SIZE - itemH) / 2f
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user