mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 18:44:05 +09:00
buildingmaker palette
This commit is contained in:
@@ -18,7 +18,7 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TILES_X = 8
|
const val TILES_X = 8
|
||||||
const val TILES_Y = 8
|
const val TILES_Y = 10
|
||||||
|
|
||||||
const val TILESREGION_SIZE = 24
|
const val TILESREGION_SIZE = 24
|
||||||
const val MENUBAR_SIZE = 72
|
const val MENUBAR_SIZE = 72
|
||||||
@@ -37,7 +37,7 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
// TODO scrolling of the palette, as the old method flat out won't work with The Flattening
|
// TODO scrolling of the palette, as the old method flat out won't work with The Flattening
|
||||||
|
|
||||||
private val tabs = UIItemTextButtonList(
|
private val tabs = UIItemTextButtonList(
|
||||||
this, 36, arrayOf("Terrain", "Wall", "Wire"),
|
this, 36, arrayOf("Terrain", "Wall", "Wire"), // TODO use inventory icons
|
||||||
0, 0, textAreaWidth = MENUBAR_SIZE, width = MENUBAR_SIZE,
|
0, 0, textAreaWidth = MENUBAR_SIZE, width = MENUBAR_SIZE,
|
||||||
defaultSelection = 0,
|
defaultSelection = 0,
|
||||||
backgroundCol = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL
|
backgroundCol = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL
|
||||||
@@ -49,6 +49,14 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
backgroundCol = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL
|
backgroundCol = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private var scroll = 0
|
||||||
|
|
||||||
|
private val <E> List<E>.visible: List<E>
|
||||||
|
get() = this.subList(
|
||||||
|
TILES_X * scroll,
|
||||||
|
(TILES_X * scroll + TILES_X * TILES_Y).coerceAtMost(this.size)
|
||||||
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
||||||
BlockCodex.getAll().filter {
|
BlockCodex.getAll().filter {
|
||||||
@@ -58,7 +66,7 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
catch (e: NullPointerException) {
|
catch (e: NullPointerException) {
|
||||||
null
|
null
|
||||||
}) != null
|
}) != null
|
||||||
}.filter { !it.hasTag("INTERNAL") }.sortedBy { it.id }.forEachIndexed { index, prop ->
|
}.filter { !it.hasTag("INTERNAL") }.sortedBy { it.id }.forEachIndexed { index, prop -> // FIXME no lexicographic sorting
|
||||||
val paletteItem = UIItemImageButton(
|
val paletteItem = UIItemImageButton(
|
||||||
this, ItemCodex.getItemImage(prop.id)!!,
|
this, ItemCodex.getItemImage(prop.id)!!,
|
||||||
initialX = MENUBAR_SIZE + (index % TILES_X) * TILESREGION_SIZE,
|
initialX = MENUBAR_SIZE + (index % TILES_X) * TILESREGION_SIZE,
|
||||||
@@ -67,14 +75,14 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
width = TILESREGION_SIZE,
|
width = TILESREGION_SIZE,
|
||||||
height = TILESREGION_SIZE,
|
height = TILESREGION_SIZE,
|
||||||
highlightCol = Color.WHITE,
|
highlightCol = Color.WHITE,
|
||||||
activeCol = Color.WHITE
|
activeCol = Color.WHITE,
|
||||||
|
backgroundCol = Color(0)
|
||||||
)
|
)
|
||||||
|
|
||||||
paletteItem.clickOnceListener = { _, _ ->
|
paletteItem.clickOnceListener = { _, _ ->
|
||||||
parent.setPencilColour(prop.id)
|
parent.setPencilColour(prop.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
uiItems.add(paletteItem)
|
|
||||||
palette.add(paletteItem)
|
palette.add(paletteItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,13 +90,13 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
private val scrollOverflowSize = ((palette.size - TILES_X * TILES_Y).toDouble() / TILES_X).ceilToDouble().coerceAtLeast(0.0)
|
private val scrollOverflowSize = ((palette.size - TILES_X * TILES_Y).toDouble() / TILES_X).ceilToDouble().coerceAtLeast(0.0)
|
||||||
|
|
||||||
private val scrollBar = UIItemVertSlider(
|
private val scrollBar = UIItemVertSlider(
|
||||||
this, WIDTH - UIItemVertSlider.WIDTH, 0, 0.0, 0.0, scrollOverflowSize, height, SCROLLBAR_SIZE
|
this, WIDTH - UIItemVertSlider.WIDTH, 0, 0.0, 0.0, scrollOverflowSize, height, (height * TILES_Y / (scrollOverflowSize + TILES_Y)).ceilToInt()
|
||||||
).also {
|
).also {
|
||||||
println("scrollOverflowSize = $scrollOverflowSize")
|
println("scrollOverflowSize = $scrollOverflowSize")
|
||||||
|
|
||||||
addUIitem(it)
|
addUIitem(it)
|
||||||
it.scrolledListener = { scrollX, scrollY ->
|
it.selectionChangeListener = { value ->
|
||||||
|
scroll = value.roundToInt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +110,10 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
closeGracefully()
|
closeGracefully()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
palette.visible.forEach {
|
||||||
|
it.update(delta)
|
||||||
|
}
|
||||||
|
|
||||||
uiItems.forEach { it.update(delta) }
|
uiItems.forEach { it.update(delta) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +129,10 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
override fun renderUI(batch: SpriteBatch, camera: OrthographicCamera) {
|
override fun renderUI(batch: SpriteBatch, camera: OrthographicCamera) {
|
||||||
blendNormalStraightAlpha(batch)
|
blendNormalStraightAlpha(batch)
|
||||||
|
|
||||||
|
// border
|
||||||
|
batch.color = Toolkit.Theme.COL_INACTIVE
|
||||||
|
Toolkit.drawBoxBorder(batch, -1, -1, width + 2, height + 2)
|
||||||
|
|
||||||
// background
|
// background
|
||||||
batch.color = DEFAULT_BACKGROUNDCOL
|
batch.color = DEFAULT_BACKGROUNDCOL
|
||||||
Toolkit.fillArea(batch, 0, 0, width, height)
|
Toolkit.fillArea(batch, 0, 0, width, height)
|
||||||
@@ -129,6 +145,10 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
tabs.render(batch, camera)
|
tabs.render(batch, camera)
|
||||||
closeButton.render(batch, camera)
|
closeButton.render(batch, camera)
|
||||||
|
|
||||||
|
palette.visible.forEach {
|
||||||
|
it.render(batch, camera, 0, -scroll * TILESREGION_SIZE)
|
||||||
|
}
|
||||||
|
|
||||||
uiItems.forEach { it.render(batch, camera) }
|
uiItems.forEach { it.render(batch, camera) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,6 +182,10 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
dragForReal = false
|
dragForReal = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
palette.visible.forEach {
|
||||||
|
it.touchDown(screenX, screenY, pointer, button)
|
||||||
|
}
|
||||||
|
|
||||||
return super.touchDown(screenX, screenY, pointer, button)
|
return super.touchDown(screenX, screenY, pointer, button)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,6 +193,12 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
return super.touchUp(screenX, screenY, pointer, button)
|
return super.touchUp(screenX, screenY, pointer, button)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||||
|
scrollBar.scrolledForce(amountX, amountY)
|
||||||
|
|
||||||
|
return super.scrolled(amountX, amountY)
|
||||||
|
}
|
||||||
|
|
||||||
override fun doOpening(delta: Float) {
|
override fun doOpening(delta: Float) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,10 @@ open class UIItemImageButton(
|
|||||||
var highlighted = false
|
var highlighted = false
|
||||||
var extraDrawOp: (UIItem, SpriteBatch) -> Unit = { _,_ -> }
|
var extraDrawOp: (UIItem, SpriteBatch) -> Unit = { _,_ -> }
|
||||||
|
|
||||||
override fun render(batch: SpriteBatch, camera: OrthographicCamera) {
|
fun render(batch: SpriteBatch, camera: OrthographicCamera, offX: Int, offY: Int) {
|
||||||
|
val posX = this.posX + offX
|
||||||
|
val posY = this.posY + offY
|
||||||
|
|
||||||
// draw background
|
// draw background
|
||||||
if (highlighted) {
|
if (highlighted) {
|
||||||
BlendMode.resolve(highlightBackBlendMode, batch)
|
BlendMode.resolve(highlightBackBlendMode, batch)
|
||||||
@@ -90,6 +93,10 @@ open class UIItemImageButton(
|
|||||||
extraDrawOp(this, batch)
|
extraDrawOp(this, batch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun render(batch: SpriteBatch, camera: OrthographicCamera) {
|
||||||
|
render(batch, camera, 0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
override fun dispose() {
|
override fun dispose() {
|
||||||
image.texture.dispose()
|
image.texture.dispose()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class UIItemVertSlider(
|
|||||||
private var mouseOnHandle = false
|
private var mouseOnHandle = false
|
||||||
|
|
||||||
private val handleTravelDist = height - handleHeight
|
private val handleTravelDist = height - handleHeight
|
||||||
private var handlePos = (initialValue / max).times(handleTravelDist).coerceIn(0.0, handleTravelDist.toDouble())
|
private var handlePos = if (max == 0.0) 0.0 else (initialValue / max).times(handleTravelDist).coerceIn(0.0, handleTravelDist.toDouble())
|
||||||
|
|
||||||
var value: Double = initialValue; private set
|
var value: Double = initialValue; private set
|
||||||
var selectionChangeListener: (Double) -> Unit = {}
|
var selectionChangeListener: (Double) -> Unit = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user