From 6fdbe1d5f05f8c40a346c754f0089ca779ab90a5 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 5 Aug 2021 14:20:23 -0400 Subject: [PATCH] Fixed minimap not updating when build team changes --- .../src/mindustry/entities/comp/BuildingComp.java | 3 +++ core/src/mindustry/game/EventType.java | 15 +++++++++++++++ core/src/mindustry/graphics/MinimapRenderer.java | 7 ++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index fb40d72eb1..b474a8bfdf 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -49,6 +49,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, static final float timeToSleep = 60f * 1, timeToUncontrol = 60f * 6; static final ObjectSet tmpTiles = new ObjectSet<>(); static final Seq tempBuilds = new Seq<>(); + static final BuildTeamChangeEvent teamChangeEvent = new BuildTeamChangeEvent(); static int sleepingEntities = 0; @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. */ public void changeTeam(Team next){ + Team last = this.team; indexer.removeIndex(tile); this.team = next; indexer.addIndex(tile); + Events.fire(teamChangeEvent.set(last, self())); } public boolean canPickup(){ diff --git a/core/src/mindustry/game/EventType.java b/core/src/mindustry/game/EventType.java index 9d590de52c..5ff6a6f264 100644 --- a/core/src/mindustry/game/EventType.java +++ b/core/src/mindustry/game/EventType.java @@ -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. */ public static class CoreChangeEvent{ public CoreBuild core; diff --git a/core/src/mindustry/graphics/MinimapRenderer.java b/core/src/mindustry/graphics/MinimapRenderer.java index 1a3b7dc7f8..51b5f7f483 100644 --- a/core/src/mindustry/graphics/MinimapRenderer.java +++ b/core/src/mindustry/graphics/MinimapRenderer.java @@ -33,13 +33,18 @@ public class MinimapRenderer{ updateAll(); }); - //make sure to call on the graphics thread Events.on(TileChangeEvent.class, event -> { //TODO don't update when the minimap is off? if(!ui.editor.isShown()){ update(event.tile); } }); + + Events.on(BuildTeamChangeEvent.class, event -> { + if(!ui.editor.isShown()){ + update(event.build.tile); + } + }); } public Pixmap getPixmap(){