From ed9d8cffd683c9eb0649f866bfc84f1aa7b50b37 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 19 Jan 2025 19:54:40 +0900 Subject: [PATCH] more codes --- .../terrarum-sans-bitmap/puae000-e0ff.tga | 2 +- assets/mods/basegame/items/itemid.csv | 7 +- assets/mods/basegame/metadata.properties | 5 +- .../gameactors/FixtureMysteriousATM.kt | 44 +++++++++++ .../gameitems/ItemMysteriousATM.kt | 21 +++++ .../modulebasegame/ui/UIRedeemCodeMachine.kt | 76 +++++++++++++++++++ src/net/torvald/terrarum/ui/UICanvas.kt | 8 ++ .../terrarum/ui/UIItemRedeemCodeArea.kt | 46 ++++++++--- 8 files changed, 192 insertions(+), 17 deletions(-) create mode 100644 src/net/torvald/terrarum/modulebasegame/gameactors/FixtureMysteriousATM.kt create mode 100644 src/net/torvald/terrarum/modulebasegame/gameitems/ItemMysteriousATM.kt create mode 100644 src/net/torvald/terrarum/modulebasegame/ui/UIRedeemCodeMachine.kt diff --git a/assets/graphics/fonts/terrarum-sans-bitmap/puae000-e0ff.tga b/assets/graphics/fonts/terrarum-sans-bitmap/puae000-e0ff.tga index cf6721f10..0287aee7d 100755 --- a/assets/graphics/fonts/terrarum-sans-bitmap/puae000-e0ff.tga +++ b/assets/graphics/fonts/terrarum-sans-bitmap/puae000-e0ff.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cd38edb59478380cdacc0b7fdf9ef4c56af3c167c5023fa278d233dcb2278e3a +oid sha256:408eefade3bd4c465a93d8cd45ff5c1453b12270babcd3d2365577b6df93fdf9 size 409618 diff --git a/assets/mods/basegame/items/itemid.csv b/assets/mods/basegame/items/itemid.csv index ee0531ba8..4cff3d815 100644 --- a/assets/mods/basegame/items/itemid.csv +++ b/assets/mods/basegame/items/itemid.csv @@ -132,8 +132,8 @@ id;classname;tags 320;net.torvald.terrarum.modulebasegame.gameitems.ItemWorldPortal;FIXTURE,STATION # industrial -#2048;net.torvald.terrarum.modulebasegame.gameitems.ItemInductionMotor;FIXTURE,POWER,KINETIC -#2049;net.torvald.terrarum.modulebasegame.gameitems.ItemGearbox;FIXTURE,POWER,KINETIC +2048;net.torvald.terrarum.modulebasegame.gameitems.ItemInductionMotor;FIXTURE,POWER,KINETIC +2049;net.torvald.terrarum.modulebasegame.gameitems.ItemGearbox;FIXTURE,POWER,KINETIC # data storage (discs; 256) # 32768 is a reserved number for a blank disc @@ -148,7 +148,7 @@ id;classname;tags 32777;net.torvald.terrarum.modulebasegame.gameitems.MusicDisc09;MUSIC,PHONO # data storage (tapestries; 256) -#33024;net.torvald.terrarum.modulebasegame.gameitems.ItemTapestry;FIXTURE,BASEOBJECT +33024;net.torvald.terrarum.modulebasegame.gameitems.ItemTapestry;FIXTURE,BASEOBJECT # data storage (text signs; 256) 33280;net.torvald.terrarum.modulebasegame.gameitems.ItemTextSignCopper;FIXTURE,BASEOBJECT @@ -181,3 +181,4 @@ id;classname;tags # reserved for debug items #16777216;net.torvald.terrarum.modulebasegame.gameitems.ItemBottomlessWaterBucket;DEBUG,TOOL #16777217;net.torvald.terrarum.modulebasegame.gameitems.ItemBottomlessLavaBucket;DEBUG,TOOL +16777472;net.torvald.terrarum.modulebasegame.gameitems.ItemMysteriousATM;DEBUG \ No newline at end of file diff --git a/assets/mods/basegame/metadata.properties b/assets/mods/basegame/metadata.properties index fe221364a..2984cfcc9 100644 --- a/assets/mods/basegame/metadata.properties +++ b/assets/mods/basegame/metadata.properties @@ -1,3 +1,4 @@ +## this file is auto-generated using Prebuild.kt ## # The name that will be displayed in-game propername=Terrarum @@ -44,10 +45,10 @@ package=net.torvald.terrarum.modulebasegame entrypoint=net.torvald.terrarum.modulebasegame.EntryPoint # Release date in YYYY-MM-DD -releasedate=2024-03-28 +releasedate=2025-01-19 # The version, must follow Semver 2.0.0 scheme (https://semver.org/) -version=0.4.2 +version=0.5.2 # External JAR that the module is compiled. If your module requires yet another library, the JAR must be compiled as a "Fatjar"; # Due to security reasons, loading an arbitrary JAR is not allowed. diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureMysteriousATM.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureMysteriousATM.kt new file mode 100644 index 000000000..21a0fe6aa --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureMysteriousATM.kt @@ -0,0 +1,44 @@ +package net.torvald.terrarum.modulebasegame.gameactors + +import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE +import net.torvald.terrarum.gameactors.AVKey +import net.torvald.terrarum.langpack.Lang +import net.torvald.terrarum.modulebasegame.gameitems.FixtureItemBase +import net.torvald.terrarum.modulebasegame.ui.UIRedeemCodeMachine +import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack +import org.dyn4j.geometry.Vector2 + +/** + * Created by minjaesong on 2025-01-19. + */ +class FixtureMysteriousATM : Electric { + + constructor() : super( + BlockBox(BlockBox.ALLOW_MOVE_DOWN, 2, 2), + nameFun = { Lang["ITEM_MYSTERIOUS_ATM"] }, + mainUI = UIRedeemCodeMachine() + ) + + init { + val itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/mysterious_atm.tga") + val itemImage2 = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/mysterious_atm_emsv.tga") + + + density = 2800.0 + setHitboxDimension(TILE_SIZE * 2, TILE_SIZE * 2, 0, 0) + + makeNewSprite(TextureRegionPack(itemImage.texture, TILE_SIZE * 2, TILE_SIZE * 2)).let { + it.setRowsAndFrames(1,1) + } + makeNewSpriteEmissive(TextureRegionPack(itemImage2.texture, TILE_SIZE * 2, TILE_SIZE * 2)).let { + it.setRowsAndFrames(1,1) + } + + actorValue[AVKey.BASEMASS] = 2000.0 + + + setWireSinkAt(0, 2, "appliance_power") + setWireConsumptionAt(0, 2, Vector2(100.0, 0.0)) + + } +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameitems/ItemMysteriousATM.kt b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemMysteriousATM.kt new file mode 100644 index 000000000..6a29b0bdd --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameitems/ItemMysteriousATM.kt @@ -0,0 +1,21 @@ +package net.torvald.terrarum.modulebasegame.gameitems + +import net.torvald.terrarum.gameitems.ItemID + +/** + * Created by minjaesong on 2025-01-19. + */ +class ItemMysteriousATM(originalID: ItemID) : FixtureItemBase(originalID, "net.torvald.terrarum.modulebasegame.gameactors.FixtureMysteriousATM") { + + override var baseMass = 2000.0 + override val canBeDynamic = false + override val materialId = "" + init { + itemImage = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/mysterious_atm.tga") + } + // it's supposed to be turned off when you pick it up +// @Transient override val itemImageEmissive = FixtureItemBase.getItemImageFromSingleImage("basegame", "sprites/fixtures/mysterious_atm_emsv.tga") + + override var originalName = "ITEM_MYSTERIOUS_ATM" + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIRedeemCodeMachine.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIRedeemCodeMachine.kt new file mode 100644 index 000000000..03f110c5f --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/ui/UIRedeemCodeMachine.kt @@ -0,0 +1,76 @@ +package net.torvald.terrarum.modulebasegame.ui + +import com.badlogic.gdx.Input +import com.badlogic.gdx.graphics.Color +import com.badlogic.gdx.graphics.OrthographicCamera +import com.badlogic.gdx.graphics.g2d.SpriteBatch +import net.torvald.terrarum.App +import net.torvald.terrarum.ControlPresets +import net.torvald.terrarum.INGAME +import net.torvald.terrarum.RunningEnvironment +import net.torvald.terrarum.langpack.Lang +import net.torvald.terrarum.ui.Toolkit +import net.torvald.terrarum.ui.UICanvas +import net.torvald.terrarum.ui.UIItemInventoryElemSimple +import net.torvald.terrarum.ui.UIItemRedeemCodeArea +import net.torvald.unicode.getKeycapPC + +/** + * Created by minjaesong on 2025-01-19. + */ +class UIRedeemCodeMachine : UICanvas( + toggleKeyLiteral = null, // no Q key to close + toggleButtonLiteral = "control_gamepad_start", +) { + + override var width = Toolkit.drawWidth + override var height = App.scr.height + + val inputPanel = UIItemRedeemCodeArea(this, + (Toolkit.drawWidth - UIItemRedeemCodeArea.estimateWidth(14)) / 2, + App.scr.halfh - UIItemRedeemCodeArea.estimateHeight(4) - 48, + 14, 4) + + init { + + addUIitem(inputPanel) + } + + private val controlHelp: String + get() = if (App.environment == RunningEnvironment.PC) + "${getKeycapPC(Input.Keys.ESCAPE)} ${Lang["GAME_ACTION_CLOSE"]}" + else + "${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]} " + + + override fun updateImpl(delta: Float) { + uiItems.forEach { it.update(delta) } + } + + private val halfSlotOffset = (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap) / 2 + private val thisOffsetX = UIInventoryFull.INVENTORY_CELLS_OFFSET_X() + UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap - halfSlotOffset + private val yEnd = -UIInventoryFull.YPOS_CORRECTION + (App.scr.height + UIInventoryFull.internalHeight).div(2).toFloat() + + + override fun renderImpl(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) { + UIInventoryFull.drawBackground(batch, 1f) + uiItems.forEach { it.render(frameDelta, batch, camera) } + + val controlHintXPos = thisOffsetX + 2f + App.fontGame.draw(batch, controlHelp, controlHintXPos, yEnd - 20) + } + + override fun doOpening(delta: Float) { + super.doOpening(delta) + INGAME.pause() + } + + override fun doClosing(delta: Float) { + super.doClosing(delta) + INGAME.resume() + } + + override fun dispose() { + } + +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt index 25e2fc7d3..f76d6e1aa 100644 --- a/src/net/torvald/terrarum/ui/UICanvas.kt +++ b/src/net/torvald/terrarum/ui/UICanvas.kt @@ -167,6 +167,10 @@ abstract class UICanvas( /** * Do not modify ui.handler.openCloseCounter here. + * + * When you override this function, you usually append either of following functions: + * - `INGAME.pause()` to literally pause the game and disable the player control + * - `INGAME.disablePlayerControl()` to not pause the game but still disable the player control */ open fun doOpening(delta: Float) { handler.opacity = handler.openCloseCounter / openCloseTime @@ -175,6 +179,10 @@ abstract class UICanvas( /** * Do not modify ui.handler.openCloseCounter here. + * + * When you override this function, you usually append either of following functions: + * - `INGAME.resume()` if your `doOpening()` paused the game + * - `INGAME.resumePlayerControl()` if `doOpening()` disabled the player control */ open fun doClosing(delta: Float) { handler.opacity = (openCloseTime - handler.openCloseCounter) / openCloseTime diff --git a/src/net/torvald/terrarum/ui/UIItemRedeemCodeArea.kt b/src/net/torvald/terrarum/ui/UIItemRedeemCodeArea.kt index 37cb24339..60b77d0fb 100644 --- a/src/net/torvald/terrarum/ui/UIItemRedeemCodeArea.kt +++ b/src/net/torvald/terrarum/ui/UIItemRedeemCodeArea.kt @@ -21,12 +21,17 @@ class UIItemRedeemCodeArea( ) : UIItem(parentUI, initialX, initialY) { - private val CELL_W = 16 - private val CELL_H = 24 - override val width = textCols * CELL_W override val height = textRows * CELL_H + companion object { + private val CELL_W = 16 + private val CELL_H = 24 + + fun estimateWidth(cols: Int) = CELL_W * cols + fun estimateHeight(rows: Int) = CELL_H * rows + } + init { CommonResourcePool.addToLoadingList("spritesheet:terrarum_redeem_code_form") { TextureRegionPack(Gdx.files.internal("assets/graphics/code_input_cells.tga"), CELL_W, CELL_H) @@ -75,6 +80,14 @@ class UIItemRedeemCodeArea( private val caretCol = Toolkit.Theme.COL_SELECTED + private var cursorBlinkTimer = 0f + + override fun update(delta: Float) { + super.update(delta) + cursorBlinkTimer += delta + if (cursorBlinkTimer >= 1f) cursorBlinkTimer -= 1f + } + override fun render(frameDelta: Float, batch: SpriteBatch, camera: OrthographicCamera) { super.render(frameDelta, batch, camera) @@ -84,6 +97,10 @@ class UIItemRedeemCodeArea( batch.color = lineCol Toolkit.drawBoxBorder(batch, posX, posY, width, height) + // draw cells back + batch.color = Toolkit.Theme.COL_CELL_FILL + Toolkit.fillArea(batch, posX, posY, CELL_W * textCols, CELL_H * textRows) + // draw cells batch.color = Toolkit.Theme.COL_INACTIVE for (y in 0 until textRows) { @@ -100,7 +117,7 @@ class UIItemRedeemCodeArea( for (x in 0 until textCols) { BigAlphNum.draw( batch, - "${inputText.getOrElse(y * textRows + x) { 'A' }}", + "${inputText.getOrElse(y * textRows + x) { ' ' }}", posX + CELL_W * x + 2f, posY + CELL_H * y + 4f ) @@ -108,13 +125,20 @@ class UIItemRedeemCodeArea( } // draw caret - batch.color = caretCol - val cx = textCaret % textCols - val cy = textCaret / textCols - Toolkit.drawStraightLine(batch, - posX + CELL_W * cx - 1, - posY + CELL_H * cy + 1, - posY + CELL_H * cy + 1 + 20, 2, true) + if (cursorBlinkTimer < 0.5f) { + batch.color = caretCol + val cx = textCaret % textCols + val cy = textCaret / textCols + Toolkit.drawStraightLine( + batch, + posX + CELL_W * cx - 1, + posY + CELL_H * cy + 1, + posY + CELL_H * cy + 1 + 20, 2, true + ) + } + + + batch.color = Color.WHITE } override fun dispose() {