mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 19:14:05 +09:00
smelter: scroll wheel to operate the item slots
This commit is contained in:
@@ -121,92 +121,93 @@ class UICrafting(val full: UIInventoryFull?) : UICanvas(
|
||||
|
||||
// ingredient list
|
||||
itemListIngredients = UIItemInventoryItemGrid(
|
||||
this,
|
||||
{ ingredients },
|
||||
thisOffsetX,
|
||||
thisOffsetY + LAST_LINE_IN_GRID,
|
||||
6, 1,
|
||||
drawScrollOnRightside = false,
|
||||
drawWallet = false,
|
||||
hideSidebar = true,
|
||||
colourTheme = UIItemInventoryCellCommonRes.defaultInventoryCellTheme.copy(
|
||||
cellHighlightSubCol = Toolkit.Theme.COL_INACTIVE
|
||||
),
|
||||
keyDownFun = { _, _, _, _, _ -> },
|
||||
touchDownFun = { gameItem, amount, _, _, _ -> gameItem?.let { gameItem ->
|
||||
// if the item is craftable one, load its recipe instead
|
||||
CraftingRecipeCodex.getRecipesFor(gameItem.originalID)?.let { recipes ->
|
||||
// select most viable recipe (completely greedy search)
|
||||
val player = getPlayerInventory()
|
||||
// list of [Score, Ingredients, Recipe]
|
||||
recipes.map { recipe ->
|
||||
// list of (Item, How many player has, How many the recipe requires)
|
||||
val items = recipeToIngredientRecord(player, recipe, nearbyCraftingStations)
|
||||
this,
|
||||
{ ingredients },
|
||||
thisOffsetX,
|
||||
thisOffsetY + LAST_LINE_IN_GRID,
|
||||
6, 1,
|
||||
drawScrollOnRightside = false,
|
||||
drawWallet = false,
|
||||
hideSidebar = true,
|
||||
colourTheme = UIItemInventoryCellCommonRes.defaultInventoryCellTheme.copy(
|
||||
cellHighlightSubCol = Toolkit.Theme.COL_INACTIVE
|
||||
),
|
||||
keyDownFun = { _, _, _, _, _ -> },
|
||||
wheelFun = { _, _, _, _, _, _ -> },
|
||||
touchDownFun = { gameItem, amount, _, _, _ -> gameItem?.let { gameItem ->
|
||||
// if the item is craftable one, load its recipe instead
|
||||
CraftingRecipeCodex.getRecipesFor(gameItem.originalID)?.let { recipes ->
|
||||
// select most viable recipe (completely greedy search)
|
||||
val player = getPlayerInventory()
|
||||
// list of [Score, Ingredients, Recipe]
|
||||
recipes.map { recipe ->
|
||||
// list of (Item, How many player has, How many the recipe requires)
|
||||
val items = recipeToIngredientRecord(player, recipe, nearbyCraftingStations)
|
||||
|
||||
val score = items.fold(1L) { acc, item ->
|
||||
(item.howManyPlayerHas).times(16L) + 1L
|
||||
}
|
||||
|
||||
listOf(score, items, recipe)
|
||||
}.maxByOrNull { it[0] as Long }?.let { (_, items, recipe) ->
|
||||
val items = items as List<List<*>>
|
||||
val recipe = recipe as CraftingCodex.CraftingRecipe
|
||||
|
||||
// change selected recipe to mostViableRecipe then update the UIs accordingly
|
||||
// FIXME recipe highlighting will not change correctly!
|
||||
val selectedItems = ArrayList<ItemID>()
|
||||
|
||||
// auto-dial the spinner so that player would just have to click the Craft! button (for the most time, that is)
|
||||
val howManyRequired = craftMult * amount
|
||||
val howManyPlayerHas = player.searchByID(gameItem.dynamicID)?.qty ?: 0
|
||||
val howManyPlayerMightNeed = ceil((howManyRequired - howManyPlayerHas).toDouble() / recipe.moq).toLong()
|
||||
resetSpinner(howManyPlayerMightNeed.coerceIn(1L, App.getConfigInt("basegame:gameplay_max_crafting").toLong()))
|
||||
|
||||
ingredients.clear()
|
||||
recipeClicked = recipe
|
||||
|
||||
items.forEach {
|
||||
val itm = it[0] as ItemID
|
||||
val qty = it[2] as Long
|
||||
|
||||
selectedItems.add(itm)
|
||||
ingredients.add(itm, qty)
|
||||
}
|
||||
|
||||
_getItemListPlayer().let {
|
||||
it.removeFromForceHighlightList(oldSelectedItems)
|
||||
filterPlayerListUsing(recipeClicked)
|
||||
it.addToForceHighlightList(selectedItems)
|
||||
it.rebuild(FILTER_CAT_ALL)
|
||||
}
|
||||
_getItemListIngredients().rebuild(FILTER_CAT_ALL)
|
||||
|
||||
// highlighting CraftingCandidateButton by searching for the buttons that has the recipe
|
||||
_getItemListCraftables().let {
|
||||
// turn the highlights off
|
||||
it.items.forEach { it.forceHighlighted = false }
|
||||
|
||||
// search for the recipe
|
||||
// also need to find what "page" the recipe might be in
|
||||
// use it.isCompactMode to find out the current mode
|
||||
var ord = 0
|
||||
while (ord < it.craftingRecipes.indices.last) {
|
||||
if (recipeClicked == it.craftingRecipes[ord]) break
|
||||
ord += 1
|
||||
}
|
||||
val itemSize = it.items.size
|
||||
|
||||
it.itemPage = ord / itemSize
|
||||
it.items[ord % itemSize].forceHighlighted = true
|
||||
}
|
||||
|
||||
oldSelectedItems.clear()
|
||||
oldSelectedItems.addAll(selectedItems)
|
||||
|
||||
refreshCraftButtonStatus()
|
||||
val score = items.fold(1L) { acc, item ->
|
||||
(item.howManyPlayerHas).times(16L) + 1L
|
||||
}
|
||||
|
||||
listOf(score, items, recipe)
|
||||
}.maxByOrNull { it[0] as Long }?.let { (_, items, recipe) ->
|
||||
val items = items as List<List<*>>
|
||||
val recipe = recipe as CraftingCodex.CraftingRecipe
|
||||
|
||||
// change selected recipe to mostViableRecipe then update the UIs accordingly
|
||||
// FIXME recipe highlighting will not change correctly!
|
||||
val selectedItems = ArrayList<ItemID>()
|
||||
|
||||
// auto-dial the spinner so that player would just have to click the Craft! button (for the most time, that is)
|
||||
val howManyRequired = craftMult * amount
|
||||
val howManyPlayerHas = player.searchByID(gameItem.dynamicID)?.qty ?: 0
|
||||
val howManyPlayerMightNeed = ceil((howManyRequired - howManyPlayerHas).toDouble() / recipe.moq).toLong()
|
||||
resetSpinner(howManyPlayerMightNeed.coerceIn(1L, App.getConfigInt("basegame:gameplay_max_crafting").toLong()))
|
||||
|
||||
ingredients.clear()
|
||||
recipeClicked = recipe
|
||||
|
||||
items.forEach {
|
||||
val itm = it[0] as ItemID
|
||||
val qty = it[2] as Long
|
||||
|
||||
selectedItems.add(itm)
|
||||
ingredients.add(itm, qty)
|
||||
}
|
||||
|
||||
_getItemListPlayer().let {
|
||||
it.removeFromForceHighlightList(oldSelectedItems)
|
||||
filterPlayerListUsing(recipeClicked)
|
||||
it.addToForceHighlightList(selectedItems)
|
||||
it.rebuild(FILTER_CAT_ALL)
|
||||
}
|
||||
_getItemListIngredients().rebuild(FILTER_CAT_ALL)
|
||||
|
||||
// highlighting CraftingCandidateButton by searching for the buttons that has the recipe
|
||||
_getItemListCraftables().let {
|
||||
// turn the highlights off
|
||||
it.items.forEach { it.forceHighlighted = false }
|
||||
|
||||
// search for the recipe
|
||||
// also need to find what "page" the recipe might be in
|
||||
// use it.isCompactMode to find out the current mode
|
||||
var ord = 0
|
||||
while (ord < it.craftingRecipes.indices.last) {
|
||||
if (recipeClicked == it.craftingRecipes[ord]) break
|
||||
ord += 1
|
||||
}
|
||||
val itemSize = it.items.size
|
||||
|
||||
it.itemPage = ord / itemSize
|
||||
it.items[ord % itemSize].forceHighlighted = true
|
||||
}
|
||||
|
||||
oldSelectedItems.clear()
|
||||
oldSelectedItems.addAll(selectedItems)
|
||||
|
||||
refreshCraftButtonStatus()
|
||||
}
|
||||
} }
|
||||
}
|
||||
} }
|
||||
)
|
||||
|
||||
// make sure grid buttons for ingredients do nothing (even if they are hidden!)
|
||||
|
||||
@@ -87,13 +87,14 @@ internal class UIInventoryCells(
|
||||
|
||||
internal val itemList: UIItemInventoryItemGrid =
|
||||
UIItemInventoryItemGrid(
|
||||
full,
|
||||
{ full.actor.inventory },
|
||||
INVENTORY_CELLS_OFFSET_X(),
|
||||
INVENTORY_CELLS_OFFSET_Y(),
|
||||
CELLS_HOR, CELLS_VRT,
|
||||
keyDownFun = createInvCellGenericKeyDownFun(),
|
||||
touchDownFun = createInvCellGenericTouchDownFun { rebuildList() }
|
||||
full,
|
||||
{ full.actor.inventory },
|
||||
INVENTORY_CELLS_OFFSET_X(),
|
||||
INVENTORY_CELLS_OFFSET_Y(),
|
||||
CELLS_HOR, CELLS_VRT,
|
||||
keyDownFun = createInvCellGenericKeyDownFun(),
|
||||
touchDownFun = createInvCellGenericTouchDownFun { rebuildList() },
|
||||
wheelFun = { _, _, _, _, _, _ -> },
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -21,16 +21,17 @@ class UIItemCraftingCandidateGrid(
|
||||
keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, keyed button
|
||||
touchDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit // Item, Amount, Button, extra info, clicked button
|
||||
) : UIItemInventoryItemGrid(
|
||||
parentUI,
|
||||
{ TODO() /* UNUSED and MUST NOT BE USED! */ },
|
||||
initialX, initialY,
|
||||
horizontalCells, verticalCells,
|
||||
drawScrollOnRightside,
|
||||
drawWallet = false,
|
||||
hideSidebar = false,
|
||||
keyDownFun = keyDownFun,
|
||||
touchDownFun = touchDownFun,
|
||||
useHighlightingManager = false
|
||||
parentUI,
|
||||
{ TODO() /* UNUSED and MUST NOT BE USED! */ },
|
||||
initialX, initialY,
|
||||
horizontalCells, verticalCells,
|
||||
drawScrollOnRightside,
|
||||
drawWallet = false,
|
||||
hideSidebar = false,
|
||||
keyDownFun = keyDownFun,
|
||||
touchDownFun = touchDownFun,
|
||||
wheelFun = { _, _, _, _, _, _ -> },
|
||||
useHighlightingManager = false
|
||||
) {
|
||||
|
||||
val craftingRecipes = ArrayList<CraftingCodex.CraftingRecipe>()
|
||||
|
||||
@@ -30,6 +30,7 @@ abstract class UIItemInventoryCellBase(
|
||||
open var equippedSlot: Int? = null,
|
||||
var keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, self
|
||||
var touchDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Button, extra info, self
|
||||
var wheelFun: (GameItem?, Long, Float, Float, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, scroll x, scroll y, extra info, self
|
||||
open var extraInfo: Any?,
|
||||
open protected val highlightEquippedItem: Boolean = true, // for some UIs that only cares about getting equipped slot number but not highlighting
|
||||
var colourTheme: InventoryCellColourTheme = UIItemInventoryCellCommonRes.defaultInventoryCellTheme,
|
||||
@@ -70,6 +71,14 @@ abstract class UIItemInventoryCellBase(
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||
if (mouseUp) {
|
||||
wheelFun(item, amount, amountX, amountY, extraInfo, this)
|
||||
super.scrolled(amountX, amountY)
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
object UIItemInventoryCellCommonRes {
|
||||
|
||||
@@ -56,7 +56,8 @@ class UIItemInventoryEquippedView(
|
||||
drawBackOnNull = true,
|
||||
keyDownFun = createInvCellGenericKeyDownFun(),
|
||||
touchDownFun = createInvCellGenericTouchDownFun(inventoryListRebuildFun), // to "unselect" the equipped item and main item grid would "untick" accordingly
|
||||
emptyCellIcon = equipPosIcon.get(cellToIcon[it], 1)
|
||||
wheelFun = { _, _, _, _, _, _ -> },
|
||||
emptyCellIcon = equipPosIcon.get(cellToIcon[it], 1),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ open class UIItemInventoryItemGrid(
|
||||
val hideSidebar: Boolean = false,
|
||||
keyDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Keycode, extra info, self
|
||||
touchDownFun: (GameItem?, Long, Int, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, Button, extra info, self
|
||||
wheelFun: (GameItem?, Long, Float, Float, Any?, UIItemInventoryCellBase) -> Unit, // Item, Amount, scroll x, scroll y, extra info, self
|
||||
protected val useHighlightingManager: Boolean = true, // only used by UIItemCraftingCandidateGrid which addresses buttons directly to set highlighting
|
||||
open protected val highlightEquippedItem: Boolean = true, // for some UIs that only cares about getting equipped slot number but not highlighting
|
||||
private val colourTheme: InventoryCellColourTheme = defaultInventoryCellTheme
|
||||
@@ -183,13 +184,14 @@ open class UIItemInventoryItemGrid(
|
||||
|
||||
protected val itemGrid = Array<UIItemInventoryCellBase>(horizontalCells * verticalCells) {
|
||||
UIItemInventoryElemSimple(
|
||||
parentUI = inventoryUI,
|
||||
initialX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % horizontalCells),
|
||||
initialY = this.posY + (UIItemInventoryElemSimple.height + listGap) * (it / horizontalCells),
|
||||
keyDownFun = keyDownFun,
|
||||
touchDownFun = touchDownFun,
|
||||
highlightEquippedItem = highlightEquippedItem,
|
||||
colourTheme = colourTheme
|
||||
parentUI = inventoryUI,
|
||||
initialX = this.posX + (UIItemInventoryElemSimple.height + listGap) * (it % horizontalCells),
|
||||
initialY = this.posY + (UIItemInventoryElemSimple.height + listGap) * (it / horizontalCells),
|
||||
keyDownFun = keyDownFun,
|
||||
touchDownFun = touchDownFun,
|
||||
wheelFun = wheelFun,
|
||||
highlightEquippedItem = highlightEquippedItem,
|
||||
colourTheme = colourTheme
|
||||
)
|
||||
}
|
||||
// automatically determine how much columns are needed. Minimum Width = 5 grids
|
||||
@@ -198,14 +200,15 @@ open class UIItemInventoryItemGrid(
|
||||
private val largeListWidth = ((listGap + actualItemCellWidth) / itemListColumnCount) - (itemListColumnCount - 1).coerceAtLeast(1) * listGap
|
||||
protected val itemList = Array<UIItemInventoryCellBase>(verticalCells * itemListColumnCount) {
|
||||
UIItemInventoryElemWide(
|
||||
parentUI = inventoryUI,
|
||||
initialX = this.posX + (largeListWidth + listGap) * (it % itemListColumnCount),
|
||||
initialY = this.posY + (UIItemInventoryElemWide.height + listGap) * (it / itemListColumnCount),
|
||||
width = largeListWidth,
|
||||
keyDownFun = keyDownFun,
|
||||
touchDownFun = touchDownFun,
|
||||
highlightEquippedItem = highlightEquippedItem,
|
||||
colourTheme = colourTheme
|
||||
parentUI = inventoryUI,
|
||||
initialX = this.posX + (largeListWidth + listGap) * (it % itemListColumnCount),
|
||||
initialY = this.posY + (UIItemInventoryElemWide.height + listGap) * (it / itemListColumnCount),
|
||||
width = largeListWidth,
|
||||
keyDownFun = keyDownFun,
|
||||
touchDownFun = touchDownFun,
|
||||
wheelFun = wheelFun,
|
||||
highlightEquippedItem = highlightEquippedItem,
|
||||
colourTheme = colourTheme
|
||||
)
|
||||
}
|
||||
|
||||
@@ -599,6 +602,8 @@ open class UIItemInventoryItemGrid(
|
||||
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
||||
super.scrolled(amountX, amountY)
|
||||
|
||||
items.forEach { if (it.mouseUp) it.scrolled(amountX, amountY) }
|
||||
|
||||
// scroll the item list (for now)
|
||||
if (mouseUp) {
|
||||
scrollItemPage(amountY.toInt())
|
||||
|
||||
@@ -48,6 +48,7 @@ class UIJukeboxInventory(val parent: UIJukebox) : UICanvas() {
|
||||
showItemCount = false,
|
||||
keyDownFun = { _, _, _, _, _ -> Unit },
|
||||
touchDownFun = { _, _, _, _, _ -> Unit },
|
||||
wheelFun = { _, _, _, _, _, _ -> },
|
||||
)
|
||||
}.toTypedArray()
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.colourutil.cieluv_getGradient
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.App.printdbg
|
||||
import net.torvald.terrarum.langpack.Lang
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.FixtureSmelterBasic
|
||||
@@ -19,7 +19,6 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
import net.torvald.unicode.getKeycapPC
|
||||
import net.torvald.unicode.getMouseButton
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.roundToLong
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2024-01-29.
|
||||
@@ -68,6 +67,67 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
||||
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
it.itemListWheelFun = { gameItem, _, _, scrollY, _, _ ->
|
||||
val scrollY = -scrollY
|
||||
if (gameItem != null) {
|
||||
val playerInventory = getPlayerInventory()
|
||||
val addCount1 = scrollY.toLong()
|
||||
|
||||
if (clickedOn == 1 && (smelter.oreItem == null || smelter.oreItem!!.itm == gameItem.dynamicID)) {
|
||||
val itemToUse = smelter.oreItem?.itm ?: gameItem.dynamicID
|
||||
|
||||
val addCount2 = scrollY.toLong().coerceIn(
|
||||
-(playerInventory.searchByID(itemToUse)?.qty ?: 0L),
|
||||
smelter.oreItem?.qty ?: 0L,
|
||||
)
|
||||
|
||||
// add to the inventory slot
|
||||
if (smelter.oreItem != null && addCount1 >= 1L) {
|
||||
getPlayerInventory().add(smelter.oreItem!!.itm, addCount2)
|
||||
smelter.oreItem!!.qty -= addCount2
|
||||
}
|
||||
// remove from the inventory slot
|
||||
else if (addCount1 <= -1L) {
|
||||
playerInventory.remove(itemToUse, -addCount2)
|
||||
if (smelter.oreItem == null)
|
||||
smelter.oreItem = InventoryPair(itemToUse, -addCount2)
|
||||
else
|
||||
smelter.oreItem!!.qty -= addCount2
|
||||
}
|
||||
if (smelter.oreItem != null && smelter.oreItem!!.qty == 0L) smelter.oreItem = null
|
||||
else if (smelter.oreItem != null && smelter.oreItem!!.qty < 0L) throw Error("Item removal count is larger than what was on the slot")
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
else if (clickedOn == 2 && (smelter.fireboxItem == null || smelter.fireboxItem!!.itm == gameItem.dynamicID)) {
|
||||
val itemToUse = smelter.fireboxItem?.itm ?: gameItem.dynamicID
|
||||
|
||||
val addCount2 = scrollY.toLong().coerceIn(
|
||||
-(playerInventory.searchByID(itemToUse)?.qty ?: 0L),
|
||||
smelter.fireboxItem?.qty ?: 0L,
|
||||
)
|
||||
|
||||
// add to the inventory slot
|
||||
if (smelter.fireboxItem != null && addCount1 >= 1L) {
|
||||
getPlayerInventory().add(smelter.fireboxItem!!.itm, addCount2)
|
||||
smelter.fireboxItem!!.qty -= addCount2
|
||||
}
|
||||
// remove from the inventory slot
|
||||
else if (addCount1 <= -1L) {
|
||||
playerInventory.remove(itemToUse, -addCount2)
|
||||
if (smelter.fireboxItem == null)
|
||||
smelter.fireboxItem = InventoryPair(itemToUse, -addCount2)
|
||||
else
|
||||
smelter.fireboxItem!!.qty -= addCount2
|
||||
}
|
||||
if (smelter.fireboxItem != null && smelter.fireboxItem!!.qty == 0L) smelter.fireboxItem = null
|
||||
else if (smelter.fireboxItem != null && smelter.fireboxItem!!.qty < 0L) throw Error("Item removal count is larger than what was on the slot")
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
else {
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getPlayerInventory(): FixtureInventory = INGAME.actorNowPlaying!!.inventory
|
||||
@@ -157,6 +217,33 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
||||
else {
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
},
|
||||
wheelFun = { _, _, _, scrollY, _, _ ->
|
||||
val scrollY = -scrollY
|
||||
if (clickedOn == 1 && smelter.oreItem != null) {
|
||||
val playerInventory = getPlayerInventory()
|
||||
val removeCount1 = scrollY.toLong()
|
||||
val removeCount2 = scrollY.toLong().coerceIn(
|
||||
-smelter.oreItem!!.qty,
|
||||
playerInventory.searchByID(smelter.oreItem!!.itm)?.qty ?: 0L,
|
||||
)
|
||||
|
||||
// add to the slot
|
||||
if (removeCount1 >= 1L) {
|
||||
playerInventory.remove(smelter.oreItem!!.itm, removeCount2)
|
||||
smelter.oreItem!!.qty += removeCount2
|
||||
}
|
||||
// remove from the slot
|
||||
else if (removeCount1 <= -1L) {
|
||||
getPlayerInventory().add(smelter.oreItem!!.itm, -removeCount2)
|
||||
smelter.oreItem!!.qty += removeCount2
|
||||
}
|
||||
if (smelter.oreItem!!.qty == 0L) smelter.oreItem = null
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
else {
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
}
|
||||
)
|
||||
private val fireboxItemSlot: UIItemInventoryElemSimple = UIItemInventoryElemSimple(
|
||||
@@ -189,6 +276,33 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
||||
else {
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
},
|
||||
wheelFun = { _, _, _, scrollY, _, _ ->
|
||||
val scrollY = -scrollY
|
||||
if (clickedOn == 2 && smelter.fireboxItem != null) {
|
||||
val playerInventory = getPlayerInventory()
|
||||
val removeCount1 = scrollY.toLong()
|
||||
val removeCount2 = scrollY.toLong().coerceIn(
|
||||
-smelter.fireboxItem!!.qty,
|
||||
playerInventory.searchByID(smelter.fireboxItem!!.itm)?.qty ?: 0L,
|
||||
)
|
||||
|
||||
// add to the slot
|
||||
if (removeCount1 >= 1L) {
|
||||
playerInventory.remove(smelter.fireboxItem!!.itm, removeCount2)
|
||||
smelter.fireboxItem!!.qty += removeCount2
|
||||
}
|
||||
// remove from the slot
|
||||
else if (removeCount1 <= -1L) {
|
||||
getPlayerInventory().add(smelter.fireboxItem!!.itm, -removeCount2)
|
||||
smelter.fireboxItem!!.qty += removeCount2
|
||||
}
|
||||
if (smelter.fireboxItem!!.qty == 0L) smelter.fireboxItem = null
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
else {
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
}
|
||||
)
|
||||
private val productItemslot: UIItemInventoryElemSimple = UIItemInventoryElemSimple(
|
||||
@@ -218,6 +332,27 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
||||
}
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
},
|
||||
wheelFun = { _, _, _, scrollY, _, _ ->
|
||||
val scrollY = -scrollY
|
||||
if (smelter.productItem != null) {
|
||||
val removeCount1 = scrollY.toLong()
|
||||
val removeCount2 = scrollY.toLong().coerceIn(
|
||||
-smelter.productItem!!.qty,
|
||||
0L,
|
||||
)
|
||||
|
||||
// remove from the slot
|
||||
if (removeCount1 <= -1L) {
|
||||
getPlayerInventory().add(smelter.productItem!!.itm, -removeCount2)
|
||||
smelter.productItem!!.qty += removeCount2
|
||||
}
|
||||
if (smelter.productItem!!.qty == 0L) smelter.productItem = null
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
else {
|
||||
itemListUpdateKeepCurrentFilter()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -309,25 +444,28 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
||||
}
|
||||
|
||||
private val SP = "\u3000"
|
||||
private val ML = getMouseButton(App.getConfigInt("config_mouseprimary"))
|
||||
private val MR = getMouseButton(App.getConfigInt("config_mousesecondary"))
|
||||
private val MW = getMouseButton(2)
|
||||
private val controlHelpForSmelter = listOf(
|
||||
// no slot selected
|
||||
{ if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_SELECT_SLOT"]}"
|
||||
"$ML ${Lang["GAME_ACTION_SELECT_SLOT"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" },
|
||||
// ore slot
|
||||
{ if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_TAKE_ALL_CONT"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mousesecondary"))} ${Lang["GAME_ACTION_TAKE_ONE_CONT"]}"
|
||||
"$ML ${Lang["GAME_ACTION_TAKE_ALL_CONT"]}$SP" +
|
||||
"$MW$MR ${Lang["GAME_ACTION_TAKE_ONE_CONT"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" },
|
||||
// firebox slot
|
||||
{ if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_TAKE_ALL_CONT"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mousesecondary"))} ${Lang["GAME_ACTION_TAKE_ONE_CONT"]}"
|
||||
"$ML ${Lang["GAME_ACTION_TAKE_ALL_CONT"]}$SP" +
|
||||
"$MW$MR ${Lang["GAME_ACTION_TAKE_ONE_CONT"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" }
|
||||
)
|
||||
@@ -337,14 +475,14 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
||||
{ "" },
|
||||
// ore slot
|
||||
{ if (App.environment == RunningEnvironment.PC)
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_PUT_ALL_CONT"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mousesecondary"))} ${Lang["GAME_ACTION_PUT_ONE_CONT"]}"
|
||||
"$ML ${Lang["GAME_ACTION_PUT_ALL_CONT"]}$SP" +
|
||||
"$MW$MR ${Lang["GAME_ACTION_PUT_ONE_CONT"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" },
|
||||
// firebox slot
|
||||
{ if (App.environment == RunningEnvironment.PC)
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_PUT_ALL_CONT"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mousesecondary"))} ${Lang["GAME_ACTION_PUT_ONE_CONT"]}"
|
||||
"$ML ${Lang["GAME_ACTION_PUT_ALL_CONT"]}$SP" +
|
||||
"$MW$MR ${Lang["GAME_ACTION_PUT_ONE_CONT"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" }
|
||||
)
|
||||
@@ -354,14 +492,14 @@ class UISmelterBasic(val smelter: FixtureSmelterBasic) : UICanvas(
|
||||
{ "" },
|
||||
// ore slot
|
||||
{ if (App.environment == RunningEnvironment.PC)
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_PUT_ALL"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mousesecondary"))} ${Lang["GAME_ACTION_PUT_ONE"]}"
|
||||
"$ML ${Lang["GAME_ACTION_PUT_ALL"]}$SP" +
|
||||
"$MW$MR ${Lang["GAME_ACTION_PUT_ONE"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" },
|
||||
// firebox slot
|
||||
{ if (App.environment == RunningEnvironment.PC)
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_PUT_ALL"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mousesecondary"))} ${Lang["GAME_ACTION_PUT_ONE"]}"
|
||||
"$ML ${Lang["GAME_ACTION_PUT_ALL"]}$SP" +
|
||||
"$MW$MR ${Lang["GAME_ACTION_PUT_ONE"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}" }
|
||||
)
|
||||
|
||||
@@ -206,25 +206,28 @@ internal class UIStorageChest : UICanvas(
|
||||
private val cellsWidth = (UIItemInventoryItemGrid.listGap + UIItemInventoryElemWide.height) * 6 - UIItemInventoryItemGrid.listGap
|
||||
|
||||
private val SP = "\u3000"
|
||||
private val ML = getMouseButton(App.getConfigInt("config_mouseprimary"))
|
||||
private val MR = getMouseButton(App.getConfigInt("config_mousesecondary"))
|
||||
private val MW = getMouseButton(2)
|
||||
private val controlHelpLeft: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getKeycapPC(ControlPresets.getKey("control_key_inventory"))} ${Lang["GAME_ACTION_CLOSE"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_TAKE_ALL_CONT"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mousesecondary"))} ${Lang["GAME_ACTION_TAKE_ONE_CONT"]}"
|
||||
"$ML ${Lang["GAME_ACTION_TAKE_ALL_CONT"]}$SP" +
|
||||
"$MW$MR ${Lang["GAME_ACTION_TAKE_ONE_CONT"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
|
||||
private val controlHelpRight: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_PUT_ALL_CONT"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mousesecondary"))} ${Lang["GAME_ACTION_PUT_ONE_CONT"]}"
|
||||
"$ML ${Lang["GAME_ACTION_PUT_ALL_CONT"]}$SP" +
|
||||
"$MW$MR ${Lang["GAME_ACTION_PUT_ONE_CONT"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
|
||||
private val controlHelpRightTwoRows: String
|
||||
get() = if (App.environment == RunningEnvironment.PC)
|
||||
"${getMouseButton(App.getConfigInt("config_mouseprimary"))} ${Lang["GAME_ACTION_PUT_ALL"]}$SP" +
|
||||
"${getMouseButton(App.getConfigInt("config_mousesecondary"))} ${Lang["GAME_ACTION_PUT_ONE"]}"
|
||||
"$ML ${Lang["GAME_ACTION_PUT_ALL"]}$SP" +
|
||||
"$MW$MR ${Lang["GAME_ACTION_PUT_ONE"]}"
|
||||
else
|
||||
"${App.gamepadLabelStart} ${Lang["GAME_ACTION_CLOSE"]}"
|
||||
|
||||
|
||||
@@ -46,6 +46,9 @@ class UITemplateHalfInventory(
|
||||
internal var itemListTouchDownFun = { gameItem: GameItem?, amount: Long, mouseButton: Int, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
|
||||
/* crickets */
|
||||
}
|
||||
internal var itemListWheelFun = { gameItem: GameItem?, amount: Long, scrollX: Float, scrollY: Float, itemExtraInfo: Any?, theButton: UIItemInventoryCellBase ->
|
||||
/* crickets */
|
||||
}
|
||||
|
||||
init {
|
||||
itemList = UIItemInventoryItemGrid(
|
||||
@@ -58,7 +61,8 @@ class UITemplateHalfInventory(
|
||||
drawWallet = false,
|
||||
highlightEquippedItem = false,
|
||||
keyDownFun = { a, b, c, d, e -> itemListKeyDownFun(a, b, c, d, e) },
|
||||
touchDownFun = { a, b, c, d, e -> itemListTouchDownFun.invoke(a, b, c, d, e) }
|
||||
touchDownFun = { a, b, c, d, e -> itemListTouchDownFun.invoke(a, b, c, d, e) },
|
||||
wheelFun = { a, b, c, d, e, f -> itemListWheelFun.invoke(a, b, c, d, e, f)}
|
||||
)
|
||||
// make grid mode buttons work together
|
||||
// itemListPlayer.gridModeButtons[0].clickOnceListener = { _,_ -> setCompact(false) }
|
||||
|
||||
@@ -96,6 +96,7 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
|
||||
drawScrollOnRightside = false,
|
||||
drawWallet = false,
|
||||
keyDownFun = { _, _, _, _, _ -> Unit },
|
||||
wheelFun = { _, _, _, _, _, _ -> },
|
||||
touchDownFun = { gameItem, amount, button, _, _ ->
|
||||
if (button == App.getConfigInt("config_mouseprimary")) {
|
||||
if (gameItem != null) {
|
||||
@@ -118,6 +119,7 @@ class UIWorldPortalCargo(val full: UIWorldPortal) : UICanvas(), HasInventory {
|
||||
drawScrollOnRightside = true,
|
||||
drawWallet = false,
|
||||
keyDownFun = { _, _, _, _, _ -> Unit },
|
||||
wheelFun = { _, _, _, _, _, _ -> },
|
||||
touchDownFun = { gameItem, amount, button, _, _ ->
|
||||
if (button == App.getConfigInt("config_mouseprimary")) {
|
||||
if (gameItem != null) {
|
||||
|
||||
Reference in New Issue
Block a user