F3 moved to PostProcessor; palette UI for buildingmaker

This commit is contained in:
minjaesong
2019-02-03 17:01:27 +09:00
parent daf5c02605
commit e3ed712a42
19 changed files with 427 additions and 156 deletions

View File

@@ -15,8 +15,10 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import net.torvald.dataclass.ArrayListMap;
import net.torvald.getcpuname.GetCpuName;
import net.torvald.terrarum.gamecontroller.KeyToggler;
import net.torvald.terrarum.imagefont.TinyAlphNum;
import net.torvald.terrarum.modulebasegame.Ingame;
import net.torvald.terrarum.modulebasegame.IngameRenderer;
import net.torvald.terrarum.utils.JsonFetcher;
import net.torvald.terrarum.utils.JsonWriter;
@@ -114,6 +116,15 @@ public class AppLoader implements ApplicationListener {
public static final String COPYRIGHT_DATE_NAME = "Copyright 2013-2019 Torvald (minjaesong)";
public static String GAME_LOCALE = System.getProperty("user.language") + System.getProperty("user.country");
public static final String systemArch = System.getProperty("os.arch");
public static String processor;
public static String processorVendor;
public static String renderer;
public static String rendererVendor;
public static final boolean is32BitJVM = !System.getProperty("sun.arch.data.model").contains("64");
public static final float TV_SAFE_GRAPHICS = 0.05f; // as per EBU recommendation (https://tech.ebu.ch/docs/r/r095.pdf)
public static final float TV_SAFE_ACTION = 0.035f; // as per EBU recommendation (https://tech.ebu.ch/docs/r/r095.pdf)
@@ -186,6 +197,12 @@ public class AppLoader implements ApplicationListener {
readConfigJson();
try { processor = GetCpuName.getModelName(); }
catch (IOException e1) { processor = "Unknown"; }
try { processorVendor = GetCpuName.getCPUID(); }
catch (IOException e2) { processorVendor = "Unknown"; }
ShaderProgram.pedantic = false;
LwjglApplicationConfiguration appConfig = new LwjglApplicationConfiguration();
@@ -213,7 +230,7 @@ public class AppLoader implements ApplicationListener {
if (args.length == 1 && args[0].equals("isdev=true")) {
IS_DEVELOPMENT_BUILD = true;
// safe area box
KeyToggler.INSTANCE.forceSet(Input.Keys.F11, true);
//KeyToggler.INSTANCE.forceSet(Input.Keys.F11, true);
}
new LwjglApplication(new AppLoader(appConfig), appConfig);
@@ -302,8 +319,15 @@ public class AppLoader implements ApplicationListener {
}
// set up renderer info variables
renderer = Gdx.graphics.getGLVersion().getRendererString();
rendererVendor = Gdx.graphics.getGLVersion().getVendorString();
// make loading list
}
/**
@@ -364,6 +388,8 @@ public class AppLoader implements ApplicationListener {
screen.render((float) UPDATE_RATE);
}
KeyToggler.INSTANCE.update(screen instanceof Ingame);
// nested FBOs are just not a thing in GL!
net.torvald.terrarum.FrameBufferManager.end();
@@ -492,6 +518,8 @@ public class AppLoader implements ApplicationListener {
this.screen.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
System.gc();
printdbg(this, "Screen transisiton complete: " + this.screen.getClass().getCanonicalName());
}

View File

@@ -12,6 +12,7 @@ import com.badlogic.gdx.graphics.glutils.ShaderProgram
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.math.Matrix4
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.ui.BasicDebugInfoWindow
/**
* Must be called by the App Loader
@@ -34,12 +35,16 @@ object PostProcessor {
private val safeAreaCol = Color(0xffffff66.toInt())
private val safeAreaCol2 = Color(0xffffff44.toInt())
private val debugUI = BasicDebugInfoWindow()
fun draw(projMat: Matrix4, fbo: FrameBuffer) {
// init
if (!init) {
init = true
debugUI.setPosition(0, 0)
batch = SpriteBatch()
camera = OrthographicCamera(AppLoader.screenW.toFloat(), AppLoader.screenH.toFloat())
camera.setToOrtho(true)
@@ -51,78 +56,96 @@ object PostProcessor {
}
debugUI.update(Gdx.graphics.deltaTime)
AppLoader.measureDebugTime("Renderer.PostProcessor") {
gdxClearAndSetBlend(.094f, .094f, .094f, 0f)
val shader: ShaderProgram? =
if (AppLoader.getConfigBoolean("fxdither"))
AppLoader.shaderHicolour
else
null
fbo.colorBufferTexture.bind(0)
shader?.begin()
shader?.setUniformMatrix("u_projTrans", projMat)
shader?.setUniformi("u_texture", 0)
AppLoader.fullscreenQuad.render(shader, GL20.GL_TRIANGLES)
shader?.end()
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
postShader(projMat, fbo)
if (AppLoader.IS_DEVELOPMENT_BUILD && KeyToggler.isOn(Input.Keys.F11)) {
val tvSafeAreaW = AppLoader.getTvSafeGraphicsWidth().toFloat()
val tvSafeAreaH = AppLoader.getTvSafeGraphicsHeight().toFloat()
val tvSafeArea2W = AppLoader.getTvSafeActionWidth().toFloat()
val tvSafeArea2H = AppLoader.getTvSafeActionHeight().toFloat()
drawSafeArea()
}
shapeRenderer.inUse(ShapeRenderer.ShapeType.Line) {
shapeRenderer.color = safeAreaCol2
shapeRenderer.rect(
tvSafeArea2W, tvSafeArea2H, AppLoader.screenW - 2 * tvSafeArea2W, AppLoader.screenH - 2 * tvSafeArea2H
)
if (KeyToggler.isOn(Input.Keys.F3)) {
if (!debugUI.isOpened && !debugUI.isOpening) debugUI.setAsOpen()
batch.inUse { debugUI.renderUI(batch, camera) }
}
else {
if (!debugUI.isClosed && !debugUI.isClosing) debugUI.setAsClose()
}
}
}
shapeRenderer.color = safeAreaCol
shapeRenderer.rect(
tvSafeAreaW, tvSafeAreaH, AppLoader.screenW - 2 * tvSafeAreaW, AppLoader.screenH - 2 * tvSafeAreaH
)
private fun postShader(projMat: Matrix4, fbo: FrameBuffer) {
val shader: ShaderProgram? =
if (AppLoader.getConfigBoolean("fxdither"))
AppLoader.shaderHicolour
else
null
shapeRenderer.color = defaultResCol
shapeRenderer.rect(
(AppLoader.screenW - AppLoader.minimumW).div(2).toFloat(),
(AppLoader.screenH - AppLoader.minimumH).div(2).toFloat(),
AppLoader.minimumW.toFloat(),
AppLoader.minimumH.toFloat()
)
}
fbo.colorBufferTexture.bind(0)
try {
batch.inUse {
batch.color = safeAreaCol
AppLoader.fontSmallNumbers.draw(
batch, safeAreaStr,
tvSafeAreaW, tvSafeAreaH - 10
)
shader?.begin()
shader?.setUniformMatrix("u_projTrans", projMat)
shader?.setUniformi("u_texture", 0)
AppLoader.fullscreenQuad.render(shader, GL20.GL_TRIANGLES)
shader?.end()
batch.color = defaultResCol
AppLoader.fontSmallNumbers.draw(
batch, defaultResStr,
(AppLoader.screenW - AppLoader.minimumW).div(2).toFloat(),
(AppLoader.screenH - AppLoader.minimumH).div(2).minus(10).toFloat()
)
}
}
catch (doNothing: NullPointerException) { }
finally {
// one-time call, caused by catching NPE before batch ends
if (batch.isDrawing) {
batch.end()
}
}
Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0) // so that batch that comes next will bind any tex to it
}
private fun drawSafeArea() {
val tvSafeAreaW = AppLoader.getTvSafeGraphicsWidth().toFloat()
val tvSafeAreaH = AppLoader.getTvSafeGraphicsHeight().toFloat()
val tvSafeArea2W = AppLoader.getTvSafeActionWidth().toFloat()
val tvSafeArea2H = AppLoader.getTvSafeActionHeight().toFloat()
shapeRenderer.inUse(ShapeRenderer.ShapeType.Line) {
shapeRenderer.color = safeAreaCol2
shapeRenderer.rect(
tvSafeArea2W, tvSafeArea2H, AppLoader.screenW - 2 * tvSafeArea2W, AppLoader.screenH - 2 * tvSafeArea2H
)
shapeRenderer.color = safeAreaCol
shapeRenderer.rect(
tvSafeAreaW, tvSafeAreaH, AppLoader.screenW - 2 * tvSafeAreaW, AppLoader.screenH - 2 * tvSafeAreaH
)
shapeRenderer.color = defaultResCol
shapeRenderer.rect(
(AppLoader.screenW - AppLoader.minimumW).div(2).toFloat(),
(AppLoader.screenH - AppLoader.minimumH).div(2).toFloat(),
AppLoader.minimumW.toFloat(),
AppLoader.minimumH.toFloat()
)
}
try {
batch.inUse {
batch.color = safeAreaCol
AppLoader.fontSmallNumbers.draw(
batch, safeAreaStr,
tvSafeAreaW, tvSafeAreaH - 10
)
batch.color = defaultResCol
AppLoader.fontSmallNumbers.draw(
batch, defaultResStr,
(AppLoader.screenW - AppLoader.minimumW).div(2).toFloat(),
(AppLoader.screenH - AppLoader.minimumH).div(2).minus(10).toFloat()
)
}
}
catch (doNothing: NullPointerException) { }
finally {
// one-time call, caused by catching NPE before batch ends
if (batch.isDrawing) {
batch.end()
}
}
}

View File

@@ -14,7 +14,6 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.utils.GdxRuntimeException
import com.jme3.math.FastMath
import net.torvald.dataclass.CircularArray
import net.torvald.getcpuname.GetCpuName
import net.torvald.random.HQRNG
import net.torvald.terrarum.AppLoader.*
import net.torvald.terrarum.gameactors.Actor
@@ -175,15 +174,6 @@ object Terrarum : Screen {
const val NAME = AppLoader.GAME_NAME
val systemArch = System.getProperty("os.arch")
val processor = GetCpuName.getModelName()
val processorVendor = GetCpuName.getCPUID()
lateinit var renderer: String
lateinit var rendererVendor: String
val is32BitJVM = !System.getProperty("sun.arch.data.model").contains("64")
lateinit var shaderBlur: ShaderProgram
lateinit var shaderBayer: ShaderProgram
lateinit var shaderSkyboxFill: ShaderProgram
@@ -283,10 +273,6 @@ object Terrarum : Screen {
println("GL_MAX_TEXTURE_SIZE = $GL_MAX_TEXTURE_SIZE")
println("GL info:\n$glInfo") // debug info
// set up renderer info variables
renderer = Gdx.graphics.glVersion.rendererString
rendererVendor = Gdx.graphics.glVersion.vendorString
if (GL_VERSION < MINIMAL_GL_VERSION || GL_MAX_TEXTURE_SIZE < MINIMAL_GL_MAX_TEXTURE_SIZE) {
// TODO notify properly

View File

@@ -210,7 +210,7 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
var i = 0L
while (updateAkku >= delta) {
updateScreen(delta)
AppLoader.measureDebugTime("Ingame.update") { updateScreen(delta) }
updateAkku -= delta
i += 1
}
@@ -218,7 +218,10 @@ class TitleScreen(val batch: SpriteBatch) : Screen {
// render? just do it anyway
renderScreen()
AppLoader.measureDebugTime("Ingame.render") { renderScreen() }
AppLoader.setDebugTime("Ingame.render-Light",
(AppLoader.debugTimers["Ingame.render"] as Long) - ((AppLoader.debugTimers["Renderer.LightTotal"] as? Long) ?: 0)
)
}
fun updateScreen(delta: Float) {

View File

@@ -92,9 +92,6 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
ingame.uiContainer.forEach { it.keyDown(keycode) } // for KeyboardControlled UIcanvases
// Debug UIs
if (keycode == Input.Keys.F3) {
ingame.debugWindow.toggleOpening()
}
if (keycode == Input.Keys.GRAVE) {
ingame.consoleHandler.toggleOpening()
}

View File

@@ -259,23 +259,27 @@ object ItemCodex {
fun getItemImage(item: GameItem?): TextureRegion? {
if (item == null) return null
return getItemImage(item.originalID)
}
fun getItemImage(itemOriginalID: Int): TextureRegion {
// terrain
if (item.originalID in ITEM_TILES) {
if (itemOriginalID in ITEM_TILES) {
return BlocksDrawer.tilesTerrain.get(
(item.originalID % 16) * 16,
item.originalID / 16
(itemOriginalID % 16) * 16,
itemOriginalID / 16
)
}
// wall
else if (item.originalID in ITEM_WALLS) {
else if (itemOriginalID in ITEM_WALLS) {
return BlocksDrawer.tileItemWall.get(
(item.originalID.minus(ITEM_WALLS.first) % 16),
(item.originalID.minus(ITEM_WALLS.first) / 16)
(itemOriginalID.minus(ITEM_WALLS.first) % 16),
(itemOriginalID.minus(ITEM_WALLS.first) / 16)
)
}
// wire
else if (item.originalID in ITEM_WIRES) {
return BlocksDrawer.tilesWire.get((item.originalID % 16) * 16, item.originalID / 16)
else if (itemOriginalID in ITEM_WIRES) {
return BlocksDrawer.tilesWire.get((itemOriginalID % 16) * 16, itemOriginalID / 16)
}
// TODO get it real, using originalID...?
else

View File

@@ -7,11 +7,11 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.modulebasegame.gameactors.ActorHumanoid
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
import net.torvald.terrarum.modulebasegame.ui.Notification
import net.torvald.terrarum.modulebasegame.ui.UIEditorPalette
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINSMenu
@@ -26,17 +26,18 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
private val menuYaml = Yaml("""
- File
- New
- New flat ter.
- New rand. ter.
- Export…
- Export sel…
- Import…
- Save world
- Load world
- Save terrain
- Load terrain
- Exit to Title : net.torvald.terrarum.modulebasegame.YamlCommandExit
- Tool
- Pencil
- Pencil : net.torvald.terrarum.modulebasegame.YamlCommandToolPencil
- Eyedropper
- Select mrq.
- Select mrq. : net.torvald.terrarum.modulebasegame.YamlCommandToolMarquee
- Move
- Undo
- Redo
@@ -81,23 +82,29 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
val uiToolbox = UINSMenu("Menu", 100, menuYaml)
val notifier = Notification()
val uiPalette = UIEditorPalette()
val uiContainer = ArrayList<UICanvas>()
var currentPenMode = PENMODE_PENCIL
val blockPointingCursor = object : ActorWithBody(Actor.RenderOrder.OVERLAY) {
override var referenceID: ActorID? = Terrarum.generateUniqueReferenceID(renderOrder)
val body = TextureRegionPack(Gdx.files.internal("assets/graphics/blocks/block_markings_common.tga"), 16, 16)
override val hitbox = Hitbox(0.0, 0.0, 16.0, 16.0)
init {
this.actorValue[AVKey.LUMR] = 1.0
this.actorValue[AVKey.LUMG] = 1.0
}
override fun drawBody(batch: SpriteBatch) {
batch.color = Color.YELLOW
batch.draw(body.get(0, 0), hitbox.startX.toFloat(), hitbox.startY.toFloat())
batch.color = toolCursorColour[currentPenMode]
batch.draw(body.get(currentPenMode, 0), hitbox.startX.toFloat(), hitbox.startY.toFloat())
}
override fun drawGlow(batch: SpriteBatch) { }
@@ -120,6 +127,16 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
}
}
companion object {
const val PENMODE_PENCIL = 0
const val PENMODE_MARQUEE = 1
val toolCursorColour = arrayOf(
Color.YELLOW,
Color.MAGENTA
)
}
private val actorsRenderOverlay = ArrayList<ActorWithBody>()
init {
@@ -129,6 +146,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
actorsRenderOverlay.add(blockPointingCursor)
uiContainer.add(uiToolbox)
uiContainer.add(uiPalette)
uiContainer.add(notifier)
@@ -137,6 +155,9 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
uiToolbox.isVisible = true
uiToolbox.invocationArgument = arrayOf(this)
uiPalette.setPosition(Terrarum.WIDTH - uiPalette.width, 0)
uiPalette.isVisible = true
notifier.setPosition(
(Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height)
@@ -153,23 +174,34 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
super.show()
}
private var updateAkku = 0.0
override fun render(delta: Float) {
Gdx.graphics.setTitle(Ingame.getCanonicalTitle())
// ASYNCHRONOUS UPDATE AND RENDER //
val dt = Gdx.graphics.deltaTime
updateAkku += dt
// TODO async update
updateGame(delta)
var i = 0L
while (updateAkku >= delta) {
AppLoader.measureDebugTime("Ingame.update") { updateGame(delta) }
updateAkku -= delta
i += 1
}
AppLoader.setDebugTime("Ingame.updateCounter", i)
// render? just do it anyway
renderGame()
AppLoader.measureDebugTime("Ingame.render") { renderGame() }
AppLoader.setDebugTime("Ingame.render-Light",
(AppLoader.debugTimers["Ingame.render"] as Long) - ((AppLoader.debugTimers["Renderer.LightTotal"] as? Long) ?: 0)
)
}
private fun updateGame(delta: Float) {
KeyToggler.update(false)
WeatherMixer.update(delta, actorNowPlaying, gameWorld)
blockPointingCursor.update(delta)
actorNowPlaying?.update(delta)
@@ -187,6 +219,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
uiToolbox.setPosition(0, 0)
notifier.setPosition(
(Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height)
println("[BuildingMaker] Resize event")
}
@@ -292,4 +325,16 @@ class YamlCommandSetTimeNight : YamlInvokable {
override fun invoke(args: Array<Any>) {
(args[0] as BuildingMaker).gameWorld.time.setTimeOfToday(WorldTime.parseTime("0h30"))
}
}
class YamlCommandToolPencil : YamlInvokable {
override fun invoke(args: Array<Any>) {
(args[0] as BuildingMaker).currentPenMode = BuildingMaker.PENMODE_PENCIL
}
}
class YamlCommandToolMarquee : YamlInvokable {
override fun invoke(args: Array<Any>) {
(args[0] as BuildingMaker).currentPenMode = BuildingMaker.PENMODE_MARQUEE
}
}

View File

@@ -13,7 +13,6 @@ import net.torvald.terrarum.console.Authenticator
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gamecontroller.IngameController
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.modulebasegame.console.AVTracker
@@ -26,7 +25,6 @@ import net.torvald.terrarum.modulebasegame.ui.*
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
import net.torvald.terrarum.modulebasegame.worldgenerator.RoguelikeRandomiser
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator
import net.torvald.terrarum.ui.BasicDebugInfoWindow
import net.torvald.terrarum.ui.ConsoleWindow
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
@@ -97,7 +95,6 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
lateinit var debugWindow: UICanvas
lateinit var notifier: UICanvas
lateinit var uiPieMenu: UICanvas
@@ -278,10 +275,6 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
consoleHandler.setPosition(0, 0)
// init debug window
debugWindow = BasicDebugInfoWindow()
debugWindow.setPosition(0, 0)
// init notifier
notifier = Notification()
notifier.setPosition(
@@ -369,7 +362,6 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// these need to appear on top of any others
uiContainer.add(notifier)
uiContainer.add(debugWindow)
LightmapRenderer.fireRecalculateEvent()
@@ -469,7 +461,6 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
particlesActive = 0
KeyToggler.update()
ingameController.update(delta)

View File

@@ -17,8 +17,11 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
*/
object ItemSlotImageFactory {
val colourBlack = Color(0x404040_FF)
val colourWhite = Color(0xC0C0C0_FF.toInt())
val CELLCOLOUR_BLACK_OPAQUE = Color(0x404040_FF)
val CELLCOLOUR_WHITE_OPAQUE = Color(0xC0C0C0_FF.toInt())
val CELLCOLOUR_BLACK = Color(0x404040_88)
val CELLCOLOUR_WHITE = Color(0xC0C0C0_88.toInt())
val slotImage = TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slots_atlas.tga"), 38, 38) // must have same w/h as slotLarge

View File

@@ -0,0 +1,164 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.fillRect
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
import net.torvald.terrarum.serialise.toLittle
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINSMenu
/**
* Created by minjaesong on 2019-02-03.
*/
class UIEditorPalette : UICanvas() {
override var width = 36
override var height = 72
override var openCloseTime = 0f
val LINE_HEIGHT = 24
val TEXT_OFFSETX = 3f
val TEXT_OFFSETY = (LINE_HEIGHT - Terrarum.fontGame.lineHeight) / 2f
fun mouseOnTitleBar() =
relativeMouseX in 0 until width && relativeMouseY in 0 until LINE_HEIGHT
var fore = Block.STONE_BRICKS
var back = Block.DIRT
private val titleText = "Pal."
private val swapIcon: Texture
init {
// make swap icon, because I can't be bothered to make yet another tga
val swapIconPixmap = Pixmap(12, 12, Pixmap.Format.RGBA8888)
swapIconPixmap.pixels.rewind()
arrayOf(
0b001000000000,
0b011000000000,
0b111111111100,
0b011000000100,
0b001000000100,
0b000000000100,
0b000000000100,
0b000000000100,
0b000000000100,
0b000000011111,
0b000000001110,
0b000000000100
).reversed().forEachIndexed { index, bits ->
for (shiftmask in 11 downTo 0) {
val bit = bits.ushr(shiftmask).and(1) == 1
swapIconPixmap.pixels.put((if (bit) -1 else 0).toLittle())
}
}
swapIconPixmap.pixels.rewind()
swapIcon = Texture(swapIconPixmap)
swapIconPixmap.dispose()
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
// draw title bar
batch.color = UINSMenu.DEFAULT_TITLEBACKCOL
blendNormal(batch)
batch.fillRect(0f, 0f, width.toFloat(), LINE_HEIGHT.toFloat())
// draw "Pal."
batch.color = UINSMenu.DEFAULT_TITLETEXTCOL
Terrarum.fontGame.draw(batch, titleText, TEXT_OFFSETX, TEXT_OFFSETY)
// draw background
batch.color = CELLCOLOUR_BLACK
batch.fillRect(0f, LINE_HEIGHT.toFloat(), 36f, 48f)
// draw back and fore selection
batch.color = Color.WHITE
// TODO carve the overlap
batch.draw(ItemCodex.getItemImage(back), 14f, 41f)
batch.draw(ItemCodex.getItemImage(fore), 6f, 33f)
Terrarum.fontSmallNumbers.draw(batch, fore.toString(), 3f, 61f)
// draw swap icon
batch.color = Color.WHITE
batch.draw(swapIcon, 18f, 26f)
}
override fun updateUI(delta: Float) {
}
fun swapForeAndBack() {
// xor used, because why not?
fore = fore xor back
back = back xor fore
fore = fore xor back
}
override fun doOpening(delta: Float) {
}
override fun doClosing(delta: Float) {
}
override fun endOpening(delta: Float) {
}
override fun endClosing(delta: Float) {
}
override fun dispose() {
}
private var dragOriginX = 0 // relative mousepos
private var dragOriginY = 0 // relative mousepos
private var dragForReal = false
private var swapDown = false
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
if (mouseInScreen(screenX, screenY)) {
if (dragForReal) {
handler.setPosition(screenX - dragOriginX, screenY - dragOriginY)
//println("drag $screenX, $screenY")
}
}
return true
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (mouseOnTitleBar()) {
dragOriginX = relativeMouseX
dragOriginY = relativeMouseY
dragForReal = true
}
else {
dragForReal = false
}
// make swap button work
if (!swapDown && (relativeMouseX in 14..35 && relativeMouseY in 24..32 || relativeMouseX in 22..35 && relativeMouseY in 33..40)) {
swapDown = true
swapForeAndBack()
}
return true
}
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
swapDown = false
return true
}
}

View File

@@ -10,6 +10,7 @@ import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
import net.torvald.terrarum.ui.UIItem
import net.torvald.terrarum.ui.UIItemImageButton
import java.util.*
@@ -39,7 +40,7 @@ class UIItemInventoryDynamicList(
override val width = WIDTH
override val height = HEIGHT
val backColour = Color(0x404040_88)
val backColour = CELLCOLOUR_BLACK
private val catArrangement = parentUI.catArrangement

View File

@@ -8,6 +8,7 @@ import net.torvald.terrarum.gameactors.ActorWBMovable
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.itemproperties.ItemCodex
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_BLACK
import net.torvald.terrarum.ui.UIItem
/**
@@ -37,7 +38,7 @@ class UIItemInventoryEquippedView(
lateinit var inventorySortList: Array<GameItem?>
private var rebuildList = true
val spriteViewBackCol: Color; get() = Color(0x404040_88.toInt())//Color(0xd4d4d4_ff.toInt())
val spriteViewBackCol: Color = CELLCOLOUR_BLACK
private val itemGrid = Array<UIItemInventoryCellBase>(2 * 6) {
UIItemInventoryElemSimple(
@@ -49,7 +50,7 @@ class UIItemInventoryEquippedView(
itemImage = null,
mouseoverBackCol = Color(0x282828_ff),
mouseoverBackBlendMode = BlendMode.SCREEN,
backCol = Color(0x404040_88),
backCol = CELLCOLOUR_BLACK,
backBlendMode = BlendMode.NORMAL,
drawBackOnNull = true
)

View File

@@ -2,25 +2,26 @@ package net.torvald.terrarum.modulebasegame.weather
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.utils.GdxRuntimeException
import net.torvald.terrarum.utils.JsonFetcher
import net.torvald.colourutil.*
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.Texture
import net.torvald.colourutil.CIELuvUtil
import net.torvald.random.HQRNG
import net.torvald.terrarum.*
import net.torvald.terrarum.console.CommandDict
import net.torvald.terrarum.console.SetGlobalLightOverride
import net.torvald.terrarum.GdxColorMap
import net.torvald.terrarum.ModMgr
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.modulebasegame.gameactors.ParticleMegaRain
import net.torvald.terrarum.gamecontroller.KeyToggler
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.RNGConsumer
import net.torvald.terrarum.modulebasegame.gameactors.ParticleMegaRain
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator
import net.torvald.terrarum.utils.JsonFetcher
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.terrarum.modulebasegame.worldgenerator.WorldGenerator
import java.io.File
import java.util.*
@@ -96,7 +97,7 @@ internal object WeatherMixer : RNGConsumer {
// test rain toggled by F2
if (KeyToggler.isOn(Input.Keys.F2)) {
if (KeyToggler.isOn(Input.Keys.F2) && Terrarum.ingame is Ingame) {
val playerPosX = player.hitbox.centeredX
val playerPosY = player.hitbox.centeredY
kotlin.repeat(7) {

View File

@@ -8,6 +8,7 @@ import com.jme3.math.FastMath
import net.torvald.terrarum.*
import net.torvald.terrarum.Terrarum.mouseTileX
import net.torvald.terrarum.Terrarum.mouseTileY
import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
@@ -19,8 +20,8 @@ import net.torvald.terrarum.worlddrawer.WorldCamera
*/
class BasicDebugInfoWindow : UICanvas() {
override var width: Int = Terrarum.WIDTH
override var height: Int = Terrarum.HEIGHT
override var width: Int = AppLoader.screenW
override var height: Int = AppLoader.screenH
override var openCloseTime: Float = 0f
@@ -30,14 +31,17 @@ class BasicDebugInfoWindow : UICanvas() {
private var xdelta = 0.0
private var ydelta = 0.0
private val ingame = Terrarum.ingame!! as Ingame
private val ingame: IngameInstance?
get() = Terrarum.ingame
private val world: GameWorldExtension
get() = Terrarum.ingame!!.world as GameWorldExtension
private val world: GameWorld?
get() = Terrarum.ingame?.world
private val world2: GameWorldExtension?
get() = Terrarum.ingame?.world as GameWorldExtension?
override fun updateUI(delta: Float) {
val player = ingame.actorNowPlaying
val player = ingame?.actorNowPlaying
val hitbox = player?.hitbox
if (hitbox != null) {
@@ -65,7 +69,7 @@ class BasicDebugInfoWindow : UICanvas() {
}
override fun renderUI(batch: SpriteBatch, camera: Camera) {
val player = ingame.actorNowPlaying
val player = ingame?.actorNowPlaying
batch.color = Color(0xFFEE88FF.toInt())
@@ -144,11 +148,14 @@ class BasicDebugInfoWindow : UICanvas() {
else "$rawR $rawG $rawB $rawA"
printLine(batch, 8, "light@cursor $ccG$lightVal")
val tileNum = ingame.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
val fluid = ingame.world.getFluid(mouseTileX, mouseTileY)
if (ingame != null) {
val tileNum = ingame!!.world.getTileFromTerrain(mouseTileX, mouseTileY) ?: -1
val fluid = ingame!!.world.getFluid(mouseTileX, mouseTileY)
printLine(batch, 9, "tile@cursor $ccG$tileNum ($mtX, $mtY)")
printLine(batch, 10, "fluid@cursor ${ccY}Type $ccM${fluid.type.value} ${ccY}Fill $ccG${fluid.amount}f")
printLine(batch, 9, "tile@cursor $ccG$tileNum ($mtX, $mtY)")
printLine(batch, 10, "fluid@cursor ${ccY}Type $ccM${fluid.type.value} ${ccY}Fill $ccG${fluid.amount}f")
}
// print time
@@ -166,8 +173,10 @@ class BasicDebugInfoWindow : UICanvas() {
//printLineColumn(batch, 2, 1, "VSync $ccG" + Terrarum.appgc.isVSyncRequested)
//printLineColumn(batch, 2, 2, "Env colour temp $ccG" + FeaturesDrawer.colTemp)
printLineColumn(batch, 2, 5, "Time $ccG${world.time.todaySeconds.toString().padStart(5, '0')}" +
" (${world.time.getFormattedTime()})")
if (world != null) {
printLineColumn(batch, 2, 5, "Time $ccG${world2!!.time.todaySeconds.toString().padStart(5, '0')}" +
" (${world2!!.time.getFormattedTime()})")
}
if (player != null) {
printLineColumn(batch, 2, 6, "Mass $ccG${player.mass}")
@@ -216,15 +225,18 @@ class BasicDebugInfoWindow : UICanvas() {
* Bottom left
*/
Terrarum.fontSmallNumbers.draw(batch, "${ccY}Actors total $ccG${ingame.actorContainer.size + ingame.actorContainerInactive.size}",
2f, Terrarum.HEIGHT - 10f)
Terrarum.fontSmallNumbers.draw(batch, "${ccY}Active $ccG${ingame.actorContainer.size}",
(2 + 17*8).toFloat(), Terrarum.HEIGHT - 10f)
Terrarum.fontSmallNumbers.draw(batch, "${ccY}Dormant $ccG${ingame.actorContainerInactive.size}",
(2 + 28*8).toFloat(), Terrarum.HEIGHT - 10f)
Terrarum.fontSmallNumbers.draw(batch, "${ccM}Particles $ccG${ingame.particlesActive}",
(2 + 41*8).toFloat(), Terrarum.HEIGHT - 10f)
if (ingame != null) {
Terrarum.fontSmallNumbers.draw(batch, "${ccY}Actors total $ccG${ingame!!.actorContainer.size + ingame!!.actorContainerInactive.size}",
2f, Terrarum.HEIGHT - 10f)
Terrarum.fontSmallNumbers.draw(batch, "${ccY}Active $ccG${ingame!!.actorContainer.size}",
(2 + 17 * 8).toFloat(), Terrarum.HEIGHT - 10f)
Terrarum.fontSmallNumbers.draw(batch, "${ccY}Dormant $ccG${ingame!!.actorContainerInactive.size}",
(2 + 28 * 8).toFloat(), Terrarum.HEIGHT - 10f)
if (ingame is Ingame) {
Terrarum.fontSmallNumbers.draw(batch, "${ccM}Particles $ccG${(ingame as Ingame).particlesActive}",
(2 + 41 * 8).toFloat(), Terrarum.HEIGHT - 10f)
}
}
/**
* Bottom right
@@ -235,8 +247,8 @@ class BasicDebugInfoWindow : UICanvas() {
(Terrarum.WIDTH - 2 - totalHardwareName.length * 8).toFloat(), Terrarum.HEIGHT - 10f)
}
private val processorName = Terrarum.processor.replace(Regex(""" Processor|( CPU)? @ [0-9.]+GHz"""), "")
private val rendererName = Terrarum.renderer
private val processorName = AppLoader.processor.replace(Regex(""" Processor|( CPU)? @ [0-9.]+GHz"""), "")
private val rendererName = AppLoader.renderer
private val totalHardwareName = "$processorName $rendererName"
private fun printLine(batch: SpriteBatch, l: Int, s: String) {

View File

@@ -30,7 +30,7 @@ class UIItemList<Item: UIItem>(
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 backgroundCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL,
val backgroundBlendMode: String = BlendMode.NORMAL,
val kinematic: Boolean = false,
val border: Int = 0

View File

@@ -37,7 +37,7 @@ class UIItemTextButtonList(
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 backgroundCol: Color = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL,
val backgroundBlendMode: String = BlendMode.NORMAL,
val kinematic: Boolean = false,
@@ -45,6 +45,10 @@ class UIItemTextButtonList(
val itemHitboxSize: Int = UIItemTextButton.height
) : UIItem(parentUI) {
companion object {
val DEFAULT_BACKGROUNDCOL = Color(0x242424_80)
}
// deal with the moving position
override var oldPosX = posX
override var oldPosY = posY

View File

@@ -16,13 +16,18 @@ class UINSMenu(
/** Optional instance of YamlInvokable can be used */
treeRepresentation: Yaml,
val titleBackCol: Color = Color(0f,0f,0f,.77f),
val titleTextCol: Color = Color.WHITE,
val titleBackCol: Color = DEFAULT_TITLEBACKCOL,
val titleTextCol: Color = DEFAULT_TITLETEXTCOL,
val titleBlendMode: String = BlendMode.NORMAL,
val allowDrag: Boolean = true
) : UICanvas() {
companion object {
val DEFAULT_TITLEBACKCOL = Color(0f,0f,0f,.77f)
val DEFAULT_TITLETEXTCOL = Color.WHITE
}
override var openCloseTime: Second = 0f
val LINE_HEIGHT = 24
val TEXT_OFFSETX = 3f
@@ -76,7 +81,7 @@ class UINSMenu(
uiWidth, listHeight,
textAreaWidth = listWidth,
alignment = UIItemTextButton.Companion.Alignment.LEFT,
activeBackCol = Color(0x242424_80),//Color(1f,0f,.75f,1f),
activeBackCol = UIItemTextButtonList.DEFAULT_BACKGROUNDCOL,//Color(1f,0f,.75f,1f),
inactiveCol = Color(.94f,.94f,.94f,1f),
itemHitboxSize = LINE_HEIGHT

Binary file not shown.