Turn notification

This commit is contained in:
Anuken 2020-05-16 16:40:24 -04:00
parent bdbc8ab6d2
commit 2b46659daf
5 changed files with 39 additions and 5 deletions

View File

@ -32,6 +32,7 @@ public class EventType{
update
}
public static class TurnEvent{}
public static class WinEvent{}
public static class LoseEvent{}
public static class LaunchEvent{}
@ -67,6 +68,7 @@ public class EventType{
}
}
public static class CommandIssueEvent{
public final Tilec tile;
public final UnitCommand command;

View File

@ -38,7 +38,17 @@ public class Stats{
/** Updates export statistics. */
public void handleItemExport(ItemStack stack){
export.getOr(stack.item, ExportStat::new).counter += stack.amount;
handleItemExport(stack.item, stack.amount);
}
/** Updates export statistics. */
public void handleItemExport(Item item, int amount){
export.getOr(item, ExportStat::new).counter += amount;
}
/** Subtracts from export statistics. */
public void handleItemImport(Item item, int amount){
export.getOr(item, ExportStat::new).counter -= amount;
}
public float getExport(Item item){

View File

@ -6,6 +6,7 @@ import arc.struct.ObjectFloatMap.*;
import arc.util.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.game.EventType.*;
import mindustry.io.*;
import mindustry.type.*;
@ -76,7 +77,7 @@ public class Universe{
for(Sector sector : planet.sectors){
//ignore the current sector if the player is in it right now
if(sector.hasSave() && !sector.isBeingPlayed()){
if(sector.hasBase() && !sector.isBeingPlayed()){
SaveMeta meta = sector.save.meta;
for(Entry<Item> entry : meta.exportRates){
@ -103,12 +104,13 @@ public class Universe{
turn ++;
turnCounter = 0;
//TODO EVENTS
//TODO EVENTS + a notification
//increment turns passed for sectors with waves
//TODO a turn passing may break the core; detect this, send an event and mark the sector as having no base!
for(Planet planet : content.planets()){
for(Sector sector : planet.sectors){
//attacks happen even for sectors without bases - stuff still gets destroyed
if(!sector.isBeingPlayed() && sector.hasSave() && sector.hasWaves()){
sector.setTurnsPassed(sector.getTurnsPassed() + 1);
}
@ -120,6 +122,20 @@ public class Universe{
for(int i = 0; i < exports.length; i++){
data.addItem(content.item(i), exports[i]);
}
Events.fire(new TurnEvent());
}
public int getTurn(){
return turn;
}
public int getSectorsAttacked(){
int count = 0;
for(Planet planet : content.planets()){
count += planet.sectors.count(s -> !s.isBeingPlayed() && s.hasSave() && s.hasWaves());
}
return count;
}
public float secondsMod(float mod, float scale){

View File

@ -364,7 +364,7 @@ public class PlanetDialog extends FloatingDialog{
}).fillX().row();
//production
if(selected.hasSave() && selected.save.meta.hasProduction){
if(selected.hasBase() && selected.save.meta.hasProduction){
stable.add("Production:").row();
stable.table(t -> {
t.left();
@ -381,7 +381,7 @@ public class PlanetDialog extends FloatingDialog{
}
//disaply how many turns this sector has been attacked
if(selected.getTurnsPassed() > 0){
if(selected.getTurnsPassed() > 0 && selected.hasBase()){
stable.row();
stable.add("[scarlet]" + Iconc.warning + " " + selected.getTurnsPassed() + "x attacks");

View File

@ -41,7 +41,13 @@ public class HudFragment extends Fragment{
private long lastToast;
@Override
public void build(Group parent){
Events.on(TurnEvent.class, e -> {
//TODO localize, clean up, etc
int attacked = universe.getSectorsAttacked();
showToast("New turn: [accent]" + universe.getTurn() + "[]" + (attacked > 0 ? "\n[scarlet]" + Iconc.warning + " " + attacked + " sectors attacked!": ""));
});
//menu at top left
parent.fill(cont -> {