Fixed inverted Y position when exiting city

Improvements near cities now notify "has been completed near X"
This commit is contained in:
Yair Morgenstern 2017-12-13 19:37:33 +02:00
parent 761b62038f
commit d55297d7df
2 changed files with 23 additions and 8 deletions

View File

@ -3,6 +3,7 @@ package com.unciv.civinfo;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Predicate; import com.badlogic.gdx.utils.Predicate;
import com.unciv.game.UnCivGame; import com.unciv.game.UnCivGame;
import com.unciv.models.LinqCollection;
import com.unciv.models.gamebasics.GameBasics; import com.unciv.models.gamebasics.GameBasics;
import com.unciv.models.gamebasics.Terrain; import com.unciv.models.gamebasics.Terrain;
import com.unciv.models.gamebasics.TileImprovement; import com.unciv.models.gamebasics.TileImprovement;
@ -131,6 +132,19 @@ public class TileInfo
String notification = improvementInProgress+" has been completed"; String notification = improvementInProgress+" has been completed";
if(workingCity!=null) notification+=" for "+getCity().name; if(workingCity!=null) notification+=" for "+getCity().name;
else {
for (int i = 1; i < 3; i++) {
LinqCollection<TileInfo> tilesWithCity = CivilizationInfo.current().tileMap.getTilesInDistance(position, i).where(new Predicate<TileInfo>() {
@Override
public boolean evaluate(TileInfo arg0) {
return arg0.isCityCenter();
}
});
if(tilesWithCity.isEmpty()) continue;
notification+=" near "+tilesWithCity.get(0).workingCity;
break;
}
}
notification+="!"; notification+="!";
CivilizationInfo.current().notifications.add(notification); CivilizationInfo.current().notifications.add(notification);
improvementInProgress = null; improvementInProgress = null;

View File

@ -258,7 +258,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
}); });
Vector2 positionalVector = com.unciv.game.utils.HexMath.Hex2WorldCoords(tileInfo.position); Vector2 positionalVector = HexMath.Hex2WorldCoords(tileInfo.position);
int groupSize = 50; int groupSize = 50;
group.setPosition(stage.getWidth() / 2 + positionalVector.x * 0.8f * groupSize, group.setPosition(stage.getWidth() / 2 + positionalVector.x * 0.8f * groupSize,
stage.getHeight() / 2 + positionalVector.y * 0.8f * groupSize); stage.getHeight() / 2 + positionalVector.y * 0.8f * groupSize);
@ -442,7 +442,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
// tiles adjacent to city tiles // tiles adjacent to city tiles
for(TileInfo tileInfo : game.civInfo.tileMap.values()) for(TileInfo tileInfo : game.civInfo.tileMap.values())
if(game.civInfo.civName.equals(tileInfo.owner)) if(game.civInfo.civName.equals(tileInfo.owner))
for(Vector2 adjacentLocation : com.unciv.game.utils.HexMath.GetAdjacentVectors(tileInfo.position)) for(Vector2 adjacentLocation : HexMath.GetAdjacentVectors(tileInfo.position))
ViewableVectorStrings.add(adjacentLocation.toString()); ViewableVectorStrings.add(adjacentLocation.toString());
// Tiles within 2 tiles of units // Tiles within 2 tiles of units
@ -453,7 +453,7 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
return arg0.unit !=null; return arg0.unit !=null;
} }
})) }))
for(Vector2 vector : com.unciv.game.utils.HexMath.GetVectorsInDistance(tile.position,2)) for(Vector2 vector : HexMath.GetVectorsInDistance(tile.position,2))
ViewableVectorStrings.add(vector.toString()); ViewableVectorStrings.add(vector.toString());
for(String string : ViewableVectorStrings) for(String string : ViewableVectorStrings)
@ -469,11 +469,12 @@ public class WorldScreen extends com.unciv.game.utils.CameraStageBaseScreen {
return arg0.tileInfo.position.equals(vector) ; return arg0.tileInfo.position.equals(vector) ;
} }
}); });
float x = TG.getX()-stage.getWidth()/2; scrollPane.layout(); // Fit the scroll pane to the contents - otherwise, setScroll won't work!
float y = TG.getY()-stage.getHeight()/2; // We want to center on the middle of TG (TG.getX()+TG.getWidth()/2)
scrollPane.layout(); // and so the scroll position (== where the screen starts) needs to be half a screen away
scrollPane.setScrollX(x); scrollPane.setScrollX(TG.getX()+TG.getWidth()/2-stage.getWidth()/2);
scrollPane.setScrollY(y); // Here it's the same, only the Y axis is inverted - when at 0 we're at the top, not bottom - so we invert it back.
scrollPane.setScrollY(scrollPane.getMaxY() - (TG.getY() + TG.getWidth()/2 - stage.getHeight()/2));
scrollPane.updateVisualScroll(); scrollPane.updateVisualScroll();
} }