From 0984b65d65327dbab3bf4ca184da27dd05895f09 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Wed, 20 Feb 2019 01:34:47 +0900 Subject: [PATCH] inventory equip slot icon --- .../graphics/gui/inventory/equip_position.tga | 3 ++ src/net/torvald/terrarum/Point2d.kt | 8 ++++++ .../terrarum/modulebasegame/BuildingMaker.kt | 28 +++++++++++++++++++ .../UIBuildingMakerBlockChooser.kt | 4 +-- .../ui/UIItemInventoryEquippedView.kt | 13 ++++++++- work_files/UI/inventory_equip_icons.psd | 4 +-- 6 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 assets/graphics/gui/inventory/equip_position.tga diff --git a/assets/graphics/gui/inventory/equip_position.tga b/assets/graphics/gui/inventory/equip_position.tga new file mode 100644 index 000000000..919c1c57e --- /dev/null +++ b/assets/graphics/gui/inventory/equip_position.tga @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4b590190e881809a54b49022ef4b761e3050684d1daf988b3aa22e6e793f445e +size 10412 diff --git a/src/net/torvald/terrarum/Point2d.kt b/src/net/torvald/terrarum/Point2d.kt index a58c047fd..261d687a0 100644 --- a/src/net/torvald/terrarum/Point2d.kt +++ b/src/net/torvald/terrarum/Point2d.kt @@ -64,4 +64,12 @@ data class Point2i(var x: Int, var y: Int) { this.x = other.x this.y = other.y } + + operator fun plus(other: Point2i): Point2i { + return Point2i(this.x + other.x, this.y + other.y) + } + + operator fun minus(other: Point2i): Point2i { + return Point2i(other.x - this.x, other.y - this.y) + } } diff --git a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt index d416215ab..4dfc45592 100644 --- a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt +++ b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt @@ -18,6 +18,7 @@ import net.torvald.terrarum.modulebasegame.ui.UIPaletteSelector import net.torvald.terrarum.modulebasegame.weather.WeatherMixer import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UINSMenu +import net.torvald.terrarum.worlddrawer.FeaturesDrawer.TILE_SIZE import net.torvald.terrarum.worlddrawer.LightmapRenderer import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack @@ -163,6 +164,8 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { override fun drawBody(batch: SpriteBatch) { batch.color = blockMarkerColour batch.draw(blockMarkings.get(2,0), hitbox.startX.toFloat(), hitbox.startY.toFloat()) + batch.draw(blockMarkings.get(2,0), hitbox.startX.toFloat() + world.width * TILE_SIZE, hitbox.startY.toFloat()) + batch.draw(blockMarkings.get(2,0), hitbox.startX.toFloat() - world.width * TILE_SIZE, hitbox.startY.toFloat()) } override fun drawGlow(batch: SpriteBatch) { } @@ -394,6 +397,31 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { } } } + + private fun getSelectionTotalDimension(): Point2i { + selection.sortBy { it.y * world.width + it.x } + return selection.last() - selection.first() + } + + private fun serialiseSelection() { + // save format: sparse list encoded in following binary format: + /* + Header: TEaT0bLD -- magic: Terrarum Attachment + Int8 version number -- always 1 + Int8 number of layers -- always 2 or 3 + Int8 number of payloads -- always 2 or 3 + int8 compression algorithm -- always 1 (DEFLATE) + Int16 width + + The rest: payloads defined in the map data format + Payloads: array of (Int48 tileAddress, UInt16 blockID) + + Footer: EndAtC \xFF\xFE -- magic: end of attachment with BOM + */ + // proc: + // translate boxes so that leftmost point is (0,0) + // write to the list using translated coords + } } class BuildingMakerController(val screen: BuildingMaker) : InputAdapter() { diff --git a/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerBlockChooser.kt b/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerBlockChooser.kt index bc50c303f..0bfeb6d50 100644 --- a/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerBlockChooser.kt +++ b/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerBlockChooser.kt @@ -25,7 +25,7 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() { const val TILES_Y = 14 const val TILESREGION_SIZE = 24 - const val MENUBAR_SIZE = 80 + const val MENUBAR_SIZE = 72 const val SCROLLBAR_SIZE = 24 const val WIDTH = TILES_X*TILESREGION_SIZE + SCROLLBAR_SIZE + MENUBAR_SIZE @@ -50,7 +50,7 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() { ) } private val tabs = UIItemTextButtonList( - this, arrayOf("Terrain", "Wall", "Wire", "Fixtures"), + this, arrayOf("Terrain", "Wall", "Wire"), 0, 0, textAreaWidth = MENUBAR_SIZE, width = MENUBAR_SIZE, defaultSelection = 0 ) diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt index 6e2d05503..1ca814c9c 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryEquippedView.kt @@ -11,6 +11,7 @@ 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.UIItem +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack /** * Created by minjaesong on 2017-10-28. @@ -42,6 +43,10 @@ class UIItemInventoryEquippedView( val spriteViewBackCol: Color = CELLCOLOUR_BLACK + private val equipPosIcon = TextureRegionPack("./assets/graphics/gui/inventory/equip_position.tga", 18, 18) + private val cellToIcon = intArrayOf(0,1,2,3,4,5,6,7,6,7,6,7) + private val equipPosIconCol = Color(0xdddddd7f.toInt()) + private val itemGrid = Array(2 * 6) { UIItemInventoryElemSimple( parentUI = parentUI, @@ -97,7 +102,13 @@ class UIItemInventoryEquippedView( // TODO inscribe slot image on each cells HERE - itemGrid.forEach { it.render(batch, camera) } + itemGrid.forEachIndexed { index, cell -> + cell.render(batch, camera) + if (cell.item == null) { + batch.color = equipPosIconCol + batch.draw(equipPosIcon.get(cellToIcon[index], 0), 15f + cell.posX, 15f + cell.posY) + } + } oldPosX = posX diff --git a/work_files/UI/inventory_equip_icons.psd b/work_files/UI/inventory_equip_icons.psd index 5c7abbda5..d6b8306a1 100644 --- a/work_files/UI/inventory_equip_icons.psd +++ b/work_files/UI/inventory_equip_icons.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b3ffda4dfa461bc046d1779f08084369c6c2a97a768900d51fde9588fdaf2638 -size 3951913 +oid sha256:8182110458b6416e58599bb8c9149c9a7c13af6a087ca021b84c73ce7b6adaa3 +size 3952352