mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
fixed various quirks and removed dirty hacks on quickslot bar/pie
This commit is contained in:
@@ -10,9 +10,9 @@ uniform sampler2D u_texture;
|
||||
|
||||
|
||||
// "steps" of R, G and B. Must be integer && equal or greater than 2
|
||||
uniform float rcount = 32.0;
|
||||
uniform float gcount = 32.0;
|
||||
uniform float bcount = 32.0;
|
||||
uniform float rcount = 64.0;
|
||||
uniform float gcount = 64.0;
|
||||
uniform float bcount = 64.0;
|
||||
uniform float acount = 1.0;
|
||||
|
||||
int bayer[14 * 14] = int[](131,187,8,78,50,18,134,89,155,102,29,95,184,73,22,86,113,171,142,105,34,166,9,60,151,128,40,110,168,137,45,28,64,188,82,54,124,189,80,13,156,56,7,61,186,121,154,6,108,177,24,100,38,176,93,123,83,148,96,17,88,133,44,145,69,161,139,72,30,181,115,27,163,47,178,65,164,14,120,48,5,127,153,52,190,58,126,81,116,21,106,77,173,92,191,63,99,12,76,144,4,185,37,149,192,39,135,23,117,31,170,132,35,172,103,66,129,79,3,97,57,159,70,141,53,94,114,20,49,158,19,146,169,122,183,11,104,180,2,165,152,87,182,118,91,42,67,25,84,147,43,85,125,68,16,136,71,10,193,112,160,138,51,111,162,26,194,46,174,107,41,143,33,74,1,101,195,15,75,140,109,90,32,62,157,98,167,119,179,59,36,130,175,55,0,150);
|
||||
|
||||
@@ -588,6 +588,7 @@ infix fun Color.mul(other: Color): Color = this.cpy().mul(other)
|
||||
|
||||
|
||||
fun blendMul(batch: SpriteBatch? = null) {
|
||||
// will break if the colour image contains semitransparency
|
||||
(batch ?: Terrarum.batch).enableBlending()
|
||||
(batch ?: Terrarum.batch).setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
||||
Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation
|
||||
@@ -597,12 +598,18 @@ fun blendNormal(batch: SpriteBatch? = null) {
|
||||
(batch ?: Terrarum.batch).enableBlending()
|
||||
(batch ?: Terrarum.batch).setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
||||
|
||||
// alpha must not be premultiplied
|
||||
// ALPHA MUST NOT BE PREMULTIPLIED //
|
||||
// we're using separate blend func to accomodate not-premultiplied alpha
|
||||
Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation
|
||||
Gdx.gl.glBlendFuncSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_SRC_ALPHA, GL20.GL_ONE)
|
||||
|
||||
// helpful links:
|
||||
// - https://gamedev.stackexchange.com/questions/82741/normal-blend-mode-with-opengl-trouble
|
||||
// - https://www.andersriggelsen.dk/glblendfunc.php
|
||||
}
|
||||
|
||||
fun blendScreen(batch: SpriteBatch? = null) {
|
||||
// will break if the colour image contains semitransparency
|
||||
(batch ?: Terrarum.batch).enableBlending()
|
||||
(batch ?: Terrarum.batch).setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_COLOR)
|
||||
Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD) // batch.flush does not touch blend equation
|
||||
@@ -621,9 +628,15 @@ fun gdxClearAndSetBlend(r: Float, g: Float, b: Float, a: Float) {
|
||||
// this assumens premultiplied alpha?
|
||||
//Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)
|
||||
|
||||
// alpha must not be premultiplied
|
||||
// ALPHA MUST NOT BE PREMULTIPLIED //
|
||||
// we're using separate blend func to accomodate not-premultiplied alpha
|
||||
Gdx.gl.glBlendFuncSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_SRC_ALPHA, GL20.GL_ONE)
|
||||
Gdx.gl.glBlendEquation(GL20.GL_FUNC_ADD)
|
||||
|
||||
|
||||
// helpful links:
|
||||
// - https://gamedev.stackexchange.com/questions/82741/normal-blend-mode-with-opengl-trouble
|
||||
// - https://www.andersriggelsen.dk/glblendfunc.php
|
||||
}
|
||||
|
||||
object BlendMode {
|
||||
|
||||
@@ -143,7 +143,7 @@ class UIItemInventoryElem(
|
||||
|
||||
val inventory = player.inventory
|
||||
val slot = if (keycode == Input.Keys.NUM_0) 9 else keycode - Input.Keys.NUM_1
|
||||
val currentSlotItem = inventory?.getQuickBar(slot)
|
||||
val currentSlotItem = inventory?.getQuickslot(slot)
|
||||
|
||||
|
||||
inventory.setQuickBar(
|
||||
@@ -157,7 +157,7 @@ class UIItemInventoryElem(
|
||||
// search for duplicates in the quickbar, except mine
|
||||
// if there is, unregister the other
|
||||
(0..9).minus(slot).forEach {
|
||||
if (inventory.getQuickBar(it)?.item == item) {
|
||||
if (inventory.getQuickslot(it)?.item == item) {
|
||||
inventory.setQuickBar(it, null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ class UIItemInventoryElemSimple(
|
||||
|
||||
val inventory = player.inventory
|
||||
val slot = if (keycode == Input.Keys.NUM_0) 9 else keycode - Input.Keys.NUM_1
|
||||
val currentSlotItem = inventory.getQuickBar(slot)
|
||||
val currentSlotItem = inventory.getQuickslot(slot)
|
||||
|
||||
|
||||
inventory.setQuickBar(
|
||||
@@ -143,7 +143,7 @@ class UIItemInventoryElemSimple(
|
||||
// search for duplicates in the quickbar, except mine
|
||||
// if there is, unregister the other
|
||||
(0..9).minus(slot).forEach {
|
||||
if (inventory.getQuickBar(it)?.item == item) {
|
||||
if (inventory.getQuickslot(it)?.item == item) {
|
||||
inventory.setQuickBar(it, null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,60 @@
|
||||
package net.torvald.terrarum.debuggerapp;
|
||||
|
||||
/**
|
||||
* To be used as undo/redo buffer. Which means, current position can go backward and rewrite objects ahead.
|
||||
*
|
||||
* The most recent item will be same as the current edit.
|
||||
*
|
||||
* Created by minjaesong on 2019-01-09.
|
||||
*/
|
||||
public class TraversingCircularArray {
|
||||
public class TraversingCircularArray<T> {
|
||||
|
||||
private T[] buf;
|
||||
private int size;
|
||||
|
||||
public TraversingCircularArray(int size) {
|
||||
buf = (T[]) new Object[size]; // create array of nulls
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
private int tail = 0;
|
||||
private int head = -1;
|
||||
|
||||
private int unreliableAddCount = 0;
|
||||
|
||||
/**
|
||||
* Adds new item.
|
||||
* @param item
|
||||
*/
|
||||
public void undoNew(T item) {
|
||||
if (unreliableAddCount <= size) unreliableAddCount += 1;
|
||||
|
||||
head = (head + 1) % size;
|
||||
if (unreliableAddCount > size) {
|
||||
tail = (tail + 1) % size;
|
||||
}
|
||||
|
||||
buf[head] = item; // overwrites oldest item when eligible
|
||||
}
|
||||
|
||||
/**
|
||||
* Pops existing item. This function is analogous to rewinding the tape. Existing data will be untouched.
|
||||
* @return
|
||||
*/
|
||||
public T redo() {
|
||||
tail -= 1;
|
||||
return buf[tail];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undo the redo. This function is analogous to fast-forwarding the tape, without touching already recorded data.
|
||||
* If head of the tape reached, will do nothing.
|
||||
*/
|
||||
public T undoAgain() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +230,9 @@ object ItemCodex {
|
||||
itemCodex[code] = item
|
||||
}
|
||||
|
||||
fun getItemImage(item: GameItem): TextureRegion {
|
||||
fun getItemImage(item: GameItem?): TextureRegion? {
|
||||
if (item == null) return null
|
||||
|
||||
// terrain
|
||||
if (item.originalID in ITEM_TILES) {
|
||||
return BlocksDrawer.tilesTerrain.get(
|
||||
|
||||
@@ -307,12 +307,12 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
|
||||
// >- lesser UIs -<
|
||||
// quick bar
|
||||
uiQuickBar = UIQuickBar()
|
||||
uiQuickBar = UIQuickslotBar()
|
||||
uiQuickBar.isVisible = true
|
||||
uiQuickBar.setPosition((Terrarum.WIDTH - uiQuickBar.width) / 2 + 12, -10)
|
||||
uiQuickBar.setPosition((Terrarum.WIDTH - uiQuickBar.width) / 2, 8)
|
||||
|
||||
// pie menu
|
||||
uiPieMenu = UIPieMenu()
|
||||
uiPieMenu = uiQuickslotPie()
|
||||
uiPieMenu.setPosition(Terrarum.HALFW, Terrarum.HALFH)
|
||||
|
||||
// vital metre
|
||||
@@ -965,7 +965,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
Watch7SegMain.dispose()
|
||||
WatchDotAlph.dispose()
|
||||
|
||||
ItemSlotImageBuilder.dispose()
|
||||
ItemSlotImageFactory.dispose()
|
||||
|
||||
MessageWindow.SEGMENT_BLACK.dispose()
|
||||
MessageWindow.SEGMENT_WHITE.dispose()
|
||||
|
||||
@@ -202,7 +202,7 @@ object IngameRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
// works but some UI elements have wrong transparency
|
||||
// works but some UI elements have wrong transparency -> should be fixed with Terrarum.gdxCleanAndSetBlend -- Torvald 2019-01-12
|
||||
blendNormal(batch)
|
||||
}
|
||||
|
||||
|
||||
@@ -589,7 +589,7 @@ open class ActorHumanoid(
|
||||
// quickslot implementation
|
||||
if (key == AVKey.__PLAYER_QUICKSLOTSEL && value != null) {
|
||||
// ONLY FOR HAND_GRIPs!!
|
||||
val quickBarItem = inventory.getQuickBar(actorValue.getAsInt(key)!!)?.item
|
||||
val quickBarItem = inventory.getQuickslot(actorValue.getAsInt(key)!!)?.item
|
||||
|
||||
if (quickBarItem != null && quickBarItem.equipPosition == GameItem.EquipPosition.HAND_GRIP) {
|
||||
equipItem(quickBarItem)
|
||||
|
||||
@@ -130,7 +130,7 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode
|
||||
quickBar[slot] = dynamicID
|
||||
}
|
||||
|
||||
fun getQuickBar(slot: Int): InventoryPair? = getByDynamicID(quickBar[slot])
|
||||
fun getQuickslot(slot: Int): InventoryPair? = getByDynamicID(quickBar[slot])
|
||||
|
||||
/**
|
||||
* HashMap<GameItem, Amounts>
|
||||
|
||||
@@ -31,6 +31,8 @@ object PlayerBuilderTestSubject1 {
|
||||
|
||||
PlayerBuilderSigrid.fillTestInventory(p.inventory)
|
||||
|
||||
p.isNoClip = true
|
||||
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.Texture
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.gameactors.ai.toInt
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
|
||||
/**
|
||||
* Make item slot image with number on bottom-right
|
||||
*
|
||||
* Created by minjaesong on 2016-07-20.
|
||||
*/
|
||||
object ItemSlotImageBuilder {
|
||||
|
||||
// FIXME it leaks mem waaaaagh
|
||||
|
||||
val colourBlack = Color(0x404040_FF)
|
||||
val colourWhite = Color(0xC0C0C0_FF.toInt())
|
||||
|
||||
val slotImage = TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slots_atlas.tga"), 38, 38) // must have same w/h as slotLarge
|
||||
|
||||
|
||||
private val imageDict = HashMap<Long, Texture>()
|
||||
|
||||
|
||||
fun produce(isBlack: Boolean, number: Int = 10): TextureRegion {
|
||||
return slotImage.get(number, 0 or isBlack.toInt().shl(1))
|
||||
}
|
||||
|
||||
fun produceLarge(isBlack: Boolean, number: Int = 10): TextureRegion {
|
||||
return slotImage.get(number, 1 or isBlack.toInt().shl(1))
|
||||
}
|
||||
|
||||
|
||||
fun dispose() {
|
||||
slotImage.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package net.torvald.terrarum.modulebasegame.ui
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.gameactors.ai.toInt
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
|
||||
/**
|
||||
* Make item slot image with number on bottom-right
|
||||
*
|
||||
* Created by minjaesong on 2016-07-20.
|
||||
*/
|
||||
object ItemSlotImageFactory {
|
||||
|
||||
val colourBlack = Color(0x404040_FF)
|
||||
val colourWhite = Color(0xC0C0C0_FF.toInt())
|
||||
|
||||
val slotImage = TextureRegionPack(Gdx.files.internal("./assets/graphics/gui/quickbar/item_slots_atlas.tga"), 38, 38) // must have same w/h as slotLarge
|
||||
|
||||
fun produce(isBlack: Boolean, number: Int = 10, item: GameItem?): ItemSlotImage {
|
||||
return ItemSlotImage(slotImage.get(number, 0 or isBlack.toInt().shl(1)), ItemCodex.getItemImage(item))
|
||||
}
|
||||
|
||||
fun produceLarge(isBlack: Boolean, number: Int = 10, item: GameItem?): ItemSlotImage {
|
||||
return ItemSlotImage(slotImage.get(number, 1 or isBlack.toInt().shl(1)), ItemCodex.getItemImage(item))
|
||||
}
|
||||
|
||||
|
||||
fun dispose() {
|
||||
slotImage.dispose()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data class ItemSlotImage(val baseTex: TextureRegion, val itemTex: TextureRegion?) {
|
||||
/**
|
||||
* batch.begin() must be called beforehand.
|
||||
*
|
||||
* @param batch a spritebatch
|
||||
* @param cx centre-x position of the draw
|
||||
* @param cy centre-y position of the draw
|
||||
*/
|
||||
fun draw(batch: SpriteBatch, cx: Int, cy: Int) {
|
||||
// just draws two image on the centre
|
||||
|
||||
batch.draw(baseTex, cx - (baseTex.regionWidth).div(2).toFloat(), cy - (baseTex.regionHeight).div(2).toFloat())
|
||||
if (itemTex != null)
|
||||
batch.draw(itemTex, cx - (itemTex.regionWidth).div(2).toFloat(), cy - (itemTex.regionHeight).div(2).toFloat())
|
||||
|
||||
}
|
||||
}
|
||||
@@ -316,8 +316,8 @@ package net.torvald.terrarum.modulebasegame.ui
|
||||
items[k].itemImage = ItemCodex.getItemImage(sortListItem.item)
|
||||
|
||||
// set quickslot number
|
||||
for (qs in 1..UIQuickBar.SLOT_COUNT) {
|
||||
if (sortListItem.item == actor?.inventory?.getQuickBar(qs - 1)?.item) {
|
||||
for (qs in 1..UIQuickslotBar.SLOT_COUNT) {
|
||||
if (sortListItem.item == actor?.inventory?.getQuickslot(qs - 1)?.item) {
|
||||
items[k].quickslot = qs % 10 // 10 -> 0, 1..9 -> 1..9
|
||||
break
|
||||
}
|
||||
|
||||
@@ -3,20 +3,16 @@ package net.torvald.terrarum.modulebasegame.ui
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.BlendMode
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.UIItemInventoryElem
|
||||
import net.torvald.terrarum.UIItemInventoryElemSimple
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
||||
import net.torvald.terrarum.ceilInt
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.itemproperties.GameItem
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.InventoryPair
|
||||
import net.torvald.terrarum.ui.UIItem
|
||||
import net.torvald.terrarum.ui.UIItemImageButton
|
||||
import java.util.ArrayList
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Display either extended or compact list
|
||||
@@ -75,8 +71,7 @@ class UIItemInventoryDynamicList(
|
||||
val defaultTextColour = Color(0xeaeaea_ff.toInt())
|
||||
|
||||
private val listGap = 8
|
||||
private val itemList = Array<UIItemInventoryCellBase>(
|
||||
7 * 2, {
|
||||
private val itemList = Array<UIItemInventoryCellBase>(7 * 2) {
|
||||
UIItemInventoryElem(
|
||||
parentUI = inventoryUI,
|
||||
posX = this.posX + (272 + listGap) * (it % 2),
|
||||
@@ -91,9 +86,9 @@ class UIItemInventoryDynamicList(
|
||||
backBlendMode = BlendMode.NORMAL,
|
||||
drawBackOnNull = true,
|
||||
inactiveTextCol = defaultTextColour
|
||||
) })
|
||||
private val itemGrid = Array<UIItemInventoryCellBase>(
|
||||
7 * 10, {
|
||||
)
|
||||
}
|
||||
private val itemGrid = Array<UIItemInventoryCellBase>(7 * 10) {
|
||||
UIItemInventoryElemSimple(
|
||||
parentUI = inventoryUI,
|
||||
posX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % 10),
|
||||
@@ -109,17 +104,13 @@ class UIItemInventoryDynamicList(
|
||||
inactiveTextCol = defaultTextColour
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
private var items: Array<UIItemInventoryCellBase>
|
||||
= if (catArrangement[selection] in compactViewCat) itemGrid else itemList // this is INIT code
|
||||
private var items: Array<UIItemInventoryCellBase> = itemList
|
||||
|
||||
var isCompactMode = (catArrangement[selection] in compactViewCat) // this is INIT code
|
||||
var isCompactMode = false // this is INIT code
|
||||
set(value) {
|
||||
items = if (value) itemGrid else itemList
|
||||
|
||||
rebuild()
|
||||
|
||||
field = value
|
||||
}
|
||||
|
||||
@@ -129,7 +120,7 @@ class UIItemInventoryDynamicList(
|
||||
posY - 2 + (4 + UIItemInventoryElem.height - (parentUI as UIInventoryFull).catIcons.tileH) * index
|
||||
|
||||
/** Long/compact mode buttons */
|
||||
private val gridModeButtons = Array<UIItemImageButton>(2, { index ->
|
||||
private val gridModeButtons = Array<UIItemImageButton>(2) { index ->
|
||||
UIItemImageButton(
|
||||
parentUI,
|
||||
parentUI.catIcons.get(index + 14, 0),
|
||||
@@ -139,7 +130,7 @@ class UIItemInventoryDynamicList(
|
||||
posY = getIconPosY(index),
|
||||
highlightable = true
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
private val scrollUpButton = UIItemImageButton(
|
||||
parentUI,
|
||||
@@ -288,8 +279,8 @@ class UIItemInventoryDynamicList(
|
||||
items[k].itemImage = ItemCodex.getItemImage(sortListItem.item)
|
||||
|
||||
// set quickslot number
|
||||
for (qs in 1..UIQuickBar.SLOT_COUNT) {
|
||||
if (sortListItem.item == inventory.getQuickBar(qs - 1)?.item) {
|
||||
for (qs in 1..UIQuickslotBar.SLOT_COUNT) {
|
||||
if (sortListItem.item == inventory.getQuickslot(qs - 1)?.item) {
|
||||
items[k].quickslot = qs % 10 // 10 -> 0, 1..9 -> 1..9
|
||||
break
|
||||
}
|
||||
|
||||
@@ -4,74 +4,61 @@ import com.badlogic.gdx.Input
|
||||
import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.gameworld.fmod
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
|
||||
/**
|
||||
* A bar-shaped representation of the Quickslot.
|
||||
*
|
||||
* Created by minjaesong on 2016-07-20.
|
||||
*/
|
||||
class UIQuickBar : UICanvas() {
|
||||
private val gutter = 8
|
||||
override var width: Int = (ItemSlotImageBuilder.slotImage.tileW + gutter) * SLOT_COUNT
|
||||
override var height: Int = ItemSlotImageBuilder.slotImage.tileH + 4 + Terrarum.fontGame.lineHeight.toInt()
|
||||
class UIQuickslotBar : UICanvas() {
|
||||
private val cellSize = ItemSlotImageFactory.slotImage.tileW // 38
|
||||
|
||||
private val gutter = 10 - 6 // do -6 to get a gutter size of not-enlarged cells
|
||||
override var width: Int = cellSize * SLOT_COUNT + gutter * (SLOT_COUNT - 1) // 452
|
||||
override var height: Int = ItemSlotImageFactory.slotImage.tileH + 4 + Terrarum.fontGame.lineHeight.toInt()
|
||||
/**
|
||||
* In milliseconds
|
||||
*/
|
||||
override var openCloseTime: Second = 0.16f
|
||||
|
||||
private val startPointX = ItemSlotImageBuilder.slotImage.tileW / 2
|
||||
private val startPointY = ItemSlotImageBuilder.slotImage.tileH / 2
|
||||
override var openCloseTime: Second = COMMON_OPEN_CLOSE
|
||||
|
||||
private var selection: Int
|
||||
get() = (Terrarum.ingame!! as Ingame).actorNowPlaying?.actorValue?.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL) ?: 0
|
||||
set(value) { (Terrarum.ingame!! as Ingame).actorNowPlaying?.actorValue?.set(AVKey.__PLAYER_QUICKSLOTSEL, value.fmod(SLOT_COUNT)) }
|
||||
|
||||
|
||||
|
||||
companion object {
|
||||
const val SLOT_COUNT = 10
|
||||
const val DISPLAY_OPACITY = 0.8f
|
||||
const val COMMON_OPEN_CLOSE = 0.12f
|
||||
}
|
||||
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
}
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
|
||||
for (i in 0..SLOT_COUNT - 1) {
|
||||
val image = if (i == selection)
|
||||
ItemSlotImageBuilder.produceLarge(false, (i + 1) % SLOT_COUNT)
|
||||
else
|
||||
ItemSlotImageBuilder.produce(true, (i + 1) % SLOT_COUNT)
|
||||
val item = (Terrarum.ingame!! as Ingame).actorNowPlaying?.inventory?.getQuickslot(i)?.item
|
||||
|
||||
val slotX = startPointX + (CELL_SIZE + gutter).times(i).toFloat()
|
||||
val slotY = startPointY.toFloat()
|
||||
val image = if (i == selection)
|
||||
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, item)
|
||||
else
|
||||
ItemSlotImageFactory.produce(true, (i + 1) % SLOT_COUNT, item)
|
||||
|
||||
val slotX = cellSize / 2 + (cellSize + gutter) * i
|
||||
val slotY = cellSize / 2
|
||||
|
||||
// draw slots
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity * finalOpacity)
|
||||
batch.draw(
|
||||
image,
|
||||
slotX,
|
||||
slotY
|
||||
)
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity * DISPLAY_OPACITY)
|
||||
image.draw(batch, slotX, slotY)
|
||||
|
||||
// draw item
|
||||
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
|
||||
if (player == null) return // if player is null, don't draw actual items
|
||||
|
||||
|
||||
val itemPair = player.inventory.getQuickBar(i)
|
||||
|
||||
if (itemPair != null) {
|
||||
val itemImage = ItemCodex.getItemImage(itemPair.item)
|
||||
val itemW = itemImage.regionWidth
|
||||
val itemH = itemImage.regionHeight
|
||||
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity)
|
||||
batch.draw(
|
||||
itemImage, // using fixed CELL_SIZE for reasons
|
||||
slotX + (CELL_SIZE - itemW) / 2f,
|
||||
slotY + (CELL_SIZE - itemH) / 2f
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,11 +108,4 @@ class UIQuickBar : UICanvas() {
|
||||
override fun dispose() {
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
val finalOpacity = 0.8f
|
||||
|
||||
const val SLOT_COUNT = 10
|
||||
const val CELL_SIZE = 32
|
||||
}
|
||||
}
|
||||
@@ -4,26 +4,27 @@ import com.badlogic.gdx.graphics.Camera
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.jme3.math.FastMath
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.Second
|
||||
import net.torvald.terrarum.itemproperties.ItemCodex
|
||||
import net.torvald.terrarum.modulebasegame.Ingame
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickBar.Companion.CELL_SIZE
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickBar.Companion.SLOT_COUNT
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.COMMON_OPEN_CLOSE
|
||||
import net.torvald.terrarum.modulebasegame.ui.UIQuickslotBar.Companion.SLOT_COUNT
|
||||
import net.torvald.terrarum.ui.UICanvas
|
||||
import org.dyn4j.geometry.Vector2
|
||||
|
||||
/**
|
||||
* The Sims styled pie representation of the Quickslot.
|
||||
*
|
||||
* Created by minjaesong on 2016-07-20.
|
||||
*/
|
||||
class UIPieMenu : UICanvas() {
|
||||
private val cellSize = UIQuickBar.CELL_SIZE
|
||||
class uiQuickslotPie : UICanvas() {
|
||||
private val cellSize = ItemSlotImageFactory.slotImage.tileW
|
||||
|
||||
private val slotCount = UIQuickBar.SLOT_COUNT
|
||||
private val slotCount = UIQuickslotBar.SLOT_COUNT
|
||||
|
||||
private val slotDistanceFromCentre: Double
|
||||
get() = cellSize * 2.8 * handler.scale
|
||||
get() = cellSize * 2.5 * handler.scale
|
||||
override var width: Int = cellSize * 7
|
||||
override var height: Int = width
|
||||
|
||||
@@ -31,7 +32,7 @@ class UIPieMenu : UICanvas() {
|
||||
/**
|
||||
* In milliseconds
|
||||
*/
|
||||
override var openCloseTime: Second = 0.16f
|
||||
override var openCloseTime: Second = COMMON_OPEN_CLOSE
|
||||
|
||||
private val smallenSize = 0.93f
|
||||
|
||||
@@ -59,48 +60,24 @@ class UIPieMenu : UICanvas() {
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
// draw radial thingies
|
||||
for (i in 0..slotCount - 1) {
|
||||
val item = (Terrarum.ingame!! as Ingame).actorNowPlaying?.inventory?.getQuickslot(i)?.item
|
||||
|
||||
// set position
|
||||
val angle = Math.PI * 2.0 * (i.toDouble() / slotCount) + Math.PI // 180 deg monitor-wise
|
||||
val slotCentrePoint = Vector2(0.0, slotDistanceFromCentre).setDirection(-angle) // NOTE: NOT a center of circle!
|
||||
|
||||
// draw cells
|
||||
val image = if (i == selection)
|
||||
ItemSlotImageBuilder.produceLarge(false, (i + 1) % SLOT_COUNT)
|
||||
ItemSlotImageFactory.produceLarge(false, (i + 1) % SLOT_COUNT, item)
|
||||
else
|
||||
ItemSlotImageBuilder.produce(true, (i + 1) % SLOT_COUNT)
|
||||
ItemSlotImageFactory.produce(true, (i + 1) % SLOT_COUNT, item)
|
||||
|
||||
val slotSize = image.regionWidth
|
||||
val slotX = slotCentrePoint.x.toInt()
|
||||
val slotY = slotCentrePoint.y.toInt()
|
||||
|
||||
val slotX = slotCentrePoint.x.toFloat() - (slotSize / 2)
|
||||
val slotY = slotCentrePoint.y.toFloat() - (slotSize / 2)
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity * UIQuickslotBar.DISPLAY_OPACITY)
|
||||
image.draw(batch, slotX, slotY)
|
||||
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity * UIQuickBar.finalOpacity)
|
||||
batch.draw(
|
||||
image,
|
||||
slotX,
|
||||
slotY
|
||||
)
|
||||
|
||||
|
||||
// draw item
|
||||
val player = (Terrarum.ingame!! as Ingame).actorNowPlaying
|
||||
if (player == null) return // don't draw actual items
|
||||
|
||||
|
||||
val itemPair = player.inventory.getQuickBar(i)
|
||||
|
||||
if (itemPair != null) {
|
||||
val itemImage = ItemCodex.getItemImage(itemPair.item)
|
||||
val itemW = itemImage.regionWidth
|
||||
val itemH = itemImage.regionHeight
|
||||
|
||||
batch.color = Color(1f, 1f, 1f, handler.opacity)
|
||||
batch.draw(
|
||||
itemImage, // using fixed CELL_SIZE for reasons
|
||||
slotX + (CELL_SIZE - itemW) / 2f,
|
||||
slotY + (CELL_SIZE - itemH) / 2f
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user