diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 13e3407d0d..2daa533eff 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -43,8 +43,7 @@ about.button = About name = Name: noname = Pick a[accent] player name[] first. filename = File Name: -unlocked = New Block Unlocked! -unlocked.plural = New Blocks Unlocked! +unlocked = New content unlocked! players = {0} players online players.single = {0} player online server.closing = [accent]Closing server... diff --git a/core/src/io/anuke/mindustry/content/Mechs.java b/core/src/io/anuke/mindustry/content/Mechs.java index 9124d484d3..59e654c357 100644 --- a/core/src/io/anuke/mindustry/content/Mechs.java +++ b/core/src/io/anuke/mindustry/content/Mechs.java @@ -40,8 +40,8 @@ public class Mechs implements ContentList{ } @Override - public void updateAlt(Player player){ - + public boolean alwaysUnlocked(){ + return true; } }; @@ -182,18 +182,25 @@ public class Mechs implements ContentList{ } }; - dart = new Mech("dart-ship", true){{ - drillPower = 1; - mineSpeed = 0.9f; - speed = 0.4f; - drag = 0.1f; - armor = 10f; - weapon = Weapons.blasterSmall; - weaponOffsetX = -1; - weaponOffsetY = -1; - trailColor = Palette.lightTrail; - cellTrnsY = 1f; - }}; + dart = new Mech("dart-ship", true){ + { + drillPower = 1; + mineSpeed = 0.9f; + speed = 0.4f; + drag = 0.1f; + armor = 10f; + weapon = Weapons.blasterSmall; + weaponOffsetX = -1; + weaponOffsetY = -1; + trailColor = Palette.lightTrail; + cellTrnsY = 1f; + } + + @Override + public boolean alwaysUnlocked(){ + return true; + } + }; javelin = new Mech("javelin-ship", true){ float minV = 3.6f; diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 756b759399..c47143ecf0 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -133,6 +133,8 @@ public class Control implements ApplicationListener{ } } }); + + Events.on(UnlockEvent.class, e -> ui.hudfrag.showUnlock(e.content)); } public void addPlayer(int index){ diff --git a/core/src/io/anuke/mindustry/game/EventType.java b/core/src/io/anuke/mindustry/game/EventType.java index 32e680e4ae..7c210cbda7 100644 --- a/core/src/io/anuke/mindustry/game/EventType.java +++ b/core/src/io/anuke/mindustry/game/EventType.java @@ -60,9 +60,9 @@ public class EventType{ } public static class UnlockEvent implements Event{ - public final Content content; + public final UnlockableContent content; - public UnlockEvent(Content content){ + public UnlockEvent(UnlockableContent content){ this.content = content; } } diff --git a/core/src/io/anuke/mindustry/game/GlobalData.java b/core/src/io/anuke/mindustry/game/GlobalData.java index f9e5a904bf..cf852bb072 100644 --- a/core/src/io/anuke/mindustry/game/GlobalData.java +++ b/core/src/io/anuke/mindustry/game/GlobalData.java @@ -57,23 +57,17 @@ public class GlobalData{ * Makes this piece of content 'unlocked', if possible. * If this piece of content is already unlocked or cannot be unlocked due to dependencies, nothing changes. * Results are not saved until you call {@link #save()}. - * - * @return whether or not this content was newly unlocked. */ - public boolean unlockContent(UnlockableContent content){ - if(!content.canBeUnlocked() || content.alwaysUnlocked()) return false; - - boolean ret = unlocked.getOr(content.getContentType(), ObjectSet::new).add(content.getContentName()); + public void unlockContent(UnlockableContent content){ + if(!content.canBeUnlocked() || content.alwaysUnlocked()) return; //fire unlock event so other classes can use it - if(ret){ + if(unlocked.getOr(content.getContentType(), ObjectSet::new).add(content.getContentName())){ modified = true; content.onUnlock(); Events.fire(new UnlockEvent(content)); save(); } - - return ret; } /** Clears all unlocked content. Automatically saves.*/ diff --git a/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java b/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java index 4174fbfbbe..17e46b96a6 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/HudFragment.java @@ -4,7 +4,6 @@ import io.anuke.arc.Core; import io.anuke.arc.Events; import io.anuke.arc.collection.Array; import io.anuke.arc.graphics.Color; -import io.anuke.arc.graphics.g2d.TextureRegion; import io.anuke.arc.math.Interpolation; import io.anuke.arc.math.Mathf; import io.anuke.arc.scene.Element; @@ -13,7 +12,6 @@ import io.anuke.arc.scene.actions.Actions; import io.anuke.arc.scene.event.Touchable; import io.anuke.arc.scene.ui.Image; import io.anuke.arc.scene.ui.ImageButton; -import io.anuke.arc.scene.ui.Label; import io.anuke.arc.scene.ui.TextButton; import io.anuke.arc.scene.ui.layout.Stack; import io.anuke.arc.scene.ui.layout.Table; @@ -24,12 +22,12 @@ import io.anuke.arc.util.Time; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.game.EventType.StateChangeEvent; import io.anuke.mindustry.game.Team; +import io.anuke.mindustry.game.UnlockableContent; import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.graphics.Palette; import io.anuke.mindustry.input.Binding; import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Packets.AdminAction; -import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.ui.IntFormat; import io.anuke.mindustry.ui.dialogs.FloatingDialog; @@ -229,7 +227,9 @@ public class HudFragment extends Fragment{ } /** Show unlock notification for a new recipe. */ - public void showUnlock(Recipe recipe){ + public void showUnlock(UnlockableContent content){ + //some content may not have icons... yet + if(content.getContentIcon() == null) return; //if there's currently no unlock notification... if(lastUnlockTable == null){ @@ -246,14 +246,10 @@ public class HudFragment extends Fragment{ Table in = new Table(); //create texture stack for displaying - Stack stack = new Stack(); - for(TextureRegion region : recipe.result.getCompactIcon()){ - Image image = new Image(region); - image.setScaling(Scaling.fit); - stack.add(image); - } + Image image = new Image(content.getContentIcon()); + image.setScaling(Scaling.fit); - in.add(stack).size(48f).pad(2); + in.add(image).size(48f).pad(2); //add to table table.add(in).padRight(8); @@ -289,11 +285,6 @@ public class HudFragment extends Fragment{ //get size of each element float size = 48f / Math.min(elements.size + 1, col); - //correct plurals if needed - if(esize == 1){ - ((Label) lastUnlockLayout.getParent().find(e -> e instanceof Label)).setText("$unlocked.plural"); - } - lastUnlockLayout.clearChildren(); lastUnlockLayout.defaults().size(size).pad(2); @@ -308,14 +299,10 @@ public class HudFragment extends Fragment{ //if there's space, add it if(esize < cap){ - Stack stack = new Stack(); - for(TextureRegion region : recipe.result.getCompactIcon()){ - Image image = new Image(region); - image.setScaling(Scaling.fit); - stack.add(image); - } + Image image = new Image(content.getContentIcon()); + image.setScaling(Scaling.fit); - lastUnlockLayout.add(stack); + lastUnlockLayout.add(image); }else{ //else, add a specific icon to denote no more space lastUnlockLayout.addImage("icon-add"); }