Ingame's Player is now mandatory; player spawn on right position

This commit is contained in:
minjaesong
2017-07-18 00:19:55 +09:00
parent 58205e5eb5
commit 33a774b5b7
17 changed files with 224 additions and 71 deletions

View File

@@ -7,6 +7,7 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ActorHumanoid
import net.torvald.terrarum.gameactors.Second
import net.torvald.terrarum.gameactors.abs
import net.torvald.terrarum.gameactors.roundInt
import net.torvald.terrarum.imagefont.Watch7SegSmall
import net.torvald.terrarum.worlddrawer.LightmapRenderer
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -44,7 +45,21 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
}
private val temperature: Int
get() = -2
get() {
if (player != null) {
val playerTilePos = player.tilewiseHitbox
val tempCelsius = -273f + (Terrarum.ingame?.world?.getTemperature(playerTilePos.centeredX.toInt(), playerTilePos.centeredY.toInt()) ?: 288f)
return if (Terrarum.getConfigBoolean("useamericanunit")) {
tempCelsius.times(1.8f).plus(32f).roundInt()
}
else {
tempCelsius.roundInt()
}
}
else {
return 888
}
}
private val mailCount: Int
get() = 0
@@ -65,7 +80,12 @@ class UIBasicNotifier(private val player: ActorHumanoid?) : UICanvas() {
sb.append(temperature.abs())
sb.append('"') // celsius superscript
if (Terrarum.getConfigBoolean("useamericanunit")) {
sb.append('#') // fahrenheit subscript
}
else {
sb.append('"') // celsius superscript
}
return sb.toString()
}

View File

@@ -124,12 +124,16 @@ class UIInventory(
private val scrollLeftButton = UIItemImageButton(this,
scrollImageButtonAtlas.get(0, 0),
posX = categoryWidth,
posY = (height - controlHelpHeight - scrollImageButtonAtlas.tileH) / 2
posY = 0,//(height - controlHelpHeight - scrollImageButtonAtlas.tileH) / 2,
width = scrollImageButtonAtlas.tileW,
height = height - controlHelpHeight
)
private val scrollRightButton = UIItemImageButton(this,
scrollImageButtonAtlas.get(1, 0),
posX = width - scrollImageButtonAtlas.tileW,
posY = (height - controlHelpHeight - scrollImageButtonAtlas.tileH) / 2
posY = 0,//(height - controlHelpHeight - scrollImageButtonAtlas.tileH) / 2,
width = scrollImageButtonAtlas.tileW,
height = height - controlHelpHeight
)
var itemPage = 0
var itemPageCount = 1 // TODO total size of current category / items.size
@@ -139,7 +143,7 @@ class UIInventory(
var inventorySortList = ArrayList<InventoryPair>()
private var rebuildList = true
private val SP = "${0x3000.toChar()}${0x3000.toChar()}${0x3000.toChar()}"
private val SP = "${0x3000.toChar()}${0x3000.toChar()}"
val listControlHelp: String
get() = if (Terrarum.environment == RunningEnvironment.PC)
"${0xe006.toChar()} ${Lang["GAME_INVENTORY_USE"]}$SP" +
@@ -161,23 +165,21 @@ class UIInventory(
private var isEncumbered = false
private val seekLeft: Int; get() = Terrarum.getConfigInt("keyleft") // to support in-screen keybind changing
private val seekRight: Int; get() = Terrarum.getConfigInt("keyright") // to support in-screen keybind changing
private val seekUp: Int; get() = Terrarum.getConfigInt("keyup") // to support in-screen keybind changing
private val seekDown: Int; get() = Terrarum.getConfigInt("keydown") // to support in-screen keybind changing
private val seekLeft: Int; get() = Terrarum.getConfigInt("keyleft") // getter used to support in-game keybind changing
private val seekRight: Int; get() = Terrarum.getConfigInt("keyright") // getter used to support in-game keybind changing
private val seekUp: Int; get() = Terrarum.getConfigInt("keyup") // getter used to support in-game keybind changing
private val seekDown: Int; get() = Terrarum.getConfigInt("keydown") // getter used to support in-game keybind changing
init {
// assign actions to the buttons
scrollLeftButton.clickOnceAction = { mouseX, mouseY, button -> // click once action doesn't work ?!
scrollLeftButton.clickOnceListener = { mouseX, mouseY, button -> // click once action doesn't work ?!
if (button == Input.Buttons.LEFT) {
println("prevpage")
itemPage = (itemPage - 1) fmod itemPageCount
}
}
scrollRightButton.clickOnceAction = { mouseX, mouseY, button ->
scrollRightButton.clickOnceListener = { mouseX, mouseY, button ->
if (button == Input.Buttons.LEFT) {
println("nextpage")
itemPage = (itemPage + 1) fmod itemPageCount
}
}

View File

@@ -31,39 +31,39 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
// kind of listener implementation
var updateAction: ((Float) -> Unit)? = null
var keyDownAction: ((Int) -> Unit)? = null
var keyUpAction: ((Int) -> Unit)? = null
var mouseMovedAction: ((Int, Int) -> Unit)? = null
var touchDraggedAction: ((Int, Int, Int) -> Unit)? = null
var touchDownAction: ((Int, Int, Int, Int) -> Unit)? = null
var touchUpAction: ((Int, Int, Int, Int) -> Unit)? = null
var scrolledAction: ((Int) -> Unit)? = null
var updateListener: ((Float) -> Unit)? = null
var keyDownListener: ((Int) -> Unit)? = null
var keyUpListener: ((Int) -> Unit)? = null
var mouseMovedListener: ((Int, Int) -> Unit)? = null
var touchDraggedListener: ((Int, Int, Int) -> Unit)? = null
var touchDownListener: ((Int, Int, Int, Int) -> Unit)? = null
var touchUpListener: ((Int, Int, Int, Int) -> Unit)? = null
var scrolledListener: ((Int) -> Unit)? = null
var clickOnceAction: ((Int, Int, Int) -> Unit)? = null
var clickOnceActionEngaged = false
var clickOnceListener: ((Int, Int, Int) -> Unit)? = null
var clickOnceListenerFired = false
open fun update(delta: Float) {
if (updateAction != null) {
updateAction!!.invoke(delta)
if (updateListener != null) {
updateListener!!.invoke(delta)
}
}
abstract fun render(batch: SpriteBatch)
// keyboard controlled
open fun keyDown(keycode: Int): Boolean {
if (keyDownAction != null) {
keyDownAction!!.invoke(keycode)
if (keyDownListener != null) {
keyDownListener!!.invoke(keycode)
return true
}
return false
}
open fun keyUp(keycode: Int): Boolean {
if (keyUpAction != null) {
keyUpAction!!.invoke(keycode)
if (keyUpListener != null) {
keyUpListener!!.invoke(keycode)
return true
}
@@ -72,16 +72,16 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
// mouse controlled
open fun mouseMoved(screenX: Int, screenY: Int): Boolean {
if (mouseMovedAction != null) {
mouseMovedAction!!.invoke(relativeMouseX, relativeMouseY)
if (mouseMovedListener != null) {
mouseMovedListener!!.invoke(relativeMouseX, relativeMouseY)
return true
}
return false
}
open fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
if (touchDraggedAction != null) {
touchDraggedAction!!.invoke(relativeMouseX, relativeMouseY, pointer)
if (touchDraggedListener != null) {
touchDraggedListener!!.invoke(relativeMouseX, relativeMouseY, pointer)
return true
}
@@ -90,31 +90,31 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
open fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
var actionDone = false
if (touchDownAction != null) {
touchDownAction!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
if (touchDownListener != null) {
touchDownListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
actionDone = true
}
if (!clickOnceActionEngaged && mouseUp) {
clickOnceAction!!.invoke(relativeMouseX, relativeMouseY, button)
if (!clickOnceListenerFired && mouseUp) {
clickOnceListener!!.invoke(relativeMouseX, relativeMouseY, button)
actionDone = true
}
return actionDone
}
open fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
clickOnceActionEngaged = false
clickOnceListenerFired = false
if (touchUpAction != null) {
touchUpAction!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
if (touchUpListener != null) {
touchUpListener!!.invoke(relativeMouseX, relativeMouseY, pointer, button)
return true
}
return false
}
open fun scrolled(amount: Int): Boolean {
if (scrolledAction != null) {
scrolledAction!!.invoke(amount)
if (scrolledListener != null) {
scrolledListener!!.invoke(amount)
return true
}