fixing list UI's colours; buildingmaker palette wip

This commit is contained in:
minjaesong
2019-02-14 15:55:31 +09:00
parent 72dbc18128
commit fcf9aa1b79
14 changed files with 229 additions and 64 deletions

View File

@@ -329,19 +329,32 @@ public class AppLoader implements ApplicationListener {
try {
gamepad = new XinputControllerAdapter(XInputDevice.getDeviceFor(0));
}
catch (Throwable e) { }
catch (Throwable e) {
gamepad = null;
}
// nullify if not actually connected
if (!((XinputControllerAdapter) gamepad).getC().isConnected()) {
gamepad = null;
}
}
if (gamepad == null) {
try {
gamepad = new GdxControllerAdapter(Controllers.getControllers().get(0));
}
catch (Throwable e) { }
catch (Throwable e) {
gamepad = null;
}
}
if (gamepad != null) {
environment = RunningEnvironment.CONSOLE;
}
else {
environment = RunningEnvironment.PC;
}
// make loading list

View File

@@ -54,6 +54,8 @@ class UIItemInventoryCatBar(
inventoryUI,
catIcons.get(catArrangement[index], 0),
activeBackCol = Color(0),
backgroundCol = Color(0),
highlightBackCol = Color(0),
activeBackBlendMode = BlendMode.NORMAL,
posX = posX + iconPosX,
posY = posY + iconPosY,
@@ -84,10 +86,12 @@ class UIItemInventoryCatBar(
inventoryUI,
catIcons.get(iconIndex[index], 0),
activeBackCol = Color(0),
backgroundCol = Color(0),
highlightBackCol = Color(0),
activeBackBlendMode = BlendMode.NORMAL,
posX = iconPosX,
posY = posY + iconPosY,
buttonCol = if (index == 0 || index == 3) Color.WHITE else Color(0xffffff7f.toInt()),
inactiveCol = if (index == 0 || index == 3) Color.WHITE else Color(0xffffff7f.toInt()),
activeCol = if (index == 0 || index == 3) Color(0xfff066_ff.toInt()) else Color(0xffffff7f.toInt()),
highlightable = (index == 0 || index == 3)
)

View File

@@ -11,7 +11,7 @@ import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
import net.torvald.terrarum.modulebasegame.ui.Notification
import net.torvald.terrarum.modulebasegame.ui.UIEditorPalette
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
@@ -82,7 +82,8 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
val uiToolbox = UINSMenu("Menu", 100, menuYaml)
val notifier = Notification()
val uiPalette = UIEditorPalette()
val uiPaletteSelector = UIPaletteSelector()
val uiPalette = UIBuildingMakerBlockChooser(this)
val uiContainer = ArrayList<UICanvas>()
@@ -146,8 +147,9 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
actorsRenderOverlay.add(blockPointingCursor)
uiContainer.add(uiToolbox)
uiContainer.add(uiPalette)
uiContainer.add(uiPaletteSelector)
uiContainer.add(notifier)
uiContainer.add(uiPalette)
@@ -155,8 +157,8 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
uiToolbox.isVisible = true
uiToolbox.invocationArgument = arrayOf(this)
uiPalette.setPosition(Terrarum.WIDTH - uiPalette.width, 0)
uiPalette.isVisible = true
uiPaletteSelector.setPosition(Terrarum.WIDTH - uiPaletteSelector.width, 0)
uiPaletteSelector.isVisible = true
notifier.setPosition(
(Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height)
@@ -165,6 +167,9 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
actorNowPlaying?.setPosition(512 * 16.0, 149 * 16.0)
uiPalette.setPosition(200, 100)
uiPalette.isVisible = true // TEST CODE should not be visible
LightmapRenderer.fireRecalculateEvent()
}
@@ -247,7 +252,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
private fun makePenWork(worldTileX: Int, worldTileY: Int) {
val world = gameWorld
val palSelection = uiPalette.fore
val palSelection = uiPaletteSelector.fore
when (currentPenMode) {
// test paint terrain layer

View File

@@ -774,7 +774,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
override fun addNewActor(actor: Actor?) {
if (actor == null) return
if (theGameHasActor(actor.referenceID!!)) {
if (AppLoader.IS_DEVELOPMENT_BUILD && theGameHasActor(actor.referenceID!!)) {
throw Error("The actor $actor already exists in the game")
}
else {
@@ -807,7 +807,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
}
fun activateDormantActor(actor: Actor) {
if (!isInactive(actor.referenceID!!)) {
if (AppLoader.IS_DEVELOPMENT_BUILD && !isInactive(actor.referenceID!!)) {
if (isActive(actor.referenceID!!))
throw Error("The actor $actor is already activated")
else

View File

@@ -89,7 +89,7 @@ object IngameRenderer {
this.player = player
LightmapRenderer.fireRecalculateEvent()
LightmapRenderer.fireRecalculateEvent(actorsRenderBehind, actorsRenderFront, actorsRenderMidTop, actorsRenderMiddle, actorsRenderOverlay)
prepLightmapRGBA()
BlocksDrawer.renderData()

View File

@@ -0,0 +1,115 @@
package net.torvald.terrarum.modulebasegame
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.BlendMode
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemImageButton
import net.torvald.terrarum.ui.UIItemTextButtonList
import net.torvald.terrarum.ui.UIItemTextButtonList.Companion.DEFAULT_BACKGROUNDCOL
/**
* Created by minjaesong on 2019-02-14.
*/
class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() {
companion object {
const val TILES_X = 16
const val TILES_Y = 14
const val TILESREGION_SIZE = 24
const val MENUBAR_SIZE = 80
const val SCROLLBAR_SIZE = 16
const val WIDTH = TILES_X*TILESREGION_SIZE + SCROLLBAR_SIZE + MENUBAR_SIZE
const val HEIGHT = TILES_Y*TILESREGION_SIZE
}
override var width = WIDTH
override var height = HEIGHT
override var openCloseTime = 0f
private val palette = Array<UIItemImageButton>(TILES_X * TILES_Y) {
// initialise with terrain blocks
UIItemImageButton(
this, ItemCodex.getItemImage(it),
posX = MENUBAR_SIZE + (it % 16) * TILESREGION_SIZE,
posY = (it / 16) * TILESREGION_SIZE,
highlightable = true,
width = TILESREGION_SIZE,
height = TILESREGION_SIZE,
highlightCol = Color.WHITE,
activeCol = Color.WHITE
)
}
private val tabs = UIItemTextButtonList(
this, arrayOf("Terrain", "Wall", "Wire", "Fixtures"),
0, 0, textAreaWidth = MENUBAR_SIZE, width = MENUBAR_SIZE,
defaultSelection = 0
)
private val closeButton = UIItemTextButtonList(
this, arrayOf("Close"),
0, this.height - UIItemTextButtonList.DEFAULT_LINE_HEIGHT,
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) {
palette.forEach { it.update(delta) }
tabs.update(delta)
closeButton.update(delta)
buttonGapClickDummy.update(delta)
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
palette.forEach { it.render(batch, camera) }
buttonGapClickDummy.render(batch, camera)
tabs.render(batch, camera)
closeButton.render(batch, camera)
}
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
return super.touchDragged(screenX, screenY, pointer)
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return super.touchDown(screenX, screenY, pointer, button)
}
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return super.touchUp(screenX, screenY, pointer, button)
}
override fun doOpening(delta: Float) {
}
override fun doClosing(delta: Float) {
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
}
override fun dispose() {
// nothing to dispose; you can't dispose the palette as its image is dynamically assigned
}
}

View File

@@ -14,6 +14,7 @@ import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BL
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK_ACTIVE
import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.ui.UIItemImageButton
import net.torvald.terrarum.ui.UIItemTextButton.Companion.defaultActiveCol
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import java.util.*
@@ -149,8 +150,11 @@ class UIItemInventoryDynamicList(
UIItemImageButton(
parentUI,
parentUI.catIcons.get(index + 14, 0),
backgroundCol = Color(0),
activeBackCol = Color(0),
highlightBackCol = Color(0),
activeBackBlendMode = BlendMode.NORMAL,
activeCol = defaultActiveCol,
posX = iconPosX,
posY = getIconPosY(index),
highlightable = true
@@ -160,8 +164,10 @@ class UIItemInventoryDynamicList(
private val scrollUpButton = UIItemImageButton(
parentUI,
parentUI.catIcons.get(18, 0),
backgroundCol = Color(0),
activeBackCol = Color(0),
activeBackBlendMode = BlendMode.NORMAL,
activeCol = defaultActiveCol,
posX = iconPosX,
posY = getIconPosY(2),
highlightable = false
@@ -170,8 +176,10 @@ class UIItemInventoryDynamicList(
private val scrollDownButton = UIItemImageButton(
parentUI,
parentUI.catIcons.get(19, 0),
backgroundCol = Color(0),
activeBackCol = Color(0),
activeBackBlendMode = BlendMode.NORMAL,
activeCol = defaultActiveCol,
posX = iconPosX,
posY = getIconPosY(3),
highlightable = false

View File

@@ -17,7 +17,7 @@ import net.torvald.terrarum.ui.UINSMenu
/**
* Created by minjaesong on 2019-02-03.
*/
class UIEditorPalette : UICanvas() {
class UIPaletteSelector : UICanvas() {
override var width = 36
override var height = 72

View File

@@ -15,17 +15,15 @@ open class UIItemImageButton(
parent: UICanvas,
val image: TextureRegion,
val buttonCol: Color = Color.WHITE,
val buttonBackCol: Color = Color(0),
val buttonBackBlendMode: String = BlendMode.NORMAL,
val activeCol: Color = Color(0xfff066_ff.toInt()),
val activeBackCol: Color = Color(0xb0b0b0_ff.toInt()),
val activeBackBlendMode: String = BlendMode.MULTIPLY,
val highlightCol: Color = Color(0x00f8ff_ff),
val highlightBackCol: Color = Color(0xb0b0b0_ff.toInt()),
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
val activeCol: Color = UIItemTextButton.defaultActiveCol,
val activeBackCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUND_ACTIVECOL,
val activeBackBlendMode: String = BlendMode.NORMAL,
val highlightCol: Color = UIItemTextButton.defaultHighlightCol,
val highlightBackCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUND_HIGHLIGHTCOL,
val highlightBackBlendMode: String = BlendMode.NORMAL,
val inactiveCol: Color = UIItemTextButton.defaultInactiveCol,
val backgroundCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL,
val backgroundBlendMode: String = BlendMode.NORMAL,
override var posX: Int,
override var posY: Int,
@@ -43,24 +41,29 @@ open class UIItemImageButton(
override fun render(batch: SpriteBatch, camera: Camera) {
// draw background
if (mouseUp) {
if (highlighted) {
BlendMode.resolve(highlightBackBlendMode, batch)
batch.color = highlightBackCol
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
}
else if (mouseUp) {
BlendMode.resolve(activeBackBlendMode, batch)
batch.color = activeBackCol
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
}
else {
BlendMode.resolve(buttonBackBlendMode, batch)
batch.color = buttonBackCol
batch.color = backgroundCol
BlendMode.resolve(backgroundBlendMode, batch)
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
}
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
// draw image
blendNormal(batch)
batch.color = if (highlighted) highlightCol
else if (mouseUp) activeCol
else buttonCol
else inactiveCol
batch.draw(image, (posX + (width - image.regionWidth) / 2).toFloat(), (posY + (height - image.regionHeight) / 2).toFloat())
}

View File

@@ -2,7 +2,6 @@ package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.GlyphLayout
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.BlendMode
import net.torvald.terrarum.Terrarum
@@ -23,13 +22,17 @@ open class UIItemTextButton(
override var posY: Int,
override val width: Int,
val readFromLang: Boolean = false,
val activeCol: Color = Color.WHITE,
val activeBackCol: Color = Color(0),
val activeCol: Color = defaultActiveCol,
val activeBackCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUND_ACTIVECOL,
val activeBackBlendMode: String = BlendMode.NORMAL,
val highlightCol: Color = defaultHighlightCol,
val highlightBackCol: Color = Color(0xb0b0b0_ff.toInt()),
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
val inactiveCol: Color = defaultInactiveCol,
val highlightCol: Color = UIItemTextButton.defaultHighlightCol,
val highlightBackCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUND_HIGHLIGHTCOL,
val highlightBackBlendMode: String = BlendMode.NORMAL,
val inactiveCol: Color = UIItemTextButton.defaultInactiveCol,
val backgroundCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL,
val backgroundBlendMode: String = BlendMode.NORMAL,
val preGapX: Int = 0,
val postGapX: Int = 0,
@@ -44,8 +47,9 @@ open class UIItemTextButton(
companion object {
val font = Terrarum.fontGame
val height = font.lineHeight.toInt()
val defaultInactiveCol: Color = Color(0xc8c8c8_ff.toInt())
val defaultHighlightCol: Color = Color(0x00f8ff_ff)
val defaultInactiveCol = Color.WHITE
val defaultHighlightCol = Color(0x00f8ff_ff)
val defaultActiveCol = Color(0xfff066_ff.toInt())
enum class Alignment {
CENTRE, LEFT, RIGHT
@@ -61,13 +65,11 @@ open class UIItemTextButton(
var highlighted: Boolean = false
private val glyphLayout = GlyphLayout()
override fun render(batch: SpriteBatch, camera: Camera) {
val textW = font.getWidth(label)
// draw background
if (highlighted) {
BlendMode.resolve(highlightBackBlendMode, batch)
batch.color = highlightBackCol
@@ -78,6 +80,12 @@ open class UIItemTextButton(
batch.color = activeBackCol
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
}
else {
batch.color = backgroundCol
BlendMode.resolve(backgroundBlendMode, batch)
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
}
blendNormal(batch)

View File

@@ -8,6 +8,7 @@ import net.torvald.terrarum.Second
import net.torvald.terrarum.fillRect
import net.torvald.terrarum.gameactors.ai.toInt
import net.torvald.terrarum.roundInt
import net.torvald.terrarum.ui.UIItemTextButton.Companion.defaultActiveCol
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
/**
@@ -30,23 +31,26 @@ class UIItemTextButtonList(
val iconCol: Color = UIItemTextButton.defaultInactiveCol,
// copied directly from UIItemTextButton
val activeCol: Color = Color(0xfff066_ff.toInt()),
val activeBackCol: Color = Color(0),
val activeCol: Color = defaultActiveCol,
val activeBackCol: Color = DEFAULT_BACKGROUND_ACTIVECOL,
val activeBackBlendMode: String = BlendMode.NORMAL,
val highlightCol: Color = Color(0x00f8ff_ff),
val highlightBackCol: Color = Color(0xb0b0b0_ff.toInt()),
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
val inactiveCol: Color = Color(0xc0c0c0_ff.toInt()),
val highlightCol: Color = UIItemTextButton.defaultHighlightCol,
val highlightBackCol: Color = DEFAULT_BACKGROUND_HIGHLIGHTCOL,
val highlightBackBlendMode: String = BlendMode.NORMAL,
val inactiveCol: Color = UIItemTextButton.defaultInactiveCol,
val backgroundCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL,
val backgroundBlendMode: String = BlendMode.NORMAL,
val kinematic: Boolean = false,
val alignment: UIItemTextButton.Companion.Alignment = UIItemTextButton.Companion.Alignment.CENTRE,
val itemHitboxSize: Int = UIItemTextButton.height
val itemHitboxSize: Int = DEFAULT_LINE_HEIGHT
) : UIItem(parentUI) {
companion object {
val DEFAULT_BACKGROUNDCOL = Color(0x242424_80)
val DEFAULT_BACKGROUND_HIGHLIGHTCOL = Color(0x121212BF)
val DEFAULT_BACKGROUND_ACTIVECOL = Color(0x1b1b1b9F)
val DEFAULT_LINE_HEIGHT = 36
}
@@ -87,6 +91,8 @@ class UIItemTextButtonList(
highlightBackCol = highlightBackCol,
highlightBackBlendMode = highlightBackBlendMode,
inactiveCol = inactiveCol,
backgroundCol = backgroundCol,
backgroundBlendMode = backgroundBlendMode,
preGapX = pregap,
postGapX = postgap,
alignment = alignment,
@@ -106,6 +112,7 @@ class UIItemTextButtonList(
highlightCol = highlightCol,
highlightBackCol = activeBackCol, // we are using custom highlighter
highlightBackBlendMode = activeBackBlendMode, // we are using custom highlighter
backgroundCol = Color(0),
inactiveCol = inactiveCol,
preGapX = pregap,
postGapX = postgap,
@@ -203,14 +210,16 @@ class UIItemTextButtonList(
override fun render(batch: SpriteBatch, camera: Camera) {
batch.color = backgroundCol
BlendMode.resolve(backgroundBlendMode, batch)
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
if (kinematic) {
batch.color = backgroundCol
BlendMode.resolve(backgroundBlendMode, batch)
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
batch.color = highlightBackCol
BlendMode.resolve(highlightBackBlendMode, batch)
if (highlightY != null) {
batch.fillRect(posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), itemHitboxSize.toFloat())
batch.color = highlightBackCol
BlendMode.resolve(highlightBackBlendMode, batch)
if (highlightY != null) {
batch.fillRect(posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), itemHitboxSize.toFloat())
}
}
buttons.forEach { it.render(batch, camera) }

View File

@@ -104,7 +104,6 @@ class UINSMenu(
uiWidth, listHeight,
textAreaWidth = listWidth,
alignment = UIItemTextButton.Companion.Alignment.LEFT,
activeBackCol = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL,//Color(1f,0f,.75f,1f),
inactiveCol = Color(.94f,.94f,.94f,1f),
itemHitboxSize = LINE_HEIGHT

View File

@@ -13,6 +13,7 @@ import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.Fluid
import net.torvald.terrarum.concurrent.ParallelUtils.sliceEvenly
import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameworld.BlockAddress
import net.torvald.terrarum.gameworld.GameWorld
@@ -230,7 +231,7 @@ object LightmapRenderer {
}
}
internal fun fireRecalculateEvent() {
internal fun fireRecalculateEvent(vararg actorContainers: List<ActorWithBody>?) {
try {
world.getTileFromTerrain(0, 0) // test inquiry
}
@@ -256,7 +257,7 @@ object LightmapRenderer {
//println("$for_x_start..$for_x_end, $for_x\t$for_y_start..$for_y_end, $for_y")
AppLoader.measureDebugTime("Renderer.Lanterns") {
buildLanternmap()
buildLanternmap(actorContainers)
} // usually takes 3000 ns
if (!SHADER_LIGHTING) {
@@ -443,10 +444,10 @@ object LightmapRenderer {
internal data class ThreadedLightmapUpdateMessage(val x: Int, val y: Int)
private fun buildLanternmap() {
private fun buildLanternmap(actorContainers: Array<out List<ActorWithBody>?>) {
lanternMap.clear()
Terrarum.ingame?.let {
it.actorContainer.forEach { it ->
actorContainers.forEach { actorContainer ->
actorContainer?.forEach {
if (it is Luminous && it is ActorWBMovable) {
// put lanterns to the area the luminantBox is occupying
for (lightBox in it.lightBoxList) {

Binary file not shown.