More changes towards player-based game starts

This commit is contained in:
Yair Morgenstern 2019-08-09 15:57:34 +03:00
parent 93634dae31
commit 9de30bfbce
3 changed files with 120 additions and 82 deletions

View File

@ -2,7 +2,6 @@ package com.unciv.ui.newgamescreen
import com.badlogic.gdx.scenes.scene2d.Touchable import com.badlogic.gdx.scenes.scene2d.Touchable
import com.badlogic.gdx.scenes.scene2d.ui.Label import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.scenes.scene2d.ui.Table import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.unciv.GameParameters import com.unciv.GameParameters
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
@ -11,7 +10,8 @@ import com.unciv.models.gamebasics.Translations
import com.unciv.models.gamebasics.tr import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.* import com.unciv.ui.utils.*
class NationTable(val nation: Nation, val newGameParameters: GameParameters, skin: Skin, width:Float, onClick:()->Unit): Table(skin){ class NationTable(val nation: Nation, val newGameParameters: GameParameters, width:Float, onClick:()->Unit)
: Table(CameraStageBaseScreen.skin){
val innerTable = Table() val innerTable = Table()
init { init {
background = ImageGetter.getBackground(nation.getSecondaryColor()) background = ImageGetter.getBackground(nation.getSecondaryColor())
@ -28,13 +28,6 @@ class NationTable(val nation: Nation, val newGameParameters: GameParameters, ski
.apply { setWrap(true);setFontColor(nation.getSecondaryColor()) }) .apply { setWrap(true);setFontColor(nation.getSecondaryColor()) })
.width(width) .width(width)
onClick { onClick {
if (nation.name in newGameParameters.humanNations) {
newGameParameters.humanNations.remove(nation.name)
} else {
newGameParameters.humanNations.add(nation.name)
if (newGameParameters.humanNations.size > newGameParameters.numberOfHumanPlayers)
newGameParameters.humanNations.removeAt(0)
}
onClick() onClick()
} }
touchable = Touchable.enabled touchable = Touchable.enabled

View File

@ -1,7 +1,10 @@
package com.unciv.ui.newgamescreen package com.unciv.ui.newgamescreen
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.utils.Array import com.badlogic.gdx.utils.Array
import com.unciv.Constants import com.unciv.Constants
import com.unciv.GameStarter import com.unciv.GameStarter
@ -11,7 +14,9 @@ import com.unciv.logic.civilization.PlayerType
import com.unciv.models.gamebasics.GameBasics import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.tr import com.unciv.models.gamebasics.tr
import com.unciv.ui.pickerscreens.PickerScreen import com.unciv.ui.pickerscreens.PickerScreen
import com.unciv.ui.utils.* import com.unciv.ui.utils.disable
import com.unciv.ui.utils.enable
import com.unciv.ui.utils.onClick
import com.unciv.ui.worldscreen.WorldScreen import com.unciv.ui.worldscreen.WorldScreen
import com.unciv.ui.worldscreen.optionstable.PopupTable import com.unciv.ui.worldscreen.optionstable.PopupTable
import kotlin.concurrent.thread import kotlin.concurrent.thread
@ -34,7 +39,16 @@ class NewGameScreen: PickerScreen(){
// mainTable.add(playerPickerTable) // mainTable.add(playerPickerTable)
for(nation in GameBasics.Nations.values.filterNot { it.name == "Barbarians" || it.isCityState() }) { for(nation in GameBasics.Nations.values.filterNot { it.name == "Barbarians" || it.isCityState() }) {
val nationTable = NationTable(nation, newGameParameters, skin, stage.width / 3) { updateNationTables() } val nationTable = NationTable(nation, newGameParameters,stage.width/3) {
if (nation.name in newGameParameters.humanNations) {
newGameParameters.humanNations.remove(nation.name)
} else {
newGameParameters.humanNations.add(nation.name)
if (newGameParameters.humanNations.size > newGameParameters.numberOfHumanPlayers)
newGameParameters.humanNations.removeAt(0)
}
updateNationTables()
}
nationTables.add(nationTable) nationTables.add(nationTable)
civPickerTable.add(nationTable).row() civPickerTable.add(nationTable).row()
} }
@ -104,36 +118,3 @@ class TranslatedSelectBox(values : Collection<String>, default:String, skin: Ski
} }
} }
class Player{
var playerType: PlayerType=PlayerType.AI
var chosenCiv = Constants.random
}
class PlayerPickerTable:Table(){
val playerList = ArrayList<Player>()
init {
update()
}
fun update(){
clear()
for(player in playerList)
add(getPlayerTable(player)).row()
add("+".toLabel().setFontSize(24).onClick { playerList.add(Player()); update() })
}
fun getPlayerTable(player:Player): Table {
val table = Table()
val playerTypeTextbutton = TextButton(player.playerType.name, CameraStageBaseScreen.skin)
playerTypeTextbutton.onClick {
if (player.playerType == PlayerType.AI)
player.playerType = PlayerType.Human
else player.playerType = PlayerType.AI
update()
}
table.add(playerTypeTextbutton)
table.add(TextButton("Remove".tr(),CameraStageBaseScreen.skin).onClick { playerList.remove(player); update() })
return table
}
}

View File

@ -0,0 +1,64 @@
package com.unciv.ui.newgamescreen
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
import com.unciv.Constants
import com.unciv.GameParameters
import com.unciv.logic.civilization.PlayerType
import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.CameraStageBaseScreen
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.setFontSize
import com.unciv.ui.utils.toLabel
class PlayerPickerTable: Table(){
val playerList = ArrayList<Player>()
val selectedPlayer: Player?=null
init {
update()
}
fun update(){
clear()
val playerListTable = Table()
for(player in playerList)
playerListTable.add(getPlayerTable(player)).row()
playerListTable.add("+".toLabel().setFontSize(24).onClick { playerList.add(Player()); update() })
add(playerListTable)
if(selectedPlayer!=null){
val nationsTable = Table()
for(nation in GameBasics.Nations.values){
if(selectedPlayer.chosenCiv!=nation.name && playerList.any { it.chosenCiv==nation.name })
continue
nationsTable.add(NationTable(nation, GameParameters(), width / 3) {
selectedPlayer.chosenCiv = nation.name
update()
})
}
}
}
fun getPlayerTable(player: Player): Table {
val table = Table()
val playerTypeTextbutton = TextButton(player.playerType.name, CameraStageBaseScreen.skin)
playerTypeTextbutton.onClick {
if (player.playerType == PlayerType.AI)
player.playerType = PlayerType.Human
else player.playerType = PlayerType.AI
update()
}
table.add(playerTypeTextbutton)
table.add(TextButton("Remove".tr(), CameraStageBaseScreen.skin).onClick { playerList.remove(player); update() })
return table
}
}
class Player{
var playerType: PlayerType=PlayerType.AI
var chosenCiv = Constants.random
}