Show Telescreen.java syntax highlighted
/*
* Copyright (C) 2001-2005 Pleasant nightmare studio
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.pleasantnightmare.riotinecity.entities;
import org.pleasantnightmare.riotinecity.model.Model;
import org.pleasantnightmare.riotinecity.model.TelescreenModel;
import org.pleasantnightmare.riotinecity.spatials.Digipad;
import org.pleasantnightmare.riotinecity.spatials.Input;
import org.pleasantnightmare.riotinecity.spatials.TelescreenSpatial;
/**
* @author: deus
* @since: Jun 8, 2007 7:42:38 AM
* @version: 1.0
*/
public class Telescreen extends Entity implements Toggleable, InputReceiver {
private TelescreenModel model;
private TelescreenSpatial spatial;
private InputAction changeChannelAction;
public Telescreen(TelescreenModel model, Input digipad) {
this.model = model;
changeChannelAction = new InputAction("Change channel", "digipad", digipad, this);
actions.add(new ToggleAction("On/Off", this, false));
}
// TODO INVERSE Model/view/controller CONNECTION!!!
public void setSpatial(TelescreenSpatial spatial) {
this.spatial = spatial;
toggleOff();
}
public String getType() {
return "telescreen";
}
@Override
public Model getModel() {
return model;
}
public void toggleOn() {
retextureToChannel(model.lastChannel());
actions.add(changeChannelAction);
}
public void toggleOff() {
retextureToChannel(model.getOffChannel());
actions.remove(changeChannelAction);
}
public void inputReceived(Input source, String input) {
if (input.equals(Digipad.RETURN)
|| input.equals(Digipad.DELETE)) {
source.hide();
return;
}
int channelNumber = Integer.parseInt(input);
String channel = model.getChannelByNumber(channelNumber);
if (channel.equals(model.lastChannel()))
return;
retextureToChannel(channel);
model.rememberLastChannel(channelNumber);
}
private void retextureToChannel(String channel) {
if (channel.equals("politics"))
spatial.setScreenTexture("images/telescreen-politics.jpg");
else if (channel.equals("war"))
spatial.setScreenTexture("images/telescreen-war.png");
else if (channel.equals("commercials"))
spatial.setScreenTexture("images/telescreen-commercials.png");
else if (channel.equals("movies"))
spatial.setScreenTexture("images/telescreen-movies.png");
else
spatial.setScreenTexture("images/telescreen-off.png");
}
}
See more files for this project here