Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ class NotificationServiceProvider : NotificationService() {
@Inject("notificationViewClass")
private lateinit var notificationViewClass: Class<out NotificationView>

@Inject("fontSizeScaleUI")
private var fontSizeScaleUI = 1.0

@Inject("fontSizeScaleNotification")
private var fontSizeScaleNotification = 1.0

private val notificationView by lazy {
ReflectionUtils.newInstance(notificationViewClass).also {
it.appWidth = sceneService.prefWidth.toInt()
it.appHeight = sceneService.prefHeight.toInt()
it.fontSize = fontSizeScaleUI * fontSizeScaleNotification * 18.0
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ abstract class NotificationView : Pane(), Updatable {
// these will be updated during notification service init
var appWidth = 800
var appHeight = 600
var fontSize = 18.0

/**
* Called when view is added to scene.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ class XboxNotificationView : NotificationView() {
*/
private val text1 = Text().also {
it.fill = textColor
it.font = Font.font(18.0)
}

private val text2 = Text().also {
it.fill = textColor
it.font = Font.font(18.0)
}

init {
Expand All @@ -67,9 +65,11 @@ class XboxNotificationView : NotificationView() {
text1.translateY = 35.0
text1.isVisible = false
text1.fill = textColor
text1.font = Font.font(fontSize)
text1.text = ""

text2.fill = textColor
text2.font = Font.font(fontSize)

translateX = appWidth / 2 - bg.width / 2 + 200
translateY = 50.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import java.util.function.Predicate
*/
class FXGLDialogFactoryServiceProvider : DialogFactoryService() {

@Inject("fontSizeScaleUI")
private var fontSizeScaleUI = 1.0
@Inject("fontSizeScaleDialog")
private var fontSizeScaleDialog = 1.0

private lateinit var uiFactory: UIFactoryService

Expand Down Expand Up @@ -155,7 +155,7 @@ class FXGLDialogFactoryServiceProvider : DialogFactoryService() {

val field = TextField()
field.maxWidth = Math.max(text.layoutBounds.width, 200.0)
field.font = uiFactory.newFont(18.0)
field.font = uiFactory.newFont(fontSizeScaleDialog * 18.0)

field.focusedProperty().addListener { _, _, isFocused ->
if (!isFocused && field.scene != null) {
Expand Down Expand Up @@ -200,7 +200,7 @@ class FXGLDialogFactoryServiceProvider : DialogFactoryService() {

val field = TextField()
field.maxWidth = Math.max(text.layoutBounds.width, 200.0)
field.font = uiFactory.newFont(18.0)
field.font = uiFactory.newFont(fontSizeScaleDialog * 18.0)

val btnOK = uiFactory.newButton(localizedStringProperty("dialog.ok"))

Expand Down Expand Up @@ -302,7 +302,7 @@ class FXGLDialogFactoryServiceProvider : DialogFactoryService() {
}

private fun createMessage(message: String): Text {
return uiFactory.newText(message, fontSizeScaleUI * 18.0)
return uiFactory.newText(message, fontSizeScaleDialog * 18.0)
}

private fun localizedStringProperty(key: String): StringBinding {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.almasb.fxgl.ui

import com.almasb.fxgl.core.Inject
import com.almasb.fxgl.core.collection.PropertyMap
import com.almasb.fxgl.core.math.Vec2
import com.almasb.fxgl.logging.Logger
Expand Down Expand Up @@ -35,6 +36,9 @@ class FXGLUIFactoryServiceProvider : UIFactoryService() {

private val log = Logger.get(javaClass)

@Inject("fontSizeScaleUI")
private var fontSizeScaleUI = 1.0

private val fontFactories = hashMapOf<FontType, ObjectProperty<FontFactory>>()
private val propertyViewFactories = hashMapOf<Class<*>, PropertyViewFactory<*, *>>()

Expand Down Expand Up @@ -90,15 +94,15 @@ class FXGLUIFactoryServiceProvider : UIFactoryService() {
}

override fun newFont(type: FontType, size: Double): Font {
val font = fontFactories[type]?.value?.newFont(size)
val font = fontFactories[type]?.value?.newFont(fontSizeScaleUI * size)

if (font != null) {
return font
}

log.warning("No font factory found for $type. Using default")

return Font.font(size)
return Font.font(fontSizeScaleUI * size)
}

override fun newButton(text: String): Button {
Expand Down Expand Up @@ -205,6 +209,6 @@ class FXGLUIFactoryServiceProvider : UIFactoryService() {

private fun fontProperty(type: FontType, fontSize: Double) =
Bindings.createObjectBinding(Callable {
return@Callable fontFactories[type]!!.value.newFont(fontSize)
return@Callable fontFactories[type]!!.value.newFont(fontSizeScaleUI * fontSize)
}, fontFactories[type]!!)
}
25 changes: 25 additions & 0 deletions fxgl/src/main/kotlin/com/almasb/fxgl/app/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,25 @@ class GameSettings(

/**
* Set the scale value for UI text size, default = 1.0.
* Applied globally to all text constructed via UIFactoryService.
*/
var fontSizeScaleUI: Double = 1.0,

/**
* Per-area scale for menu text, multiplied on top of [fontSizeScaleUI], default = 1.0.
*/
var fontSizeScaleMenu: Double = 1.0,

/**
* Per-area scale for dialog text, multiplied on top of [fontSizeScaleUI], default = 1.0.
*/
var fontSizeScaleDialog: Double = 1.0,

/**
* Per-area scale for notification text, multiplied on top of [fontSizeScaleUI], default = 1.0.
*/
var fontSizeScaleNotification: Double = 1.0,

var pixelsPerMeter: Double = 50.0,

var collisionDetectionStrategy: CollisionDetectionStrategy = CollisionDetectionStrategy.BRUTE_FORCE,
Expand Down Expand Up @@ -409,6 +425,9 @@ class GameSettings(
soundMenuPress,
soundMenuSelect,
fontSizeScaleUI,
fontSizeScaleMenu,
fontSizeScaleDialog,
fontSizeScaleNotification,
pixelsPerMeter,
collisionDetectionStrategy,
secondsIn24h,
Expand Down Expand Up @@ -583,6 +602,12 @@ class ReadOnlyGameSettings internal constructor(

val fontSizeScaleUI: Double,

val fontSizeScaleMenu: Double,

val fontSizeScaleDialog: Double,

val fontSizeScaleNotification: Double,

val pixelsPerMeter: Double,

val collisionDetectionStrategy: CollisionDetectionStrategy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ open class FXGLDefaultMenu(type: MenuType) : FXGLMenu(type) {

private val particleSystem = ParticleSystem()

private val menuScale: Double
get() = getSettings().fontSizeScaleMenu

private val titleColor = SimpleObjectProperty(Color.WHITE)
private var t = 0.0

Expand Down Expand Up @@ -189,12 +192,12 @@ open class FXGLDefaultMenu(type: MenuType) : FXGLMenu(type) {
}

private fun createTitleView(title: String): Node {
val text = getUIFactoryService().newText(title.substring(0, 1), 50.0)
val text = getUIFactoryService().newText(title.substring(0, 1), menuScale * 50.0)
text.fill = null
text.strokeProperty().bind(titleColor)
text.strokeWidth = 1.5

val text2 = getUIFactoryService().newText(title.substring(1, title.length), 50.0)
val text2 = getUIFactoryService().newText(title.substring(1, title.length), menuScale * 50.0)
text2.fill = null
text2.stroke = titleColor.value
text2.strokeWidth = 1.5
Expand Down Expand Up @@ -540,7 +543,7 @@ open class FXGLDefaultMenu(type: MenuType) : FXGLMenu(type) {

val nameDate = "%-25.25s %s".format(item.name, item.dateTime.format(DateTimeFormatter.ofPattern("dd-MM-yyyy HH-mm")))

val text = getUIFactoryService().newText(nameDate, Color.WHITE, FontType.MONO, FONT_SIZE)
val text = getUIFactoryService().newText(nameDate, Color.WHITE, FontType.MONO, menuScale * FONT_SIZE)

graphic = text
}
Expand Down Expand Up @@ -654,7 +657,7 @@ open class FXGLDefaultMenu(type: MenuType) : FXGLMenu(type) {
rect.arcWidth = 15.0
rect.arcHeight = 15.0

val text = getUIFactoryService().newText("", 24.0)
val text = getUIFactoryService().newText("", menuScale * 24.0)
text.textProperty().bind(localizedStringProperty("menu.pressAnyKey"))

val pane = StackPane(rect, text)
Expand All @@ -666,7 +669,7 @@ open class FXGLDefaultMenu(type: MenuType) : FXGLMenu(type) {
}

private fun addNewInputBinding(action: UserAction, trigger: Trigger, grid: GridPane) {
val actionName = getUIFactoryService().newText(action.name, Color.WHITE, 18.0)
val actionName = getUIFactoryService().newText(action.name, Color.WHITE, menuScale * 18.0)

val triggerView = TriggerView(trigger)
triggerView.triggerProperty().bind(getInput().triggerProperty(action))
Expand Down