From 51ba657b75e0ac43dbd6879beed91607abfa6e95 Mon Sep 17 00:00:00 2001 From: alexban011 Date: Sat, 25 Jun 2022 14:46:12 +0300 Subject: [PATCH] Added option to select font size (#7238) --- .../jsons/translations/template.properties | 1 + android/src/com/unciv/app/AndroidLauncher.kt | 2 +- .../com/unciv/models/metadata/GameSettings.kt | 1 + core/src/com/unciv/ui/options/AdvancedTab.kt | 28 +++++++++++++++++-- core/src/com/unciv/ui/utils/Fonts.kt | 2 +- .../com/unciv/app/desktop/DesktopLauncher.kt | 2 +- 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/android/assets/jsons/translations/template.properties b/android/assets/jsons/translations/template.properties index fbca4277ce..7d211e40cd 100644 --- a/android/assets/jsons/translations/template.properties +++ b/android/assets/jsons/translations/template.properties @@ -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. = diff --git a/android/src/com/unciv/app/AndroidLauncher.kt b/android/src/com/unciv/app/AndroidLauncher.kt index 634d5b13d3..9d58ce85f5 100644 --- a/android/src/com/unciv/app/AndroidLauncher.kt +++ b/android/src/com/unciv/app/AndroidLauncher.kt @@ -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 ) diff --git a/core/src/com/unciv/models/metadata/GameSettings.kt b/core/src/com/unciv/models/metadata/GameSettings.kt index c8b32a0877..7a81ba8a86 100644 --- a/core/src/com/unciv/models/metadata/GameSettings.kt +++ b/core/src/com/unciv/models/metadata/GameSettings.kt @@ -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 diff --git a/core/src/com/unciv/ui/options/AdvancedTab.kt b/core/src/com/unciv/ui/options/AdvancedTab.kt index 6df820f135..099fb24443 100644 --- a/core/src/com/unciv/ui/options/AdvancedTab.kt +++ b/core/src/com/unciv/ui/options/AdvancedTab.kt @@ -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( diff --git a/core/src/com/unciv/ui/utils/Fonts.kt b/core/src/com/unciv/ui/utils/Fonts.kt index bcc0e6b926..c35f10dacf 100644 --- a/core/src/com/unciv/ui/utils/Fonts.kt +++ b/core/src/com/unciv/ui/utils/Fonts.kt @@ -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) {} diff --git a/desktop/src/com/unciv/app/desktop/DesktopLauncher.kt b/desktop/src/com/unciv/app/desktop/DesktopLauncher.kt index 3141d58fe0..e149a4cd1d 100644 --- a/desktop/src/com/unciv/app/desktop/DesktopLauncher.kt +++ b/desktop/src/com/unciv/app/desktop/DesktopLauncher.kt @@ -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,