New icon for "Load Scenario" (#2768)
* New icon for "Load Scenario" * Javadoc comments
This commit is contained in:
parent
5753115c30
commit
aa677042dd
8 changed files with 483 additions and 411 deletions
BIN
android/Images/OtherIcons/Scenario.png
Normal file
BIN
android/Images/OtherIcons/Scenario.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
File diff suppressed because it is too large
Load diff
Binary file not shown.
Before Width: | Height: | Size: 448 KiB After Width: | Height: | Size: 455 KiB |
|
@ -132,7 +132,7 @@ class MainMenuScreen: CameraStageBaseScreen() {
|
|||
mapEditorPopup.add(loadMapButton).row()
|
||||
|
||||
if (UncivGame.Current.scenarioDebugSwitch) {
|
||||
val loadScenarioButton = getTableBlock("Load scenario", "OtherIcons/Load") {
|
||||
val loadScenarioButton = getTableBlock("Load scenario", "OtherIcons/Scenario") {
|
||||
val loadScenarioScreen = LoadScenarioScreen(null)
|
||||
loadScenarioScreen.closeButton.isVisible = true
|
||||
loadScenarioScreen.closeButton.onClick {
|
||||
|
|
|
@ -8,7 +8,13 @@ import com.unciv.ui.newgamescreen.PlayerPickerTable
|
|||
import com.unciv.ui.newgamescreen.IPreviousScreen
|
||||
import com.unciv.ui.pickerscreens.PickerScreen
|
||||
import com.unciv.ui.utils.*
|
||||
|
||||
/**
|
||||
* This [Screen] is used for editing game parameters when scenario is edited/created in map editor.
|
||||
* Implements [PreviousScreenInterface] for compatibility with [PlayerPickerTable], [GameOptionsTable]
|
||||
* Uses [PlayerPickerTable] and [GameOptionsTable] to change local [gameSetupInfo]. Upon confirmation
|
||||
* updates [mapEditorScreen] and switches to it.
|
||||
* @param [mapEditorScreen] previous screen from map editor.
|
||||
*/
|
||||
class GameParametersScreen(var mapEditorScreen: MapEditorScreen): IPreviousScreen, PickerScreen() {
|
||||
|
||||
override var gameSetupInfo: GameSetupInfo = mapEditorScreen.gameSetupInfo
|
||||
|
|
|
@ -13,6 +13,11 @@ import com.unciv.ui.pickerscreens.PickerScreen
|
|||
import com.unciv.ui.saves.Gzip
|
||||
import com.unciv.ui.utils.*
|
||||
|
||||
/**
|
||||
* [PickerScreen] used for simple load/delete scenario. Called from [MapEditorScreen]
|
||||
* and returns to that [Screen] type.
|
||||
* @param previousMap [TileMap] to return when no scenario chosen
|
||||
*/
|
||||
class LoadScenarioScreen(previousMap: TileMap?): PickerScreen(){
|
||||
var chosenScenario = ""
|
||||
val deleteScenarioButton = "Delete scenario".toTextButton()
|
||||
|
|
|
@ -6,20 +6,16 @@ import com.unciv.ui.pickerscreens.PickerScreen
|
|||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
|
||||
/**
|
||||
* Interface to use as a previous screen for GameOptionsTable and PlayerPickerTable
|
||||
* It should be a child of the PickerScreen class during new game creation
|
||||
* or CameraBackStageScreen class for map editing
|
||||
* Interface to implement for all screens using [GameOptionsTable] and [PlayerPickerTable]
|
||||
* for universal usage of those two tables.
|
||||
*/
|
||||
|
||||
interface IPreviousScreen {
|
||||
val gameSetupInfo: GameSetupInfo
|
||||
var stage: Stage
|
||||
|
||||
// added for compatibility with NewGameScreen: PickerScreen
|
||||
/**
|
||||
* Method added for compatibility with [PlayerPickerTable] which addresses
|
||||
* [setRightSideButtonEnabled] method of previous screen
|
||||
*/
|
||||
fun setRightSideButtonEnabled(boolean: Boolean)
|
||||
}
|
||||
|
||||
//abstract class GameParametersPreviousScreen: PickerScreen() {
|
||||
// abstract var gameSetupInfo: GameSetupInfo
|
||||
// abstract val ruleset: Ruleset
|
||||
//}
|
||||
}
|
|
@ -20,11 +20,25 @@ import com.unciv.ui.mapeditor.GameParametersScreen
|
|||
import com.unciv.ui.utils.*
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* This [Table] is used to pick or edit players information for new game/scenario creation.
|
||||
* Could be inserted to [NewGameScreen], [GameParametersScreen] or any other [Screen]
|
||||
* which provides [GameSetupInfo] for ruleset and updates.
|
||||
* Upon player changes updates property [gameParameters]. Also updates available nations when mod changes.
|
||||
* In case it is used in map editor, as a part of [GameParametersScreen], additionally tries to
|
||||
* update units/starting location on the [previousScreen] when player deleted or
|
||||
* switched nation.
|
||||
* @param [previousScreen] [Screen] where player table is inserted, should provide [GameSetupInfo] as property,
|
||||
* updated when player added/deleted/changed
|
||||
* @param [gameParameters] contains info about number of players.
|
||||
*/
|
||||
class PlayerPickerTable(val previousScreen: IPreviousScreen, var gameParameters: GameParameters): Table() {
|
||||
val playerListTable = Table()
|
||||
val nationsPopupWidth = previousScreen.stage.width / 2f
|
||||
val civBlocksWidth = previousScreen.stage.width / 3
|
||||
/** Locks player table for editing, used during new game creation with scenario.*/
|
||||
var locked = false
|
||||
/** No random civilization is available, used during map editing.*/
|
||||
var noRandom = false
|
||||
|
||||
init {
|
||||
|
@ -34,6 +48,11 @@ class PlayerPickerTable(val previousScreen: IPreviousScreen, var gameParameters:
|
|||
update()
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates view of main player table. Used when mod picked or player changed.
|
||||
* Also sets desired civilization, that is preferable for human players.
|
||||
* @param desiredCiv desired civilization name
|
||||
*/
|
||||
fun update(desiredCiv: String = "") {
|
||||
playerListTable.clear()
|
||||
val ruleset = previousScreen.gameSetupInfo.ruleset // the mod picking changes this ruleset
|
||||
|
@ -60,6 +79,10 @@ class PlayerPickerTable(val previousScreen: IPreviousScreen, var gameParameters:
|
|||
previousScreen.setRightSideButtonEnabled(gameParameters.players.size > 1)
|
||||
}
|
||||
|
||||
/**
|
||||
* If new mod removes nations already chosen by some player
|
||||
* sets first civilization available in the ruleset
|
||||
*/
|
||||
private fun reassignRemovedModReferences() {
|
||||
for (player in gameParameters.players) {
|
||||
if (!previousScreen.gameSetupInfo.ruleset.nations.containsKey(player.chosenCiv))
|
||||
|
@ -67,6 +90,10 @@ class PlayerPickerTable(val previousScreen: IPreviousScreen, var gameParameters:
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns desired civilization for human players with 'random' choice
|
||||
* @param desiredCiv string containing desired civilization name
|
||||
*/
|
||||
private fun assignDesiredCiv(desiredCiv: String) {
|
||||
// No auto-select if desiredCiv already used
|
||||
if (gameParameters.players.any { it.chosenCiv == desiredCiv }) return
|
||||
|
@ -74,6 +101,13 @@ class PlayerPickerTable(val previousScreen: IPreviousScreen, var gameParameters:
|
|||
gameParameters.players.firstOrNull { it.chosenCiv == "Random" && it.playerType == PlayerType.Human }?.chosenCiv = desiredCiv
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates [Table] for single player containing clickable
|
||||
* player type button ("AI" or "Human"), nation [Table]
|
||||
* and "-" remove player button.*
|
||||
* @param player for which [Table] is generated
|
||||
* @return [Table] containing the all the elements
|
||||
*/
|
||||
fun getPlayerTable(player: Player): Table {
|
||||
val playerTable = Table()
|
||||
playerTable.pad(5f)
|
||||
|
@ -138,6 +172,12 @@ class PlayerPickerTable(val previousScreen: IPreviousScreen, var gameParameters:
|
|||
return playerTable
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates clickable icon and nation name for some [Player]
|
||||
* as a [Table]. Clicking creates [popupNationPicker] to choose new nation.
|
||||
* @param player [Player] for which generated
|
||||
* @return [Table] containing nation icon and name
|
||||
*/
|
||||
private fun getNationTable(player: Player): Table {
|
||||
val nationTable = Table()
|
||||
val nationImage = if (player.chosenCiv == "Random") "?".toLabel(Color.WHITE, 25)
|
||||
|
@ -154,6 +194,12 @@ class PlayerPickerTable(val previousScreen: IPreviousScreen, var gameParameters:
|
|||
return nationTable
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens Nation picking popup with all nations,
|
||||
* currently available for [player] to choose, depending on current
|
||||
* ruleset and other players nation choice.
|
||||
* @param player current player
|
||||
*/
|
||||
private fun popupNationPicker(player: Player) {
|
||||
val nationsPopup = Popup(previousScreen as CameraStageBaseScreen)
|
||||
val nationListTable = Table()
|
||||
|
@ -206,6 +252,11 @@ class PlayerPickerTable(val previousScreen: IPreviousScreen, var gameParameters:
|
|||
update()
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of available civilization for all players, according
|
||||
* to current ruleset, with exeption of city states nations and barbarians
|
||||
* @return [ArrayList] of available [Nation]s
|
||||
*/
|
||||
private fun getAvailablePlayerCivs(): ArrayList<Nation> {
|
||||
var nations = ArrayList<Nation>()
|
||||
for (nation in previousScreen.gameSetupInfo.ruleset.nations.values
|
||||
|
|
Loading…
Reference in a new issue