prettier text print on Notification

This commit is contained in:
minjaesong
2019-02-24 05:06:54 +09:00
parent 7cbe09eee8
commit 6afd36db64
6 changed files with 34 additions and 23 deletions

View File

@@ -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.")
}

View File

@@ -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<String>) {
(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() {

View File

@@ -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)

View File

@@ -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<String>) {
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<String>) {
(Terrarum.ingame!! as Ingame).sendNotification(message)
fun send(msg1: String, msg2: String? = null) {
(Terrarum.ingame!! as Ingame).sendNotification(msg1, msg2)
println("sent notifinator")
}
}

View File

@@ -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)
}

BIN
work_files/UI/chest_view.psd LFS Normal file

Binary file not shown.