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.system.MainState; import com.lucasdnd.ags.system.ResourceLoader; public class FinancesList extends List { private final int rows = 11; private final int columns = 9; private int[][] values; /** * Basic Constructor * @param listHeaders * @param listRows */ public FinancesList(float xPos, float yPos, float width, float height, Business business) 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; // Create the List listRows = new ArrayList<ListRow>(); for(int i = 0; i < rows; i++) { listRows.add(new FinancesListRow(business, i)); } // Create the values values = new int[rows][columns]; for(int r = 0; r < rows; r++) { for(int c = 0; c < columns; c++) { values[r][c] = 0; } } // Now let's create the Headers... listHeaders = new ListHeader[10]; listHeaders[0] = new ListHeader(0, "", Alignment.LEFT, this.xPos + leftMargin, this.yPos + topMargin + lineSize, 210f, lineSize); listHeaders[1] = new ListHeader(1, "Month 1", Alignment.RIGHT, listHeaders[0].xPos + listHeaders[0].width, this.yPos + topMargin + lineSize, 120f, lineSize); listHeaders[2] = new ListHeader(2, "Month 2", Alignment.RIGHT, listHeaders[1].xPos + listHeaders[1].width, this.yPos + topMargin + lineSize, 120f, lineSize); listHeaders[3] = new ListHeader(3, "Month 3", Alignment.RIGHT, listHeaders[2].xPos + listHeaders[2].width, this.yPos + topMargin + lineSize, 120f, lineSize); listHeaders[4] = new ListHeader(4, "Month 4", Alignment.RIGHT, listHeaders[3].xPos + listHeaders[3].width, this.yPos + topMargin + lineSize, 120f, lineSize); listHeaders[5] = new ListHeader(5, "Month 5", Alignment.RIGHT, listHeaders[4].xPos + listHeaders[4].width, this.yPos + topMargin + lineSize, 120f, lineSize); listHeaders[6] = new ListHeader(6, "Month 6", Alignment.RIGHT, listHeaders[5].xPos + listHeaders[5].width, this.yPos + topMargin + lineSize, 120f, lineSize); listHeaders[7] = new ListHeader(7, "Month 7", Alignment.RIGHT, listHeaders[6].xPos + listHeaders[6].width, this.yPos + topMargin + lineSize, 120f, lineSize); listHeaders[8] = new ListHeader(8, "Month 8", Alignment.RIGHT, listHeaders[7].xPos + listHeaders[7].width, this.yPos + topMargin + lineSize, 120f, lineSize); listHeaders[9] = new ListHeader(9, "Month 9", Alignment.RIGHT, listHeaders[8].xPos + listHeaders[8].width, this.yPos + topMargin + lineSize, 120f, lineSize); } /** * Specific update method for the View Games List */ public void update(GameContainer container, StateBasedGame game, int delta, MainState mainState, Business business, boolean leftMouseClicked, int mouseX, int mouseY) throws SlickException { // Super Class update super.update(container, game, delta, business, leftMouseClicked, false, mouseX, mouseY); // Adjust the columns and rows positions super.updateRowsPositions(); // Update the List Headers texts (with the name of each month) int currentIndex = business.getBuyingGamesCosts().size(); for(int i = 1; i < listHeaders.length; i++) { int month = (int)((currentIndex + i - 5) % 12); if(month == 0) month = 12; int year = 1989 + (int)((currentIndex + i) / 12); listHeaders[listHeaders.length - i].setText(month + "/" + year); } // Update the values // If this gets slow, do a delta counter to update in an interval for(int c = 0; c < columns; c++) { int columnTotal = 0; for(int r = 0; r < rows - 1; r++) { // Get the corresponding value int val = 0; int i = currentIndex - c - 1; switch(r) { case Business.BUYING_GAME: val = business.getBuyingGamesCosts().get(i); break; case Business.BUYING_CONSOLE: val = business.getBuyingConsolesCosts().get(i); break; case Business.BUYING_ASSET: val = business.getBuyingAssetsCosts().get(i); break; case Business.BUYING_MAP: val = business.getBuyingMapCosts().get(i); break; case Business.PAYING_BILLS: val = business.getBillsCosts().get(i); break; case Business.SELLING_GAME: val = business.getSalesReceipt().get(i); break; case Business.RENTING_GAME: val = business.getRentReceipt().get(i); break; case Business.PLAYING_GAME: val = business.getPlaysReceipt().get(i); break; case Business.DISPOSING: val = business.getDisposalReceipt().get(i); break; case 11: // Totals row, do nothing here break; default: break; } values[r][c] = val; columnTotal += values[r][c]; } // Set the total to the last row values[rows - 1][c] = columnTotal; } } @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 int r = 0; for(ListRow lr : listRows) { if (r == rows - 2) { // Skip the row before the last, to separate the totals row r++; continue; } ((FinancesListRow)lr).render(container, game, g, ResourceLoader.getInstance().tinyGreenFont, ResourceLoader.getInstance().tinyRedFont, shadowFont, values[r]); r++; } } public int getColumns() { return columns; } }