diff --git a/assets/graphics/gui/box_border_flat_tileable.tga b/assets/graphics/gui/box_border_flat_tileable.tga new file mode 100644 index 000000000..5cfa92340 --- /dev/null +++ b/assets/graphics/gui/box_border_flat_tileable.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15634b6d5bf5e720297e076ff047ee545a19f2011626db17c29fb525350e446f +size 54 diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index 3325e85b5..4e6815e96 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -12,6 +12,8 @@ import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText +import net.torvald.terrarum.ui.Toolkit +import net.torvald.terrarum.ui.Toolkit.DEFAULT_BOX_BORDER_COL import net.torvald.terrarum.ui.UIItemTextButton /*** @@ -86,8 +88,11 @@ class UIItemInventoryElem( BlendMode.resolve(backBlendMode, batch) batch.color = backCol } - batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat()) + Toolkit.fillArea(batch, posX, posY, width, height) } + batch.color = DEFAULT_BOX_BORDER_COL + //blendNormal(batch) + Toolkit.drawBoxBorder(batch, posX, posY, width, height) if (item != null && itemImage != null) { diff --git a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt index 3543af14f..dadbf0ae7 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElemSimple.kt @@ -12,6 +12,8 @@ import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellBase import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes import net.torvald.terrarum.modulebasegame.ui.UIItemInventoryCellCommonRes.toItemCountText +import net.torvald.terrarum.ui.Toolkit +import net.torvald.terrarum.ui.Toolkit.DEFAULT_BOX_BORDER_COL import net.torvald.terrarum.ui.UIItemTextButton /** @@ -71,8 +73,11 @@ class UIItemInventoryElemSimple( BlendMode.resolve(backBlendMode, batch) batch.color = backCol } - batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat()) + Toolkit.fillArea(batch, posX, posY, width, height) } + batch.color = DEFAULT_BOX_BORDER_COL + //blendNormal(batch) + Toolkit.drawBoxBorder(batch, posX, posY, width, height) // quickslot and equipped slot indicator is not needed as it's intended for blocks and walls diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt index 3bee2dbcd..e0f51055d 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt @@ -10,6 +10,8 @@ import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK_ACTIVE +import net.torvald.terrarum.ui.Toolkit +import net.torvald.terrarum.ui.Toolkit.DEFAULT_BOX_BORDER_COL import net.torvald.terrarum.ui.UIItem import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack @@ -82,10 +84,10 @@ class UIItemInventoryEquippedView( // sprite background blendNormal(batch) batch.color = spriteViewBackCol - batch.fillRect( - posX.toFloat(), posY.toFloat(), - width.toFloat(), width.toFloat() - ) + Toolkit.fillArea(batch, posX, posY, width, width) + batch.color = DEFAULT_BOX_BORDER_COL + Toolkit.drawBoxBorder(batch, posX, posY, width, width) + // sprite val sprite = theActor.sprite @@ -101,8 +103,7 @@ class UIItemInventoryEquippedView( } - // TODO inscribe slot image on each cells HERE - + // slot image on each cells itemGrid.forEachIndexed { index, cell -> cell.render(batch, camera) if (cell.item == null) { diff --git a/src/net/torvald/terrarum/ui/DrawUtil.kt b/src/net/torvald/terrarum/ui/DrawUtil.kt deleted file mode 100644 index 493ece590..000000000 --- a/src/net/torvald/terrarum/ui/DrawUtil.kt +++ /dev/null @@ -1,23 +0,0 @@ -package net.torvald.terrarum.ui - -import com.badlogic.gdx.graphics.Texture -import com.badlogic.gdx.graphics.g2d.SpriteBatch -import net.torvald.terrarum.AppLoader - - -/** - * Created by minjaesong on 2016-08-04. - */ -object DrawUtil { - fun drawCentered(batch: SpriteBatch, image: Texture, screenPosY: Int, ui: UICanvas? = null) { - val imageW = image.width - val targetW = if (ui == null) AppLoader.screenW else ui.width - - batch.draw(image, targetW.minus(imageW).ushr(1).toFloat(), screenPosY.toFloat()) - } - - fun drawCentered(batch: SpriteBatch, image: Texture, screenPosY: Int, targetW: Int, offsetX: Int = 0, offsetY: Int = 0) { - val imageW = image.width - batch.draw(image, targetW.minus(imageW).ushr(1).toFloat() + offsetX, screenPosY.toFloat() + offsetY) - } -} \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/Toolkit.kt b/src/net/torvald/terrarum/ui/Toolkit.kt new file mode 100644 index 000000000..34860aae3 --- /dev/null +++ b/src/net/torvald/terrarum/ui/Toolkit.kt @@ -0,0 +1,71 @@ +package net.torvald.terrarum.ui + +import com.badlogic.gdx.Gdx +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.Texture +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.AppLoader +import net.torvald.terrarum.CommonResourcePool +import net.torvald.terrarum.fillRect +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack + + +/** + * Created by minjaesong on 2016-08-04. + */ +object Toolkit { + + val DEFAULT_BOX_BORDER_COL = Color(1f, 1f, 1f, 0.2f) + + init { + CommonResourcePool.addToLoadingList("toolkit_box_border") { + TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/box_border_flat_tileable.tga"), 1, 1) + } + CommonResourcePool.loadAll() + } + + fun drawCentered(batch: SpriteBatch, image: Texture, screenPosY: Int, ui: UICanvas? = null) { + val imageW = image.width + val targetW = if (ui == null) AppLoader.screenW else ui.width + + batch.draw(image, targetW.minus(imageW).ushr(1).toFloat(), screenPosY.toFloat()) + } + + fun drawCentered(batch: SpriteBatch, image: Texture, screenPosY: Int, targetW: Int, offsetX: Int = 0, offsetY: Int = 0) { + val imageW = image.width + batch.draw(image, targetW.minus(imageW).ushr(1).toFloat() + offsetX, screenPosY.toFloat() + offsetY) + } + + fun fillArea(batch: SpriteBatch, x: Int, y: Int, w: Int, h: Int) { + batch.fillRect(x.toFloat(), y.toFloat(), w.toFloat(), h.toFloat()) + } + + /** + * Parameters are THAT OF THE BOX, the border will be drawn OUTSIDE of the params you specified! + */ + fun drawBoxBorder(batch: SpriteBatch, x: Int, y: Int, w: Int, h: Int) { + val pack = CommonResourcePool.getAsTextureRegionPack("toolkit_box_border") + val tx = pack.tileW.toFloat() + val ty = pack.tileH.toFloat() + + // top edge + batch.draw(pack.get(1, 0), x.toFloat(), y - ty, w.toFloat(), ty) + // bottom edge + batch.draw(pack.get(1, 2), x.toFloat(), y.toFloat() + h, w.toFloat(), ty) + // left edge + batch.draw(pack.get(0, 1), x.toFloat() - tx, y.toFloat(), tx, h.toFloat()) + // right edge + batch.draw(pack.get(2, 1), x.toFloat() + w, y.toFloat(), tx, h.toFloat()) + + // top left point + /*batch.draw(pack.get(0, 0), x - tx, y - ty) + // top right point + batch.draw(pack.get(2, 0), x + tx, y - ty) + // bottom left point + batch.draw(pack.get(0, 2), x - tx, y + ty) + // bottom right point + batch.draw(pack.get(2, 2), x + tx, y + ty)*/ + + } + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/UIItemImageGallery.kt b/src/net/torvald/terrarum/ui/UIItemImageGallery.kt index 78daa81e8..b763f71af 100644 --- a/src/net/torvald/terrarum/ui/UIItemImageGallery.kt +++ b/src/net/torvald/terrarum/ui/UIItemImageGallery.kt @@ -39,7 +39,7 @@ class UIItemImageGallery( } imageList.forEachIndexed { i, image -> - DrawUtil.drawCentered(batch, image, + Toolkit.drawCentered(batch, image, imagePosY(i), width.toFloat().div(column).times(column(i).plus(1)).roundInt(), posX, posY