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.state.StateBasedGame;
import com.lucasdnd.ags.gameplay.Business;
import com.lucasdnd.ags.gameplay.Tv;
import com.lucasdnd.ags.system.GameSystem;
import com.lucasdnd.ags.system.MainState;
import com.lucasdnd.ags.system.ResourceLoader;
public class TvMiniPanel extends MiniPanel {
// Tv
private Tv tv;
// Buttons!
private Button moveTvButton;
private Button sellTvButton;
/**
* Constructor!
* @param title
* @param xPos
* @param yPos
* @param width
* @param height
* @param tv
* @throws SlickException
*/
public TvMiniPanel(float xPos, float yPos, float width, float height, Tv tv) throws SlickException {
// Super
super(tv.getReferringMarketAsset().getName(), xPos, yPos, width, height);
// Set the Tv
this.tv = tv;
// Buttons!
moveTvButton = new Button(ResourceLoader.getInstance().moveButtonImages, xPos, yPos);
sellTvButton = new Button(ResourceLoader.getInstance().sellButtonImages, xPos, yPos);
// The Title Color!
titleBackgroundColor = new Color(77f / 255f, 242f / 255f, 129f / 255f, 1f); // 141 235
}
/**
* 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
moveTvButton.setxPos(xPos + width - moveTvButton.getWidth());
moveTvButton.setyPos(yPos + 1f);
moveTvButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY);
sellTvButton.setxPos(xPos + leftMargin);
sellTvButton.setyPos(yPos + topBodyMargin + lineSize);
sellTvButton.update(container, game, delta, leftMouseClicked, leftMouseDown, mouseX, mouseY);
// Sell Tv
if(sellTvButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) {
// Return 40% of the money to the Player
business.makeBusiness((int)(tv.getReferringMarketAsset().getPrice() * 0.4), Business.DISPOSING, true);
// Remove the Tv from the Map
business.getStore().getMap().removeObject(tv);
// Delete it from the Store
tv.setCanBeDisposed(true);
}
// Move Tv
if(moveTvButton.gotLeftClicked(leftMouseClicked, mouseX, mouseY)) {
// Set the Moving Asset
mainState.setSelectedEntity(tv);
mainState.setPlacingAsset(tv);
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(tv);
}
}
}
/**
* 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, tv.getReferringMarketAsset().getName());
panelFont.drawString(xPos + leftMargin, yPos + topHeaderMargin, tv.getReferringMarketAsset().getName());
// Attributes
shadowFont.drawString(xPos + leftMargin + 1f, yPos + topBodyMargin + 1f, "Rating: " + tv.getReferringMarketTv().getLevelOfAwesome() + "/10");
panelFont.drawString(xPos + leftMargin, yPos + topBodyMargin, "Rating: " + tv.getReferringMarketTv().getLevelOfAwesome() + "/10");
// Render Buttons!
moveTvButton.render(container, game, g);
sellTvButton.render(container, game, g);
shadowFont.drawString(sellTvButton.getxPos() + sellTvButton.getWidth() + leftMargin + 1f, sellTvButton.getyPos() + 2f + 1f, "Sell for $ " + GameSystem.printMoney((int)(tv.getReferringMarketAsset().getPrice() * 0.4), false));
panelFont.drawString(sellTvButton.getxPos() + sellTvButton.getWidth() + leftMargin, sellTvButton.getyPos() + 2f, "Sell for $ " + GameSystem.printMoney((int)(tv.getReferringMarketAsset().getPrice() * 0.4), false));
}
}
}