mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-09 10:04:05 +09:00
buildingmaker palette close and open again
This commit is contained in:
@@ -82,7 +82,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
|
|||||||
|
|
||||||
val uiToolbox = UINSMenu("Menu", 100, menuYaml)
|
val uiToolbox = UINSMenu("Menu", 100, menuYaml)
|
||||||
val notifier = Notification()
|
val notifier = Notification()
|
||||||
val uiPaletteSelector = UIPaletteSelector()
|
val uiPaletteSelector = UIPaletteSelector(this)
|
||||||
val uiPalette = UIBuildingMakerBlockChooser(this)
|
val uiPalette = UIBuildingMakerBlockChooser(this)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ package net.torvald.terrarum.modulebasegame
|
|||||||
import com.badlogic.gdx.graphics.Camera
|
import com.badlogic.gdx.graphics.Camera
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
import net.torvald.terrarum.fillRect
|
||||||
import net.torvald.terrarum.AppLoader
|
|
||||||
import net.torvald.terrarum.BlendMode
|
|
||||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarum.ui.UIItemImageButton
|
import net.torvald.terrarum.ui.UIItemImageButton
|
||||||
@@ -57,44 +55,64 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
|
|||||||
0, this.height - UIItemTextButtonList.DEFAULT_LINE_HEIGHT,
|
0, this.height - UIItemTextButtonList.DEFAULT_LINE_HEIGHT,
|
||||||
width = MENUBAR_SIZE, textAreaWidth = MENUBAR_SIZE
|
width = MENUBAR_SIZE, textAreaWidth = MENUBAR_SIZE
|
||||||
)
|
)
|
||||||
private val buttonGapClickDummy = UIItemImageButton(
|
|
||||||
this, TextureRegion(AppLoader.textureWhiteSquare),
|
|
||||||
width = MENUBAR_SIZE, height = height - (tabs.height + closeButton.height),
|
|
||||||
highlightable = false,
|
|
||||||
posX = 0, posY = tabs.height,
|
|
||||||
activeCol = Color(0),
|
|
||||||
inactiveCol = Color(0),
|
|
||||||
activeBackCol = DEFAULT_BACKGROUNDCOL,
|
|
||||||
activeBackBlendMode = BlendMode.NORMAL,
|
|
||||||
backgroundCol = DEFAULT_BACKGROUNDCOL,
|
|
||||||
backgroundBlendMode = BlendMode.NORMAL
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun updateUI(delta: Float) {
|
override fun updateUI(delta: Float) {
|
||||||
palette.forEach { it.update(delta) }
|
palette.forEach { it.update(delta) }
|
||||||
tabs.update(delta)
|
tabs.update(delta)
|
||||||
closeButton.update(delta)
|
closeButton.update(delta)
|
||||||
buttonGapClickDummy.update(delta)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||||
palette.forEach { it.render(batch, camera) }
|
palette.forEach { it.render(batch, camera) }
|
||||||
|
|
||||||
buttonGapClickDummy.render(batch, camera)
|
// gaps between tabs and close button
|
||||||
|
batch.color = DEFAULT_BACKGROUNDCOL
|
||||||
|
batch.fillRect(0f, tabs.height.toFloat(), MENUBAR_SIZE.toFloat(), height.toFloat() - (tabs.height + closeButton.height))
|
||||||
|
|
||||||
|
// the actual buttons
|
||||||
tabs.render(batch, camera)
|
tabs.render(batch, camera)
|
||||||
closeButton.render(batch, camera)
|
closeButton.render(batch, camera)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var dragOriginX = 0 // relative mousepos
|
||||||
|
private var dragOriginY = 0 // relative mousepos
|
||||||
|
private var dragForReal = false
|
||||||
|
private var closeReady = false // so that it'll close when the mouse is DOWN then UP
|
||||||
|
|
||||||
|
private fun mouseOnDragHandle() = relativeMouseX in 0 until MENUBAR_SIZE && relativeMouseY in tabs.height until height - closeButton.height
|
||||||
|
|
||||||
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||||
return super.touchDragged(screenX, screenY, pointer)
|
if (mouseOnDragHandle()) {
|
||||||
|
if (dragForReal) {
|
||||||
|
handler.setPosition(screenX - dragOriginX, screenY - dragOriginY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
return super.touchDown(screenX, screenY, pointer, button)
|
if (mouseOnDragHandle()) {
|
||||||
|
dragOriginX = relativeMouseX
|
||||||
|
dragOriginY = relativeMouseY
|
||||||
|
dragForReal = true
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dragForReal = false
|
||||||
|
}
|
||||||
|
|
||||||
|
closeReady = closeButton.mouseUp
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
return super.touchUp(screenX, screenY, pointer, button)
|
if (closeReady && closeButton.mouseUp) {
|
||||||
|
closeButton.deselect()
|
||||||
|
this.isVisible = false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doOpening(delta: Float) {
|
override fun doOpening(delta: Float) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.torvald.terrarum.blendNormal
|
|||||||
import net.torvald.terrarum.blockproperties.Block
|
import net.torvald.terrarum.blockproperties.Block
|
||||||
import net.torvald.terrarum.fillRect
|
import net.torvald.terrarum.fillRect
|
||||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||||
|
import net.torvald.terrarum.modulebasegame.BuildingMaker
|
||||||
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
|
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
|
||||||
import net.torvald.terrarum.ui.UICanvas
|
import net.torvald.terrarum.ui.UICanvas
|
||||||
import net.torvald.terrarum.ui.UINSMenu
|
import net.torvald.terrarum.ui.UINSMenu
|
||||||
@@ -17,7 +18,7 @@ import net.torvald.terrarum.ui.UINSMenu
|
|||||||
/**
|
/**
|
||||||
* Created by minjaesong on 2019-02-03.
|
* Created by minjaesong on 2019-02-03.
|
||||||
*/
|
*/
|
||||||
class UIPaletteSelector : UICanvas() {
|
class UIPaletteSelector(val parent: BuildingMaker) : UICanvas() {
|
||||||
|
|
||||||
override var width = 36
|
override var width = 36
|
||||||
override var height = 72
|
override var height = 72
|
||||||
@@ -154,6 +155,11 @@ class UIPaletteSelector : UICanvas() {
|
|||||||
swapForeAndBack()
|
swapForeAndBack()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if either of the block is down, open palette window of the parent
|
||||||
|
if ((relativeMouseX in 14..30 && relativeMouseY in 41..57) || (relativeMouseX in 6..22 && relativeMouseY in 33..49)) {
|
||||||
|
parent.uiPalette.isVisible = true
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ class UIItemTextButtonList(
|
|||||||
selectedIndex = index
|
selectedIndex = index
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unselect() {
|
fun deselect() {
|
||||||
selectedIndex = null
|
selectedIndex = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user