camera clamping, UI resize

This commit is contained in:
minjaesong
2017-07-15 02:02:30 +09:00
parent dfa2a0a86d
commit 1f0608b768
7 changed files with 83 additions and 39 deletions

View File

@@ -1553,6 +1553,28 @@ class Ingame(val batch: SpriteBatch) : Screen {
if (gameFullyLoaded) {
LightmapRenderer.fireRecalculateEvent()
}
if (postInitDone) {
// resize UIs
notifier.setPosition(
(Terrarum.WIDTH - notifier.UI.width) / 2, Terrarum.HEIGHT - notifier.UI.height)
// inventory
uiInventoryPlayer.UI =
UIInventory(player,
width = 840,
height = Terrarum.HEIGHT - 160,
categoryWidth = 210
)
uiInventoryPlayer.UI.handler = uiInventoryPlayer
// basic watch-style notification bar (temperature, new mail)
uiWatchBasic.setPosition(Terrarum.WIDTH - uiWatchBasic.UI.width, 0)
uiWatchTierOne.setPosition(Terrarum.WIDTH - uiWatchTierOne.UI.width, uiWatchBasic.UI.height - 2)
}
}
override fun dispose() {

View File

@@ -652,7 +652,6 @@ infix fun Color.mul(other: Color): Color = this.cpy().mul(other)
fun blendMul() {
// I must say: What the fuck is wrong with you, Slick2D? Your built-it blending is just fucking wrong.
Terrarum.batch.enableBlending()
Terrarum.batch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ONE_MINUS_SRC_ALPHA)
Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation

View File

@@ -14,11 +14,11 @@ import net.torvald.terrarum.gamecontroller.KeyToggler
*
* Created by minjaesong on 15-12-31.
*/
class UIHandler(val UI: UICanvas,
val toggleKey: Int? = null, val toggleButton: Int? = null,
class UIHandler(var UI: UICanvas,
var toggleKey: Int? = null, var toggleButton: Int? = null,
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
var customPositioning: Boolean = false, // mainly used by vital meter
val doNotWarnConstant: Boolean = false
var doNotWarnConstant: Boolean = false
) {
// X/Y Position relative to the game window.
@@ -65,7 +65,7 @@ class UIHandler(val UI: UICanvas,
fun update(delta: Float) {
// open/close UI by key pressed
if (toggleKey != null) {
if (KeyToggler.isOn(toggleKey)) {
if (KeyToggler.isOn(toggleKey!!)) {
setAsOpen()
}
else {
@@ -219,7 +219,7 @@ class UIHandler(val UI: UICanvas,
fun keyDown(keycode: Int): Boolean {
if (isVisible && UI is KeyControlled) {
return UI.keyDown(keycode)
return (UI as KeyControlled).keyDown(keycode)
}
return false
@@ -227,7 +227,7 @@ class UIHandler(val UI: UICanvas,
fun keyUp(keycode: Int): Boolean {
if (isVisible && UI is KeyControlled) {
return UI.keyUp(keycode)
return (UI as KeyControlled).keyUp(keycode)
}
return false
@@ -235,7 +235,7 @@ class UIHandler(val UI: UICanvas,
fun keyTyped(char: Char): Boolean {
if (isVisible && UI is KeyControlled) {
return UI.keyTyped(char)
return (UI as KeyControlled).keyTyped(char)
}
return false
@@ -243,13 +243,13 @@ class UIHandler(val UI: UICanvas,
fun mouseMoved(screenX: Int, screenY: Int) {
if (isVisible && UI is MouseControlled) {
UI.mouseMoved(screenX, screenY)
(UI as MouseControlled).mouseMoved(screenX, screenY)
}
}
fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
if (isVisible && UI is MouseControlled) {
UI.touchDragged(screenX, screenY, pointer)
(UI as MouseControlled).touchDragged(screenX, screenY, pointer)
}
return false
@@ -257,7 +257,7 @@ class UIHandler(val UI: UICanvas,
fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (isVisible && UI is MouseControlled) {
UI.touchDown(screenX, screenY, pointer, button)
(UI as MouseControlled).touchDown(screenX, screenY, pointer, button)
}
return false
@@ -265,7 +265,7 @@ class UIHandler(val UI: UICanvas,
fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (isVisible && UI is MouseControlled) {
UI.touchUp(screenX, screenY, pointer, button)
(UI as MouseControlled).touchUp(screenX, screenY, pointer, button)
}
return false
@@ -273,7 +273,7 @@ class UIHandler(val UI: UICanvas,
fun scrolled(amount: Int): Boolean {
if (isVisible && UI is MouseControlled) {
UI.scrolled(amount)
(UI as MouseControlled).scrolled(amount)
}
return false

View File

@@ -135,6 +135,10 @@ class UIInventory(
private var isEncumbered = false
override fun update(delta: Float) {
if (handler == null) {
throw Error("Handler for this UI is null, you douchebag.")
}
catButtons.update(delta)
if (actor != null && inventory != null) {

View File

@@ -383,8 +383,9 @@ object BlocksDrawer {
private val tileDrawLightThreshold = 2f / LightmapRenderer.MUL
private fun canIHazRender(mode: Int, x: Int, y: Int) =
(world.getTileFrom(mode, x, y) != 0) && // not an air tile
// for WALLs:
(world.getTileFrom(mode, x, y) != 0) // not an air tile
&&
// for WALLs; else: ret true
if (mode == WALL) { // DRAW WHEN it is visible and 'is a lip'
( BlockCodex[world.getTileFromTerrain(x, y) ?: 0].isClear ||
!
@@ -399,6 +400,18 @@ object BlocksDrawer {
// end
private fun hasLightNearby(x: Int, y: Int) = ( // check if light level of nearby or this tile is illuminated
LightmapRenderer.getHighestRGB(x, y) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x, y - 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x, y + 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y - 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y + 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y - 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y + 1) ?: 0f >= tileDrawLightThreshold
)
private fun drawTiles(batch: SpriteBatch, mode: Int, drawModeTilesBlendMul: Boolean, color: Color) {
val for_y_start = y / TILE_SIZE
val for_y_end = BlocksDrawer.clampHTile(for_y_start + (height / TILE_SIZE) + 2)
@@ -430,18 +443,17 @@ object BlocksDrawer {
// draw a tile, but only when illuminated
try {
if (canIHazRender(mode, x, y)) {
// check if light level of nearby or this tile is illuminated
if ( LightmapRenderer.getHighestRGB(x, y) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x, y - 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x, y + 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y - 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y + 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x + 1, y - 1) ?: 0f >= tileDrawLightThreshold ||
LightmapRenderer.getHighestRGB(x - 1, y + 1) ?: 0f >= tileDrawLightThreshold)
{
// FIXME bad scanlines bug
if (!hasLightNearby(x, y)) {
// draw black patch
zeroTileCounter += 1 // unused for now
// temporary solution; FIXME bad scanlines bug
batch.color = Color.BLACK
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, TILE_SIZEF, TILE_SIZEF)
}
else {
// commented out; FIXME bad scanlines bug
if (zeroTileCounter > 0) {
/*batch.color = Color.BLACK
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, -zeroTileCounter * TILE_SIZEF, TILE_SIZEF)
@@ -504,12 +516,6 @@ object BlocksDrawer {
} // end if (is illuminated)
// draw black patch
else {
zeroTileCounter += 1 // unused for now
batch.color = Color.BLACK
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, TILE_SIZEF, TILE_SIZEF)
}
} // end if (not an air)
} catch (e: NullPointerException) {
// do nothing. WARNING: This exception handling may hide erratic behaviour completely.

View File

@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.blockproperties.BlockCodex
import com.jme3.math.FastMath
import net.torvald.dataclass.Float16
import net.torvald.terrarum.Ingame
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameworld.GameWorld
@@ -40,6 +41,8 @@ object LightmapRenderer {
val LIGHTMAP_HEIGHT = Terrarum.ingame!!.ZOOM_MINIMUM.inv().times(Terrarum.HEIGHT)
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
//data class Lux(var r: Float16, var g: Float16, var b: Float16, var uv: Float16)
/**
* Float value, 1.0 for 1023
*/

View File

@@ -15,13 +15,13 @@ object WorldCamera {
private val world: GameWorld? = Terrarum.ingame?.world
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
var x: Int = 0
var x: Int = 0 // left position
private set
var y: Int = 0
var y: Int = 0 // top position
private set
var gdxCamX: Float = 0f
var gdxCamX: Float = 0f // centre position
private set
var gdxCamY: Float = 0f
var gdxCamY: Float = 0f // centre position
private set
var width: Int = 0
private set
@@ -47,11 +47,21 @@ object WorldCamera {
(player?.hitbox?.centeredY?.toFloat() ?: 0f) - height / 2,
TILE_SIZE.toFloat(),
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
)).floorInt()
)).floorInt().clampCameraY()
gdxCamX = x + (width / 2f).floor()
gdxCamY = y + (height / 2f).floor()
}
}
}
private fun Int.clampCameraY(): Int {
return if (this < 0)
0
else if (this > (world?.height ?: Terrarum.HEIGHT).times(TILE_SIZE) - Terrarum.HEIGHT)
(world?.height ?: Terrarum.HEIGHT).times(TILE_SIZE) - Terrarum.HEIGHT
else
this
}
}