@Override
public void initState() throws SlickException {
this.colonies = new ArrayList<ColonySelector>();
for (Colony c : GameData.getColonies()) {
this.colonies.add(new ColonySelector(c, getRootPane()));
}
this.map = new HexagonMap(4, 5, 64);
int x = SIDEBAR_WIDTH + (Settings.WIDTH - SIDEBAR_WIDTH) / 2
- this.map.getWidth() / 2;
this.map.setOX(x);
this.map.setOY(Settings.HEIGHT / 2 - this.map.getHeight() / 2);
int i = 0;
for (Colony c : GameData.getColonies()) {
this.map.addColonyAt(c, i);
i++;
}
this.background = ImageManager.getGfx("space_background");
this.exploreButton = new ImageButton("exploration");
this.exploreButton.setTitle(I18n.get("planet.explore_sector"));
this.exploreButton.setActionHandler(new ActionHandler() {
@Override
public void run() {
if (PlanetState.this.selectedColony == null) {
// TODO play error sound
} else {
startZoneSelectionForExploration();
}
}
});
exploreButton.setHoverHandler(new ActionHandler() {
@Override
public void run() {
// Exploration = 2500 Gas
Map<Resource, BigDecimal> costMap = new HashMap<Resource, BigDecimal>();
costMap.put(Resource.GAS, BigDecimal.valueOf(2500));
resources.setMap(costMap);
resources.show();
}
});
add(this.exploreButton);
this.viewButton = new ImageButton("home");
this.viewButton.setTitle(I18n.get("planet.go_to_colony"));
this.viewButton.setActionHandler(new ActionHandler() {
@Override
public void run() {
if (PlanetState.this.selectedColony == null) {
// TODO play error sound
} else {
GameData.setSelectedColony(PlanetState.this.selectedColony);
GameData.getGame().enterState(AloneInSpace.SECTOR_STATE);
}
}
});
add(this.viewButton);
this.colonizeButton = new ImageButton("top_right_expand");
this.colonizeButton.setTitle(I18n.get("planet.colonize"));
this.colonizeButton.setActionHandler(new ActionHandler() {
@Override
public void run() {
if (PlanetState.this.selectedColony == null) {
// TODO play error sound
} else {
// TODO Externalize
Map<Resource, BigDecimal> costMap = new HashMap<Resource, BigDecimal>();
for (Resource r : Resource.values()) {
costMap.put(r, BigDecimal.valueOf(10000));
}
if (ResourceHelper.enoughResourcesFor(costMap)) {
startZoneSelectionForColonization();
} else {
// TODO Play error sound
}
}
}
});
this.colonizeButton.setHoverHandler(new ActionHandler() {
@Override
public void run() {
// Colonization = 10.000 each
Map<Resource, BigDecimal> costMap = new HashMap<Resource, BigDecimal>();
for (Resource r : Resource.values()) {
costMap.put(r, BigDecimal.valueOf(10000));
}
resources.setMap(costMap);
resources.show();
}
});
add(this.colonizeButton);
transferButton = new ImageButton("transfer");
transferButton.setTitle(I18n.get("planet.transfer"));
transferButton.setActionHandler(new ActionHandler() {
@Override
public void run() {
transferWindow.show();
}
});
add(transferButton);
this.showNewColonyWindow = false;
this.createColonyButton = new TextButton(I18n.get("global.ok"));
this.createColonyButton.setWidth(80);
this.createColonyButton.setActionHandler(new ActionHandler() {
@Override
public void run() {
final Colony c = new Colony();
c.setName(PlanetState.this.colonyNameField.getText());
PlanetState.this.colonyNameField.setText("");
try {
c.setMap(new TiledMap("data/testmap.tmx"));
} catch (SlickException e) {
// TODO Handle TiledMap loading in a manager
e.printStackTrace();
}
c.setResource(Resource.CRISTAL, BigDecimal.valueOf(1000));
c.setResource(Resource.ENERGY, BigDecimal.valueOf(1000));
c.setResource(Resource.FOOD, BigDecimal.valueOf(1000));
c.setResource(Resource.GAS, BigDecimal.valueOf(1000));
final int selectedIndex = PlanetState.this.map
.getSelectedZone();
final HexagonMapAction a = new HexagonMapAction(2,
PlanetState.this.map, PlanetState.this.map
.getSelectedZone());
a.setExploration(false);
a.setCallback(new Runnable() {
@Override
public void run() {
GameData.putInPool(c);
PlanetState.this.map.addColonyAt(c, selectedIndex);
// Create the new selector
PlanetState.this.colonies.add(new ColonySelector(c,
getRootPane()));
}
});
GameData.addHexagonMapAction(a);