Fixed minimap not updating when build team changes

This commit is contained in:
Anuken
2021-08-05 14:20:23 -04:00
parent 66ce3e75ec
commit 6fdbe1d5f0
3 changed files with 24 additions and 1 deletions

View File

@@ -49,6 +49,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
static final float timeToSleep = 60f * 1, timeToUncontrol = 60f * 6; static final float timeToSleep = 60f * 1, timeToUncontrol = 60f * 6;
static final ObjectSet<Building> tmpTiles = new ObjectSet<>(); static final ObjectSet<Building> tmpTiles = new ObjectSet<>();
static final Seq<Building> tempBuilds = new Seq<>(); static final Seq<Building> tempBuilds = new Seq<>();
static final BuildTeamChangeEvent teamChangeEvent = new BuildTeamChangeEvent();
static int sleepingEntities = 0; static int sleepingEntities = 0;
@Import float x, y, health, maxHealth; @Import float x, y, health, maxHealth;
@@ -1258,9 +1259,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
/** Changes this building's team in a safe manner. */ /** Changes this building's team in a safe manner. */
public void changeTeam(Team next){ public void changeTeam(Team next){
Team last = this.team;
indexer.removeIndex(tile); indexer.removeIndex(tile);
this.team = next; this.team = next;
indexer.addIndex(tile); indexer.addIndex(tile);
Events.fire(teamChangeEvent.set(last, self()));
} }
public boolean canPickup(){ public boolean canPickup(){

View File

@@ -284,6 +284,21 @@ public class EventType{
} }
} }
/**
* Called after a building's team changes.
* Event object is reused, do not nest!
* */
public static class BuildTeamChangeEvent{
public Team previous;
public Building build;
public BuildTeamChangeEvent set(Team previous, Building build){
this.build = build;
this.previous = previous;
return this;
}
}
/** Called when a core block is placed/removed or its team is changed. */ /** Called when a core block is placed/removed or its team is changed. */
public static class CoreChangeEvent{ public static class CoreChangeEvent{
public CoreBuild core; public CoreBuild core;

View File

@@ -33,13 +33,18 @@ public class MinimapRenderer{
updateAll(); updateAll();
}); });
//make sure to call on the graphics thread
Events.on(TileChangeEvent.class, event -> { Events.on(TileChangeEvent.class, event -> {
//TODO don't update when the minimap is off? //TODO don't update when the minimap is off?
if(!ui.editor.isShown()){ if(!ui.editor.isShown()){
update(event.tile); update(event.tile);
} }
}); });
Events.on(BuildTeamChangeEvent.class, event -> {
if(!ui.editor.isShown()){
update(event.build.tile);
}
});
} }
public Pixmap getPixmap(){ public Pixmap getPixmap(){