mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-29 15:01:09 -04:00
More changes towards player-based game starts
This commit is contained in:
parent
93634dae31
commit
9de30bfbce
@ -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,40 +10,34 @@ 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())
|
||||||
innerTable.pad(10f)
|
innerTable.pad(10f)
|
||||||
innerTable.background= ImageGetter.getBackground(nation.getColor())
|
innerTable.background = ImageGetter.getBackground(nation.getColor())
|
||||||
|
|
||||||
val titleTable = Table()
|
val titleTable = Table()
|
||||||
titleTable.add(ImageGetter.getNationIndicator(nation,50f)).pad(10f)
|
titleTable.add(ImageGetter.getNationIndicator(nation, 50f)).pad(10f)
|
||||||
titleTable.add(nation.getLeaderDisplayName().toLabel()
|
titleTable.add(nation.getLeaderDisplayName().toLabel()
|
||||||
.apply { setFontColor(nation.getSecondaryColor()); setFontSize(24)})
|
.apply { setFontColor(nation.getSecondaryColor()); setFontSize(24) })
|
||||||
innerTable.add(titleTable).row()
|
innerTable.add(titleTable).row()
|
||||||
|
|
||||||
innerTable.add(getUniqueLabel(nation)
|
innerTable.add(getUniqueLabel(nation)
|
||||||
.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
|
||||||
add(innerTable)
|
add(innerTable)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getUniqueLabel(nation: Nation): Label {
|
private fun getUniqueLabel(nation: Nation): Label {
|
||||||
val textList = ArrayList<String>()
|
val textList = ArrayList<String>()
|
||||||
|
|
||||||
if(nation.unique!=null) {
|
if (nation.unique != null) {
|
||||||
textList += nation.unique!!.tr()
|
textList += nation.unique!!.tr()
|
||||||
textList += ""
|
textList += ""
|
||||||
}
|
}
|
||||||
@ -57,19 +50,19 @@ class NationTable(val nation: Nation, val newGameParameters: GameParameters, ski
|
|||||||
val originalBuildingStatMap = originalBuilding.toHashMap()
|
val originalBuildingStatMap = originalBuilding.toHashMap()
|
||||||
for (stat in building.toHashMap())
|
for (stat in building.toHashMap())
|
||||||
if (stat.value != originalBuildingStatMap[stat.key])
|
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 })
|
for (unique in building.uniques.filter { it !in originalBuilding.uniques })
|
||||||
textList += " "+unique.tr()
|
textList += " " + unique.tr()
|
||||||
if (building.maintenance != originalBuilding.maintenance)
|
if (building.maintenance != originalBuilding.maintenance)
|
||||||
textList += " {Maintenance} " + building.maintenance + " vs " + 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
|
textList += " {Cost} " + building.cost + " vs " + originalBuilding.cost
|
||||||
if(building.cityStrength != originalBuilding.cityStrength)
|
if (building.cityStrength != originalBuilding.cityStrength)
|
||||||
textList += " {City strength} " + building.cityStrength+ " vs " + originalBuilding.cityStrength
|
textList += " {City strength} " + building.cityStrength + " vs " + originalBuilding.cityStrength
|
||||||
if(building.cityHealth!= originalBuilding.cityHealth)
|
if (building.cityHealth != originalBuilding.cityHealth)
|
||||||
textList += " {City health} " + building.cityHealth+ " vs " + originalBuilding.cityHealth
|
textList += " {City health} " + building.cityHealth + " vs " + originalBuilding.cityHealth
|
||||||
textList+=""
|
textList += ""
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unit in GameBasics.Units.values)
|
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!!]!!
|
val originalUnit = GameBasics.Units[unit.replaces!!]!!
|
||||||
|
|
||||||
textList += unit.name.tr() + " - {replaces} " + originalUnit.name.tr()
|
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
|
textList += " {Cost} " + unit.cost + " vs " + originalUnit.cost
|
||||||
if (unit.strength != originalUnit.strength)
|
if (unit.strength != originalUnit.strength)
|
||||||
textList += " {Strength} " + unit.strength + " vs " + originalUnit.strength
|
textList += " {Strength} " + unit.strength + " vs " + originalUnit.strength
|
||||||
if (unit.rangedStrength!= originalUnit.rangedStrength)
|
if (unit.rangedStrength != originalUnit.rangedStrength)
|
||||||
textList+= " {Ranged strength} " + unit.rangedStrength+ " vs " + originalUnit.rangedStrength
|
textList += " {Ranged strength} " + unit.rangedStrength + " vs " + originalUnit.rangedStrength
|
||||||
if (unit.range!= originalUnit.range)
|
if (unit.range != originalUnit.range)
|
||||||
textList+= " {Range} " + unit.range+ " vs " + originalUnit.range
|
textList += " {Range} " + unit.range + " vs " + originalUnit.range
|
||||||
if (unit.movement!= originalUnit.movement)
|
if (unit.movement != originalUnit.movement)
|
||||||
textList+= " {Movement} " + unit.movement+ " vs " + originalUnit.movement
|
textList += " {Movement} " + unit.movement + " vs " + originalUnit.movement
|
||||||
if(originalUnit.requiredResource!=null && unit.requiredResource==null)
|
if (originalUnit.requiredResource != null && unit.requiredResource == null)
|
||||||
textList+= " "+"[${originalUnit.requiredResource}] not required".tr()
|
textList += " " + "[${originalUnit.requiredResource}] not required".tr()
|
||||||
for(unique in unit.uniques.filterNot { it in originalUnit.uniques })
|
for (unique in unit.uniques.filterNot { it in originalUnit.uniques })
|
||||||
textList += " "+Translations.translateBonusOrPenalty(unique)
|
textList += " " + Translations.translateBonusOrPenalty(unique)
|
||||||
for(promotion in unit.promotions.filter { it !in originalUnit.promotions})
|
for (promotion in unit.promotions.filter { it !in originalUnit.promotions })
|
||||||
textList += " "+promotion.tr()+ " ("+Translations.translateBonusOrPenalty(GameBasics.UnitPromotions[promotion]!!.effect)+")"
|
textList += " " + promotion.tr() + " (" + Translations.translateBonusOrPenalty(GameBasics.UnitPromotions[promotion]!!.effect) + ")"
|
||||||
textList+=""
|
textList += ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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
|
||||||
@ -33,8 +38,17 @@ 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()
|
||||||
}
|
}
|
||||||
@ -89,51 +103,18 @@ class NewGameScreen: PickerScreen(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TranslatedSelectBox(values : Collection<String>, default:String, skin: Skin) : SelectBox<TranslatedSelectBox.TranslatedString>(skin){
|
class TranslatedSelectBox(values : Collection<String>, default:String, skin: Skin) : SelectBox<TranslatedSelectBox.TranslatedString>(skin) {
|
||||||
class TranslatedString(val value: String){
|
class TranslatedString(val value: String) {
|
||||||
val translation = value.tr()
|
val translation = value.tr()
|
||||||
override fun toString()=translation
|
override fun toString() = translation
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val array = Array<TranslatedString>()
|
val array = Array<TranslatedString>()
|
||||||
values.forEach{array.add(TranslatedString(it))}
|
values.forEach { array.add(TranslatedString(it)) }
|
||||||
items = array
|
items = array
|
||||||
val defaultItem = array.firstOrNull { it.value==default }
|
val defaultItem = array.firstOrNull { it.value == default }
|
||||||
selected = if(defaultItem!=null) defaultItem else array.first()
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
64
core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt
Normal file
64
core/src/com/unciv/ui/newgamescreen/PlayerPickerTable.kt
Normal 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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user