load app using apploader -- no more black screen on app load

This commit is contained in:
minjaesong
2017-08-01 23:55:48 +09:00
parent 5c2b1e7586
commit aa238eb65c
19 changed files with 668 additions and 88 deletions

View File

@@ -93,27 +93,27 @@ Copyright (C) 2011 Joshua Tippetts
Copyright (c) 2010-2015 William Bittle http://www.dyn4j.org/
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the
distribution.
* Neither the name of dyn4j nor the names of its contributors may be used to endorse or
promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the
distribution.
* Neither the name of dyn4j nor the names of its contributors may be used to endorse or
promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kotlin translated and modified code Copyright (C) 2016 Minjaesong (Torvald)
Kotlin translated and modified code Copyright (C) 2016 Minjaesong (Torvald)
----
@@ -135,22 +135,45 @@ LuaJ
Copyright (c) 2007 LuaJ. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
----
Some of the resources were created by _raxod502_.
Copyright (c) 2016 Radon Rosborough
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -2233,7 +2233,7 @@
},
{
"n": "MENU_LANGUAGE_THIS",
"s": "日本語"
"s": "にほんご"
},
{
"n": "MENU_LANGUAGE_THIS_EN",

View File

@@ -4,7 +4,7 @@ import net.torvald.terrarum.langpack.Lang
object CreditSingleton {
val credit: List<String> =
val credit: List<String>; get() =
("${Lang["CREDITS_PROGRAMMER"]}\n\nTorvald (minjaesong)\n\n" +
"${Lang["CREDITS_ARTIST_PLURAL"]}\n\nTorvald (minjaesong)\nRoundworld (leedonggeun)" +
"""
@@ -161,7 +161,7 @@ Sound from http://www.freesound.org/people/klankbeeld/""").split('\n')
val gpl3: List<String> = """ GNU GENERAL PUBLIC LICENSE
val gpl3: List<String>; get() = """ GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>

View File

@@ -166,9 +166,6 @@ class Ingame(val batch: SpriteBatch) : Screen {
// invert Y
fun initViewPort(width: Int, height: Int) {
//val width = if (width % 1 == 1) width + 1 else width
//val height = if (height % 1 == 1) height + 1 else width
// Set Y to point downwards
camera.setToOrtho(true, width.toFloat(), height.toFloat())
@@ -430,7 +427,7 @@ class Ingame(val batch: SpriteBatch) : Screen {
Gdx.graphics.setTitle(GAME_NAME +
Gdx.graphics.setTitle(TerrarumAppLoader.GAME_NAME +
" — F: ${Gdx.graphics.framesPerSecond} (${Terrarum.TARGET_INTERNAL_FPS})" +
" — M: ${Terrarum.memInUse}M / ${Terrarum.memTotal}M / ${Terrarum.memXmx}M"
)

View File

@@ -15,6 +15,7 @@ import com.google.gson.JsonArray
import com.google.gson.JsonPrimitive
import net.torvald.random.HQRNG
import net.torvald.terrarum.Terrarum.RENDER_FPS
import net.torvald.terrarum.TerrarumAppLoader
import net.torvald.terrarum.gameactors.floorInt
import net.torvald.terrarum.gamecontroller.IngameController
import net.torvald.terrarum.imagefont.TinyAlphNum
@@ -36,18 +37,15 @@ import java.lang.management.ManagementFactory
import java.util.*
/**
* Created by minjaesong on 2017-06-15.
* Slick2d Version Created by minjaesong on 15-12-30.
*
* LibGDX Version Created by minjaesong on 2017-06-15.
*/
const val GAME_NAME = "Terrarum"
const val COPYRIGHT_DATE_NAME = "Copyright 2013-2017 Torvald (minjaesong)"
fun main(args: Array<String>) {
/*fun main(args: Array<String>) {
Terrarum // invoke
val config = LwjglApplicationConfiguration()
config.foregroundFPS = Terrarum.RENDER_FPS
config.backgroundFPS = Terrarum.RENDER_FPS
config.vSyncEnabled = Terrarum.USE_VSYNC
config.resizable = true
config.width = 1072
@@ -65,14 +63,16 @@ fun main(args: Array<String>) {
// "Terrarum.TARGET_INTERNAL_FPS" denotes "execute as if FPS was set to this value"
LwjglApplication(Terrarum, config)
}
}*/
typealias RGBA8888 = Int
object Terrarum : Game() {
object Terrarum : Screen {
lateinit var appLoader: TerrarumAppLoader
internal var screenW: Int? = null
internal var screenH: Int? = null
@@ -90,9 +90,9 @@ object Terrarum : Game() {
//////////////////////////////
val WIDTH: Int
get() = if (screenW!! % 2 == 0) screenW!! else screenW!! + 1
get() = if ((screenW ?: Gdx.graphics.width) % 2 == 0) (screenW ?: Gdx.graphics.width) else (screenW ?: Gdx.graphics.width) - 1
val HEIGHT: Int
get() = if (screenH!! % 2 == 0) screenH!! else screenH!! + 1
get() = if ((screenH ?: Gdx.graphics.height) % 2 == 0) (screenH ?: Gdx.graphics.height) else (screenH ?: Gdx.graphics.height) - 1
val WIDTH_MIN = 800
val HEIGHT_MIN = 600
@@ -105,7 +105,7 @@ object Terrarum : Game() {
/**
* To be used with physics simulator
*/
val TARGET_FPS: Double = 26.6666666666666666666666666 // lower value == faster gravity responce (IT WON'T HOTSWAP!!)
val TARGET_FPS: Double = 26.6666666666666666666666666 // lower value == faster gravity response (IT WON'T HOTSWAP!!)
/**
* To be used with render, to achieve smooth frame drawing
@@ -180,7 +180,7 @@ object Terrarum : Game() {
lateinit var fontGame: GameFontBase
lateinit var fontSmallNumbers: BitmapFont
lateinit var fontSmallNumbers: TinyAlphNum
var joypadLabelStart: Char = 0xE000.toChar() // lateinit
var joypadLableSelect: Char = 0xE000.toChar() // lateinit
@@ -333,7 +333,7 @@ object Terrarum : Game() {
val MINIMAL_GL_VERSION = 210
override fun create() {
override fun show() {
if (environment != RunningEnvironment.MOBILE) {
Gdx.gl.glDisable(GL20.GL_DITHER)
}
@@ -360,9 +360,9 @@ object Terrarum : Game() {
fullscreenQuad.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
WIDTH.toFloat(), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
WIDTH.toFloat(), HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 1f, 0f,
0f, HEIGHT.toFloat(), 0f, 1f, 1f, 1f, 1f, 0f, 0f
))
fullscreenQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
@@ -395,7 +395,7 @@ object Terrarum : Game() {
shaderBayer.setUniformf("bcount", 16f)
shaderBayer.end()
shaderBayerSkyboxFill = ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer_skyboxfill.frag"))
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"))
@@ -441,28 +441,28 @@ object Terrarum : Game() {
// title screen
super.setScreen(TitleScreen(batch))
appLoader.setScreen(TitleScreen(batch))
}
internal fun changeScreen(screen: Screen) {
super.setScreen(screen)
appLoader.setScreen(screen)
}
override fun render() {
super.screen.render(deltaTime)
override fun render(delta: Float) {
//appLoader.screen.render(deltaTime)
GLOBAL_RENDER_TIMER += 1
}
override fun pause() {
super.screen.pause()
//appLoader.screen.pause()
}
override fun resume() {
super.screen.resume()
//appLoader.screen.resume()
}
override fun dispose() {
super.screen.dispose()
//appLoader.screen.dispose()
fontGame.dispose()
fontSmallNumbers.dispose()
@@ -477,6 +477,10 @@ object Terrarum : Game() {
//dispose any other resources used in this level
}
override fun hide() {
}
override fun resize(width: Int, height: Int) {
var width = maxOf(width, WIDTH_MIN)
var height = maxOf(height, HEIGHT_MIN)
@@ -498,7 +502,7 @@ object Terrarum : Game() {
fullscreenQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
super.resize(width, height)
//appLoader.resize(width, height)
//Gdx.graphics.setWindowedMode(width, height)
println("newsize: ${Gdx.graphics.width}x${Gdx.graphics.height}")

View File

@@ -0,0 +1,166 @@
package net.torvald.terrarum;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
/**
* Created by minjaesong on 2017-08-01.
*/
public class TerrarumAppLoader implements ApplicationListener {
public static final String GAME_NAME = "Terrarum";
public static final String COPYRIGHT_DATE_NAME = "Copyright 2013-2017 Torvald (minjaesong)";
private static LwjglApplicationConfiguration appConfig;
public static void main(String[] args) {
appConfig = new LwjglApplicationConfiguration();
appConfig.vSyncEnabled = false;
appConfig.resizable = true;
appConfig.width = 1072;
appConfig.height = 742;
appConfig.backgroundFPS = 9999;
appConfig.foregroundFPS = 9999;
appConfig.title = GAME_NAME;
new LwjglApplication(new TerrarumAppLoader(), appConfig);
}
private ShaderProgram shaderBayerSkyboxFill;
private Mesh fullscreenQuad;
private OrthographicCamera camera;
private SpriteBatch batch;
private TextureRegion logo;
private Color gradWhiteTop = new Color(0xf8f8f8ff);
private Color gradWhiteBottom = new Color(0xd8d8d8ff);
public Screen screen;
private TerrarumAppLoader() {
}
private void initViewPort(int width, int height) {
// Set Y to point downwards
camera.setToOrtho(true, width, height);
// Update camera matrix
camera.update();
// Set viewport to restrict drawing
Gdx.gl20.glViewport(0, 0, width, height);
}
private float loadTimer = 0f;
private final float showupTime = 50f / 1000f;
@Override
public void create() {
batch = new SpriteBatch();
camera = new OrthographicCamera(((float) appConfig.width), ((float) appConfig.height));
initViewPort(appConfig.width, appConfig.height);
shaderBayerSkyboxFill = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer_skyboxfill.frag"));
fullscreenQuad = new Mesh(
true, 4, 6,
VertexAttribute.Position(),
VertexAttribute.ColorUnpacked(),
VertexAttribute.TexCoords(0)
);
fullscreenQuad.setVertices(new float[]{
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 1f,
((float) appConfig.width), 0f, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
((float) appConfig.width), ((float) appConfig.height), 0f, 1f, 1f, 1f, 1f, 1f, 0f,
0f, ((float) appConfig.height), 0f, 1f, 1f, 1f, 1f, 0f, 0f
});
fullscreenQuad.setIndices(new short[]{0, 1, 2, 2, 3, 0});
logo = new TextureRegion(new Texture(Gdx.files.internal("assets/graphics/logo_placeholder.tga")));
logo.flip(false, true);
}
@Override
public void render() {
if (screen == null) {
shaderBayerSkyboxFill.begin();
shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined);
shaderBayerSkyboxFill.setUniformf("topColor", gradWhiteTop.r, gradWhiteTop.g, gradWhiteTop.b);
shaderBayerSkyboxFill.setUniformf("bottomColor", gradWhiteBottom.r, gradWhiteBottom.g, gradWhiteBottom.b);
fullscreenQuad.render(shaderBayerSkyboxFill, GL20.GL_TRIANGLES);
shaderBayerSkyboxFill.end();
batch.begin();
batch.setColor(Color.WHITE);
//blendNormal();
batch.setShader(null);
setCameraPosition(0f, 0f);
batch.draw(logo, (appConfig.width - logo.getRegionWidth()) / 2f,
(appConfig.height - logo.getRegionHeight()) / 2f
);
batch.end();
loadTimer += Gdx.graphics.getRawDeltaTime();
if (loadTimer >= showupTime) {
Terrarum.INSTANCE.setAppLoader(this);
setScreen(Terrarum.INSTANCE);
}
}
else {
screen.render(Gdx.graphics.getDeltaTime());
}
}
@Override
public void resize(int width, int height) {
initViewPort(width, height);
}
@Override
public void dispose () {
if (screen != null) screen.hide();
}
@Override
public void pause () {
if (screen != null) screen.pause();
}
@Override
public void resume () {
if (screen != null) screen.resume();
}
public void setScreen(Screen screen) {
if (this.screen != null) this.screen.hide();
this.screen = screen;
if (this.screen != null) {
this.screen.show();
this.screen.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
}
private void setCameraPosition(float newX, float newY) {
camera.position.set((-newX + appConfig.width / 2), (-newY + appConfig.height / 2), 0f);
camera.update();
batch.setProjectionMatrix(camera.combined);
}
}

View File

@@ -32,9 +32,6 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
// invert Y
fun initViewPort(width: Int, height: Int) {
//val width = if (width % 1 == 1) width + 1 else width
//val height = if (height % 1 == 1) height + 1 else width
// Set Y to point downwards
camera.setToOrtho(true, width.toFloat(), height.toFloat())
@@ -335,7 +332,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
batch.color = Color.LIGHT_GRAY
val COPYTING = arrayOf(
COPYRIGHT_DATE_NAME,
TerrarumAppLoader.COPYRIGHT_DATE_NAME,
Lang["COPYRIGHT_GNU_GPL_3"]
)

View File

@@ -30,7 +30,7 @@ class GameWorld(val width: Int, val height: Int) {
val wallDamages = HashMap<BlockAddress, BlockDamage>()
val terrainDamages = HashMap<BlockAddress, BlockDamage>()
//public World physWorld = new World( new Vec2(0, -TerrarumMain.game.gravitationalAccel) );
//public World physWorld = new World( new Vec2(0, -Terrarum.game.gravitationalAccel) );
//physics
/** Meter per second squared. Currently only the downward gravity is supported. No reverse gravity :p */
var gravitation: Vector2 = Vector2(0.0, 9.8)

View File

@@ -14,6 +14,8 @@ object Lang {
* Get record by its STRING_ID
*
* HashMap<"$key_$language", Value>
*
* E.g. langpack["MENU_LANGUAGE_THIS_fiFI"]
*/
val langpack = HashMap<String, String>()
private val FALLBACK_LANG_CODE = "en"
@@ -55,9 +57,10 @@ object Lang {
if (!it.name.startsWith("Polyglot") && it.name.endsWith(".json")) {
processRegularLangfile(it, lang)
}
else {
else if (it.name.startsWith("Polyglot") && it.name.endsWith(".json")) {
processPolyglotLangFile(it, lang)
}
// else, ignore
}
}

View File

@@ -0,0 +1,124 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.BlendMode
import net.torvald.terrarum.fillRect
import net.torvald.terrarum.gameactors.Second
/**
* Created by minjaesong on 2017-08-01.
*/
class UIItemList<Item: UIItem>(
parentUI: UICanvas,
val itemList: ArrayList<Item>,
override var posX: Int,
override var posY: Int,
override val width: Int,
override val height: Int,
var selectable: Boolean = false,
val defaultSelection: Int? = null, // negative: INVALID, positive: valid, null: no select
// copied directly from UIItemTextButton
val activeCol: Color = Color(0xfff066_ff.toInt()),
val activeBackCol: Color = Color(0),
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 backgroundCol: Color = Color(0x242424_80),
val backgroundBlendMode: String = BlendMode.NORMAL,
val kinematic: Boolean = false
) : UIItem(parentUI) {
init {
itemList.forEachIndexed { index, item ->
item.posX = this.posX
item.posY = if (index == 0) this.posY else itemList[index - 1].posY + itemList[index - 1].height + this.posY
}
}
var selectedIndex: Int? = defaultSelection
val selectedButton: UIItem?
get() = if (selectedIndex != null) itemList[selectedIndex!!] else null
private var highlightY: Double? = if (selectedIndex != null) itemList[selectedIndex!!].posY.toDouble() else null
private val highlighterMoveDuration: Second = 0.1f
private var highlighterMoveTimer: Second = 0f
private var highlighterMoving = false
private var highlighterYStart = highlightY
private var highlighterYEnd = highlightY
/** (oldIndex: Int?, newIndex: Int) -> Unit */
var selectionChangeListener: ((Int?, Int) -> Unit)? = null
override fun update(delta: Float) {
if (highlighterMoving) {
highlighterMoveTimer += delta
if (selectedIndex != null) {
highlightY = UIUtils.moveQuick(
highlighterYStart!!,
highlighterYEnd!!,
highlighterMoveTimer.toDouble(),
highlighterMoveDuration.toDouble()
)
}
if (highlighterMoveTimer > highlighterMoveDuration) {
highlighterMoveTimer = 0f
highlighterYStart = highlighterYEnd
highlightY = highlighterYEnd
highlighterMoving = false
}
}
itemList.forEachIndexed { index, item ->
item.update(delta)
if (item.mousePushed && index != selectedIndex) {
val oldIndex = selectedIndex
if (kinematic) {
highlighterYStart = itemList[selectedIndex!!].posY.toDouble()
selectedIndex = index
highlighterMoving = true
highlighterYEnd = itemList[selectedIndex!!].posY.toDouble()
}
else {
selectedIndex = index
highlightY = itemList[selectedIndex!!].posY.toDouble()
}
selectionChangeListener?.invoke(oldIndex, index)
}
//item.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
}
}
override fun render(batch: SpriteBatch) {
batch.color = backgroundCol
BlendMode.resolve(backgroundBlendMode)
batch.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
batch.color = highlightBackCol
BlendMode.resolve(highlightBackBlendMode)
if (highlightY != null) {
batch.fillRect(posX.toFloat(), highlightY!!.toFloat(), width.toFloat(), UIItemTextButton.height.toFloat())
}
itemList.forEach { it.render(batch) }
batch.color = backgroundCol
}
override fun dispose() {
itemList.forEach { it.dispose() }
}
}

View File

@@ -0,0 +1,80 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.floor
class UIItemModuleInfoCell(
parent: UICanvas,
var moduleName: String,
override val width: Int,
override var posX: Int,
override var posY: Int
) : UIItem(parent) {
override val height: Int = Terrarum.fontGame.lineHeight.toInt() * 2
private val numberAreaWidth = Terrarum.fontSmallNumbers.W * 3 + 4
override fun render(batch: SpriteBatch) {
if (ModMgr.moduleInfo.containsKey(moduleName)) {
val modInfo = ModMgr.moduleInfo[moduleName]!!
// print load order index
batch.color = Color(0x7f7f7fff)
var strlen = Terrarum.fontSmallNumbers.getWidth(modInfo.order.toString())
Terrarum.fontSmallNumbers.draw(batch,
modInfo.order.toString(),
(numberAreaWidth - strlen).div(2f).floor(),
(height - Terrarum.fontSmallNumbers.H).div(2f).floor()
)
// print module name
batch.color = Color.WHITE
Terrarum.fontGame.draw(batch,
"${modInfo.properName} (${modInfo.version})",
numberAreaWidth.toFloat(),
0f
)
// print author name
strlen = Terrarum.fontGame.getWidth(modInfo.author)
Terrarum.fontGame.draw(batch,
modInfo.author,
width - strlen.toFloat(),
0f
)
// print description
Terrarum.fontGame.draw(batch,
modInfo.description,
numberAreaWidth.toFloat(),
Terrarum.fontGame.lineHeight
)
// print releasedate
strlen = Terrarum.fontGame.getWidth(modInfo.releaseDate)
Terrarum.fontGame.draw(batch,
modInfo.releaseDate,
width - strlen.toFloat(),
Terrarum.fontGame.lineHeight
)
}
else {
batch.color = Color(0xff8080_ff.toInt())
val str = "InternalError: no such module: '$moduleName'"
val strlen = Terrarum.fontSmallNumbers.getWidth(str)
Terrarum.fontSmallNumbers.draw(batch,
str,
(width - numberAreaWidth - strlen).div(2f).floor() + numberAreaWidth,
(height - Terrarum.fontSmallNumbers.H).div(2f).floor()
)
}
}
override fun dispose() {
}
}

View File

@@ -3,6 +3,7 @@ package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.floor
class UIItemTextArea(
parentUI: UICanvas,
@@ -11,10 +12,14 @@ class UIItemTextArea(
override val width: Int,
override val height: Int,
val lineGap: Int = 0,
val lineCount: Int = ((height + lineGap) / Terrarum.fontGame.lineHeight).toInt()
val lineCount: Int = ((height + lineGap) / Terrarum.fontGame.lineHeight).toInt(),
val align: UIItemTextArea.Align = Align.LEFT
) : UIItem(parentUI) {
enum class Align {
LEFT, CENTRE, RIGHT
}
@@ -34,11 +39,16 @@ class UIItemTextArea(
}
override fun render(batch: SpriteBatch) {
batch.color = Color.WHITE
for (i in scrollPos until minOf(lineCount + scrollPos, entireText.size)) {
val yPtr = i - scrollPos
Terrarum.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
val textWidth = Terrarum.fontGame.getWidth(entireText[i])
when (align) {
Align.LEFT -> Terrarum.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
Align.CENTRE -> Terrarum.fontGame.draw(batch, entireText[i], posX + ((width - textWidth) / 2f).floor(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
Align.RIGHT -> Terrarum.fontGame.draw(batch, entireText[i], posX + width - textWidth.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
}
}
}

View File

@@ -58,8 +58,9 @@ class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
menubar.selectedIndex = menubar.defaultSelection
this.setAsClose()
Thread.sleep(50)
menubar.selectedIndex = menubar.defaultSelection
superMenu.setAsOpen()
}
@@ -90,6 +91,7 @@ class UITitleRemoConCredits(val superMenu: UICanvas) : UICanvas() {
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch)
if (drawTextArea) {
batch.color = Color.WHITE
textArea.render(batch)
}
}

View File

@@ -3,7 +3,9 @@ package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.Second
import net.torvald.terrarum.langpack.Lang
class UITitleRemoConLanguage(val superMenu: UICanvas) : UICanvas() {
@@ -31,31 +33,64 @@ class UITitleRemoConLanguage(val superMenu: UICanvas) : UICanvas() {
defaultSelection = null
)
private val textAreaHMargin = 48
private val textAreaWidth = (Terrarum.WIDTH * 0.75).toInt()
private val textAreaHeight = Terrarum.HEIGHT - textAreaHMargin * 2
/*private val textArea = UIItemTextArea(this,
Terrarum.WIDTH - textAreaWidth, textAreaHMargin,
textAreaWidth, textAreaHeight,
align = UIItemTextArea.Align.CENTRE
)*/
private val localeList = Lang.languageList.toList().sorted()
private val textArea = UIItemTextButtonList(this,
localeList.map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }.toTypedArray(),
Terrarum.WIDTH - textAreaWidth, textAreaHMargin,
textAreaWidth, textAreaHeight,
textAreaWidth = textAreaWidth,
readFromLang = false,
activeBackCol = Color(0),
highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = null
)
init {
uiItems.add(menubar)
//textArea.entireText = Lang.languageList.toList().sorted().map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }
////////////////////////////
uiItems.add(menubar)
// attach listeners
textArea.selectionChangeListener = { _, newSelectionIndex ->
Terrarum.gameLocale = localeList[newSelectionIndex]
}
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
menubar.selectedIndex = menubar.defaultSelection
this.setAsClose()
Thread.sleep(50)
menubar.selectedIndex = menubar.defaultSelection
superMenu.setAsOpen()
}
}
override fun updateUI(delta: Float) {
menubar.update(delta)
textArea.update(delta)
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch)
batch.color = Color.WHITE
textArea.render(batch)
}
override fun doOpening(delta: Float) {

View File

@@ -0,0 +1,116 @@
package net.torvald.terrarum.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.Second
import net.torvald.terrarum.langpack.Lang
/**
* Created by minjaesong on 2017-08-01.
*/
/*class UITitleRemoConModules(val superMenu: UICanvas) : UICanvas() {
val menuLabels = arrayOf(
"MENU_LABEL_RETURN"
)
override var width: Int = UITitleRemoConRoot.remoConWidth
override var height: Int = UITitleRemoConRoot.getRemoConHeight(menuLabels)
override var openCloseTime: Second = 0f
private val moduleListWidth = Terrarum.WIDTH / 2
private val moduleList = UIItemList<UIItemModuleInfoCell>(
this,
menuLabels,
0, UITitleRemoConRoot.menubarOffY,
this.width, this.height,
textAreaWidth = this.width,
readFromLang = true,
activeBackCol = Color(0),
highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = null
)
private val textAreaHMargin = 48
private val textAreaWidth = (Terrarum.WIDTH * 0.75).toInt()
private val textAreaHeight = Terrarum.HEIGHT - textAreaHMargin * 2
/*private val textArea = UIItemTextArea(this,
Terrarum.WIDTH - textAreaWidth, textAreaHMargin,
textAreaWidth, textAreaHeight,
align = UIItemTextArea.Align.CENTRE
)*/
private val localeList = Lang.languageList.toList().sorted()
private val textArea = UIItemTextButtonList(this,
localeList.map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }.toTypedArray(),
Terrarum.WIDTH - textAreaWidth, textAreaHMargin,
textAreaWidth, textAreaHeight,
textAreaWidth = textAreaWidth,
readFromLang = false,
activeBackCol = Color(0),
highlightBackCol = Color(0),
backgroundCol = Color(0),
inactiveCol = Color.WHITE,
defaultSelection = null
)
init {
uiItems.add(menubar)
//textArea.entireText = Lang.languageList.toList().sorted().map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }
////////////////////////////
// attach listeners
textArea.selectionChangeListener = { _, newSelectionIndex ->
Terrarum.gameLocale = localeList[newSelectionIndex]
}
menubar.buttons[menuLabels.indexOf("MENU_LABEL_RETURN")].clickOnceListener = { _, _, _ ->
this.setAsClose()
Thread.sleep(50)
menubar.selectedIndex = menubar.defaultSelection
superMenu.setAsOpen()
}
}
override fun updateUI(delta: Float) {
menubar.update(delta)
textArea.update(delta)
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
menubar.render(batch)
batch.color = Color.WHITE
textArea.render(batch)
}
override fun doOpening(delta: Float) {
}
override fun doClosing(delta: Float) {
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
}
override fun dispose() {
}
}*/

View File

@@ -70,13 +70,15 @@ class UITitleRemoConRoot : UICanvas() {
// attach listeners
menubar.buttons[menuLabels.indexOf("MENU_LABEL_LANGUAGE")].clickOnceListener = { _, _, _ ->
this.setAsClose()
Thread.sleep(50)
remoConLanguage.setAsOpen()
}
menubar.buttons[menuLabels.indexOf("MENU_LABEL_CREDITS")].clickOnceListener = { _, _, _ ->
this.setAsClose()
Thread.sleep(50)
remoConCredits.setAsOpen()
}
menubar.buttons[menuLabels.indexOf("MENU_LABEL_QUIT")].clickOnceListener = { _, _, _ -> System.exit(0) }
menubar.buttons[menuLabels.indexOf("MENU_LABEL_QUIT")].clickOnceListener = { _, _, _ -> Thread.sleep(50); System.exit(0) }
}
override fun updateUI(delta: Float) {

View File

@@ -43,10 +43,15 @@ object JsonFetcher {
return jsonObj
}
@Throws(java.io.IOException::class)
private fun readJsonFileAsString(path: String) {
java.nio.file.Files.lines(java.nio.file.FileSystems.getDefault().getPath(path)).forEach(
{ net.torvald.terrarum.utils.JsonFetcher.jsonString!!.append(it) }
) // JSON does not require line break
try {
java.nio.file.Files.lines(java.nio.file.FileSystems.getDefault().getPath(path)).forEach(
{ net.torvald.terrarum.utils.JsonFetcher.jsonString!!.append(it) }
) // JSON does not require line break
}
catch (e: IOException) {
System.err.println("An error occurred while reading $path")
e.printStackTrace()
}
}
}

View File

@@ -13,4 +13,19 @@ If things would run with infinite energy, I'm out. We need realism to implement
- Direct Current (only! because AC makes EE 10x harder), follows Ohm's law, and EXPLOSION!
- Take 'some' idea from _IndustrialCraft_ (Minecraft mod)
- Solar Windows, blocks light bit more than regular windows, high energies are absorbed more (it's a real thing!!)
### Source of Electricity
- Conventional
+ Fuel burn
+ Nuclear fission
- (almost) Infinite
+ Dark solar panel (traditional panel)
+ Transparent solar panel (window panel)
- Capacitor
+ Battery pack
+ Pu-238 RTG (super long-lasting battery with radiooactive taste)

View File

@@ -38,6 +38,7 @@ Simulation of the world, day and night fast, camera follows landscape
- Controls
- Graphics
- Gameplay Options
- MIDI (* Do-not-translate)
- Return