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;
public abstract class MiniPanel extends Panel {
// Position of items in the Panel
public static float lineSize = 34f;
public static float leftMargin = 10f;
public static float rightMargin = 4f;
public static float topHeaderMargin = 8f;
public static float topBodyMargin = topHeaderMargin + lineSize + 6f;
public static float priceButtonSeparation = 108f;
/**
* Creates the Mini Panel
* @param title
* @param xPos
* @param yPos
* @param width
* @param height
* @param table
* @throws SlickException
*/
public MiniPanel(String title, float xPos, float yPos, float width, float height) throws SlickException {
// Panel Constructor
super(title, xPos, yPos, width, height, lineSize);
titleBackgroundColor = new Color(192f / 255f, 191f / 255f, 235f / 255f, 1f);
}
/**
* Update!
*/
public void update(GameContainer container, StateBasedGame game, int delta,
Business business, boolean leftMouseClicked, int mouseX, int mouseY) throws SlickException {
// Only if visible :P
if(visible) {
// Set the x and y Positions of the Window
if (xPos + width >= container.getWidth()) {
xPos = container.getWidth() - width - rightMargin;
}
window.setLocation(xPos, yPos);
dropShadow.setLocation(xPos + rightMargin, yPos + rightMargin);
titleBar.setLocation(xPos, yPos);
}
}
/**
* Render!
*/
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font shadowFont) throws SlickException {
// Only renders the Mini Panel if it's visible
if(visible) {
// Save the previous Color
Color previousColor = g.getColor();
// Main Panel and Drop Shadow
g.setLineWidth(8f);
g.setColor(new Color(0.4f, 0.4f, 0.4f));
g.draw(dropShadow);
g.setColor(Color.black);
g.draw(window);
g.setColor(backgroundColor);
g.fill(window);
g.setColor(Color.black);
g.draw(titleBar);
g.setLineWidth(1/8f);
g.setColor(titleBackgroundColor);
g.fill(titleBar);
// Revert back to previous Color
g.setColor(previousColor);
}
}
@Override
public boolean gotLeftClicked(boolean leftMouseClicked, int mouseX, int mouseY) {
if((leftMouseClicked) &&
(mouseX >= this.xPos && mouseX <= this.xPos + this.width) &&
(mouseY >= this.yPos && mouseY <= this.yPos + this.height)
)
return true;
return false;
}
@Override
public boolean gotRightClicked(boolean rightMouseClicked, int mouseX, int mouseY) {
if((rightMouseClicked) &&
(mouseX >= this.xPos && mouseX <= this.xPos + this.width) &&
(mouseY >= this.yPos && mouseY <= this.yPos + this.height)
)
return true;
return false;
}
@Override
public void setxPos(float xPos) {
super.setxPos(xPos + 30f);
}
@Override
public void setyPos(float yPos) {
super.setyPos(yPos - height / 2);
}
}