Changes to MoveButtonDto in preparation for multiple unit movement

This commit is contained in:
Yair Morgenstern 2020-09-11 15:40:43 +03:00
parent 395292e2f3
commit 7e36b51db5
4 changed files with 14 additions and 11 deletions

View File

@ -544,7 +544,8 @@ class MapUnit {
if (unit.currentMovement < 0.1) if (unit.currentMovement < 0.1)
unit.disband() unit.disband()
// let's find closest city or another carrier where it can be evacuated // let's find closest city or another carrier where it can be evacuated
val tileCanMoveTo = unit.currentTile.getTilesInDistance(unit.getRange() * 2).filterNot { it == currentTile }.firstOrNull { unit.movement.canMoveTo(it) } val tileCanMoveTo = unit.currentTile.getTilesInDistance(unit.getRange() * 2)
.filterNot { it == currentTile }.firstOrNull { unit.movement.canMoveTo(it) }
if (tileCanMoveTo != null) if (tileCanMoveTo != null)
unit.movement.moveToTile(tileCanMoveTo) unit.movement.moveToTile(tileCanMoveTo)

View File

@ -85,7 +85,7 @@ class ModManagementScreen: PickerScreen() {
fun downloadMod(gitRepoUrl:String, postAction:()->Unit={}){ fun downloadMod(gitRepoUrl:String, postAction:()->Unit={}){
thread { // to avoid ANRs - we've learnt our lesson from previous download-related actions thread { // to avoid ANRs - we've learnt our lesson from previous download-related actions
try { try {
Github.downloadAndExtract(gitRepoUrl+"/archive/master.zip", Github.downloadAndExtract("$gitRepoUrl/archive/master.zip",
Gdx.files.local("mods")) Gdx.files.local("mods"))
Gdx.app.postRunnable { Gdx.app.postRunnable {
ResponsePopup("Downloaded!", this) ResponsePopup("Downloaded!", this)

View File

@ -33,7 +33,8 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
var unitActionOverlay :Actor?=null var unitActionOverlay :Actor?=null
// Used to transfer data on the "move here" button that should be created, from the side thread to the main thread // Used to transfer data on the "move here" button that should be created, from the side thread to the main thread
class MoveHereButtonDto(val unit: MapUnit, val tileInfo: TileInfo, val turnsToGetThere: Int) // This is a hashmap in preparation for moving multiple units at once
class MoveHereButtonDto(val unitToTurnsToDestination: HashMap<MapUnit,Int>, val tileInfo: TileInfo)
internal fun addTiles() { internal fun addTiles() {
val tileSetStrings = TileSetStrings() val tileSetStrings = TileSetStrings()
@ -167,7 +168,7 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
worldScreen.bottomUnitTable.selectUnits(selectedUnit) // keep moved unit selected worldScreen.bottomUnitTable.selectUnits(selectedUnit) // keep moved unit selected
} else { } else {
// add "move to" button if there is a path to tileInfo // add "move to" button if there is a path to tileInfo
val moveHereButtonDto = if (turnsToGetThere != 0) MoveHereButtonDto(selectedUnit, tileInfo, turnsToGetThere) val moveHereButtonDto = if (turnsToGetThere != 0) MoveHereButtonDto(hashMapOf(selectedUnit to turnsToGetThere), tileInfo)
else null else null
addTileOverlays(tileInfo, moveHereButtonDto) addTileOverlays(tileInfo, moveHereButtonDto)
} }
@ -217,18 +218,20 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap
val numberCircle = ImageGetter.getCircle().apply { width = size / 2; height = size / 2;color = Color.BLUE } val numberCircle = ImageGetter.getCircle().apply { width = size / 2; height = size / 2;color = Color.BLUE }
moveHereButton.addActor(numberCircle) moveHereButton.addActor(numberCircle)
moveHereButton.addActor(dto.turnsToGetThere.toString().toLabel().apply { center(numberCircle) })
val unitIcon = UnitGroup(dto.unit, size / 2)
moveHereButton.addActor(dto.unitToTurnsToDestination.values.first().toString().toLabel().apply { center(numberCircle) })
val unit = dto.unitToTurnsToDestination.keys.first()
val unitIcon = UnitGroup(unit, size / 2)
unitIcon.y = size - unitIcon.height unitIcon.y = size - unitIcon.height
moveHereButton.addActor(unitIcon) moveHereButton.addActor(unitIcon)
if (dto.unit.currentMovement > 0) if (unit.currentMovement > 0)
moveHereButton.onClick(UncivSound.Silent) { moveHereButton.onClick(UncivSound.Silent) {
UncivGame.Current.settings.addCompletedTutorialTask("Move unit") UncivGame.Current.settings.addCompletedTutorialTask("Move unit")
if(dto.unit.type.isAirUnit()) if(unit.type.isAirUnit())
UncivGame.Current.settings.addCompletedTutorialTask("Move an air unit") UncivGame.Current.settings.addCompletedTutorialTask("Move an air unit")
moveUnitToTargetTile(dto.unit, dto.tileInfo) moveUnitToTargetTile(unit, dto.tileInfo)
} }
else moveHereButton.color.a = 0.5f else moveHereButton.color.a = 0.5f

View File

@ -4,7 +4,6 @@ import com.badlogic.gdx.files.FileHandle
import com.unciv.logic.GameInfo import com.unciv.logic.GameInfo
import com.unciv.logic.GameSaver import com.unciv.logic.GameSaver
import com.unciv.logic.civilization.CivilizationInfo import com.unciv.logic.civilization.CivilizationInfo
import com.unciv.models.metadata.GameSettings
import com.unciv.ui.saves.Gzip import com.unciv.ui.saves.Gzip
import java.io.* import java.io.*
import java.net.HttpURLConnection import java.net.HttpURLConnection
@ -177,7 +176,7 @@ object Github {
fun tryGetGithubReposWithTopic(): ArrayList<Repo> { fun tryGetGithubReposWithTopic(): ArrayList<Repo> {
val inputStream = download("https://api.github.com/search/repositories?q=topic:unciv-mod") val inputStream = download("https://api.github.com/search/repositories?q=topic:unciv-mod")
if (inputStream == null) return ArrayList() if (inputStream == null) return ArrayList()
return GameSaver.json().fromJson(RepoSearch::class.java, inputStream!!.bufferedReader().readText()).items return GameSaver.json().fromJson(RepoSearch::class.java, inputStream.bufferedReader().readText()).items
} }
class RepoSearch{ class RepoSearch{