quickslot selections are controlled by the ingame rather than the 'bar UI'

This commit is contained in:
minjaesong
2019-01-13 02:17:49 +09:00
parent 822b9bf4fd
commit d9c7d3c681
10 changed files with 45 additions and 77 deletions

View File

@@ -509,7 +509,7 @@ public class AppLoader implements ApplicationListener {
return true;
}
catch (IOException e) {
catch (java.nio.file.NoSuchFileException e) {
// write default config to game dir. Call this method again to read config from it.
try {
createConfigJson();

View File

@@ -67,8 +67,8 @@ object DefaultConfig {
jsonObject.addProperty("keyjump", Input.Keys.SPACE)
val keyquickbars = JsonArray(); for (i in Input.Keys.NUMPAD_1..Input.Keys.NUMPAD_9) keyquickbars.add(i); keyquickbars.add(Input.Keys.NUMPAD_0) // NUM_1 to NUM_0
jsonObject.add("keyquickbars", keyquickbars)
val keyquickslots = JsonArray(); for (i in Input.Keys.NUM_1..Input.Keys.NUM_9) keyquickslots.add(i); keyquickslots.add(Input.Keys.NUM_0) // NUM_1 to NUM_0
jsonObject.add("keyquickslots", keyquickslots)
jsonObject.addProperty("mouseprimary", Input.Buttons.LEFT) // left mouse
jsonObject.addProperty("mousesecondary", Input.Buttons.RIGHT) // right mouse

View File

@@ -12,6 +12,10 @@ class ActorValue(val actor: Actor) : KVHashMap() {
}
override fun set(key: String, value: Any) {
/*if (key == AVKey.__PLAYER_QUICKSLOTSEL) {
Thread.currentThread().stackTrace.forEach { println(it) }
}*/
super.set(key, value)
actor.onActorValueChange(key, value) // fire the event handler
}

View File

@@ -4,11 +4,12 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.InputAdapter
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.floorInt
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.worlddrawer.FeaturesDrawer
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.itemproperties.GameItem
import net.torvald.terrarum.floorInt
import net.torvald.terrarum.worlddrawer.WorldCamera
/**
@@ -70,12 +71,19 @@ class IngameController(val ingame: Ingame) : InputAdapter() {
if (ingame.canPlayerControl) {
ingame.actorNowPlaying?.keyDown(keycode)
}
if (AppLoader.getConfigIntArray("keyquickselalt").contains(keycode)
|| keycode == AppLoader.getConfigInt("keyquicksel")) {
ingame.uiPieMenu.setAsOpen()
ingame.uiQuickBar.setAsClose()
// quickslot (quickbar)
val quickslotKeys = AppLoader.getConfigIntArray("keyquickslots")
if (keycode in quickslotKeys) {
ingame.actorNowPlaying?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, quickslotKeys.indexOf(keycode))
}
// pie menu
if (AppLoader.getConfigIntArray("keyquickselalt").contains(keycode)
|| keycode == AppLoader.getConfigInt("keyquicksel")) {
ingame.uiPieMenu.setAsOpen()
ingame.uiQuickBar.setAsClose()
}
}
ingame.uiContainer.forEach { it.keyDown(keycode) } // for KeyboardControlled UIcanvases

View File

@@ -116,11 +116,11 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// UI aliases
lateinit var uiAliases: ArrayList<UICanvas>
private set
lateinit var uiAlasesPausing: ArrayList<UICanvas>
lateinit var uiAliasesPausing: ArrayList<UICanvas>
private set
inline val paused: Boolean
get() = uiAlasesPausing.map { if (it.isOpened) return true else 0 }.isEmpty() // isEmply is always false, which we want
get() = uiAliasesPausing.map { if (it.isOpened) return true else 0 }.isEmpty() // isEmpty is always false, which we want
/**
* Set to false if UI is opened; set to true if UI is closed.
*/
@@ -355,13 +355,13 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
uiTooltip
// drawn last
)
uiAlasesPausing = arrayListOf(
uiAliasesPausing = arrayListOf(
uiInventoryPlayer,
//uiInventoryContainer,
consoleHandler,
uiCheatMotherfuckerNootNoot
)
uiAlasesPausing.forEach { addUI(it) } // put them all to the UIContainer
uiAliasesPausing.forEach { addUI(it) } // put them all to the UIContainer
uiAliases.forEach { addUI(it) } // put them all to the UIContainer
@@ -958,7 +958,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
actorsRenderOverlay.forEach { it.dispose() }
uiAliases.forEach { it.dispose() }
uiAlasesPausing.forEach { it.dispose() }
uiAliasesPausing.forEach { it.dispose() }
WatchDotAlph.dispose()

View File

@@ -358,14 +358,7 @@ open class ActorHumanoid(
}
override fun keyDown(keycode: Int): Boolean {
// quickslot (quickbar)
val quickbarKeys = AppLoader.getConfigIntArray("keyquickbars")
if (keycode in quickbarKeys) {
actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = quickbarKeys.indexOf(keycode)
}
return true
return false
}

View File

@@ -11,8 +11,8 @@ import net.torvald.terrarum.itemproperties.ItemCodex.ITEM_WALLS
import net.torvald.terrarum.itemproperties.ItemID
import net.torvald.terrarum.lock
import net.torvald.terrarum.modulebasegame.Ingame
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar
import java.util.*
import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReentrantLock
/**
@@ -30,13 +30,13 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
/**
* List of all equipped items (tools, armours, rings, necklaces, etc.)
*/
val itemEquipped = Array<GameItem?>(GameItem.EquipPosition.INDEX_MAX, { null })
val itemEquipped = Array<GameItem?>(GameItem.EquipPosition.INDEX_MAX) { null }
/**
* Sorted by referenceID.
*/
val itemList = ArrayList<InventoryPair>()
val quickBar = Array<ItemID?>(10, { null }) // 0: Slot 1, 9: Slot 10
val quickSlot = Array<ItemID?>(UIQuickslotBar.SLOT_COUNT) { null } // 0: Slot 1, 9: Slot 10
var currency = 0 // unified currency for whole civs; Dwarf Fortress approach seems too complicated
@@ -127,10 +127,10 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
}
fun setQuickBar(slot: Int, dynamicID: ItemID?) {
quickBar[slot] = dynamicID
quickSlot[slot] = dynamicID
}
fun getQuickslot(slot: Int): InventoryPair? = getByDynamicID(quickBar[slot])
fun getQuickslot(slot: Int): InventoryPair? = getByDynamicID(quickSlot[slot])
/**
* HashMap<GameItem, Amounts>

View File

@@ -1,6 +1,5 @@
package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
@@ -87,24 +86,6 @@ class UIQuickslotBar : UICanvas() {
return true
}
override fun keyDown(keycode: Int): Boolean {
selection = when (keycode) {
Input.Keys.NUM_1 -> 0
Input.Keys.NUM_2 -> 1
Input.Keys.NUM_3 -> 2
Input.Keys.NUM_4 -> 3
Input.Keys.NUM_5 -> 4
Input.Keys.NUM_6 -> 5
Input.Keys.NUM_7 -> 6
Input.Keys.NUM_8 -> 7
Input.Keys.NUM_9 -> 8
Input.Keys.NUM_0 -> 9
else -> return false
}
return true
}
override fun dispose() {
}

View File

@@ -1,15 +1,6 @@
package net.torvald.terrarum.utils
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import net.torvald.terrarum.AppLoader.printdbg
import java.io.File
import java.io.IOException
import java.nio.file.FileSystems
import java.nio.file.Files
import java.util.ArrayList
import java.util.function.Consumer
/**
* Created by minjaesong on 2016-02-15.
@@ -18,7 +9,7 @@ object JsonFetcher {
private var jsonString: StringBuffer? = null
@Throws(java.io.IOException::class)
@Throws(java.nio.file.NoSuchFileException::class)
operator fun invoke(jsonFilePath: String): com.google.gson.JsonObject {
jsonString = StringBuffer() // reset buffer every time it called
readJsonFileAsString(jsonFilePath)
@@ -35,7 +26,7 @@ object JsonFetcher {
return jsonObj
}
@Throws(java.io.IOException::class)
@Throws(java.nio.file.NoSuchFileException::class)
operator fun invoke(jsonFile: java.io.File): com.google.gson.JsonObject {
jsonString = StringBuffer() // reset buffer every time it called
readJsonFileAsString(jsonFile.canonicalPath)
@@ -52,15 +43,11 @@ object JsonFetcher {
return jsonObj
}
@Throws(java.nio.file.NoSuchFileException::class)
private fun readJsonFileAsString(path: String) {
try {
java.nio.file.Files.lines(java.nio.file.FileSystems.getDefault().getPath(path)).forEach(
{ jsonString!!.append(it) }
) // JSON does not require line break
}
catch (e: IOException) {
System.err.println("[JsonFetcher] An error occurred while reading $path")
e.printStackTrace()
}
java.nio.file.Files.lines(java.nio.file.FileSystems.getDefault().getPath(path)).forEach(
{ jsonString!!.append(it) }
) // JSON does not require line break
}
}

View File

@@ -1,17 +1,12 @@
package net.torvald.terrarum.utils
import com.google.gson.Gson
import com.google.gson.JsonElement
import com.google.gson.JsonObject
import java.io.FileWriter
import java.io.IOException
/**
* Created by minjaesong on 2016-03-04.
*/
object JsonWriter {
private val formattingRegex = Regex("""(?<=[\{,\[])|(?=[\]}])""")
/**
* serialise a class to the file as JSON, using Google GSON.
*
@@ -23,7 +18,7 @@ object JsonWriter {
val classElem = com.google.gson.Gson().toJsonTree(c)
val jsonString = classElem.toString()
val writer = java.io.FileWriter(path)
writer.write(jsonString)
writer.write(jsonString.replace(formattingRegex, "\n"))
writer.close()
}
@@ -36,7 +31,7 @@ object JsonWriter {
@Throws(java.io.IOException::class)
fun writeToFile(jsonObject: com.google.gson.JsonObject, path: String) {
val writer = java.io.FileWriter(path)
writer.write(jsonObject.toString())
writer.write(jsonObject.toString().replace(formattingRegex, "\n"))
writer.close()
}