UIs will draw on "backing" framebuffer where skybox is

This commit is contained in:
Song Minjae
2017-04-09 22:22:29 +09:00
parent 4254b87e51
commit bb37f2aed7
8 changed files with 88 additions and 55 deletions

View File

@@ -193,7 +193,7 @@ class BasicDebugInfoWindow : UICanvas {
val histogramH = 200
private fun drawHistogram(g: Graphics, histogram: LightmapRenderer.Histogram, x: Int, y: Int) {
val uiColour = Color(0xAA000000.toInt())
val uiColour = Color(0x80000000.toInt())
val barR = Color(0xDD0000)
val barG = Color(0x00DD00)
val barB = Color(0x0000DD)

View File

@@ -16,7 +16,7 @@ import org.newdawn.slick.Input
*/
class ConsoleWindow : UICanvas, KeyboardControlled {
internal var UIColour = Color(0xCC000000.toInt())
internal var UIColour = Color(0x80404080.toInt())
private var inputCursorPos: Int = 0
private val MESSAGES_MAX = 5000

View File

@@ -18,18 +18,17 @@ import org.newdawn.slick.state.StateBasedGame
* Created by minjaesong on 15-12-31.
*/
class UIHandler(val UI: UICanvas,
val toggleKey: Int? = null, val toggleButton: Int? = null
val toggleKey: Int? = null, val toggleButton: Int? = null,
// UI positions itself? (you must g.flush() yourself after the g.translate(Int, Int))
var customPositioning: Boolean = false
) {
// X/Y Position to the game window.
// X/Y Position relative to the game window.
var posX: Int = 0
var posY: Int = 0
private var alwaysVisible = false
private val UIGraphicInstance: Graphics
private val UIDrawnCanvas: Image
var isOpening = false
var isClosing = false
var isOpened = false // fully opened
@@ -56,11 +55,6 @@ class UIHandler(val UI: UICanvas,
init {
UI.handler = this
println("[UIHandler] Creating framebuffer for UI '${UI.javaClass.simpleName}'")
UIDrawnCanvas = Image(UI.width, UI.height)
UIGraphicInstance = UIDrawnCanvas.graphics
}
@@ -123,14 +117,11 @@ class UIHandler(val UI: UICanvas,
fun render(gc: GameContainer, sbg: StateBasedGame, ingameGraphics: Graphics) {
if (isVisible || alwaysVisible) {
UIGraphicInstance.clear()
UIGraphicInstance.font = Terrarum.fontGame
ingameGraphics.font = Terrarum.fontGame // default font. Re-assign in the UI to change
UI.render(gc, UIGraphicInstance)
ingameGraphics.drawImage(
UIDrawnCanvas, posX.toFloat(), posY.toFloat(), Color(1f, 1f, 1f, opacity)
)
if (!customPositioning) ingameGraphics.translate(posX.toFloat(), posY.toFloat())
UI.render(gc, ingameGraphics)
ingameGraphics.flush()
}
}

View File

@@ -28,7 +28,7 @@ class UIInventory(
val catButtonsToCatIdent = HashMap<String, String>()
val backgroundColour = Color(0x1c1c1c)
val backgroundColour = Color(0xA0282828.toInt())
init {
catButtonsToCatIdent.put("GAME_INVENTORY_WEAPONS", InventoryItem.Category.WEAPON)
@@ -73,9 +73,10 @@ class UIInventory(
defaultSelection = 0,
iconSpriteSheet = SpriteSheet("./assets/graphics/gui/inventory/category.tga", 20, 20),
iconSpriteSheetIndices = intArrayOf(9,0,1,2,3,4,5,6,7,8),
highlightBackCol = backgroundColour screen Color(0x0c0c0c),
highlightBackBlendMode = BlendMode.NORMAL,
highlightBackCol = Color(0x0c0c0c),
highlightBackBlendMode = BlendMode.SCREEN,
backgroundCol = Color(0x383838),
backgroundBlendMode = BlendMode.MULTIPLY,
kinematic = true
)
@@ -93,8 +94,6 @@ class UIInventory(
mouseoverBackCol = Color(0x282828),
mouseoverBackBlendMode = BlendMode.SCREEN,
drawBackOnNull = false
//backCol = Color(0x101010),
//backBlendMode = BlendMode.SCREEN
) })
val itemsScrollOffset = 0
@@ -175,6 +174,8 @@ class UIInventory(
}
override fun render(gc: GameContainer, g: Graphics) {
//blendMul()
blendNormal()
g.color = backgroundColour
g.fillRect(0f, 0f, width.toFloat(), height.toFloat())

View File

@@ -48,7 +48,7 @@ class UIPieMenu : UICanvas {
for (i in 0..slotCount - 1) {
// set position
val angle = Math.PI * 2.0 * (i.toDouble() / slotCount) + Math.PI // 180 deg monitor-wise
val slotCentrePoint = Vector2(0.0, slotDistanceFromCentre.toDouble()).setDirection(angle) + centrePoint
val slotCentrePoint = Vector2(0.0, slotDistanceFromCentre).setDirection(angle) + centrePoint
// draw cells
val color = if (i == selection)

View File

@@ -5,6 +5,7 @@ import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameactors.ActorHumanoid
import net.torvald.terrarum.gameactors.floorInt
import net.torvald.terrarum.gameactors.roundInt
import net.torvald.terrarum.mapdrawer.MapCamera
import org.newdawn.slick.Color
import org.newdawn.slick.GameContainer
import org.newdawn.slick.Graphics
@@ -27,10 +28,17 @@ class UIVitalMetre(
override var width: Int = 80 + 2 * margin; set(value) { throw Error("operation not permitted") }
override var height: Int; get() = player?.baseHitboxH ?: 0 * 3 + margin; set(value) { throw Error("operation not permitted") }
override var handler: UIHandler? = null
set(value) {
// override customPositioning to be true
if (value != null) {
value.customPositioning = true
}
field = value
}
override var openCloseTime: Int = 50
private val relativePX = width / 2f
private val relativePY: Float; get() = (player?.baseHitboxH ?: 0) * 1.5f
//private val relativePX = width / 2f
private val offsetY: Float; get() = (player?.baseHitboxH ?: 0) * 1.5f
private val circleRadius: Float; get() = (player?.baseHitboxH ?: 0) * 3f
private val theta = 33f
@@ -41,21 +49,35 @@ class UIVitalMetre(
override fun update(gc: GameContainer, delta: Int) {
handler!!.setPosition(
(Terrarum.HALFW - relativePX).roundInt(),
(Terrarum.HALFH - relativePY).floorInt()
Terrarum.HALFW,
Terrarum.HALFH
)
handler!!.customPositioning = true
}
/**
* g must be same as World Graphics!
*/
override fun render(gc: GameContainer, g: Graphics) {
if (vitalGetterVal() != null && vitalGetterMax() != null) {
if (vitalGetterVal() != null && vitalGetterMax() != null && player != null) {
// FIXME does not work well with screen zoom, because of my custom g.translate
g.translate(
-MapCamera.x + player!!.centrePosPoint.x.toFloat(),
-MapCamera.y + player!!.centrePosPoint.y.toFloat()
)
g.lineWidth = 2f
// background
g.color = backColor
g.drawArc(
relativePX - circleRadius - order * gap,
-circleRadius - order * gap,
-circleRadius - order * gap - offsetY,
circleRadius * 2f + order * gap * 2,
circleRadius * 2f + order * gap * 2,
90f - halfTheta,
@@ -64,13 +86,17 @@ class UIVitalMetre(
g.color = color
g.drawArc(
relativePX - circleRadius - order * gap,
-circleRadius - order * gap,
-circleRadius - order * gap - offsetY,
circleRadius * 2f + order * gap * 2,
circleRadius * 2f + order * gap * 2,
90f + halfTheta - theta * (vitalGetterVal()!! / vitalGetterMax()!!),
90f + halfTheta
)
g.flush()
}
}
@@ -96,10 +122,10 @@ class UIVitalMetre(
/*
X-------------+ (84)
+-------------+ (84)
| |
| |
| @ |
| X |
| @ |
|, ,|
| ''-------'' |