Modding: allow mods to supply custom fonts (#8715)

* Modding: allow mods to supply custom fonts

* Cleanup

* Code cleanup

---------

Co-authored-by: vegeta1k95 <vfylfhby>
This commit is contained in:
vegeta1k95
2023-02-21 22:09:11 +01:00
committed by GitHub
parent 96fdbbff09
commit c593056e42
10 changed files with 217 additions and 101 deletions

View File

@ -19,7 +19,7 @@ import com.unciv.ui.images.ImageWithCustomSize
import com.unciv.ui.screens.basescreen.BaseScreen
import com.unciv.ui.components.FontFamilyData
import com.unciv.ui.components.Fonts
import com.unciv.ui.components.NativeFontImplementation
import com.unciv.ui.components.FontImplementation
import com.unciv.ui.components.extensions.center
import com.unciv.ui.components.extensions.toLabel
import com.unciv.utils.concurrency.Concurrency
@ -62,7 +62,7 @@ object FasterUIDevelopment {
class UIDevGame : Game() {
val game = UncivGame(UncivGameParameters(
fontImplementation = NativeFontDesktop()
fontImplementation = FontDesktop()
))
override fun create() {
UncivGame.Current = game
@ -126,7 +126,7 @@ object FasterUIDevelopment {
}
class NativeFontDesktop : NativeFontImplementation {
class FontDesktop : FontImplementation {
private val font by lazy {
Font(Fonts.DEFAULT_FONT_FAMILY, Font.PLAIN, Fonts.ORIGINAL_FONT_SIZE.toInt())
}
@ -139,6 +139,10 @@ class NativeFontDesktop : NativeFontImplementation {
fontMetrics
}
override fun setFontFamily(fontFamilyData: FontFamilyData, size: Int) {
// Empty
}
override fun getFontSize(): Int {
return Fonts.ORIGINAL_FONT_SIZE.toInt()
}
@ -168,7 +172,7 @@ class NativeFontDesktop : NativeFontImplementation {
return pixmap
}
override fun getAvailableFontFamilies(): Sequence<FontFamilyData> {
override fun getSystemFonts(): Sequence<FontFamilyData> {
return sequenceOf(FontFamilyData(Fonts.DEFAULT_FONT_FAMILY))
}
}