Added display options, to show/hide worked tiles and resources/tile improvements
This commit is contained in:
parent
145c908af2
commit
431c5449f3
11 changed files with 139 additions and 83 deletions
|
@ -6,14 +6,13 @@ import com.unciv.logic.GameInfo
|
|||
import com.unciv.logic.GameSaver
|
||||
import com.unciv.models.gamebasics.GameBasics
|
||||
import com.unciv.ui.GameSettings
|
||||
import com.unciv.ui.NewGameScreen
|
||||
import com.unciv.ui.worldscreen.WorldScreen
|
||||
|
||||
class UnCivGame : Game() {
|
||||
var gameInfo: GameInfo = GameInfo()
|
||||
var settings = GameSettings()
|
||||
|
||||
var worldScreen: WorldScreen? = null
|
||||
lateinit var worldScreen: WorldScreen
|
||||
|
||||
override fun create() {
|
||||
GameBasics.run { } // just to initialize
|
||||
|
@ -48,8 +47,8 @@ class UnCivGame : Game() {
|
|||
|
||||
fun setWorldScreen() {
|
||||
setScreen(worldScreen)
|
||||
worldScreen!!.update()
|
||||
Gdx.input.inputProcessor = worldScreen!!.stage
|
||||
worldScreen.update()
|
||||
Gdx.input.inputProcessor = worldScreen.stage
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.unciv.logic
|
|||
import com.badlogic.gdx.Gdx
|
||||
import com.badlogic.gdx.files.FileHandle
|
||||
import com.badlogic.gdx.utils.Json
|
||||
import com.unciv.ui.GameSettings
|
||||
|
||||
class GameSaver {
|
||||
private val saveFilesFolder = "SaveFiles"
|
||||
|
@ -28,4 +29,12 @@ class GameSaver {
|
|||
fun deleteSave(GameName: String){
|
||||
getSave(GameName).delete()
|
||||
}
|
||||
|
||||
fun getGeneralSettings():GameSettings{
|
||||
return Json().fromJson(GameSettings::class.java, Gdx.files.local("GameSettings.json"))
|
||||
}
|
||||
|
||||
fun setGeneralSettings(gameSettings: GameSettings){
|
||||
Gdx.files.local("GameSettings.json").writeString(Json().toJson(gameSettings), false)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,22 @@
|
|||
package com.unciv.ui
|
||||
|
||||
class GameSettings {
|
||||
var labelScale = 1.5f
|
||||
var buttonScale = 0.9f
|
||||
var tilesZoom = 1f
|
||||
var cityTilesX = 0f
|
||||
var cityTilesY = 0f
|
||||
internal var worldScrollX = 0f
|
||||
internal var worldScrollY = 0f
|
||||
class GameSettings : LinkedHashMap<String, String>() {
|
||||
|
||||
var showWorkedTiles:Boolean
|
||||
get() {
|
||||
if(this.containsKey("ShowWorkedTiles")) return get("ShowWorkedTiles")!!.toBoolean()
|
||||
else return true
|
||||
}
|
||||
set(value) {
|
||||
this["ShowWorkedTiles"]=value.toString()
|
||||
}
|
||||
|
||||
var showResourcesAndImprovements:Boolean
|
||||
get() {
|
||||
if(this.containsKey("ShowResourcesAndImprovements")) return get("ShowResourcesAndImprovements")!!.toBoolean()
|
||||
else return true
|
||||
}
|
||||
set(value) {
|
||||
this["ShowResourcesAndImprovements"]=value.toString()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
|||
private var tileGroups = ArrayList<CityTileGroup>()
|
||||
|
||||
init {
|
||||
Label("", CameraStageBaseScreen.skin).style.font.data.setScale(game.settings.labelScale)
|
||||
Label("", CameraStageBaseScreen.skin).style.font.data.setScale(1.5f)
|
||||
|
||||
addTiles()
|
||||
stage.addActor(tileTable)
|
||||
|
@ -169,7 +169,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
|||
goToWorldButton.clearListeners()
|
||||
goToWorldButton.addClickListener {
|
||||
game.setWorldScreen()
|
||||
game.worldScreen!!.tileMapHolder.setCenterPosition(city.location)
|
||||
game.worldScreen.tileMapHolder.setCenterPosition(city.location)
|
||||
dispose()
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
|||
|
||||
val scrollPane = ScrollPane(allTiles)
|
||||
scrollPane.setFillParent(true)
|
||||
scrollPane.setPosition(game.settings.cityTilesX, game.settings.cityTilesY)
|
||||
scrollPane.setPosition(cityTilesX, cityTilesY)
|
||||
scrollPane.setOrigin(stage.width / 2, stage.height / 2)
|
||||
scrollPane.addListener(object : ActorGestureListener() {
|
||||
var lastScale = 1f
|
||||
|
@ -231,8 +231,8 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
|||
|
||||
override fun pan(event: InputEvent?, x: Float, y: Float, deltaX: Float, deltaY: Float) {
|
||||
scrollPane.moveBy(deltaX * scrollPane.scaleX, deltaY * scrollPane.scaleX)
|
||||
game.settings.cityTilesX = scrollPane.x
|
||||
game.settings.cityTilesY = scrollPane.y
|
||||
cityTilesX = scrollPane.x
|
||||
cityTilesY = scrollPane.y
|
||||
}
|
||||
})
|
||||
stage.addActor(scrollPane)
|
||||
|
@ -264,5 +264,9 @@ class CityScreen(internal val city: CityInfo) : CameraStageBaseScreen() {
|
|||
tileTable.setPosition(stage.width - 10f - tileTable.width, 10f)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@Transient var cityTilesX = 0f
|
||||
@Transient var cityTilesY = 0f
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.util.*
|
|||
class CityStatsTable(val cityScreen: CityScreen) : Table(){
|
||||
fun update() {
|
||||
val city = cityScreen.city
|
||||
val buttonScale = cityScreen.game.settings.buttonScale
|
||||
val buttonScale = 0.9f
|
||||
val stats = city.cityStats.currentCityStats
|
||||
pad(20f)
|
||||
columnDefaults(0).padRight(10f)
|
||||
|
|
|
@ -29,7 +29,7 @@ open class PickerScreen : CameraStageBaseScreen() {
|
|||
|
||||
descriptionLabel = Label("", CameraStageBaseScreen.skin)
|
||||
descriptionLabel.setWrap(true)
|
||||
descriptionLabel.setFontScale(game.settings.labelScale)
|
||||
descriptionLabel.setFontScale(1.5f)
|
||||
val labelScroll = ScrollPane(descriptionLabel)
|
||||
bottomTable.add(labelScroll).pad(5f).width(stage.width / 2)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Color
|
|||
import com.badlogic.gdx.scenes.scene2d.Group
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image
|
||||
import com.badlogic.gdx.utils.Align
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.logic.HexMath
|
||||
import com.unciv.logic.map.MapUnit
|
||||
import com.unciv.logic.map.RoadStatus
|
||||
|
@ -25,7 +26,6 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||
|
||||
protected var resourceImage: Image? = null
|
||||
protected var improvementImage: Image? =null
|
||||
private var improvementType: String? = null
|
||||
var populationImage: Image? = null
|
||||
private val roadImages = HashMap<String, Image>()
|
||||
private val borderImages = ArrayList<Image>()
|
||||
|
@ -78,8 +78,10 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||
}
|
||||
|
||||
protected fun removePopulationIcon() {
|
||||
populationImage!!.remove()
|
||||
populationImage = null
|
||||
if(populationImage!=null) {
|
||||
populationImage!!.remove()
|
||||
populationImage = null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -97,6 +99,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||
updateResourceImage(isViewable)
|
||||
updateImprovementImage(isViewable)
|
||||
|
||||
|
||||
civilianUnitImage = newUnitImage(tileInfo.civilianUnit,civilianUnitImage,isViewable,-20f)
|
||||
militaryUnitImage = newUnitImage(tileInfo.militaryUnit,militaryUnitImage,isViewable,20f)
|
||||
|
||||
|
@ -188,7 +191,7 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||
addActor(terrainFeatureImage)
|
||||
terrainFeatureImage!!.run {
|
||||
setSize(30f, 30f)
|
||||
setColor(1f, 1f, 1f, 0.5f)
|
||||
//setColor(1f, 1f, 1f, 0.5f)
|
||||
center(this@TileGroup)
|
||||
}
|
||||
}
|
||||
|
@ -200,7 +203,12 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||
}
|
||||
|
||||
private fun updateImprovementImage(viewable: Boolean) {
|
||||
if (tileInfo.improvement != null && tileInfo.improvement != improvementType) {
|
||||
if(improvementImage!=null){
|
||||
improvementImage!!.remove()
|
||||
improvementImage=null
|
||||
}
|
||||
|
||||
if (tileInfo.improvement != null && UnCivGame.Current.settings.showResourcesAndImprovements) {
|
||||
improvementImage = ImageGetter.getImprovementIcon(tileInfo.improvement!!)
|
||||
addActor(improvementImage)
|
||||
improvementImage!!.run {
|
||||
|
@ -209,7 +217,6 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||
this.x -= 22 // left
|
||||
this.y -= 10 // bottom
|
||||
}
|
||||
improvementType = tileInfo.improvement
|
||||
}
|
||||
if(improvementImage!=null){
|
||||
if(viewable) improvementImage!!.color= Color.WHITE
|
||||
|
@ -218,7 +225,13 @@ open class TileGroup(var tileInfo: TileInfo) : Group() {
|
|||
}
|
||||
|
||||
private fun updateResourceImage(viewable: Boolean) {
|
||||
if (tileInfo.hasViewableResource(tileInfo.tileMap.gameInfo.getPlayerCivilization()) && resourceImage == null) { // Need to add the resource image!
|
||||
if(resourceImage!=null){
|
||||
resourceImage!!.remove()
|
||||
resourceImage=null
|
||||
}
|
||||
|
||||
if(UnCivGame.Current.settings.showResourcesAndImprovements
|
||||
&& tileInfo.hasViewableResource(tileInfo.tileMap.gameInfo.getPlayerCivilization())) { // Need to add the resource image!
|
||||
val fileName = "ResourceIcons/" + tileInfo.resource + "_(Civ5).png"
|
||||
resourceImage = ImageGetter.getImage(fileName)
|
||||
resourceImage!!.setSize(20f, 20f)
|
||||
|
|
|
@ -36,7 +36,10 @@ class WorldTileGroup(tileInfo: TileInfo) : TileGroup(tileInfo) {
|
|||
override fun update(isViewable: Boolean) {
|
||||
|
||||
val city = tileInfo.getCity()
|
||||
if (isViewable && tileInfo.isWorked() && city!!.civInfo.isPlayerCivilization() && populationImage == null)
|
||||
|
||||
removePopulationIcon()
|
||||
if (isViewable && tileInfo.isWorked() && UnCivGame.Current.settings.showWorkedTiles
|
||||
&& city!!.civInfo.isPlayerCivilization())
|
||||
addPopulationIcon()
|
||||
|
||||
if (tileInfo.tileMap.gameInfo.getPlayerCivilization().exploredTiles.contains(tileInfo.position)
|
||||
|
|
|
@ -17,7 +17,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||
|
||||
val tileMapHolder: TileMapHolder = TileMapHolder(this, gameInfo.tileMap, civInfo)
|
||||
|
||||
internal var buttonScale = game.settings.buttonScale
|
||||
internal var buttonScale = 0.9f
|
||||
private val topBar = WorldScreenTopBar(this)
|
||||
val bottomBar = WorldScreenBottomBar(this)
|
||||
val unitActionsTable = UnitActionsTable(this)
|
||||
|
@ -25,7 +25,6 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||
private val techButton = TextButton("", CameraStageBaseScreen.skin)
|
||||
private val nextTurnButton = createNextTurnButton()
|
||||
|
||||
internal val optionsTable: WorldScreenOptionsTable
|
||||
private val notificationsScroll: NotificationsScroll
|
||||
|
||||
init {
|
||||
|
@ -36,8 +35,7 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||
topBar.y - nextTurnButton.height - 10f)
|
||||
notificationsScroll = NotificationsScroll(gameInfo.notifications, this)
|
||||
notificationsScroll.width = stage.width/3
|
||||
optionsTable = WorldScreenOptionsTable(this, civInfo)
|
||||
Label("", CameraStageBaseScreen.skin).style.font.data.setScale(game.settings.labelScale)
|
||||
Label("", skin).style.font.data.setScale(1.5f)
|
||||
|
||||
|
||||
tileMapHolder.addTiles()
|
||||
|
@ -56,7 +54,6 @@ class WorldScreen : CameraStageBaseScreen() {
|
|||
|
||||
tileMapHolder.setCenterPosition(Vector2.Zero)
|
||||
createNextTurnButton() // needs civ table to be positioned
|
||||
stage.addActor(optionsTable)
|
||||
displayTutorials("NewGame")
|
||||
}
|
||||
|
||||
|
|
|
@ -3,68 +3,88 @@ package com.unciv.ui.worldscreen
|
|||
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.*
|
||||
import com.unciv.UnCivGame
|
||||
import com.unciv.ui.LoadScreen
|
||||
import com.unciv.ui.NewGameScreen
|
||||
import com.unciv.ui.SaveScreen
|
||||
import com.unciv.ui.VictoryScreen
|
||||
import com.unciv.ui.cityscreen.addClickListener
|
||||
import com.unciv.ui.pickerscreens.PolicyPickerScreen
|
||||
import com.unciv.ui.utils.CameraStageBaseScreen
|
||||
import com.unciv.ui.utils.ImageGetter
|
||||
import com.unciv.ui.utils.center
|
||||
|
||||
class WorldScreenOptionsTable internal constructor(worldScreen: WorldScreen, private val civInfo: CivilizationInfo) : Table() {
|
||||
class WorldScreenOptionsTable internal constructor() : OptionsTable() {
|
||||
|
||||
init {
|
||||
addButton("Load game"){
|
||||
UnCivGame.Current.screen = LoadScreen()
|
||||
remove()
|
||||
}
|
||||
|
||||
addButton("Save game") {
|
||||
UnCivGame.Current.screen = SaveScreen()
|
||||
remove()
|
||||
}
|
||||
|
||||
addButton("Start new game"){ UnCivGame.Current.screen = NewGameScreen() }
|
||||
|
||||
addButton("Victory status") { UnCivGame.Current.screen = VictoryScreen() }
|
||||
|
||||
addButton("Social Policies"){
|
||||
UnCivGame.Current.screen = PolicyPickerScreen(UnCivGame.Current.gameInfo.getPlayerCivilization())
|
||||
}
|
||||
|
||||
|
||||
addButton("Display options"){
|
||||
UnCivGame.Current.worldScreen.stage.addActor(WorldScreenDisplayOptionsTable())
|
||||
remove()
|
||||
}
|
||||
|
||||
addButton("Close"){ remove() }
|
||||
|
||||
pack() // Needed to show the background.
|
||||
center(UnCivGame.Current.worldScreen.stage)
|
||||
}
|
||||
}
|
||||
|
||||
open class OptionsTable:Table(){
|
||||
init {
|
||||
val tileTableBackground = ImageGetter.getDrawable("skin/whiteDot.png")
|
||||
.tint(Color(0x004085bf))
|
||||
background = tileTableBackground
|
||||
isVisible = false
|
||||
|
||||
pad(20f)
|
||||
defaults().pad(5f)
|
||||
this.pad(20f)
|
||||
this.defaults().pad(5f)
|
||||
}
|
||||
|
||||
val openCivilopediaButton = TextButton("Civilopedia", CameraStageBaseScreen.skin).apply { color=ImageGetter.getBlue(); background=null }
|
||||
openCivilopediaButton.addClickListener {
|
||||
worldScreen.game.screen = CivilopediaScreen()
|
||||
isVisible = false
|
||||
}
|
||||
add(openCivilopediaButton).row()
|
||||
|
||||
val loadGameButton = TextButton("Load game", CameraStageBaseScreen.skin).apply { color=ImageGetter.getBlue() }
|
||||
loadGameButton .addClickListener {
|
||||
worldScreen.game.screen = LoadScreen()
|
||||
isVisible=false
|
||||
}
|
||||
add(loadGameButton ).row()
|
||||
|
||||
|
||||
val saveGameButton = TextButton("Save game", CameraStageBaseScreen.skin).apply { color=ImageGetter.getBlue() }
|
||||
saveGameButton .addClickListener {
|
||||
worldScreen.game.screen = SaveScreen()
|
||||
isVisible=false
|
||||
}
|
||||
add(saveGameButton ).row()
|
||||
|
||||
val startNewGameButton = TextButton("Start new game", CameraStageBaseScreen.skin).apply { color=ImageGetter.getBlue() }
|
||||
startNewGameButton.addClickListener { worldScreen.game.screen = NewGameScreen() }
|
||||
add(startNewGameButton).row()
|
||||
|
||||
val openVictoryScreen = TextButton("Victory status", CameraStageBaseScreen.skin).apply { color=ImageGetter.getBlue() }
|
||||
openVictoryScreen.addClickListener {
|
||||
worldScreen.game.screen = VictoryScreen()
|
||||
}
|
||||
add(openVictoryScreen).row()
|
||||
|
||||
val openPolicyPickerScreen = TextButton("Social Policies", CameraStageBaseScreen.skin).apply { color=ImageGetter.getBlue() }
|
||||
openPolicyPickerScreen.addClickListener {
|
||||
worldScreen.game.screen = PolicyPickerScreen(this@WorldScreenOptionsTable.civInfo)
|
||||
}
|
||||
add(openPolicyPickerScreen).row()
|
||||
|
||||
val closeButton = TextButton("Close", CameraStageBaseScreen.skin).apply { color=ImageGetter.getBlue() }
|
||||
closeButton.addClickListener { isVisible = false }
|
||||
add(closeButton)
|
||||
|
||||
pack() // Needed to show the background.
|
||||
center(worldScreen.stage)
|
||||
fun addButton(text:String, action:()->Unit){
|
||||
val button = TextButton(text, CameraStageBaseScreen.skin).apply { color=ImageGetter.getBlue() }
|
||||
button.addClickListener(action)
|
||||
add(button).row()
|
||||
}
|
||||
}
|
||||
|
||||
class WorldScreenDisplayOptionsTable() : OptionsTable(){
|
||||
init {
|
||||
update()
|
||||
}
|
||||
|
||||
fun update(){
|
||||
clear()
|
||||
val tileMapHolder=UnCivGame.Current.worldScreen.tileMapHolder
|
||||
val settings = UnCivGame.Current.settings
|
||||
if(settings.showWorkedTiles) addButton("Hide worked tiles") {settings.showWorkedTiles=false; update()}
|
||||
else addButton("Show worked tiles") {settings.showWorkedTiles=true; update()}
|
||||
|
||||
if(settings.showResourcesAndImprovements)
|
||||
addButton("Hide resources and improvements") {settings.showResourcesAndImprovements=false; update()}
|
||||
else addButton("Show resources and improvements") {settings.showResourcesAndImprovements=true; update()}
|
||||
|
||||
addButton("Close"){ remove() }
|
||||
|
||||
pack() // Needed to show the background.
|
||||
center(UnCivGame.Current.worldScreen.stage)
|
||||
tileMapHolder.updateTiles()
|
||||
}
|
||||
}
|
|
@ -79,7 +79,7 @@ class WorldScreenTopBar(val screen: WorldScreen) : Table() {
|
|||
.apply { setSize(50f, 50f) }
|
||||
menuButton.color = Color.WHITE
|
||||
menuButton.addClickListener {
|
||||
screen.optionsTable.isVisible = !screen.optionsTable.isVisible
|
||||
screen.stage.addActor(WorldScreenOptionsTable())
|
||||
}
|
||||
menuButton.centerY(this)
|
||||
menuButton.x = menuButton.y
|
||||
|
|
Loading…
Reference in a new issue