Added Roboto font and finally figured out how to make TrueType fonts look good!

This commit is contained in:
Yair Morgenstern 2018-06-05 21:53:51 +03:00
parent c7e14a0242
commit c088c02b1e
5 changed files with 27 additions and 3 deletions

1
.gitignore vendored
View file

@ -126,3 +126,4 @@ Thumbs.db
gradle.properties
SaveFiles/
android/android-release.apk
android/assets/GameSettings.json

Binary file not shown.

View file

@ -21,8 +21,8 @@ android {
applicationId "com.unciv.game"
minSdkVersion 14
targetSdkVersion 26
versionCode 68
versionName "2.3.0"
versionCode 72
versionName "2.4.2"
}
buildTypes {
release {

View file

@ -4,8 +4,11 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Screen
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.Batch
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.Touchable
@ -116,4 +119,24 @@ fun Actor.centerX(parent:Stage){ x = parent.width/2 - width/2 }
fun Actor.centerY(parent:Stage){ y = parent.height/2- height/2}
fun Actor.center(parent:Stage){ centerX(parent); centerY(parent)}
fun Label.setFontColor(color:Color): Label {style=Label.LabelStyle(style).apply { fontColor=color }; return this}
fun Label.setFontColor(color:Color): Label {style=Label.LabelStyle(style).apply { fontColor=color }; return this}
fun String.tr(): String {return GameBasics.Translations.get(this,UnCivGame.Current.settings.language)}
fun getFont(size: Int): BitmapFont {
val generator = FreeTypeFontGenerator(Gdx.files.internal("skin/Roboto-Regular.ttf"))
val parameter = FreeTypeFontGenerator.FreeTypeFontParameter()
parameter.size = size
parameter.genMipMaps = true
parameter.minFilter = Texture.TextureFilter.MipMapLinearLinear
parameter.magFilter = Texture.TextureFilter.MipMapLinearLinear
parameter.characters = "ABCČĆDĐEFGHIJKLMNOPQRSŠTUVWXYZŽabcčćdđefghijklmnopqrsštuvwxyzžАБВГҐДЂЕЁЄЖЗЅИІЇЙЈКЛЉМНЊОПРСТЋУЎФХЦЧЏШЩЪЫЬЭЮЯабвгґдђеёєжзѕиіїйјклљмнњопрстћуўфхцчџшщъыьэюяΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψωάΆέΈέΉίϊΐΊόΌύΰϋΎΫΏĂÂÊÔƠƯăâêôơư1234567890?’“!”(%)[#]{@}/&\\<-+÷×=>®©\$€£¥¢:;,.*|"
val font = generator.generateFont(parameter) // font size 12 pixels
generator.dispose() // don't forget to dispose to avoid memory leaks!
return font
}
fun Label.setFont(size:Int) {
style = Label.LabelStyle(style)
style.font = getFont(size)
style = style // because we need it to call the SetStyle function. Yuk, I know.
}