inventory ui: number of cells can be given on creation

This commit is contained in:
minjaesong
2019-08-05 05:20:09 +09:00
parent df63824f69
commit aaec9c6b5b
3 changed files with 26 additions and 14 deletions

View File

@@ -39,10 +39,13 @@ class UIInventoryFull(
override var width: Int = AppLoader.screenW
override var height: Int = AppLoader.screenH
private val CELLS_HOR = 10
private val CELLS_VRT = 8
private val itemListToEquipViewGap = UIItemInventoryDynamicList.listGap // used to be 24; figured out that the extra gap does nothig
val internalWidth: Int = UIItemInventoryDynamicList.WIDTH + UIItemInventoryEquippedView.WIDTH + itemListToEquipViewGap
val internalHeight: Int = 166 + UIItemInventoryDynamicList.HEIGHT // grad_begin..grad_end..contents..grad_begin..grad_end
val internalWidth: Int = UIItemInventoryDynamicList.getEstimatedW(CELLS_HOR) + UIItemInventoryEquippedView.WIDTH + itemListToEquipViewGap
val internalHeight: Int = 166 + UIItemInventoryDynamicList.getEstimatedH(CELLS_VRT) // grad_begin..grad_end..contents..grad_begin..grad_end
init {
handler.allowESCtoClose = true
@@ -105,12 +108,13 @@ class UIInventoryFull(
override var openCloseTime: Second = 0.0f
private val itemList: UIItemInventoryDynamicList =
internal val itemList: UIItemInventoryDynamicList =
UIItemInventoryDynamicList(
this,
actor.inventory,
0 + (AppLoader.screenW - internalWidth) / 2,
107 + (AppLoader.screenH - internalHeight) / 2
107 + (AppLoader.screenH - internalHeight) / 2,
CELLS_HOR, CELLS_VRT
)
@@ -349,7 +353,7 @@ class UIInventoryFull(
get() = (currentScreen) * AppLoader.screenW
private val MINIMAP_WIDTH = 800f
private val MINIMAP_HEIGHT = UIItemInventoryDynamicList.HEIGHT.toFloat()
private val MINIMAP_HEIGHT = itemList.height.toFloat()
private val MINIMAP_SKYCOL = Color(0x88bbddff.toInt())
private var minimapZoom = 1f
private var minimapPanX = -MinimapComposer.totalWidth / 2f

View File

@@ -34,6 +34,8 @@ class UIItemInventoryDynamicList(
val inventory: ActorInventory, // when you're going to display List of Craftables, you could implement a Delegator...? Or just build a virtual inventory
override var posX: Int,
override var posY: Int,
val horizontalCells: Int,
val verticalCells: Int,
val drawScrollOnRightside: Boolean = false,
val drawWallet: Boolean = true
) : UIItem(parentUI) {
@@ -42,9 +44,10 @@ class UIItemInventoryDynamicList(
override var oldPosX = posX
override var oldPosY = posY
override val width = WIDTH
override val height = HEIGHT
override val width = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
override val height = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
val largeListWidth = (horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 2) * listGap) / 2
val backColour = CELLCOLOUR_BLACK
private val catArrangement = parentUI.catArrangement
@@ -98,13 +101,16 @@ class UIItemInventoryDynamicList(
companion object {
const val listGap = 8
const val horizontalCells = 11
const val verticalCells = 8
//const val horizontalCells = 11
//const val verticalCells = 8
const val LIST_TO_CONTROL_GAP = 12
val largeListWidth = (horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 2) * listGap) / 2
val WIDTH = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
val HEIGHT = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
//val largeListWidth = (horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 2) * listGap) / 2
//val WIDTH = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
//val HEIGHT = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
fun getEstimatedW(horizontalCells: Int) = horizontalCells * UIItemInventoryElemSimple.height + (horizontalCells - 1) * listGap
fun getEstimatedH(verticalCells: Int) = verticalCells * UIItemInventoryElemSimple.height + (verticalCells - 1) * listGap
}
private val itemGrid = Array<UIItemInventoryCellBase>(horizontalCells * verticalCells) {
@@ -123,6 +129,7 @@ class UIItemInventoryDynamicList(
inactiveTextCol = defaultTextColour
)
}
// TODO automatically determine how much columns are needed. Minimum width = 5 grids
private val itemList = Array<UIItemInventoryCellBase>(verticalCells * 2) {
UIItemInventoryElem(
parentUI = inventoryUI,

View File

@@ -24,12 +24,13 @@ class UIItemInventoryEquippedView(
override var posY: Int
) : UIItem(parentUI) {
override val width = WIDTH
override val height = HEIGHT
override val height = parentUI.itemList.height
companion object {
val WIDTH = 2 * UIItemInventoryElemSimple.height + UIItemInventoryDynamicList.listGap
val HEIGHT = UIItemInventoryDynamicList.HEIGHT
//val HEIGHT = UIItemInventoryDynamicList.HEIGHT
val SPRITE_DRAW_COL = Color(0xddddddff.toInt())
}