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.Console;
import com.lucasdnd.ags.system.GameSystem;
import com.lucasdnd.ags.system.MainState;
import com.lucasdnd.ags.system.ResourceLoader;
public class ConsoleMiniPanel extends MiniPanel {
// Console
private Console console;
// Buttons
private Button moveConsoleButton;
private Button sellConsoleButton;
private Button increasePriceButton;
private Button decreasePriceButton;
// Layout
private float plusButtonOffset; // Add this value to the X of the Plus Button when the price is >= 10,00
/**
* Constructor
* @param title
* @param xPos
* @param yPos
* @param width
* @param height
* @param mapAsset
* @throws SlickException
*/
public ConsoleMiniPanel(float xPos, float yPos, float width, float height, Console console) throws SlickException {
// Super Class Constructor
super(console.getReferringMarketAsset().getName(), xPos, yPos, width, height);
// The Console!
this.console = console;
// The Buttons!
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);
}
/**
* 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);
// Move and Sell Buttons
moveConsoleButton.setxPos(xPos + width - moveConsoleButton.getWidth());
moveConsoleButton.setyPos(yPos + 1f);
moveConsoleButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY);
sellConsoleButton.setxPos(xPos + leftMargin);
sellConsoleButton.setyPos(yPos + topBodyMargin + lineSize*2);
sellConsoleButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY);
// Increase and Decrease Price Buttons
if(console.getReferringMarketConsole().getPlayPrice() >= 1000) {
plusButtonOffset = 12f;
} else {
plusButtonOffset = 0f;
}
decreasePriceButton.setxPos(xPos + 230f);
decreasePriceButton.setyPos(yPos + topBodyMargin - 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);
// Price Change
if(decreasePriceButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) {
// Check if Shift is down
int priceChange;
if(isShiftDown) {
priceChange = -50;
} else {
priceChange = -10;
}
// Change price!
console.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!
console.getReferringMarketConsole().changeRentPrice(priceChange);
}
// If this Console can move, it can be moved or deleted. Same for its Console and Console
if(console.canMove()) {
// Move Console
if(moveConsoleButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) {
// Set the Moving Asset
mainState.setSelectedEntity(console);
mainState.setPlacingAsset(console);
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(console);
}
// Sell Console
if(sellConsoleButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) {
// Remove Characters from this Asset
business.getStore().removeCharacterReferences(console);
// Remove the Table from the Map
business.getStore().getMap().removeObject(console);
// Return 40% of the money to the Player
business.makeBusiness((int)(console.getReferringMarketAsset().getPrice() * 0.4), Business.DISPOSING, true);
// Flag the Table to be removed in the next Update cycle
console.setCanBeDisposed(true);
// Enter Mode 0
mainState.setCurrentMode(MainState.SELECTION_MODE);
}
}
}
}
/**
* 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, console.getReferringMarketAsset().getName());
panelFont.drawString(xPos + leftMargin + 1f, yPos + topHeaderMargin + 1f, console.getReferringMarketAsset().getName());
// Play Price
shadowFont.drawString(xPos + leftMargin + 1f, yPos + topBodyMargin + 1f, "Play price / hour: ");
panelFont.drawString(xPos + leftMargin, yPos + topBodyMargin, "Play price / hour: ");
shadowFont.drawString(decreasePriceButton.xPos + decreasePriceButton.width + 8f + 1f, yPos + topBodyMargin + 1f, GameSystem.printMoney(console.getReferringMarketConsole().getPlayPrice(), true));
panelFont.drawString(decreasePriceButton.xPos + decreasePriceButton.width + 8f, yPos + topBodyMargin, GameSystem.printMoney(console.getReferringMarketConsole().getPlayPrice(), true));
// Total Profit
shadowFont.drawString(xPos + leftMargin + 1f, yPos + topBodyMargin + lineSize + 1f, "Total profit: $" + GameSystem.printMoney(console.getReferringMarketAsset().getTotalProfit(), false));
panelFont.drawString(xPos + leftMargin, yPos + + topBodyMargin + lineSize, "Total profit: $" + GameSystem.printMoney(console.getReferringMarketAsset().getTotalProfit(), false));
// Render Buttons!
moveConsoleButton.render(container, game, g);
sellConsoleButton.render(container, game, g);
shadowFont.drawString(sellConsoleButton.getxPos() + sellConsoleButton.getWidth() + leftMargin + 1f, sellConsoleButton.getyPos() + 2f + 1f, "Sell for $ " + GameSystem.printMoney((int)(console.getReferringMarketAsset().getPrice() * 0.4), false));
panelFont.drawString(sellConsoleButton.getxPos() + sellConsoleButton.getWidth() + leftMargin, sellConsoleButton.getyPos() + 2f, "Sell for $ " + GameSystem.printMoney((int)(console.getReferringMarketAsset().getPrice() * 0.4), false));
increasePriceButton.render(container, game, g);
decreasePriceButton.render(container, game, g);
}
}
}