mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-09 10:29:02 +07:00
Added New Game screen
This commit is contained in:
parent
9316510a07
commit
39b9a65596
37
core/src/com/unciv/GameStarter.kt
Normal file
37
core/src/com/unciv/GameStarter.kt
Normal file
@ -0,0 +1,37 @@
|
||||
package com.unciv
|
||||
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.ui.utils.getRandom
|
||||
|
||||
class GameStarter(){
|
||||
fun startNewGame(mapRadius: Int, numberOfCivs: Int, civilization: String): GameInfo {
|
||||
val gameInfo = GameInfo()
|
||||
|
||||
gameInfo.tileMap = TileMap(mapRadius)
|
||||
gameInfo.civilizations.add(CivilizationInfo(civilization, Vector2.Zero, gameInfo)) // first one is player civ
|
||||
|
||||
val freeTiles = gameInfo.tileMap.values.toMutableList()
|
||||
freeTiles.removeAll(gameInfo.tileMap.getTilesInDistance(Vector2.Zero,6))
|
||||
|
||||
val barbarianCivilization = CivilizationInfo()
|
||||
gameInfo.civilizations.add(barbarianCivilization)// second is barbarian civ
|
||||
|
||||
for (civname in GameBasics.Civilizations.keys.filterNot { it=="Barbarians" || it==civilization }.take(numberOfCivs)) {
|
||||
val startingLocation = freeTiles.toList().getRandom().position
|
||||
gameInfo.civilizations.add(CivilizationInfo(civname, startingLocation, gameInfo)) // all the rest whatever
|
||||
freeTiles.removeAll(gameInfo.tileMap.getTilesInDistance(startingLocation, 6))
|
||||
}
|
||||
|
||||
barbarianCivilization.civName = "Barbarians"
|
||||
|
||||
gameInfo.setTransients() // needs to be before placeBarbarianUnit because it depends on the tilemap having its gameinfo set
|
||||
|
||||
(1..5).forEach { gameInfo.placeBarbarianUnit(freeTiles.toList().getRandom()) }
|
||||
|
||||
return gameInfo
|
||||
}
|
||||
}
|
@ -2,18 +2,11 @@ package com.unciv
|
||||
|
||||
import com.badlogic.gdx.Game
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.math.Vector2
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import com.unciv.logic.GameInfo
|
||||
import com.unciv.logic.GameSaver
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.logic.map.TileMap
|
||||
import com.unciv.models.gamebasics.*
|
||||
import com.unciv.models.gamebasics.Unit
|
||||
import com.unciv.models.stats.INamed
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.ui.GameSettings
|
||||
import com.unciv.ui.NewGameScreen
|
||||
import com.unciv.ui.utils.getRandom
|
||||
import com.unciv.ui.worldscreen.WorldScreen
|
||||
|
||||
class UnCivGame : Game() {
|
||||
@ -23,8 +16,7 @@ class UnCivGame : Game() {
|
||||
var worldScreen: WorldScreen? = null
|
||||
|
||||
override fun create() {
|
||||
setupGameBasics()
|
||||
|
||||
GameBasics.run { } // just to initialize
|
||||
Current = this
|
||||
if (GameSaver().getSave("Autosave").exists()) {
|
||||
try {
|
||||
@ -43,34 +35,11 @@ class UnCivGame : Game() {
|
||||
}
|
||||
|
||||
fun startNewGame(saveTutorialState:Boolean = false) {
|
||||
val newGame = GameStarter().startNewGame(20, 3, "Babylon")
|
||||
if(saveTutorialState) {
|
||||
val tutorials = gameInfo.tutorial
|
||||
gameInfo = GameInfo()
|
||||
gameInfo.tutorial = tutorials
|
||||
newGame.tutorial = gameInfo.tutorial
|
||||
}
|
||||
else gameInfo = GameInfo()
|
||||
|
||||
gameInfo.tileMap = TileMap(20)
|
||||
gameInfo.civilizations.add(CivilizationInfo("Babylon", Vector2.Zero, gameInfo)) // first one is player civ
|
||||
|
||||
val freeTiles = gameInfo.tileMap.values.toMutableList()
|
||||
freeTiles.removeAll(gameInfo.tileMap.getTilesInDistance(Vector2.Zero,6))
|
||||
|
||||
val barbarianCivilization = CivilizationInfo()
|
||||
gameInfo.civilizations.add(barbarianCivilization)// second is barbarian civ
|
||||
|
||||
for (civname in listOf("Greece","China","Egypt")) {
|
||||
val startingLocation = freeTiles.toList().getRandom().position
|
||||
gameInfo.civilizations.add(CivilizationInfo(civname, startingLocation, gameInfo)) // all the rest whatever
|
||||
freeTiles.removeAll(gameInfo.tileMap.getTilesInDistance(startingLocation, 6))
|
||||
}
|
||||
|
||||
barbarianCivilization.civName = "Barbarians"
|
||||
|
||||
gameInfo.setTransients() // needs to be before placeBarbarianUnit because it depends on the tilemap having its gameinfo set
|
||||
|
||||
(1..5).forEach { gameInfo.placeBarbarianUnit(freeTiles.toList().getRandom()) }
|
||||
|
||||
gameInfo = newGame
|
||||
|
||||
worldScreen = WorldScreen()
|
||||
setWorldScreen()
|
||||
@ -83,59 +52,6 @@ class UnCivGame : Game() {
|
||||
Gdx.input.inputProcessor = worldScreen!!.stage
|
||||
}
|
||||
|
||||
private fun <T> getFromJson(tClass: Class<T>, name: String): T {
|
||||
val jsonText = Gdx.files.internal("jsons/$name.json").readString()
|
||||
return Json().fromJson(tClass, jsonText)
|
||||
}
|
||||
|
||||
private fun <T : INamed> createHashmap(items: Array<T>): LinkedHashMap<String, T> {
|
||||
val hashMap = LinkedHashMap<String, T>()
|
||||
for (item in items)
|
||||
hashMap[item.name] = item
|
||||
return hashMap
|
||||
}
|
||||
|
||||
private fun setupGameBasics() {
|
||||
GameBasics.Buildings += createHashmap(getFromJson(Array<Building>::class.java, "Buildings"))
|
||||
GameBasics.Terrains += createHashmap(getFromJson(Array<Terrain>::class.java, "Terrains"))
|
||||
GameBasics.TileResources += createHashmap(getFromJson(Array<TileResource>::class.java, "TileResources"))
|
||||
GameBasics.TileImprovements += createHashmap(getFromJson(Array<TileImprovement>::class.java, "TileImprovements"))
|
||||
GameBasics.Helps += createHashmap(getFromJson(Array<BasicHelp>::class.java, "BasicHelp"))
|
||||
GameBasics.Units += createHashmap(getFromJson(Array<Unit>::class.java, "Units"))
|
||||
GameBasics.PolicyBranches += createHashmap(getFromJson(Array<PolicyBranch>::class.java, "Policies"))
|
||||
GameBasics.Civilizations += createHashmap(getFromJson(Array<Civilization>::class.java, "Civilizations"))
|
||||
|
||||
// ...Yes. Total Voodoo. I wish I didn't have to do this.
|
||||
val x = LinkedHashMap<String,com.badlogic.gdx.utils.Array<com.badlogic.gdx.utils.Array<String>>>()
|
||||
val tutorials = getFromJson(x.javaClass, "Tutorials")
|
||||
for (tut in tutorials)
|
||||
GameBasics.Tutorials[tut.key] = tut.value.map{it.joinToString("\r\n")}
|
||||
|
||||
val techColumns = getFromJson(Array<TechColumn>::class.java, "Techs")
|
||||
for (techColumn in techColumns) {
|
||||
for (tech in techColumn.techs) {
|
||||
tech.cost = techColumn.techCost
|
||||
tech.column = techColumn
|
||||
GameBasics.Technologies[tech.name] = tech
|
||||
}
|
||||
}
|
||||
for (building in GameBasics.Buildings.values) {
|
||||
if (building.requiredTech == null) continue
|
||||
val column = building.getRequiredTech().column
|
||||
if (building.cost == 0)
|
||||
building.cost = if (building.isWonder) column!!.wonderCost else column!!.buildingCost
|
||||
}
|
||||
|
||||
for (branch in GameBasics.PolicyBranches.values) {
|
||||
branch.requires = ArrayList()
|
||||
branch.branch = branch.name
|
||||
for (policy in branch.policies) {
|
||||
policy.branch = branch.name
|
||||
if (policy.requires == null) policy.requires = arrayListOf(branch.name)
|
||||
}
|
||||
branch.policies.last().name = branch.name + " Complete"
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
lateinit var Current: UnCivGame
|
||||
|
@ -34,7 +34,6 @@ class GameInfo {
|
||||
civInfo.endTurn()
|
||||
}
|
||||
|
||||
|
||||
// We need to update the stats after ALL the cities are done updating because
|
||||
// maybe one of them has a wonder that affects the stats of all the rest of the cities
|
||||
|
||||
|
@ -45,10 +45,12 @@ class PopulationManager {
|
||||
// starvation!
|
||||
{
|
||||
population--
|
||||
val lowestRankedWorkedTile = cityInfo.workedTiles
|
||||
.map{cityInfo.tileMap[it]}
|
||||
.minBy { Automation().rankTile(it,cityInfo.civInfo) }!!
|
||||
cityInfo.workedTiles.remove(lowestRankedWorkedTile.position)
|
||||
if(cityInfo.workedTiles.size>population) {
|
||||
val lowestRankedWorkedTile = cityInfo.workedTiles
|
||||
.map { cityInfo.tileMap[it] }
|
||||
.minBy { Automation().rankTile(it, cityInfo.civInfo) }!!
|
||||
cityInfo.workedTiles.remove(lowestRankedWorkedTile.position)
|
||||
}
|
||||
foodStored = 0
|
||||
cityInfo.civInfo.addNotification(cityInfo.name + " is starving!", cityInfo.location)
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
package com.unciv.models.gamebasics
|
||||
|
||||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import com.unciv.models.stats.INamed
|
||||
|
||||
object GameBasics {
|
||||
val Buildings = LinkedHashMap<String, Building>()
|
||||
val Terrains = LinkedHashMap<String, Terrain>()
|
||||
@ -11,4 +15,58 @@ object GameBasics {
|
||||
val Civilizations = LinkedHashMap<String, Civilization>()
|
||||
val PolicyBranches = LinkedHashMap<String, PolicyBranch>()
|
||||
val Tutorials = LinkedHashMap<String, List<String>>()
|
||||
|
||||
private fun <T> getFromJson(tClass: Class<T>, name: String): T {
|
||||
val jsonText = Gdx.files.internal("jsons/$name.json").readString()
|
||||
return Json().fromJson(tClass, jsonText)
|
||||
}
|
||||
|
||||
private fun <T : INamed> createHashmap(items: Array<T>): LinkedHashMap<String, T> {
|
||||
val hashMap = LinkedHashMap<String, T>()
|
||||
for (item in items)
|
||||
hashMap[item.name] = item
|
||||
return hashMap
|
||||
}
|
||||
|
||||
init {
|
||||
Buildings += createHashmap(getFromJson(Array<Building>::class.java, "Buildings"))
|
||||
Terrains += createHashmap(getFromJson(Array<Terrain>::class.java, "Terrains"))
|
||||
TileResources += createHashmap(getFromJson(Array<TileResource>::class.java, "TileResources"))
|
||||
TileImprovements += createHashmap(getFromJson(Array<TileImprovement>::class.java, "TileImprovements"))
|
||||
Helps += createHashmap(getFromJson(Array<BasicHelp>::class.java, "BasicHelp"))
|
||||
Units += createHashmap(getFromJson(Array<Unit>::class.java, "Units"))
|
||||
PolicyBranches += createHashmap(getFromJson(Array<PolicyBranch>::class.java, "Policies"))
|
||||
Civilizations += createHashmap(getFromJson(Array<Civilization>::class.java, "Civilizations"))
|
||||
|
||||
// ...Yes. Total Voodoo. I wish I didn't have to do this.
|
||||
val x = LinkedHashMap<String,com.badlogic.gdx.utils.Array<com.badlogic.gdx.utils.Array<String>>>()
|
||||
val tutorials = getFromJson(x.javaClass, "Tutorials")
|
||||
for (tut in tutorials)
|
||||
Tutorials[tut.key] = tut.value.map{it.joinToString("\r\n")}
|
||||
|
||||
val techColumns = getFromJson(Array<TechColumn>::class.java, "Techs")
|
||||
for (techColumn in techColumns) {
|
||||
for (tech in techColumn.techs) {
|
||||
tech.cost = techColumn.techCost
|
||||
tech.column = techColumn
|
||||
Technologies[tech.name] = tech
|
||||
}
|
||||
}
|
||||
for (building in Buildings.values) {
|
||||
if (building.requiredTech == null) continue
|
||||
val column = building.getRequiredTech().column
|
||||
if (building.cost == 0)
|
||||
building.cost = if (building.isWonder) column!!.wonderCost else column!!.buildingCost
|
||||
}
|
||||
|
||||
for (branch in PolicyBranches.values) {
|
||||
branch.requires = ArrayList()
|
||||
branch.branch = branch.name
|
||||
for (policy in branch.policies) {
|
||||
policy.branch = branch.name
|
||||
if (policy.requires == null) policy.requires = arrayListOf(branch.name)
|
||||
}
|
||||
branch.policies.last().name = branch.name + " Complete"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,10 @@
|
||||
package com.unciv.ui
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.SelectBox
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.badlogic.gdx.utils.Array
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.logic.GameSaver
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.pickerscreens.PickerScreen
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
@ -56,36 +53,3 @@ class LoadScreen : PickerScreen() {
|
||||
|
||||
}
|
||||
|
||||
class NewGameScreen:CameraStageBaseScreen(){
|
||||
init {
|
||||
val table = Table()
|
||||
table.skin=skin
|
||||
|
||||
table.add("Civilization: ")
|
||||
val civSelectBox = SelectBox<String>(skin)
|
||||
val civArray = Array<String>()
|
||||
GameBasics.Civilizations.keys.filterNot { it=="Barbarians" }.forEach{civArray.add(it)}
|
||||
civSelectBox.setItems(civArray)
|
||||
civSelectBox.selected = civSelectBox.items.first()
|
||||
table.add(civSelectBox).pad(10f).row()
|
||||
|
||||
table.add("World size: ")
|
||||
val worldSizeToRadius=LinkedHashMap<String,Int>()
|
||||
worldSizeToRadius.put("Small",10)
|
||||
worldSizeToRadius.put("Medium",20)
|
||||
worldSizeToRadius.put("Large",30)
|
||||
val worldSizeSelectBox = SelectBox<String>(skin)
|
||||
val worldSizeArray = Array<String>()
|
||||
worldSizeToRadius.keys.forEach{worldSizeArray.add(it)}
|
||||
worldSizeSelectBox.setItems(worldSizeArray)
|
||||
worldSizeSelectBox.selected = "Medium"
|
||||
table.add(worldSizeSelectBox)
|
||||
|
||||
val createButton = TextButton("Start game!",skin)
|
||||
createButton.addClickListener { }
|
||||
|
||||
table.setFillParent(true)
|
||||
table.pack()
|
||||
stage.addActor(table)
|
||||
}
|
||||
}
|
2
core/src/com/unciv/ui/NewGameScreen.kt
Normal file
2
core/src/com/unciv/ui/NewGameScreen.kt
Normal file
@ -0,0 +1,2 @@
|
||||
package com.unciv.ui
|
||||
|
@ -4,10 +4,7 @@ import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton
|
||||
import com.unciv.logic.civilization.CivilizationInfo
|
||||
import com.unciv.ui.CivilopediaScreen
|
||||
import com.unciv.ui.LoadScreen
|
||||
import com.unciv.ui.SaveScreen
|
||||
import com.unciv.ui.VictoryScreen
|
||||
import com.unciv.ui.*
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.pickerscreens.PolicyPickerScreen
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
@ -48,7 +45,7 @@ class WorldScreenOptionsTable internal constructor(worldScreen: WorldScreen, pri
|
||||
add(saveGameButton ).row()
|
||||
|
||||
val startNewGameButton = TextButton("Start new game", CameraStageBaseScreen.skin).apply { color=ImageGetter.getBlue() }
|
||||
startNewGameButton.addClickListener { worldScreen.game.startNewGame(true) }
|
||||
startNewGameButton.addClickListener { worldScreen.game.screen = NewGameScreen() }
|
||||
add(startNewGameButton).row()
|
||||
|
||||
val openVictoryScreen = TextButton("Victory status", CameraStageBaseScreen.skin).apply { color=ImageGetter.getBlue() }
|
||||
|
Loading…
Reference in New Issue
Block a user