inventory UI: quickslot designation

Former-commit-id: b2bddf7c271c678213f8f346d1de4b5c1dc27f60
This commit is contained in:
Song Minjae
2017-03-26 00:42:41 +09:00
parent b6290134a9
commit 816502df3d
29 changed files with 137 additions and 93 deletions

View File

@@ -94,7 +94,7 @@ nopqrstuvwxyz
"Широкая электрификация южных губерний даст мощный толчок подъёму сельского хозяйства",
"Pijamalı hasta yağız şoföre çabucak güvendi",
"Also supports: Unicode „quotation marks“—dashes…「括弧」‼",
"ASCII Latin-1 Latin_Ext-A Latin_Ext-B Greek Cyrillic CJK-Ideo Kana Hangul_Syllables (More coming!)",
"ASCII Latin-1 Latin_Ext-A Latin_Ext-B Greek Cyrillic CJK-Ideo Kana Hangul_Syllables",
""
)

View File

@@ -13,6 +13,7 @@ import net.torvald.terrarum.ui.UIItemTextButtonList
import org.newdawn.slick.*
import org.newdawn.slick.state.BasicGameState
import org.newdawn.slick.state.StateBasedGame
import java.util.*
/**
* Created by SKYHi14 on 2017-03-13.
@@ -68,6 +69,8 @@ class StateUITest : BasicGameState() {
}
override fun update(container: GameContainer, game: StateBasedGame, delta: Int) {
Terrarum.appgc.setTitle("${Terrarum.NAME} — F: ${Terrarum.appgc.fps}")
ui.update(container, delta)
}
@@ -92,7 +95,7 @@ private class SimpleUI(val inventory: ActorInventory) : UICanvas {
init {
catButtonsToCatIdent.put("GAME_INVENTORY_WEAPONS", InventoryItem.Category.WEAPON)
catButtonsToCatIdent.put("CONTEXT_ITEM_EQUIPMENT_PLURAL", InventoryItem.Category.TOOL)
catButtonsToCatIdent.put("CONTEXT_ITEM_TOOL_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)
@@ -111,7 +114,7 @@ private class SimpleUI(val inventory: ActorInventory) : UICanvas {
arrayOf(
"MENU_LABEL_ALL",
"GAME_INVENTORY_WEAPONS", // weapons and tools
"CONTEXT_ITEM_EQUIPMENT_PLURAL",
"CONTEXT_ITEM_TOOL_PLURAL",
"CONTEXT_ITEM_ARMOR",
"GAME_INVENTORY_INGREDIENTS",
"GAME_INVENTORY_POTIONS",
@@ -156,7 +159,7 @@ private class SimpleUI(val inventory: ActorInventory) : UICanvas {
private var oldCatSelect = -1
override fun update(gc: GameContainer, delta: Int) {
Terrarum.gameLocale = "en" // hot swap this to test
Terrarum.gameLocale = "fiFI" // hot swap this to test
buttons.update(gc, delta)
@@ -191,11 +194,14 @@ private class SimpleUI(val inventory: ActorInventory) : UICanvas {
items[k].item = sortListItem.item
items[k].amount = sortListItem.amount
items[k].itemImage = itemImagePlaceholder
items[k].quickslot = Random().nextInt(10) // TODO test
}
catch (e: IndexOutOfBoundsException) {
items[k].item = null
items[k].amount = 0
items[k].itemImage = null
items[k].quickslot = null
}
}
}

View File

@@ -279,8 +279,13 @@ object Terrarum : StateBasedGame(GAME_NAME) {
break
}
}
// test acquired controller
controller!!.getAxisValue(0)
}
catch (e: IndexOutOfBoundsException) {
catch (controllerDoesNotHaveAnyAxesException: java.lang.ArrayIndexOutOfBoundsException) {
controller = null
}
if (controller != null) {
@@ -304,6 +309,7 @@ object Terrarum : StateBasedGame(GAME_NAME) {
addState(StateUITest())
//addState(StateControllerRumbleTest())
//addState(StateMidiInputTest())
//addState(StateNewRunesTest())
//ingame = StateInGame(); addState(ingame)

View File

@@ -24,7 +24,9 @@ class UIItemInventoryElem(
var amount: Int,
var itemImage: Image?,
val backCol: Color = Color(0,0,0,0),
val backColBlendMode: String = BlendMode.NORMAL
val backColBlendMode: String = BlendMode.NORMAL,
var quickslot: Int? = null,
var equippedSlot: Int? = null
) : UIItem(parentUI) {
companion object {
@@ -37,10 +39,12 @@ class UIItemInventoryElem(
private val imgOffset: Float
get() = (this.height - itemImage!!.height).div(2).toFloat() // to snap to the pixel grid
private val textOffsetX = 52f
private val textOffsetY = 8f
private val durabilityCol = Color(0x22ff11)
private val durabilityBack: Color; get() = durabilityCol.darkerLab(0.4f)
private val durabilityBarOffY = 35f
@@ -71,20 +75,30 @@ class UIItemInventoryElem(
g.drawString(
item!!.name + (if (amount > 0 && !item!!.isUnique) "${0x3000.toChar()}($amount)" else "")
, posX + textOffsetX
, posY + 8f
, posY + textOffsetY
)
// durability metre
val barFullLen = (width - 20f) - textOffsetX
val barOffset = posX + textOffsetX
if (item!!.maxDurability > 0.0) {
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.drawLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen, posY + durabilityBarOffY)
g.color = durabilityCol
g.drawLine(barOffset, posY + 35f, barOffset + fullLen * (item!!.durability / item!!.maxDurability).toFloat(), posY + 35f)
g.drawLine(barOffset, posY + durabilityBarOffY, barOffset + barFullLen * (item!!.durability / item!!.maxDurability).toFloat(), posY + durabilityBarOffY)
}
// quickslot marker (TEMPORARY UNTIL WE GET BETTER DESIGN)
if (quickslot != null) {
val label = quickslot!!.plus(0xE010).toChar()
val labelW = g.font.getWidth("$label")
g.color = Color.white
g.drawString("$label", barOffset + barFullLen - labelW, posY + textOffsetY)
}
}
}

View File

@@ -87,5 +87,7 @@ object AVKey {
const val __PLAYER_QUICKBARSEL = "__quickbarselection"
const val __PLAYER_QUICKSLOTSEL = "__quickslotselection"
/** Item ID; they are supposed to be unique */
const val __PLAYER_QSPREFIX = "__qsitem" // __qsitem1 .. __qsitem10
}

View File

@@ -7,8 +7,6 @@ import net.torvald.terrarum.gamecontroller.EnumKeyFunc
import net.torvald.terrarum.gamecontroller.KeyMap
import net.torvald.terrarum.gameitem.InventoryItem
import net.torvald.terrarum.realestate.RealEstateUtility
import org.dyn4j.geometry.Vector2
import org.lwjgl.input.Controller
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Input
import java.util.*
@@ -24,9 +22,9 @@ open class ActorHumanoid(birth: GameDate, death: GameDate? = null)
/** Must be set by PlayerFactory */
override var inventory: ActorInventory = ActorInventory()
override val itemEquipped = Array<InventoryItem?>(InventoryItem.EquipPosition.INDEX_MAX + 1, { null })
/** Must be set by PlayerFactory */
override var faction: HashSet<Faction> = HashSet()
/**

View File

@@ -18,7 +18,7 @@ object PlayerBuilder {
// attach sprite
// do etc.
p.actorValue[AVKey.__PLAYER_QUICKBARSEL] = 0
p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0
return p
}

View File

@@ -18,7 +18,7 @@ object PlayerBuilderCynthia {
InjectCreatureRaw(p.actorValue, "CreatureHuman.json")
p.actorValue[AVKey.__PLAYER_QUICKBARSEL] = 0
p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0
p.actorValue[AVKey.NAME] = "Cynthia"

View File

@@ -60,7 +60,7 @@ object PlayerBuilderSigrid {
p.actorValue[AVKey.BASEDEFENCE] = 141
p.actorValue[AVKey.__PLAYER_QUICKBARSEL] = 0
p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0
//p.actorValue["__selectedtile"] = 147 // test code; replace with <tile_item>.primaryUse(gc, delta)
p.actorValue["__aimhelper"] = true // TODO when you'll gonna implement it?

View File

@@ -12,7 +12,7 @@ object PlayerBuilderTestSubject1 {
InjectCreatureRaw(p.actorValue, "CreatureHuman.json")
p.actorValue[AVKey.__PLAYER_QUICKBARSEL] = 0
p.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = 0
p.actorValue[AVKey.NAME] = "Test Subject 1"

View File

@@ -24,7 +24,7 @@ class UIInventory : UICanvas {
private val categories = arrayOf(
"GAME_INVENTORY_WEAPONS", // weapons and tools
"CONTEXT_ITEM_EQUIPMENT_PLURAL",
"CONTEXT_ITEM_TOOL_PLURAL",
"CONTEXT_ITEM_ARMOR",
"GAME_INVENTORY_INGREDIENTS",
"GAME_INVENTORY_POTIONS",

View File

@@ -65,7 +65,6 @@ class UIItemTextButton(
g.fillRect(posX.toFloat(), posY.toFloat(), width.toFloat(), height.toFloat())
}
blendNormal()
g.font = font

View File

@@ -35,7 +35,7 @@ class UIPieMenu : UICanvas {
override fun update(gc: GameContainer, delta: Int) {
if (selection >= 0)
Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKBARSEL] =
Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] =
selection % slotCount

View File

@@ -25,8 +25,8 @@ class UIQuickBar : UICanvas, MouseControlled {
override var handler: UIHandler? = null
private var selection: Int
get() = Terrarum.ingame!!.player.actorValue.getAsInt(AVKey.__PLAYER_QUICKBARSEL) ?: 0
set(value) { Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKBARSEL] = value }
get() = Terrarum.ingame!!.player.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
set(value) { Terrarum.ingame!!.player.actorValue[AVKey.__PLAYER_QUICKSLOTSEL] = value }
override fun update(gc: GameContainer, delta: Int) {
}