tweak in Kana font, fonts can now produce colours

Former-commit-id: 4f83fbe93e86ffae090986b58802a2fe0c1fd83e
Former-commit-id: 9b0ae019b5dae16236c25597ca31e6aa3b6fb78c
This commit is contained in:
Song Minjae
2016-04-07 00:24:27 +09:00
parent bad4afe247
commit 062abfff36
7 changed files with 93 additions and 46 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

@@ -162,7 +162,7 @@ constructor() : Font {
override fun drawString(x: Float, y: Float, s: String, color: Color) { override fun drawString(x: Float, y: Float, s: String, color: Color) {
// hangul fonts first // hangul fonts first
hangulSheet.startUse() //hangulSheet.startUse() // disabling texture binding to make the font coloured
// JOHAB // JOHAB
for (i in 0..s.length - 1) { for (i in 0..s.length - 1) {
val ch = s[i] val ch = s[i]
@@ -180,18 +180,43 @@ constructor() : Font {
val glyphW = getWidth("" + ch) val glyphW = getWidth("" + ch)
// initials /*// initials
hangulSheet.renderInUse( hangulSheet.renderInUse(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW), Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f), indexCho, choRow) Math.round(x + getWidthSubstr(s, i + 1) - glyphW),
Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f),
indexCho, choRow
)
// medials // medials
hangulSheet.renderInUse( hangulSheet.renderInUse(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW), Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f), indexJung, jungRow) Math.round(x + getWidthSubstr(s, i + 1) - glyphW),
Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f),
indexJung, jungRow
)
// finals // finals
hangulSheet.renderInUse( hangulSheet.renderInUse(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW), Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f), indexJong, jongRow) Math.round(x + getWidthSubstr(s, i + 1) - glyphW),
Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f),
indexJong, jongRow
)*/
hangulSheet.getSubImage(indexCho, choRow).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f).toFloat(),
color
)
hangulSheet.getSubImage(indexJung, jungRow).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f).toFloat(),
color
)
hangulSheet.getSubImage(indexJong, jongRow).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round(((H - H_HANGUL) / 2).toFloat() + y + 1f).toFloat(),
color
)
} }
} }
hangulSheet.endUse() //hangulSheet.endUse()
// unihan fonts // unihan fonts
/*uniHan.startUse(); /*uniHan.startUse();
@@ -214,41 +239,51 @@ constructor() : Font {
uniHan.endUse();*/ uniHan.endUse();*/
// WenQuanYi 1 // WenQuanYi 1
wenQuanYi_1.startUse() //wenQuanYi_1.startUse()
for (i in 0..s.length - 1) { for (i in 0..s.length - 1) {
val ch = s[i] val ch = s[i]
if (isWenQuanYi1(ch)) { if (isWenQuanYi1(ch)) {
val glyphW = getWidth("" + ch) val glyphW = getWidth("" + ch)
wenQuanYi_1.renderInUse( /*wenQuanYi_1.renderInUse(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW), Math.round(x + getWidthSubstr(s, i + 1) - glyphW),
Math.round((H - H_UNIHAN) / 2 + y), Math.round((H - H_UNIHAN) / 2 + y),
wenQuanYiIndexX(ch), wenQuanYiIndexX(ch),
wenQuanYi1IndexY(ch) wenQuanYi1IndexY(ch)
)*/
wenQuanYi_1.getSubImage(wenQuanYiIndexX(ch), wenQuanYi1IndexY(ch)).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round((H - H_UNIHAN) / 2 + y).toFloat(),
color
) )
} }
} }
wenQuanYi_1.endUse() //wenQuanYi_1.endUse()
// WenQuanYi 2 // WenQuanYi 2
wenQuanYi_2.startUse() //wenQuanYi_2.startUse()
for (i in 0..s.length - 1) { for (i in 0..s.length - 1) {
val ch = s[i] val ch = s[i]
if (isWenQuanYi2(ch)) { if (isWenQuanYi2(ch)) {
val glyphW = getWidth("" + ch) val glyphW = getWidth("" + ch)
wenQuanYi_2.renderInUse( /*wenQuanYi_2.renderInUse(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW), Math.round(x + getWidthSubstr(s, i + 1) - glyphW),
Math.round((H - H_UNIHAN) / 2 + y), Math.round((H - H_UNIHAN) / 2 + y),
wenQuanYiIndexX(ch), wenQuanYiIndexX(ch),
wenQuanYi2IndexY(ch) wenQuanYi2IndexY(ch)
)*/
wenQuanYi_2.getSubImage(wenQuanYiIndexX(ch), wenQuanYi2IndexY(ch)).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat(),
Math.round((H - H_UNIHAN) / 2 + y).toFloat(),
color
) )
} }
} }
wenQuanYi_2.endUse() //wenQuanYi_2.endUse()
// regular fonts // regular fonts
var prevInstance = -1 var prevInstance = -1
@@ -259,9 +294,9 @@ constructor() : Font {
// if not init, endUse first // if not init, endUse first
if (prevInstance != -1) { if (prevInstance != -1) {
sheetKey[prevInstance].endUse() //sheetKey[prevInstance].endUse()
} }
sheetKey[getSheetType(ch)].startUse() //sheetKey[getSheetType(ch)].startUse()
prevInstance = getSheetType(ch) prevInstance = getSheetType(ch)
val sheetX: Int val sheetX: Int
@@ -315,15 +350,22 @@ constructor() : Font {
val glyphW = getWidth("" + ch) val glyphW = getWidth("" + ch)
try { try {
sheetKey[prevInstance].renderInUse( /*sheetKey[prevInstance].renderInUse(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW) // Interchar: pull punct right next to hangul to the left Math.round(x + getWidthSubstr(s, i + 1) - glyphW) // Interchar: pull punct right next to hangul to the left
+ if (i > 0 && isHangul(s[i - 1])) -3 else 0, Math.round(y) + + if (i > 0 && isHangul(s[i - 1])) -3 else 0,
if (prevInstance == SHEET_CJK_PUNCT) Math.round(y) + if (prevInstance == SHEET_CJK_PUNCT) -1
-1 else if (prevInstance == SHEET_FW_UNI) (H - H_HANGUL) / 2
else if (prevInstance == SHEET_FW_UNI) else 0,
(H - H_HANGUL) / 2 sheetX, sheetY
else 0, )*/
sheetX, sheetY) sheetKey[prevInstance].getSubImage(sheetX, sheetY).draw(
Math.round(x + getWidthSubstr(s, i + 1) - glyphW).toFloat() // Interchar: pull punct right next to hangul to the left
+ if (i > 0 && isHangul(s[i - 1])) -3f else 0f,
Math.round(y).toFloat() + (if (prevInstance == SHEET_CJK_PUNCT) -1
else if (prevInstance == SHEET_FW_UNI) (H - H_HANGUL) / 2
else 0).toFloat(),
color
)
} }
catch (e: ArrayIndexOutOfBoundsException) { catch (e: ArrayIndexOutOfBoundsException) {
// character that does not exist in the sheet. No render, pass. // character that does not exist in the sheet. No render, pass.
@@ -332,7 +374,7 @@ constructor() : Font {
} }
if (prevInstance != -1) { if (prevInstance != -1) {
sheetKey[prevInstance].endUse() //sheetKey[prevInstance].endUse()
} }
} }

View File

@@ -54,7 +54,7 @@ object Lang {
// reload correct (C/J) unihan fonts if applicable // reload correct (C/J) unihan fonts if applicable
try { try {
(Terrarum.gameFontWhite as GameFontWhite).reloadUnihan() (Terrarum.gameFont as GameFontWhite).reloadUnihan()
} }
catch (e: SlickException) { catch (e: SlickException) {
} }

View File

@@ -3,7 +3,6 @@ package com.torvald.terrarum
import com.torvald.imagefont.GameFontWhite import com.torvald.imagefont.GameFontWhite
import com.torvald.JsonFetcher import com.torvald.JsonFetcher
import com.torvald.JsonWriter import com.torvald.JsonWriter
import com.torvald.terrarum.langpack.Lang
import org.lwjgl.input.Controllers import org.lwjgl.input.Controllers
import org.lwjgl.opengl.GL11 import org.lwjgl.opengl.GL11
import org.newdawn.slick.AppGameContainer import org.newdawn.slick.AppGameContainer
@@ -12,7 +11,6 @@ import org.newdawn.slick.GameContainer
import org.newdawn.slick.SlickException import org.newdawn.slick.SlickException
import org.newdawn.slick.state.StateBasedGame import org.newdawn.slick.state.StateBasedGame
import java.io.File import java.io.File
import java.io.FileWriter
import java.io.IOException import java.io.IOException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
@@ -50,7 +48,7 @@ constructor(gamename: String) : StateBasedGame(gamename) {
@Throws(SlickException::class) @Throws(SlickException::class)
override fun initStatesList(gc: GameContainer) { override fun initStatesList(gc: GameContainer) {
gameFontWhite = GameFontWhite() gameFont = GameFontWhite()
hasController = gc.input.controllerCount > 0 hasController = gc.input.controllerCount > 0
if (hasController) { if (hasController) {
@@ -99,7 +97,7 @@ constructor(gamename: String) : StateBasedGame(gamename) {
var gameLocale = "" // locale override var gameLocale = "" // locale override
lateinit var gameFontWhite: Font lateinit var gameFont: Font
val SCENE_ID_HOME = 1 val SCENE_ID_HOME = 1
val SCENE_ID_GAME = 3 val SCENE_ID_GAME = 3
@@ -354,10 +352,21 @@ fun main(args: Array<String>) = Terrarum.main(args)
fun setBlendModeMul() { fun setBlendModeMul() {
GL11.glEnable(GL11.GL_BLEND) GL11.glEnable(GL11.GL_BLEND)
GL11.glColorMask(true, true, true, true)
GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA) GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ONE_MINUS_SRC_ALPHA)
} }
fun setBlendModeNormal() { fun setBlendModeNormal() {
GL11.glEnable(GL11.GL_BLEND) GL11.glEnable(GL11.GL_BLEND)
GL11.glColorMask(true, true, true, true)
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA) GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA)
} }
fun setBlendModeAlphaMap() {
GL11.glDisable(GL11.GL_BLEND)
GL11.glColorMask(false, false, false, true)
}
fun disableBlend() {
GL11.glDisable(GL11.GL_BLEND)
}

View File

@@ -25,16 +25,9 @@ Connect two or more tracker head to play the array of trackers play simultaneous
<actorid>.json <actorid>.json
{ {
0 = [long], notes = [arr<int>, fixed size of 48],
1 = [long],
...
47 = [long],
speed = 120 speed = 120
} }
*long: array of bits that indicates the note is stricken (1) or not (0) *int: (0-63) number of the note pitch that is struck. 32: Middle C (C3)
0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000
↑G5 ↑C5 ↑C4 ↑C3 ↑C2 ↑C1 E0↑
(Assuming C3 (32nd bit) as middle 'C')
*speed: in BPM *speed: in BPM

View File

@@ -2,6 +2,8 @@ package com.torvald.terrarum.ui
import com.torvald.imagefont.GameFontWhite import com.torvald.imagefont.GameFontWhite
import com.jme3.math.FastMath import com.jme3.math.FastMath
import com.torvald.terrarum.disableBlend
import com.torvald.terrarum.setBlendModeNormal
import org.lwjgl.opengl.GL11 import org.lwjgl.opengl.GL11
import org.newdawn.slick.* import org.newdawn.slick.*
@@ -20,6 +22,7 @@ constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
private val messageWindowRadius: Int private val messageWindowRadius: Int
private var uiFont: Font? = null private var uiFont: Font? = null
private var fontCol: Color = if (!isBlackVariant) Color.black else Color.white
private val GLYPH_HEIGHT = 20 private val GLYPH_HEIGHT = 20
override var openCloseTime: Int = OPEN_CLOSE_TIME override var openCloseTime: Int = OPEN_CLOSE_TIME
@@ -31,18 +34,16 @@ constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
init { init {
if (!isBlackVariant) { if (!isBlackVariant) {
//segmentLeft = new Image("./res/graphics/gui/message_twoline_white_left.png"); segmentLeft = Image("./res/graphics/gui/message_twoline_white_left.png");
//segmentRight = new Image("./res/graphics/gui/message_twoline_white_right.png"); segmentRight = Image("./res/graphics/gui/message_twoline_white_right.png");
//segmentBody = new Image("./res/graphics/gui/message_twoline_white_body.png"); segmentBody = Image("./res/graphics/gui/message_twoline_white_body.png");
//uiFont = new GameFontBlack();
TODO("Black font not supported for now")
} }
else { else {
segmentLeft = Image("./res/graphics/gui/message_twoline_black_left.png") segmentLeft = Image("./res/graphics/gui/message_twoline_black_left.png")
segmentRight = Image("./res/graphics/gui/message_twoline_black_right.png") segmentRight = Image("./res/graphics/gui/message_twoline_black_right.png")
segmentBody = Image("./res/graphics/gui/message_twoline_black_body.png") segmentBody = Image("./res/graphics/gui/message_twoline_black_body.png")
uiFont = GameFontWhite()
} }
uiFont = GameFontWhite()
height = segmentLeft!!.height height = segmentLeft!!.height
messageWindowRadius = segmentLeft!!.width messageWindowRadius = segmentLeft!!.width
messagesList = arrayOf("", "") messagesList = arrayOf("", "")
@@ -60,7 +61,7 @@ constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
override fun render(gc: GameContainer, g: Graphics) { override fun render(gc: GameContainer, g: Graphics) {
val canvasG = uidrawCanvas.graphics val canvasG = uidrawCanvas.graphics
canvasG.setDrawMode(Graphics.MODE_NORMAL) disableBlend()
drawSegments(canvasG) drawSegments(canvasG)
canvasG.setDrawMode(Graphics.MODE_ALPHA_MAP) canvasG.setDrawMode(Graphics.MODE_ALPHA_MAP)
drawSegments(canvasG) drawSegments(canvasG)
@@ -69,9 +70,11 @@ constructor(override var width: Int, isBlackVariant: Boolean) : UICanvas {
canvasG.setDrawMode(Graphics.MODE_NORMAL) canvasG.setDrawMode(Graphics.MODE_NORMAL)
for (i in 0..Math.min(messagesList.size, MESSAGES_DISPLAY) - 1) { for (i in 0..Math.min(messagesList.size, MESSAGES_DISPLAY) - 1) {
canvasG.color = fontCol
canvasG.drawString(messagesList[i], (messageWindowRadius + 4).toFloat(), (messageWindowRadius + GLYPH_HEIGHT * i).toFloat()) canvasG.drawString(messagesList[i], (messageWindowRadius + 4).toFloat(), (messageWindowRadius + GLYPH_HEIGHT * i).toFloat())
} }
setBlendModeNormal()
g.drawImage(uidrawCanvas, 0f, 0f, Color(1f,1f,1f,opacity)) g.drawImage(uidrawCanvas, 0f, 0f, Color(1f,1f,1f,opacity))
canvasG.clear() canvasG.clear()

View File

@@ -93,7 +93,7 @@ constructor(val UI: UICanvas) {
fun render(gc: GameContainer, gameGraphicInstance: Graphics) { fun render(gc: GameContainer, gameGraphicInstance: Graphics) {
if (visible || alwaysVisible) { if (visible || alwaysVisible) {
UIGraphicInstance.clear() UIGraphicInstance.clear()
UIGraphicInstance.font = Terrarum.gameFontWhite UIGraphicInstance.font = Terrarum.gameFont
UI.render(gc, UIGraphicInstance) UI.render(gc, UIGraphicInstance)
gameGraphicInstance.drawImage(UIDrawnCanvas, gameGraphicInstance.drawImage(UIDrawnCanvas,