From dbbfd1348656b2ae825f0e1e43616f4b02f877cf Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Thu, 31 Oct 2019 09:40:50 +0200 Subject: [PATCH] Music now downloads on another thread to not harm the user experience Removed unused "Username" string --- .../{sounds => music}/thatched-villagers.mp3 | Bin android/build.gradle | 4 +- core/src/com/unciv/UnCivGame.kt | 2 +- .../logic/civilization/CivilizationInfo.kt | 2 +- .../com/unciv/models/metadata/GameSettings.kt | 1 - .../optionstable/WorldScreenOptionsTable.kt | 37 +++++++----------- 6 files changed, 19 insertions(+), 27 deletions(-) rename android/assets/{sounds => music}/thatched-villagers.mp3 (100%) diff --git a/android/assets/sounds/thatched-villagers.mp3 b/android/assets/music/thatched-villagers.mp3 similarity index 100% rename from android/assets/sounds/thatched-villagers.mp3 rename to android/assets/music/thatched-villagers.mp3 diff --git a/android/build.gradle b/android/build.gradle index 1623046dc3..0a4930aeab 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -41,7 +41,7 @@ android { release { // Don't add local save files and fonts to release, obviously aaptOptions { - ignoreAssetsPattern "!SaveFiles:!fonts:!maps" + ignoreAssetsPattern "!SaveFiles:!fonts:!maps:!music" } minifyEnabled false @@ -51,7 +51,7 @@ android { debug { // Don't add local save files and fonts to release, obviously aaptOptions { - ignoreAssetsPattern "!SaveFiles:!fonts:!maps" + ignoreAssetsPattern "!SaveFiles:!fonts:!maps:!music" } } } diff --git a/core/src/com/unciv/UnCivGame.kt b/core/src/com/unciv/UnCivGame.kt index a9ba8be322..d2b75ef441 100644 --- a/core/src/com/unciv/UnCivGame.kt +++ b/core/src/com/unciv/UnCivGame.kt @@ -65,7 +65,7 @@ class UnCivGame(val version: String) : Game() { if(musicFile.exists()){ music = Gdx.audio.newMusic(musicFile) music!!.isLooping=true - music!!.volume = 0.4f + music!!.volume = 0.4f*settings.musicVolume music!!.play() } } diff --git a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt index 74f1d5efd0..9c26acae11 100644 --- a/core/src/com/unciv/logic/civilization/CivilizationInfo.kt +++ b/core/src/com/unciv/logic/civilization/CivilizationInfo.kt @@ -278,7 +278,7 @@ class CivilizationInfo { leaderName += " (" + "AI".tr() + ")" else if (gameInfo.civilizations.count { it.playerType == PlayerType.Human } > 1) leaderName += " (" + "Human".tr() + " - " + "Hotseat".tr() + ")" - else leaderName += " (" + "Human".tr() + " - " + UnCivGame.Current.settings.userName + ")" + else leaderName += " (" + "Human".tr() + " - " + "Multiplayer".tr() + ")" return leaderName } //endregion diff --git a/core/src/com/unciv/models/metadata/GameSettings.kt b/core/src/com/unciv/models/metadata/GameSettings.kt index 28464862d0..86f06105c6 100644 --- a/core/src/com/unciv/models/metadata/GameSettings.kt +++ b/core/src/com/unciv/models/metadata/GameSettings.kt @@ -22,7 +22,6 @@ class GameSettings { var showPixelUnits: Boolean = false var showPixelImprovements: Boolean = false - var userName:String="" var userId = "" fun save(){ diff --git a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt index 8efb6d9351..2cb54c09fa 100644 --- a/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt +++ b/core/src/com/unciv/ui/worldscreen/optionstable/WorldScreenOptionsTable.kt @@ -11,6 +11,7 @@ import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.tr import com.unciv.ui.utils.* import com.unciv.ui.worldscreen.WorldScreen +import kotlin.concurrent.thread class Language(val language:String){ val percentComplete:Int @@ -117,7 +118,6 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr innerTable.add("Version".toLabel()) innerTable.add(UnCivGame.Current.version.toLabel()).row() - addUsernameAndId(innerTable) val scrollPane = ScrollPane(innerTable, skin) scrollPane.setOverscroll(false, false) @@ -132,18 +132,6 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr UnCivGame.Current.worldScreen.shouldUpdate = true } - private fun addUsernameAndId(innerTable: PopupTable) { - innerTable.add("Username".toLabel()) - val userNameTextField = TextField(UnCivGame.Current.settings.userName, skin) - userNameTextField.addListener { - UnCivGame.Current.settings.userName = userNameTextField.text - UnCivGame.Current.settings.save() - true - } - innerTable.add(userNameTextField).row() - - - } private fun addSoundEffectsVolumeSlider(innerTable: PopupTable) { innerTable.add("Sound effects volume".tr()) @@ -183,15 +171,20 @@ class WorldScreenOptionsTable(val worldScreen:WorldScreen) : PopupTable(worldScr innerTable.add(errorTable).colspan(2).row() downloadMusicButton.onClick { - try{ - val file = DropBox().downloadFile("/Music/thatched-villagers.mp3") - musicLocation.write(file,false) - update() - UnCivGame.Current.startMusic() - } - catch (ex:Exception){ - errorTable.clear() - errorTable.add("Could not download music!".toLabel().setFontColor(Color.RED)) + // So the whole game doesn't get stuck while downloading the file + thread { + try { + downloadMusicButton.disable() + errorTable.clear() + errorTable.add("Downloading...".toLabel()) + val file = DropBox().downloadFile("/Music/thatched-villagers.mp3") + musicLocation.write(file, false) + update() + UnCivGame.Current.startMusic() + } catch (ex: Exception) { + errorTable.clear() + errorTable.add("Could not download music!".toLabel().setFontColor(Color.RED)) + } } } }