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.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.unciv.GameParameters
import com.unciv.models.gamebasics.GameBasics
@ -11,40 +10,34 @@ import com.unciv.models.gamebasics.Translations
import com.unciv.models.gamebasics.tr
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()
init {
background= ImageGetter.getBackground(nation.getSecondaryColor())
background = ImageGetter.getBackground(nation.getSecondaryColor())
innerTable.pad(10f)
innerTable.background= ImageGetter.getBackground(nation.getColor())
innerTable.background = ImageGetter.getBackground(nation.getColor())
val titleTable = Table()
titleTable.add(ImageGetter.getNationIndicator(nation,50f)).pad(10f)
titleTable.add(ImageGetter.getNationIndicator(nation, 50f)).pad(10f)
titleTable.add(nation.getLeaderDisplayName().toLabel()
.apply { setFontColor(nation.getSecondaryColor()); setFontSize(24)})
.apply { setFontColor(nation.getSecondaryColor()); setFontSize(24) })
innerTable.add(titleTable).row()
innerTable.add(getUniqueLabel(nation)
.apply { setWrap(true);setFontColor(nation.getSecondaryColor())})
.apply { setWrap(true);setFontColor(nation.getSecondaryColor()) })
.width(width)
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()
}
touchable= Touchable.enabled
touchable = Touchable.enabled
add(innerTable)
}
private fun getUniqueLabel(nation: Nation): Label {
val textList = ArrayList<String>()
if(nation.unique!=null) {
if (nation.unique != null) {
textList += nation.unique!!.tr()
textList += ""
}
@ -57,19 +50,19 @@ class NationTable(val nation: Nation, val newGameParameters: GameParameters, ski
val originalBuildingStatMap = originalBuilding.toHashMap()
for (stat in building.toHashMap())
if (stat.value != originalBuildingStatMap[stat.key])
textList += " "+stat.key.toString().tr() +" "+stat.value.toInt() + " vs " + originalBuildingStatMap[stat.key]!!.toInt()
textList += " " + stat.key.toString().tr() + " " + stat.value.toInt() + " vs " + originalBuildingStatMap[stat.key]!!.toInt()
for(unique in building.uniques.filter { it !in originalBuilding.uniques })
textList += " "+unique.tr()
for (unique in building.uniques.filter { it !in originalBuilding.uniques })
textList += " " + unique.tr()
if (building.maintenance != originalBuilding.maintenance)
textList += " {Maintenance} " + building.maintenance + " vs " + originalBuilding.maintenance
if(building.cost != originalBuilding.cost)
if (building.cost != originalBuilding.cost)
textList += " {Cost} " + building.cost + " vs " + originalBuilding.cost
if(building.cityStrength != originalBuilding.cityStrength)
textList += " {City strength} " + building.cityStrength+ " vs " + originalBuilding.cityStrength
if(building.cityHealth!= originalBuilding.cityHealth)
textList += " {City health} " + building.cityHealth+ " vs " + originalBuilding.cityHealth
textList+=""
if (building.cityStrength != originalBuilding.cityStrength)
textList += " {City strength} " + building.cityStrength + " vs " + originalBuilding.cityStrength
if (building.cityHealth != originalBuilding.cityHealth)
textList += " {City health} " + building.cityHealth + " vs " + originalBuilding.cityHealth
textList += ""
}
for (unit in GameBasics.Units.values)
@ -77,23 +70,23 @@ class NationTable(val nation: Nation, val newGameParameters: GameParameters, ski
val originalUnit = GameBasics.Units[unit.replaces!!]!!
textList += unit.name.tr() + " - {replaces} " + originalUnit.name.tr()
if(unit.cost != originalUnit.cost)
if (unit.cost != originalUnit.cost)
textList += " {Cost} " + unit.cost + " vs " + originalUnit.cost
if (unit.strength != originalUnit.strength)
textList += " {Strength} " + unit.strength + " vs " + originalUnit.strength
if (unit.rangedStrength!= originalUnit.rangedStrength)
textList+= " {Ranged strength} " + unit.rangedStrength+ " vs " + originalUnit.rangedStrength
if (unit.range!= originalUnit.range)
textList+= " {Range} " + unit.range+ " vs " + originalUnit.range
if (unit.movement!= originalUnit.movement)
textList+= " {Movement} " + unit.movement+ " vs " + originalUnit.movement
if(originalUnit.requiredResource!=null && unit.requiredResource==null)
textList+= " "+"[${originalUnit.requiredResource}] not required".tr()
for(unique in unit.uniques.filterNot { it in originalUnit.uniques })
textList += " "+Translations.translateBonusOrPenalty(unique)
for(promotion in unit.promotions.filter { it !in originalUnit.promotions})
textList += " "+promotion.tr()+ " ("+Translations.translateBonusOrPenalty(GameBasics.UnitPromotions[promotion]!!.effect)+")"
textList+=""
if (unit.rangedStrength != originalUnit.rangedStrength)
textList += " {Ranged strength} " + unit.rangedStrength + " vs " + originalUnit.rangedStrength
if (unit.range != originalUnit.range)
textList += " {Range} " + unit.range + " vs " + originalUnit.range
if (unit.movement != originalUnit.movement)
textList += " {Movement} " + unit.movement + " vs " + originalUnit.movement
if (originalUnit.requiredResource != null && unit.requiredResource == null)
textList += " " + "[${originalUnit.requiredResource}] not required".tr()
for (unique in unit.uniques.filterNot { it in originalUnit.uniques })
textList += " " + Translations.translateBonusOrPenalty(unique)
for (promotion in unit.promotions.filter { it !in originalUnit.promotions })
textList += " " + promotion.tr() + " (" + Translations.translateBonusOrPenalty(GameBasics.UnitPromotions[promotion]!!.effect) + ")"
textList += ""
}

View File

@ -1,7 +1,10 @@
package com.unciv.ui.newgamescreen
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.unciv.Constants
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.tr
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.optionstable.PopupTable
import kotlin.concurrent.thread
@ -33,8 +38,17 @@ class NewGameScreen: PickerScreen(){
// mainTable.add(playerPickerTable)
for(nation in GameBasics.Nations.values.filterNot { it.name == "Barbarians" || it.isCityState() }){
val nationTable = NationTable(nation, newGameParameters, skin, stage.width / 3) { updateNationTables() }
for(nation in GameBasics.Nations.values.filterNot { it.name == "Barbarians" || it.isCityState() }) {
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)
civPickerTable.add(nationTable).row()
}
@ -89,51 +103,18 @@ class NewGameScreen: PickerScreen(){
}
}
class TranslatedSelectBox(values : Collection<String>, default:String, skin: Skin) : SelectBox<TranslatedSelectBox.TranslatedString>(skin){
class TranslatedString(val value: String){
class TranslatedSelectBox(values : Collection<String>, default:String, skin: Skin) : SelectBox<TranslatedSelectBox.TranslatedString>(skin) {
class TranslatedString(val value: String) {
val translation = value.tr()
override fun toString()=translation
override fun toString() = translation
}
init {
val array = Array<TranslatedString>()
values.forEach{array.add(TranslatedString(it))}
values.forEach { array.add(TranslatedString(it)) }
items = array
val defaultItem = array.firstOrNull { it.value==default }
selected = if(defaultItem!=null) defaultItem else array.first()
val defaultItem = array.firstOrNull { it.value == default }
selected = if (defaultItem != null) defaultItem else array.first()
}
}
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
}