mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-06 08:38:30 +09:00
camera clamping, UI resize
This commit is contained in:
@@ -1553,6 +1553,28 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
|||||||
if (gameFullyLoaded) {
|
if (gameFullyLoaded) {
|
||||||
LightmapRenderer.fireRecalculateEvent()
|
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() {
|
override fun dispose() {
|
||||||
|
|||||||
@@ -652,7 +652,6 @@ infix fun Color.mul(other: Color): Color = this.cpy().mul(other)
|
|||||||
|
|
||||||
|
|
||||||
fun blendMul() {
|
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.enableBlending()
|
||||||
Terrarum.batch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
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
|
Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ import net.torvald.terrarum.gamecontroller.KeyToggler
|
|||||||
*
|
*
|
||||||
* Created by minjaesong on 15-12-31.
|
* Created by minjaesong on 15-12-31.
|
||||||
*/
|
*/
|
||||||
class UIHandler(val UI: UICanvas,
|
class UIHandler(var UI: UICanvas,
|
||||||
val toggleKey: Int? = null, val toggleButton: Int? = null,
|
var toggleKey: Int? = null, var toggleButton: Int? = null,
|
||||||
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
|
||||||
var customPositioning: Boolean = false, // mainly used by vital meter
|
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.
|
// X/Y Position relative to the game window.
|
||||||
@@ -65,7 +65,7 @@ class UIHandler(val UI: UICanvas,
|
|||||||
fun update(delta: Float) {
|
fun update(delta: Float) {
|
||||||
// open/close UI by key pressed
|
// open/close UI by key pressed
|
||||||
if (toggleKey != null) {
|
if (toggleKey != null) {
|
||||||
if (KeyToggler.isOn(toggleKey)) {
|
if (KeyToggler.isOn(toggleKey!!)) {
|
||||||
setAsOpen()
|
setAsOpen()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -219,7 +219,7 @@ class UIHandler(val UI: UICanvas,
|
|||||||
|
|
||||||
fun keyDown(keycode: Int): Boolean {
|
fun keyDown(keycode: Int): Boolean {
|
||||||
if (isVisible && UI is KeyControlled) {
|
if (isVisible && UI is KeyControlled) {
|
||||||
return UI.keyDown(keycode)
|
return (UI as KeyControlled).keyDown(keycode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@@ -227,7 +227,7 @@ class UIHandler(val UI: UICanvas,
|
|||||||
|
|
||||||
fun keyUp(keycode: Int): Boolean {
|
fun keyUp(keycode: Int): Boolean {
|
||||||
if (isVisible && UI is KeyControlled) {
|
if (isVisible && UI is KeyControlled) {
|
||||||
return UI.keyUp(keycode)
|
return (UI as KeyControlled).keyUp(keycode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@@ -235,7 +235,7 @@ class UIHandler(val UI: UICanvas,
|
|||||||
|
|
||||||
fun keyTyped(char: Char): Boolean {
|
fun keyTyped(char: Char): Boolean {
|
||||||
if (isVisible && UI is KeyControlled) {
|
if (isVisible && UI is KeyControlled) {
|
||||||
return UI.keyTyped(char)
|
return (UI as KeyControlled).keyTyped(char)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@@ -243,13 +243,13 @@ class UIHandler(val UI: UICanvas,
|
|||||||
|
|
||||||
fun mouseMoved(screenX: Int, screenY: Int) {
|
fun mouseMoved(screenX: Int, screenY: Int) {
|
||||||
if (isVisible && UI is MouseControlled) {
|
if (isVisible && UI is MouseControlled) {
|
||||||
UI.mouseMoved(screenX, screenY)
|
(UI as MouseControlled).mouseMoved(screenX, screenY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||||
if (isVisible && UI is MouseControlled) {
|
if (isVisible && UI is MouseControlled) {
|
||||||
UI.touchDragged(screenX, screenY, pointer)
|
(UI as MouseControlled).touchDragged(screenX, screenY, pointer)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@@ -257,7 +257,7 @@ class UIHandler(val UI: UICanvas,
|
|||||||
|
|
||||||
fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
if (isVisible && UI is MouseControlled) {
|
if (isVisible && UI is MouseControlled) {
|
||||||
UI.touchDown(screenX, screenY, pointer, button)
|
(UI as MouseControlled).touchDown(screenX, screenY, pointer, button)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@@ -265,7 +265,7 @@ class UIHandler(val UI: UICanvas,
|
|||||||
|
|
||||||
fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||||
if (isVisible && UI is MouseControlled) {
|
if (isVisible && UI is MouseControlled) {
|
||||||
UI.touchUp(screenX, screenY, pointer, button)
|
(UI as MouseControlled).touchUp(screenX, screenY, pointer, button)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@@ -273,7 +273,7 @@ class UIHandler(val UI: UICanvas,
|
|||||||
|
|
||||||
fun scrolled(amount: Int): Boolean {
|
fun scrolled(amount: Int): Boolean {
|
||||||
if (isVisible && UI is MouseControlled) {
|
if (isVisible && UI is MouseControlled) {
|
||||||
UI.scrolled(amount)
|
(UI as MouseControlled).scrolled(amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -135,6 +135,10 @@ class UIInventory(
|
|||||||
private var isEncumbered = false
|
private var isEncumbered = false
|
||||||
|
|
||||||
override fun update(delta: Float) {
|
override fun update(delta: Float) {
|
||||||
|
if (handler == null) {
|
||||||
|
throw Error("Handler for this UI is null, you douchebag.")
|
||||||
|
}
|
||||||
|
|
||||||
catButtons.update(delta)
|
catButtons.update(delta)
|
||||||
|
|
||||||
if (actor != null && inventory != null) {
|
if (actor != null && inventory != null) {
|
||||||
|
|||||||
@@ -383,8 +383,9 @@ object BlocksDrawer {
|
|||||||
private val tileDrawLightThreshold = 2f / LightmapRenderer.MUL
|
private val tileDrawLightThreshold = 2f / LightmapRenderer.MUL
|
||||||
|
|
||||||
private fun canIHazRender(mode: Int, x: Int, y: Int) =
|
private fun canIHazRender(mode: Int, x: Int, y: Int) =
|
||||||
(world.getTileFrom(mode, x, y) != 0) && // not an air tile
|
(world.getTileFrom(mode, x, y) != 0) // not an air tile
|
||||||
// for WALLs:
|
&&
|
||||||
|
// for WALLs; else: ret true
|
||||||
if (mode == WALL) { // DRAW WHEN it is visible and 'is a lip'
|
if (mode == WALL) { // DRAW WHEN it is visible and 'is a lip'
|
||||||
( BlockCodex[world.getTileFromTerrain(x, y) ?: 0].isClear ||
|
( BlockCodex[world.getTileFromTerrain(x, y) ?: 0].isClear ||
|
||||||
!
|
!
|
||||||
@@ -399,6 +400,18 @@ object BlocksDrawer {
|
|||||||
|
|
||||||
// end
|
// 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) {
|
private fun drawTiles(batch: SpriteBatch, mode: Int, drawModeTilesBlendMul: Boolean, color: Color) {
|
||||||
val for_y_start = y / TILE_SIZE
|
val for_y_start = y / TILE_SIZE
|
||||||
val for_y_end = BlocksDrawer.clampHTile(for_y_start + (height / TILE_SIZE) + 2)
|
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
|
// draw a tile, but only when illuminated
|
||||||
try {
|
try {
|
||||||
if (canIHazRender(mode, x, y)) {
|
if (canIHazRender(mode, x, y)) {
|
||||||
// check if light level of nearby or this tile is illuminated
|
|
||||||
if ( LightmapRenderer.getHighestRGB(x, y) ?: 0f >= tileDrawLightThreshold ||
|
if (!hasLightNearby(x, y)) {
|
||||||
LightmapRenderer.getHighestRGB(x - 1, y) ?: 0f >= tileDrawLightThreshold ||
|
// draw black patch
|
||||||
LightmapRenderer.getHighestRGB(x + 1, y) ?: 0f >= tileDrawLightThreshold ||
|
zeroTileCounter += 1 // unused for now
|
||||||
LightmapRenderer.getHighestRGB(x, y - 1) ?: 0f >= tileDrawLightThreshold ||
|
|
||||||
LightmapRenderer.getHighestRGB(x, y + 1) ?: 0f >= tileDrawLightThreshold ||
|
// temporary solution; FIXME bad scanlines bug
|
||||||
LightmapRenderer.getHighestRGB(x - 1, y - 1) ?: 0f >= tileDrawLightThreshold ||
|
batch.color = Color.BLACK
|
||||||
LightmapRenderer.getHighestRGB(x + 1, y + 1) ?: 0f >= tileDrawLightThreshold ||
|
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, TILE_SIZEF, TILE_SIZEF)
|
||||||
LightmapRenderer.getHighestRGB(x + 1, y - 1) ?: 0f >= tileDrawLightThreshold ||
|
}
|
||||||
LightmapRenderer.getHighestRGB(x - 1, y + 1) ?: 0f >= tileDrawLightThreshold)
|
else {
|
||||||
{
|
// commented out; FIXME bad scanlines bug
|
||||||
// FIXME bad scanlines bug
|
|
||||||
if (zeroTileCounter > 0) {
|
if (zeroTileCounter > 0) {
|
||||||
/*batch.color = Color.BLACK
|
/*batch.color = Color.BLACK
|
||||||
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, -zeroTileCounter * TILE_SIZEF, TILE_SIZEF)
|
batch.fillRect(x * TILE_SIZEF, y * TILE_SIZEF, -zeroTileCounter * TILE_SIZEF, TILE_SIZEF)
|
||||||
@@ -504,12 +516,6 @@ object BlocksDrawer {
|
|||||||
|
|
||||||
|
|
||||||
} // end if (is illuminated)
|
} // 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)
|
} // end if (not an air)
|
||||||
} catch (e: NullPointerException) {
|
} catch (e: NullPointerException) {
|
||||||
// do nothing. WARNING: This exception handling may hide erratic behaviour completely.
|
// do nothing. WARNING: This exception handling may hide erratic behaviour completely.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||||
import com.jme3.math.FastMath
|
import com.jme3.math.FastMath
|
||||||
|
import net.torvald.dataclass.Float16
|
||||||
import net.torvald.terrarum.Ingame
|
import net.torvald.terrarum.Ingame
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.gameworld.GameWorld
|
import net.torvald.terrarum.gameworld.GameWorld
|
||||||
@@ -40,6 +41,8 @@ object LightmapRenderer {
|
|||||||
val LIGHTMAP_HEIGHT = Terrarum.ingame!!.ZOOM_MINIMUM.inv().times(Terrarum.HEIGHT)
|
val LIGHTMAP_HEIGHT = Terrarum.ingame!!.ZOOM_MINIMUM.inv().times(Terrarum.HEIGHT)
|
||||||
.div(FeaturesDrawer.TILE_SIZE).ceil() + overscan_open * 2 + 3
|
.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
|
* Float value, 1.0 for 1023
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ object WorldCamera {
|
|||||||
private val world: GameWorld? = Terrarum.ingame?.world
|
private val world: GameWorld? = Terrarum.ingame?.world
|
||||||
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
|
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
|
||||||
|
|
||||||
var x: Int = 0
|
var x: Int = 0 // left position
|
||||||
private set
|
private set
|
||||||
var y: Int = 0
|
var y: Int = 0 // top position
|
||||||
private set
|
private set
|
||||||
var gdxCamX: Float = 0f
|
var gdxCamX: Float = 0f // centre position
|
||||||
private set
|
private set
|
||||||
var gdxCamY: Float = 0f
|
var gdxCamY: Float = 0f // centre position
|
||||||
private set
|
private set
|
||||||
var width: Int = 0
|
var width: Int = 0
|
||||||
private set
|
private set
|
||||||
@@ -47,11 +47,21 @@ object WorldCamera {
|
|||||||
(player?.hitbox?.centeredY?.toFloat() ?: 0f) - height / 2,
|
(player?.hitbox?.centeredY?.toFloat() ?: 0f) - height / 2,
|
||||||
TILE_SIZE.toFloat(),
|
TILE_SIZE.toFloat(),
|
||||||
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
world!!.height * TILE_SIZE - height - TILE_SIZE.toFloat()
|
||||||
)).floorInt()
|
)).floorInt().clampCameraY()
|
||||||
|
|
||||||
|
|
||||||
gdxCamX = x + (width / 2f).floor()
|
gdxCamX = x + (width / 2f).floor()
|
||||||
gdxCamY = y + (height / 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user