From 7e36b51db541fca089072635555f49e7f7a61253 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Fri, 11 Sep 2020 15:40:43 +0300 Subject: [PATCH] Changes to MoveButtonDto in preparation for multiple unit movement --- core/src/com/unciv/logic/map/MapUnit.kt | 3 ++- .../ui/pickerscreens/ModManagementScreen.kt | 2 +- .../com/unciv/ui/worldscreen/WorldMapHolder.kt | 17 ++++++++++------- .../unciv/ui/worldscreen/mainmenu/DropBox.kt | 3 +-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/core/src/com/unciv/logic/map/MapUnit.kt b/core/src/com/unciv/logic/map/MapUnit.kt index fbcbe544a2..d67f32a94e 100644 --- a/core/src/com/unciv/logic/map/MapUnit.kt +++ b/core/src/com/unciv/logic/map/MapUnit.kt @@ -544,7 +544,8 @@ class MapUnit { if (unit.currentMovement < 0.1) unit.disband() // 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) unit.movement.moveToTile(tileCanMoveTo) diff --git a/core/src/com/unciv/ui/pickerscreens/ModManagementScreen.kt b/core/src/com/unciv/ui/pickerscreens/ModManagementScreen.kt index 8618268d2d..b90dd8e426 100644 --- a/core/src/com/unciv/ui/pickerscreens/ModManagementScreen.kt +++ b/core/src/com/unciv/ui/pickerscreens/ModManagementScreen.kt @@ -85,7 +85,7 @@ class ModManagementScreen: PickerScreen() { fun downloadMod(gitRepoUrl:String, postAction:()->Unit={}){ thread { // to avoid ANRs - we've learnt our lesson from previous download-related actions try { - Github.downloadAndExtract(gitRepoUrl+"/archive/master.zip", + Github.downloadAndExtract("$gitRepoUrl/archive/master.zip", Gdx.files.local("mods")) Gdx.app.postRunnable { ResponsePopup("Downloaded!", this) diff --git a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt index e241565e77..6f11c01058 100644 --- a/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt +++ b/core/src/com/unciv/ui/worldscreen/WorldMapHolder.kt @@ -33,7 +33,8 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap 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 - 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, val tileInfo: TileInfo) internal fun addTiles() { val tileSetStrings = TileSetStrings() @@ -167,7 +168,7 @@ class WorldMapHolder(internal val worldScreen: WorldScreen, internal val tileMap worldScreen.bottomUnitTable.selectUnits(selectedUnit) // keep moved unit selected } else { // 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 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 } 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 moveHereButton.addActor(unitIcon) - if (dto.unit.currentMovement > 0) + if (unit.currentMovement > 0) moveHereButton.onClick(UncivSound.Silent) { UncivGame.Current.settings.addCompletedTutorialTask("Move unit") - if(dto.unit.type.isAirUnit()) + if(unit.type.isAirUnit()) UncivGame.Current.settings.addCompletedTutorialTask("Move an air unit") - moveUnitToTargetTile(dto.unit, dto.tileInfo) + moveUnitToTargetTile(unit, dto.tileInfo) } else moveHereButton.color.a = 0.5f diff --git a/core/src/com/unciv/ui/worldscreen/mainmenu/DropBox.kt b/core/src/com/unciv/ui/worldscreen/mainmenu/DropBox.kt index 4e687366b4..95540350f7 100644 --- a/core/src/com/unciv/ui/worldscreen/mainmenu/DropBox.kt +++ b/core/src/com/unciv/ui/worldscreen/mainmenu/DropBox.kt @@ -4,7 +4,6 @@ import com.badlogic.gdx.files.FileHandle import com.unciv.logic.GameInfo import com.unciv.logic.GameSaver import com.unciv.logic.civilization.CivilizationInfo -import com.unciv.models.metadata.GameSettings import com.unciv.ui.saves.Gzip import java.io.* import java.net.HttpURLConnection @@ -177,7 +176,7 @@ object Github { fun tryGetGithubReposWithTopic(): ArrayList { val inputStream = download("https://api.github.com/search/repositories?q=topic:unciv-mod") 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{