mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
dithered skybox
This commit is contained in:
@@ -3,25 +3,29 @@ varying vec2 v_texCoords;
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
|
||||
// "steps" of R, G and B. Must be integer && equal or greater than 2
|
||||
uniform float rcount = 4.0;
|
||||
uniform float gcount = 4.0;
|
||||
uniform float bcount = 4.0;
|
||||
uniform float acount = 1.0;
|
||||
|
||||
|
||||
//uniform mat4 bayer;
|
||||
uniform float monitorGamma; // give 2.2f
|
||||
|
||||
int bayer[8][8] = {
|
||||
{ 0, 32, 8, 40, 2, 34, 10, 42}, // 8x8 bayer ordered dithering
|
||||
{48, 16, 56, 24, 50, 18, 58, 26}, // pattern. Each input pixel
|
||||
{12, 44, 4, 36, 14, 46, 6, 38}, // is scaled to the 0..63 range
|
||||
{60, 28, 52, 20, 62, 30, 54, 22}, // before looking in this table
|
||||
{ 3, 35, 11, 43, 1, 33, 9, 41}, // to determine the action
|
||||
{51, 19, 59, 27, 49, 17, 57, 25},
|
||||
{15, 47, 7, 39, 13, 45, 5, 37},
|
||||
{63, 31, 55, 23, 61, 29, 53, 21} }; // fun fact: you can calculate bayer value on-the-fly but LUT is faster
|
||||
{ 0,32, 8,40, 2,34,10,42}, // 8x8 bayer ordered dithering
|
||||
{48,16,56,24,50,18,58,26}, // pattern. Each input pixel
|
||||
{12,44, 4,36,14,46, 6,38}, // is scaled to the 0..63 range
|
||||
{60,28,52,20,62,30,54,22}, // before looking in this table
|
||||
{ 3,35,11,43, 1,33, 9,41}, // to determine the action
|
||||
{51,19,59,27,49,17,57,25},
|
||||
{15,47, 7,39,13,45, 5,37},
|
||||
{63,31,55,23,61,29,53,21} }; // fun fact: you can calculate bayer value on-the-fly but LUT is faster
|
||||
float bayerSize = 8.0;
|
||||
float bayerDivider = bayerSize * bayerSize;
|
||||
|
||||
|
||||
vec4 nearestColour(vec4 incolor) {
|
||||
vec4 rgbaCounts = vec4(16.0, 16.0, 16.0, 1.0);
|
||||
vec4 rgbaCounts = vec4(rcount, gcount, bcount, acount);
|
||||
|
||||
|
||||
vec4 color = incolor;
|
||||
@@ -33,9 +37,6 @@ vec4 nearestColour(vec4 incolor) {
|
||||
if (rgbaCounts.a >= 2.0) {
|
||||
color.a = floor((rgbaCounts.a - 1.0) * color.a + 0.5) / (rgbaCounts.a - 1.0);
|
||||
}
|
||||
else if (rgbaCounts.a == 1.0) {
|
||||
color.a = (color.a >= 0.5f) ? 1.0 : 0.0;
|
||||
}
|
||||
else {
|
||||
color.a = 1.0;
|
||||
}
|
||||
@@ -44,13 +45,14 @@ vec4 nearestColour(vec4 incolor) {
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
float spread = 1.0 / (0.299 * (rcount - 1.0) + 0.587 * (gcount - 1.0) + 0.114 * (bcount - 1.0)); // this spread value is optimised one -- try your own values for various effects!
|
||||
|
||||
|
||||
// create texture coordinates based on pixelSize //
|
||||
vec4 inColor = texture2D(u_texture, v_texCoords);
|
||||
|
||||
vec2 entry = mod(gl_FragCoord.xy, vec2(bayerSize, bayerSize));
|
||||
|
||||
float r = 1.0 / monitorGamma;
|
||||
|
||||
gl_FragColor = nearestColour(inColor + r * (bayer[int(entry.y)][int(entry.x)] / bayerDivider - 0.5));
|
||||
gl_FragColor = nearestColour(inColor + spread * (bayer[int(entry.y)][int(entry.x)] / bayerDivider - 0.5));
|
||||
//gl_FragColor = nearestColour(inColor);
|
||||
}
|
||||
58
assets/4096_bayer_skyboxfill.frag
Normal file
58
assets/4096_bayer_skyboxfill.frag
Normal file
@@ -0,0 +1,58 @@
|
||||
varying vec4 v_color;
|
||||
varying vec2 v_texCoords;
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
|
||||
uniform vec3 topColor;
|
||||
uniform vec3 bottomColor;
|
||||
uniform float screenHeight;
|
||||
|
||||
|
||||
// "steps" of R, G and B. Must be integer && equal or greater than 2
|
||||
uniform float rcount = 256.0; // it even works on 256.0!
|
||||
uniform float gcount = 256.0;
|
||||
uniform float bcount = 256.0;
|
||||
|
||||
|
||||
|
||||
int bayer[8][8] = {
|
||||
{ 0,32, 8,40, 2,34,10,42}, // 8x8 bayer ordered dithering
|
||||
{48,16,56,24,50,18,58,26}, // pattern. Each input pixel
|
||||
{12,44, 4,36,14,46, 6,38}, // is scaled to the 0..63 range
|
||||
{60,28,52,20,62,30,54,22}, // before looking in this table
|
||||
{ 3,35,11,43, 1,33, 9,41}, // to determine the action
|
||||
{51,19,59,27,49,17,57,25},
|
||||
{15,47, 7,39,13,45, 5,37},
|
||||
{63,31,55,23,61,29,53,21} }; // fun fact: you can calculate bayer value on-the-fly but LUT is faster
|
||||
float bayerSize = 8.0;
|
||||
float bayerDivider = bayerSize * bayerSize;
|
||||
|
||||
|
||||
vec4 nearestColour(vec4 incolor) {
|
||||
vec4 rgbaCounts = vec4(rcount, gcount, bcount, 1.0);
|
||||
|
||||
|
||||
vec4 color = incolor;
|
||||
|
||||
color.r = floor((rgbaCounts.r - 1.0) * color.r + 0.5) / (rgbaCounts.r - 1.0);
|
||||
color.g = floor((rgbaCounts.g - 1.0) * color.g + 0.5) / (rgbaCounts.g - 1.0);
|
||||
color.b = floor((rgbaCounts.b - 1.0) * color.b + 0.5) / (rgbaCounts.b - 1.0);
|
||||
color.a = 1.0;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void main(void) {
|
||||
float spread = 1.0 / (0.299 * (rcount - 1.0) + 0.587 * (gcount - 1.0) + 0.114 * (bcount - 1.0)); // this spread value is optimised one -- try your own values for various effects!
|
||||
|
||||
float scale = v_texCoords.y; // screenHeight;
|
||||
float inR = mix(bottomColor.r, topColor.r, scale);
|
||||
float inG = mix(bottomColor.g, topColor.g, scale);
|
||||
float inB = mix(bottomColor.b, topColor.b, scale);
|
||||
|
||||
vec4 inColor = vec4(inR, inG, inB, 1.0);
|
||||
|
||||
vec2 entry = mod(gl_FragCoord.xy, vec2(bayerSize, bayerSize));
|
||||
|
||||
gl_FragColor = nearestColour(inColor + spread * (bayer[int(entry.y)][int(entry.x)] / bayerDivider - 0.5));
|
||||
}
|
||||
BIN
assets/graphics/gui/inventory/page_arrow_button.tga
LFS
Normal file
BIN
assets/graphics/gui/inventory/page_arrow_button.tga
LFS
Normal file
Binary file not shown.
@@ -10,6 +10,8 @@ import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||
import com.badlogic.gdx.math.Matrix4
|
||||
import net.torvald.terrarum.gameactors.sqrt
|
||||
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-07-05.
|
||||
@@ -33,22 +35,47 @@ object ColorLimiterTest : ApplicationAdapter() {
|
||||
|
||||
lateinit var batch: SpriteBatch
|
||||
|
||||
lateinit var font: GameFontBase
|
||||
|
||||
override fun create() {
|
||||
ShaderProgram.pedantic = false
|
||||
|
||||
shader4096 = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer.frag"))
|
||||
shader4096.begin()
|
||||
shader4096.setUniformf("monitorGamma", 2.2f)
|
||||
shader4096.setUniformf("rcount", 2f)
|
||||
shader4096.setUniformf("gcount", 2f)
|
||||
shader4096.setUniformf("bcount", 2f)
|
||||
shader4096.end()
|
||||
|
||||
|
||||
img = Texture("assets/test_texture.tga")
|
||||
|
||||
batch = SpriteBatch()
|
||||
|
||||
font = GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", flipY = false)
|
||||
|
||||
|
||||
if (!shader4096.isCompiled) {
|
||||
Gdx.app.log("Shader", shader4096.log)
|
||||
System.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
private var timer = 0f
|
||||
private var timerTick = 0.5f
|
||||
private var ditherStart = 2f
|
||||
private var ditherEnd = 16f
|
||||
private var dither = ditherStart
|
||||
|
||||
override fun render() {
|
||||
timer += Gdx.graphics.deltaTime
|
||||
|
||||
if (timer > timerTick) {
|
||||
timer -= timerTick
|
||||
dither += 1f
|
||||
if (dither > ditherEnd)
|
||||
dither = ditherStart
|
||||
}
|
||||
|
||||
Gdx.graphics.setTitle("TestTestTest — F: ${Gdx.graphics.framesPerSecond}")
|
||||
|
||||
Gdx.gl.glClearColor(.094f, .094f, .094f, 0f)
|
||||
@@ -57,7 +84,9 @@ object ColorLimiterTest : ApplicationAdapter() {
|
||||
|
||||
batch.inUse {
|
||||
batch.shader = shader4096
|
||||
shader4096.setUniformf("rgbaCounts", 16f, 16f, 16f, 16f)
|
||||
shader4096.setUniformf("rcount", dither)
|
||||
shader4096.setUniformf("gcount", dither)
|
||||
shader4096.setUniformf("bcount", dither)
|
||||
batch.color = Color.WHITE
|
||||
batch.draw(img, 0f, 0f)
|
||||
|
||||
@@ -65,6 +94,10 @@ object ColorLimiterTest : ApplicationAdapter() {
|
||||
batch.shader = null
|
||||
batch.color = Color.WHITE
|
||||
batch.draw(img, img.width.toFloat(), 0f)
|
||||
|
||||
|
||||
|
||||
font.draw(batch, "Dither level: ${dither.toInt()}", 10f, Gdx.graphics.height - 30f)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
|
||||
var worldDrawFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, false)
|
||||
var worldGlowFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, false)
|
||||
var worldBlendFrameBuffer = FrameBuffer(worldFBOformat, Terrarum.WIDTH, Terrarum.HEIGHT, false)
|
||||
var worldBlendFrameBuffer = FrameBuffer(Pixmap.Format.RGB888, Terrarum.WIDTH, Terrarum.HEIGHT, false)
|
||||
// RGB elements of Lightmap for Color Vec4(R, G, B, 1.0) 24-bit
|
||||
var lightmapFboA = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), false)
|
||||
var lightmapFboB = FrameBuffer(lightFBOformat, Terrarum.WIDTH.div(lightmapDownsample.toInt()), Terrarum.HEIGHT.div(lightmapDownsample.toInt()), false)
|
||||
@@ -253,6 +253,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
println("[Ingame] loaded successfully.")
|
||||
}
|
||||
else {
|
||||
LoadScreen.addMessage("${Terrarum.NAME} version ${Terrarum.VERSION_STRING}")
|
||||
LoadScreen.addMessage("Creating new world")
|
||||
|
||||
|
||||
@@ -317,11 +318,11 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
// inventory
|
||||
uiInventoryPlayer = UIHandler(
|
||||
UIInventory(player,
|
||||
width = 840,
|
||||
width = 900,
|
||||
height = Terrarum.HEIGHT - 160,
|
||||
categoryWidth = 210
|
||||
),
|
||||
toggleKey = Terrarum.getConfigInt("keyinventory")
|
||||
toggleKeyLiteral = Terrarum.getConfigInt("keyinventory")
|
||||
)
|
||||
uiInventoryPlayer.setPosition(
|
||||
-uiInventoryPlayer.UI.width,
|
||||
@@ -700,31 +701,34 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
Gdx.gl.glClearColor(0f, 0f, 0f, 0f)
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
||||
|
||||
|
||||
|
||||
// draw skybox
|
||||
/*WeatherMixer.render(camera)
|
||||
|
||||
|
||||
batch.inUse {
|
||||
batch.color = Color.WHITE
|
||||
blendNormal()
|
||||
|
||||
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // reset active textureunit to zero (i don't know tbh, but it won't work without this)
|
||||
batch.shader = null
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
|
||||
// draw blended world
|
||||
val worldTex = worldDrawFrameBuffer.colorBufferTexture // WORLD: light_color must be applied beforehand
|
||||
val glowTex = worldGlowFrameBuffer.colorBufferTexture // GLOW: light_uvlight must be applied beforehand
|
||||
|
||||
worldTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
glowTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
|
||||
//Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0)
|
||||
worldTex.bind(0)
|
||||
glowTex.bind(1)
|
||||
|
||||
|
||||
/*val quad = Mesh(
|
||||
true, 4, 6,
|
||||
VertexAttribute.Position(),
|
||||
VertexAttribute.ColorUnpacked(),
|
||||
VertexAttribute.TexCoords(0)
|
||||
)
|
||||
quad.setVertices(floatArrayOf(
|
||||
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
|
||||
Terrarum.WIDTH.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
|
||||
Terrarum.WIDTH.toFloat(), Terrarum.HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 1f, 0f,
|
||||
0f, Terrarum.HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 0f, 0f
|
||||
))
|
||||
quad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))*/
|
||||
|
||||
Terrarum.shaderBlendGlow.begin()
|
||||
Terrarum.shaderBlendGlow.setUniformMatrix("u_projTrans", camera.combined)
|
||||
Terrarum.shaderBlendGlow.setUniformi("u_texture", 0)
|
||||
@@ -756,15 +760,23 @@ class Ingame(val batch: SpriteBatch) : Screen {
|
||||
blendNormal()
|
||||
|
||||
|
||||
///////////////////////////
|
||||
// draw skybox to screen //
|
||||
///////////////////////////
|
||||
|
||||
WeatherMixer.render(camera)
|
||||
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// draw framebuffers to screen //
|
||||
/////////////////////////////////
|
||||
WeatherMixer.render(batch)
|
||||
|
||||
|
||||
val blendedTex = worldBlendFrameBuffer.colorBufferTexture
|
||||
blendedTex.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
||||
batch.color = Color.WHITE
|
||||
//batch.shader = Terrarum.shaderBayer
|
||||
batch.shader = null
|
||||
blendNormal()
|
||||
batch.draw(blendedTex, 0f, 0f, blendedTex.width.toFloat(), blendedTex.height.toFloat())
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import com.badlogic.gdx.ApplicationAdapter
|
||||
import com.badlogic.gdx.Game
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.Screen
|
||||
@@ -12,7 +11,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
|
||||
import com.badlogic.gdx.math.Matrix4
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonPrimitive
|
||||
import net.torvald.random.HQRNG
|
||||
@@ -56,7 +54,7 @@ fun main(args: Array<String>) {
|
||||
Terrarum.screenW = config.width
|
||||
Terrarum.screenH = config.height
|
||||
|
||||
println("usevsync = ${Terrarum.USE_VSYNC}")
|
||||
println("[TerrarumKt] usevsync = ${Terrarum.USE_VSYNC}")
|
||||
|
||||
// the game must run on same speed regardless of the display FPS;
|
||||
// "Terrarum.TARGET_INTERNAL_FPS" denotes "execute as if FPS was set to this value"
|
||||
@@ -227,7 +225,7 @@ object Terrarum : Game() {
|
||||
*
|
||||
* e.g. 0x02010034 can be translated as 2.1.52
|
||||
*/
|
||||
const val VERSION_RAW = 0x00_02_018E
|
||||
const val VERSION_RAW = 0x00_02_0226
|
||||
const val VERSION_STRING: String =
|
||||
"${VERSION_RAW.ushr(24)}.${VERSION_RAW.and(0xFF0000).ushr(16)}.${VERSION_RAW.and(0xFFFF)}"
|
||||
const val NAME = "Terrarum"
|
||||
@@ -241,8 +239,8 @@ object Terrarum : Game() {
|
||||
lateinit var shaderBlur: ShaderProgram
|
||||
lateinit var shaderRGBOnly: ShaderProgram
|
||||
lateinit var shaderAOnly: ShaderProgram
|
||||
lateinit var shader4096: ShaderProgram
|
||||
lateinit var shader4096Bayer: ShaderProgram
|
||||
lateinit var shaderBayer: ShaderProgram
|
||||
lateinit var shaderBayerSkyboxFill: ShaderProgram
|
||||
lateinit var shaderBlendGlow: ShaderProgram
|
||||
|
||||
|
||||
@@ -250,6 +248,9 @@ object Terrarum : Game() {
|
||||
|
||||
|
||||
init {
|
||||
println("$NAME version $VERSION_STRING")
|
||||
|
||||
|
||||
getDefaultDirectory()
|
||||
createDirs()
|
||||
|
||||
@@ -319,13 +320,15 @@ object Terrarum : Game() {
|
||||
|
||||
ShaderProgram.pedantic = false
|
||||
shaderBlur = ShaderProgram(Gdx.files.internal("assets/blur.vert"), Gdx.files.internal("assets/blur.frag"))
|
||||
shader4096 = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096.frag"))
|
||||
shader4096Bayer = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer.frag"))
|
||||
|
||||
shader4096Bayer.begin()
|
||||
shader4096Bayer.setUniformMatrix("Bayer", Matrix4(floatArrayOf(0f,8f,2f,10f,12f,4f,14f,6f,3f,11f,1f,9f,15f,7f,13f,5f)))
|
||||
shader4096Bayer.setUniformf("monitorGamma", 2.2f)
|
||||
shader4096Bayer.end()
|
||||
shaderBayer = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer.frag"))
|
||||
shaderBayer.begin()
|
||||
shaderBayer.setUniformf("rcount", 16f)
|
||||
shaderBayer.setUniformf("gcount", 16f)
|
||||
shaderBayer.setUniformf("bcount", 16f)
|
||||
shaderBayer.end()
|
||||
|
||||
shaderBayerSkyboxFill = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer_skyboxfill.frag"))
|
||||
|
||||
|
||||
shaderRGBOnly = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/rgbonly.frag"))
|
||||
@@ -334,11 +337,21 @@ object Terrarum : Game() {
|
||||
shaderBlendGlow = ShaderProgram(Gdx.files.internal("assets/blendGlow.vert"), Gdx.files.internal("assets/blendGlow.frag"))
|
||||
|
||||
if (!shaderBlendGlow.isCompiled) {
|
||||
Gdx.app.log("Shader", shaderBlendGlow.log)
|
||||
Gdx.app.log("shaderBlendGlow", shaderBlendGlow.log)
|
||||
System.exit(1)
|
||||
}
|
||||
|
||||
|
||||
if (!shaderBayer.isCompiled) {
|
||||
Gdx.app.log("shaderBayer", shaderBayer.log)
|
||||
System.exit(1)
|
||||
}
|
||||
|
||||
if (!shaderBayerSkyboxFill.isCompiled) {
|
||||
Gdx.app.log("shaderBayerSkyboxFill", shaderBayerSkyboxFill.log)
|
||||
System.exit(1)
|
||||
}
|
||||
|
||||
|
||||
gameLocale = getConfigString("language")
|
||||
println("[Terrarum] locale = $gameLocale")
|
||||
@@ -670,9 +683,9 @@ fun blendScreen() {
|
||||
}
|
||||
|
||||
object BlendMode {
|
||||
const val SCREEN = "GL_BLEND screen"
|
||||
const val MULTIPLY = "GL_BLEND multiply"
|
||||
const val NORMAL = "GL_BLEND normal"
|
||||
const val SCREEN = "screen"
|
||||
const val MULTIPLY = "multiply"
|
||||
const val NORMAL = "normal"
|
||||
//const val MAX = "GL_MAX" // not supported by GLES -- use shader
|
||||
|
||||
fun resolve(mode: String) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
* Created by minjaesong on 15-12-31.
|
||||
*/
|
||||
class UIHandler(var UI: UICanvas,
|
||||
var toggleKey: Int? = null, var toggleButton: Int? = null,
|
||||
var toggleKeyLiteral: Int? = null, var toggleButtonLiteral: 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
|
||||
var doNotWarnConstant: Boolean = false
|
||||
@@ -62,6 +62,10 @@ class UIHandler(var UI: UICanvas,
|
||||
}
|
||||
|
||||
|
||||
private val toggleKey: Int?; get() = toggleKeyLiteral // to support in-screen keybind changing
|
||||
private val toggleButton: Int?; get() = toggleButtonLiteral // to support in-screen keybind changing
|
||||
|
||||
|
||||
fun update(delta: Float) {
|
||||
// open/close UI by key pressed
|
||||
if (toggleKey != null) {
|
||||
|
||||
@@ -58,6 +58,10 @@ class UIInventory(
|
||||
|
||||
val controlHelpHeight = Terrarum.fontGame.lineHeight.toInt()
|
||||
|
||||
val pageButtonExtraGap = 32
|
||||
|
||||
val pageButtonRealWidth = pageButtonExtraGap + itemStripGutterH
|
||||
|
||||
val catButtons = UIItemTextButtonList(
|
||||
this,
|
||||
arrayOf(
|
||||
@@ -90,12 +94,12 @@ class UIInventory(
|
||||
inactiveCol = defaultTextColour
|
||||
)
|
||||
|
||||
val itemsStripWidth = ((width - catButtons.width) - (2 * itemStripGutterH + itemInterColGutter)) / 2
|
||||
val itemsStripWidth = ((width - catButtons.width) - (2 * itemStripGutterH + itemInterColGutter)) / 2 - pageButtonExtraGap
|
||||
val items = Array(
|
||||
((height - controlHelpHeight) / (UIItemInventoryElem.height + itemStripGutterV)) * 2, {
|
||||
UIItemInventoryElem(
|
||||
parentUI = this,
|
||||
posX = catButtons.width + if (it % 2 == 0) itemStripGutterH else (itemStripGutterH + itemsStripWidth + itemInterColGutter),
|
||||
posX = pageButtonExtraGap + catButtons.width + if (it % 2 == 0) itemStripGutterH else (itemStripGutterH + itemsStripWidth + itemInterColGutter),
|
||||
posY = itemStripGutterH + it / 2 * (UIItemInventoryElem.height + itemStripGutterV),
|
||||
width = itemsStripWidth,
|
||||
item = null,
|
||||
@@ -134,6 +138,13 @@ class UIInventory(
|
||||
private var encumbrancePerc = 0f
|
||||
private var isEncumbered = false
|
||||
|
||||
|
||||
private val seekLeft: Int; get() = Terrarum.getConfigInt("keyleft") // to support in-screen keybind changing
|
||||
private val seekRight: Int; get() = Terrarum.getConfigInt("keyright") // to support in-screen keybind changing
|
||||
private val seekUp: Int; get() = Terrarum.getConfigInt("keyup") // to support in-screen keybind changing
|
||||
private val seekDown: Int; get() = Terrarum.getConfigInt("keydown") // to support in-screen keybind changing
|
||||
|
||||
|
||||
override fun update(delta: Float) {
|
||||
if (handler == null) {
|
||||
throw Error("Handler for this UI is null, you douchebag.")
|
||||
|
||||
83
src/net/torvald/terrarum/ui/UIItemImageButton.kt
Normal file
83
src/net/torvald/terrarum/ui/UIItemImageButton.kt
Normal file
@@ -0,0 +1,83 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.BlendMode
|
||||
import net.torvald.terrarum.blendNormal
|
||||
import net.torvald.terrarum.fillRect
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2017-07-16.
|
||||
*/
|
||||
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(0x00f8ff_ff),
|
||||
val activeBackCol: Color = Color(0xb0b0b0_ff.toInt()),
|
||||
val activeBackBlendMode: String = BlendMode.MULTIPLY,
|
||||
|
||||
override var posX: Int,
|
||||
override var posY: Int,
|
||||
override val width: Int,
|
||||
override val height: Int
|
||||
) : UIItem(parent) {
|
||||
|
||||
override fun update(delta: Float) {
|
||||
}
|
||||
|
||||
override fun render(batch: SpriteBatch) {
|
||||
if (mouseUp) {
|
||||
BlendMode.resolve(activeBackBlendMode)
|
||||
batch.color = activeBackCol
|
||||
}
|
||||
else {
|
||||
BlendMode.resolve(buttonBackBlendMode)
|
||||
batch.color = buttonBackCol
|
||||
}
|
||||
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
|
||||
blendNormal()
|
||||
|
||||
batch.color = if (mouseUp) activeCol else buttonCol
|
||||
batch.draw(image, (posX - (image.regionWidth / 2)).toFloat(), (posY - (image.regionHeight / 2)).toFloat())
|
||||
}
|
||||
|
||||
override fun dispose() {
|
||||
image.texture.dispose()
|
||||
}
|
||||
|
||||
override fun keyDown(keycode: Int): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun keyUp(keycode: Int): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun scrolled(amount: Int): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,6 @@ class UIItemTextButton(
|
||||
override val height: Int = UIItemTextButton.height
|
||||
|
||||
var highlighted: Boolean = false
|
||||
var mouseOver = false
|
||||
|
||||
|
||||
override fun update(delta: Float) {
|
||||
@@ -59,7 +58,7 @@ class UIItemTextButton(
|
||||
batch.color = highlightBackCol
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
}
|
||||
else if (mouseOver) {
|
||||
else if (mouseUp) {
|
||||
BlendMode.resolve(activeBackBlendMode)
|
||||
batch.color = activeBackCol
|
||||
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
|
||||
@@ -68,9 +67,8 @@ class UIItemTextButton(
|
||||
blendNormal()
|
||||
|
||||
|
||||
mouseOver = mouseUp
|
||||
batch.color = if (highlighted) highlightCol
|
||||
else if (mouseOver) activeCol
|
||||
else if (mouseUp) activeCol
|
||||
else inactiveCol
|
||||
|
||||
font.draw(batch,
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package net.torvald.terrarum.weather
|
||||
|
||||
import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.*
|
||||
import net.torvald.terrarum.utils.JsonFetcher
|
||||
import net.torvald.colourutil.*
|
||||
import net.torvald.random.HQRNG
|
||||
@@ -11,7 +9,6 @@ import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameactors.ParticleTestRain
|
||||
import net.torvald.terrarum.gamecontroller.KeyToggler
|
||||
import net.torvald.terrarum.gameworld.WorldTime
|
||||
import net.torvald.terrarum.worlddrawer.LightmapRenderer
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
@@ -94,10 +91,7 @@ object WeatherMixer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning! Ends and begins SpriteBatch
|
||||
*/
|
||||
fun render(batch: SpriteBatch) {
|
||||
fun render(camera: Camera) {
|
||||
|
||||
// we will not care for nextSkybox for now
|
||||
val timeNow = Terrarum.ingame!!.world.time.todaySeconds
|
||||
@@ -107,20 +101,20 @@ object WeatherMixer {
|
||||
val globalLight = getGradientColour(skyboxColourMap, 2, timeNow)
|
||||
globalLightNow.set(globalLight)
|
||||
|
||||
|
||||
// draw skybox to provided graphics instance
|
||||
batch.end()
|
||||
Terrarum.inShapeRenderer {
|
||||
it.rect(
|
||||
0f, 0f,
|
||||
Terrarum.WIDTH.toFloat(),
|
||||
Terrarum.HEIGHT.toFloat(),
|
||||
getGradientColour(skyboxColourMap, 1, timeNow),
|
||||
getGradientColour(skyboxColourMap, 1, timeNow),
|
||||
getGradientColour(skyboxColourMap, 0, timeNow),
|
||||
getGradientColour(skyboxColourMap, 0, timeNow)
|
||||
)
|
||||
}
|
||||
batch.begin()
|
||||
val topCol = getGradientColour(skyboxColourMap, 0, timeNow)
|
||||
val bottomCol = getGradientColour(skyboxColourMap, 1, timeNow)
|
||||
|
||||
Terrarum.textureWhiteSquare.bind(0)
|
||||
|
||||
Terrarum.shaderBayerSkyboxFill.begin()
|
||||
Terrarum.shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined)
|
||||
Terrarum.shaderBayerSkyboxFill.setUniformf("topColor", topCol.r, topCol.g, topCol.b)
|
||||
Terrarum.shaderBayerSkyboxFill.setUniformf("bottomColor", bottomCol.r, bottomCol.g, bottomCol.b)
|
||||
Terrarum.shaderBayerSkyboxFill.setUniformf("screenHeight", Terrarum.HEIGHT.toFloat())
|
||||
Terrarum.ingame!!.fullscreenQuad.render(Terrarum.shaderBayerSkyboxFill, GL20.GL_TRIANGLES)
|
||||
Terrarum.shaderBayerSkyboxFill.end()
|
||||
}
|
||||
|
||||
fun Float.clampOne() = if (this > 1) 1f else this
|
||||
|
||||
Reference in New Issue
Block a user