F3 moved to PostProcessor; palette UI for buildingmaker

This commit is contained in:
minjaesong
2019-02-03 17:01:27 +09:00
parent c476ca0d99
commit 8da8fdb863
19 changed files with 427 additions and 156 deletions

View File

@@ -17,8 +17,11 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
object ItemSlotImageFactory {
val colourBlack = Color(0x404040_FF)
val colourWhite = Color(0xC0C0C0_FF.toInt())
val CELLCOLOUR_BLACK_OPAQUE = Color(0x404040_FF)
val CELLCOLOUR_WHITE_OPAQUE = Color(0xC0C0C0_FF.toInt())
val CELLCOLOUR_BLACK = Color(0x404040_88)
val CELLCOLOUR_WHITE = Color(0xC0C0C0_88.toInt())
val slotImage = TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slots_atlas.tga"), 38, 38) // must have same w/h as slotLarge

View File

@@ -0,0 +1,164 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.fillRect
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
import net.torvald.terrarum.serialise.toLittle
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINSMenu
/**
* Created by minjaesong on 2019-02-03.
*/
class UIEditorPalette : UICanvas() {
override var width = 36
override var height = 72
override var openCloseTime = 0f
val LINE_HEIGHT = 24
val TEXT_OFFSETX = 3f
val TEXT_OFFSETY = (LINE_HEIGHT - Terrarum.fontGame.lineHeight) / 2f
fun mouseOnTitleBar() =
relativeMouseX in 0 until width && relativeMouseY in 0 until LINE_HEIGHT
var fore = Block.STONE_BRICKS
var back = Block.DIRT
private val titleText = "Pal."
private val swapIcon: Texture
init {
// make swap icon, because I can't be bothered to make yet another tga
val swapIconPixmap = Pixmap(12, 12, Pixmap.Format.RGBA8888)
swapIconPixmap.pixels.rewind()
arrayOf(
0b001000000000,
0b011000000000,
0b111111111100,
0b011000000100,
0b001000000100,
0b000000000100,
0b000000000100,
0b000000000100,
0b000000000100,
0b000000011111,
0b000000001110,
0b000000000100
).reversed().forEachIndexed { index, bits ->
for (shiftmask in 11 downTo 0) {
val bit = bits.ushr(shiftmask).and(1) == 1
swapIconPixmap.pixels.put((if (bit) -1 else 0).toLittle())
}
}
swapIconPixmap.pixels.rewind()
swapIcon = Texture(swapIconPixmap)
swapIconPixmap.dispose()
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// draw title bar
batch.color = UINSMenu.DEFAULT_TITLEBACKCOL
blendNormal(batch)
batch.fillRect(0f, 0f, width.toFloat(), LINE_HEIGHT.toFloat())
// draw "Pal."
batch.color = UINSMenu.DEFAULT_TITLETEXTCOL
Terrarum.fontGame.draw(batch, titleText, TEXT_OFFSETX, TEXT_OFFSETY)
// draw background
batch.color = CELLCOLOUR_BLACK
batch.fillRect(0f, LINE_HEIGHT.toFloat(), 36f, 48f)
// draw back and fore selection
batch.color = Color.WHITE
// TODO carve the overlap
batch.draw(ItemCodex.getItemImage(back), 14f, 41f)
batch.draw(ItemCodex.getItemImage(fore), 6f, 33f)
Terrarum.fontSmallNumbers.draw(batch, fore.toString(), 3f, 61f)
// draw swap icon
batch.color = Color.WHITE
batch.draw(swapIcon, 18f, 26f)
}
override fun updateUI(delta: Float) {
}
fun swapForeAndBack() {
// xor used, because why not?
fore = fore xor back
back = back xor fore
fore = fore xor back
}
override fun doOpening(delta: Float) {
}
override fun doClosing(delta: Float) {
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
}
override fun dispose() {
}
private var dragOriginX = 0 // relative mousepos
private var dragOriginY = 0 // relative mousepos
private var dragForReal = false
private var swapDown = false
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
if (mouseInScreen(screenX, screenY)) {
if (dragForReal) {
handler.setPosition(screenX - dragOriginX, screenY - dragOriginY)
//println("drag $screenX, $screenY")
}
}
return true
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (mouseOnTitleBar()) {
dragOriginX = relativeMouseX
dragOriginY = relativeMouseY
dragForReal = true
}
else {
dragForReal = false
}
// make swap button work
if (!swapDown && (relativeMouseX in 14..35 && relativeMouseY in 24..32 || relativeMouseX in 22..35 && relativeMouseY in 33..40)) {
swapDown = true
swapForeAndBack()
}
return true
}
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
swapDown = false
return true
}
}

View File

@@ -10,6 +10,7 @@ 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.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.ui.UIItemImageButton
import java.util.*
@@ -39,7 +40,7 @@ class UIItemInventoryDynamicList(
override val width = WIDTH
override val height = HEIGHT
val backColour = Color(0x404040_88)
val backColour = CELLCOLOUR_BLACK
private val catArrangement = parentUI.catArrangement

View File

@@ -8,6 +8,7 @@ import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.itemproperties.GameItem
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.ui.UIItem
/**
@@ -37,7 +38,7 @@ class UIItemInventoryEquippedView(
lateinit var inventorySortList: Array<GameItem?>
private var rebuildList = true
val spriteViewBackCol: Color; get() = Color(0x404040_88.toInt())//Color(0xd4d4d4_ff.toInt())
val spriteViewBackCol: Color = CELLCOLOUR_BLACK
private val itemGrid = Array<UIItemInventoryCellBase>(2 * 6) {
UIItemInventoryElemSimple(
@@ -49,7 +50,7 @@ class UIItemInventoryEquippedView(
itemImage = null,
mouseoverBackCol = Color(0x282828_ff),
mouseoverBackBlendMode = BlendMode.SCREEN,
backCol = Color(0x404040_88),
backCol = CELLCOLOUR_BLACK,
backBlendMode = BlendMode.NORMAL,
drawBackOnNull = true
)