mirror of
https://github.com/yairm210/Unciv.git
synced 2025-07-21 13:18:56 +07:00
added game option to disable unwanted spectators from a multiplayer game (#7290)
* feature * only display option if onlineMultiplayer is enabled * translatable * no more negativity * 1 * threw UncivShowableException * reviews * reviewed myself
This commit is contained in:
@ -361,6 +361,7 @@ Disable starting bias =
|
|||||||
Raging Barbarians =
|
Raging Barbarians =
|
||||||
No Ancient Ruins =
|
No Ancient Ruins =
|
||||||
No Natural Wonders =
|
No Natural Wonders =
|
||||||
|
Allow anyone to spectate =
|
||||||
Victory Conditions =
|
Victory Conditions =
|
||||||
Scientific =
|
Scientific =
|
||||||
Domination =
|
Domination =
|
||||||
@ -602,6 +603,7 @@ Paste gameID from clipboard =
|
|||||||
GameID =
|
GameID =
|
||||||
Game name =
|
Game name =
|
||||||
Loading latest game state... =
|
Loading latest game state... =
|
||||||
|
You are not allowed to spectate! =
|
||||||
Couldn't download the latest game state! =
|
Couldn't download the latest game state! =
|
||||||
Resign =
|
Resign =
|
||||||
Are you sure you want to resign? =
|
Are you sure you want to resign? =
|
||||||
|
@ -8,6 +8,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table
|
|||||||
import com.badlogic.gdx.utils.Align
|
import com.badlogic.gdx.utils.Align
|
||||||
import com.unciv.logic.GameInfo
|
import com.unciv.logic.GameInfo
|
||||||
import com.unciv.logic.GameStarter
|
import com.unciv.logic.GameStarter
|
||||||
|
import com.unciv.logic.UncivShowableException
|
||||||
import com.unciv.logic.map.MapParameters
|
import com.unciv.logic.map.MapParameters
|
||||||
import com.unciv.logic.map.MapShape
|
import com.unciv.logic.map.MapShape
|
||||||
import com.unciv.logic.map.MapSizeNew
|
import com.unciv.logic.map.MapSizeNew
|
||||||
@ -227,6 +228,10 @@ class MainMenuScreen: BaseScreen(), RecreateOnResize {
|
|||||||
// Can fail when starting the game...
|
// Can fail when starting the game...
|
||||||
try {
|
try {
|
||||||
newGame = GameStarter.startNewGame(GameSetupInfo.fromSettings("Chieftain"))
|
newGame = GameStarter.startNewGame(GameSetupInfo.fromSettings("Chieftain"))
|
||||||
|
} catch (notAPlayer: UncivShowableException) {
|
||||||
|
val (message) = LoadGameScreen.getLoadExceptionMessage(notAPlayer)
|
||||||
|
launchOnGLThread { ToastPopup(message, this@MainMenuScreen) }
|
||||||
|
return@run
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
launchOnGLThread { ToastPopup(errorText, this@MainMenuScreen) }
|
launchOnGLThread { ToastPopup(errorText, this@MainMenuScreen) }
|
||||||
return@run
|
return@run
|
||||||
@ -239,6 +244,11 @@ class MainMenuScreen: BaseScreen(), RecreateOnResize {
|
|||||||
launchOnGLThread {
|
launchOnGLThread {
|
||||||
ToastPopup("Not enough memory on phone to load game!", this@MainMenuScreen)
|
ToastPopup("Not enough memory on phone to load game!", this@MainMenuScreen)
|
||||||
}
|
}
|
||||||
|
} catch (notAPlayer: UncivShowableException) {
|
||||||
|
val (message) = LoadGameScreen.getLoadExceptionMessage(notAPlayer)
|
||||||
|
launchOnGLThread {
|
||||||
|
ToastPopup(message, this@MainMenuScreen)
|
||||||
|
}
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
launchOnGLThread {
|
launchOnGLThread {
|
||||||
ToastPopup(errorText, this@MainMenuScreen)
|
ToastPopup(errorText, this@MainMenuScreen)
|
||||||
|
@ -10,6 +10,7 @@ import com.badlogic.gdx.utils.Align
|
|||||||
import com.unciv.logic.GameInfo
|
import com.unciv.logic.GameInfo
|
||||||
import com.unciv.logic.IsPartOfGameInfoSerialization
|
import com.unciv.logic.IsPartOfGameInfoSerialization
|
||||||
import com.unciv.logic.UncivFiles
|
import com.unciv.logic.UncivFiles
|
||||||
|
import com.unciv.logic.UncivShowableException
|
||||||
import com.unciv.logic.civilization.PlayerType
|
import com.unciv.logic.civilization.PlayerType
|
||||||
import com.unciv.logic.multiplayer.OnlineMultiplayer
|
import com.unciv.logic.multiplayer.OnlineMultiplayer
|
||||||
import com.unciv.models.metadata.GameSettings
|
import com.unciv.models.metadata.GameSettings
|
||||||
@ -179,6 +180,12 @@ class UncivGame(parameters: UncivGameParameters) : Game() {
|
|||||||
val prevGameInfo = gameInfo
|
val prevGameInfo = gameInfo
|
||||||
gameInfo = newGameInfo
|
gameInfo = newGameInfo
|
||||||
|
|
||||||
|
if (gameInfo?.gameParameters?.anyoneCanSpectate == false) {
|
||||||
|
if (gameInfo!!.civilizations.none { it.playerId == settings.multiplayer.userId }) {
|
||||||
|
throw UncivShowableException("You are not allowed to spectate!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initializeResources(prevGameInfo, newGameInfo)
|
initializeResources(prevGameInfo, newGameInfo)
|
||||||
|
|
||||||
val isLoadingSameGame = worldScreen != null && prevGameInfo != null && prevGameInfo.gameId == newGameInfo.gameId
|
val isLoadingSameGame = worldScreen != null && prevGameInfo != null && prevGameInfo.gameId == newGameInfo.gameId
|
||||||
|
@ -35,6 +35,7 @@ class GameParameters : IsPartOfGameInfoSerialization { // Default values are the
|
|||||||
var startingEra = "Ancient era"
|
var startingEra = "Ancient era"
|
||||||
|
|
||||||
var isOnlineMultiplayer = false
|
var isOnlineMultiplayer = false
|
||||||
|
var anyoneCanSpectate = false
|
||||||
var baseRuleset: String = BaseRuleset.Civ_V_GnK.fullName
|
var baseRuleset: String = BaseRuleset.Civ_V_GnK.fullName
|
||||||
var mods = LinkedHashSet<String>()
|
var mods = LinkedHashSet<String>()
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import com.unciv.logic.multiplayer.OnlineMultiplayer
|
|||||||
import com.unciv.logic.multiplayer.OnlineMultiplayerGame
|
import com.unciv.logic.multiplayer.OnlineMultiplayerGame
|
||||||
import com.unciv.models.translations.tr
|
import com.unciv.models.translations.tr
|
||||||
import com.unciv.ui.popup.Popup
|
import com.unciv.ui.popup.Popup
|
||||||
|
import com.unciv.ui.popup.ToastPopup
|
||||||
import com.unciv.ui.saves.LoadGameScreen
|
import com.unciv.ui.saves.LoadGameScreen
|
||||||
import com.unciv.ui.utils.BaseScreen
|
import com.unciv.ui.utils.BaseScreen
|
||||||
import com.unciv.ui.utils.extensions.formatShort
|
import com.unciv.ui.utils.extensions.formatShort
|
||||||
|
@ -70,6 +70,8 @@ class GameOptionsTable(
|
|||||||
checkboxTable.addOneCityChallengeCheckbox()
|
checkboxTable.addOneCityChallengeCheckbox()
|
||||||
checkboxTable.addNuclearWeaponsCheckbox()
|
checkboxTable.addNuclearWeaponsCheckbox()
|
||||||
checkboxTable.addIsOnlineMultiplayerCheckbox()
|
checkboxTable.addIsOnlineMultiplayerCheckbox()
|
||||||
|
if (gameParameters.isOnlineMultiplayer)
|
||||||
|
checkboxTable.addAnyoneCanSpectateCheckbox()
|
||||||
if (UncivGame.Current.settings.enableEspionageOption)
|
if (UncivGame.Current.settings.enableEspionageOption)
|
||||||
checkboxTable.addEnableEspionageCheckbox()
|
checkboxTable.addEnableEspionageCheckbox()
|
||||||
checkboxTable.addNoStartBiasCheckbox()
|
checkboxTable.addNoStartBiasCheckbox()
|
||||||
@ -92,8 +94,8 @@ class GameOptionsTable(
|
|||||||
{ gameParameters.noBarbarians = it }
|
{ gameParameters.noBarbarians = it }
|
||||||
|
|
||||||
private fun Table.addRagingBarbariansCheckbox() =
|
private fun Table.addRagingBarbariansCheckbox() =
|
||||||
addCheckbox("Raging Barbarians", gameParameters.ragingBarbarians)
|
addCheckbox("Raging Barbarians", gameParameters.ragingBarbarians)
|
||||||
{ gameParameters.ragingBarbarians = it }
|
{ gameParameters.ragingBarbarians = it }
|
||||||
|
|
||||||
private fun Table.addOneCityChallengeCheckbox() =
|
private fun Table.addOneCityChallengeCheckbox() =
|
||||||
addCheckbox("One City Challenge", gameParameters.oneCityChallenge)
|
addCheckbox("One City Challenge", gameParameters.oneCityChallenge)
|
||||||
@ -111,6 +113,13 @@ class GameOptionsTable(
|
|||||||
if (shouldUseMultiplayer) {
|
if (shouldUseMultiplayer) {
|
||||||
MultiplayerHelpers.showDropboxWarning(previousScreen as BaseScreen)
|
MultiplayerHelpers.showDropboxWarning(previousScreen as BaseScreen)
|
||||||
}
|
}
|
||||||
|
update()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Table.addAnyoneCanSpectateCheckbox() =
|
||||||
|
addCheckbox("Allow anyone to spectate", gameParameters.anyoneCanSpectate)
|
||||||
|
{
|
||||||
|
gameParameters.anyoneCanSpectate = it
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Table.addEnableEspionageCheckbox() =
|
private fun Table.addEnableEspionageCheckbox() =
|
||||||
|
@ -24,6 +24,7 @@ import com.unciv.ui.pickerscreens.PickerScreen
|
|||||||
import com.unciv.ui.popup.ConfirmPopup
|
import com.unciv.ui.popup.ConfirmPopup
|
||||||
import com.unciv.ui.popup.Popup
|
import com.unciv.ui.popup.Popup
|
||||||
import com.unciv.ui.popup.ToastPopup
|
import com.unciv.ui.popup.ToastPopup
|
||||||
|
import com.unciv.ui.saves.LoadGameScreen
|
||||||
import com.unciv.ui.utils.BaseScreen
|
import com.unciv.ui.utils.BaseScreen
|
||||||
import com.unciv.ui.utils.ExpanderTab
|
import com.unciv.ui.utils.ExpanderTab
|
||||||
import com.unciv.ui.utils.RecreateOnResize
|
import com.unciv.ui.utils.RecreateOnResize
|
||||||
@ -35,6 +36,7 @@ import com.unciv.ui.utils.extensions.onClick
|
|||||||
import com.unciv.ui.utils.extensions.pad
|
import com.unciv.ui.utils.extensions.pad
|
||||||
import com.unciv.ui.utils.extensions.toLabel
|
import com.unciv.ui.utils.extensions.toLabel
|
||||||
import com.unciv.ui.utils.extensions.toTextButton
|
import com.unciv.ui.utils.extensions.toTextButton
|
||||||
|
import com.unciv.ui.worldscreen.WorldScreen
|
||||||
import com.unciv.utils.Log
|
import com.unciv.utils.Log
|
||||||
import com.unciv.utils.concurrency.Concurrency
|
import com.unciv.utils.concurrency.Concurrency
|
||||||
import com.unciv.utils.concurrency.launchOnGLThread
|
import com.unciv.utils.concurrency.launchOnGLThread
|
||||||
@ -113,6 +115,16 @@ class NewGameScreen(
|
|||||||
return@onClick
|
return@onClick
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!gameSetupInfo.gameParameters.anyoneCanSpectate) {
|
||||||
|
if (gameSetupInfo.gameParameters.players.none { it.playerId == UncivGame.Current.settings.multiplayer.userId }) {
|
||||||
|
val notAllowedToSpectate = Popup(this)
|
||||||
|
notAllowedToSpectate.addGoodSizedLabel("You are not allowed to spectate!".tr()).row()
|
||||||
|
notAllowedToSpectate.addCloseButton()
|
||||||
|
notAllowedToSpectate.open()
|
||||||
|
return@onClick
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameSetupInfo.gameParameters.players.none {
|
if (gameSetupInfo.gameParameters.players.none {
|
||||||
|
@ -119,6 +119,12 @@ class LoadGameScreen(previousScreen:BaseScreen) : LoadOrSaveScreen() {
|
|||||||
// This is what can lead to ANRs - reading the file and setting the transients, that's why this is in another thread
|
// This is what can lead to ANRs - reading the file and setting the transients, that's why this is in another thread
|
||||||
val loadedGame = game.files.loadGameByName(selectedSave)
|
val loadedGame = game.files.loadGameByName(selectedSave)
|
||||||
game.loadGame(loadedGame)
|
game.loadGame(loadedGame)
|
||||||
|
} catch (notAPlayer: UncivShowableException) {
|
||||||
|
launchOnGLThread {
|
||||||
|
val (message) = getLoadExceptionMessage(notAPlayer)
|
||||||
|
loadingPopup.reuseWith(message, true)
|
||||||
|
handleLoadGameException(notAPlayer)
|
||||||
|
}
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
launchOnGLThread {
|
launchOnGLThread {
|
||||||
loadingPopup.close()
|
loadingPopup.close()
|
||||||
|
@ -4,6 +4,7 @@ import com.unciv.Constants
|
|||||||
import com.unciv.MainMenuScreen
|
import com.unciv.MainMenuScreen
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
import com.unciv.logic.GameInfo
|
import com.unciv.logic.GameInfo
|
||||||
|
import com.unciv.logic.UncivShowableException
|
||||||
import com.unciv.ui.multiplayer.MultiplayerHelpers
|
import com.unciv.ui.multiplayer.MultiplayerHelpers
|
||||||
import com.unciv.ui.popup.Popup
|
import com.unciv.ui.popup.Popup
|
||||||
import com.unciv.ui.popup.ToastPopup
|
import com.unciv.ui.popup.ToastPopup
|
||||||
@ -88,6 +89,12 @@ object QuickSave {
|
|||||||
screen.game.onlineMultiplayer.loadGame(savedGame)
|
screen.game.onlineMultiplayer.loadGame(savedGame)
|
||||||
} catch (oom: OutOfMemoryError) {
|
} catch (oom: OutOfMemoryError) {
|
||||||
outOfMemory()
|
outOfMemory()
|
||||||
|
} catch (notAPlayer: UncivShowableException) {
|
||||||
|
val (message) = LoadGameScreen.getLoadExceptionMessage(notAPlayer)
|
||||||
|
launchOnGLThread {
|
||||||
|
loadingPopup.close()
|
||||||
|
ToastPopup(message, screen)
|
||||||
|
}
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
Log.error("Could not autoload game", ex)
|
Log.error("Could not autoload game", ex)
|
||||||
val (message) = LoadGameScreen.getLoadExceptionMessage(ex)
|
val (message) = LoadGameScreen.getLoadExceptionMessage(ex)
|
||||||
|
@ -15,6 +15,7 @@ import com.unciv.Constants
|
|||||||
import com.unciv.MainMenuScreen
|
import com.unciv.MainMenuScreen
|
||||||
import com.unciv.UncivGame
|
import com.unciv.UncivGame
|
||||||
import com.unciv.logic.GameInfo
|
import com.unciv.logic.GameInfo
|
||||||
|
import com.unciv.logic.UncivShowableException
|
||||||
import com.unciv.logic.civilization.CivilizationInfo
|
import com.unciv.logic.civilization.CivilizationInfo
|
||||||
import com.unciv.logic.civilization.ReligionState
|
import com.unciv.logic.civilization.ReligionState
|
||||||
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
import com.unciv.logic.civilization.diplomacy.DiplomaticStatus
|
||||||
@ -855,6 +856,13 @@ private fun startNewScreenJob(gameInfo: GameInfo, autosaveDisabled:Boolean = fal
|
|||||||
Concurrency.run {
|
Concurrency.run {
|
||||||
val newWorldScreen = try {
|
val newWorldScreen = try {
|
||||||
UncivGame.Current.loadGame(gameInfo)
|
UncivGame.Current.loadGame(gameInfo)
|
||||||
|
} catch (notAPlayer: UncivShowableException) {
|
||||||
|
withGLContext {
|
||||||
|
val (message) = LoadGameScreen.getLoadExceptionMessage(notAPlayer)
|
||||||
|
val mainMenu = UncivGame.Current.goToMainMenu()
|
||||||
|
ToastPopup(message, mainMenu)
|
||||||
|
}
|
||||||
|
return@run
|
||||||
} catch (oom: OutOfMemoryError) {
|
} catch (oom: OutOfMemoryError) {
|
||||||
withGLContext {
|
withGLContext {
|
||||||
val mainMenu = UncivGame.Current.goToMainMenu()
|
val mainMenu = UncivGame.Current.goToMainMenu()
|
||||||
|
Reference in New Issue
Block a user