package com.lucasdnd.ags.ui; import org.newdawn.slick.Color; import org.newdawn.slick.Font; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; import org.newdawn.slick.SlickException; import org.newdawn.slick.geom.Rectangle; import org.newdawn.slick.state.StateBasedGame; import com.lucasdnd.ags.gameplay.Business; import com.lucasdnd.ags.gameplay.Table; import com.lucasdnd.ags.system.GameSystem; import com.lucasdnd.ags.system.MainState; import com.lucasdnd.ags.system.ResourceLoader; public class TableMiniPanel extends MiniPanel { // Table private Table table; // Buttons private Button moveTvButton; private Button sellTvButton; private Button moveConsoleButton; private Button sellConsoleButton; private Button increasePriceButton; private Button decreasePriceButton; private float plusButtonOffset; private Button moveTableButton; private Button sellTableButton; // Panel Addons for Console and Tv protected Rectangle consoleTitleBar; protected Rectangle tvTitleBar; protected Color consoleTitleBarBackground; protected Color tvTitleBarBackground; protected float consoleTitleYOffset = topBodyMargin + lineSize; protected float tvTitleYOffset = consoleTitleYOffset + lineSize * 3; /** * Constructor * @param title * @param xPos * @param yPos * @param width * @param height * @param mapAsset * @throws SlickException */ public TableMiniPanel(float xPos, float yPos, float width, float height, Table table) throws SlickException { // Super Class Constructor super(table.getReferringMarketAsset().getName(), xPos, yPos, width, height); // The Table! this.table = table; // The Buttons! moveTvButton = new Button(ResourceLoader.getInstance().moveButtonImages, xPos, yPos); sellTvButton = new Button(ResourceLoader.getInstance().sellButtonImages, xPos, yPos); moveConsoleButton = new Button(ResourceLoader.getInstance().moveButtonImages, xPos, yPos); sellConsoleButton = new Button(ResourceLoader.getInstance().sellButtonImages, xPos, yPos); increasePriceButton = new Button(ResourceLoader.getInstance().plusButtonImages, xPos, yPos); decreasePriceButton = new Button(ResourceLoader.getInstance().minusButtonImages, xPos, yPos); moveTableButton = new Button(ResourceLoader.getInstance().moveButtonImages, xPos, yPos); sellTableButton = new Button(ResourceLoader.getInstance().sellButtonImages, xPos, yPos); // Extra Titles for Console and Tv consoleTitleBar = new Rectangle(xPos, yPos + consoleTitleYOffset, width, lineSize); tvTitleBar = new Rectangle(xPos, yPos + tvTitleYOffset, width, lineSize); consoleTitleBarBackground = new Color(192f / 255f, 191f / 255f, 235f / 255f, 1f); tvTitleBarBackground = new Color(192f / 255f, 191f / 255f, 235f / 255f, 1f); } /** * Update! */ public void update(GameContainer container, StateBasedGame game, int delta, MainState mainState, Business business, boolean leftMouseClicked, boolean leftMouseDown, int mouseX, int mouseY, boolean isShiftDown) throws SlickException { // Only if visible! if(visible) { // Super Class Update super.update(container, game, delta, business, leftMouseClicked, mouseX, mouseY); // Console and TV section positions tvTitleYOffset = consoleTitleYOffset + lineSize * 4 + 16f; consoleTitleYOffset = topBodyMargin + lineSize + 2f; consoleTitleBar.setLocation(xPos, yPos + consoleTitleYOffset); tvTitleBar.setLocation(xPos, yPos + tvTitleYOffset); // Tv Buttons moveTvButton.setxPos(xPos + width - moveTableButton.getWidth()); moveTvButton.setyPos(yPos + tvTitleYOffset + 1f); moveTvButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY); sellTvButton.setxPos(xPos + leftMargin); sellTvButton.setyPos(yPos + + topHeaderMargin + tvTitleYOffset + lineSize * 2f + 8f); sellTvButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY); // Console Buttons moveConsoleButton.setxPos(xPos + width - moveTableButton.getWidth()); moveConsoleButton.setyPos(yPos + consoleTitleYOffset + 1f); moveConsoleButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY); sellConsoleButton.setxPos(xPos + leftMargin); sellConsoleButton.setyPos(yPos + topBodyMargin + lineSize*2 + consoleTitleYOffset); sellConsoleButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY); // Increase and Decrease Price Buttons if(table.getConsole() != null) { // Increase and Decrease Price Buttons if(table.getConsole().getReferringMarketConsole().getPlayPrice() >= 1000) { plusButtonOffset = 12f; } else { plusButtonOffset = 0f; } decreasePriceButton.setxPos(xPos + 230f); decreasePriceButton.setyPos(yPos + topBodyMargin + consoleTitleYOffset - 2f); decreasePriceButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY); increasePriceButton.setxPos(decreasePriceButton.xPos + plusButtonOffset + priceButtonSeparation); increasePriceButton.setyPos(decreasePriceButton.yPos); increasePriceButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY); } // Table Buttons moveTableButton.setxPos(xPos + width - moveTableButton.getWidth()); moveTableButton.setyPos(yPos + 1f); moveTableButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY); sellTableButton.setxPos(xPos + leftMargin); sellTableButton.setyPos(yPos + topBodyMargin); sellTableButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY); // If this Table can move, it can be moved or deleted. Same for its Tv and Console if(table.canMove()) { // Check if this Table has a Tv if(table.getTv() != null) { // Move Tv if(moveTvButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) { // Set the Moving Asset mainState.setSelectedEntity(table.getTv()); mainState.setPlacingAsset(table.getTv()); mainState.getPlacingAsset().setBeingMoved(true); // Remove the Tv from the Asset table.setTv(null); // Hide the Panel this.visible = false; // Enter Moving Asset Mode mainState.setCurrentMode(MainState.MOVING_ASSET); } // Sell Tv if(sellTvButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) { // Remove Characters from this Asset business.getStore().removeCharacterReferences(table); // Remove the Tv from the Store business.getStore().removeAsset(table.getTv()); // Return 40% of the money to the Player business.makeBusiness((int)(table.getTv().getReferringMarketAsset().getPrice() * 0.4), Business.DISPOSING, true); // Remove the Tv from the Table table.setTv(null); } } // Check if this Table has a Console if(table.getConsole() != null) { // Move Console if(moveConsoleButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) { // Set the Moving Asset mainState.setSelectedEntity(table.getConsole()); mainState.setPlacingAsset(table.getConsole()); mainState.getPlacingAsset().setBeingMoved(true); // Remove the Tv from the Asset table.setConsole(null); // Hide the Panel this.visible = false; // Enter Moving Asset Mode mainState.setCurrentMode(MainState.MOVING_ASSET); } // Sell Console if(sellConsoleButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) { // Remove Characters from this Asset business.getStore().removeCharacterReferences(table); // Remove the Tv from the Store business.getStore().removeAsset(table.getConsole()); // Return 40% of the money to the Player business.makeBusiness( - (int)(table.getConsole().getReferringMarketAsset().getPrice() * 0.4), Business.DISPOSING, true); // Remove the Tv from the Table table.setConsole(null); } } // Move Table if(moveTableButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) { // Set the Moving Asset mainState.setSelectedEntity(table); mainState.setPlacingAsset(table); 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(table); } // Sell Table if(sellTableButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) { // If it has a Console or a Tv, block the Sale if(table.getConsole() != null || table.getTv() != null) { // TODO: play a pop sound // Send a message saying it has to sell the Tv and Console first } else { // Remove Characters from this Asset business.getStore().removeCharacterReferences(table); // Remove the Table from the Map business.getStore().getMap().removeObject(table); // Return 40% of the money to the Player business.makeBusiness( - (int)(table.getReferringMarketAsset().getPrice() * 0.4), Business.DISPOSING, true); // Flag the Table to be removed in the next Update cycle table.setCanBeDisposed(true); // Enter Mode 0 mainState.setCurrentMode(MainState.SELECTION_MODE); } } } // Increase and decrease price buttons if(table.getConsole() != null) { if(decreasePriceButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) { // Check if Shift is down int priceChange; if(isShiftDown) { priceChange = -50; } else { priceChange = -10; } // Change price! table.getConsole().getReferringMarketConsole().changeRentPrice(priceChange); } if(increasePriceButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) { // Check if Shift is down int priceChange; if(isShiftDown) { priceChange = 50; } else { priceChange = 10; } // Change price! table.getConsole().getReferringMarketConsole().changeRentPrice(priceChange); } } } } /** * 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); // Tv and Console Title Bars Color previousColor = g.getColor(); // Main Panel and Drop Shadow g.setLineWidth(8f); g.setColor(Color.black); g.draw(consoleTitleBar); g.setColor(consoleTitleBarBackground); g.fill(consoleTitleBar); g.setColor(Color.black); g.draw(tvTitleBar); g.setColor(tvTitleBarBackground); g.fill(tvTitleBar); g.setLineWidth(1/8f); // Revert back to previous Color g.setColor(previousColor); // Table label shadowFont.drawString(xPos + leftMargin + 1f, yPos + topHeaderMargin + 1f, table.getReferringMarketAsset().getName()); panelFont.drawString(xPos + leftMargin, yPos + topHeaderMargin, table.getReferringMarketAsset().getName()); // Tvs and Consoles if(table.getTv() != null) { // Has tv! shadowFont.drawString(xPos + leftMargin + 1f, yPos + tvTitleYOffset + 8f + 1f, table.getTv().getReferringMarketAsset().getName()); panelFont.drawString(xPos + leftMargin, yPos + tvTitleYOffset + 8f, table.getTv().getReferringMarketAsset().getName()); shadowFont.drawString(xPos + leftMargin + 1f, yPos + topHeaderMargin + tvTitleYOffset + lineSize + 8f + 1f, "Rating: " + table.getTv().getReferringMarketTv().getLevelOfAwesome() + "/10"); panelFont.drawString(xPos + leftMargin, yPos + topHeaderMargin + tvTitleYOffset + lineSize+ 8f, "Rating: " + table.getTv().getReferringMarketTv().getLevelOfAwesome() + "/10"); // Sell For shadowFont.drawString(sellTvButton.getxPos() + sellTvButton.getWidth() + leftMargin + 1f, sellTvButton.getyPos() + 2f + 1f, "Sell for $ " + GameSystem.printMoney((int)(table.getTv().getReferringMarketAsset().getPrice() * 0.4), false)); panelFont.drawString(sellTvButton.getxPos() + sellTvButton.getWidth() + leftMargin, sellTvButton.getyPos() + 2f, "Sell for $ " + GameSystem.printMoney((int)(table.getTv().getReferringMarketAsset().getPrice() * 0.4), false)); // Render Buttons! moveTvButton.render(container, game, g); sellTvButton.render(container, game, g); } else { // No Tv :( shadowFont.drawString(xPos + leftMargin + 1f, yPos + tvTitleYOffset + 8f + 1f, "No Tv"); panelFont.drawString(xPos + leftMargin, yPos + tvTitleYOffset + 8f, "No Tv"); } if(table.getConsole() != null) { // Has console! // Console Title shadowFont.drawString(xPos + leftMargin + 1f, yPos + consoleTitleYOffset + 8f, table.getConsole().getReferringMarketConsole().getName()); panelFont.drawString(xPos + leftMargin, yPos + consoleTitleYOffset + 8f, table.getConsole().getReferringMarketConsole().getName()); // Play Price shadowFont.drawString(xPos + leftMargin + 1f, yPos + topBodyMargin + consoleTitleYOffset + 1f, "Play price / hour: "); panelFont.drawString(xPos + leftMargin, yPos + topBodyMargin + consoleTitleYOffset, "Play price / hour: "); shadowFont.drawString(decreasePriceButton.xPos + decreasePriceButton.width + 8f + 1f, yPos + topBodyMargin + 1f + consoleTitleYOffset, GameSystem.printMoney(table.getConsole().getReferringMarketConsole().getPlayPrice(), true)); panelFont.drawString(decreasePriceButton.xPos + decreasePriceButton.width + 8f, yPos + topBodyMargin + consoleTitleYOffset, GameSystem.printMoney(table.getConsole().getReferringMarketConsole().getPlayPrice(), true)); // Total Profit shadowFont.drawString(xPos + leftMargin + 1f, yPos + topBodyMargin + lineSize + consoleTitleYOffset + 1f, "Total profit: $" + GameSystem.printMoney(table.getConsole().getReferringMarketAsset().getTotalProfit(), false)); panelFont.drawString(xPos + leftMargin, yPos + + topBodyMargin + lineSize + consoleTitleYOffset, "Total profit: $" + GameSystem.printMoney(table.getConsole().getReferringMarketAsset().getTotalProfit(), false)); // Sell For shadowFont.drawString(sellConsoleButton.getxPos() + sellConsoleButton.getWidth() + leftMargin + 1f, sellConsoleButton.getyPos() + 2f + 1f, "Sell for $ " + GameSystem.printMoney((int)(table.getConsole().getReferringMarketAsset().getPrice() * 0.4), false)); panelFont.drawString(sellConsoleButton.getxPos() + sellConsoleButton.getWidth() + leftMargin, sellConsoleButton.getyPos() + 2f, "Sell for $ " + GameSystem.printMoney((int)(table.getConsole().getReferringMarketAsset().getPrice() * 0.4), false)); // Render moveConsoleButton.render(container, game, g); sellConsoleButton.render(container, game, g); increasePriceButton.render(container, game, g); decreasePriceButton.render(container, game, g); } else { // No console :( shadowFont.drawString(xPos + leftMargin + 1f, yPos + consoleTitleYOffset + 8f + 1f, "No Console"); panelFont.drawString(xPos + leftMargin, yPos + consoleTitleYOffset + 8f, "No Console"); } // Table Buttons moveTableButton.render(container, game, g); sellTableButton.render(container, game, g); shadowFont.drawString(sellTableButton.getxPos() + sellTableButton.getWidth() + leftMargin + 1f, sellTableButton.getyPos() + 2f + 1f, "Sell for $ " + GameSystem.printMoney((int)(table.getReferringMarketAsset().getPrice() * 0.4), false)); panelFont.drawString(sellTableButton.getxPos() + sellTableButton.getWidth() + leftMargin, sellTableButton.getyPos() + 2f, "Sell for $ " + GameSystem.printMoney((int)(table.getReferringMarketAsset().getPrice() * 0.4), false)); } } }