package com.lucasdnd.ags.ui; import java.text.SimpleDateFormat; import java.util.Date; import org.newdawn.slick.GameContainer; 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.gameplay.market.MarketGame; import com.lucasdnd.ags.system.GameSystem; import com.lucasdnd.ags.system.MainState; import com.lucasdnd.ags.system.ResourceLoader; public class BuyGamesListRow extends ListRow { // The game this List Item refers to protected MarketGame referringMarketGame; private boolean alreadyUpdatedRatingsSprite = false; /** * Market Game Constructor * @param marketGame * @throws SlickException */ public BuyGamesListRow(MarketGame marketGame, Business business) throws SlickException { // The referring Product this.referringMarketGame = marketGame; // Creates the Row Columns columns = new ListColumn[6]; columns[0] = new ListColumn(0, referringMarketGame.getMarketConsole().getName(), Alignment.LEFT); columns[0].setDataType(ListColumn.TEXT); columns[1] = new ListColumn(1, referringMarketGame.getName(), Alignment.LEFT); columns[1].setDataType(ListColumn.TEXT); columns[2] = new ListColumn(2, "" + business.getStore().getNumberOfGames(referringMarketGame), Alignment.CENTER); columns[2].setDataType(ListColumn.NUMBER); columns[3] = new ListColumn(3, "?", Alignment.CENTER); columns[3].setDataType(ListColumn.TEXT); columns[4] = new ListColumn(4, GameSystem.printMoney(referringMarketGame.getPrice(), false), Alignment.RIGHT); columns[4].setDataType(ListColumn.NUMBER); columns[5] = new ListColumn(5, "" + new SimpleDateFormat("dd/MM/yyyy").format(new Date(referringMarketGame.getReleaseDate())), Alignment.RIGHT); columns[5].setDataType(ListColumn.DATE); } /** * 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, ViewGamesList viewGamesList, Market market, boolean leftMouseClicked, int mouseX, int mouseY, boolean updateQuantities) throws SlickException { // Super class update. This is where we check for mouse overs. super.update(container, game, delta, business, leftMouseClicked, mouseX, mouseY, referringMarketGame.getReleaseDate() <= mainState.getTimeController().getTime()); // Check if this List Row has been clicked if(isAvailable && gotLeftClicked(leftMouseClicked, mouseX, mouseY)) { // If it has, we buy the game business.buyGame((MarketGame)referringMarketGame); // Update the Inventory List viewGamesList.recreateList(business, market); // Updates the Quantity Column updateQuantityText(business); } // Updates the Rating Sprites, only if this ListRow hasn't been updated yet. if(!alreadyUpdatedRatingsSprite) { updateGameRatingSprite(mainState); } } /** * Updates the Quantity column * @param business * @param viewGamesList * @throws SlickException */ protected void updateQuantityText(Business business) { // Update the quantity text columns[2].setText("" + business.getStore().getNumberOfGames(referringMarketGame)); } /** * Update this game's Rating * @throws SlickException */ public void updateGameRatingSprite(MainState mainState) throws SlickException { if(referringMarketGame.isUnlocked() && referringMarketGame.getReleaseDate() <= mainState.getTimeController().getTime()) { columns[3].setBulletsImage(ResourceLoader.getInstance().gameRatingImages[referringMarketGame.getQuality()]); columns[3].setText("" + referringMarketGame.getQuality()); columns[3].setImageLeftPadding(4); columns[3].setImageTopPadding(4); columns[3].setDataType(ListColumn.NUMBER); alreadyUpdatedRatingsSprite = true; columns[4].setText(GameSystem.printMoney(referringMarketGame.getPrice(), false)); columns[4].setTextAlignment(Alignment.RIGHT); } else { columns[3].setText("?"); columns[3].setTextAlignment(Alignment.CENTER); columns[3].setDataType(ListColumn.NUMBER); columns[4].setText("? "); columns[4].setTextAlignment(Alignment.RIGHT); } } public MarketGame getReferringMarketGame() { return referringMarketGame; } public void setReferringMarketGame(MarketGame referringMarketGame) { this.referringMarketGame = referringMarketGame; } }