mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 12:21:52 +09:00
inventory ui
icon in list Former-commit-id: 7182dcda408d9710d77e25e357f3a67bdd42fff9
This commit is contained in:
@@ -5,6 +5,7 @@ import java.util.*
|
||||
import java.util.function.Consumer
|
||||
|
||||
typealias ActorValue = KVHashMap
|
||||
typealias ItemValue = KVHashMap
|
||||
typealias GameConfig = KVHashMap
|
||||
|
||||
/**
|
||||
|
||||
@@ -69,10 +69,10 @@ nopqrstuvwxyz
|
||||
"most of them does not support your language, vector fonts takes too much time to be loaded,",
|
||||
"even then their legibility suffers because fuck built-in antialias.",
|
||||
"You somehow found a good font, and it makes your game look like a linux terminal, and you say:",
|
||||
"\"what the fuck? Is this a game or should I rm -rf this shit‽\"",
|
||||
"“what the fuck? Is this a game or should I rm -rf this shit‽”",
|
||||
"You speak Japanese, and you wish to support it, but then このクソなfontは only good for Japanese,",
|
||||
"and it is not multilingual, and you don't have a time for this shenanigan.",
|
||||
"Eventually you give up, saying \"fuck it!\" and just use the fonts that do not match well.",
|
||||
"Eventually you give up, saying “fuck it!” and just use the fonts that do not match well.",
|
||||
"",
|
||||
"No more suffering. This font has everything you need.",
|
||||
"",
|
||||
|
||||
@@ -2,7 +2,9 @@ package net.torvald.terrarum
|
||||
|
||||
import net.torvald.terrarum.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.gameactors.InventoryPair
|
||||
import net.torvald.terrarum.gameitem.IVKey
|
||||
import net.torvald.terrarum.gameitem.InventoryItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.mapdrawer.MapCamera
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIHandler
|
||||
@@ -29,24 +31,37 @@ class StateUITest : BasicGameState() {
|
||||
ui.isVisible = true
|
||||
|
||||
|
||||
// these are the test codes.
|
||||
// Item properties must be pre-composed using CSV/JSON, and read and made into the item instance
|
||||
// using factory/builder pattern. @see ItemCodex
|
||||
inventory.add(object : InventoryItem() {
|
||||
init {
|
||||
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.HAMMER
|
||||
}
|
||||
override val id: Int = 5656
|
||||
override val isUnique: Boolean = true
|
||||
override var originalName: String = "Test tool"
|
||||
override var baseMass: Double = 12.0
|
||||
override var baseToolSize: Double? = 8.0
|
||||
override var category: String = "tool"
|
||||
override var category: String = InventoryItem.Category.TOOL
|
||||
override var maxDurability: Double = 10.0
|
||||
override var durability: Double = 10.0
|
||||
override var durability: Double = 6.43
|
||||
})
|
||||
inventory.getByID(5656)!!.item.name = "Test tool"
|
||||
|
||||
inventory.add(object : InventoryItem() {
|
||||
init {
|
||||
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.ARTEFACT
|
||||
}
|
||||
override val id: Int = 4633
|
||||
override val isUnique: Boolean = true
|
||||
override var originalName: String = "CONTEXT_ITEM_QUEST_NOUN"
|
||||
override var baseMass: Double = 1.4
|
||||
override var baseToolSize: Double? = null
|
||||
override var category: String = "bulk"
|
||||
override var category: String = InventoryItem.Category.MISC
|
||||
})
|
||||
|
||||
inventory.add(ItemCodex[16], 543)
|
||||
}
|
||||
|
||||
override fun init(container: GameContainer?, game: StateBasedGame?) {
|
||||
@@ -65,21 +80,36 @@ class StateUITest : BasicGameState() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private class SimpleUI(val inventory: ActorInventory) : UICanvas {
|
||||
override var width = 700
|
||||
override var height = 480 // multiple of 40 (2 * font.lineHeight)
|
||||
override var handler: UIHandler? = null
|
||||
override var openCloseTime: Int = UICanvas.OPENCLOSE_GENERIC
|
||||
|
||||
val itemImage = Image("./assets/item_kari_24.tga")
|
||||
val itemImagePlaceholder = Image("./assets/item_kari_24.tga")
|
||||
|
||||
val catButtonsToCatIdent = HashMap<String, String>()
|
||||
|
||||
init {
|
||||
catButtonsToCatIdent.put("GAME_INVENTORY_WEAPONS", InventoryItem.Category.WEAPON)
|
||||
catButtonsToCatIdent.put("CONTEXT_ITEM_EQUIPMENT_PLURAL", InventoryItem.Category.TOOL)
|
||||
catButtonsToCatIdent.put("CONTEXT_ITEM_ARMOR", InventoryItem.Category.ARMOUR)
|
||||
catButtonsToCatIdent.put("GAME_INVENTORY_INGREDIENTS", InventoryItem.Category.GENERIC)
|
||||
catButtonsToCatIdent.put("GAME_INVENTORY_POTIONS", InventoryItem.Category.POTION)
|
||||
catButtonsToCatIdent.put("CONTEXT_ITEM_MAGIC", InventoryItem.Category.MAGIC)
|
||||
catButtonsToCatIdent.put("GAME_INVENTORY_BLOCKS", InventoryItem.Category.BLOCK)
|
||||
catButtonsToCatIdent.put("GAME_INVENTORY_WALLS", InventoryItem.Category.WALL)
|
||||
catButtonsToCatIdent.put("GAME_GENRE_MISC", InventoryItem.Category.MISC)
|
||||
|
||||
// special filter
|
||||
catButtonsToCatIdent.put("MENU_LABEL_ALL", "__all__")
|
||||
|
||||
}
|
||||
|
||||
val buttons = UIItemTextButtonList(
|
||||
this,
|
||||
arrayOf(
|
||||
"MENU_LABEL_ALL",
|
||||
"GAME_INVENTORY_WEAPONS", // weapons and tools
|
||||
"CONTEXT_ITEM_EQUIPMENT_PLURAL",
|
||||
"CONTEXT_ITEM_ARMOR",
|
||||
@@ -88,19 +118,23 @@ private class SimpleUI(val inventory: ActorInventory) : UICanvas {
|
||||
"CONTEXT_ITEM_MAGIC",
|
||||
"GAME_INVENTORY_BLOCKS",
|
||||
"GAME_INVENTORY_WALLS",
|
||||
"GAME_INVENTORY_FAVORITES",
|
||||
"MENU_LABEL_ALL"
|
||||
"GAME_GENRE_MISC"
|
||||
//"GAME_INVENTORY_FAVORITES",
|
||||
),
|
||||
width = (width / 3 / 100) * 100, // chop to hundreds unit (100, 200, 300, ...) with the black magic of integer division
|
||||
height = height,
|
||||
readFromLang = true,
|
||||
textAreaWidth = 100,
|
||||
defaultSelection = 0,
|
||||
iconSpriteSheet = SpriteSheet("./assets/graphics/gui/inventory/category.tga", 20, 20),
|
||||
iconSpriteSheetIndices = intArrayOf(9,0,1,2,3,4,5,6,7,8),
|
||||
highlightBackCol = Color(0x202020),
|
||||
highlightBackBlendMode = BlendMode.NORMAL,
|
||||
backgroundCol = Color(0x383838),
|
||||
kinematic = true
|
||||
)
|
||||
|
||||
val itemStripGutterV = 4
|
||||
val itemStripGutterV = 10
|
||||
val itemStripGutterH = 48
|
||||
|
||||
val itemsStripWidth = width - buttons.width - 2 * itemStripGutterH
|
||||
@@ -119,29 +153,55 @@ private class SimpleUI(val inventory: ActorInventory) : UICanvas {
|
||||
var inventorySortList = ArrayList<InventoryPair>()
|
||||
var rebuildList = true
|
||||
|
||||
private var oldCatSelect = -1
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
Terrarum.gameLocale = "en" // hot swap this to test
|
||||
|
||||
buttons.update(gc, delta)
|
||||
|
||||
|
||||
// test fill: just copy the inventory, fuck sorting
|
||||
// monitor and check if category selection has been changed
|
||||
if (oldCatSelect != buttons.selectedIndex) {
|
||||
rebuildList = true
|
||||
}
|
||||
|
||||
|
||||
if (rebuildList) {
|
||||
val filter = catButtonsToCatIdent[buttons.selectedButton.labelText]
|
||||
|
||||
inventorySortList = ArrayList<InventoryPair>()
|
||||
inventory.forEach { inventorySortList.add(it) }
|
||||
|
||||
// filter items
|
||||
inventory.forEach {
|
||||
if (it.item.category == filter || filter == "__all__")
|
||||
inventorySortList.add(it)
|
||||
}
|
||||
|
||||
rebuildList = false
|
||||
|
||||
// sort if needed //
|
||||
// sort if needed
|
||||
// test sort by name
|
||||
inventorySortList.sortBy { it.item.name }
|
||||
|
||||
inventorySortList.forEachIndexed { index, pair ->
|
||||
if (index - itemsScrollOffset >= 0 && index < items.size + itemsScrollOffset) {
|
||||
items[index - itemsScrollOffset].item = pair.item
|
||||
items[index - itemsScrollOffset].amount = pair.amount
|
||||
items[index - itemsScrollOffset].itemImage = itemImage
|
||||
// map sortList to item list
|
||||
for (k in 0..items.size - 1) {
|
||||
try {
|
||||
val sortListItem = inventorySortList[k + itemsScrollOffset]
|
||||
items[k].item = sortListItem.item
|
||||
items[k].amount = sortListItem.amount
|
||||
items[k].itemImage = itemImagePlaceholder
|
||||
}
|
||||
catch (e: IndexOutOfBoundsException) {
|
||||
items[k].item = null
|
||||
items[k].amount = 0
|
||||
items[k].itemImage = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
oldCatSelect = buttons.selectedIndex
|
||||
}
|
||||
|
||||
override fun render(gc: GameContainer, g: Graphics) {
|
||||
@@ -171,7 +231,7 @@ private class SimpleUI(val inventory: ActorInventory) : UICanvas {
|
||||
UICanvas.endOpeningFade(handler)
|
||||
}
|
||||
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {7
|
||||
override fun endClosing(gc: GameContainer, delta: Int) {
|
||||
UICanvas.endClosingFade(handler)
|
||||
}
|
||||
}
|
||||
@@ -102,9 +102,23 @@ object Terrarum : StateBasedGame(GAME_NAME) {
|
||||
if (fontGame != null) (fontGame as GameFontImpl).reload()
|
||||
}
|
||||
|
||||
var fontGame: Font? = null
|
||||
var fontGame: Font = object : Font {
|
||||
override fun getHeight(str: String?) = 0
|
||||
override fun drawString(x: Float, y: Float, text: String?) {}
|
||||
override fun drawString(x: Float, y: Float, text: String?, col: Color?) {}
|
||||
override fun drawString(x: Float, y: Float, text: String?, col: Color?, startIndex: Int, endIndex: Int) {}
|
||||
override fun getWidth(str: String?) = 0
|
||||
override fun getLineHeight() = 0
|
||||
} // null font
|
||||
private set
|
||||
lateinit var fontSmallNumbers: Font
|
||||
var fontSmallNumbers: Font = object : Font {
|
||||
override fun getHeight(str: String?) = 0
|
||||
override fun drawString(x: Float, y: Float, text: String?) {}
|
||||
override fun drawString(x: Float, y: Float, text: String?, col: Color?) {}
|
||||
override fun drawString(x: Float, y: Float, text: String?, col: Color?, startIndex: Int, endIndex: Int) {}
|
||||
override fun getWidth(str: String?) = 0
|
||||
override fun getLineHeight() = 0
|
||||
} // null font
|
||||
private set
|
||||
|
||||
var joypadLabelStart: Char = 0xE000.toChar() // lateinit
|
||||
@@ -228,6 +242,10 @@ object Terrarum : StateBasedGame(GAME_NAME) {
|
||||
|
||||
@Throws(SlickException::class)
|
||||
override fun initStatesList(gc: GameContainer) {
|
||||
fontGame = GameFontImpl()
|
||||
fontSmallNumbers = TinyAlphNum()
|
||||
|
||||
|
||||
gc.input.enableKeyRepeat()
|
||||
|
||||
|
||||
@@ -243,9 +261,6 @@ object Terrarum : StateBasedGame(GAME_NAME) {
|
||||
println("[Terrarum] Locale: " + gameLocale)
|
||||
|
||||
|
||||
fontGame = GameFontImpl()
|
||||
fontSmallNumbers = TinyAlphNum()
|
||||
|
||||
|
||||
// search for real controller
|
||||
// exclude controllers with name "Mouse", "keyboard"
|
||||
@@ -286,9 +301,9 @@ object Terrarum : StateBasedGame(GAME_NAME) {
|
||||
//addState(StateBlurTest())
|
||||
//addState(StateShaderTest())
|
||||
//addState(StateNoiseTester())
|
||||
//addState(StateUITest())
|
||||
addState(StateUITest())
|
||||
//addState(StateControllerRumbleTest())
|
||||
addState(StateMidiInputTest())
|
||||
//addState(StateMidiInputTest())
|
||||
|
||||
//ingame = StateInGame(); addState(ingame)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum
|
||||
|
||||
import net.torvald.colourutil.CIELabUtil.darkerLab
|
||||
import net.torvald.terrarum.gameitem.InventoryItem
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
@@ -9,9 +10,7 @@ import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
|
||||
/**
|
||||
* @param amount: set to -1 (UIItemInventoryElem.UNIQUE_ITEM_HAS_NO_AMOUNT) for unique item (does not show item count)
|
||||
*
|
||||
/***
|
||||
* Note that the UI will not render if either item or itemImage is null.
|
||||
*
|
||||
* Created by SKYHi14 on 2017-03-16.
|
||||
@@ -39,6 +38,12 @@ class UIItemInventoryElem(
|
||||
get() = (this.height - itemImage!!.height).div(2).toFloat() // to snap to the pixel grid
|
||||
private val textOffsetX = 52f
|
||||
|
||||
|
||||
private val durabilityCol = Color(0x22ff11)
|
||||
private val durabilityBack: Color; get() = durabilityCol.darkerLab(0.4f)
|
||||
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
if (item != null) {
|
||||
|
||||
@@ -63,11 +68,22 @@ class UIItemInventoryElem(
|
||||
|
||||
// if mouse is over, text lights up
|
||||
g.color = item!!.nameColour * if (mouseUp) Color(0xffffff) else UIItemTextButton.defaultInactiveCol
|
||||
g.drawString(item!!.name, posX + textOffsetX, posY + 0f)
|
||||
g.drawString(
|
||||
item!!.name + (if (amount > 0 && !item!!.isUnique) "${0x3000.toChar()}($amount)" else "")
|
||||
, posX + textOffsetX
|
||||
, posY + 8f
|
||||
)
|
||||
|
||||
|
||||
// durability metre
|
||||
if (item!!.maxDurability > 0.0) {
|
||||
// TODO durability gauge
|
||||
g.color = durabilityBack
|
||||
g.lineWidth = 3f
|
||||
val fullLen = (width - 20f) - textOffsetX
|
||||
val barOffset = posX + textOffsetX
|
||||
g.drawLine(barOffset, posY + 35f, barOffset + fullLen, posY + 35f)
|
||||
g.color = durabilityCol
|
||||
g.drawLine(barOffset, posY + 35f, barOffset + fullLen * (item!!.durability / item!!.maxDurability).toFloat(), posY + 35f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.gameactors.Player
|
||||
import net.torvald.terrarum.gameactors.Pocketed
|
||||
import net.torvald.terrarum.gameitem.EquipPosition
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,6 @@ import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.faction.Faction
|
||||
import net.torvald.terrarum.gamecontroller.EnumKeyFunc
|
||||
import net.torvald.terrarum.gamecontroller.KeyMap
|
||||
import net.torvald.terrarum.gameitem.EquipPosition
|
||||
import net.torvald.terrarum.gameitem.InventoryItem
|
||||
import net.torvald.terrarum.realestate.RealEstateUtility
|
||||
import org.dyn4j.geometry.Vector2
|
||||
@@ -26,7 +25,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
||||
/** Must be set by PlayerFactory */
|
||||
override var inventory: ActorInventory = ActorInventory()
|
||||
|
||||
override val itemEquipped = Array<InventoryItem?>(EquipPosition.INDEX_MAX + 1, { null })
|
||||
override val itemEquipped = Array<InventoryItem?>(InventoryItem.EquipPosition.INDEX_MAX + 1, { null })
|
||||
|
||||
/** Must be set by PlayerFactory */
|
||||
override var faction: HashSet<Faction> = HashSet()
|
||||
@@ -137,6 +136,7 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
||||
|
||||
private val nullItem = object : InventoryItem() {
|
||||
override val id: Int = 0
|
||||
override val isUnique: Boolean = false
|
||||
override var baseMass: Double = 0.0
|
||||
override var baseToolSize: Double? = null
|
||||
override var category = "should_not_be_seen"
|
||||
@@ -236,12 +236,12 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
|
||||
*/
|
||||
// Left mouse
|
||||
if (isGamer && isFuncDown(input, EnumKeyFunc.HAND_PRIMARY)) {
|
||||
(itemEquipped[EquipPosition.HAND_GRIP] ?: nullItem).primaryUse(gc, delta)
|
||||
(itemEquipped[InventoryItem.EquipPosition.HAND_GRIP] ?: nullItem).primaryUse(gc, delta)
|
||||
}
|
||||
|
||||
// Right mouse
|
||||
if (isGamer && isFuncDown(input, EnumKeyFunc.HAND_SECONDARY)) {
|
||||
(itemEquipped[EquipPosition.HAND_GRIP] ?: nullItem).secondaryUse(gc, delta)
|
||||
(itemEquipped[InventoryItem.EquipPosition.HAND_GRIP] ?: nullItem).secondaryUse(gc, delta)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,6 @@ import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameactors.ai.AILuaAPI
|
||||
import net.torvald.terrarum.gameactors.ai.ActorAI
|
||||
import net.torvald.terrarum.gameactors.ai.LuaAIWrapper
|
||||
import net.torvald.terrarum.gameitem.EquipPosition
|
||||
import net.torvald.terrarum.gameitem.InventoryItem
|
||||
import org.luaj.vm2.*
|
||||
import org.luaj.vm2.compiler.LuaC
|
||||
@@ -42,7 +41,7 @@ open class HumanoidNPC(
|
||||
// we're having InventoryItem data so that this class could be somewhat universal
|
||||
override var itemData: InventoryItem = object : InventoryItem() {
|
||||
override var id = referenceID
|
||||
|
||||
override val isUnique: Boolean = true
|
||||
override var baseMass: Double
|
||||
get() = actorValue.getAsDouble(AVKey.BASEMASS)!!
|
||||
set(value) { actorValue[AVKey.BASEMASS] = value }
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.google.gson.JsonObject
|
||||
import net.torvald.terrarum.ActorValue
|
||||
import net.torvald.terrarum.gameactors.ActorHumanoid
|
||||
import net.torvald.terrarum.gameactors.faction.FactionFactory
|
||||
import net.torvald.terrarum.gameitem.EquipPosition
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer
|
||||
import net.torvald.terrarum.to10bit
|
||||
|
||||
@@ -12,9 +12,10 @@ import org.newdawn.slick.GameContainer
|
||||
*
|
||||
* Created by minjaesong on 16-09-08.
|
||||
*/
|
||||
@Deprecated("Use InventoryItem's ItemProp")
|
||||
open abstract class DynamicItem(val baseItemID: Int?, newMass: Double? = null, newScale: Double? = null)
|
||||
: InventoryItem() {
|
||||
|
||||
/*
|
||||
/**
|
||||
* Internal ID of an Item, Long
|
||||
* 0-4096: Tiles
|
||||
@@ -69,5 +70,5 @@ open abstract class DynamicItem(val baseItemID: Int?, newMass: Double? = null, n
|
||||
else {
|
||||
scale = newScale ?: ItemCodex[baseItemID].scale
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
23
src/net/torvald/terrarum/gameitem/IVKey.kt
Normal file
23
src/net/torvald/terrarum/gameitem/IVKey.kt
Normal file
@@ -0,0 +1,23 @@
|
||||
package net.torvald.terrarum.gameitem
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-09.
|
||||
*/
|
||||
object IVKey {
|
||||
const val ITEMTYPE = "itemtype" // "sword1h", "sword2h", "pick", "hammer", "tile", "wall", etc
|
||||
const val UUID = "uuid" // some items need UUID to be stored
|
||||
|
||||
|
||||
object ItemType {
|
||||
const val BLOCK = "tile"
|
||||
const val WALL = "wall"
|
||||
// tools
|
||||
const val PICK = "pick"
|
||||
const val HAMMER= "hammer"
|
||||
// weapons
|
||||
const val SWORDJAB = "sword1h"
|
||||
const val SWORDSWING = "sword2h"
|
||||
// generic
|
||||
const val ARTEFACT = "artefact" // or Key Items
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.torvald.terrarum.gameitem
|
||||
|
||||
import net.torvald.terrarum.ItemValue
|
||||
import net.torvald.terrarum.itemproperties.Material
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import org.newdawn.slick.Color
|
||||
@@ -10,17 +11,25 @@ import org.newdawn.slick.GameContainer
|
||||
*/
|
||||
abstract class InventoryItem : Comparable<InventoryItem> {
|
||||
/**
|
||||
* Internal ID of an Item, Long
|
||||
* Internal ID of an Item,
|
||||
* 0-4095: Tiles
|
||||
* 4096-32767: Static items
|
||||
* 32768-16777215: Dynamic items
|
||||
* 4096-32767: Unique items (isUnique = true), brand-new tools
|
||||
* 32768-16777215: Dynamic items (e.g. tools with damage)
|
||||
* >= 16777216: Actor RefID
|
||||
*/
|
||||
abstract val id: Int
|
||||
|
||||
/**
|
||||
* e.g. Key Items (in a Pokémon sense), floppies
|
||||
*/
|
||||
abstract val isUnique: Boolean
|
||||
|
||||
/**
|
||||
* OriginalName is always read from Language files.
|
||||
*/
|
||||
abstract protected val originalName: String
|
||||
|
||||
private var newName: String = "SET THE NAME!!"
|
||||
private var newName: String = "I AM VITTUN PLACEHOLDER"
|
||||
|
||||
var name: String
|
||||
set(value) {
|
||||
@@ -39,6 +48,8 @@ abstract class InventoryItem : Comparable<InventoryItem> {
|
||||
|
||||
abstract var category: String // "weapon", "tool", "armor", etc. (all smallcaps)
|
||||
|
||||
var itemProperties = ItemValue()
|
||||
|
||||
/**
|
||||
* Where to equip the item
|
||||
*/
|
||||
@@ -140,31 +151,43 @@ abstract class InventoryItem : Comparable<InventoryItem> {
|
||||
override fun compareTo(other: InventoryItem): Int = (this.id - other.id).sign()
|
||||
|
||||
fun Int.sign(): Int = if (this > 0) 1 else if (this < 0) -1 else 0
|
||||
}
|
||||
|
||||
object EquipPosition {
|
||||
const val NULL = -1
|
||||
object EquipPosition {
|
||||
const val NULL = -1
|
||||
|
||||
const val ARMOUR = 0
|
||||
// you can add alias to address something like LEGGINGS, BREASTPLATE, RINGS, NECKLACES, etc.
|
||||
const val BODY_BACK = 1 // wings, jetpacks, etc.
|
||||
const val BODY_BUFF2 = 2
|
||||
const val BODY_BUFF3 = 3
|
||||
const val BODY_BUFF4 = 4
|
||||
const val BODY_BUFF5 = 5
|
||||
const val BODY_BUFF6 = 6
|
||||
const val BODY_BUFF7 = 7
|
||||
const val BODY_BUFF8 = 8
|
||||
const val ARMOUR = 0
|
||||
// you can add alias to address something like LEGGINGS, BREASTPLATE, RINGS, NECKLACES, etc.
|
||||
const val BODY_BACK = 1 // wings, jetpacks, etc.
|
||||
const val BODY_BUFF2 = 2
|
||||
const val BODY_BUFF3 = 3
|
||||
const val BODY_BUFF4 = 4
|
||||
const val BODY_BUFF5 = 5
|
||||
const val BODY_BUFF6 = 6
|
||||
const val BODY_BUFF7 = 7
|
||||
const val BODY_BUFF8 = 8
|
||||
|
||||
const val HAND_GRIP = 9
|
||||
const val HAND_GAUNTLET = 10
|
||||
const val HAND_BUFF2 = 11
|
||||
const val HAND_BUFF3 = 12
|
||||
const val HAND_BUFF4 = 13
|
||||
const val HAND_GRIP = 9
|
||||
const val HAND_GAUNTLET = 10
|
||||
const val HAND_BUFF2 = 11
|
||||
const val HAND_BUFF3 = 12
|
||||
const val HAND_BUFF4 = 13
|
||||
|
||||
const val FOOTWEAR = 14
|
||||
const val FOOTWEAR = 14
|
||||
|
||||
const val HEADGEAR = 15
|
||||
const val HEADGEAR = 15
|
||||
|
||||
const val INDEX_MAX = 15
|
||||
const val INDEX_MAX = 15
|
||||
}
|
||||
|
||||
object Category {
|
||||
const val WEAPON = "weapon"
|
||||
const val TOOL = "tool"
|
||||
const val ARMOUR = "armour"
|
||||
const val GENERIC = "generic"
|
||||
const val POTION = "potion"
|
||||
const val MAGIC = "magic"
|
||||
const val BLOCK = "block"
|
||||
const val WALL = "wall"
|
||||
const val MISC = "misc"
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package net.torvald.terrarum.gameitem
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 16-09-09.
|
||||
*/
|
||||
object ItemInfoKey {
|
||||
const val SCALE = "scale"
|
||||
const val MASS = "mass"
|
||||
const val UUID = "uuid"
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.ActorWithSprite
|
||||
import net.torvald.terrarum.gamecontroller.mouseTileX
|
||||
import net.torvald.terrarum.gamecontroller.mouseTileY
|
||||
import net.torvald.terrarum.gameitem.EquipPosition
|
||||
import net.torvald.terrarum.gameitem.IVKey
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.tileproperties.TileCodex
|
||||
import org.newdawn.slick.GameContainer
|
||||
@@ -34,16 +34,21 @@ object ItemCodex {
|
||||
val ITEM_STATIC_MIN = ITEM_TILE_MAX + 1 // 4096
|
||||
|
||||
init {
|
||||
// tile items
|
||||
// tile items (blocks and walls are the same thing basically)
|
||||
for (i in 0..ITEM_TILE_MAX) {
|
||||
itemCodex[i] = object : InventoryItem() {
|
||||
override val id: Int = i
|
||||
override val isUnique: Boolean = false
|
||||
override var baseMass: Double = TileCodex[i].density / 1000.0
|
||||
override var baseToolSize: Double? = null
|
||||
override var equipPosition = EquipPosition.HAND_GRIP
|
||||
override var category = "block"
|
||||
override val originalName = TileCodex[i].nameKey
|
||||
|
||||
init {
|
||||
itemProperties[IVKey.ITEMTYPE] = IVKey.ItemType.BLOCK
|
||||
}
|
||||
|
||||
override fun primaryUse(gc: GameContainer, delta: Int) {
|
||||
// TODO base punch attack
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ abstract class UIItem(var parentUI: UICanvas) { // do not replace parentUI to UI
|
||||
protected val relativeMouseY: Int
|
||||
get() = (Terrarum.appgc.mouseY - (parentUI.handler?.posY ?: 0) - this.posY).roundInt()
|
||||
|
||||
val mouseUp: Boolean
|
||||
open val mouseUp: Boolean
|
||||
get() = relativeMouseX in 0..width - 1 && relativeMouseY in 0..height - 1
|
||||
val mousePushed: Boolean
|
||||
open val mousePushed: Boolean
|
||||
get() = mouseUp && Terrarum.appgc.input.isMouseButtonDown(Terrarum.getConfigInt("mouseprimary")!!)
|
||||
|
||||
abstract fun update(gc: GameContainer, delta: Int)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.torvald.terrarum.ui
|
||||
|
||||
import net.torvald.point.Point2d
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameactors.Hitbox
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
@@ -24,16 +26,18 @@ class UIItemTextButton(
|
||||
val highlightCol: Color = Color(0x00f8ff),
|
||||
val highlightBackCol: Color = Color(0xb0b0b0),
|
||||
val highlightBackBlendMode: String = BlendMode.MULTIPLY,
|
||||
val inactiveCol: Color = UIItemTextButton.defaultInactiveCol
|
||||
val inactiveCol: Color = UIItemTextButton.defaultInactiveCol,
|
||||
val preGapX: Int = 0,
|
||||
val postGapX: Int = 0
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
companion object {
|
||||
val font = Terrarum.fontGame!!
|
||||
val font = Terrarum.fontGame
|
||||
val height = font.lineHeight * 2
|
||||
val defaultInactiveCol: Color = Color(0xc8c8c8)
|
||||
}
|
||||
|
||||
private val label: String
|
||||
val label: String
|
||||
get() = if (readFromLang) Lang[labelText] else labelText
|
||||
|
||||
|
||||
@@ -70,7 +74,11 @@ class UIItemTextButton(
|
||||
else if (mouseOver) activeCol
|
||||
else inactiveCol
|
||||
|
||||
g.drawString(label, posX.toFloat() + (width.minus(textW).div(2)), posY.toFloat() + height / 4)
|
||||
g.drawString(
|
||||
label,
|
||||
posX.toFloat() + width.minus(textW).div(2) + (preGapX - postGapX).div(2),
|
||||
posY.toFloat() + height / 4
|
||||
)
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
|
||||
@@ -4,9 +4,11 @@ import net.torvald.terrarum.BlendMode
|
||||
import net.torvald.terrarum.gameactors.roundInt
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.Millisec
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import org.newdawn.slick.Color
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.SpriteSheet
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-03-13.
|
||||
@@ -17,6 +19,12 @@ class UIItemTextButtonList(
|
||||
override val width: Int,
|
||||
override val height: Int,
|
||||
val readFromLang: Boolean = false,
|
||||
val defaultSelection: Int = 0,
|
||||
|
||||
// icons
|
||||
val textAreaWidth: Int,
|
||||
val iconSpriteSheet: SpriteSheet? = null,
|
||||
val iconSpriteSheetIndices: IntArray? = null,
|
||||
|
||||
// copied directly from UIItemTextButton
|
||||
val activeCol: Color = Color.white,
|
||||
@@ -31,6 +39,15 @@ class UIItemTextButtonList(
|
||||
val kinematic: Boolean = false // more "kinetic" movement of selector
|
||||
) : UIItem(parentUI) {
|
||||
|
||||
val iconToTextGap = 20
|
||||
val iconCellWidth = (iconSpriteSheet?.width ?: -iconToTextGap) / (iconSpriteSheet?.horizontalCount ?: 1)
|
||||
val iconCellHeight = (iconSpriteSheet?.height ?: 0) / (iconSpriteSheet?.verticalCount ?: 1)
|
||||
|
||||
// zero if iconSpriteSheet is null
|
||||
val iconsWithGap: Int = iconToTextGap + iconCellWidth
|
||||
val pregap = (width - textAreaWidth - iconsWithGap) / 2 + iconsWithGap
|
||||
val postgap = (width - textAreaWidth - iconsWithGap) / 2
|
||||
|
||||
val buttons = labelsList.mapIndexed { index, s ->
|
||||
val height = this.height - UIItemTextButton.height
|
||||
if (!kinematic) {
|
||||
@@ -39,14 +56,16 @@ class UIItemTextButtonList(
|
||||
posX = 0,
|
||||
posY = (height / labelsList.size.minus(1).toFloat() * index).roundInt(),
|
||||
width = width,
|
||||
readFromLang = true,
|
||||
readFromLang = readFromLang,
|
||||
activeCol = activeCol,
|
||||
activeBackCol = activeBackCol,
|
||||
activeBackBlendMode = activeBackBlendMode,
|
||||
highlightCol = highlightCol,
|
||||
highlightBackCol = highlightBackCol,
|
||||
highlightBackBlendMode = highlightBackBlendMode,
|
||||
inactiveCol = inactiveCol
|
||||
inactiveCol = inactiveCol,
|
||||
preGapX = pregap,
|
||||
postGapX = postgap
|
||||
)
|
||||
}
|
||||
else {
|
||||
@@ -55,10 +74,12 @@ class UIItemTextButtonList(
|
||||
posX = 0,
|
||||
posY = (height / labelsList.size.minus(1).toFloat() * index).roundInt(),
|
||||
width = width,
|
||||
readFromLang = true,
|
||||
readFromLang = readFromLang,
|
||||
activeBackCol = Color(0,0,0,0),
|
||||
activeBackBlendMode = BlendMode.NORMAL,
|
||||
highlightBackCol = Color(0,0,0,0)
|
||||
highlightBackCol = Color(0,0,0,0),
|
||||
preGapX = pregap,
|
||||
postGapX = postgap
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -66,8 +87,10 @@ class UIItemTextButtonList(
|
||||
override var posX = 0
|
||||
override var posY = 0
|
||||
|
||||
var selected = labelsList.size - 1 // default to "All"
|
||||
private var highlightY = buttons[selected].posY.toDouble()
|
||||
var selectedIndex = defaultSelection
|
||||
val selectedButton: UIItemTextButton
|
||||
get() = buttons[selectedIndex]
|
||||
private var highlightY = buttons[selectedIndex].posY.toDouble()
|
||||
private val highlighterMoveDuration: Millisec = 100
|
||||
private var highlighterMoveTimer: Millisec = 0
|
||||
private var highlighterMoving = false
|
||||
@@ -97,19 +120,19 @@ class UIItemTextButtonList(
|
||||
btn.update(gc, delta)
|
||||
|
||||
|
||||
if (btn.mousePushed && index != selected) {
|
||||
if (btn.mousePushed && index != selectedIndex) {
|
||||
if (kinematic) {
|
||||
highlighterYStart = buttons[selected].posY.toDouble()
|
||||
selected = index
|
||||
highlighterYStart = buttons[selectedIndex].posY.toDouble()
|
||||
selectedIndex = index
|
||||
highlighterMoving = true
|
||||
highlighterYEnd = buttons[selected].posY.toDouble()
|
||||
highlighterYEnd = buttons[selectedIndex].posY.toDouble()
|
||||
}
|
||||
else {
|
||||
selected = index
|
||||
highlightY = buttons[selected].posY.toDouble()
|
||||
selectedIndex = index
|
||||
highlightY = buttons[selectedIndex].posY.toDouble()
|
||||
}
|
||||
}
|
||||
btn.highlighted = (index == selected) // forcibly highlight if this.highlighted != null
|
||||
btn.highlighted = (index == selectedIndex) // forcibly highlight if this.highlighted != null
|
||||
|
||||
}
|
||||
}
|
||||
@@ -123,6 +146,17 @@ class UIItemTextButtonList(
|
||||
g.fillRect(posX.toFloat(), highlightY.toFloat(), width.toFloat(), UIItemTextButton.height.toFloat())
|
||||
|
||||
buttons.forEach { it.render(gc, g) }
|
||||
|
||||
if (iconSpriteSheet != null) {
|
||||
val iconY = (buttons[1].height - iconCellHeight) / 2
|
||||
iconSpriteSheetIndices!!.forEachIndexed { counter, imageIndex ->
|
||||
iconSpriteSheet.getSubImage(imageIndex, 0).draw(
|
||||
32f,
|
||||
buttons[counter].posY + iconY.toFloat()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun keyPressed(key: Int, c: Char) {
|
||||
|
||||
@@ -36,7 +36,7 @@ class UIVitalMetre(
|
||||
private val theta = 33f
|
||||
private val halfTheta = theta / 2f
|
||||
|
||||
private val backColor: Color; get() = color?.darkerLab(0.3f) ?: Color.black
|
||||
private val backColor: Color; get() = color?.darkerLab(0.4f) ?: Color.black
|
||||
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
|
||||
Reference in New Issue
Block a user