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) {
|
for (Listener l : listeners) {
|
||||||
l.cityMessage(message, loc, isPic);
|
l.cityMessage(message, loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,7 +380,7 @@ public class Micropolis
|
||||||
*/
|
*/
|
||||||
public interface Listener
|
public interface Listener
|
||||||
{
|
{
|
||||||
void cityMessage(MicropolisMessage message, CityLocation loc, boolean isPic);
|
void cityMessage(MicropolisMessage message, CityLocation loc);
|
||||||
void citySound(Sound sound, CityLocation loc);
|
void citySound(Sound sound, CityLocation loc);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1783,7 +1783,7 @@ public class Micropolis
|
||||||
}
|
}
|
||||||
|
|
||||||
clearMes();
|
clearMes();
|
||||||
sendMessageAtPic(MicropolisMessage.MELTDOWN_REPORT, xpos, ypos);
|
sendMessageAt(MicropolisMessage.MELTDOWN_REPORT, xpos, ypos);
|
||||||
}
|
}
|
||||||
|
|
||||||
static final int [] MltdwnTab = { 30000, 20000, 10000 };
|
static final int [] MltdwnTab = { 30000, 20000, 10000 };
|
||||||
|
@ -2124,7 +2124,7 @@ public class Micropolis
|
||||||
makeSound(centerMassX, centerMassY, Sound.EXPLOSION_LOW);
|
makeSound(centerMassX, centerMassY, Sound.EXPLOSION_LOW);
|
||||||
fireEarthquakeStarted();
|
fireEarthquakeStarted();
|
||||||
|
|
||||||
sendMessageAtPic(MicropolisMessage.EARTHQUAKE_REPORT, centerMassX, centerMassY);
|
sendMessageAt(MicropolisMessage.EARTHQUAKE_REPORT, centerMassX, centerMassY);
|
||||||
int time = PRNG.nextInt(701) + 300;
|
int time = PRNG.nextInt(701) + 300;
|
||||||
for (int z = 0; z < time; z++) {
|
for (int z = 0; z < time; z++) {
|
||||||
int x = PRNG.nextInt(getWidth());
|
int x = PRNG.nextInt(getWidth());
|
||||||
|
@ -2150,7 +2150,7 @@ public class Micropolis
|
||||||
if (TileConstants.isArsonable(t)) {
|
if (TileConstants.isArsonable(t)) {
|
||||||
setTile(x, y, (char)(FIRE + PRNG.nextInt(8)));
|
setTile(x, y, (char)(FIRE + PRNG.nextInt(8)));
|
||||||
crashLocation = new CityLocation(x, y);
|
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 xpos = PRNG.nextInt(getWidth() - 19) + 10;
|
||||||
int ypos = PRNG.nextInt(getHeight() - 19) + 10;
|
int ypos = PRNG.nextInt(getHeight() - 19) + 10;
|
||||||
sprites.add(new TornadoSprite(this, xpos, ypos));
|
sprites.add(new TornadoSprite(this, xpos, ypos));
|
||||||
sendMessageAtPic(MicropolisMessage.TORNADO_REPORT, xpos, ypos);
|
sendMessageAt(MicropolisMessage.TORNADO_REPORT, xpos, ypos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void makeFlood()
|
public void makeFlood()
|
||||||
|
@ -2271,7 +2271,7 @@ public class Micropolis
|
||||||
if (isFloodable(c)) {
|
if (isFloodable(c)) {
|
||||||
setTile(xx, yy, FLOOD);
|
setTile(xx, yy, FLOOD);
|
||||||
floodCnt = 30;
|
floodCnt = 30;
|
||||||
sendMessageAtPic(MicropolisMessage.FLOOD_REPORT, xx, yy);
|
sendMessageAt(MicropolisMessage.FLOOD_REPORT, xx, yy);
|
||||||
floodX = xx;
|
floodX = xx;
|
||||||
floodY = yy;
|
floodY = yy;
|
||||||
return;
|
return;
|
||||||
|
@ -2403,7 +2403,7 @@ public class Micropolis
|
||||||
z = MicropolisMessage.POP_2K_REACHED;
|
z = MicropolisMessage.POP_2K_REACHED;
|
||||||
}
|
}
|
||||||
if (z != null) {
|
if (z != null) {
|
||||||
sendMessage(z, true);
|
sendMessage(z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastCityPop = newPop;
|
lastCityPop = newPop;
|
||||||
|
@ -2479,12 +2479,12 @@ public class Micropolis
|
||||||
break;
|
break;
|
||||||
case 35:
|
case 35:
|
||||||
if (pollutionAverage > 60) { // FIXME, consider changing threshold to 80
|
if (pollutionAverage > 60) { // FIXME, consider changing threshold to 80
|
||||||
sendMessage(MicropolisMessage.HIGH_POLLUTION, true);
|
sendMessage(MicropolisMessage.HIGH_POLLUTION);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 42:
|
case 42:
|
||||||
if (crimeAverage > 100) {
|
if (crimeAverage > 100) {
|
||||||
sendMessage(MicropolisMessage.HIGH_CRIME, true);
|
sendMessage(MicropolisMessage.HIGH_CRIME);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 45:
|
case 45:
|
||||||
|
@ -2537,22 +2537,12 @@ public class Micropolis
|
||||||
|
|
||||||
void sendMessage(MicropolisMessage message)
|
void sendMessage(MicropolisMessage message)
|
||||||
{
|
{
|
||||||
fireCityMessage(message, null, false);
|
fireCityMessage(message, null);
|
||||||
}
|
|
||||||
|
|
||||||
void sendMessage(MicropolisMessage message, boolean isPic)
|
|
||||||
{
|
|
||||||
fireCityMessage(message, null, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendMessageAt(MicropolisMessage message, int x, int y)
|
void sendMessageAt(MicropolisMessage message, int x, int y)
|
||||||
{
|
{
|
||||||
fireCityMessage(message, new CityLocation(x,y), false);
|
fireCityMessage(message, new CityLocation(x,y));
|
||||||
}
|
|
||||||
|
|
||||||
void sendMessageAtPic(MicropolisMessage message, int x, int y)
|
|
||||||
{
|
|
||||||
fireCityMessage(message, new CityLocation(x,y), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZoneStatus queryZoneStatus(int xpos, int ypos)
|
public ZoneStatus queryZoneStatus(int xpos, int ypos)
|
||||||
|
|
|
@ -61,4 +61,30 @@ public enum MicropolisMessage
|
||||||
|
|
||||||
// added by Jason
|
// added by Jason
|
||||||
NO_NUCLEAR_PLANTS;
|
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) {
|
switch (kind) {
|
||||||
case AIR:
|
case AIR:
|
||||||
city.crashLocation = new CityLocation(xpos, ypos);
|
city.crashLocation = new CityLocation(xpos, ypos);
|
||||||
city.sendMessageAtPic(MicropolisMessage.PLANECRASH_REPORT, xpos, ypos);
|
city.sendMessageAt(MicropolisMessage.PLANECRASH_REPORT, xpos, ypos);
|
||||||
break;
|
break;
|
||||||
case SHI:
|
case SHI:
|
||||||
city.crashLocation = new CityLocation(xpos, ypos);
|
city.crashLocation = new CityLocation(xpos, ypos);
|
||||||
city.sendMessageAtPic(MicropolisMessage.SHIPWRECK_REPORT, xpos, ypos);
|
city.sendMessageAt(MicropolisMessage.SHIPWRECK_REPORT, xpos, ypos);
|
||||||
break;
|
break;
|
||||||
case TRA:
|
case TRA:
|
||||||
case BUS:
|
case BUS:
|
||||||
city.crashLocation = new CityLocation(xpos, ypos);
|
city.crashLocation = new CityLocation(xpos, ypos);
|
||||||
city.sendMessageAtPic(MicropolisMessage.TRAIN_CRASH_REPORT, xpos, ypos);
|
city.sendMessageAt(MicropolisMessage.TRAIN_CRASH_REPORT, xpos, ypos);
|
||||||
break;
|
break;
|
||||||
case COP:
|
case COP:
|
||||||
city.crashLocation = new CityLocation(xpos, ypos);
|
city.crashLocation = new CityLocation(xpos, ypos);
|
||||||
city.sendMessageAtPic(MicropolisMessage.COPTER_CRASH_REPORT, xpos, ypos);
|
city.sendMessageAt(MicropolisMessage.COPTER_CRASH_REPORT, xpos, ypos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -141,7 +141,7 @@ public class DemandIndicator extends JComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
//implements Micropolis.Listener
|
//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 citySound(Sound sound, CityLocation p) { }
|
||||||
public void censusChanged() { }
|
public void censusChanged() { }
|
||||||
public void evaluationChanged() { }
|
public void evaluationChanged() { }
|
||||||
|
|
|
@ -242,7 +242,7 @@ public class EvaluationPane extends JPanel
|
||||||
}
|
}
|
||||||
|
|
||||||
//implements Micropolis.Listener
|
//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 citySound(Sound sound, CityLocation loc) {}
|
||||||
public void censusChanged() {}
|
public void censusChanged() {}
|
||||||
public void demandChanged() {}
|
public void demandChanged() {}
|
||||||
|
|
|
@ -143,7 +143,7 @@ public class GraphsPane extends JPanel
|
||||||
}
|
}
|
||||||
|
|
||||||
//implements Micropolis.Listener
|
//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 citySound(Sound sound, CityLocation loc) {}
|
||||||
public void demandChanged() {}
|
public void demandChanged() {}
|
||||||
public void evaluationChanged() {}
|
public void evaluationChanged() {}
|
||||||
|
|
|
@ -1540,11 +1540,11 @@ public class MainWindow extends JFrame
|
||||||
}
|
}
|
||||||
|
|
||||||
//implements Micropolis.Listener
|
//implements Micropolis.Listener
|
||||||
public void cityMessage(MicropolisMessage m, CityLocation p, boolean pictureMessage)
|
public void cityMessage(MicropolisMessage m, CityLocation p)
|
||||||
{
|
{
|
||||||
messagesPane.appendCityMessage(m);
|
messagesPane.appendCityMessage(m);
|
||||||
|
|
||||||
if (pictureMessage && p != null)
|
if (m.useNotificationPane && p != null)
|
||||||
{
|
{
|
||||||
notificationPane.showMessage(engine, m, p.x, p.y);
|
notificationPane.showMessage(engine, m, p.x, p.y);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue