package com.lucasdnd.ags.ui; import java.util.ArrayList; import org.newdawn.slick.GameContainer; import org.newdawn.slick.SlickException; import org.newdawn.slick.state.StateBasedGame; import com.lucasdnd.ags.gameplay.Business; import com.lucasdnd.ags.gameplay.market.MarketMisc; import com.lucasdnd.ags.gameplay.market.MarketShelf; import com.lucasdnd.ags.gameplay.market.MarketTable; import com.lucasdnd.ags.gameplay.market.MarketTv; import com.lucasdnd.ags.system.MainState; public class BuyFurnituresList extends List { // The sizes, padding, margins, etc. protected float lineSize = 130f; // The size of one row in the list private float previousLineSize = 25f; // The row size in the other Lists protected final float leftMargin = 19f; // Left margin, between the List and the left border of the Panel protected final float topMargin = 3f; // Top margin, between the List and the Tile Bar /** * Basic Constructor * @param listHeaders * @param listRows */ public BuyFurnituresList(float xPos, float yPos, float width, float height, Business business, ArrayList<MarketShelf> marketShelfs, ArrayList<MarketTable> marketTables, ArrayList<MarketTv> marketTvs, ArrayList<MarketMisc> marketMiscs) throws SlickException { super(xPos, yPos, width, height); pageSize = 4; // Let's create the List of Items listRows = new ArrayList<ListRow>(); if(marketShelfs != null) { for(int i = 0; i < marketShelfs.size(); i++) { listRows.add(new BuyFurnituresListRow(marketShelfs.get(i), business)); } } if(marketTables != null) { for(int i = 0; i < marketTables.size(); i++) { listRows.add(new BuyFurnituresListRow(marketTables.get(i), business)); } } if(marketTvs != null) { for(int i = 0; i < marketTvs.size(); i++) { listRows.add(new BuyFurnituresListRow(marketTvs.get(i), business)); } } if(marketMiscs != null) { for(int i = 0; i < marketMiscs.size(); i++) { listRows.add(new BuyFurnituresListRow(marketMiscs.get(i), business)); } } // Creates the Rectangle around the List Row using the right parameters this.updateRowsPositions(); for(ListRow lr : listRows) lr.createRectangle(); } /** * Specific update method for the Buy Furnitures List. * @param container * @param game * @param delta * @param business * @param mapState * @param leftMouseClicked * @param mouseX * @param mouseY * @throws SlickException */ public void update(GameContainer container, StateBasedGame game, int delta, Business business, MainState mapState, boolean leftMouseClicked, boolean leftMouseDown, int mouseX, int mouseY) throws SlickException { // Super class update (since we're not overriding) super.update(container, game, delta, business, leftMouseClicked, leftMouseDown, mouseX, mouseY); // Updates the List Rows for(int i = 0; i < listRows.size(); i++) { // With this if statement, we make sure we update only what's in the current page if((i >= page * pageSize) && (i <= (page + 1) * (pageSize - 1))) { BuyFurnituresListRow bflr = (BuyFurnituresListRow)listRows.get(i); bflr.update(container, game, delta, business, mapState, leftMouseClicked, mouseX, mouseY); } } } /** * Updates the position and size of the List Rows. * This should be called every time the user changes the page he's browsing */ @Override public void updateRowsPositions() { // Goes through each List Row for(int i = 0; i < listRows.size(); i++) { // Define the size and dimension of each List Row listRows.get(i).setxPos(this.getxPos() - 2f); listRows.get(i).setyPos(this.getyPos() + topMargin + previousLineSize + (i - (page * pageSize)) * lineSize); listRows.get(i).setWidth(this.getWidth() + 4f); listRows.get(i).setHeight(lineSize); } } }