Added option to select font size (#7238)

This commit is contained in:
alexban011 2022-06-25 14:46:12 +03:00 committed by GitHub
parent 8047278d80
commit 51ba657b75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 5 deletions

View File

@ -722,6 +722,7 @@ Translation files are generated successfully. =
Fastlane files are generated successfully. =
Please note that translations are a community-based work in progress and are INCOMPLETE! The percentage shown is how much of the language is translated in-game. If you want to help translating the game into your language, click here. =
Font family =
Font size multiplier =
Default Font =
You need to restart the game for this change to take effect. =

View File

@ -52,7 +52,7 @@ open class AndroidLauncher : AndroidApplication() {
val androidParameters = UncivGameParameters(
version = BuildConfig.VERSION_NAME,
crashReportSysInfo = CrashReportSysInfoAndroid,
fontImplementation = NativeFontAndroid(Fonts.ORIGINAL_FONT_SIZE.toInt(), fontFamily),
fontImplementation = NativeFontAndroid((Fonts.ORIGINAL_FONT_SIZE * settings.fontSizeMultiplier).toInt(), fontFamily),
customFileLocationHelper = customFileLocationHelper,
platformSpecificHelper = platformSpecificHelper
)

View File

@ -72,6 +72,7 @@ class GameSettings {
var lastGameSetup: GameSetupInfo? = null
var fontFamily: String = Fonts.DEFAULT_FONT_FAMILY
var fontSizeMultiplier: Float = 1f
/** Maximum zoom-out of the map - performance heavy */
var maxWorldZoomOut = 2f

View File

@ -65,6 +65,8 @@ fun advancedTab(
addFontFamilySelect(this, settings, optionsPopup.selectBoxMinWidth, onFontChange)
addFontSizeMultiplier(this, settings, onFontChange)
addTranslationGeneration(this, optionsPopup)
addSetUserId(this, settings)
@ -87,8 +89,7 @@ private fun addAutosaveTurnsSelectBox(table: Table, settings: GameSettings) {
}
}
private
fun addFontFamilySelect(table: Table, settings: GameSettings, selectBoxMinWidth: Float, onFontChange: () -> Unit) {
private fun addFontFamilySelect(table: Table, settings: GameSettings, selectBoxMinWidth: Float, onFontChange: () -> Unit) {
table.add("Font family".toLabel()).left().fillX()
val selectCell = table.add()
table.row()
@ -131,6 +132,29 @@ fun addFontFamilySelect(table: Table, settings: GameSettings, selectBoxMinWidth:
}
}
private fun addFontSizeMultiplier(
table: Table,
settings: GameSettings,
onFontChange: () -> Unit
) {
table.add("Font size multiplier".toLabel()).left().fillX()
val fontSizeSlider = UncivSlider(
0.7f, 1.5f, 0.05f,
initial = settings.fontSizeMultiplier
) {
settings.fontSizeMultiplier = it
settings.save()
}
fontSizeSlider.onChange {
if (!fontSizeSlider.isDragging) {
Fonts.resetFont(settings.fontFamily)
onFontChange()
}
}
table.add(fontSizeSlider).pad(5f).row()
}
private fun addMaxZoomSlider(table: Table, settings: GameSettings) {
table.add("Max zoom out".tr()).left().fillX()
val maxZoomSlider = UncivSlider(

View File

@ -174,7 +174,7 @@ object Fonts {
try {
val fontImplementationClass = UncivGame.Current.fontImplementation!!::class.java
val fontImplementationConstructor = fontImplementationClass.constructors.first()
val newFontImpl = fontImplementationConstructor.newInstance(ORIGINAL_FONT_SIZE.toInt(), newFamily)
val newFontImpl = fontImplementationConstructor.newInstance((ORIGINAL_FONT_SIZE * UncivGame.Current.settings.fontSizeMultiplier).toInt(), newFamily)
if (newFontImpl is NativeFontImplementation)
UncivGame.Current.fontImplementation = newFontImpl
} catch (ex: Exception) {}

View File

@ -57,7 +57,7 @@ internal object DesktopLauncher {
val desktopParameters = UncivGameParameters(
versionFromJar,
cancelDiscordEvent = { discordTimer?.cancel() },
fontImplementation = NativeFontDesktop(Fonts.ORIGINAL_FONT_SIZE.toInt(), settings.fontFamily),
fontImplementation = NativeFontDesktop((Fonts.ORIGINAL_FONT_SIZE * settings.fontSizeMultiplier).toInt(), settings.fontFamily),
customFileLocationHelper = CustomFileLocationHelperDesktop(),
crashReportSysInfo = CrashReportSysInfoDesktop(),
platformSpecificHelper = platformSpecificHelper,