diff --git a/src/net/torvald/terrarum/blockproperties/Block.kt b/src/net/torvald/terrarum/blockproperties/Block.kt index aaa1f2a0a..5a130838a 100644 --- a/src/net/torvald/terrarum/blockproperties/Block.kt +++ b/src/net/torvald/terrarum/blockproperties/Block.kt @@ -5,119 +5,126 @@ package net.torvald.terrarum.blockproperties */ object Block { - val AIR = 0 // hard coded; this is the standard + const val AIR = 0 // hard coded; this is the standard - val STONE = 16 - val STONE_QUARRIED = 17 - val STONE_TILE_WHITE = 18 - val STONE_BRICKS = 19 + const val STONE = 16 + const val STONE_QUARRIED = 17 + const val STONE_TILE_WHITE = 18 + const val STONE_BRICKS = 19 - val DIRT = 32 - val GRASS = 33 - val GRASSWALL = 34 + const val DIRT = 32 + const val GRASS = 33 + const val GRASSWALL = 34 - val PLANK_NORMAL = 48 - val PLANK_EBONY = 49 - val PLANK_BIRCH = 50 - val PLANK_BLOODROSE = 51 + const val PLANK_NORMAL = 48 + const val PLANK_EBONY = 49 + const val PLANK_BIRCH = 50 + const val PLANK_BLOODROSE = 51 - val TRUNK_NORMAL = 64 - val TRUNK_EBONY = 65 - val TRUNK_BIRCH = 66 - val TRUNK_BLOODROSE = 67 + const val TRUNK_NORMAL = 64 + const val TRUNK_EBONY = 65 + const val TRUNK_BIRCH = 66 + const val TRUNK_BLOODROSE = 67 - val SAND = 80 - val SAND_WHITE = 81 - val SAND_RED = 82 - val SAND_DESERT = 83 - val SAND_BLACK = 84 - val SAND_GREEN = 85 + const val SAND = 80 + const val SAND_WHITE = 81 + const val SAND_RED = 82 + const val SAND_DESERT = 83 + const val SAND_BLACK = 84 + const val SAND_GREEN = 85 - val GRAVEL = 96 - val GRAVEL_GREY = 97 + const val GRAVEL = 96 + const val GRAVEL_GREY = 97 - val ORE_COPPER = 112 - val ORE_IRON = 113 - val ORE_GOLD = 114 - val ORE_SILVER = 115 - val ORE_ILMENITE = 116 - val ORE_AURICHALCUM = 117 + const val ORE_COPPER = 112 + const val ORE_IRON = 113 + const val ORE_GOLD = 114 + const val ORE_SILVER = 115 + const val ORE_ILMENITE = 116 + const val ORE_AURICHALCUM = 117 - val RAW_RUBY = 128 - val RAW_EMERALD = 129 - val RAW_SAPPHIRE = 130 - val RAW_TOPAZ = 131 - val RAW_DIAMOND = 132 - val RAW_AMETHYST = 133 + const val RAW_RUBY = 128 + const val RAW_EMERALD = 129 + const val RAW_SAPPHIRE = 130 + const val RAW_TOPAZ = 131 + const val RAW_DIAMOND = 132 + const val RAW_AMETHYST = 133 - val SNOW = 144 - val ICE_FRAGILE = 145 - val ICE_NATURAL = 146 - val ICE_MAGICAL = 147 + const val SNOW = 144 + const val ICE_FRAGILE = 145 + const val ICE_NATURAL = 146 + const val ICE_MAGICAL = 147 - val GLASS_CRUDE = 148 - val GLASS_CLEAN = 149 + const val GLASS_CRUDE = 148 + const val GLASS_CLEAN = 149 - val PLATFORM_STONE = 160 - val PLATFORM_WOODEN = 161 - val PLATFORM_EBONY = 162 - val PLATFORM_BIRCH = 163 - val PLATFORM_BLOODROSE = 164 + const val PLATFORM_STONE = 160 + const val PLATFORM_WOODEN = 161 + const val PLATFORM_EBONY = 162 + const val PLATFORM_BIRCH = 163 + const val PLATFORM_BLOODROSE = 164 - val TORCH = 176 - val TORCH_FROST = 177 + const val TORCH = 176 + const val TORCH_FROST = 177 - val TORCH_OFF = 192 - val TORCH_FROST_OFF = 193 + const val TORCH_OFF = 192 + const val TORCH_FROST_OFF = 193 - val ILLUMINATOR_WHITE = 208 - val ILLUMINATOR_YELLOW = 209 - val ILLUMINATOR_ORANGE = 210 - val ILLUMINATOR_RED = 211 - val ILLUMINATOR_FUCHSIA = 212 - val ILLUMINATOR_PURPLE = 213 - val ILLUMINATOR_BLUE = 214 - val ILLUMINATOR_CYAN = 215 - val ILLUMINATOR_GREEN = 216 - val ILLUMINATOR_GREEN_DARK = 217 - val ILLUMINATOR_BROWN = 218 - val ILLUMINATOR_TAN = 219 - val ILLUMINATOR_GREY_LIGHT = 220 - val ILLUMINATOR_GREY_MED = 221 - val ILLUMINATOR_GREY_DARK = 222 - val ILLUMINATOR_BLACK = 223 + const val ILLUMINATOR_WHITE = 208 + const val ILLUMINATOR_YELLOW = 209 + const val ILLUMINATOR_ORANGE = 210 + const val ILLUMINATOR_RED = 211 + const val ILLUMINATOR_FUCHSIA = 212 + const val ILLUMINATOR_PURPLE = 213 + const val ILLUMINATOR_BLUE = 214 + const val ILLUMINATOR_CYAN = 215 + const val ILLUMINATOR_GREEN = 216 + const val ILLUMINATOR_GREEN_DARK = 217 + const val ILLUMINATOR_BROWN = 218 + const val ILLUMINATOR_TAN = 219 + const val ILLUMINATOR_GREY_LIGHT = 220 + const val ILLUMINATOR_GREY_MED = 221 + const val ILLUMINATOR_GREY_DARK = 222 + const val ILLUMINATOR_BLACK = 223 - val ILLUMINATOR_WHITE_OFF = 224 - val ILLUMINATOR_YELLOW_OFF = 225 - val ILLUMINATOR_ORANGE_OFF = 226 - val ILLUMINATOR_RED_OFF = 227 - val ILLUMINATOR_FUCHSIA_OFF = 228 - val ILLUMINATOR_PURPLE_OFF = 229 - val ILLUMINATOR_BLUE_OFF = 230 - val ILLUMINATOR_CYAN_OFF = 231 - val ILLUMINATOR_GREEN_OFF = 232 - val ILLUMINATOR_GREEN_DARK_OFF = 233 - val ILLUMINATOR_BROWN_OFF = 234 - val ILLUMINATOR_TAN_OFF = 235 - val ILLUMINATOR_GREY_LIGHT_OFF = 236 - val ILLUMINATOR_GREY_MED_OFF = 237 - val ILLUMINATOR_GREY_DARK_OFF = 238 - val ILLUMINATOR_BLACK_OFF = 239 + const val ILLUMINATOR_WHITE_OFF = 224 + const val ILLUMINATOR_YELLOW_OFF = 225 + const val ILLUMINATOR_ORANGE_OFF = 226 + const val ILLUMINATOR_RED_OFF = 227 + const val ILLUMINATOR_FUCHSIA_OFF = 228 + const val ILLUMINATOR_PURPLE_OFF = 229 + const val ILLUMINATOR_BLUE_OFF = 230 + const val ILLUMINATOR_CYAN_OFF = 231 + const val ILLUMINATOR_GREEN_OFF = 232 + const val ILLUMINATOR_GREEN_DARK_OFF = 233 + const val ILLUMINATOR_BROWN_OFF = 234 + const val ILLUMINATOR_TAN_OFF = 235 + const val ILLUMINATOR_GREY_LIGHT_OFF = 236 + const val ILLUMINATOR_GREY_MED_OFF = 237 + const val ILLUMINATOR_GREY_DARK_OFF = 238 + const val ILLUMINATOR_BLACK_OFF = 239 - val SANDSTONE = 240 - val SANDSTONE_WHITE = 241 - val SANDSTONE_RED = 242 - val SANDSTONE_DESERT = 243 - val SANDSTONE_BLACK = 244 - val SANDSTONE_GREEN = 245 + const val SANDSTONE = 240 + const val SANDSTONE_WHITE = 241 + const val SANDSTONE_RED = 242 + const val SANDSTONE_DESERT = 243 + const val SANDSTONE_BLACK = 244 + const val SANDSTONE_GREEN = 245 - val LANTERN = 256 - val SUNSTONE = 257 - val DAYLIGHT_CAPACITOR = 258 + const val LANTERN = 256 + const val SUNSTONE = 257 + const val DAYLIGHT_CAPACITOR = 258 - val LAVA = 4094 - val WATER = 4095 + const val ACTORBLOCK_NO_COLLISION = 4191 + const val ACTORBLOCK_FULL_COLLISION = 4092 + const val ACTORBLOCK_ALLOW_MOVE_DOWN = 4093 + const val ACTORBLOCK_NO_PASS_RIGHT = 4094 + const val ACTORBLOCK_NO_PASS_LEFT = 4095 - val NULL = -1 + + const val LAVA = 4094 + const val WATER = 4095 + + const val NULL = -1 } diff --git a/src/net/torvald/terrarum/gameactors/Actor.kt b/src/net/torvald/terrarum/gameactors/Actor.kt index 5585db8cd..7a158c51e 100644 --- a/src/net/torvald/terrarum/gameactors/Actor.kt +++ b/src/net/torvald/terrarum/gameactors/Actor.kt @@ -1,8 +1,5 @@ package net.torvald.terrarum.gameactors -import net.torvald.random.HQRNG -import net.torvald.terrarum.Terrarum -import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.itemproperties.ItemCodex.ACTORID_MIN @@ -64,6 +61,8 @@ abstract class Actor(val renderOrder: RenderOrder) : Comparable, Runnable */ abstract @Event fun onActorValueChange(key: String, value: Any?) + abstract fun dispose() + } annotation class Event diff --git a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt index d62ad3a7f..964f0110d 100644 --- a/src/net/torvald/terrarum/gameactors/ActorWithBody.kt +++ b/src/net/torvald/terrarum/gameactors/ActorWithBody.kt @@ -12,6 +12,4 @@ abstract class ActorWithBody(renderOrder: RenderOrder) : Actor(renderOrder) { abstract fun drawBody(batch: SpriteBatch) abstract fun drawGlow(batch: SpriteBatch) open var tooltipText: String? = null // null: display nothing - - abstract fun dispose() } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt index 31cc45f6e..da251ef8f 100644 --- a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt +++ b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt @@ -1,9 +1,13 @@ package net.torvald.terrarum.modulebasegame import com.badlogic.gdx.Gdx +import com.badlogic.gdx.InputAdapter import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch -import net.torvald.terrarum.* +import net.torvald.terrarum.AppLoader +import net.torvald.terrarum.IngameInstance +import net.torvald.terrarum.Terrarum +import net.torvald.terrarum.Yaml import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.gameactors.* import net.torvald.terrarum.gamecontroller.KeyToggler @@ -11,8 +15,8 @@ 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.UIBuildingMakerToolbox import net.torvald.terrarum.ui.UICanvas +import net.torvald.terrarum.ui.UINSMenu import net.torvald.terrarum.worlddrawer.LightmapRenderer import net.torvald.terrarum.worlddrawer.WorldCamera import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack @@ -23,6 +27,32 @@ import kotlin.system.measureNanoTime */ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { + private val menuYaml = Yaml(""" +- File + - New + - Export… + - Export sel… + - Import… + - Save world… + - Load world… +- Tool + - Pencil + - Eyedropper + - Select mrq. + - Move + - Undo + - Redo +- Time + - Morning + - Noon + - Dusk + - Night + - Set… +- Weather + - Sunny + - Raining + """.trimIndent()) + private val timeNow = System.currentTimeMillis() / 1000 val gameWorld = GameWorldExtension(1, 1024, 256, timeNow, timeNow, 0) @@ -49,7 +79,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { override var actorNowPlaying: ActorHumanoid? = MovableWorldCamera() - val uiToolbox = UIBuildingMakerToolbox() + val uiToolbox = UINSMenu("Menu", 100, menuYaml) val notifier = Notification() val uiContainer = ArrayList() @@ -106,7 +136,8 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { - uiToolbox.setPosition(Terrarum.WIDTH - 20, 4) + uiToolbox.setPosition(0, 0) + uiToolbox.isVisible = true notifier.setPosition( (Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height) @@ -118,6 +149,11 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { LightmapRenderer.fireRecalculateEvent() } + override fun show() { + Gdx.input.inputProcessor = BuildingMakerController(this) + super.show() + } + override fun render(delta: Float) { Gdx.graphics.setTitle(Ingame.getCanonicalTitle()) @@ -172,7 +208,7 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { override fun resize(width: Int, height: Int) { IngameRenderer.resize(Terrarum.WIDTH, Terrarum.HEIGHT) - uiToolbox.setPosition(Terrarum.WIDTH - 20, 4) + uiToolbox.setPosition(0, 0) notifier.setPosition( (Terrarum.WIDTH - notifier.width) / 2, Terrarum.HEIGHT - notifier.height) println("[BuildingMaker] Resize event") @@ -181,16 +217,49 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) { override fun dispose() { IngameRenderer.dispose() } - - private val menuYaml = Yaml(""" -- File - - New - - Export - - Import -- Edit - """.trimIndent()) } +class BuildingMakerController(val screen: BuildingMaker) : InputAdapter() { + override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { + screen.uiContainer.forEach { it.touchUp(screenX, screenY, pointer, button) } + return true + } + + override fun mouseMoved(screenX: Int, screenY: Int): Boolean { + screen.uiContainer.forEach { it.mouseMoved(screenX, screenY) } + return true + } + + override fun keyTyped(character: Char): Boolean { + screen.uiContainer.forEach { it.keyTyped(character) } + return true + } + + override fun scrolled(amount: Int): Boolean { + screen.uiContainer.forEach { it.scrolled(amount) } + return true + } + + override fun keyUp(keycode: Int): Boolean { + screen.uiContainer.forEach { it.keyUp(keycode) } + return true + } + + override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean { + screen.uiContainer.forEach { it.touchDragged(screenX, screenY, pointer) } + return true + } + + override fun keyDown(keycode: Int): Boolean { + screen.uiContainer.forEach { it.keyDown(keycode) } + return true + } + + override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { + screen.uiContainer.forEach { it.touchDown(screenX, screenY, pointer, button) } + return true + } +} class MovableWorldCamera : ActorHumanoid(0, usePhysics = false) { diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt index 823e16fac..9198bf242 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureBase.kt @@ -1,31 +1,53 @@ package net.torvald.terrarum.modulebasegame.gameactors +import net.torvald.terrarum.Point2d +import net.torvald.terrarum.blockproperties.Block import net.torvald.terrarum.gameactors.ActorWBMovable -import net.torvald.terrarum.gameworld.GameWorld /** * Created by minjaesong on 2016-06-17. */ -open class FixtureBase(physics: Boolean = true) : - ActorWBMovable(RenderOrder.BEHIND, immobileBody = true, usePhysics = physics) { - /** - * 0: Open - * 1: Blocked - * 2: Platform; can be stood on, press DOWN to go down. Also allows other blocks can be places on top of it (e.g. torch) - * 3: Wall_left; blocks rightward movement - * 4: Wall_right: blocks leftward movement - * 5: Same as 2 but player CANNOT go down - * For example, flag of 4 is good for tables; player can stand on, which means - * downward movement is blocked within the fixtures' AABB. - */ - var collisionFlag: Int = 0 +open class FixtureBase(val blockBox: BlockBox) : +// disabling physics (not allowing the fixture to move) WILL make things easier + ActorWBMovable(RenderOrder.BEHIND, immobileBody = true, usePhysics = false) { + /** + * Block-wise position of this fixture when it's placed on the world. Null if it's not on the world + */ + private var worldBlockPos: Point2d? = null + + /** + * Adds this instance of the fixture to the world + */ + open fun spawn() { + // place filler blocks + // place the filler blocks where: + // origin posX: centre-left if mouseX is on the right-half of the game window, + // centre-right otherwise + // origin posY: bottom + // place the actor within the blockBox where: + // posX: centre of the blockBox + // posY: bottom of the blockBox + // using the actor's hitbox + + + + } + + /** + * Removes this instance of the fixture from the world + */ + open fun despawn() { + // remove filler block + } +} + +data class BlockBox(val collisionType: Int, val width: Int, val height: Int) { companion object { - val COLLISION_OPEN = 0 - val COLLISION_BLOCKED = 1 - val COLLISION_PLATFORM = 2 - val COLLISION_WALL_LEFT = 3 - val COLLISION_WALL_RIGHT = 4 - val COLLISION_PLATFORM_NOGODOWN = 5 + const val NO_COLLISION = Block.ACTORBLOCK_NO_COLLISION + const val FULL_COLLISION = Block.ACTORBLOCK_FULL_COLLISION + const val ALLOW_MOVE_DOWN = Block.ACTORBLOCK_ALLOW_MOVE_DOWN + const val NO_PASS_RIGHT = Block.ACTORBLOCK_NO_PASS_RIGHT + const val NO_PASS_LEFT = Block.ACTORBLOCK_NO_PASS_LEFT } } \ No newline at end of file diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt index 740b8945b..664760179 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureTikiTorch.kt @@ -7,14 +7,15 @@ import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.gameactors.AVKey import net.torvald.terrarum.gameactors.Hitbox import net.torvald.terrarum.gameactors.Luminous -import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack import java.util.* /** * Created by minjaesong on 2016-06-17. */ -internal class FixtureTikiTorch : FixtureBase(), Luminous { +internal class FixtureTikiTorch : FixtureBase( + BlockBox(BlockBox.NO_COLLISION, 1, 2) +), Luminous { override var color: Color get() = BlockCodex[Block.TORCH].luminosity diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/Interactable.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/Interactable.kt new file mode 100644 index 000000000..dab0e7c94 --- /dev/null +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/Interactable.kt @@ -0,0 +1,25 @@ +package net.torvald.terrarum.modulebasegame.gameactors + +import net.torvald.terrarum.ui.UICanvas + +/** + * Furnitures that opens its own UI when right-clicked/interact-key-downed + * + * It is recommended to override dispose() as follows: + * ``` + * override fun dispose() { + * closeUI() // UI will be closed when the furniture is being destroyed while the UI is opened + * super.dispose() + * } + * ``` + * + * Created by minjaesong on 2018-12-29. + */ +interface Interactable { + + val ui: UICanvas + + fun openUI() + fun closeUI() + +} \ No newline at end of file diff --git a/work_files/terrarum_ui_elements_coord_explained.png b/work_files/terrarum_ui_elements_coord_explained.png new file mode 100644 index 000000000..d376a842f Binary files /dev/null and b/work_files/terrarum_ui_elements_coord_explained.png differ diff --git a/work_files/terrarum_ui_elements_coord_explained.psd b/work_files/terrarum_ui_elements_coord_explained.psd new file mode 100644 index 000000000..282b56480 --- /dev/null +++ b/work_files/terrarum_ui_elements_coord_explained.psd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd691e59de05dfb9a8f7a1f0aa1ebf714bc9ec68e449b5fc6ca1f2a708a2cabf +size 524984