package com.lucasdnd.ags.ui;
import java.util.ArrayList;
import org.newdawn.slick.Font;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.util.FontUtils.Alignment;
import com.lucasdnd.ags.gameplay.Business;
import com.lucasdnd.ags.gameplay.market.Market;
import com.lucasdnd.ags.system.GameSystem;
import com.lucasdnd.ags.system.MainState;
import com.lucasdnd.ags.system.ResourceLoader;
public class ManagementList extends List {
/**
* Basic Constructor
* @param listHeaders
* @param listRows
*/
public ManagementList(float xPos, float yPos, float width, float height, Business business, Market market) throws SlickException {
// Super Class Constructor (for the arrow buttons)
super(xPos, yPos, width, height);
// Get the Objects that will define this List
this.xPos = xPos;
this.yPos = yPos;
this.width = width;
this.height = height;
// Now let's create the Headers...
listHeaders = new ListHeader[20];
listHeaders[0] = new ListHeader(0, "Demand", Alignment.CENTER, this.xPos + leftMargin - 8f, this.yPos + topMargin + lineSize, 120f, lineSize);
listHeaders[1] = new ListHeader(1, "",/*minus*/ Alignment.CENTER, listHeaders[0].xPos + listHeaders[0].width, this.yPos + topMargin + lineSize, 32f, lineSize);
listHeaders[2] = new ListHeader(2, "Rent Price", Alignment.CENTER, listHeaders[1].xPos + listHeaders[1].width, this.yPos + topMargin + lineSize, 80f, lineSize);
listHeaders[3] = new ListHeader(3, "",/*plus*/ Alignment.CENTER, listHeaders[2].xPos + listHeaders[2].width, this.yPos + topMargin + lineSize, 32f, lineSize);
listHeaders[4] = new ListHeader(4, "",/*minus*/ Alignment.CENTER, listHeaders[3].xPos + listHeaders[3].width, this.yPos + topMargin + lineSize, 32f, lineSize);
listHeaders[5] = new ListHeader(5, "Sell Price", Alignment.CENTER, listHeaders[4].xPos + listHeaders[4].width, this.yPos + topMargin + lineSize, 80f, lineSize);
listHeaders[6] = new ListHeader(6, "",/*plus*/ Alignment.CENTER, listHeaders[5].xPos + listHeaders[5].width, this.yPos + topMargin + lineSize, 32f, lineSize);
listHeaders[7] = new ListHeader(7, "",/*minus*/ Alignment.CENTER, listHeaders[6].xPos + listHeaders[6].width, this.yPos + topMargin + lineSize, 32f, lineSize);
listHeaders[8] = new ListHeader(8, "Min. Play Stock",Alignment.CENTER, listHeaders[7].xPos + listHeaders[7].width, this.yPos + topMargin + lineSize, 140f, lineSize);
listHeaders[9] = new ListHeader(9, "",/*plus*/ Alignment.CENTER, listHeaders[8].xPos + listHeaders[8].width, this.yPos + topMargin + lineSize, 32f, lineSize);
listHeaders[10] = new ListHeader(10, "",/*minus*/ Alignment.CENTER, listHeaders[9].xPos + listHeaders[9].width, this.yPos + topMargin + lineSize, 32f, lineSize);
listHeaders[11] = new ListHeader(11, "Min. Rent Stock", Alignment.CENTER, listHeaders[10].xPos + listHeaders[10].width, this.yPos + topMargin + lineSize, 140f, lineSize);
listHeaders[12] = new ListHeader(12, "",/*plus*/ Alignment.CENTER, listHeaders[11].xPos + listHeaders[11].width, this.yPos + topMargin + lineSize, 32f, lineSize);
listHeaders[13] = new ListHeader(13, "",/*minus*/ Alignment.CENTER, listHeaders[12].xPos + listHeaders[12].width, this.yPos + topMargin + lineSize, 32f, lineSize);
listHeaders[14] = new ListHeader(14, "Min. Sale Stock", Alignment.CENTER, listHeaders[13].xPos + listHeaders[13].width, this.yPos + topMargin + lineSize, 140f, lineSize);
listHeaders[15] = new ListHeader(15, "",/*plus*/ Alignment.CENTER, listHeaders[14].xPos + listHeaders[14].width, this.yPos + topMargin + lineSize, 32f, lineSize);
listHeaders[16] = new ListHeader(16, "Play", Alignment.CENTER, listHeaders[15].xPos + listHeaders[15].width, this.yPos + topMargin + lineSize, 60f, lineSize);
listHeaders[17] = new ListHeader(17, "Rent", Alignment.CENTER, listHeaders[16].xPos + listHeaders[16].width, this.yPos + topMargin + lineSize, 60f, lineSize);
listHeaders[18] = new ListHeader(18, "Sell", Alignment.CENTER, listHeaders[17].xPos + listHeaders[17].width, this.yPos + topMargin + lineSize, 60f, lineSize);
listHeaders[19] = new ListHeader(19, "Restock", Alignment.CENTER, listHeaders[18].xPos + listHeaders[18].width, this.yPos + topMargin + lineSize, 110f, lineSize);
recreateList(business, market);
}
/**
* Specific update method for the View Games List
*/
public void update(GameContainer container, StateBasedGame game, int delta, MainState mainState, Business business,
boolean leftMouseClicked, boolean leftMouseDown, int mouseX, int mouseY, boolean isShiftDown) throws SlickException {
// Super Class update
super.update(container, game, delta, business, leftMouseClicked, leftMouseDown, mouseX, mouseY);
// Check for updates
for(ListRow lr : listRows) {
ManagementListRow mlr = (ManagementListRow)lr;
mlr.update(container, game, delta, mainState, business, leftMouseClicked, leftMouseDown, mouseX, mouseY, isShiftDown);
int rowId = mlr.getRowId();
// Check for any price changes
if (mlr.isRentPriceModified()) {
// Rent Price Change
int rentPriceChange = mlr.getRentPriceChange();
mainState.getMarket().changeRentPrice(rowId, rentPriceChange);
mlr.getListColumns()[2].setText(GameSystem.printMoney(mainState.getMarket().getGameRentPriceByDemand(rowId), false));
} else if (mlr.isSellPriceModified()) {
// Sell Price Change
int sellPriceChange = mlr.getSellPriceChange();
mainState.getMarket().changeSellPrice(rowId, sellPriceChange);
mlr.getListColumns()[5].setText(GameSystem.printMoney(mainState.getMarket().getGamePriceByDemand(rowId), false));
} else if (mlr.isPlayStockModified()) {
// Play Stock change
int playStockChange = mlr.getPlayStockChange();
int currentPlayStock = mainState.getMarket().getPlayStockByDemand(rowId);
if (playStockChange == -1 && currentPlayStock > 0) {
currentPlayStock--;
} else if (playStockChange == 1 && currentPlayStock < 99) {
currentPlayStock++;
}
mainState.getMarket().setPlayStockByDemand(rowId, currentPlayStock);
mlr.getListColumns()[8].setText("" + mainState.getMarket().getPlayStockByDemand(rowId));
} else if (mlr.isRentStockModified()) {
// Rent Stock change
int rentStockChange = mlr.getRentStockChange();
int currentRentStock = mainState.getMarket().getRentStockByDemand(rowId);
if (rentStockChange == -1 && currentRentStock > 0) {
currentRentStock--;
} else if (rentStockChange == 1 && currentRentStock < 99) {
currentRentStock++;
}
mainState.getMarket().setRentStockByDemand(rowId, currentRentStock);
mlr.getListColumns()[11].setText("" + mainState.getMarket().getRentStockByDemand(rowId));
} else if (mlr.isSaleStockModified()) {
// Sale Stock change
int saleStockChange = mlr.getSaleStockChange();
int currentSaleStock = mainState.getMarket().getSaleStockByDemand(rowId);
if (saleStockChange == -1 && currentSaleStock > 0) {
currentSaleStock--;
} else if (saleStockChange == 1 && currentSaleStock < 99) {
currentSaleStock++;
}
mainState.getMarket().setSaleStockByDemand(rowId, currentSaleStock);
mlr.getListColumns()[14].setText("" + mainState.getMarket().getSaleStockByDemand(rowId));
} else if (mlr.isPlayAvailableModified()) {
// Change Play Available status
boolean isPlayAvailable = mlr.getPlayCheckBox().isSelected();
mainState.getMarket().setPlayAvailableByDemand(rowId, isPlayAvailable);
} else if (mlr.isRentAvailableModified()) {
// Change Rent Available status
boolean isRentAvailable = mlr.getRentCheckBox().isSelected();
mainState.getMarket().setRentAvailableByDemand(rowId, isRentAvailable);
} else if (mlr.isSaleAvailableModified()) {
// Change Sale Available status
boolean isSaleAvailable = mlr.getSaleCheckBox().isSelected();
mainState.getMarket().setSaleAvailableByDemand(rowId, isSaleAvailable);
} else if (mlr.isAutoRestockModified()) {
// Change auto restock status
boolean isAutoRestockAvailable = mlr.getRestockCheckBox().isSelected();
mainState.getMarket().setAutoRestockByDemand(rowId, isAutoRestockAvailable);
}
}
}
/**
* Recreates the list. This is called when the list structure changes (adds or removes an item)
* @param business
* @throws SlickException
*/
public void recreateList(Business business, Market market) throws SlickException {
// We create the List Row
listRows = new ArrayList<ListRow>();
// We read the numberOfGames Array to assist us
for(int i = 0; i < 5; i++) {
listRows.add(new ManagementListRow(i, business, market));
}
// And update their positions
super.updateRowsPositions();
}
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont) throws SlickException {
// Renders the List Headers
for(ListHeader lh : listHeaders) {
lh.render(container, game, g, panelFont, disabledFont, shadowFont);
}
// Renders the List Rows
for(ListRow lr : listRows) {
((ManagementListRow)lr).render(container, game, g, ResourceLoader.getInstance().tinyGreenFont, ResourceLoader.getInstance().tinyRedFont, shadowFont);
}
}
}