package com.lucasdnd.ags.ui; 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 com.lucasdnd.ags.gameplay.Business; import com.lucasdnd.ags.gameplay.Shelf; import com.lucasdnd.ags.system.GameSystem; import com.lucasdnd.ags.system.MainState; import com.lucasdnd.ags.system.ResourceLoader; public class ShelfMiniPanel extends MiniPanel { // Shelf private Shelf shelf; // Buttons private Button moveShelfButton; private Button sellShelfButton; // Total Shelf capacity and current use private int totalShelfCapacity; private int totalNumberOfGames; /** * Constructor * @param title * @param xPos * @param yPos * @param width * @param height * @param mapAsset * @throws SlickException */ public ShelfMiniPanel(float xPos, float yPos, float width, float height, Shelf shelf) throws SlickException { // Super Class Constructor super(shelf.getReferringMarketAsset().getName(), xPos, yPos, width, height); // The Shelf! this.shelf = shelf; // The Buttons! moveShelfButton = new Button(ResourceLoader.getInstance().moveButtonImages, xPos, yPos); sellShelfButton = new Button(ResourceLoader.getInstance().sellButtonImages, xPos, yPos); } /** * Update! */ public void update(GameContainer container, StateBasedGame game, int delta, MainState mainState, Business business, boolean leftMouseClicked, boolean leftMouseDown, int mouseX, int mouseY) throws SlickException { // Only if visible! if(visible) { // Super Class Update super.update(container, game, delta, business, leftMouseClicked, mouseX, mouseY); // Fix Button Positions, check for Mouse Overs moveShelfButton.setxPos(xPos + width - moveShelfButton.getWidth()); moveShelfButton.setyPos(yPos + 1f); moveShelfButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY); sellShelfButton.setxPos(xPos + leftMargin); sellShelfButton.setyPos(yPos + topBodyMargin + lineSize); sellShelfButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY); // Update the amount of Games and capacity totalNumberOfGames = business.getStore().getGames().size(); totalShelfCapacity = business.getStore().getGameStorageLimit(); // If this Shelf can move, it can be moved or deleted if(shelf.canMove()) { // Move Shelf if(moveShelfButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) { // Set the Moving Asset mainState.setSelectedEntity(shelf); mainState.setPlacingAsset(shelf); mainState.getPlacingAsset().setBeingMoved(true); // Hide the Panel this.visible = false; // Enter Moving Asset Mode mainState.setCurrentMode(MainState.MOVING_ASSET); // Unblock the Tiles it currently occupies (so we can freely move it into tiles it already blocks) business.getStore().getMap().removeObject(shelf); } // Sell Shelf if(sellShelfButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) { // Check if there's capacity to hold all the games after removing this shelf int numGames = business.getStore().getGames().size(); int newCapacity = business.getStore().getGameStorageLimit() - shelf.getCapacity(); if (newCapacity >= numGames) { // Remove asset from map business.getStore().removeCharacterReferences(shelf); business.getStore().getMap().removeObject(shelf); // Pay the player business.makeBusiness((int)(shelf.getReferringMarketAsset().getPrice() * 0.4), Business.DISPOSING, true); shelf.setCanBeDisposed(true); mainState.setCurrentMode(MainState.SELECTION_MODE); } else { // Can't sell! ResourceLoader.getInstance().popSound.play(); mainState.getTooltip().show("You have too many games to sell this shelf!"); } } } } } /** * Render! */ @Override public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font shadowFont) throws SlickException { // Only if visible! if(visible) { // Super Class Render super.render(container, game, g, panelFont, shadowFont); // Title shadowFont.drawString(xPos + leftMargin + 1f, yPos + topHeaderMargin + 1f, shelf.getReferringMarketAsset().getName()); panelFont.drawString(xPos + leftMargin, yPos + topHeaderMargin, shelf.getReferringMarketAsset().getName()); // Capacity shadowFont.drawString(xPos + leftMargin + 1f, yPos + topBodyMargin + 1f, "Games capacity: " + totalNumberOfGames + "/" + totalShelfCapacity); panelFont.drawString(xPos + leftMargin, yPos + topBodyMargin, "Games capacity: " + totalNumberOfGames + "/" + totalShelfCapacity); // Render Buttons! moveShelfButton.render(container, game, g); sellShelfButton.render(container, game, g); shadowFont.drawString(sellShelfButton.getxPos() + sellShelfButton.getWidth() + leftMargin + 1f, sellShelfButton.getyPos() + 2f + 1f, "Sell for $ " + GameSystem.printMoney((int)(shelf.getReferringMarketAsset().getPrice() * 0.4), false)); panelFont.drawString(sellShelfButton.getxPos() + sellShelfButton.getWidth() + leftMargin, sellShelfButton.getyPos() + 2f, "Sell for $ " + GameSystem.printMoney((int)(shelf.getReferringMarketAsset().getPrice() * 0.4), false)); } } }