From 6afd36db6499ad029b77819dccaa2a7103ab6ca8 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 24 Feb 2019 05:06:54 +0900 Subject: [PATCH] prettier text print on Notification --- .../gamecontroller/IngameController.kt | 2 +- .../torvald/terrarum/modulebasegame/Ingame.kt | 7 +++--- .../UIBuildingMakerBlockChooser.kt | 11 +++++----- .../modulebasegame/console/SetBulletin.kt | 12 ++++------ .../modulebasegame/ui/Notification.kt | 22 ++++++++++++++----- work_files/UI/chest_view.psd | 3 +++ 6 files changed, 34 insertions(+), 23 deletions(-) create mode 100644 work_files/UI/chest_view.psd diff --git a/src/net/torvald/terrarum/gamecontroller/IngameController.kt b/src/net/torvald/terrarum/gamecontroller/IngameController.kt index 6f9a6594e..205cbc322 100644 --- a/src/net/torvald/terrarum/gamecontroller/IngameController.kt +++ b/src/net/torvald/terrarum/gamecontroller/IngameController.kt @@ -114,7 +114,7 @@ class IngameController(val ingame: Ingame) : InputAdapter() { // screenshot key if (keycode == Input.Keys.F12 && !f12Down) { AppLoader.requestScreenshot() - ingame.sendNotification(arrayOf("Screenshot taken", "")) + ingame.sendNotification("Screenshot taken") f12Down = true println("Screenshot taken.") } diff --git a/src/net/torvald/terrarum/modulebasegame/Ingame.kt b/src/net/torvald/terrarum/modulebasegame/Ingame.kt index a92239dee..ef01885c4 100644 --- a/src/net/torvald/terrarum/modulebasegame/Ingame.kt +++ b/src/net/torvald/terrarum/modulebasegame/Ingame.kt @@ -15,7 +15,6 @@ import net.torvald.terrarum.gameactors.Actor import net.torvald.terrarum.gameactors.ActorWithBody import net.torvald.terrarum.gamecontroller.IngameController import net.torvald.terrarum.gamecontroller.KeyToggler -import net.torvald.terrarum.gameworld.GameWorld import net.torvald.terrarum.itemproperties.GameItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.modulebasegame.console.AVTracker @@ -250,7 +249,7 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { val timeNow = System.currentTimeMillis() / 1000 gameworld = GameWorldExtension(1, worldParams.width, worldParams.height, timeNow, timeNow, 0) // new game, so the creation time is right now gameworldCount++ - world = gameworld as GameWorld + world = gameworld // generate terrain for the map WorldGenerator.attachMap(world) @@ -594,8 +593,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) { } /** Send message to notifier UI and toggle the UI as opened. */ - fun sendNotification(msg: Array) { - (notifier as Notification).sendNotification(msg) + fun sendNotification(msg1: String, msg2: String? = null) { + (notifier as Notification).sendNotification(if (msg2 != null) arrayOf(msg1, msg2) else arrayOf(msg1)) } fun wakeDormantActors() { diff --git a/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerBlockChooser.kt b/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerBlockChooser.kt index 0bfeb6d50..f9f0d4e20 100644 --- a/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerBlockChooser.kt +++ b/src/net/torvald/terrarum/modulebasegame/UIBuildingMakerBlockChooser.kt @@ -6,9 +6,9 @@ import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarum.AppLoader import net.torvald.terrarum.blendNormal -import net.torvald.terrarum.blendScreen import net.torvald.terrarum.fillRect import net.torvald.terrarum.itemproperties.ItemCodex +import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory.CELLCOLOUR_WHITE import net.torvald.terrarum.ui.UICanvas import net.torvald.terrarum.ui.UIItemImageButton import net.torvald.terrarum.ui.UIItemTextButtonList @@ -104,7 +104,7 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() { } } - private val addCol = Color(0x242424ff) + private val scrollbarBackCol = Color(0x000000_70) private var scrollBarPos = 0 private var paletteScroll = 0 private val paletteScrollMax = 256f - 14f @@ -125,18 +125,19 @@ class UIBuildingMakerBlockChooser(val parent: BuildingMaker): UICanvas() { override fun renderUI(batch: SpriteBatch, camera: Camera) { palette.forEach { it.render(batch, camera) } + blendNormal(batch) // gaps between tabs and close button batch.color = DEFAULT_BACKGROUNDCOL batch.fillRect(0f, tabs.height.toFloat(), MENUBAR_SIZE.toFloat(), height.toFloat() - (tabs.height + closeButton.height)) // scrollbar back + batch.color = DEFAULT_BACKGROUNDCOL batch.fillRect(width - SCROLLBAR_SIZE.toFloat(), 0f, SCROLLBAR_SIZE.toFloat(), height.toFloat()) - blendScreen(batch) - batch.color = addCol + batch.color = scrollbarBackCol batch.fillRect(width - SCROLLBAR_SIZE.toFloat(), 0f, SCROLLBAR_SIZE.toFloat(), height.toFloat()) // scrollbar + batch.color = CELLCOLOUR_WHITE batch.fillRect(width - SCROLLBAR_SIZE.toFloat(), scrollBarPos.toFloat(), SCROLLBAR_SIZE.toFloat(), scrollBarHeight) - blendNormal(batch) // the actual buttons tabs.render(batch, camera) diff --git a/src/net/torvald/terrarum/modulebasegame/console/SetBulletin.kt b/src/net/torvald/terrarum/modulebasegame/console/SetBulletin.kt index c289de1bc..e66dc5989 100644 --- a/src/net/torvald/terrarum/modulebasegame/console/SetBulletin.kt +++ b/src/net/torvald/terrarum/modulebasegame/console/SetBulletin.kt @@ -1,8 +1,8 @@ package net.torvald.terrarum.modulebasegame.console -import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.Terrarum import net.torvald.terrarum.console.ConsoleCommand +import net.torvald.terrarum.langpack.Lang import net.torvald.terrarum.modulebasegame.Ingame /** @@ -10,11 +10,7 @@ import net.torvald.terrarum.modulebasegame.Ingame */ internal object SetBulletin : ConsoleCommand { override fun execute(args: Array) { - val testMsg = arrayOf( - Lang["ERROR_SAVE_CORRUPTED"], - Lang["MENU_LABEL_CONTINUE_QUESTION"] - ) - send(testMsg) + send(Lang["ERROR_SAVE_CORRUPTED"], Lang["MENU_LABEL_CONTINUE_QUESTION"]) } override fun printUsage() { @@ -25,8 +21,8 @@ internal object SetBulletin : ConsoleCommand { * Actually send notifinator * @param message real message */ - fun send(message: Array) { - (Terrarum.ingame!! as Ingame).sendNotification(message) + fun send(msg1: String, msg2: String? = null) { + (Terrarum.ingame!! as Ingame).sendNotification(msg1, msg2) println("sent notifinator") } } diff --git a/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt b/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt index 3b3fa512a..5a5fb482c 100644 --- a/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt +++ b/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt @@ -61,18 +61,30 @@ class Notification : UICanvas() { drawColor.a = handler.opacity fontCol.a = handler.opacity - val textWidth = width//maxOf(width, messagesList.map { Terrarum.fontGame.getWidth(it) }.sorted()[1]) + val realTextWidth = 12 + if (message.size == 1) + Terrarum.fontGame.getWidth(message[0]) + else + maxOf(Terrarum.fontGame.getWidth(message[0]), Terrarum.fontGame.getWidth(message[1])) + val displayedTextWidth = maxOf(240, realTextWidth) + + // force the UI to the centre of the screen + this.posX = (Terrarum.WIDTH - displayedTextWidth) / 2 + batch.color = drawColor batch.draw(segment.get(0, 0), -segment.tileW.toFloat(), 0f) - batch.draw(segment.get(1, 0), 0f, 0f, textWidth.toFloat(), segment.tileH.toFloat()) - batch.draw(segment.get(2, 0), textWidth.toFloat(), 0f) + batch.draw(segment.get(1, 0), 0f, 0f, displayedTextWidth.toFloat(), segment.tileH.toFloat()) + batch.draw(segment.get(2, 0), displayedTextWidth.toFloat(), 0f) batch.color = fontCol message.forEachIndexed { index, s -> - val y = imageToTextAreaDelta + index * (textAreaHeight / 2) + (textAreaHeight / 2 - Terrarum.fontGame.lineHeight) / 2 - Terrarum.fontGame.draw(batch, s, LRmargin, y) + val xoff = 6 + (displayedTextWidth - realTextWidth) / 2 + val y = if (message.size == 1) + -2 + imageToTextAreaDelta + 0.5f * (textAreaHeight / 2) + (textAreaHeight / 2 - Terrarum.fontGame.lineHeight) / 2 + else + -1 + imageToTextAreaDelta + index * (textAreaHeight / 2) + (textAreaHeight / 2 - Terrarum.fontGame.lineHeight) / 2 + Terrarum.fontGame.draw(batch, s, LRmargin + xoff, y) } diff --git a/work_files/UI/chest_view.psd b/work_files/UI/chest_view.psd new file mode 100644 index 000000000..9491eb03d --- /dev/null +++ b/work_files/UI/chest_view.psd @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bd0e1899250f2100b65d4060d5a301dbc41372e06b958583181bf196bff0917c +size 6627494