package com.lucasdnd.ags.ui;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.util.FontUtils.Alignment;
import com.lucasdnd.ags.gameplay.Business;
import com.lucasdnd.ags.gameplay.Game;
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 ViewGamesListRow extends ListRow {
protected Game game; // The game this List Item refers to
private Button disposeButton; // Dispose Game
// Modification Control
private boolean deleteFlag; // Has been sold or not
boolean alreadyUpdatedRatingsSprite;
/**
* Market Game Constructor
* @param marketGame
* @throws SlickException
*/
public ViewGamesListRow(Game game, Business business, Market market) throws SlickException {
// The Game this List Row refers to
this.game = game;
// The Buttons
disposeButton = new Button(ResourceLoader.getInstance().sellButtonImages, 0, 0);
// Creates the Row Columns
columns = new ListColumn[8];
columns[0] = new ListColumn(0, game.getReferredMarketGame().getMarketConsole().getName(), Alignment.LEFT);
columns[0].setDataType(ListColumn.TEXT);
columns[1] = new ListColumn(1, game.getReferredMarketGame().getName(), Alignment.LEFT);
columns[1].setDataType(ListColumn.TEXT);
columns[2] = new ListColumn(2, "" + business.getStore().getNumberOfAvailableGames(game.getReferredMarketGame().getId()) + "/" + business.getStore().getNumberOfGames(game.getReferredMarketGame()), Alignment.CENTER);
columns[2].setDataType(ListColumn.NUMBER);
columns[3] = new ListColumn(3, ResourceLoader.getInstance().gameRatingImages[game.getReferredMarketGame().getQuality()], "" + game.getReferredMarketGame().getQuality(), 12, 4);
columns[3].setDataType(ListColumn.NUMBER);
/* Rent Price */
columns[4] = new ListColumn(4, GameSystem.printMoney(market.getGameRentPriceByDemand(game.getReferredMarketGame().getQuality()), false), Alignment.CENTER);
columns[4].setDataType(ListColumn.NUMBER);
/* Sell Price */
columns[5] = new ListColumn(5, GameSystem.printMoney(market.getGamePriceByDemand(game.getReferredMarketGame().getQuality()), false), Alignment.CENTER);
columns[5].setDataType(ListColumn.NUMBER);
/* Profit and Dispose */
columns[6] = new ListColumn(6, GameSystem.printMoney(game.getReferredMarketGame().getTotalProfit(), false), Alignment.CENTER);
columns[6].setDataType(ListColumn.NUMBER);
columns[7] = new ListColumn(7, disposeButton, 13, 3);
columns[7].setDataType(ListColumn.TEXT);
}
/**
* The update method, where we call the super class update (for mouse overs) and check for clicks.
*/
public void update(GameContainer container, StateBasedGame game, int delta, MainState mainState, Business business,
boolean leftMouseClicked, boolean leftMouseDown, int mouseX, int mouseY, ViewGamesList viewGamesList, boolean isShiftDown) throws SlickException {
// Super class update. This is where we check for mouse overs.
super.update(container, game, delta, business, leftMouseClicked, mouseX, mouseY,
this.game.getReferredMarketGame().getReleaseDate() <= mainState.getTimeController().getTime());
// Update the Available/Total amount
columns[2].setText("" + business.getStore().getNumberOfAvailableGames(this.game.getReferredMarketGame().getId()) + "/" + business.getStore().getNumberOfGames(this.game.getReferredMarketGame()));
// Update the Total Profit
columns[6].setText("" + GameSystem.printMoney(this.game.getReferredMarketGame().getTotalProfit(), false));
// Not modified yet
deleteFlag = false;
// Update the Buttons positions
disposeButton.setxPos(columns[7].getxPos() + columns[7].getImageLeftPadding());
disposeButton.setyPos(columns[7].getyPos() + columns[7].getImageTopPadding());
// Update the Buttons (check for mouse over)
disposeButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY);
// Dispose
if(disposeButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) {
deleteFlag = true;
}
// Updates the Rating Sprites
updateGameRatingSprite(mainState);
}
/**
* Creates the rectangle around the List Row
*
* This override adjusts the position of the rectangle so it stands around the Row without touching the borders of the Panel or the text
*/
@Override
public void createRectangle() {
float xPos = this.xPos - 5f;
float yPos = this.yPos;
float width = this.width + 7f;
float height = this.height;
rectangle = new Rectangle(xPos, yPos, width, height);
}
/**
* Update this game's Rating
* @throws SlickException
*/
public void updateGameRatingSprite(MainState mainState) throws SlickException {
columns[3].setBulletsImage(ResourceLoader.getInstance().gameRatingImages[game.getReferredMarketGame().getQuality()]);
columns[3].setText("" + game.getReferredMarketGame().getQuality());
columns[3].setImageLeftPadding(4);
columns[3].setImageTopPadding(4);
columns[3].setDataType(ListColumn.NUMBER);
}
public Game getGame() {
return game;
}
public void setgGame(Game game) {
this.game = game;
}
public boolean isDeleteFlag() {
return deleteFlag;
}
public void setDeleteFlag(boolean deleteFlag) {
this.deleteFlag = deleteFlag;
}
}