mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 10:34:06 +09:00
moved white box tex to AppLoader; textButton now has alignment option
This commit is contained in:
@@ -41,7 +41,19 @@ public class AppLoader implements ApplicationListener {
|
|||||||
|
|
||||||
private static AppLoader INSTANCE = null;
|
private static AppLoader INSTANCE = null;
|
||||||
|
|
||||||
private AppLoader() { }
|
private static Screen injectScreen = null;
|
||||||
|
|
||||||
|
public AppLoader(LwjglApplicationConfiguration appConfig, Screen injectScreen) {
|
||||||
|
AppLoader.injectScreen = injectScreen;
|
||||||
|
AppLoader.appConfig = appConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppLoader(LwjglApplicationConfiguration appConfig) {
|
||||||
|
AppLoader.appConfig = appConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AppLoader() {
|
||||||
|
}
|
||||||
|
|
||||||
public static AppLoader getINSTANCE() {
|
public static AppLoader getINSTANCE() {
|
||||||
if (INSTANCE == null) {
|
if (INSTANCE == null) {
|
||||||
@@ -98,7 +110,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ShaderProgram.pedantic = false;
|
ShaderProgram.pedantic = false;
|
||||||
|
|
||||||
appConfig = new LwjglApplicationConfiguration();
|
LwjglApplicationConfiguration appConfig = new LwjglApplicationConfiguration();
|
||||||
appConfig.vSyncEnabled = false;
|
appConfig.vSyncEnabled = false;
|
||||||
appConfig.resizable = false;//true;
|
appConfig.resizable = false;//true;
|
||||||
//appConfig.width = 1072; // IMAX ratio
|
//appConfig.width = 1072; // IMAX ratio
|
||||||
@@ -110,7 +122,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
appConfig.title = GAME_NAME;
|
appConfig.title = GAME_NAME;
|
||||||
appConfig.forceExit = false;
|
appConfig.forceExit = false;
|
||||||
|
|
||||||
new LwjglApplication(new AppLoader(), appConfig);
|
new LwjglApplication(new AppLoader(appConfig), appConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -128,6 +140,8 @@ public class AppLoader implements ApplicationListener {
|
|||||||
|
|
||||||
public Screen screen;
|
public Screen screen;
|
||||||
|
|
||||||
|
public static Texture textureWhiteSquare;
|
||||||
|
|
||||||
private void initViewPort(int width, int height) {
|
private void initViewPort(int width, int height) {
|
||||||
// Set Y to point downwards
|
// Set Y to point downwards
|
||||||
camera.setToOrtho(true, width, height);
|
camera.setToOrtho(true, width, height);
|
||||||
@@ -153,6 +167,10 @@ public class AppLoader implements ApplicationListener {
|
|||||||
initViewPort(appConfig.width, appConfig.height);
|
initViewPort(appConfig.width, appConfig.height);
|
||||||
|
|
||||||
|
|
||||||
|
textureWhiteSquare = new Texture(Gdx.files.internal("assets/graphics/ortho_line_tex_2px.tga"));
|
||||||
|
textureWhiteSquare.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest);
|
||||||
|
|
||||||
|
|
||||||
shaderBayerSkyboxFill = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer_skyboxfill.frag"));
|
shaderBayerSkyboxFill = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/4096_bayer_skyboxfill.frag"));
|
||||||
shaderHicolour = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/hicolour.frag"));
|
shaderHicolour = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/hicolour.frag"));
|
||||||
shaderColLUT = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/passthru.frag"));
|
shaderColLUT = new ShaderProgram(Gdx.files.internal("assets/4096.vert"), Gdx.files.internal("assets/passthru.frag"));
|
||||||
@@ -182,6 +200,12 @@ public class AppLoader implements ApplicationListener {
|
|||||||
|
|
||||||
TextureRegionPack.Companion.setGlobalFlipY(true);
|
TextureRegionPack.Companion.setGlobalFlipY(true);
|
||||||
fontGame = new GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", false, true, Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 128, false);
|
fontGame = new GameFontBase("assets/graphics/fonts/terrarum-sans-bitmap", false, true, Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 128, false);
|
||||||
|
|
||||||
|
|
||||||
|
// if there is a predefined screen, open that screen after my init process
|
||||||
|
if (injectScreen != null) {
|
||||||
|
setScreen(injectScreen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -200,6 +224,7 @@ public class AppLoader implements ApplicationListener {
|
|||||||
FrameBufferManager.begin(renderFBO);
|
FrameBufferManager.begin(renderFBO);
|
||||||
setCameraPosition(0, 0);
|
setCameraPosition(0, 0);
|
||||||
|
|
||||||
|
// if there's no predefined screen, default to the actual game's screen, and set the screen as the one
|
||||||
if (screen == null) {
|
if (screen == null) {
|
||||||
shaderBayerSkyboxFill.begin();
|
shaderBayerSkyboxFill.begin();
|
||||||
shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined);
|
shaderBayerSkyboxFill.setUniformMatrix("u_projTrans", camera.combined);
|
||||||
|
|||||||
@@ -222,10 +222,6 @@ object Terrarum : Screen {
|
|||||||
lateinit var shaderRGBOnly: ShaderProgram
|
lateinit var shaderRGBOnly: ShaderProgram
|
||||||
lateinit var shaderAtoGrey: ShaderProgram
|
lateinit var shaderAtoGrey: ShaderProgram
|
||||||
|
|
||||||
|
|
||||||
lateinit var textureWhiteSquare: Texture
|
|
||||||
|
|
||||||
|
|
||||||
lateinit var testTexture: Texture
|
lateinit var testTexture: Texture
|
||||||
|
|
||||||
|
|
||||||
@@ -357,10 +353,6 @@ object Terrarum : Screen {
|
|||||||
fontSmallNumbers = TinyAlphNum
|
fontSmallNumbers = TinyAlphNum
|
||||||
|
|
||||||
|
|
||||||
textureWhiteSquare = Texture(Gdx.files.internal("assets/graphics/ortho_line_tex_2px.tga"))
|
|
||||||
textureWhiteSquare.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
|
|
||||||
|
|
||||||
|
|
||||||
ShaderProgram.pedantic = false
|
ShaderProgram.pedantic = false
|
||||||
shaderBlur = ShaderProgram(Gdx.files.internal("assets/blur.vert"), Gdx.files.internal("assets/blur.frag"))
|
shaderBlur = ShaderProgram(Gdx.files.internal("assets/blur.vert"), Gdx.files.internal("assets/blur.frag"))
|
||||||
|
|
||||||
@@ -788,7 +780,7 @@ fun Float.round(): Float {
|
|||||||
|
|
||||||
// ShapeRenderer alternative for rects
|
// ShapeRenderer alternative for rects
|
||||||
fun SpriteBatch.fillRect(x: Float, y: Float, w: Float, h: Float) {
|
fun SpriteBatch.fillRect(x: Float, y: Float, w: Float, h: Float) {
|
||||||
this.draw(Terrarum.textureWhiteSquare, x, y, w, h)
|
this.draw(AppLoader.textureWhiteSquare, x, y, w, h)
|
||||||
}
|
}
|
||||||
inline fun SpriteBatch.drawStraightLine(x: Float, y: Float, otherEnd: Float, thickness: Float, isVertical: Boolean) {
|
inline fun SpriteBatch.drawStraightLine(x: Float, y: Float, otherEnd: Float, thickness: Float, isVertical: Boolean) {
|
||||||
if (!isVertical)
|
if (!isVertical)
|
||||||
@@ -840,11 +832,11 @@ object BlendMode {
|
|||||||
const val NORMAL = "normal"
|
const val NORMAL = "normal"
|
||||||
//const val MAX = "GL_MAX" // not supported by GLES -- use shader
|
//const val MAX = "GL_MAX" // not supported by GLES -- use shader
|
||||||
|
|
||||||
fun resolve(mode: String) {
|
fun resolve(mode: String, batch: SpriteBatch? = null) {
|
||||||
when (mode) {
|
when (mode) {
|
||||||
SCREEN -> blendScreen()
|
SCREEN -> blendScreen(batch)
|
||||||
MULTIPLY -> blendMul()
|
MULTIPLY -> blendMul(batch)
|
||||||
NORMAL -> blendNormal()
|
NORMAL -> blendNormal(batch)
|
||||||
//MAX -> blendLightenOnly() // not supported by GLES -- use shader
|
//MAX -> blendLightenOnly() // not supported by GLES -- use shader
|
||||||
else -> throw Error("Unknown blend mode: $mode")
|
else -> throw Error("Unknown blend mode: $mode")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,9 +78,9 @@ abstract class UICanvas(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Override this for the actual update. You must update uiItems by yourself. */
|
/** Override this for the actual update. Note that you must update uiItems by yourself. */
|
||||||
abstract fun updateUI(delta: Float)
|
abstract fun updateUI(delta: Float)
|
||||||
/** Override this for the actual render. You must render uiItems by yourself. */
|
/** Override this for the actual render. Note that you must render uiItems by yourself. */
|
||||||
abstract fun renderUI(batch: SpriteBatch, camera: Camera)
|
abstract fun renderUI(batch: SpriteBatch, camera: Camera)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Camera
|
|||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||||
import net.torvald.terrarum.Terrarum
|
import net.torvald.terrarum.Terrarum
|
||||||
import net.torvald.terrarum.floor
|
import net.torvald.terrarum.floor
|
||||||
|
import net.torvald.terrarum.ui.UIItemTextButton.Companion.Alignment
|
||||||
|
|
||||||
class UIItemTextArea(
|
class UIItemTextArea(
|
||||||
parentUI: UICanvas,
|
parentUI: UICanvas,
|
||||||
@@ -13,16 +14,9 @@ class UIItemTextArea(
|
|||||||
override val height: Int,
|
override val height: Int,
|
||||||
val lineGap: Int = 0,
|
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
|
val align: Alignment = Alignment.LEFT
|
||||||
) : UIItem(parentUI) {
|
) : UIItem(parentUI) {
|
||||||
|
|
||||||
|
|
||||||
enum class Align {
|
|
||||||
LEFT, CENTRE, RIGHT
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private var entireText: List<String> = listOf("") // placeholder
|
private var entireText: List<String> = listOf("") // placeholder
|
||||||
|
|
||||||
var scrollPos = 0
|
var scrollPos = 0
|
||||||
@@ -45,9 +39,9 @@ class UIItemTextArea(
|
|||||||
val textWidth = Terrarum.fontGame.getWidth(entireText[i])
|
val textWidth = Terrarum.fontGame.getWidth(entireText[i])
|
||||||
|
|
||||||
when (align) {
|
when (align) {
|
||||||
Align.LEFT -> Terrarum.fontGame.draw(batch, entireText[i], posX.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
|
Alignment.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))
|
Alignment.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))
|
Alignment.RIGHT -> Terrarum.fontGame.draw(batch, entireText[i], posX + width - textWidth.toFloat(), posY + yPtr * (Terrarum.fontGame.lineHeight + lineGap))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ open class UIItemTextButton(
|
|||||||
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
|
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
|
||||||
val inactiveCol: Color = defaultInactiveCol,
|
val inactiveCol: Color = defaultInactiveCol,
|
||||||
val preGapX: Int = 0,
|
val preGapX: Int = 0,
|
||||||
val postGapX: Int = 0
|
val postGapX: Int = 0,
|
||||||
|
|
||||||
|
val alignment: Alignment = Alignment.CENTRE
|
||||||
) : UIItem(parentUI) {
|
) : UIItem(parentUI) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -36,6 +38,10 @@ open class UIItemTextButton(
|
|||||||
val height = font.lineHeight.toInt() * 2
|
val height = font.lineHeight.toInt() * 2
|
||||||
val defaultInactiveCol: Color = Color(0xc8c8c8_ff.toInt())
|
val defaultInactiveCol: Color = Color(0xc8c8c8_ff.toInt())
|
||||||
val defaultHighlightCol: Color = Color(0x00f8ff_ff)
|
val defaultHighlightCol: Color = Color(0x00f8ff_ff)
|
||||||
|
|
||||||
|
enum class Alignment {
|
||||||
|
CENTRE, LEFT, RIGHT
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Actually displayed text (changes with the app language) */
|
/** Actually displayed text (changes with the app language) */
|
||||||
@@ -74,7 +80,11 @@ open class UIItemTextButton(
|
|||||||
|
|
||||||
font.draw(batch,
|
font.draw(batch,
|
||||||
label,
|
label,
|
||||||
posX.toFloat() + width.minus(textW).div(2) + (preGapX - postGapX).div(2),
|
when (alignment) {
|
||||||
|
Alignment.CENTRE -> posX.toFloat() + width.minus(textW).div(2) + (preGapX - postGapX).div(2)
|
||||||
|
Alignment.LEFT -> posX.toFloat() + preGapX
|
||||||
|
Alignment.RIGHT -> width - postGapX - textW.toFloat()
|
||||||
|
},
|
||||||
posY.toFloat() + height / 4
|
posY.toFloat() + height / 4
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,9 @@ class UIItemTextButtonList(
|
|||||||
val inactiveCol: Color = Color(0xc0c0c0_ff.toInt()),
|
val inactiveCol: Color = Color(0xc0c0c0_ff.toInt()),
|
||||||
val backgroundCol: Color = Color(0x242424_80),
|
val backgroundCol: Color = Color(0x242424_80),
|
||||||
val backgroundBlendMode: String = BlendMode.NORMAL,
|
val backgroundBlendMode: String = BlendMode.NORMAL,
|
||||||
val kinematic: Boolean = false
|
val kinematic: Boolean = false,
|
||||||
|
|
||||||
|
val alignment: UIItemTextButton.Companion.Alignment = UIItemTextButton.Companion.Alignment.CENTRE
|
||||||
) : UIItem(parentUI) {
|
) : UIItem(parentUI) {
|
||||||
|
|
||||||
val iconToTextGap = 20
|
val iconToTextGap = 20
|
||||||
@@ -71,7 +73,8 @@ class UIItemTextButtonList(
|
|||||||
highlightBackBlendMode = highlightBackBlendMode,
|
highlightBackBlendMode = highlightBackBlendMode,
|
||||||
inactiveCol = inactiveCol,
|
inactiveCol = inactiveCol,
|
||||||
preGapX = pregap,
|
preGapX = pregap,
|
||||||
postGapX = postgap
|
postGapX = postgap,
|
||||||
|
alignment = alignment
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -89,7 +92,8 @@ class UIItemTextButtonList(
|
|||||||
highlightBackBlendMode = activeBackBlendMode, // we are using custom highlighter
|
highlightBackBlendMode = activeBackBlendMode, // we are using custom highlighter
|
||||||
inactiveCol = inactiveCol,
|
inactiveCol = inactiveCol,
|
||||||
preGapX = pregap,
|
preGapX = pregap,
|
||||||
postGapX = postgap
|
postGapX = postgap,
|
||||||
|
alignment = alignment
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user