Resolved #396 - save game start parameters and use for subsequent games

Later, we could use this info to display to the user in the load game screen
Solved #394 - couldn't scroll map far on edges, some tiles were hard to get to
This commit is contained in:
Yair Morgenstern
2019-01-04 10:59:47 +02:00
parent f8b13095db
commit 2f5b6e7be5
7 changed files with 112 additions and 112 deletions

View File

@ -1,20 +0,0 @@
@ECHO OFF
ECHO ##############################################################
ECHO # Crush all PNG from Images/* and store them in Optimized/* #
ECHO ##############################################################
ECHO Files to crush:
for /D %%d in (.\*) do ( for /F "tokens=*" %%x IN ('DIR %%d\*.png /B') DO ECHO - %%x )
PAUSE
for /D %%d in (.\*) do (
for /F "tokens=*" %%x IN ('DIR %%d\*.png /B') DO (
ECHO Crushing: %%d\%%x
pngcrush -brute "%%d\%%x" temp.png
if not exist "Optimized\%%d" mkdir "Optimized\%%d"
MOVE /Y temp.png "Optimized\%%d\%%x"
)
)
PAUSE

View File

@ -4,17 +4,27 @@ import com.badlogic.gdx.math.Vector2
import com.unciv.logic.GameInfo
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.PlayerType
import com.unciv.logic.map.MapType
import com.unciv.logic.map.TileInfo
import com.unciv.logic.map.TileMap
import com.unciv.models.gamebasics.GameBasics
import com.unciv.ui.NewGameScreen
import com.unciv.ui.utils.getRandom
import java.util.*
class GameParameters{
var difficulty="Prince"
var nation="Babylon"
var mapRadius=20
var numberOfEnemies=3
var mapType= MapType.Perlin
}
class GameStarter{
fun startNewGame(newGameParameters: NewGameScreen.NewGameParameters): GameInfo {
fun startNewGame(newGameParameters: GameParameters): GameInfo {
val gameInfo = GameInfo()
gameInfo.gameParameters = newGameParameters
gameInfo.tileMap = TileMap(newGameParameters.mapRadius, newGameParameters.mapType)
gameInfo.tileMap.gameInfo = gameInfo // need to set this transient before placing units in the map
val startingLocations = getStartingLocations(newGameParameters.numberOfEnemies+1,gameInfo.tileMap)

View File

@ -6,7 +6,6 @@ import com.unciv.logic.GameInfo
import com.unciv.logic.GameSaver
import com.unciv.models.gamebasics.GameBasics
import com.unciv.ui.LanguagePickerScreen
import com.unciv.ui.NewGameScreen
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.worldscreen.WorldScreen
@ -37,8 +36,7 @@ class UnCivGame : Game() {
startNewGame()
}
}
//startNewGame() //
else screen= LanguagePickerScreen() // disabled because of people's negative reviews =(
else screen= LanguagePickerScreen()
}
fun loadGame(gameInfo:GameInfo){
@ -52,7 +50,7 @@ class UnCivGame : Game() {
}
fun startNewGame() {
val newGame = GameStarter().startNewGame(NewGameScreen.NewGameParameters().apply { difficulty="Chieftain" })
val newGame = GameStarter().startNewGame(GameParameters().apply { difficulty="Chieftain" })
gameInfo = newGame
worldScreen = WorldScreen()

View File

@ -1,9 +1,9 @@
package com.unciv.logic
import com.badlogic.gdx.graphics.Color
import com.unciv.GameParameters
import com.unciv.logic.automation.NextTurnAutomation
import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.logic.civilization.Notification
import com.unciv.logic.civilization.PlayerType
import com.unciv.logic.map.TileInfo
import com.unciv.logic.map.TileMap
@ -11,10 +11,10 @@ import com.unciv.models.gamebasics.GameBasics
import com.unciv.ui.utils.getRandom
class GameInfo {
var notifications = mutableListOf<Notification>()
var civilizations = mutableListOf<CivilizationInfo>()
var difficulty="Chieftain" // difficulty is game-wide, think what would happen if 2 human players could play on diffferent difficulties?
var tileMap: TileMap = TileMap()
var gameParameters=GameParameters()
var turns = 0
var oneMoreTurnMode=false
@ -25,6 +25,7 @@ class GameInfo {
toReturn.civilizations.addAll(civilizations.map { it.clone() })
toReturn.turns = turns
toReturn.difficulty=difficulty
toReturn.gameParameters = gameParameters
return toReturn
}

View File

@ -0,0 +1,80 @@
package com.unciv.ui
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
import com.unciv.models.gamebasics.Nation
import com.unciv.models.gamebasics.Translations
import com.unciv.models.gamebasics.tr
import com.unciv.ui.utils.ImageGetter
import com.unciv.ui.utils.onClick
import com.unciv.ui.utils.setFontColor
class NationTable(val nation: Nation, val newGameParameters: GameParameters, skin: Skin, width:Float, onClick:()->Unit): Table(skin){
init {
pad(10f)
background= ImageGetter.getBackground(nation.getColor().apply { a = 0.5f })
add(Label(nation.name.tr(), skin).apply { setFontColor(nation.getSecondaryColor())}).row()
add(Label(getUniqueLabel(nation), skin).apply { setWrap(true);setFontColor(nation.getSecondaryColor())}).width(width)
onClick { newGameParameters.nation=nation.name; onClick() }
touchable= Touchable.enabled
update()
}
private fun getUniqueLabel(nation: Nation): String {
val textList = ArrayList<String>()
if(nation.unique!=null) {
textList += nation.unique!!.tr()
textList += ""
}
for (building in GameBasics.Buildings.values)
if (building.uniqueTo == nation.name) {
val originalBuilding = GameBasics.Buildings[building.replaces!!]!!
textList += building.name.tr() + " - {replaces} " + originalBuilding.name.tr()
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()
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
textList+=""
}
for (unit in GameBasics.Units.values)
if (unit.uniqueTo == nation.name) {
val originalUnit = GameBasics.Units[unit.replaces!!]!!
textList += unit.name.tr() + " - {replaces} " + originalUnit.name.tr()
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
val newUniques = unit.uniques.filterNot { it in originalUnit.uniques }
if(newUniques.isNotEmpty())
textList+=" {Uniques}: "+newUniques.joinToString{ Translations.translateBonusOrPenalty(it) }
textList+=""
}
return textList.joinToString("\n").tr().trim()
}
fun update(){
val color = nation.getColor()
if(newGameParameters.nation!=nation.name) color.a=0.5f
background= ImageGetter.getBackground(color)
}
}

View File

@ -2,99 +2,28 @@ package com.unciv.ui
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.scenes.scene2d.Actor
import com.badlogic.gdx.scenes.scene2d.Touchable
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.scenes.scene2d.utils.ChangeListener
import com.badlogic.gdx.utils.Array
import com.unciv.GameStarter
import com.unciv.UnCivGame
import com.unciv.logic.GameInfo
import com.unciv.logic.map.MapType
import com.unciv.models.gamebasics.GameBasics
import com.unciv.models.gamebasics.Nation
import com.unciv.models.gamebasics.Translations
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 kotlin.concurrent.thread
class NewGameScreen: PickerScreen(){
class NewGameParameters{
var difficulty="Prince"
var nation="Babylon"
var mapRadius=20
var numberOfEnemies=3
var mapType=MapType.Perlin
}
val newGameParameters=NewGameParameters()
class NationTable(val nation:Nation,val newGameParameters: NewGameParameters, skin:Skin, width:Float, onClick:()->Unit):Table(skin){
init {
pad(10f)
background=ImageGetter.getBackground(nation.getColor().apply { a=0.5f })
add(Label(nation.name.tr(), skin).apply { setFontColor(nation.getSecondaryColor())}).row()
add(Label(getUniqueLabel(nation), skin).apply { setWrap(true);setFontColor(nation.getSecondaryColor())}).width(width)
onClick { newGameParameters.nation=nation.name; onClick() }
touchable=Touchable.enabled
update()
}
private fun getUniqueLabel(nation: Nation): String {
val textList = ArrayList<String>()
if(nation.unique!=null) {
textList += nation.unique!!.tr()
textList += ""
}
for (building in GameBasics.Buildings.values)
if (building.uniqueTo == nation.name) {
val originalBuilding = GameBasics.Buildings[building.replaces!!]!!
textList += building.name.tr() + " - {replaces} " + originalBuilding.name.tr()
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()
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
textList+=""
}
for (unit in GameBasics.Units.values)
if (unit.uniqueTo == nation.name) {
val originalUnit = GameBasics.Units[unit.replaces!!]!!
textList += unit.name.tr() + " - {replaces} " + originalUnit.name.tr()
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
val newUniques = unit.uniques.filterNot { it in originalUnit.uniques }
if(newUniques.isNotEmpty())
textList+=" {Uniques}: "+newUniques.joinToString{ Translations.translateBonusOrPenalty(it)}
textList+=""
}
return textList.joinToString("\n").tr().trim()
}
fun update(){
val color = nation.getColor()
if(newGameParameters.nation!=nation.name) color.a=0.5f
background=ImageGetter.getBackground(color)
}
}
val newGameParameters= UnCivGame.Current.gameInfo.gameParameters
val nationTables = ArrayList<NationTable>()
@ -126,7 +55,7 @@ class NewGameScreen: PickerScreen(){
for (type in MapType.values()) {
mapTypes[type.toString()] = type
}
val mapTypeSelectBox = TranslatedSelectBox(mapTypes.keys, "Perlin", skin)
val mapTypeSelectBox = TranslatedSelectBox(mapTypes.keys, newGameParameters.mapType.toString(), skin)
mapTypeSelectBox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
newGameParameters.mapType = mapTypes[mapTypeSelectBox.selected.value]!!
@ -141,7 +70,9 @@ class NewGameScreen: PickerScreen(){
worldSizeToRadius["Medium"] = 20
worldSizeToRadius["Large"] = 30
worldSizeToRadius["Huge"] = 40
val worldSizeSelectBox = TranslatedSelectBox(worldSizeToRadius.keys, "Medium", skin)
val currentWorldSizeName = worldSizeToRadius.entries.first { it.value==newGameParameters.mapRadius }.key
val worldSizeSelectBox = TranslatedSelectBox(worldSizeToRadius.keys, currentWorldSizeName, skin)
worldSizeSelectBox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
@ -167,7 +98,7 @@ class NewGameScreen: PickerScreen(){
newGameOptionsTable.add("{Difficulty}:".tr())
val difficultySelectBox = TranslatedSelectBox(GameBasics.Difficulties.keys, newGameParameters.difficulty, skin)
val difficultySelectBox = TranslatedSelectBox(GameBasics.Difficulties.keys, newGameParameters.difficulty , skin)
difficultySelectBox.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) {
newGameParameters.difficulty = difficultySelectBox.selected.value

View File

@ -32,7 +32,7 @@ class TileMapHolder(internal val worldScreen: WorldScreen, internal val tileMap:
internal fun addTiles() {
val allTiles = Group()
val groupPadding = 300f // This is so that no tile will be stuck "on the side" and be unreachable or difficult to reach
val groupPadding = 600f // This is so that no tile will be stuck "on the side" and be unreachable or difficult to reach
var topX = 0f
var topY = 0f