package com.lucasdnd.ags.ui;
import java.util.ArrayList;
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.market.Market;
import com.lucasdnd.ags.gameplay.market.MarketGame;
import com.lucasdnd.ags.system.MainState;
public class BuyGamesPanel extends Panel {
private BuyGamesList buyGamesList; // The actual list
/**
* Constructor
*
* @param title
* @param xPos
* @param yPos
* @param width
* @param height
* @param marketGames
* @throws SlickException
*/
public BuyGamesPanel(String title, float xPos, float yPos, float width, float height, Business business, ArrayList<MarketGame> marketGames)
throws SlickException {
// Create the Panel
super(title, xPos, yPos, width, height);
// Then we create the List from the ListRows. Inside the List constructor, it already creates the Headers so no need to worry about that here.
buyGamesList = new BuyGamesList(xPos, yPos, width, height, business, marketGames);
}
/**
* Update.
*
* @param container
* @param game
* @param delta
* @param business
* @param leftMouseClicked
* @param mouseX
* @param mouseY
* @throws SlickException
*/
public void update(GameContainer container, StateBasedGame game, int delta, MainState mainState, Business business, ViewGamesList viewGamesList,
Market market, boolean leftMouseClicked, boolean leftMouseDown, int mouseX, int mouseY) throws SlickException {
// Updates the List
buyGamesList.update(container, game, delta, mainState, business, viewGamesList, market, leftMouseClicked, leftMouseDown, mouseX, mouseY);
}
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont)
throws SlickException {
// Let the Panel render
super.render(container, game, g, panelFont, shadowFont);
// Render the List, only if the Panel is visible
if (visible) {
buyGamesList.render(container, game, g, panelFont, disabledFont, shadowFont);
}
}
@Override
public void setVisible(boolean visible) {
this.visible = visible;
buyGamesList.visible = visible;
}
@Override
public boolean gotLeftClicked(boolean leftMouseClicked, int mouseX, int mouseY) {
if ((leftMouseClicked) &&
// (mouseX / GameSystem.globalScale >= xPos && mouseX / GameSystem.globalScale <= xPos + images[0].getWidth()) &&
// (mouseY / GameSystem.globalScale >= yPos && mouseY / GameSystem.globalScale <= yPos + images[0].getHeight()))
(mouseX >= xPos && mouseX <= xPos + width) && (mouseY >= yPos && mouseY <= yPos + height))
return true;
return false;
}
@Override
public boolean gotRightClicked(boolean rightMouseClicked, int mouseX, int mouseY) {
if ((rightMouseClicked) &&
// (mouseX / GameSystem.globalScale >= xPos && mouseX / GameSystem.globalScale <= xPos + images[0].getWidth()) &&
// (mouseY / GameSystem.globalScale >= yPos && mouseY / GameSystem.globalScale <= yPos + images[0].getHeight()))
(mouseX >= xPos && mouseX <= xPos + width) && (mouseY >= yPos && mouseY <= yPos + height))
return true;
return false;
}
public BuyGamesList getBuyGamesList() {
return buyGamesList;
}
public void setBuyGamesList(BuyGamesList buyGamesList) {
this.buyGamesList = buyGamesList;
}
}