refactor: remove isPic argument from cityMessage() notification
Have the decision of whether to show the message in the notification pane be determined by the message type itself, rather than being decided by the sender of the message. git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@859 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
parent
736754a5ab
commit
b18b51d08e
7 changed files with 48 additions and 32 deletions
|
@ -257,10 +257,10 @@ public class Micropolis
|
|||
}
|
||||
}
|
||||
|
||||
void fireCityMessage(MicropolisMessage message, CityLocation loc, boolean isPic)
|
||||
void fireCityMessage(MicropolisMessage message, CityLocation loc)
|
||||
{
|
||||
for (Listener l : listeners) {
|
||||
l.cityMessage(message, loc, isPic);
|
||||
l.cityMessage(message, loc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -380,7 +380,7 @@ public class Micropolis
|
|||
*/
|
||||
public interface Listener
|
||||
{
|
||||
void cityMessage(MicropolisMessage message, CityLocation loc, boolean isPic);
|
||||
void cityMessage(MicropolisMessage message, CityLocation loc);
|
||||
void citySound(Sound sound, CityLocation loc);
|
||||
|
||||
/**
|
||||
|
@ -1783,7 +1783,7 @@ public class Micropolis
|
|||
}
|
||||
|
||||
clearMes();
|
||||
sendMessageAtPic(MicropolisMessage.MELTDOWN_REPORT, xpos, ypos);
|
||||
sendMessageAt(MicropolisMessage.MELTDOWN_REPORT, xpos, ypos);
|
||||
}
|
||||
|
||||
static final int [] MltdwnTab = { 30000, 20000, 10000 };
|
||||
|
@ -2124,7 +2124,7 @@ public class Micropolis
|
|||
makeSound(centerMassX, centerMassY, Sound.EXPLOSION_LOW);
|
||||
fireEarthquakeStarted();
|
||||
|
||||
sendMessageAtPic(MicropolisMessage.EARTHQUAKE_REPORT, centerMassX, centerMassY);
|
||||
sendMessageAt(MicropolisMessage.EARTHQUAKE_REPORT, centerMassX, centerMassY);
|
||||
int time = PRNG.nextInt(701) + 300;
|
||||
for (int z = 0; z < time; z++) {
|
||||
int x = PRNG.nextInt(getWidth());
|
||||
|
@ -2150,7 +2150,7 @@ public class Micropolis
|
|||
if (TileConstants.isArsonable(t)) {
|
||||
setTile(x, y, (char)(FIRE + PRNG.nextInt(8)));
|
||||
crashLocation = new CityLocation(x, y);
|
||||
sendMessageAtPic(MicropolisMessage.FIRE_REPORT, x, y);
|
||||
sendMessageAt(MicropolisMessage.FIRE_REPORT, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2249,7 +2249,7 @@ public class Micropolis
|
|||
int xpos = PRNG.nextInt(getWidth() - 19) + 10;
|
||||
int ypos = PRNG.nextInt(getHeight() - 19) + 10;
|
||||
sprites.add(new TornadoSprite(this, xpos, ypos));
|
||||
sendMessageAtPic(MicropolisMessage.TORNADO_REPORT, xpos, ypos);
|
||||
sendMessageAt(MicropolisMessage.TORNADO_REPORT, xpos, ypos);
|
||||
}
|
||||
|
||||
public void makeFlood()
|
||||
|
@ -2271,7 +2271,7 @@ public class Micropolis
|
|||
if (isFloodable(c)) {
|
||||
setTile(xx, yy, FLOOD);
|
||||
floodCnt = 30;
|
||||
sendMessageAtPic(MicropolisMessage.FLOOD_REPORT, xx, yy);
|
||||
sendMessageAt(MicropolisMessage.FLOOD_REPORT, xx, yy);
|
||||
floodX = xx;
|
||||
floodY = yy;
|
||||
return;
|
||||
|
@ -2403,7 +2403,7 @@ public class Micropolis
|
|||
z = MicropolisMessage.POP_2K_REACHED;
|
||||
}
|
||||
if (z != null) {
|
||||
sendMessage(z, true);
|
||||
sendMessage(z);
|
||||
}
|
||||
}
|
||||
lastCityPop = newPop;
|
||||
|
@ -2479,12 +2479,12 @@ public class Micropolis
|
|||
break;
|
||||
case 35:
|
||||
if (pollutionAverage > 60) { // FIXME, consider changing threshold to 80
|
||||
sendMessage(MicropolisMessage.HIGH_POLLUTION, true);
|
||||
sendMessage(MicropolisMessage.HIGH_POLLUTION);
|
||||
}
|
||||
break;
|
||||
case 42:
|
||||
if (crimeAverage > 100) {
|
||||
sendMessage(MicropolisMessage.HIGH_CRIME, true);
|
||||
sendMessage(MicropolisMessage.HIGH_CRIME);
|
||||
}
|
||||
break;
|
||||
case 45:
|
||||
|
@ -2537,22 +2537,12 @@ public class Micropolis
|
|||
|
||||
void sendMessage(MicropolisMessage message)
|
||||
{
|
||||
fireCityMessage(message, null, false);
|
||||
}
|
||||
|
||||
void sendMessage(MicropolisMessage message, boolean isPic)
|
||||
{
|
||||
fireCityMessage(message, null, true);
|
||||
fireCityMessage(message, null);
|
||||
}
|
||||
|
||||
void sendMessageAt(MicropolisMessage message, int x, int y)
|
||||
{
|
||||
fireCityMessage(message, new CityLocation(x,y), false);
|
||||
}
|
||||
|
||||
void sendMessageAtPic(MicropolisMessage message, int x, int y)
|
||||
{
|
||||
fireCityMessage(message, new CityLocation(x,y), true);
|
||||
fireCityMessage(message, new CityLocation(x,y));
|
||||
}
|
||||
|
||||
public ZoneStatus queryZoneStatus(int xpos, int ypos)
|
||||
|
|
|
@ -61,4 +61,30 @@ public enum MicropolisMessage
|
|||
|
||||
// added by Jason
|
||||
NO_NUCLEAR_PLANTS;
|
||||
|
||||
/** Whether the message should be displayed in the notification pane. */
|
||||
public boolean useNotificationPane = false;
|
||||
|
||||
static
|
||||
{
|
||||
// not location-specific
|
||||
POP_2K_REACHED.useNotificationPane = true;
|
||||
POP_10K_REACHED.useNotificationPane = true;
|
||||
POP_50K_REACHED.useNotificationPane = true;
|
||||
POP_100K_REACHED.useNotificationPane = true;
|
||||
POP_500K_REACHED.useNotificationPane = true;
|
||||
HIGH_CRIME.useNotificationPane = true;
|
||||
HIGH_POLLUTION.useNotificationPane = true;
|
||||
|
||||
// location-specific
|
||||
FLOOD_REPORT.useNotificationPane = true;
|
||||
FIRE_REPORT.useNotificationPane = true;
|
||||
TORNADO_REPORT.useNotificationPane = true;
|
||||
MELTDOWN_REPORT.useNotificationPane = true;
|
||||
EARTHQUAKE_REPORT.useNotificationPane = true;
|
||||
TRAIN_CRASH_REPORT.useNotificationPane = true;
|
||||
SHIPWRECK_REPORT.useNotificationPane = true;
|
||||
COPTER_CRASH_REPORT.useNotificationPane = true;
|
||||
PLANECRASH_REPORT.useNotificationPane = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,20 +130,20 @@ public abstract class Sprite
|
|||
switch (kind) {
|
||||
case AIR:
|
||||
city.crashLocation = new CityLocation(xpos, ypos);
|
||||
city.sendMessageAtPic(MicropolisMessage.PLANECRASH_REPORT, xpos, ypos);
|
||||
city.sendMessageAt(MicropolisMessage.PLANECRASH_REPORT, xpos, ypos);
|
||||
break;
|
||||
case SHI:
|
||||
city.crashLocation = new CityLocation(xpos, ypos);
|
||||
city.sendMessageAtPic(MicropolisMessage.SHIPWRECK_REPORT, xpos, ypos);
|
||||
city.sendMessageAt(MicropolisMessage.SHIPWRECK_REPORT, xpos, ypos);
|
||||
break;
|
||||
case TRA:
|
||||
case BUS:
|
||||
city.crashLocation = new CityLocation(xpos, ypos);
|
||||
city.sendMessageAtPic(MicropolisMessage.TRAIN_CRASH_REPORT, xpos, ypos);
|
||||
city.sendMessageAt(MicropolisMessage.TRAIN_CRASH_REPORT, xpos, ypos);
|
||||
break;
|
||||
case COP:
|
||||
city.crashLocation = new CityLocation(xpos, ypos);
|
||||
city.sendMessageAtPic(MicropolisMessage.COPTER_CRASH_REPORT, xpos, ypos);
|
||||
city.sendMessageAt(MicropolisMessage.COPTER_CRASH_REPORT, xpos, ypos);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ public class DemandIndicator extends JComponent
|
|||
}
|
||||
|
||||
//implements Micropolis.Listener
|
||||
public void cityMessage(MicropolisMessage m, CityLocation p, boolean x) { }
|
||||
public void cityMessage(MicropolisMessage m, CityLocation p) { }
|
||||
public void citySound(Sound sound, CityLocation p) { }
|
||||
public void censusChanged() { }
|
||||
public void evaluationChanged() { }
|
||||
|
|
|
@ -242,7 +242,7 @@ public class EvaluationPane extends JPanel
|
|||
}
|
||||
|
||||
//implements Micropolis.Listener
|
||||
public void cityMessage(MicropolisMessage message, CityLocation loc, boolean isPic) {}
|
||||
public void cityMessage(MicropolisMessage message, CityLocation loc) {}
|
||||
public void citySound(Sound sound, CityLocation loc) {}
|
||||
public void censusChanged() {}
|
||||
public void demandChanged() {}
|
||||
|
|
|
@ -143,7 +143,7 @@ public class GraphsPane extends JPanel
|
|||
}
|
||||
|
||||
//implements Micropolis.Listener
|
||||
public void cityMessage(MicropolisMessage message, CityLocation loc, boolean isPic) {}
|
||||
public void cityMessage(MicropolisMessage message, CityLocation loc) {}
|
||||
public void citySound(Sound sound, CityLocation loc) {}
|
||||
public void demandChanged() {}
|
||||
public void evaluationChanged() {}
|
||||
|
|
|
@ -1540,11 +1540,11 @@ public class MainWindow extends JFrame
|
|||
}
|
||||
|
||||
//implements Micropolis.Listener
|
||||
public void cityMessage(MicropolisMessage m, CityLocation p, boolean pictureMessage)
|
||||
public void cityMessage(MicropolisMessage m, CityLocation p)
|
||||
{
|
||||
messagesPane.appendCityMessage(m);
|
||||
|
||||
if (pictureMessage && p != null)
|
||||
if (m.useNotificationPane && p != null)
|
||||
{
|
||||
notificationPane.showMessage(engine, m, p.x, p.y);
|
||||
}
|
||||
|
|
Reference in a new issue