From 799aafbc88f33b7cadd0d07e2f0a87b19243a5a7 Mon Sep 17 00:00:00 2001 From: MehdiAyadi <91869915+MehdiAyadi@users.noreply.github.com> Date: Sun, 20 Nov 2022 11:12:16 +0100 Subject: [PATCH] Added Viewport scaling for Settings.kt --- .../kotlin/com/last/commit/screen/MainMenu.kt | 2 +- .../kotlin/com/last/commit/screen/Settings.kt | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/com/last/commit/screen/MainMenu.kt b/core/src/main/kotlin/com/last/commit/screen/MainMenu.kt index 7f80f8a..3a780bb 100644 --- a/core/src/main/kotlin/com/last/commit/screen/MainMenu.kt +++ b/core/src/main/kotlin/com/last/commit/screen/MainMenu.kt @@ -60,7 +60,7 @@ class MainMenu(val parent: Game) : TimeTravelScreen() { table.setFillParent(true); val newGame = TextButton("Play Game", uiSkin) - val preferences = TextButton("Preferences", uiSkin) + val preferences = TextButton("Settings", uiSkin) preferences.setSize(stage.viewport.screenWidth.toFloat(), stage.viewport.screenHeight.toFloat()) val exit = TextButton("Exit", uiSkin) diff --git a/core/src/main/kotlin/com/last/commit/screen/Settings.kt b/core/src/main/kotlin/com/last/commit/screen/Settings.kt index f6aa6dd..c37bce0 100644 --- a/core/src/main/kotlin/com/last/commit/screen/Settings.kt +++ b/core/src/main/kotlin/com/last/commit/screen/Settings.kt @@ -22,6 +22,8 @@ class Settings(val parent: Game) : TimeTravelScreen() { lateinit var musicOnOffLabel: Label lateinit var soundOnOffLabel: Label + val table = Table() + init { parent.state.assetManager.finishLoading() stage = Stage(ScreenViewport()) @@ -46,7 +48,11 @@ class Settings(val parent: Game) : TimeTravelScreen() { // Create a table that fills the screen. Everything else will go inside // this table. - val table = Table() + + } + + fun renderTable(x: Float, y: Float) { + table.reset() table.setFillParent(true) //table.setDebug(true); stage.addActor(table) @@ -101,17 +107,22 @@ class Settings(val parent: Game) : TimeTravelScreen() { soundOnOffLabel = Label("Sound Effect", skin) table.add(titleLabel).colspan(2) table.row().pad(10F, 0F, 0F, 10F) + table.row().size(x, y); table.add(volumeMusicLabel).left() table.add(volumeMusicSlider) + table.row().size(x, y); table.row().pad(10F, 0F, 0F, 10F) table.add(musicOnOffLabel).left() table.add(musicCheckbox) + table.row().size(x, y); table.row().pad(10F, 0F, 0F, 10F) table.add(volumeSoundLabel).left() table.add(soundMusicSlider) + table.row().size(x, y); table.row().pad(10F, 0F, 0F, 10F) table.add(soundOnOffLabel).left() table.add(soundEffectsCheckbox) + table.row().size(x, y); table.row().pad(10F, 0F, 0F, 10F) table.add(backButton).colspan(2) } @@ -127,7 +138,14 @@ class Settings(val parent: Game) : TimeTravelScreen() { } override fun resize(width: Int, height: Int) { - stage.viewport.update(width, height) + println("width $width, height $height") + stage.viewport.update(width, height, true); + + + val y = stage.viewport.screenHeight.toFloat() / 6 + val x = stage.viewport.screenWidth.toFloat() / 4 + + renderTable(x, y) } override fun pause() {