mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
F3 moved to PostProcessor; palette UI for buildingmaker
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
164
src/net/torvald/terrarum/modulebasegame/ui/UIEditorPalette.kt
Normal file
164
src/net/torvald/terrarum/modulebasegame/ui/UIEditorPalette.kt
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user