From 753f2ebad4f39cdcc9fe3fc9775086592bd421be Mon Sep 17 00:00:00 2001 From: minjaesong Date: Tue, 7 Nov 2017 23:29:07 +0900 Subject: [PATCH] inventory grid mode buttons working highlight --- assets/graphics/gui/inventory/category.tga | 2 +- assets/modules/basegame/default.json | 67 +++++++++++++++++++ src/net/torvald/terrarum/ModMgr.kt | 14 +++- .../terrarum/ui/UIItemInventoryDynamicList.kt | 51 +++++++++++++- work_files/UI/inventory_nouveau_2.psd | 4 +- work_files/UI/portable_computer_mockup.psd | 4 +- 6 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 assets/modules/basegame/default.json diff --git a/assets/graphics/gui/inventory/category.tga b/assets/graphics/gui/inventory/category.tga index d02142c30..56ceb5999 100644 --- a/assets/graphics/gui/inventory/category.tga +++ b/assets/graphics/gui/inventory/category.tga @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d28e7271e03aa4898b8f5d90f0021b29cffc2ebf0988e0ade5acb444c1b7a8e6 +oid sha256:65fb603ab26dd765c6abae88760a7d005cdbf353735a0431acca94780ccb86cc size 28844 diff --git a/assets/modules/basegame/default.json b/assets/modules/basegame/default.json new file mode 100644 index 000000000..00dd8d51c --- /dev/null +++ b/assets/modules/basegame/default.json @@ -0,0 +1,67 @@ +{ + "displayfps": 0, + "usevsync": true, + + "imtooyoungtodie": false, + "language": "enUS", + "notificationshowuptime": 6500, + "multithread": true, + + + "joypadkeyn": 4, + "joypadkeyw": 1, + "joypadkeys": 2, + "joypadkeye": 3, + + "joypadlup": 4, + "joypadrup": 5, + "joypadldown": 6, + "joypadrdown": 7, + + "joypadlstickx": 0, + "joypadlsticky": 1, + "joypadrstickx": 2, + "joypadrsticky": 3, + + "joypadlabelstyle": "msxb360", + + + "keyup": 33, + "keyleft": 47, + "keydown": 32, + "keyright": 34, + + "keymovementaux": 29, + "keyinventory": 45, + "keyinteract": 46, + "keyclose": 31, + + "keygamemenu": 61, + "keyquicksel": 59, + + "keyquickselalt": [4, 129, 73], + + "keyjump": 62, + + "keyquickbars": [145, 146, 147, 148, 149, 150, 151, 152, 153, 144], + + "mouseprimary": 0, + "mousesecondary": 1, + + + "pcgamepadenv": "console", + + "safetywarning": true, + + + "maxparticles": 768, + + + "fullframelightupdate": false, + + "useamericanunit": false, + + + "fxdither": true, + "fx3dlut": false +} \ No newline at end of file diff --git a/src/net/torvald/terrarum/ModMgr.kt b/src/net/torvald/terrarum/ModMgr.kt index 9d2e697de..438677086 100644 --- a/src/net/torvald/terrarum/ModMgr.kt +++ b/src/net/torvald/terrarum/ModMgr.kt @@ -7,6 +7,7 @@ import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.blockproperties.BlockCodex import net.torvald.terrarum.langpack.Lang +import net.torvald.terrarum.utils.JsonFetcher import org.apache.commons.csv.CSVFormat import org.apache.commons.csv.CSVParser import java.io.File @@ -35,6 +36,8 @@ object ModMgr { val groovyEngine = ScriptEngineManager().getEngineByExtension("groovy")!! val groovyInvocable = groovyEngine as Invocable + val metaFilename = "metadata.properties" + val defaultConfigFilename = "default.json" data class ModuleMetadata( val order: Int, @@ -74,7 +77,16 @@ object ModMgr { try { val modMetadata = Properties() - modMetadata.load(FileInputStream("$modDir/$moduleName/metadata.properties")) + modMetadata.load(FileInputStream("$modDir/$moduleName/$metaFilename")) + + if (File("$modDir/$moduleName/$defaultConfigFilename").exists()) { + val defaultConfig = JsonFetcher("$modDir/$moduleName/$defaultConfigFilename") + // read config and store it to the game + + // write to user's config file + } + + val properName = modMetadata.getProperty("propername") val description = modMetadata.getProperty("description") diff --git a/src/net/torvald/terrarum/ui/UIItemInventoryDynamicList.kt b/src/net/torvald/terrarum/ui/UIItemInventoryDynamicList.kt index 56ee45315..2b382825b 100644 --- a/src/net/torvald/terrarum/ui/UIItemInventoryDynamicList.kt +++ b/src/net/torvald/terrarum/ui/UIItemInventoryDynamicList.kt @@ -106,15 +106,58 @@ class UIItemInventoryDynamicList( } ) - private val items: Array - get() = if (catArrangement[selection] in compactViewCat) itemGrid else itemList + private var items: Array + = if (catArrangement[selection] in compactViewCat) itemGrid else itemList // this is INIT code + var isCompactView = (catArrangement[selection] in compactViewCat) // this is INIT code + set(value) { + items = if (value) itemGrid else itemList + + rebuild() + + field = value + } + + private val gridModeButtons = Array(2, { index -> + val iconPosX = posX - 12 - parentUI.catIcons.tileW + 2 + val iconPosY = posY - 2 + (4 + UIItemInventoryElem.height - parentUI.catIcons.tileH) * index + + UIItemImageButton( + parentUI, + parentUI.catIcons.get(index + 14, 0), + activeBackCol = Color(0), + activeBackBlendMode = BlendMode.NORMAL, + posX = iconPosX, + posY = iconPosY, + highlightable = true + ) + }) + + init { + // initially highlight grid mode buttons + gridModeButtons[if (isCompactView) 1 else 0].highlighted = true + + + gridModeButtons[0].touchDownListener = { _, _, _, _ -> + isCompactView = false + gridModeButtons[0].highlighted = true + gridModeButtons[1].highlighted = false + } + gridModeButtons[1].touchDownListener = { _, _, _, _ -> + isCompactView = true + gridModeButtons[0].highlighted = false + gridModeButtons[1].highlighted = true + } + + // if (is.mouseUp) handled by this.touchDown() + } override fun render(batch: SpriteBatch, camera: Camera) { items.forEach { it.render(batch, camera) } + gridModeButtons.forEach { it.render(batch, camera) } super.render(batch, camera) } @@ -124,6 +167,8 @@ class UIItemInventoryDynamicList( super.update(delta) items.forEach { it.update(delta) } + + gridModeButtons.forEach { it.update(delta) } } @@ -190,12 +235,14 @@ class UIItemInventoryDynamicList( override fun dispose() { itemList.forEach { it.dispose() } itemGrid.forEach { it.dispose() } + gridModeButtons.forEach { it.dispose() } } override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { super.touchDown(screenX, screenY, pointer, button) items.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) } + gridModeButtons.forEach { if (it.mouseUp) it.touchDown(screenX, screenY, pointer, button) } return true } diff --git a/work_files/UI/inventory_nouveau_2.psd b/work_files/UI/inventory_nouveau_2.psd index b68c8266d..c4596964f 100644 --- a/work_files/UI/inventory_nouveau_2.psd +++ b/work_files/UI/inventory_nouveau_2.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7d7da8dec5912953d7ea5b5d759eec790b1726652a1f51481c368b64657d685b -size 3112111 +oid sha256:ecc43dc29845b465af2e1e06a0fb5f4a5d054a311d56f5bbe1244a6934081ceb +size 3112067 diff --git a/work_files/UI/portable_computer_mockup.psd b/work_files/UI/portable_computer_mockup.psd index f5591d508..fed764953 100644 --- a/work_files/UI/portable_computer_mockup.psd +++ b/work_files/UI/portable_computer_mockup.psd @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b196e2464ec6c289ea11bfffd06f5b29aa26560b5e553d94e82357289c78de31 -size 212804 +oid sha256:3b2fdafe9ba9f98b47594fecd42c939b640c988371e6e808d93c1db9b1fc4d75 +size 212796